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_DrawPanels(PANEL_BACK
);
2516 g_Map_DrawPanels(PANEL_STEP
);
2519 g_Player_DrawShells();
2521 g_Player_DrawCorpses();
2522 g_Map_DrawPanels(PANEL_WALL
);
2524 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2527 g_Map_DrawPanels(PANEL_ACID1
);
2528 g_Map_DrawPanels(PANEL_ACID2
);
2529 g_Map_DrawPanels(PANEL_WATER
);
2530 g_Map_DrawPanels(PANEL_FORE
);
2531 if g_debug_HealthBar
then
2533 g_Monsters_DrawHealth();
2534 g_Player_DrawHealth();
2540 procedure DrawPlayer(p
: TPlayer
);
2542 px
, py
, a
, b
, c
, d
: Integer;
2545 if (p
= nil) or (p
.FDummy
) then
2548 g_Map_DrawBack(0, 0);
2557 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2558 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2560 if px
> (gPlayerScreenSize
.X
div 2) then
2561 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2564 if py
> (gPlayerScreenSize
.Y
div 2) then
2565 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2568 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2569 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2570 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2571 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2572 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2574 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2577 if p
.IncCam
<> 0 then
2579 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2581 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2582 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2585 if py
< (gPlayerScreenSize
.Y
div 2) then
2587 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2588 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2591 if p
.IncCam
< 0 then
2592 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2594 p
.IncCam
:= p
.IncCam
+ 1;
2596 if p
.IncCam
> 0 then
2597 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2599 p
.IncCam
:= p
.IncCam
- 1;
2602 if (px
< gPlayerScreenSize
.X
div 2) or
2603 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2606 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2607 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2609 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2611 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2612 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2615 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2616 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2618 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2620 g_Map_DrawBack(-c
, -d
);
2623 sY
:= -(b
+p
.IncCam
);
2624 sWidth
:= gPlayerScreenSize
.X
;
2625 sHeight
:= gPlayerScreenSize
.Y
;
2627 glTranslatef(a
, b
+p
.IncCam
, 0);
2629 g_Map_DrawPanels(PANEL_BACK
);
2630 g_Map_DrawPanels(PANEL_STEP
);
2633 g_Player_DrawShells();
2635 g_Player_DrawCorpses();
2636 g_Map_DrawPanels(PANEL_WALL
);
2638 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2641 g_Map_DrawPanels(PANEL_ACID1
);
2642 g_Map_DrawPanels(PANEL_ACID2
);
2643 g_Map_DrawPanels(PANEL_WATER
);
2644 g_Map_DrawPanels(PANEL_FORE
);
2645 if g_debug_HealthBar
then
2647 g_Monsters_DrawHealth();
2648 g_Player_DrawHealth();
2651 if p
.FSpectator
then
2652 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2653 p
.GameY
+ PLAYER_RECT_CY
- 4,
2654 'X', gStdFont
, 255, 255, 255, 1, True);
2656 for a := 0 to High(gCollideMap) do
2657 for b := 0 to High(gCollideMap[a]) do
2660 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2662 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2666 1: e_DrawPoint(1, b, a, 200, 200, 200);
2667 2: e_DrawPoint(1, b, a, 64, 64, 255);
2668 3: e_DrawPoint(1, b, a, 255, 0, 255);
2678 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2679 if g_Debug_Player
then
2680 g_Player_DrawDebug(p
);
2684 procedure g_Game_Draw();
2691 plView1
, plView2
: TPlayer
;
2694 if gExit
= EXIT_QUIT
then Exit
;
2696 Time
:= GetTimer() {div 1000};
2697 FPSCounter
:= FPSCounter
+1;
2698 if Time
- FPSTime
>= 1000 then
2705 if gGameOn
or (gState
= STATE_FOLD
) then
2707 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2709 gSpectMode
:= SPECT_NONE
;
2710 if not gRevertPlayers
then
2712 plView1
:= gPlayer1
;
2713 plView2
:= gPlayer2
;
2717 plView1
:= gPlayer2
;
2718 plView2
:= gPlayer1
;
2722 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2724 gSpectMode
:= SPECT_NONE
;
2725 if gPlayer2
= nil then
2728 plView1
:= gPlayer2
;
2737 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2738 gSpectMode
:= SPECT_STATS
;
2740 if gSpectMode
= SPECT_PLAYERS
then
2741 if gPlayers
<> nil then
2743 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2744 if plView1
= nil then
2746 gSpectPID1
:= GetActivePlayerID_Next();
2747 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2749 if gSpectViewTwo
then
2751 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2752 if plView2
= nil then
2754 gSpectPID2
:= GetActivePlayerID_Next();
2755 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2760 if gSpectMode
= SPECT_MAPVIEW
then
2762 // Ðåæèì ïðîñìîòðà êàðòû
2764 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2765 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2766 gHearPoint1
.Active
:= True;
2767 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2768 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2769 gHearPoint2
.Active
:= False;
2773 Split
:= (plView1
<> nil) and (plView2
<> nil);
2775 // Òî÷êè ñëóõà èãðîêîâ
2776 if plView1
<> nil then
2778 gHearPoint1
.Active
:= True;
2779 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2780 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2782 gHearPoint1
.Active
:= False;
2783 if plView2
<> nil then
2785 gHearPoint2
.Active
:= True;
2786 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2787 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2789 gHearPoint2
.Active
:= False;
2791 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2792 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2795 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2796 if gScreenHeight
mod 2 = 0 then
2797 Dec(gPlayerScreenSize
.Y
);
2800 gPlayerScreenSize
.Y
:= gScreenHeight
;
2803 if gScreenHeight
mod 2 = 0 then
2804 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2806 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2808 DrawPlayer(plView1
);
2809 gPlayer1ScreenCoord
.X
:= sX
;
2810 gPlayer1ScreenCoord
.Y
:= sY
;
2814 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2816 DrawPlayer(plView2
);
2817 gPlayer2ScreenCoord
.X
:= sX
;
2818 gPlayer2ScreenCoord
.Y
:= sY
;
2821 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2824 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2827 if MessageText
<> '' then
2831 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2833 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2834 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2836 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2837 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2840 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2842 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2844 // Draw spectator GUI
2847 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2850 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2852 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2854 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2856 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2857 if gSpectMode
= SPECT_MAPVIEW
then
2859 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2860 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2861 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2862 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2863 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2865 if gSpectMode
= SPECT_PLAYERS
then
2867 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2868 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2869 if gSpectViewTwo
then
2871 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2872 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2873 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2874 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2878 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2879 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2885 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2887 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2889 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2890 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2891 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2896 if (gState
= STATE_MENU
) then
2898 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2900 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2901 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2902 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2904 if g_ActiveWindow
<> nil then
2905 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2908 if gState
= STATE_FOLD
then
2909 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2911 if gState
= STATE_INTERCUSTOM
then
2913 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2915 back
:= 'TEXTURE_endpic';
2916 if not g_Texture_Get(back
, ID
) then
2917 back
:= _lc
[I_TEXTURE_ENDPIC
];
2922 if g_Texture_Get(back
, ID
) then
2923 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2925 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2929 if g_ActiveWindow
<> nil then
2930 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2933 if gState
= STATE_INTERSINGLE
then
2935 if EndingGameCounter
> 0 then
2936 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2941 if g_Texture_Get(back
, ID
) then
2942 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2944 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2948 if g_ActiveWindow
<> nil then
2949 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2953 if gState
= STATE_ENDPIC
then
2956 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2957 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2959 if ID
<> DWORD(-1) then
2960 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2962 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2964 if g_ActiveWindow
<> nil then
2965 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2968 if gState
= STATE_SLIST
then
2970 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2972 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2973 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2975 g_Serverlist_Draw(slCurrent
);
2979 if g_ActiveWindow
<> nil then
2982 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2983 g_ActiveWindow
.Draw();
2988 if g_debug_Sounds
and gGameOn
then
2990 for w
:= 0 to High(e_SoundsArray
) do
2991 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2992 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
2997 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
2998 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3001 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3002 e_TextureFontPrint(gScreenWidth
-72, 0,
3003 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3007 procedure g_Game_Quit();
3009 g_Game_StopAllSounds(True);
3011 g_Game_SaveOptions();
3013 g_PlayerModel_FreeData();
3014 g_Texture_DeleteAll();
3015 g_Frames_DeleteAll();
3018 if NetInitDone
then g_Net_Free
;
3020 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3021 if gMapToDelete
<> '' then
3022 g_Game_DeleteTestMap();
3028 procedure g_FatalError(Text: String);
3030 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3031 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3033 gExit
:= EXIT_SIMPLE
;
3036 procedure g_SimpleError(Text: String);
3038 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3039 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3042 procedure g_Game_SetupScreenSize();
3046 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3047 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3048 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3049 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3051 gPlayerScreenSize
.Y
:= gScreenHeight
;
3053 // Ðàçìåð çàäíåãî ïëàíà:
3054 if BackID
<> DWORD(-1) then
3058 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3059 (gScreenHeight
*d
> gMapInfo
.Height
) then
3062 gBackSize
.X
:= Round(gScreenWidth
*d
);
3063 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3067 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3069 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3072 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3074 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3075 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3077 if gPlayer1
= nil then
3079 if g_Game_IsClient
then
3081 if NetPlrUID1
> -1 then
3083 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3084 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3089 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3090 Team
:= gPlayer1Settings
.Team
;
3092 // Ñîçäàíèå ïåðâîãî èãðîêà:
3093 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3094 gPlayer1Settings
.Color
,
3096 if gPlayer1
= nil then
3097 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3100 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3101 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3102 if g_Game_IsServer
and g_Game_IsNet
then
3103 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3104 gPlayer1
.Respawn(False, True);
3106 if g_Game_IsNet
and NetUseMaster
then
3112 if gPlayer2
= nil then
3114 if g_Game_IsClient
then
3116 if NetPlrUID2
> -1 then
3117 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3121 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3122 Team
:= gPlayer2Settings
.Team
;
3124 // Ñîçäàíèå âòîðîãî èãðîêà:
3125 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3126 gPlayer2Settings
.Color
,
3128 if gPlayer2
= nil then
3129 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3132 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3133 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3134 if g_Game_IsServer
and g_Game_IsNet
then
3135 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3136 gPlayer2
.Respawn(False, True);
3138 if g_Game_IsNet
and NetUseMaster
then
3146 procedure g_Game_RemovePlayer();
3150 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3151 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3156 if g_Game_IsServer
then
3159 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3160 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3161 g_Player_Remove(Pl
.UID
);
3163 if g_Game_IsNet
and NetUseMaster
then
3172 if g_Game_IsServer
then
3175 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3176 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3177 g_Player_Remove(Pl
.UID
);
3179 if g_Game_IsNet
and NetUseMaster
then
3184 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3190 procedure g_Game_Spectate();
3192 g_Game_RemovePlayer();
3193 if gPlayer1
<> nil then
3194 g_Game_RemovePlayer();
3197 procedure g_Game_SpectateCenterView();
3199 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3200 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3203 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3209 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3211 g_Game_ClearLoading();
3214 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3217 gGameSettings
.GameType
:= GT_SINGLE
;
3218 gGameSettings
.MaxLives
:= 0;
3219 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3220 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3221 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3222 gSwitchGameMode
:= GM_SINGLE
;
3224 g_Game_ExecuteEvent('ongamestart');
3226 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3227 g_Game_SetupScreenSize();
3229 // Ñîçäàíèå ïåðâîãî èãðîêà:
3230 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3231 gPlayer1Settings
.Color
,
3232 gPlayer1Settings
.Team
, False));
3233 if gPlayer1
= nil then
3235 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3239 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3242 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3245 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3246 gPlayer2Settings
.Color
,
3247 gPlayer2Settings
.Team
, False));
3248 if gPlayer2
= nil then
3250 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3254 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3258 // Çàãðóçêà è çàïóñê êàðòû:
3259 if not g_Game_StartMap(MAP
, True) then
3261 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3265 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3269 for i
:= nPl
+1 to nPlayers
do
3270 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3273 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3274 TimeLimit
, GoalLimit
: Word;
3276 Options
: LongWord; nPlayers
: Byte);
3282 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3284 g_Game_ClearLoading();
3287 gGameSettings
.GameType
:= GT_CUSTOM
;
3288 gGameSettings
.GameMode
:= GameMode
;
3289 gSwitchGameMode
:= GameMode
;
3290 gGameSettings
.TimeLimit
:= TimeLimit
;
3291 gGameSettings
.GoalLimit
:= GoalLimit
;
3292 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3293 gGameSettings
.Options
:= Options
;
3295 gCoopTotalMonstersKilled
:= 0;
3296 gCoopTotalSecretsFound
:= 0;
3297 gCoopTotalMonsters
:= 0;
3298 gCoopTotalSecrets
:= 0;
3302 g_Game_ExecuteEvent('ongamestart');
3304 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3305 g_Game_SetupScreenSize();
3307 // Ðåæèì íàáëþäàòåëÿ:
3308 if nPlayers
= 0 then
3315 if nPlayers
>= 1 then
3317 // Ñîçäàíèå ïåðâîãî èãðîêà:
3318 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3319 gPlayer1Settings
.Color
,
3320 gPlayer1Settings
.Team
, False));
3321 if gPlayer1
= nil then
3323 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3327 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3331 if nPlayers
>= 2 then
3333 // Ñîçäàíèå âòîðîãî èãðîêà:
3334 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3335 gPlayer2Settings
.Color
,
3336 gPlayer2Settings
.Team
, False));
3337 if gPlayer2
= nil then
3339 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3343 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3347 // Çàãðóçêà è çàïóñê êàðòû:
3348 if not g_Game_StartMap(Map
, True) then
3350 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3354 // Íåò òî÷åê ïîÿâëåíèÿ:
3355 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3356 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3357 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3358 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3359 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3361 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3365 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3369 for i
:= nPl
+1 to nPlayers
do
3370 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3373 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3374 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3375 Options
: LongWord; nPlayers
: Byte;
3376 IPAddr
: LongWord; Port
: Word);
3380 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3382 g_Game_ClearLoading();
3385 gGameSettings
.GameType
:= GT_SERVER
;
3386 gGameSettings
.GameMode
:= GameMode
;
3387 gSwitchGameMode
:= GameMode
;
3388 gGameSettings
.TimeLimit
:= TimeLimit
;
3389 gGameSettings
.GoalLimit
:= GoalLimit
;
3390 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3391 gGameSettings
.Options
:= Options
;
3393 gCoopTotalMonstersKilled
:= 0;
3394 gCoopTotalSecretsFound
:= 0;
3395 gCoopTotalMonsters
:= 0;
3396 gCoopTotalSecrets
:= 0;
3400 g_Game_ExecuteEvent('ongamestart');
3402 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3403 g_Game_SetupScreenSize();
3405 // Ðåæèì íàáëþäàòåëÿ:
3406 if nPlayers
= 0 then
3412 if nPlayers
>= 1 then
3414 // Ñîçäàíèå ïåðâîãî èãðîêà:
3415 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3416 gPlayer1Settings
.Color
,
3417 gPlayer1Settings
.Team
, False));
3418 if gPlayer1
= nil then
3420 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3424 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3427 if nPlayers
>= 2 then
3429 // Ñîçäàíèå âòîðîãî èãðîêà:
3430 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3431 gPlayer2Settings
.Color
,
3432 gPlayer2Settings
.Team
, False));
3433 if gPlayer2
= nil then
3435 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3439 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3443 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3445 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3449 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3451 // Çàãðóçêà è çàïóñê êàðòû:
3452 if not g_Game_StartMap(Map
, True) then
3454 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3458 // Íåò òî÷åê ïîÿâëåíèÿ:
3459 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3460 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3461 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3462 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3463 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3465 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3469 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3472 NetState
:= NET_STATE_GAME
;
3475 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3489 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3490 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3492 g_Game_ClearLoading();
3495 gGameSettings
.GameType
:= GT_CLIENT
;
3497 gCoopTotalMonstersKilled
:= 0;
3498 gCoopTotalSecretsFound
:= 0;
3499 gCoopTotalMonsters
:= 0;
3500 gCoopTotalSecrets
:= 0;
3504 g_Game_ExecuteEvent('ongamestart');
3506 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3507 g_Game_SetupScreenSize();
3509 NetState
:= NET_STATE_AUTH
;
3511 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3513 if not g_Net_Connect(Addr
, Port
) then
3515 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3516 NetState
:= NET_STATE_NONE
;
3520 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3522 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3527 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3529 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3531 Ptr
:= NetEvent
.packet
^.data
;
3534 MID
:= e_Raw_Read_Byte(Ptr
);
3536 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3538 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3539 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3541 WadName
:= e_Raw_Read_String(Ptr
);
3542 Map
:= e_Raw_Read_String(Ptr
);
3544 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3546 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3547 gSwitchGameMode
:= gGameSettings
.GameMode
;
3548 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3549 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3550 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3551 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3552 T
:= e_Raw_Read_LongWord(Ptr
);
3554 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3555 if newResPath
= '' then
3557 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3558 newResPath
:= g_Res_DownloadWAD(WadName
);
3559 if newResPath
= '' then
3561 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3562 enet_packet_destroy(NetEvent
.packet
);
3563 NetState
:= NET_STATE_NONE
;
3567 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3569 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3570 gPlayer1Settings
.Color
,
3571 gPlayer1Settings
.Team
, False));
3573 if gPlayer1
= nil then
3575 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3577 enet_packet_destroy(NetEvent
.packet
);
3578 NetState
:= NET_STATE_NONE
;
3582 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3583 gPlayer1
.UID
:= NetPlrUID1
;
3584 gPlayer1
.Reset(True);
3586 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3588 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3590 enet_packet_destroy(NetEvent
.packet
);
3591 NetState
:= NET_STATE_NONE
;
3599 enet_packet_destroy(NetEvent
.packet
);
3603 enet_packet_destroy(NetEvent
.packet
);
3606 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3609 if (NetEvent
.data
<= NET_DISC_MAX
) then
3610 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3611 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3621 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3630 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3631 NetState
:= NET_STATE_NONE
;
3635 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3636 gLMSRespawnTime
:= 0;
3639 NetState
:= NET_STATE_GAME
;
3640 MC_SEND_FullStateRequest
;
3641 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3644 procedure g_Game_SaveOptions();
3646 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3649 procedure g_Game_ChangeMap(MapPath
: String);
3653 g_Game_ClearLoading();
3655 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3656 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3657 if gExitByTrigger
then
3660 gExitByTrigger
:= False;
3662 if not g_Game_StartMap(MapPath
, Force
) then
3663 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3666 procedure g_Game_Restart();
3670 if g_Game_IsClient
then
3672 map
:= g_ExtractFileName(gMapInfo
.Map
);
3676 g_Game_ClearLoading();
3677 g_Game_StartMap(Map
, True);
3680 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3682 NewWAD
, ResName
: String;
3686 g_Player_RemoveAllCorpses();
3688 if (not g_Game_IsClient
) and
3689 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3690 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3692 if gSwitchGameMode
= GM_CTF
then
3693 gGameSettings
.MaxLives
:= 0;
3694 gGameSettings
.GameMode
:= gSwitchGameMode
;
3697 gSwitchGameMode
:= gGameSettings
.GameMode
;
3699 g_Player_ResetTeams();
3701 if Pos(':\', Map
) > 0 then
3703 NewWAD
:= g_ExtractWadName(Map
);
3704 ResName
:= g_ExtractFileName(Map
);
3705 if g_Game_IsServer
then
3707 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3708 g_Game_LoadWAD(NewWAD
);
3710 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3711 g_Game_ClientWAD(NewWAD
, gWADHash
);
3715 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3718 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3720 gState
:= STATE_NONE
;
3721 g_ActiveWindow
:= nil;
3727 if gGameSettings
.GameMode
= GM_CTF
then
3729 g_Map_ResetFlag(FLAG_RED
);
3730 g_Map_ResetFlag(FLAG_BLUE
);
3731 // CTF, à ôëàãîâ íåò:
3732 if not g_Map_HaveFlagPoints() then
3733 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3738 gState
:= STATE_MENU
;
3745 NetTimeToUpdate
:= 1;
3746 NetTimeToReliable
:= 0;
3747 NetTimeToMaster
:= NetMasterRate
;
3748 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3749 gLMSRespawnTime
:= 0;
3750 gMissionFailed
:= False;
3753 gCoopMonstersKilled
:= 0;
3754 gCoopSecretsFound
:= 0;
3756 gVoteInProgress
:= False;
3757 gVotePassed
:= False;
3763 if not gGameOn
then Exit
;
3765 g_Game_SpectateCenterView();
3767 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3769 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3770 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3771 gLMSSoftSpawn
:= True;
3772 if NetMode
= NET_SERVER
then
3773 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3775 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3778 if NetMode
= NET_SERVER
then
3780 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3783 if NetUseMaster
then
3785 if (NetMHost
= nil) or (NetMPeer
= nil) then
3786 if not g_Net_Slist_Connect
then
3787 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3792 if NetClients
<> nil then
3793 for I
:= 0 to High(NetClients
) do
3794 if NetClients
[I
].Used
then
3796 NetClients
[I
].Voted
:= False;
3797 if NetClients
[I
].RequestedFullUpdate
then
3799 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3800 NetClients
[I
].RequestedFullUpdate
:= False;
3804 g_Net_UnbanNonPermHosts();
3809 gCoopTotalMonstersKilled
:= 0;
3810 gCoopTotalSecretsFound
:= 0;
3811 gCoopTotalMonsters
:= 0;
3812 gCoopTotalSecrets
:= 0;
3816 g_Game_ExecuteEvent('onmapstart');
3819 procedure SetFirstLevel();
3823 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3824 if MapList
= nil then
3827 SortSArray(MapList
);
3828 gNextMap
:= MapList
[Low(MapList
)];
3833 procedure g_Game_ExitLevel(Map
: Char16
);
3837 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3838 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3839 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3840 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3842 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3843 if gGameSettings
.GameType
= GT_SINGLE
then
3844 gExit
:= EXIT_ENDLEVELSINGLE
3845 else // Âûøëè â âûõîä â Ñâîåé èãðå
3847 gExit
:= EXIT_ENDLEVELCUSTOM
;
3848 if gGameSettings
.GameMode
= GM_COOP
then
3849 g_Player_RememberAll
;
3851 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3854 if gGameSettings
.GameMode
= GM_COOP
then
3857 gStatsPressed
:= True;
3858 gNextMap
:= 'MAP01';
3860 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3863 if g_Game_IsNet
then
3865 MH_SEND_GameStats();
3866 MH_SEND_CoopStats();
3872 procedure g_Game_RestartLevel();
3876 if gGameSettings
.GameMode
= GM_SINGLE
then
3881 gExit
:= EXIT_ENDLEVELCUSTOM
;
3882 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3886 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3890 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3892 if not g_Game_IsClient
then
3894 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3897 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3898 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3902 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3906 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3907 g_Game_LoadWAD(NewWAD
);
3910 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3912 i
, n
, nb
, nr
: Integer;
3914 if not g_Game_IsServer
then Exit
;
3915 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3916 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3917 gLMSRespawnTime
:= 0;
3920 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3922 gMissionFailed
:= True;
3923 g_Game_RestartLevel
;
3927 n
:= 0; nb
:= 0; nr
:= 0;
3928 for i
:= Low(gPlayers
) to High(gPlayers
) do
3929 if (gPlayers
[i
] <> nil) and
3930 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3931 (gPlayers
[i
] is TBot
)) then
3934 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3935 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3938 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3940 // wait a second until the fuckers finally decide to join
3941 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3942 gLMSRespawnTime
:= gTime
+ 1000;
3943 gLMSSoftSpawn
:= NoMapRestart
;
3947 g_Player_RemoveAllCorpses
;
3948 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3949 if g_Game_IsNet
then
3950 MH_SEND_GameEvent(NET_EV_LMS_START
);
3952 for i
:= Low(gPlayers
) to High(gPlayers
) do
3954 if gPlayers
[i
] = nil then continue
;
3955 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3956 // don't touch normal spectators
3957 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3959 gPlayers
[i
].FNoRespawn
:= True;
3960 gPlayers
[i
].Lives
:= 0;
3961 if g_Game_IsNet
then
3962 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3965 gPlayers
[i
].FNoRespawn
:= False;
3966 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3967 gPlayers
[i
].Respawn(False, True);
3968 if gGameSettings
.GameMode
= GM_COOP
then
3970 gPlayers
[i
].Frags
:= 0;
3971 gPlayers
[i
].RecallState
;
3973 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3974 gPlayer1
:= g_Player_Get(gLMSPID1
);
3975 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3976 gPlayer2
:= g_Player_Get(gLMSPID2
);
3979 for i
:= Low(gItems
) to High(gItems
) do
3981 if gItems
[i
].Respawnable
then
3983 gItems
[i
].QuietRespawn
:= True;
3984 gItems
[i
].RespawnTime
:= 0;
3989 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3993 for i
:= Low(gMonsters
) to High(gMonsters
) do
3995 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
3996 gMonsters
[i
].Respawn
;
3999 gLMSSoftSpawn
:= False;
4002 function g_Game_GetFirstMap(WAD
: String): String;
4006 MapList
:= g_Map_GetMapsList(WAD
);
4007 if MapList
= nil then
4010 SortSArray(MapList
);
4011 Result
:= MapList
[Low(MapList
)];
4013 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4019 function g_Game_GetNextMap(): String;
4026 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4027 if MapList
= nil then
4030 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4032 SortSArray(MapList
);
4034 for I
:= Low(MapList
) to High(MapList
) do
4035 if Map
= MapList
[I
] then
4041 if MapIndex
<> -255 then
4043 if MapIndex
= High(MapList
) then
4044 Result
:= MapList
[Low(MapList
)]
4046 Result
:= MapList
[MapIndex
+ 1];
4048 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4054 procedure g_Game_NextLevel();
4056 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4057 gExit
:= EXIT_ENDLEVELCUSTOM
4060 gExit
:= EXIT_ENDLEVELSINGLE
;
4064 if gNextMap
<> '' then Exit
;
4065 gNextMap
:= g_Game_GetNextMap();
4068 function g_Game_IsTestMap(): Boolean;
4070 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4073 procedure g_Game_DeleteTestMap();
4084 a
:= Pos('.wad:\', gMapToDelete
);
4088 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4089 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4090 Delete(gMapToDelete
, 1, a
+ 5);
4091 gMapToDelete
:= UpperCase(gMapToDelete
);
4093 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4096 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4097 if MapName <> TEST_MAP_NAME then
4100 if not gTempDelete then
4102 time := g_GetFileTime(WadName);
4103 WAD := TWADFile.Create();
4106 if not WAD.ReadFile(WadName) then
4107 begin // Íåò òàêîãî WAD-ôàéëà
4112 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4114 MapList := WAD.GetResourcesList('');
4116 if MapList <> nil then
4117 for a := 0 to High(MapList) do
4118 if MapList[a] = MapName then
4120 // Óäàëÿåì è ñîõðàíÿåì:
4121 WAD.RemoveResource('', MapName);
4122 WAD.SaveTo(WadName);
4127 g_SetFileTime(WadName, time);
4130 if gTempDelete
then DeleteFile(WadName
);
4133 procedure GameCVars(P
: SArray
);
4136 stat
: TPlayerStatArray
;
4141 cmd
:= LowerCase(P
[0]);
4142 if cmd
= 'r_showfps' then
4144 if (Length(P
) > 1) and
4145 ((P
[1] = '1') or (P
[1] = '0')) then
4146 gShowFPS
:= (P
[1][1] = '1');
4149 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4151 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4153 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4155 with gGameSettings
do
4157 if (Length(P
) > 1) and
4158 ((P
[1] = '1') or (P
[1] = '0')) then
4160 if (P
[1][1] = '1') then
4161 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4163 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4166 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4167 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4169 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4171 if g_Game_IsNet
then MH_SEND_GameSettings
;
4174 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4176 with gGameSettings
do
4178 if (Length(P
) > 1) and
4179 ((P
[1] = '1') or (P
[1] = '0')) then
4181 if (P
[1][1] = '1') then
4182 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4184 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4187 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4188 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4190 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4192 if g_Game_IsNet
then MH_SEND_GameSettings
;
4195 else if cmd
= 'g_gamemode' then
4197 a
:= g_Game_TextToMode(P
[1]);
4198 if a
= GM_SINGLE
then a
:= GM_COOP
;
4199 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4201 gSwitchGameMode
:= a
;
4202 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4203 (gState
= STATE_INTERSINGLE
) then
4204 gSwitchGameMode
:= GM_SINGLE
;
4206 gGameSettings
.GameMode
:= gSwitchGameMode
;
4208 if gSwitchGameMode
= gGameSettings
.GameMode
then
4209 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4210 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4212 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4213 [g_Game_ModeToText(gGameSettings
.GameMode
),
4214 g_Game_ModeToText(gSwitchGameMode
)]));
4216 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4218 with gGameSettings
do
4220 if (Length(P
) > 1) and
4221 ((P
[1] = '1') or (P
[1] = '0')) then
4223 if (P
[1][1] = '1') then
4224 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4226 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4229 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4230 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4232 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4233 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4235 if g_Game_IsNet
then MH_SEND_GameSettings
;
4238 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4240 with gGameSettings
do
4242 if (Length(P
) > 1) and
4243 ((P
[1] = '1') or (P
[1] = '0')) then
4245 if (P
[1][1] = '1') then
4246 Options
:= Options
or GAME_OPTION_MONSTERS
4248 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4251 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4252 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4254 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4255 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4257 if g_Game_IsNet
then MH_SEND_GameSettings
;
4260 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4262 with gGameSettings
do
4264 if (Length(P
) > 1) and
4265 ((P
[1] = '1') or (P
[1] = '0')) then
4267 if (P
[1][1] = '1') then
4268 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4270 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4273 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4274 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4276 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4278 if g_Game_IsNet
then MH_SEND_GameSettings
;
4281 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4283 with gGameSettings
do
4285 if (Length(P
) > 1) and
4286 ((P
[1] = '1') or (P
[1] = '0')) then
4288 if (P
[1][1] = '1') then
4289 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4291 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4294 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4295 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4297 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4299 if g_Game_IsNet
then MH_SEND_GameSettings
;
4302 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4304 if Length(P
) > 1 then
4306 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4307 gGameSettings
.WarmupTime
:= 30
4309 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4312 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4313 [gGameSettings
.WarmupTime
]));
4314 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4316 else if cmd
= 'net_interp' then
4318 if (Length(P
) > 1) then
4319 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4321 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4322 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4323 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4324 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4327 else if cmd
= 'net_forceplayerupdate' then
4329 if (Length(P
) > 1) and
4330 ((P
[1] = '1') or (P
[1] = '0')) then
4331 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4333 if NetForcePlayerUpdate
then
4334 g_Console_Add('net_forceplayerupdate = 1')
4336 g_Console_Add('net_forceplayerupdate = 0');
4337 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4338 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4339 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4342 else if cmd
= 'net_predictself' then
4344 if (Length(P
) > 1) and
4345 ((P
[1] = '1') or (P
[1] = '0')) then
4346 NetPredictSelf
:= (P
[1][1] = '1');
4348 if NetPredictSelf
then
4349 g_Console_Add('net_predictself = 1')
4351 g_Console_Add('net_predictself = 0');
4352 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4353 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4354 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4357 else if cmd
= 'sv_name' then
4359 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4361 NetServerName
:= P
[1];
4362 if Length(NetServerName
) > 64 then
4363 SetLength(NetServerName
, 64);
4364 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4368 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4370 else if cmd
= 'sv_passwd' then
4372 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4374 NetPassword
:= P
[1];
4375 if Length(NetPassword
) > 24 then
4376 SetLength(NetPassword
, 24);
4377 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4381 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4383 else if cmd
= 'sv_maxplrs' then
4385 if (Length(P
) > 1) then
4387 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4388 if g_Game_IsServer
and g_Game_IsNet
then
4391 for a
:= 0 to High(NetClients
) do
4392 if NetClients
[a
].Used
then
4395 if b
> NetMaxClients
then
4397 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4398 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4399 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4400 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4403 if NetUseMaster
then
4408 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4410 else if cmd
= 'sv_public' then
4412 if (Length(P
) > 1) then
4414 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4415 if g_Game_IsServer
and g_Game_IsNet
then
4416 if NetUseMaster
then
4418 if NetMPeer
= nil then
4419 if not g_Net_Slist_Connect() then
4420 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4421 g_Net_Slist_Update();
4424 if NetMPeer
<> nil then
4425 g_Net_Slist_Disconnect();
4428 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4430 else if cmd
= 'sv_intertime' then
4432 if (Length(P
) > 1) then
4433 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4435 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4437 else if cmd
= 'p1_name' then
4439 if (Length(P
) > 1) and gGameOn
then
4441 if g_Game_IsClient
then
4443 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4444 MC_SEND_PlayerSettings
;
4447 if gPlayer1
<> nil then
4449 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4450 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4453 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4456 else if cmd
= 'p2_name' then
4458 if (Length(P
) > 1) and gGameOn
then
4460 if g_Game_IsClient
then
4462 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4463 MC_SEND_PlayerSettings
;
4466 if gPlayer2
<> nil then
4468 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4469 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4472 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4475 else if cmd
= 'p1_color' then
4477 if Length(P
) > 3 then
4478 if g_Game_IsClient
then
4480 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4481 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4482 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4483 MC_SEND_PlayerSettings
;
4486 if gPlayer1
<> nil then
4488 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4489 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4490 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4491 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4494 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4495 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4496 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4498 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4500 if Length(P
) > 3 then
4501 if g_Game_IsClient
then
4503 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4504 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4505 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4506 MC_SEND_PlayerSettings
;
4509 if gPlayer2
<> nil then
4511 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4512 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4513 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4514 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4517 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4518 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4519 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4521 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4523 if cmd
= 'r_showtime' then
4525 if (Length(P
) > 1) and
4526 ((P
[1] = '1') or (P
[1] = '0')) then
4527 gShowTime
:= (P
[1][1] = '1');
4530 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4532 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4534 else if cmd
= 'r_showscore' then
4536 if (Length(P
) > 1) and
4537 ((P
[1] = '1') or (P
[1] = '0')) then
4538 gShowGoals
:= (P
[1][1] = '1');
4541 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4543 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4545 else if cmd
= 'r_showstat' then
4547 if (Length(P
) > 1) and
4548 ((P
[1] = '1') or (P
[1] = '0')) then
4549 gShowStat
:= (P
[1][1] = '1');
4552 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4554 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4556 else if cmd
= 'r_showkillmsg' then
4558 if (Length(P
) > 1) and
4559 ((P
[1] = '1') or (P
[1] = '0')) then
4560 gShowKillMsg
:= (P
[1][1] = '1');
4562 if gShowKillMsg
then
4563 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4565 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4567 else if cmd
= 'r_showlives' then
4569 if (Length(P
) > 1) and
4570 ((P
[1] = '1') or (P
[1] = '0')) then
4571 gShowLives
:= (P
[1][1] = '1');
4574 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4576 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4578 else if cmd
= 'r_showspect' then
4580 if (Length(P
) > 1) and
4581 ((P
[1] = '1') or (P
[1] = '0')) then
4582 gSpectHUD
:= (P
[1][1] = '1');
4585 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4587 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4589 else if cmd
= 'r_showping' then
4591 if (Length(P
) > 1) and
4592 ((P
[1] = '1') or (P
[1] = '0')) then
4593 gShowPing
:= (P
[1][1] = '1');
4596 g_Console_Add(_lc
[I_MSG_PING_ON
])
4598 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4600 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4602 if Length(P
) > 1 then
4604 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4605 gGameSettings
.GoalLimit
:= 0
4610 if gGameSettings
.GameMode
= GM_DM
then
4612 stat
:= g_Player_GetStats();
4614 for a
:= 0 to High(stat
) do
4615 if stat
[a
].Frags
> b
then
4619 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4621 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4624 if g_Game_IsNet
then MH_SEND_GameSettings
;
4627 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4629 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4631 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4632 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4634 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4635 [gGameSettings
.TimeLimit
div 3600,
4636 (gGameSettings
.TimeLimit
div 60) mod 60,
4637 gGameSettings
.TimeLimit
mod 60]));
4638 if g_Game_IsNet
then MH_SEND_GameSettings
;
4640 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4642 if Length(P
) > 1 then
4644 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4645 gGameSettings
.MaxLives
:= 0
4649 stat
:= g_Player_GetStats();
4651 for a
:= 0 to High(stat
) do
4652 if stat
[a
].Lives
> b
then
4654 gGameSettings
.MaxLives
:=
4655 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4659 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4660 [gGameSettings
.MaxLives
]));
4661 if g_Game_IsNet
then MH_SEND_GameSettings
;
4666 procedure DebugCommands(P
: SArray
);
4672 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4675 cmd
:= LowerCase(P
[0]);
4676 if cmd
= 'd_window' then
4678 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4679 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4680 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4681 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4682 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4684 else if cmd
= 'd_sounds' then
4686 if (Length(P
) > 1) and
4687 ((P
[1] = '1') or (P
[1] = '0')) then
4688 g_Debug_Sounds
:= (P
[1][1] = '1');
4690 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4692 else if cmd
= 'd_frames' then
4694 if (Length(P
) > 1) and
4695 ((P
[1] = '1') or (P
[1] = '0')) then
4696 g_Debug_Frames
:= (P
[1][1] = '1');
4698 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4700 else if cmd
= 'd_winmsg' then
4702 if (Length(P
) > 1) and
4703 ((P
[1] = '1') or (P
[1] = '0')) then
4704 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4706 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4708 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4710 if (Length(P
) > 1) and
4711 ((P
[1] = '1') or (P
[1] = '0')) then
4712 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4714 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4716 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4718 if Length(P
) > 1 then
4720 '0': g_debug_BotAIOff
:= 0;
4721 '1': g_debug_BotAIOff
:= 1;
4722 '2': g_debug_BotAIOff
:= 2;
4723 '3': g_debug_BotAIOff
:= 3;
4726 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4728 else if cmd
= 'd_monster' then
4730 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4731 if Length(P
) < 2 then
4733 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4734 g_Console_Add('ID | Name');
4735 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4736 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4739 a
:= StrToIntDef(P
[1], 0);
4740 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4741 a
:= g_Monsters_GetIDByName(P
[1]);
4743 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4744 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4747 with gPlayer1
.Obj
do
4748 b
:= g_Monsters_Create(a
,
4749 X
+ Rect
.X
+ (Rect
.Width
div 2),
4750 Y
+ Rect
.Y
+ Rect
.Height
,
4751 gPlayer1
.Direction
, True);
4752 if (Length(P
) > 2) and (b
>= 0) then
4753 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4757 else if (cmd
= 'd_health') then
4759 if (Length(P
) > 1) and
4760 ((P
[1] = '1') or (P
[1] = '0')) then
4761 g_debug_HealthBar
:= (P
[1][1] = '1');
4763 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4765 else if (cmd
= 'd_player') then
4767 if (Length(P
) > 1) and
4768 ((P
[1] = '1') or (P
[1] = '0')) then
4769 g_debug_Player
:= (P
[1][1] = '1');
4771 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4773 else if (cmd
= 'd_joy') then
4776 g_Console_Add(e_JoystickStateToString(a
));
4780 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4784 procedure GameCheats(P
: SArray
);
4790 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4791 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4793 g_Console_Add('not available');
4799 g_Console_Add('where is the player?!');
4802 cmd
:= LowerCase(P
[0]);
4806 plr
.GodMode
:= not plr
.GodMode
;
4807 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4810 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4811 if cmd
= 'give' then
4813 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4814 for f
:= 1 to High(P
) do
4816 cmd
:= LowerCase(P
[f
]);
4817 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4818 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4819 if cmd
= 'exit' then
4821 if gTriggers
<> nil then
4823 for a
:= 0 to High(gTriggers
) do
4825 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4827 g_Console_Add('player left the map');
4828 gExitByTrigger
:= True;
4829 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4837 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4838 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4839 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4840 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4841 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4843 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4844 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4846 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4847 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;
4849 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4850 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4852 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4853 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4855 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4856 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4858 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4859 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4860 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4862 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4863 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4864 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4865 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;
4866 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4867 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4869 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;
4870 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;
4871 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;
4872 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;
4873 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;
4874 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;
4876 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4877 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;
4879 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;
4880 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;
4882 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4884 if cmd
= 'ammo' then
4886 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4887 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4888 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4889 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4890 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4891 g_Console_Add('player got some ammo');
4895 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4896 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4898 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4899 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4901 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4902 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4904 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4905 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4907 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4909 if cmd
= 'weapons' then
4911 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4912 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4913 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4914 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4915 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4916 plr
.GiveItem(ITEM_WEAPON_BFG
);
4917 g_Console_Add('player got weapons');
4921 if cmd
= 'keys' then
4923 plr
.GiveItem(ITEM_KEY_RED
);
4924 plr
.GiveItem(ITEM_KEY_GREEN
);
4925 plr
.GiveItem(ITEM_KEY_BLUE
);
4926 g_Console_Add('player got all keys');
4930 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4935 if cmd
= 'open' then
4937 g_Console_Add('player activated sesame');
4938 g_Triggers_OpenAll();
4945 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4949 if cmd
= 'noclip' then
4952 g_Console_Add('wall hardeness adjusted');
4956 if cmd
= 'notarget' then
4958 plr
.NoTarget
:= not plr
.NoTarget
;
4959 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4963 if cmd
= 'noreload' then
4965 plr
.NoReload
:= not plr
.NoReload
;
4966 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4970 if cmd
= 'speedy' then
4972 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4973 g_Console_Add('speed adjusted');
4977 if cmd
= 'jumpy' then
4979 VEL_JUMP
:= 30-VEL_JUMP
;
4980 g_Console_Add('jump height adjusted');
4984 if cmd
= 'automap' then
4986 gShowMap
:= not gShowMap
;
4987 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4991 if cmd
= 'aimline' then
4993 gAimLine
:= not gAimLine
;
4994 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4999 procedure GameCommands(P
: SArray
);
5005 pl
: pTNetClient
= nil;
5012 cmd
:= LowerCase(P
[0]);
5014 if (cmd
= 'quit') or
5021 else if cmd
= 'pause' then
5023 if (g_ActiveWindow
= nil) then
5024 g_Game_Pause(not gPause
);
5026 else if cmd
= 'endgame' then
5027 gExit
:= EXIT_SIMPLE
5028 else if cmd
= 'restart' then
5030 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5032 if g_Game_IsClient
then
5034 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5039 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5041 else if cmd
= 'kick' then
5043 if g_Game_IsServer
then
5045 if Length(P
) < 2 then
5047 g_Console_Add('kick <name>');
5052 g_Console_Add('kick <name>');
5056 if g_Game_IsNet
then
5057 pl
:= g_Net_Client_ByName(P
[1]);
5060 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5061 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5062 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5063 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5064 if NetUseMaster
then
5066 end else if gPlayers
<> nil then
5067 for a
:= Low(gPlayers
) to High(gPlayers
) do
5068 if gPlayers
[a
] <> nil then
5069 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5071 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5072 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5074 gPlayers
[a
].Lives
:= 0;
5075 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5076 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5077 g_Player_Remove(gPlayers
[a
].UID
);
5078 if NetUseMaster
then
5080 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5084 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5086 else if cmd
= 'kick_id' then
5088 if g_Game_IsServer
and g_Game_IsNet
then
5090 if Length(P
) < 2 then
5092 g_Console_Add('kick_id <client ID>');
5097 g_Console_Add('kick_id <client ID>');
5101 a
:= StrToIntDef(P
[1], 0);
5102 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5104 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5106 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5107 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5108 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5109 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5110 if NetUseMaster
then
5115 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5117 else if cmd
= 'ban' then
5119 if g_Game_IsServer
and g_Game_IsNet
then
5121 if Length(P
) < 2 then
5123 g_Console_Add('ban <name>');
5128 g_Console_Add('ban <name>');
5132 pl
:= g_Net_Client_ByName(P
[1]);
5135 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5136 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5137 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5138 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5139 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5140 if NetUseMaster
then
5143 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5145 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5147 else if cmd
= 'ban_id' then
5149 if g_Game_IsServer
and g_Game_IsNet
then
5151 if Length(P
) < 2 then
5153 g_Console_Add('ban_id <client ID>');
5158 g_Console_Add('ban_id <client ID>');
5162 a
:= StrToIntDef(P
[1], 0);
5163 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5164 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5166 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5167 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5168 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5169 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5170 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5171 if NetUseMaster
then
5175 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5177 else if cmd
= 'permban' then
5179 if g_Game_IsServer
and g_Game_IsNet
then
5181 if Length(P
) < 2 then
5183 g_Console_Add('permban <name>');
5188 g_Console_Add('permban <name>');
5192 pl
:= g_Net_Client_ByName(P
[1]);
5195 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5196 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5197 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5198 g_Net_SaveBanList();
5199 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5200 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5201 if NetUseMaster
then
5204 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5206 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5208 else if cmd
= 'permban_id' then
5210 if g_Game_IsServer
and g_Game_IsNet
then
5212 if Length(P
) < 2 then
5214 g_Console_Add('permban_id <client ID>');
5219 g_Console_Add('permban_id <client ID>');
5223 a
:= StrToIntDef(P
[1], 0);
5224 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5225 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5227 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5228 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5229 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5230 g_Net_SaveBanList();
5231 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5232 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5233 if NetUseMaster
then
5237 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5239 else if cmd
= 'unban' then
5241 if g_Game_IsServer
and g_Game_IsNet
then
5243 if Length(P
) < 2 then
5245 g_Console_Add('unban <IP Address>');
5250 g_Console_Add('unban <IP Address>');
5254 if g_Net_UnbanHost(P
[1]) then
5256 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5257 g_Net_SaveBanList();
5259 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5261 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5263 else if cmd
= 'clientlist' then
5265 if g_Game_IsServer
and g_Game_IsNet
then
5268 if NetClients
<> nil then
5269 for a
:= Low(NetClients
) to High(NetClients
) do
5270 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5272 plr
:= g_Player_Get(NetClients
[a
].Player
);
5273 if plr
= nil then continue
;
5275 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5276 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5279 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5281 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5283 else if cmd
= 'connect' then
5285 if (NetMode
= NET_NONE
) then
5287 if Length(P
) < 2 then
5289 g_Console_Add('connect <IP> [port] [password]');
5294 g_Console_Add('connect <IP> [port] [password]');
5298 if Length(P
) > 2 then
5299 prt
:= StrToIntDef(P
[2], 25666)
5303 if Length(P
) > 3 then
5308 g_Game_StartClient(P
[1], prt
, pw
);
5311 else if cmd
= 'disconnect' then
5313 if (NetMode
= NET_CLIENT
) then
5316 else if cmd
= 'reconnect' then
5318 if (NetMode
= NET_SERVER
) then
5321 if (NetMode
= NET_CLIENT
) then
5324 gExit
:= EXIT_SIMPLE
;
5328 //TODO: Use last successful password to reconnect, instead of ''
5329 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5331 else if (cmd
= 'addbot') or
5332 (cmd
= 'bot_add') then
5334 if Length(P
) > 1 then
5335 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5337 g_Bot_Add(TEAM_NONE
, 2);
5339 else if cmd
= 'bot_addlist' then
5341 if Length(P
) > 1 then
5342 if Length(P
) = 2 then
5343 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5345 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5347 else if cmd
= 'bot_removeall' then
5349 else if cmd
= 'chat' then
5351 if g_Game_IsNet
then
5353 if Length(P
) > 1 then
5355 for a
:= 1 to High(P
) do
5356 chstr
:= chstr
+ P
[a
] + ' ';
5358 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5360 if Length(chstr
) < 1 then
5362 g_Console_Add('chat <text>');
5366 chstr
:= b_Text_Format(chstr
);
5367 if g_Game_IsClient
then
5368 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5370 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5373 g_Console_Add('chat <text>');
5375 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5377 else if cmd
= 'teamchat' then
5379 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5381 if Length(P
) > 1 then
5383 for a
:= 1 to High(P
) do
5384 chstr
:= chstr
+ P
[a
] + ' ';
5386 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5388 if Length(chstr
) < 1 then
5390 g_Console_Add('teamchat <text>');
5394 chstr
:= b_Text_Format(chstr
);
5395 if g_Game_IsClient
then
5396 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5398 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5399 gPlayer1Settings
.Team
);
5402 g_Console_Add('teamchat <text>');
5404 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5406 else if cmd
= 'game' then
5408 if gGameSettings
.GameType
<> GT_NONE
then
5410 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5413 if Length(P
) = 1 then
5415 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5418 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5419 P
[1] := addWadExtension(P
[1]);
5420 if FileExists(MapsDir
+ P
[1]) then
5422 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5423 if Length(P
) < 3 then
5426 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5429 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5431 if g_Map_Exist(MapsDir
+ s
) then
5433 // Çàïóñêàåì ñâîþ èãðó
5435 with gGameSettings
do
5437 GameMode
:= g_Game_TextToMode(gcGameMode
);
5438 if gSwitchGameMode
<> GM_NONE
then
5439 GameMode
:= gSwitchGameMode
;
5440 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5441 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5443 if Length(P
) >= 4 then
5444 b
:= StrToIntDef(P
[3], 1);
5445 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5446 GoalLimit
, MaxLives
, Options
, b
);
5451 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5453 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5455 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5457 else if cmd
= 'host' then
5459 if gGameSettings
.GameType
<> GT_NONE
then
5461 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5464 if Length(P
) < 4 then
5466 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5469 if not StrToIp(P
[1], listen
) then
5471 prt
:= StrToIntDef(P
[2], 25666);
5473 P
[3] := addWadExtension(P
[3]);
5474 if FileExists(MapsDir
+ P
[3]) then
5476 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5477 if Length(P
) < 5 then
5480 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5483 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5485 if g_Map_Exist(MapsDir
+ s
) then
5487 // Çàïóñêàåì ñâîþ èãðó
5489 with gGameSettings
do
5491 GameMode
:= g_Game_TextToMode(gcGameMode
);
5492 if gSwitchGameMode
<> GM_NONE
then
5493 GameMode
:= gSwitchGameMode
;
5494 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5495 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5497 if Length(P
) >= 6 then
5498 b
:= StrToIntDef(P
[5], 0);
5499 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5500 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5505 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5507 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5509 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5511 else if cmd
= 'map' then
5513 if Length(P
) = 1 then
5515 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5517 g_Console_Add(cmd
+ ' <MAP>');
5518 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5520 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5522 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5524 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5525 if Length(P
) < 3 then
5527 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5528 s
:= UpperCase(P
[1]);
5529 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5530 begin // Êàðòà íàøëàñü
5531 gExitByTrigger
:= False;
5533 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5535 gExit
:= EXIT_ENDLEVELCUSTOM
;
5537 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5538 g_Game_ChangeMap(s
);
5541 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5542 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5543 P
[1] := addWadExtension(P
[1]);
5544 if FileExists(MapsDir
+ P
[1]) then
5546 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5548 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5550 s
:= P
[1] + ':\' + P
[2];
5552 if g_Map_Exist(MapsDir
+ s
) then
5554 gExitByTrigger
:= False;
5556 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5558 gExit
:= EXIT_ENDLEVELCUSTOM
;
5560 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5561 g_Game_ChangeMap(s
);
5564 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5566 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5568 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5572 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5573 P
[1] := addWadExtension(P
[1]);
5574 if FileExists(MapsDir
+ P
[1]) then
5577 P
[2] := UpperCase(P
[2]);
5578 s
:= P
[1] + ':\' + P
[2];
5580 if g_Map_Exist(MapsDir
+ s
) then
5581 begin // Íàøëè êàðòó
5582 gExitByTrigger
:= False;
5584 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5586 gExit
:= EXIT_ENDLEVELCUSTOM
;
5588 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5589 g_Game_ChangeMap(s
);
5591 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5593 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5596 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5598 else if cmd
= 'nextmap' then
5600 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5601 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5604 if Length(P
) = 1 then
5606 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5608 g_Console_Add(cmd
+ ' <MAP>');
5609 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5612 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5617 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5619 if Length(P
) < 3 then
5621 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5622 s
:= UpperCase(P
[1]);
5623 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5624 begin // Êàðòà íàøëàñü
5625 gExitByTrigger
:= False;
5630 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5631 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5632 P
[1] := addWadExtension(P
[1]);
5633 if FileExists(MapsDir
+ P
[1]) then
5635 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5637 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5639 s
:= P
[1] + ':\' + P
[2];
5641 if g_Map_Exist(MapsDir
+ s
) then
5642 begin // Óñòàíàâëèâàåì êàðòó
5643 gExitByTrigger
:= False;
5648 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5650 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5652 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5656 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5657 P
[1] := addWadExtension(P
[1]);
5658 if FileExists(MapsDir
+ P
[1]) then
5661 P
[2] := UpperCase(P
[2]);
5662 s
:= P
[1] + ':\' + P
[2];
5664 if g_Map_Exist(MapsDir
+ s
) then
5665 begin // Íàøëè êàðòó
5666 gExitByTrigger
:= False;
5670 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5672 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5675 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5678 if gNextMap
= '' then
5679 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5681 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5684 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5687 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5689 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5691 gExitByTrigger
:= False;
5692 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5693 if (gNextMap
= '') and (gTriggers
<> nil) then
5694 for a
:= 0 to High(gTriggers
) do
5695 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5697 gExitByTrigger
:= True;
5698 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5701 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5702 if gNextMap
= '' then
5703 gNextMap
:= g_Game_GetNextMap();
5704 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5705 if Pos(':\', gNextMap
) = 0 then
5706 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5709 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5710 if g_Map_Exist(MapsDir
+ s
) then
5711 gExit
:= EXIT_ENDLEVELCUSTOM
5713 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5715 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5717 else if (cmd
= 'event') then
5719 if (Length(P
) <= 1) then
5721 for a
:= 0 to High(gEvents
) do
5722 if gEvents
[a
].Command
= '' then
5723 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5725 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5728 if (Length(P
) = 2) then
5730 for a
:= 0 to High(gEvents
) do
5731 if gEvents
[a
].Name
= P
[1] then
5732 if gEvents
[a
].Command
= '' then
5733 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5735 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5738 for a
:= 0 to High(gEvents
) do
5739 if gEvents
[a
].Name
= P
[1] then
5741 gEvents
[a
].Command
:= '';
5742 for b
:= 2 to High(P
) do
5743 if Pos(' ', P
[b
]) = 0 then
5744 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5746 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5747 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5751 // Êîìàíäû Ñâîåé èãðû:
5752 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5754 if cmd
= 'bot_addred' then
5756 if Length(P
) > 1 then
5757 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5759 g_Bot_Add(TEAM_RED
, 2);
5761 else if cmd
= 'bot_addblue' then
5763 if Length(P
) > 1 then
5764 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5766 g_Bot_Add(TEAM_BLUE
, 2);
5768 else if cmd
= 'suicide' then
5772 if g_Game_IsClient
then
5773 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5776 if gPlayer1
<> nil then
5777 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5778 if gPlayer2
<> nil then
5779 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5783 else if cmd
= 'spectate' then
5789 else if cmd
= 'say' then
5791 if g_Game_IsServer
and g_Game_IsNet
then
5793 if Length(P
) > 1 then
5796 for a
:= 1 to High(P
) do
5797 chstr
:= chstr
+ P
[a
] + ' ';
5799 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5801 if Length(chstr
) < 1 then
5803 g_Console_Add('say <text>');
5807 chstr
:= b_Text_Format(chstr
);
5808 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5810 else g_Console_Add('say <text>');
5812 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5814 else if cmd
= 'tell' then
5816 if g_Game_IsServer
and g_Game_IsNet
then
5818 if (Length(P
) > 2) and (P
[1] <> '') then
5821 for a
:= 2 to High(P
) do
5822 chstr
:= chstr
+ P
[a
] + ' ';
5824 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5826 if Length(chstr
) < 1 then
5828 g_Console_Add('tell <playername> <text>');
5832 pl
:= g_Net_Client_ByName(P
[1]);
5834 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5836 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5838 else g_Console_Add('tell <playername> <text>');
5840 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5842 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5844 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5846 // Äîïîëíèòåëüíîå âðåìÿ:
5847 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5849 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5850 [gGameSettings
.TimeLimit
div 3600,
5851 (gGameSettings
.TimeLimit
div 60) mod 60,
5852 gGameSettings
.TimeLimit
mod 60]));
5853 if g_Game_IsNet
then MH_SEND_GameSettings
;
5855 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5857 if (Length(P
) <= 1) then
5858 g_Console_Add('rcon_password <password>')
5860 MC_SEND_RCONPassword(P
[1]);
5862 else if cmd
= 'rcon' then
5864 if g_Game_IsClient
then
5866 if Length(P
) > 1 then
5869 for a
:= 1 to High(P
) do
5870 chstr
:= chstr
+ P
[a
] + ' ';
5872 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5874 if Length(chstr
) < 1 then
5876 g_Console_Add('rcon <command>');
5880 MC_SEND_RCONCommand(chstr
);
5882 else g_Console_Add('rcon <command>');
5885 else if cmd
= 'ready' then
5887 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5888 gLMSRespawnTime
:= gTime
+ 100;
5890 else if (cmd
= 'callvote') and g_Game_IsNet
then
5892 if Length(P
) > 1 then
5895 for a
:= 1 to High(P
) do begin
5896 if a
> 1 then chstr
:= chstr
+ ' ';
5897 chstr
:= chstr
+ P
[a
];
5900 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5902 if Length(chstr
) < 1 then
5904 g_Console_Add('callvote <command>');
5908 if g_Game_IsClient
then
5909 MC_SEND_Vote(True, chstr
)
5911 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5912 g_Console_Process('vote', True);
5915 g_Console_Add('callvote <command>');
5917 else if (cmd
= 'vote') and g_Game_IsNet
then
5919 if g_Game_IsClient
then
5921 else if gVoteInProgress
then
5923 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5924 a
:= Floor((NetClientCount
+1)/2.0) + 1
5926 a
:= Floor(NetClientCount
/2.0) + 1;
5931 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5932 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5938 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5939 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5947 procedure g_TakeScreenShot();
5955 if e_NoGraphics
then Exit
;
5956 ssdir
:= GameDir
+'/screenshots';
5957 if not findFileCI(ssdir
, true) then
5959 // try to create dir
5964 if not findFileCI(ssdir
, true) then exit
; // alas
5967 for a
:= 1 to High(Word) do
5969 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5971 if findFileCI(t
, true) then continue
;
5972 if not findFileCI(FileName
) then
5975 st
:= createDiskFile(FileName
);
5977 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5982 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5990 procedure g_Game_InGameMenu(Show
: Boolean);
5992 if (g_ActiveWindow
= nil) and Show
then
5994 if gGameSettings
.GameType
= GT_SINGLE
then
5995 g_GUI_ShowWindow('GameSingleMenu')
5998 if g_Game_IsClient
then
5999 g_GUI_ShowWindow('GameClientMenu')
6001 if g_Game_IsNet
then
6002 g_GUI_ShowWindow('GameServerMenu')
6004 g_GUI_ShowWindow('GameCustomMenu');
6006 g_Sound_PlayEx('MENU_OPEN');
6008 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6009 if (not g_Game_IsNet
) then
6013 if (g_ActiveWindow
<> nil) and (not Show
) then
6015 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6016 if (not g_Game_IsNet
) then
6017 g_Game_Pause(False);
6021 procedure g_Game_Pause(Enable
: Boolean);
6026 if gPause
= Enable
then
6029 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6033 g_Game_PauseAllSounds(Enable
);
6036 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6041 if gTriggers
<> nil then
6042 for i
:= 0 to High(gTriggers
) do
6043 with gTriggers
[i
] do
6044 if (TriggerType
= TRIGGER_SOUND
) and
6046 Sound
.IsPlaying() then
6048 Sound
.Pause(Enable
);
6052 if gPlayers
<> nil then
6053 for i
:= 0 to High(gPlayers
) do
6054 if gPlayers
[i
] <> nil then
6055 gPlayers
[i
].PauseSounds(Enable
);
6058 if gMusic
<> nil then
6059 gMusic
.Pause(Enable
);
6062 procedure g_Game_StopAllSounds(all
: Boolean);
6066 if gTriggers
<> nil then
6067 for i
:= 0 to High(gTriggers
) do
6068 with gTriggers
[i
] do
6069 if (TriggerType
= TRIGGER_SOUND
) and
6073 if gMusic
<> nil then
6080 procedure g_Game_UpdateTriggerSounds();
6084 if gTriggers
<> nil then
6085 for i
:= 0 to High(gTriggers
) do
6086 with gTriggers
[i
] do
6087 if (TriggerType
= TRIGGER_SOUND
) and
6090 Sound
.IsPlaying() then
6092 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6093 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6095 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6096 Sound
.SetVolume(Data
.Volume
/255.0);
6099 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6103 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6106 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6111 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6116 if gSpectMode
<> SPECT_PLAYERS
then
6118 if gSpectPID1
= UID
then
6123 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6130 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6135 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6140 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6145 if gSpectMode
<> SPECT_PLAYERS
then
6147 Pl
:= g_Player_Get(gSpectPID1
);
6148 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6153 if gSpectViewTwo
then
6155 Pl
:= g_Player_Get(gSpectPID2
);
6156 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6164 procedure g_Game_Message(Msg
: string; Time
: Word);
6166 MessageText
:= b_Text_Format(Msg
);
6167 MessageTime
:= Time
;
6170 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6179 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6183 if goodsnd
[a
].IsPlaying() then
6186 goodsnd
[Random(4)].Play();
6189 procedure g_Game_Announce_KillCombo(Param
: Integer);
6196 UID
:= Param
and $FFFF;
6201 Pl
:= g_Player_Get(UID
);
6210 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6214 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6218 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6222 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6230 if not g_Game_IsWatchedPlayer(UID
) then
6233 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6237 if killsnd
[n
].IsPlaying() then
6242 procedure g_Game_StartVote(Command
, Initiator
: string);
6246 if not gVotesEnabled
then Exit
;
6247 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6248 if gVoteInProgress
or gVotePassed
then
6250 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6251 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6254 gVoteInProgress
:= True;
6255 gVotePassed
:= False;
6256 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6259 gVoteCommand
:= Command
;
6261 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6262 Need
:= Floor((NetClientCount
+1)/2.0)+1
6264 Need
:= Floor(NetClientCount
/2.0)+1;
6265 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6266 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6269 procedure g_Game_CheckVote
;
6273 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6274 if not gVoteInProgress
then Exit
;
6276 if (gTime
>= gVoteTimer
) then
6278 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6279 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6281 Need
:= Floor(NetClientCount
/2.0) + 1;
6282 if gVoteCount
>= Need
then
6284 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6285 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6286 gVotePassed
:= True;
6287 gVoteCmdTimer
:= gTime
+ 5000;
6291 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6292 MH_SEND_VoteEvent(NET_VE_FAILED
);
6294 if NetClients
<> nil then
6295 for I
:= Low(NetClients
) to High(NetClients
) do
6296 if NetClients
[i
].Used
then
6297 NetClients
[i
].Voted
:= False;
6298 gVoteInProgress
:= False;
6304 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6305 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6307 Need
:= Floor(NetClientCount
/2.0) + 1;
6308 if gVoteCount
>= Need
then
6310 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6311 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6312 gVoteInProgress
:= False;
6313 gVotePassed
:= True;
6314 gVoteCmdTimer
:= gTime
+ 5000;
6317 if NetClients
<> nil then
6318 for I
:= Low(NetClients
) to High(NetClients
) do
6319 if NetClients
[i
].Used
then
6320 NetClients
[i
].Voted
:= False;
6325 procedure g_Game_LoadMapList(FileName
: string);
6333 if not FileExists(FileName
) then Exit
;
6335 AssignFile(ListFile
, FileName
);
6337 while not EOF(ListFile
) do
6339 ReadLn(ListFile
, s
);
6342 if s
= '' then Continue
;
6344 SetLength(MapList
, Length(MapList
)+1);
6345 MapList
[High(MapList
)] := s
;
6347 CloseFile(ListFile
);
6350 procedure g_Game_SetDebugMode();
6353 // ×èòû (äàæå â ñâîåé èãðå):
6357 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6361 if Length(LoadingStat
.Msgs
) = 0 then
6367 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6368 if NextMsg
= Length(Msgs
) then
6370 for i
:= 0 to High(Msgs
)-1 do
6371 Msgs
[i
] := Msgs
[i
+1];
6379 Msgs
[NextMsg
-1] := Text;
6385 g_ActiveWindow
:= nil;
6390 procedure g_Game_StepLoading();
6396 if (ShowCount
> LOADING_SHOW_STEP
) then
6404 procedure g_Game_ClearLoading();
6413 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6414 if len
< 1 then len
:= 1;
6415 SetLength(Msgs
, len
);
6416 for len
:= Low(Msgs
) to High(Msgs
) do
6422 procedure Parse_Params(var pars
: TParamStrValues
);
6429 while i
<= ParamCount
do
6432 if (s
[1] = '-') and (Length(s
) > 1) then
6434 if (s
[2] = '-') and (Length(s
) > 2) then
6435 begin // Îäèíî÷íûé ïàðàìåòð
6436 SetLength(pars
, Length(pars
) + 1);
6437 with pars
[High(pars
)] do
6439 Name
:= LowerCase(s
);
6444 if (i
< ParamCount
) then
6445 begin // Ïàðàìåòð ñî çíà÷åíèåì
6447 SetLength(pars
, Length(pars
) + 1);
6448 with pars
[High(pars
)] do
6450 Name
:= LowerCase(s
);
6451 Value
:= LowerCase(ParamStr(i
));
6460 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6465 for i
:= 0 to High(pars
) do
6466 if pars
[i
].Name
= aName
then
6468 Result
:= pars
[i
].Value
;
6473 procedure g_Game_Process_Params();
6475 pars
: TParamStrValues
;
6478 LimT
, LimS
: Integer;
6489 s
:= Find_Param_Value(pars
, '--debug');
6492 g_Game_SetDebugMode();
6493 s
:= Find_Param_Value(pars
, '--netdump');
6498 // Connect when game loads
6499 ip
:= Find_Param_Value(pars
, '-connect');
6503 s
:= Find_Param_Value(pars
, '-port');
6504 if (s
= '') or not TryStrToInt(s
, Port
) then
6507 s
:= Find_Param_Value(pars
, '-pw');
6509 g_Game_StartClient(ip
, Port
, s
);
6513 // Start map when game loads:
6514 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6515 if isWadPath(map
) then
6518 s
:= Find_Param_Value(pars
, '-gm');
6519 GMode
:= g_Game_TextToMode(s
);
6520 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6521 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6524 s
:= Find_Param_Value(pars
, '-limt');
6525 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6531 s
:= Find_Param_Value(pars
, '-lims');
6532 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6538 s
:= Find_Param_Value(pars
, '-lives');
6539 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6545 s
:= Find_Param_Value(pars
, '-opt');
6547 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6549 Opt
:= StrToIntDef(s
, 0);
6551 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6554 s
:= Find_Param_Value(pars
, '--close');
6558 // Delete test map after play:
6559 s
:= Find_Param_Value(pars
, '--testdelete');
6562 gMapToDelete
:= MapsDir
+ map
;
6563 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6567 // Delete temporary WAD after play:
6568 s
:= Find_Param_Value(pars
, '--tempdelete');
6571 gMapToDelete
:= MapsDir
+ map
;
6572 gTempDelete
:= True;
6575 // Number of players:
6576 s
:= Find_Param_Value(pars
, '-pl');
6580 n
:= StrToIntDef(s
, 1);
6583 s
:= Find_Param_Value(pars
, '-port');
6584 if (s
= '') or not TryStrToInt(s
, Port
) then
6585 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6587 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6590 // Execute script when game loads:
6591 s
:= Find_Param_Value(pars
, '-exec');
6594 if Pos(':\', s
) = 0 then
6595 s
:= GameDir
+ '/' + s
;
6600 if IOResult
<> 0 then
6602 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6603 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6607 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6608 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6613 if IOResult
<> 0 then
6615 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6616 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6620 if Pos('#', s
) <> 1 then // script comment
6621 g_Console_Process(s
, True);