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 = true;
316 procedure g_ResetDynlights ();
317 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
318 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
323 g_textures
, g_main
, g_window
, g_menu
,
324 e_input
, e_log
, g_console
, g_items
, g_map
,
325 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
326 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
327 BinEditor
, g_language
, g_net
, SDL
,
328 ENet
, e_fixedbuffer
, g_netmsg
, g_netmaster
, GL
, GLExt
,
332 // ////////////////////////////////////////////////////////////////////////// //
335 x
, y
, radius
: Integer;
338 exploRadius
: Integer;
342 g_dynLights
: array of TDynLight
= nil;
343 g_dynLightCount
: Integer = 0;
344 g_playerLight
: Boolean = false;
346 procedure g_ResetDynlights ();
350 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
352 for idx
:= 0 to g_dynLightCount
-1 do
354 if g_dynLights
[idx
].exploCount
= -666 then
361 Inc(g_dynLights
[idx
].exploCount
);
362 if (g_dynLights
[idx
].exploCount
< 10) then
364 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
365 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
366 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
367 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
372 g_dynLightCount
:= lnum
;
375 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
377 if not gwin_has_stencil
then exit
;
378 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
379 g_dynLights
[g_dynLightCount
].x
:= x
;
380 g_dynLights
[g_dynLightCount
].y
:= y
;
381 g_dynLights
[g_dynLightCount
].radius
:= radius
;
382 g_dynLights
[g_dynLightCount
].r
:= r
;
383 g_dynLights
[g_dynLightCount
].g
:= g
;
384 g_dynLights
[g_dynLightCount
].b
:= b
;
385 g_dynLights
[g_dynLightCount
].a
:= a
;
386 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
387 Inc(g_dynLightCount
);
390 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
392 if not gwin_has_stencil
then exit
;
393 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
394 g_dynLights
[g_dynLightCount
].x
:= x
;
395 g_dynLights
[g_dynLightCount
].y
:= y
;
396 g_dynLights
[g_dynLightCount
].radius
:= 0;
397 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
398 g_dynLights
[g_dynLightCount
].r
:= r
;
399 g_dynLights
[g_dynLightCount
].g
:= g
;
400 g_dynLights
[g_dynLightCount
].b
:= b
;
401 g_dynLights
[g_dynLightCount
].a
:= 0;
402 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
403 Inc(g_dynLightCount
);
407 // ////////////////////////////////////////////////////////////////////////// //
408 procedure drawProfiles (x
, y
: Integer; title
: AnsiString);
413 procedure drawItems ();
416 e_TextureFontPrintEx(x
+2+4*xprofItDepth
, yy
, Format('%s: %d', [xprofItName
, xprofItMicro
]), gStdFont
, 255, 255, 0, 1, false);
418 if xprofItHasChildren
then
429 if not xprofItReset() then exit
;
431 hgt
:= 16+2+xprofTotalCount
*(16+2); // title, items
433 e_DrawFillQuad(x
, y
, x
+wdt
-1, y
+hgt
-1, 255, 255, 255, 200, B_BLEND
);
435 e_TextureFontPrintEx(x
+2, y
+2, Format('%s: %d', [title
, Integer(xprofTotalMicro
)]), gStdFont
, 255, 255, 0, 1, false);
441 // ////////////////////////////////////////////////////////////////////////// //
443 TEndCustomGameStat
= record
444 PlayerStat
: TPlayerStatArray
;
448 Map
, MapName
: String;
451 TEndSingleGameStat
= record
452 PlayerStat
: Array [0..1] of record
458 TotalSecrets
: Integer;
461 TLoadingStat
= record
465 Msgs
: Array of String;
469 TParamStrValue
= record
474 TParamStrValues
= Array of TParamStrValue
;
477 INTER_ACTION_TEXT
= 1;
478 INTER_ACTION_PIC
= 2;
479 INTER_ACTION_MUSIC
= 3;
483 FPSCounter
, UPSCounter
: Word;
484 FPSTime
, UPSTime
: LongWord;
485 DataLoaded
: Boolean = False;
486 LastScreenShot
: Int64;
487 IsDrawStat
: Boolean = False;
488 CustomStat
: TEndCustomGameStat
;
489 SingleStat
: TEndSingleGameStat
;
490 LoadingStat
: TLoadingStat
;
491 EndingGameCounter
: Byte = 0;
494 MapList
: SArray
= nil;
495 MapIndex
: Integer = -1;
501 text: Array of ShortString;
502 anim
: Array of ShortString;
503 pic
: Array of ShortString;
504 mus
: Array of ShortString;
506 triggers
: Array of record
508 actions
: Array of record
509 action
, p1
, p2
: Integer;
512 cur_trigger
: Integer;
525 function Compare(a
, b
: TPlayerStat
): Integer;
527 if a
.Spectator
then Result
:= 1
528 else if b
.Spectator
then Result
:= -1
529 else if a
.Frags
< b
.Frags
then Result
:= 1
530 else if a
.Frags
> b
.Frags
then Result
:= -1
531 else if a
.Deaths
< b
.Deaths
then Result
:= -1
532 else if a
.Deaths
> b
.Deaths
then Result
:= 1
533 else if a
.Kills
< b
.Kills
then Result
:= -1
537 procedure SortGameStat(var stat
: TPlayerStatArray
);
542 if stat
= nil then Exit
;
544 for I
:= High(stat
) downto Low(stat
) do
545 for J
:= Low(stat
) to High(stat
) - 1 do
546 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
549 stat
[J
] := stat
[J
+ 1];
554 function g_Game_ModeToText(Mode
: Byte): string;
558 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
559 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
560 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
561 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
562 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
566 function g_Game_TextToMode(Mode
: string): Byte;
569 Mode
:= UpperCase(Mode
);
570 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
575 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
580 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
585 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
590 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
597 function g_Game_IsNet(): Boolean;
599 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
602 function g_Game_IsServer(): Boolean;
604 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
607 function g_Game_IsClient(): Boolean;
609 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
612 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
619 Result
.name
:= ExtractFileName(WAD
);
620 Result
.description
:= '';
623 w
:= TWADFile
.Create();
626 if not w
.GetResource('INTERSCRIPT', p
, len
) then
632 cfg
:= TConfig
.CreateMem(p
, len
);
633 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
634 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
635 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
636 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
642 procedure g_Game_FreeWAD();
646 for a
:= 0 to High(MegaWAD
.res
.pic
) do
647 if MegaWAD
.res
.pic
[a
] <> '' then
648 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
650 for a
:= 0 to High(MegaWAD
.res
.mus
) do
651 if MegaWAD
.res
.mus
[a
] <> '' then
652 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
654 MegaWAD
.res
.pic
:= nil;
655 MegaWAD
.res
.text := nil;
656 MegaWAD
.res
.anim
:= nil;
657 MegaWAD
.res
.mus
:= nil;
658 MegaWAD
.triggers
:= nil;
660 g_Texture_Delete('TEXTURE_endpic');
661 g_Sound_Delete('MUSIC_endmus');
663 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
664 gGameSettings
.WAD
:= '';
667 procedure g_Game_LoadWAD(WAD
: string);
676 gGameSettings
.WAD
:= WAD
;
677 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
680 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
682 w
:= TWADFile
.Create();
683 w
.ReadFile(MapsDir
+ WAD
);
685 if not w
.GetResource('INTERSCRIPT', p
, len
) then
691 cfg
:= TConfig
.CreateMem(p
, len
);
696 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
697 if s = '' then Break;
700 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
701 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
703 g_Texture_CreateWADEx(s, s);
709 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
710 if s = '' then Break;
713 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
714 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
716 g_Music_CreateWADEx(s, s);
719 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
720 if MegaWAD
.endpic
<> '' then
722 s
:= g_ExtractWadName(MegaWAD
.endpic
);
723 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
724 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
726 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
727 if MegaWAD
.endmus
<> '' then
729 s
:= g_ExtractWadName(MegaWAD
.endmus
);
730 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
731 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
739 {procedure start_trigger(t: string);
743 function next_trigger(): Boolean;
747 procedure DisableCheats();
753 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
754 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
755 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
756 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
759 procedure g_Game_ExecuteEvent(Name
: String);
765 if gEvents
= nil then
767 for a
:= 0 to High(gEvents
) do
768 if gEvents
[a
].Name
= Name
then
770 if gEvents
[a
].Command
<> '' then
771 g_Console_Process(gEvents
[a
].Command
, True);
776 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
781 if gDelayedEvents
<> nil then
782 for a
:= 0 to High(gDelayedEvents
) do
783 if not gDelayedEvents
[a
].Pending
then
790 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
791 n
:= High(gDelayedEvents
);
793 gDelayedEvents
[n
].Pending
:= True;
794 gDelayedEvents
[n
].DEType
:= DEType
;
795 gDelayedEvents
[n
].DENum
:= Num
;
796 gDelayedEvents
[n
].DEStr
:= Str
;
797 if DEType
= DE_GLOBEVENT
then
798 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
800 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
809 if g_Game_IsNet
and g_Game_IsServer
then
810 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
816 g_Game_StopAllSounds(False);
821 EndingGameCounter
:= 0;
822 g_ActiveWindow
:= nil;
824 gLMSRespawn
:= LMS_RESPAWN_NONE
;
825 gLMSRespawnTime
:= 0;
828 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
833 begin // Ýòî áûë òåñò
837 begin // Âûõîä â ãëàâíîå ìåíþ
838 gMusic
.SetByName('MUSIC_MENU');
840 if gState
<> STATE_SLIST
then
842 g_GUI_ShowWindow('MainMenu');
843 gState
:= STATE_MENU
;
846 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
847 slReturnPressed
:= True;
848 if g_Net_Slist_Fetch(slCurrent
) then
850 if slCurrent
= nil then
851 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
854 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
857 g_Game_ExecuteEvent('ongameend');
861 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
863 if not g_Game_IsClient
then g_Game_Restart();
866 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
868 // Ñòàòèñòèêà Ñâîåé èãðû:
869 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
871 CustomStat
.GameTime
:= gTime
;
872 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
873 CustomStat
.MapName
:= gMapInfo
.Name
;
874 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
875 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
876 CustomStat
.TeamStat
:= gTeamStat
;
878 CustomStat
.PlayerStat
:= nil;
880 // Ñòàòèñòèêà èãðîêîâ:
881 if gPlayers
<> nil then
883 for a
:= 0 to High(gPlayers
) do
884 if gPlayers
[a
] <> nil then
886 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
887 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
889 Name
:= gPlayers
[a
].Name
;
890 Frags
:= gPlayers
[a
].Frags
;
891 Deaths
:= gPlayers
[a
].Death
;
892 Kills
:= gPlayers
[a
].Kills
;
893 Team
:= gPlayers
[a
].Team
;
894 Color
:= gPlayers
[a
].Model
.Color
;
895 Spectator
:= gPlayers
[a
].FSpectator
;
899 SortGameStat(CustomStat
.PlayerStat
);
902 g_Game_ExecuteEvent('onmapend');
905 EndingGameCounter
:= 255;
906 gState
:= STATE_FOLD
;
908 if gDefInterTime
< 0 then
909 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
911 gInterEndTime
:= gDefInterTime
* 1000;
914 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
916 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
917 SingleStat
.GameTime
:= gTime
;
918 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
919 SingleStat
.TotalSecrets
:= gSecretsCount
;
920 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
921 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
922 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
923 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
924 if SingleStat
.TwoPlayers
then
926 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
927 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
930 g_Game_ExecuteEvent('onmapend');
933 if gNextMap
<> '' then
935 gMusic
.SetByName('MUSIC_INTERMUS');
937 gState
:= STATE_INTERSINGLE
;
939 g_Game_ExecuteEvent('oninter');
941 else // Áîëüøå íåò êàðò
944 EndingGameCounter
:= 255;
945 gState
:= STATE_FOLD
;
950 // Îêîí÷àíèå îáðàáîòàíî:
951 if gExit
<> EXIT_QUIT
then
955 procedure DrawStat();
957 pc
, x
, y
, w
, h
: Integer;
958 w1
, w2
, w3
, w4
: Integer;
960 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
963 stat
: TPlayerStatArray
;
970 pc
:= g_Player_GetCount
;
971 e_TextureFontGetSize(gStdFont
, cw
, ch
);
973 w
:= gScreenWidth
-(gScreenWidth
div 5);
974 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
977 h
:= 40+ch
*5+(ch
+8)*pc
;
978 x
:= (gScreenWidth
div 2)-(w
div 2);
979 y
:= (gScreenHeight
div 2)-(h
div 2);
981 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
982 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
984 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
985 map
:= g_ExtractFileName(gMapInfo
.Map
);
986 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
988 case gGameSettings
.GameMode
of
991 if gGameSettings
.MaxLives
= 0 then
994 s1
:= _lc
[I_GAME_LMS
];
995 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
996 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1001 if gGameSettings
.MaxLives
= 0 then
1002 s1
:= _lc
[I_GAME_TDM
]
1004 s1
:= _lc
[I_GAME_TLMS
];
1005 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1006 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1011 s1
:= _lc
[I_GAME_CTF
];
1012 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1013 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1018 if gGameSettings
.MaxLives
= 0 then
1019 s1
:= _lc
[I_GAME_COOP
]
1021 s1
:= _lc
[I_GAME_SURV
];
1022 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1023 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1034 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1036 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1038 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1040 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1041 gStdFont
, 200, 200, 200, 1);
1043 if NetMode
= NET_SERVER
then
1044 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1046 if NetMode
= NET_CLIENT
then
1047 e_TextureFontPrintEx(x
+8, y
+ 8,
1048 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1052 stat
:= g_Player_GetStats();
1055 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1056 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1058 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1060 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1064 for a
:= TEAM_RED
to TEAM_BLUE
do
1066 if a
= TEAM_RED
then
1068 s1
:= _lc
[I_GAME_TEAM_RED
];
1075 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1081 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1082 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1083 gStdFont
, r
, g
, b
, 1);
1085 _y
:= _y
+ch
+(ch
div 4);
1086 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1087 _y
:= _y
+(ch
div 4);
1089 for aa
:= 0 to High(stat
) do
1090 if stat
[aa
].Team
= a
then
1106 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1108 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1110 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1112 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1119 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1122 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1123 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1124 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1125 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1128 for aa
:= 0 to High(stat
) do
1142 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1143 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1145 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1147 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1149 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1151 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1157 procedure g_Game_Init();
1163 gTempDelete
:= False;
1165 sfsGCDisable(); // temporary disable removing of temporary volumes
1168 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1169 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1170 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1171 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1173 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1174 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1175 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1177 g_Game_ClearLoading();
1178 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1179 g_Game_SetLoadingText('', 0, False);
1181 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1184 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1185 g_PlayerModel_LoadData();
1187 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1189 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1190 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1191 until FindNext(SR
) <> 0;
1194 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1196 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1197 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1198 until FindNext(SR
) <> 0;
1201 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1203 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1204 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1205 until FindNext(SR
) <> 0;
1211 LastScreenShot
:= 0;
1213 {e_MouseInfo.Accel := 1.0;}
1215 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1218 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1219 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1220 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1221 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1222 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1224 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1227 gMusic
:= TMusic
.Create();
1228 gMusic
.SetByName('MUSIC_MENU');
1231 gGameSettings
.WarmupTime
:= 30;
1233 gState
:= STATE_MENU
;
1235 SetLength(gEvents
, 6);
1236 gEvents
[0].Name
:= 'ongamestart';
1237 gEvents
[1].Name
:= 'ongameend';
1238 gEvents
[2].Name
:= 'onmapstart';
1239 gEvents
[3].Name
:= 'onmapend';
1240 gEvents
[4].Name
:= 'oninter';
1241 gEvents
[5].Name
:= 'onwadend';
1243 sfsGCEnable(); // enable releasing unused volumes
1247 procedure g_Game_Free();
1249 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1250 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1254 g_Player_RemoveAllCorpses();
1256 gGameSettings
.GameType
:= GT_NONE
;
1257 if gGameSettings
.GameMode
= GM_SINGLE
then
1258 gGameSettings
.GameMode
:= GM_DM
;
1259 gSwitchGameMode
:= gGameSettings
.GameMode
;
1262 gExitByTrigger
:= False;
1265 function IsActivePlayer(p
: TPlayer
): Boolean;
1270 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1273 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1280 if gPlayers
= nil then
1282 for a
:= Low(gPlayers
) to High(gPlayers
) do
1283 if IsActivePlayer(gPlayers
[a
]) then
1285 if gPlayers
[a
].UID
<> ID
then
1287 Result
:= gPlayers
[a
];
1292 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1298 if gPlayers
= nil then
1302 for a
:= Low(gPlayers
) to High(gPlayers
) do
1303 if IsActivePlayer(gPlayers
[a
]) then
1305 SetLength(ids
, Length(ids
) + 1);
1306 ids
[High(ids
)] := gPlayers
[a
].UID
;
1307 if gPlayers
[a
].UID
= Skip
then
1310 if Length(ids
) = 0 then
1315 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1318 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1324 if gPlayers
= nil then
1328 for a
:= Low(gPlayers
) to High(gPlayers
) do
1329 if IsActivePlayer(gPlayers
[a
]) then
1331 SetLength(ids
, Length(ids
) + 1);
1332 ids
[High(ids
)] := gPlayers
[a
].UID
;
1333 if gPlayers
[a
].UID
= Skip
then
1336 if Length(ids
) = 0 then
1339 Result
:= ids
[Length(ids
) - 1]
1341 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1344 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1346 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1347 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1351 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1357 if (plr
= nil) then exit
;
1358 if (p2hack
) then time
:= 1000 else time
:= 1;
1359 strafeDir
:= MoveButton
shr 4;
1360 MoveButton
:= MoveButton
and $0F;
1363 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1364 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1365 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1367 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1368 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1369 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1371 // if we have "strafe" key, turn off old strafe mechanics
1372 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1374 // new strafe mechanics
1375 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1376 // now set direction according to strafe (reversed)
1377 if (strafeDir
= 2) then plr
.SetDirection(D_LEFT
)
1378 else if (strafeDir
= 1) then plr
.SetDirection(D_RIGHT
);
1382 strafeDir
:= 0; // not strafing anymore
1383 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1384 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1385 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1386 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1387 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1388 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1391 // fix movebutton state
1392 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1394 // Îñòàëüíûå êëàâèøè:
1395 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1396 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1397 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1398 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1399 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1400 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1401 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1403 for i
:= 0 to High(KeyWeapon
) do
1404 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1405 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1408 // HACK: add dynlight here
1409 if gwin_k8_enable_light_experiments
then
1411 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1413 g_playerLight
:= true;
1415 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1417 g_playerLight
:= false;
1421 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1424 procedure g_Game_Update();
1426 Msg
: g_gui
.TMessage
;
1433 // Ïîðà âûêëþ÷àòü èãðó:
1434 if gExit
= EXIT_QUIT
then
1436 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1440 if gExit
= EXIT_QUIT
then
1444 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1447 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1450 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1452 gExit
:= EXIT_SIMPLE
;
1458 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1459 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1460 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1461 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1463 if g_Game_IsNet
and g_Game_IsServer
then
1465 gInterTime
:= gInterTime
+ GAME_TICK
;
1466 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1467 if a
<> gServInterTime
then
1469 gServInterTime
:= a
;
1470 MH_SEND_TimeSync(gServInterTime
);
1474 if (not g_Game_IsClient
) and
1477 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1478 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1479 and (g_ActiveWindow
= nil)
1481 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1484 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1485 g_Game_StopAllSounds(True);
1487 if gMapOnce
then // Ýòî áûë òåñò
1488 gExit
:= EXIT_SIMPLE
1490 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1491 g_Game_ChangeMap(gNextMap
)
1492 else // Ñëåäóþùåé êàðòû íåò
1494 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1496 // Âûõîä â ãëàâíîå ìåíþ:
1498 g_GUI_ShowWindow('MainMenu');
1499 gMusic
.SetByName('MUSIC_MENU');
1501 gState
:= STATE_MENU
;
1504 // Ôèíàëüíàÿ êàðòèíêà:
1505 g_Game_ExecuteEvent('onwadend');
1507 if not gMusic
.SetByName('MUSIC_endmus') then
1508 gMusic
.SetByName('MUSIC_STDENDMUS');
1510 gState
:= STATE_ENDPIC
;
1512 g_Game_ExecuteEvent('ongameend');
1518 if gState
= STATE_INTERTEXT
then
1519 if InterText
.counter
> 0 then
1520 InterText
.counter
:= InterText
.counter
- 1;
1523 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1525 if EndingGameCounter
= 0 then
1527 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1528 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1530 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1532 g_Game_ExecuteEvent('onwadend');
1533 if not gMusic
.SetByName('MUSIC_endmus') then
1534 gMusic
.SetByName('MUSIC_STDENDMUS');
1537 gMusic
.SetByName('MUSIC_ROUNDMUS');
1540 gState
:= STATE_INTERCUSTOM
;
1542 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1544 gMusic
.SetByName('MUSIC_INTERMUS');
1546 gState
:= STATE_INTERSINGLE
;
1548 g_Game_ExecuteEvent('oninter');
1551 DecMin(EndingGameCounter
, 6, 0);
1554 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1556 if gMapOnce
then // Ýòî áûë òåñò
1558 gExit
:= EXIT_SIMPLE
;
1564 g_Serverlist_Control(slCurrent
);
1567 if g_Game_IsNet
then
1568 if not gConsoleShow
then
1569 if not gChatShow
then
1571 if g_ActiveWindow
= nil then
1573 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1574 g_Console_Chat_Switch(False)
1575 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1576 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1577 g_Console_Chat_Switch(True);
1580 if not gChatEnter
then
1581 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1582 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1585 // Ñòàòèñòèêà ïî Tab:
1587 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1588 (gGameSettings
.GameType
<> GT_SINGLE
) and
1589 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1592 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1594 // Âðåìÿ += 28 ìèëëèñåêóíä:
1595 gTime
:= gTime
+ GAME_TICK
;
1597 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1598 if MessageTime
= 0 then
1600 if MessageTime
> 0 then
1601 MessageTime
:= MessageTime
- 1;
1603 if (g_Game_IsServer
) then
1605 // Áûë çàäàí ëèìèò âðåìåíè:
1606 if (gGameSettings
.TimeLimit
> 0) then
1607 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1608 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1613 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1614 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1615 g_Game_RestartRound(gLMSSoftSpawn
);
1617 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1618 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1620 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1622 g_Console_Process(gVoteCommand
);
1624 gVotePassed
:= False;
1627 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1628 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1629 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1630 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1631 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1633 // Áûë çàäàí ëèìèò ïîáåä:
1634 if (gGameSettings
.GoalLimit
> 0) then
1638 if gGameSettings
.GameMode
= GM_DM
then
1639 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1640 for i
:= 0 to High(gPlayers
) do
1641 if gPlayers
[i
] <> nil then
1642 if gPlayers
[i
].Frags
> b
then
1643 b
:= gPlayers
[i
].Frags
;
1646 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1647 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1648 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1651 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1652 if b
>= gGameSettings
.GoalLimit
then
1659 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1660 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1661 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1662 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1664 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1665 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1666 end // if not console
1669 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1671 // process weapon switch queue
1675 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1676 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1678 if not gSpectKeyPress
then
1680 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1682 // switch spect mode
1684 SPECT_NONE
: ; // not spectator
1686 SPECT_MAPVIEW
: Inc(gSpectMode
);
1687 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1689 gSpectKeyPress
:= True;
1691 if gSpectMode
= SPECT_MAPVIEW
then
1693 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1694 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1695 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1696 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1697 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1698 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1699 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1700 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1701 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1704 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1705 gSpectKeyPress
:= True;
1707 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1710 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1711 gSpectKeyPress
:= True;
1714 if gSpectMode
= SPECT_PLAYERS
then
1716 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1719 gSpectViewTwo
:= True;
1720 gSpectKeyPress
:= True;
1722 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1724 // remove second view
1725 gSpectViewTwo
:= False;
1726 gSpectKeyPress
:= True;
1728 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1730 // prev player (view 1)
1731 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1732 gSpectKeyPress
:= True;
1734 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1736 // next player (view 1)
1737 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1738 gSpectKeyPress
:= True;
1740 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1742 // prev player (view 2)
1743 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1744 gSpectKeyPress
:= True;
1746 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1748 // next player (view 2)
1749 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1750 gSpectKeyPress
:= True;
1755 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1756 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1757 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1758 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1759 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1760 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1761 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1762 gSpectKeyPress
:= False;
1765 // Îáíîâëÿåì âñå îñòàëüíîå:
1768 g_Triggers_Update();
1770 g_Monsters_Update();
1772 g_Player_UpdateAll();
1773 g_Player_UpdatePhysicalObjects();
1774 if gGameSettings
.GameType
= GT_SERVER
then
1775 if Length(gMonstersSpawned
) > 0 then
1777 for I
:= 0 to High(gMonstersSpawned
) do
1778 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1779 SetLength(gMonstersSpawned
, 0);
1782 if (gSoundTriggerTime
> 8) then
1784 g_Game_UpdateTriggerSounds();
1785 gSoundTriggerTime
:= 0;
1788 Inc(gSoundTriggerTime
);
1790 if (NetMode
= NET_SERVER
) then
1792 Inc(NetTimeToUpdate
);
1793 Inc(NetTimeToReliable
);
1794 if NetTimeToReliable
>= NetRelupdRate
then
1796 for I
:= 0 to High(gPlayers
) do
1797 if gPlayers
[I
] <> nil then
1798 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1800 if gMonsters
<> nil then
1801 for I
:= 0 to High(gMonsters
) do
1802 if gMonsters
[I
] <> nil then
1804 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1806 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1807 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1810 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1811 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1812 (gMonsters
[I
].GameVelX
<> 0) or
1813 (gMonsters
[I
].GameVelY
<> 0) then
1814 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1817 NetTimeToReliable
:= 0;
1818 NetTimeToUpdate
:= NetUpdateRate
;
1820 else if NetTimeToUpdate
>= NetUpdateRate
then
1822 if gPlayers
<> nil then
1823 for I
:= 0 to High(gPlayers
) do
1824 if gPlayers
[I
] <> nil then
1825 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1827 if gMonsters
<> nil then
1828 for I
:= 0 to High(gMonsters
) do
1829 if gMonsters
[I
] <> nil then
1831 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1833 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1834 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1837 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1838 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1839 (gMonsters
[I
].GameVelX
<> 0) or
1840 (gMonsters
[I
].GameVelY
<> 0) then
1841 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1844 NetTimeToUpdate
:= 0;
1847 if NetUseMaster
then
1848 if gTime
>= NetTimeToMaster
then
1850 if (NetMHost
= nil) or (NetMPeer
= nil) then
1851 if not g_Net_Slist_Connect
then
1852 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1855 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1859 if NetMode
= NET_CLIENT
then
1860 MC_SEND_PlayerPos();
1861 end; // if gameOn ...
1863 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1864 if g_ActiveWindow
<> nil then
1866 w
:= e_GetFirstKeyPressed();
1868 if (w
<> IK_INVALID
) then
1870 Msg
.Msg
:= MESSAGE_DIKEY
;
1872 g_ActiveWindow
.OnMessage(Msg
);
1875 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1876 if g_ActiveWindow
<> nil then
1877 g_ActiveWindow
.Update();
1879 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1880 if gResolutionChange
then
1882 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1883 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1884 gResolutionChange
:= False;
1887 // Íóæíî ñìåíèòü ÿçûê:
1888 if gLanguageChange
then
1890 //e_WriteLog('Read language file', MSG_NOTIFY);
1891 //g_Language_Load(DataDir + gLanguage + '.txt');
1892 g_Language_Set(gLanguage
);
1894 gLanguageChange
:= False;
1898 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1899 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1900 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1903 LastScreenShot
:= GetTimer();
1906 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1907 if e_KeyPressed(IK_F10
) and
1909 (not gConsoleShow
) and
1910 (g_ActiveWindow
= nil) then
1915 Time
:= GetTimer() {div 1000};
1917 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1918 if gDelayedEvents
<> nil then
1919 for a
:= 0 to High(gDelayedEvents
) do
1920 if gDelayedEvents
[a
].Pending
and
1922 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1923 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1926 case gDelayedEvents
[a
].DEType
of
1928 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1931 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1935 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1936 if g_Game_IsNet
and g_Game_IsServer
then
1937 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1940 gDelayedEvents
[a
].Pending
:= False;
1943 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1944 UPSCounter
:= UPSCounter
+ 1;
1945 if Time
- UPSTime
>= 1000 then
1952 if gGameOn
then g_Weapon_AddDynLights();
1955 procedure g_Game_LoadData();
1957 if DataLoaded
then Exit
;
1959 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1961 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1962 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1963 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1964 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1965 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1966 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1967 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1968 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1969 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1970 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1971 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1972 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1973 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1974 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1975 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1976 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1977 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1978 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1979 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1980 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1981 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1982 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1983 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1984 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1985 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1986 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1987 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1988 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1989 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1990 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1991 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1992 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1993 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1994 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1996 goodsnd
[0] := TPlayableSound
.Create();
1997 goodsnd
[1] := TPlayableSound
.Create();
1998 goodsnd
[2] := TPlayableSound
.Create();
1999 goodsnd
[3] := TPlayableSound
.Create();
2001 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2002 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2003 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2004 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2006 killsnd
[0] := TPlayableSound
.Create();
2007 killsnd
[1] := TPlayableSound
.Create();
2008 killsnd
[2] := TPlayableSound
.Create();
2009 killsnd
[3] := TPlayableSound
.Create();
2011 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2012 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2013 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2014 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2016 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2019 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2020 g_Weapon_LoadData();
2022 g_Monsters_LoadData();
2027 procedure g_Game_FreeData();
2029 if not DataLoaded
then Exit
;
2032 g_Weapon_FreeData();
2033 g_Monsters_FreeData();
2035 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
2037 g_Texture_Delete('NOTEXTURE');
2038 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2039 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2040 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2041 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2042 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2043 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2044 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2045 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2046 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2047 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2048 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2049 g_Frames_DeleteByName('FRAMES_TELEPORT');
2050 g_Sound_Delete('SOUND_GAME_TELEPORT');
2051 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2052 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2053 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2054 g_Sound_Delete('SOUND_GAME_BULK1');
2055 g_Sound_Delete('SOUND_GAME_BULK2');
2056 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2057 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2058 g_Sound_Delete('SOUND_GAME_SWITCH1');
2059 g_Sound_Delete('SOUND_GAME_SWITCH0');
2066 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2067 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2068 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2069 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2076 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2077 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2078 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2079 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2081 DataLoaded
:= False;
2084 procedure DrawCustomStat();
2090 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2091 s1
, s2
, topstr
: String;
2093 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2096 if e_KeyPressed(IK_TAB
) then
2098 if not gStatsPressed
then
2100 gStatsOff
:= not gStatsOff
;
2101 gStatsPressed
:= True;
2105 gStatsPressed
:= False;
2109 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2110 w
:= (Length(s1
) * ww2
) div 2;
2111 x
:= gScreenWidth
div 2 - w
;
2113 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2117 if (gGameSettings
.GameMode
= GM_COOP
) then
2119 if gMissionFailed
then
2120 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2122 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2125 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2127 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2128 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2130 if g_Game_IsNet
then
2132 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2133 if not gChatShow
then
2134 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2135 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2138 if g_Game_IsClient
then
2139 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2141 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2142 if not gChatShow
then
2143 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2144 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2149 w
:= gScreenWidth
-x
*2;
2155 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2156 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2158 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2160 case CustomStat
.GameMode
of
2163 if gGameSettings
.MaxLives
= 0 then
2164 s1
:= _lc
[I_GAME_DM
]
2166 s1
:= _lc
[I_GAME_LMS
];
2170 if gGameSettings
.MaxLives
= 0 then
2171 s1
:= _lc
[I_GAME_TDM
]
2173 s1
:= _lc
[I_GAME_TLMS
];
2175 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2178 if gGameSettings
.MaxLives
= 0 then
2179 s1
:= _lc
[I_GAME_COOP
]
2181 s1
:= _lc
[I_GAME_SURV
];
2187 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2191 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2192 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2195 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2196 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2197 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2198 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2200 pc
:= Length(CustomStat
.PlayerStat
);
2201 if pc
= 0 then Exit
;
2203 if CustomStat
.GameMode
= GM_COOP
then
2205 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2207 s2
:= _lc
[I_GAME_MONSTERS
];
2208 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2209 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2211 s2
:= _lc
[I_GAME_SECRETS
];
2212 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2213 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2216 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2218 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2219 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2220 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2222 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2223 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2224 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2228 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2233 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2234 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2235 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2237 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2240 for t
:= TEAM_RED
to TEAM_BLUE
do
2242 if t
= TEAM_RED
then
2244 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2245 gStdFont
, 255, 0, 0, 1);
2246 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2247 gStdFont
, 255, 0, 0, 1);
2254 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2255 gStdFont
, 0, 0, 255, 1);
2256 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2257 gStdFont
, 0, 0, 255, 1);
2263 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2266 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2267 if CustomStat
.PlayerStat
[p
].Team
= t
then
2268 with CustomStat
.PlayerStat
[p
] do
2282 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2283 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2284 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2291 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2294 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2295 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2296 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2299 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2300 with CustomStat
.PlayerStat
[p
] do
2302 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2309 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2310 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2311 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2317 procedure DrawSingleStat();
2319 tm
, key_x
, val_x
, y
: Integer;
2323 procedure player_stat(n
: Integer);
2329 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2330 s2
:= Format(' %d', [gTotalMonsters
]);
2332 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2333 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2334 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2335 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2337 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2338 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2340 // "Kills-per-minute: ##.#":
2341 s1
:= _lc
[I_MENU_INTER_KPM
];
2343 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2345 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2346 s2
:= Format(' %.1f', [kpm
]);
2348 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2349 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2351 // "Secrets found: # / #":
2352 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2353 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2355 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2356 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2357 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2358 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2360 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2361 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2365 // "Level Complete":
2366 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2367 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2369 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2370 s1
:= _lc
[I_MENU_INTER_KPM
];
2371 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2374 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2376 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2377 val_x
:= key_x
+ w1
;
2380 tm
:= SingleStat
.GameTime
div 1000;
2381 s1
:= _lc
[I_MENU_INTER_TIME
];
2382 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2384 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2385 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2387 if SingleStat
.TwoPlayers
then
2390 s1
:= _lc
[I_MENU_PLAYER_1
];
2391 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2392 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2394 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2399 s1
:= _lc
[I_MENU_PLAYER_2
];
2400 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2401 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2403 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2409 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2415 procedure DrawLoadingStat();
2421 if Length(LoadingStat
.Msgs
) = 0 then
2424 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2425 yy
:= (gScreenHeight
div 3);
2426 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2427 xx
:= (gScreenWidth
div 3);
2430 for i
:= 0 to NextMsg
-1 do
2432 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2433 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2437 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2438 yy
:= yy
+ LOADING_INTERLINE
;
2442 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2444 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2446 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2447 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2450 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2451 ScaleSz
:= 16 div Scale
;
2452 // Ðàçìåðû ìèíè-êàðòû:
2453 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2454 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2456 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2458 if gWalls
<> nil then
2461 for a
:= 0 to High(gWalls
) do
2463 if PanelType
<> 0 then
2465 // Ëåâûé âåðõíèé óãîë:
2466 aX
:= X
div ScaleSz
;
2467 aY
:= Y
div ScaleSz
;
2469 aX2
:= max(Width
div ScaleSz
, 1);
2470 aY2
:= max(Height
div ScaleSz
, 1);
2471 // Ïðàâûé íèæíèé óãîë:
2472 aX2
:= aX
+ aX2
- 1;
2473 aY2
:= aY
+ aY2
- 1;
2476 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2477 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2478 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2482 if gSteps
<> nil then
2485 for a
:= 0 to High(gSteps
) do
2487 if PanelType
<> 0 then
2489 // Ëåâûé âåðõíèé óãîë:
2490 aX
:= X
div ScaleSz
;
2491 aY
:= Y
div ScaleSz
;
2493 aX2
:= max(Width
div ScaleSz
, 1);
2494 aY2
:= max(Height
div ScaleSz
, 1);
2495 // Ïðàâûé íèæíèé óãîë:
2496 aX2
:= aX
+ aX2
- 1;
2497 aY2
:= aY
+ aY2
- 1;
2499 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2502 if gLifts
<> nil then
2505 for a
:= 0 to High(gLifts
) do
2507 if PanelType
<> 0 then
2509 // Ëåâûé âåðõíèé óãîë:
2510 aX
:= X
div ScaleSz
;
2511 aY
:= Y
div ScaleSz
;
2513 aX2
:= max(Width
div ScaleSz
, 1);
2514 aY2
:= max(Height
div ScaleSz
, 1);
2515 // Ïðàâûé íèæíèé óãîë:
2516 aX2
:= aX
+ aX2
- 1;
2517 aY2
:= aY
+ aY2
- 1;
2520 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2521 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2522 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2523 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2527 if gWater
<> nil then
2530 for a
:= 0 to High(gWater
) do
2532 if PanelType
<> 0 then
2534 // Ëåâûé âåðõíèé óãîë:
2535 aX
:= X
div ScaleSz
;
2536 aY
:= Y
div ScaleSz
;
2538 aX2
:= max(Width
div ScaleSz
, 1);
2539 aY2
:= max(Height
div ScaleSz
, 1);
2540 // Ïðàâûé íèæíèé óãîë:
2541 aX2
:= aX
+ aX2
- 1;
2542 aY2
:= aY
+ aY2
- 1;
2544 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2547 if gAcid1
<> nil then
2549 // Ðèñóåì êèñëîòó 1:
2550 for a
:= 0 to High(gAcid1
) do
2552 if PanelType
<> 0 then
2554 // Ëåâûé âåðõíèé óãîë:
2555 aX
:= X
div ScaleSz
;
2556 aY
:= Y
div ScaleSz
;
2558 aX2
:= max(Width
div ScaleSz
, 1);
2559 aY2
:= max(Height
div ScaleSz
, 1);
2560 // Ïðàâûé íèæíèé óãîë:
2561 aX2
:= aX
+ aX2
- 1;
2562 aY2
:= aY
+ aY2
- 1;
2564 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2567 if gAcid2
<> nil then
2569 // Ðèñóåì êèñëîòó 2:
2570 for a
:= 0 to High(gAcid2
) do
2572 if PanelType
<> 0 then
2574 // Ëåâûé âåðõíèé óãîë:
2575 aX
:= X
div ScaleSz
;
2576 aY
:= Y
div ScaleSz
;
2578 aX2
:= max(Width
div ScaleSz
, 1);
2579 aY2
:= max(Height
div ScaleSz
, 1);
2580 // Ïðàâûé íèæíèé óãîë:
2581 aX2
:= aX
+ aX2
- 1;
2582 aY2
:= aY
+ aY2
- 1;
2584 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2587 if gPlayers
<> nil then
2590 for a
:= 0 to High(gPlayers
) do
2591 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2593 // Ëåâûé âåðõíèé óãîë:
2594 aX
:= Obj
.X
div ScaleSz
+ 1;
2595 aY
:= Obj
.Y
div ScaleSz
+ 1;
2597 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2598 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2599 // Ïðàâûé íèæíèé óãîë:
2600 aX2
:= aX
+ aX2
- 1;
2601 aY2
:= aY
+ aY2
- 1;
2603 if gPlayers
[a
] = p
then
2604 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2607 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2608 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2609 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2613 if gMonsters
<> nil then
2616 for a
:= 0 to High(gMonsters
) do
2617 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2619 // Ëåâûé âåðõíèé óãîë:
2620 aX
:= Obj
.X
div ScaleSz
+ 1;
2621 aY
:= Obj
.Y
div ScaleSz
+ 1;
2623 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2624 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2625 // Ïðàâûé íèæíèé óãîë:
2626 aX2
:= aX
+ aX2
- 1;
2627 aY2
:= aY
+ aY2
- 1;
2629 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2635 procedure DrawMapView(x
, y
, w
, h
: Integer);
2641 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2642 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2643 g_Map_DrawBack(-bx
, -by
);
2650 glTranslatef(-x
, -y
, 0);
2652 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_BACK
);
2653 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_STEP
);
2656 g_Player_DrawShells();
2658 g_Player_DrawCorpses();
2659 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WALL
);
2661 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_CLOSEDOOR
);
2664 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID1
);
2665 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID2
);
2666 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WATER
);
2667 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_FORE
);
2668 if g_debug_HealthBar
then
2670 g_Monsters_DrawHealth();
2671 g_Player_DrawHealth();
2677 procedure DrawPlayer(p
: TPlayer
);
2679 px
, py
, a
, b
, c
, d
: Integer;
2682 lx
, ly
, lrad
: Integer;
2684 if (p
= nil) or (p
.FDummy
) then
2687 g_Map_DrawBack(0, 0);
2696 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2697 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2699 if px
> (gPlayerScreenSize
.X
div 2) then
2700 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2703 if py
> (gPlayerScreenSize
.Y
div 2) then
2704 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2707 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2708 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2709 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2710 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2711 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2713 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2716 if p
.IncCam
<> 0 then
2718 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2720 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2721 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2724 if py
< (gPlayerScreenSize
.Y
div 2) then
2726 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2727 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2730 if p
.IncCam
< 0 then
2731 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2733 p
.IncCam
:= p
.IncCam
+ 1;
2735 if p
.IncCam
> 0 then
2736 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2738 p
.IncCam
:= p
.IncCam
- 1;
2741 if (px
< gPlayerScreenSize
.X
div 2) or
2742 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2745 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2746 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2748 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2750 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2751 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2754 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2755 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2757 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2759 xprofBeginSection('map background');
2760 g_Map_DrawBack(-c
, -d
);
2764 sY
:= -(b
+p
.IncCam
);
2765 sWidth
:= gPlayerScreenSize
.X
;
2766 sHeight
:= gPlayerScreenSize
.Y
;
2768 glTranslatef(a
, b
+p
.IncCam
, 0);
2770 xprofBeginSection('map rendering');
2772 xprofBeginSection('panel_back');
2773 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_BACK
);
2776 xprofBeginSection('panel_step');
2777 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_STEP
);
2780 xprofBeginSection('items');
2784 xprofBeginSection('weapons');
2788 xprofBeginSection('shells');
2789 g_Player_DrawShells();
2792 xprofBeginSection('drawall');
2796 xprofBeginSection('corpses');
2797 g_Player_DrawCorpses();
2800 xprofBeginSection('panel_wall');
2801 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WALL
);
2804 xprofBeginSection('monsters');
2808 xprofBeginSection('panel_closedoor');
2809 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_CLOSEDOOR
);
2812 xprofBeginSection('gfx');
2816 xprofBeginSection('flags');
2820 xprofBeginSection('panel_acid1');
2821 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID1
);
2824 xprofBeginSection('panel_acid2');
2825 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID2
);
2828 xprofBeginSection('panel_water');
2829 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WATER
);
2832 //TODO: lights should be in separate grid, i think
2833 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2834 if gwin_has_stencil
and (g_dynLightCount
> 0) then
2836 xprofBeginSection('dynlights');
2838 // setup OpenGL parameters
2839 glStencilMask($FFFFFFFF);
2840 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
2841 glEnable(GL_STENCIL_TEST
);
2842 glEnable(GL_SCISSOR_TEST
);
2843 glClear(GL_STENCIL_BUFFER_BIT
);
2844 glStencilFunc(GL_EQUAL
, 0, $ff);
2846 for lln
:= 0 to g_dynLightCount
-1 do
2848 lx
:= g_dynLights
[lln
].x
;
2849 ly
:= g_dynLights
[lln
].y
;
2850 lrad
:= g_dynLights
[lln
].radius
;
2851 if lrad
< 3 then continue
;
2853 if lx
-sX
+lrad
< 0 then continue
;
2854 if ly
-sY
+lrad
< 0 then continue
;
2855 if lx
-sX
-lrad
>= gPlayerScreenSize
.X
then continue
;
2856 if ly
-sY
-lrad
>= gPlayerScreenSize
.Y
then continue
;
2858 // set scissor to optimize drawing
2859 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
2860 // no need to clear stencil buffer, light blitting will do it for us
2861 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
2862 // draw extruded panels
2863 glDisable(GL_TEXTURE_2D
);
2864 glDisable(GL_BLEND
);
2865 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
2866 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
2867 // render light texture
2868 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
2869 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
2872 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2873 glEnable(GL_TEXTURE_2D
);
2874 // color and opacity
2875 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
2876 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
2878 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
2879 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
2880 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
2881 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
2886 glDisable(GL_STENCIL_TEST
);
2887 glDisable(GL_BLEND
);
2888 glDisable(GL_SCISSOR_TEST
);
2889 glScissor(0, 0, sWidth
, sHeight
);
2895 xprofBeginSection('dynlights');
2899 xprofBeginSection('panel_fore');
2900 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_FORE
);
2903 if g_debug_HealthBar
then
2905 xprofBeginSection('monster health');
2906 g_Monsters_DrawHealth();
2909 xprofBeginSection('player health');
2910 g_Player_DrawHealth();
2914 if p
.FSpectator
then
2915 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2916 p
.GameY
+ PLAYER_RECT_CY
- 4,
2917 'X', gStdFont
, 255, 255, 255, 1, True);
2919 for a := 0 to High(gCollideMap) do
2920 for b := 0 to High(gCollideMap[a]) do
2923 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2925 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2929 1: e_DrawPoint(1, b, a, 200, 200, 200);
2930 2: e_DrawPoint(1, b, a, 64, 64, 255);
2931 3: e_DrawPoint(1, b, a, 255, 0, 255);
2938 xprofEndSection(); // map rendering
2943 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2944 if g_Debug_Player
then
2945 g_Player_DrawDebug(p
);
2949 procedure g_Game_Draw();
2956 plView1
, plView2
: TPlayer
;
2959 if gExit
= EXIT_QUIT
then Exit
;
2961 Time
:= GetTimer() {div 1000};
2962 FPSCounter
:= FPSCounter
+1;
2963 if Time
- FPSTime
>= 1000 then
2970 xprofBegin(g_profile_frame_draw
);
2972 if gGameOn
or (gState
= STATE_FOLD
) then
2974 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2976 gSpectMode
:= SPECT_NONE
;
2977 if not gRevertPlayers
then
2979 plView1
:= gPlayer1
;
2980 plView2
:= gPlayer2
;
2984 plView1
:= gPlayer2
;
2985 plView2
:= gPlayer1
;
2989 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2991 gSpectMode
:= SPECT_NONE
;
2992 if gPlayer2
= nil then
2995 plView1
:= gPlayer2
;
3004 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3005 gSpectMode
:= SPECT_STATS
;
3007 if gSpectMode
= SPECT_PLAYERS
then
3008 if gPlayers
<> nil then
3010 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3011 if plView1
= nil then
3013 gSpectPID1
:= GetActivePlayerID_Next();
3014 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3016 if gSpectViewTwo
then
3018 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3019 if plView2
= nil then
3021 gSpectPID2
:= GetActivePlayerID_Next();
3022 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3027 if gSpectMode
= SPECT_MAPVIEW
then
3029 // Ðåæèì ïðîñìîòðà êàðòû
3031 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3032 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3033 gHearPoint1
.Active
:= True;
3034 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3035 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3036 gHearPoint2
.Active
:= False;
3040 Split
:= (plView1
<> nil) and (plView2
<> nil);
3042 // Òî÷êè ñëóõà èãðîêîâ
3043 if plView1
<> nil then
3045 gHearPoint1
.Active
:= True;
3046 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3047 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3049 gHearPoint1
.Active
:= False;
3050 if plView2
<> nil then
3052 gHearPoint2
.Active
:= True;
3053 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3054 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3056 gHearPoint2
.Active
:= False;
3058 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3059 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3062 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3063 if gScreenHeight
mod 2 = 0 then
3064 Dec(gPlayerScreenSize
.Y
);
3067 gPlayerScreenSize
.Y
:= gScreenHeight
;
3070 if gScreenHeight
mod 2 = 0 then
3071 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3073 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3075 DrawPlayer(plView1
);
3076 gPlayer1ScreenCoord
.X
:= sX
;
3077 gPlayer1ScreenCoord
.Y
:= sY
;
3081 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3083 DrawPlayer(plView2
);
3084 gPlayer2ScreenCoord
.X
:= sX
;
3085 gPlayer2ScreenCoord
.Y
:= sY
;
3088 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3091 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3094 if MessageText
<> '' then
3098 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3100 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3101 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3103 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3104 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3107 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3109 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3111 // Draw spectator GUI
3114 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3117 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3119 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3121 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3123 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3124 if gSpectMode
= SPECT_MAPVIEW
then
3126 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3127 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3128 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3129 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3130 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3132 if gSpectMode
= SPECT_PLAYERS
then
3134 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3135 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3136 if gSpectViewTwo
then
3138 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3139 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3140 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3141 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3145 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3146 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3152 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
3154 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3156 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3157 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3158 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3163 if (gState
= STATE_MENU
) then
3165 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
3167 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3168 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3169 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3171 if g_ActiveWindow
<> nil then
3172 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3175 if gState
= STATE_FOLD
then
3176 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3178 if gState
= STATE_INTERCUSTOM
then
3180 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3182 back
:= 'TEXTURE_endpic';
3183 if not g_Texture_Get(back
, ID
) then
3184 back
:= _lc
[I_TEXTURE_ENDPIC
];
3189 if g_Texture_Get(back
, ID
) then
3190 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3192 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3196 if g_ActiveWindow
<> nil then
3197 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3200 if gState
= STATE_INTERSINGLE
then
3202 if EndingGameCounter
> 0 then
3203 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
3208 if g_Texture_Get(back
, ID
) then
3209 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3211 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3215 if g_ActiveWindow
<> nil then
3216 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3220 if gState
= STATE_ENDPIC
then
3223 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3224 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3226 if ID
<> DWORD(-1) then
3227 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3229 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3231 if g_ActiveWindow
<> nil then
3232 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3235 if gState
= STATE_SLIST
then
3237 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3239 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3240 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3242 g_Serverlist_Draw(slCurrent
);
3246 if g_ActiveWindow
<> nil then
3249 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3250 g_ActiveWindow
.Draw();
3255 if g_debug_Sounds
and gGameOn
then
3257 for w
:= 0 to High(e_SoundsArray
) do
3258 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3259 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3264 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3265 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3268 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3269 e_TextureFontPrint(gScreenWidth
-72, 0,
3270 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3274 if g_profile_frame_draw
then drawProfiles(0, 0, 'MAP RENDER');
3277 procedure g_Game_Quit();
3279 g_Game_StopAllSounds(True);
3281 g_Game_SaveOptions();
3283 g_PlayerModel_FreeData();
3284 g_Texture_DeleteAll();
3285 g_Frames_DeleteAll();
3288 if NetInitDone
then g_Net_Free
;
3290 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3291 if gMapToDelete
<> '' then
3292 g_Game_DeleteTestMap();
3298 procedure g_FatalError(Text: String);
3300 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3301 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3303 gExit
:= EXIT_SIMPLE
;
3306 procedure g_SimpleError(Text: String);
3308 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3309 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3312 procedure g_Game_SetupScreenSize();
3316 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3317 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3318 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3319 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3321 gPlayerScreenSize
.Y
:= gScreenHeight
;
3323 // Ðàçìåð çàäíåãî ïëàíà:
3324 if BackID
<> DWORD(-1) then
3328 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3329 (gScreenHeight
*d
> gMapInfo
.Height
) then
3332 gBackSize
.X
:= Round(gScreenWidth
*d
);
3333 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3337 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3339 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3342 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3344 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3345 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3347 if gPlayer1
= nil then
3349 if g_Game_IsClient
then
3351 if NetPlrUID1
> -1 then
3353 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3354 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3359 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3360 Team
:= gPlayer1Settings
.Team
;
3362 // Ñîçäàíèå ïåðâîãî èãðîêà:
3363 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3364 gPlayer1Settings
.Color
,
3366 if gPlayer1
= nil then
3367 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3370 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3371 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3372 if g_Game_IsServer
and g_Game_IsNet
then
3373 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3374 gPlayer1
.Respawn(False, True);
3376 if g_Game_IsNet
and NetUseMaster
then
3382 if gPlayer2
= nil then
3384 if g_Game_IsClient
then
3386 if NetPlrUID2
> -1 then
3387 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3391 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3392 Team
:= gPlayer2Settings
.Team
;
3394 // Ñîçäàíèå âòîðîãî èãðîêà:
3395 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3396 gPlayer2Settings
.Color
,
3398 if gPlayer2
= nil then
3399 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3402 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3403 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3404 if g_Game_IsServer
and g_Game_IsNet
then
3405 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3406 gPlayer2
.Respawn(False, True);
3408 if g_Game_IsNet
and NetUseMaster
then
3416 procedure g_Game_RemovePlayer();
3420 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3421 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3426 if g_Game_IsServer
then
3429 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3430 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3431 g_Player_Remove(Pl
.UID
);
3433 if g_Game_IsNet
and NetUseMaster
then
3442 if g_Game_IsServer
then
3445 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3446 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3447 g_Player_Remove(Pl
.UID
);
3449 if g_Game_IsNet
and NetUseMaster
then
3454 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3460 procedure g_Game_Spectate();
3462 g_Game_RemovePlayer();
3463 if gPlayer1
<> nil then
3464 g_Game_RemovePlayer();
3467 procedure g_Game_SpectateCenterView();
3469 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3470 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3473 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3479 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3481 g_Game_ClearLoading();
3484 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3487 gGameSettings
.GameType
:= GT_SINGLE
;
3488 gGameSettings
.MaxLives
:= 0;
3489 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3490 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3491 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3492 gSwitchGameMode
:= GM_SINGLE
;
3494 g_Game_ExecuteEvent('ongamestart');
3496 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3497 g_Game_SetupScreenSize();
3499 // Ñîçäàíèå ïåðâîãî èãðîêà:
3500 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3501 gPlayer1Settings
.Color
,
3502 gPlayer1Settings
.Team
, False));
3503 if gPlayer1
= nil then
3505 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3509 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3512 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3515 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3516 gPlayer2Settings
.Color
,
3517 gPlayer2Settings
.Team
, False));
3518 if gPlayer2
= nil then
3520 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3524 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3528 // Çàãðóçêà è çàïóñê êàðòû:
3529 if not g_Game_StartMap(MAP
, True) then
3531 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3535 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3539 for i
:= nPl
+1 to nPlayers
do
3540 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3543 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3544 TimeLimit
, GoalLimit
: Word;
3546 Options
: LongWord; nPlayers
: Byte);
3552 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3554 g_Game_ClearLoading();
3557 gGameSettings
.GameType
:= GT_CUSTOM
;
3558 gGameSettings
.GameMode
:= GameMode
;
3559 gSwitchGameMode
:= GameMode
;
3560 gGameSettings
.TimeLimit
:= TimeLimit
;
3561 gGameSettings
.GoalLimit
:= GoalLimit
;
3562 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3563 gGameSettings
.Options
:= Options
;
3565 gCoopTotalMonstersKilled
:= 0;
3566 gCoopTotalSecretsFound
:= 0;
3567 gCoopTotalMonsters
:= 0;
3568 gCoopTotalSecrets
:= 0;
3572 g_Game_ExecuteEvent('ongamestart');
3574 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3575 g_Game_SetupScreenSize();
3577 // Ðåæèì íàáëþäàòåëÿ:
3578 if nPlayers
= 0 then
3585 if nPlayers
>= 1 then
3587 // Ñîçäàíèå ïåðâîãî èãðîêà:
3588 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3589 gPlayer1Settings
.Color
,
3590 gPlayer1Settings
.Team
, False));
3591 if gPlayer1
= nil then
3593 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3597 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3601 if nPlayers
>= 2 then
3603 // Ñîçäàíèå âòîðîãî èãðîêà:
3604 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3605 gPlayer2Settings
.Color
,
3606 gPlayer2Settings
.Team
, False));
3607 if gPlayer2
= nil then
3609 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3613 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3617 // Çàãðóçêà è çàïóñê êàðòû:
3618 if not g_Game_StartMap(Map
, True) then
3620 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3624 // Íåò òî÷åê ïîÿâëåíèÿ:
3625 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3626 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3627 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3628 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3629 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3631 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3635 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3639 for i
:= nPl
+1 to nPlayers
do
3640 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3643 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3644 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3645 Options
: LongWord; nPlayers
: Byte;
3646 IPAddr
: LongWord; Port
: Word);
3650 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3652 g_Game_ClearLoading();
3655 gGameSettings
.GameType
:= GT_SERVER
;
3656 gGameSettings
.GameMode
:= GameMode
;
3657 gSwitchGameMode
:= GameMode
;
3658 gGameSettings
.TimeLimit
:= TimeLimit
;
3659 gGameSettings
.GoalLimit
:= GoalLimit
;
3660 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3661 gGameSettings
.Options
:= Options
;
3663 gCoopTotalMonstersKilled
:= 0;
3664 gCoopTotalSecretsFound
:= 0;
3665 gCoopTotalMonsters
:= 0;
3666 gCoopTotalSecrets
:= 0;
3670 g_Game_ExecuteEvent('ongamestart');
3672 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3673 g_Game_SetupScreenSize();
3675 // Ðåæèì íàáëþäàòåëÿ:
3676 if nPlayers
= 0 then
3682 if nPlayers
>= 1 then
3684 // Ñîçäàíèå ïåðâîãî èãðîêà:
3685 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3686 gPlayer1Settings
.Color
,
3687 gPlayer1Settings
.Team
, False));
3688 if gPlayer1
= nil then
3690 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3694 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3697 if nPlayers
>= 2 then
3699 // Ñîçäàíèå âòîðîãî èãðîêà:
3700 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3701 gPlayer2Settings
.Color
,
3702 gPlayer2Settings
.Team
, False));
3703 if gPlayer2
= nil then
3705 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3709 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3713 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3715 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3719 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3721 // Çàãðóçêà è çàïóñê êàðòû:
3722 if not g_Game_StartMap(Map
, True) then
3724 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3728 // Íåò òî÷åê ïîÿâëåíèÿ:
3729 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3730 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3731 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3732 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3733 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3735 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3739 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3742 NetState
:= NET_STATE_GAME
;
3745 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3759 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3760 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3762 g_Game_ClearLoading();
3765 gGameSettings
.GameType
:= GT_CLIENT
;
3767 gCoopTotalMonstersKilled
:= 0;
3768 gCoopTotalSecretsFound
:= 0;
3769 gCoopTotalMonsters
:= 0;
3770 gCoopTotalSecrets
:= 0;
3774 g_Game_ExecuteEvent('ongamestart');
3776 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3777 g_Game_SetupScreenSize();
3779 NetState
:= NET_STATE_AUTH
;
3781 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3783 if not g_Net_Connect(Addr
, Port
) then
3785 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3786 NetState
:= NET_STATE_NONE
;
3790 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3792 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3797 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3799 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3801 Ptr
:= NetEvent
.packet
^.data
;
3804 MID
:= e_Raw_Read_Byte(Ptr
);
3806 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3808 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3809 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3811 WadName
:= e_Raw_Read_String(Ptr
);
3812 Map
:= e_Raw_Read_String(Ptr
);
3814 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3816 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3817 gSwitchGameMode
:= gGameSettings
.GameMode
;
3818 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3819 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3820 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3821 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3822 T
:= e_Raw_Read_LongWord(Ptr
);
3824 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3825 if newResPath
= '' then
3827 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3828 newResPath
:= g_Res_DownloadWAD(WadName
);
3829 if newResPath
= '' then
3831 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3832 enet_packet_destroy(NetEvent
.packet
);
3833 NetState
:= NET_STATE_NONE
;
3837 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3839 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3840 gPlayer1Settings
.Color
,
3841 gPlayer1Settings
.Team
, False));
3843 if gPlayer1
= nil then
3845 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3847 enet_packet_destroy(NetEvent
.packet
);
3848 NetState
:= NET_STATE_NONE
;
3852 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3853 gPlayer1
.UID
:= NetPlrUID1
;
3854 gPlayer1
.Reset(True);
3856 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3858 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3860 enet_packet_destroy(NetEvent
.packet
);
3861 NetState
:= NET_STATE_NONE
;
3869 enet_packet_destroy(NetEvent
.packet
);
3873 enet_packet_destroy(NetEvent
.packet
);
3876 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3879 if (NetEvent
.data
<= NET_DISC_MAX
) then
3880 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3881 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3891 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3900 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3901 NetState
:= NET_STATE_NONE
;
3905 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3906 gLMSRespawnTime
:= 0;
3909 NetState
:= NET_STATE_GAME
;
3910 MC_SEND_FullStateRequest
;
3911 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3914 procedure g_Game_SaveOptions();
3916 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3919 procedure g_Game_ChangeMap(MapPath
: String);
3923 g_Game_ClearLoading();
3925 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3926 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3927 if gExitByTrigger
then
3930 gExitByTrigger
:= False;
3932 if not g_Game_StartMap(MapPath
, Force
) then
3933 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3936 procedure g_Game_Restart();
3940 if g_Game_IsClient
then
3942 map
:= g_ExtractFileName(gMapInfo
.Map
);
3946 g_Game_ClearLoading();
3947 g_Game_StartMap(Map
, True);
3950 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3952 NewWAD
, ResName
: String;
3956 g_Player_RemoveAllCorpses();
3958 if (not g_Game_IsClient
) and
3959 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3960 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3962 if gSwitchGameMode
= GM_CTF
then
3963 gGameSettings
.MaxLives
:= 0;
3964 gGameSettings
.GameMode
:= gSwitchGameMode
;
3967 gSwitchGameMode
:= gGameSettings
.GameMode
;
3969 g_Player_ResetTeams();
3971 if Pos(':\', Map
) > 0 then
3973 NewWAD
:= g_ExtractWadName(Map
);
3974 ResName
:= g_ExtractFileName(Map
);
3975 if g_Game_IsServer
then
3977 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3978 g_Game_LoadWAD(NewWAD
);
3980 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3981 g_Game_ClientWAD(NewWAD
, gWADHash
);
3985 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3988 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3990 gState
:= STATE_NONE
;
3991 g_ActiveWindow
:= nil;
3997 if gGameSettings
.GameMode
= GM_CTF
then
3999 g_Map_ResetFlag(FLAG_RED
);
4000 g_Map_ResetFlag(FLAG_BLUE
);
4001 // CTF, à ôëàãîâ íåò:
4002 if not g_Map_HaveFlagPoints() then
4003 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4008 gState
:= STATE_MENU
;
4015 NetTimeToUpdate
:= 1;
4016 NetTimeToReliable
:= 0;
4017 NetTimeToMaster
:= NetMasterRate
;
4018 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4019 gLMSRespawnTime
:= 0;
4020 gMissionFailed
:= False;
4023 gCoopMonstersKilled
:= 0;
4024 gCoopSecretsFound
:= 0;
4026 gVoteInProgress
:= False;
4027 gVotePassed
:= False;
4033 if not gGameOn
then Exit
;
4035 g_Game_SpectateCenterView();
4037 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4039 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4040 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4041 gLMSSoftSpawn
:= True;
4042 if NetMode
= NET_SERVER
then
4043 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4045 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4048 if NetMode
= NET_SERVER
then
4050 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4053 if NetUseMaster
then
4055 if (NetMHost
= nil) or (NetMPeer
= nil) then
4056 if not g_Net_Slist_Connect
then
4057 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4062 if NetClients
<> nil then
4063 for I
:= 0 to High(NetClients
) do
4064 if NetClients
[I
].Used
then
4066 NetClients
[I
].Voted
:= False;
4067 if NetClients
[I
].RequestedFullUpdate
then
4069 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4070 NetClients
[I
].RequestedFullUpdate
:= False;
4074 g_Net_UnbanNonPermHosts();
4079 gCoopTotalMonstersKilled
:= 0;
4080 gCoopTotalSecretsFound
:= 0;
4081 gCoopTotalMonsters
:= 0;
4082 gCoopTotalSecrets
:= 0;
4086 g_Game_ExecuteEvent('onmapstart');
4089 procedure SetFirstLevel();
4093 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4094 if MapList
= nil then
4097 SortSArray(MapList
);
4098 gNextMap
:= MapList
[Low(MapList
)];
4103 procedure g_Game_ExitLevel(Map
: Char16
);
4107 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4108 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4109 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4110 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4112 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4113 if gGameSettings
.GameType
= GT_SINGLE
then
4114 gExit
:= EXIT_ENDLEVELSINGLE
4115 else // Âûøëè â âûõîä â Ñâîåé èãðå
4117 gExit
:= EXIT_ENDLEVELCUSTOM
;
4118 if gGameSettings
.GameMode
= GM_COOP
then
4119 g_Player_RememberAll
;
4121 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4124 if gGameSettings
.GameMode
= GM_COOP
then
4127 gStatsPressed
:= True;
4128 gNextMap
:= 'MAP01';
4130 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4133 if g_Game_IsNet
then
4135 MH_SEND_GameStats();
4136 MH_SEND_CoopStats();
4142 procedure g_Game_RestartLevel();
4146 if gGameSettings
.GameMode
= GM_SINGLE
then
4151 gExit
:= EXIT_ENDLEVELCUSTOM
;
4152 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4156 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4160 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4162 if not g_Game_IsClient
then
4164 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4167 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4168 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4172 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4176 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4177 g_Game_LoadWAD(NewWAD
);
4180 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4182 i
, n
, nb
, nr
: Integer;
4184 if not g_Game_IsServer
then Exit
;
4185 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4186 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4187 gLMSRespawnTime
:= 0;
4190 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4192 gMissionFailed
:= True;
4193 g_Game_RestartLevel
;
4197 n
:= 0; nb
:= 0; nr
:= 0;
4198 for i
:= Low(gPlayers
) to High(gPlayers
) do
4199 if (gPlayers
[i
] <> nil) and
4200 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4201 (gPlayers
[i
] is TBot
)) then
4204 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4205 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4208 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4210 // wait a second until the fuckers finally decide to join
4211 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4212 gLMSRespawnTime
:= gTime
+ 1000;
4213 gLMSSoftSpawn
:= NoMapRestart
;
4217 g_Player_RemoveAllCorpses
;
4218 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4219 if g_Game_IsNet
then
4220 MH_SEND_GameEvent(NET_EV_LMS_START
);
4222 for i
:= Low(gPlayers
) to High(gPlayers
) do
4224 if gPlayers
[i
] = nil then continue
;
4225 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4226 // don't touch normal spectators
4227 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4229 gPlayers
[i
].FNoRespawn
:= True;
4230 gPlayers
[i
].Lives
:= 0;
4231 if g_Game_IsNet
then
4232 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4235 gPlayers
[i
].FNoRespawn
:= False;
4236 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4237 gPlayers
[i
].Respawn(False, True);
4238 if gGameSettings
.GameMode
= GM_COOP
then
4240 gPlayers
[i
].Frags
:= 0;
4241 gPlayers
[i
].RecallState
;
4243 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4244 gPlayer1
:= g_Player_Get(gLMSPID1
);
4245 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4246 gPlayer2
:= g_Player_Get(gLMSPID2
);
4249 for i
:= Low(gItems
) to High(gItems
) do
4251 if gItems
[i
].Respawnable
then
4253 gItems
[i
].QuietRespawn
:= True;
4254 gItems
[i
].RespawnTime
:= 0;
4259 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
4263 for i
:= Low(gMonsters
) to High(gMonsters
) do
4265 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
4266 gMonsters
[i
].Respawn
;
4269 gLMSSoftSpawn
:= False;
4272 function g_Game_GetFirstMap(WAD
: String): String;
4276 MapList
:= g_Map_GetMapsList(WAD
);
4277 if MapList
= nil then
4280 SortSArray(MapList
);
4281 Result
:= MapList
[Low(MapList
)];
4283 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4289 function g_Game_GetNextMap(): String;
4296 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4297 if MapList
= nil then
4300 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4302 SortSArray(MapList
);
4304 for I
:= Low(MapList
) to High(MapList
) do
4305 if Map
= MapList
[I
] then
4311 if MapIndex
<> -255 then
4313 if MapIndex
= High(MapList
) then
4314 Result
:= MapList
[Low(MapList
)]
4316 Result
:= MapList
[MapIndex
+ 1];
4318 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4324 procedure g_Game_NextLevel();
4326 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4327 gExit
:= EXIT_ENDLEVELCUSTOM
4330 gExit
:= EXIT_ENDLEVELSINGLE
;
4334 if gNextMap
<> '' then Exit
;
4335 gNextMap
:= g_Game_GetNextMap();
4338 function g_Game_IsTestMap(): Boolean;
4340 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4343 procedure g_Game_DeleteTestMap();
4354 a
:= Pos('.wad:\', gMapToDelete
);
4358 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4359 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4360 Delete(gMapToDelete
, 1, a
+ 5);
4361 gMapToDelete
:= UpperCase(gMapToDelete
);
4363 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4366 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4367 if MapName <> TEST_MAP_NAME then
4370 if not gTempDelete then
4372 time := g_GetFileTime(WadName);
4373 WAD := TWADFile.Create();
4376 if not WAD.ReadFile(WadName) then
4377 begin // Íåò òàêîãî WAD-ôàéëà
4382 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4384 MapList := WAD.GetResourcesList('');
4386 if MapList <> nil then
4387 for a := 0 to High(MapList) do
4388 if MapList[a] = MapName then
4390 // Óäàëÿåì è ñîõðàíÿåì:
4391 WAD.RemoveResource('', MapName);
4392 WAD.SaveTo(WadName);
4397 g_SetFileTime(WadName, time);
4400 if gTempDelete
then DeleteFile(WadName
);
4403 procedure GameCVars(P
: SArray
);
4406 stat
: TPlayerStatArray
;
4411 cmd
:= LowerCase(P
[0]);
4412 if cmd
= 'r_showfps' then
4414 if (Length(P
) > 1) and
4415 ((P
[1] = '1') or (P
[1] = '0')) then
4416 gShowFPS
:= (P
[1][1] = '1');
4419 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4421 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4423 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4425 with gGameSettings
do
4427 if (Length(P
) > 1) and
4428 ((P
[1] = '1') or (P
[1] = '0')) then
4430 if (P
[1][1] = '1') then
4431 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4433 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4436 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4437 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4439 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4441 if g_Game_IsNet
then MH_SEND_GameSettings
;
4444 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4446 with gGameSettings
do
4448 if (Length(P
) > 1) and
4449 ((P
[1] = '1') or (P
[1] = '0')) then
4451 if (P
[1][1] = '1') then
4452 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4454 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4457 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4458 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4460 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4462 if g_Game_IsNet
then MH_SEND_GameSettings
;
4465 else if cmd
= 'g_gamemode' then
4467 a
:= g_Game_TextToMode(P
[1]);
4468 if a
= GM_SINGLE
then a
:= GM_COOP
;
4469 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4471 gSwitchGameMode
:= a
;
4472 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4473 (gState
= STATE_INTERSINGLE
) then
4474 gSwitchGameMode
:= GM_SINGLE
;
4476 gGameSettings
.GameMode
:= gSwitchGameMode
;
4478 if gSwitchGameMode
= gGameSettings
.GameMode
then
4479 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4480 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4482 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4483 [g_Game_ModeToText(gGameSettings
.GameMode
),
4484 g_Game_ModeToText(gSwitchGameMode
)]));
4486 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4488 with gGameSettings
do
4490 if (Length(P
) > 1) and
4491 ((P
[1] = '1') or (P
[1] = '0')) then
4493 if (P
[1][1] = '1') then
4494 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4496 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4499 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4500 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4502 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4503 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4505 if g_Game_IsNet
then MH_SEND_GameSettings
;
4508 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4510 with gGameSettings
do
4512 if (Length(P
) > 1) and
4513 ((P
[1] = '1') or (P
[1] = '0')) then
4515 if (P
[1][1] = '1') then
4516 Options
:= Options
or GAME_OPTION_MONSTERS
4518 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4521 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4522 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4524 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4525 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4527 if g_Game_IsNet
then MH_SEND_GameSettings
;
4530 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4532 with gGameSettings
do
4534 if (Length(P
) > 1) and
4535 ((P
[1] = '1') or (P
[1] = '0')) then
4537 if (P
[1][1] = '1') then
4538 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4540 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4543 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4544 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4546 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4548 if g_Game_IsNet
then MH_SEND_GameSettings
;
4551 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4553 with gGameSettings
do
4555 if (Length(P
) > 1) and
4556 ((P
[1] = '1') or (P
[1] = '0')) then
4558 if (P
[1][1] = '1') then
4559 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4561 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4564 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4565 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4567 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4569 if g_Game_IsNet
then MH_SEND_GameSettings
;
4572 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4574 if Length(P
) > 1 then
4576 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4577 gGameSettings
.WarmupTime
:= 30
4579 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4582 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4583 [gGameSettings
.WarmupTime
]));
4584 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4586 else if cmd
= 'net_interp' then
4588 if (Length(P
) > 1) then
4589 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4591 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4592 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4593 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4594 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4597 else if cmd
= 'net_forceplayerupdate' then
4599 if (Length(P
) > 1) and
4600 ((P
[1] = '1') or (P
[1] = '0')) then
4601 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4603 if NetForcePlayerUpdate
then
4604 g_Console_Add('net_forceplayerupdate = 1')
4606 g_Console_Add('net_forceplayerupdate = 0');
4607 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4608 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4609 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4612 else if cmd
= 'net_predictself' then
4614 if (Length(P
) > 1) and
4615 ((P
[1] = '1') or (P
[1] = '0')) then
4616 NetPredictSelf
:= (P
[1][1] = '1');
4618 if NetPredictSelf
then
4619 g_Console_Add('net_predictself = 1')
4621 g_Console_Add('net_predictself = 0');
4622 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4623 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4624 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4627 else if cmd
= 'sv_name' then
4629 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4631 NetServerName
:= P
[1];
4632 if Length(NetServerName
) > 64 then
4633 SetLength(NetServerName
, 64);
4634 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4638 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4640 else if cmd
= 'sv_passwd' then
4642 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4644 NetPassword
:= P
[1];
4645 if Length(NetPassword
) > 24 then
4646 SetLength(NetPassword
, 24);
4647 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4651 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4653 else if cmd
= 'sv_maxplrs' then
4655 if (Length(P
) > 1) then
4657 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4658 if g_Game_IsServer
and g_Game_IsNet
then
4661 for a
:= 0 to High(NetClients
) do
4662 if NetClients
[a
].Used
then
4665 if b
> NetMaxClients
then
4667 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4668 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4669 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4670 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4673 if NetUseMaster
then
4678 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4680 else if cmd
= 'sv_public' then
4682 if (Length(P
) > 1) then
4684 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4685 if g_Game_IsServer
and g_Game_IsNet
then
4686 if NetUseMaster
then
4688 if NetMPeer
= nil then
4689 if not g_Net_Slist_Connect() then
4690 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4691 g_Net_Slist_Update();
4694 if NetMPeer
<> nil then
4695 g_Net_Slist_Disconnect();
4698 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4700 else if cmd
= 'sv_intertime' then
4702 if (Length(P
) > 1) then
4703 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4705 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4707 else if cmd
= 'p1_name' then
4709 if (Length(P
) > 1) and gGameOn
then
4711 if g_Game_IsClient
then
4713 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4714 MC_SEND_PlayerSettings
;
4717 if gPlayer1
<> nil then
4719 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4720 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4723 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4726 else if cmd
= 'p2_name' then
4728 if (Length(P
) > 1) and gGameOn
then
4730 if g_Game_IsClient
then
4732 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4733 MC_SEND_PlayerSettings
;
4736 if gPlayer2
<> nil then
4738 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4739 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4742 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4745 else if cmd
= 'p1_color' then
4747 if Length(P
) > 3 then
4748 if g_Game_IsClient
then
4750 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4751 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4752 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4753 MC_SEND_PlayerSettings
;
4756 if gPlayer1
<> nil then
4758 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4759 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4760 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4761 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4764 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4765 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4766 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4768 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4770 if Length(P
) > 3 then
4771 if g_Game_IsClient
then
4773 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4774 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4775 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4776 MC_SEND_PlayerSettings
;
4779 if gPlayer2
<> nil then
4781 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4782 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4783 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4784 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4787 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4788 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4789 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4791 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4793 if cmd
= 'r_showtime' then
4795 if (Length(P
) > 1) and
4796 ((P
[1] = '1') or (P
[1] = '0')) then
4797 gShowTime
:= (P
[1][1] = '1');
4800 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4802 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4804 else if cmd
= 'r_showscore' then
4806 if (Length(P
) > 1) and
4807 ((P
[1] = '1') or (P
[1] = '0')) then
4808 gShowGoals
:= (P
[1][1] = '1');
4811 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4813 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4815 else if cmd
= 'r_showstat' then
4817 if (Length(P
) > 1) and
4818 ((P
[1] = '1') or (P
[1] = '0')) then
4819 gShowStat
:= (P
[1][1] = '1');
4822 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4824 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4826 else if cmd
= 'r_showkillmsg' then
4828 if (Length(P
) > 1) and
4829 ((P
[1] = '1') or (P
[1] = '0')) then
4830 gShowKillMsg
:= (P
[1][1] = '1');
4832 if gShowKillMsg
then
4833 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4835 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4837 else if cmd
= 'r_showlives' then
4839 if (Length(P
) > 1) and
4840 ((P
[1] = '1') or (P
[1] = '0')) then
4841 gShowLives
:= (P
[1][1] = '1');
4844 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4846 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4848 else if cmd
= 'r_showspect' then
4850 if (Length(P
) > 1) and
4851 ((P
[1] = '1') or (P
[1] = '0')) then
4852 gSpectHUD
:= (P
[1][1] = '1');
4855 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4857 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4859 else if cmd
= 'r_showping' then
4861 if (Length(P
) > 1) and
4862 ((P
[1] = '1') or (P
[1] = '0')) then
4863 gShowPing
:= (P
[1][1] = '1');
4866 g_Console_Add(_lc
[I_MSG_PING_ON
])
4868 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4870 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4872 if Length(P
) > 1 then
4874 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4875 gGameSettings
.GoalLimit
:= 0
4880 if gGameSettings
.GameMode
= GM_DM
then
4882 stat
:= g_Player_GetStats();
4884 for a
:= 0 to High(stat
) do
4885 if stat
[a
].Frags
> b
then
4889 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4891 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4894 if g_Game_IsNet
then MH_SEND_GameSettings
;
4897 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4899 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4901 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4902 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4904 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4905 [gGameSettings
.TimeLimit
div 3600,
4906 (gGameSettings
.TimeLimit
div 60) mod 60,
4907 gGameSettings
.TimeLimit
mod 60]));
4908 if g_Game_IsNet
then MH_SEND_GameSettings
;
4910 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4912 if Length(P
) > 1 then
4914 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4915 gGameSettings
.MaxLives
:= 0
4919 stat
:= g_Player_GetStats();
4921 for a
:= 0 to High(stat
) do
4922 if stat
[a
].Lives
> b
then
4924 gGameSettings
.MaxLives
:=
4925 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4929 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4930 [gGameSettings
.MaxLives
]));
4931 if g_Game_IsNet
then MH_SEND_GameSettings
;
4936 // profiler console commands
4937 procedure ProfilerCommands (P
: SArray
);
4941 //if not gDebugMode then exit;
4942 cmd
:= LowerCase(P
[0]);
4945 g_profile_frame_draw
:= not g_profile_frame_draw
;
4950 g_profile_frame_update
:= not g_profile_frame_update
;
4955 procedure DebugCommands(P
: SArray
);
4961 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4964 cmd
:= LowerCase(P
[0]);
4965 if cmd
= 'd_window' then
4967 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4968 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4969 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4970 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4971 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4973 else if cmd
= 'd_sounds' then
4975 if (Length(P
) > 1) and
4976 ((P
[1] = '1') or (P
[1] = '0')) then
4977 g_Debug_Sounds
:= (P
[1][1] = '1');
4979 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4981 else if cmd
= 'd_frames' then
4983 if (Length(P
) > 1) and
4984 ((P
[1] = '1') or (P
[1] = '0')) then
4985 g_Debug_Frames
:= (P
[1][1] = '1');
4987 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4989 else if cmd
= 'd_winmsg' then
4991 if (Length(P
) > 1) and
4992 ((P
[1] = '1') or (P
[1] = '0')) then
4993 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4995 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4997 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4999 if (Length(P
) > 1) and
5000 ((P
[1] = '1') or (P
[1] = '0')) then
5001 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5003 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5005 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5007 if Length(P
) > 1 then
5009 '0': g_debug_BotAIOff
:= 0;
5010 '1': g_debug_BotAIOff
:= 1;
5011 '2': g_debug_BotAIOff
:= 2;
5012 '3': g_debug_BotAIOff
:= 3;
5015 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5017 else if cmd
= 'd_monster' then
5019 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
5020 if Length(P
) < 2 then
5022 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5023 g_Console_Add('ID | Name');
5024 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5025 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
5028 a
:= StrToIntDef(P
[1], 0);
5029 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5030 a
:= g_Monsters_GetIDByName(P
[1]);
5032 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5033 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5036 with gPlayer1
.Obj
do
5037 b
:= g_Monsters_Create(a
,
5038 X
+ Rect
.X
+ (Rect
.Width
div 2),
5039 Y
+ Rect
.Y
+ Rect
.Height
,
5040 gPlayer1
.Direction
, True);
5041 if (Length(P
) > 2) and (b
>= 0) then
5042 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5046 else if (cmd
= 'd_health') then
5048 if (Length(P
) > 1) and
5049 ((P
[1] = '1') or (P
[1] = '0')) then
5050 g_debug_HealthBar
:= (P
[1][1] = '1');
5052 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5054 else if (cmd
= 'd_player') then
5056 if (Length(P
) > 1) and
5057 ((P
[1] = '1') or (P
[1] = '0')) then
5058 g_debug_Player
:= (P
[1][1] = '1');
5060 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5062 else if (cmd
= 'd_joy') then
5065 g_Console_Add(e_JoystickStateToString(a
));
5069 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5073 procedure GameCheats(P
: SArray
);
5079 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
5080 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
5082 g_Console_Add('not available');
5088 g_Console_Add('where is the player?!');
5091 cmd
:= LowerCase(P
[0]);
5095 plr
.GodMode
:= not plr
.GodMode
;
5096 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5099 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5100 if cmd
= 'give' then
5102 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5103 for f
:= 1 to High(P
) do
5105 cmd
:= LowerCase(P
[f
]);
5106 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5107 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5108 if cmd
= 'exit' then
5110 if gTriggers
<> nil then
5112 for a
:= 0 to High(gTriggers
) do
5114 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5116 g_Console_Add('player left the map');
5117 gExitByTrigger
:= True;
5118 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
5126 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5127 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5128 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5129 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5130 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5132 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5133 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5135 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5136 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;
5138 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5139 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5141 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5142 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5144 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5145 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5147 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5148 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5149 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5151 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5152 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5153 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5154 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;
5155 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5156 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5158 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;
5159 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;
5160 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;
5161 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;
5162 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;
5163 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;
5165 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5166 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;
5168 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;
5169 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;
5171 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5173 if cmd
= 'ammo' then
5175 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5176 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5177 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5178 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5179 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5180 g_Console_Add('player got some ammo');
5184 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5185 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5187 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5188 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5190 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5191 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5193 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5194 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5196 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5198 if cmd
= 'weapons' then
5200 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5201 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5202 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5203 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5204 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5205 plr
.GiveItem(ITEM_WEAPON_BFG
);
5206 g_Console_Add('player got weapons');
5210 if cmd
= 'keys' then
5212 plr
.GiveItem(ITEM_KEY_RED
);
5213 plr
.GiveItem(ITEM_KEY_GREEN
);
5214 plr
.GiveItem(ITEM_KEY_BLUE
);
5215 g_Console_Add('player got all keys');
5219 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5224 if cmd
= 'open' then
5226 g_Console_Add('player activated sesame');
5227 g_Triggers_OpenAll();
5234 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5238 if cmd
= 'noclip' then
5241 g_Console_Add('wall hardeness adjusted');
5245 if cmd
= 'notarget' then
5247 plr
.NoTarget
:= not plr
.NoTarget
;
5248 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5252 if cmd
= 'noreload' then
5254 plr
.NoReload
:= not plr
.NoReload
;
5255 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5259 if cmd
= 'speedy' then
5261 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5262 g_Console_Add('speed adjusted');
5266 if cmd
= 'jumpy' then
5268 VEL_JUMP
:= 30-VEL_JUMP
;
5269 g_Console_Add('jump height adjusted');
5273 if cmd
= 'automap' then
5275 gShowMap
:= not gShowMap
;
5276 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5280 if cmd
= 'aimline' then
5282 gAimLine
:= not gAimLine
;
5283 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5288 procedure GameCommands(P
: SArray
);
5294 pl
: pTNetClient
= nil;
5301 cmd
:= LowerCase(P
[0]);
5303 if (cmd
= 'quit') or
5310 else if cmd
= 'pause' then
5312 if (g_ActiveWindow
= nil) then
5313 g_Game_Pause(not gPause
);
5315 else if cmd
= 'endgame' then
5316 gExit
:= EXIT_SIMPLE
5317 else if cmd
= 'restart' then
5319 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5321 if g_Game_IsClient
then
5323 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5328 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5330 else if cmd
= 'kick' then
5332 if g_Game_IsServer
then
5334 if Length(P
) < 2 then
5336 g_Console_Add('kick <name>');
5341 g_Console_Add('kick <name>');
5345 if g_Game_IsNet
then
5346 pl
:= g_Net_Client_ByName(P
[1]);
5349 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5350 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5351 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5352 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5353 if NetUseMaster
then
5355 end else if gPlayers
<> nil then
5356 for a
:= Low(gPlayers
) to High(gPlayers
) do
5357 if gPlayers
[a
] <> nil then
5358 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5360 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5361 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5363 gPlayers
[a
].Lives
:= 0;
5364 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5365 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5366 g_Player_Remove(gPlayers
[a
].UID
);
5367 if NetUseMaster
then
5369 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5373 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5375 else if cmd
= 'kick_id' then
5377 if g_Game_IsServer
and g_Game_IsNet
then
5379 if Length(P
) < 2 then
5381 g_Console_Add('kick_id <client ID>');
5386 g_Console_Add('kick_id <client ID>');
5390 a
:= StrToIntDef(P
[1], 0);
5391 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5393 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5395 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5396 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5397 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5398 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5399 if NetUseMaster
then
5404 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5406 else if cmd
= 'ban' then
5408 if g_Game_IsServer
and g_Game_IsNet
then
5410 if Length(P
) < 2 then
5412 g_Console_Add('ban <name>');
5417 g_Console_Add('ban <name>');
5421 pl
:= g_Net_Client_ByName(P
[1]);
5424 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5425 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5426 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5427 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5428 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5429 if NetUseMaster
then
5432 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5434 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5436 else if cmd
= 'ban_id' then
5438 if g_Game_IsServer
and g_Game_IsNet
then
5440 if Length(P
) < 2 then
5442 g_Console_Add('ban_id <client ID>');
5447 g_Console_Add('ban_id <client ID>');
5451 a
:= StrToIntDef(P
[1], 0);
5452 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5453 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5455 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5456 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5457 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5458 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5459 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5460 if NetUseMaster
then
5464 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5466 else if cmd
= 'permban' then
5468 if g_Game_IsServer
and g_Game_IsNet
then
5470 if Length(P
) < 2 then
5472 g_Console_Add('permban <name>');
5477 g_Console_Add('permban <name>');
5481 pl
:= g_Net_Client_ByName(P
[1]);
5484 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5485 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5486 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5487 g_Net_SaveBanList();
5488 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5489 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5490 if NetUseMaster
then
5493 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5495 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5497 else if cmd
= 'permban_id' then
5499 if g_Game_IsServer
and g_Game_IsNet
then
5501 if Length(P
) < 2 then
5503 g_Console_Add('permban_id <client ID>');
5508 g_Console_Add('permban_id <client ID>');
5512 a
:= StrToIntDef(P
[1], 0);
5513 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5514 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5516 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5517 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5518 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5519 g_Net_SaveBanList();
5520 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5521 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5522 if NetUseMaster
then
5526 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5528 else if cmd
= 'unban' then
5530 if g_Game_IsServer
and g_Game_IsNet
then
5532 if Length(P
) < 2 then
5534 g_Console_Add('unban <IP Address>');
5539 g_Console_Add('unban <IP Address>');
5543 if g_Net_UnbanHost(P
[1]) then
5545 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5546 g_Net_SaveBanList();
5548 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5550 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5552 else if cmd
= 'clientlist' then
5554 if g_Game_IsServer
and g_Game_IsNet
then
5557 if NetClients
<> nil then
5558 for a
:= Low(NetClients
) to High(NetClients
) do
5559 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5561 plr
:= g_Player_Get(NetClients
[a
].Player
);
5562 if plr
= nil then continue
;
5564 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5565 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5568 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5570 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5572 else if cmd
= 'connect' then
5574 if (NetMode
= NET_NONE
) then
5576 if Length(P
) < 2 then
5578 g_Console_Add('connect <IP> [port] [password]');
5583 g_Console_Add('connect <IP> [port] [password]');
5587 if Length(P
) > 2 then
5588 prt
:= StrToIntDef(P
[2], 25666)
5592 if Length(P
) > 3 then
5597 g_Game_StartClient(P
[1], prt
, pw
);
5600 else if cmd
= 'disconnect' then
5602 if (NetMode
= NET_CLIENT
) then
5605 else if cmd
= 'reconnect' then
5607 if (NetMode
= NET_SERVER
) then
5610 if (NetMode
= NET_CLIENT
) then
5613 gExit
:= EXIT_SIMPLE
;
5617 //TODO: Use last successful password to reconnect, instead of ''
5618 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5620 else if (cmd
= 'addbot') or
5621 (cmd
= 'bot_add') then
5623 if Length(P
) > 1 then
5624 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5626 g_Bot_Add(TEAM_NONE
, 2);
5628 else if cmd
= 'bot_addlist' then
5630 if Length(P
) > 1 then
5631 if Length(P
) = 2 then
5632 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5634 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5636 else if cmd
= 'bot_removeall' then
5638 else if cmd
= 'chat' then
5640 if g_Game_IsNet
then
5642 if Length(P
) > 1 then
5644 for a
:= 1 to High(P
) do
5645 chstr
:= chstr
+ P
[a
] + ' ';
5647 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5649 if Length(chstr
) < 1 then
5651 g_Console_Add('chat <text>');
5655 chstr
:= b_Text_Format(chstr
);
5656 if g_Game_IsClient
then
5657 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5659 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5662 g_Console_Add('chat <text>');
5664 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5666 else if cmd
= 'teamchat' then
5668 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5670 if Length(P
) > 1 then
5672 for a
:= 1 to High(P
) do
5673 chstr
:= chstr
+ P
[a
] + ' ';
5675 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5677 if Length(chstr
) < 1 then
5679 g_Console_Add('teamchat <text>');
5683 chstr
:= b_Text_Format(chstr
);
5684 if g_Game_IsClient
then
5685 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5687 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5688 gPlayer1Settings
.Team
);
5691 g_Console_Add('teamchat <text>');
5693 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5695 else if cmd
= 'game' then
5697 if gGameSettings
.GameType
<> GT_NONE
then
5699 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5702 if Length(P
) = 1 then
5704 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5707 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5708 P
[1] := addWadExtension(P
[1]);
5709 if FileExists(MapsDir
+ P
[1]) then
5711 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5712 if Length(P
) < 3 then
5715 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5718 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5720 if g_Map_Exist(MapsDir
+ s
) then
5722 // Çàïóñêàåì ñâîþ èãðó
5724 with gGameSettings
do
5726 GameMode
:= g_Game_TextToMode(gcGameMode
);
5727 if gSwitchGameMode
<> GM_NONE
then
5728 GameMode
:= gSwitchGameMode
;
5729 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5730 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5732 if Length(P
) >= 4 then
5733 b
:= StrToIntDef(P
[3], 1);
5734 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5735 GoalLimit
, MaxLives
, Options
, b
);
5740 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5742 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5744 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5746 else if cmd
= 'host' then
5748 if gGameSettings
.GameType
<> GT_NONE
then
5750 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5753 if Length(P
) < 4 then
5755 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5758 if not StrToIp(P
[1], listen
) then
5760 prt
:= StrToIntDef(P
[2], 25666);
5762 P
[3] := addWadExtension(P
[3]);
5763 if FileExists(MapsDir
+ P
[3]) then
5765 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5766 if Length(P
) < 5 then
5769 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5772 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5774 if g_Map_Exist(MapsDir
+ s
) then
5776 // Çàïóñêàåì ñâîþ èãðó
5778 with gGameSettings
do
5780 GameMode
:= g_Game_TextToMode(gcGameMode
);
5781 if gSwitchGameMode
<> GM_NONE
then
5782 GameMode
:= gSwitchGameMode
;
5783 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5784 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5786 if Length(P
) >= 6 then
5787 b
:= StrToIntDef(P
[5], 0);
5788 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5789 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5794 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5796 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5798 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5800 else if cmd
= 'map' then
5802 if Length(P
) = 1 then
5804 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5806 g_Console_Add(cmd
+ ' <MAP>');
5807 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5809 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5811 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5813 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5814 if Length(P
) < 3 then
5816 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5817 s
:= UpperCase(P
[1]);
5818 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5819 begin // Êàðòà íàøëàñü
5820 gExitByTrigger
:= False;
5822 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5824 gExit
:= EXIT_ENDLEVELCUSTOM
;
5826 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5827 g_Game_ChangeMap(s
);
5830 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5831 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5832 P
[1] := addWadExtension(P
[1]);
5833 if FileExists(MapsDir
+ P
[1]) then
5835 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5837 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5839 s
:= P
[1] + ':\' + P
[2];
5841 if g_Map_Exist(MapsDir
+ s
) then
5843 gExitByTrigger
:= False;
5845 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5847 gExit
:= EXIT_ENDLEVELCUSTOM
;
5849 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5850 g_Game_ChangeMap(s
);
5853 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5855 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5857 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5861 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5862 P
[1] := addWadExtension(P
[1]);
5863 if FileExists(MapsDir
+ P
[1]) then
5866 P
[2] := UpperCase(P
[2]);
5867 s
:= P
[1] + ':\' + P
[2];
5869 if g_Map_Exist(MapsDir
+ s
) then
5870 begin // Íàøëè êàðòó
5871 gExitByTrigger
:= False;
5873 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5875 gExit
:= EXIT_ENDLEVELCUSTOM
;
5877 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5878 g_Game_ChangeMap(s
);
5880 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5882 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5885 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5887 else if cmd
= 'nextmap' then
5889 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5890 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5893 if Length(P
) = 1 then
5895 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5897 g_Console_Add(cmd
+ ' <MAP>');
5898 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5901 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5906 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5908 if Length(P
) < 3 then
5910 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5911 s
:= UpperCase(P
[1]);
5912 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5913 begin // Êàðòà íàøëàñü
5914 gExitByTrigger
:= False;
5919 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5920 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5921 P
[1] := addWadExtension(P
[1]);
5922 if FileExists(MapsDir
+ P
[1]) then
5924 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5926 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5928 s
:= P
[1] + ':\' + P
[2];
5930 if g_Map_Exist(MapsDir
+ s
) then
5931 begin // Óñòàíàâëèâàåì êàðòó
5932 gExitByTrigger
:= False;
5937 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5939 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5941 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5945 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5946 P
[1] := addWadExtension(P
[1]);
5947 if FileExists(MapsDir
+ P
[1]) then
5950 P
[2] := UpperCase(P
[2]);
5951 s
:= P
[1] + ':\' + P
[2];
5953 if g_Map_Exist(MapsDir
+ s
) then
5954 begin // Íàøëè êàðòó
5955 gExitByTrigger
:= False;
5959 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5961 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5964 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5967 if gNextMap
= '' then
5968 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5970 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5973 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5976 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5978 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5980 gExitByTrigger
:= False;
5981 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5982 if (gNextMap
= '') and (gTriggers
<> nil) then
5983 for a
:= 0 to High(gTriggers
) do
5984 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5986 gExitByTrigger
:= True;
5987 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5990 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5991 if gNextMap
= '' then
5992 gNextMap
:= g_Game_GetNextMap();
5993 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5994 if Pos(':\', gNextMap
) = 0 then
5995 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5998 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5999 if g_Map_Exist(MapsDir
+ s
) then
6000 gExit
:= EXIT_ENDLEVELCUSTOM
6002 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6004 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6006 else if (cmd
= 'event') then
6008 if (Length(P
) <= 1) then
6010 for a
:= 0 to High(gEvents
) do
6011 if gEvents
[a
].Command
= '' then
6012 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6014 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6017 if (Length(P
) = 2) then
6019 for a
:= 0 to High(gEvents
) do
6020 if gEvents
[a
].Name
= P
[1] then
6021 if gEvents
[a
].Command
= '' then
6022 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6024 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6027 for a
:= 0 to High(gEvents
) do
6028 if gEvents
[a
].Name
= P
[1] then
6030 gEvents
[a
].Command
:= '';
6031 for b
:= 2 to High(P
) do
6032 if Pos(' ', P
[b
]) = 0 then
6033 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6035 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6036 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6040 // Êîìàíäû Ñâîåé èãðû:
6041 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6043 if cmd
= 'bot_addred' then
6045 if Length(P
) > 1 then
6046 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6048 g_Bot_Add(TEAM_RED
, 2);
6050 else if cmd
= 'bot_addblue' then
6052 if Length(P
) > 1 then
6053 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6055 g_Bot_Add(TEAM_BLUE
, 2);
6057 else if cmd
= 'suicide' then
6061 if g_Game_IsClient
then
6062 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6065 if gPlayer1
<> nil then
6066 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6067 if gPlayer2
<> nil then
6068 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6072 else if cmd
= 'spectate' then
6078 else if cmd
= 'say' then
6080 if g_Game_IsServer
and g_Game_IsNet
then
6082 if Length(P
) > 1 then
6085 for a
:= 1 to High(P
) do
6086 chstr
:= chstr
+ P
[a
] + ' ';
6088 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6090 if Length(chstr
) < 1 then
6092 g_Console_Add('say <text>');
6096 chstr
:= b_Text_Format(chstr
);
6097 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6099 else g_Console_Add('say <text>');
6101 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6103 else if cmd
= 'tell' then
6105 if g_Game_IsServer
and g_Game_IsNet
then
6107 if (Length(P
) > 2) and (P
[1] <> '') then
6110 for a
:= 2 to High(P
) do
6111 chstr
:= chstr
+ P
[a
] + ' ';
6113 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6115 if Length(chstr
) < 1 then
6117 g_Console_Add('tell <playername> <text>');
6121 pl
:= g_Net_Client_ByName(P
[1]);
6123 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6125 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6127 else g_Console_Add('tell <playername> <text>');
6129 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6131 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6133 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6135 // Äîïîëíèòåëüíîå âðåìÿ:
6136 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6138 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6139 [gGameSettings
.TimeLimit
div 3600,
6140 (gGameSettings
.TimeLimit
div 60) mod 60,
6141 gGameSettings
.TimeLimit
mod 60]));
6142 if g_Game_IsNet
then MH_SEND_GameSettings
;
6144 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6146 if (Length(P
) <= 1) then
6147 g_Console_Add('rcon_password <password>')
6149 MC_SEND_RCONPassword(P
[1]);
6151 else if cmd
= 'rcon' then
6153 if g_Game_IsClient
then
6155 if Length(P
) > 1 then
6158 for a
:= 1 to High(P
) do
6159 chstr
:= chstr
+ P
[a
] + ' ';
6161 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6163 if Length(chstr
) < 1 then
6165 g_Console_Add('rcon <command>');
6169 MC_SEND_RCONCommand(chstr
);
6171 else g_Console_Add('rcon <command>');
6174 else if cmd
= 'ready' then
6176 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6177 gLMSRespawnTime
:= gTime
+ 100;
6179 else if (cmd
= 'callvote') and g_Game_IsNet
then
6181 if Length(P
) > 1 then
6184 for a
:= 1 to High(P
) do begin
6185 if a
> 1 then chstr
:= chstr
+ ' ';
6186 chstr
:= chstr
+ P
[a
];
6189 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6191 if Length(chstr
) < 1 then
6193 g_Console_Add('callvote <command>');
6197 if g_Game_IsClient
then
6198 MC_SEND_Vote(True, chstr
)
6200 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6201 g_Console_Process('vote', True);
6204 g_Console_Add('callvote <command>');
6206 else if (cmd
= 'vote') and g_Game_IsNet
then
6208 if g_Game_IsClient
then
6210 else if gVoteInProgress
then
6212 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6213 a
:= Floor((NetClientCount
+1)/2.0) + 1
6215 a
:= Floor(NetClientCount
/2.0) + 1;
6220 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6221 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6227 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6228 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6236 procedure g_TakeScreenShot();
6244 if e_NoGraphics
then Exit
;
6245 ssdir
:= GameDir
+'/screenshots';
6246 if not findFileCI(ssdir
, true) then
6248 // try to create dir
6253 if not findFileCI(ssdir
, true) then exit
; // alas
6256 for a
:= 1 to High(Word) do
6258 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6260 if findFileCI(t
, true) then continue
;
6261 if not findFileCI(FileName
) then
6264 st
:= createDiskFile(FileName
);
6266 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6271 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6279 procedure g_Game_InGameMenu(Show
: Boolean);
6281 if (g_ActiveWindow
= nil) and Show
then
6283 if gGameSettings
.GameType
= GT_SINGLE
then
6284 g_GUI_ShowWindow('GameSingleMenu')
6287 if g_Game_IsClient
then
6288 g_GUI_ShowWindow('GameClientMenu')
6290 if g_Game_IsNet
then
6291 g_GUI_ShowWindow('GameServerMenu')
6293 g_GUI_ShowWindow('GameCustomMenu');
6295 g_Sound_PlayEx('MENU_OPEN');
6297 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6298 if (not g_Game_IsNet
) then
6302 if (g_ActiveWindow
<> nil) and (not Show
) then
6304 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6305 if (not g_Game_IsNet
) then
6306 g_Game_Pause(False);
6310 procedure g_Game_Pause(Enable
: Boolean);
6315 if gPause
= Enable
then
6318 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6322 g_Game_PauseAllSounds(Enable
);
6325 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6330 if gTriggers
<> nil then
6331 for i
:= 0 to High(gTriggers
) do
6332 with gTriggers
[i
] do
6333 if (TriggerType
= TRIGGER_SOUND
) and
6335 Sound
.IsPlaying() then
6337 Sound
.Pause(Enable
);
6341 if gPlayers
<> nil then
6342 for i
:= 0 to High(gPlayers
) do
6343 if gPlayers
[i
] <> nil then
6344 gPlayers
[i
].PauseSounds(Enable
);
6347 if gMusic
<> nil then
6348 gMusic
.Pause(Enable
);
6351 procedure g_Game_StopAllSounds(all
: Boolean);
6355 if gTriggers
<> nil then
6356 for i
:= 0 to High(gTriggers
) do
6357 with gTriggers
[i
] do
6358 if (TriggerType
= TRIGGER_SOUND
) and
6362 if gMusic
<> nil then
6369 procedure g_Game_UpdateTriggerSounds();
6373 if gTriggers
<> nil then
6374 for i
:= 0 to High(gTriggers
) do
6375 with gTriggers
[i
] do
6376 if (TriggerType
= TRIGGER_SOUND
) and
6379 Sound
.IsPlaying() then
6381 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6382 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6384 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6385 Sound
.SetVolume(Data
.Volume
/255.0);
6388 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6392 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6395 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6400 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6405 if gSpectMode
<> SPECT_PLAYERS
then
6407 if gSpectPID1
= UID
then
6412 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6419 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6424 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6429 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6434 if gSpectMode
<> SPECT_PLAYERS
then
6436 Pl
:= g_Player_Get(gSpectPID1
);
6437 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6442 if gSpectViewTwo
then
6444 Pl
:= g_Player_Get(gSpectPID2
);
6445 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6453 procedure g_Game_Message(Msg
: string; Time
: Word);
6455 MessageText
:= b_Text_Format(Msg
);
6456 MessageTime
:= Time
;
6459 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6468 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6472 if goodsnd
[a
].IsPlaying() then
6475 goodsnd
[Random(4)].Play();
6478 procedure g_Game_Announce_KillCombo(Param
: Integer);
6485 UID
:= Param
and $FFFF;
6490 Pl
:= g_Player_Get(UID
);
6499 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6503 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6507 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6511 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6519 if not g_Game_IsWatchedPlayer(UID
) then
6522 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6526 if killsnd
[n
].IsPlaying() then
6531 procedure g_Game_StartVote(Command
, Initiator
: string);
6535 if not gVotesEnabled
then Exit
;
6536 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6537 if gVoteInProgress
or gVotePassed
then
6539 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6540 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6543 gVoteInProgress
:= True;
6544 gVotePassed
:= False;
6545 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6548 gVoteCommand
:= Command
;
6550 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6551 Need
:= Floor((NetClientCount
+1)/2.0)+1
6553 Need
:= Floor(NetClientCount
/2.0)+1;
6554 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6555 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6558 procedure g_Game_CheckVote
;
6562 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6563 if not gVoteInProgress
then Exit
;
6565 if (gTime
>= gVoteTimer
) then
6567 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6568 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6570 Need
:= Floor(NetClientCount
/2.0) + 1;
6571 if gVoteCount
>= Need
then
6573 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6574 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6575 gVotePassed
:= True;
6576 gVoteCmdTimer
:= gTime
+ 5000;
6580 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6581 MH_SEND_VoteEvent(NET_VE_FAILED
);
6583 if NetClients
<> nil then
6584 for I
:= Low(NetClients
) to High(NetClients
) do
6585 if NetClients
[i
].Used
then
6586 NetClients
[i
].Voted
:= False;
6587 gVoteInProgress
:= False;
6593 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6594 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6596 Need
:= Floor(NetClientCount
/2.0) + 1;
6597 if gVoteCount
>= Need
then
6599 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6600 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6601 gVoteInProgress
:= False;
6602 gVotePassed
:= True;
6603 gVoteCmdTimer
:= gTime
+ 5000;
6606 if NetClients
<> nil then
6607 for I
:= Low(NetClients
) to High(NetClients
) do
6608 if NetClients
[i
].Used
then
6609 NetClients
[i
].Voted
:= False;
6614 procedure g_Game_LoadMapList(FileName
: string);
6622 if not FileExists(FileName
) then Exit
;
6624 AssignFile(ListFile
, FileName
);
6626 while not EOF(ListFile
) do
6628 ReadLn(ListFile
, s
);
6631 if s
= '' then Continue
;
6633 SetLength(MapList
, Length(MapList
)+1);
6634 MapList
[High(MapList
)] := s
;
6636 CloseFile(ListFile
);
6639 procedure g_Game_SetDebugMode();
6642 // ×èòû (äàæå â ñâîåé èãðå):
6646 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6650 if Length(LoadingStat
.Msgs
) = 0 then
6656 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6657 if NextMsg
= Length(Msgs
) then
6659 for i
:= 0 to High(Msgs
)-1 do
6660 Msgs
[i
] := Msgs
[i
+1];
6668 Msgs
[NextMsg
-1] := Text;
6674 g_ActiveWindow
:= nil;
6679 procedure g_Game_StepLoading();
6685 if (ShowCount
> LOADING_SHOW_STEP
) then
6693 procedure g_Game_ClearLoading();
6702 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6703 if len
< 1 then len
:= 1;
6704 SetLength(Msgs
, len
);
6705 for len
:= Low(Msgs
) to High(Msgs
) do
6711 procedure Parse_Params(var pars
: TParamStrValues
);
6718 while i
<= ParamCount
do
6721 if (s
[1] = '-') and (Length(s
) > 1) then
6723 if (s
[2] = '-') and (Length(s
) > 2) then
6724 begin // Îäèíî÷íûé ïàðàìåòð
6725 SetLength(pars
, Length(pars
) + 1);
6726 with pars
[High(pars
)] do
6728 Name
:= LowerCase(s
);
6733 if (i
< ParamCount
) then
6734 begin // Ïàðàìåòð ñî çíà÷åíèåì
6736 SetLength(pars
, Length(pars
) + 1);
6737 with pars
[High(pars
)] do
6739 Name
:= LowerCase(s
);
6740 Value
:= LowerCase(ParamStr(i
));
6749 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6754 for i
:= 0 to High(pars
) do
6755 if pars
[i
].Name
= aName
then
6757 Result
:= pars
[i
].Value
;
6762 procedure g_Game_Process_Params();
6764 pars
: TParamStrValues
;
6767 LimT
, LimS
: Integer;
6778 s
:= Find_Param_Value(pars
, '--debug');
6781 g_Game_SetDebugMode();
6782 s
:= Find_Param_Value(pars
, '--netdump');
6787 // Connect when game loads
6788 ip
:= Find_Param_Value(pars
, '-connect');
6792 s
:= Find_Param_Value(pars
, '-port');
6793 if (s
= '') or not TryStrToInt(s
, Port
) then
6796 s
:= Find_Param_Value(pars
, '-pw');
6798 g_Game_StartClient(ip
, Port
, s
);
6802 // Start map when game loads:
6803 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6804 if isWadPath(map
) then
6807 s
:= Find_Param_Value(pars
, '-gm');
6808 GMode
:= g_Game_TextToMode(s
);
6809 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6810 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6813 s
:= Find_Param_Value(pars
, '-limt');
6814 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6820 s
:= Find_Param_Value(pars
, '-lims');
6821 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6827 s
:= Find_Param_Value(pars
, '-lives');
6828 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6834 s
:= Find_Param_Value(pars
, '-opt');
6836 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6838 Opt
:= StrToIntDef(s
, 0);
6840 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6843 s
:= Find_Param_Value(pars
, '--close');
6847 // Delete test map after play:
6848 s
:= Find_Param_Value(pars
, '--testdelete');
6851 gMapToDelete
:= MapsDir
+ map
;
6852 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6856 // Delete temporary WAD after play:
6857 s
:= Find_Param_Value(pars
, '--tempdelete');
6860 gMapToDelete
:= MapsDir
+ map
;
6861 gTempDelete
:= True;
6864 // Number of players:
6865 s
:= Find_Param_Value(pars
, '-pl');
6869 n
:= StrToIntDef(s
, 1);
6872 s
:= Find_Param_Value(pars
, '-port');
6873 if (s
= '') or not TryStrToInt(s
, Port
) then
6874 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6876 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6879 // Execute script when game loads:
6880 s
:= Find_Param_Value(pars
, '-exec');
6883 if Pos(':\', s
) = 0 then
6884 s
:= GameDir
+ '/' + s
;
6889 if IOResult
<> 0 then
6891 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6892 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6896 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6897 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6902 if IOResult
<> 0 then
6904 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6905 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6909 if Pos('#', s
) <> 1 then // script comment
6910 g_Console_Process(s
, True);