1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, wadreader
, md5
;
26 TGameSettings
= record
42 TDelayedEvent
= record
50 TPlayerSettings
= record
69 function g_Game_IsNet(): Boolean;
70 function g_Game_IsServer(): Boolean;
71 function g_Game_IsClient(): Boolean;
72 procedure g_Game_Init();
73 procedure g_Game_Free();
74 procedure g_Game_LoadData();
75 procedure g_Game_FreeData();
76 procedure g_Game_Update();
77 procedure g_Game_Draw();
78 procedure g_Game_Quit();
79 procedure g_Game_SetupScreenSize();
80 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
81 function g_Game_ModeToText(Mode
: Byte): string;
82 function g_Game_TextToMode(Mode
: string): Byte;
83 procedure g_Game_ExecuteEvent(Name
: String);
84 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
85 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
86 procedure g_Game_RemovePlayer();
87 procedure g_Game_Spectate();
88 procedure g_Game_SpectateCenterView();
89 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
90 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
91 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
92 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
93 procedure g_Game_Restart();
94 procedure g_Game_RestartLevel();
95 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
96 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
97 procedure g_Game_SaveOptions();
98 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
99 procedure g_Game_ChangeMap(MapPath
: String);
100 procedure g_Game_ExitLevel(Map
: Char16
);
101 function g_Game_GetFirstMap(WAD
: String): String;
102 function g_Game_GetNextMap(): String;
103 procedure g_Game_NextLevel();
104 procedure g_Game_Pause(Enable
: Boolean);
105 procedure g_Game_InGameMenu(Show
: Boolean);
106 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
107 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
108 procedure g_Game_Message(Msg
: String; Time
: Word);
109 procedure g_Game_LoadMapList(FileName
: String);
110 procedure g_Game_PauseAllSounds(Enable
: Boolean);
111 procedure g_Game_StopAllSounds(all
: Boolean);
112 procedure g_Game_UpdateTriggerSounds();
113 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
114 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
115 procedure g_Game_Announce_KillCombo(Param
: Integer);
116 procedure g_Game_StartVote(Command
, Initiator
: string);
117 procedure g_Game_CheckVote
;
118 procedure g_TakeScreenShot();
119 procedure g_FatalError(Text: String);
120 procedure g_SimpleError(Text: String);
121 function g_Game_IsTestMap(): Boolean;
122 procedure g_Game_DeleteTestMap();
123 procedure GameCVars(P
: SArray
);
124 procedure GameCommands(P
: SArray
);
125 procedure GameCheats(P
: SArray
);
126 procedure DebugCommands(P
: SArray
);
127 procedure g_Game_Process_Params
;
128 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
129 procedure g_Game_StepLoading();
130 procedure g_Game_ClearLoading();
131 procedure g_Game_SetDebugMode();
132 procedure DrawLoadingStat();
134 { procedure SetWinPause(Enable: Boolean); }
139 LOADING_SHOW_STEP
= 100;
140 LOADING_INTERLINE
= 20;
155 MESSAGE_DIKEY
= WM_USER
+ 1;
160 EXIT_ENDLEVELSINGLE
= 4;
161 EXIT_ENDLEVELCUSTOM
= 5;
163 GAME_OPTION_RESERVED
= 1;
164 GAME_OPTION_TEAMDAMAGE
= 2;
165 GAME_OPTION_ALLOWEXIT
= 4;
166 GAME_OPTION_WEAPONSTAY
= 8;
167 GAME_OPTION_MONSTERS
= 16;
168 GAME_OPTION_BOTVSPLAYER
= 32;
169 GAME_OPTION_BOTVSMONSTER
= 64;
174 STATE_INTERCUSTOM
= 3;
175 STATE_INTERSINGLE
= 4;
181 LMS_RESPAWN_NONE
= 0;
182 LMS_RESPAWN_WARMUP
= 1;
183 LMS_RESPAWN_FINAL
= 2;
199 CONFIG_FILENAME
= 'Doom2DF.cfg';
200 LOG_FILENAME
= 'Doom2DF.log';
202 TEST_MAP_NAME
= '$$$_TEST_$$$';
204 STD_PLAYER_MODEL
= 'Doomer';
208 gGameSettings
: TGameSettings
;
209 gPlayer1Settings
: TPlayerSettings
;
210 gPlayer2Settings
: TPlayerSettings
;
212 gPlayerScreenSize
: TPoint
;
213 gPlayer1ScreenCoord
: TPoint
;
214 gPlayer2ScreenCoord
: TPoint
;
215 gPlayer1
: TPlayer
= nil;
216 gPlayer2
: TPlayer
= nil;
217 gPlayerDrawn
: TPlayer
= nil;
219 gSwitchGameMode
: Byte = GM_DM
;
220 gHearPoint1
, gHearPoint2
: THearPoint
;
221 gSoundEffectsDF
: Boolean = False;
222 gSoundTriggerTime
: Word = 0;
223 gAnnouncer
: Byte = ANNOUNCE_NONE
;
224 goodsnd
: array[0..3] of TPlayableSound
;
225 killsnd
: array[0..3] of TPlayableSound
;
226 gDefInterTime
: ShortInt = -1;
227 gInterEndTime
: LongWord = 0;
228 gInterTime
: LongWord = 0;
229 gServInterTime
: Byte = 0;
230 gGameStartTime
: LongWord = 0;
231 gTotalMonsters
: Integer = 0;
233 gShowTime
: Boolean = True;
234 gShowFPS
: Boolean = False;
235 gShowGoals
: Boolean = True;
236 gShowStat
: Boolean = True;
237 gShowKillMsg
: Boolean = True;
238 gShowLives
: Boolean = True;
239 gShowPing
: Boolean = False;
240 gShowMap
: Boolean = False;
242 gState
: Byte = STATE_NONE
;
244 sWidth
, sHeight
: Word;
245 gSpectMode
: Byte = SPECT_NONE
;
246 gSpectHUD
: Boolean = True;
247 gSpectKeyPress
: Boolean = False;
248 gSpectX
: Integer = 0;
249 gSpectY
: Integer = 0;
250 gSpectStep
: Byte = 8;
251 gSpectViewTwo
: Boolean = False;
252 gSpectPID1
: Integer = -1;
253 gSpectPID2
: Integer = -1;
254 gMusic
: TMusic
= nil;
255 gLoadGameMode
: Boolean;
256 gCheats
: Boolean = False;
257 gMapOnce
: Boolean = False;
258 gMapToDelete
: String;
259 gTempDelete
: Boolean = False;
260 gLastMap
: Boolean = False;
261 gWinPosX
, gWinPosY
: Integer;
262 gWinSizeX
, gWinSizeY
: Integer;
263 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
264 gWinActive
: Boolean = True; // by default window is active, lol
265 gResolutionChange
: Boolean = False;
266 gRC_Width
, gRC_Height
: Word;
267 gRC_FullScreen
, gRC_Maximized
: Boolean;
268 gLanguageChange
: Boolean = False;
269 gDebugMode
: Boolean = False;
270 g_debug_Sounds
: Boolean = False;
271 g_debug_Frames
: Boolean = False;
272 g_debug_WinMsgs
: Boolean = False;
273 g_debug_MonsterOff
: Boolean = False;
274 g_debug_BotAIOff
: Byte = 0;
275 g_debug_HealthBar
: Boolean = False;
276 g_Debug_Player
: Boolean = False;
277 gCoopMonstersKilled
: Word = 0;
278 gCoopSecretsFound
: Word = 0;
279 gCoopTotalMonstersKilled
: Word = 0;
280 gCoopTotalSecretsFound
: Word = 0;
281 gCoopTotalMonsters
: Word = 0;
282 gCoopTotalSecrets
: Word = 0;
283 gStatsOff
: Boolean = False;
284 gStatsPressed
: Boolean = False;
285 gExitByTrigger
: Boolean = False;
286 gNextMap
: String = '';
287 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
288 gLMSRespawnTime
: Cardinal = 0;
289 gLMSSoftSpawn
: Boolean = False;
290 gMissionFailed
: Boolean = False;
291 gVoteInProgress
: Boolean = False;
292 gVotePassed
: Boolean = False;
293 gVoteCommand
: string = '';
294 gVoteTimer
: Cardinal = 0;
295 gVoteCmdTimer
: Cardinal = 0;
296 gVoteCount
: Integer = 0;
297 gVoteTimeout
: Cardinal = 30;
298 gVoted
: Boolean = False;
299 gVotesEnabled
: Boolean = True;
300 gEvents
: Array of TGameEvent
;
301 gDelayedEvents
: Array of TDelayedEvent
;
303 P1MoveButton
: Byte = 0;
304 P2MoveButton
: Byte = 0;
309 g_textures
, g_main
, g_window
, g_menu
,
310 e_input
, e_log
, g_console
, g_items
, g_map
,
311 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
312 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
313 BinEditor
, g_language
, g_net
, SDL
,
314 ENet
, e_fixedbuffer
, g_netmsg
, g_netmaster
, GL
, GLExt
,
318 TEndCustomGameStat
= record
319 PlayerStat
: TPlayerStatArray
;
323 Map
, MapName
: String;
326 TEndSingleGameStat
= record
327 PlayerStat
: Array [0..1] of record
333 TotalSecrets
: Integer;
336 TLoadingStat
= record
340 Msgs
: Array of String;
344 TParamStrValue
= record
349 TParamStrValues
= Array of TParamStrValue
;
352 INTER_ACTION_TEXT
= 1;
353 INTER_ACTION_PIC
= 2;
354 INTER_ACTION_MUSIC
= 3;
358 FPSCounter
, UPSCounter
: Word;
359 FPSTime
, UPSTime
: LongWord;
360 DataLoaded
: Boolean = False;
361 LastScreenShot
: Int64;
362 IsDrawStat
: Boolean = False;
363 CustomStat
: TEndCustomGameStat
;
364 SingleStat
: TEndSingleGameStat
;
365 LoadingStat
: TLoadingStat
;
366 EndingGameCounter
: Byte = 0;
369 MapList
: SArray
= nil;
370 MapIndex
: Integer = -1;
376 text: Array of ShortString;
377 anim
: Array of ShortString;
378 pic
: Array of ShortString;
379 mus
: Array of ShortString;
381 triggers
: Array of record
383 actions
: Array of record
384 action
, p1
, p2
: Integer;
387 cur_trigger
: Integer;
400 function Compare(a
, b
: TPlayerStat
): Integer;
402 if a
.Spectator
then Result
:= 1
403 else if b
.Spectator
then Result
:= -1
404 else if a
.Frags
< b
.Frags
then Result
:= 1
405 else if a
.Frags
> b
.Frags
then Result
:= -1
406 else if a
.Deaths
< b
.Deaths
then Result
:= -1
407 else if a
.Deaths
> b
.Deaths
then Result
:= 1
408 else if a
.Kills
< b
.Kills
then Result
:= -1
412 procedure SortGameStat(var stat
: TPlayerStatArray
);
417 if stat
= nil then Exit
;
419 for I
:= High(stat
) downto Low(stat
) do
420 for J
:= Low(stat
) to High(stat
) - 1 do
421 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
424 stat
[J
] := stat
[J
+ 1];
429 function g_Game_ModeToText(Mode
: Byte): string;
433 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
434 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
435 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
436 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
437 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
441 function g_Game_TextToMode(Mode
: string): Byte;
444 Mode
:= UpperCase(Mode
);
445 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
450 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
455 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
460 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
465 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
472 function g_Game_IsNet(): Boolean;
474 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
477 function g_Game_IsServer(): Boolean;
479 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
482 function g_Game_IsClient(): Boolean;
484 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
487 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
494 Result
.name
:= ExtractFileName(WAD
);
495 Result
.description
:= '';
498 w
:= TWADFile
.Create();
501 if not w
.GetResource('INTERSCRIPT', p
, len
) then
507 cfg
:= TConfig
.CreateMem(p
, len
);
508 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
509 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
510 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
511 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
517 procedure g_Game_FreeWAD();
521 for a
:= 0 to High(MegaWAD
.res
.pic
) do
522 if MegaWAD
.res
.pic
[a
] <> '' then
523 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
525 for a
:= 0 to High(MegaWAD
.res
.mus
) do
526 if MegaWAD
.res
.mus
[a
] <> '' then
527 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
529 MegaWAD
.res
.pic
:= nil;
530 MegaWAD
.res
.text := nil;
531 MegaWAD
.res
.anim
:= nil;
532 MegaWAD
.res
.mus
:= nil;
533 MegaWAD
.triggers
:= nil;
535 g_Texture_Delete('TEXTURE_endpic');
536 g_Sound_Delete('MUSIC_endmus');
538 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
539 gGameSettings
.WAD
:= '';
542 procedure g_Game_LoadWAD(WAD
: string);
551 gGameSettings
.WAD
:= WAD
;
552 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
555 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
557 w
:= TWADFile
.Create();
558 w
.ReadFile(MapsDir
+ WAD
);
560 if not w
.GetResource('INTERSCRIPT', p
, len
) then
566 cfg
:= TConfig
.CreateMem(p
, len
);
571 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
572 if s = '' then Break;
575 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
576 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
578 g_Texture_CreateWADEx(s, s);
584 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
585 if s = '' then Break;
588 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
589 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
591 g_Music_CreateWADEx(s, s);
594 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
595 if MegaWAD
.endpic
<> '' then
597 s
:= g_ExtractWadName(MegaWAD
.endpic
);
598 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
599 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
601 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
602 if MegaWAD
.endmus
<> '' then
604 s
:= g_ExtractWadName(MegaWAD
.endmus
);
605 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
606 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
614 {procedure start_trigger(t: string);
618 function next_trigger(): Boolean;
622 procedure DisableCheats();
628 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
629 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
630 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
631 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
634 procedure g_Game_ExecuteEvent(Name
: String);
640 if gEvents
= nil then
642 for a
:= 0 to High(gEvents
) do
643 if gEvents
[a
].Name
= Name
then
645 if gEvents
[a
].Command
<> '' then
646 g_Console_Process(gEvents
[a
].Command
, True);
651 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
656 if gDelayedEvents
<> nil then
657 for a
:= 0 to High(gDelayedEvents
) do
658 if not gDelayedEvents
[a
].Pending
then
665 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
666 n
:= High(gDelayedEvents
);
668 gDelayedEvents
[n
].Pending
:= True;
669 gDelayedEvents
[n
].DEType
:= DEType
;
670 gDelayedEvents
[n
].DENum
:= Num
;
671 gDelayedEvents
[n
].DEStr
:= Str
;
672 if DEType
= DE_GLOBEVENT
then
673 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
675 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
684 if g_Game_IsNet
and g_Game_IsServer
then
685 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
691 g_Game_StopAllSounds(False);
696 EndingGameCounter
:= 0;
697 g_ActiveWindow
:= nil;
699 gLMSRespawn
:= LMS_RESPAWN_NONE
;
700 gLMSRespawnTime
:= 0;
703 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
708 begin // Ýòî áûë òåñò
712 begin // Âûõîä â ãëàâíîå ìåíþ
713 gMusic
.SetByName('MUSIC_MENU');
715 if gState
<> STATE_SLIST
then
717 g_GUI_ShowWindow('MainMenu');
718 gState
:= STATE_MENU
;
721 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
722 slReturnPressed
:= True;
723 if g_Net_Slist_Fetch(slCurrent
) then
725 if slCurrent
= nil then
726 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
729 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
732 g_Game_ExecuteEvent('ongameend');
736 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
738 if not g_Game_IsClient
then g_Game_Restart();
741 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
743 // Ñòàòèñòèêà Ñâîåé èãðû:
744 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
746 CustomStat
.GameTime
:= gTime
;
747 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
748 CustomStat
.MapName
:= gMapInfo
.Name
;
749 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
750 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
751 CustomStat
.TeamStat
:= gTeamStat
;
753 CustomStat
.PlayerStat
:= nil;
755 // Ñòàòèñòèêà èãðîêîâ:
756 if gPlayers
<> nil then
758 for a
:= 0 to High(gPlayers
) do
759 if gPlayers
[a
] <> nil then
761 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
762 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
764 Name
:= gPlayers
[a
].Name
;
765 Frags
:= gPlayers
[a
].Frags
;
766 Deaths
:= gPlayers
[a
].Death
;
767 Kills
:= gPlayers
[a
].Kills
;
768 Team
:= gPlayers
[a
].Team
;
769 Color
:= gPlayers
[a
].Model
.Color
;
770 Spectator
:= gPlayers
[a
].FSpectator
;
774 SortGameStat(CustomStat
.PlayerStat
);
777 g_Game_ExecuteEvent('onmapend');
780 EndingGameCounter
:= 255;
781 gState
:= STATE_FOLD
;
783 if gDefInterTime
< 0 then
784 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
786 gInterEndTime
:= gDefInterTime
* 1000;
789 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
791 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
792 SingleStat
.GameTime
:= gTime
;
793 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
794 SingleStat
.TotalSecrets
:= gSecretsCount
;
795 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
796 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
797 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
798 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
799 if SingleStat
.TwoPlayers
then
801 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
802 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
805 g_Game_ExecuteEvent('onmapend');
808 if gNextMap
<> '' then
810 gMusic
.SetByName('MUSIC_INTERMUS');
812 gState
:= STATE_INTERSINGLE
;
814 g_Game_ExecuteEvent('oninter');
816 else // Áîëüøå íåò êàðò
819 EndingGameCounter
:= 255;
820 gState
:= STATE_FOLD
;
825 // Îêîí÷àíèå îáðàáîòàíî:
826 if gExit
<> EXIT_QUIT
then
830 procedure DrawStat();
832 pc
, x
, y
, w
, h
: Integer;
833 w1
, w2
, w3
, w4
: Integer;
835 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
838 stat
: TPlayerStatArray
;
845 pc
:= g_Player_GetCount
;
846 e_TextureFontGetSize(gStdFont
, cw
, ch
);
848 w
:= gScreenWidth
-(gScreenWidth
div 5);
849 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
852 h
:= 40+ch
*5+(ch
+8)*pc
;
853 x
:= (gScreenWidth
div 2)-(w
div 2);
854 y
:= (gScreenHeight
div 2)-(h
div 2);
856 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
857 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
859 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
860 map
:= g_ExtractFileName(gMapInfo
.Map
);
861 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
863 case gGameSettings
.GameMode
of
866 if gGameSettings
.MaxLives
= 0 then
869 s1
:= _lc
[I_GAME_LMS
];
870 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
871 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
876 if gGameSettings
.MaxLives
= 0 then
877 s1
:= _lc
[I_GAME_TDM
]
879 s1
:= _lc
[I_GAME_TLMS
];
880 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
881 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
886 s1
:= _lc
[I_GAME_CTF
];
887 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
888 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
893 if gGameSettings
.MaxLives
= 0 then
894 s1
:= _lc
[I_GAME_COOP
]
896 s1
:= _lc
[I_GAME_SURV
];
897 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
898 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
909 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
911 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
913 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
915 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
916 gStdFont
, 200, 200, 200, 1);
918 if NetMode
= NET_SERVER
then
919 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
921 if NetMode
= NET_CLIENT
then
922 e_TextureFontPrintEx(x
+8, y
+ 8,
923 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
927 stat
:= g_Player_GetStats();
930 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
931 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
933 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
935 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
939 for a
:= TEAM_RED
to TEAM_BLUE
do
943 s1
:= _lc
[I_GAME_TEAM_RED
];
950 s1
:= _lc
[I_GAME_TEAM_BLUE
];
956 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
957 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
958 gStdFont
, r
, g
, b
, 1);
960 _y
:= _y
+ch
+(ch
div 4);
961 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
964 for aa
:= 0 to High(stat
) do
965 if stat
[aa
].Team
= a
then
981 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
983 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
985 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
987 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
994 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
997 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
998 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
999 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1000 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1003 for aa
:= 0 to High(stat
) do
1017 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1018 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1020 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1022 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1024 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1026 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1032 procedure g_Game_Init();
1038 gTempDelete
:= False;
1040 sfsGCDisable(); // temporary disable removing of temporary volumes
1043 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1044 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1045 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1046 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1048 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1049 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1050 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1052 g_Game_ClearLoading();
1053 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1054 g_Game_SetLoadingText('', 0, False);
1056 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1059 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1060 g_PlayerModel_LoadData();
1062 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1064 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1065 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1066 until FindNext(SR
) <> 0;
1069 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1071 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1072 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1073 until FindNext(SR
) <> 0;
1076 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1078 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1079 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1080 until FindNext(SR
) <> 0;
1086 LastScreenShot
:= 0;
1088 {e_MouseInfo.Accel := 1.0;}
1090 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1093 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1094 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1095 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1096 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1097 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1099 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1102 gMusic
:= TMusic
.Create();
1103 gMusic
.SetByName('MUSIC_MENU');
1106 gGameSettings
.WarmupTime
:= 30;
1108 gState
:= STATE_MENU
;
1110 SetLength(gEvents
, 6);
1111 gEvents
[0].Name
:= 'ongamestart';
1112 gEvents
[1].Name
:= 'ongameend';
1113 gEvents
[2].Name
:= 'onmapstart';
1114 gEvents
[3].Name
:= 'onmapend';
1115 gEvents
[4].Name
:= 'oninter';
1116 gEvents
[5].Name
:= 'onwadend';
1118 sfsGCEnable(); // enable releasing unused volumes
1122 procedure g_Game_Free();
1124 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1125 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1129 g_Player_RemoveAllCorpses();
1131 gGameSettings
.GameType
:= GT_NONE
;
1132 if gGameSettings
.GameMode
= GM_SINGLE
then
1133 gGameSettings
.GameMode
:= GM_DM
;
1134 gSwitchGameMode
:= gGameSettings
.GameMode
;
1137 gExitByTrigger
:= False;
1140 function IsActivePlayer(p
: TPlayer
): Boolean;
1145 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1148 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1155 if gPlayers
= nil then
1157 for a
:= Low(gPlayers
) to High(gPlayers
) do
1158 if IsActivePlayer(gPlayers
[a
]) then
1160 if gPlayers
[a
].UID
<> ID
then
1162 Result
:= gPlayers
[a
];
1167 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1173 if gPlayers
= nil then
1177 for a
:= Low(gPlayers
) to High(gPlayers
) do
1178 if IsActivePlayer(gPlayers
[a
]) then
1180 SetLength(ids
, Length(ids
) + 1);
1181 ids
[High(ids
)] := gPlayers
[a
].UID
;
1182 if gPlayers
[a
].UID
= Skip
then
1185 if Length(ids
) = 0 then
1190 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1193 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1199 if gPlayers
= nil then
1203 for a
:= Low(gPlayers
) to High(gPlayers
) do
1204 if IsActivePlayer(gPlayers
[a
]) then
1206 SetLength(ids
, Length(ids
) + 1);
1207 ids
[High(ids
)] := gPlayers
[a
].UID
;
1208 if gPlayers
[a
].UID
= Skip
then
1211 if Length(ids
) = 0 then
1214 Result
:= ids
[Length(ids
) - 1]
1216 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1219 procedure g_Game_Update();
1221 Msg
: g_gui
.TMessage
;
1227 // Ïîðà âûêëþ÷àòü èãðó:
1228 if gExit
= EXIT_QUIT
then
1230 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1234 if gExit
= EXIT_QUIT
then
1238 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1241 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1244 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1246 gExit
:= EXIT_SIMPLE
;
1252 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1253 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1254 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1255 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1257 if g_Game_IsNet
and g_Game_IsServer
then
1259 gInterTime
:= gInterTime
+ GAME_TICK
;
1260 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1261 if a
<> gServInterTime
then
1263 gServInterTime
:= a
;
1264 MH_SEND_TimeSync(gServInterTime
);
1268 if (not g_Game_IsClient
) and
1271 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1272 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1273 and (g_ActiveWindow
= nil)
1275 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1278 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1279 g_Game_StopAllSounds(True);
1281 if gMapOnce
then // Ýòî áûë òåñò
1282 gExit
:= EXIT_SIMPLE
1284 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1285 g_Game_ChangeMap(gNextMap
)
1286 else // Ñëåäóþùåé êàðòû íåò
1288 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1290 // Âûõîä â ãëàâíîå ìåíþ:
1292 g_GUI_ShowWindow('MainMenu');
1293 gMusic
.SetByName('MUSIC_MENU');
1295 gState
:= STATE_MENU
;
1298 // Ôèíàëüíàÿ êàðòèíêà:
1299 g_Game_ExecuteEvent('onwadend');
1301 if not gMusic
.SetByName('MUSIC_endmus') then
1302 gMusic
.SetByName('MUSIC_STDENDMUS');
1304 gState
:= STATE_ENDPIC
;
1306 g_Game_ExecuteEvent('ongameend');
1312 if gState
= STATE_INTERTEXT
then
1313 if InterText
.counter
> 0 then
1314 InterText
.counter
:= InterText
.counter
- 1;
1317 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1319 if EndingGameCounter
= 0 then
1321 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1322 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1324 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1326 g_Game_ExecuteEvent('onwadend');
1327 if not gMusic
.SetByName('MUSIC_endmus') then
1328 gMusic
.SetByName('MUSIC_STDENDMUS');
1331 gMusic
.SetByName('MUSIC_ROUNDMUS');
1334 gState
:= STATE_INTERCUSTOM
;
1336 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1338 gMusic
.SetByName('MUSIC_INTERMUS');
1340 gState
:= STATE_INTERSINGLE
;
1342 g_Game_ExecuteEvent('oninter');
1345 DecMin(EndingGameCounter
, 6, 0);
1348 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1350 if gMapOnce
then // Ýòî áûë òåñò
1352 gExit
:= EXIT_SIMPLE
;
1358 g_Serverlist_Control(slCurrent
);
1361 if g_Game_IsNet
then
1362 if not gConsoleShow
then
1363 if not gChatShow
then
1365 if g_ActiveWindow
= nil then
1367 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1368 g_Console_Chat_Switch(False)
1369 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1370 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1371 g_Console_Chat_Switch(True);
1374 if not gChatEnter
then
1375 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1376 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1379 // Ñòàòèñòèêà ïî Tab:
1381 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1382 (gGameSettings
.GameType
<> GT_SINGLE
) and
1383 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1386 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1388 // Âðåìÿ += 28 ìèëëèñåêóíä:
1389 gTime
:= gTime
+ GAME_TICK
;
1391 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1392 if MessageTime
= 0 then
1394 if MessageTime
> 0 then
1395 MessageTime
:= MessageTime
- 1;
1397 if (g_Game_IsServer
) then
1399 // Áûë çàäàí ëèìèò âðåìåíè:
1400 if (gGameSettings
.TimeLimit
> 0) then
1401 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1402 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1407 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1408 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1409 g_Game_RestartRound(gLMSSoftSpawn
);
1411 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1412 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1414 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1416 g_Console_Process(gVoteCommand
);
1418 gVotePassed
:= False;
1421 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1422 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1423 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1424 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1425 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1427 // Áûë çàäàí ëèìèò ïîáåä:
1428 if (gGameSettings
.GoalLimit
> 0) then
1432 if gGameSettings
.GameMode
= GM_DM
then
1433 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1434 for i
:= 0 to High(gPlayers
) do
1435 if gPlayers
[i
] <> nil then
1436 if gPlayers
[i
].Frags
> b
then
1437 b
:= gPlayers
[i
].Frags
;
1440 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1441 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1442 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1445 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1446 if b
>= gGameSettings
.GoalLimit
then
1453 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1454 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1455 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1456 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1459 if gPlayer1
<> nil then
1460 with gGameControls
.P1Control
do
1462 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1463 P1MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1465 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1466 P1MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1468 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1469 P1MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1471 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1472 if P1MoveButton
= 1 then
1473 gPlayer1
.PressKey(KEY_LEFT
)
1475 if P1MoveButton
= 2 then
1476 gPlayer1
.PressKey(KEY_RIGHT
);
1478 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1479 if (P1MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1480 gPlayer1
.SetDirection(D_LEFT
)
1482 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1483 if (P1MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1484 gPlayer1
.SetDirection(D_RIGHT
)
1486 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1487 if P1MoveButton
<> 0 then
1488 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
1490 // Îñòàëüíûå êëàâèøè:
1491 if e_KeyPressed(KeyJump
) then gPlayer1
.PressKey(KEY_JUMP
);
1492 if e_KeyPressed(KeyUp
) then gPlayer1
.PressKey(KEY_UP
);
1493 if e_KeyPressed(KeyDown
) then gPlayer1
.PressKey(KEY_DOWN
);
1494 if e_KeyPressed(KeyFire
) then gPlayer1
.PressKey(KEY_FIRE
);
1495 if e_KeyPressed(KeyNextWeapon
) then gPlayer1
.PressKey(KEY_NEXTWEAPON
);
1496 if e_KeyPressed(KeyPrevWeapon
) then gPlayer1
.PressKey(KEY_PREVWEAPON
);
1497 if e_KeyPressed(KeyOpen
) then gPlayer1
.PressKey(KEY_OPEN
);
1500 if gPlayer2
<> nil then
1501 with gGameControls
.P2Control
do
1503 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1504 P2MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1506 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1507 P2MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1509 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1510 P2MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1512 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1513 if P2MoveButton
= 1 then
1514 gPlayer2
.PressKey(KEY_LEFT
, 1000)
1516 if P2MoveButton
= 2 then
1517 gPlayer2
.PressKey(KEY_RIGHT
, 1000);
1519 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1520 if (P2MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1521 gPlayer2
.SetDirection(D_LEFT
)
1523 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1524 if (P2MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1525 gPlayer2
.SetDirection(D_RIGHT
)
1527 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1528 if P2MoveButton
<> 0 then
1529 gPlayer2
.SetDirection(TDirection(P2MoveButton
-1));
1531 // Îñòàëüíûå êëàâèøè:
1532 if e_KeyPressed(KeyJump
) then gPlayer2
.PressKey(KEY_JUMP
, 1000);
1533 if e_KeyPressed(KeyUp
) then gPlayer2
.PressKey(KEY_UP
, 1000);
1534 if e_KeyPressed(KeyDown
) then gPlayer2
.PressKey(KEY_DOWN
, 1000);
1535 if e_KeyPressed(KeyFire
) then gPlayer2
.PressKey(KEY_FIRE
);
1536 if e_KeyPressed(KeyNextWeapon
) then gPlayer2
.PressKey(KEY_NEXTWEAPON
);
1537 if e_KeyPressed(KeyPrevWeapon
) then gPlayer2
.PressKey(KEY_PREVWEAPON
);
1538 if e_KeyPressed(KeyOpen
) then gPlayer2
.PressKey(KEY_OPEN
);
1540 end // if not console
1542 if g_Game_IsNet
and (gPlayer1
<> nil) then
1543 gPlayer1
.PressKey(KEY_CHAT
, 10000);
1548 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1549 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1551 if not gSpectKeyPress
then
1553 if e_KeyPressed(gGameControls
.P1Control
.KeyJump
) then
1555 // switch spect mode
1557 SPECT_NONE
: ; // not spectator
1559 SPECT_MAPVIEW
: Inc(gSpectMode
);
1560 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1562 gSpectKeyPress
:= True;
1564 if gSpectMode
= SPECT_MAPVIEW
then
1566 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1567 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1568 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1569 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1570 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1571 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1572 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1573 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1574 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1577 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1578 gSpectKeyPress
:= True;
1580 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1583 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1584 gSpectKeyPress
:= True;
1587 if gSpectMode
= SPECT_PLAYERS
then
1589 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1592 gSpectViewTwo
:= True;
1593 gSpectKeyPress
:= True;
1595 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1597 // remove second view
1598 gSpectViewTwo
:= False;
1599 gSpectKeyPress
:= True;
1601 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1603 // prev player (view 1)
1604 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1605 gSpectKeyPress
:= True;
1607 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1609 // next player (view 1)
1610 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1611 gSpectKeyPress
:= True;
1613 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1615 // prev player (view 2)
1616 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1617 gSpectKeyPress
:= True;
1619 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1621 // next player (view 2)
1622 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1623 gSpectKeyPress
:= True;
1628 if (not e_KeyPressed(gGameControls
.P1Control
.KeyJump
)) and
1629 (not e_KeyPressed(gGameControls
.P1Control
.KeyLeft
)) and
1630 (not e_KeyPressed(gGameControls
.P1Control
.KeyRight
)) and
1631 (not e_KeyPressed(gGameControls
.P1Control
.KeyUp
)) and
1632 (not e_KeyPressed(gGameControls
.P1Control
.KeyDown
)) and
1633 (not e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
)) and
1634 (not e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
)) then
1635 gSpectKeyPress
:= False;
1638 // Îáíîâëÿåì âñå îñòàëüíîå:
1641 g_Triggers_Update();
1643 g_Monsters_Update();
1645 g_Player_UpdateAll();
1646 g_Player_UpdatePhysicalObjects();
1647 if gGameSettings
.GameType
= GT_SERVER
then
1648 if Length(gMonstersSpawned
) > 0 then
1650 for I
:= 0 to High(gMonstersSpawned
) do
1651 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1652 SetLength(gMonstersSpawned
, 0);
1655 if (gSoundTriggerTime
> 8) then
1657 g_Game_UpdateTriggerSounds();
1658 gSoundTriggerTime
:= 0;
1661 Inc(gSoundTriggerTime
);
1663 if (NetMode
= NET_SERVER
) then
1665 Inc(NetTimeToUpdate
);
1666 Inc(NetTimeToReliable
);
1667 if NetTimeToReliable
>= NetRelupdRate
then
1669 for I
:= 0 to High(gPlayers
) do
1670 if gPlayers
[I
] <> nil then
1671 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1673 if gMonsters
<> nil then
1674 for I
:= 0 to High(gMonsters
) do
1675 if gMonsters
[I
] <> nil then
1677 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1679 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1680 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1683 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1684 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1685 (gMonsters
[I
].GameVelX
<> 0) or
1686 (gMonsters
[I
].GameVelY
<> 0) then
1687 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1690 NetTimeToReliable
:= 0;
1691 NetTimeToUpdate
:= NetUpdateRate
;
1693 else if NetTimeToUpdate
>= NetUpdateRate
then
1695 if gPlayers
<> nil then
1696 for I
:= 0 to High(gPlayers
) do
1697 if gPlayers
[I
] <> nil then
1698 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1700 if gMonsters
<> nil then
1701 for I
:= 0 to High(gMonsters
) do
1702 if gMonsters
[I
] <> nil then
1704 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1706 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1707 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1710 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1711 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1712 (gMonsters
[I
].GameVelX
<> 0) or
1713 (gMonsters
[I
].GameVelY
<> 0) then
1714 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1717 NetTimeToUpdate
:= 0;
1720 if NetUseMaster
then
1721 if gTime
>= NetTimeToMaster
then
1723 if (NetMHost
= nil) or (NetMPeer
= nil) then
1724 if not g_Net_Slist_Connect
then
1725 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1728 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1732 if NetMode
= NET_CLIENT
then
1733 MC_SEND_PlayerPos();
1734 end; // if gameOn ...
1736 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1737 if g_ActiveWindow
<> nil then
1739 w
:= e_GetFirstKeyPressed();
1741 if (w
<> IK_INVALID
) then
1743 Msg
.Msg
:= MESSAGE_DIKEY
;
1745 g_ActiveWindow
.OnMessage(Msg
);
1748 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1749 if g_ActiveWindow
<> nil then
1750 g_ActiveWindow
.Update();
1752 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1753 if gResolutionChange
then
1755 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1756 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1757 gResolutionChange
:= False;
1760 // Íóæíî ñìåíèòü ÿçûê:
1761 if gLanguageChange
then
1763 //e_WriteLog('Read language file', MSG_NOTIFY);
1764 //g_Language_Load(DataDir + gLanguage + '.txt');
1765 g_Language_Set(gLanguage
);
1767 gLanguageChange
:= False;
1771 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1772 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1773 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1776 LastScreenShot
:= GetTimer();
1779 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1780 if e_KeyPressed(IK_F10
) and
1782 (not gConsoleShow
) and
1783 (g_ActiveWindow
= nil) then
1788 Time
:= GetTimer() {div 1000};
1790 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1791 if gDelayedEvents
<> nil then
1792 for a
:= 0 to High(gDelayedEvents
) do
1793 if gDelayedEvents
[a
].Pending
and
1795 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1796 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1799 case gDelayedEvents
[a
].DEType
of
1801 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1804 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1808 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1809 if g_Game_IsNet
and g_Game_IsServer
then
1810 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1813 gDelayedEvents
[a
].Pending
:= False;
1816 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1817 UPSCounter
:= UPSCounter
+ 1;
1818 if Time
- UPSTime
>= 1000 then
1826 procedure g_Game_LoadData();
1828 if DataLoaded
then Exit
;
1830 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1832 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1833 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1834 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1835 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1836 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1837 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1838 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1839 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1840 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1841 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1842 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1843 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1844 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1845 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1846 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1847 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1848 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1849 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1850 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1851 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1852 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1853 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1854 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1855 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1856 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1857 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1858 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1859 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1860 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1861 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1862 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1863 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1864 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1865 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1867 goodsnd
[0] := TPlayableSound
.Create();
1868 goodsnd
[1] := TPlayableSound
.Create();
1869 goodsnd
[2] := TPlayableSound
.Create();
1870 goodsnd
[3] := TPlayableSound
.Create();
1872 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1873 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1874 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1875 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1877 killsnd
[0] := TPlayableSound
.Create();
1878 killsnd
[1] := TPlayableSound
.Create();
1879 killsnd
[2] := TPlayableSound
.Create();
1880 killsnd
[3] := TPlayableSound
.Create();
1882 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1883 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1884 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1885 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1887 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1890 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1891 g_Weapon_LoadData();
1893 g_Monsters_LoadData();
1898 procedure g_Game_FreeData();
1900 if not DataLoaded
then Exit
;
1903 g_Weapon_FreeData();
1904 g_Monsters_FreeData();
1906 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1908 g_Texture_Delete('NOTEXTURE');
1909 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1910 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1911 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1912 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1913 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1914 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1915 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1916 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1917 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1918 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1919 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1920 g_Frames_DeleteByName('FRAMES_TELEPORT');
1921 g_Sound_Delete('SOUND_GAME_TELEPORT');
1922 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1923 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1924 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1925 g_Sound_Delete('SOUND_GAME_BULK1');
1926 g_Sound_Delete('SOUND_GAME_BULK2');
1927 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1928 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1929 g_Sound_Delete('SOUND_GAME_SWITCH1');
1930 g_Sound_Delete('SOUND_GAME_SWITCH0');
1937 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1938 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1939 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1940 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1947 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1948 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1949 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1950 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1952 DataLoaded
:= False;
1955 procedure DrawCustomStat();
1961 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1962 s1
, s2
, topstr
: String;
1964 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1967 if e_KeyPressed(IK_TAB
) then
1969 if not gStatsPressed
then
1971 gStatsOff
:= not gStatsOff
;
1972 gStatsPressed
:= True;
1976 gStatsPressed
:= False;
1980 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1981 w
:= (Length(s1
) * ww2
) div 2;
1982 x
:= gScreenWidth
div 2 - w
;
1984 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1988 if (gGameSettings
.GameMode
= GM_COOP
) then
1990 if gMissionFailed
then
1991 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1993 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1996 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1998 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1999 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2001 if g_Game_IsNet
then
2003 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2004 if not gChatShow
then
2005 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2006 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2009 if g_Game_IsClient
then
2010 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2012 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2013 if not gChatShow
then
2014 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2015 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2020 w
:= gScreenWidth
-x
*2;
2026 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2027 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2029 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2031 case CustomStat
.GameMode
of
2034 if gGameSettings
.MaxLives
= 0 then
2035 s1
:= _lc
[I_GAME_DM
]
2037 s1
:= _lc
[I_GAME_LMS
];
2041 if gGameSettings
.MaxLives
= 0 then
2042 s1
:= _lc
[I_GAME_TDM
]
2044 s1
:= _lc
[I_GAME_TLMS
];
2046 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2049 if gGameSettings
.MaxLives
= 0 then
2050 s1
:= _lc
[I_GAME_COOP
]
2052 s1
:= _lc
[I_GAME_SURV
];
2058 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2062 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2063 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2066 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2067 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2068 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2069 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2071 pc
:= Length(CustomStat
.PlayerStat
);
2072 if pc
= 0 then Exit
;
2074 if CustomStat
.GameMode
= GM_COOP
then
2076 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2078 s2
:= _lc
[I_GAME_MONSTERS
];
2079 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2080 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2082 s2
:= _lc
[I_GAME_SECRETS
];
2083 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2084 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2087 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2089 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2090 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2091 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2093 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2094 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2095 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2099 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2104 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2105 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2106 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2108 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2111 for t
:= TEAM_RED
to TEAM_BLUE
do
2113 if t
= TEAM_RED
then
2115 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2116 gStdFont
, 255, 0, 0, 1);
2117 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2118 gStdFont
, 255, 0, 0, 1);
2125 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2126 gStdFont
, 0, 0, 255, 1);
2127 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2128 gStdFont
, 0, 0, 255, 1);
2134 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2137 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2138 if CustomStat
.PlayerStat
[p
].Team
= t
then
2139 with CustomStat
.PlayerStat
[p
] do
2153 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2154 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2155 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2162 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2165 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2166 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2167 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2170 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2171 with CustomStat
.PlayerStat
[p
] do
2173 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2180 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2181 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2182 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2188 procedure DrawSingleStat();
2190 tm
, key_x
, val_x
, y
: Integer;
2194 procedure player_stat(n
: Integer);
2200 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2201 s2
:= Format(' %d', [gTotalMonsters
]);
2203 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2204 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2205 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2206 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2208 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2209 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2211 // "Kills-per-minute: ##.#":
2212 s1
:= _lc
[I_MENU_INTER_KPM
];
2214 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2216 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2217 s2
:= Format(' %.1f', [kpm
]);
2219 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2220 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2222 // "Secrets found: # / #":
2223 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2224 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2226 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2227 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2228 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2229 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2231 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2232 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2236 // "Level Complete":
2237 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2238 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2240 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2241 s1
:= _lc
[I_MENU_INTER_KPM
];
2242 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2245 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2247 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2248 val_x
:= key_x
+ w1
;
2251 tm
:= SingleStat
.GameTime
div 1000;
2252 s1
:= _lc
[I_MENU_INTER_TIME
];
2253 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2255 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2256 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2258 if SingleStat
.TwoPlayers
then
2261 s1
:= _lc
[I_MENU_PLAYER_1
];
2262 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2263 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2265 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2270 s1
:= _lc
[I_MENU_PLAYER_2
];
2271 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2272 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2274 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2280 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2286 procedure DrawLoadingStat();
2292 if Length(LoadingStat
.Msgs
) = 0 then
2295 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2296 yy
:= (gScreenHeight
div 3);
2297 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2298 xx
:= (gScreenWidth
div 3);
2301 for i
:= 0 to NextMsg
-1 do
2303 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2304 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2308 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2309 yy
:= yy
+ LOADING_INTERLINE
;
2313 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2315 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2317 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2318 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2321 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2322 ScaleSz
:= 16 div Scale
;
2323 // Ðàçìåðû ìèíè-êàðòû:
2324 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2325 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2327 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2329 if gWalls
<> nil then
2332 for a
:= 0 to High(gWalls
) do
2334 if PanelType
<> 0 then
2336 // Ëåâûé âåðõíèé óãîë:
2337 aX
:= X
div ScaleSz
;
2338 aY
:= Y
div ScaleSz
;
2340 aX2
:= max(Width
div ScaleSz
, 1);
2341 aY2
:= max(Height
div ScaleSz
, 1);
2342 // Ïðàâûé íèæíèé óãîë:
2343 aX2
:= aX
+ aX2
- 1;
2344 aY2
:= aY
+ aY2
- 1;
2347 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2348 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2349 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2353 if gSteps
<> nil then
2356 for a
:= 0 to High(gSteps
) do
2358 if PanelType
<> 0 then
2360 // Ëåâûé âåðõíèé óãîë:
2361 aX
:= X
div ScaleSz
;
2362 aY
:= Y
div ScaleSz
;
2364 aX2
:= max(Width
div ScaleSz
, 1);
2365 aY2
:= max(Height
div ScaleSz
, 1);
2366 // Ïðàâûé íèæíèé óãîë:
2367 aX2
:= aX
+ aX2
- 1;
2368 aY2
:= aY
+ aY2
- 1;
2370 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2373 if gLifts
<> nil then
2376 for a
:= 0 to High(gLifts
) do
2378 if PanelType
<> 0 then
2380 // Ëåâûé âåðõíèé óãîë:
2381 aX
:= X
div ScaleSz
;
2382 aY
:= Y
div ScaleSz
;
2384 aX2
:= max(Width
div ScaleSz
, 1);
2385 aY2
:= max(Height
div ScaleSz
, 1);
2386 // Ïðàâûé íèæíèé óãîë:
2387 aX2
:= aX
+ aX2
- 1;
2388 aY2
:= aY
+ aY2
- 1;
2391 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2392 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2393 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2394 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2398 if gWater
<> nil then
2401 for a
:= 0 to High(gWater
) do
2403 if PanelType
<> 0 then
2405 // Ëåâûé âåðõíèé óãîë:
2406 aX
:= X
div ScaleSz
;
2407 aY
:= Y
div ScaleSz
;
2409 aX2
:= max(Width
div ScaleSz
, 1);
2410 aY2
:= max(Height
div ScaleSz
, 1);
2411 // Ïðàâûé íèæíèé óãîë:
2412 aX2
:= aX
+ aX2
- 1;
2413 aY2
:= aY
+ aY2
- 1;
2415 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2418 if gAcid1
<> nil then
2420 // Ðèñóåì êèñëîòó 1:
2421 for a
:= 0 to High(gAcid1
) do
2423 if PanelType
<> 0 then
2425 // Ëåâûé âåðõíèé óãîë:
2426 aX
:= X
div ScaleSz
;
2427 aY
:= Y
div ScaleSz
;
2429 aX2
:= max(Width
div ScaleSz
, 1);
2430 aY2
:= max(Height
div ScaleSz
, 1);
2431 // Ïðàâûé íèæíèé óãîë:
2432 aX2
:= aX
+ aX2
- 1;
2433 aY2
:= aY
+ aY2
- 1;
2435 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2438 if gAcid2
<> nil then
2440 // Ðèñóåì êèñëîòó 2:
2441 for a
:= 0 to High(gAcid2
) do
2443 if PanelType
<> 0 then
2445 // Ëåâûé âåðõíèé óãîë:
2446 aX
:= X
div ScaleSz
;
2447 aY
:= Y
div ScaleSz
;
2449 aX2
:= max(Width
div ScaleSz
, 1);
2450 aY2
:= max(Height
div ScaleSz
, 1);
2451 // Ïðàâûé íèæíèé óãîë:
2452 aX2
:= aX
+ aX2
- 1;
2453 aY2
:= aY
+ aY2
- 1;
2455 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2458 if gPlayers
<> nil then
2461 for a
:= 0 to High(gPlayers
) do
2462 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2464 // Ëåâûé âåðõíèé óãîë:
2465 aX
:= Obj
.X
div ScaleSz
+ 1;
2466 aY
:= Obj
.Y
div ScaleSz
+ 1;
2468 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2469 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2470 // Ïðàâûé íèæíèé óãîë:
2471 aX2
:= aX
+ aX2
- 1;
2472 aY2
:= aY
+ aY2
- 1;
2474 if gPlayers
[a
] = p
then
2475 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2478 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2479 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2480 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2484 if gMonsters
<> nil then
2487 for a
:= 0 to High(gMonsters
) do
2488 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2490 // Ëåâûé âåðõíèé óãîë:
2491 aX
:= Obj
.X
div ScaleSz
+ 1;
2492 aY
:= Obj
.Y
div ScaleSz
+ 1;
2494 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2495 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2496 // Ïðàâûé íèæíèé óãîë:
2497 aX2
:= aX
+ aX2
- 1;
2498 aY2
:= aY
+ aY2
- 1;
2500 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2506 procedure DrawMapView(x
, y
, w
, h
: Integer);
2512 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2513 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2514 g_Map_DrawBack(-bx
, -by
);
2521 glTranslatef(-x
, -y
, 0);
2523 g_Map_DrawPanels(PANEL_BACK
);
2524 g_Map_DrawPanels(PANEL_STEP
);
2527 g_Player_DrawShells();
2529 g_Player_DrawCorpses();
2530 g_Map_DrawPanels(PANEL_WALL
);
2532 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2535 g_Map_DrawPanels(PANEL_ACID1
);
2536 g_Map_DrawPanels(PANEL_ACID2
);
2537 g_Map_DrawPanels(PANEL_WATER
);
2538 g_Map_DrawPanels(PANEL_FORE
);
2539 if g_debug_HealthBar
then
2541 g_Monsters_DrawHealth();
2542 g_Player_DrawHealth();
2548 procedure DrawPlayer(p
: TPlayer
);
2550 px
, py
, a
, b
, c
, d
: Integer;
2553 if (p
= nil) or (p
.FDummy
) then
2556 g_Map_DrawBack(0, 0);
2565 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2566 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2568 if px
> (gPlayerScreenSize
.X
div 2) then
2569 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2572 if py
> (gPlayerScreenSize
.Y
div 2) then
2573 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2576 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2577 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2578 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2579 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2580 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2582 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2585 if p
.IncCam
<> 0 then
2587 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2589 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2590 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2593 if py
< (gPlayerScreenSize
.Y
div 2) then
2595 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2596 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2599 if p
.IncCam
< 0 then
2600 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2602 p
.IncCam
:= p
.IncCam
+ 1;
2604 if p
.IncCam
> 0 then
2605 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2607 p
.IncCam
:= p
.IncCam
- 1;
2610 if (px
< gPlayerScreenSize
.X
div 2) or
2611 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2614 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2615 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2617 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2619 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2620 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2623 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2624 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2626 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2628 g_Map_DrawBack(-c
, -d
);
2631 sY
:= -(b
+p
.IncCam
);
2632 sWidth
:= gPlayerScreenSize
.X
;
2633 sHeight
:= gPlayerScreenSize
.Y
;
2635 glTranslatef(a
, b
+p
.IncCam
, 0);
2637 g_Map_DrawPanels(PANEL_BACK
);
2638 g_Map_DrawPanels(PANEL_STEP
);
2641 g_Player_DrawShells();
2643 g_Player_DrawCorpses();
2644 g_Map_DrawPanels(PANEL_WALL
);
2646 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2649 g_Map_DrawPanels(PANEL_ACID1
);
2650 g_Map_DrawPanels(PANEL_ACID2
);
2651 g_Map_DrawPanels(PANEL_WATER
);
2652 g_Map_DrawPanels(PANEL_FORE
);
2653 if g_debug_HealthBar
then
2655 g_Monsters_DrawHealth();
2656 g_Player_DrawHealth();
2659 if p
.FSpectator
then
2660 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2661 p
.GameY
+ PLAYER_RECT_CY
- 4,
2662 'X', gStdFont
, 255, 255, 255, 1, True);
2664 for a := 0 to High(gCollideMap) do
2665 for b := 0 to High(gCollideMap[a]) do
2668 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2670 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2674 1: e_DrawPoint(1, b, a, 200, 200, 200);
2675 2: e_DrawPoint(1, b, a, 64, 64, 255);
2676 3: e_DrawPoint(1, b, a, 255, 0, 255);
2686 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2687 if g_Debug_Player
then
2688 g_Player_DrawDebug(p
);
2692 procedure g_Game_Draw();
2699 plView1
, plView2
: TPlayer
;
2702 if gExit
= EXIT_QUIT
then Exit
;
2704 Time
:= GetTimer() {div 1000};
2705 FPSCounter
:= FPSCounter
+1;
2706 if Time
- FPSTime
>= 1000 then
2713 if gGameOn
or (gState
= STATE_FOLD
) then
2715 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2717 gSpectMode
:= SPECT_NONE
;
2718 if not gRevertPlayers
then
2720 plView1
:= gPlayer1
;
2721 plView2
:= gPlayer2
;
2725 plView1
:= gPlayer2
;
2726 plView2
:= gPlayer1
;
2730 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2732 gSpectMode
:= SPECT_NONE
;
2733 if gPlayer2
= nil then
2736 plView1
:= gPlayer2
;
2745 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2746 gSpectMode
:= SPECT_STATS
;
2748 if gSpectMode
= SPECT_PLAYERS
then
2749 if gPlayers
<> nil then
2751 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2752 if plView1
= nil then
2754 gSpectPID1
:= GetActivePlayerID_Next();
2755 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2757 if gSpectViewTwo
then
2759 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2760 if plView2
= nil then
2762 gSpectPID2
:= GetActivePlayerID_Next();
2763 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2768 if gSpectMode
= SPECT_MAPVIEW
then
2770 // Ðåæèì ïðîñìîòðà êàðòû
2772 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2773 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2774 gHearPoint1
.Active
:= True;
2775 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2776 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2777 gHearPoint2
.Active
:= False;
2781 Split
:= (plView1
<> nil) and (plView2
<> nil);
2783 // Òî÷êè ñëóõà èãðîêîâ
2784 if plView1
<> nil then
2786 gHearPoint1
.Active
:= True;
2787 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2788 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2790 gHearPoint1
.Active
:= False;
2791 if plView2
<> nil then
2793 gHearPoint2
.Active
:= True;
2794 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2795 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2797 gHearPoint2
.Active
:= False;
2799 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2800 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2803 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2804 if gScreenHeight
mod 2 = 0 then
2805 Dec(gPlayerScreenSize
.Y
);
2808 gPlayerScreenSize
.Y
:= gScreenHeight
;
2811 if gScreenHeight
mod 2 = 0 then
2812 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2814 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2816 DrawPlayer(plView1
);
2817 gPlayer1ScreenCoord
.X
:= sX
;
2818 gPlayer1ScreenCoord
.Y
:= sY
;
2822 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2824 DrawPlayer(plView2
);
2825 gPlayer2ScreenCoord
.X
:= sX
;
2826 gPlayer2ScreenCoord
.Y
:= sY
;
2829 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2832 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2835 if MessageText
<> '' then
2839 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2841 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2842 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2844 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2845 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2848 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2850 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2852 // Draw spectator GUI
2855 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2858 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2860 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2862 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2864 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2865 if gSpectMode
= SPECT_MAPVIEW
then
2867 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2868 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2869 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2870 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2871 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2873 if gSpectMode
= SPECT_PLAYERS
then
2875 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2876 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2877 if gSpectViewTwo
then
2879 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2880 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2881 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2882 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2886 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2887 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2893 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2895 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2897 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2898 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2899 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2904 if (gState
= STATE_MENU
) then
2906 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2908 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2909 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2910 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2912 if g_ActiveWindow
<> nil then
2913 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2916 if gState
= STATE_FOLD
then
2917 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2919 if gState
= STATE_INTERCUSTOM
then
2921 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2923 back
:= 'TEXTURE_endpic';
2924 if not g_Texture_Get(back
, ID
) then
2925 back
:= _lc
[I_TEXTURE_ENDPIC
];
2930 if g_Texture_Get(back
, ID
) then
2931 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2933 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2937 if g_ActiveWindow
<> nil then
2938 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2941 if gState
= STATE_INTERSINGLE
then
2943 if EndingGameCounter
> 0 then
2944 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2949 if g_Texture_Get(back
, ID
) then
2950 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2952 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2956 if g_ActiveWindow
<> nil then
2957 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2961 if gState
= STATE_ENDPIC
then
2964 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2965 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2967 if ID
<> DWORD(-1) then
2968 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2970 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2972 if g_ActiveWindow
<> nil then
2973 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2976 if gState
= STATE_SLIST
then
2978 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2980 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2981 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2983 g_Serverlist_Draw(slCurrent
);
2987 if g_ActiveWindow
<> nil then
2990 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2991 g_ActiveWindow
.Draw();
2996 if g_debug_Sounds
and gGameOn
then
2998 for w
:= 0 to High(e_SoundsArray
) do
2999 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3000 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3005 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3006 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3009 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3010 e_TextureFontPrint(gScreenWidth
-72, 0,
3011 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3015 procedure g_Game_Quit();
3017 g_Game_StopAllSounds(True);
3019 g_Game_SaveOptions();
3021 g_PlayerModel_FreeData();
3022 g_Texture_DeleteAll();
3023 g_Frames_DeleteAll();
3026 if NetInitDone
then g_Net_Free
;
3028 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3029 if gMapToDelete
<> '' then
3030 g_Game_DeleteTestMap();
3036 procedure g_FatalError(Text: String);
3038 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3039 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3041 gExit
:= EXIT_SIMPLE
;
3044 procedure g_SimpleError(Text: String);
3046 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3047 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3050 procedure g_Game_SetupScreenSize();
3054 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3055 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3056 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3057 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3059 gPlayerScreenSize
.Y
:= gScreenHeight
;
3061 // Ðàçìåð çàäíåãî ïëàíà:
3062 if BackID
<> DWORD(-1) then
3066 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3067 (gScreenHeight
*d
> gMapInfo
.Height
) then
3070 gBackSize
.X
:= Round(gScreenWidth
*d
);
3071 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3075 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3077 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3080 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3082 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3083 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3085 if gPlayer1
= nil then
3087 if g_Game_IsClient
then
3089 if NetPlrUID1
> -1 then
3091 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3092 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3097 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3098 Team
:= gPlayer1Settings
.Team
;
3100 // Ñîçäàíèå ïåðâîãî èãðîêà:
3101 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3102 gPlayer1Settings
.Color
,
3104 if gPlayer1
= nil then
3105 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3108 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3109 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3110 if g_Game_IsServer
and g_Game_IsNet
then
3111 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3112 gPlayer1
.Respawn(False, True);
3114 if g_Game_IsNet
and NetUseMaster
then
3120 if gPlayer2
= nil then
3122 if g_Game_IsClient
then
3124 if NetPlrUID2
> -1 then
3125 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3129 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3130 Team
:= gPlayer2Settings
.Team
;
3132 // Ñîçäàíèå âòîðîãî èãðîêà:
3133 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3134 gPlayer2Settings
.Color
,
3136 if gPlayer2
= nil then
3137 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3140 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3141 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3142 if g_Game_IsServer
and g_Game_IsNet
then
3143 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3144 gPlayer2
.Respawn(False, True);
3146 if g_Game_IsNet
and NetUseMaster
then
3154 procedure g_Game_RemovePlayer();
3158 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3159 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3164 if g_Game_IsServer
then
3167 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3168 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3169 g_Player_Remove(Pl
.UID
);
3171 if g_Game_IsNet
and NetUseMaster
then
3180 if g_Game_IsServer
then
3183 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3184 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3185 g_Player_Remove(Pl
.UID
);
3187 if g_Game_IsNet
and NetUseMaster
then
3192 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3198 procedure g_Game_Spectate();
3200 g_Game_RemovePlayer();
3201 if gPlayer1
<> nil then
3202 g_Game_RemovePlayer();
3205 procedure g_Game_SpectateCenterView();
3207 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3208 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3211 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3217 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3219 g_Game_ClearLoading();
3222 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3225 gGameSettings
.GameType
:= GT_SINGLE
;
3226 gGameSettings
.MaxLives
:= 0;
3227 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3228 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3229 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3230 gSwitchGameMode
:= GM_SINGLE
;
3232 g_Game_ExecuteEvent('ongamestart');
3234 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3235 g_Game_SetupScreenSize();
3237 // Ñîçäàíèå ïåðâîãî èãðîêà:
3238 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3239 gPlayer1Settings
.Color
,
3240 gPlayer1Settings
.Team
, False));
3241 if gPlayer1
= nil then
3243 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3247 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3250 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3253 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3254 gPlayer2Settings
.Color
,
3255 gPlayer2Settings
.Team
, False));
3256 if gPlayer2
= nil then
3258 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3262 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3266 // Çàãðóçêà è çàïóñê êàðòû:
3267 if not g_Game_StartMap(MAP
, True) then
3269 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3273 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3277 for i
:= nPl
+1 to nPlayers
do
3278 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3281 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3282 TimeLimit
, GoalLimit
: Word;
3284 Options
: LongWord; nPlayers
: Byte);
3290 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3292 g_Game_ClearLoading();
3295 gGameSettings
.GameType
:= GT_CUSTOM
;
3296 gGameSettings
.GameMode
:= GameMode
;
3297 gSwitchGameMode
:= GameMode
;
3298 gGameSettings
.TimeLimit
:= TimeLimit
;
3299 gGameSettings
.GoalLimit
:= GoalLimit
;
3300 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3301 gGameSettings
.Options
:= Options
;
3303 gCoopTotalMonstersKilled
:= 0;
3304 gCoopTotalSecretsFound
:= 0;
3305 gCoopTotalMonsters
:= 0;
3306 gCoopTotalSecrets
:= 0;
3310 g_Game_ExecuteEvent('ongamestart');
3312 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3313 g_Game_SetupScreenSize();
3315 // Ðåæèì íàáëþäàòåëÿ:
3316 if nPlayers
= 0 then
3323 if nPlayers
>= 1 then
3325 // Ñîçäàíèå ïåðâîãî èãðîêà:
3326 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3327 gPlayer1Settings
.Color
,
3328 gPlayer1Settings
.Team
, False));
3329 if gPlayer1
= nil then
3331 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3335 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3339 if nPlayers
>= 2 then
3341 // Ñîçäàíèå âòîðîãî èãðîêà:
3342 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3343 gPlayer2Settings
.Color
,
3344 gPlayer2Settings
.Team
, False));
3345 if gPlayer2
= nil then
3347 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3351 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3355 // Çàãðóçêà è çàïóñê êàðòû:
3356 if not g_Game_StartMap(Map
, True) then
3358 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3362 // Íåò òî÷åê ïîÿâëåíèÿ:
3363 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3364 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3365 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3366 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3367 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3369 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3373 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3377 for i
:= nPl
+1 to nPlayers
do
3378 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3381 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3382 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3383 Options
: LongWord; nPlayers
: Byte;
3384 IPAddr
: LongWord; Port
: Word);
3388 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3390 g_Game_ClearLoading();
3393 gGameSettings
.GameType
:= GT_SERVER
;
3394 gGameSettings
.GameMode
:= GameMode
;
3395 gSwitchGameMode
:= GameMode
;
3396 gGameSettings
.TimeLimit
:= TimeLimit
;
3397 gGameSettings
.GoalLimit
:= GoalLimit
;
3398 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3399 gGameSettings
.Options
:= Options
;
3401 gCoopTotalMonstersKilled
:= 0;
3402 gCoopTotalSecretsFound
:= 0;
3403 gCoopTotalMonsters
:= 0;
3404 gCoopTotalSecrets
:= 0;
3408 g_Game_ExecuteEvent('ongamestart');
3410 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3411 g_Game_SetupScreenSize();
3413 // Ðåæèì íàáëþäàòåëÿ:
3414 if nPlayers
= 0 then
3420 if nPlayers
>= 1 then
3422 // Ñîçäàíèå ïåðâîãî èãðîêà:
3423 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3424 gPlayer1Settings
.Color
,
3425 gPlayer1Settings
.Team
, False));
3426 if gPlayer1
= nil then
3428 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3432 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3435 if nPlayers
>= 2 then
3437 // Ñîçäàíèå âòîðîãî èãðîêà:
3438 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3439 gPlayer2Settings
.Color
,
3440 gPlayer2Settings
.Team
, False));
3441 if gPlayer2
= nil then
3443 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3447 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3451 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3453 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3457 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3459 // Çàãðóçêà è çàïóñê êàðòû:
3460 if not g_Game_StartMap(Map
, True) then
3462 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3466 // Íåò òî÷åê ïîÿâëåíèÿ:
3467 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3468 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3469 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3470 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3471 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3473 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3477 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3480 NetState
:= NET_STATE_GAME
;
3483 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3497 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3498 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3500 g_Game_ClearLoading();
3503 gGameSettings
.GameType
:= GT_CLIENT
;
3505 gCoopTotalMonstersKilled
:= 0;
3506 gCoopTotalSecretsFound
:= 0;
3507 gCoopTotalMonsters
:= 0;
3508 gCoopTotalSecrets
:= 0;
3512 g_Game_ExecuteEvent('ongamestart');
3514 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3515 g_Game_SetupScreenSize();
3517 NetState
:= NET_STATE_AUTH
;
3519 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3521 if not g_Net_Connect(Addr
, Port
) then
3523 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3524 NetState
:= NET_STATE_NONE
;
3528 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3530 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3535 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3537 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3539 Ptr
:= NetEvent
.packet
^.data
;
3542 MID
:= e_Raw_Read_Byte(Ptr
);
3544 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3546 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3547 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3549 WadName
:= e_Raw_Read_String(Ptr
);
3550 Map
:= e_Raw_Read_String(Ptr
);
3552 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3554 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3555 gSwitchGameMode
:= gGameSettings
.GameMode
;
3556 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3557 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3558 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3559 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3560 T
:= e_Raw_Read_LongWord(Ptr
);
3562 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3563 if newResPath
= '' then
3565 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3566 newResPath
:= g_Res_DownloadWAD(WadName
);
3567 if newResPath
= '' then
3569 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3570 enet_packet_destroy(NetEvent
.packet
);
3571 NetState
:= NET_STATE_NONE
;
3575 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3577 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3578 gPlayer1Settings
.Color
,
3579 gPlayer1Settings
.Team
, False));
3581 if gPlayer1
= nil then
3583 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3585 enet_packet_destroy(NetEvent
.packet
);
3586 NetState
:= NET_STATE_NONE
;
3590 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3591 gPlayer1
.UID
:= NetPlrUID1
;
3592 gPlayer1
.Reset(True);
3594 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3596 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3598 enet_packet_destroy(NetEvent
.packet
);
3599 NetState
:= NET_STATE_NONE
;
3607 enet_packet_destroy(NetEvent
.packet
);
3611 enet_packet_destroy(NetEvent
.packet
);
3614 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3617 if (NetEvent
.data
<= NET_DISC_MAX
) then
3618 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3619 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3629 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3638 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3639 NetState
:= NET_STATE_NONE
;
3643 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3644 gLMSRespawnTime
:= 0;
3647 NetState
:= NET_STATE_GAME
;
3648 MC_SEND_FullStateRequest
;
3649 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3652 procedure g_Game_SaveOptions();
3654 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3657 procedure g_Game_ChangeMap(MapPath
: String);
3661 g_Game_ClearLoading();
3663 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3664 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3665 if gExitByTrigger
then
3668 gExitByTrigger
:= False;
3670 if not g_Game_StartMap(MapPath
, Force
) then
3671 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3674 procedure g_Game_Restart();
3678 if g_Game_IsClient
then
3680 map
:= g_ExtractFileName(gMapInfo
.Map
);
3684 g_Game_ClearLoading();
3685 g_Game_StartMap(Map
, True);
3688 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3690 NewWAD
, ResName
: String;
3694 g_Player_RemoveAllCorpses();
3696 if (not g_Game_IsClient
) and
3697 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3698 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3700 if gSwitchGameMode
= GM_CTF
then
3701 gGameSettings
.MaxLives
:= 0;
3702 gGameSettings
.GameMode
:= gSwitchGameMode
;
3705 gSwitchGameMode
:= gGameSettings
.GameMode
;
3707 g_Player_ResetTeams();
3709 if Pos(':\', Map
) > 0 then
3711 NewWAD
:= g_ExtractWadName(Map
);
3712 ResName
:= g_ExtractFileName(Map
);
3713 if g_Game_IsServer
then
3715 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3716 g_Game_LoadWAD(NewWAD
);
3718 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3719 g_Game_ClientWAD(NewWAD
, gWADHash
);
3723 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3726 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3728 gState
:= STATE_NONE
;
3729 g_ActiveWindow
:= nil;
3735 if gGameSettings
.GameMode
= GM_CTF
then
3737 g_Map_ResetFlag(FLAG_RED
);
3738 g_Map_ResetFlag(FLAG_BLUE
);
3739 // CTF, à ôëàãîâ íåò:
3740 if not g_Map_HaveFlagPoints() then
3741 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3746 gState
:= STATE_MENU
;
3753 NetTimeToUpdate
:= 1;
3754 NetTimeToReliable
:= 0;
3755 NetTimeToMaster
:= NetMasterRate
;
3756 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3757 gLMSRespawnTime
:= 0;
3758 gMissionFailed
:= False;
3761 gCoopMonstersKilled
:= 0;
3762 gCoopSecretsFound
:= 0;
3764 gVoteInProgress
:= False;
3765 gVotePassed
:= False;
3771 if not gGameOn
then Exit
;
3773 g_Game_SpectateCenterView();
3775 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3777 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3778 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3779 gLMSSoftSpawn
:= True;
3780 if NetMode
= NET_SERVER
then
3781 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3783 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3786 if NetMode
= NET_SERVER
then
3788 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3791 if NetUseMaster
then
3793 if (NetMHost
= nil) or (NetMPeer
= nil) then
3794 if not g_Net_Slist_Connect
then
3795 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3800 if NetClients
<> nil then
3801 for I
:= 0 to High(NetClients
) do
3802 if NetClients
[I
].Used
then
3804 NetClients
[I
].Voted
:= False;
3805 if NetClients
[I
].RequestedFullUpdate
then
3807 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3808 NetClients
[I
].RequestedFullUpdate
:= False;
3812 g_Net_UnbanNonPermHosts();
3817 gCoopTotalMonstersKilled
:= 0;
3818 gCoopTotalSecretsFound
:= 0;
3819 gCoopTotalMonsters
:= 0;
3820 gCoopTotalSecrets
:= 0;
3824 g_Game_ExecuteEvent('onmapstart');
3827 procedure SetFirstLevel();
3831 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3832 if MapList
= nil then
3835 SortSArray(MapList
);
3836 gNextMap
:= MapList
[Low(MapList
)];
3841 procedure g_Game_ExitLevel(Map
: Char16
);
3845 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3846 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3847 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3848 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3850 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3851 if gGameSettings
.GameType
= GT_SINGLE
then
3852 gExit
:= EXIT_ENDLEVELSINGLE
3853 else // Âûøëè â âûõîä â Ñâîåé èãðå
3855 gExit
:= EXIT_ENDLEVELCUSTOM
;
3856 if gGameSettings
.GameMode
= GM_COOP
then
3857 g_Player_RememberAll
;
3859 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3862 if gGameSettings
.GameMode
= GM_COOP
then
3865 gStatsPressed
:= True;
3866 gNextMap
:= 'MAP01';
3868 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3871 if g_Game_IsNet
then
3873 MH_SEND_GameStats();
3874 MH_SEND_CoopStats();
3880 procedure g_Game_RestartLevel();
3884 if gGameSettings
.GameMode
= GM_SINGLE
then
3889 gExit
:= EXIT_ENDLEVELCUSTOM
;
3890 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3894 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3898 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3900 if not g_Game_IsClient
then
3902 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3905 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3906 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3910 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3914 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3915 g_Game_LoadWAD(NewWAD
);
3918 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3920 i
, n
, nb
, nr
: Integer;
3922 if not g_Game_IsServer
then Exit
;
3923 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3924 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3925 gLMSRespawnTime
:= 0;
3928 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3930 gMissionFailed
:= True;
3931 g_Game_RestartLevel
;
3935 n
:= 0; nb
:= 0; nr
:= 0;
3936 for i
:= Low(gPlayers
) to High(gPlayers
) do
3937 if (gPlayers
[i
] <> nil) and
3938 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3939 (gPlayers
[i
] is TBot
)) then
3942 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3943 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3946 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3948 // wait a second until the fuckers finally decide to join
3949 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3950 gLMSRespawnTime
:= gTime
+ 1000;
3951 gLMSSoftSpawn
:= NoMapRestart
;
3955 g_Player_RemoveAllCorpses
;
3956 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3957 if g_Game_IsNet
then
3958 MH_SEND_GameEvent(NET_EV_LMS_START
);
3960 for i
:= Low(gPlayers
) to High(gPlayers
) do
3962 if gPlayers
[i
] = nil then continue
;
3963 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3964 // don't touch normal spectators
3965 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3967 gPlayers
[i
].FNoRespawn
:= True;
3968 gPlayers
[i
].Lives
:= 0;
3969 if g_Game_IsNet
then
3970 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3973 gPlayers
[i
].FNoRespawn
:= False;
3974 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3975 gPlayers
[i
].Respawn(False, True);
3976 if gGameSettings
.GameMode
= GM_COOP
then
3978 gPlayers
[i
].Frags
:= 0;
3979 gPlayers
[i
].RecallState
;
3981 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3982 gPlayer1
:= g_Player_Get(gLMSPID1
);
3983 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3984 gPlayer2
:= g_Player_Get(gLMSPID2
);
3987 for i
:= Low(gItems
) to High(gItems
) do
3989 if gItems
[i
].Respawnable
then
3991 gItems
[i
].QuietRespawn
:= True;
3992 gItems
[i
].RespawnTime
:= 0;
3997 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
4001 for i
:= Low(gMonsters
) to High(gMonsters
) do
4003 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
4004 gMonsters
[i
].Respawn
;
4007 gLMSSoftSpawn
:= False;
4010 function g_Game_GetFirstMap(WAD
: String): String;
4014 MapList
:= g_Map_GetMapsList(WAD
);
4015 if MapList
= nil then
4018 SortSArray(MapList
);
4019 Result
:= MapList
[Low(MapList
)];
4021 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4027 function g_Game_GetNextMap(): String;
4034 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4035 if MapList
= nil then
4038 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4040 SortSArray(MapList
);
4042 for I
:= Low(MapList
) to High(MapList
) do
4043 if Map
= MapList
[I
] then
4049 if MapIndex
<> -255 then
4051 if MapIndex
= High(MapList
) then
4052 Result
:= MapList
[Low(MapList
)]
4054 Result
:= MapList
[MapIndex
+ 1];
4056 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4062 procedure g_Game_NextLevel();
4064 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4065 gExit
:= EXIT_ENDLEVELCUSTOM
4068 gExit
:= EXIT_ENDLEVELSINGLE
;
4072 if gNextMap
<> '' then Exit
;
4073 gNextMap
:= g_Game_GetNextMap();
4076 function g_Game_IsTestMap(): Boolean;
4078 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4081 procedure g_Game_DeleteTestMap();
4092 a
:= Pos('.wad:\', gMapToDelete
);
4096 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4097 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4098 Delete(gMapToDelete
, 1, a
+ 5);
4099 gMapToDelete
:= UpperCase(gMapToDelete
);
4101 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4104 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4105 if MapName <> TEST_MAP_NAME then
4108 if not gTempDelete then
4110 time := g_GetFileTime(WadName);
4111 WAD := TWADFile.Create();
4114 if not WAD.ReadFile(WadName) then
4115 begin // Íåò òàêîãî WAD-ôàéëà
4120 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4122 MapList := WAD.GetResourcesList('');
4124 if MapList <> nil then
4125 for a := 0 to High(MapList) do
4126 if MapList[a] = MapName then
4128 // Óäàëÿåì è ñîõðàíÿåì:
4129 WAD.RemoveResource('', MapName);
4130 WAD.SaveTo(WadName);
4135 g_SetFileTime(WadName, time);
4138 if gTempDelete
then DeleteFile(WadName
);
4141 procedure GameCVars(P
: SArray
);
4144 stat
: TPlayerStatArray
;
4149 cmd
:= LowerCase(P
[0]);
4150 if cmd
= 'r_showfps' then
4152 if (Length(P
) > 1) and
4153 ((P
[1] = '1') or (P
[1] = '0')) then
4154 gShowFPS
:= (P
[1][1] = '1');
4157 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4159 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4161 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4163 with gGameSettings
do
4165 if (Length(P
) > 1) and
4166 ((P
[1] = '1') or (P
[1] = '0')) then
4168 if (P
[1][1] = '1') then
4169 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4171 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4174 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4175 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4177 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4179 if g_Game_IsNet
then MH_SEND_GameSettings
;
4182 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4184 with gGameSettings
do
4186 if (Length(P
) > 1) and
4187 ((P
[1] = '1') or (P
[1] = '0')) then
4189 if (P
[1][1] = '1') then
4190 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4192 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4195 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4196 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4198 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4200 if g_Game_IsNet
then MH_SEND_GameSettings
;
4203 else if cmd
= 'g_gamemode' then
4205 a
:= g_Game_TextToMode(P
[1]);
4206 if a
= GM_SINGLE
then a
:= GM_COOP
;
4207 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4209 gSwitchGameMode
:= a
;
4210 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4211 (gState
= STATE_INTERSINGLE
) then
4212 gSwitchGameMode
:= GM_SINGLE
;
4214 gGameSettings
.GameMode
:= gSwitchGameMode
;
4216 if gSwitchGameMode
= gGameSettings
.GameMode
then
4217 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4218 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4220 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4221 [g_Game_ModeToText(gGameSettings
.GameMode
),
4222 g_Game_ModeToText(gSwitchGameMode
)]));
4224 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4226 with gGameSettings
do
4228 if (Length(P
) > 1) and
4229 ((P
[1] = '1') or (P
[1] = '0')) then
4231 if (P
[1][1] = '1') then
4232 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4234 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4237 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4238 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4240 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4241 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4243 if g_Game_IsNet
then MH_SEND_GameSettings
;
4246 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4248 with gGameSettings
do
4250 if (Length(P
) > 1) and
4251 ((P
[1] = '1') or (P
[1] = '0')) then
4253 if (P
[1][1] = '1') then
4254 Options
:= Options
or GAME_OPTION_MONSTERS
4256 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4259 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4260 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4262 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4263 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4265 if g_Game_IsNet
then MH_SEND_GameSettings
;
4268 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4270 with gGameSettings
do
4272 if (Length(P
) > 1) and
4273 ((P
[1] = '1') or (P
[1] = '0')) then
4275 if (P
[1][1] = '1') then
4276 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4278 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4281 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4282 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4284 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4286 if g_Game_IsNet
then MH_SEND_GameSettings
;
4289 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4291 with gGameSettings
do
4293 if (Length(P
) > 1) and
4294 ((P
[1] = '1') or (P
[1] = '0')) then
4296 if (P
[1][1] = '1') then
4297 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4299 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4302 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4303 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4305 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4307 if g_Game_IsNet
then MH_SEND_GameSettings
;
4310 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4312 if Length(P
) > 1 then
4314 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4315 gGameSettings
.WarmupTime
:= 30
4317 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4320 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4321 [gGameSettings
.WarmupTime
]));
4322 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4324 else if cmd
= 'net_interp' then
4326 if (Length(P
) > 1) then
4327 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4329 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4330 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4331 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4332 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4335 else if cmd
= 'net_forceplayerupdate' then
4337 if (Length(P
) > 1) and
4338 ((P
[1] = '1') or (P
[1] = '0')) then
4339 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4341 if NetForcePlayerUpdate
then
4342 g_Console_Add('net_forceplayerupdate = 1')
4344 g_Console_Add('net_forceplayerupdate = 0');
4345 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4346 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4347 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4350 else if cmd
= 'net_predictself' then
4352 if (Length(P
) > 1) and
4353 ((P
[1] = '1') or (P
[1] = '0')) then
4354 NetPredictSelf
:= (P
[1][1] = '1');
4356 if NetPredictSelf
then
4357 g_Console_Add('net_predictself = 1')
4359 g_Console_Add('net_predictself = 0');
4360 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4361 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4362 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4365 else if cmd
= 'sv_name' then
4367 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4369 NetServerName
:= P
[1];
4370 if Length(NetServerName
) > 64 then
4371 SetLength(NetServerName
, 64);
4372 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4376 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4378 else if cmd
= 'sv_passwd' then
4380 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4382 NetPassword
:= P
[1];
4383 if Length(NetPassword
) > 24 then
4384 SetLength(NetPassword
, 24);
4385 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4389 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4391 else if cmd
= 'sv_maxplrs' then
4393 if (Length(P
) > 1) then
4395 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4396 if g_Game_IsServer
and g_Game_IsNet
then
4399 for a
:= 0 to High(NetClients
) do
4400 if NetClients
[a
].Used
then
4403 if b
> NetMaxClients
then
4405 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4406 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4407 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4408 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4411 if NetUseMaster
then
4416 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4418 else if cmd
= 'sv_public' then
4420 if (Length(P
) > 1) then
4422 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4423 if g_Game_IsServer
and g_Game_IsNet
then
4424 if NetUseMaster
then
4426 if NetMPeer
= nil then
4427 if not g_Net_Slist_Connect() then
4428 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4429 g_Net_Slist_Update();
4432 if NetMPeer
<> nil then
4433 g_Net_Slist_Disconnect();
4436 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4438 else if cmd
= 'sv_intertime' then
4440 if (Length(P
) > 1) then
4441 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4443 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4445 else if cmd
= 'p1_name' then
4447 if (Length(P
) > 1) and gGameOn
then
4449 if g_Game_IsClient
then
4451 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4452 MC_SEND_PlayerSettings
;
4455 if gPlayer1
<> nil then
4457 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4458 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4461 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4464 else if cmd
= 'p2_name' then
4466 if (Length(P
) > 1) and gGameOn
then
4468 if g_Game_IsClient
then
4470 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4471 MC_SEND_PlayerSettings
;
4474 if gPlayer2
<> nil then
4476 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4477 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4480 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4483 else if cmd
= 'p1_color' then
4485 if Length(P
) > 3 then
4486 if g_Game_IsClient
then
4488 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4489 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4490 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4491 MC_SEND_PlayerSettings
;
4494 if gPlayer1
<> nil then
4496 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4497 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4498 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4499 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4502 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4503 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4504 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4506 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4508 if Length(P
) > 3 then
4509 if g_Game_IsClient
then
4511 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4512 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4513 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4514 MC_SEND_PlayerSettings
;
4517 if gPlayer2
<> nil then
4519 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4520 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4521 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4522 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4525 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4526 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4527 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4529 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4531 if cmd
= 'r_showtime' then
4533 if (Length(P
) > 1) and
4534 ((P
[1] = '1') or (P
[1] = '0')) then
4535 gShowTime
:= (P
[1][1] = '1');
4538 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4540 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4542 else if cmd
= 'r_showscore' then
4544 if (Length(P
) > 1) and
4545 ((P
[1] = '1') or (P
[1] = '0')) then
4546 gShowGoals
:= (P
[1][1] = '1');
4549 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4551 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4553 else if cmd
= 'r_showstat' then
4555 if (Length(P
) > 1) and
4556 ((P
[1] = '1') or (P
[1] = '0')) then
4557 gShowStat
:= (P
[1][1] = '1');
4560 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4562 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4564 else if cmd
= 'r_showkillmsg' then
4566 if (Length(P
) > 1) and
4567 ((P
[1] = '1') or (P
[1] = '0')) then
4568 gShowKillMsg
:= (P
[1][1] = '1');
4570 if gShowKillMsg
then
4571 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4573 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4575 else if cmd
= 'r_showlives' then
4577 if (Length(P
) > 1) and
4578 ((P
[1] = '1') or (P
[1] = '0')) then
4579 gShowLives
:= (P
[1][1] = '1');
4582 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4584 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4586 else if cmd
= 'r_showspect' then
4588 if (Length(P
) > 1) and
4589 ((P
[1] = '1') or (P
[1] = '0')) then
4590 gSpectHUD
:= (P
[1][1] = '1');
4593 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4595 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4597 else if cmd
= 'r_showping' then
4599 if (Length(P
) > 1) and
4600 ((P
[1] = '1') or (P
[1] = '0')) then
4601 gShowPing
:= (P
[1][1] = '1');
4604 g_Console_Add(_lc
[I_MSG_PING_ON
])
4606 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4608 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4610 if Length(P
) > 1 then
4612 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4613 gGameSettings
.GoalLimit
:= 0
4618 if gGameSettings
.GameMode
= GM_DM
then
4620 stat
:= g_Player_GetStats();
4622 for a
:= 0 to High(stat
) do
4623 if stat
[a
].Frags
> b
then
4627 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4629 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4632 if g_Game_IsNet
then MH_SEND_GameSettings
;
4635 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4637 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4639 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4640 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4642 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4643 [gGameSettings
.TimeLimit
div 3600,
4644 (gGameSettings
.TimeLimit
div 60) mod 60,
4645 gGameSettings
.TimeLimit
mod 60]));
4646 if g_Game_IsNet
then MH_SEND_GameSettings
;
4648 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4650 if Length(P
) > 1 then
4652 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4653 gGameSettings
.MaxLives
:= 0
4657 stat
:= g_Player_GetStats();
4659 for a
:= 0 to High(stat
) do
4660 if stat
[a
].Lives
> b
then
4662 gGameSettings
.MaxLives
:=
4663 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4667 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4668 [gGameSettings
.MaxLives
]));
4669 if g_Game_IsNet
then MH_SEND_GameSettings
;
4674 procedure DebugCommands(P
: SArray
);
4680 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4683 cmd
:= LowerCase(P
[0]);
4684 if cmd
= 'd_window' then
4686 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4687 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4688 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4689 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4690 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4692 else if cmd
= 'd_sounds' then
4694 if (Length(P
) > 1) and
4695 ((P
[1] = '1') or (P
[1] = '0')) then
4696 g_Debug_Sounds
:= (P
[1][1] = '1');
4698 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4700 else if cmd
= 'd_frames' then
4702 if (Length(P
) > 1) and
4703 ((P
[1] = '1') or (P
[1] = '0')) then
4704 g_Debug_Frames
:= (P
[1][1] = '1');
4706 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4708 else if cmd
= 'd_winmsg' then
4710 if (Length(P
) > 1) and
4711 ((P
[1] = '1') or (P
[1] = '0')) then
4712 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4714 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4716 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4718 if (Length(P
) > 1) and
4719 ((P
[1] = '1') or (P
[1] = '0')) then
4720 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4722 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4724 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4726 if Length(P
) > 1 then
4728 '0': g_debug_BotAIOff
:= 0;
4729 '1': g_debug_BotAIOff
:= 1;
4730 '2': g_debug_BotAIOff
:= 2;
4731 '3': g_debug_BotAIOff
:= 3;
4734 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4736 else if cmd
= 'd_monster' then
4738 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4739 if Length(P
) < 2 then
4741 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4742 g_Console_Add('ID | Name');
4743 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4744 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4747 a
:= StrToIntDef(P
[1], 0);
4748 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4749 a
:= g_Monsters_GetIDByName(P
[1]);
4751 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4752 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4755 with gPlayer1
.Obj
do
4756 b
:= g_Monsters_Create(a
,
4757 X
+ Rect
.X
+ (Rect
.Width
div 2),
4758 Y
+ Rect
.Y
+ Rect
.Height
,
4759 gPlayer1
.Direction
, True);
4760 if (Length(P
) > 2) and (b
>= 0) then
4761 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4765 else if (cmd
= 'd_health') then
4767 if (Length(P
) > 1) and
4768 ((P
[1] = '1') or (P
[1] = '0')) then
4769 g_debug_HealthBar
:= (P
[1][1] = '1');
4771 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4773 else if (cmd
= 'd_player') then
4775 if (Length(P
) > 1) and
4776 ((P
[1] = '1') or (P
[1] = '0')) then
4777 g_debug_Player
:= (P
[1][1] = '1');
4779 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4781 else if (cmd
= 'd_joy') then
4784 g_Console_Add(e_JoystickStateToString(a
));
4788 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4792 procedure GameCheats(P
: SArray
);
4798 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4799 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4801 g_Console_Add('not available');
4807 g_Console_Add('where is the player?!');
4810 cmd
:= LowerCase(P
[0]);
4814 plr
.GodMode
:= not plr
.GodMode
;
4815 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4818 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4819 if cmd
= 'give' then
4821 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4822 for f
:= 1 to High(P
) do
4824 cmd
:= LowerCase(P
[f
]);
4825 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4826 if (cmd
= 'all') or (cmd
= 'weapons') then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4827 if cmd
= 'exit' then
4829 if gTriggers
<> nil then
4831 for a
:= 0 to High(gTriggers
) do
4833 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4835 g_Console_Add('player left the map');
4836 gExitByTrigger
:= True;
4837 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4844 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4845 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got jetpack'); continue
; end;
4846 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got envirosuit'); continue
; end;
4847 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got berserk pack'); continue
; end;
4848 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4853 if cmd
= 'open' then
4855 g_Console_Add('player activated sesame');
4856 g_Triggers_OpenAll();
4863 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4867 if cmd
= 'noclip' then
4870 g_Console_Add('wall hardeness adjusted');
4874 if cmd
= 'notarget' then
4876 plr
.NoTarget
:= not plr
.NoTarget
;
4877 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4881 if cmd
= 'noreload' then
4883 plr
.NoReload
:= not plr
.NoReload
;
4884 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4888 if cmd
= 'speedy' then
4890 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4891 g_Console_Add('speed adjusted');
4895 if cmd
= 'jumpy' then
4897 VEL_JUMP
:= 30-VEL_JUMP
;
4898 g_Console_Add('jump height adjusted');
4902 if cmd
= 'automap' then
4904 gShowMap
:= not gShowMap
;
4905 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4909 if cmd
= 'aimline' then
4911 gAimLine
:= not gAimLine
;
4912 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4917 procedure GameCommands(P
: SArray
);
4923 pl
: pTNetClient
= nil;
4930 cmd
:= LowerCase(P
[0]);
4932 if (cmd
= 'quit') or
4939 else if cmd
= 'pause' then
4941 if (g_ActiveWindow
= nil) then
4942 g_Game_Pause(not gPause
);
4944 else if cmd
= 'endgame' then
4945 gExit
:= EXIT_SIMPLE
4946 else if cmd
= 'restart' then
4948 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4950 if g_Game_IsClient
then
4952 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4957 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4959 else if cmd
= 'kick' then
4961 if g_Game_IsServer
then
4963 if Length(P
) < 2 then
4965 g_Console_Add('kick <name>');
4970 g_Console_Add('kick <name>');
4974 if g_Game_IsNet
then
4975 pl
:= g_Net_Client_ByName(P
[1]);
4978 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4979 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4980 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4981 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4982 if NetUseMaster
then
4984 end else if gPlayers
<> nil then
4985 for a
:= Low(gPlayers
) to High(gPlayers
) do
4986 if gPlayers
[a
] <> nil then
4987 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4989 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4990 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4992 gPlayers
[a
].Lives
:= 0;
4993 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4994 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4995 g_Player_Remove(gPlayers
[a
].UID
);
4996 if NetUseMaster
then
4998 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5002 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5004 else if cmd
= 'kick_id' then
5006 if g_Game_IsServer
and g_Game_IsNet
then
5008 if Length(P
) < 2 then
5010 g_Console_Add('kick_id <client ID>');
5015 g_Console_Add('kick_id <client ID>');
5019 a
:= StrToIntDef(P
[1], 0);
5020 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5022 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5024 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5025 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5026 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5027 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5028 if NetUseMaster
then
5033 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5035 else if cmd
= 'ban' then
5037 if g_Game_IsServer
and g_Game_IsNet
then
5039 if Length(P
) < 2 then
5041 g_Console_Add('ban <name>');
5046 g_Console_Add('ban <name>');
5050 pl
:= g_Net_Client_ByName(P
[1]);
5053 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5054 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5055 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5056 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5057 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5058 if NetUseMaster
then
5061 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5063 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5065 else if cmd
= 'ban_id' then
5067 if g_Game_IsServer
and g_Game_IsNet
then
5069 if Length(P
) < 2 then
5071 g_Console_Add('ban_id <client ID>');
5076 g_Console_Add('ban_id <client ID>');
5080 a
:= StrToIntDef(P
[1], 0);
5081 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5082 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5084 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5085 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5086 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5087 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5088 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5089 if NetUseMaster
then
5093 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5095 else if cmd
= 'permban' then
5097 if g_Game_IsServer
and g_Game_IsNet
then
5099 if Length(P
) < 2 then
5101 g_Console_Add('permban <name>');
5106 g_Console_Add('permban <name>');
5110 pl
:= g_Net_Client_ByName(P
[1]);
5113 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5114 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5115 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5116 g_Net_SaveBanList();
5117 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5118 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5119 if NetUseMaster
then
5122 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5124 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5126 else if cmd
= 'permban_id' then
5128 if g_Game_IsServer
and g_Game_IsNet
then
5130 if Length(P
) < 2 then
5132 g_Console_Add('permban_id <client ID>');
5137 g_Console_Add('permban_id <client ID>');
5141 a
:= StrToIntDef(P
[1], 0);
5142 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5143 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5145 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5146 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5147 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5148 g_Net_SaveBanList();
5149 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5150 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5151 if NetUseMaster
then
5155 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5157 else if cmd
= 'unban' then
5159 if g_Game_IsServer
and g_Game_IsNet
then
5161 if Length(P
) < 2 then
5163 g_Console_Add('unban <IP Address>');
5168 g_Console_Add('unban <IP Address>');
5172 if g_Net_UnbanHost(P
[1]) then
5174 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5175 g_Net_SaveBanList();
5177 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5179 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5181 else if cmd
= 'clientlist' then
5183 if g_Game_IsServer
and g_Game_IsNet
then
5186 if NetClients
<> nil then
5187 for a
:= Low(NetClients
) to High(NetClients
) do
5188 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5190 plr
:= g_Player_Get(NetClients
[a
].Player
);
5191 if plr
= nil then continue
;
5193 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5194 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5197 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5199 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5201 else if cmd
= 'connect' then
5203 if (NetMode
= NET_NONE
) then
5205 if Length(P
) < 2 then
5207 g_Console_Add('connect <IP> [port] [password]');
5212 g_Console_Add('connect <IP> [port] [password]');
5216 if Length(P
) > 2 then
5217 prt
:= StrToIntDef(P
[2], 25666)
5221 if Length(P
) > 3 then
5226 g_Game_StartClient(P
[1], prt
, pw
);
5229 else if cmd
= 'disconnect' then
5231 if (NetMode
= NET_CLIENT
) then
5234 else if cmd
= 'reconnect' then
5236 if (NetMode
= NET_SERVER
) then
5239 if (NetMode
= NET_CLIENT
) then
5242 gExit
:= EXIT_SIMPLE
;
5246 //TODO: Use last successful password to reconnect, instead of ''
5247 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5249 else if (cmd
= 'addbot') or
5250 (cmd
= 'bot_add') then
5252 if Length(P
) > 1 then
5253 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5255 g_Bot_Add(TEAM_NONE
, 2);
5257 else if cmd
= 'bot_addlist' then
5259 if Length(P
) > 1 then
5260 if Length(P
) = 2 then
5261 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5263 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5265 else if cmd
= 'bot_removeall' then
5267 else if cmd
= 'chat' then
5269 if g_Game_IsNet
then
5271 if Length(P
) > 1 then
5273 for a
:= 1 to High(P
) do
5274 chstr
:= chstr
+ P
[a
] + ' ';
5276 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5278 if Length(chstr
) < 1 then
5280 g_Console_Add('chat <text>');
5284 chstr
:= b_Text_Format(chstr
);
5285 if g_Game_IsClient
then
5286 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5288 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5291 g_Console_Add('chat <text>');
5293 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5295 else if cmd
= 'teamchat' then
5297 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5299 if Length(P
) > 1 then
5301 for a
:= 1 to High(P
) do
5302 chstr
:= chstr
+ P
[a
] + ' ';
5304 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5306 if Length(chstr
) < 1 then
5308 g_Console_Add('teamchat <text>');
5312 chstr
:= b_Text_Format(chstr
);
5313 if g_Game_IsClient
then
5314 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5316 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5317 gPlayer1Settings
.Team
);
5320 g_Console_Add('teamchat <text>');
5322 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5324 else if cmd
= 'game' then
5326 if gGameSettings
.GameType
<> GT_NONE
then
5328 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5331 if Length(P
) = 1 then
5333 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5336 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5337 P
[1] := addWadExtension(P
[1]);
5338 if FileExists(MapsDir
+ P
[1]) then
5340 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5341 if Length(P
) < 3 then
5344 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5347 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5349 if g_Map_Exist(MapsDir
+ s
) then
5351 // Çàïóñêàåì ñâîþ èãðó
5353 with gGameSettings
do
5355 GameMode
:= g_Game_TextToMode(gcGameMode
);
5356 if gSwitchGameMode
<> GM_NONE
then
5357 GameMode
:= gSwitchGameMode
;
5358 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5359 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5361 if Length(P
) >= 4 then
5362 b
:= StrToIntDef(P
[3], 1);
5363 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5364 GoalLimit
, MaxLives
, Options
, b
);
5369 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5371 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5373 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5375 else if cmd
= 'host' then
5377 if gGameSettings
.GameType
<> GT_NONE
then
5379 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5382 if Length(P
) < 4 then
5384 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5387 if not StrToIp(P
[1], listen
) then
5389 prt
:= StrToIntDef(P
[2], 25666);
5391 P
[3] := addWadExtension(P
[3]);
5392 if FileExists(MapsDir
+ P
[3]) then
5394 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5395 if Length(P
) < 5 then
5398 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5401 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5403 if g_Map_Exist(MapsDir
+ s
) then
5405 // Çàïóñêàåì ñâîþ èãðó
5407 with gGameSettings
do
5409 GameMode
:= g_Game_TextToMode(gcGameMode
);
5410 if gSwitchGameMode
<> GM_NONE
then
5411 GameMode
:= gSwitchGameMode
;
5412 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5413 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5415 if Length(P
) >= 6 then
5416 b
:= StrToIntDef(P
[5], 0);
5417 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5418 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5423 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5425 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5427 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5429 else if cmd
= 'map' then
5431 if Length(P
) = 1 then
5433 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5435 g_Console_Add(cmd
+ ' <MAP>');
5436 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5438 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5440 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5442 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5443 if Length(P
) < 3 then
5445 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5446 s
:= UpperCase(P
[1]);
5447 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5448 begin // Êàðòà íàøëàñü
5449 gExitByTrigger
:= False;
5451 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5453 gExit
:= EXIT_ENDLEVELCUSTOM
;
5455 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5456 g_Game_ChangeMap(s
);
5459 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5460 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5461 P
[1] := addWadExtension(P
[1]);
5462 if FileExists(MapsDir
+ P
[1]) then
5464 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5466 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5468 s
:= P
[1] + ':\' + P
[2];
5470 if g_Map_Exist(MapsDir
+ s
) then
5472 gExitByTrigger
:= False;
5474 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5476 gExit
:= EXIT_ENDLEVELCUSTOM
;
5478 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5479 g_Game_ChangeMap(s
);
5482 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5484 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5486 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5490 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5491 P
[1] := addWadExtension(P
[1]);
5492 if FileExists(MapsDir
+ P
[1]) then
5495 P
[2] := UpperCase(P
[2]);
5496 s
:= P
[1] + ':\' + P
[2];
5498 if g_Map_Exist(MapsDir
+ s
) then
5499 begin // Íàøëè êàðòó
5500 gExitByTrigger
:= False;
5502 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5504 gExit
:= EXIT_ENDLEVELCUSTOM
;
5506 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5507 g_Game_ChangeMap(s
);
5509 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5511 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5514 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5516 else if cmd
= 'nextmap' then
5518 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5519 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5522 if Length(P
) = 1 then
5524 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5526 g_Console_Add(cmd
+ ' <MAP>');
5527 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5530 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5535 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5537 if Length(P
) < 3 then
5539 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5540 s
:= UpperCase(P
[1]);
5541 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5542 begin // Êàðòà íàøëàñü
5543 gExitByTrigger
:= False;
5548 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5549 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5550 P
[1] := addWadExtension(P
[1]);
5551 if FileExists(MapsDir
+ P
[1]) then
5553 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5555 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5557 s
:= P
[1] + ':\' + P
[2];
5559 if g_Map_Exist(MapsDir
+ s
) then
5560 begin // Óñòàíàâëèâàåì êàðòó
5561 gExitByTrigger
:= False;
5566 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5568 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5570 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5574 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5575 P
[1] := addWadExtension(P
[1]);
5576 if FileExists(MapsDir
+ P
[1]) then
5579 P
[2] := UpperCase(P
[2]);
5580 s
:= P
[1] + ':\' + P
[2];
5582 if g_Map_Exist(MapsDir
+ s
) then
5583 begin // Íàøëè êàðòó
5584 gExitByTrigger
:= False;
5588 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5590 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5593 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5596 if gNextMap
= '' then
5597 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5599 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5602 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5605 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5607 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5609 gExitByTrigger
:= False;
5610 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5611 if (gNextMap
= '') and (gTriggers
<> nil) then
5612 for a
:= 0 to High(gTriggers
) do
5613 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5615 gExitByTrigger
:= True;
5616 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5619 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5620 if gNextMap
= '' then
5621 gNextMap
:= g_Game_GetNextMap();
5622 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5623 if Pos(':\', gNextMap
) = 0 then
5624 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5627 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5628 if g_Map_Exist(MapsDir
+ s
) then
5629 gExit
:= EXIT_ENDLEVELCUSTOM
5631 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5633 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5635 else if (cmd
= 'event') then
5637 if (Length(P
) <= 1) then
5639 for a
:= 0 to High(gEvents
) do
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 if (Length(P
) = 2) then
5648 for a
:= 0 to High(gEvents
) do
5649 if gEvents
[a
].Name
= P
[1] then
5650 if gEvents
[a
].Command
= '' then
5651 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5653 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5656 for a
:= 0 to High(gEvents
) do
5657 if gEvents
[a
].Name
= P
[1] then
5659 gEvents
[a
].Command
:= '';
5660 for b
:= 2 to High(P
) do
5661 if Pos(' ', P
[b
]) = 0 then
5662 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5664 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5665 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5669 // Êîìàíäû Ñâîåé èãðû:
5670 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5672 if cmd
= 'bot_addred' then
5674 if Length(P
) > 1 then
5675 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5677 g_Bot_Add(TEAM_RED
, 2);
5679 else if cmd
= 'bot_addblue' then
5681 if Length(P
) > 1 then
5682 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5684 g_Bot_Add(TEAM_BLUE
, 2);
5686 else if cmd
= 'suicide' then
5690 if g_Game_IsClient
then
5691 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5694 if gPlayer1
<> nil then
5695 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5696 if gPlayer2
<> nil then
5697 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5701 else if cmd
= 'spectate' then
5707 else if cmd
= 'say' then
5709 if g_Game_IsServer
and g_Game_IsNet
then
5711 if Length(P
) > 1 then
5714 for a
:= 1 to High(P
) do
5715 chstr
:= chstr
+ P
[a
] + ' ';
5717 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5719 if Length(chstr
) < 1 then
5721 g_Console_Add('say <text>');
5725 chstr
:= b_Text_Format(chstr
);
5726 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5728 else g_Console_Add('say <text>');
5730 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5732 else if cmd
= 'tell' then
5734 if g_Game_IsServer
and g_Game_IsNet
then
5736 if (Length(P
) > 2) and (P
[1] <> '') then
5739 for a
:= 2 to High(P
) do
5740 chstr
:= chstr
+ P
[a
] + ' ';
5742 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5744 if Length(chstr
) < 1 then
5746 g_Console_Add('tell <playername> <text>');
5750 pl
:= g_Net_Client_ByName(P
[1]);
5752 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5754 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5756 else g_Console_Add('tell <playername> <text>');
5758 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5760 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5762 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5764 // Äîïîëíèòåëüíîå âðåìÿ:
5765 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5767 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5768 [gGameSettings
.TimeLimit
div 3600,
5769 (gGameSettings
.TimeLimit
div 60) mod 60,
5770 gGameSettings
.TimeLimit
mod 60]));
5771 if g_Game_IsNet
then MH_SEND_GameSettings
;
5773 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5775 if (Length(P
) <= 1) then
5776 g_Console_Add('rcon_password <password>')
5778 MC_SEND_RCONPassword(P
[1]);
5780 else if cmd
= 'rcon' then
5782 if g_Game_IsClient
then
5784 if Length(P
) > 1 then
5787 for a
:= 1 to High(P
) do
5788 chstr
:= chstr
+ P
[a
] + ' ';
5790 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5792 if Length(chstr
) < 1 then
5794 g_Console_Add('rcon <command>');
5798 MC_SEND_RCONCommand(chstr
);
5800 else g_Console_Add('rcon <command>');
5803 else if cmd
= 'ready' then
5805 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5806 gLMSRespawnTime
:= gTime
+ 100;
5808 else if (cmd
= 'callvote') and g_Game_IsNet
then
5810 if Length(P
) > 1 then
5813 for a
:= 1 to High(P
) do begin
5814 if a
> 1 then chstr
:= chstr
+ ' ';
5815 chstr
:= chstr
+ P
[a
];
5818 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5820 if Length(chstr
) < 1 then
5822 g_Console_Add('callvote <command>');
5826 if g_Game_IsClient
then
5827 MC_SEND_Vote(True, chstr
)
5829 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5830 g_Console_Process('vote', True);
5833 g_Console_Add('callvote <command>');
5835 else if (cmd
= 'vote') and g_Game_IsNet
then
5837 if g_Game_IsClient
then
5839 else if gVoteInProgress
then
5841 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5842 a
:= Floor((NetClientCount
+1)/2.0) + 1
5844 a
:= Floor(NetClientCount
/2.0) + 1;
5849 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5850 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5856 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5857 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5865 procedure g_TakeScreenShot();
5873 if e_NoGraphics
then Exit
;
5874 ssdir
:= GameDir
+'/screenshots';
5875 if not findFileCI(ssdir
, true) then
5877 // try to create dir
5882 if not findFileCI(ssdir
, true) then exit
; // alas
5885 for a
:= 1 to High(Word) do
5887 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5889 if findFileCI(t
, true) then continue
;
5890 if not findFileCI(FileName
) then
5893 st
:= createDiskFile(FileName
);
5895 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5900 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5908 procedure g_Game_InGameMenu(Show
: Boolean);
5910 if (g_ActiveWindow
= nil) and Show
then
5912 if gGameSettings
.GameType
= GT_SINGLE
then
5913 g_GUI_ShowWindow('GameSingleMenu')
5916 if g_Game_IsClient
then
5917 g_GUI_ShowWindow('GameClientMenu')
5919 if g_Game_IsNet
then
5920 g_GUI_ShowWindow('GameServerMenu')
5922 g_GUI_ShowWindow('GameCustomMenu');
5924 g_Sound_PlayEx('MENU_OPEN');
5926 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5927 if (not g_Game_IsNet
) then
5931 if (g_ActiveWindow
<> nil) and (not Show
) then
5933 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5934 if (not g_Game_IsNet
) then
5935 g_Game_Pause(False);
5939 procedure g_Game_Pause(Enable
: Boolean);
5944 if gPause
= Enable
then
5947 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5951 g_Game_PauseAllSounds(Enable
);
5954 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5959 if gTriggers
<> nil then
5960 for i
:= 0 to High(gTriggers
) do
5961 with gTriggers
[i
] do
5962 if (TriggerType
= TRIGGER_SOUND
) and
5964 Sound
.IsPlaying() then
5966 Sound
.Pause(Enable
);
5970 if gPlayers
<> nil then
5971 for i
:= 0 to High(gPlayers
) do
5972 if gPlayers
[i
] <> nil then
5973 gPlayers
[i
].PauseSounds(Enable
);
5976 if gMusic
<> nil then
5977 gMusic
.Pause(Enable
);
5980 procedure g_Game_StopAllSounds(all
: Boolean);
5984 if gTriggers
<> nil then
5985 for i
:= 0 to High(gTriggers
) do
5986 with gTriggers
[i
] do
5987 if (TriggerType
= TRIGGER_SOUND
) and
5991 if gMusic
<> nil then
5998 procedure g_Game_UpdateTriggerSounds();
6002 if gTriggers
<> nil then
6003 for i
:= 0 to High(gTriggers
) do
6004 with gTriggers
[i
] do
6005 if (TriggerType
= TRIGGER_SOUND
) and
6008 Sound
.IsPlaying() then
6010 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6011 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6013 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6014 Sound
.SetVolume(Data
.Volume
/255.0);
6017 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6021 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6024 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6029 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6034 if gSpectMode
<> SPECT_PLAYERS
then
6036 if gSpectPID1
= UID
then
6041 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6048 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6053 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6058 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6063 if gSpectMode
<> SPECT_PLAYERS
then
6065 Pl
:= g_Player_Get(gSpectPID1
);
6066 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6071 if gSpectViewTwo
then
6073 Pl
:= g_Player_Get(gSpectPID2
);
6074 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6082 procedure g_Game_Message(Msg
: string; Time
: Word);
6084 MessageText
:= b_Text_Format(Msg
);
6085 MessageTime
:= Time
;
6088 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6097 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6101 if goodsnd
[a
].IsPlaying() then
6104 goodsnd
[Random(4)].Play();
6107 procedure g_Game_Announce_KillCombo(Param
: Integer);
6114 UID
:= Param
and $FFFF;
6119 Pl
:= g_Player_Get(UID
);
6128 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6132 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6136 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6140 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6148 if not g_Game_IsWatchedPlayer(UID
) then
6151 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6155 if killsnd
[n
].IsPlaying() then
6160 procedure g_Game_StartVote(Command
, Initiator
: string);
6164 if not gVotesEnabled
then Exit
;
6165 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6166 if gVoteInProgress
or gVotePassed
then
6168 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6169 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6172 gVoteInProgress
:= True;
6173 gVotePassed
:= False;
6174 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6177 gVoteCommand
:= Command
;
6179 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6180 Need
:= Floor((NetClientCount
+1)/2.0)+1
6182 Need
:= Floor(NetClientCount
/2.0)+1;
6183 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6184 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6187 procedure g_Game_CheckVote
;
6191 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6192 if not gVoteInProgress
then Exit
;
6194 if (gTime
>= gVoteTimer
) then
6196 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6197 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6199 Need
:= Floor(NetClientCount
/2.0) + 1;
6200 if gVoteCount
>= Need
then
6202 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6203 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6204 gVotePassed
:= True;
6205 gVoteCmdTimer
:= gTime
+ 5000;
6209 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6210 MH_SEND_VoteEvent(NET_VE_FAILED
);
6212 if NetClients
<> nil then
6213 for I
:= Low(NetClients
) to High(NetClients
) do
6214 if NetClients
[i
].Used
then
6215 NetClients
[i
].Voted
:= False;
6216 gVoteInProgress
:= False;
6222 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6223 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6225 Need
:= Floor(NetClientCount
/2.0) + 1;
6226 if gVoteCount
>= Need
then
6228 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6229 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6230 gVoteInProgress
:= False;
6231 gVotePassed
:= True;
6232 gVoteCmdTimer
:= gTime
+ 5000;
6235 if NetClients
<> nil then
6236 for I
:= Low(NetClients
) to High(NetClients
) do
6237 if NetClients
[i
].Used
then
6238 NetClients
[i
].Voted
:= False;
6243 procedure g_Game_LoadMapList(FileName
: string);
6251 if not FileExists(FileName
) then Exit
;
6253 AssignFile(ListFile
, FileName
);
6255 while not EOF(ListFile
) do
6257 ReadLn(ListFile
, s
);
6260 if s
= '' then Continue
;
6262 SetLength(MapList
, Length(MapList
)+1);
6263 MapList
[High(MapList
)] := s
;
6265 CloseFile(ListFile
);
6268 procedure g_Game_SetDebugMode();
6271 // ×èòû (äàæå â ñâîåé èãðå):
6275 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6279 if Length(LoadingStat
.Msgs
) = 0 then
6285 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6286 if NextMsg
= Length(Msgs
) then
6288 for i
:= 0 to High(Msgs
)-1 do
6289 Msgs
[i
] := Msgs
[i
+1];
6297 Msgs
[NextMsg
-1] := Text;
6303 g_ActiveWindow
:= nil;
6308 procedure g_Game_StepLoading();
6314 if (ShowCount
> LOADING_SHOW_STEP
) then
6322 procedure g_Game_ClearLoading();
6331 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6332 if len
< 1 then len
:= 1;
6333 SetLength(Msgs
, len
);
6334 for len
:= Low(Msgs
) to High(Msgs
) do
6340 procedure Parse_Params(var pars
: TParamStrValues
);
6347 while i
<= ParamCount
do
6350 if (s
[1] = '-') and (Length(s
) > 1) then
6352 if (s
[2] = '-') and (Length(s
) > 2) then
6353 begin // Îäèíî÷íûé ïàðàìåòð
6354 SetLength(pars
, Length(pars
) + 1);
6355 with pars
[High(pars
)] do
6357 Name
:= LowerCase(s
);
6362 if (i
< ParamCount
) then
6363 begin // Ïàðàìåòð ñî çíà÷åíèåì
6365 SetLength(pars
, Length(pars
) + 1);
6366 with pars
[High(pars
)] do
6368 Name
:= LowerCase(s
);
6369 Value
:= LowerCase(ParamStr(i
));
6378 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6383 for i
:= 0 to High(pars
) do
6384 if pars
[i
].Name
= aName
then
6386 Result
:= pars
[i
].Value
;
6391 procedure g_Game_Process_Params();
6393 pars
: TParamStrValues
;
6396 LimT
, LimS
: Integer;
6407 s
:= Find_Param_Value(pars
, '--debug');
6409 g_Game_SetDebugMode();
6411 // Connect when game loads
6412 ip
:= Find_Param_Value(pars
, '-connect');
6416 s
:= Find_Param_Value(pars
, '-port');
6417 if (s
= '') or not TryStrToInt(s
, Port
) then
6420 s
:= Find_Param_Value(pars
, '-pw');
6422 g_Game_StartClient(ip
, Port
, s
);
6426 // Start map when game loads:
6427 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6428 if isWadPath(map
) then
6431 s
:= Find_Param_Value(pars
, '-gm');
6432 GMode
:= g_Game_TextToMode(s
);
6433 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6434 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6437 s
:= Find_Param_Value(pars
, '-limt');
6438 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6444 s
:= Find_Param_Value(pars
, '-lims');
6445 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6451 s
:= Find_Param_Value(pars
, '-lives');
6452 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6458 s
:= Find_Param_Value(pars
, '-opt');
6460 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6462 Opt
:= StrToIntDef(s
, 0);
6464 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6467 s
:= Find_Param_Value(pars
, '--close');
6471 // Delete test map after play:
6472 s
:= Find_Param_Value(pars
, '--testdelete');
6475 gMapToDelete
:= MapsDir
+ map
;
6476 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6480 // Delete temporary WAD after play:
6481 s
:= Find_Param_Value(pars
, '--tempdelete');
6484 gMapToDelete
:= MapsDir
+ map
;
6485 gTempDelete
:= True;
6488 // Number of players:
6489 s
:= Find_Param_Value(pars
, '-pl');
6493 n
:= StrToIntDef(s
, 1);
6496 s
:= Find_Param_Value(pars
, '-port');
6497 if (s
= '') or not TryStrToInt(s
, Port
) then
6498 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6500 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6503 // Execute script when game loads:
6504 s
:= Find_Param_Value(pars
, '-exec');
6507 if Pos(':\', s
) = 0 then
6508 s
:= GameDir
+ '/' + s
;
6513 if IOResult
<> 0 then
6515 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6516 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6520 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6521 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6526 if IOResult
<> 0 then
6528 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6529 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6533 if Pos('#', s
) <> 1 then // script comment
6534 g_Console_Process(s
, True);