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
, g_scripts
, 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);
1109 g_Scripts_Load('game.conprint("Scripts Init")');
1111 gMusic
:= TMusic
.Create();
1112 gMusic
.SetByName('MUSIC_MENU');
1115 gGameSettings
.WarmupTime
:= 30;
1117 gState
:= STATE_MENU
;
1119 SetLength(gEvents
, 6);
1120 gEvents
[0].Name
:= 'ongamestart';
1121 gEvents
[1].Name
:= 'ongameend';
1122 gEvents
[2].Name
:= 'onmapstart';
1123 gEvents
[3].Name
:= 'onmapend';
1124 gEvents
[4].Name
:= 'oninter';
1125 gEvents
[5].Name
:= 'onwadend';
1127 sfsGCEnable(); // enable releasing unused volumes
1131 procedure g_Game_Free();
1133 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1134 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1138 g_Player_RemoveAllCorpses();
1140 gGameSettings
.GameType
:= GT_NONE
;
1141 if gGameSettings
.GameMode
= GM_SINGLE
then
1142 gGameSettings
.GameMode
:= GM_DM
;
1143 gSwitchGameMode
:= gGameSettings
.GameMode
;
1146 gExitByTrigger
:= False;
1149 function IsActivePlayer(p
: TPlayer
): Boolean;
1154 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1157 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1164 if gPlayers
= nil then
1166 for a
:= Low(gPlayers
) to High(gPlayers
) do
1167 if IsActivePlayer(gPlayers
[a
]) then
1169 if gPlayers
[a
].UID
<> ID
then
1171 Result
:= gPlayers
[a
];
1176 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1182 if gPlayers
= nil then
1186 for a
:= Low(gPlayers
) to High(gPlayers
) do
1187 if IsActivePlayer(gPlayers
[a
]) then
1189 SetLength(ids
, Length(ids
) + 1);
1190 ids
[High(ids
)] := gPlayers
[a
].UID
;
1191 if gPlayers
[a
].UID
= Skip
then
1194 if Length(ids
) = 0 then
1199 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1202 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1208 if gPlayers
= nil then
1212 for a
:= Low(gPlayers
) to High(gPlayers
) do
1213 if IsActivePlayer(gPlayers
[a
]) then
1215 SetLength(ids
, Length(ids
) + 1);
1216 ids
[High(ids
)] := gPlayers
[a
].UID
;
1217 if gPlayers
[a
].UID
= Skip
then
1220 if Length(ids
) = 0 then
1223 Result
:= ids
[Length(ids
) - 1]
1225 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1228 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1230 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1231 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1235 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1240 if (plr
= nil) then exit
;
1241 if (p2hack
) then time
:= 1000 else time
:= 1;
1242 strafeDir
:= MoveButton
shr 4;
1243 MoveButton
:= MoveButton
and $0F;
1246 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1247 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1248 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1250 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1251 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1252 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1254 // if we have "strafe" key, turn off old strafe mechanics
1255 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1257 // new strafe mechanics
1258 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1259 // now set direction according to strafe
1260 if (strafeDir
= 1) then plr
.SetDirection(D_LEFT
)
1261 else if (strafeDir
= 2) then plr
.SetDirection(D_RIGHT
)
1262 else plr
.SetDirection(TDirection(MoveButton
-1));
1266 strafeDir
:= 0; // not strafing anymore
1267 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1268 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1269 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1270 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1271 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1272 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1275 // fix movebutton state
1276 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1278 // Îñòàëüíûå êëàâèøè:
1279 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1280 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1281 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1282 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1283 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1284 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1285 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1289 procedure g_Game_Update();
1291 Msg
: g_gui
.TMessage
;
1297 // Ïîðà âûêëþ÷àòü èãðó:
1298 if gExit
= EXIT_QUIT
then
1300 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1304 if gExit
= EXIT_QUIT
then
1308 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1311 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1314 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1316 gExit
:= EXIT_SIMPLE
;
1322 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1323 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1324 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1325 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1327 if g_Game_IsNet
and g_Game_IsServer
then
1329 gInterTime
:= gInterTime
+ GAME_TICK
;
1330 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1331 if a
<> gServInterTime
then
1333 gServInterTime
:= a
;
1334 MH_SEND_TimeSync(gServInterTime
);
1338 if (not g_Game_IsClient
) and
1341 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1342 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1343 and (g_ActiveWindow
= nil)
1345 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1348 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1349 g_Game_StopAllSounds(True);
1351 if gMapOnce
then // Ýòî áûë òåñò
1352 gExit
:= EXIT_SIMPLE
1354 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1355 g_Game_ChangeMap(gNextMap
)
1356 else // Ñëåäóþùåé êàðòû íåò
1358 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1360 // Âûõîä â ãëàâíîå ìåíþ:
1362 g_GUI_ShowWindow('MainMenu');
1363 gMusic
.SetByName('MUSIC_MENU');
1365 gState
:= STATE_MENU
;
1368 // Ôèíàëüíàÿ êàðòèíêà:
1369 g_Game_ExecuteEvent('onwadend');
1371 if not gMusic
.SetByName('MUSIC_endmus') then
1372 gMusic
.SetByName('MUSIC_STDENDMUS');
1374 gState
:= STATE_ENDPIC
;
1376 g_Game_ExecuteEvent('ongameend');
1382 if gState
= STATE_INTERTEXT
then
1383 if InterText
.counter
> 0 then
1384 InterText
.counter
:= InterText
.counter
- 1;
1387 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1389 if EndingGameCounter
= 0 then
1391 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1392 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1394 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1396 g_Game_ExecuteEvent('onwadend');
1397 if not gMusic
.SetByName('MUSIC_endmus') then
1398 gMusic
.SetByName('MUSIC_STDENDMUS');
1401 gMusic
.SetByName('MUSIC_ROUNDMUS');
1404 gState
:= STATE_INTERCUSTOM
;
1406 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1408 gMusic
.SetByName('MUSIC_INTERMUS');
1410 gState
:= STATE_INTERSINGLE
;
1412 g_Game_ExecuteEvent('oninter');
1415 DecMin(EndingGameCounter
, 6, 0);
1418 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1420 if gMapOnce
then // Ýòî áûë òåñò
1422 gExit
:= EXIT_SIMPLE
;
1428 g_Serverlist_Control(slCurrent
);
1431 if g_Game_IsNet
then
1432 if not gConsoleShow
then
1433 if not gChatShow
then
1435 if g_ActiveWindow
= nil then
1437 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1438 g_Console_Chat_Switch(False)
1439 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1440 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1441 g_Console_Chat_Switch(True);
1444 if not gChatEnter
then
1445 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1446 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1449 // Ñòàòèñòèêà ïî Tab:
1451 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1452 (gGameSettings
.GameType
<> GT_SINGLE
) and
1453 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1456 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1458 // Âðåìÿ += 28 ìèëëèñåêóíä:
1459 gTime
:= gTime
+ GAME_TICK
;
1461 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1462 if MessageTime
= 0 then
1464 if MessageTime
> 0 then
1465 MessageTime
:= MessageTime
- 1;
1467 if (g_Game_IsServer
) then
1469 // Áûë çàäàí ëèìèò âðåìåíè:
1470 if (gGameSettings
.TimeLimit
> 0) then
1471 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1472 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1477 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1478 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1479 g_Game_RestartRound(gLMSSoftSpawn
);
1481 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1482 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1484 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1486 g_Console_Process(gVoteCommand
);
1488 gVotePassed
:= False;
1491 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1492 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1493 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1494 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1495 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1497 // Áûë çàäàí ëèìèò ïîáåä:
1498 if (gGameSettings
.GoalLimit
> 0) then
1502 if gGameSettings
.GameMode
= GM_DM
then
1503 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1504 for i
:= 0 to High(gPlayers
) do
1505 if gPlayers
[i
] <> nil then
1506 if gPlayers
[i
].Frags
> b
then
1507 b
:= gPlayers
[i
].Frags
;
1510 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1511 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1512 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1515 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1516 if b
>= gGameSettings
.GoalLimit
then
1523 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1524 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1525 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1526 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1528 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1529 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1530 end // if not console
1533 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1538 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1539 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1541 if not gSpectKeyPress
then
1543 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1545 // switch spect mode
1547 SPECT_NONE
: ; // not spectator
1549 SPECT_MAPVIEW
: Inc(gSpectMode
);
1550 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1552 gSpectKeyPress
:= True;
1554 if gSpectMode
= SPECT_MAPVIEW
then
1556 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1557 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1558 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1559 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1560 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1561 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1562 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1563 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1564 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1567 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1568 gSpectKeyPress
:= True;
1570 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1573 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1574 gSpectKeyPress
:= True;
1577 if gSpectMode
= SPECT_PLAYERS
then
1579 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1582 gSpectViewTwo
:= True;
1583 gSpectKeyPress
:= True;
1585 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1587 // remove second view
1588 gSpectViewTwo
:= False;
1589 gSpectKeyPress
:= True;
1591 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1593 // prev player (view 1)
1594 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1595 gSpectKeyPress
:= True;
1597 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1599 // next player (view 1)
1600 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1601 gSpectKeyPress
:= True;
1603 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1605 // prev player (view 2)
1606 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1607 gSpectKeyPress
:= True;
1609 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1611 // next player (view 2)
1612 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1613 gSpectKeyPress
:= True;
1618 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1619 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1620 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1621 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1622 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1623 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1624 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1625 gSpectKeyPress
:= False;
1628 // Îáíîâëÿåì âñå îñòàëüíîå:
1631 g_Triggers_Update();
1633 g_Monsters_Update();
1635 g_Player_UpdateAll();
1636 g_Player_UpdatePhysicalObjects();
1637 if gGameSettings
.GameType
= GT_SERVER
then
1638 if Length(gMonstersSpawned
) > 0 then
1640 for I
:= 0 to High(gMonstersSpawned
) do
1641 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1642 SetLength(gMonstersSpawned
, 0);
1645 if (gSoundTriggerTime
> 8) then
1647 g_Game_UpdateTriggerSounds();
1648 gSoundTriggerTime
:= 0;
1651 Inc(gSoundTriggerTime
);
1653 if (NetMode
= NET_SERVER
) then
1655 Inc(NetTimeToUpdate
);
1656 Inc(NetTimeToReliable
);
1657 if NetTimeToReliable
>= NetRelupdRate
then
1659 for I
:= 0 to High(gPlayers
) do
1660 if gPlayers
[I
] <> nil then
1661 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1663 if gMonsters
<> nil then
1664 for I
:= 0 to High(gMonsters
) do
1665 if gMonsters
[I
] <> nil then
1667 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1669 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1670 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1673 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1674 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1675 (gMonsters
[I
].GameVelX
<> 0) or
1676 (gMonsters
[I
].GameVelY
<> 0) then
1677 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1680 NetTimeToReliable
:= 0;
1681 NetTimeToUpdate
:= NetUpdateRate
;
1683 else if NetTimeToUpdate
>= NetUpdateRate
then
1685 if gPlayers
<> nil then
1686 for I
:= 0 to High(gPlayers
) do
1687 if gPlayers
[I
] <> nil then
1688 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1690 if gMonsters
<> nil then
1691 for I
:= 0 to High(gMonsters
) do
1692 if gMonsters
[I
] <> nil then
1694 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1696 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1697 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1700 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1701 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1702 (gMonsters
[I
].GameVelX
<> 0) or
1703 (gMonsters
[I
].GameVelY
<> 0) then
1704 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1707 NetTimeToUpdate
:= 0;
1710 if NetUseMaster
then
1711 if gTime
>= NetTimeToMaster
then
1713 if (NetMHost
= nil) or (NetMPeer
= nil) then
1714 if not g_Net_Slist_Connect
then
1715 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1718 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1722 if NetMode
= NET_CLIENT
then
1723 MC_SEND_PlayerPos();
1724 end; // if gameOn ...
1726 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1727 if g_ActiveWindow
<> nil then
1729 w
:= e_GetFirstKeyPressed();
1731 if (w
<> IK_INVALID
) then
1733 Msg
.Msg
:= MESSAGE_DIKEY
;
1735 g_ActiveWindow
.OnMessage(Msg
);
1738 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1739 if g_ActiveWindow
<> nil then
1740 g_ActiveWindow
.Update();
1742 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1743 if gResolutionChange
then
1745 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1746 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1747 gResolutionChange
:= False;
1750 // Íóæíî ñìåíèòü ÿçûê:
1751 if gLanguageChange
then
1753 //e_WriteLog('Read language file', MSG_NOTIFY);
1754 //g_Language_Load(DataDir + gLanguage + '.txt');
1755 g_Language_Set(gLanguage
);
1757 gLanguageChange
:= False;
1761 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1762 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1763 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1766 LastScreenShot
:= GetTimer();
1769 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1770 if e_KeyPressed(IK_F10
) and
1772 (not gConsoleShow
) and
1773 (g_ActiveWindow
= nil) then
1778 Time
:= GetTimer() {div 1000};
1780 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1781 if gDelayedEvents
<> nil then
1782 for a
:= 0 to High(gDelayedEvents
) do
1783 if gDelayedEvents
[a
].Pending
and
1785 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1786 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1789 case gDelayedEvents
[a
].DEType
of
1791 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1794 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1798 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1799 if g_Game_IsNet
and g_Game_IsServer
then
1800 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1803 gDelayedEvents
[a
].Pending
:= False;
1806 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1807 UPSCounter
:= UPSCounter
+ 1;
1808 if Time
- UPSTime
>= 1000 then
1816 procedure g_Game_LoadData();
1818 if DataLoaded
then Exit
;
1820 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1822 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1823 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1824 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1825 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1826 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1827 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1828 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1829 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1830 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1831 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1832 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1833 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1834 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1835 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1836 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1837 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1838 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1839 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1840 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1841 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1842 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1843 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1844 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1845 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1846 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1847 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1848 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1849 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1850 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1851 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1852 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1853 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1854 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1855 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1857 goodsnd
[0] := TPlayableSound
.Create();
1858 goodsnd
[1] := TPlayableSound
.Create();
1859 goodsnd
[2] := TPlayableSound
.Create();
1860 goodsnd
[3] := TPlayableSound
.Create();
1862 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1863 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1864 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1865 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1867 killsnd
[0] := TPlayableSound
.Create();
1868 killsnd
[1] := TPlayableSound
.Create();
1869 killsnd
[2] := TPlayableSound
.Create();
1870 killsnd
[3] := TPlayableSound
.Create();
1872 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1873 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1874 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1875 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1877 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1880 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1881 g_Weapon_LoadData();
1883 g_Monsters_LoadData();
1888 procedure g_Game_FreeData();
1890 if not DataLoaded
then Exit
;
1893 g_Weapon_FreeData();
1894 g_Monsters_FreeData();
1896 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1898 g_Texture_Delete('NOTEXTURE');
1899 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1900 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1901 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1902 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1903 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1904 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1905 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1906 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1907 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1908 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1909 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1910 g_Frames_DeleteByName('FRAMES_TELEPORT');
1911 g_Sound_Delete('SOUND_GAME_TELEPORT');
1912 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1913 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1914 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1915 g_Sound_Delete('SOUND_GAME_BULK1');
1916 g_Sound_Delete('SOUND_GAME_BULK2');
1917 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1918 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1919 g_Sound_Delete('SOUND_GAME_SWITCH1');
1920 g_Sound_Delete('SOUND_GAME_SWITCH0');
1927 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1928 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1929 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1930 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1937 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1938 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1939 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1940 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1942 DataLoaded
:= False;
1945 procedure DrawCustomStat();
1951 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1952 s1
, s2
, topstr
: String;
1954 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1957 if e_KeyPressed(IK_TAB
) then
1959 if not gStatsPressed
then
1961 gStatsOff
:= not gStatsOff
;
1962 gStatsPressed
:= True;
1966 gStatsPressed
:= False;
1970 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1971 w
:= (Length(s1
) * ww2
) div 2;
1972 x
:= gScreenWidth
div 2 - w
;
1974 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1978 if (gGameSettings
.GameMode
= GM_COOP
) then
1980 if gMissionFailed
then
1981 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1983 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1986 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1988 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1989 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
1991 if g_Game_IsNet
then
1993 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
1994 if not gChatShow
then
1995 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1996 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
1999 if g_Game_IsClient
then
2000 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2002 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2003 if not gChatShow
then
2004 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2005 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2010 w
:= gScreenWidth
-x
*2;
2016 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2017 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2019 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2021 case CustomStat
.GameMode
of
2024 if gGameSettings
.MaxLives
= 0 then
2025 s1
:= _lc
[I_GAME_DM
]
2027 s1
:= _lc
[I_GAME_LMS
];
2031 if gGameSettings
.MaxLives
= 0 then
2032 s1
:= _lc
[I_GAME_TDM
]
2034 s1
:= _lc
[I_GAME_TLMS
];
2036 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2039 if gGameSettings
.MaxLives
= 0 then
2040 s1
:= _lc
[I_GAME_COOP
]
2042 s1
:= _lc
[I_GAME_SURV
];
2048 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2052 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2053 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2056 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2057 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2058 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2059 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2061 pc
:= Length(CustomStat
.PlayerStat
);
2062 if pc
= 0 then Exit
;
2064 if CustomStat
.GameMode
= GM_COOP
then
2066 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2068 s2
:= _lc
[I_GAME_MONSTERS
];
2069 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2070 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2072 s2
:= _lc
[I_GAME_SECRETS
];
2073 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2074 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2077 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2079 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2080 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2081 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2083 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2084 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2085 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2089 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2094 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2095 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2096 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2098 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2101 for t
:= TEAM_RED
to TEAM_BLUE
do
2103 if t
= TEAM_RED
then
2105 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2106 gStdFont
, 255, 0, 0, 1);
2107 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2108 gStdFont
, 255, 0, 0, 1);
2115 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2116 gStdFont
, 0, 0, 255, 1);
2117 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2118 gStdFont
, 0, 0, 255, 1);
2124 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2127 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2128 if CustomStat
.PlayerStat
[p
].Team
= t
then
2129 with CustomStat
.PlayerStat
[p
] do
2143 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2144 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2145 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2152 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2155 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2156 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2157 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2160 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2161 with CustomStat
.PlayerStat
[p
] do
2163 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2170 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2171 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2172 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2178 procedure DrawSingleStat();
2180 tm
, key_x
, val_x
, y
: Integer;
2184 procedure player_stat(n
: Integer);
2190 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2191 s2
:= Format(' %d', [gTotalMonsters
]);
2193 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2194 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2195 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2196 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2198 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2199 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2201 // "Kills-per-minute: ##.#":
2202 s1
:= _lc
[I_MENU_INTER_KPM
];
2204 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2206 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2207 s2
:= Format(' %.1f', [kpm
]);
2209 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2210 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2212 // "Secrets found: # / #":
2213 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2214 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2216 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2217 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2218 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2219 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2221 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2222 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2226 // "Level Complete":
2227 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2228 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2230 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2231 s1
:= _lc
[I_MENU_INTER_KPM
];
2232 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2235 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2237 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2238 val_x
:= key_x
+ w1
;
2241 tm
:= SingleStat
.GameTime
div 1000;
2242 s1
:= _lc
[I_MENU_INTER_TIME
];
2243 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2245 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2246 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2248 if SingleStat
.TwoPlayers
then
2251 s1
:= _lc
[I_MENU_PLAYER_1
];
2252 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2253 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2255 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2260 s1
:= _lc
[I_MENU_PLAYER_2
];
2261 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2262 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2264 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2270 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2276 procedure DrawLoadingStat();
2282 if Length(LoadingStat
.Msgs
) = 0 then
2285 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2286 yy
:= (gScreenHeight
div 3);
2287 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2288 xx
:= (gScreenWidth
div 3);
2291 for i
:= 0 to NextMsg
-1 do
2293 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2294 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2298 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2299 yy
:= yy
+ LOADING_INTERLINE
;
2303 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2305 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2307 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2308 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2311 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2312 ScaleSz
:= 16 div Scale
;
2313 // Ðàçìåðû ìèíè-êàðòû:
2314 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2315 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2317 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2319 if gWalls
<> nil then
2322 for a
:= 0 to High(gWalls
) do
2324 if PanelType
<> 0 then
2326 // Ëåâûé âåðõíèé óãîë:
2327 aX
:= X
div ScaleSz
;
2328 aY
:= Y
div ScaleSz
;
2330 aX2
:= max(Width
div ScaleSz
, 1);
2331 aY2
:= max(Height
div ScaleSz
, 1);
2332 // Ïðàâûé íèæíèé óãîë:
2333 aX2
:= aX
+ aX2
- 1;
2334 aY2
:= aY
+ aY2
- 1;
2337 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2338 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2339 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2343 if gSteps
<> nil then
2346 for a
:= 0 to High(gSteps
) do
2348 if PanelType
<> 0 then
2350 // Ëåâûé âåðõíèé óãîë:
2351 aX
:= X
div ScaleSz
;
2352 aY
:= Y
div ScaleSz
;
2354 aX2
:= max(Width
div ScaleSz
, 1);
2355 aY2
:= max(Height
div ScaleSz
, 1);
2356 // Ïðàâûé íèæíèé óãîë:
2357 aX2
:= aX
+ aX2
- 1;
2358 aY2
:= aY
+ aY2
- 1;
2360 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2363 if gLifts
<> nil then
2366 for a
:= 0 to High(gLifts
) do
2368 if PanelType
<> 0 then
2370 // Ëåâûé âåðõíèé óãîë:
2371 aX
:= X
div ScaleSz
;
2372 aY
:= Y
div ScaleSz
;
2374 aX2
:= max(Width
div ScaleSz
, 1);
2375 aY2
:= max(Height
div ScaleSz
, 1);
2376 // Ïðàâûé íèæíèé óãîë:
2377 aX2
:= aX
+ aX2
- 1;
2378 aY2
:= aY
+ aY2
- 1;
2381 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2382 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2383 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2384 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2388 if gWater
<> nil then
2391 for a
:= 0 to High(gWater
) do
2393 if PanelType
<> 0 then
2395 // Ëåâûé âåðõíèé óãîë:
2396 aX
:= X
div ScaleSz
;
2397 aY
:= Y
div ScaleSz
;
2399 aX2
:= max(Width
div ScaleSz
, 1);
2400 aY2
:= max(Height
div ScaleSz
, 1);
2401 // Ïðàâûé íèæíèé óãîë:
2402 aX2
:= aX
+ aX2
- 1;
2403 aY2
:= aY
+ aY2
- 1;
2405 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2408 if gAcid1
<> nil then
2410 // Ðèñóåì êèñëîòó 1:
2411 for a
:= 0 to High(gAcid1
) do
2413 if PanelType
<> 0 then
2415 // Ëåâûé âåðõíèé óãîë:
2416 aX
:= X
div ScaleSz
;
2417 aY
:= Y
div ScaleSz
;
2419 aX2
:= max(Width
div ScaleSz
, 1);
2420 aY2
:= max(Height
div ScaleSz
, 1);
2421 // Ïðàâûé íèæíèé óãîë:
2422 aX2
:= aX
+ aX2
- 1;
2423 aY2
:= aY
+ aY2
- 1;
2425 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2428 if gAcid2
<> nil then
2430 // Ðèñóåì êèñëîòó 2:
2431 for a
:= 0 to High(gAcid2
) do
2433 if PanelType
<> 0 then
2435 // Ëåâûé âåðõíèé óãîë:
2436 aX
:= X
div ScaleSz
;
2437 aY
:= Y
div ScaleSz
;
2439 aX2
:= max(Width
div ScaleSz
, 1);
2440 aY2
:= max(Height
div ScaleSz
, 1);
2441 // Ïðàâûé íèæíèé óãîë:
2442 aX2
:= aX
+ aX2
- 1;
2443 aY2
:= aY
+ aY2
- 1;
2445 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2448 if gPlayers
<> nil then
2451 for a
:= 0 to High(gPlayers
) do
2452 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2454 // Ëåâûé âåðõíèé óãîë:
2455 aX
:= Obj
.X
div ScaleSz
+ 1;
2456 aY
:= Obj
.Y
div ScaleSz
+ 1;
2458 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2459 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2460 // Ïðàâûé íèæíèé óãîë:
2461 aX2
:= aX
+ aX2
- 1;
2462 aY2
:= aY
+ aY2
- 1;
2464 if gPlayers
[a
] = p
then
2465 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2468 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2469 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2470 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2474 if gMonsters
<> nil then
2477 for a
:= 0 to High(gMonsters
) do
2478 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2480 // Ëåâûé âåðõíèé óãîë:
2481 aX
:= Obj
.X
div ScaleSz
+ 1;
2482 aY
:= Obj
.Y
div ScaleSz
+ 1;
2484 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2485 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2486 // Ïðàâûé íèæíèé óãîë:
2487 aX2
:= aX
+ aX2
- 1;
2488 aY2
:= aY
+ aY2
- 1;
2490 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2496 procedure DrawMapView(x
, y
, w
, h
: Integer);
2502 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2503 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2504 g_Map_DrawBack(-bx
, -by
);
2511 glTranslatef(-x
, -y
, 0);
2513 g_Map_DrawPanels(PANEL_BACK
);
2514 g_Map_DrawPanels(PANEL_STEP
);
2517 g_Player_DrawShells();
2519 g_Player_DrawCorpses();
2520 g_Map_DrawPanels(PANEL_WALL
);
2522 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2525 g_Map_DrawPanels(PANEL_ACID1
);
2526 g_Map_DrawPanels(PANEL_ACID2
);
2527 g_Map_DrawPanels(PANEL_WATER
);
2528 g_Map_DrawPanels(PANEL_FORE
);
2529 if g_debug_HealthBar
then
2531 g_Monsters_DrawHealth();
2532 g_Player_DrawHealth();
2538 procedure DrawPlayer(p
: TPlayer
);
2540 px
, py
, a
, b
, c
, d
: Integer;
2543 if (p
= nil) or (p
.FDummy
) then
2546 g_Map_DrawBack(0, 0);
2555 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2556 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2558 if px
> (gPlayerScreenSize
.X
div 2) then
2559 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2562 if py
> (gPlayerScreenSize
.Y
div 2) then
2563 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2566 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2567 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2568 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2569 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2570 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2572 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2575 if p
.IncCam
<> 0 then
2577 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2579 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2580 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2583 if py
< (gPlayerScreenSize
.Y
div 2) then
2585 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2586 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2589 if p
.IncCam
< 0 then
2590 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2592 p
.IncCam
:= p
.IncCam
+ 1;
2594 if p
.IncCam
> 0 then
2595 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2597 p
.IncCam
:= p
.IncCam
- 1;
2600 if (px
< gPlayerScreenSize
.X
div 2) or
2601 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2604 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2605 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2607 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2609 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2610 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2613 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2614 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2616 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2618 g_Map_DrawBack(-c
, -d
);
2621 sY
:= -(b
+p
.IncCam
);
2622 sWidth
:= gPlayerScreenSize
.X
;
2623 sHeight
:= gPlayerScreenSize
.Y
;
2625 glTranslatef(a
, b
+p
.IncCam
, 0);
2627 g_Map_DrawPanels(PANEL_BACK
);
2628 g_Map_DrawPanels(PANEL_STEP
);
2631 g_Player_DrawShells();
2633 g_Player_DrawCorpses();
2634 g_Map_DrawPanels(PANEL_WALL
);
2636 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2639 g_Map_DrawPanels(PANEL_ACID1
);
2640 g_Map_DrawPanels(PANEL_ACID2
);
2641 g_Map_DrawPanels(PANEL_WATER
);
2642 g_Map_DrawPanels(PANEL_FORE
);
2643 if g_debug_HealthBar
then
2645 g_Monsters_DrawHealth();
2646 g_Player_DrawHealth();
2649 if p
.FSpectator
then
2650 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2651 p
.GameY
+ PLAYER_RECT_CY
- 4,
2652 'X', gStdFont
, 255, 255, 255, 1, True);
2654 for a := 0 to High(gCollideMap) do
2655 for b := 0 to High(gCollideMap[a]) do
2658 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2660 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2664 1: e_DrawPoint(1, b, a, 200, 200, 200);
2665 2: e_DrawPoint(1, b, a, 64, 64, 255);
2666 3: e_DrawPoint(1, b, a, 255, 0, 255);
2676 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2677 if g_Debug_Player
then
2678 g_Player_DrawDebug(p
);
2682 procedure g_Game_Draw();
2689 plView1
, plView2
: TPlayer
;
2692 if gExit
= EXIT_QUIT
then Exit
;
2694 Time
:= GetTimer() {div 1000};
2695 FPSCounter
:= FPSCounter
+1;
2696 if Time
- FPSTime
>= 1000 then
2703 if gGameOn
or (gState
= STATE_FOLD
) then
2705 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2707 gSpectMode
:= SPECT_NONE
;
2708 if not gRevertPlayers
then
2710 plView1
:= gPlayer1
;
2711 plView2
:= gPlayer2
;
2715 plView1
:= gPlayer2
;
2716 plView2
:= gPlayer1
;
2720 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2722 gSpectMode
:= SPECT_NONE
;
2723 if gPlayer2
= nil then
2726 plView1
:= gPlayer2
;
2735 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2736 gSpectMode
:= SPECT_STATS
;
2738 if gSpectMode
= SPECT_PLAYERS
then
2739 if gPlayers
<> nil then
2741 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2742 if plView1
= nil then
2744 gSpectPID1
:= GetActivePlayerID_Next();
2745 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2747 if gSpectViewTwo
then
2749 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2750 if plView2
= nil then
2752 gSpectPID2
:= GetActivePlayerID_Next();
2753 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2758 if gSpectMode
= SPECT_MAPVIEW
then
2760 // Ðåæèì ïðîñìîòðà êàðòû
2762 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2763 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2764 gHearPoint1
.Active
:= True;
2765 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2766 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2767 gHearPoint2
.Active
:= False;
2771 Split
:= (plView1
<> nil) and (plView2
<> nil);
2773 // Òî÷êè ñëóõà èãðîêîâ
2774 if plView1
<> nil then
2776 gHearPoint1
.Active
:= True;
2777 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2778 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2780 gHearPoint1
.Active
:= False;
2781 if plView2
<> nil then
2783 gHearPoint2
.Active
:= True;
2784 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2785 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2787 gHearPoint2
.Active
:= False;
2789 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2790 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2793 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2794 if gScreenHeight
mod 2 = 0 then
2795 Dec(gPlayerScreenSize
.Y
);
2798 gPlayerScreenSize
.Y
:= gScreenHeight
;
2801 if gScreenHeight
mod 2 = 0 then
2802 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2804 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2806 DrawPlayer(plView1
);
2807 gPlayer1ScreenCoord
.X
:= sX
;
2808 gPlayer1ScreenCoord
.Y
:= sY
;
2812 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2814 DrawPlayer(plView2
);
2815 gPlayer2ScreenCoord
.X
:= sX
;
2816 gPlayer2ScreenCoord
.Y
:= sY
;
2819 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2822 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2825 if MessageText
<> '' then
2829 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2831 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2832 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2834 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2835 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2838 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2840 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2842 // Draw spectator GUI
2845 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2848 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2850 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2852 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2854 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2855 if gSpectMode
= SPECT_MAPVIEW
then
2857 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2858 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2859 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2860 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2861 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2863 if gSpectMode
= SPECT_PLAYERS
then
2865 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2866 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2867 if gSpectViewTwo
then
2869 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2870 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2871 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2872 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2876 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2877 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2883 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2885 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2887 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2888 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2889 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2894 if (gState
= STATE_MENU
) then
2896 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2898 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2899 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2900 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2902 if g_ActiveWindow
<> nil then
2903 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2906 if gState
= STATE_FOLD
then
2907 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2909 if gState
= STATE_INTERCUSTOM
then
2911 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2913 back
:= 'TEXTURE_endpic';
2914 if not g_Texture_Get(back
, ID
) then
2915 back
:= _lc
[I_TEXTURE_ENDPIC
];
2920 if g_Texture_Get(back
, ID
) then
2921 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2923 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2927 if g_ActiveWindow
<> nil then
2928 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2931 if gState
= STATE_INTERSINGLE
then
2933 if EndingGameCounter
> 0 then
2934 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2939 if g_Texture_Get(back
, ID
) then
2940 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2942 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2946 if g_ActiveWindow
<> nil then
2947 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2951 if gState
= STATE_ENDPIC
then
2954 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2955 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2957 if ID
<> DWORD(-1) then
2958 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2960 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2962 if g_ActiveWindow
<> nil then
2963 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2966 if gState
= STATE_SLIST
then
2968 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2970 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2971 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2973 g_Serverlist_Draw(slCurrent
);
2977 if g_ActiveWindow
<> nil then
2980 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2981 g_ActiveWindow
.Draw();
2986 if g_debug_Sounds
and gGameOn
then
2988 for w
:= 0 to High(e_SoundsArray
) do
2989 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2990 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
2995 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
2996 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
2999 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3000 e_TextureFontPrint(gScreenWidth
-72, 0,
3001 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3005 procedure g_Game_Quit();
3007 g_Game_StopAllSounds(True);
3009 g_Game_SaveOptions();
3011 g_PlayerModel_FreeData();
3012 g_Texture_DeleteAll();
3013 g_Frames_DeleteAll();
3016 if NetInitDone
then g_Net_Free
;
3018 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3019 if gMapToDelete
<> '' then
3020 g_Game_DeleteTestMap();
3026 procedure g_FatalError(Text: String);
3028 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3029 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3031 gExit
:= EXIT_SIMPLE
;
3034 procedure g_SimpleError(Text: String);
3036 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3037 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3040 procedure g_Game_SetupScreenSize();
3044 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3045 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3046 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3047 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3049 gPlayerScreenSize
.Y
:= gScreenHeight
;
3051 // Ðàçìåð çàäíåãî ïëàíà:
3052 if BackID
<> DWORD(-1) then
3056 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3057 (gScreenHeight
*d
> gMapInfo
.Height
) then
3060 gBackSize
.X
:= Round(gScreenWidth
*d
);
3061 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3065 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3067 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3070 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3072 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3073 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3075 if gPlayer1
= nil then
3077 if g_Game_IsClient
then
3079 if NetPlrUID1
> -1 then
3081 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3082 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3087 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3088 Team
:= gPlayer1Settings
.Team
;
3090 // Ñîçäàíèå ïåðâîãî èãðîêà:
3091 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3092 gPlayer1Settings
.Color
,
3094 if gPlayer1
= nil then
3095 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3098 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3099 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3100 if g_Game_IsServer
and g_Game_IsNet
then
3101 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3102 gPlayer1
.Respawn(False, True);
3104 if g_Game_IsNet
and NetUseMaster
then
3110 if gPlayer2
= nil then
3112 if g_Game_IsClient
then
3114 if NetPlrUID2
> -1 then
3115 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3119 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3120 Team
:= gPlayer2Settings
.Team
;
3122 // Ñîçäàíèå âòîðîãî èãðîêà:
3123 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3124 gPlayer2Settings
.Color
,
3126 if gPlayer2
= nil then
3127 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3130 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3131 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3132 if g_Game_IsServer
and g_Game_IsNet
then
3133 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3134 gPlayer2
.Respawn(False, True);
3136 if g_Game_IsNet
and NetUseMaster
then
3144 procedure g_Game_RemovePlayer();
3148 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3149 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3154 if g_Game_IsServer
then
3157 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3158 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3159 g_Player_Remove(Pl
.UID
);
3161 if g_Game_IsNet
and NetUseMaster
then
3170 if g_Game_IsServer
then
3173 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3174 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3175 g_Player_Remove(Pl
.UID
);
3177 if g_Game_IsNet
and NetUseMaster
then
3182 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3188 procedure g_Game_Spectate();
3190 g_Game_RemovePlayer();
3191 if gPlayer1
<> nil then
3192 g_Game_RemovePlayer();
3195 procedure g_Game_SpectateCenterView();
3197 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3198 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3201 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3207 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3209 g_Game_ClearLoading();
3212 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3215 gGameSettings
.GameType
:= GT_SINGLE
;
3216 gGameSettings
.MaxLives
:= 0;
3217 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3218 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3219 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3220 gSwitchGameMode
:= GM_SINGLE
;
3222 g_Game_ExecuteEvent('ongamestart');
3224 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3225 g_Game_SetupScreenSize();
3227 // Ñîçäàíèå ïåðâîãî èãðîêà:
3228 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3229 gPlayer1Settings
.Color
,
3230 gPlayer1Settings
.Team
, False));
3231 if gPlayer1
= nil then
3233 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3237 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3240 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3243 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3244 gPlayer2Settings
.Color
,
3245 gPlayer2Settings
.Team
, False));
3246 if gPlayer2
= nil then
3248 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3252 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3256 // Çàãðóçêà è çàïóñê êàðòû:
3257 if not g_Game_StartMap(MAP
, True) then
3259 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3263 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3267 for i
:= nPl
+1 to nPlayers
do
3268 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3271 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3272 TimeLimit
, GoalLimit
: Word;
3274 Options
: LongWord; nPlayers
: Byte);
3280 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3282 g_Game_ClearLoading();
3285 gGameSettings
.GameType
:= GT_CUSTOM
;
3286 gGameSettings
.GameMode
:= GameMode
;
3287 gSwitchGameMode
:= GameMode
;
3288 gGameSettings
.TimeLimit
:= TimeLimit
;
3289 gGameSettings
.GoalLimit
:= GoalLimit
;
3290 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3291 gGameSettings
.Options
:= Options
;
3293 gCoopTotalMonstersKilled
:= 0;
3294 gCoopTotalSecretsFound
:= 0;
3295 gCoopTotalMonsters
:= 0;
3296 gCoopTotalSecrets
:= 0;
3300 g_Game_ExecuteEvent('ongamestart');
3302 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3303 g_Game_SetupScreenSize();
3305 // Ðåæèì íàáëþäàòåëÿ:
3306 if nPlayers
= 0 then
3313 if nPlayers
>= 1 then
3315 // Ñîçäàíèå ïåðâîãî èãðîêà:
3316 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3317 gPlayer1Settings
.Color
,
3318 gPlayer1Settings
.Team
, False));
3319 if gPlayer1
= nil then
3321 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3325 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3329 if nPlayers
>= 2 then
3331 // Ñîçäàíèå âòîðîãî èãðîêà:
3332 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3333 gPlayer2Settings
.Color
,
3334 gPlayer2Settings
.Team
, False));
3335 if gPlayer2
= nil then
3337 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3341 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3345 // Çàãðóçêà è çàïóñê êàðòû:
3346 if not g_Game_StartMap(Map
, True) then
3348 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3352 // Íåò òî÷åê ïîÿâëåíèÿ:
3353 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3354 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3355 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3356 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3357 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3359 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3363 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3367 for i
:= nPl
+1 to nPlayers
do
3368 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3371 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3372 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3373 Options
: LongWord; nPlayers
: Byte;
3374 IPAddr
: LongWord; Port
: Word);
3378 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3380 g_Game_ClearLoading();
3383 gGameSettings
.GameType
:= GT_SERVER
;
3384 gGameSettings
.GameMode
:= GameMode
;
3385 gSwitchGameMode
:= GameMode
;
3386 gGameSettings
.TimeLimit
:= TimeLimit
;
3387 gGameSettings
.GoalLimit
:= GoalLimit
;
3388 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3389 gGameSettings
.Options
:= Options
;
3391 gCoopTotalMonstersKilled
:= 0;
3392 gCoopTotalSecretsFound
:= 0;
3393 gCoopTotalMonsters
:= 0;
3394 gCoopTotalSecrets
:= 0;
3398 g_Game_ExecuteEvent('ongamestart');
3400 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3401 g_Game_SetupScreenSize();
3403 // Ðåæèì íàáëþäàòåëÿ:
3404 if nPlayers
= 0 then
3410 if nPlayers
>= 1 then
3412 // Ñîçäàíèå ïåðâîãî èãðîêà:
3413 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3414 gPlayer1Settings
.Color
,
3415 gPlayer1Settings
.Team
, False));
3416 if gPlayer1
= nil then
3418 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3422 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3425 if nPlayers
>= 2 then
3427 // Ñîçäàíèå âòîðîãî èãðîêà:
3428 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3429 gPlayer2Settings
.Color
,
3430 gPlayer2Settings
.Team
, False));
3431 if gPlayer2
= nil then
3433 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3437 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3441 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3443 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3447 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3449 // Çàãðóçêà è çàïóñê êàðòû:
3450 if not g_Game_StartMap(Map
, True) then
3452 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3456 // Íåò òî÷åê ïîÿâëåíèÿ:
3457 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3458 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3459 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3460 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3461 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3463 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3467 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3470 NetState
:= NET_STATE_GAME
;
3473 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3487 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3488 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3490 g_Game_ClearLoading();
3493 gGameSettings
.GameType
:= GT_CLIENT
;
3495 gCoopTotalMonstersKilled
:= 0;
3496 gCoopTotalSecretsFound
:= 0;
3497 gCoopTotalMonsters
:= 0;
3498 gCoopTotalSecrets
:= 0;
3502 g_Game_ExecuteEvent('ongamestart');
3504 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3505 g_Game_SetupScreenSize();
3507 NetState
:= NET_STATE_AUTH
;
3509 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3511 if not g_Net_Connect(Addr
, Port
) then
3513 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3514 NetState
:= NET_STATE_NONE
;
3518 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3520 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3525 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3527 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3529 Ptr
:= NetEvent
.packet
^.data
;
3532 MID
:= e_Raw_Read_Byte(Ptr
);
3534 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3536 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3537 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3539 WadName
:= e_Raw_Read_String(Ptr
);
3540 Map
:= e_Raw_Read_String(Ptr
);
3542 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3544 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3545 gSwitchGameMode
:= gGameSettings
.GameMode
;
3546 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3547 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3548 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3549 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3550 T
:= e_Raw_Read_LongWord(Ptr
);
3552 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3553 if newResPath
= '' then
3555 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3556 newResPath
:= g_Res_DownloadWAD(WadName
);
3557 if newResPath
= '' then
3559 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3560 enet_packet_destroy(NetEvent
.packet
);
3561 NetState
:= NET_STATE_NONE
;
3565 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3567 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3568 gPlayer1Settings
.Color
,
3569 gPlayer1Settings
.Team
, False));
3571 if gPlayer1
= nil then
3573 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3575 enet_packet_destroy(NetEvent
.packet
);
3576 NetState
:= NET_STATE_NONE
;
3580 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3581 gPlayer1
.UID
:= NetPlrUID1
;
3582 gPlayer1
.Reset(True);
3584 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3586 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3588 enet_packet_destroy(NetEvent
.packet
);
3589 NetState
:= NET_STATE_NONE
;
3597 enet_packet_destroy(NetEvent
.packet
);
3601 enet_packet_destroy(NetEvent
.packet
);
3604 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3607 if (NetEvent
.data
<= NET_DISC_MAX
) then
3608 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3609 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3619 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3628 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3629 NetState
:= NET_STATE_NONE
;
3633 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3634 gLMSRespawnTime
:= 0;
3637 NetState
:= NET_STATE_GAME
;
3638 MC_SEND_FullStateRequest
;
3639 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3642 procedure g_Game_SaveOptions();
3644 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3647 procedure g_Game_ChangeMap(MapPath
: String);
3651 g_Game_ClearLoading();
3653 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3654 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3655 if gExitByTrigger
then
3658 gExitByTrigger
:= False;
3660 if not g_Game_StartMap(MapPath
, Force
) then
3661 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3664 procedure g_Game_Restart();
3668 if g_Game_IsClient
then
3670 map
:= g_ExtractFileName(gMapInfo
.Map
);
3674 g_Game_ClearLoading();
3675 g_Game_StartMap(Map
, True);
3678 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3680 NewWAD
, ResName
: String;
3684 g_Player_RemoveAllCorpses();
3686 if (not g_Game_IsClient
) and
3687 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3688 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3690 if gSwitchGameMode
= GM_CTF
then
3691 gGameSettings
.MaxLives
:= 0;
3692 gGameSettings
.GameMode
:= gSwitchGameMode
;
3695 gSwitchGameMode
:= gGameSettings
.GameMode
;
3697 g_Player_ResetTeams();
3699 if Pos(':\', Map
) > 0 then
3701 NewWAD
:= g_ExtractWadName(Map
);
3702 ResName
:= g_ExtractFileName(Map
);
3703 if g_Game_IsServer
then
3705 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3706 g_Game_LoadWAD(NewWAD
);
3708 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3709 g_Game_ClientWAD(NewWAD
, gWADHash
);
3713 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3716 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3718 gState
:= STATE_NONE
;
3719 g_ActiveWindow
:= nil;
3725 if gGameSettings
.GameMode
= GM_CTF
then
3727 g_Map_ResetFlag(FLAG_RED
);
3728 g_Map_ResetFlag(FLAG_BLUE
);
3729 // CTF, à ôëàãîâ íåò:
3730 if not g_Map_HaveFlagPoints() then
3731 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3736 gState
:= STATE_MENU
;
3743 NetTimeToUpdate
:= 1;
3744 NetTimeToReliable
:= 0;
3745 NetTimeToMaster
:= NetMasterRate
;
3746 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3747 gLMSRespawnTime
:= 0;
3748 gMissionFailed
:= False;
3751 gCoopMonstersKilled
:= 0;
3752 gCoopSecretsFound
:= 0;
3754 gVoteInProgress
:= False;
3755 gVotePassed
:= False;
3761 if not gGameOn
then Exit
;
3763 g_Game_SpectateCenterView();
3765 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3767 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3768 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3769 gLMSSoftSpawn
:= True;
3770 if NetMode
= NET_SERVER
then
3771 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3773 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3776 if NetMode
= NET_SERVER
then
3778 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3781 if NetUseMaster
then
3783 if (NetMHost
= nil) or (NetMPeer
= nil) then
3784 if not g_Net_Slist_Connect
then
3785 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3790 if NetClients
<> nil then
3791 for I
:= 0 to High(NetClients
) do
3792 if NetClients
[I
].Used
then
3794 NetClients
[I
].Voted
:= False;
3795 if NetClients
[I
].RequestedFullUpdate
then
3797 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3798 NetClients
[I
].RequestedFullUpdate
:= False;
3802 g_Net_UnbanNonPermHosts();
3807 gCoopTotalMonstersKilled
:= 0;
3808 gCoopTotalSecretsFound
:= 0;
3809 gCoopTotalMonsters
:= 0;
3810 gCoopTotalSecrets
:= 0;
3814 g_Game_ExecuteEvent('onmapstart');
3817 procedure SetFirstLevel();
3821 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3822 if MapList
= nil then
3825 SortSArray(MapList
);
3826 gNextMap
:= MapList
[Low(MapList
)];
3831 procedure g_Game_ExitLevel(Map
: Char16
);
3835 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3836 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3837 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3838 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3840 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3841 if gGameSettings
.GameType
= GT_SINGLE
then
3842 gExit
:= EXIT_ENDLEVELSINGLE
3843 else // Âûøëè â âûõîä â Ñâîåé èãðå
3845 gExit
:= EXIT_ENDLEVELCUSTOM
;
3846 if gGameSettings
.GameMode
= GM_COOP
then
3847 g_Player_RememberAll
;
3849 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3852 if gGameSettings
.GameMode
= GM_COOP
then
3855 gStatsPressed
:= True;
3856 gNextMap
:= 'MAP01';
3858 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3861 if g_Game_IsNet
then
3863 MH_SEND_GameStats();
3864 MH_SEND_CoopStats();
3870 procedure g_Game_RestartLevel();
3874 if gGameSettings
.GameMode
= GM_SINGLE
then
3879 gExit
:= EXIT_ENDLEVELCUSTOM
;
3880 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3884 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3888 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3890 if not g_Game_IsClient
then
3892 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3895 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3896 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3900 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3904 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3905 g_Game_LoadWAD(NewWAD
);
3908 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3910 i
, n
, nb
, nr
: Integer;
3912 if not g_Game_IsServer
then Exit
;
3913 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3914 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3915 gLMSRespawnTime
:= 0;
3918 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3920 gMissionFailed
:= True;
3921 g_Game_RestartLevel
;
3925 n
:= 0; nb
:= 0; nr
:= 0;
3926 for i
:= Low(gPlayers
) to High(gPlayers
) do
3927 if (gPlayers
[i
] <> nil) and
3928 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3929 (gPlayers
[i
] is TBot
)) then
3932 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3933 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3936 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3938 // wait a second until the fuckers finally decide to join
3939 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3940 gLMSRespawnTime
:= gTime
+ 1000;
3941 gLMSSoftSpawn
:= NoMapRestart
;
3945 g_Player_RemoveAllCorpses
;
3946 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3947 if g_Game_IsNet
then
3948 MH_SEND_GameEvent(NET_EV_LMS_START
);
3950 for i
:= Low(gPlayers
) to High(gPlayers
) do
3952 if gPlayers
[i
] = nil then continue
;
3953 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3954 // don't touch normal spectators
3955 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3957 gPlayers
[i
].FNoRespawn
:= True;
3958 gPlayers
[i
].Lives
:= 0;
3959 if g_Game_IsNet
then
3960 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3963 gPlayers
[i
].FNoRespawn
:= False;
3964 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3965 gPlayers
[i
].Respawn(False, True);
3966 if gGameSettings
.GameMode
= GM_COOP
then
3968 gPlayers
[i
].Frags
:= 0;
3969 gPlayers
[i
].RecallState
;
3971 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3972 gPlayer1
:= g_Player_Get(gLMSPID1
);
3973 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3974 gPlayer2
:= g_Player_Get(gLMSPID2
);
3977 for i
:= Low(gItems
) to High(gItems
) do
3979 if gItems
[i
].Respawnable
then
3981 gItems
[i
].QuietRespawn
:= True;
3982 gItems
[i
].RespawnTime
:= 0;
3987 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3991 for i
:= Low(gMonsters
) to High(gMonsters
) do
3993 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
3994 gMonsters
[i
].Respawn
;
3997 gLMSSoftSpawn
:= False;
4000 function g_Game_GetFirstMap(WAD
: String): String;
4004 MapList
:= g_Map_GetMapsList(WAD
);
4005 if MapList
= nil then
4008 SortSArray(MapList
);
4009 Result
:= MapList
[Low(MapList
)];
4011 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4017 function g_Game_GetNextMap(): String;
4024 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4025 if MapList
= nil then
4028 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4030 SortSArray(MapList
);
4032 for I
:= Low(MapList
) to High(MapList
) do
4033 if Map
= MapList
[I
] then
4039 if MapIndex
<> -255 then
4041 if MapIndex
= High(MapList
) then
4042 Result
:= MapList
[Low(MapList
)]
4044 Result
:= MapList
[MapIndex
+ 1];
4046 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4052 procedure g_Game_NextLevel();
4054 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4055 gExit
:= EXIT_ENDLEVELCUSTOM
4058 gExit
:= EXIT_ENDLEVELSINGLE
;
4062 if gNextMap
<> '' then Exit
;
4063 gNextMap
:= g_Game_GetNextMap();
4066 function g_Game_IsTestMap(): Boolean;
4068 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4071 procedure g_Game_DeleteTestMap();
4082 a
:= Pos('.wad:\', gMapToDelete
);
4086 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4087 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4088 Delete(gMapToDelete
, 1, a
+ 5);
4089 gMapToDelete
:= UpperCase(gMapToDelete
);
4091 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4094 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4095 if MapName <> TEST_MAP_NAME then
4098 if not gTempDelete then
4100 time := g_GetFileTime(WadName);
4101 WAD := TWADFile.Create();
4104 if not WAD.ReadFile(WadName) then
4105 begin // Íåò òàêîãî WAD-ôàéëà
4110 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4112 MapList := WAD.GetResourcesList('');
4114 if MapList <> nil then
4115 for a := 0 to High(MapList) do
4116 if MapList[a] = MapName then
4118 // Óäàëÿåì è ñîõðàíÿåì:
4119 WAD.RemoveResource('', MapName);
4120 WAD.SaveTo(WadName);
4125 g_SetFileTime(WadName, time);
4128 if gTempDelete
then DeleteFile(WadName
);
4131 procedure GameCVars(P
: SArray
);
4134 stat
: TPlayerStatArray
;
4139 cmd
:= LowerCase(P
[0]);
4140 if cmd
= 'r_showfps' then
4142 if (Length(P
) > 1) and
4143 ((P
[1] = '1') or (P
[1] = '0')) then
4144 gShowFPS
:= (P
[1][1] = '1');
4147 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4149 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4151 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4153 with gGameSettings
do
4155 if (Length(P
) > 1) and
4156 ((P
[1] = '1') or (P
[1] = '0')) then
4158 if (P
[1][1] = '1') then
4159 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4161 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4164 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4165 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4167 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4169 if g_Game_IsNet
then MH_SEND_GameSettings
;
4172 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4174 with gGameSettings
do
4176 if (Length(P
) > 1) and
4177 ((P
[1] = '1') or (P
[1] = '0')) then
4179 if (P
[1][1] = '1') then
4180 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4182 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4185 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4186 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4188 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4190 if g_Game_IsNet
then MH_SEND_GameSettings
;
4193 else if cmd
= 'g_gamemode' then
4195 a
:= g_Game_TextToMode(P
[1]);
4196 if a
= GM_SINGLE
then a
:= GM_COOP
;
4197 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4199 gSwitchGameMode
:= a
;
4200 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4201 (gState
= STATE_INTERSINGLE
) then
4202 gSwitchGameMode
:= GM_SINGLE
;
4204 gGameSettings
.GameMode
:= gSwitchGameMode
;
4206 if gSwitchGameMode
= gGameSettings
.GameMode
then
4207 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4208 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4210 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4211 [g_Game_ModeToText(gGameSettings
.GameMode
),
4212 g_Game_ModeToText(gSwitchGameMode
)]));
4214 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4216 with gGameSettings
do
4218 if (Length(P
) > 1) and
4219 ((P
[1] = '1') or (P
[1] = '0')) then
4221 if (P
[1][1] = '1') then
4222 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4224 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4227 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4228 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4230 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4231 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4233 if g_Game_IsNet
then MH_SEND_GameSettings
;
4236 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4238 with gGameSettings
do
4240 if (Length(P
) > 1) and
4241 ((P
[1] = '1') or (P
[1] = '0')) then
4243 if (P
[1][1] = '1') then
4244 Options
:= Options
or GAME_OPTION_MONSTERS
4246 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4249 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4250 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4252 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4253 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4255 if g_Game_IsNet
then MH_SEND_GameSettings
;
4258 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4260 with gGameSettings
do
4262 if (Length(P
) > 1) and
4263 ((P
[1] = '1') or (P
[1] = '0')) then
4265 if (P
[1][1] = '1') then
4266 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4268 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4271 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4272 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4274 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4276 if g_Game_IsNet
then MH_SEND_GameSettings
;
4279 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4281 with gGameSettings
do
4283 if (Length(P
) > 1) and
4284 ((P
[1] = '1') or (P
[1] = '0')) then
4286 if (P
[1][1] = '1') then
4287 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4289 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4292 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4293 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4295 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4297 if g_Game_IsNet
then MH_SEND_GameSettings
;
4300 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4302 if Length(P
) > 1 then
4304 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4305 gGameSettings
.WarmupTime
:= 30
4307 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4310 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4311 [gGameSettings
.WarmupTime
]));
4312 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4314 else if cmd
= 'net_interp' then
4316 if (Length(P
) > 1) then
4317 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4319 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4320 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4321 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4322 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4325 else if cmd
= 'net_forceplayerupdate' then
4327 if (Length(P
) > 1) and
4328 ((P
[1] = '1') or (P
[1] = '0')) then
4329 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4331 if NetForcePlayerUpdate
then
4332 g_Console_Add('net_forceplayerupdate = 1')
4334 g_Console_Add('net_forceplayerupdate = 0');
4335 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4336 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4337 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4340 else if cmd
= 'net_predictself' then
4342 if (Length(P
) > 1) and
4343 ((P
[1] = '1') or (P
[1] = '0')) then
4344 NetPredictSelf
:= (P
[1][1] = '1');
4346 if NetPredictSelf
then
4347 g_Console_Add('net_predictself = 1')
4349 g_Console_Add('net_predictself = 0');
4350 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4351 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4352 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4355 else if cmd
= 'sv_name' then
4357 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4359 NetServerName
:= P
[1];
4360 if Length(NetServerName
) > 64 then
4361 SetLength(NetServerName
, 64);
4362 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4366 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4368 else if cmd
= 'sv_passwd' then
4370 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4372 NetPassword
:= P
[1];
4373 if Length(NetPassword
) > 24 then
4374 SetLength(NetPassword
, 24);
4375 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4379 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4381 else if cmd
= 'sv_maxplrs' then
4383 if (Length(P
) > 1) then
4385 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4386 if g_Game_IsServer
and g_Game_IsNet
then
4389 for a
:= 0 to High(NetClients
) do
4390 if NetClients
[a
].Used
then
4393 if b
> NetMaxClients
then
4395 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4396 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4397 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4398 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4401 if NetUseMaster
then
4406 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4408 else if cmd
= 'sv_public' then
4410 if (Length(P
) > 1) then
4412 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4413 if g_Game_IsServer
and g_Game_IsNet
then
4414 if NetUseMaster
then
4416 if NetMPeer
= nil then
4417 if not g_Net_Slist_Connect() then
4418 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4419 g_Net_Slist_Update();
4422 if NetMPeer
<> nil then
4423 g_Net_Slist_Disconnect();
4426 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4428 else if cmd
= 'sv_intertime' then
4430 if (Length(P
) > 1) then
4431 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4433 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4435 else if cmd
= 'p1_name' then
4437 if (Length(P
) > 1) and gGameOn
then
4439 if g_Game_IsClient
then
4441 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4442 MC_SEND_PlayerSettings
;
4445 if gPlayer1
<> nil then
4447 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4448 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4451 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4454 else if cmd
= 'p2_name' then
4456 if (Length(P
) > 1) and gGameOn
then
4458 if g_Game_IsClient
then
4460 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4461 MC_SEND_PlayerSettings
;
4464 if gPlayer2
<> nil then
4466 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4467 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4470 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4473 else if cmd
= 'p1_color' then
4475 if Length(P
) > 3 then
4476 if g_Game_IsClient
then
4478 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4479 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4480 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4481 MC_SEND_PlayerSettings
;
4484 if gPlayer1
<> nil then
4486 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4487 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4488 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4489 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4492 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4493 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4494 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4496 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4498 if Length(P
) > 3 then
4499 if g_Game_IsClient
then
4501 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4502 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4503 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4504 MC_SEND_PlayerSettings
;
4507 if gPlayer2
<> nil then
4509 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4510 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4511 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4512 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4515 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4516 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4517 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4519 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4521 if cmd
= 'r_showtime' then
4523 if (Length(P
) > 1) and
4524 ((P
[1] = '1') or (P
[1] = '0')) then
4525 gShowTime
:= (P
[1][1] = '1');
4528 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4530 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4532 else if cmd
= 'r_showscore' then
4534 if (Length(P
) > 1) and
4535 ((P
[1] = '1') or (P
[1] = '0')) then
4536 gShowGoals
:= (P
[1][1] = '1');
4539 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4541 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4543 else if cmd
= 'r_showstat' then
4545 if (Length(P
) > 1) and
4546 ((P
[1] = '1') or (P
[1] = '0')) then
4547 gShowStat
:= (P
[1][1] = '1');
4550 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4552 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4554 else if cmd
= 'r_showkillmsg' then
4556 if (Length(P
) > 1) and
4557 ((P
[1] = '1') or (P
[1] = '0')) then
4558 gShowKillMsg
:= (P
[1][1] = '1');
4560 if gShowKillMsg
then
4561 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4563 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4565 else if cmd
= 'r_showlives' then
4567 if (Length(P
) > 1) and
4568 ((P
[1] = '1') or (P
[1] = '0')) then
4569 gShowLives
:= (P
[1][1] = '1');
4572 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4574 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4576 else if cmd
= 'r_showspect' then
4578 if (Length(P
) > 1) and
4579 ((P
[1] = '1') or (P
[1] = '0')) then
4580 gSpectHUD
:= (P
[1][1] = '1');
4583 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4585 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4587 else if cmd
= 'r_showping' then
4589 if (Length(P
) > 1) and
4590 ((P
[1] = '1') or (P
[1] = '0')) then
4591 gShowPing
:= (P
[1][1] = '1');
4594 g_Console_Add(_lc
[I_MSG_PING_ON
])
4596 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4598 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4600 if Length(P
) > 1 then
4602 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4603 gGameSettings
.GoalLimit
:= 0
4608 if gGameSettings
.GameMode
= GM_DM
then
4610 stat
:= g_Player_GetStats();
4612 for a
:= 0 to High(stat
) do
4613 if stat
[a
].Frags
> b
then
4617 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4619 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4622 if g_Game_IsNet
then MH_SEND_GameSettings
;
4625 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4627 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4629 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4630 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4632 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4633 [gGameSettings
.TimeLimit
div 3600,
4634 (gGameSettings
.TimeLimit
div 60) mod 60,
4635 gGameSettings
.TimeLimit
mod 60]));
4636 if g_Game_IsNet
then MH_SEND_GameSettings
;
4638 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4640 if Length(P
) > 1 then
4642 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4643 gGameSettings
.MaxLives
:= 0
4647 stat
:= g_Player_GetStats();
4649 for a
:= 0 to High(stat
) do
4650 if stat
[a
].Lives
> b
then
4652 gGameSettings
.MaxLives
:=
4653 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4657 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4658 [gGameSettings
.MaxLives
]));
4659 if g_Game_IsNet
then MH_SEND_GameSettings
;
4664 procedure DebugCommands(P
: SArray
);
4670 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4673 cmd
:= LowerCase(P
[0]);
4674 if cmd
= 'd_window' then
4676 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4677 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4678 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4679 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4680 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4682 else if cmd
= 'd_sounds' then
4684 if (Length(P
) > 1) and
4685 ((P
[1] = '1') or (P
[1] = '0')) then
4686 g_Debug_Sounds
:= (P
[1][1] = '1');
4688 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4690 else if cmd
= 'd_frames' then
4692 if (Length(P
) > 1) and
4693 ((P
[1] = '1') or (P
[1] = '0')) then
4694 g_Debug_Frames
:= (P
[1][1] = '1');
4696 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4698 else if cmd
= 'd_winmsg' then
4700 if (Length(P
) > 1) and
4701 ((P
[1] = '1') or (P
[1] = '0')) then
4702 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4704 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4706 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4708 if (Length(P
) > 1) and
4709 ((P
[1] = '1') or (P
[1] = '0')) then
4710 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4712 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4714 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4716 if Length(P
) > 1 then
4718 '0': g_debug_BotAIOff
:= 0;
4719 '1': g_debug_BotAIOff
:= 1;
4720 '2': g_debug_BotAIOff
:= 2;
4721 '3': g_debug_BotAIOff
:= 3;
4724 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4726 else if cmd
= 'd_monster' then
4728 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4729 if Length(P
) < 2 then
4731 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4732 g_Console_Add('ID | Name');
4733 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4734 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4737 a
:= StrToIntDef(P
[1], 0);
4738 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4739 a
:= g_Monsters_GetIDByName(P
[1]);
4741 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4742 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4745 with gPlayer1
.Obj
do
4746 b
:= g_Monsters_Create(a
,
4747 X
+ Rect
.X
+ (Rect
.Width
div 2),
4748 Y
+ Rect
.Y
+ Rect
.Height
,
4749 gPlayer1
.Direction
, True);
4750 if (Length(P
) > 2) and (b
>= 0) then
4751 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4755 else if (cmd
= 'd_health') then
4757 if (Length(P
) > 1) and
4758 ((P
[1] = '1') or (P
[1] = '0')) then
4759 g_debug_HealthBar
:= (P
[1][1] = '1');
4761 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4763 else if (cmd
= 'd_player') then
4765 if (Length(P
) > 1) and
4766 ((P
[1] = '1') or (P
[1] = '0')) then
4767 g_debug_Player
:= (P
[1][1] = '1');
4769 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4771 else if (cmd
= 'd_joy') then
4774 g_Console_Add(e_JoystickStateToString(a
));
4778 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4782 procedure GameCheats(P
: SArray
);
4788 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4789 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4791 g_Console_Add('not available');
4797 g_Console_Add('where is the player?!');
4800 cmd
:= LowerCase(P
[0]);
4804 plr
.GodMode
:= not plr
.GodMode
;
4805 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4808 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4809 if cmd
= 'give' then
4811 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4812 for f
:= 1 to High(P
) do
4814 cmd
:= LowerCase(P
[f
]);
4815 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4816 if (cmd
= 'all') or (cmd
= 'weapons') then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4817 if cmd
= 'exit' then
4819 if gTriggers
<> nil then
4821 for a
:= 0 to High(gTriggers
) do
4823 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4825 g_Console_Add('player left the map');
4826 gExitByTrigger
:= True;
4827 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4834 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4835 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got jetpack'); continue
; end;
4836 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got envirosuit'); continue
; end;
4837 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got berserk pack'); continue
; end;
4838 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4843 if cmd
= 'open' then
4845 g_Console_Add('player activated sesame');
4846 g_Triggers_OpenAll();
4853 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4857 if cmd
= 'noclip' then
4860 g_Console_Add('wall hardeness adjusted');
4864 if cmd
= 'notarget' then
4866 plr
.NoTarget
:= not plr
.NoTarget
;
4867 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4871 if cmd
= 'noreload' then
4873 plr
.NoReload
:= not plr
.NoReload
;
4874 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4878 if cmd
= 'speedy' then
4880 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4881 g_Console_Add('speed adjusted');
4885 if cmd
= 'jumpy' then
4887 VEL_JUMP
:= 30-VEL_JUMP
;
4888 g_Console_Add('jump height adjusted');
4892 if cmd
= 'automap' then
4894 gShowMap
:= not gShowMap
;
4895 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4899 if cmd
= 'aimline' then
4901 gAimLine
:= not gAimLine
;
4902 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4907 procedure GameCommands(P
: SArray
);
4913 pl
: pTNetClient
= nil;
4920 cmd
:= LowerCase(P
[0]);
4922 if (cmd
= 'quit') or
4929 else if cmd
= 'pause' then
4931 if (g_ActiveWindow
= nil) then
4932 g_Game_Pause(not gPause
);
4934 else if cmd
= 'endgame' then
4935 gExit
:= EXIT_SIMPLE
4936 else if cmd
= 'restart' then
4938 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4940 if g_Game_IsClient
then
4942 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4947 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4949 else if cmd
= 'kick' then
4951 if g_Game_IsServer
then
4953 if Length(P
) < 2 then
4955 g_Console_Add('kick <name>');
4960 g_Console_Add('kick <name>');
4964 if g_Game_IsNet
then
4965 pl
:= g_Net_Client_ByName(P
[1]);
4968 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4969 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4970 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4971 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4972 if NetUseMaster
then
4974 end else if gPlayers
<> nil then
4975 for a
:= Low(gPlayers
) to High(gPlayers
) do
4976 if gPlayers
[a
] <> nil then
4977 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4979 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4980 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4982 gPlayers
[a
].Lives
:= 0;
4983 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4984 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4985 g_Player_Remove(gPlayers
[a
].UID
);
4986 if NetUseMaster
then
4988 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4992 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4994 else if cmd
= 'kick_id' then
4996 if g_Game_IsServer
and g_Game_IsNet
then
4998 if Length(P
) < 2 then
5000 g_Console_Add('kick_id <client ID>');
5005 g_Console_Add('kick_id <client ID>');
5009 a
:= StrToIntDef(P
[1], 0);
5010 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5012 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5014 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5015 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5016 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5017 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5018 if NetUseMaster
then
5023 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5025 else if cmd
= 'ban' then
5027 if g_Game_IsServer
and g_Game_IsNet
then
5029 if Length(P
) < 2 then
5031 g_Console_Add('ban <name>');
5036 g_Console_Add('ban <name>');
5040 pl
:= g_Net_Client_ByName(P
[1]);
5043 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5044 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5045 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5046 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5047 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5048 if NetUseMaster
then
5051 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5053 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5055 else if cmd
= 'ban_id' then
5057 if g_Game_IsServer
and g_Game_IsNet
then
5059 if Length(P
) < 2 then
5061 g_Console_Add('ban_id <client ID>');
5066 g_Console_Add('ban_id <client ID>');
5070 a
:= StrToIntDef(P
[1], 0);
5071 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5072 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5074 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5075 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5076 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5077 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5078 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5079 if NetUseMaster
then
5083 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5085 else if cmd
= 'permban' then
5087 if g_Game_IsServer
and g_Game_IsNet
then
5089 if Length(P
) < 2 then
5091 g_Console_Add('permban <name>');
5096 g_Console_Add('permban <name>');
5100 pl
:= g_Net_Client_ByName(P
[1]);
5103 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5104 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5105 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5106 g_Net_SaveBanList();
5107 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5108 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5109 if NetUseMaster
then
5112 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5114 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5116 else if cmd
= 'permban_id' then
5118 if g_Game_IsServer
and g_Game_IsNet
then
5120 if Length(P
) < 2 then
5122 g_Console_Add('permban_id <client ID>');
5127 g_Console_Add('permban_id <client ID>');
5131 a
:= StrToIntDef(P
[1], 0);
5132 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5133 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5135 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5136 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5137 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5138 g_Net_SaveBanList();
5139 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5140 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5141 if NetUseMaster
then
5145 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5147 else if cmd
= 'unban' then
5149 if g_Game_IsServer
and g_Game_IsNet
then
5151 if Length(P
) < 2 then
5153 g_Console_Add('unban <IP Address>');
5158 g_Console_Add('unban <IP Address>');
5162 if g_Net_UnbanHost(P
[1]) then
5164 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5165 g_Net_SaveBanList();
5167 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5169 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5171 else if cmd
= 'clientlist' then
5173 if g_Game_IsServer
and g_Game_IsNet
then
5176 if NetClients
<> nil then
5177 for a
:= Low(NetClients
) to High(NetClients
) do
5178 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5180 plr
:= g_Player_Get(NetClients
[a
].Player
);
5181 if plr
= nil then continue
;
5183 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5184 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5187 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5189 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5191 else if cmd
= 'connect' then
5193 if (NetMode
= NET_NONE
) then
5195 if Length(P
) < 2 then
5197 g_Console_Add('connect <IP> [port] [password]');
5202 g_Console_Add('connect <IP> [port] [password]');
5206 if Length(P
) > 2 then
5207 prt
:= StrToIntDef(P
[2], 25666)
5211 if Length(P
) > 3 then
5216 g_Game_StartClient(P
[1], prt
, pw
);
5219 else if cmd
= 'disconnect' then
5221 if (NetMode
= NET_CLIENT
) then
5224 else if cmd
= 'reconnect' then
5226 if (NetMode
= NET_SERVER
) then
5229 if (NetMode
= NET_CLIENT
) then
5232 gExit
:= EXIT_SIMPLE
;
5236 //TODO: Use last successful password to reconnect, instead of ''
5237 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5239 else if (cmd
= 'addbot') or
5240 (cmd
= 'bot_add') then
5242 if Length(P
) > 1 then
5243 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5245 g_Bot_Add(TEAM_NONE
, 2);
5247 else if cmd
= 'bot_addlist' then
5249 if Length(P
) > 1 then
5250 if Length(P
) = 2 then
5251 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5253 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5255 else if cmd
= 'bot_removeall' then
5257 else if cmd
= 'chat' then
5259 if g_Game_IsNet
then
5261 if Length(P
) > 1 then
5263 for a
:= 1 to High(P
) do
5264 chstr
:= chstr
+ P
[a
] + ' ';
5266 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5268 if Length(chstr
) < 1 then
5270 g_Console_Add('chat <text>');
5274 chstr
:= b_Text_Format(chstr
);
5275 if g_Game_IsClient
then
5276 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5278 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5281 g_Console_Add('chat <text>');
5283 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5285 else if cmd
= 'teamchat' then
5287 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5289 if Length(P
) > 1 then
5291 for a
:= 1 to High(P
) do
5292 chstr
:= chstr
+ P
[a
] + ' ';
5294 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5296 if Length(chstr
) < 1 then
5298 g_Console_Add('teamchat <text>');
5302 chstr
:= b_Text_Format(chstr
);
5303 if g_Game_IsClient
then
5304 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5306 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5307 gPlayer1Settings
.Team
);
5310 g_Console_Add('teamchat <text>');
5312 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5314 else if cmd
= 'game' then
5316 if gGameSettings
.GameType
<> GT_NONE
then
5318 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5321 if Length(P
) = 1 then
5323 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5326 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5327 P
[1] := addWadExtension(P
[1]);
5328 if FileExists(MapsDir
+ P
[1]) then
5330 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5331 if Length(P
) < 3 then
5334 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5337 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5339 if g_Map_Exist(MapsDir
+ s
) then
5341 // Çàïóñêàåì ñâîþ èãðó
5343 with gGameSettings
do
5345 GameMode
:= g_Game_TextToMode(gcGameMode
);
5346 if gSwitchGameMode
<> GM_NONE
then
5347 GameMode
:= gSwitchGameMode
;
5348 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5349 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5351 if Length(P
) >= 4 then
5352 b
:= StrToIntDef(P
[3], 1);
5353 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5354 GoalLimit
, MaxLives
, Options
, b
);
5359 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5361 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5363 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5365 else if cmd
= 'host' then
5367 if gGameSettings
.GameType
<> GT_NONE
then
5369 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5372 if Length(P
) < 4 then
5374 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5377 if not StrToIp(P
[1], listen
) then
5379 prt
:= StrToIntDef(P
[2], 25666);
5381 P
[3] := addWadExtension(P
[3]);
5382 if FileExists(MapsDir
+ P
[3]) then
5384 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5385 if Length(P
) < 5 then
5388 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5391 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5393 if g_Map_Exist(MapsDir
+ s
) then
5395 // Çàïóñêàåì ñâîþ èãðó
5397 with gGameSettings
do
5399 GameMode
:= g_Game_TextToMode(gcGameMode
);
5400 if gSwitchGameMode
<> GM_NONE
then
5401 GameMode
:= gSwitchGameMode
;
5402 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5403 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5405 if Length(P
) >= 6 then
5406 b
:= StrToIntDef(P
[5], 0);
5407 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5408 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5413 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5415 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5417 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5419 else if cmd
= 'map' then
5421 if Length(P
) = 1 then
5423 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5425 g_Console_Add(cmd
+ ' <MAP>');
5426 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5428 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5430 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5432 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5433 if Length(P
) < 3 then
5435 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5436 s
:= UpperCase(P
[1]);
5437 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5438 begin // Êàðòà íàøëàñü
5439 gExitByTrigger
:= False;
5441 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5443 gExit
:= EXIT_ENDLEVELCUSTOM
;
5445 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5446 g_Game_ChangeMap(s
);
5449 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5450 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5451 P
[1] := addWadExtension(P
[1]);
5452 if FileExists(MapsDir
+ P
[1]) then
5454 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5456 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5458 s
:= P
[1] + ':\' + P
[2];
5460 if g_Map_Exist(MapsDir
+ s
) then
5462 gExitByTrigger
:= False;
5464 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5466 gExit
:= EXIT_ENDLEVELCUSTOM
;
5468 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5469 g_Game_ChangeMap(s
);
5472 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5474 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5476 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5480 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5481 P
[1] := addWadExtension(P
[1]);
5482 if FileExists(MapsDir
+ P
[1]) then
5485 P
[2] := UpperCase(P
[2]);
5486 s
:= P
[1] + ':\' + P
[2];
5488 if g_Map_Exist(MapsDir
+ s
) then
5489 begin // Íàøëè êàðòó
5490 gExitByTrigger
:= False;
5492 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5494 gExit
:= EXIT_ENDLEVELCUSTOM
;
5496 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5497 g_Game_ChangeMap(s
);
5499 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5501 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5504 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5506 else if cmd
= 'nextmap' then
5508 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5509 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5512 if Length(P
) = 1 then
5514 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5516 g_Console_Add(cmd
+ ' <MAP>');
5517 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5520 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5525 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5527 if Length(P
) < 3 then
5529 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5530 s
:= UpperCase(P
[1]);
5531 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5532 begin // Êàðòà íàøëàñü
5533 gExitByTrigger
:= False;
5538 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5539 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5540 P
[1] := addWadExtension(P
[1]);
5541 if FileExists(MapsDir
+ P
[1]) then
5543 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5545 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5547 s
:= P
[1] + ':\' + P
[2];
5549 if g_Map_Exist(MapsDir
+ s
) then
5550 begin // Óñòàíàâëèâàåì êàðòó
5551 gExitByTrigger
:= False;
5556 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5558 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5560 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5564 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5565 P
[1] := addWadExtension(P
[1]);
5566 if FileExists(MapsDir
+ P
[1]) then
5569 P
[2] := UpperCase(P
[2]);
5570 s
:= P
[1] + ':\' + P
[2];
5572 if g_Map_Exist(MapsDir
+ s
) then
5573 begin // Íàøëè êàðòó
5574 gExitByTrigger
:= False;
5578 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5580 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5583 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5586 if gNextMap
= '' then
5587 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5589 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5592 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5595 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5597 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5599 gExitByTrigger
:= False;
5600 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5601 if (gNextMap
= '') and (gTriggers
<> nil) then
5602 for a
:= 0 to High(gTriggers
) do
5603 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5605 gExitByTrigger
:= True;
5606 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5609 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5610 if gNextMap
= '' then
5611 gNextMap
:= g_Game_GetNextMap();
5612 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5613 if Pos(':\', gNextMap
) = 0 then
5614 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5617 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5618 if g_Map_Exist(MapsDir
+ s
) then
5619 gExit
:= EXIT_ENDLEVELCUSTOM
5621 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5623 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5625 else if (cmd
= 'event') then
5627 if (Length(P
) <= 1) then
5629 for a
:= 0 to High(gEvents
) do
5630 if gEvents
[a
].Command
= '' then
5631 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5633 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5636 if (Length(P
) = 2) then
5638 for a
:= 0 to High(gEvents
) do
5639 if gEvents
[a
].Name
= P
[1] then
5640 if gEvents
[a
].Command
= '' then
5641 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5643 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5646 for a
:= 0 to High(gEvents
) do
5647 if gEvents
[a
].Name
= P
[1] then
5649 gEvents
[a
].Command
:= '';
5650 for b
:= 2 to High(P
) do
5651 if Pos(' ', P
[b
]) = 0 then
5652 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5654 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5655 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5659 // Êîìàíäû Ñâîåé èãðû:
5660 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5662 if cmd
= 'bot_addred' then
5664 if Length(P
) > 1 then
5665 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5667 g_Bot_Add(TEAM_RED
, 2);
5669 else if cmd
= 'bot_addblue' then
5671 if Length(P
) > 1 then
5672 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5674 g_Bot_Add(TEAM_BLUE
, 2);
5676 else if cmd
= 'suicide' then
5680 if g_Game_IsClient
then
5681 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5684 if gPlayer1
<> nil then
5685 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5686 if gPlayer2
<> nil then
5687 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5691 else if cmd
= 'spectate' then
5697 else if cmd
= 'say' then
5699 if g_Game_IsServer
and g_Game_IsNet
then
5701 if Length(P
) > 1 then
5704 for a
:= 1 to High(P
) do
5705 chstr
:= chstr
+ P
[a
] + ' ';
5707 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5709 if Length(chstr
) < 1 then
5711 g_Console_Add('say <text>');
5715 chstr
:= b_Text_Format(chstr
);
5716 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5718 else g_Console_Add('say <text>');
5720 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5722 else if cmd
= 'tell' then
5724 if g_Game_IsServer
and g_Game_IsNet
then
5726 if (Length(P
) > 2) and (P
[1] <> '') then
5729 for a
:= 2 to High(P
) do
5730 chstr
:= chstr
+ P
[a
] + ' ';
5732 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5734 if Length(chstr
) < 1 then
5736 g_Console_Add('tell <playername> <text>');
5740 pl
:= g_Net_Client_ByName(P
[1]);
5742 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5744 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5746 else g_Console_Add('tell <playername> <text>');
5748 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5750 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5752 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5754 // Äîïîëíèòåëüíîå âðåìÿ:
5755 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5757 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5758 [gGameSettings
.TimeLimit
div 3600,
5759 (gGameSettings
.TimeLimit
div 60) mod 60,
5760 gGameSettings
.TimeLimit
mod 60]));
5761 if g_Game_IsNet
then MH_SEND_GameSettings
;
5763 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5765 if (Length(P
) <= 1) then
5766 g_Console_Add('rcon_password <password>')
5768 MC_SEND_RCONPassword(P
[1]);
5770 else if cmd
= 'rcon' then
5772 if g_Game_IsClient
then
5774 if Length(P
) > 1 then
5777 for a
:= 1 to High(P
) do
5778 chstr
:= chstr
+ P
[a
] + ' ';
5780 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5782 if Length(chstr
) < 1 then
5784 g_Console_Add('rcon <command>');
5788 MC_SEND_RCONCommand(chstr
);
5790 else g_Console_Add('rcon <command>');
5793 else if cmd
= 'ready' then
5795 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5796 gLMSRespawnTime
:= gTime
+ 100;
5798 else if (cmd
= 'callvote') and g_Game_IsNet
then
5800 if Length(P
) > 1 then
5803 for a
:= 1 to High(P
) do begin
5804 if a
> 1 then chstr
:= chstr
+ ' ';
5805 chstr
:= chstr
+ P
[a
];
5808 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5810 if Length(chstr
) < 1 then
5812 g_Console_Add('callvote <command>');
5816 if g_Game_IsClient
then
5817 MC_SEND_Vote(True, chstr
)
5819 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5820 g_Console_Process('vote', True);
5823 g_Console_Add('callvote <command>');
5825 else if (cmd
= 'vote') and g_Game_IsNet
then
5827 if g_Game_IsClient
then
5829 else if gVoteInProgress
then
5831 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5832 a
:= Floor((NetClientCount
+1)/2.0) + 1
5834 a
:= Floor(NetClientCount
/2.0) + 1;
5839 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5840 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5846 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5847 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5855 procedure g_TakeScreenShot();
5863 if e_NoGraphics
then Exit
;
5864 ssdir
:= GameDir
+'/screenshots';
5865 if not findFileCI(ssdir
, true) then
5867 // try to create dir
5872 if not findFileCI(ssdir
, true) then exit
; // alas
5875 for a
:= 1 to High(Word) do
5877 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5879 if findFileCI(t
, true) then continue
;
5880 if not findFileCI(FileName
) then
5883 st
:= createDiskFile(FileName
);
5885 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5890 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5898 procedure g_Game_InGameMenu(Show
: Boolean);
5900 if (g_ActiveWindow
= nil) and Show
then
5902 if gGameSettings
.GameType
= GT_SINGLE
then
5903 g_GUI_ShowWindow('GameSingleMenu')
5906 if g_Game_IsClient
then
5907 g_GUI_ShowWindow('GameClientMenu')
5909 if g_Game_IsNet
then
5910 g_GUI_ShowWindow('GameServerMenu')
5912 g_GUI_ShowWindow('GameCustomMenu');
5914 g_Sound_PlayEx('MENU_OPEN');
5916 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5917 if (not g_Game_IsNet
) then
5921 if (g_ActiveWindow
<> nil) and (not Show
) then
5923 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5924 if (not g_Game_IsNet
) then
5925 g_Game_Pause(False);
5929 procedure g_Game_Pause(Enable
: Boolean);
5934 if gPause
= Enable
then
5937 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5941 g_Game_PauseAllSounds(Enable
);
5944 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5949 if gTriggers
<> nil then
5950 for i
:= 0 to High(gTriggers
) do
5951 with gTriggers
[i
] do
5952 if (TriggerType
= TRIGGER_SOUND
) and
5954 Sound
.IsPlaying() then
5956 Sound
.Pause(Enable
);
5960 if gPlayers
<> nil then
5961 for i
:= 0 to High(gPlayers
) do
5962 if gPlayers
[i
] <> nil then
5963 gPlayers
[i
].PauseSounds(Enable
);
5966 if gMusic
<> nil then
5967 gMusic
.Pause(Enable
);
5970 procedure g_Game_StopAllSounds(all
: Boolean);
5974 if gTriggers
<> nil then
5975 for i
:= 0 to High(gTriggers
) do
5976 with gTriggers
[i
] do
5977 if (TriggerType
= TRIGGER_SOUND
) and
5981 if gMusic
<> nil then
5988 procedure g_Game_UpdateTriggerSounds();
5992 if gTriggers
<> nil then
5993 for i
:= 0 to High(gTriggers
) do
5994 with gTriggers
[i
] do
5995 if (TriggerType
= TRIGGER_SOUND
) and
5998 Sound
.IsPlaying() then
6000 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6001 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6003 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6004 Sound
.SetVolume(Data
.Volume
/255.0);
6007 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6011 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6014 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6019 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6024 if gSpectMode
<> SPECT_PLAYERS
then
6026 if gSpectPID1
= UID
then
6031 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6038 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6043 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6048 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6053 if gSpectMode
<> SPECT_PLAYERS
then
6055 Pl
:= g_Player_Get(gSpectPID1
);
6056 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6061 if gSpectViewTwo
then
6063 Pl
:= g_Player_Get(gSpectPID2
);
6064 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6072 procedure g_Game_Message(Msg
: string; Time
: Word);
6074 MessageText
:= b_Text_Format(Msg
);
6075 MessageTime
:= Time
;
6078 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6087 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6091 if goodsnd
[a
].IsPlaying() then
6094 goodsnd
[Random(4)].Play();
6097 procedure g_Game_Announce_KillCombo(Param
: Integer);
6104 UID
:= Param
and $FFFF;
6109 Pl
:= g_Player_Get(UID
);
6118 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6122 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6126 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6130 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6138 if not g_Game_IsWatchedPlayer(UID
) then
6141 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6145 if killsnd
[n
].IsPlaying() then
6150 procedure g_Game_StartVote(Command
, Initiator
: string);
6154 if not gVotesEnabled
then Exit
;
6155 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6156 if gVoteInProgress
or gVotePassed
then
6158 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6159 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6162 gVoteInProgress
:= True;
6163 gVotePassed
:= False;
6164 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6167 gVoteCommand
:= Command
;
6169 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6170 Need
:= Floor((NetClientCount
+1)/2.0)+1
6172 Need
:= Floor(NetClientCount
/2.0)+1;
6173 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6174 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6177 procedure g_Game_CheckVote
;
6181 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6182 if not gVoteInProgress
then Exit
;
6184 if (gTime
>= gVoteTimer
) then
6186 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6187 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6189 Need
:= Floor(NetClientCount
/2.0) + 1;
6190 if gVoteCount
>= Need
then
6192 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6193 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6194 gVotePassed
:= True;
6195 gVoteCmdTimer
:= gTime
+ 5000;
6199 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6200 MH_SEND_VoteEvent(NET_VE_FAILED
);
6202 if NetClients
<> nil then
6203 for I
:= Low(NetClients
) to High(NetClients
) do
6204 if NetClients
[i
].Used
then
6205 NetClients
[i
].Voted
:= False;
6206 gVoteInProgress
:= False;
6212 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6213 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6215 Need
:= Floor(NetClientCount
/2.0) + 1;
6216 if gVoteCount
>= Need
then
6218 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6219 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6220 gVoteInProgress
:= False;
6221 gVotePassed
:= True;
6222 gVoteCmdTimer
:= gTime
+ 5000;
6225 if NetClients
<> nil then
6226 for I
:= Low(NetClients
) to High(NetClients
) do
6227 if NetClients
[i
].Used
then
6228 NetClients
[i
].Voted
:= False;
6233 procedure g_Game_LoadMapList(FileName
: string);
6241 if not FileExists(FileName
) then Exit
;
6243 AssignFile(ListFile
, FileName
);
6245 while not EOF(ListFile
) do
6247 ReadLn(ListFile
, s
);
6250 if s
= '' then Continue
;
6252 SetLength(MapList
, Length(MapList
)+1);
6253 MapList
[High(MapList
)] := s
;
6255 CloseFile(ListFile
);
6258 procedure g_Game_SetDebugMode();
6261 // ×èòû (äàæå â ñâîåé èãðå):
6265 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6269 if Length(LoadingStat
.Msgs
) = 0 then
6275 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6276 if NextMsg
= Length(Msgs
) then
6278 for i
:= 0 to High(Msgs
)-1 do
6279 Msgs
[i
] := Msgs
[i
+1];
6287 Msgs
[NextMsg
-1] := Text;
6293 g_ActiveWindow
:= nil;
6298 procedure g_Game_StepLoading();
6304 if (ShowCount
> LOADING_SHOW_STEP
) then
6312 procedure g_Game_ClearLoading();
6321 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6322 if len
< 1 then len
:= 1;
6323 SetLength(Msgs
, len
);
6324 for len
:= Low(Msgs
) to High(Msgs
) do
6330 procedure Parse_Params(var pars
: TParamStrValues
);
6337 while i
<= ParamCount
do
6340 if (s
[1] = '-') and (Length(s
) > 1) then
6342 if (s
[2] = '-') and (Length(s
) > 2) then
6343 begin // Îäèíî÷íûé ïàðàìåòð
6344 SetLength(pars
, Length(pars
) + 1);
6345 with pars
[High(pars
)] do
6347 Name
:= LowerCase(s
);
6352 if (i
< ParamCount
) then
6353 begin // Ïàðàìåòð ñî çíà÷åíèåì
6355 SetLength(pars
, Length(pars
) + 1);
6356 with pars
[High(pars
)] do
6358 Name
:= LowerCase(s
);
6359 Value
:= LowerCase(ParamStr(i
));
6368 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6373 for i
:= 0 to High(pars
) do
6374 if pars
[i
].Name
= aName
then
6376 Result
:= pars
[i
].Value
;
6381 procedure g_Game_Process_Params();
6383 pars
: TParamStrValues
;
6386 LimT
, LimS
: Integer;
6397 s
:= Find_Param_Value(pars
, '--debug');
6399 g_Game_SetDebugMode();
6401 // Connect when game loads
6402 ip
:= Find_Param_Value(pars
, '-connect');
6406 s
:= Find_Param_Value(pars
, '-port');
6407 if (s
= '') or not TryStrToInt(s
, Port
) then
6410 s
:= Find_Param_Value(pars
, '-pw');
6412 g_Game_StartClient(ip
, Port
, s
);
6416 // Start map when game loads:
6417 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6418 if isWadPath(map
) then
6421 s
:= Find_Param_Value(pars
, '-gm');
6422 GMode
:= g_Game_TextToMode(s
);
6423 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6424 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6427 s
:= Find_Param_Value(pars
, '-limt');
6428 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6434 s
:= Find_Param_Value(pars
, '-lims');
6435 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6441 s
:= Find_Param_Value(pars
, '-lives');
6442 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6448 s
:= Find_Param_Value(pars
, '-opt');
6450 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6452 Opt
:= StrToIntDef(s
, 0);
6454 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6457 s
:= Find_Param_Value(pars
, '--close');
6461 // Delete test map after play:
6462 s
:= Find_Param_Value(pars
, '--testdelete');
6465 gMapToDelete
:= MapsDir
+ map
;
6466 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6470 // Delete temporary WAD after play:
6471 s
:= Find_Param_Value(pars
, '--tempdelete');
6474 gMapToDelete
:= MapsDir
+ map
;
6475 gTempDelete
:= True;
6478 // Number of players:
6479 s
:= Find_Param_Value(pars
, '-pl');
6483 n
:= StrToIntDef(s
, 1);
6486 s
:= Find_Param_Value(pars
, '-port');
6487 if (s
= '') or not TryStrToInt(s
, Port
) then
6488 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6490 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6493 // Execute script when game loads:
6494 s
:= Find_Param_Value(pars
, '-exec');
6497 if Pos(':\', s
) = 0 then
6498 s
:= GameDir
+ '/' + s
;
6503 if IOResult
<> 0 then
6505 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6506 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6510 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6511 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6516 if IOResult
<> 0 then
6518 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6519 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6523 if Pos('#', s
) <> 1 then // script comment
6524 g_Console_Process(s
, True);