1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, g_scripts
, MAPSTRUCT
, wadreader
, md5
;
26 TGameSettings
= record
42 TDelayedEvent
= record
50 TPlayerSettings
= record
69 function g_Game_IsNet(): Boolean;
70 function g_Game_IsServer(): Boolean;
71 function g_Game_IsClient(): Boolean;
72 procedure g_Game_Init();
73 procedure g_Game_Free();
74 procedure g_Game_LoadData();
75 procedure g_Game_FreeData();
76 procedure g_Game_Update();
77 procedure g_Game_Draw();
78 procedure g_Game_Quit();
79 procedure g_Game_SetupScreenSize();
80 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
81 function g_Game_ModeToText(Mode
: Byte): string;
82 function g_Game_TextToMode(Mode
: string): Byte;
83 procedure g_Game_ExecuteEvent(Name
: String);
84 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
85 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
86 procedure g_Game_RemovePlayer();
87 procedure g_Game_Spectate();
88 procedure g_Game_SpectateCenterView();
89 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
90 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
91 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
92 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
93 procedure g_Game_Restart();
94 procedure g_Game_RestartLevel();
95 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
96 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
97 procedure g_Game_SaveOptions();
98 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
99 procedure g_Game_ChangeMap(MapPath
: String);
100 procedure g_Game_ExitLevel(Map
: Char16
);
101 function g_Game_GetFirstMap(WAD
: String): String;
102 function g_Game_GetNextMap(): String;
103 procedure g_Game_NextLevel();
104 procedure g_Game_Pause(Enable
: Boolean);
105 procedure g_Game_InGameMenu(Show
: Boolean);
106 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
107 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
108 procedure g_Game_Message(Msg
: String; Time
: Word);
109 procedure g_Game_LoadMapList(FileName
: String);
110 procedure g_Game_PauseAllSounds(Enable
: Boolean);
111 procedure g_Game_StopAllSounds(all
: Boolean);
112 procedure g_Game_UpdateTriggerSounds();
113 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
114 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
115 procedure g_Game_Announce_KillCombo(Param
: Integer);
116 procedure g_Game_StartVote(Command
, Initiator
: string);
117 procedure g_Game_CheckVote
;
118 procedure g_TakeScreenShot();
119 procedure g_FatalError(Text: String);
120 procedure g_SimpleError(Text: String);
121 function g_Game_IsTestMap(): Boolean;
122 procedure g_Game_DeleteTestMap();
123 procedure GameCVars(P
: SArray
);
124 procedure GameCommands(P
: SArray
);
125 procedure GameCheats(P
: SArray
);
126 procedure DebugCommands(P
: SArray
);
127 procedure g_Game_Process_Params
;
128 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
129 procedure g_Game_StepLoading();
130 procedure g_Game_ClearLoading();
131 procedure g_Game_SetDebugMode();
132 procedure DrawLoadingStat();
134 { procedure SetWinPause(Enable: Boolean); }
139 LOADING_SHOW_STEP
= 100;
140 LOADING_INTERLINE
= 20;
155 MESSAGE_DIKEY
= WM_USER
+ 1;
160 EXIT_ENDLEVELSINGLE
= 4;
161 EXIT_ENDLEVELCUSTOM
= 5;
163 GAME_OPTION_RESERVED
= 1;
164 GAME_OPTION_TEAMDAMAGE
= 2;
165 GAME_OPTION_ALLOWEXIT
= 4;
166 GAME_OPTION_WEAPONSTAY
= 8;
167 GAME_OPTION_MONSTERS
= 16;
168 GAME_OPTION_BOTVSPLAYER
= 32;
169 GAME_OPTION_BOTVSMONSTER
= 64;
174 STATE_INTERCUSTOM
= 3;
175 STATE_INTERSINGLE
= 4;
181 LMS_RESPAWN_NONE
= 0;
182 LMS_RESPAWN_WARMUP
= 1;
183 LMS_RESPAWN_FINAL
= 2;
199 CONFIG_FILENAME
= 'Doom2DF.cfg';
200 LOG_FILENAME
= 'Doom2DF.log';
202 TEST_MAP_NAME
= '$$$_TEST_$$$';
204 STD_PLAYER_MODEL
= 'Doomer';
208 gGameSettings
: TGameSettings
;
209 gPlayer1Settings
: TPlayerSettings
;
210 gPlayer2Settings
: TPlayerSettings
;
212 gPlayerScreenSize
: TPoint
;
213 gPlayer1ScreenCoord
: TPoint
;
214 gPlayer2ScreenCoord
: TPoint
;
215 gPlayer1
: TPlayer
= nil;
216 gPlayer2
: TPlayer
= nil;
217 gPlayerDrawn
: TPlayer
= nil;
219 gSwitchGameMode
: Byte = GM_DM
;
220 gHearPoint1
, gHearPoint2
: THearPoint
;
221 gSoundEffectsDF
: Boolean = False;
222 gSoundTriggerTime
: Word = 0;
223 gAnnouncer
: Byte = ANNOUNCE_NONE
;
224 goodsnd
: array[0..3] of TPlayableSound
;
225 killsnd
: array[0..3] of TPlayableSound
;
226 gDefInterTime
: ShortInt = -1;
227 gInterEndTime
: LongWord = 0;
228 gInterTime
: LongWord = 0;
229 gServInterTime
: Byte = 0;
230 gGameStartTime
: LongWord = 0;
231 gTotalMonsters
: Integer = 0;
233 gShowTime
: Boolean = True;
234 gShowFPS
: Boolean = False;
235 gShowGoals
: Boolean = True;
236 gShowStat
: Boolean = True;
237 gShowKillMsg
: Boolean = True;
238 gShowLives
: Boolean = True;
239 gShowPing
: Boolean = False;
240 gShowMap
: Boolean = False;
242 gState
: Byte = STATE_NONE
;
244 sWidth
, sHeight
: Word;
245 gSpectMode
: Byte = SPECT_NONE
;
246 gSpectHUD
: Boolean = True;
247 gSpectKeyPress
: Boolean = False;
248 gSpectX
: Integer = 0;
249 gSpectY
: Integer = 0;
250 gSpectStep
: Byte = 8;
251 gSpectViewTwo
: Boolean = False;
252 gSpectPID1
: Integer = -1;
253 gSpectPID2
: Integer = -1;
254 gMusic
: TMusic
= nil;
255 gLoadGameMode
: Boolean;
256 gCheats
: Boolean = False;
257 gMapOnce
: Boolean = False;
258 gMapToDelete
: String;
259 gTempDelete
: Boolean = False;
260 gLastMap
: Boolean = False;
261 gWinPosX
, gWinPosY
: Integer;
262 gWinSizeX
, gWinSizeY
: Integer;
263 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
264 gWinActive
: Boolean = True; // by default window is active, lol
265 gResolutionChange
: Boolean = False;
266 gRC_Width
, gRC_Height
: Word;
267 gRC_FullScreen
, gRC_Maximized
: Boolean;
268 gLanguageChange
: Boolean = False;
269 gDebugMode
: Boolean = False;
270 g_debug_Sounds
: Boolean = False;
271 g_debug_Frames
: Boolean = False;
272 g_debug_WinMsgs
: Boolean = False;
273 g_debug_MonsterOff
: Boolean = False;
274 g_debug_BotAIOff
: Byte = 0;
275 g_debug_HealthBar
: Boolean = False;
276 g_Debug_Player
: Boolean = False;
277 gCoopMonstersKilled
: Word = 0;
278 gCoopSecretsFound
: Word = 0;
279 gCoopTotalMonstersKilled
: Word = 0;
280 gCoopTotalSecretsFound
: Word = 0;
281 gCoopTotalMonsters
: Word = 0;
282 gCoopTotalSecrets
: Word = 0;
283 gStatsOff
: Boolean = False;
284 gStatsPressed
: Boolean = False;
285 gExitByTrigger
: Boolean = False;
286 gNextMap
: String = '';
287 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
288 gLMSRespawnTime
: Cardinal = 0;
289 gLMSSoftSpawn
: Boolean = False;
290 gMissionFailed
: Boolean = False;
291 gVoteInProgress
: Boolean = False;
292 gVotePassed
: Boolean = False;
293 gVoteCommand
: string = '';
294 gVoteTimer
: Cardinal = 0;
295 gVoteCmdTimer
: Cardinal = 0;
296 gVoteCount
: Integer = 0;
297 gVoteTimeout
: Cardinal = 30;
298 gVoted
: Boolean = False;
299 gVotesEnabled
: Boolean = True;
300 gEvents
: Array of TGameEvent
;
301 gDelayedEvents
: Array of TDelayedEvent
;
303 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);
1103 g_Scripts_Load('game.conprint("ass")');
1105 gMusic
:= TMusic
.Create();
1106 gMusic
.SetByName('MUSIC_MENU');
1109 gGameSettings
.WarmupTime
:= 30;
1111 gState
:= STATE_MENU
;
1113 SetLength(gEvents
, 6);
1114 gEvents
[0].Name
:= 'ongamestart';
1115 gEvents
[1].Name
:= 'ongameend';
1116 gEvents
[2].Name
:= 'onmapstart';
1117 gEvents
[3].Name
:= 'onmapend';
1118 gEvents
[4].Name
:= 'oninter';
1119 gEvents
[5].Name
:= 'onwadend';
1121 sfsGCEnable(); // enable releasing unused volumes
1125 procedure g_Game_Free();
1127 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1128 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1132 g_Player_RemoveAllCorpses();
1134 gGameSettings
.GameType
:= GT_NONE
;
1135 if gGameSettings
.GameMode
= GM_SINGLE
then
1136 gGameSettings
.GameMode
:= GM_DM
;
1137 gSwitchGameMode
:= gGameSettings
.GameMode
;
1140 gExitByTrigger
:= False;
1143 function IsActivePlayer(p
: TPlayer
): Boolean;
1148 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1151 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1158 if gPlayers
= nil then
1160 for a
:= Low(gPlayers
) to High(gPlayers
) do
1161 if IsActivePlayer(gPlayers
[a
]) then
1163 if gPlayers
[a
].UID
<> ID
then
1165 Result
:= gPlayers
[a
];
1170 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1176 if gPlayers
= nil then
1180 for a
:= Low(gPlayers
) to High(gPlayers
) do
1181 if IsActivePlayer(gPlayers
[a
]) then
1183 SetLength(ids
, Length(ids
) + 1);
1184 ids
[High(ids
)] := gPlayers
[a
].UID
;
1185 if gPlayers
[a
].UID
= Skip
then
1188 if Length(ids
) = 0 then
1193 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1196 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1202 if gPlayers
= nil then
1206 for a
:= Low(gPlayers
) to High(gPlayers
) do
1207 if IsActivePlayer(gPlayers
[a
]) then
1209 SetLength(ids
, Length(ids
) + 1);
1210 ids
[High(ids
)] := gPlayers
[a
].UID
;
1211 if gPlayers
[a
].UID
= Skip
then
1214 if Length(ids
) = 0 then
1217 Result
:= ids
[Length(ids
) - 1]
1219 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1222 procedure g_Game_Update();
1224 Msg
: g_gui
.TMessage
;
1230 // Ïîðà âûêëþ÷àòü èãðó:
1231 if gExit
= EXIT_QUIT
then
1233 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1237 if gExit
= EXIT_QUIT
then
1241 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1244 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1247 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1249 gExit
:= EXIT_SIMPLE
;
1255 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1256 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1257 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1258 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1260 if g_Game_IsNet
and g_Game_IsServer
then
1262 gInterTime
:= gInterTime
+ GAME_TICK
;
1263 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1264 if a
<> gServInterTime
then
1266 gServInterTime
:= a
;
1267 MH_SEND_TimeSync(gServInterTime
);
1271 if (not g_Game_IsClient
) and
1274 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1275 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1276 and (g_ActiveWindow
= nil)
1278 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1281 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1282 g_Game_StopAllSounds(True);
1284 if gMapOnce
then // Ýòî áûë òåñò
1285 gExit
:= EXIT_SIMPLE
1287 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1288 g_Game_ChangeMap(gNextMap
)
1289 else // Ñëåäóþùåé êàðòû íåò
1291 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1293 // Âûõîä â ãëàâíîå ìåíþ:
1295 g_GUI_ShowWindow('MainMenu');
1296 gMusic
.SetByName('MUSIC_MENU');
1298 gState
:= STATE_MENU
;
1301 // Ôèíàëüíàÿ êàðòèíêà:
1302 g_Game_ExecuteEvent('onwadend');
1304 if not gMusic
.SetByName('MUSIC_endmus') then
1305 gMusic
.SetByName('MUSIC_STDENDMUS');
1307 gState
:= STATE_ENDPIC
;
1309 g_Game_ExecuteEvent('ongameend');
1315 if gState
= STATE_INTERTEXT
then
1316 if InterText
.counter
> 0 then
1317 InterText
.counter
:= InterText
.counter
- 1;
1320 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1322 if EndingGameCounter
= 0 then
1324 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1325 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1327 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1329 g_Game_ExecuteEvent('onwadend');
1330 if not gMusic
.SetByName('MUSIC_endmus') then
1331 gMusic
.SetByName('MUSIC_STDENDMUS');
1334 gMusic
.SetByName('MUSIC_ROUNDMUS');
1337 gState
:= STATE_INTERCUSTOM
;
1339 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1341 gMusic
.SetByName('MUSIC_INTERMUS');
1343 gState
:= STATE_INTERSINGLE
;
1345 g_Game_ExecuteEvent('oninter');
1348 DecMin(EndingGameCounter
, 6, 0);
1351 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1353 if gMapOnce
then // Ýòî áûë òåñò
1355 gExit
:= EXIT_SIMPLE
;
1361 g_Serverlist_Control(slCurrent
);
1364 if g_Game_IsNet
then
1365 if not gConsoleShow
then
1366 if not gChatShow
then
1368 if g_ActiveWindow
= nil then
1370 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1371 g_Console_Chat_Switch(False)
1372 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1373 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1374 g_Console_Chat_Switch(True);
1377 if not gChatEnter
then
1378 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1379 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1382 // Ñòàòèñòèêà ïî Tab:
1384 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1385 (gGameSettings
.GameType
<> GT_SINGLE
) and
1386 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1389 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1391 // Âðåìÿ += 28 ìèëëèñåêóíä:
1392 gTime
:= gTime
+ GAME_TICK
;
1394 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1395 if MessageTime
= 0 then
1397 if MessageTime
> 0 then
1398 MessageTime
:= MessageTime
- 1;
1400 if (g_Game_IsServer
) then
1402 // Áûë çàäàí ëèìèò âðåìåíè:
1403 if (gGameSettings
.TimeLimit
> 0) then
1404 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1405 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1410 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1411 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1412 g_Game_RestartRound(gLMSSoftSpawn
);
1414 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1415 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1417 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1419 g_Console_Process(gVoteCommand
);
1421 gVotePassed
:= False;
1424 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1425 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1426 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1427 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1428 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1430 // Áûë çàäàí ëèìèò ïîáåä:
1431 if (gGameSettings
.GoalLimit
> 0) then
1435 if gGameSettings
.GameMode
= GM_DM
then
1436 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1437 for i
:= 0 to High(gPlayers
) do
1438 if gPlayers
[i
] <> nil then
1439 if gPlayers
[i
].Frags
> b
then
1440 b
:= gPlayers
[i
].Frags
;
1443 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1444 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1445 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1448 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1449 if b
>= gGameSettings
.GoalLimit
then
1456 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1457 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1458 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1459 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1462 if gPlayer1
<> nil then
1463 with gGameControls
.P1Control
do
1465 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1466 P1MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1468 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1469 P1MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1471 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1472 P1MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1474 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1475 if P1MoveButton
= 1 then
1476 gPlayer1
.PressKey(KEY_LEFT
)
1478 if P1MoveButton
= 2 then
1479 gPlayer1
.PressKey(KEY_RIGHT
);
1481 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1482 if (P1MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1483 gPlayer1
.SetDirection(D_LEFT
)
1485 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1486 if (P1MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1487 gPlayer1
.SetDirection(D_RIGHT
)
1489 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1490 if P1MoveButton
<> 0 then
1491 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
1493 // Îñòàëüíûå êëàâèøè:
1494 if e_KeyPressed(KeyJump
) then gPlayer1
.PressKey(KEY_JUMP
);
1495 if e_KeyPressed(KeyUp
) then gPlayer1
.PressKey(KEY_UP
);
1496 if e_KeyPressed(KeyDown
) then gPlayer1
.PressKey(KEY_DOWN
);
1497 if e_KeyPressed(KeyFire
) then gPlayer1
.PressKey(KEY_FIRE
);
1498 if e_KeyPressed(KeyNextWeapon
) then gPlayer1
.PressKey(KEY_NEXTWEAPON
);
1499 if e_KeyPressed(KeyPrevWeapon
) then gPlayer1
.PressKey(KEY_PREVWEAPON
);
1500 if e_KeyPressed(KeyOpen
) then gPlayer1
.PressKey(KEY_OPEN
);
1503 if gPlayer2
<> nil then
1504 with gGameControls
.P2Control
do
1506 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1507 P2MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1509 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1510 P2MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1512 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1513 P2MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1515 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1516 if P2MoveButton
= 1 then
1517 gPlayer2
.PressKey(KEY_LEFT
, 1000)
1519 if P2MoveButton
= 2 then
1520 gPlayer2
.PressKey(KEY_RIGHT
, 1000);
1522 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1523 if (P2MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1524 gPlayer2
.SetDirection(D_LEFT
)
1526 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1527 if (P2MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1528 gPlayer2
.SetDirection(D_RIGHT
)
1530 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1531 if P2MoveButton
<> 0 then
1532 gPlayer2
.SetDirection(TDirection(P2MoveButton
-1));
1534 // Îñòàëüíûå êëàâèøè:
1535 if e_KeyPressed(KeyJump
) then gPlayer2
.PressKey(KEY_JUMP
, 1000);
1536 if e_KeyPressed(KeyUp
) then gPlayer2
.PressKey(KEY_UP
, 1000);
1537 if e_KeyPressed(KeyDown
) then gPlayer2
.PressKey(KEY_DOWN
, 1000);
1538 if e_KeyPressed(KeyFire
) then gPlayer2
.PressKey(KEY_FIRE
);
1539 if e_KeyPressed(KeyNextWeapon
) then gPlayer2
.PressKey(KEY_NEXTWEAPON
);
1540 if e_KeyPressed(KeyPrevWeapon
) then gPlayer2
.PressKey(KEY_PREVWEAPON
);
1541 if e_KeyPressed(KeyOpen
) then gPlayer2
.PressKey(KEY_OPEN
);
1543 end // if not console
1545 if g_Game_IsNet
and (gPlayer1
<> nil) then
1546 gPlayer1
.PressKey(KEY_CHAT
, 10000);
1551 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1552 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1554 if not gSpectKeyPress
then
1556 if e_KeyPressed(gGameControls
.P1Control
.KeyJump
) then
1558 // switch spect mode
1560 SPECT_NONE
: ; // not spectator
1562 SPECT_MAPVIEW
: Inc(gSpectMode
);
1563 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1565 gSpectKeyPress
:= True;
1567 if gSpectMode
= SPECT_MAPVIEW
then
1569 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1570 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1571 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1572 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1573 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1574 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1575 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1576 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1577 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1580 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1581 gSpectKeyPress
:= True;
1583 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1586 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1587 gSpectKeyPress
:= True;
1590 if gSpectMode
= SPECT_PLAYERS
then
1592 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1595 gSpectViewTwo
:= True;
1596 gSpectKeyPress
:= True;
1598 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1600 // remove second view
1601 gSpectViewTwo
:= False;
1602 gSpectKeyPress
:= True;
1604 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1606 // prev player (view 1)
1607 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1608 gSpectKeyPress
:= True;
1610 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1612 // next player (view 1)
1613 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1614 gSpectKeyPress
:= True;
1616 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1618 // prev player (view 2)
1619 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1620 gSpectKeyPress
:= True;
1622 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1624 // next player (view 2)
1625 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1626 gSpectKeyPress
:= True;
1631 if (not e_KeyPressed(gGameControls
.P1Control
.KeyJump
)) and
1632 (not e_KeyPressed(gGameControls
.P1Control
.KeyLeft
)) and
1633 (not e_KeyPressed(gGameControls
.P1Control
.KeyRight
)) and
1634 (not e_KeyPressed(gGameControls
.P1Control
.KeyUp
)) and
1635 (not e_KeyPressed(gGameControls
.P1Control
.KeyDown
)) and
1636 (not e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
)) and
1637 (not e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
)) then
1638 gSpectKeyPress
:= False;
1641 // Îáíîâëÿåì âñå îñòàëüíîå:
1644 g_Triggers_Update();
1646 g_Monsters_Update();
1648 g_Player_UpdateAll();
1649 g_Player_UpdatePhysicalObjects();
1650 if gGameSettings
.GameType
= GT_SERVER
then
1651 if Length(gMonstersSpawned
) > 0 then
1653 for I
:= 0 to High(gMonstersSpawned
) do
1654 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1655 SetLength(gMonstersSpawned
, 0);
1658 if (gSoundTriggerTime
> 8) then
1660 g_Game_UpdateTriggerSounds();
1661 gSoundTriggerTime
:= 0;
1664 Inc(gSoundTriggerTime
);
1666 if (NetMode
= NET_SERVER
) then
1668 Inc(NetTimeToUpdate
);
1669 Inc(NetTimeToReliable
);
1670 if NetTimeToReliable
>= NetRelupdRate
then
1672 for I
:= 0 to High(gPlayers
) do
1673 if gPlayers
[I
] <> nil then
1674 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1676 if gMonsters
<> nil then
1677 for I
:= 0 to High(gMonsters
) do
1678 if gMonsters
[I
] <> nil then
1680 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1682 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1683 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1686 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1687 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1688 (gMonsters
[I
].GameVelX
<> 0) or
1689 (gMonsters
[I
].GameVelY
<> 0) then
1690 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1693 NetTimeToReliable
:= 0;
1694 NetTimeToUpdate
:= NetUpdateRate
;
1696 else if NetTimeToUpdate
>= NetUpdateRate
then
1698 if gPlayers
<> nil then
1699 for I
:= 0 to High(gPlayers
) do
1700 if gPlayers
[I
] <> nil then
1701 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1703 if gMonsters
<> nil then
1704 for I
:= 0 to High(gMonsters
) do
1705 if gMonsters
[I
] <> nil then
1707 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1709 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1710 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1713 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1714 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1715 (gMonsters
[I
].GameVelX
<> 0) or
1716 (gMonsters
[I
].GameVelY
<> 0) then
1717 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1720 NetTimeToUpdate
:= 0;
1723 if NetUseMaster
then
1724 if gTime
>= NetTimeToMaster
then
1726 if (NetMHost
= nil) or (NetMPeer
= nil) then
1727 if not g_Net_Slist_Connect
then
1728 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1731 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1735 if NetMode
= NET_CLIENT
then
1736 MC_SEND_PlayerPos();
1737 end; // if gameOn ...
1739 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1740 if g_ActiveWindow
<> nil then
1742 w
:= e_GetFirstKeyPressed();
1744 if (w
<> IK_INVALID
) then
1746 Msg
.Msg
:= MESSAGE_DIKEY
;
1748 g_ActiveWindow
.OnMessage(Msg
);
1751 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1752 if g_ActiveWindow
<> nil then
1753 g_ActiveWindow
.Update();
1755 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1756 if gResolutionChange
then
1758 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1759 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1760 gResolutionChange
:= False;
1763 // Íóæíî ñìåíèòü ÿçûê:
1764 if gLanguageChange
then
1766 //e_WriteLog('Read language file', MSG_NOTIFY);
1767 //g_Language_Load(DataDir + gLanguage + '.txt');
1768 g_Language_Set(gLanguage
);
1770 gLanguageChange
:= False;
1774 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1775 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1776 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1779 LastScreenShot
:= GetTimer();
1782 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1783 if e_KeyPressed(IK_F10
) and
1785 (not gConsoleShow
) and
1786 (g_ActiveWindow
= nil) then
1791 Time
:= GetTimer() {div 1000};
1793 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1794 if gDelayedEvents
<> nil then
1795 for a
:= 0 to High(gDelayedEvents
) do
1796 if gDelayedEvents
[a
].Pending
and
1798 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1799 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1802 case gDelayedEvents
[a
].DEType
of
1804 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1807 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1811 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1812 if g_Game_IsNet
and g_Game_IsServer
then
1813 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1816 gDelayedEvents
[a
].Pending
:= False;
1819 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1820 UPSCounter
:= UPSCounter
+ 1;
1821 if Time
- UPSTime
>= 1000 then
1829 procedure g_Game_LoadData();
1831 if DataLoaded
then Exit
;
1833 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1835 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1836 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1837 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1838 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1839 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1840 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1841 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1842 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1843 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1844 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1845 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1846 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1847 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1848 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1849 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1850 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1851 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1852 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1853 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1854 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1855 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1856 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1857 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1858 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1859 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1860 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1861 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1862 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1863 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1864 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1865 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1866 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1867 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1868 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1870 goodsnd
[0] := TPlayableSound
.Create();
1871 goodsnd
[1] := TPlayableSound
.Create();
1872 goodsnd
[2] := TPlayableSound
.Create();
1873 goodsnd
[3] := TPlayableSound
.Create();
1875 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1876 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1877 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1878 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1880 killsnd
[0] := TPlayableSound
.Create();
1881 killsnd
[1] := TPlayableSound
.Create();
1882 killsnd
[2] := TPlayableSound
.Create();
1883 killsnd
[3] := TPlayableSound
.Create();
1885 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1886 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1887 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1888 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1890 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1893 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1894 g_Weapon_LoadData();
1896 g_Monsters_LoadData();
1901 procedure g_Game_FreeData();
1903 if not DataLoaded
then Exit
;
1906 g_Weapon_FreeData();
1907 g_Monsters_FreeData();
1909 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1911 g_Texture_Delete('NOTEXTURE');
1912 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1913 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1914 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1915 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1916 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1917 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1918 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1919 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1920 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1921 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1922 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1923 g_Frames_DeleteByName('FRAMES_TELEPORT');
1924 g_Sound_Delete('SOUND_GAME_TELEPORT');
1925 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1926 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1927 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1928 g_Sound_Delete('SOUND_GAME_BULK1');
1929 g_Sound_Delete('SOUND_GAME_BULK2');
1930 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1931 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1932 g_Sound_Delete('SOUND_GAME_SWITCH1');
1933 g_Sound_Delete('SOUND_GAME_SWITCH0');
1940 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1941 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1942 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1943 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1950 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1951 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1952 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1953 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1955 DataLoaded
:= False;
1958 procedure DrawCustomStat();
1964 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1965 s1
, s2
, topstr
: String;
1967 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1970 if e_KeyPressed(IK_TAB
) then
1972 if not gStatsPressed
then
1974 gStatsOff
:= not gStatsOff
;
1975 gStatsPressed
:= True;
1979 gStatsPressed
:= False;
1983 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1984 w
:= (Length(s1
) * ww2
) div 2;
1985 x
:= gScreenWidth
div 2 - w
;
1987 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1991 if (gGameSettings
.GameMode
= GM_COOP
) then
1993 if gMissionFailed
then
1994 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1996 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1999 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2001 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2002 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2004 if g_Game_IsNet
then
2006 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2007 if not gChatShow
then
2008 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2009 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2012 if g_Game_IsClient
then
2013 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2015 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2016 if not gChatShow
then
2017 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2018 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2023 w
:= gScreenWidth
-x
*2;
2029 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2030 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2032 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2034 case CustomStat
.GameMode
of
2037 if gGameSettings
.MaxLives
= 0 then
2038 s1
:= _lc
[I_GAME_DM
]
2040 s1
:= _lc
[I_GAME_LMS
];
2044 if gGameSettings
.MaxLives
= 0 then
2045 s1
:= _lc
[I_GAME_TDM
]
2047 s1
:= _lc
[I_GAME_TLMS
];
2049 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2052 if gGameSettings
.MaxLives
= 0 then
2053 s1
:= _lc
[I_GAME_COOP
]
2055 s1
:= _lc
[I_GAME_SURV
];
2061 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2065 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2066 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2069 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2070 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2071 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2072 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2074 pc
:= Length(CustomStat
.PlayerStat
);
2075 if pc
= 0 then Exit
;
2077 if CustomStat
.GameMode
= GM_COOP
then
2079 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2081 s2
:= _lc
[I_GAME_MONSTERS
];
2082 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2083 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2085 s2
:= _lc
[I_GAME_SECRETS
];
2086 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2087 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2090 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2092 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2093 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2094 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2096 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2097 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2098 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2102 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2107 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2108 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2109 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2111 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2114 for t
:= TEAM_RED
to TEAM_BLUE
do
2116 if t
= TEAM_RED
then
2118 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2119 gStdFont
, 255, 0, 0, 1);
2120 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2121 gStdFont
, 255, 0, 0, 1);
2128 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2129 gStdFont
, 0, 0, 255, 1);
2130 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2131 gStdFont
, 0, 0, 255, 1);
2137 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2140 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2141 if CustomStat
.PlayerStat
[p
].Team
= t
then
2142 with CustomStat
.PlayerStat
[p
] do
2156 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2157 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2158 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2165 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2168 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2169 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2170 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2173 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2174 with CustomStat
.PlayerStat
[p
] do
2176 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2183 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2184 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2185 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2191 procedure DrawSingleStat();
2193 tm
, key_x
, val_x
, y
: Integer;
2197 procedure player_stat(n
: Integer);
2203 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2204 s2
:= Format(' %d', [gTotalMonsters
]);
2206 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2207 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2208 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2209 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2211 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2212 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2214 // "Kills-per-minute: ##.#":
2215 s1
:= _lc
[I_MENU_INTER_KPM
];
2217 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2219 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2220 s2
:= Format(' %.1f', [kpm
]);
2222 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2223 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2225 // "Secrets found: # / #":
2226 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2227 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2229 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2230 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2231 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2232 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2234 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2235 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2239 // "Level Complete":
2240 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2241 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2243 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2244 s1
:= _lc
[I_MENU_INTER_KPM
];
2245 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2248 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2250 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2251 val_x
:= key_x
+ w1
;
2254 tm
:= SingleStat
.GameTime
div 1000;
2255 s1
:= _lc
[I_MENU_INTER_TIME
];
2256 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2258 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2259 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2261 if SingleStat
.TwoPlayers
then
2264 s1
:= _lc
[I_MENU_PLAYER_1
];
2265 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2266 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2268 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2273 s1
:= _lc
[I_MENU_PLAYER_2
];
2274 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2275 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2277 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2283 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2289 procedure DrawLoadingStat();
2295 if Length(LoadingStat
.Msgs
) = 0 then
2298 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2299 yy
:= (gScreenHeight
div 3);
2300 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2301 xx
:= (gScreenWidth
div 3);
2304 for i
:= 0 to NextMsg
-1 do
2306 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2307 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2311 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2312 yy
:= yy
+ LOADING_INTERLINE
;
2316 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2318 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2320 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2321 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2324 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2325 ScaleSz
:= 16 div Scale
;
2326 // Ðàçìåðû ìèíè-êàðòû:
2327 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2328 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2330 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2332 if gWalls
<> nil then
2335 for a
:= 0 to High(gWalls
) do
2337 if PanelType
<> 0 then
2339 // Ëåâûé âåðõíèé óãîë:
2340 aX
:= X
div ScaleSz
;
2341 aY
:= Y
div ScaleSz
;
2343 aX2
:= max(Width
div ScaleSz
, 1);
2344 aY2
:= max(Height
div ScaleSz
, 1);
2345 // Ïðàâûé íèæíèé óãîë:
2346 aX2
:= aX
+ aX2
- 1;
2347 aY2
:= aY
+ aY2
- 1;
2350 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2351 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2352 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2356 if gSteps
<> nil then
2359 for a
:= 0 to High(gSteps
) do
2361 if PanelType
<> 0 then
2363 // Ëåâûé âåðõíèé óãîë:
2364 aX
:= X
div ScaleSz
;
2365 aY
:= Y
div ScaleSz
;
2367 aX2
:= max(Width
div ScaleSz
, 1);
2368 aY2
:= max(Height
div ScaleSz
, 1);
2369 // Ïðàâûé íèæíèé óãîë:
2370 aX2
:= aX
+ aX2
- 1;
2371 aY2
:= aY
+ aY2
- 1;
2373 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2376 if gLifts
<> nil then
2379 for a
:= 0 to High(gLifts
) do
2381 if PanelType
<> 0 then
2383 // Ëåâûé âåðõíèé óãîë:
2384 aX
:= X
div ScaleSz
;
2385 aY
:= Y
div ScaleSz
;
2387 aX2
:= max(Width
div ScaleSz
, 1);
2388 aY2
:= max(Height
div ScaleSz
, 1);
2389 // Ïðàâûé íèæíèé óãîë:
2390 aX2
:= aX
+ aX2
- 1;
2391 aY2
:= aY
+ aY2
- 1;
2394 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2395 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2396 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2397 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2401 if gWater
<> nil then
2404 for a
:= 0 to High(gWater
) do
2406 if PanelType
<> 0 then
2408 // Ëåâûé âåðõíèé óãîë:
2409 aX
:= X
div ScaleSz
;
2410 aY
:= Y
div ScaleSz
;
2412 aX2
:= max(Width
div ScaleSz
, 1);
2413 aY2
:= max(Height
div ScaleSz
, 1);
2414 // Ïðàâûé íèæíèé óãîë:
2415 aX2
:= aX
+ aX2
- 1;
2416 aY2
:= aY
+ aY2
- 1;
2418 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2421 if gAcid1
<> nil then
2423 // Ðèñóåì êèñëîòó 1:
2424 for a
:= 0 to High(gAcid1
) do
2426 if PanelType
<> 0 then
2428 // Ëåâûé âåðõíèé óãîë:
2429 aX
:= X
div ScaleSz
;
2430 aY
:= Y
div ScaleSz
;
2432 aX2
:= max(Width
div ScaleSz
, 1);
2433 aY2
:= max(Height
div ScaleSz
, 1);
2434 // Ïðàâûé íèæíèé óãîë:
2435 aX2
:= aX
+ aX2
- 1;
2436 aY2
:= aY
+ aY2
- 1;
2438 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2441 if gAcid2
<> nil then
2443 // Ðèñóåì êèñëîòó 2:
2444 for a
:= 0 to High(gAcid2
) do
2446 if PanelType
<> 0 then
2448 // Ëåâûé âåðõíèé óãîë:
2449 aX
:= X
div ScaleSz
;
2450 aY
:= Y
div ScaleSz
;
2452 aX2
:= max(Width
div ScaleSz
, 1);
2453 aY2
:= max(Height
div ScaleSz
, 1);
2454 // Ïðàâûé íèæíèé óãîë:
2455 aX2
:= aX
+ aX2
- 1;
2456 aY2
:= aY
+ aY2
- 1;
2458 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2461 if gPlayers
<> nil then
2464 for a
:= 0 to High(gPlayers
) do
2465 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2467 // Ëåâûé âåðõíèé óãîë:
2468 aX
:= Obj
.X
div ScaleSz
+ 1;
2469 aY
:= Obj
.Y
div ScaleSz
+ 1;
2471 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2472 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2473 // Ïðàâûé íèæíèé óãîë:
2474 aX2
:= aX
+ aX2
- 1;
2475 aY2
:= aY
+ aY2
- 1;
2477 if gPlayers
[a
] = p
then
2478 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2481 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2482 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2483 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2487 if gMonsters
<> nil then
2490 for a
:= 0 to High(gMonsters
) do
2491 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2493 // Ëåâûé âåðõíèé óãîë:
2494 aX
:= Obj
.X
div ScaleSz
+ 1;
2495 aY
:= Obj
.Y
div ScaleSz
+ 1;
2497 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2498 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2499 // Ïðàâûé íèæíèé óãîë:
2500 aX2
:= aX
+ aX2
- 1;
2501 aY2
:= aY
+ aY2
- 1;
2503 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2509 procedure DrawMapView(x
, y
, w
, h
: Integer);
2515 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2516 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2517 g_Map_DrawBack(-bx
, -by
);
2524 glTranslatef(-x
, -y
, 0);
2526 g_Map_DrawPanels(PANEL_BACK
);
2527 g_Map_DrawPanels(PANEL_STEP
);
2530 g_Player_DrawShells();
2532 g_Player_DrawCorpses();
2533 g_Map_DrawPanels(PANEL_WALL
);
2535 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2538 g_Map_DrawPanels(PANEL_ACID1
);
2539 g_Map_DrawPanels(PANEL_ACID2
);
2540 g_Map_DrawPanels(PANEL_WATER
);
2541 g_Map_DrawPanels(PANEL_FORE
);
2542 if g_debug_HealthBar
then
2544 g_Monsters_DrawHealth();
2545 g_Player_DrawHealth();
2551 procedure DrawPlayer(p
: TPlayer
);
2553 px
, py
, a
, b
, c
, d
: Integer;
2556 if (p
= nil) or (p
.FDummy
) then
2559 g_Map_DrawBack(0, 0);
2568 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2569 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2571 if px
> (gPlayerScreenSize
.X
div 2) then
2572 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2575 if py
> (gPlayerScreenSize
.Y
div 2) then
2576 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2579 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2580 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2581 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2582 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2583 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2585 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2588 if p
.IncCam
<> 0 then
2590 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2592 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2593 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2596 if py
< (gPlayerScreenSize
.Y
div 2) then
2598 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2599 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2602 if p
.IncCam
< 0 then
2603 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2605 p
.IncCam
:= p
.IncCam
+ 1;
2607 if p
.IncCam
> 0 then
2608 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2610 p
.IncCam
:= p
.IncCam
- 1;
2613 if (px
< gPlayerScreenSize
.X
div 2) or
2614 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2617 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2618 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2620 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2622 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2623 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2626 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2627 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2629 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2631 g_Map_DrawBack(-c
, -d
);
2634 sY
:= -(b
+p
.IncCam
);
2635 sWidth
:= gPlayerScreenSize
.X
;
2636 sHeight
:= gPlayerScreenSize
.Y
;
2638 glTranslatef(a
, b
+p
.IncCam
, 0);
2640 g_Map_DrawPanels(PANEL_BACK
);
2641 g_Map_DrawPanels(PANEL_STEP
);
2644 g_Player_DrawShells();
2646 g_Player_DrawCorpses();
2647 g_Map_DrawPanels(PANEL_WALL
);
2649 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2652 g_Map_DrawPanels(PANEL_ACID1
);
2653 g_Map_DrawPanels(PANEL_ACID2
);
2654 g_Map_DrawPanels(PANEL_WATER
);
2655 g_Map_DrawPanels(PANEL_FORE
);
2656 if g_debug_HealthBar
then
2658 g_Monsters_DrawHealth();
2659 g_Player_DrawHealth();
2662 if p
.FSpectator
then
2663 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2664 p
.GameY
+ PLAYER_RECT_CY
- 4,
2665 'X', gStdFont
, 255, 255, 255, 1, True);
2667 for a := 0 to High(gCollideMap) do
2668 for b := 0 to High(gCollideMap[a]) do
2671 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2673 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2677 1: e_DrawPoint(1, b, a, 200, 200, 200);
2678 2: e_DrawPoint(1, b, a, 64, 64, 255);
2679 3: e_DrawPoint(1, b, a, 255, 0, 255);
2689 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2690 if g_Debug_Player
then
2691 g_Player_DrawDebug(p
);
2695 procedure g_Game_Draw();
2702 plView1
, plView2
: TPlayer
;
2705 if gExit
= EXIT_QUIT
then Exit
;
2707 Time
:= GetTimer() {div 1000};
2708 FPSCounter
:= FPSCounter
+1;
2709 if Time
- FPSTime
>= 1000 then
2716 if gGameOn
or (gState
= STATE_FOLD
) then
2718 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2720 gSpectMode
:= SPECT_NONE
;
2721 if not gRevertPlayers
then
2723 plView1
:= gPlayer1
;
2724 plView2
:= gPlayer2
;
2728 plView1
:= gPlayer2
;
2729 plView2
:= gPlayer1
;
2733 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2735 gSpectMode
:= SPECT_NONE
;
2736 if gPlayer2
= nil then
2739 plView1
:= gPlayer2
;
2748 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2749 gSpectMode
:= SPECT_STATS
;
2751 if gSpectMode
= SPECT_PLAYERS
then
2752 if gPlayers
<> nil then
2754 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2755 if plView1
= nil then
2757 gSpectPID1
:= GetActivePlayerID_Next();
2758 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2760 if gSpectViewTwo
then
2762 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2763 if plView2
= nil then
2765 gSpectPID2
:= GetActivePlayerID_Next();
2766 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2771 if gSpectMode
= SPECT_MAPVIEW
then
2773 // Ðåæèì ïðîñìîòðà êàðòû
2775 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2776 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2777 gHearPoint1
.Active
:= True;
2778 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2779 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2780 gHearPoint2
.Active
:= False;
2784 Split
:= (plView1
<> nil) and (plView2
<> nil);
2786 // Òî÷êè ñëóõà èãðîêîâ
2787 if plView1
<> nil then
2789 gHearPoint1
.Active
:= True;
2790 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2791 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2793 gHearPoint1
.Active
:= False;
2794 if plView2
<> nil then
2796 gHearPoint2
.Active
:= True;
2797 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2798 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2800 gHearPoint2
.Active
:= False;
2802 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2803 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2806 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2807 if gScreenHeight
mod 2 = 0 then
2808 Dec(gPlayerScreenSize
.Y
);
2811 gPlayerScreenSize
.Y
:= gScreenHeight
;
2814 if gScreenHeight
mod 2 = 0 then
2815 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2817 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2819 DrawPlayer(plView1
);
2820 gPlayer1ScreenCoord
.X
:= sX
;
2821 gPlayer1ScreenCoord
.Y
:= sY
;
2825 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2827 DrawPlayer(plView2
);
2828 gPlayer2ScreenCoord
.X
:= sX
;
2829 gPlayer2ScreenCoord
.Y
:= sY
;
2832 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2835 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2838 if MessageText
<> '' then
2842 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2844 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2845 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2847 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2848 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2851 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2853 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2855 // Draw spectator GUI
2858 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2861 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2863 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2865 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2867 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2868 if gSpectMode
= SPECT_MAPVIEW
then
2870 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2871 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2872 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2873 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2874 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2876 if gSpectMode
= SPECT_PLAYERS
then
2878 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2879 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2880 if gSpectViewTwo
then
2882 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2883 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2884 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2885 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2889 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2890 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2896 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2898 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2900 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2901 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2902 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2907 if (gState
= STATE_MENU
) then
2909 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2911 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2912 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2913 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2915 if g_ActiveWindow
<> nil then
2916 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2919 if gState
= STATE_FOLD
then
2920 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2922 if gState
= STATE_INTERCUSTOM
then
2924 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2926 back
:= 'TEXTURE_endpic';
2927 if not g_Texture_Get(back
, ID
) then
2928 back
:= _lc
[I_TEXTURE_ENDPIC
];
2933 if g_Texture_Get(back
, ID
) then
2934 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2936 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2940 if g_ActiveWindow
<> nil then
2941 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2944 if gState
= STATE_INTERSINGLE
then
2946 if EndingGameCounter
> 0 then
2947 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2952 if g_Texture_Get(back
, ID
) then
2953 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2955 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2959 if g_ActiveWindow
<> nil then
2960 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2964 if gState
= STATE_ENDPIC
then
2967 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2968 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2970 if ID
<> DWORD(-1) then
2971 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2973 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2975 if g_ActiveWindow
<> nil then
2976 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2979 if gState
= STATE_SLIST
then
2981 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2983 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2984 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2986 g_Serverlist_Draw(slCurrent
);
2990 if g_ActiveWindow
<> nil then
2993 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2994 g_ActiveWindow
.Draw();
2999 if g_debug_Sounds
and gGameOn
then
3001 for w
:= 0 to High(e_SoundsArray
) do
3002 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3003 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3008 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3009 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3012 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3013 e_TextureFontPrint(gScreenWidth
-72, 0,
3014 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3018 procedure g_Game_Quit();
3020 g_Game_StopAllSounds(True);
3022 g_Game_SaveOptions();
3024 g_PlayerModel_FreeData();
3025 g_Texture_DeleteAll();
3026 g_Frames_DeleteAll();
3029 if NetInitDone
then g_Net_Free
;
3031 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3032 if gMapToDelete
<> '' then
3033 g_Game_DeleteTestMap();
3039 procedure g_FatalError(Text: String);
3041 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3042 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3044 gExit
:= EXIT_SIMPLE
;
3047 procedure g_SimpleError(Text: String);
3049 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3050 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3053 procedure g_Game_SetupScreenSize();
3057 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3058 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3059 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3060 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3062 gPlayerScreenSize
.Y
:= gScreenHeight
;
3064 // Ðàçìåð çàäíåãî ïëàíà:
3065 if BackID
<> DWORD(-1) then
3069 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3070 (gScreenHeight
*d
> gMapInfo
.Height
) then
3073 gBackSize
.X
:= Round(gScreenWidth
*d
);
3074 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3078 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3080 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3083 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3085 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3086 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3088 if gPlayer1
= nil then
3090 if g_Game_IsClient
then
3092 if NetPlrUID1
> -1 then
3094 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3095 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3100 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3101 Team
:= gPlayer1Settings
.Team
;
3103 // Ñîçäàíèå ïåðâîãî èãðîêà:
3104 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3105 gPlayer1Settings
.Color
,
3107 if gPlayer1
= nil then
3108 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3111 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3112 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3113 if g_Game_IsServer
and g_Game_IsNet
then
3114 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3115 gPlayer1
.Respawn(False, True);
3117 if g_Game_IsNet
and NetUseMaster
then
3123 if gPlayer2
= nil then
3125 if g_Game_IsClient
then
3127 if NetPlrUID2
> -1 then
3128 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3132 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3133 Team
:= gPlayer2Settings
.Team
;
3135 // Ñîçäàíèå âòîðîãî èãðîêà:
3136 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3137 gPlayer2Settings
.Color
,
3139 if gPlayer2
= nil then
3140 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3143 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3144 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3145 if g_Game_IsServer
and g_Game_IsNet
then
3146 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3147 gPlayer2
.Respawn(False, True);
3149 if g_Game_IsNet
and NetUseMaster
then
3157 procedure g_Game_RemovePlayer();
3161 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3162 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3167 if g_Game_IsServer
then
3170 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3171 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3172 g_Player_Remove(Pl
.UID
);
3174 if g_Game_IsNet
and NetUseMaster
then
3183 if g_Game_IsServer
then
3186 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3187 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3188 g_Player_Remove(Pl
.UID
);
3190 if g_Game_IsNet
and NetUseMaster
then
3195 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3201 procedure g_Game_Spectate();
3203 g_Game_RemovePlayer();
3204 if gPlayer1
<> nil then
3205 g_Game_RemovePlayer();
3208 procedure g_Game_SpectateCenterView();
3210 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3211 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3214 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3220 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3222 g_Game_ClearLoading();
3225 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3228 gGameSettings
.GameType
:= GT_SINGLE
;
3229 gGameSettings
.MaxLives
:= 0;
3230 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3231 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3232 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3233 gSwitchGameMode
:= GM_SINGLE
;
3235 g_Game_ExecuteEvent('ongamestart');
3237 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3238 g_Game_SetupScreenSize();
3240 // Ñîçäàíèå ïåðâîãî èãðîêà:
3241 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3242 gPlayer1Settings
.Color
,
3243 gPlayer1Settings
.Team
, False));
3244 if gPlayer1
= nil then
3246 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3250 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3253 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3256 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3257 gPlayer2Settings
.Color
,
3258 gPlayer2Settings
.Team
, False));
3259 if gPlayer2
= nil then
3261 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3265 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3269 // Çàãðóçêà è çàïóñê êàðòû:
3270 if not g_Game_StartMap(MAP
, True) then
3272 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3276 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3280 for i
:= nPl
+1 to nPlayers
do
3281 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3284 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3285 TimeLimit
, GoalLimit
: Word;
3287 Options
: LongWord; nPlayers
: Byte);
3293 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3295 g_Game_ClearLoading();
3298 gGameSettings
.GameType
:= GT_CUSTOM
;
3299 gGameSettings
.GameMode
:= GameMode
;
3300 gSwitchGameMode
:= GameMode
;
3301 gGameSettings
.TimeLimit
:= TimeLimit
;
3302 gGameSettings
.GoalLimit
:= GoalLimit
;
3303 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3304 gGameSettings
.Options
:= Options
;
3306 gCoopTotalMonstersKilled
:= 0;
3307 gCoopTotalSecretsFound
:= 0;
3308 gCoopTotalMonsters
:= 0;
3309 gCoopTotalSecrets
:= 0;
3313 g_Game_ExecuteEvent('ongamestart');
3315 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3316 g_Game_SetupScreenSize();
3318 // Ðåæèì íàáëþäàòåëÿ:
3319 if nPlayers
= 0 then
3326 if nPlayers
>= 1 then
3328 // Ñîçäàíèå ïåðâîãî èãðîêà:
3329 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3330 gPlayer1Settings
.Color
,
3331 gPlayer1Settings
.Team
, False));
3332 if gPlayer1
= nil then
3334 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3338 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3342 if nPlayers
>= 2 then
3344 // Ñîçäàíèå âòîðîãî èãðîêà:
3345 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3346 gPlayer2Settings
.Color
,
3347 gPlayer2Settings
.Team
, False));
3348 if gPlayer2
= nil then
3350 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3354 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3358 // Çàãðóçêà è çàïóñê êàðòû:
3359 if not g_Game_StartMap(Map
, True) then
3361 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3365 // Íåò òî÷åê ïîÿâëåíèÿ:
3366 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3367 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3368 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3369 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3370 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3372 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3376 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3380 for i
:= nPl
+1 to nPlayers
do
3381 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3384 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3385 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3386 Options
: LongWord; nPlayers
: Byte;
3387 IPAddr
: LongWord; Port
: Word);
3391 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3393 g_Game_ClearLoading();
3396 gGameSettings
.GameType
:= GT_SERVER
;
3397 gGameSettings
.GameMode
:= GameMode
;
3398 gSwitchGameMode
:= GameMode
;
3399 gGameSettings
.TimeLimit
:= TimeLimit
;
3400 gGameSettings
.GoalLimit
:= GoalLimit
;
3401 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3402 gGameSettings
.Options
:= Options
;
3404 gCoopTotalMonstersKilled
:= 0;
3405 gCoopTotalSecretsFound
:= 0;
3406 gCoopTotalMonsters
:= 0;
3407 gCoopTotalSecrets
:= 0;
3411 g_Game_ExecuteEvent('ongamestart');
3413 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3414 g_Game_SetupScreenSize();
3416 // Ðåæèì íàáëþäàòåëÿ:
3417 if nPlayers
= 0 then
3423 if nPlayers
>= 1 then
3425 // Ñîçäàíèå ïåðâîãî èãðîêà:
3426 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3427 gPlayer1Settings
.Color
,
3428 gPlayer1Settings
.Team
, False));
3429 if gPlayer1
= nil then
3431 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3435 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3438 if nPlayers
>= 2 then
3440 // Ñîçäàíèå âòîðîãî èãðîêà:
3441 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3442 gPlayer2Settings
.Color
,
3443 gPlayer2Settings
.Team
, False));
3444 if gPlayer2
= nil then
3446 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3450 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3454 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3456 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3460 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3462 // Çàãðóçêà è çàïóñê êàðòû:
3463 if not g_Game_StartMap(Map
, True) then
3465 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3469 // Íåò òî÷åê ïîÿâëåíèÿ:
3470 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3471 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3472 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3473 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3474 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3476 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3480 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3483 NetState
:= NET_STATE_GAME
;
3486 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3500 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3501 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3503 g_Game_ClearLoading();
3506 gGameSettings
.GameType
:= GT_CLIENT
;
3508 gCoopTotalMonstersKilled
:= 0;
3509 gCoopTotalSecretsFound
:= 0;
3510 gCoopTotalMonsters
:= 0;
3511 gCoopTotalSecrets
:= 0;
3515 g_Game_ExecuteEvent('ongamestart');
3517 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3518 g_Game_SetupScreenSize();
3520 NetState
:= NET_STATE_AUTH
;
3522 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3524 if not g_Net_Connect(Addr
, Port
) then
3526 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3527 NetState
:= NET_STATE_NONE
;
3531 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3533 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3538 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3540 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3542 Ptr
:= NetEvent
.packet
^.data
;
3545 MID
:= e_Raw_Read_Byte(Ptr
);
3547 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3549 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3550 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3552 WadName
:= e_Raw_Read_String(Ptr
);
3553 Map
:= e_Raw_Read_String(Ptr
);
3555 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3557 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3558 gSwitchGameMode
:= gGameSettings
.GameMode
;
3559 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3560 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3561 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3562 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3563 T
:= e_Raw_Read_LongWord(Ptr
);
3565 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3566 if newResPath
= '' then
3568 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3569 newResPath
:= g_Res_DownloadWAD(WadName
);
3570 if newResPath
= '' then
3572 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3573 enet_packet_destroy(NetEvent
.packet
);
3574 NetState
:= NET_STATE_NONE
;
3578 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3580 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3581 gPlayer1Settings
.Color
,
3582 gPlayer1Settings
.Team
, False));
3584 if gPlayer1
= nil then
3586 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3588 enet_packet_destroy(NetEvent
.packet
);
3589 NetState
:= NET_STATE_NONE
;
3593 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3594 gPlayer1
.UID
:= NetPlrUID1
;
3595 gPlayer1
.Reset(True);
3597 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3599 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3601 enet_packet_destroy(NetEvent
.packet
);
3602 NetState
:= NET_STATE_NONE
;
3610 enet_packet_destroy(NetEvent
.packet
);
3614 enet_packet_destroy(NetEvent
.packet
);
3617 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3620 if (NetEvent
.data
<= NET_DISC_MAX
) then
3621 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3622 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3632 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3641 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3642 NetState
:= NET_STATE_NONE
;
3646 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3647 gLMSRespawnTime
:= 0;
3650 NetState
:= NET_STATE_GAME
;
3651 MC_SEND_FullStateRequest
;
3652 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3655 procedure g_Game_SaveOptions();
3657 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3660 procedure g_Game_ChangeMap(MapPath
: String);
3664 g_Game_ClearLoading();
3666 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3667 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3668 if gExitByTrigger
then
3671 gExitByTrigger
:= False;
3673 if not g_Game_StartMap(MapPath
, Force
) then
3674 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3677 procedure g_Game_Restart();
3681 if g_Game_IsClient
then
3683 map
:= g_ExtractFileName(gMapInfo
.Map
);
3687 g_Game_ClearLoading();
3688 g_Game_StartMap(Map
, True);
3691 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3693 NewWAD
, ResName
: String;
3697 g_Player_RemoveAllCorpses();
3699 if (not g_Game_IsClient
) and
3700 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3701 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3703 if gSwitchGameMode
= GM_CTF
then
3704 gGameSettings
.MaxLives
:= 0;
3705 gGameSettings
.GameMode
:= gSwitchGameMode
;
3708 gSwitchGameMode
:= gGameSettings
.GameMode
;
3710 g_Player_ResetTeams();
3712 if Pos(':\', Map
) > 0 then
3714 NewWAD
:= g_ExtractWadName(Map
);
3715 ResName
:= g_ExtractFileName(Map
);
3716 if g_Game_IsServer
then
3718 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3719 g_Game_LoadWAD(NewWAD
);
3721 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3722 g_Game_ClientWAD(NewWAD
, gWADHash
);
3726 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3729 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3731 gState
:= STATE_NONE
;
3732 g_ActiveWindow
:= nil;
3738 if gGameSettings
.GameMode
= GM_CTF
then
3740 g_Map_ResetFlag(FLAG_RED
);
3741 g_Map_ResetFlag(FLAG_BLUE
);
3742 // CTF, à ôëàãîâ íåò:
3743 if not g_Map_HaveFlagPoints() then
3744 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3749 gState
:= STATE_MENU
;
3756 NetTimeToUpdate
:= 1;
3757 NetTimeToReliable
:= 0;
3758 NetTimeToMaster
:= NetMasterRate
;
3759 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3760 gLMSRespawnTime
:= 0;
3761 gMissionFailed
:= False;
3764 gCoopMonstersKilled
:= 0;
3765 gCoopSecretsFound
:= 0;
3767 gVoteInProgress
:= False;
3768 gVotePassed
:= False;
3774 if not gGameOn
then Exit
;
3776 g_Game_SpectateCenterView();
3778 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3780 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3781 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3782 gLMSSoftSpawn
:= True;
3783 if NetMode
= NET_SERVER
then
3784 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3786 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3789 if NetMode
= NET_SERVER
then
3791 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3794 if NetUseMaster
then
3796 if (NetMHost
= nil) or (NetMPeer
= nil) then
3797 if not g_Net_Slist_Connect
then
3798 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3803 if NetClients
<> nil then
3804 for I
:= 0 to High(NetClients
) do
3805 if NetClients
[I
].Used
then
3807 NetClients
[I
].Voted
:= False;
3808 if NetClients
[I
].RequestedFullUpdate
then
3810 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3811 NetClients
[I
].RequestedFullUpdate
:= False;
3815 g_Net_UnbanNonPermHosts();
3820 gCoopTotalMonstersKilled
:= 0;
3821 gCoopTotalSecretsFound
:= 0;
3822 gCoopTotalMonsters
:= 0;
3823 gCoopTotalSecrets
:= 0;
3827 g_Game_ExecuteEvent('onmapstart');
3830 procedure SetFirstLevel();
3834 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3835 if MapList
= nil then
3838 SortSArray(MapList
);
3839 gNextMap
:= MapList
[Low(MapList
)];
3844 procedure g_Game_ExitLevel(Map
: Char16
);
3848 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3849 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3850 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3851 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3853 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3854 if gGameSettings
.GameType
= GT_SINGLE
then
3855 gExit
:= EXIT_ENDLEVELSINGLE
3856 else // Âûøëè â âûõîä â Ñâîåé èãðå
3858 gExit
:= EXIT_ENDLEVELCUSTOM
;
3859 if gGameSettings
.GameMode
= GM_COOP
then
3860 g_Player_RememberAll
;
3862 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3865 if gGameSettings
.GameMode
= GM_COOP
then
3868 gStatsPressed
:= True;
3869 gNextMap
:= 'MAP01';
3871 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3874 if g_Game_IsNet
then
3876 MH_SEND_GameStats();
3877 MH_SEND_CoopStats();
3883 procedure g_Game_RestartLevel();
3887 if gGameSettings
.GameMode
= GM_SINGLE
then
3892 gExit
:= EXIT_ENDLEVELCUSTOM
;
3893 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3897 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3901 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3903 if not g_Game_IsClient
then
3905 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3908 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3909 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3913 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3917 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3918 g_Game_LoadWAD(NewWAD
);
3921 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3923 i
, n
, nb
, nr
: Integer;
3925 if not g_Game_IsServer
then Exit
;
3926 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3927 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3928 gLMSRespawnTime
:= 0;
3931 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3933 gMissionFailed
:= True;
3934 g_Game_RestartLevel
;
3938 n
:= 0; nb
:= 0; nr
:= 0;
3939 for i
:= Low(gPlayers
) to High(gPlayers
) do
3940 if (gPlayers
[i
] <> nil) and
3941 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3942 (gPlayers
[i
] is TBot
)) then
3945 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3946 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3949 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3951 // wait a second until the fuckers finally decide to join
3952 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3953 gLMSRespawnTime
:= gTime
+ 1000;
3954 gLMSSoftSpawn
:= NoMapRestart
;
3958 g_Player_RemoveAllCorpses
;
3959 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3960 if g_Game_IsNet
then
3961 MH_SEND_GameEvent(NET_EV_LMS_START
);
3963 for i
:= Low(gPlayers
) to High(gPlayers
) do
3965 if gPlayers
[i
] = nil then continue
;
3966 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3967 // don't touch normal spectators
3968 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3970 gPlayers
[i
].FNoRespawn
:= True;
3971 gPlayers
[i
].Lives
:= 0;
3972 if g_Game_IsNet
then
3973 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3976 gPlayers
[i
].FNoRespawn
:= False;
3977 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3978 gPlayers
[i
].Respawn(False, True);
3979 if gGameSettings
.GameMode
= GM_COOP
then
3981 gPlayers
[i
].Frags
:= 0;
3982 gPlayers
[i
].RecallState
;
3984 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3985 gPlayer1
:= g_Player_Get(gLMSPID1
);
3986 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3987 gPlayer2
:= g_Player_Get(gLMSPID2
);
3990 for i
:= Low(gItems
) to High(gItems
) do
3992 if gItems
[i
].Respawnable
then
3994 gItems
[i
].QuietRespawn
:= True;
3995 gItems
[i
].RespawnTime
:= 0;
4000 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
4004 for i
:= Low(gMonsters
) to High(gMonsters
) do
4006 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
4007 gMonsters
[i
].Respawn
;
4010 gLMSSoftSpawn
:= False;
4013 function g_Game_GetFirstMap(WAD
: String): String;
4017 MapList
:= g_Map_GetMapsList(WAD
);
4018 if MapList
= nil then
4021 SortSArray(MapList
);
4022 Result
:= MapList
[Low(MapList
)];
4024 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4030 function g_Game_GetNextMap(): String;
4037 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4038 if MapList
= nil then
4041 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4043 SortSArray(MapList
);
4045 for I
:= Low(MapList
) to High(MapList
) do
4046 if Map
= MapList
[I
] then
4052 if MapIndex
<> -255 then
4054 if MapIndex
= High(MapList
) then
4055 Result
:= MapList
[Low(MapList
)]
4057 Result
:= MapList
[MapIndex
+ 1];
4059 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4065 procedure g_Game_NextLevel();
4067 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4068 gExit
:= EXIT_ENDLEVELCUSTOM
4071 gExit
:= EXIT_ENDLEVELSINGLE
;
4075 if gNextMap
<> '' then Exit
;
4076 gNextMap
:= g_Game_GetNextMap();
4079 function g_Game_IsTestMap(): Boolean;
4081 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4084 procedure g_Game_DeleteTestMap();
4095 a
:= Pos('.wad:\', gMapToDelete
);
4099 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4100 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4101 Delete(gMapToDelete
, 1, a
+ 5);
4102 gMapToDelete
:= UpperCase(gMapToDelete
);
4104 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4107 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4108 if MapName <> TEST_MAP_NAME then
4111 if not gTempDelete then
4113 time := g_GetFileTime(WadName);
4114 WAD := TWADFile.Create();
4117 if not WAD.ReadFile(WadName) then
4118 begin // Íåò òàêîãî WAD-ôàéëà
4123 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4125 MapList := WAD.GetResourcesList('');
4127 if MapList <> nil then
4128 for a := 0 to High(MapList) do
4129 if MapList[a] = MapName then
4131 // Óäàëÿåì è ñîõðàíÿåì:
4132 WAD.RemoveResource('', MapName);
4133 WAD.SaveTo(WadName);
4138 g_SetFileTime(WadName, time);
4141 if gTempDelete
then DeleteFile(WadName
);
4144 procedure GameCVars(P
: SArray
);
4147 stat
: TPlayerStatArray
;
4152 cmd
:= LowerCase(P
[0]);
4153 if cmd
= 'r_showfps' then
4155 if (Length(P
) > 1) and
4156 ((P
[1] = '1') or (P
[1] = '0')) then
4157 gShowFPS
:= (P
[1][1] = '1');
4160 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4162 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4164 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4166 with gGameSettings
do
4168 if (Length(P
) > 1) and
4169 ((P
[1] = '1') or (P
[1] = '0')) then
4171 if (P
[1][1] = '1') then
4172 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4174 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4177 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4178 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4180 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4182 if g_Game_IsNet
then MH_SEND_GameSettings
;
4185 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4187 with gGameSettings
do
4189 if (Length(P
) > 1) and
4190 ((P
[1] = '1') or (P
[1] = '0')) then
4192 if (P
[1][1] = '1') then
4193 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4195 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4198 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4199 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4201 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4203 if g_Game_IsNet
then MH_SEND_GameSettings
;
4206 else if cmd
= 'g_gamemode' then
4208 a
:= g_Game_TextToMode(P
[1]);
4209 if a
= GM_SINGLE
then a
:= GM_COOP
;
4210 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4212 gSwitchGameMode
:= a
;
4213 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4214 (gState
= STATE_INTERSINGLE
) then
4215 gSwitchGameMode
:= GM_SINGLE
;
4217 gGameSettings
.GameMode
:= gSwitchGameMode
;
4219 if gSwitchGameMode
= gGameSettings
.GameMode
then
4220 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4221 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4223 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4224 [g_Game_ModeToText(gGameSettings
.GameMode
),
4225 g_Game_ModeToText(gSwitchGameMode
)]));
4227 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4229 with gGameSettings
do
4231 if (Length(P
) > 1) and
4232 ((P
[1] = '1') or (P
[1] = '0')) then
4234 if (P
[1][1] = '1') then
4235 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4237 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4240 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4241 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4243 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4244 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4246 if g_Game_IsNet
then MH_SEND_GameSettings
;
4249 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4251 with gGameSettings
do
4253 if (Length(P
) > 1) and
4254 ((P
[1] = '1') or (P
[1] = '0')) then
4256 if (P
[1][1] = '1') then
4257 Options
:= Options
or GAME_OPTION_MONSTERS
4259 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4262 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4263 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4265 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4266 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4268 if g_Game_IsNet
then MH_SEND_GameSettings
;
4271 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4273 with gGameSettings
do
4275 if (Length(P
) > 1) and
4276 ((P
[1] = '1') or (P
[1] = '0')) then
4278 if (P
[1][1] = '1') then
4279 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4281 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4284 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4285 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4287 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4289 if g_Game_IsNet
then MH_SEND_GameSettings
;
4292 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4294 with gGameSettings
do
4296 if (Length(P
) > 1) and
4297 ((P
[1] = '1') or (P
[1] = '0')) then
4299 if (P
[1][1] = '1') then
4300 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4302 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4305 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4306 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4308 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4310 if g_Game_IsNet
then MH_SEND_GameSettings
;
4313 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4315 if Length(P
) > 1 then
4317 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4318 gGameSettings
.WarmupTime
:= 30
4320 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4323 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4324 [gGameSettings
.WarmupTime
]));
4325 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4327 else if cmd
= 'net_interp' then
4329 if (Length(P
) > 1) then
4330 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4332 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4333 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4334 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4335 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4338 else if cmd
= 'net_forceplayerupdate' then
4340 if (Length(P
) > 1) and
4341 ((P
[1] = '1') or (P
[1] = '0')) then
4342 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4344 if NetForcePlayerUpdate
then
4345 g_Console_Add('net_forceplayerupdate = 1')
4347 g_Console_Add('net_forceplayerupdate = 0');
4348 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4349 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4350 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4353 else if cmd
= 'net_predictself' then
4355 if (Length(P
) > 1) and
4356 ((P
[1] = '1') or (P
[1] = '0')) then
4357 NetPredictSelf
:= (P
[1][1] = '1');
4359 if NetPredictSelf
then
4360 g_Console_Add('net_predictself = 1')
4362 g_Console_Add('net_predictself = 0');
4363 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4364 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4365 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4368 else if cmd
= 'sv_name' then
4370 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4372 NetServerName
:= P
[1];
4373 if Length(NetServerName
) > 64 then
4374 SetLength(NetServerName
, 64);
4375 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4379 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4381 else if cmd
= 'sv_passwd' then
4383 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4385 NetPassword
:= P
[1];
4386 if Length(NetPassword
) > 24 then
4387 SetLength(NetPassword
, 24);
4388 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4392 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4394 else if cmd
= 'sv_maxplrs' then
4396 if (Length(P
) > 1) then
4398 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4399 if g_Game_IsServer
and g_Game_IsNet
then
4402 for a
:= 0 to High(NetClients
) do
4403 if NetClients
[a
].Used
then
4406 if b
> NetMaxClients
then
4408 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4409 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4410 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4411 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4414 if NetUseMaster
then
4419 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4421 else if cmd
= 'sv_public' then
4423 if (Length(P
) > 1) then
4425 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4426 if g_Game_IsServer
and g_Game_IsNet
then
4427 if NetUseMaster
then
4429 if NetMPeer
= nil then
4430 if not g_Net_Slist_Connect() then
4431 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4432 g_Net_Slist_Update();
4435 if NetMPeer
<> nil then
4436 g_Net_Slist_Disconnect();
4439 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4441 else if cmd
= 'sv_intertime' then
4443 if (Length(P
) > 1) then
4444 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4446 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4448 else if cmd
= 'p1_name' then
4450 if (Length(P
) > 1) and gGameOn
then
4452 if g_Game_IsClient
then
4454 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4455 MC_SEND_PlayerSettings
;
4458 if gPlayer1
<> nil then
4460 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4461 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4464 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4467 else if cmd
= 'p2_name' then
4469 if (Length(P
) > 1) and gGameOn
then
4471 if g_Game_IsClient
then
4473 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4474 MC_SEND_PlayerSettings
;
4477 if gPlayer2
<> nil then
4479 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4480 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4483 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4486 else if cmd
= 'p1_color' then
4488 if Length(P
) > 3 then
4489 if g_Game_IsClient
then
4491 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4492 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4493 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4494 MC_SEND_PlayerSettings
;
4497 if gPlayer1
<> nil then
4499 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4500 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4501 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4502 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4505 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4506 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4507 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4509 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4511 if Length(P
) > 3 then
4512 if g_Game_IsClient
then
4514 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4515 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4516 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4517 MC_SEND_PlayerSettings
;
4520 if gPlayer2
<> nil then
4522 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4523 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4524 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4525 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4528 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4529 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4530 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4532 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4534 if cmd
= 'r_showtime' then
4536 if (Length(P
) > 1) and
4537 ((P
[1] = '1') or (P
[1] = '0')) then
4538 gShowTime
:= (P
[1][1] = '1');
4541 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4543 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4545 else if cmd
= 'r_showscore' then
4547 if (Length(P
) > 1) and
4548 ((P
[1] = '1') or (P
[1] = '0')) then
4549 gShowGoals
:= (P
[1][1] = '1');
4552 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4554 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4556 else if cmd
= 'r_showstat' then
4558 if (Length(P
) > 1) and
4559 ((P
[1] = '1') or (P
[1] = '0')) then
4560 gShowStat
:= (P
[1][1] = '1');
4563 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4565 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4567 else if cmd
= 'r_showkillmsg' then
4569 if (Length(P
) > 1) and
4570 ((P
[1] = '1') or (P
[1] = '0')) then
4571 gShowKillMsg
:= (P
[1][1] = '1');
4573 if gShowKillMsg
then
4574 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4576 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4578 else if cmd
= 'r_showlives' then
4580 if (Length(P
) > 1) and
4581 ((P
[1] = '1') or (P
[1] = '0')) then
4582 gShowLives
:= (P
[1][1] = '1');
4585 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4587 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4589 else if cmd
= 'r_showspect' then
4591 if (Length(P
) > 1) and
4592 ((P
[1] = '1') or (P
[1] = '0')) then
4593 gSpectHUD
:= (P
[1][1] = '1');
4596 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4598 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4600 else if cmd
= 'r_showping' then
4602 if (Length(P
) > 1) and
4603 ((P
[1] = '1') or (P
[1] = '0')) then
4604 gShowPing
:= (P
[1][1] = '1');
4607 g_Console_Add(_lc
[I_MSG_PING_ON
])
4609 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4611 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4613 if Length(P
) > 1 then
4615 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4616 gGameSettings
.GoalLimit
:= 0
4621 if gGameSettings
.GameMode
= GM_DM
then
4623 stat
:= g_Player_GetStats();
4625 for a
:= 0 to High(stat
) do
4626 if stat
[a
].Frags
> b
then
4630 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4632 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4635 if g_Game_IsNet
then MH_SEND_GameSettings
;
4638 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4640 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4642 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4643 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4645 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4646 [gGameSettings
.TimeLimit
div 3600,
4647 (gGameSettings
.TimeLimit
div 60) mod 60,
4648 gGameSettings
.TimeLimit
mod 60]));
4649 if g_Game_IsNet
then MH_SEND_GameSettings
;
4651 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4653 if Length(P
) > 1 then
4655 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4656 gGameSettings
.MaxLives
:= 0
4660 stat
:= g_Player_GetStats();
4662 for a
:= 0 to High(stat
) do
4663 if stat
[a
].Lives
> b
then
4665 gGameSettings
.MaxLives
:=
4666 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4670 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4671 [gGameSettings
.MaxLives
]));
4672 if g_Game_IsNet
then MH_SEND_GameSettings
;
4677 procedure DebugCommands(P
: SArray
);
4683 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4686 cmd
:= LowerCase(P
[0]);
4687 if cmd
= 'd_window' then
4689 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4690 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4691 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4692 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4693 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4695 else if cmd
= 'd_sounds' then
4697 if (Length(P
) > 1) and
4698 ((P
[1] = '1') or (P
[1] = '0')) then
4699 g_Debug_Sounds
:= (P
[1][1] = '1');
4701 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4703 else if cmd
= 'd_frames' then
4705 if (Length(P
) > 1) and
4706 ((P
[1] = '1') or (P
[1] = '0')) then
4707 g_Debug_Frames
:= (P
[1][1] = '1');
4709 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4711 else if cmd
= 'd_winmsg' then
4713 if (Length(P
) > 1) and
4714 ((P
[1] = '1') or (P
[1] = '0')) then
4715 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4717 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4719 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4721 if (Length(P
) > 1) and
4722 ((P
[1] = '1') or (P
[1] = '0')) then
4723 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4725 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4727 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4729 if Length(P
) > 1 then
4731 '0': g_debug_BotAIOff
:= 0;
4732 '1': g_debug_BotAIOff
:= 1;
4733 '2': g_debug_BotAIOff
:= 2;
4734 '3': g_debug_BotAIOff
:= 3;
4737 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4739 else if cmd
= 'd_monster' then
4741 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4742 if Length(P
) < 2 then
4744 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4745 g_Console_Add('ID | Name');
4746 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4747 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4750 a
:= StrToIntDef(P
[1], 0);
4751 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4752 a
:= g_Monsters_GetIDByName(P
[1]);
4754 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4755 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4758 with gPlayer1
.Obj
do
4759 b
:= g_Monsters_Create(a
,
4760 X
+ Rect
.X
+ (Rect
.Width
div 2),
4761 Y
+ Rect
.Y
+ Rect
.Height
,
4762 gPlayer1
.Direction
, True);
4763 if (Length(P
) > 2) and (b
>= 0) then
4764 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4768 else if (cmd
= 'd_health') then
4770 if (Length(P
) > 1) and
4771 ((P
[1] = '1') or (P
[1] = '0')) then
4772 g_debug_HealthBar
:= (P
[1][1] = '1');
4774 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4776 else if (cmd
= 'd_player') then
4778 if (Length(P
) > 1) and
4779 ((P
[1] = '1') or (P
[1] = '0')) then
4780 g_debug_Player
:= (P
[1][1] = '1');
4782 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4784 else if (cmd
= 'd_joy') then
4787 g_Console_Add(e_JoystickStateToString(a
));
4791 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4795 procedure GameCheats(P
: SArray
);
4801 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4802 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4804 g_Console_Add('not available');
4810 g_Console_Add('where is the player?!');
4813 cmd
:= LowerCase(P
[0]);
4817 plr
.GodMode
:= not plr
.GodMode
;
4818 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4821 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4822 if cmd
= 'give' then
4824 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4825 for f
:= 1 to High(P
) do
4827 cmd
:= LowerCase(P
[f
]);
4828 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4829 if (cmd
= 'all') or (cmd
= 'weapons') then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4830 if cmd
= 'exit' then
4832 if gTriggers
<> nil then
4834 for a
:= 0 to High(gTriggers
) do
4836 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4838 g_Console_Add('player left the map');
4839 gExitByTrigger
:= True;
4840 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4847 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4848 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got jetpack'); continue
; end;
4849 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got envirosuit'); continue
; end;
4850 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got berserk pack'); continue
; end;
4851 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4856 if cmd
= 'open' then
4858 g_Console_Add('player activated sesame');
4859 g_Triggers_OpenAll();
4866 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4870 if cmd
= 'noclip' then
4873 g_Console_Add('wall hardeness adjusted');
4877 if cmd
= 'notarget' then
4879 plr
.NoTarget
:= not plr
.NoTarget
;
4880 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4884 if cmd
= 'noreload' then
4886 plr
.NoReload
:= not plr
.NoReload
;
4887 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4891 if cmd
= 'speedy' then
4893 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4894 g_Console_Add('speed adjusted');
4898 if cmd
= 'jumpy' then
4900 VEL_JUMP
:= 30-VEL_JUMP
;
4901 g_Console_Add('jump height adjusted');
4905 if cmd
= 'automap' then
4907 gShowMap
:= not gShowMap
;
4908 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4912 if cmd
= 'aimline' then
4914 gAimLine
:= not gAimLine
;
4915 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4920 procedure GameCommands(P
: SArray
);
4926 pl
: pTNetClient
= nil;
4933 cmd
:= LowerCase(P
[0]);
4935 if (cmd
= 'quit') or
4942 else if cmd
= 'pause' then
4944 if (g_ActiveWindow
= nil) then
4945 g_Game_Pause(not gPause
);
4947 else if cmd
= 'endgame' then
4948 gExit
:= EXIT_SIMPLE
4949 else if cmd
= 'restart' then
4951 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4953 if g_Game_IsClient
then
4955 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4960 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4962 else if cmd
= 'kick' then
4964 if g_Game_IsServer
then
4966 if Length(P
) < 2 then
4968 g_Console_Add('kick <name>');
4973 g_Console_Add('kick <name>');
4977 if g_Game_IsNet
then
4978 pl
:= g_Net_Client_ByName(P
[1]);
4981 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4982 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4983 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4984 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4985 if NetUseMaster
then
4987 end else if gPlayers
<> nil then
4988 for a
:= Low(gPlayers
) to High(gPlayers
) do
4989 if gPlayers
[a
] <> nil then
4990 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4992 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4993 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4995 gPlayers
[a
].Lives
:= 0;
4996 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4997 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4998 g_Player_Remove(gPlayers
[a
].UID
);
4999 if NetUseMaster
then
5001 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5005 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5007 else if cmd
= 'kick_id' then
5009 if g_Game_IsServer
and g_Game_IsNet
then
5011 if Length(P
) < 2 then
5013 g_Console_Add('kick_id <client ID>');
5018 g_Console_Add('kick_id <client ID>');
5022 a
:= StrToIntDef(P
[1], 0);
5023 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5025 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5027 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5028 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5029 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5030 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5031 if NetUseMaster
then
5036 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5038 else if cmd
= 'ban' then
5040 if g_Game_IsServer
and g_Game_IsNet
then
5042 if Length(P
) < 2 then
5044 g_Console_Add('ban <name>');
5049 g_Console_Add('ban <name>');
5053 pl
:= g_Net_Client_ByName(P
[1]);
5056 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5057 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5058 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5059 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5060 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5061 if NetUseMaster
then
5064 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5066 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5068 else if cmd
= 'ban_id' then
5070 if g_Game_IsServer
and g_Game_IsNet
then
5072 if Length(P
) < 2 then
5074 g_Console_Add('ban_id <client ID>');
5079 g_Console_Add('ban_id <client ID>');
5083 a
:= StrToIntDef(P
[1], 0);
5084 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5085 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5087 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5088 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5089 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5090 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5091 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5092 if NetUseMaster
then
5096 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5098 else if cmd
= 'permban' then
5100 if g_Game_IsServer
and g_Game_IsNet
then
5102 if Length(P
) < 2 then
5104 g_Console_Add('permban <name>');
5109 g_Console_Add('permban <name>');
5113 pl
:= g_Net_Client_ByName(P
[1]);
5116 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5117 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5118 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5119 g_Net_SaveBanList();
5120 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5121 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5122 if NetUseMaster
then
5125 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5127 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5129 else if cmd
= 'permban_id' then
5131 if g_Game_IsServer
and g_Game_IsNet
then
5133 if Length(P
) < 2 then
5135 g_Console_Add('permban_id <client ID>');
5140 g_Console_Add('permban_id <client ID>');
5144 a
:= StrToIntDef(P
[1], 0);
5145 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5146 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5148 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5149 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5150 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5151 g_Net_SaveBanList();
5152 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5153 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5154 if NetUseMaster
then
5158 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5160 else if cmd
= 'unban' then
5162 if g_Game_IsServer
and g_Game_IsNet
then
5164 if Length(P
) < 2 then
5166 g_Console_Add('unban <IP Address>');
5171 g_Console_Add('unban <IP Address>');
5175 if g_Net_UnbanHost(P
[1]) then
5177 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5178 g_Net_SaveBanList();
5180 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5182 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5184 else if cmd
= 'clientlist' then
5186 if g_Game_IsServer
and g_Game_IsNet
then
5189 if NetClients
<> nil then
5190 for a
:= Low(NetClients
) to High(NetClients
) do
5191 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5193 plr
:= g_Player_Get(NetClients
[a
].Player
);
5194 if plr
= nil then continue
;
5196 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5197 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5200 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5202 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5204 else if cmd
= 'connect' then
5206 if (NetMode
= NET_NONE
) then
5208 if Length(P
) < 2 then
5210 g_Console_Add('connect <IP> [port] [password]');
5215 g_Console_Add('connect <IP> [port] [password]');
5219 if Length(P
) > 2 then
5220 prt
:= StrToIntDef(P
[2], 25666)
5224 if Length(P
) > 3 then
5229 g_Game_StartClient(P
[1], prt
, pw
);
5232 else if cmd
= 'disconnect' then
5234 if (NetMode
= NET_CLIENT
) then
5237 else if cmd
= 'reconnect' then
5239 if (NetMode
= NET_SERVER
) then
5242 if (NetMode
= NET_CLIENT
) then
5245 gExit
:= EXIT_SIMPLE
;
5249 //TODO: Use last successful password to reconnect, instead of ''
5250 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5252 else if (cmd
= 'addbot') or
5253 (cmd
= 'bot_add') then
5255 if Length(P
) > 1 then
5256 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5258 g_Bot_Add(TEAM_NONE
, 2);
5260 else if cmd
= 'bot_addlist' then
5262 if Length(P
) > 1 then
5263 if Length(P
) = 2 then
5264 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5266 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5268 else if cmd
= 'bot_removeall' then
5270 else if cmd
= 'chat' then
5272 if g_Game_IsNet
then
5274 if Length(P
) > 1 then
5276 for a
:= 1 to High(P
) do
5277 chstr
:= chstr
+ P
[a
] + ' ';
5279 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5281 if Length(chstr
) < 1 then
5283 g_Console_Add('chat <text>');
5287 chstr
:= b_Text_Format(chstr
);
5288 if g_Game_IsClient
then
5289 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5291 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5294 g_Console_Add('chat <text>');
5296 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5298 else if cmd
= 'teamchat' then
5300 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5302 if Length(P
) > 1 then
5304 for a
:= 1 to High(P
) do
5305 chstr
:= chstr
+ P
[a
] + ' ';
5307 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5309 if Length(chstr
) < 1 then
5311 g_Console_Add('teamchat <text>');
5315 chstr
:= b_Text_Format(chstr
);
5316 if g_Game_IsClient
then
5317 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5319 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5320 gPlayer1Settings
.Team
);
5323 g_Console_Add('teamchat <text>');
5325 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5327 else if cmd
= 'game' then
5329 if gGameSettings
.GameType
<> GT_NONE
then
5331 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5334 if Length(P
) = 1 then
5336 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5339 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5340 P
[1] := addWadExtension(P
[1]);
5341 if FileExists(MapsDir
+ P
[1]) then
5343 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5344 if Length(P
) < 3 then
5347 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5350 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5352 if g_Map_Exist(MapsDir
+ s
) then
5354 // Çàïóñêàåì ñâîþ èãðó
5356 with gGameSettings
do
5358 GameMode
:= g_Game_TextToMode(gcGameMode
);
5359 if gSwitchGameMode
<> GM_NONE
then
5360 GameMode
:= gSwitchGameMode
;
5361 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5362 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5364 if Length(P
) >= 4 then
5365 b
:= StrToIntDef(P
[3], 1);
5366 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5367 GoalLimit
, MaxLives
, Options
, b
);
5372 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5374 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5376 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5378 else if cmd
= 'host' then
5380 if gGameSettings
.GameType
<> GT_NONE
then
5382 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5385 if Length(P
) < 4 then
5387 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5390 if not StrToIp(P
[1], listen
) then
5392 prt
:= StrToIntDef(P
[2], 25666);
5394 P
[3] := addWadExtension(P
[3]);
5395 if FileExists(MapsDir
+ P
[3]) then
5397 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5398 if Length(P
) < 5 then
5401 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5404 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5406 if g_Map_Exist(MapsDir
+ s
) then
5408 // Çàïóñêàåì ñâîþ èãðó
5410 with gGameSettings
do
5412 GameMode
:= g_Game_TextToMode(gcGameMode
);
5413 if gSwitchGameMode
<> GM_NONE
then
5414 GameMode
:= gSwitchGameMode
;
5415 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5416 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5418 if Length(P
) >= 6 then
5419 b
:= StrToIntDef(P
[5], 0);
5420 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5421 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5426 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5428 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5430 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5432 else if cmd
= 'map' then
5434 if Length(P
) = 1 then
5436 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5438 g_Console_Add(cmd
+ ' <MAP>');
5439 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5441 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5443 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5445 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5446 if Length(P
) < 3 then
5448 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5449 s
:= UpperCase(P
[1]);
5450 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5451 begin // Êàðòà íàøëàñü
5452 gExitByTrigger
:= False;
5454 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5456 gExit
:= EXIT_ENDLEVELCUSTOM
;
5458 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5459 g_Game_ChangeMap(s
);
5462 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5463 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5464 P
[1] := addWadExtension(P
[1]);
5465 if FileExists(MapsDir
+ P
[1]) then
5467 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5469 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5471 s
:= P
[1] + ':\' + P
[2];
5473 if g_Map_Exist(MapsDir
+ s
) then
5475 gExitByTrigger
:= False;
5477 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5479 gExit
:= EXIT_ENDLEVELCUSTOM
;
5481 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5482 g_Game_ChangeMap(s
);
5485 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5487 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5489 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5493 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5494 P
[1] := addWadExtension(P
[1]);
5495 if FileExists(MapsDir
+ P
[1]) then
5498 P
[2] := UpperCase(P
[2]);
5499 s
:= P
[1] + ':\' + P
[2];
5501 if g_Map_Exist(MapsDir
+ s
) then
5502 begin // Íàøëè êàðòó
5503 gExitByTrigger
:= False;
5505 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5507 gExit
:= EXIT_ENDLEVELCUSTOM
;
5509 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5510 g_Game_ChangeMap(s
);
5512 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5514 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5517 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5519 else if cmd
= 'nextmap' then
5521 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5522 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5525 if Length(P
) = 1 then
5527 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5529 g_Console_Add(cmd
+ ' <MAP>');
5530 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5533 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5538 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5540 if Length(P
) < 3 then
5542 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5543 s
:= UpperCase(P
[1]);
5544 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5545 begin // Êàðòà íàøëàñü
5546 gExitByTrigger
:= False;
5551 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5552 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5553 P
[1] := addWadExtension(P
[1]);
5554 if FileExists(MapsDir
+ P
[1]) then
5556 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5558 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5560 s
:= P
[1] + ':\' + P
[2];
5562 if g_Map_Exist(MapsDir
+ s
) then
5563 begin // Óñòàíàâëèâàåì êàðòó
5564 gExitByTrigger
:= False;
5569 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5571 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5573 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5577 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5578 P
[1] := addWadExtension(P
[1]);
5579 if FileExists(MapsDir
+ P
[1]) then
5582 P
[2] := UpperCase(P
[2]);
5583 s
:= P
[1] + ':\' + P
[2];
5585 if g_Map_Exist(MapsDir
+ s
) then
5586 begin // Íàøëè êàðòó
5587 gExitByTrigger
:= False;
5591 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5593 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5596 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5599 if gNextMap
= '' then
5600 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5602 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5605 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5608 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5610 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5612 gExitByTrigger
:= False;
5613 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5614 if (gNextMap
= '') and (gTriggers
<> nil) then
5615 for a
:= 0 to High(gTriggers
) do
5616 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5618 gExitByTrigger
:= True;
5619 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5622 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5623 if gNextMap
= '' then
5624 gNextMap
:= g_Game_GetNextMap();
5625 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5626 if Pos(':\', gNextMap
) = 0 then
5627 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5630 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5631 if g_Map_Exist(MapsDir
+ s
) then
5632 gExit
:= EXIT_ENDLEVELCUSTOM
5634 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5636 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5638 else if (cmd
= 'event') then
5640 if (Length(P
) <= 1) then
5642 for a
:= 0 to High(gEvents
) do
5643 if gEvents
[a
].Command
= '' then
5644 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5646 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5649 if (Length(P
) = 2) then
5651 for a
:= 0 to High(gEvents
) do
5652 if gEvents
[a
].Name
= P
[1] then
5653 if gEvents
[a
].Command
= '' then
5654 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5656 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5659 for a
:= 0 to High(gEvents
) do
5660 if gEvents
[a
].Name
= P
[1] then
5662 gEvents
[a
].Command
:= '';
5663 for b
:= 2 to High(P
) do
5664 if Pos(' ', P
[b
]) = 0 then
5665 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5667 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5668 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5672 // Êîìàíäû Ñâîåé èãðû:
5673 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5675 if cmd
= 'bot_addred' then
5677 if Length(P
) > 1 then
5678 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5680 g_Bot_Add(TEAM_RED
, 2);
5682 else if cmd
= 'bot_addblue' then
5684 if Length(P
) > 1 then
5685 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5687 g_Bot_Add(TEAM_BLUE
, 2);
5689 else if cmd
= 'suicide' then
5693 if g_Game_IsClient
then
5694 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5697 if gPlayer1
<> nil then
5698 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5699 if gPlayer2
<> nil then
5700 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5704 else if cmd
= 'spectate' then
5710 else if cmd
= 'say' then
5712 if g_Game_IsServer
and g_Game_IsNet
then
5714 if Length(P
) > 1 then
5717 for a
:= 1 to High(P
) do
5718 chstr
:= chstr
+ P
[a
] + ' ';
5720 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5722 if Length(chstr
) < 1 then
5724 g_Console_Add('say <text>');
5728 chstr
:= b_Text_Format(chstr
);
5729 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5731 else g_Console_Add('say <text>');
5733 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5735 else if cmd
= 'tell' then
5737 if g_Game_IsServer
and g_Game_IsNet
then
5739 if (Length(P
) > 2) and (P
[1] <> '') then
5742 for a
:= 2 to High(P
) do
5743 chstr
:= chstr
+ P
[a
] + ' ';
5745 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5747 if Length(chstr
) < 1 then
5749 g_Console_Add('tell <playername> <text>');
5753 pl
:= g_Net_Client_ByName(P
[1]);
5755 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5757 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5759 else g_Console_Add('tell <playername> <text>');
5761 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5763 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5765 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5767 // Äîïîëíèòåëüíîå âðåìÿ:
5768 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5770 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5771 [gGameSettings
.TimeLimit
div 3600,
5772 (gGameSettings
.TimeLimit
div 60) mod 60,
5773 gGameSettings
.TimeLimit
mod 60]));
5774 if g_Game_IsNet
then MH_SEND_GameSettings
;
5776 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5778 if (Length(P
) <= 1) then
5779 g_Console_Add('rcon_password <password>')
5781 MC_SEND_RCONPassword(P
[1]);
5783 else if cmd
= 'rcon' then
5785 if g_Game_IsClient
then
5787 if Length(P
) > 1 then
5790 for a
:= 1 to High(P
) do
5791 chstr
:= chstr
+ P
[a
] + ' ';
5793 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5795 if Length(chstr
) < 1 then
5797 g_Console_Add('rcon <command>');
5801 MC_SEND_RCONCommand(chstr
);
5803 else g_Console_Add('rcon <command>');
5806 else if cmd
= 'ready' then
5808 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5809 gLMSRespawnTime
:= gTime
+ 100;
5811 else if (cmd
= 'callvote') and g_Game_IsNet
then
5813 if Length(P
) > 1 then
5816 for a
:= 1 to High(P
) do begin
5817 if a
> 1 then chstr
:= chstr
+ ' ';
5818 chstr
:= chstr
+ P
[a
];
5821 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5823 if Length(chstr
) < 1 then
5825 g_Console_Add('callvote <command>');
5829 if g_Game_IsClient
then
5830 MC_SEND_Vote(True, chstr
)
5832 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5833 g_Console_Process('vote', True);
5836 g_Console_Add('callvote <command>');
5838 else if (cmd
= 'vote') and g_Game_IsNet
then
5840 if g_Game_IsClient
then
5842 else if gVoteInProgress
then
5844 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5845 a
:= Floor((NetClientCount
+1)/2.0) + 1
5847 a
:= Floor(NetClientCount
/2.0) + 1;
5852 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5853 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5859 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5860 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5868 procedure g_TakeScreenShot();
5876 if e_NoGraphics
then Exit
;
5877 ssdir
:= GameDir
+'/screenshots';
5878 if not findFileCI(ssdir
, true) then
5880 // try to create dir
5885 if not findFileCI(ssdir
, true) then exit
; // alas
5888 for a
:= 1 to High(Word) do
5890 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5892 if findFileCI(t
, true) then continue
;
5893 if not findFileCI(FileName
) then
5896 st
:= createDiskFile(FileName
);
5898 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5903 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5911 procedure g_Game_InGameMenu(Show
: Boolean);
5913 if (g_ActiveWindow
= nil) and Show
then
5915 if gGameSettings
.GameType
= GT_SINGLE
then
5916 g_GUI_ShowWindow('GameSingleMenu')
5919 if g_Game_IsClient
then
5920 g_GUI_ShowWindow('GameClientMenu')
5922 if g_Game_IsNet
then
5923 g_GUI_ShowWindow('GameServerMenu')
5925 g_GUI_ShowWindow('GameCustomMenu');
5927 g_Sound_PlayEx('MENU_OPEN');
5929 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5930 if (not g_Game_IsNet
) then
5934 if (g_ActiveWindow
<> nil) and (not Show
) then
5936 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5937 if (not g_Game_IsNet
) then
5938 g_Game_Pause(False);
5942 procedure g_Game_Pause(Enable
: Boolean);
5947 if gPause
= Enable
then
5950 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5954 g_Game_PauseAllSounds(Enable
);
5957 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5962 if gTriggers
<> nil then
5963 for i
:= 0 to High(gTriggers
) do
5964 with gTriggers
[i
] do
5965 if (TriggerType
= TRIGGER_SOUND
) and
5967 Sound
.IsPlaying() then
5969 Sound
.Pause(Enable
);
5973 if gPlayers
<> nil then
5974 for i
:= 0 to High(gPlayers
) do
5975 if gPlayers
[i
] <> nil then
5976 gPlayers
[i
].PauseSounds(Enable
);
5979 if gMusic
<> nil then
5980 gMusic
.Pause(Enable
);
5983 procedure g_Game_StopAllSounds(all
: Boolean);
5987 if gTriggers
<> nil then
5988 for i
:= 0 to High(gTriggers
) do
5989 with gTriggers
[i
] do
5990 if (TriggerType
= TRIGGER_SOUND
) and
5994 if gMusic
<> nil then
6001 procedure g_Game_UpdateTriggerSounds();
6005 if gTriggers
<> nil then
6006 for i
:= 0 to High(gTriggers
) do
6007 with gTriggers
[i
] do
6008 if (TriggerType
= TRIGGER_SOUND
) and
6011 Sound
.IsPlaying() then
6013 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6014 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6016 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6017 Sound
.SetVolume(Data
.Volume
/255.0);
6020 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6024 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6027 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6032 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6037 if gSpectMode
<> SPECT_PLAYERS
then
6039 if gSpectPID1
= UID
then
6044 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6051 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6056 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6061 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6066 if gSpectMode
<> SPECT_PLAYERS
then
6068 Pl
:= g_Player_Get(gSpectPID1
);
6069 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6074 if gSpectViewTwo
then
6076 Pl
:= g_Player_Get(gSpectPID2
);
6077 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6085 procedure g_Game_Message(Msg
: string; Time
: Word);
6087 MessageText
:= b_Text_Format(Msg
);
6088 MessageTime
:= Time
;
6091 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6100 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6104 if goodsnd
[a
].IsPlaying() then
6107 goodsnd
[Random(4)].Play();
6110 procedure g_Game_Announce_KillCombo(Param
: Integer);
6117 UID
:= Param
and $FFFF;
6122 Pl
:= g_Player_Get(UID
);
6131 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6135 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6139 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6143 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6151 if not g_Game_IsWatchedPlayer(UID
) then
6154 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6158 if killsnd
[n
].IsPlaying() then
6163 procedure g_Game_StartVote(Command
, Initiator
: string);
6167 if not gVotesEnabled
then Exit
;
6168 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6169 if gVoteInProgress
or gVotePassed
then
6171 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6172 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6175 gVoteInProgress
:= True;
6176 gVotePassed
:= False;
6177 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6180 gVoteCommand
:= Command
;
6182 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6183 Need
:= Floor((NetClientCount
+1)/2.0)+1
6185 Need
:= Floor(NetClientCount
/2.0)+1;
6186 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6187 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6190 procedure g_Game_CheckVote
;
6194 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6195 if not gVoteInProgress
then Exit
;
6197 if (gTime
>= gVoteTimer
) then
6199 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6200 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6202 Need
:= Floor(NetClientCount
/2.0) + 1;
6203 if gVoteCount
>= Need
then
6205 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6206 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6207 gVotePassed
:= True;
6208 gVoteCmdTimer
:= gTime
+ 5000;
6212 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6213 MH_SEND_VoteEvent(NET_VE_FAILED
);
6215 if NetClients
<> nil then
6216 for I
:= Low(NetClients
) to High(NetClients
) do
6217 if NetClients
[i
].Used
then
6218 NetClients
[i
].Voted
:= False;
6219 gVoteInProgress
:= False;
6225 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6226 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6228 Need
:= Floor(NetClientCount
/2.0) + 1;
6229 if gVoteCount
>= Need
then
6231 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6232 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6233 gVoteInProgress
:= False;
6234 gVotePassed
:= True;
6235 gVoteCmdTimer
:= gTime
+ 5000;
6238 if NetClients
<> nil then
6239 for I
:= Low(NetClients
) to High(NetClients
) do
6240 if NetClients
[i
].Used
then
6241 NetClients
[i
].Voted
:= False;
6246 procedure g_Game_LoadMapList(FileName
: string);
6254 if not FileExists(FileName
) then Exit
;
6256 AssignFile(ListFile
, FileName
);
6258 while not EOF(ListFile
) do
6260 ReadLn(ListFile
, s
);
6263 if s
= '' then Continue
;
6265 SetLength(MapList
, Length(MapList
)+1);
6266 MapList
[High(MapList
)] := s
;
6268 CloseFile(ListFile
);
6271 procedure g_Game_SetDebugMode();
6274 // ×èòû (äàæå â ñâîåé èãðå):
6278 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6282 if Length(LoadingStat
.Msgs
) = 0 then
6288 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6289 if NextMsg
= Length(Msgs
) then
6291 for i
:= 0 to High(Msgs
)-1 do
6292 Msgs
[i
] := Msgs
[i
+1];
6300 Msgs
[NextMsg
-1] := Text;
6306 g_ActiveWindow
:= nil;
6311 procedure g_Game_StepLoading();
6317 if (ShowCount
> LOADING_SHOW_STEP
) then
6325 procedure g_Game_ClearLoading();
6334 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6335 if len
< 1 then len
:= 1;
6336 SetLength(Msgs
, len
);
6337 for len
:= Low(Msgs
) to High(Msgs
) do
6343 procedure Parse_Params(var pars
: TParamStrValues
);
6350 while i
<= ParamCount
do
6353 if (s
[1] = '-') and (Length(s
) > 1) then
6355 if (s
[2] = '-') and (Length(s
) > 2) then
6356 begin // Îäèíî÷íûé ïàðàìåòð
6357 SetLength(pars
, Length(pars
) + 1);
6358 with pars
[High(pars
)] do
6360 Name
:= LowerCase(s
);
6365 if (i
< ParamCount
) then
6366 begin // Ïàðàìåòð ñî çíà÷åíèåì
6368 SetLength(pars
, Length(pars
) + 1);
6369 with pars
[High(pars
)] do
6371 Name
:= LowerCase(s
);
6372 Value
:= LowerCase(ParamStr(i
));
6381 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6386 for i
:= 0 to High(pars
) do
6387 if pars
[i
].Name
= aName
then
6389 Result
:= pars
[i
].Value
;
6394 procedure g_Game_Process_Params();
6396 pars
: TParamStrValues
;
6399 LimT
, LimS
: Integer;
6410 s
:= Find_Param_Value(pars
, '--debug');
6412 g_Game_SetDebugMode();
6414 // Connect when game loads
6415 ip
:= Find_Param_Value(pars
, '-connect');
6419 s
:= Find_Param_Value(pars
, '-port');
6420 if (s
= '') or not TryStrToInt(s
, Port
) then
6423 s
:= Find_Param_Value(pars
, '-pw');
6425 g_Game_StartClient(ip
, Port
, s
);
6429 // Start map when game loads:
6430 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6431 if isWadPath(map
) then
6434 s
:= Find_Param_Value(pars
, '-gm');
6435 GMode
:= g_Game_TextToMode(s
);
6436 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6437 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6440 s
:= Find_Param_Value(pars
, '-limt');
6441 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6447 s
:= Find_Param_Value(pars
, '-lims');
6448 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6454 s
:= Find_Param_Value(pars
, '-lives');
6455 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6461 s
:= Find_Param_Value(pars
, '-opt');
6463 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6465 Opt
:= StrToIntDef(s
, 0);
6467 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6470 s
:= Find_Param_Value(pars
, '--close');
6474 // Delete test map after play:
6475 s
:= Find_Param_Value(pars
, '--testdelete');
6478 gMapToDelete
:= MapsDir
+ map
;
6479 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6483 // Delete temporary WAD after play:
6484 s
:= Find_Param_Value(pars
, '--tempdelete');
6487 gMapToDelete
:= MapsDir
+ map
;
6488 gTempDelete
:= True;
6491 // Number of players:
6492 s
:= Find_Param_Value(pars
, '-pl');
6496 n
:= StrToIntDef(s
, 1);
6499 s
:= Find_Param_Value(pars
, '-port');
6500 if (s
= '') or not TryStrToInt(s
, Port
) then
6501 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6503 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6506 // Execute script when game loads:
6507 s
:= Find_Param_Value(pars
, '-exec');
6510 if Pos(':\', s
) = 0 then
6511 s
:= GameDir
+ '/' + s
;
6516 if IOResult
<> 0 then
6518 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6519 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6523 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6524 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6529 if IOResult
<> 0 then
6531 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6532 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6536 if Pos('#', s
) <> 1 then // script comment
6537 g_Console_Process(s
, True);