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
1286 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1290 procedure g_Game_Update();
1292 Msg
: g_gui
.TMessage
;
1298 // Ïîðà âûêëþ÷àòü èãðó:
1299 if gExit
= EXIT_QUIT
then
1301 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1305 if gExit
= EXIT_QUIT
then
1309 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1312 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1315 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1317 gExit
:= EXIT_SIMPLE
;
1323 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1324 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1325 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1326 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1328 if g_Game_IsNet
and g_Game_IsServer
then
1330 gInterTime
:= gInterTime
+ GAME_TICK
;
1331 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1332 if a
<> gServInterTime
then
1334 gServInterTime
:= a
;
1335 MH_SEND_TimeSync(gServInterTime
);
1339 if (not g_Game_IsClient
) and
1342 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1343 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1344 and (g_ActiveWindow
= nil)
1346 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1349 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1350 g_Game_StopAllSounds(True);
1352 if gMapOnce
then // Ýòî áûë òåñò
1353 gExit
:= EXIT_SIMPLE
1355 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1356 g_Game_ChangeMap(gNextMap
)
1357 else // Ñëåäóþùåé êàðòû íåò
1359 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1361 // Âûõîä â ãëàâíîå ìåíþ:
1363 g_GUI_ShowWindow('MainMenu');
1364 gMusic
.SetByName('MUSIC_MENU');
1366 gState
:= STATE_MENU
;
1369 // Ôèíàëüíàÿ êàðòèíêà:
1370 g_Game_ExecuteEvent('onwadend');
1372 if not gMusic
.SetByName('MUSIC_endmus') then
1373 gMusic
.SetByName('MUSIC_STDENDMUS');
1375 gState
:= STATE_ENDPIC
;
1377 g_Game_ExecuteEvent('ongameend');
1383 if gState
= STATE_INTERTEXT
then
1384 if InterText
.counter
> 0 then
1385 InterText
.counter
:= InterText
.counter
- 1;
1388 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1390 if EndingGameCounter
= 0 then
1392 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1393 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1395 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1397 g_Game_ExecuteEvent('onwadend');
1398 if not gMusic
.SetByName('MUSIC_endmus') then
1399 gMusic
.SetByName('MUSIC_STDENDMUS');
1402 gMusic
.SetByName('MUSIC_ROUNDMUS');
1405 gState
:= STATE_INTERCUSTOM
;
1407 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1409 gMusic
.SetByName('MUSIC_INTERMUS');
1411 gState
:= STATE_INTERSINGLE
;
1413 g_Game_ExecuteEvent('oninter');
1416 DecMin(EndingGameCounter
, 6, 0);
1419 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1421 if gMapOnce
then // Ýòî áûë òåñò
1423 gExit
:= EXIT_SIMPLE
;
1429 g_Serverlist_Control(slCurrent
);
1432 if g_Game_IsNet
then
1433 if not gConsoleShow
then
1434 if not gChatShow
then
1436 if g_ActiveWindow
= nil then
1438 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1439 g_Console_Chat_Switch(False)
1440 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1441 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1442 g_Console_Chat_Switch(True);
1445 if not gChatEnter
then
1446 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1447 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1450 // Ñòàòèñòèêà ïî Tab:
1452 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1453 (gGameSettings
.GameType
<> GT_SINGLE
) and
1454 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1457 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1459 // Âðåìÿ += 28 ìèëëèñåêóíä:
1460 gTime
:= gTime
+ GAME_TICK
;
1462 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1463 if MessageTime
= 0 then
1465 if MessageTime
> 0 then
1466 MessageTime
:= MessageTime
- 1;
1468 if (g_Game_IsServer
) then
1470 // Áûë çàäàí ëèìèò âðåìåíè:
1471 if (gGameSettings
.TimeLimit
> 0) then
1472 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1473 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1478 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1479 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1480 g_Game_RestartRound(gLMSSoftSpawn
);
1482 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1483 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1485 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1487 g_Console_Process(gVoteCommand
);
1489 gVotePassed
:= False;
1492 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1493 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1494 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1495 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1496 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1498 // Áûë çàäàí ëèìèò ïîáåä:
1499 if (gGameSettings
.GoalLimit
> 0) then
1503 if gGameSettings
.GameMode
= GM_DM
then
1504 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1505 for i
:= 0 to High(gPlayers
) do
1506 if gPlayers
[i
] <> nil then
1507 if gPlayers
[i
].Frags
> b
then
1508 b
:= gPlayers
[i
].Frags
;
1511 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1512 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1513 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1516 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1517 if b
>= gGameSettings
.GoalLimit
then
1524 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1525 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1526 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1527 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1529 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1530 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1531 end // if not console
1534 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1536 // process weapon switch queue
1540 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1541 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1543 if not gSpectKeyPress
then
1545 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1547 // switch spect mode
1549 SPECT_NONE
: ; // not spectator
1551 SPECT_MAPVIEW
: Inc(gSpectMode
);
1552 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1554 gSpectKeyPress
:= True;
1556 if gSpectMode
= SPECT_MAPVIEW
then
1558 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1559 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1560 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1561 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1562 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1563 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1564 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1565 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1566 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1569 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1570 gSpectKeyPress
:= True;
1572 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1575 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1576 gSpectKeyPress
:= True;
1579 if gSpectMode
= SPECT_PLAYERS
then
1581 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1584 gSpectViewTwo
:= True;
1585 gSpectKeyPress
:= True;
1587 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1589 // remove second view
1590 gSpectViewTwo
:= False;
1591 gSpectKeyPress
:= True;
1593 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1595 // prev player (view 1)
1596 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1597 gSpectKeyPress
:= True;
1599 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1601 // next player (view 1)
1602 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1603 gSpectKeyPress
:= True;
1605 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1607 // prev player (view 2)
1608 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1609 gSpectKeyPress
:= True;
1611 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1613 // next player (view 2)
1614 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1615 gSpectKeyPress
:= True;
1620 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1621 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1622 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1623 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1624 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1625 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1626 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1627 gSpectKeyPress
:= False;
1630 // Îáíîâëÿåì âñå îñòàëüíîå:
1633 g_Triggers_Update();
1635 g_Monsters_Update();
1637 g_Player_UpdateAll();
1638 g_Player_UpdatePhysicalObjects();
1639 if gGameSettings
.GameType
= GT_SERVER
then
1640 if Length(gMonstersSpawned
) > 0 then
1642 for I
:= 0 to High(gMonstersSpawned
) do
1643 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1644 SetLength(gMonstersSpawned
, 0);
1647 if (gSoundTriggerTime
> 8) then
1649 g_Game_UpdateTriggerSounds();
1650 gSoundTriggerTime
:= 0;
1653 Inc(gSoundTriggerTime
);
1655 if (NetMode
= NET_SERVER
) then
1657 Inc(NetTimeToUpdate
);
1658 Inc(NetTimeToReliable
);
1659 if NetTimeToReliable
>= NetRelupdRate
then
1661 for I
:= 0 to High(gPlayers
) do
1662 if gPlayers
[I
] <> nil then
1663 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1665 if gMonsters
<> nil then
1666 for I
:= 0 to High(gMonsters
) do
1667 if gMonsters
[I
] <> nil then
1669 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1671 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1672 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1675 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1676 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1677 (gMonsters
[I
].GameVelX
<> 0) or
1678 (gMonsters
[I
].GameVelY
<> 0) then
1679 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1682 NetTimeToReliable
:= 0;
1683 NetTimeToUpdate
:= NetUpdateRate
;
1685 else if NetTimeToUpdate
>= NetUpdateRate
then
1687 if gPlayers
<> nil then
1688 for I
:= 0 to High(gPlayers
) do
1689 if gPlayers
[I
] <> nil then
1690 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1692 if gMonsters
<> nil then
1693 for I
:= 0 to High(gMonsters
) do
1694 if gMonsters
[I
] <> nil then
1696 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1698 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1699 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1702 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1703 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1704 (gMonsters
[I
].GameVelX
<> 0) or
1705 (gMonsters
[I
].GameVelY
<> 0) then
1706 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1709 NetTimeToUpdate
:= 0;
1712 if NetUseMaster
then
1713 if gTime
>= NetTimeToMaster
then
1715 if (NetMHost
= nil) or (NetMPeer
= nil) then
1716 if not g_Net_Slist_Connect
then
1717 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1720 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1724 if NetMode
= NET_CLIENT
then
1725 MC_SEND_PlayerPos();
1726 end; // if gameOn ...
1728 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1729 if g_ActiveWindow
<> nil then
1731 w
:= e_GetFirstKeyPressed();
1733 if (w
<> IK_INVALID
) then
1735 Msg
.Msg
:= MESSAGE_DIKEY
;
1737 g_ActiveWindow
.OnMessage(Msg
);
1740 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1741 if g_ActiveWindow
<> nil then
1742 g_ActiveWindow
.Update();
1744 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1745 if gResolutionChange
then
1747 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1748 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1749 gResolutionChange
:= False;
1752 // Íóæíî ñìåíèòü ÿçûê:
1753 if gLanguageChange
then
1755 //e_WriteLog('Read language file', MSG_NOTIFY);
1756 //g_Language_Load(DataDir + gLanguage + '.txt');
1757 g_Language_Set(gLanguage
);
1759 gLanguageChange
:= False;
1763 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1764 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1765 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1768 LastScreenShot
:= GetTimer();
1771 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1772 if e_KeyPressed(IK_F10
) and
1774 (not gConsoleShow
) and
1775 (g_ActiveWindow
= nil) then
1780 Time
:= GetTimer() {div 1000};
1782 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1783 if gDelayedEvents
<> nil then
1784 for a
:= 0 to High(gDelayedEvents
) do
1785 if gDelayedEvents
[a
].Pending
and
1787 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1788 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1791 case gDelayedEvents
[a
].DEType
of
1793 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1796 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1800 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1801 if g_Game_IsNet
and g_Game_IsServer
then
1802 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1805 gDelayedEvents
[a
].Pending
:= False;
1808 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1809 UPSCounter
:= UPSCounter
+ 1;
1810 if Time
- UPSTime
>= 1000 then
1818 procedure g_Game_LoadData();
1820 if DataLoaded
then Exit
;
1822 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1824 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1825 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1826 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1827 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1828 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1829 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1830 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1831 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1832 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1833 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1834 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1835 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1836 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1837 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1838 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1839 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1840 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1841 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1842 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1843 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1844 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1845 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1846 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1847 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1848 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1849 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1850 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1851 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1852 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1853 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1854 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1855 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1856 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1857 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1859 goodsnd
[0] := TPlayableSound
.Create();
1860 goodsnd
[1] := TPlayableSound
.Create();
1861 goodsnd
[2] := TPlayableSound
.Create();
1862 goodsnd
[3] := TPlayableSound
.Create();
1864 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1865 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1866 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1867 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1869 killsnd
[0] := TPlayableSound
.Create();
1870 killsnd
[1] := TPlayableSound
.Create();
1871 killsnd
[2] := TPlayableSound
.Create();
1872 killsnd
[3] := TPlayableSound
.Create();
1874 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1875 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1876 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1877 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1879 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1882 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1883 g_Weapon_LoadData();
1885 g_Monsters_LoadData();
1890 procedure g_Game_FreeData();
1892 if not DataLoaded
then Exit
;
1895 g_Weapon_FreeData();
1896 g_Monsters_FreeData();
1898 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1900 g_Texture_Delete('NOTEXTURE');
1901 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1902 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1903 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1904 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1905 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1906 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1907 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1908 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1909 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1910 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1911 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1912 g_Frames_DeleteByName('FRAMES_TELEPORT');
1913 g_Sound_Delete('SOUND_GAME_TELEPORT');
1914 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1915 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1916 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1917 g_Sound_Delete('SOUND_GAME_BULK1');
1918 g_Sound_Delete('SOUND_GAME_BULK2');
1919 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1920 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1921 g_Sound_Delete('SOUND_GAME_SWITCH1');
1922 g_Sound_Delete('SOUND_GAME_SWITCH0');
1929 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1930 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1931 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1932 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1939 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1940 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1941 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1942 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1944 DataLoaded
:= False;
1947 procedure DrawCustomStat();
1953 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1954 s1
, s2
, topstr
: String;
1956 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1959 if e_KeyPressed(IK_TAB
) then
1961 if not gStatsPressed
then
1963 gStatsOff
:= not gStatsOff
;
1964 gStatsPressed
:= True;
1968 gStatsPressed
:= False;
1972 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1973 w
:= (Length(s1
) * ww2
) div 2;
1974 x
:= gScreenWidth
div 2 - w
;
1976 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1980 if (gGameSettings
.GameMode
= GM_COOP
) then
1982 if gMissionFailed
then
1983 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1985 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1988 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1990 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1991 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
1993 if g_Game_IsNet
then
1995 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
1996 if not gChatShow
then
1997 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1998 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2001 if g_Game_IsClient
then
2002 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2004 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2005 if not gChatShow
then
2006 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2007 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2012 w
:= gScreenWidth
-x
*2;
2018 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2019 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2021 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2023 case CustomStat
.GameMode
of
2026 if gGameSettings
.MaxLives
= 0 then
2027 s1
:= _lc
[I_GAME_DM
]
2029 s1
:= _lc
[I_GAME_LMS
];
2033 if gGameSettings
.MaxLives
= 0 then
2034 s1
:= _lc
[I_GAME_TDM
]
2036 s1
:= _lc
[I_GAME_TLMS
];
2038 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2041 if gGameSettings
.MaxLives
= 0 then
2042 s1
:= _lc
[I_GAME_COOP
]
2044 s1
:= _lc
[I_GAME_SURV
];
2050 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2054 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2055 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2058 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2059 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2060 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2061 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2063 pc
:= Length(CustomStat
.PlayerStat
);
2064 if pc
= 0 then Exit
;
2066 if CustomStat
.GameMode
= GM_COOP
then
2068 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2070 s2
:= _lc
[I_GAME_MONSTERS
];
2071 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2072 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2074 s2
:= _lc
[I_GAME_SECRETS
];
2075 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2076 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2079 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2081 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2082 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2083 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2085 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2086 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2087 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2091 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2096 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2097 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2098 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2100 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2103 for t
:= TEAM_RED
to TEAM_BLUE
do
2105 if t
= TEAM_RED
then
2107 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2108 gStdFont
, 255, 0, 0, 1);
2109 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2110 gStdFont
, 255, 0, 0, 1);
2117 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2118 gStdFont
, 0, 0, 255, 1);
2119 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2120 gStdFont
, 0, 0, 255, 1);
2126 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2129 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2130 if CustomStat
.PlayerStat
[p
].Team
= t
then
2131 with CustomStat
.PlayerStat
[p
] do
2145 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2146 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2147 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2154 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2157 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2158 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2159 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2162 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2163 with CustomStat
.PlayerStat
[p
] do
2165 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2172 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2173 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2174 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2180 procedure DrawSingleStat();
2182 tm
, key_x
, val_x
, y
: Integer;
2186 procedure player_stat(n
: Integer);
2192 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2193 s2
:= Format(' %d', [gTotalMonsters
]);
2195 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2196 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2197 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2198 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2200 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2201 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2203 // "Kills-per-minute: ##.#":
2204 s1
:= _lc
[I_MENU_INTER_KPM
];
2206 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2208 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2209 s2
:= Format(' %.1f', [kpm
]);
2211 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2212 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2214 // "Secrets found: # / #":
2215 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2216 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2218 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2219 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2220 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2221 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2223 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2224 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2228 // "Level Complete":
2229 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2230 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2232 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2233 s1
:= _lc
[I_MENU_INTER_KPM
];
2234 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2237 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2239 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2240 val_x
:= key_x
+ w1
;
2243 tm
:= SingleStat
.GameTime
div 1000;
2244 s1
:= _lc
[I_MENU_INTER_TIME
];
2245 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2247 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2248 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2250 if SingleStat
.TwoPlayers
then
2253 s1
:= _lc
[I_MENU_PLAYER_1
];
2254 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2255 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2257 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2262 s1
:= _lc
[I_MENU_PLAYER_2
];
2263 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2264 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2266 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2272 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2278 procedure DrawLoadingStat();
2284 if Length(LoadingStat
.Msgs
) = 0 then
2287 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2288 yy
:= (gScreenHeight
div 3);
2289 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2290 xx
:= (gScreenWidth
div 3);
2293 for i
:= 0 to NextMsg
-1 do
2295 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2296 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2300 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2301 yy
:= yy
+ LOADING_INTERLINE
;
2305 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2307 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2309 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2310 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2313 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2314 ScaleSz
:= 16 div Scale
;
2315 // Ðàçìåðû ìèíè-êàðòû:
2316 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2317 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2319 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2321 if gWalls
<> nil then
2324 for a
:= 0 to High(gWalls
) do
2326 if PanelType
<> 0 then
2328 // Ëåâûé âåðõíèé óãîë:
2329 aX
:= X
div ScaleSz
;
2330 aY
:= Y
div ScaleSz
;
2332 aX2
:= max(Width
div ScaleSz
, 1);
2333 aY2
:= max(Height
div ScaleSz
, 1);
2334 // Ïðàâûé íèæíèé óãîë:
2335 aX2
:= aX
+ aX2
- 1;
2336 aY2
:= aY
+ aY2
- 1;
2339 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2340 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2341 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2345 if gSteps
<> nil then
2348 for a
:= 0 to High(gSteps
) do
2350 if PanelType
<> 0 then
2352 // Ëåâûé âåðõíèé óãîë:
2353 aX
:= X
div ScaleSz
;
2354 aY
:= Y
div ScaleSz
;
2356 aX2
:= max(Width
div ScaleSz
, 1);
2357 aY2
:= max(Height
div ScaleSz
, 1);
2358 // Ïðàâûé íèæíèé óãîë:
2359 aX2
:= aX
+ aX2
- 1;
2360 aY2
:= aY
+ aY2
- 1;
2362 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2365 if gLifts
<> nil then
2368 for a
:= 0 to High(gLifts
) do
2370 if PanelType
<> 0 then
2372 // Ëåâûé âåðõíèé óãîë:
2373 aX
:= X
div ScaleSz
;
2374 aY
:= Y
div ScaleSz
;
2376 aX2
:= max(Width
div ScaleSz
, 1);
2377 aY2
:= max(Height
div ScaleSz
, 1);
2378 // Ïðàâûé íèæíèé óãîë:
2379 aX2
:= aX
+ aX2
- 1;
2380 aY2
:= aY
+ aY2
- 1;
2383 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2384 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2385 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2386 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2390 if gWater
<> nil then
2393 for a
:= 0 to High(gWater
) do
2395 if PanelType
<> 0 then
2397 // Ëåâûé âåðõíèé óãîë:
2398 aX
:= X
div ScaleSz
;
2399 aY
:= Y
div ScaleSz
;
2401 aX2
:= max(Width
div ScaleSz
, 1);
2402 aY2
:= max(Height
div ScaleSz
, 1);
2403 // Ïðàâûé íèæíèé óãîë:
2404 aX2
:= aX
+ aX2
- 1;
2405 aY2
:= aY
+ aY2
- 1;
2407 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2410 if gAcid1
<> nil then
2412 // Ðèñóåì êèñëîòó 1:
2413 for a
:= 0 to High(gAcid1
) do
2415 if PanelType
<> 0 then
2417 // Ëåâûé âåðõíèé óãîë:
2418 aX
:= X
div ScaleSz
;
2419 aY
:= Y
div ScaleSz
;
2421 aX2
:= max(Width
div ScaleSz
, 1);
2422 aY2
:= max(Height
div ScaleSz
, 1);
2423 // Ïðàâûé íèæíèé óãîë:
2424 aX2
:= aX
+ aX2
- 1;
2425 aY2
:= aY
+ aY2
- 1;
2427 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2430 if gAcid2
<> nil then
2432 // Ðèñóåì êèñëîòó 2:
2433 for a
:= 0 to High(gAcid2
) do
2435 if PanelType
<> 0 then
2437 // Ëåâûé âåðõíèé óãîë:
2438 aX
:= X
div ScaleSz
;
2439 aY
:= Y
div ScaleSz
;
2441 aX2
:= max(Width
div ScaleSz
, 1);
2442 aY2
:= max(Height
div ScaleSz
, 1);
2443 // Ïðàâûé íèæíèé óãîë:
2444 aX2
:= aX
+ aX2
- 1;
2445 aY2
:= aY
+ aY2
- 1;
2447 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2450 if gPlayers
<> nil then
2453 for a
:= 0 to High(gPlayers
) do
2454 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2456 // Ëåâûé âåðõíèé óãîë:
2457 aX
:= Obj
.X
div ScaleSz
+ 1;
2458 aY
:= Obj
.Y
div ScaleSz
+ 1;
2460 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2461 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2462 // Ïðàâûé íèæíèé óãîë:
2463 aX2
:= aX
+ aX2
- 1;
2464 aY2
:= aY
+ aY2
- 1;
2466 if gPlayers
[a
] = p
then
2467 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2470 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2471 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2472 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2476 if gMonsters
<> nil then
2479 for a
:= 0 to High(gMonsters
) do
2480 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2482 // Ëåâûé âåðõíèé óãîë:
2483 aX
:= Obj
.X
div ScaleSz
+ 1;
2484 aY
:= Obj
.Y
div ScaleSz
+ 1;
2486 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2487 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2488 // Ïðàâûé íèæíèé óãîë:
2489 aX2
:= aX
+ aX2
- 1;
2490 aY2
:= aY
+ aY2
- 1;
2492 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2498 procedure DrawMapView(x
, y
, w
, h
: Integer);
2504 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2505 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2506 g_Map_DrawBack(-bx
, -by
);
2513 glTranslatef(-x
, -y
, 0);
2515 g_Map_BuildPVP(sX
, sY
, sX
+sWidth
-1, sY
+sHeight
-1);
2516 g_Map_DrawPanels(PANEL_BACK
);
2517 g_Map_DrawPanels(PANEL_STEP
);
2520 g_Player_DrawShells();
2522 g_Player_DrawCorpses();
2523 g_Map_DrawPanels(PANEL_WALL
);
2525 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2528 g_Map_DrawPanels(PANEL_ACID1
);
2529 g_Map_DrawPanels(PANEL_ACID2
);
2530 g_Map_DrawPanels(PANEL_WATER
);
2531 g_Map_DrawPanels(PANEL_FORE
);
2532 if g_debug_HealthBar
then
2534 g_Monsters_DrawHealth();
2535 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_BuildPVP(sX
, sY
, sX
+sWidth
-1, sY
+sHeight
-1);
2633 g_Map_DrawPanels(PANEL_BACK
);
2634 g_Map_DrawPanels(PANEL_STEP
);
2637 g_Player_DrawShells();
2639 g_Player_DrawCorpses();
2640 g_Map_DrawPanels(PANEL_WALL
);
2642 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2645 g_Map_DrawPanels(PANEL_ACID1
);
2646 g_Map_DrawPanels(PANEL_ACID2
);
2647 g_Map_DrawPanels(PANEL_WATER
);
2648 g_Map_DrawPanels(PANEL_FORE
);
2649 if g_debug_HealthBar
then
2651 g_Monsters_DrawHealth();
2652 g_Player_DrawHealth();
2655 if p
.FSpectator
then
2656 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2657 p
.GameY
+ PLAYER_RECT_CY
- 4,
2658 'X', gStdFont
, 255, 255, 255, 1, True);
2660 for a := 0 to High(gCollideMap) do
2661 for b := 0 to High(gCollideMap[a]) do
2664 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2666 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2670 1: e_DrawPoint(1, b, a, 200, 200, 200);
2671 2: e_DrawPoint(1, b, a, 64, 64, 255);
2672 3: e_DrawPoint(1, b, a, 255, 0, 255);
2683 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2684 if g_Debug_Player
then
2685 g_Player_DrawDebug(p
);
2689 procedure g_Game_Draw();
2696 plView1
, plView2
: TPlayer
;
2699 if gExit
= EXIT_QUIT
then Exit
;
2701 Time
:= GetTimer() {div 1000};
2702 FPSCounter
:= FPSCounter
+1;
2703 if Time
- FPSTime
>= 1000 then
2710 if gGameOn
or (gState
= STATE_FOLD
) then
2712 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2714 gSpectMode
:= SPECT_NONE
;
2715 if not gRevertPlayers
then
2717 plView1
:= gPlayer1
;
2718 plView2
:= gPlayer2
;
2722 plView1
:= gPlayer2
;
2723 plView2
:= gPlayer1
;
2727 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2729 gSpectMode
:= SPECT_NONE
;
2730 if gPlayer2
= nil then
2733 plView1
:= gPlayer2
;
2742 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2743 gSpectMode
:= SPECT_STATS
;
2745 if gSpectMode
= SPECT_PLAYERS
then
2746 if gPlayers
<> nil then
2748 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2749 if plView1
= nil then
2751 gSpectPID1
:= GetActivePlayerID_Next();
2752 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2754 if gSpectViewTwo
then
2756 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2757 if plView2
= nil then
2759 gSpectPID2
:= GetActivePlayerID_Next();
2760 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2765 if gSpectMode
= SPECT_MAPVIEW
then
2767 // Ðåæèì ïðîñìîòðà êàðòû
2769 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2770 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2771 gHearPoint1
.Active
:= True;
2772 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2773 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2774 gHearPoint2
.Active
:= False;
2778 Split
:= (plView1
<> nil) and (plView2
<> nil);
2780 // Òî÷êè ñëóõà èãðîêîâ
2781 if plView1
<> nil then
2783 gHearPoint1
.Active
:= True;
2784 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2785 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2787 gHearPoint1
.Active
:= False;
2788 if plView2
<> nil then
2790 gHearPoint2
.Active
:= True;
2791 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2792 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2794 gHearPoint2
.Active
:= False;
2796 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2797 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2800 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2801 if gScreenHeight
mod 2 = 0 then
2802 Dec(gPlayerScreenSize
.Y
);
2805 gPlayerScreenSize
.Y
:= gScreenHeight
;
2808 if gScreenHeight
mod 2 = 0 then
2809 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2811 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2813 DrawPlayer(plView1
);
2814 gPlayer1ScreenCoord
.X
:= sX
;
2815 gPlayer1ScreenCoord
.Y
:= sY
;
2819 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2821 DrawPlayer(plView2
);
2822 gPlayer2ScreenCoord
.X
:= sX
;
2823 gPlayer2ScreenCoord
.Y
:= sY
;
2826 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2829 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2832 if MessageText
<> '' then
2836 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2838 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2839 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2841 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2842 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2845 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2847 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2849 // Draw spectator GUI
2852 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2855 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2857 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2859 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2861 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2862 if gSpectMode
= SPECT_MAPVIEW
then
2864 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2865 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2866 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2867 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2868 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2870 if gSpectMode
= SPECT_PLAYERS
then
2872 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2873 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2874 if gSpectViewTwo
then
2876 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2877 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2878 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2879 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2883 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2884 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2890 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2892 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2894 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2895 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2896 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2901 if (gState
= STATE_MENU
) then
2903 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2905 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2906 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2907 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2909 if g_ActiveWindow
<> nil then
2910 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2913 if gState
= STATE_FOLD
then
2914 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2916 if gState
= STATE_INTERCUSTOM
then
2918 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2920 back
:= 'TEXTURE_endpic';
2921 if not g_Texture_Get(back
, ID
) then
2922 back
:= _lc
[I_TEXTURE_ENDPIC
];
2927 if g_Texture_Get(back
, ID
) then
2928 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2930 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2934 if g_ActiveWindow
<> nil then
2935 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2938 if gState
= STATE_INTERSINGLE
then
2940 if EndingGameCounter
> 0 then
2941 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2946 if g_Texture_Get(back
, ID
) then
2947 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2949 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2953 if g_ActiveWindow
<> nil then
2954 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2958 if gState
= STATE_ENDPIC
then
2961 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2962 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2964 if ID
<> DWORD(-1) then
2965 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2967 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2969 if g_ActiveWindow
<> nil then
2970 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2973 if gState
= STATE_SLIST
then
2975 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2977 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2978 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2980 g_Serverlist_Draw(slCurrent
);
2984 if g_ActiveWindow
<> nil then
2987 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2988 g_ActiveWindow
.Draw();
2993 if g_debug_Sounds
and gGameOn
then
2995 for w
:= 0 to High(e_SoundsArray
) do
2996 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2997 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3002 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3003 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3006 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3007 e_TextureFontPrint(gScreenWidth
-72, 0,
3008 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3012 procedure g_Game_Quit();
3014 g_Game_StopAllSounds(True);
3016 g_Game_SaveOptions();
3018 g_PlayerModel_FreeData();
3019 g_Texture_DeleteAll();
3020 g_Frames_DeleteAll();
3023 if NetInitDone
then g_Net_Free
;
3025 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3026 if gMapToDelete
<> '' then
3027 g_Game_DeleteTestMap();
3033 procedure g_FatalError(Text: String);
3035 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3036 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3038 gExit
:= EXIT_SIMPLE
;
3041 procedure g_SimpleError(Text: String);
3043 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3044 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3047 procedure g_Game_SetupScreenSize();
3051 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3052 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3053 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3054 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3056 gPlayerScreenSize
.Y
:= gScreenHeight
;
3058 // Ðàçìåð çàäíåãî ïëàíà:
3059 if BackID
<> DWORD(-1) then
3063 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3064 (gScreenHeight
*d
> gMapInfo
.Height
) then
3067 gBackSize
.X
:= Round(gScreenWidth
*d
);
3068 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3072 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3074 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3077 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3079 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3080 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3082 if gPlayer1
= nil then
3084 if g_Game_IsClient
then
3086 if NetPlrUID1
> -1 then
3088 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3089 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3094 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3095 Team
:= gPlayer1Settings
.Team
;
3097 // Ñîçäàíèå ïåðâîãî èãðîêà:
3098 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3099 gPlayer1Settings
.Color
,
3101 if gPlayer1
= nil then
3102 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3105 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3106 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3107 if g_Game_IsServer
and g_Game_IsNet
then
3108 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3109 gPlayer1
.Respawn(False, True);
3111 if g_Game_IsNet
and NetUseMaster
then
3117 if gPlayer2
= nil then
3119 if g_Game_IsClient
then
3121 if NetPlrUID2
> -1 then
3122 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3126 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3127 Team
:= gPlayer2Settings
.Team
;
3129 // Ñîçäàíèå âòîðîãî èãðîêà:
3130 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3131 gPlayer2Settings
.Color
,
3133 if gPlayer2
= nil then
3134 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3137 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3138 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3139 if g_Game_IsServer
and g_Game_IsNet
then
3140 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3141 gPlayer2
.Respawn(False, True);
3143 if g_Game_IsNet
and NetUseMaster
then
3151 procedure g_Game_RemovePlayer();
3155 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3156 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3161 if g_Game_IsServer
then
3164 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3165 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3166 g_Player_Remove(Pl
.UID
);
3168 if g_Game_IsNet
and NetUseMaster
then
3177 if g_Game_IsServer
then
3180 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3181 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3182 g_Player_Remove(Pl
.UID
);
3184 if g_Game_IsNet
and NetUseMaster
then
3189 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3195 procedure g_Game_Spectate();
3197 g_Game_RemovePlayer();
3198 if gPlayer1
<> nil then
3199 g_Game_RemovePlayer();
3202 procedure g_Game_SpectateCenterView();
3204 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3205 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3208 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3214 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3216 g_Game_ClearLoading();
3219 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3222 gGameSettings
.GameType
:= GT_SINGLE
;
3223 gGameSettings
.MaxLives
:= 0;
3224 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3225 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3226 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3227 gSwitchGameMode
:= GM_SINGLE
;
3229 g_Game_ExecuteEvent('ongamestart');
3231 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3232 g_Game_SetupScreenSize();
3234 // Ñîçäàíèå ïåðâîãî èãðîêà:
3235 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3236 gPlayer1Settings
.Color
,
3237 gPlayer1Settings
.Team
, False));
3238 if gPlayer1
= nil then
3240 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3244 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3247 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3250 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3251 gPlayer2Settings
.Color
,
3252 gPlayer2Settings
.Team
, False));
3253 if gPlayer2
= nil then
3255 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3259 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3263 // Çàãðóçêà è çàïóñê êàðòû:
3264 if not g_Game_StartMap(MAP
, True) then
3266 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3270 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3274 for i
:= nPl
+1 to nPlayers
do
3275 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3278 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3279 TimeLimit
, GoalLimit
: Word;
3281 Options
: LongWord; nPlayers
: Byte);
3287 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3289 g_Game_ClearLoading();
3292 gGameSettings
.GameType
:= GT_CUSTOM
;
3293 gGameSettings
.GameMode
:= GameMode
;
3294 gSwitchGameMode
:= GameMode
;
3295 gGameSettings
.TimeLimit
:= TimeLimit
;
3296 gGameSettings
.GoalLimit
:= GoalLimit
;
3297 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3298 gGameSettings
.Options
:= Options
;
3300 gCoopTotalMonstersKilled
:= 0;
3301 gCoopTotalSecretsFound
:= 0;
3302 gCoopTotalMonsters
:= 0;
3303 gCoopTotalSecrets
:= 0;
3307 g_Game_ExecuteEvent('ongamestart');
3309 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3310 g_Game_SetupScreenSize();
3312 // Ðåæèì íàáëþäàòåëÿ:
3313 if nPlayers
= 0 then
3320 if nPlayers
>= 1 then
3322 // Ñîçäàíèå ïåðâîãî èãðîêà:
3323 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3324 gPlayer1Settings
.Color
,
3325 gPlayer1Settings
.Team
, False));
3326 if gPlayer1
= nil then
3328 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3332 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3336 if nPlayers
>= 2 then
3338 // Ñîçäàíèå âòîðîãî èãðîêà:
3339 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3340 gPlayer2Settings
.Color
,
3341 gPlayer2Settings
.Team
, False));
3342 if gPlayer2
= nil then
3344 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3348 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3352 // Çàãðóçêà è çàïóñê êàðòû:
3353 if not g_Game_StartMap(Map
, True) then
3355 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3359 // Íåò òî÷åê ïîÿâëåíèÿ:
3360 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3361 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3362 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3363 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3364 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3366 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3370 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3374 for i
:= nPl
+1 to nPlayers
do
3375 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3378 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3379 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3380 Options
: LongWord; nPlayers
: Byte;
3381 IPAddr
: LongWord; Port
: Word);
3385 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3387 g_Game_ClearLoading();
3390 gGameSettings
.GameType
:= GT_SERVER
;
3391 gGameSettings
.GameMode
:= GameMode
;
3392 gSwitchGameMode
:= GameMode
;
3393 gGameSettings
.TimeLimit
:= TimeLimit
;
3394 gGameSettings
.GoalLimit
:= GoalLimit
;
3395 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3396 gGameSettings
.Options
:= Options
;
3398 gCoopTotalMonstersKilled
:= 0;
3399 gCoopTotalSecretsFound
:= 0;
3400 gCoopTotalMonsters
:= 0;
3401 gCoopTotalSecrets
:= 0;
3405 g_Game_ExecuteEvent('ongamestart');
3407 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3408 g_Game_SetupScreenSize();
3410 // Ðåæèì íàáëþäàòåëÿ:
3411 if nPlayers
= 0 then
3417 if nPlayers
>= 1 then
3419 // Ñîçäàíèå ïåðâîãî èãðîêà:
3420 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3421 gPlayer1Settings
.Color
,
3422 gPlayer1Settings
.Team
, False));
3423 if gPlayer1
= nil then
3425 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3429 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3432 if nPlayers
>= 2 then
3434 // Ñîçäàíèå âòîðîãî èãðîêà:
3435 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3436 gPlayer2Settings
.Color
,
3437 gPlayer2Settings
.Team
, False));
3438 if gPlayer2
= nil then
3440 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3444 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3448 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3450 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3454 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3456 // Çàãðóçêà è çàïóñê êàðòû:
3457 if not g_Game_StartMap(Map
, True) then
3459 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3463 // Íåò òî÷åê ïîÿâëåíèÿ:
3464 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3465 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3466 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3467 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3468 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3470 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3474 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3477 NetState
:= NET_STATE_GAME
;
3480 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3494 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3495 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3497 g_Game_ClearLoading();
3500 gGameSettings
.GameType
:= GT_CLIENT
;
3502 gCoopTotalMonstersKilled
:= 0;
3503 gCoopTotalSecretsFound
:= 0;
3504 gCoopTotalMonsters
:= 0;
3505 gCoopTotalSecrets
:= 0;
3509 g_Game_ExecuteEvent('ongamestart');
3511 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3512 g_Game_SetupScreenSize();
3514 NetState
:= NET_STATE_AUTH
;
3516 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3518 if not g_Net_Connect(Addr
, Port
) then
3520 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3521 NetState
:= NET_STATE_NONE
;
3525 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3527 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3532 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3534 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3536 Ptr
:= NetEvent
.packet
^.data
;
3539 MID
:= e_Raw_Read_Byte(Ptr
);
3541 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3543 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3544 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3546 WadName
:= e_Raw_Read_String(Ptr
);
3547 Map
:= e_Raw_Read_String(Ptr
);
3549 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3551 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3552 gSwitchGameMode
:= gGameSettings
.GameMode
;
3553 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3554 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3555 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3556 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3557 T
:= e_Raw_Read_LongWord(Ptr
);
3559 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3560 if newResPath
= '' then
3562 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3563 newResPath
:= g_Res_DownloadWAD(WadName
);
3564 if newResPath
= '' then
3566 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3567 enet_packet_destroy(NetEvent
.packet
);
3568 NetState
:= NET_STATE_NONE
;
3572 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3574 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3575 gPlayer1Settings
.Color
,
3576 gPlayer1Settings
.Team
, False));
3578 if gPlayer1
= nil then
3580 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3582 enet_packet_destroy(NetEvent
.packet
);
3583 NetState
:= NET_STATE_NONE
;
3587 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3588 gPlayer1
.UID
:= NetPlrUID1
;
3589 gPlayer1
.Reset(True);
3591 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3593 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3595 enet_packet_destroy(NetEvent
.packet
);
3596 NetState
:= NET_STATE_NONE
;
3604 enet_packet_destroy(NetEvent
.packet
);
3608 enet_packet_destroy(NetEvent
.packet
);
3611 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3614 if (NetEvent
.data
<= NET_DISC_MAX
) then
3615 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3616 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3626 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3635 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3636 NetState
:= NET_STATE_NONE
;
3640 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3641 gLMSRespawnTime
:= 0;
3644 NetState
:= NET_STATE_GAME
;
3645 MC_SEND_FullStateRequest
;
3646 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3649 procedure g_Game_SaveOptions();
3651 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3654 procedure g_Game_ChangeMap(MapPath
: String);
3658 g_Game_ClearLoading();
3660 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3661 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3662 if gExitByTrigger
then
3665 gExitByTrigger
:= False;
3667 if not g_Game_StartMap(MapPath
, Force
) then
3668 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3671 procedure g_Game_Restart();
3675 if g_Game_IsClient
then
3677 map
:= g_ExtractFileName(gMapInfo
.Map
);
3681 g_Game_ClearLoading();
3682 g_Game_StartMap(Map
, True);
3685 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3687 NewWAD
, ResName
: String;
3691 g_Player_RemoveAllCorpses();
3693 if (not g_Game_IsClient
) and
3694 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3695 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3697 if gSwitchGameMode
= GM_CTF
then
3698 gGameSettings
.MaxLives
:= 0;
3699 gGameSettings
.GameMode
:= gSwitchGameMode
;
3702 gSwitchGameMode
:= gGameSettings
.GameMode
;
3704 g_Player_ResetTeams();
3706 if Pos(':\', Map
) > 0 then
3708 NewWAD
:= g_ExtractWadName(Map
);
3709 ResName
:= g_ExtractFileName(Map
);
3710 if g_Game_IsServer
then
3712 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3713 g_Game_LoadWAD(NewWAD
);
3715 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3716 g_Game_ClientWAD(NewWAD
, gWADHash
);
3720 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3723 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3725 gState
:= STATE_NONE
;
3726 g_ActiveWindow
:= nil;
3732 if gGameSettings
.GameMode
= GM_CTF
then
3734 g_Map_ResetFlag(FLAG_RED
);
3735 g_Map_ResetFlag(FLAG_BLUE
);
3736 // CTF, à ôëàãîâ íåò:
3737 if not g_Map_HaveFlagPoints() then
3738 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3743 gState
:= STATE_MENU
;
3750 NetTimeToUpdate
:= 1;
3751 NetTimeToReliable
:= 0;
3752 NetTimeToMaster
:= NetMasterRate
;
3753 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3754 gLMSRespawnTime
:= 0;
3755 gMissionFailed
:= False;
3758 gCoopMonstersKilled
:= 0;
3759 gCoopSecretsFound
:= 0;
3761 gVoteInProgress
:= False;
3762 gVotePassed
:= False;
3768 if not gGameOn
then Exit
;
3770 g_Game_SpectateCenterView();
3772 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3774 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3775 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3776 gLMSSoftSpawn
:= True;
3777 if NetMode
= NET_SERVER
then
3778 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3780 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3783 if NetMode
= NET_SERVER
then
3785 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3788 if NetUseMaster
then
3790 if (NetMHost
= nil) or (NetMPeer
= nil) then
3791 if not g_Net_Slist_Connect
then
3792 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3797 if NetClients
<> nil then
3798 for I
:= 0 to High(NetClients
) do
3799 if NetClients
[I
].Used
then
3801 NetClients
[I
].Voted
:= False;
3802 if NetClients
[I
].RequestedFullUpdate
then
3804 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3805 NetClients
[I
].RequestedFullUpdate
:= False;
3809 g_Net_UnbanNonPermHosts();
3814 gCoopTotalMonstersKilled
:= 0;
3815 gCoopTotalSecretsFound
:= 0;
3816 gCoopTotalMonsters
:= 0;
3817 gCoopTotalSecrets
:= 0;
3821 g_Game_ExecuteEvent('onmapstart');
3824 procedure SetFirstLevel();
3828 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3829 if MapList
= nil then
3832 SortSArray(MapList
);
3833 gNextMap
:= MapList
[Low(MapList
)];
3838 procedure g_Game_ExitLevel(Map
: Char16
);
3842 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3843 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3844 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3845 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3847 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3848 if gGameSettings
.GameType
= GT_SINGLE
then
3849 gExit
:= EXIT_ENDLEVELSINGLE
3850 else // Âûøëè â âûõîä â Ñâîåé èãðå
3852 gExit
:= EXIT_ENDLEVELCUSTOM
;
3853 if gGameSettings
.GameMode
= GM_COOP
then
3854 g_Player_RememberAll
;
3856 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3859 if gGameSettings
.GameMode
= GM_COOP
then
3862 gStatsPressed
:= True;
3863 gNextMap
:= 'MAP01';
3865 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3868 if g_Game_IsNet
then
3870 MH_SEND_GameStats();
3871 MH_SEND_CoopStats();
3877 procedure g_Game_RestartLevel();
3881 if gGameSettings
.GameMode
= GM_SINGLE
then
3886 gExit
:= EXIT_ENDLEVELCUSTOM
;
3887 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3891 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3895 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3897 if not g_Game_IsClient
then
3899 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3902 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3903 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3907 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3911 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3912 g_Game_LoadWAD(NewWAD
);
3915 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3917 i
, n
, nb
, nr
: Integer;
3919 if not g_Game_IsServer
then Exit
;
3920 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3921 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3922 gLMSRespawnTime
:= 0;
3925 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3927 gMissionFailed
:= True;
3928 g_Game_RestartLevel
;
3932 n
:= 0; nb
:= 0; nr
:= 0;
3933 for i
:= Low(gPlayers
) to High(gPlayers
) do
3934 if (gPlayers
[i
] <> nil) and
3935 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3936 (gPlayers
[i
] is TBot
)) then
3939 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3940 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3943 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3945 // wait a second until the fuckers finally decide to join
3946 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3947 gLMSRespawnTime
:= gTime
+ 1000;
3948 gLMSSoftSpawn
:= NoMapRestart
;
3952 g_Player_RemoveAllCorpses
;
3953 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3954 if g_Game_IsNet
then
3955 MH_SEND_GameEvent(NET_EV_LMS_START
);
3957 for i
:= Low(gPlayers
) to High(gPlayers
) do
3959 if gPlayers
[i
] = nil then continue
;
3960 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3961 // don't touch normal spectators
3962 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3964 gPlayers
[i
].FNoRespawn
:= True;
3965 gPlayers
[i
].Lives
:= 0;
3966 if g_Game_IsNet
then
3967 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3970 gPlayers
[i
].FNoRespawn
:= False;
3971 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3972 gPlayers
[i
].Respawn(False, True);
3973 if gGameSettings
.GameMode
= GM_COOP
then
3975 gPlayers
[i
].Frags
:= 0;
3976 gPlayers
[i
].RecallState
;
3978 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3979 gPlayer1
:= g_Player_Get(gLMSPID1
);
3980 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3981 gPlayer2
:= g_Player_Get(gLMSPID2
);
3984 for i
:= Low(gItems
) to High(gItems
) do
3986 if gItems
[i
].Respawnable
then
3988 gItems
[i
].QuietRespawn
:= True;
3989 gItems
[i
].RespawnTime
:= 0;
3994 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3998 for i
:= Low(gMonsters
) to High(gMonsters
) do
4000 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
4001 gMonsters
[i
].Respawn
;
4004 gLMSSoftSpawn
:= False;
4007 function g_Game_GetFirstMap(WAD
: String): String;
4011 MapList
:= g_Map_GetMapsList(WAD
);
4012 if MapList
= nil then
4015 SortSArray(MapList
);
4016 Result
:= MapList
[Low(MapList
)];
4018 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4024 function g_Game_GetNextMap(): String;
4031 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4032 if MapList
= nil then
4035 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4037 SortSArray(MapList
);
4039 for I
:= Low(MapList
) to High(MapList
) do
4040 if Map
= MapList
[I
] then
4046 if MapIndex
<> -255 then
4048 if MapIndex
= High(MapList
) then
4049 Result
:= MapList
[Low(MapList
)]
4051 Result
:= MapList
[MapIndex
+ 1];
4053 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4059 procedure g_Game_NextLevel();
4061 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4062 gExit
:= EXIT_ENDLEVELCUSTOM
4065 gExit
:= EXIT_ENDLEVELSINGLE
;
4069 if gNextMap
<> '' then Exit
;
4070 gNextMap
:= g_Game_GetNextMap();
4073 function g_Game_IsTestMap(): Boolean;
4075 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4078 procedure g_Game_DeleteTestMap();
4089 a
:= Pos('.wad:\', gMapToDelete
);
4093 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4094 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4095 Delete(gMapToDelete
, 1, a
+ 5);
4096 gMapToDelete
:= UpperCase(gMapToDelete
);
4098 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4101 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4102 if MapName <> TEST_MAP_NAME then
4105 if not gTempDelete then
4107 time := g_GetFileTime(WadName);
4108 WAD := TWADFile.Create();
4111 if not WAD.ReadFile(WadName) then
4112 begin // Íåò òàêîãî WAD-ôàéëà
4117 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4119 MapList := WAD.GetResourcesList('');
4121 if MapList <> nil then
4122 for a := 0 to High(MapList) do
4123 if MapList[a] = MapName then
4125 // Óäàëÿåì è ñîõðàíÿåì:
4126 WAD.RemoveResource('', MapName);
4127 WAD.SaveTo(WadName);
4132 g_SetFileTime(WadName, time);
4135 if gTempDelete
then DeleteFile(WadName
);
4138 procedure GameCVars(P
: SArray
);
4141 stat
: TPlayerStatArray
;
4146 cmd
:= LowerCase(P
[0]);
4147 if cmd
= 'r_showfps' then
4149 if (Length(P
) > 1) and
4150 ((P
[1] = '1') or (P
[1] = '0')) then
4151 gShowFPS
:= (P
[1][1] = '1');
4154 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4156 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4158 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4160 with gGameSettings
do
4162 if (Length(P
) > 1) and
4163 ((P
[1] = '1') or (P
[1] = '0')) then
4165 if (P
[1][1] = '1') then
4166 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4168 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4171 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4172 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4174 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4176 if g_Game_IsNet
then MH_SEND_GameSettings
;
4179 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4181 with gGameSettings
do
4183 if (Length(P
) > 1) and
4184 ((P
[1] = '1') or (P
[1] = '0')) then
4186 if (P
[1][1] = '1') then
4187 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4189 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4192 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4193 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4195 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4197 if g_Game_IsNet
then MH_SEND_GameSettings
;
4200 else if cmd
= 'g_gamemode' then
4202 a
:= g_Game_TextToMode(P
[1]);
4203 if a
= GM_SINGLE
then a
:= GM_COOP
;
4204 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4206 gSwitchGameMode
:= a
;
4207 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4208 (gState
= STATE_INTERSINGLE
) then
4209 gSwitchGameMode
:= GM_SINGLE
;
4211 gGameSettings
.GameMode
:= gSwitchGameMode
;
4213 if gSwitchGameMode
= gGameSettings
.GameMode
then
4214 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4215 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4217 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4218 [g_Game_ModeToText(gGameSettings
.GameMode
),
4219 g_Game_ModeToText(gSwitchGameMode
)]));
4221 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4223 with gGameSettings
do
4225 if (Length(P
) > 1) and
4226 ((P
[1] = '1') or (P
[1] = '0')) then
4228 if (P
[1][1] = '1') then
4229 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4231 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4234 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4235 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4237 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4238 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4240 if g_Game_IsNet
then MH_SEND_GameSettings
;
4243 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4245 with gGameSettings
do
4247 if (Length(P
) > 1) and
4248 ((P
[1] = '1') or (P
[1] = '0')) then
4250 if (P
[1][1] = '1') then
4251 Options
:= Options
or GAME_OPTION_MONSTERS
4253 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4256 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4257 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4259 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4260 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4262 if g_Game_IsNet
then MH_SEND_GameSettings
;
4265 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4267 with gGameSettings
do
4269 if (Length(P
) > 1) and
4270 ((P
[1] = '1') or (P
[1] = '0')) then
4272 if (P
[1][1] = '1') then
4273 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4275 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4278 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4279 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4281 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4283 if g_Game_IsNet
then MH_SEND_GameSettings
;
4286 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4288 with gGameSettings
do
4290 if (Length(P
) > 1) and
4291 ((P
[1] = '1') or (P
[1] = '0')) then
4293 if (P
[1][1] = '1') then
4294 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4296 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4299 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4300 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4302 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4304 if g_Game_IsNet
then MH_SEND_GameSettings
;
4307 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4309 if Length(P
) > 1 then
4311 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4312 gGameSettings
.WarmupTime
:= 30
4314 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4317 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4318 [gGameSettings
.WarmupTime
]));
4319 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4321 else if cmd
= 'net_interp' then
4323 if (Length(P
) > 1) then
4324 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4326 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4327 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4328 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4329 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4332 else if cmd
= 'net_forceplayerupdate' then
4334 if (Length(P
) > 1) and
4335 ((P
[1] = '1') or (P
[1] = '0')) then
4336 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4338 if NetForcePlayerUpdate
then
4339 g_Console_Add('net_forceplayerupdate = 1')
4341 g_Console_Add('net_forceplayerupdate = 0');
4342 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4343 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4344 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4347 else if cmd
= 'net_predictself' then
4349 if (Length(P
) > 1) and
4350 ((P
[1] = '1') or (P
[1] = '0')) then
4351 NetPredictSelf
:= (P
[1][1] = '1');
4353 if NetPredictSelf
then
4354 g_Console_Add('net_predictself = 1')
4356 g_Console_Add('net_predictself = 0');
4357 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4358 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4359 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4362 else if cmd
= 'sv_name' then
4364 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4366 NetServerName
:= P
[1];
4367 if Length(NetServerName
) > 64 then
4368 SetLength(NetServerName
, 64);
4369 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4373 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4375 else if cmd
= 'sv_passwd' then
4377 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4379 NetPassword
:= P
[1];
4380 if Length(NetPassword
) > 24 then
4381 SetLength(NetPassword
, 24);
4382 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4386 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4388 else if cmd
= 'sv_maxplrs' then
4390 if (Length(P
) > 1) then
4392 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4393 if g_Game_IsServer
and g_Game_IsNet
then
4396 for a
:= 0 to High(NetClients
) do
4397 if NetClients
[a
].Used
then
4400 if b
> NetMaxClients
then
4402 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4403 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4404 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4405 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4408 if NetUseMaster
then
4413 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4415 else if cmd
= 'sv_public' then
4417 if (Length(P
) > 1) then
4419 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4420 if g_Game_IsServer
and g_Game_IsNet
then
4421 if NetUseMaster
then
4423 if NetMPeer
= nil then
4424 if not g_Net_Slist_Connect() then
4425 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4426 g_Net_Slist_Update();
4429 if NetMPeer
<> nil then
4430 g_Net_Slist_Disconnect();
4433 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4435 else if cmd
= 'sv_intertime' then
4437 if (Length(P
) > 1) then
4438 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4440 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4442 else if cmd
= 'p1_name' then
4444 if (Length(P
) > 1) and gGameOn
then
4446 if g_Game_IsClient
then
4448 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4449 MC_SEND_PlayerSettings
;
4452 if gPlayer1
<> nil then
4454 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4455 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4458 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4461 else if cmd
= 'p2_name' then
4463 if (Length(P
) > 1) and gGameOn
then
4465 if g_Game_IsClient
then
4467 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4468 MC_SEND_PlayerSettings
;
4471 if gPlayer2
<> nil then
4473 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4474 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4477 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4480 else if cmd
= 'p1_color' then
4482 if Length(P
) > 3 then
4483 if g_Game_IsClient
then
4485 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4486 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4487 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4488 MC_SEND_PlayerSettings
;
4491 if gPlayer1
<> nil then
4493 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4494 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4495 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4496 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4499 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4500 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4501 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4503 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4505 if Length(P
) > 3 then
4506 if g_Game_IsClient
then
4508 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4509 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4510 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4511 MC_SEND_PlayerSettings
;
4514 if gPlayer2
<> nil then
4516 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4517 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4518 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4519 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4522 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4523 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4524 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4526 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4528 if cmd
= 'r_showtime' then
4530 if (Length(P
) > 1) and
4531 ((P
[1] = '1') or (P
[1] = '0')) then
4532 gShowTime
:= (P
[1][1] = '1');
4535 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4537 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4539 else if cmd
= 'r_showscore' then
4541 if (Length(P
) > 1) and
4542 ((P
[1] = '1') or (P
[1] = '0')) then
4543 gShowGoals
:= (P
[1][1] = '1');
4546 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4548 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4550 else if cmd
= 'r_showstat' then
4552 if (Length(P
) > 1) and
4553 ((P
[1] = '1') or (P
[1] = '0')) then
4554 gShowStat
:= (P
[1][1] = '1');
4557 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4559 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4561 else if cmd
= 'r_showkillmsg' then
4563 if (Length(P
) > 1) and
4564 ((P
[1] = '1') or (P
[1] = '0')) then
4565 gShowKillMsg
:= (P
[1][1] = '1');
4567 if gShowKillMsg
then
4568 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4570 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4572 else if cmd
= 'r_showlives' then
4574 if (Length(P
) > 1) and
4575 ((P
[1] = '1') or (P
[1] = '0')) then
4576 gShowLives
:= (P
[1][1] = '1');
4579 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4581 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4583 else if cmd
= 'r_showspect' then
4585 if (Length(P
) > 1) and
4586 ((P
[1] = '1') or (P
[1] = '0')) then
4587 gSpectHUD
:= (P
[1][1] = '1');
4590 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4592 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4594 else if cmd
= 'r_showping' then
4596 if (Length(P
) > 1) and
4597 ((P
[1] = '1') or (P
[1] = '0')) then
4598 gShowPing
:= (P
[1][1] = '1');
4601 g_Console_Add(_lc
[I_MSG_PING_ON
])
4603 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4605 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4607 if Length(P
) > 1 then
4609 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4610 gGameSettings
.GoalLimit
:= 0
4615 if gGameSettings
.GameMode
= GM_DM
then
4617 stat
:= g_Player_GetStats();
4619 for a
:= 0 to High(stat
) do
4620 if stat
[a
].Frags
> b
then
4624 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4626 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4629 if g_Game_IsNet
then MH_SEND_GameSettings
;
4632 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4634 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4636 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4637 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4639 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4640 [gGameSettings
.TimeLimit
div 3600,
4641 (gGameSettings
.TimeLimit
div 60) mod 60,
4642 gGameSettings
.TimeLimit
mod 60]));
4643 if g_Game_IsNet
then MH_SEND_GameSettings
;
4645 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4647 if Length(P
) > 1 then
4649 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4650 gGameSettings
.MaxLives
:= 0
4654 stat
:= g_Player_GetStats();
4656 for a
:= 0 to High(stat
) do
4657 if stat
[a
].Lives
> b
then
4659 gGameSettings
.MaxLives
:=
4660 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4664 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4665 [gGameSettings
.MaxLives
]));
4666 if g_Game_IsNet
then MH_SEND_GameSettings
;
4671 procedure DebugCommands(P
: SArray
);
4677 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4680 cmd
:= LowerCase(P
[0]);
4681 if cmd
= 'd_window' then
4683 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4684 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4685 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4686 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4687 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4689 else if cmd
= 'd_sounds' then
4691 if (Length(P
) > 1) and
4692 ((P
[1] = '1') or (P
[1] = '0')) then
4693 g_Debug_Sounds
:= (P
[1][1] = '1');
4695 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4697 else if cmd
= 'd_frames' then
4699 if (Length(P
) > 1) and
4700 ((P
[1] = '1') or (P
[1] = '0')) then
4701 g_Debug_Frames
:= (P
[1][1] = '1');
4703 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4705 else if cmd
= 'd_winmsg' then
4707 if (Length(P
) > 1) and
4708 ((P
[1] = '1') or (P
[1] = '0')) then
4709 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4711 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4713 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4715 if (Length(P
) > 1) and
4716 ((P
[1] = '1') or (P
[1] = '0')) then
4717 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4719 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4721 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4723 if Length(P
) > 1 then
4725 '0': g_debug_BotAIOff
:= 0;
4726 '1': g_debug_BotAIOff
:= 1;
4727 '2': g_debug_BotAIOff
:= 2;
4728 '3': g_debug_BotAIOff
:= 3;
4731 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4733 else if cmd
= 'd_monster' then
4735 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4736 if Length(P
) < 2 then
4738 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4739 g_Console_Add('ID | Name');
4740 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4741 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4744 a
:= StrToIntDef(P
[1], 0);
4745 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4746 a
:= g_Monsters_GetIDByName(P
[1]);
4748 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4749 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4752 with gPlayer1
.Obj
do
4753 b
:= g_Monsters_Create(a
,
4754 X
+ Rect
.X
+ (Rect
.Width
div 2),
4755 Y
+ Rect
.Y
+ Rect
.Height
,
4756 gPlayer1
.Direction
, True);
4757 if (Length(P
) > 2) and (b
>= 0) then
4758 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4762 else if (cmd
= 'd_health') then
4764 if (Length(P
) > 1) and
4765 ((P
[1] = '1') or (P
[1] = '0')) then
4766 g_debug_HealthBar
:= (P
[1][1] = '1');
4768 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4770 else if (cmd
= 'd_player') then
4772 if (Length(P
) > 1) and
4773 ((P
[1] = '1') or (P
[1] = '0')) then
4774 g_debug_Player
:= (P
[1][1] = '1');
4776 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4778 else if (cmd
= 'd_joy') then
4781 g_Console_Add(e_JoystickStateToString(a
));
4785 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4789 procedure GameCheats(P
: SArray
);
4795 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4796 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4798 g_Console_Add('not available');
4804 g_Console_Add('where is the player?!');
4807 cmd
:= LowerCase(P
[0]);
4811 plr
.GodMode
:= not plr
.GodMode
;
4812 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4815 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4816 if cmd
= 'give' then
4818 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4819 for f
:= 1 to High(P
) do
4821 cmd
:= LowerCase(P
[f
]);
4822 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4823 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4824 if cmd
= 'exit' then
4826 if gTriggers
<> nil then
4828 for a
:= 0 to High(gTriggers
) do
4830 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4832 g_Console_Add('player left the map');
4833 gExitByTrigger
:= True;
4834 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4842 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4843 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4844 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4845 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4846 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4848 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4849 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4851 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4852 if (cmd
= 'medkit') or (cmd
= 'medikit') or (cmd
= 'medpack') or (cmd
= 'medipack') then begin plr
.GiveItem(ITEM_MEDKIT_LARGE
); g_Console_Add('player got a '+cmd
); continue
; end;
4854 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4855 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4857 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4858 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4860 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4861 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4863 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4864 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4865 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4867 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4868 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4869 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4870 if (cmd
= 'launcher') or (cmd
= 'rocketlauncher') or (cmd
= 'rl') then begin plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
); g_Console_Add('player got a rocket launcher'); continue
; end;
4871 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4872 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4874 if (cmd
= 'shotgunzz') or (cmd
= 'sgzz') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a shotgun'); continue
; end;
4875 if (cmd
= 'supershotgunzz') or (cmd
= 'ssgzz') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a supershotgun'); continue
; end;
4876 if cmd
= 'chaingunzz' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a chaingun'); continue
; end;
4877 if (cmd
= 'launcherzz') or (cmd
= 'rocketlauncherzz') or (cmd
= 'rlzz') then begin plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
); plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got a rocket launcher'); continue
; end;
4878 if cmd
= 'plasmagunzz' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got a plasma gun'); continue
; end;
4879 if cmd
= 'bfgzz' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4881 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4882 if cmd
= 'superchaingunzz' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a superchaingun'); continue
; end;
4884 if (cmd
= 'flamer') or (cmd
= 'flamethrower') or (cmd
= 'ft') then begin plr
.GiveItem(ITEM_WEAPON_FLAMETHROWER
); g_Console_Add('player got a flame thrower'); continue
; end;
4885 if (cmd
= 'flamerzz') or (cmd
= 'flamethrowerzz') or (cmd
= 'ftzz') then begin plr
.GiveItem(ITEM_WEAPON_FLAMETHROWER
); plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got a flame thrower'); continue
; end;
4887 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4889 if cmd
= 'ammo' then
4891 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4892 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4893 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4894 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4895 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4896 g_Console_Add('player got some ammo');
4900 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4901 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4903 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4904 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4906 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4907 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4909 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4910 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4912 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4914 if cmd
= 'weapons' then
4916 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4917 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4918 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4919 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4920 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4921 plr
.GiveItem(ITEM_WEAPON_BFG
);
4922 g_Console_Add('player got weapons');
4926 if cmd
= 'keys' then
4928 plr
.GiveItem(ITEM_KEY_RED
);
4929 plr
.GiveItem(ITEM_KEY_GREEN
);
4930 plr
.GiveItem(ITEM_KEY_BLUE
);
4931 g_Console_Add('player got all keys');
4935 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4940 if cmd
= 'open' then
4942 g_Console_Add('player activated sesame');
4943 g_Triggers_OpenAll();
4950 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4954 if cmd
= 'noclip' then
4957 g_Console_Add('wall hardeness adjusted');
4961 if cmd
= 'notarget' then
4963 plr
.NoTarget
:= not plr
.NoTarget
;
4964 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4968 if cmd
= 'noreload' then
4970 plr
.NoReload
:= not plr
.NoReload
;
4971 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4975 if cmd
= 'speedy' then
4977 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4978 g_Console_Add('speed adjusted');
4982 if cmd
= 'jumpy' then
4984 VEL_JUMP
:= 30-VEL_JUMP
;
4985 g_Console_Add('jump height adjusted');
4989 if cmd
= 'automap' then
4991 gShowMap
:= not gShowMap
;
4992 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4996 if cmd
= 'aimline' then
4998 gAimLine
:= not gAimLine
;
4999 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5004 procedure GameCommands(P
: SArray
);
5010 pl
: pTNetClient
= nil;
5017 cmd
:= LowerCase(P
[0]);
5019 if (cmd
= 'quit') or
5026 else if cmd
= 'pause' then
5028 if (g_ActiveWindow
= nil) then
5029 g_Game_Pause(not gPause
);
5031 else if cmd
= 'endgame' then
5032 gExit
:= EXIT_SIMPLE
5033 else if cmd
= 'restart' then
5035 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5037 if g_Game_IsClient
then
5039 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5044 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5046 else if cmd
= 'kick' then
5048 if g_Game_IsServer
then
5050 if Length(P
) < 2 then
5052 g_Console_Add('kick <name>');
5057 g_Console_Add('kick <name>');
5061 if g_Game_IsNet
then
5062 pl
:= g_Net_Client_ByName(P
[1]);
5065 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5066 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5067 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5068 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5069 if NetUseMaster
then
5071 end else if gPlayers
<> nil then
5072 for a
:= Low(gPlayers
) to High(gPlayers
) do
5073 if gPlayers
[a
] <> nil then
5074 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5076 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5077 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5079 gPlayers
[a
].Lives
:= 0;
5080 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5081 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5082 g_Player_Remove(gPlayers
[a
].UID
);
5083 if NetUseMaster
then
5085 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5089 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5091 else if cmd
= 'kick_id' then
5093 if g_Game_IsServer
and g_Game_IsNet
then
5095 if Length(P
) < 2 then
5097 g_Console_Add('kick_id <client ID>');
5102 g_Console_Add('kick_id <client ID>');
5106 a
:= StrToIntDef(P
[1], 0);
5107 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5109 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5111 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5112 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5113 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5114 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5115 if NetUseMaster
then
5120 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5122 else if cmd
= 'ban' then
5124 if g_Game_IsServer
and g_Game_IsNet
then
5126 if Length(P
) < 2 then
5128 g_Console_Add('ban <name>');
5133 g_Console_Add('ban <name>');
5137 pl
:= g_Net_Client_ByName(P
[1]);
5140 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5141 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5142 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5143 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5144 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5145 if NetUseMaster
then
5148 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5150 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5152 else if cmd
= 'ban_id' then
5154 if g_Game_IsServer
and g_Game_IsNet
then
5156 if Length(P
) < 2 then
5158 g_Console_Add('ban_id <client ID>');
5163 g_Console_Add('ban_id <client ID>');
5167 a
:= StrToIntDef(P
[1], 0);
5168 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5169 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5171 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5172 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5173 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5174 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5175 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5176 if NetUseMaster
then
5180 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5182 else if cmd
= 'permban' then
5184 if g_Game_IsServer
and g_Game_IsNet
then
5186 if Length(P
) < 2 then
5188 g_Console_Add('permban <name>');
5193 g_Console_Add('permban <name>');
5197 pl
:= g_Net_Client_ByName(P
[1]);
5200 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5201 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5202 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5203 g_Net_SaveBanList();
5204 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5205 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5206 if NetUseMaster
then
5209 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5211 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5213 else if cmd
= 'permban_id' then
5215 if g_Game_IsServer
and g_Game_IsNet
then
5217 if Length(P
) < 2 then
5219 g_Console_Add('permban_id <client ID>');
5224 g_Console_Add('permban_id <client ID>');
5228 a
:= StrToIntDef(P
[1], 0);
5229 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5230 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5232 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5233 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5234 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5235 g_Net_SaveBanList();
5236 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5237 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5238 if NetUseMaster
then
5242 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5244 else if cmd
= 'unban' then
5246 if g_Game_IsServer
and g_Game_IsNet
then
5248 if Length(P
) < 2 then
5250 g_Console_Add('unban <IP Address>');
5255 g_Console_Add('unban <IP Address>');
5259 if g_Net_UnbanHost(P
[1]) then
5261 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5262 g_Net_SaveBanList();
5264 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5266 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5268 else if cmd
= 'clientlist' then
5270 if g_Game_IsServer
and g_Game_IsNet
then
5273 if NetClients
<> nil then
5274 for a
:= Low(NetClients
) to High(NetClients
) do
5275 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5277 plr
:= g_Player_Get(NetClients
[a
].Player
);
5278 if plr
= nil then continue
;
5280 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5281 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5284 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5286 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5288 else if cmd
= 'connect' then
5290 if (NetMode
= NET_NONE
) then
5292 if Length(P
) < 2 then
5294 g_Console_Add('connect <IP> [port] [password]');
5299 g_Console_Add('connect <IP> [port] [password]');
5303 if Length(P
) > 2 then
5304 prt
:= StrToIntDef(P
[2], 25666)
5308 if Length(P
) > 3 then
5313 g_Game_StartClient(P
[1], prt
, pw
);
5316 else if cmd
= 'disconnect' then
5318 if (NetMode
= NET_CLIENT
) then
5321 else if cmd
= 'reconnect' then
5323 if (NetMode
= NET_SERVER
) then
5326 if (NetMode
= NET_CLIENT
) then
5329 gExit
:= EXIT_SIMPLE
;
5333 //TODO: Use last successful password to reconnect, instead of ''
5334 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5336 else if (cmd
= 'addbot') or
5337 (cmd
= 'bot_add') then
5339 if Length(P
) > 1 then
5340 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5342 g_Bot_Add(TEAM_NONE
, 2);
5344 else if cmd
= 'bot_addlist' then
5346 if Length(P
) > 1 then
5347 if Length(P
) = 2 then
5348 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5350 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5352 else if cmd
= 'bot_removeall' then
5354 else if cmd
= 'chat' then
5356 if g_Game_IsNet
then
5358 if Length(P
) > 1 then
5360 for a
:= 1 to High(P
) do
5361 chstr
:= chstr
+ P
[a
] + ' ';
5363 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5365 if Length(chstr
) < 1 then
5367 g_Console_Add('chat <text>');
5371 chstr
:= b_Text_Format(chstr
);
5372 if g_Game_IsClient
then
5373 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5375 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5378 g_Console_Add('chat <text>');
5380 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5382 else if cmd
= 'teamchat' then
5384 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5386 if Length(P
) > 1 then
5388 for a
:= 1 to High(P
) do
5389 chstr
:= chstr
+ P
[a
] + ' ';
5391 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5393 if Length(chstr
) < 1 then
5395 g_Console_Add('teamchat <text>');
5399 chstr
:= b_Text_Format(chstr
);
5400 if g_Game_IsClient
then
5401 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5403 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5404 gPlayer1Settings
.Team
);
5407 g_Console_Add('teamchat <text>');
5409 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5411 else if cmd
= 'game' then
5413 if gGameSettings
.GameType
<> GT_NONE
then
5415 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5418 if Length(P
) = 1 then
5420 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5423 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5424 P
[1] := addWadExtension(P
[1]);
5425 if FileExists(MapsDir
+ P
[1]) then
5427 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5428 if Length(P
) < 3 then
5431 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5434 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5436 if g_Map_Exist(MapsDir
+ s
) then
5438 // Çàïóñêàåì ñâîþ èãðó
5440 with gGameSettings
do
5442 GameMode
:= g_Game_TextToMode(gcGameMode
);
5443 if gSwitchGameMode
<> GM_NONE
then
5444 GameMode
:= gSwitchGameMode
;
5445 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5446 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5448 if Length(P
) >= 4 then
5449 b
:= StrToIntDef(P
[3], 1);
5450 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5451 GoalLimit
, MaxLives
, Options
, b
);
5456 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5458 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5460 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5462 else if cmd
= 'host' then
5464 if gGameSettings
.GameType
<> GT_NONE
then
5466 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5469 if Length(P
) < 4 then
5471 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5474 if not StrToIp(P
[1], listen
) then
5476 prt
:= StrToIntDef(P
[2], 25666);
5478 P
[3] := addWadExtension(P
[3]);
5479 if FileExists(MapsDir
+ P
[3]) then
5481 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5482 if Length(P
) < 5 then
5485 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5488 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5490 if g_Map_Exist(MapsDir
+ s
) then
5492 // Çàïóñêàåì ñâîþ èãðó
5494 with gGameSettings
do
5496 GameMode
:= g_Game_TextToMode(gcGameMode
);
5497 if gSwitchGameMode
<> GM_NONE
then
5498 GameMode
:= gSwitchGameMode
;
5499 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5500 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5502 if Length(P
) >= 6 then
5503 b
:= StrToIntDef(P
[5], 0);
5504 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5505 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5510 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5512 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5514 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5516 else if cmd
= 'map' then
5518 if Length(P
) = 1 then
5520 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5522 g_Console_Add(cmd
+ ' <MAP>');
5523 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5525 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5527 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5529 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5530 if Length(P
) < 3 then
5532 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5533 s
:= UpperCase(P
[1]);
5534 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5535 begin // Êàðòà íàøëàñü
5536 gExitByTrigger
:= False;
5538 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5540 gExit
:= EXIT_ENDLEVELCUSTOM
;
5542 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5543 g_Game_ChangeMap(s
);
5546 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5547 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5548 P
[1] := addWadExtension(P
[1]);
5549 if FileExists(MapsDir
+ P
[1]) then
5551 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5553 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5555 s
:= P
[1] + ':\' + P
[2];
5557 if g_Map_Exist(MapsDir
+ s
) then
5559 gExitByTrigger
:= False;
5561 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5563 gExit
:= EXIT_ENDLEVELCUSTOM
;
5565 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5566 g_Game_ChangeMap(s
);
5569 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5571 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5573 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5577 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5578 P
[1] := addWadExtension(P
[1]);
5579 if FileExists(MapsDir
+ P
[1]) then
5582 P
[2] := UpperCase(P
[2]);
5583 s
:= P
[1] + ':\' + P
[2];
5585 if g_Map_Exist(MapsDir
+ s
) then
5586 begin // Íàøëè êàðòó
5587 gExitByTrigger
:= False;
5589 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5591 gExit
:= EXIT_ENDLEVELCUSTOM
;
5593 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5594 g_Game_ChangeMap(s
);
5596 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5598 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5601 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5603 else if cmd
= 'nextmap' then
5605 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5606 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5609 if Length(P
) = 1 then
5611 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5613 g_Console_Add(cmd
+ ' <MAP>');
5614 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5617 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5622 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5624 if Length(P
) < 3 then
5626 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5627 s
:= UpperCase(P
[1]);
5628 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5629 begin // Êàðòà íàøëàñü
5630 gExitByTrigger
:= False;
5635 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5636 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5637 P
[1] := addWadExtension(P
[1]);
5638 if FileExists(MapsDir
+ P
[1]) then
5640 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5642 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5644 s
:= P
[1] + ':\' + P
[2];
5646 if g_Map_Exist(MapsDir
+ s
) then
5647 begin // Óñòàíàâëèâàåì êàðòó
5648 gExitByTrigger
:= False;
5653 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5655 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5657 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5661 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5662 P
[1] := addWadExtension(P
[1]);
5663 if FileExists(MapsDir
+ P
[1]) then
5666 P
[2] := UpperCase(P
[2]);
5667 s
:= P
[1] + ':\' + P
[2];
5669 if g_Map_Exist(MapsDir
+ s
) then
5670 begin // Íàøëè êàðòó
5671 gExitByTrigger
:= False;
5675 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5677 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5680 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5683 if gNextMap
= '' then
5684 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5686 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5689 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5692 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5694 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5696 gExitByTrigger
:= False;
5697 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5698 if (gNextMap
= '') and (gTriggers
<> nil) then
5699 for a
:= 0 to High(gTriggers
) do
5700 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5702 gExitByTrigger
:= True;
5703 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5706 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5707 if gNextMap
= '' then
5708 gNextMap
:= g_Game_GetNextMap();
5709 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5710 if Pos(':\', gNextMap
) = 0 then
5711 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5714 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5715 if g_Map_Exist(MapsDir
+ s
) then
5716 gExit
:= EXIT_ENDLEVELCUSTOM
5718 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5720 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5722 else if (cmd
= 'event') then
5724 if (Length(P
) <= 1) then
5726 for a
:= 0 to High(gEvents
) do
5727 if gEvents
[a
].Command
= '' then
5728 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5730 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5733 if (Length(P
) = 2) then
5735 for a
:= 0 to High(gEvents
) do
5736 if gEvents
[a
].Name
= P
[1] then
5737 if gEvents
[a
].Command
= '' then
5738 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5740 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5743 for a
:= 0 to High(gEvents
) do
5744 if gEvents
[a
].Name
= P
[1] then
5746 gEvents
[a
].Command
:= '';
5747 for b
:= 2 to High(P
) do
5748 if Pos(' ', P
[b
]) = 0 then
5749 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5751 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5752 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5756 // Êîìàíäû Ñâîåé èãðû:
5757 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5759 if cmd
= 'bot_addred' then
5761 if Length(P
) > 1 then
5762 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5764 g_Bot_Add(TEAM_RED
, 2);
5766 else if cmd
= 'bot_addblue' then
5768 if Length(P
) > 1 then
5769 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5771 g_Bot_Add(TEAM_BLUE
, 2);
5773 else if cmd
= 'suicide' then
5777 if g_Game_IsClient
then
5778 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5781 if gPlayer1
<> nil then
5782 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5783 if gPlayer2
<> nil then
5784 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5788 else if cmd
= 'spectate' then
5794 else if cmd
= 'say' then
5796 if g_Game_IsServer
and g_Game_IsNet
then
5798 if Length(P
) > 1 then
5801 for a
:= 1 to High(P
) do
5802 chstr
:= chstr
+ P
[a
] + ' ';
5804 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5806 if Length(chstr
) < 1 then
5808 g_Console_Add('say <text>');
5812 chstr
:= b_Text_Format(chstr
);
5813 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5815 else g_Console_Add('say <text>');
5817 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5819 else if cmd
= 'tell' then
5821 if g_Game_IsServer
and g_Game_IsNet
then
5823 if (Length(P
) > 2) and (P
[1] <> '') then
5826 for a
:= 2 to High(P
) do
5827 chstr
:= chstr
+ P
[a
] + ' ';
5829 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5831 if Length(chstr
) < 1 then
5833 g_Console_Add('tell <playername> <text>');
5837 pl
:= g_Net_Client_ByName(P
[1]);
5839 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5841 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5843 else g_Console_Add('tell <playername> <text>');
5845 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5847 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5849 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5851 // Äîïîëíèòåëüíîå âðåìÿ:
5852 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5854 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5855 [gGameSettings
.TimeLimit
div 3600,
5856 (gGameSettings
.TimeLimit
div 60) mod 60,
5857 gGameSettings
.TimeLimit
mod 60]));
5858 if g_Game_IsNet
then MH_SEND_GameSettings
;
5860 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5862 if (Length(P
) <= 1) then
5863 g_Console_Add('rcon_password <password>')
5865 MC_SEND_RCONPassword(P
[1]);
5867 else if cmd
= 'rcon' then
5869 if g_Game_IsClient
then
5871 if Length(P
) > 1 then
5874 for a
:= 1 to High(P
) do
5875 chstr
:= chstr
+ P
[a
] + ' ';
5877 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5879 if Length(chstr
) < 1 then
5881 g_Console_Add('rcon <command>');
5885 MC_SEND_RCONCommand(chstr
);
5887 else g_Console_Add('rcon <command>');
5890 else if cmd
= 'ready' then
5892 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5893 gLMSRespawnTime
:= gTime
+ 100;
5895 else if (cmd
= 'callvote') and g_Game_IsNet
then
5897 if Length(P
) > 1 then
5900 for a
:= 1 to High(P
) do begin
5901 if a
> 1 then chstr
:= chstr
+ ' ';
5902 chstr
:= chstr
+ P
[a
];
5905 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5907 if Length(chstr
) < 1 then
5909 g_Console_Add('callvote <command>');
5913 if g_Game_IsClient
then
5914 MC_SEND_Vote(True, chstr
)
5916 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5917 g_Console_Process('vote', True);
5920 g_Console_Add('callvote <command>');
5922 else if (cmd
= 'vote') and g_Game_IsNet
then
5924 if g_Game_IsClient
then
5926 else if gVoteInProgress
then
5928 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5929 a
:= Floor((NetClientCount
+1)/2.0) + 1
5931 a
:= Floor(NetClientCount
/2.0) + 1;
5936 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5937 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5943 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5944 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5952 procedure g_TakeScreenShot();
5960 if e_NoGraphics
then Exit
;
5961 ssdir
:= GameDir
+'/screenshots';
5962 if not findFileCI(ssdir
, true) then
5964 // try to create dir
5969 if not findFileCI(ssdir
, true) then exit
; // alas
5972 for a
:= 1 to High(Word) do
5974 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5976 if findFileCI(t
, true) then continue
;
5977 if not findFileCI(FileName
) then
5980 st
:= createDiskFile(FileName
);
5982 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5987 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5995 procedure g_Game_InGameMenu(Show
: Boolean);
5997 if (g_ActiveWindow
= nil) and Show
then
5999 if gGameSettings
.GameType
= GT_SINGLE
then
6000 g_GUI_ShowWindow('GameSingleMenu')
6003 if g_Game_IsClient
then
6004 g_GUI_ShowWindow('GameClientMenu')
6006 if g_Game_IsNet
then
6007 g_GUI_ShowWindow('GameServerMenu')
6009 g_GUI_ShowWindow('GameCustomMenu');
6011 g_Sound_PlayEx('MENU_OPEN');
6013 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6014 if (not g_Game_IsNet
) then
6018 if (g_ActiveWindow
<> nil) and (not Show
) then
6020 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6021 if (not g_Game_IsNet
) then
6022 g_Game_Pause(False);
6026 procedure g_Game_Pause(Enable
: Boolean);
6031 if gPause
= Enable
then
6034 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6038 g_Game_PauseAllSounds(Enable
);
6041 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6046 if gTriggers
<> nil then
6047 for i
:= 0 to High(gTriggers
) do
6048 with gTriggers
[i
] do
6049 if (TriggerType
= TRIGGER_SOUND
) and
6051 Sound
.IsPlaying() then
6053 Sound
.Pause(Enable
);
6057 if gPlayers
<> nil then
6058 for i
:= 0 to High(gPlayers
) do
6059 if gPlayers
[i
] <> nil then
6060 gPlayers
[i
].PauseSounds(Enable
);
6063 if gMusic
<> nil then
6064 gMusic
.Pause(Enable
);
6067 procedure g_Game_StopAllSounds(all
: Boolean);
6071 if gTriggers
<> nil then
6072 for i
:= 0 to High(gTriggers
) do
6073 with gTriggers
[i
] do
6074 if (TriggerType
= TRIGGER_SOUND
) and
6078 if gMusic
<> nil then
6085 procedure g_Game_UpdateTriggerSounds();
6089 if gTriggers
<> nil then
6090 for i
:= 0 to High(gTriggers
) do
6091 with gTriggers
[i
] do
6092 if (TriggerType
= TRIGGER_SOUND
) and
6095 Sound
.IsPlaying() then
6097 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6098 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6100 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6101 Sound
.SetVolume(Data
.Volume
/255.0);
6104 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6108 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6111 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6116 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6121 if gSpectMode
<> SPECT_PLAYERS
then
6123 if gSpectPID1
= UID
then
6128 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6135 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6140 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6145 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6150 if gSpectMode
<> SPECT_PLAYERS
then
6152 Pl
:= g_Player_Get(gSpectPID1
);
6153 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6158 if gSpectViewTwo
then
6160 Pl
:= g_Player_Get(gSpectPID2
);
6161 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6169 procedure g_Game_Message(Msg
: string; Time
: Word);
6171 MessageText
:= b_Text_Format(Msg
);
6172 MessageTime
:= Time
;
6175 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6184 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6188 if goodsnd
[a
].IsPlaying() then
6191 goodsnd
[Random(4)].Play();
6194 procedure g_Game_Announce_KillCombo(Param
: Integer);
6201 UID
:= Param
and $FFFF;
6206 Pl
:= g_Player_Get(UID
);
6215 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6219 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6223 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6227 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6235 if not g_Game_IsWatchedPlayer(UID
) then
6238 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6242 if killsnd
[n
].IsPlaying() then
6247 procedure g_Game_StartVote(Command
, Initiator
: string);
6251 if not gVotesEnabled
then Exit
;
6252 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6253 if gVoteInProgress
or gVotePassed
then
6255 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6256 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6259 gVoteInProgress
:= True;
6260 gVotePassed
:= False;
6261 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6264 gVoteCommand
:= Command
;
6266 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6267 Need
:= Floor((NetClientCount
+1)/2.0)+1
6269 Need
:= Floor(NetClientCount
/2.0)+1;
6270 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6271 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6274 procedure g_Game_CheckVote
;
6278 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6279 if not gVoteInProgress
then Exit
;
6281 if (gTime
>= gVoteTimer
) then
6283 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6284 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6286 Need
:= Floor(NetClientCount
/2.0) + 1;
6287 if gVoteCount
>= Need
then
6289 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6290 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6291 gVotePassed
:= True;
6292 gVoteCmdTimer
:= gTime
+ 5000;
6296 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6297 MH_SEND_VoteEvent(NET_VE_FAILED
);
6299 if NetClients
<> nil then
6300 for I
:= Low(NetClients
) to High(NetClients
) do
6301 if NetClients
[i
].Used
then
6302 NetClients
[i
].Voted
:= False;
6303 gVoteInProgress
:= False;
6309 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6310 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6312 Need
:= Floor(NetClientCount
/2.0) + 1;
6313 if gVoteCount
>= Need
then
6315 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6316 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6317 gVoteInProgress
:= False;
6318 gVotePassed
:= True;
6319 gVoteCmdTimer
:= gTime
+ 5000;
6322 if NetClients
<> nil then
6323 for I
:= Low(NetClients
) to High(NetClients
) do
6324 if NetClients
[i
].Used
then
6325 NetClients
[i
].Voted
:= False;
6330 procedure g_Game_LoadMapList(FileName
: string);
6338 if not FileExists(FileName
) then Exit
;
6340 AssignFile(ListFile
, FileName
);
6342 while not EOF(ListFile
) do
6344 ReadLn(ListFile
, s
);
6347 if s
= '' then Continue
;
6349 SetLength(MapList
, Length(MapList
)+1);
6350 MapList
[High(MapList
)] := s
;
6352 CloseFile(ListFile
);
6355 procedure g_Game_SetDebugMode();
6358 // ×èòû (äàæå â ñâîåé èãðå):
6362 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6366 if Length(LoadingStat
.Msgs
) = 0 then
6372 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6373 if NextMsg
= Length(Msgs
) then
6375 for i
:= 0 to High(Msgs
)-1 do
6376 Msgs
[i
] := Msgs
[i
+1];
6384 Msgs
[NextMsg
-1] := Text;
6390 g_ActiveWindow
:= nil;
6395 procedure g_Game_StepLoading();
6401 if (ShowCount
> LOADING_SHOW_STEP
) then
6409 procedure g_Game_ClearLoading();
6418 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6419 if len
< 1 then len
:= 1;
6420 SetLength(Msgs
, len
);
6421 for len
:= Low(Msgs
) to High(Msgs
) do
6427 procedure Parse_Params(var pars
: TParamStrValues
);
6434 while i
<= ParamCount
do
6437 if (s
[1] = '-') and (Length(s
) > 1) then
6439 if (s
[2] = '-') and (Length(s
) > 2) then
6440 begin // Îäèíî÷íûé ïàðàìåòð
6441 SetLength(pars
, Length(pars
) + 1);
6442 with pars
[High(pars
)] do
6444 Name
:= LowerCase(s
);
6449 if (i
< ParamCount
) then
6450 begin // Ïàðàìåòð ñî çíà÷åíèåì
6452 SetLength(pars
, Length(pars
) + 1);
6453 with pars
[High(pars
)] do
6455 Name
:= LowerCase(s
);
6456 Value
:= LowerCase(ParamStr(i
));
6465 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6470 for i
:= 0 to High(pars
) do
6471 if pars
[i
].Name
= aName
then
6473 Result
:= pars
[i
].Value
;
6478 procedure g_Game_Process_Params();
6480 pars
: TParamStrValues
;
6483 LimT
, LimS
: Integer;
6494 s
:= Find_Param_Value(pars
, '--debug');
6497 g_Game_SetDebugMode();
6498 s
:= Find_Param_Value(pars
, '--netdump');
6503 // Connect when game loads
6504 ip
:= Find_Param_Value(pars
, '-connect');
6508 s
:= Find_Param_Value(pars
, '-port');
6509 if (s
= '') or not TryStrToInt(s
, Port
) then
6512 s
:= Find_Param_Value(pars
, '-pw');
6514 g_Game_StartClient(ip
, Port
, s
);
6518 // Start map when game loads:
6519 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6520 if isWadPath(map
) then
6523 s
:= Find_Param_Value(pars
, '-gm');
6524 GMode
:= g_Game_TextToMode(s
);
6525 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6526 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6529 s
:= Find_Param_Value(pars
, '-limt');
6530 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6536 s
:= Find_Param_Value(pars
, '-lims');
6537 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6543 s
:= Find_Param_Value(pars
, '-lives');
6544 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6550 s
:= Find_Param_Value(pars
, '-opt');
6552 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6554 Opt
:= StrToIntDef(s
, 0);
6556 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6559 s
:= Find_Param_Value(pars
, '--close');
6563 // Delete test map after play:
6564 s
:= Find_Param_Value(pars
, '--testdelete');
6567 gMapToDelete
:= MapsDir
+ map
;
6568 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6572 // Delete temporary WAD after play:
6573 s
:= Find_Param_Value(pars
, '--tempdelete');
6576 gMapToDelete
:= MapsDir
+ map
;
6577 gTempDelete
:= True;
6580 // Number of players:
6581 s
:= Find_Param_Value(pars
, '-pl');
6585 n
:= StrToIntDef(s
, 1);
6588 s
:= Find_Param_Value(pars
, '-port');
6589 if (s
= '') or not TryStrToInt(s
, Port
) then
6590 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6592 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6595 // Execute script when game loads:
6596 s
:= Find_Param_Value(pars
, '-exec');
6599 if Pos(':\', s
) = 0 then
6600 s
:= GameDir
+ '/' + s
;
6605 if IOResult
<> 0 then
6607 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6608 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6612 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6613 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6618 if IOResult
<> 0 then
6620 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6621 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6625 if Pos('#', s
) <> 1 then // script comment
6626 g_Console_Process(s
, True);