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/>.
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, wadreader
, md5
;
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 g_Game_Process_Params
;
128 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
129 procedure g_Game_StepLoading();
130 procedure g_Game_ClearLoading();
131 procedure g_Game_SetDebugMode();
132 procedure DrawLoadingStat();
134 { procedure SetWinPause(Enable: Boolean); }
139 LOADING_SHOW_STEP
= 100;
140 LOADING_INTERLINE
= 20;
155 MESSAGE_DIKEY
= WM_USER
+ 1;
160 EXIT_ENDLEVELSINGLE
= 4;
161 EXIT_ENDLEVELCUSTOM
= 5;
163 GAME_OPTION_RESERVED
= 1;
164 GAME_OPTION_TEAMDAMAGE
= 2;
165 GAME_OPTION_ALLOWEXIT
= 4;
166 GAME_OPTION_WEAPONSTAY
= 8;
167 GAME_OPTION_MONSTERS
= 16;
168 GAME_OPTION_BOTVSPLAYER
= 32;
169 GAME_OPTION_BOTVSMONSTER
= 64;
174 STATE_INTERCUSTOM
= 3;
175 STATE_INTERSINGLE
= 4;
181 LMS_RESPAWN_NONE
= 0;
182 LMS_RESPAWN_WARMUP
= 1;
183 LMS_RESPAWN_FINAL
= 2;
199 CONFIG_FILENAME
= 'Doom2DF.cfg';
200 LOG_FILENAME
= 'Doom2DF.log';
202 TEST_MAP_NAME
= '$$$_TEST_$$$';
204 STD_PLAYER_MODEL
= 'Doomer';
208 gGameSettings
: TGameSettings
;
209 gPlayer1Settings
: TPlayerSettings
;
210 gPlayer2Settings
: TPlayerSettings
;
212 gPlayerScreenSize
: TPoint
;
213 gPlayer1ScreenCoord
: TPoint
;
214 gPlayer2ScreenCoord
: TPoint
;
215 gPlayer1
: TPlayer
= nil;
216 gPlayer2
: TPlayer
= nil;
217 gPlayerDrawn
: TPlayer
= nil;
219 gSwitchGameMode
: Byte = GM_DM
;
220 gHearPoint1
, gHearPoint2
: THearPoint
;
221 gSoundEffectsDF
: Boolean = False;
222 gSoundTriggerTime
: Word = 0;
223 gAnnouncer
: Byte = ANNOUNCE_NONE
;
224 goodsnd
: array[0..3] of TPlayableSound
;
225 killsnd
: array[0..3] of TPlayableSound
;
226 gDefInterTime
: ShortInt = -1;
227 gInterEndTime
: LongWord = 0;
228 gInterTime
: LongWord = 0;
229 gServInterTime
: Byte = 0;
230 gGameStartTime
: LongWord = 0;
231 gTotalMonsters
: Integer = 0;
233 gShowTime
: Boolean = True;
234 gShowFPS
: Boolean = False;
235 gShowGoals
: Boolean = True;
236 gShowStat
: Boolean = True;
237 gShowKillMsg
: Boolean = True;
238 gShowLives
: Boolean = True;
239 gShowPing
: Boolean = False;
240 gShowMap
: Boolean = False;
242 gState
: Byte = STATE_NONE
;
244 sWidth
, sHeight
: Word;
245 gSpectMode
: Byte = SPECT_NONE
;
246 gSpectHUD
: Boolean = True;
247 gSpectKeyPress
: Boolean = False;
248 gSpectX
: Integer = 0;
249 gSpectY
: Integer = 0;
250 gSpectStep
: Byte = 8;
251 gSpectViewTwo
: Boolean = False;
252 gSpectPID1
: Integer = -1;
253 gSpectPID2
: Integer = -1;
254 gMusic
: TMusic
= nil;
255 gLoadGameMode
: Boolean;
256 gCheats
: Boolean = False;
257 gMapOnce
: Boolean = False;
258 gMapToDelete
: String;
259 gTempDelete
: Boolean = False;
260 gLastMap
: Boolean = False;
261 gWinPosX
, gWinPosY
: Integer;
262 gWinSizeX
, gWinSizeY
: Integer;
263 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
264 gWinActive
: Boolean = True; // by default window is active, lol
265 gResolutionChange
: Boolean = False;
266 gRC_Width
, gRC_Height
: Word;
267 gRC_FullScreen
, gRC_Maximized
: Boolean;
268 gLanguageChange
: Boolean = False;
269 gDebugMode
: Boolean = False;
270 g_debug_Sounds
: Boolean = False;
271 g_debug_Frames
: Boolean = False;
272 g_debug_WinMsgs
: Boolean = False;
273 g_debug_MonsterOff
: Boolean = False;
274 g_debug_BotAIOff
: Byte = 0;
275 g_debug_HealthBar
: Boolean = False;
276 g_Debug_Player
: Boolean = False;
277 gCoopMonstersKilled
: Word = 0;
278 gCoopSecretsFound
: Word = 0;
279 gCoopTotalMonstersKilled
: Word = 0;
280 gCoopTotalSecretsFound
: Word = 0;
281 gCoopTotalMonsters
: Word = 0;
282 gCoopTotalSecrets
: Word = 0;
283 gStatsOff
: Boolean = False;
284 gStatsPressed
: Boolean = False;
285 gExitByTrigger
: Boolean = False;
286 gNextMap
: String = '';
287 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
288 gLMSRespawnTime
: Cardinal = 0;
289 gLMSSoftSpawn
: Boolean = False;
290 gMissionFailed
: Boolean = False;
291 gVoteInProgress
: Boolean = False;
292 gVotePassed
: Boolean = False;
293 gVoteCommand
: string = '';
294 gVoteTimer
: Cardinal = 0;
295 gVoteCmdTimer
: Cardinal = 0;
296 gVoteCount
: Integer = 0;
297 gVoteTimeout
: Cardinal = 30;
298 gVoted
: Boolean = False;
299 gVotesEnabled
: Boolean = True;
300 gEvents
: Array of TGameEvent
;
301 gDelayedEvents
: Array of TDelayedEvent
;
303 // move button values:
304 // bits 0-1: l/r state:
305 // 0: neither left, nor right pressed
308 // bits 4-5: l/r state when strafe was pressed
309 P1MoveButton
: Byte = 0;
310 P2MoveButton
: Byte = 0;
315 g_textures
, g_main
, g_window
, g_menu
,
316 e_input
, e_log
, g_console
, g_items
, g_map
,
317 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
318 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
319 BinEditor
, g_language
, g_net
, SDL
,
320 ENet
, e_fixedbuffer
, g_netmsg
, g_netmaster
, GL
, GLExt
,
324 TEndCustomGameStat
= record
325 PlayerStat
: TPlayerStatArray
;
329 Map
, MapName
: String;
332 TEndSingleGameStat
= record
333 PlayerStat
: Array [0..1] of record
339 TotalSecrets
: Integer;
342 TLoadingStat
= record
346 Msgs
: Array of String;
350 TParamStrValue
= record
355 TParamStrValues
= Array of TParamStrValue
;
358 INTER_ACTION_TEXT
= 1;
359 INTER_ACTION_PIC
= 2;
360 INTER_ACTION_MUSIC
= 3;
364 FPSCounter
, UPSCounter
: Word;
365 FPSTime
, UPSTime
: LongWord;
366 DataLoaded
: Boolean = False;
367 LastScreenShot
: Int64;
368 IsDrawStat
: Boolean = False;
369 CustomStat
: TEndCustomGameStat
;
370 SingleStat
: TEndSingleGameStat
;
371 LoadingStat
: TLoadingStat
;
372 EndingGameCounter
: Byte = 0;
375 MapList
: SArray
= nil;
376 MapIndex
: Integer = -1;
382 text: Array of ShortString;
383 anim
: Array of ShortString;
384 pic
: Array of ShortString;
385 mus
: Array of ShortString;
387 triggers
: Array of record
389 actions
: Array of record
390 action
, p1
, p2
: Integer;
393 cur_trigger
: Integer;
406 function Compare(a
, b
: TPlayerStat
): Integer;
408 if a
.Spectator
then Result
:= 1
409 else if b
.Spectator
then Result
:= -1
410 else if a
.Frags
< b
.Frags
then Result
:= 1
411 else if a
.Frags
> b
.Frags
then Result
:= -1
412 else if a
.Deaths
< b
.Deaths
then Result
:= -1
413 else if a
.Deaths
> b
.Deaths
then Result
:= 1
414 else if a
.Kills
< b
.Kills
then Result
:= -1
418 procedure SortGameStat(var stat
: TPlayerStatArray
);
423 if stat
= nil then Exit
;
425 for I
:= High(stat
) downto Low(stat
) do
426 for J
:= Low(stat
) to High(stat
) - 1 do
427 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
430 stat
[J
] := stat
[J
+ 1];
435 function g_Game_ModeToText(Mode
: Byte): string;
439 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
440 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
441 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
442 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
443 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
447 function g_Game_TextToMode(Mode
: string): Byte;
450 Mode
:= UpperCase(Mode
);
451 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
456 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
461 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
466 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
471 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
478 function g_Game_IsNet(): Boolean;
480 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
483 function g_Game_IsServer(): Boolean;
485 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
488 function g_Game_IsClient(): Boolean;
490 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
493 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
500 Result
.name
:= ExtractFileName(WAD
);
501 Result
.description
:= '';
504 w
:= TWADFile
.Create();
507 if not w
.GetResource('INTERSCRIPT', p
, len
) then
513 cfg
:= TConfig
.CreateMem(p
, len
);
514 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
515 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
516 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
517 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
523 procedure g_Game_FreeWAD();
527 for a
:= 0 to High(MegaWAD
.res
.pic
) do
528 if MegaWAD
.res
.pic
[a
] <> '' then
529 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
531 for a
:= 0 to High(MegaWAD
.res
.mus
) do
532 if MegaWAD
.res
.mus
[a
] <> '' then
533 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
535 MegaWAD
.res
.pic
:= nil;
536 MegaWAD
.res
.text := nil;
537 MegaWAD
.res
.anim
:= nil;
538 MegaWAD
.res
.mus
:= nil;
539 MegaWAD
.triggers
:= nil;
541 g_Texture_Delete('TEXTURE_endpic');
542 g_Sound_Delete('MUSIC_endmus');
544 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
545 gGameSettings
.WAD
:= '';
548 procedure g_Game_LoadWAD(WAD
: string);
557 gGameSettings
.WAD
:= WAD
;
558 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
561 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
563 w
:= TWADFile
.Create();
564 w
.ReadFile(MapsDir
+ WAD
);
566 if not w
.GetResource('INTERSCRIPT', p
, len
) then
572 cfg
:= TConfig
.CreateMem(p
, len
);
577 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
578 if s = '' then Break;
581 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
582 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
584 g_Texture_CreateWADEx(s, s);
590 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
591 if s = '' then Break;
594 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
595 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
597 g_Music_CreateWADEx(s, s);
600 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
601 if MegaWAD
.endpic
<> '' then
603 s
:= g_ExtractWadName(MegaWAD
.endpic
);
604 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
605 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
607 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
608 if MegaWAD
.endmus
<> '' then
610 s
:= g_ExtractWadName(MegaWAD
.endmus
);
611 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
612 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
620 {procedure start_trigger(t: string);
624 function next_trigger(): Boolean;
628 procedure DisableCheats();
634 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
635 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
636 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
637 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
640 procedure g_Game_ExecuteEvent(Name
: String);
646 if gEvents
= nil then
648 for a
:= 0 to High(gEvents
) do
649 if gEvents
[a
].Name
= Name
then
651 if gEvents
[a
].Command
<> '' then
652 g_Console_Process(gEvents
[a
].Command
, True);
657 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
662 if gDelayedEvents
<> nil then
663 for a
:= 0 to High(gDelayedEvents
) do
664 if not gDelayedEvents
[a
].Pending
then
671 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
672 n
:= High(gDelayedEvents
);
674 gDelayedEvents
[n
].Pending
:= True;
675 gDelayedEvents
[n
].DEType
:= DEType
;
676 gDelayedEvents
[n
].DENum
:= Num
;
677 gDelayedEvents
[n
].DEStr
:= Str
;
678 if DEType
= DE_GLOBEVENT
then
679 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
681 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
690 if g_Game_IsNet
and g_Game_IsServer
then
691 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
697 g_Game_StopAllSounds(False);
702 EndingGameCounter
:= 0;
703 g_ActiveWindow
:= nil;
705 gLMSRespawn
:= LMS_RESPAWN_NONE
;
706 gLMSRespawnTime
:= 0;
709 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
714 begin // Ýòî áûë òåñò
718 begin // Âûõîä â ãëàâíîå ìåíþ
719 gMusic
.SetByName('MUSIC_MENU');
721 if gState
<> STATE_SLIST
then
723 g_GUI_ShowWindow('MainMenu');
724 gState
:= STATE_MENU
;
727 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
728 slReturnPressed
:= True;
729 if g_Net_Slist_Fetch(slCurrent
) then
731 if slCurrent
= nil then
732 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
735 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
738 g_Game_ExecuteEvent('ongameend');
742 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
744 if not g_Game_IsClient
then g_Game_Restart();
747 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
749 // Ñòàòèñòèêà Ñâîåé èãðû:
750 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
752 CustomStat
.GameTime
:= gTime
;
753 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
754 CustomStat
.MapName
:= gMapInfo
.Name
;
755 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
756 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
757 CustomStat
.TeamStat
:= gTeamStat
;
759 CustomStat
.PlayerStat
:= nil;
761 // Ñòàòèñòèêà èãðîêîâ:
762 if gPlayers
<> nil then
764 for a
:= 0 to High(gPlayers
) do
765 if gPlayers
[a
] <> nil then
767 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
768 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
770 Name
:= gPlayers
[a
].Name
;
771 Frags
:= gPlayers
[a
].Frags
;
772 Deaths
:= gPlayers
[a
].Death
;
773 Kills
:= gPlayers
[a
].Kills
;
774 Team
:= gPlayers
[a
].Team
;
775 Color
:= gPlayers
[a
].Model
.Color
;
776 Spectator
:= gPlayers
[a
].FSpectator
;
780 SortGameStat(CustomStat
.PlayerStat
);
783 g_Game_ExecuteEvent('onmapend');
786 EndingGameCounter
:= 255;
787 gState
:= STATE_FOLD
;
789 if gDefInterTime
< 0 then
790 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
792 gInterEndTime
:= gDefInterTime
* 1000;
795 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
797 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
798 SingleStat
.GameTime
:= gTime
;
799 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
800 SingleStat
.TotalSecrets
:= gSecretsCount
;
801 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
802 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
803 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
804 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
805 if SingleStat
.TwoPlayers
then
807 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
808 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
811 g_Game_ExecuteEvent('onmapend');
814 if gNextMap
<> '' then
816 gMusic
.SetByName('MUSIC_INTERMUS');
818 gState
:= STATE_INTERSINGLE
;
820 g_Game_ExecuteEvent('oninter');
822 else // Áîëüøå íåò êàðò
825 EndingGameCounter
:= 255;
826 gState
:= STATE_FOLD
;
831 // Îêîí÷àíèå îáðàáîòàíî:
832 if gExit
<> EXIT_QUIT
then
836 procedure DrawStat();
838 pc
, x
, y
, w
, h
: Integer;
839 w1
, w2
, w3
, w4
: Integer;
841 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
844 stat
: TPlayerStatArray
;
851 pc
:= g_Player_GetCount
;
852 e_TextureFontGetSize(gStdFont
, cw
, ch
);
854 w
:= gScreenWidth
-(gScreenWidth
div 5);
855 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
858 h
:= 40+ch
*5+(ch
+8)*pc
;
859 x
:= (gScreenWidth
div 2)-(w
div 2);
860 y
:= (gScreenHeight
div 2)-(h
div 2);
862 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
863 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
865 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
866 map
:= g_ExtractFileName(gMapInfo
.Map
);
867 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
869 case gGameSettings
.GameMode
of
872 if gGameSettings
.MaxLives
= 0 then
875 s1
:= _lc
[I_GAME_LMS
];
876 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
877 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
882 if gGameSettings
.MaxLives
= 0 then
883 s1
:= _lc
[I_GAME_TDM
]
885 s1
:= _lc
[I_GAME_TLMS
];
886 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
887 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
892 s1
:= _lc
[I_GAME_CTF
];
893 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
894 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
899 if gGameSettings
.MaxLives
= 0 then
900 s1
:= _lc
[I_GAME_COOP
]
902 s1
:= _lc
[I_GAME_SURV
];
903 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
904 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
915 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
917 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
919 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
921 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
922 gStdFont
, 200, 200, 200, 1);
924 if NetMode
= NET_SERVER
then
925 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
927 if NetMode
= NET_CLIENT
then
928 e_TextureFontPrintEx(x
+8, y
+ 8,
929 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
933 stat
:= g_Player_GetStats();
936 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
937 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
939 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
941 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
945 for a
:= TEAM_RED
to TEAM_BLUE
do
949 s1
:= _lc
[I_GAME_TEAM_RED
];
956 s1
:= _lc
[I_GAME_TEAM_BLUE
];
962 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
963 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
964 gStdFont
, r
, g
, b
, 1);
966 _y
:= _y
+ch
+(ch
div 4);
967 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
970 for aa
:= 0 to High(stat
) do
971 if stat
[aa
].Team
= a
then
987 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
989 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
991 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
993 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1000 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1003 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1004 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1005 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1006 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1009 for aa
:= 0 to High(stat
) do
1023 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1024 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1026 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1028 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1030 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1032 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1038 procedure g_Game_Init();
1044 gTempDelete
:= False;
1046 sfsGCDisable(); // temporary disable removing of temporary volumes
1049 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1050 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1051 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1052 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1054 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1055 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1056 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1058 g_Game_ClearLoading();
1059 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1060 g_Game_SetLoadingText('', 0, False);
1062 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1065 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1066 g_PlayerModel_LoadData();
1068 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1070 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1071 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1072 until FindNext(SR
) <> 0;
1075 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1077 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1078 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1079 until FindNext(SR
) <> 0;
1082 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1084 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1085 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1086 until FindNext(SR
) <> 0;
1092 LastScreenShot
:= 0;
1094 {e_MouseInfo.Accel := 1.0;}
1096 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1099 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1100 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1101 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1102 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1103 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1105 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1108 gMusic
:= TMusic
.Create();
1109 gMusic
.SetByName('MUSIC_MENU');
1112 gGameSettings
.WarmupTime
:= 30;
1114 gState
:= STATE_MENU
;
1116 SetLength(gEvents
, 6);
1117 gEvents
[0].Name
:= 'ongamestart';
1118 gEvents
[1].Name
:= 'ongameend';
1119 gEvents
[2].Name
:= 'onmapstart';
1120 gEvents
[3].Name
:= 'onmapend';
1121 gEvents
[4].Name
:= 'oninter';
1122 gEvents
[5].Name
:= 'onwadend';
1124 sfsGCEnable(); // enable releasing unused volumes
1128 procedure g_Game_Free();
1130 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1131 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1135 g_Player_RemoveAllCorpses();
1137 gGameSettings
.GameType
:= GT_NONE
;
1138 if gGameSettings
.GameMode
= GM_SINGLE
then
1139 gGameSettings
.GameMode
:= GM_DM
;
1140 gSwitchGameMode
:= gGameSettings
.GameMode
;
1143 gExitByTrigger
:= False;
1146 function IsActivePlayer(p
: TPlayer
): Boolean;
1151 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1154 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1161 if gPlayers
= nil then
1163 for a
:= Low(gPlayers
) to High(gPlayers
) do
1164 if IsActivePlayer(gPlayers
[a
]) then
1166 if gPlayers
[a
].UID
<> ID
then
1168 Result
:= gPlayers
[a
];
1173 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1179 if gPlayers
= nil then
1183 for a
:= Low(gPlayers
) to High(gPlayers
) do
1184 if IsActivePlayer(gPlayers
[a
]) then
1186 SetLength(ids
, Length(ids
) + 1);
1187 ids
[High(ids
)] := gPlayers
[a
].UID
;
1188 if gPlayers
[a
].UID
= Skip
then
1191 if Length(ids
) = 0 then
1196 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1199 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1205 if gPlayers
= nil then
1209 for a
:= Low(gPlayers
) to High(gPlayers
) do
1210 if IsActivePlayer(gPlayers
[a
]) then
1212 SetLength(ids
, Length(ids
) + 1);
1213 ids
[High(ids
)] := gPlayers
[a
].UID
;
1214 if gPlayers
[a
].UID
= Skip
then
1217 if Length(ids
) = 0 then
1220 Result
:= ids
[Length(ids
) - 1]
1222 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1225 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1227 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1228 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1232 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1238 if (plr
= nil) then exit
;
1239 if (p2hack
) then time
:= 1000 else time
:= 1;
1240 strafeDir
:= MoveButton
shr 4;
1241 MoveButton
:= MoveButton
and $0F;
1244 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1245 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1246 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1248 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1249 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1250 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1252 // if we have "strafe" key, turn off old strafe mechanics
1253 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1255 // new strafe mechanics
1256 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1257 // now set direction according to strafe (reversed)
1258 if (strafeDir
= 2) then plr
.SetDirection(D_LEFT
)
1259 else if (strafeDir
= 1) then plr
.SetDirection(D_RIGHT
);
1263 strafeDir
:= 0; // not strafing anymore
1264 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1265 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1266 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1267 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1268 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1269 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1272 // fix movebutton state
1273 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1275 // Îñòàëüíûå êëàâèøè:
1276 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1277 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1278 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1279 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1280 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1281 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1282 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1284 for i
:= 0 to High(KeyWeapon
) do
1285 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1293 procedure g_Game_Update();
1295 Msg
: g_gui
.TMessage
;
1301 // Ïîðà âûêëþ÷àòü èãðó:
1302 if gExit
= EXIT_QUIT
then
1304 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1308 if gExit
= EXIT_QUIT
then
1312 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1315 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1318 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1320 gExit
:= EXIT_SIMPLE
;
1326 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1327 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1328 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1329 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1331 if g_Game_IsNet
and g_Game_IsServer
then
1333 gInterTime
:= gInterTime
+ GAME_TICK
;
1334 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1335 if a
<> gServInterTime
then
1337 gServInterTime
:= a
;
1338 MH_SEND_TimeSync(gServInterTime
);
1342 if (not g_Game_IsClient
) and
1345 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1346 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1347 and (g_ActiveWindow
= nil)
1349 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1352 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1353 g_Game_StopAllSounds(True);
1355 if gMapOnce
then // Ýòî áûë òåñò
1356 gExit
:= EXIT_SIMPLE
1358 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1359 g_Game_ChangeMap(gNextMap
)
1360 else // Ñëåäóþùåé êàðòû íåò
1362 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1364 // Âûõîä â ãëàâíîå ìåíþ:
1366 g_GUI_ShowWindow('MainMenu');
1367 gMusic
.SetByName('MUSIC_MENU');
1369 gState
:= STATE_MENU
;
1372 // Ôèíàëüíàÿ êàðòèíêà:
1373 g_Game_ExecuteEvent('onwadend');
1375 if not gMusic
.SetByName('MUSIC_endmus') then
1376 gMusic
.SetByName('MUSIC_STDENDMUS');
1378 gState
:= STATE_ENDPIC
;
1380 g_Game_ExecuteEvent('ongameend');
1386 if gState
= STATE_INTERTEXT
then
1387 if InterText
.counter
> 0 then
1388 InterText
.counter
:= InterText
.counter
- 1;
1391 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1393 if EndingGameCounter
= 0 then
1395 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1396 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1398 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1400 g_Game_ExecuteEvent('onwadend');
1401 if not gMusic
.SetByName('MUSIC_endmus') then
1402 gMusic
.SetByName('MUSIC_STDENDMUS');
1405 gMusic
.SetByName('MUSIC_ROUNDMUS');
1408 gState
:= STATE_INTERCUSTOM
;
1410 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1412 gMusic
.SetByName('MUSIC_INTERMUS');
1414 gState
:= STATE_INTERSINGLE
;
1416 g_Game_ExecuteEvent('oninter');
1419 DecMin(EndingGameCounter
, 6, 0);
1422 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1424 if gMapOnce
then // Ýòî áûë òåñò
1426 gExit
:= EXIT_SIMPLE
;
1432 g_Serverlist_Control(slCurrent
);
1435 if g_Game_IsNet
then
1436 if not gConsoleShow
then
1437 if not gChatShow
then
1439 if g_ActiveWindow
= nil then
1441 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1442 g_Console_Chat_Switch(False)
1443 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1444 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1445 g_Console_Chat_Switch(True);
1448 if not gChatEnter
then
1449 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1450 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1453 // Ñòàòèñòèêà ïî Tab:
1455 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1456 (gGameSettings
.GameType
<> GT_SINGLE
) and
1457 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1460 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1462 // Âðåìÿ += 28 ìèëëèñåêóíä:
1463 gTime
:= gTime
+ GAME_TICK
;
1465 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1466 if MessageTime
= 0 then
1468 if MessageTime
> 0 then
1469 MessageTime
:= MessageTime
- 1;
1471 if (g_Game_IsServer
) then
1473 // Áûë çàäàí ëèìèò âðåìåíè:
1474 if (gGameSettings
.TimeLimit
> 0) then
1475 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1476 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1481 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1482 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1483 g_Game_RestartRound(gLMSSoftSpawn
);
1485 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1486 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1488 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1490 g_Console_Process(gVoteCommand
);
1492 gVotePassed
:= False;
1495 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1496 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1497 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1498 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1499 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1501 // Áûë çàäàí ëèìèò ïîáåä:
1502 if (gGameSettings
.GoalLimit
> 0) then
1506 if gGameSettings
.GameMode
= GM_DM
then
1507 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1508 for i
:= 0 to High(gPlayers
) do
1509 if gPlayers
[i
] <> nil then
1510 if gPlayers
[i
].Frags
> b
then
1511 b
:= gPlayers
[i
].Frags
;
1514 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1515 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1516 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1519 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1520 if b
>= gGameSettings
.GoalLimit
then
1527 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1528 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1529 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1530 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1532 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1533 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1534 end // if not console
1537 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1542 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1543 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1545 if not gSpectKeyPress
then
1547 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1549 // switch spect mode
1551 SPECT_NONE
: ; // not spectator
1553 SPECT_MAPVIEW
: Inc(gSpectMode
);
1554 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1556 gSpectKeyPress
:= True;
1558 if gSpectMode
= SPECT_MAPVIEW
then
1560 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1561 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1562 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1563 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1564 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1565 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1566 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1567 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1568 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1571 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1572 gSpectKeyPress
:= True;
1574 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1577 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1578 gSpectKeyPress
:= True;
1581 if gSpectMode
= SPECT_PLAYERS
then
1583 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1586 gSpectViewTwo
:= True;
1587 gSpectKeyPress
:= True;
1589 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1591 // remove second view
1592 gSpectViewTwo
:= False;
1593 gSpectKeyPress
:= True;
1595 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1597 // prev player (view 1)
1598 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1599 gSpectKeyPress
:= True;
1601 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1603 // next player (view 1)
1604 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1605 gSpectKeyPress
:= True;
1607 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1609 // prev player (view 2)
1610 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1611 gSpectKeyPress
:= True;
1613 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1615 // next player (view 2)
1616 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1617 gSpectKeyPress
:= True;
1622 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1623 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1624 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1625 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1626 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1627 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1628 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1629 gSpectKeyPress
:= False;
1632 // Îáíîâëÿåì âñå îñòàëüíîå:
1635 g_Triggers_Update();
1637 g_Monsters_Update();
1639 g_Player_UpdateAll();
1640 g_Player_UpdatePhysicalObjects();
1641 if gGameSettings
.GameType
= GT_SERVER
then
1642 if Length(gMonstersSpawned
) > 0 then
1644 for I
:= 0 to High(gMonstersSpawned
) do
1645 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1646 SetLength(gMonstersSpawned
, 0);
1649 if (gSoundTriggerTime
> 8) then
1651 g_Game_UpdateTriggerSounds();
1652 gSoundTriggerTime
:= 0;
1655 Inc(gSoundTriggerTime
);
1657 if (NetMode
= NET_SERVER
) then
1659 Inc(NetTimeToUpdate
);
1660 Inc(NetTimeToReliable
);
1661 if NetTimeToReliable
>= NetRelupdRate
then
1663 for I
:= 0 to High(gPlayers
) do
1664 if gPlayers
[I
] <> nil then
1665 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1667 if gMonsters
<> nil then
1668 for I
:= 0 to High(gMonsters
) do
1669 if gMonsters
[I
] <> nil then
1671 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1673 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1674 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1677 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1678 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1679 (gMonsters
[I
].GameVelX
<> 0) or
1680 (gMonsters
[I
].GameVelY
<> 0) then
1681 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1684 NetTimeToReliable
:= 0;
1685 NetTimeToUpdate
:= NetUpdateRate
;
1687 else if NetTimeToUpdate
>= NetUpdateRate
then
1689 if gPlayers
<> nil then
1690 for I
:= 0 to High(gPlayers
) do
1691 if gPlayers
[I
] <> nil then
1692 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1694 if gMonsters
<> nil then
1695 for I
:= 0 to High(gMonsters
) do
1696 if gMonsters
[I
] <> nil then
1698 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1700 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1701 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1704 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1705 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1706 (gMonsters
[I
].GameVelX
<> 0) or
1707 (gMonsters
[I
].GameVelY
<> 0) then
1708 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1711 NetTimeToUpdate
:= 0;
1714 if NetUseMaster
then
1715 if gTime
>= NetTimeToMaster
then
1717 if (NetMHost
= nil) or (NetMPeer
= nil) then
1718 if not g_Net_Slist_Connect
then
1719 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1722 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1726 if NetMode
= NET_CLIENT
then
1727 MC_SEND_PlayerPos();
1728 end; // if gameOn ...
1730 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1731 if g_ActiveWindow
<> nil then
1733 w
:= e_GetFirstKeyPressed();
1735 if (w
<> IK_INVALID
) then
1737 Msg
.Msg
:= MESSAGE_DIKEY
;
1739 g_ActiveWindow
.OnMessage(Msg
);
1742 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1743 if g_ActiveWindow
<> nil then
1744 g_ActiveWindow
.Update();
1746 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1747 if gResolutionChange
then
1749 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1750 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1751 gResolutionChange
:= False;
1754 // Íóæíî ñìåíèòü ÿçûê:
1755 if gLanguageChange
then
1757 //e_WriteLog('Read language file', MSG_NOTIFY);
1758 //g_Language_Load(DataDir + gLanguage + '.txt');
1759 g_Language_Set(gLanguage
);
1761 gLanguageChange
:= False;
1765 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1766 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1767 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1770 LastScreenShot
:= GetTimer();
1773 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1774 if e_KeyPressed(IK_F10
) and
1776 (not gConsoleShow
) and
1777 (g_ActiveWindow
= nil) then
1782 Time
:= GetTimer() {div 1000};
1784 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1785 if gDelayedEvents
<> nil then
1786 for a
:= 0 to High(gDelayedEvents
) do
1787 if gDelayedEvents
[a
].Pending
and
1789 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1790 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1793 case gDelayedEvents
[a
].DEType
of
1795 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1798 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1802 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1803 if g_Game_IsNet
and g_Game_IsServer
then
1804 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1807 gDelayedEvents
[a
].Pending
:= False;
1810 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1811 UPSCounter
:= UPSCounter
+ 1;
1812 if Time
- UPSTime
>= 1000 then
1820 procedure g_Game_LoadData();
1822 if DataLoaded
then Exit
;
1824 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1826 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1827 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1828 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1829 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1830 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1831 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1832 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1833 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1834 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1835 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1836 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1837 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1838 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1839 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1840 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1841 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1842 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1843 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1844 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1845 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1846 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1847 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1848 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1849 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1850 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1851 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1852 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1853 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1854 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1855 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1856 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1857 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1858 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1859 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1861 goodsnd
[0] := TPlayableSound
.Create();
1862 goodsnd
[1] := TPlayableSound
.Create();
1863 goodsnd
[2] := TPlayableSound
.Create();
1864 goodsnd
[3] := TPlayableSound
.Create();
1866 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1867 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1868 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1869 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1871 killsnd
[0] := TPlayableSound
.Create();
1872 killsnd
[1] := TPlayableSound
.Create();
1873 killsnd
[2] := TPlayableSound
.Create();
1874 killsnd
[3] := TPlayableSound
.Create();
1876 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1877 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1878 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1879 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1881 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1884 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1885 g_Weapon_LoadData();
1887 g_Monsters_LoadData();
1892 procedure g_Game_FreeData();
1894 if not DataLoaded
then Exit
;
1897 g_Weapon_FreeData();
1898 g_Monsters_FreeData();
1900 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1902 g_Texture_Delete('NOTEXTURE');
1903 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1904 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1905 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1906 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1907 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1908 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1909 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1910 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1911 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1912 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1913 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1914 g_Frames_DeleteByName('FRAMES_TELEPORT');
1915 g_Sound_Delete('SOUND_GAME_TELEPORT');
1916 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1917 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1918 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1919 g_Sound_Delete('SOUND_GAME_BULK1');
1920 g_Sound_Delete('SOUND_GAME_BULK2');
1921 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1922 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1923 g_Sound_Delete('SOUND_GAME_SWITCH1');
1924 g_Sound_Delete('SOUND_GAME_SWITCH0');
1931 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1932 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1933 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1934 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1941 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1942 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1943 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1944 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1946 DataLoaded
:= False;
1949 procedure DrawCustomStat();
1955 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1956 s1
, s2
, topstr
: String;
1958 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1961 if e_KeyPressed(IK_TAB
) then
1963 if not gStatsPressed
then
1965 gStatsOff
:= not gStatsOff
;
1966 gStatsPressed
:= True;
1970 gStatsPressed
:= False;
1974 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1975 w
:= (Length(s1
) * ww2
) div 2;
1976 x
:= gScreenWidth
div 2 - w
;
1978 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1982 if (gGameSettings
.GameMode
= GM_COOP
) then
1984 if gMissionFailed
then
1985 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1987 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1990 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1992 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1993 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
1995 if g_Game_IsNet
then
1997 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
1998 if not gChatShow
then
1999 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2000 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2003 if g_Game_IsClient
then
2004 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2006 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2007 if not gChatShow
then
2008 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2009 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2014 w
:= gScreenWidth
-x
*2;
2020 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2021 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2023 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2025 case CustomStat
.GameMode
of
2028 if gGameSettings
.MaxLives
= 0 then
2029 s1
:= _lc
[I_GAME_DM
]
2031 s1
:= _lc
[I_GAME_LMS
];
2035 if gGameSettings
.MaxLives
= 0 then
2036 s1
:= _lc
[I_GAME_TDM
]
2038 s1
:= _lc
[I_GAME_TLMS
];
2040 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2043 if gGameSettings
.MaxLives
= 0 then
2044 s1
:= _lc
[I_GAME_COOP
]
2046 s1
:= _lc
[I_GAME_SURV
];
2052 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2056 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2057 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2060 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2061 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2062 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2063 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2065 pc
:= Length(CustomStat
.PlayerStat
);
2066 if pc
= 0 then Exit
;
2068 if CustomStat
.GameMode
= GM_COOP
then
2070 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2072 s2
:= _lc
[I_GAME_MONSTERS
];
2073 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2074 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2076 s2
:= _lc
[I_GAME_SECRETS
];
2077 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2078 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2081 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2083 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2084 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2085 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2087 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2088 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2089 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2093 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2098 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2099 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2100 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2102 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2105 for t
:= TEAM_RED
to TEAM_BLUE
do
2107 if t
= TEAM_RED
then
2109 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2110 gStdFont
, 255, 0, 0, 1);
2111 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2112 gStdFont
, 255, 0, 0, 1);
2119 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2120 gStdFont
, 0, 0, 255, 1);
2121 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2122 gStdFont
, 0, 0, 255, 1);
2128 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2131 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2132 if CustomStat
.PlayerStat
[p
].Team
= t
then
2133 with CustomStat
.PlayerStat
[p
] do
2147 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2148 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2149 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2156 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2159 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2160 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2161 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2164 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2165 with CustomStat
.PlayerStat
[p
] do
2167 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2174 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2175 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2176 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2182 procedure DrawSingleStat();
2184 tm
, key_x
, val_x
, y
: Integer;
2188 procedure player_stat(n
: Integer);
2194 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2195 s2
:= Format(' %d', [gTotalMonsters
]);
2197 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2198 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2199 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2200 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2202 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2203 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2205 // "Kills-per-minute: ##.#":
2206 s1
:= _lc
[I_MENU_INTER_KPM
];
2208 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2210 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2211 s2
:= Format(' %.1f', [kpm
]);
2213 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2214 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2216 // "Secrets found: # / #":
2217 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2218 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2220 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2221 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2222 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2223 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2225 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2226 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2230 // "Level Complete":
2231 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2232 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2234 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2235 s1
:= _lc
[I_MENU_INTER_KPM
];
2236 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2239 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2241 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2242 val_x
:= key_x
+ w1
;
2245 tm
:= SingleStat
.GameTime
div 1000;
2246 s1
:= _lc
[I_MENU_INTER_TIME
];
2247 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2249 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2250 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2252 if SingleStat
.TwoPlayers
then
2255 s1
:= _lc
[I_MENU_PLAYER_1
];
2256 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2257 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2259 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2264 s1
:= _lc
[I_MENU_PLAYER_2
];
2265 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2266 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2268 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2274 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2280 procedure DrawLoadingStat();
2286 if Length(LoadingStat
.Msgs
) = 0 then
2289 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2290 yy
:= (gScreenHeight
div 3);
2291 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2292 xx
:= (gScreenWidth
div 3);
2295 for i
:= 0 to NextMsg
-1 do
2297 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2298 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2302 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2303 yy
:= yy
+ LOADING_INTERLINE
;
2307 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2309 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2311 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2312 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2315 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2316 ScaleSz
:= 16 div Scale
;
2317 // Ðàçìåðû ìèíè-êàðòû:
2318 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2319 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2321 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2323 if gWalls
<> nil then
2326 for a
:= 0 to High(gWalls
) do
2328 if PanelType
<> 0 then
2330 // Ëåâûé âåðõíèé óãîë:
2331 aX
:= X
div ScaleSz
;
2332 aY
:= Y
div ScaleSz
;
2334 aX2
:= max(Width
div ScaleSz
, 1);
2335 aY2
:= max(Height
div ScaleSz
, 1);
2336 // Ïðàâûé íèæíèé óãîë:
2337 aX2
:= aX
+ aX2
- 1;
2338 aY2
:= aY
+ aY2
- 1;
2341 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2342 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2343 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2347 if gSteps
<> nil then
2350 for a
:= 0 to High(gSteps
) do
2352 if PanelType
<> 0 then
2354 // Ëåâûé âåðõíèé óãîë:
2355 aX
:= X
div ScaleSz
;
2356 aY
:= Y
div ScaleSz
;
2358 aX2
:= max(Width
div ScaleSz
, 1);
2359 aY2
:= max(Height
div ScaleSz
, 1);
2360 // Ïðàâûé íèæíèé óãîë:
2361 aX2
:= aX
+ aX2
- 1;
2362 aY2
:= aY
+ aY2
- 1;
2364 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2367 if gLifts
<> nil then
2370 for a
:= 0 to High(gLifts
) do
2372 if PanelType
<> 0 then
2374 // Ëåâûé âåðõíèé óãîë:
2375 aX
:= X
div ScaleSz
;
2376 aY
:= Y
div ScaleSz
;
2378 aX2
:= max(Width
div ScaleSz
, 1);
2379 aY2
:= max(Height
div ScaleSz
, 1);
2380 // Ïðàâûé íèæíèé óãîë:
2381 aX2
:= aX
+ aX2
- 1;
2382 aY2
:= aY
+ aY2
- 1;
2385 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2386 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2387 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2388 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2392 if gWater
<> nil then
2395 for a
:= 0 to High(gWater
) do
2397 if PanelType
<> 0 then
2399 // Ëåâûé âåðõíèé óãîë:
2400 aX
:= X
div ScaleSz
;
2401 aY
:= Y
div ScaleSz
;
2403 aX2
:= max(Width
div ScaleSz
, 1);
2404 aY2
:= max(Height
div ScaleSz
, 1);
2405 // Ïðàâûé íèæíèé óãîë:
2406 aX2
:= aX
+ aX2
- 1;
2407 aY2
:= aY
+ aY2
- 1;
2409 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2412 if gAcid1
<> nil then
2414 // Ðèñóåì êèñëîòó 1:
2415 for a
:= 0 to High(gAcid1
) do
2417 if PanelType
<> 0 then
2419 // Ëåâûé âåðõíèé óãîë:
2420 aX
:= X
div ScaleSz
;
2421 aY
:= Y
div ScaleSz
;
2423 aX2
:= max(Width
div ScaleSz
, 1);
2424 aY2
:= max(Height
div ScaleSz
, 1);
2425 // Ïðàâûé íèæíèé óãîë:
2426 aX2
:= aX
+ aX2
- 1;
2427 aY2
:= aY
+ aY2
- 1;
2429 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2432 if gAcid2
<> nil then
2434 // Ðèñóåì êèñëîòó 2:
2435 for a
:= 0 to High(gAcid2
) do
2437 if PanelType
<> 0 then
2439 // Ëåâûé âåðõíèé óãîë:
2440 aX
:= X
div ScaleSz
;
2441 aY
:= Y
div ScaleSz
;
2443 aX2
:= max(Width
div ScaleSz
, 1);
2444 aY2
:= max(Height
div ScaleSz
, 1);
2445 // Ïðàâûé íèæíèé óãîë:
2446 aX2
:= aX
+ aX2
- 1;
2447 aY2
:= aY
+ aY2
- 1;
2449 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2452 if gPlayers
<> nil then
2455 for a
:= 0 to High(gPlayers
) do
2456 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2458 // Ëåâûé âåðõíèé óãîë:
2459 aX
:= Obj
.X
div ScaleSz
+ 1;
2460 aY
:= Obj
.Y
div ScaleSz
+ 1;
2462 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2463 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2464 // Ïðàâûé íèæíèé óãîë:
2465 aX2
:= aX
+ aX2
- 1;
2466 aY2
:= aY
+ aY2
- 1;
2468 if gPlayers
[a
] = p
then
2469 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2472 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2473 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2474 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2478 if gMonsters
<> nil then
2481 for a
:= 0 to High(gMonsters
) do
2482 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2484 // Ëåâûé âåðõíèé óãîë:
2485 aX
:= Obj
.X
div ScaleSz
+ 1;
2486 aY
:= Obj
.Y
div ScaleSz
+ 1;
2488 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2489 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2490 // Ïðàâûé íèæíèé óãîë:
2491 aX2
:= aX
+ aX2
- 1;
2492 aY2
:= aY
+ aY2
- 1;
2494 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2500 procedure DrawMapView(x
, y
, w
, h
: Integer);
2506 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2507 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2508 g_Map_DrawBack(-bx
, -by
);
2515 glTranslatef(-x
, -y
, 0);
2517 g_Map_DrawPanels(PANEL_BACK
);
2518 g_Map_DrawPanels(PANEL_STEP
);
2521 g_Player_DrawShells();
2523 g_Player_DrawCorpses();
2524 g_Map_DrawPanels(PANEL_WALL
);
2526 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2529 g_Map_DrawPanels(PANEL_ACID1
);
2530 g_Map_DrawPanels(PANEL_ACID2
);
2531 g_Map_DrawPanels(PANEL_WATER
);
2532 g_Map_DrawPanels(PANEL_FORE
);
2533 if g_debug_HealthBar
then
2535 g_Monsters_DrawHealth();
2536 g_Player_DrawHealth();
2542 procedure DrawPlayer(p
: TPlayer
);
2544 px
, py
, a
, b
, c
, d
: Integer;
2547 if (p
= nil) or (p
.FDummy
) then
2550 g_Map_DrawBack(0, 0);
2559 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2560 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2562 if px
> (gPlayerScreenSize
.X
div 2) then
2563 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2566 if py
> (gPlayerScreenSize
.Y
div 2) then
2567 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2570 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2571 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2572 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2573 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2574 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2576 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2579 if p
.IncCam
<> 0 then
2581 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2583 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2584 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2587 if py
< (gPlayerScreenSize
.Y
div 2) then
2589 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2590 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2593 if p
.IncCam
< 0 then
2594 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2596 p
.IncCam
:= p
.IncCam
+ 1;
2598 if p
.IncCam
> 0 then
2599 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2601 p
.IncCam
:= p
.IncCam
- 1;
2604 if (px
< gPlayerScreenSize
.X
div 2) or
2605 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2608 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2609 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2611 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2613 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2614 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2617 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2618 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2620 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2622 g_Map_DrawBack(-c
, -d
);
2625 sY
:= -(b
+p
.IncCam
);
2626 sWidth
:= gPlayerScreenSize
.X
;
2627 sHeight
:= gPlayerScreenSize
.Y
;
2629 glTranslatef(a
, b
+p
.IncCam
, 0);
2631 g_Map_DrawPanels(PANEL_BACK
);
2632 g_Map_DrawPanels(PANEL_STEP
);
2635 g_Player_DrawShells();
2637 g_Player_DrawCorpses();
2638 g_Map_DrawPanels(PANEL_WALL
);
2640 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2643 g_Map_DrawPanels(PANEL_ACID1
);
2644 g_Map_DrawPanels(PANEL_ACID2
);
2645 g_Map_DrawPanels(PANEL_WATER
);
2646 g_Map_DrawPanels(PANEL_FORE
);
2647 if g_debug_HealthBar
then
2649 g_Monsters_DrawHealth();
2650 g_Player_DrawHealth();
2653 if p
.FSpectator
then
2654 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2655 p
.GameY
+ PLAYER_RECT_CY
- 4,
2656 'X', gStdFont
, 255, 255, 255, 1, True);
2658 for a := 0 to High(gCollideMap) do
2659 for b := 0 to High(gCollideMap[a]) do
2662 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2664 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2668 1: e_DrawPoint(1, b, a, 200, 200, 200);
2669 2: e_DrawPoint(1, b, a, 64, 64, 255);
2670 3: e_DrawPoint(1, b, a, 255, 0, 255);
2680 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2681 if g_Debug_Player
then
2682 g_Player_DrawDebug(p
);
2686 procedure g_Game_Draw();
2693 plView1
, plView2
: TPlayer
;
2696 if gExit
= EXIT_QUIT
then Exit
;
2698 Time
:= GetTimer() {div 1000};
2699 FPSCounter
:= FPSCounter
+1;
2700 if Time
- FPSTime
>= 1000 then
2707 if gGameOn
or (gState
= STATE_FOLD
) then
2709 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2711 gSpectMode
:= SPECT_NONE
;
2712 if not gRevertPlayers
then
2714 plView1
:= gPlayer1
;
2715 plView2
:= gPlayer2
;
2719 plView1
:= gPlayer2
;
2720 plView2
:= gPlayer1
;
2724 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2726 gSpectMode
:= SPECT_NONE
;
2727 if gPlayer2
= nil then
2730 plView1
:= gPlayer2
;
2739 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2740 gSpectMode
:= SPECT_STATS
;
2742 if gSpectMode
= SPECT_PLAYERS
then
2743 if gPlayers
<> nil then
2745 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2746 if plView1
= nil then
2748 gSpectPID1
:= GetActivePlayerID_Next();
2749 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2751 if gSpectViewTwo
then
2753 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2754 if plView2
= nil then
2756 gSpectPID2
:= GetActivePlayerID_Next();
2757 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2762 if gSpectMode
= SPECT_MAPVIEW
then
2764 // Ðåæèì ïðîñìîòðà êàðòû
2766 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2767 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2768 gHearPoint1
.Active
:= True;
2769 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2770 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2771 gHearPoint2
.Active
:= False;
2775 Split
:= (plView1
<> nil) and (plView2
<> nil);
2777 // Òî÷êè ñëóõà èãðîêîâ
2778 if plView1
<> nil then
2780 gHearPoint1
.Active
:= True;
2781 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2782 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2784 gHearPoint1
.Active
:= False;
2785 if plView2
<> nil then
2787 gHearPoint2
.Active
:= True;
2788 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2789 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2791 gHearPoint2
.Active
:= False;
2793 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2794 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2797 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2798 if gScreenHeight
mod 2 = 0 then
2799 Dec(gPlayerScreenSize
.Y
);
2802 gPlayerScreenSize
.Y
:= gScreenHeight
;
2805 if gScreenHeight
mod 2 = 0 then
2806 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2808 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2810 DrawPlayer(plView1
);
2811 gPlayer1ScreenCoord
.X
:= sX
;
2812 gPlayer1ScreenCoord
.Y
:= sY
;
2816 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2818 DrawPlayer(plView2
);
2819 gPlayer2ScreenCoord
.X
:= sX
;
2820 gPlayer2ScreenCoord
.Y
:= sY
;
2823 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2826 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2829 if MessageText
<> '' then
2833 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2835 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2836 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2838 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2839 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2842 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2844 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2846 // Draw spectator GUI
2849 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2852 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2854 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2856 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2858 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2859 if gSpectMode
= SPECT_MAPVIEW
then
2861 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2862 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2863 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2864 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2865 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2867 if gSpectMode
= SPECT_PLAYERS
then
2869 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2870 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2871 if gSpectViewTwo
then
2873 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2874 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2875 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2876 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2880 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2881 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2887 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2889 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2891 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2892 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2893 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2898 if (gState
= STATE_MENU
) then
2900 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2902 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2903 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2904 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2906 if g_ActiveWindow
<> nil then
2907 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2910 if gState
= STATE_FOLD
then
2911 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2913 if gState
= STATE_INTERCUSTOM
then
2915 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2917 back
:= 'TEXTURE_endpic';
2918 if not g_Texture_Get(back
, ID
) then
2919 back
:= _lc
[I_TEXTURE_ENDPIC
];
2924 if g_Texture_Get(back
, ID
) then
2925 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2927 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2931 if g_ActiveWindow
<> nil then
2932 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2935 if gState
= STATE_INTERSINGLE
then
2937 if EndingGameCounter
> 0 then
2938 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2943 if g_Texture_Get(back
, ID
) then
2944 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2946 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2950 if g_ActiveWindow
<> nil then
2951 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2955 if gState
= STATE_ENDPIC
then
2958 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2959 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2961 if ID
<> DWORD(-1) then
2962 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2964 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2966 if g_ActiveWindow
<> nil then
2967 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2970 if gState
= STATE_SLIST
then
2972 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2974 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2975 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2977 g_Serverlist_Draw(slCurrent
);
2981 if g_ActiveWindow
<> nil then
2984 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2985 g_ActiveWindow
.Draw();
2990 if g_debug_Sounds
and gGameOn
then
2992 for w
:= 0 to High(e_SoundsArray
) do
2993 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2994 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
2999 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3000 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3003 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3004 e_TextureFontPrint(gScreenWidth
-72, 0,
3005 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3009 procedure g_Game_Quit();
3011 g_Game_StopAllSounds(True);
3013 g_Game_SaveOptions();
3015 g_PlayerModel_FreeData();
3016 g_Texture_DeleteAll();
3017 g_Frames_DeleteAll();
3020 if NetInitDone
then g_Net_Free
;
3022 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3023 if gMapToDelete
<> '' then
3024 g_Game_DeleteTestMap();
3030 procedure g_FatalError(Text: String);
3032 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3033 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3035 gExit
:= EXIT_SIMPLE
;
3038 procedure g_SimpleError(Text: String);
3040 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3041 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3044 procedure g_Game_SetupScreenSize();
3048 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3049 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3050 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3051 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3053 gPlayerScreenSize
.Y
:= gScreenHeight
;
3055 // Ðàçìåð çàäíåãî ïëàíà:
3056 if BackID
<> DWORD(-1) then
3060 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3061 (gScreenHeight
*d
> gMapInfo
.Height
) then
3064 gBackSize
.X
:= Round(gScreenWidth
*d
);
3065 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3069 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3071 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3074 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3076 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3077 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3079 if gPlayer1
= nil then
3081 if g_Game_IsClient
then
3083 if NetPlrUID1
> -1 then
3085 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3086 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3091 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3092 Team
:= gPlayer1Settings
.Team
;
3094 // Ñîçäàíèå ïåðâîãî èãðîêà:
3095 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3096 gPlayer1Settings
.Color
,
3098 if gPlayer1
= nil then
3099 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3102 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3103 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3104 if g_Game_IsServer
and g_Game_IsNet
then
3105 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3106 gPlayer1
.Respawn(False, True);
3108 if g_Game_IsNet
and NetUseMaster
then
3114 if gPlayer2
= nil then
3116 if g_Game_IsClient
then
3118 if NetPlrUID2
> -1 then
3119 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3123 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3124 Team
:= gPlayer2Settings
.Team
;
3126 // Ñîçäàíèå âòîðîãî èãðîêà:
3127 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3128 gPlayer2Settings
.Color
,
3130 if gPlayer2
= nil then
3131 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3134 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3135 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3136 if g_Game_IsServer
and g_Game_IsNet
then
3137 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3138 gPlayer2
.Respawn(False, True);
3140 if g_Game_IsNet
and NetUseMaster
then
3148 procedure g_Game_RemovePlayer();
3152 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3153 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3158 if g_Game_IsServer
then
3161 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3162 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3163 g_Player_Remove(Pl
.UID
);
3165 if g_Game_IsNet
and NetUseMaster
then
3174 if g_Game_IsServer
then
3177 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3178 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3179 g_Player_Remove(Pl
.UID
);
3181 if g_Game_IsNet
and NetUseMaster
then
3186 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3192 procedure g_Game_Spectate();
3194 g_Game_RemovePlayer();
3195 if gPlayer1
<> nil then
3196 g_Game_RemovePlayer();
3199 procedure g_Game_SpectateCenterView();
3201 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3202 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3205 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3211 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3213 g_Game_ClearLoading();
3216 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3219 gGameSettings
.GameType
:= GT_SINGLE
;
3220 gGameSettings
.MaxLives
:= 0;
3221 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3222 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3223 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3224 gSwitchGameMode
:= GM_SINGLE
;
3226 g_Game_ExecuteEvent('ongamestart');
3228 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3229 g_Game_SetupScreenSize();
3231 // Ñîçäàíèå ïåðâîãî èãðîêà:
3232 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3233 gPlayer1Settings
.Color
,
3234 gPlayer1Settings
.Team
, False));
3235 if gPlayer1
= nil then
3237 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3241 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3244 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3247 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3248 gPlayer2Settings
.Color
,
3249 gPlayer2Settings
.Team
, False));
3250 if gPlayer2
= nil then
3252 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3256 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3260 // Çàãðóçêà è çàïóñê êàðòû:
3261 if not g_Game_StartMap(MAP
, True) then
3263 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3267 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3271 for i
:= nPl
+1 to nPlayers
do
3272 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3275 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3276 TimeLimit
, GoalLimit
: Word;
3278 Options
: LongWord; nPlayers
: Byte);
3284 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3286 g_Game_ClearLoading();
3289 gGameSettings
.GameType
:= GT_CUSTOM
;
3290 gGameSettings
.GameMode
:= GameMode
;
3291 gSwitchGameMode
:= GameMode
;
3292 gGameSettings
.TimeLimit
:= TimeLimit
;
3293 gGameSettings
.GoalLimit
:= GoalLimit
;
3294 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3295 gGameSettings
.Options
:= Options
;
3297 gCoopTotalMonstersKilled
:= 0;
3298 gCoopTotalSecretsFound
:= 0;
3299 gCoopTotalMonsters
:= 0;
3300 gCoopTotalSecrets
:= 0;
3304 g_Game_ExecuteEvent('ongamestart');
3306 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3307 g_Game_SetupScreenSize();
3309 // Ðåæèì íàáëþäàòåëÿ:
3310 if nPlayers
= 0 then
3317 if nPlayers
>= 1 then
3319 // Ñîçäàíèå ïåðâîãî èãðîêà:
3320 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3321 gPlayer1Settings
.Color
,
3322 gPlayer1Settings
.Team
, False));
3323 if gPlayer1
= nil then
3325 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3329 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3333 if nPlayers
>= 2 then
3335 // Ñîçäàíèå âòîðîãî èãðîêà:
3336 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3337 gPlayer2Settings
.Color
,
3338 gPlayer2Settings
.Team
, False));
3339 if gPlayer2
= nil then
3341 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3345 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3349 // Çàãðóçêà è çàïóñê êàðòû:
3350 if not g_Game_StartMap(Map
, True) then
3352 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3356 // Íåò òî÷åê ïîÿâëåíèÿ:
3357 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3358 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3359 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3360 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3361 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3363 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3367 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3371 for i
:= nPl
+1 to nPlayers
do
3372 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3375 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3376 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3377 Options
: LongWord; nPlayers
: Byte;
3378 IPAddr
: LongWord; Port
: Word);
3382 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3384 g_Game_ClearLoading();
3387 gGameSettings
.GameType
:= GT_SERVER
;
3388 gGameSettings
.GameMode
:= GameMode
;
3389 gSwitchGameMode
:= GameMode
;
3390 gGameSettings
.TimeLimit
:= TimeLimit
;
3391 gGameSettings
.GoalLimit
:= GoalLimit
;
3392 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3393 gGameSettings
.Options
:= Options
;
3395 gCoopTotalMonstersKilled
:= 0;
3396 gCoopTotalSecretsFound
:= 0;
3397 gCoopTotalMonsters
:= 0;
3398 gCoopTotalSecrets
:= 0;
3402 g_Game_ExecuteEvent('ongamestart');
3404 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3405 g_Game_SetupScreenSize();
3407 // Ðåæèì íàáëþäàòåëÿ:
3408 if nPlayers
= 0 then
3414 if nPlayers
>= 1 then
3416 // Ñîçäàíèå ïåðâîãî èãðîêà:
3417 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3418 gPlayer1Settings
.Color
,
3419 gPlayer1Settings
.Team
, False));
3420 if gPlayer1
= nil then
3422 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3426 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3429 if nPlayers
>= 2 then
3431 // Ñîçäàíèå âòîðîãî èãðîêà:
3432 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3433 gPlayer2Settings
.Color
,
3434 gPlayer2Settings
.Team
, False));
3435 if gPlayer2
= nil then
3437 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3441 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3445 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3447 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3451 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3453 // Çàãðóçêà è çàïóñê êàðòû:
3454 if not g_Game_StartMap(Map
, True) then
3456 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3460 // Íåò òî÷åê ïîÿâëåíèÿ:
3461 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3462 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3463 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3464 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3465 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3467 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3471 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3474 NetState
:= NET_STATE_GAME
;
3477 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3491 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3492 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3494 g_Game_ClearLoading();
3497 gGameSettings
.GameType
:= GT_CLIENT
;
3499 gCoopTotalMonstersKilled
:= 0;
3500 gCoopTotalSecretsFound
:= 0;
3501 gCoopTotalMonsters
:= 0;
3502 gCoopTotalSecrets
:= 0;
3506 g_Game_ExecuteEvent('ongamestart');
3508 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3509 g_Game_SetupScreenSize();
3511 NetState
:= NET_STATE_AUTH
;
3513 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3515 if not g_Net_Connect(Addr
, Port
) then
3517 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3518 NetState
:= NET_STATE_NONE
;
3522 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3524 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3529 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3531 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3533 Ptr
:= NetEvent
.packet
^.data
;
3536 MID
:= e_Raw_Read_Byte(Ptr
);
3538 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3540 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3541 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3543 WadName
:= e_Raw_Read_String(Ptr
);
3544 Map
:= e_Raw_Read_String(Ptr
);
3546 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3548 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3549 gSwitchGameMode
:= gGameSettings
.GameMode
;
3550 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3551 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3552 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3553 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3554 T
:= e_Raw_Read_LongWord(Ptr
);
3556 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3557 if newResPath
= '' then
3559 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3560 newResPath
:= g_Res_DownloadWAD(WadName
);
3561 if newResPath
= '' then
3563 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3564 enet_packet_destroy(NetEvent
.packet
);
3565 NetState
:= NET_STATE_NONE
;
3569 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3571 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3572 gPlayer1Settings
.Color
,
3573 gPlayer1Settings
.Team
, False));
3575 if gPlayer1
= nil then
3577 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3579 enet_packet_destroy(NetEvent
.packet
);
3580 NetState
:= NET_STATE_NONE
;
3584 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3585 gPlayer1
.UID
:= NetPlrUID1
;
3586 gPlayer1
.Reset(True);
3588 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3590 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3592 enet_packet_destroy(NetEvent
.packet
);
3593 NetState
:= NET_STATE_NONE
;
3601 enet_packet_destroy(NetEvent
.packet
);
3605 enet_packet_destroy(NetEvent
.packet
);
3608 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3611 if (NetEvent
.data
<= NET_DISC_MAX
) then
3612 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3613 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3623 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3632 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3633 NetState
:= NET_STATE_NONE
;
3637 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3638 gLMSRespawnTime
:= 0;
3641 NetState
:= NET_STATE_GAME
;
3642 MC_SEND_FullStateRequest
;
3643 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3646 procedure g_Game_SaveOptions();
3648 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3651 procedure g_Game_ChangeMap(MapPath
: String);
3655 g_Game_ClearLoading();
3657 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3658 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3659 if gExitByTrigger
then
3662 gExitByTrigger
:= False;
3664 if not g_Game_StartMap(MapPath
, Force
) then
3665 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3668 procedure g_Game_Restart();
3672 if g_Game_IsClient
then
3674 map
:= g_ExtractFileName(gMapInfo
.Map
);
3678 g_Game_ClearLoading();
3679 g_Game_StartMap(Map
, True);
3682 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3684 NewWAD
, ResName
: String;
3688 g_Player_RemoveAllCorpses();
3690 if (not g_Game_IsClient
) and
3691 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3692 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3694 if gSwitchGameMode
= GM_CTF
then
3695 gGameSettings
.MaxLives
:= 0;
3696 gGameSettings
.GameMode
:= gSwitchGameMode
;
3699 gSwitchGameMode
:= gGameSettings
.GameMode
;
3701 g_Player_ResetTeams();
3703 if Pos(':\', Map
) > 0 then
3705 NewWAD
:= g_ExtractWadName(Map
);
3706 ResName
:= g_ExtractFileName(Map
);
3707 if g_Game_IsServer
then
3709 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3710 g_Game_LoadWAD(NewWAD
);
3712 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3713 g_Game_ClientWAD(NewWAD
, gWADHash
);
3717 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3720 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3722 gState
:= STATE_NONE
;
3723 g_ActiveWindow
:= nil;
3729 if gGameSettings
.GameMode
= GM_CTF
then
3731 g_Map_ResetFlag(FLAG_RED
);
3732 g_Map_ResetFlag(FLAG_BLUE
);
3733 // CTF, à ôëàãîâ íåò:
3734 if not g_Map_HaveFlagPoints() then
3735 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3740 gState
:= STATE_MENU
;
3747 NetTimeToUpdate
:= 1;
3748 NetTimeToReliable
:= 0;
3749 NetTimeToMaster
:= NetMasterRate
;
3750 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3751 gLMSRespawnTime
:= 0;
3752 gMissionFailed
:= False;
3755 gCoopMonstersKilled
:= 0;
3756 gCoopSecretsFound
:= 0;
3758 gVoteInProgress
:= False;
3759 gVotePassed
:= False;
3765 if not gGameOn
then Exit
;
3767 g_Game_SpectateCenterView();
3769 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3771 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3772 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3773 gLMSSoftSpawn
:= True;
3774 if NetMode
= NET_SERVER
then
3775 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3777 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3780 if NetMode
= NET_SERVER
then
3782 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3785 if NetUseMaster
then
3787 if (NetMHost
= nil) or (NetMPeer
= nil) then
3788 if not g_Net_Slist_Connect
then
3789 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3794 if NetClients
<> nil then
3795 for I
:= 0 to High(NetClients
) do
3796 if NetClients
[I
].Used
then
3798 NetClients
[I
].Voted
:= False;
3799 if NetClients
[I
].RequestedFullUpdate
then
3801 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3802 NetClients
[I
].RequestedFullUpdate
:= False;
3806 g_Net_UnbanNonPermHosts();
3811 gCoopTotalMonstersKilled
:= 0;
3812 gCoopTotalSecretsFound
:= 0;
3813 gCoopTotalMonsters
:= 0;
3814 gCoopTotalSecrets
:= 0;
3818 g_Game_ExecuteEvent('onmapstart');
3821 procedure SetFirstLevel();
3825 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3826 if MapList
= nil then
3829 SortSArray(MapList
);
3830 gNextMap
:= MapList
[Low(MapList
)];
3835 procedure g_Game_ExitLevel(Map
: Char16
);
3839 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3840 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3841 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3842 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3844 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3845 if gGameSettings
.GameType
= GT_SINGLE
then
3846 gExit
:= EXIT_ENDLEVELSINGLE
3847 else // Âûøëè â âûõîä â Ñâîåé èãðå
3849 gExit
:= EXIT_ENDLEVELCUSTOM
;
3850 if gGameSettings
.GameMode
= GM_COOP
then
3851 g_Player_RememberAll
;
3853 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3856 if gGameSettings
.GameMode
= GM_COOP
then
3859 gStatsPressed
:= True;
3860 gNextMap
:= 'MAP01';
3862 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3865 if g_Game_IsNet
then
3867 MH_SEND_GameStats();
3868 MH_SEND_CoopStats();
3874 procedure g_Game_RestartLevel();
3878 if gGameSettings
.GameMode
= GM_SINGLE
then
3883 gExit
:= EXIT_ENDLEVELCUSTOM
;
3884 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3888 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3892 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3894 if not g_Game_IsClient
then
3896 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3899 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3900 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3904 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3908 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3909 g_Game_LoadWAD(NewWAD
);
3912 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3914 i
, n
, nb
, nr
: Integer;
3916 if not g_Game_IsServer
then Exit
;
3917 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3918 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3919 gLMSRespawnTime
:= 0;
3922 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3924 gMissionFailed
:= True;
3925 g_Game_RestartLevel
;
3929 n
:= 0; nb
:= 0; nr
:= 0;
3930 for i
:= Low(gPlayers
) to High(gPlayers
) do
3931 if (gPlayers
[i
] <> nil) and
3932 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3933 (gPlayers
[i
] is TBot
)) then
3936 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3937 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3940 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3942 // wait a second until the fuckers finally decide to join
3943 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3944 gLMSRespawnTime
:= gTime
+ 1000;
3945 gLMSSoftSpawn
:= NoMapRestart
;
3949 g_Player_RemoveAllCorpses
;
3950 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3951 if g_Game_IsNet
then
3952 MH_SEND_GameEvent(NET_EV_LMS_START
);
3954 for i
:= Low(gPlayers
) to High(gPlayers
) do
3956 if gPlayers
[i
] = nil then continue
;
3957 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3958 // don't touch normal spectators
3959 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3961 gPlayers
[i
].FNoRespawn
:= True;
3962 gPlayers
[i
].Lives
:= 0;
3963 if g_Game_IsNet
then
3964 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3967 gPlayers
[i
].FNoRespawn
:= False;
3968 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3969 gPlayers
[i
].Respawn(False, True);
3970 if gGameSettings
.GameMode
= GM_COOP
then
3972 gPlayers
[i
].Frags
:= 0;
3973 gPlayers
[i
].RecallState
;
3975 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3976 gPlayer1
:= g_Player_Get(gLMSPID1
);
3977 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3978 gPlayer2
:= g_Player_Get(gLMSPID2
);
3981 for i
:= Low(gItems
) to High(gItems
) do
3983 if gItems
[i
].Respawnable
then
3985 gItems
[i
].QuietRespawn
:= True;
3986 gItems
[i
].RespawnTime
:= 0;
3991 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3995 for i
:= Low(gMonsters
) to High(gMonsters
) do
3997 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
3998 gMonsters
[i
].Respawn
;
4001 gLMSSoftSpawn
:= False;
4004 function g_Game_GetFirstMap(WAD
: String): String;
4008 MapList
:= g_Map_GetMapsList(WAD
);
4009 if MapList
= nil then
4012 SortSArray(MapList
);
4013 Result
:= MapList
[Low(MapList
)];
4015 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4021 function g_Game_GetNextMap(): String;
4028 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4029 if MapList
= nil then
4032 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4034 SortSArray(MapList
);
4036 for I
:= Low(MapList
) to High(MapList
) do
4037 if Map
= MapList
[I
] then
4043 if MapIndex
<> -255 then
4045 if MapIndex
= High(MapList
) then
4046 Result
:= MapList
[Low(MapList
)]
4048 Result
:= MapList
[MapIndex
+ 1];
4050 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4056 procedure g_Game_NextLevel();
4058 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4059 gExit
:= EXIT_ENDLEVELCUSTOM
4062 gExit
:= EXIT_ENDLEVELSINGLE
;
4066 if gNextMap
<> '' then Exit
;
4067 gNextMap
:= g_Game_GetNextMap();
4070 function g_Game_IsTestMap(): Boolean;
4072 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4075 procedure g_Game_DeleteTestMap();
4086 a
:= Pos('.wad:\', gMapToDelete
);
4090 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4091 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4092 Delete(gMapToDelete
, 1, a
+ 5);
4093 gMapToDelete
:= UpperCase(gMapToDelete
);
4095 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4098 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4099 if MapName <> TEST_MAP_NAME then
4102 if not gTempDelete then
4104 time := g_GetFileTime(WadName);
4105 WAD := TWADFile.Create();
4108 if not WAD.ReadFile(WadName) then
4109 begin // Íåò òàêîãî WAD-ôàéëà
4114 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4116 MapList := WAD.GetResourcesList('');
4118 if MapList <> nil then
4119 for a := 0 to High(MapList) do
4120 if MapList[a] = MapName then
4122 // Óäàëÿåì è ñîõðàíÿåì:
4123 WAD.RemoveResource('', MapName);
4124 WAD.SaveTo(WadName);
4129 g_SetFileTime(WadName, time);
4132 if gTempDelete
then DeleteFile(WadName
);
4135 procedure GameCVars(P
: SArray
);
4138 stat
: TPlayerStatArray
;
4143 cmd
:= LowerCase(P
[0]);
4144 if cmd
= 'r_showfps' then
4146 if (Length(P
) > 1) and
4147 ((P
[1] = '1') or (P
[1] = '0')) then
4148 gShowFPS
:= (P
[1][1] = '1');
4151 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4153 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4155 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4157 with gGameSettings
do
4159 if (Length(P
) > 1) and
4160 ((P
[1] = '1') or (P
[1] = '0')) then
4162 if (P
[1][1] = '1') then
4163 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4165 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4168 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4169 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4171 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4173 if g_Game_IsNet
then MH_SEND_GameSettings
;
4176 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4178 with gGameSettings
do
4180 if (Length(P
) > 1) and
4181 ((P
[1] = '1') or (P
[1] = '0')) then
4183 if (P
[1][1] = '1') then
4184 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4186 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4189 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4190 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4192 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4194 if g_Game_IsNet
then MH_SEND_GameSettings
;
4197 else if cmd
= 'g_gamemode' then
4199 a
:= g_Game_TextToMode(P
[1]);
4200 if a
= GM_SINGLE
then a
:= GM_COOP
;
4201 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4203 gSwitchGameMode
:= a
;
4204 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4205 (gState
= STATE_INTERSINGLE
) then
4206 gSwitchGameMode
:= GM_SINGLE
;
4208 gGameSettings
.GameMode
:= gSwitchGameMode
;
4210 if gSwitchGameMode
= gGameSettings
.GameMode
then
4211 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4212 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4214 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4215 [g_Game_ModeToText(gGameSettings
.GameMode
),
4216 g_Game_ModeToText(gSwitchGameMode
)]));
4218 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4220 with gGameSettings
do
4222 if (Length(P
) > 1) and
4223 ((P
[1] = '1') or (P
[1] = '0')) then
4225 if (P
[1][1] = '1') then
4226 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4228 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4231 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4232 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4234 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4235 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4237 if g_Game_IsNet
then MH_SEND_GameSettings
;
4240 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4242 with gGameSettings
do
4244 if (Length(P
) > 1) and
4245 ((P
[1] = '1') or (P
[1] = '0')) then
4247 if (P
[1][1] = '1') then
4248 Options
:= Options
or GAME_OPTION_MONSTERS
4250 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4253 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4254 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4256 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4257 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4259 if g_Game_IsNet
then MH_SEND_GameSettings
;
4262 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4264 with gGameSettings
do
4266 if (Length(P
) > 1) and
4267 ((P
[1] = '1') or (P
[1] = '0')) then
4269 if (P
[1][1] = '1') then
4270 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4272 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4275 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4276 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4278 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4280 if g_Game_IsNet
then MH_SEND_GameSettings
;
4283 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4285 with gGameSettings
do
4287 if (Length(P
) > 1) and
4288 ((P
[1] = '1') or (P
[1] = '0')) then
4290 if (P
[1][1] = '1') then
4291 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4293 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4296 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4297 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4299 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4301 if g_Game_IsNet
then MH_SEND_GameSettings
;
4304 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4306 if Length(P
) > 1 then
4308 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4309 gGameSettings
.WarmupTime
:= 30
4311 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4314 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4315 [gGameSettings
.WarmupTime
]));
4316 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4318 else if cmd
= 'net_interp' then
4320 if (Length(P
) > 1) then
4321 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4323 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4324 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4325 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4326 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4329 else if cmd
= 'net_forceplayerupdate' then
4331 if (Length(P
) > 1) and
4332 ((P
[1] = '1') or (P
[1] = '0')) then
4333 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4335 if NetForcePlayerUpdate
then
4336 g_Console_Add('net_forceplayerupdate = 1')
4338 g_Console_Add('net_forceplayerupdate = 0');
4339 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4340 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4341 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4344 else if cmd
= 'net_predictself' then
4346 if (Length(P
) > 1) and
4347 ((P
[1] = '1') or (P
[1] = '0')) then
4348 NetPredictSelf
:= (P
[1][1] = '1');
4350 if NetPredictSelf
then
4351 g_Console_Add('net_predictself = 1')
4353 g_Console_Add('net_predictself = 0');
4354 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4355 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4356 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4359 else if cmd
= 'sv_name' then
4361 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4363 NetServerName
:= P
[1];
4364 if Length(NetServerName
) > 64 then
4365 SetLength(NetServerName
, 64);
4366 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4370 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4372 else if cmd
= 'sv_passwd' then
4374 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4376 NetPassword
:= P
[1];
4377 if Length(NetPassword
) > 24 then
4378 SetLength(NetPassword
, 24);
4379 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4383 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4385 else if cmd
= 'sv_maxplrs' then
4387 if (Length(P
) > 1) then
4389 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4390 if g_Game_IsServer
and g_Game_IsNet
then
4393 for a
:= 0 to High(NetClients
) do
4394 if NetClients
[a
].Used
then
4397 if b
> NetMaxClients
then
4399 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4400 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4401 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4402 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4405 if NetUseMaster
then
4410 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4412 else if cmd
= 'sv_public' then
4414 if (Length(P
) > 1) then
4416 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4417 if g_Game_IsServer
and g_Game_IsNet
then
4418 if NetUseMaster
then
4420 if NetMPeer
= nil then
4421 if not g_Net_Slist_Connect() then
4422 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4423 g_Net_Slist_Update();
4426 if NetMPeer
<> nil then
4427 g_Net_Slist_Disconnect();
4430 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4432 else if cmd
= 'sv_intertime' then
4434 if (Length(P
) > 1) then
4435 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4437 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4439 else if cmd
= 'p1_name' then
4441 if (Length(P
) > 1) and gGameOn
then
4443 if g_Game_IsClient
then
4445 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4446 MC_SEND_PlayerSettings
;
4449 if gPlayer1
<> nil then
4451 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4452 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4455 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4458 else if cmd
= 'p2_name' then
4460 if (Length(P
) > 1) and gGameOn
then
4462 if g_Game_IsClient
then
4464 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4465 MC_SEND_PlayerSettings
;
4468 if gPlayer2
<> nil then
4470 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4471 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4474 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4477 else if cmd
= 'p1_color' then
4479 if Length(P
) > 3 then
4480 if g_Game_IsClient
then
4482 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4483 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4484 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4485 MC_SEND_PlayerSettings
;
4488 if gPlayer1
<> nil then
4490 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4491 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4492 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4493 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4496 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4497 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4498 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4500 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4502 if Length(P
) > 3 then
4503 if g_Game_IsClient
then
4505 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4506 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4507 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4508 MC_SEND_PlayerSettings
;
4511 if gPlayer2
<> nil then
4513 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4514 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4515 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4516 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4519 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4520 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4521 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4523 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4525 if cmd
= 'r_showtime' then
4527 if (Length(P
) > 1) and
4528 ((P
[1] = '1') or (P
[1] = '0')) then
4529 gShowTime
:= (P
[1][1] = '1');
4532 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4534 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4536 else if cmd
= 'r_showscore' then
4538 if (Length(P
) > 1) and
4539 ((P
[1] = '1') or (P
[1] = '0')) then
4540 gShowGoals
:= (P
[1][1] = '1');
4543 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4545 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4547 else if cmd
= 'r_showstat' then
4549 if (Length(P
) > 1) and
4550 ((P
[1] = '1') or (P
[1] = '0')) then
4551 gShowStat
:= (P
[1][1] = '1');
4554 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4556 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4558 else if cmd
= 'r_showkillmsg' then
4560 if (Length(P
) > 1) and
4561 ((P
[1] = '1') or (P
[1] = '0')) then
4562 gShowKillMsg
:= (P
[1][1] = '1');
4564 if gShowKillMsg
then
4565 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4567 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4569 else if cmd
= 'r_showlives' then
4571 if (Length(P
) > 1) and
4572 ((P
[1] = '1') or (P
[1] = '0')) then
4573 gShowLives
:= (P
[1][1] = '1');
4576 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4578 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4580 else if cmd
= 'r_showspect' then
4582 if (Length(P
) > 1) and
4583 ((P
[1] = '1') or (P
[1] = '0')) then
4584 gSpectHUD
:= (P
[1][1] = '1');
4587 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4589 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4591 else if cmd
= 'r_showping' then
4593 if (Length(P
) > 1) and
4594 ((P
[1] = '1') or (P
[1] = '0')) then
4595 gShowPing
:= (P
[1][1] = '1');
4598 g_Console_Add(_lc
[I_MSG_PING_ON
])
4600 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4602 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4604 if Length(P
) > 1 then
4606 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4607 gGameSettings
.GoalLimit
:= 0
4612 if gGameSettings
.GameMode
= GM_DM
then
4614 stat
:= g_Player_GetStats();
4616 for a
:= 0 to High(stat
) do
4617 if stat
[a
].Frags
> b
then
4621 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4623 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4626 if g_Game_IsNet
then MH_SEND_GameSettings
;
4629 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4631 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4633 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4634 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4636 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4637 [gGameSettings
.TimeLimit
div 3600,
4638 (gGameSettings
.TimeLimit
div 60) mod 60,
4639 gGameSettings
.TimeLimit
mod 60]));
4640 if g_Game_IsNet
then MH_SEND_GameSettings
;
4642 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4644 if Length(P
) > 1 then
4646 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4647 gGameSettings
.MaxLives
:= 0
4651 stat
:= g_Player_GetStats();
4653 for a
:= 0 to High(stat
) do
4654 if stat
[a
].Lives
> b
then
4656 gGameSettings
.MaxLives
:=
4657 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4661 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4662 [gGameSettings
.MaxLives
]));
4663 if g_Game_IsNet
then MH_SEND_GameSettings
;
4668 procedure DebugCommands(P
: SArray
);
4674 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4677 cmd
:= LowerCase(P
[0]);
4678 if cmd
= 'd_window' then
4680 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4681 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4682 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4683 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4684 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4686 else if cmd
= 'd_sounds' then
4688 if (Length(P
) > 1) and
4689 ((P
[1] = '1') or (P
[1] = '0')) then
4690 g_Debug_Sounds
:= (P
[1][1] = '1');
4692 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4694 else if cmd
= 'd_frames' then
4696 if (Length(P
) > 1) and
4697 ((P
[1] = '1') or (P
[1] = '0')) then
4698 g_Debug_Frames
:= (P
[1][1] = '1');
4700 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4702 else if cmd
= 'd_winmsg' then
4704 if (Length(P
) > 1) and
4705 ((P
[1] = '1') or (P
[1] = '0')) then
4706 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4708 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4710 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4712 if (Length(P
) > 1) and
4713 ((P
[1] = '1') or (P
[1] = '0')) then
4714 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4716 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4718 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4720 if Length(P
) > 1 then
4722 '0': g_debug_BotAIOff
:= 0;
4723 '1': g_debug_BotAIOff
:= 1;
4724 '2': g_debug_BotAIOff
:= 2;
4725 '3': g_debug_BotAIOff
:= 3;
4728 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4730 else if cmd
= 'd_monster' then
4732 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4733 if Length(P
) < 2 then
4735 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4736 g_Console_Add('ID | Name');
4737 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4738 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4741 a
:= StrToIntDef(P
[1], 0);
4742 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4743 a
:= g_Monsters_GetIDByName(P
[1]);
4745 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4746 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4749 with gPlayer1
.Obj
do
4750 b
:= g_Monsters_Create(a
,
4751 X
+ Rect
.X
+ (Rect
.Width
div 2),
4752 Y
+ Rect
.Y
+ Rect
.Height
,
4753 gPlayer1
.Direction
, True);
4754 if (Length(P
) > 2) and (b
>= 0) then
4755 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4759 else if (cmd
= 'd_health') then
4761 if (Length(P
) > 1) and
4762 ((P
[1] = '1') or (P
[1] = '0')) then
4763 g_debug_HealthBar
:= (P
[1][1] = '1');
4765 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4767 else if (cmd
= 'd_player') then
4769 if (Length(P
) > 1) and
4770 ((P
[1] = '1') or (P
[1] = '0')) then
4771 g_debug_Player
:= (P
[1][1] = '1');
4773 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4775 else if (cmd
= 'd_joy') then
4778 g_Console_Add(e_JoystickStateToString(a
));
4782 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4786 procedure GameCheats(P
: SArray
);
4792 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4793 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4795 g_Console_Add('not available');
4801 g_Console_Add('where is the player?!');
4804 cmd
:= LowerCase(P
[0]);
4808 plr
.GodMode
:= not plr
.GodMode
;
4809 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4812 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4813 if cmd
= 'give' then
4815 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4816 for f
:= 1 to High(P
) do
4818 cmd
:= LowerCase(P
[f
]);
4819 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4820 if (cmd
= 'all') or (cmd
= 'weapons') then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4821 if cmd
= 'exit' then
4823 if gTriggers
<> nil then
4825 for a
:= 0 to High(gTriggers
) do
4827 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4829 g_Console_Add('player left the map');
4830 gExitByTrigger
:= True;
4831 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4838 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4839 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got jetpack'); continue
; end;
4840 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got envirosuit'); continue
; end;
4841 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got berserk pack'); continue
; end;
4842 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4847 if cmd
= 'open' then
4849 g_Console_Add('player activated sesame');
4850 g_Triggers_OpenAll();
4857 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4861 if cmd
= 'noclip' then
4864 g_Console_Add('wall hardeness adjusted');
4868 if cmd
= 'notarget' then
4870 plr
.NoTarget
:= not plr
.NoTarget
;
4871 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4875 if cmd
= 'noreload' then
4877 plr
.NoReload
:= not plr
.NoReload
;
4878 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4882 if cmd
= 'speedy' then
4884 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4885 g_Console_Add('speed adjusted');
4889 if cmd
= 'jumpy' then
4891 VEL_JUMP
:= 30-VEL_JUMP
;
4892 g_Console_Add('jump height adjusted');
4896 if cmd
= 'automap' then
4898 gShowMap
:= not gShowMap
;
4899 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4903 if cmd
= 'aimline' then
4905 gAimLine
:= not gAimLine
;
4906 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4911 procedure GameCommands(P
: SArray
);
4917 pl
: pTNetClient
= nil;
4924 cmd
:= LowerCase(P
[0]);
4926 if (cmd
= 'quit') or
4933 else if cmd
= 'pause' then
4935 if (g_ActiveWindow
= nil) then
4936 g_Game_Pause(not gPause
);
4938 else if cmd
= 'endgame' then
4939 gExit
:= EXIT_SIMPLE
4940 else if cmd
= 'restart' then
4942 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4944 if g_Game_IsClient
then
4946 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4951 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4953 else if cmd
= 'kick' then
4955 if g_Game_IsServer
then
4957 if Length(P
) < 2 then
4959 g_Console_Add('kick <name>');
4964 g_Console_Add('kick <name>');
4968 if g_Game_IsNet
then
4969 pl
:= g_Net_Client_ByName(P
[1]);
4972 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4973 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4974 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4975 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4976 if NetUseMaster
then
4978 end else if gPlayers
<> nil then
4979 for a
:= Low(gPlayers
) to High(gPlayers
) do
4980 if gPlayers
[a
] <> nil then
4981 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4983 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4984 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4986 gPlayers
[a
].Lives
:= 0;
4987 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4988 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4989 g_Player_Remove(gPlayers
[a
].UID
);
4990 if NetUseMaster
then
4992 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4996 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4998 else if cmd
= 'kick_id' then
5000 if g_Game_IsServer
and g_Game_IsNet
then
5002 if Length(P
) < 2 then
5004 g_Console_Add('kick_id <client ID>');
5009 g_Console_Add('kick_id <client ID>');
5013 a
:= StrToIntDef(P
[1], 0);
5014 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5016 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5018 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5019 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5020 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5021 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5022 if NetUseMaster
then
5027 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5029 else if cmd
= 'ban' then
5031 if g_Game_IsServer
and g_Game_IsNet
then
5033 if Length(P
) < 2 then
5035 g_Console_Add('ban <name>');
5040 g_Console_Add('ban <name>');
5044 pl
:= g_Net_Client_ByName(P
[1]);
5047 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5048 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5049 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5050 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5051 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5052 if NetUseMaster
then
5055 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5057 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5059 else if cmd
= 'ban_id' then
5061 if g_Game_IsServer
and g_Game_IsNet
then
5063 if Length(P
) < 2 then
5065 g_Console_Add('ban_id <client ID>');
5070 g_Console_Add('ban_id <client ID>');
5074 a
:= StrToIntDef(P
[1], 0);
5075 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5076 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5078 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5079 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5080 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5081 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5082 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5083 if NetUseMaster
then
5087 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5089 else if cmd
= 'permban' then
5091 if g_Game_IsServer
and g_Game_IsNet
then
5093 if Length(P
) < 2 then
5095 g_Console_Add('permban <name>');
5100 g_Console_Add('permban <name>');
5104 pl
:= g_Net_Client_ByName(P
[1]);
5107 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5108 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5109 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5110 g_Net_SaveBanList();
5111 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5112 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5113 if NetUseMaster
then
5116 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5118 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5120 else if cmd
= 'permban_id' then
5122 if g_Game_IsServer
and g_Game_IsNet
then
5124 if Length(P
) < 2 then
5126 g_Console_Add('permban_id <client ID>');
5131 g_Console_Add('permban_id <client ID>');
5135 a
:= StrToIntDef(P
[1], 0);
5136 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5137 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5139 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5140 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5141 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5142 g_Net_SaveBanList();
5143 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5144 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5145 if NetUseMaster
then
5149 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5151 else if cmd
= 'unban' then
5153 if g_Game_IsServer
and g_Game_IsNet
then
5155 if Length(P
) < 2 then
5157 g_Console_Add('unban <IP Address>');
5162 g_Console_Add('unban <IP Address>');
5166 if g_Net_UnbanHost(P
[1]) then
5168 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5169 g_Net_SaveBanList();
5171 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5173 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5175 else if cmd
= 'clientlist' then
5177 if g_Game_IsServer
and g_Game_IsNet
then
5180 if NetClients
<> nil then
5181 for a
:= Low(NetClients
) to High(NetClients
) do
5182 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5184 plr
:= g_Player_Get(NetClients
[a
].Player
);
5185 if plr
= nil then continue
;
5187 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5188 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5191 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5193 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5195 else if cmd
= 'connect' then
5197 if (NetMode
= NET_NONE
) then
5199 if Length(P
) < 2 then
5201 g_Console_Add('connect <IP> [port] [password]');
5206 g_Console_Add('connect <IP> [port] [password]');
5210 if Length(P
) > 2 then
5211 prt
:= StrToIntDef(P
[2], 25666)
5215 if Length(P
) > 3 then
5220 g_Game_StartClient(P
[1], prt
, pw
);
5223 else if cmd
= 'disconnect' then
5225 if (NetMode
= NET_CLIENT
) then
5228 else if cmd
= 'reconnect' then
5230 if (NetMode
= NET_SERVER
) then
5233 if (NetMode
= NET_CLIENT
) then
5236 gExit
:= EXIT_SIMPLE
;
5240 //TODO: Use last successful password to reconnect, instead of ''
5241 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5243 else if (cmd
= 'addbot') or
5244 (cmd
= 'bot_add') then
5246 if Length(P
) > 1 then
5247 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5249 g_Bot_Add(TEAM_NONE
, 2);
5251 else if cmd
= 'bot_addlist' then
5253 if Length(P
) > 1 then
5254 if Length(P
) = 2 then
5255 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5257 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5259 else if cmd
= 'bot_removeall' then
5261 else if cmd
= 'chat' then
5263 if g_Game_IsNet
then
5265 if Length(P
) > 1 then
5267 for a
:= 1 to High(P
) do
5268 chstr
:= chstr
+ P
[a
] + ' ';
5270 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5272 if Length(chstr
) < 1 then
5274 g_Console_Add('chat <text>');
5278 chstr
:= b_Text_Format(chstr
);
5279 if g_Game_IsClient
then
5280 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5282 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5285 g_Console_Add('chat <text>');
5287 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5289 else if cmd
= 'teamchat' then
5291 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5293 if Length(P
) > 1 then
5295 for a
:= 1 to High(P
) do
5296 chstr
:= chstr
+ P
[a
] + ' ';
5298 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5300 if Length(chstr
) < 1 then
5302 g_Console_Add('teamchat <text>');
5306 chstr
:= b_Text_Format(chstr
);
5307 if g_Game_IsClient
then
5308 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5310 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5311 gPlayer1Settings
.Team
);
5314 g_Console_Add('teamchat <text>');
5316 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5318 else if cmd
= 'game' then
5320 if gGameSettings
.GameType
<> GT_NONE
then
5322 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5325 if Length(P
) = 1 then
5327 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5330 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5331 P
[1] := addWadExtension(P
[1]);
5332 if FileExists(MapsDir
+ P
[1]) then
5334 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5335 if Length(P
) < 3 then
5338 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5341 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5343 if g_Map_Exist(MapsDir
+ s
) then
5345 // Çàïóñêàåì ñâîþ èãðó
5347 with gGameSettings
do
5349 GameMode
:= g_Game_TextToMode(gcGameMode
);
5350 if gSwitchGameMode
<> GM_NONE
then
5351 GameMode
:= gSwitchGameMode
;
5352 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5353 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5355 if Length(P
) >= 4 then
5356 b
:= StrToIntDef(P
[3], 1);
5357 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5358 GoalLimit
, MaxLives
, Options
, b
);
5363 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5365 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5367 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5369 else if cmd
= 'host' then
5371 if gGameSettings
.GameType
<> GT_NONE
then
5373 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5376 if Length(P
) < 4 then
5378 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5381 if not StrToIp(P
[1], listen
) then
5383 prt
:= StrToIntDef(P
[2], 25666);
5385 P
[3] := addWadExtension(P
[3]);
5386 if FileExists(MapsDir
+ P
[3]) then
5388 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5389 if Length(P
) < 5 then
5392 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5395 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5397 if g_Map_Exist(MapsDir
+ s
) then
5399 // Çàïóñêàåì ñâîþ èãðó
5401 with gGameSettings
do
5403 GameMode
:= g_Game_TextToMode(gcGameMode
);
5404 if gSwitchGameMode
<> GM_NONE
then
5405 GameMode
:= gSwitchGameMode
;
5406 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5407 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5409 if Length(P
) >= 6 then
5410 b
:= StrToIntDef(P
[5], 0);
5411 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5412 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5417 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5419 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5421 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5423 else if cmd
= 'map' then
5425 if Length(P
) = 1 then
5427 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5429 g_Console_Add(cmd
+ ' <MAP>');
5430 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5432 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5434 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5436 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5437 if Length(P
) < 3 then
5439 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5440 s
:= UpperCase(P
[1]);
5441 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5442 begin // Êàðòà íàøëàñü
5443 gExitByTrigger
:= False;
5445 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5447 gExit
:= EXIT_ENDLEVELCUSTOM
;
5449 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5450 g_Game_ChangeMap(s
);
5453 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5454 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5455 P
[1] := addWadExtension(P
[1]);
5456 if FileExists(MapsDir
+ P
[1]) then
5458 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5460 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5462 s
:= P
[1] + ':\' + P
[2];
5464 if g_Map_Exist(MapsDir
+ s
) then
5466 gExitByTrigger
:= False;
5468 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5470 gExit
:= EXIT_ENDLEVELCUSTOM
;
5472 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5473 g_Game_ChangeMap(s
);
5476 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5478 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5480 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5484 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5485 P
[1] := addWadExtension(P
[1]);
5486 if FileExists(MapsDir
+ P
[1]) then
5489 P
[2] := UpperCase(P
[2]);
5490 s
:= P
[1] + ':\' + P
[2];
5492 if g_Map_Exist(MapsDir
+ s
) then
5493 begin // Íàøëè êàðòó
5494 gExitByTrigger
:= False;
5496 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5498 gExit
:= EXIT_ENDLEVELCUSTOM
;
5500 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5501 g_Game_ChangeMap(s
);
5503 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5505 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5508 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5510 else if cmd
= 'nextmap' then
5512 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5513 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5516 if Length(P
) = 1 then
5518 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5520 g_Console_Add(cmd
+ ' <MAP>');
5521 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5524 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5529 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5531 if Length(P
) < 3 then
5533 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5534 s
:= UpperCase(P
[1]);
5535 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5536 begin // Êàðòà íàøëàñü
5537 gExitByTrigger
:= False;
5542 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5543 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5544 P
[1] := addWadExtension(P
[1]);
5545 if FileExists(MapsDir
+ P
[1]) then
5547 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5549 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5551 s
:= P
[1] + ':\' + P
[2];
5553 if g_Map_Exist(MapsDir
+ s
) then
5554 begin // Óñòàíàâëèâàåì êàðòó
5555 gExitByTrigger
:= False;
5560 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5562 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5564 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5568 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5569 P
[1] := addWadExtension(P
[1]);
5570 if FileExists(MapsDir
+ P
[1]) then
5573 P
[2] := UpperCase(P
[2]);
5574 s
:= P
[1] + ':\' + P
[2];
5576 if g_Map_Exist(MapsDir
+ s
) then
5577 begin // Íàøëè êàðòó
5578 gExitByTrigger
:= False;
5582 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5584 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5587 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5590 if gNextMap
= '' then
5591 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5593 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5596 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5599 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5601 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5603 gExitByTrigger
:= False;
5604 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5605 if (gNextMap
= '') and (gTriggers
<> nil) then
5606 for a
:= 0 to High(gTriggers
) do
5607 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5609 gExitByTrigger
:= True;
5610 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5613 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5614 if gNextMap
= '' then
5615 gNextMap
:= g_Game_GetNextMap();
5616 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5617 if Pos(':\', gNextMap
) = 0 then
5618 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5621 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5622 if g_Map_Exist(MapsDir
+ s
) then
5623 gExit
:= EXIT_ENDLEVELCUSTOM
5625 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5627 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5629 else if (cmd
= 'event') then
5631 if (Length(P
) <= 1) then
5633 for a
:= 0 to High(gEvents
) do
5634 if gEvents
[a
].Command
= '' then
5635 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5637 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5640 if (Length(P
) = 2) then
5642 for a
:= 0 to High(gEvents
) do
5643 if gEvents
[a
].Name
= P
[1] then
5644 if gEvents
[a
].Command
= '' then
5645 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5647 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5650 for a
:= 0 to High(gEvents
) do
5651 if gEvents
[a
].Name
= P
[1] then
5653 gEvents
[a
].Command
:= '';
5654 for b
:= 2 to High(P
) do
5655 if Pos(' ', P
[b
]) = 0 then
5656 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5658 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5659 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5663 // Êîìàíäû Ñâîåé èãðû:
5664 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5666 if cmd
= 'bot_addred' then
5668 if Length(P
) > 1 then
5669 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5671 g_Bot_Add(TEAM_RED
, 2);
5673 else if cmd
= 'bot_addblue' then
5675 if Length(P
) > 1 then
5676 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5678 g_Bot_Add(TEAM_BLUE
, 2);
5680 else if cmd
= 'suicide' then
5684 if g_Game_IsClient
then
5685 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5688 if gPlayer1
<> nil then
5689 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5690 if gPlayer2
<> nil then
5691 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5695 else if cmd
= 'spectate' then
5701 else if cmd
= 'say' then
5703 if g_Game_IsServer
and g_Game_IsNet
then
5705 if Length(P
) > 1 then
5708 for a
:= 1 to High(P
) do
5709 chstr
:= chstr
+ P
[a
] + ' ';
5711 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5713 if Length(chstr
) < 1 then
5715 g_Console_Add('say <text>');
5719 chstr
:= b_Text_Format(chstr
);
5720 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5722 else g_Console_Add('say <text>');
5724 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5726 else if cmd
= 'tell' then
5728 if g_Game_IsServer
and g_Game_IsNet
then
5730 if (Length(P
) > 2) and (P
[1] <> '') then
5733 for a
:= 2 to High(P
) do
5734 chstr
:= chstr
+ P
[a
] + ' ';
5736 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5738 if Length(chstr
) < 1 then
5740 g_Console_Add('tell <playername> <text>');
5744 pl
:= g_Net_Client_ByName(P
[1]);
5746 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5748 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5750 else g_Console_Add('tell <playername> <text>');
5752 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5754 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5756 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5758 // Äîïîëíèòåëüíîå âðåìÿ:
5759 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5761 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5762 [gGameSettings
.TimeLimit
div 3600,
5763 (gGameSettings
.TimeLimit
div 60) mod 60,
5764 gGameSettings
.TimeLimit
mod 60]));
5765 if g_Game_IsNet
then MH_SEND_GameSettings
;
5767 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5769 if (Length(P
) <= 1) then
5770 g_Console_Add('rcon_password <password>')
5772 MC_SEND_RCONPassword(P
[1]);
5774 else if cmd
= 'rcon' then
5776 if g_Game_IsClient
then
5778 if Length(P
) > 1 then
5781 for a
:= 1 to High(P
) do
5782 chstr
:= chstr
+ P
[a
] + ' ';
5784 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5786 if Length(chstr
) < 1 then
5788 g_Console_Add('rcon <command>');
5792 MC_SEND_RCONCommand(chstr
);
5794 else g_Console_Add('rcon <command>');
5797 else if cmd
= 'ready' then
5799 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5800 gLMSRespawnTime
:= gTime
+ 100;
5802 else if (cmd
= 'callvote') and g_Game_IsNet
then
5804 if Length(P
) > 1 then
5807 for a
:= 1 to High(P
) do begin
5808 if a
> 1 then chstr
:= chstr
+ ' ';
5809 chstr
:= chstr
+ P
[a
];
5812 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5814 if Length(chstr
) < 1 then
5816 g_Console_Add('callvote <command>');
5820 if g_Game_IsClient
then
5821 MC_SEND_Vote(True, chstr
)
5823 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5824 g_Console_Process('vote', True);
5827 g_Console_Add('callvote <command>');
5829 else if (cmd
= 'vote') and g_Game_IsNet
then
5831 if g_Game_IsClient
then
5833 else if gVoteInProgress
then
5835 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5836 a
:= Floor((NetClientCount
+1)/2.0) + 1
5838 a
:= Floor(NetClientCount
/2.0) + 1;
5843 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5844 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5850 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5851 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5859 procedure g_TakeScreenShot();
5867 if e_NoGraphics
then Exit
;
5868 ssdir
:= GameDir
+'/screenshots';
5869 if not findFileCI(ssdir
, true) then
5871 // try to create dir
5876 if not findFileCI(ssdir
, true) then exit
; // alas
5879 for a
:= 1 to High(Word) do
5881 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5883 if findFileCI(t
, true) then continue
;
5884 if not findFileCI(FileName
) then
5887 st
:= createDiskFile(FileName
);
5889 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5894 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5902 procedure g_Game_InGameMenu(Show
: Boolean);
5904 if (g_ActiveWindow
= nil) and Show
then
5906 if gGameSettings
.GameType
= GT_SINGLE
then
5907 g_GUI_ShowWindow('GameSingleMenu')
5910 if g_Game_IsClient
then
5911 g_GUI_ShowWindow('GameClientMenu')
5913 if g_Game_IsNet
then
5914 g_GUI_ShowWindow('GameServerMenu')
5916 g_GUI_ShowWindow('GameCustomMenu');
5918 g_Sound_PlayEx('MENU_OPEN');
5920 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5921 if (not g_Game_IsNet
) then
5925 if (g_ActiveWindow
<> nil) and (not Show
) then
5927 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5928 if (not g_Game_IsNet
) then
5929 g_Game_Pause(False);
5933 procedure g_Game_Pause(Enable
: Boolean);
5938 if gPause
= Enable
then
5941 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5945 g_Game_PauseAllSounds(Enable
);
5948 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5953 if gTriggers
<> nil then
5954 for i
:= 0 to High(gTriggers
) do
5955 with gTriggers
[i
] do
5956 if (TriggerType
= TRIGGER_SOUND
) and
5958 Sound
.IsPlaying() then
5960 Sound
.Pause(Enable
);
5964 if gPlayers
<> nil then
5965 for i
:= 0 to High(gPlayers
) do
5966 if gPlayers
[i
] <> nil then
5967 gPlayers
[i
].PauseSounds(Enable
);
5970 if gMusic
<> nil then
5971 gMusic
.Pause(Enable
);
5974 procedure g_Game_StopAllSounds(all
: Boolean);
5978 if gTriggers
<> nil then
5979 for i
:= 0 to High(gTriggers
) do
5980 with gTriggers
[i
] do
5981 if (TriggerType
= TRIGGER_SOUND
) and
5985 if gMusic
<> nil then
5992 procedure g_Game_UpdateTriggerSounds();
5996 if gTriggers
<> nil then
5997 for i
:= 0 to High(gTriggers
) do
5998 with gTriggers
[i
] do
5999 if (TriggerType
= TRIGGER_SOUND
) and
6002 Sound
.IsPlaying() then
6004 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6005 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6007 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6008 Sound
.SetVolume(Data
.Volume
/255.0);
6011 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6015 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6018 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6023 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6028 if gSpectMode
<> SPECT_PLAYERS
then
6030 if gSpectPID1
= UID
then
6035 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6042 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6047 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6052 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6057 if gSpectMode
<> SPECT_PLAYERS
then
6059 Pl
:= g_Player_Get(gSpectPID1
);
6060 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6065 if gSpectViewTwo
then
6067 Pl
:= g_Player_Get(gSpectPID2
);
6068 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6076 procedure g_Game_Message(Msg
: string; Time
: Word);
6078 MessageText
:= b_Text_Format(Msg
);
6079 MessageTime
:= Time
;
6082 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6091 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6095 if goodsnd
[a
].IsPlaying() then
6098 goodsnd
[Random(4)].Play();
6101 procedure g_Game_Announce_KillCombo(Param
: Integer);
6108 UID
:= Param
and $FFFF;
6113 Pl
:= g_Player_Get(UID
);
6122 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6126 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6130 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6134 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6142 if not g_Game_IsWatchedPlayer(UID
) then
6145 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6149 if killsnd
[n
].IsPlaying() then
6154 procedure g_Game_StartVote(Command
, Initiator
: string);
6158 if not gVotesEnabled
then Exit
;
6159 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6160 if gVoteInProgress
or gVotePassed
then
6162 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6163 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6166 gVoteInProgress
:= True;
6167 gVotePassed
:= False;
6168 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6171 gVoteCommand
:= Command
;
6173 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6174 Need
:= Floor((NetClientCount
+1)/2.0)+1
6176 Need
:= Floor(NetClientCount
/2.0)+1;
6177 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6178 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6181 procedure g_Game_CheckVote
;
6185 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6186 if not gVoteInProgress
then Exit
;
6188 if (gTime
>= gVoteTimer
) then
6190 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6191 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6193 Need
:= Floor(NetClientCount
/2.0) + 1;
6194 if gVoteCount
>= Need
then
6196 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6197 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6198 gVotePassed
:= True;
6199 gVoteCmdTimer
:= gTime
+ 5000;
6203 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6204 MH_SEND_VoteEvent(NET_VE_FAILED
);
6206 if NetClients
<> nil then
6207 for I
:= Low(NetClients
) to High(NetClients
) do
6208 if NetClients
[i
].Used
then
6209 NetClients
[i
].Voted
:= False;
6210 gVoteInProgress
:= False;
6216 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6217 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6219 Need
:= Floor(NetClientCount
/2.0) + 1;
6220 if gVoteCount
>= Need
then
6222 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6223 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6224 gVoteInProgress
:= False;
6225 gVotePassed
:= True;
6226 gVoteCmdTimer
:= gTime
+ 5000;
6229 if NetClients
<> nil then
6230 for I
:= Low(NetClients
) to High(NetClients
) do
6231 if NetClients
[i
].Used
then
6232 NetClients
[i
].Voted
:= False;
6237 procedure g_Game_LoadMapList(FileName
: string);
6245 if not FileExists(FileName
) then Exit
;
6247 AssignFile(ListFile
, FileName
);
6249 while not EOF(ListFile
) do
6251 ReadLn(ListFile
, s
);
6254 if s
= '' then Continue
;
6256 SetLength(MapList
, Length(MapList
)+1);
6257 MapList
[High(MapList
)] := s
;
6259 CloseFile(ListFile
);
6262 procedure g_Game_SetDebugMode();
6265 // ×èòû (äàæå â ñâîåé èãðå):
6269 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6273 if Length(LoadingStat
.Msgs
) = 0 then
6279 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6280 if NextMsg
= Length(Msgs
) then
6282 for i
:= 0 to High(Msgs
)-1 do
6283 Msgs
[i
] := Msgs
[i
+1];
6291 Msgs
[NextMsg
-1] := Text;
6297 g_ActiveWindow
:= nil;
6302 procedure g_Game_StepLoading();
6308 if (ShowCount
> LOADING_SHOW_STEP
) then
6316 procedure g_Game_ClearLoading();
6325 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6326 if len
< 1 then len
:= 1;
6327 SetLength(Msgs
, len
);
6328 for len
:= Low(Msgs
) to High(Msgs
) do
6334 procedure Parse_Params(var pars
: TParamStrValues
);
6341 while i
<= ParamCount
do
6344 if (s
[1] = '-') and (Length(s
) > 1) then
6346 if (s
[2] = '-') and (Length(s
) > 2) then
6347 begin // Îäèíî÷íûé ïàðàìåòð
6348 SetLength(pars
, Length(pars
) + 1);
6349 with pars
[High(pars
)] do
6351 Name
:= LowerCase(s
);
6356 if (i
< ParamCount
) then
6357 begin // Ïàðàìåòð ñî çíà÷åíèåì
6359 SetLength(pars
, Length(pars
) + 1);
6360 with pars
[High(pars
)] do
6362 Name
:= LowerCase(s
);
6363 Value
:= LowerCase(ParamStr(i
));
6372 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6377 for i
:= 0 to High(pars
) do
6378 if pars
[i
].Name
= aName
then
6380 Result
:= pars
[i
].Value
;
6385 procedure g_Game_Process_Params();
6387 pars
: TParamStrValues
;
6390 LimT
, LimS
: Integer;
6401 s
:= Find_Param_Value(pars
, '--debug');
6403 g_Game_SetDebugMode();
6405 // Connect when game loads
6406 ip
:= Find_Param_Value(pars
, '-connect');
6410 s
:= Find_Param_Value(pars
, '-port');
6411 if (s
= '') or not TryStrToInt(s
, Port
) then
6414 s
:= Find_Param_Value(pars
, '-pw');
6416 g_Game_StartClient(ip
, Port
, s
);
6420 // Start map when game loads:
6421 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6422 if isWadPath(map
) then
6425 s
:= Find_Param_Value(pars
, '-gm');
6426 GMode
:= g_Game_TextToMode(s
);
6427 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6428 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6431 s
:= Find_Param_Value(pars
, '-limt');
6432 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6438 s
:= Find_Param_Value(pars
, '-lims');
6439 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6445 s
:= Find_Param_Value(pars
, '-lives');
6446 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6452 s
:= Find_Param_Value(pars
, '-opt');
6454 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6456 Opt
:= StrToIntDef(s
, 0);
6458 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6461 s
:= Find_Param_Value(pars
, '--close');
6465 // Delete test map after play:
6466 s
:= Find_Param_Value(pars
, '--testdelete');
6469 gMapToDelete
:= MapsDir
+ map
;
6470 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6474 // Delete temporary WAD after play:
6475 s
:= Find_Param_Value(pars
, '--tempdelete');
6478 gMapToDelete
:= MapsDir
+ map
;
6479 gTempDelete
:= True;
6482 // Number of players:
6483 s
:= Find_Param_Value(pars
, '-pl');
6487 n
:= StrToIntDef(s
, 1);
6490 s
:= Find_Param_Value(pars
, '-port');
6491 if (s
= '') or not TryStrToInt(s
, Port
) then
6492 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6494 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6497 // Execute script when game loads:
6498 s
:= Find_Param_Value(pars
, '-exec');
6501 if Pos(':\', s
) = 0 then
6502 s
:= GameDir
+ '/' + s
;
6507 if IOResult
<> 0 then
6509 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6510 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6514 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6515 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6520 if IOResult
<> 0 then
6522 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6523 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6527 if Pos('#', s
) <> 1 then // script comment
6528 g_Console_Process(s
, True);