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("Scripts Init")');
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 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1224 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1225 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1229 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1233 if (plr
= nil) then exit
;
1234 if (p2hack
) then time
:= 1000 else time
:= 1;
1237 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1238 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1239 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1241 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1242 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1243 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1245 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1246 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1247 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1248 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1249 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1250 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1252 // Îñòàëüíûå êëàâèøè:
1253 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1254 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1255 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1256 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1257 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1258 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1259 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1263 procedure g_Game_Update();
1265 Msg
: g_gui
.TMessage
;
1271 // Ïîðà âûêëþ÷àòü èãðó:
1272 if gExit
= EXIT_QUIT
then
1274 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1278 if gExit
= EXIT_QUIT
then
1282 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1285 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1288 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1290 gExit
:= EXIT_SIMPLE
;
1296 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1297 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1298 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1299 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1301 if g_Game_IsNet
and g_Game_IsServer
then
1303 gInterTime
:= gInterTime
+ GAME_TICK
;
1304 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1305 if a
<> gServInterTime
then
1307 gServInterTime
:= a
;
1308 MH_SEND_TimeSync(gServInterTime
);
1312 if (not g_Game_IsClient
) and
1315 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1316 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1317 and (g_ActiveWindow
= nil)
1319 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1322 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1323 g_Game_StopAllSounds(True);
1325 if gMapOnce
then // Ýòî áûë òåñò
1326 gExit
:= EXIT_SIMPLE
1328 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1329 g_Game_ChangeMap(gNextMap
)
1330 else // Ñëåäóþùåé êàðòû íåò
1332 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1334 // Âûõîä â ãëàâíîå ìåíþ:
1336 g_GUI_ShowWindow('MainMenu');
1337 gMusic
.SetByName('MUSIC_MENU');
1339 gState
:= STATE_MENU
;
1342 // Ôèíàëüíàÿ êàðòèíêà:
1343 g_Game_ExecuteEvent('onwadend');
1345 if not gMusic
.SetByName('MUSIC_endmus') then
1346 gMusic
.SetByName('MUSIC_STDENDMUS');
1348 gState
:= STATE_ENDPIC
;
1350 g_Game_ExecuteEvent('ongameend');
1356 if gState
= STATE_INTERTEXT
then
1357 if InterText
.counter
> 0 then
1358 InterText
.counter
:= InterText
.counter
- 1;
1361 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1363 if EndingGameCounter
= 0 then
1365 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1366 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1368 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1370 g_Game_ExecuteEvent('onwadend');
1371 if not gMusic
.SetByName('MUSIC_endmus') then
1372 gMusic
.SetByName('MUSIC_STDENDMUS');
1375 gMusic
.SetByName('MUSIC_ROUNDMUS');
1378 gState
:= STATE_INTERCUSTOM
;
1380 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1382 gMusic
.SetByName('MUSIC_INTERMUS');
1384 gState
:= STATE_INTERSINGLE
;
1386 g_Game_ExecuteEvent('oninter');
1389 DecMin(EndingGameCounter
, 6, 0);
1392 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1394 if gMapOnce
then // Ýòî áûë òåñò
1396 gExit
:= EXIT_SIMPLE
;
1402 g_Serverlist_Control(slCurrent
);
1405 if g_Game_IsNet
then
1406 if not gConsoleShow
then
1407 if not gChatShow
then
1409 if g_ActiveWindow
= nil then
1411 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1412 g_Console_Chat_Switch(False)
1413 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1414 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1415 g_Console_Chat_Switch(True);
1418 if not gChatEnter
then
1419 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1420 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1423 // Ñòàòèñòèêà ïî Tab:
1425 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1426 (gGameSettings
.GameType
<> GT_SINGLE
) and
1427 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1430 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1432 // Âðåìÿ += 28 ìèëëèñåêóíä:
1433 gTime
:= gTime
+ GAME_TICK
;
1435 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1436 if MessageTime
= 0 then
1438 if MessageTime
> 0 then
1439 MessageTime
:= MessageTime
- 1;
1441 if (g_Game_IsServer
) then
1443 // Áûë çàäàí ëèìèò âðåìåíè:
1444 if (gGameSettings
.TimeLimit
> 0) then
1445 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1446 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1451 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1452 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1453 g_Game_RestartRound(gLMSSoftSpawn
);
1455 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1456 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1458 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1460 g_Console_Process(gVoteCommand
);
1462 gVotePassed
:= False;
1465 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1466 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1467 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1468 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1469 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1471 // Áûë çàäàí ëèìèò ïîáåä:
1472 if (gGameSettings
.GoalLimit
> 0) then
1476 if gGameSettings
.GameMode
= GM_DM
then
1477 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1478 for i
:= 0 to High(gPlayers
) do
1479 if gPlayers
[i
] <> nil then
1480 if gPlayers
[i
].Frags
> b
then
1481 b
:= gPlayers
[i
].Frags
;
1484 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1485 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1486 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1489 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1490 if b
>= gGameSettings
.GoalLimit
then
1497 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1498 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1499 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1500 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1502 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1503 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1504 end // if not console
1507 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1512 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1513 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1515 if not gSpectKeyPress
then
1517 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1519 // switch spect mode
1521 SPECT_NONE
: ; // not spectator
1523 SPECT_MAPVIEW
: Inc(gSpectMode
);
1524 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1526 gSpectKeyPress
:= True;
1528 if gSpectMode
= SPECT_MAPVIEW
then
1530 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1531 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1532 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1533 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1534 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1535 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1536 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1537 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1538 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1541 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1542 gSpectKeyPress
:= True;
1544 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1547 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1548 gSpectKeyPress
:= True;
1551 if gSpectMode
= SPECT_PLAYERS
then
1553 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1556 gSpectViewTwo
:= True;
1557 gSpectKeyPress
:= True;
1559 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1561 // remove second view
1562 gSpectViewTwo
:= False;
1563 gSpectKeyPress
:= True;
1565 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1567 // prev player (view 1)
1568 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1569 gSpectKeyPress
:= True;
1571 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1573 // next player (view 1)
1574 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1575 gSpectKeyPress
:= True;
1577 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1579 // prev player (view 2)
1580 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1581 gSpectKeyPress
:= True;
1583 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1585 // next player (view 2)
1586 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1587 gSpectKeyPress
:= True;
1592 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1593 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1594 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1595 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1596 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1597 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1598 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1599 gSpectKeyPress
:= False;
1602 // Îáíîâëÿåì âñå îñòàëüíîå:
1605 g_Triggers_Update();
1607 g_Monsters_Update();
1609 g_Player_UpdateAll();
1610 g_Player_UpdatePhysicalObjects();
1611 if gGameSettings
.GameType
= GT_SERVER
then
1612 if Length(gMonstersSpawned
) > 0 then
1614 for I
:= 0 to High(gMonstersSpawned
) do
1615 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1616 SetLength(gMonstersSpawned
, 0);
1619 if (gSoundTriggerTime
> 8) then
1621 g_Game_UpdateTriggerSounds();
1622 gSoundTriggerTime
:= 0;
1625 Inc(gSoundTriggerTime
);
1627 if (NetMode
= NET_SERVER
) then
1629 Inc(NetTimeToUpdate
);
1630 Inc(NetTimeToReliable
);
1631 if NetTimeToReliable
>= NetRelupdRate
then
1633 for I
:= 0 to High(gPlayers
) do
1634 if gPlayers
[I
] <> nil then
1635 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1637 if gMonsters
<> nil then
1638 for I
:= 0 to High(gMonsters
) do
1639 if gMonsters
[I
] <> nil then
1641 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1643 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1644 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1647 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1648 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1649 (gMonsters
[I
].GameVelX
<> 0) or
1650 (gMonsters
[I
].GameVelY
<> 0) then
1651 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1654 NetTimeToReliable
:= 0;
1655 NetTimeToUpdate
:= NetUpdateRate
;
1657 else if NetTimeToUpdate
>= NetUpdateRate
then
1659 if gPlayers
<> nil then
1660 for I
:= 0 to High(gPlayers
) do
1661 if gPlayers
[I
] <> nil then
1662 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1664 if gMonsters
<> nil then
1665 for I
:= 0 to High(gMonsters
) do
1666 if gMonsters
[I
] <> nil then
1668 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1670 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1671 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1674 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1675 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1676 (gMonsters
[I
].GameVelX
<> 0) or
1677 (gMonsters
[I
].GameVelY
<> 0) then
1678 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1681 NetTimeToUpdate
:= 0;
1684 if NetUseMaster
then
1685 if gTime
>= NetTimeToMaster
then
1687 if (NetMHost
= nil) or (NetMPeer
= nil) then
1688 if not g_Net_Slist_Connect
then
1689 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1692 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1696 if NetMode
= NET_CLIENT
then
1697 MC_SEND_PlayerPos();
1698 end; // if gameOn ...
1700 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1701 if g_ActiveWindow
<> nil then
1703 w
:= e_GetFirstKeyPressed();
1705 if (w
<> IK_INVALID
) then
1707 Msg
.Msg
:= MESSAGE_DIKEY
;
1709 g_ActiveWindow
.OnMessage(Msg
);
1712 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1713 if g_ActiveWindow
<> nil then
1714 g_ActiveWindow
.Update();
1716 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1717 if gResolutionChange
then
1719 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1720 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1721 gResolutionChange
:= False;
1724 // Íóæíî ñìåíèòü ÿçûê:
1725 if gLanguageChange
then
1727 //e_WriteLog('Read language file', MSG_NOTIFY);
1728 //g_Language_Load(DataDir + gLanguage + '.txt');
1729 g_Language_Set(gLanguage
);
1731 gLanguageChange
:= False;
1735 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1736 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1737 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1740 LastScreenShot
:= GetTimer();
1743 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1744 if e_KeyPressed(IK_F10
) and
1746 (not gConsoleShow
) and
1747 (g_ActiveWindow
= nil) then
1752 Time
:= GetTimer() {div 1000};
1754 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1755 if gDelayedEvents
<> nil then
1756 for a
:= 0 to High(gDelayedEvents
) do
1757 if gDelayedEvents
[a
].Pending
and
1759 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1760 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1763 case gDelayedEvents
[a
].DEType
of
1765 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1768 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1772 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1773 if g_Game_IsNet
and g_Game_IsServer
then
1774 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1777 gDelayedEvents
[a
].Pending
:= False;
1780 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1781 UPSCounter
:= UPSCounter
+ 1;
1782 if Time
- UPSTime
>= 1000 then
1790 procedure g_Game_LoadData();
1792 if DataLoaded
then Exit
;
1794 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1796 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1797 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1798 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1799 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1800 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1801 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1802 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1803 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1804 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1805 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1806 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1807 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1808 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1809 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1810 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1811 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1812 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1813 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1814 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1815 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1816 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1817 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1818 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1819 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1820 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1821 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1822 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1823 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1824 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1825 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1826 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1827 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1828 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1829 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1831 goodsnd
[0] := TPlayableSound
.Create();
1832 goodsnd
[1] := TPlayableSound
.Create();
1833 goodsnd
[2] := TPlayableSound
.Create();
1834 goodsnd
[3] := TPlayableSound
.Create();
1836 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1837 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1838 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1839 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1841 killsnd
[0] := TPlayableSound
.Create();
1842 killsnd
[1] := TPlayableSound
.Create();
1843 killsnd
[2] := TPlayableSound
.Create();
1844 killsnd
[3] := TPlayableSound
.Create();
1846 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1847 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1848 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1849 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1851 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1854 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1855 g_Weapon_LoadData();
1857 g_Monsters_LoadData();
1862 procedure g_Game_FreeData();
1864 if not DataLoaded
then Exit
;
1867 g_Weapon_FreeData();
1868 g_Monsters_FreeData();
1870 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1872 g_Texture_Delete('NOTEXTURE');
1873 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1874 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1875 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1876 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1877 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1878 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1879 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1880 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1881 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1882 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1883 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1884 g_Frames_DeleteByName('FRAMES_TELEPORT');
1885 g_Sound_Delete('SOUND_GAME_TELEPORT');
1886 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1887 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1888 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1889 g_Sound_Delete('SOUND_GAME_BULK1');
1890 g_Sound_Delete('SOUND_GAME_BULK2');
1891 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1892 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1893 g_Sound_Delete('SOUND_GAME_SWITCH1');
1894 g_Sound_Delete('SOUND_GAME_SWITCH0');
1901 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1902 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1903 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1904 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1911 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1912 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1913 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1914 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1916 DataLoaded
:= False;
1919 procedure DrawCustomStat();
1925 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1926 s1
, s2
, topstr
: String;
1928 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1931 if e_KeyPressed(IK_TAB
) then
1933 if not gStatsPressed
then
1935 gStatsOff
:= not gStatsOff
;
1936 gStatsPressed
:= True;
1940 gStatsPressed
:= False;
1944 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1945 w
:= (Length(s1
) * ww2
) div 2;
1946 x
:= gScreenWidth
div 2 - w
;
1948 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1952 if (gGameSettings
.GameMode
= GM_COOP
) then
1954 if gMissionFailed
then
1955 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1957 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1960 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1962 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1963 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
1965 if g_Game_IsNet
then
1967 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
1968 if not gChatShow
then
1969 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1970 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
1973 if g_Game_IsClient
then
1974 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
1976 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
1977 if not gChatShow
then
1978 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1979 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
1984 w
:= gScreenWidth
-x
*2;
1990 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
1991 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
1993 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
1995 case CustomStat
.GameMode
of
1998 if gGameSettings
.MaxLives
= 0 then
1999 s1
:= _lc
[I_GAME_DM
]
2001 s1
:= _lc
[I_GAME_LMS
];
2005 if gGameSettings
.MaxLives
= 0 then
2006 s1
:= _lc
[I_GAME_TDM
]
2008 s1
:= _lc
[I_GAME_TLMS
];
2010 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2013 if gGameSettings
.MaxLives
= 0 then
2014 s1
:= _lc
[I_GAME_COOP
]
2016 s1
:= _lc
[I_GAME_SURV
];
2022 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2026 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2027 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2030 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2031 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2032 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2033 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2035 pc
:= Length(CustomStat
.PlayerStat
);
2036 if pc
= 0 then Exit
;
2038 if CustomStat
.GameMode
= GM_COOP
then
2040 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2042 s2
:= _lc
[I_GAME_MONSTERS
];
2043 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2044 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2046 s2
:= _lc
[I_GAME_SECRETS
];
2047 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2048 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2051 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2053 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2054 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2055 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2057 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2058 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2059 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2063 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2068 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2069 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2070 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2072 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2075 for t
:= TEAM_RED
to TEAM_BLUE
do
2077 if t
= TEAM_RED
then
2079 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2080 gStdFont
, 255, 0, 0, 1);
2081 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2082 gStdFont
, 255, 0, 0, 1);
2089 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2090 gStdFont
, 0, 0, 255, 1);
2091 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2092 gStdFont
, 0, 0, 255, 1);
2098 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2101 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2102 if CustomStat
.PlayerStat
[p
].Team
= t
then
2103 with CustomStat
.PlayerStat
[p
] do
2117 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2118 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2119 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2126 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2129 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2130 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2131 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2134 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2135 with CustomStat
.PlayerStat
[p
] do
2137 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2144 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2145 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2146 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2152 procedure DrawSingleStat();
2154 tm
, key_x
, val_x
, y
: Integer;
2158 procedure player_stat(n
: Integer);
2164 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2165 s2
:= Format(' %d', [gTotalMonsters
]);
2167 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2168 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2169 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2170 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2172 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2173 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2175 // "Kills-per-minute: ##.#":
2176 s1
:= _lc
[I_MENU_INTER_KPM
];
2178 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2180 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2181 s2
:= Format(' %.1f', [kpm
]);
2183 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2184 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2186 // "Secrets found: # / #":
2187 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2188 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2190 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2191 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2192 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2193 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2195 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2196 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2200 // "Level Complete":
2201 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2202 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2204 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2205 s1
:= _lc
[I_MENU_INTER_KPM
];
2206 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2209 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2211 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2212 val_x
:= key_x
+ w1
;
2215 tm
:= SingleStat
.GameTime
div 1000;
2216 s1
:= _lc
[I_MENU_INTER_TIME
];
2217 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2219 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2220 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2222 if SingleStat
.TwoPlayers
then
2225 s1
:= _lc
[I_MENU_PLAYER_1
];
2226 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2227 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2229 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2234 s1
:= _lc
[I_MENU_PLAYER_2
];
2235 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2236 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2238 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2244 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2250 procedure DrawLoadingStat();
2256 if Length(LoadingStat
.Msgs
) = 0 then
2259 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2260 yy
:= (gScreenHeight
div 3);
2261 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2262 xx
:= (gScreenWidth
div 3);
2265 for i
:= 0 to NextMsg
-1 do
2267 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2268 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2272 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2273 yy
:= yy
+ LOADING_INTERLINE
;
2277 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2279 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2281 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2282 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2285 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2286 ScaleSz
:= 16 div Scale
;
2287 // Ðàçìåðû ìèíè-êàðòû:
2288 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2289 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2291 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2293 if gWalls
<> nil then
2296 for a
:= 0 to High(gWalls
) do
2298 if PanelType
<> 0 then
2300 // Ëåâûé âåðõíèé óãîë:
2301 aX
:= X
div ScaleSz
;
2302 aY
:= Y
div ScaleSz
;
2304 aX2
:= max(Width
div ScaleSz
, 1);
2305 aY2
:= max(Height
div ScaleSz
, 1);
2306 // Ïðàâûé íèæíèé óãîë:
2307 aX2
:= aX
+ aX2
- 1;
2308 aY2
:= aY
+ aY2
- 1;
2311 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2312 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2313 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2317 if gSteps
<> nil then
2320 for a
:= 0 to High(gSteps
) do
2322 if PanelType
<> 0 then
2324 // Ëåâûé âåðõíèé óãîë:
2325 aX
:= X
div ScaleSz
;
2326 aY
:= Y
div ScaleSz
;
2328 aX2
:= max(Width
div ScaleSz
, 1);
2329 aY2
:= max(Height
div ScaleSz
, 1);
2330 // Ïðàâûé íèæíèé óãîë:
2331 aX2
:= aX
+ aX2
- 1;
2332 aY2
:= aY
+ aY2
- 1;
2334 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2337 if gLifts
<> nil then
2340 for a
:= 0 to High(gLifts
) do
2342 if PanelType
<> 0 then
2344 // Ëåâûé âåðõíèé óãîë:
2345 aX
:= X
div ScaleSz
;
2346 aY
:= Y
div ScaleSz
;
2348 aX2
:= max(Width
div ScaleSz
, 1);
2349 aY2
:= max(Height
div ScaleSz
, 1);
2350 // Ïðàâûé íèæíèé óãîë:
2351 aX2
:= aX
+ aX2
- 1;
2352 aY2
:= aY
+ aY2
- 1;
2355 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2356 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2357 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2358 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2362 if gWater
<> nil then
2365 for a
:= 0 to High(gWater
) do
2367 if PanelType
<> 0 then
2369 // Ëåâûé âåðõíèé óãîë:
2370 aX
:= X
div ScaleSz
;
2371 aY
:= Y
div ScaleSz
;
2373 aX2
:= max(Width
div ScaleSz
, 1);
2374 aY2
:= max(Height
div ScaleSz
, 1);
2375 // Ïðàâûé íèæíèé óãîë:
2376 aX2
:= aX
+ aX2
- 1;
2377 aY2
:= aY
+ aY2
- 1;
2379 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2382 if gAcid1
<> nil then
2384 // Ðèñóåì êèñëîòó 1:
2385 for a
:= 0 to High(gAcid1
) do
2387 if PanelType
<> 0 then
2389 // Ëåâûé âåðõíèé óãîë:
2390 aX
:= X
div ScaleSz
;
2391 aY
:= Y
div ScaleSz
;
2393 aX2
:= max(Width
div ScaleSz
, 1);
2394 aY2
:= max(Height
div ScaleSz
, 1);
2395 // Ïðàâûé íèæíèé óãîë:
2396 aX2
:= aX
+ aX2
- 1;
2397 aY2
:= aY
+ aY2
- 1;
2399 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2402 if gAcid2
<> nil then
2404 // Ðèñóåì êèñëîòó 2:
2405 for a
:= 0 to High(gAcid2
) do
2407 if PanelType
<> 0 then
2409 // Ëåâûé âåðõíèé óãîë:
2410 aX
:= X
div ScaleSz
;
2411 aY
:= Y
div ScaleSz
;
2413 aX2
:= max(Width
div ScaleSz
, 1);
2414 aY2
:= max(Height
div ScaleSz
, 1);
2415 // Ïðàâûé íèæíèé óãîë:
2416 aX2
:= aX
+ aX2
- 1;
2417 aY2
:= aY
+ aY2
- 1;
2419 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2422 if gPlayers
<> nil then
2425 for a
:= 0 to High(gPlayers
) do
2426 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2428 // Ëåâûé âåðõíèé óãîë:
2429 aX
:= Obj
.X
div ScaleSz
+ 1;
2430 aY
:= Obj
.Y
div ScaleSz
+ 1;
2432 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2433 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2434 // Ïðàâûé íèæíèé óãîë:
2435 aX2
:= aX
+ aX2
- 1;
2436 aY2
:= aY
+ aY2
- 1;
2438 if gPlayers
[a
] = p
then
2439 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2442 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2443 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2444 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2448 if gMonsters
<> nil then
2451 for a
:= 0 to High(gMonsters
) do
2452 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2454 // Ëåâûé âåðõíèé óãîë:
2455 aX
:= Obj
.X
div ScaleSz
+ 1;
2456 aY
:= Obj
.Y
div ScaleSz
+ 1;
2458 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2459 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2460 // Ïðàâûé íèæíèé óãîë:
2461 aX2
:= aX
+ aX2
- 1;
2462 aY2
:= aY
+ aY2
- 1;
2464 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2470 procedure DrawMapView(x
, y
, w
, h
: Integer);
2476 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2477 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2478 g_Map_DrawBack(-bx
, -by
);
2485 glTranslatef(-x
, -y
, 0);
2487 g_Map_DrawPanels(PANEL_BACK
);
2488 g_Map_DrawPanels(PANEL_STEP
);
2491 g_Player_DrawShells();
2493 g_Player_DrawCorpses();
2494 g_Map_DrawPanels(PANEL_WALL
);
2496 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2499 g_Map_DrawPanels(PANEL_ACID1
);
2500 g_Map_DrawPanels(PANEL_ACID2
);
2501 g_Map_DrawPanels(PANEL_WATER
);
2502 g_Map_DrawPanels(PANEL_FORE
);
2503 if g_debug_HealthBar
then
2505 g_Monsters_DrawHealth();
2506 g_Player_DrawHealth();
2512 procedure DrawPlayer(p
: TPlayer
);
2514 px
, py
, a
, b
, c
, d
: Integer;
2517 if (p
= nil) or (p
.FDummy
) then
2520 g_Map_DrawBack(0, 0);
2529 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2530 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2532 if px
> (gPlayerScreenSize
.X
div 2) then
2533 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2536 if py
> (gPlayerScreenSize
.Y
div 2) then
2537 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2540 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2541 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2542 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2543 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2544 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2546 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2549 if p
.IncCam
<> 0 then
2551 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2553 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2554 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2557 if py
< (gPlayerScreenSize
.Y
div 2) then
2559 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2560 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2563 if p
.IncCam
< 0 then
2564 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2566 p
.IncCam
:= p
.IncCam
+ 1;
2568 if p
.IncCam
> 0 then
2569 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2571 p
.IncCam
:= p
.IncCam
- 1;
2574 if (px
< gPlayerScreenSize
.X
div 2) or
2575 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2578 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2579 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2581 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2583 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2584 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2587 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2588 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2590 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2592 g_Map_DrawBack(-c
, -d
);
2595 sY
:= -(b
+p
.IncCam
);
2596 sWidth
:= gPlayerScreenSize
.X
;
2597 sHeight
:= gPlayerScreenSize
.Y
;
2599 glTranslatef(a
, b
+p
.IncCam
, 0);
2601 g_Map_DrawPanels(PANEL_BACK
);
2602 g_Map_DrawPanels(PANEL_STEP
);
2605 g_Player_DrawShells();
2607 g_Player_DrawCorpses();
2608 g_Map_DrawPanels(PANEL_WALL
);
2610 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2613 g_Map_DrawPanels(PANEL_ACID1
);
2614 g_Map_DrawPanels(PANEL_ACID2
);
2615 g_Map_DrawPanels(PANEL_WATER
);
2616 g_Map_DrawPanels(PANEL_FORE
);
2617 if g_debug_HealthBar
then
2619 g_Monsters_DrawHealth();
2620 g_Player_DrawHealth();
2623 if p
.FSpectator
then
2624 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2625 p
.GameY
+ PLAYER_RECT_CY
- 4,
2626 'X', gStdFont
, 255, 255, 255, 1, True);
2628 for a := 0 to High(gCollideMap) do
2629 for b := 0 to High(gCollideMap[a]) do
2632 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2634 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2638 1: e_DrawPoint(1, b, a, 200, 200, 200);
2639 2: e_DrawPoint(1, b, a, 64, 64, 255);
2640 3: e_DrawPoint(1, b, a, 255, 0, 255);
2650 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2651 if g_Debug_Player
then
2652 g_Player_DrawDebug(p
);
2656 procedure g_Game_Draw();
2663 plView1
, plView2
: TPlayer
;
2666 if gExit
= EXIT_QUIT
then Exit
;
2668 Time
:= GetTimer() {div 1000};
2669 FPSCounter
:= FPSCounter
+1;
2670 if Time
- FPSTime
>= 1000 then
2677 if gGameOn
or (gState
= STATE_FOLD
) then
2679 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2681 gSpectMode
:= SPECT_NONE
;
2682 if not gRevertPlayers
then
2684 plView1
:= gPlayer1
;
2685 plView2
:= gPlayer2
;
2689 plView1
:= gPlayer2
;
2690 plView2
:= gPlayer1
;
2694 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2696 gSpectMode
:= SPECT_NONE
;
2697 if gPlayer2
= nil then
2700 plView1
:= gPlayer2
;
2709 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2710 gSpectMode
:= SPECT_STATS
;
2712 if gSpectMode
= SPECT_PLAYERS
then
2713 if gPlayers
<> nil then
2715 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2716 if plView1
= nil then
2718 gSpectPID1
:= GetActivePlayerID_Next();
2719 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2721 if gSpectViewTwo
then
2723 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2724 if plView2
= nil then
2726 gSpectPID2
:= GetActivePlayerID_Next();
2727 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2732 if gSpectMode
= SPECT_MAPVIEW
then
2734 // Ðåæèì ïðîñìîòðà êàðòû
2736 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2737 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2738 gHearPoint1
.Active
:= True;
2739 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2740 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2741 gHearPoint2
.Active
:= False;
2745 Split
:= (plView1
<> nil) and (plView2
<> nil);
2747 // Òî÷êè ñëóõà èãðîêîâ
2748 if plView1
<> nil then
2750 gHearPoint1
.Active
:= True;
2751 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2752 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2754 gHearPoint1
.Active
:= False;
2755 if plView2
<> nil then
2757 gHearPoint2
.Active
:= True;
2758 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2759 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2761 gHearPoint2
.Active
:= False;
2763 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2764 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2767 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2768 if gScreenHeight
mod 2 = 0 then
2769 Dec(gPlayerScreenSize
.Y
);
2772 gPlayerScreenSize
.Y
:= gScreenHeight
;
2775 if gScreenHeight
mod 2 = 0 then
2776 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2778 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2780 DrawPlayer(plView1
);
2781 gPlayer1ScreenCoord
.X
:= sX
;
2782 gPlayer1ScreenCoord
.Y
:= sY
;
2786 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2788 DrawPlayer(plView2
);
2789 gPlayer2ScreenCoord
.X
:= sX
;
2790 gPlayer2ScreenCoord
.Y
:= sY
;
2793 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2796 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2799 if MessageText
<> '' then
2803 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2805 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2806 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2808 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2809 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2812 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2814 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2816 // Draw spectator GUI
2819 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2822 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2824 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2826 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2828 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2829 if gSpectMode
= SPECT_MAPVIEW
then
2831 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2832 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2833 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2834 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2835 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2837 if gSpectMode
= SPECT_PLAYERS
then
2839 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2840 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2841 if gSpectViewTwo
then
2843 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2844 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2845 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2846 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2850 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2851 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2857 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2859 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2861 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2862 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2863 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2868 if (gState
= STATE_MENU
) then
2870 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2872 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2873 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2874 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2876 if g_ActiveWindow
<> nil then
2877 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2880 if gState
= STATE_FOLD
then
2881 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2883 if gState
= STATE_INTERCUSTOM
then
2885 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2887 back
:= 'TEXTURE_endpic';
2888 if not g_Texture_Get(back
, ID
) then
2889 back
:= _lc
[I_TEXTURE_ENDPIC
];
2894 if g_Texture_Get(back
, ID
) then
2895 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2897 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2901 if g_ActiveWindow
<> nil then
2902 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2905 if gState
= STATE_INTERSINGLE
then
2907 if EndingGameCounter
> 0 then
2908 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2913 if g_Texture_Get(back
, ID
) then
2914 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2916 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2920 if g_ActiveWindow
<> nil then
2921 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2925 if gState
= STATE_ENDPIC
then
2928 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2929 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2931 if ID
<> DWORD(-1) then
2932 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2934 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2936 if g_ActiveWindow
<> nil then
2937 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2940 if gState
= STATE_SLIST
then
2942 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2944 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2945 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2947 g_Serverlist_Draw(slCurrent
);
2951 if g_ActiveWindow
<> nil then
2954 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2955 g_ActiveWindow
.Draw();
2960 if g_debug_Sounds
and gGameOn
then
2962 for w
:= 0 to High(e_SoundsArray
) do
2963 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2964 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
2969 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
2970 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
2973 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
2974 e_TextureFontPrint(gScreenWidth
-72, 0,
2975 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
2979 procedure g_Game_Quit();
2981 g_Game_StopAllSounds(True);
2983 g_Game_SaveOptions();
2985 g_PlayerModel_FreeData();
2986 g_Texture_DeleteAll();
2987 g_Frames_DeleteAll();
2990 if NetInitDone
then g_Net_Free
;
2992 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
2993 if gMapToDelete
<> '' then
2994 g_Game_DeleteTestMap();
3000 procedure g_FatalError(Text: String);
3002 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3003 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3005 gExit
:= EXIT_SIMPLE
;
3008 procedure g_SimpleError(Text: String);
3010 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3011 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3014 procedure g_Game_SetupScreenSize();
3018 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3019 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3020 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3021 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3023 gPlayerScreenSize
.Y
:= gScreenHeight
;
3025 // Ðàçìåð çàäíåãî ïëàíà:
3026 if BackID
<> DWORD(-1) then
3030 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3031 (gScreenHeight
*d
> gMapInfo
.Height
) then
3034 gBackSize
.X
:= Round(gScreenWidth
*d
);
3035 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3039 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3041 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3044 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3046 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3047 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3049 if gPlayer1
= nil then
3051 if g_Game_IsClient
then
3053 if NetPlrUID1
> -1 then
3055 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3056 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3061 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3062 Team
:= gPlayer1Settings
.Team
;
3064 // Ñîçäàíèå ïåðâîãî èãðîêà:
3065 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3066 gPlayer1Settings
.Color
,
3068 if gPlayer1
= nil then
3069 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3072 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3073 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3074 if g_Game_IsServer
and g_Game_IsNet
then
3075 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3076 gPlayer1
.Respawn(False, True);
3078 if g_Game_IsNet
and NetUseMaster
then
3084 if gPlayer2
= nil then
3086 if g_Game_IsClient
then
3088 if NetPlrUID2
> -1 then
3089 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3093 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3094 Team
:= gPlayer2Settings
.Team
;
3096 // Ñîçäàíèå âòîðîãî èãðîêà:
3097 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3098 gPlayer2Settings
.Color
,
3100 if gPlayer2
= nil then
3101 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3104 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3105 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3106 if g_Game_IsServer
and g_Game_IsNet
then
3107 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3108 gPlayer2
.Respawn(False, True);
3110 if g_Game_IsNet
and NetUseMaster
then
3118 procedure g_Game_RemovePlayer();
3122 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3123 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3128 if g_Game_IsServer
then
3131 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3132 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3133 g_Player_Remove(Pl
.UID
);
3135 if g_Game_IsNet
and NetUseMaster
then
3144 if g_Game_IsServer
then
3147 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3148 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3149 g_Player_Remove(Pl
.UID
);
3151 if g_Game_IsNet
and NetUseMaster
then
3156 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3162 procedure g_Game_Spectate();
3164 g_Game_RemovePlayer();
3165 if gPlayer1
<> nil then
3166 g_Game_RemovePlayer();
3169 procedure g_Game_SpectateCenterView();
3171 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3172 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3175 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3181 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3183 g_Game_ClearLoading();
3186 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3189 gGameSettings
.GameType
:= GT_SINGLE
;
3190 gGameSettings
.MaxLives
:= 0;
3191 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3192 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3193 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3194 gSwitchGameMode
:= GM_SINGLE
;
3196 g_Game_ExecuteEvent('ongamestart');
3198 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3199 g_Game_SetupScreenSize();
3201 // Ñîçäàíèå ïåðâîãî èãðîêà:
3202 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3203 gPlayer1Settings
.Color
,
3204 gPlayer1Settings
.Team
, False));
3205 if gPlayer1
= nil then
3207 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3211 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3214 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3217 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3218 gPlayer2Settings
.Color
,
3219 gPlayer2Settings
.Team
, False));
3220 if gPlayer2
= nil then
3222 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3226 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3230 // Çàãðóçêà è çàïóñê êàðòû:
3231 if not g_Game_StartMap(MAP
, True) then
3233 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3237 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3241 for i
:= nPl
+1 to nPlayers
do
3242 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3245 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3246 TimeLimit
, GoalLimit
: Word;
3248 Options
: LongWord; nPlayers
: Byte);
3254 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3256 g_Game_ClearLoading();
3259 gGameSettings
.GameType
:= GT_CUSTOM
;
3260 gGameSettings
.GameMode
:= GameMode
;
3261 gSwitchGameMode
:= GameMode
;
3262 gGameSettings
.TimeLimit
:= TimeLimit
;
3263 gGameSettings
.GoalLimit
:= GoalLimit
;
3264 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3265 gGameSettings
.Options
:= Options
;
3267 gCoopTotalMonstersKilled
:= 0;
3268 gCoopTotalSecretsFound
:= 0;
3269 gCoopTotalMonsters
:= 0;
3270 gCoopTotalSecrets
:= 0;
3274 g_Game_ExecuteEvent('ongamestart');
3276 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3277 g_Game_SetupScreenSize();
3279 // Ðåæèì íàáëþäàòåëÿ:
3280 if nPlayers
= 0 then
3287 if nPlayers
>= 1 then
3289 // Ñîçäàíèå ïåðâîãî èãðîêà:
3290 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3291 gPlayer1Settings
.Color
,
3292 gPlayer1Settings
.Team
, False));
3293 if gPlayer1
= nil then
3295 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3299 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3303 if nPlayers
>= 2 then
3305 // Ñîçäàíèå âòîðîãî èãðîêà:
3306 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3307 gPlayer2Settings
.Color
,
3308 gPlayer2Settings
.Team
, False));
3309 if gPlayer2
= nil then
3311 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3315 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3319 // Çàãðóçêà è çàïóñê êàðòû:
3320 if not g_Game_StartMap(Map
, True) then
3322 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3326 // Íåò òî÷åê ïîÿâëåíèÿ:
3327 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3328 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3329 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3330 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3331 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3333 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3337 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3341 for i
:= nPl
+1 to nPlayers
do
3342 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3345 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3346 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3347 Options
: LongWord; nPlayers
: Byte;
3348 IPAddr
: LongWord; Port
: Word);
3352 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3354 g_Game_ClearLoading();
3357 gGameSettings
.GameType
:= GT_SERVER
;
3358 gGameSettings
.GameMode
:= GameMode
;
3359 gSwitchGameMode
:= GameMode
;
3360 gGameSettings
.TimeLimit
:= TimeLimit
;
3361 gGameSettings
.GoalLimit
:= GoalLimit
;
3362 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3363 gGameSettings
.Options
:= Options
;
3365 gCoopTotalMonstersKilled
:= 0;
3366 gCoopTotalSecretsFound
:= 0;
3367 gCoopTotalMonsters
:= 0;
3368 gCoopTotalSecrets
:= 0;
3372 g_Game_ExecuteEvent('ongamestart');
3374 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3375 g_Game_SetupScreenSize();
3377 // Ðåæèì íàáëþäàòåëÿ:
3378 if nPlayers
= 0 then
3384 if nPlayers
>= 1 then
3386 // Ñîçäàíèå ïåðâîãî èãðîêà:
3387 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3388 gPlayer1Settings
.Color
,
3389 gPlayer1Settings
.Team
, False));
3390 if gPlayer1
= nil then
3392 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3396 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3399 if nPlayers
>= 2 then
3401 // Ñîçäàíèå âòîðîãî èãðîêà:
3402 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3403 gPlayer2Settings
.Color
,
3404 gPlayer2Settings
.Team
, False));
3405 if gPlayer2
= nil then
3407 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3411 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3415 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3417 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3421 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3423 // Çàãðóçêà è çàïóñê êàðòû:
3424 if not g_Game_StartMap(Map
, True) then
3426 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3430 // Íåò òî÷åê ïîÿâëåíèÿ:
3431 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3432 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3433 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3434 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3435 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3437 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3441 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3444 NetState
:= NET_STATE_GAME
;
3447 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3461 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3462 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3464 g_Game_ClearLoading();
3467 gGameSettings
.GameType
:= GT_CLIENT
;
3469 gCoopTotalMonstersKilled
:= 0;
3470 gCoopTotalSecretsFound
:= 0;
3471 gCoopTotalMonsters
:= 0;
3472 gCoopTotalSecrets
:= 0;
3476 g_Game_ExecuteEvent('ongamestart');
3478 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3479 g_Game_SetupScreenSize();
3481 NetState
:= NET_STATE_AUTH
;
3483 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3485 if not g_Net_Connect(Addr
, Port
) then
3487 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3488 NetState
:= NET_STATE_NONE
;
3492 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3494 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3499 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3501 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3503 Ptr
:= NetEvent
.packet
^.data
;
3506 MID
:= e_Raw_Read_Byte(Ptr
);
3508 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3510 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3511 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3513 WadName
:= e_Raw_Read_String(Ptr
);
3514 Map
:= e_Raw_Read_String(Ptr
);
3516 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3518 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3519 gSwitchGameMode
:= gGameSettings
.GameMode
;
3520 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3521 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3522 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3523 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3524 T
:= e_Raw_Read_LongWord(Ptr
);
3526 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3527 if newResPath
= '' then
3529 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3530 newResPath
:= g_Res_DownloadWAD(WadName
);
3531 if newResPath
= '' then
3533 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3534 enet_packet_destroy(NetEvent
.packet
);
3535 NetState
:= NET_STATE_NONE
;
3539 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3541 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3542 gPlayer1Settings
.Color
,
3543 gPlayer1Settings
.Team
, False));
3545 if gPlayer1
= nil then
3547 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3549 enet_packet_destroy(NetEvent
.packet
);
3550 NetState
:= NET_STATE_NONE
;
3554 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3555 gPlayer1
.UID
:= NetPlrUID1
;
3556 gPlayer1
.Reset(True);
3558 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3560 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3562 enet_packet_destroy(NetEvent
.packet
);
3563 NetState
:= NET_STATE_NONE
;
3571 enet_packet_destroy(NetEvent
.packet
);
3575 enet_packet_destroy(NetEvent
.packet
);
3578 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3581 if (NetEvent
.data
<= NET_DISC_MAX
) then
3582 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3583 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3593 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3602 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3603 NetState
:= NET_STATE_NONE
;
3607 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3608 gLMSRespawnTime
:= 0;
3611 NetState
:= NET_STATE_GAME
;
3612 MC_SEND_FullStateRequest
;
3613 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3616 procedure g_Game_SaveOptions();
3618 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3621 procedure g_Game_ChangeMap(MapPath
: String);
3625 g_Game_ClearLoading();
3627 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3628 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3629 if gExitByTrigger
then
3632 gExitByTrigger
:= False;
3634 if not g_Game_StartMap(MapPath
, Force
) then
3635 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3638 procedure g_Game_Restart();
3642 if g_Game_IsClient
then
3644 map
:= g_ExtractFileName(gMapInfo
.Map
);
3648 g_Game_ClearLoading();
3649 g_Game_StartMap(Map
, True);
3652 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3654 NewWAD
, ResName
: String;
3658 g_Player_RemoveAllCorpses();
3660 if (not g_Game_IsClient
) and
3661 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3662 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3664 if gSwitchGameMode
= GM_CTF
then
3665 gGameSettings
.MaxLives
:= 0;
3666 gGameSettings
.GameMode
:= gSwitchGameMode
;
3669 gSwitchGameMode
:= gGameSettings
.GameMode
;
3671 g_Player_ResetTeams();
3673 if Pos(':\', Map
) > 0 then
3675 NewWAD
:= g_ExtractWadName(Map
);
3676 ResName
:= g_ExtractFileName(Map
);
3677 if g_Game_IsServer
then
3679 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3680 g_Game_LoadWAD(NewWAD
);
3682 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3683 g_Game_ClientWAD(NewWAD
, gWADHash
);
3687 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3690 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3692 gState
:= STATE_NONE
;
3693 g_ActiveWindow
:= nil;
3699 if gGameSettings
.GameMode
= GM_CTF
then
3701 g_Map_ResetFlag(FLAG_RED
);
3702 g_Map_ResetFlag(FLAG_BLUE
);
3703 // CTF, à ôëàãîâ íåò:
3704 if not g_Map_HaveFlagPoints() then
3705 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3710 gState
:= STATE_MENU
;
3717 NetTimeToUpdate
:= 1;
3718 NetTimeToReliable
:= 0;
3719 NetTimeToMaster
:= NetMasterRate
;
3720 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3721 gLMSRespawnTime
:= 0;
3722 gMissionFailed
:= False;
3725 gCoopMonstersKilled
:= 0;
3726 gCoopSecretsFound
:= 0;
3728 gVoteInProgress
:= False;
3729 gVotePassed
:= False;
3735 if not gGameOn
then Exit
;
3737 g_Game_SpectateCenterView();
3739 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3741 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3742 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3743 gLMSSoftSpawn
:= True;
3744 if NetMode
= NET_SERVER
then
3745 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3747 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3750 if NetMode
= NET_SERVER
then
3752 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3755 if NetUseMaster
then
3757 if (NetMHost
= nil) or (NetMPeer
= nil) then
3758 if not g_Net_Slist_Connect
then
3759 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3764 if NetClients
<> nil then
3765 for I
:= 0 to High(NetClients
) do
3766 if NetClients
[I
].Used
then
3768 NetClients
[I
].Voted
:= False;
3769 if NetClients
[I
].RequestedFullUpdate
then
3771 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3772 NetClients
[I
].RequestedFullUpdate
:= False;
3776 g_Net_UnbanNonPermHosts();
3781 gCoopTotalMonstersKilled
:= 0;
3782 gCoopTotalSecretsFound
:= 0;
3783 gCoopTotalMonsters
:= 0;
3784 gCoopTotalSecrets
:= 0;
3788 g_Game_ExecuteEvent('onmapstart');
3791 procedure SetFirstLevel();
3795 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3796 if MapList
= nil then
3799 SortSArray(MapList
);
3800 gNextMap
:= MapList
[Low(MapList
)];
3805 procedure g_Game_ExitLevel(Map
: Char16
);
3809 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3810 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3811 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3812 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3814 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3815 if gGameSettings
.GameType
= GT_SINGLE
then
3816 gExit
:= EXIT_ENDLEVELSINGLE
3817 else // Âûøëè â âûõîä â Ñâîåé èãðå
3819 gExit
:= EXIT_ENDLEVELCUSTOM
;
3820 if gGameSettings
.GameMode
= GM_COOP
then
3821 g_Player_RememberAll
;
3823 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3826 if gGameSettings
.GameMode
= GM_COOP
then
3829 gStatsPressed
:= True;
3830 gNextMap
:= 'MAP01';
3832 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3835 if g_Game_IsNet
then
3837 MH_SEND_GameStats();
3838 MH_SEND_CoopStats();
3844 procedure g_Game_RestartLevel();
3848 if gGameSettings
.GameMode
= GM_SINGLE
then
3853 gExit
:= EXIT_ENDLEVELCUSTOM
;
3854 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3858 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3862 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3864 if not g_Game_IsClient
then
3866 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3869 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3870 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3874 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3878 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3879 g_Game_LoadWAD(NewWAD
);
3882 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3884 i
, n
, nb
, nr
: Integer;
3886 if not g_Game_IsServer
then Exit
;
3887 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3888 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3889 gLMSRespawnTime
:= 0;
3892 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3894 gMissionFailed
:= True;
3895 g_Game_RestartLevel
;
3899 n
:= 0; nb
:= 0; nr
:= 0;
3900 for i
:= Low(gPlayers
) to High(gPlayers
) do
3901 if (gPlayers
[i
] <> nil) and
3902 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3903 (gPlayers
[i
] is TBot
)) then
3906 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3907 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3910 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3912 // wait a second until the fuckers finally decide to join
3913 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3914 gLMSRespawnTime
:= gTime
+ 1000;
3915 gLMSSoftSpawn
:= NoMapRestart
;
3919 g_Player_RemoveAllCorpses
;
3920 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3921 if g_Game_IsNet
then
3922 MH_SEND_GameEvent(NET_EV_LMS_START
);
3924 for i
:= Low(gPlayers
) to High(gPlayers
) do
3926 if gPlayers
[i
] = nil then continue
;
3927 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3928 // don't touch normal spectators
3929 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3931 gPlayers
[i
].FNoRespawn
:= True;
3932 gPlayers
[i
].Lives
:= 0;
3933 if g_Game_IsNet
then
3934 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3937 gPlayers
[i
].FNoRespawn
:= False;
3938 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3939 gPlayers
[i
].Respawn(False, True);
3940 if gGameSettings
.GameMode
= GM_COOP
then
3942 gPlayers
[i
].Frags
:= 0;
3943 gPlayers
[i
].RecallState
;
3945 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3946 gPlayer1
:= g_Player_Get(gLMSPID1
);
3947 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3948 gPlayer2
:= g_Player_Get(gLMSPID2
);
3951 for i
:= Low(gItems
) to High(gItems
) do
3953 if gItems
[i
].Respawnable
then
3955 gItems
[i
].QuietRespawn
:= True;
3956 gItems
[i
].RespawnTime
:= 0;
3961 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3965 for i
:= Low(gMonsters
) to High(gMonsters
) do
3967 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
3968 gMonsters
[i
].Respawn
;
3971 gLMSSoftSpawn
:= False;
3974 function g_Game_GetFirstMap(WAD
: String): String;
3978 MapList
:= g_Map_GetMapsList(WAD
);
3979 if MapList
= nil then
3982 SortSArray(MapList
);
3983 Result
:= MapList
[Low(MapList
)];
3985 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3991 function g_Game_GetNextMap(): String;
3998 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3999 if MapList
= nil then
4002 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4004 SortSArray(MapList
);
4006 for I
:= Low(MapList
) to High(MapList
) do
4007 if Map
= MapList
[I
] then
4013 if MapIndex
<> -255 then
4015 if MapIndex
= High(MapList
) then
4016 Result
:= MapList
[Low(MapList
)]
4018 Result
:= MapList
[MapIndex
+ 1];
4020 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4026 procedure g_Game_NextLevel();
4028 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4029 gExit
:= EXIT_ENDLEVELCUSTOM
4032 gExit
:= EXIT_ENDLEVELSINGLE
;
4036 if gNextMap
<> '' then Exit
;
4037 gNextMap
:= g_Game_GetNextMap();
4040 function g_Game_IsTestMap(): Boolean;
4042 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4045 procedure g_Game_DeleteTestMap();
4056 a
:= Pos('.wad:\', gMapToDelete
);
4060 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4061 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4062 Delete(gMapToDelete
, 1, a
+ 5);
4063 gMapToDelete
:= UpperCase(gMapToDelete
);
4065 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4068 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4069 if MapName <> TEST_MAP_NAME then
4072 if not gTempDelete then
4074 time := g_GetFileTime(WadName);
4075 WAD := TWADFile.Create();
4078 if not WAD.ReadFile(WadName) then
4079 begin // Íåò òàêîãî WAD-ôàéëà
4084 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4086 MapList := WAD.GetResourcesList('');
4088 if MapList <> nil then
4089 for a := 0 to High(MapList) do
4090 if MapList[a] = MapName then
4092 // Óäàëÿåì è ñîõðàíÿåì:
4093 WAD.RemoveResource('', MapName);
4094 WAD.SaveTo(WadName);
4099 g_SetFileTime(WadName, time);
4102 if gTempDelete
then DeleteFile(WadName
);
4105 procedure GameCVars(P
: SArray
);
4108 stat
: TPlayerStatArray
;
4113 cmd
:= LowerCase(P
[0]);
4114 if cmd
= 'r_showfps' then
4116 if (Length(P
) > 1) and
4117 ((P
[1] = '1') or (P
[1] = '0')) then
4118 gShowFPS
:= (P
[1][1] = '1');
4121 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4123 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4125 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4127 with gGameSettings
do
4129 if (Length(P
) > 1) and
4130 ((P
[1] = '1') or (P
[1] = '0')) then
4132 if (P
[1][1] = '1') then
4133 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4135 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4138 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4139 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4141 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4143 if g_Game_IsNet
then MH_SEND_GameSettings
;
4146 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4148 with gGameSettings
do
4150 if (Length(P
) > 1) and
4151 ((P
[1] = '1') or (P
[1] = '0')) then
4153 if (P
[1][1] = '1') then
4154 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4156 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4159 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4160 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4162 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4164 if g_Game_IsNet
then MH_SEND_GameSettings
;
4167 else if cmd
= 'g_gamemode' then
4169 a
:= g_Game_TextToMode(P
[1]);
4170 if a
= GM_SINGLE
then a
:= GM_COOP
;
4171 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4173 gSwitchGameMode
:= a
;
4174 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4175 (gState
= STATE_INTERSINGLE
) then
4176 gSwitchGameMode
:= GM_SINGLE
;
4178 gGameSettings
.GameMode
:= gSwitchGameMode
;
4180 if gSwitchGameMode
= gGameSettings
.GameMode
then
4181 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4182 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4184 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4185 [g_Game_ModeToText(gGameSettings
.GameMode
),
4186 g_Game_ModeToText(gSwitchGameMode
)]));
4188 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4190 with gGameSettings
do
4192 if (Length(P
) > 1) and
4193 ((P
[1] = '1') or (P
[1] = '0')) then
4195 if (P
[1][1] = '1') then
4196 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4198 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4201 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4202 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4204 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4205 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4207 if g_Game_IsNet
then MH_SEND_GameSettings
;
4210 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4212 with gGameSettings
do
4214 if (Length(P
) > 1) and
4215 ((P
[1] = '1') or (P
[1] = '0')) then
4217 if (P
[1][1] = '1') then
4218 Options
:= Options
or GAME_OPTION_MONSTERS
4220 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4223 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4224 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4226 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4227 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4229 if g_Game_IsNet
then MH_SEND_GameSettings
;
4232 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4234 with gGameSettings
do
4236 if (Length(P
) > 1) and
4237 ((P
[1] = '1') or (P
[1] = '0')) then
4239 if (P
[1][1] = '1') then
4240 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4242 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4245 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4246 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4248 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4250 if g_Game_IsNet
then MH_SEND_GameSettings
;
4253 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4255 with gGameSettings
do
4257 if (Length(P
) > 1) and
4258 ((P
[1] = '1') or (P
[1] = '0')) then
4260 if (P
[1][1] = '1') then
4261 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4263 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4266 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4267 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4269 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4271 if g_Game_IsNet
then MH_SEND_GameSettings
;
4274 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4276 if Length(P
) > 1 then
4278 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4279 gGameSettings
.WarmupTime
:= 30
4281 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4284 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4285 [gGameSettings
.WarmupTime
]));
4286 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4288 else if cmd
= 'net_interp' then
4290 if (Length(P
) > 1) then
4291 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4293 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4294 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4295 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4296 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4299 else if cmd
= 'net_forceplayerupdate' then
4301 if (Length(P
) > 1) and
4302 ((P
[1] = '1') or (P
[1] = '0')) then
4303 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4305 if NetForcePlayerUpdate
then
4306 g_Console_Add('net_forceplayerupdate = 1')
4308 g_Console_Add('net_forceplayerupdate = 0');
4309 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4310 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4311 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4314 else if cmd
= 'net_predictself' then
4316 if (Length(P
) > 1) and
4317 ((P
[1] = '1') or (P
[1] = '0')) then
4318 NetPredictSelf
:= (P
[1][1] = '1');
4320 if NetPredictSelf
then
4321 g_Console_Add('net_predictself = 1')
4323 g_Console_Add('net_predictself = 0');
4324 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4325 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4326 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4329 else if cmd
= 'sv_name' then
4331 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4333 NetServerName
:= P
[1];
4334 if Length(NetServerName
) > 64 then
4335 SetLength(NetServerName
, 64);
4336 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4340 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4342 else if cmd
= 'sv_passwd' then
4344 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4346 NetPassword
:= P
[1];
4347 if Length(NetPassword
) > 24 then
4348 SetLength(NetPassword
, 24);
4349 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4353 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4355 else if cmd
= 'sv_maxplrs' then
4357 if (Length(P
) > 1) then
4359 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4360 if g_Game_IsServer
and g_Game_IsNet
then
4363 for a
:= 0 to High(NetClients
) do
4364 if NetClients
[a
].Used
then
4367 if b
> NetMaxClients
then
4369 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4370 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4371 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4372 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4375 if NetUseMaster
then
4380 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4382 else if cmd
= 'sv_public' then
4384 if (Length(P
) > 1) then
4386 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4387 if g_Game_IsServer
and g_Game_IsNet
then
4388 if NetUseMaster
then
4390 if NetMPeer
= nil then
4391 if not g_Net_Slist_Connect() then
4392 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4393 g_Net_Slist_Update();
4396 if NetMPeer
<> nil then
4397 g_Net_Slist_Disconnect();
4400 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4402 else if cmd
= 'sv_intertime' then
4404 if (Length(P
) > 1) then
4405 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4407 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4409 else if cmd
= 'p1_name' then
4411 if (Length(P
) > 1) and gGameOn
then
4413 if g_Game_IsClient
then
4415 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4416 MC_SEND_PlayerSettings
;
4419 if gPlayer1
<> nil then
4421 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4422 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4425 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4428 else if cmd
= 'p2_name' then
4430 if (Length(P
) > 1) and gGameOn
then
4432 if g_Game_IsClient
then
4434 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4435 MC_SEND_PlayerSettings
;
4438 if gPlayer2
<> nil then
4440 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4441 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4444 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4447 else if cmd
= 'p1_color' then
4449 if Length(P
) > 3 then
4450 if g_Game_IsClient
then
4452 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4453 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4454 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4455 MC_SEND_PlayerSettings
;
4458 if gPlayer1
<> nil then
4460 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4461 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4462 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4463 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4466 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4467 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4468 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4470 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4472 if Length(P
) > 3 then
4473 if g_Game_IsClient
then
4475 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4476 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4477 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4478 MC_SEND_PlayerSettings
;
4481 if gPlayer2
<> nil then
4483 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4484 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4485 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4486 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4489 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4490 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4491 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4493 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4495 if cmd
= 'r_showtime' then
4497 if (Length(P
) > 1) and
4498 ((P
[1] = '1') or (P
[1] = '0')) then
4499 gShowTime
:= (P
[1][1] = '1');
4502 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4504 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4506 else if cmd
= 'r_showscore' then
4508 if (Length(P
) > 1) and
4509 ((P
[1] = '1') or (P
[1] = '0')) then
4510 gShowGoals
:= (P
[1][1] = '1');
4513 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4515 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4517 else if cmd
= 'r_showstat' then
4519 if (Length(P
) > 1) and
4520 ((P
[1] = '1') or (P
[1] = '0')) then
4521 gShowStat
:= (P
[1][1] = '1');
4524 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4526 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4528 else if cmd
= 'r_showkillmsg' then
4530 if (Length(P
) > 1) and
4531 ((P
[1] = '1') or (P
[1] = '0')) then
4532 gShowKillMsg
:= (P
[1][1] = '1');
4534 if gShowKillMsg
then
4535 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4537 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4539 else if cmd
= 'r_showlives' then
4541 if (Length(P
) > 1) and
4542 ((P
[1] = '1') or (P
[1] = '0')) then
4543 gShowLives
:= (P
[1][1] = '1');
4546 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4548 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4550 else if cmd
= 'r_showspect' then
4552 if (Length(P
) > 1) and
4553 ((P
[1] = '1') or (P
[1] = '0')) then
4554 gSpectHUD
:= (P
[1][1] = '1');
4557 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4559 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4561 else if cmd
= 'r_showping' then
4563 if (Length(P
) > 1) and
4564 ((P
[1] = '1') or (P
[1] = '0')) then
4565 gShowPing
:= (P
[1][1] = '1');
4568 g_Console_Add(_lc
[I_MSG_PING_ON
])
4570 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4572 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4574 if Length(P
) > 1 then
4576 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4577 gGameSettings
.GoalLimit
:= 0
4582 if gGameSettings
.GameMode
= GM_DM
then
4584 stat
:= g_Player_GetStats();
4586 for a
:= 0 to High(stat
) do
4587 if stat
[a
].Frags
> b
then
4591 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4593 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4596 if g_Game_IsNet
then MH_SEND_GameSettings
;
4599 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4601 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4603 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4604 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4606 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4607 [gGameSettings
.TimeLimit
div 3600,
4608 (gGameSettings
.TimeLimit
div 60) mod 60,
4609 gGameSettings
.TimeLimit
mod 60]));
4610 if g_Game_IsNet
then MH_SEND_GameSettings
;
4612 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4614 if Length(P
) > 1 then
4616 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4617 gGameSettings
.MaxLives
:= 0
4621 stat
:= g_Player_GetStats();
4623 for a
:= 0 to High(stat
) do
4624 if stat
[a
].Lives
> b
then
4626 gGameSettings
.MaxLives
:=
4627 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4631 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4632 [gGameSettings
.MaxLives
]));
4633 if g_Game_IsNet
then MH_SEND_GameSettings
;
4638 procedure DebugCommands(P
: SArray
);
4644 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4647 cmd
:= LowerCase(P
[0]);
4648 if cmd
= 'd_window' then
4650 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4651 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4652 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4653 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4654 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4656 else if cmd
= 'd_sounds' then
4658 if (Length(P
) > 1) and
4659 ((P
[1] = '1') or (P
[1] = '0')) then
4660 g_Debug_Sounds
:= (P
[1][1] = '1');
4662 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4664 else if cmd
= 'd_frames' then
4666 if (Length(P
) > 1) and
4667 ((P
[1] = '1') or (P
[1] = '0')) then
4668 g_Debug_Frames
:= (P
[1][1] = '1');
4670 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4672 else if cmd
= 'd_winmsg' then
4674 if (Length(P
) > 1) and
4675 ((P
[1] = '1') or (P
[1] = '0')) then
4676 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4678 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4680 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4682 if (Length(P
) > 1) and
4683 ((P
[1] = '1') or (P
[1] = '0')) then
4684 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4686 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4688 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4690 if Length(P
) > 1 then
4692 '0': g_debug_BotAIOff
:= 0;
4693 '1': g_debug_BotAIOff
:= 1;
4694 '2': g_debug_BotAIOff
:= 2;
4695 '3': g_debug_BotAIOff
:= 3;
4698 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4700 else if cmd
= 'd_monster' then
4702 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4703 if Length(P
) < 2 then
4705 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4706 g_Console_Add('ID | Name');
4707 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4708 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4711 a
:= StrToIntDef(P
[1], 0);
4712 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4713 a
:= g_Monsters_GetIDByName(P
[1]);
4715 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4716 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4719 with gPlayer1
.Obj
do
4720 b
:= g_Monsters_Create(a
,
4721 X
+ Rect
.X
+ (Rect
.Width
div 2),
4722 Y
+ Rect
.Y
+ Rect
.Height
,
4723 gPlayer1
.Direction
, True);
4724 if (Length(P
) > 2) and (b
>= 0) then
4725 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4729 else if (cmd
= 'd_health') then
4731 if (Length(P
) > 1) and
4732 ((P
[1] = '1') or (P
[1] = '0')) then
4733 g_debug_HealthBar
:= (P
[1][1] = '1');
4735 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4737 else if (cmd
= 'd_player') then
4739 if (Length(P
) > 1) and
4740 ((P
[1] = '1') or (P
[1] = '0')) then
4741 g_debug_Player
:= (P
[1][1] = '1');
4743 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4745 else if (cmd
= 'd_joy') then
4748 g_Console_Add(e_JoystickStateToString(a
));
4752 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4756 procedure GameCheats(P
: SArray
);
4762 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4763 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4765 g_Console_Add('not available');
4771 g_Console_Add('where is the player?!');
4774 cmd
:= LowerCase(P
[0]);
4778 plr
.GodMode
:= not plr
.GodMode
;
4779 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4782 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4783 if cmd
= 'give' then
4785 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4786 for f
:= 1 to High(P
) do
4788 cmd
:= LowerCase(P
[f
]);
4789 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4790 if (cmd
= 'all') or (cmd
= 'weapons') then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4791 if cmd
= 'exit' then
4793 if gTriggers
<> nil then
4795 for a
:= 0 to High(gTriggers
) do
4797 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4799 g_Console_Add('player left the map');
4800 gExitByTrigger
:= True;
4801 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4808 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4809 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got jetpack'); continue
; end;
4810 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got envirosuit'); continue
; end;
4811 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got berserk pack'); continue
; end;
4812 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4817 if cmd
= 'open' then
4819 g_Console_Add('player activated sesame');
4820 g_Triggers_OpenAll();
4827 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4831 if cmd
= 'noclip' then
4834 g_Console_Add('wall hardeness adjusted');
4838 if cmd
= 'notarget' then
4840 plr
.NoTarget
:= not plr
.NoTarget
;
4841 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4845 if cmd
= 'noreload' then
4847 plr
.NoReload
:= not plr
.NoReload
;
4848 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4852 if cmd
= 'speedy' then
4854 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4855 g_Console_Add('speed adjusted');
4859 if cmd
= 'jumpy' then
4861 VEL_JUMP
:= 30-VEL_JUMP
;
4862 g_Console_Add('jump height adjusted');
4866 if cmd
= 'automap' then
4868 gShowMap
:= not gShowMap
;
4869 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4873 if cmd
= 'aimline' then
4875 gAimLine
:= not gAimLine
;
4876 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4881 procedure GameCommands(P
: SArray
);
4887 pl
: pTNetClient
= nil;
4894 cmd
:= LowerCase(P
[0]);
4896 if (cmd
= 'quit') or
4903 else if cmd
= 'pause' then
4905 if (g_ActiveWindow
= nil) then
4906 g_Game_Pause(not gPause
);
4908 else if cmd
= 'endgame' then
4909 gExit
:= EXIT_SIMPLE
4910 else if cmd
= 'restart' then
4912 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4914 if g_Game_IsClient
then
4916 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4921 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4923 else if cmd
= 'kick' then
4925 if g_Game_IsServer
then
4927 if Length(P
) < 2 then
4929 g_Console_Add('kick <name>');
4934 g_Console_Add('kick <name>');
4938 if g_Game_IsNet
then
4939 pl
:= g_Net_Client_ByName(P
[1]);
4942 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4943 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4944 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4945 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4946 if NetUseMaster
then
4948 end else if gPlayers
<> nil then
4949 for a
:= Low(gPlayers
) to High(gPlayers
) do
4950 if gPlayers
[a
] <> nil then
4951 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4953 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4954 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4956 gPlayers
[a
].Lives
:= 0;
4957 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4958 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4959 g_Player_Remove(gPlayers
[a
].UID
);
4960 if NetUseMaster
then
4962 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4966 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4968 else if cmd
= 'kick_id' then
4970 if g_Game_IsServer
and g_Game_IsNet
then
4972 if Length(P
) < 2 then
4974 g_Console_Add('kick_id <client ID>');
4979 g_Console_Add('kick_id <client ID>');
4983 a
:= StrToIntDef(P
[1], 0);
4984 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4986 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4988 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4989 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4990 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4991 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4992 if NetUseMaster
then
4997 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4999 else if cmd
= 'ban' then
5001 if g_Game_IsServer
and g_Game_IsNet
then
5003 if Length(P
) < 2 then
5005 g_Console_Add('ban <name>');
5010 g_Console_Add('ban <name>');
5014 pl
:= g_Net_Client_ByName(P
[1]);
5017 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5018 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5019 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5020 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5021 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5022 if NetUseMaster
then
5025 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5027 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5029 else if cmd
= 'ban_id' then
5031 if g_Game_IsServer
and g_Game_IsNet
then
5033 if Length(P
) < 2 then
5035 g_Console_Add('ban_id <client ID>');
5040 g_Console_Add('ban_id <client ID>');
5044 a
:= StrToIntDef(P
[1], 0);
5045 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5046 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5048 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5049 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5050 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5051 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5052 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5053 if NetUseMaster
then
5057 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5059 else if cmd
= 'permban' then
5061 if g_Game_IsServer
and g_Game_IsNet
then
5063 if Length(P
) < 2 then
5065 g_Console_Add('permban <name>');
5070 g_Console_Add('permban <name>');
5074 pl
:= g_Net_Client_ByName(P
[1]);
5077 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5078 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5079 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5080 g_Net_SaveBanList();
5081 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5082 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5083 if NetUseMaster
then
5086 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5088 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5090 else if cmd
= 'permban_id' then
5092 if g_Game_IsServer
and g_Game_IsNet
then
5094 if Length(P
) < 2 then
5096 g_Console_Add('permban_id <client ID>');
5101 g_Console_Add('permban_id <client ID>');
5105 a
:= StrToIntDef(P
[1], 0);
5106 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5107 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5109 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5110 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5111 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5112 g_Net_SaveBanList();
5113 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5114 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5115 if NetUseMaster
then
5119 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5121 else if cmd
= 'unban' then
5123 if g_Game_IsServer
and g_Game_IsNet
then
5125 if Length(P
) < 2 then
5127 g_Console_Add('unban <IP Address>');
5132 g_Console_Add('unban <IP Address>');
5136 if g_Net_UnbanHost(P
[1]) then
5138 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5139 g_Net_SaveBanList();
5141 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5143 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5145 else if cmd
= 'clientlist' then
5147 if g_Game_IsServer
and g_Game_IsNet
then
5150 if NetClients
<> nil then
5151 for a
:= Low(NetClients
) to High(NetClients
) do
5152 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5154 plr
:= g_Player_Get(NetClients
[a
].Player
);
5155 if plr
= nil then continue
;
5157 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5158 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5161 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5163 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5165 else if cmd
= 'connect' then
5167 if (NetMode
= NET_NONE
) then
5169 if Length(P
) < 2 then
5171 g_Console_Add('connect <IP> [port] [password]');
5176 g_Console_Add('connect <IP> [port] [password]');
5180 if Length(P
) > 2 then
5181 prt
:= StrToIntDef(P
[2], 25666)
5185 if Length(P
) > 3 then
5190 g_Game_StartClient(P
[1], prt
, pw
);
5193 else if cmd
= 'disconnect' then
5195 if (NetMode
= NET_CLIENT
) then
5198 else if cmd
= 'reconnect' then
5200 if (NetMode
= NET_SERVER
) then
5203 if (NetMode
= NET_CLIENT
) then
5206 gExit
:= EXIT_SIMPLE
;
5210 //TODO: Use last successful password to reconnect, instead of ''
5211 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5213 else if (cmd
= 'addbot') or
5214 (cmd
= 'bot_add') then
5216 if Length(P
) > 1 then
5217 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5219 g_Bot_Add(TEAM_NONE
, 2);
5221 else if cmd
= 'bot_addlist' then
5223 if Length(P
) > 1 then
5224 if Length(P
) = 2 then
5225 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5227 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5229 else if cmd
= 'bot_removeall' then
5231 else if cmd
= 'chat' then
5233 if g_Game_IsNet
then
5235 if Length(P
) > 1 then
5237 for a
:= 1 to High(P
) do
5238 chstr
:= chstr
+ P
[a
] + ' ';
5240 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5242 if Length(chstr
) < 1 then
5244 g_Console_Add('chat <text>');
5248 chstr
:= b_Text_Format(chstr
);
5249 if g_Game_IsClient
then
5250 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5252 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5255 g_Console_Add('chat <text>');
5257 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5259 else if cmd
= 'teamchat' then
5261 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5263 if Length(P
) > 1 then
5265 for a
:= 1 to High(P
) do
5266 chstr
:= chstr
+ P
[a
] + ' ';
5268 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5270 if Length(chstr
) < 1 then
5272 g_Console_Add('teamchat <text>');
5276 chstr
:= b_Text_Format(chstr
);
5277 if g_Game_IsClient
then
5278 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5280 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5281 gPlayer1Settings
.Team
);
5284 g_Console_Add('teamchat <text>');
5286 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5288 else if cmd
= 'game' then
5290 if gGameSettings
.GameType
<> GT_NONE
then
5292 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5295 if Length(P
) = 1 then
5297 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5300 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5301 P
[1] := addWadExtension(P
[1]);
5302 if FileExists(MapsDir
+ P
[1]) then
5304 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5305 if Length(P
) < 3 then
5308 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5311 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5313 if g_Map_Exist(MapsDir
+ s
) then
5315 // Çàïóñêàåì ñâîþ èãðó
5317 with gGameSettings
do
5319 GameMode
:= g_Game_TextToMode(gcGameMode
);
5320 if gSwitchGameMode
<> GM_NONE
then
5321 GameMode
:= gSwitchGameMode
;
5322 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5323 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5325 if Length(P
) >= 4 then
5326 b
:= StrToIntDef(P
[3], 1);
5327 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5328 GoalLimit
, MaxLives
, Options
, b
);
5333 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5335 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5337 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5339 else if cmd
= 'host' then
5341 if gGameSettings
.GameType
<> GT_NONE
then
5343 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5346 if Length(P
) < 4 then
5348 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5351 if not StrToIp(P
[1], listen
) then
5353 prt
:= StrToIntDef(P
[2], 25666);
5355 P
[3] := addWadExtension(P
[3]);
5356 if FileExists(MapsDir
+ P
[3]) then
5358 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5359 if Length(P
) < 5 then
5362 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5365 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5367 if g_Map_Exist(MapsDir
+ s
) then
5369 // Çàïóñêàåì ñâîþ èãðó
5371 with gGameSettings
do
5373 GameMode
:= g_Game_TextToMode(gcGameMode
);
5374 if gSwitchGameMode
<> GM_NONE
then
5375 GameMode
:= gSwitchGameMode
;
5376 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5377 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5379 if Length(P
) >= 6 then
5380 b
:= StrToIntDef(P
[5], 0);
5381 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5382 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5387 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5389 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5391 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5393 else if cmd
= 'map' then
5395 if Length(P
) = 1 then
5397 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5399 g_Console_Add(cmd
+ ' <MAP>');
5400 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5402 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5404 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5406 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5407 if Length(P
) < 3 then
5409 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5410 s
:= UpperCase(P
[1]);
5411 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5412 begin // Êàðòà íàøëàñü
5413 gExitByTrigger
:= False;
5415 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5417 gExit
:= EXIT_ENDLEVELCUSTOM
;
5419 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5420 g_Game_ChangeMap(s
);
5423 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5424 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5425 P
[1] := addWadExtension(P
[1]);
5426 if FileExists(MapsDir
+ P
[1]) then
5428 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5430 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5432 s
:= P
[1] + ':\' + P
[2];
5434 if g_Map_Exist(MapsDir
+ s
) then
5436 gExitByTrigger
:= False;
5438 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5440 gExit
:= EXIT_ENDLEVELCUSTOM
;
5442 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5443 g_Game_ChangeMap(s
);
5446 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5448 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5450 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5454 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5455 P
[1] := addWadExtension(P
[1]);
5456 if FileExists(MapsDir
+ P
[1]) then
5459 P
[2] := UpperCase(P
[2]);
5460 s
:= P
[1] + ':\' + P
[2];
5462 if g_Map_Exist(MapsDir
+ s
) then
5463 begin // Íàøëè êàðòó
5464 gExitByTrigger
:= False;
5466 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5468 gExit
:= EXIT_ENDLEVELCUSTOM
;
5470 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5471 g_Game_ChangeMap(s
);
5473 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5475 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5478 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5480 else if cmd
= 'nextmap' then
5482 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5483 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5486 if Length(P
) = 1 then
5488 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5490 g_Console_Add(cmd
+ ' <MAP>');
5491 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5494 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5499 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5501 if Length(P
) < 3 then
5503 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5504 s
:= UpperCase(P
[1]);
5505 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5506 begin // Êàðòà íàøëàñü
5507 gExitByTrigger
:= False;
5512 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5513 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5514 P
[1] := addWadExtension(P
[1]);
5515 if FileExists(MapsDir
+ P
[1]) then
5517 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5519 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5521 s
:= P
[1] + ':\' + P
[2];
5523 if g_Map_Exist(MapsDir
+ s
) then
5524 begin // Óñòàíàâëèâàåì êàðòó
5525 gExitByTrigger
:= False;
5530 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5532 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5534 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5538 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5539 P
[1] := addWadExtension(P
[1]);
5540 if FileExists(MapsDir
+ P
[1]) then
5543 P
[2] := UpperCase(P
[2]);
5544 s
:= P
[1] + ':\' + P
[2];
5546 if g_Map_Exist(MapsDir
+ s
) then
5547 begin // Íàøëè êàðòó
5548 gExitByTrigger
:= False;
5552 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5554 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5557 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5560 if gNextMap
= '' then
5561 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5563 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5566 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5569 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5571 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5573 gExitByTrigger
:= False;
5574 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5575 if (gNextMap
= '') and (gTriggers
<> nil) then
5576 for a
:= 0 to High(gTriggers
) do
5577 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5579 gExitByTrigger
:= True;
5580 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5583 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5584 if gNextMap
= '' then
5585 gNextMap
:= g_Game_GetNextMap();
5586 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5587 if Pos(':\', gNextMap
) = 0 then
5588 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5591 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5592 if g_Map_Exist(MapsDir
+ s
) then
5593 gExit
:= EXIT_ENDLEVELCUSTOM
5595 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5597 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5599 else if (cmd
= 'event') then
5601 if (Length(P
) <= 1) then
5603 for a
:= 0 to High(gEvents
) do
5604 if gEvents
[a
].Command
= '' then
5605 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5607 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5610 if (Length(P
) = 2) then
5612 for a
:= 0 to High(gEvents
) do
5613 if gEvents
[a
].Name
= P
[1] then
5614 if gEvents
[a
].Command
= '' then
5615 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5617 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5620 for a
:= 0 to High(gEvents
) do
5621 if gEvents
[a
].Name
= P
[1] then
5623 gEvents
[a
].Command
:= '';
5624 for b
:= 2 to High(P
) do
5625 if Pos(' ', P
[b
]) = 0 then
5626 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5628 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5629 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5633 // Êîìàíäû Ñâîåé èãðû:
5634 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5636 if cmd
= 'bot_addred' then
5638 if Length(P
) > 1 then
5639 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5641 g_Bot_Add(TEAM_RED
, 2);
5643 else if cmd
= 'bot_addblue' then
5645 if Length(P
) > 1 then
5646 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5648 g_Bot_Add(TEAM_BLUE
, 2);
5650 else if cmd
= 'suicide' then
5654 if g_Game_IsClient
then
5655 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5658 if gPlayer1
<> nil then
5659 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5660 if gPlayer2
<> nil then
5661 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5665 else if cmd
= 'spectate' then
5671 else if cmd
= 'say' then
5673 if g_Game_IsServer
and g_Game_IsNet
then
5675 if Length(P
) > 1 then
5678 for a
:= 1 to High(P
) do
5679 chstr
:= chstr
+ P
[a
] + ' ';
5681 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5683 if Length(chstr
) < 1 then
5685 g_Console_Add('say <text>');
5689 chstr
:= b_Text_Format(chstr
);
5690 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5692 else g_Console_Add('say <text>');
5694 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5696 else if cmd
= 'tell' then
5698 if g_Game_IsServer
and g_Game_IsNet
then
5700 if (Length(P
) > 2) and (P
[1] <> '') then
5703 for a
:= 2 to High(P
) do
5704 chstr
:= chstr
+ P
[a
] + ' ';
5706 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5708 if Length(chstr
) < 1 then
5710 g_Console_Add('tell <playername> <text>');
5714 pl
:= g_Net_Client_ByName(P
[1]);
5716 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5718 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5720 else g_Console_Add('tell <playername> <text>');
5722 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5724 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5726 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5728 // Äîïîëíèòåëüíîå âðåìÿ:
5729 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5731 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5732 [gGameSettings
.TimeLimit
div 3600,
5733 (gGameSettings
.TimeLimit
div 60) mod 60,
5734 gGameSettings
.TimeLimit
mod 60]));
5735 if g_Game_IsNet
then MH_SEND_GameSettings
;
5737 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5739 if (Length(P
) <= 1) then
5740 g_Console_Add('rcon_password <password>')
5742 MC_SEND_RCONPassword(P
[1]);
5744 else if cmd
= 'rcon' then
5746 if g_Game_IsClient
then
5748 if Length(P
) > 1 then
5751 for a
:= 1 to High(P
) do
5752 chstr
:= chstr
+ P
[a
] + ' ';
5754 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5756 if Length(chstr
) < 1 then
5758 g_Console_Add('rcon <command>');
5762 MC_SEND_RCONCommand(chstr
);
5764 else g_Console_Add('rcon <command>');
5767 else if cmd
= 'ready' then
5769 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5770 gLMSRespawnTime
:= gTime
+ 100;
5772 else if (cmd
= 'callvote') and g_Game_IsNet
then
5774 if Length(P
) > 1 then
5777 for a
:= 1 to High(P
) do begin
5778 if a
> 1 then chstr
:= chstr
+ ' ';
5779 chstr
:= chstr
+ P
[a
];
5782 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5784 if Length(chstr
) < 1 then
5786 g_Console_Add('callvote <command>');
5790 if g_Game_IsClient
then
5791 MC_SEND_Vote(True, chstr
)
5793 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5794 g_Console_Process('vote', True);
5797 g_Console_Add('callvote <command>');
5799 else if (cmd
= 'vote') and g_Game_IsNet
then
5801 if g_Game_IsClient
then
5803 else if gVoteInProgress
then
5805 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5806 a
:= Floor((NetClientCount
+1)/2.0) + 1
5808 a
:= Floor(NetClientCount
/2.0) + 1;
5813 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5814 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5820 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5821 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5829 procedure g_TakeScreenShot();
5837 if e_NoGraphics
then Exit
;
5838 ssdir
:= GameDir
+'/screenshots';
5839 if not findFileCI(ssdir
, true) then
5841 // try to create dir
5846 if not findFileCI(ssdir
, true) then exit
; // alas
5849 for a
:= 1 to High(Word) do
5851 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
5853 if findFileCI(t
, true) then continue
;
5854 if not findFileCI(FileName
) then
5857 st
:= createDiskFile(FileName
);
5859 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
5864 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5872 procedure g_Game_InGameMenu(Show
: Boolean);
5874 if (g_ActiveWindow
= nil) and Show
then
5876 if gGameSettings
.GameType
= GT_SINGLE
then
5877 g_GUI_ShowWindow('GameSingleMenu')
5880 if g_Game_IsClient
then
5881 g_GUI_ShowWindow('GameClientMenu')
5883 if g_Game_IsNet
then
5884 g_GUI_ShowWindow('GameServerMenu')
5886 g_GUI_ShowWindow('GameCustomMenu');
5888 g_Sound_PlayEx('MENU_OPEN');
5890 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5891 if (not g_Game_IsNet
) then
5895 if (g_ActiveWindow
<> nil) and (not Show
) then
5897 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5898 if (not g_Game_IsNet
) then
5899 g_Game_Pause(False);
5903 procedure g_Game_Pause(Enable
: Boolean);
5908 if gPause
= Enable
then
5911 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5915 g_Game_PauseAllSounds(Enable
);
5918 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5923 if gTriggers
<> nil then
5924 for i
:= 0 to High(gTriggers
) do
5925 with gTriggers
[i
] do
5926 if (TriggerType
= TRIGGER_SOUND
) and
5928 Sound
.IsPlaying() then
5930 Sound
.Pause(Enable
);
5934 if gPlayers
<> nil then
5935 for i
:= 0 to High(gPlayers
) do
5936 if gPlayers
[i
] <> nil then
5937 gPlayers
[i
].PauseSounds(Enable
);
5940 if gMusic
<> nil then
5941 gMusic
.Pause(Enable
);
5944 procedure g_Game_StopAllSounds(all
: Boolean);
5948 if gTriggers
<> nil then
5949 for i
:= 0 to High(gTriggers
) do
5950 with gTriggers
[i
] do
5951 if (TriggerType
= TRIGGER_SOUND
) and
5955 if gMusic
<> nil then
5962 procedure g_Game_UpdateTriggerSounds();
5966 if gTriggers
<> nil then
5967 for i
:= 0 to High(gTriggers
) do
5968 with gTriggers
[i
] do
5969 if (TriggerType
= TRIGGER_SOUND
) and
5972 Sound
.IsPlaying() then
5974 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
5975 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
5977 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
5978 Sound
.SetVolume(Data
.Volume
/255.0);
5981 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
5985 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
5988 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
5993 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
5998 if gSpectMode
<> SPECT_PLAYERS
then
6000 if gSpectPID1
= UID
then
6005 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6012 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6017 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6022 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6027 if gSpectMode
<> SPECT_PLAYERS
then
6029 Pl
:= g_Player_Get(gSpectPID1
);
6030 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6035 if gSpectViewTwo
then
6037 Pl
:= g_Player_Get(gSpectPID2
);
6038 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6046 procedure g_Game_Message(Msg
: string; Time
: Word);
6048 MessageText
:= b_Text_Format(Msg
);
6049 MessageTime
:= Time
;
6052 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6061 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6065 if goodsnd
[a
].IsPlaying() then
6068 goodsnd
[Random(4)].Play();
6071 procedure g_Game_Announce_KillCombo(Param
: Integer);
6078 UID
:= Param
and $FFFF;
6083 Pl
:= g_Player_Get(UID
);
6092 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6096 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6100 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6104 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6112 if not g_Game_IsWatchedPlayer(UID
) then
6115 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6119 if killsnd
[n
].IsPlaying() then
6124 procedure g_Game_StartVote(Command
, Initiator
: string);
6128 if not gVotesEnabled
then Exit
;
6129 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6130 if gVoteInProgress
or gVotePassed
then
6132 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6133 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6136 gVoteInProgress
:= True;
6137 gVotePassed
:= False;
6138 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6141 gVoteCommand
:= Command
;
6143 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6144 Need
:= Floor((NetClientCount
+1)/2.0)+1
6146 Need
:= Floor(NetClientCount
/2.0)+1;
6147 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6148 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6151 procedure g_Game_CheckVote
;
6155 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6156 if not gVoteInProgress
then Exit
;
6158 if (gTime
>= gVoteTimer
) then
6160 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6161 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6163 Need
:= Floor(NetClientCount
/2.0) + 1;
6164 if gVoteCount
>= Need
then
6166 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6167 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6168 gVotePassed
:= True;
6169 gVoteCmdTimer
:= gTime
+ 5000;
6173 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6174 MH_SEND_VoteEvent(NET_VE_FAILED
);
6176 if NetClients
<> nil then
6177 for I
:= Low(NetClients
) to High(NetClients
) do
6178 if NetClients
[i
].Used
then
6179 NetClients
[i
].Voted
:= False;
6180 gVoteInProgress
:= False;
6186 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6187 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6189 Need
:= Floor(NetClientCount
/2.0) + 1;
6190 if gVoteCount
>= Need
then
6192 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6193 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6194 gVoteInProgress
:= False;
6195 gVotePassed
:= True;
6196 gVoteCmdTimer
:= gTime
+ 5000;
6199 if NetClients
<> nil then
6200 for I
:= Low(NetClients
) to High(NetClients
) do
6201 if NetClients
[i
].Used
then
6202 NetClients
[i
].Voted
:= False;
6207 procedure g_Game_LoadMapList(FileName
: string);
6215 if not FileExists(FileName
) then Exit
;
6217 AssignFile(ListFile
, FileName
);
6219 while not EOF(ListFile
) do
6221 ReadLn(ListFile
, s
);
6224 if s
= '' then Continue
;
6226 SetLength(MapList
, Length(MapList
)+1);
6227 MapList
[High(MapList
)] := s
;
6229 CloseFile(ListFile
);
6232 procedure g_Game_SetDebugMode();
6235 // ×èòû (äàæå â ñâîåé èãðå):
6239 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6243 if Length(LoadingStat
.Msgs
) = 0 then
6249 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6250 if NextMsg
= Length(Msgs
) then
6252 for i
:= 0 to High(Msgs
)-1 do
6253 Msgs
[i
] := Msgs
[i
+1];
6261 Msgs
[NextMsg
-1] := Text;
6267 g_ActiveWindow
:= nil;
6272 procedure g_Game_StepLoading();
6278 if (ShowCount
> LOADING_SHOW_STEP
) then
6286 procedure g_Game_ClearLoading();
6295 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6296 if len
< 1 then len
:= 1;
6297 SetLength(Msgs
, len
);
6298 for len
:= Low(Msgs
) to High(Msgs
) do
6304 procedure Parse_Params(var pars
: TParamStrValues
);
6311 while i
<= ParamCount
do
6314 if (s
[1] = '-') and (Length(s
) > 1) then
6316 if (s
[2] = '-') and (Length(s
) > 2) then
6317 begin // Îäèíî÷íûé ïàðàìåòð
6318 SetLength(pars
, Length(pars
) + 1);
6319 with pars
[High(pars
)] do
6321 Name
:= LowerCase(s
);
6326 if (i
< ParamCount
) then
6327 begin // Ïàðàìåòð ñî çíà÷åíèåì
6329 SetLength(pars
, Length(pars
) + 1);
6330 with pars
[High(pars
)] do
6332 Name
:= LowerCase(s
);
6333 Value
:= LowerCase(ParamStr(i
));
6342 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6347 for i
:= 0 to High(pars
) do
6348 if pars
[i
].Name
= aName
then
6350 Result
:= pars
[i
].Value
;
6355 procedure g_Game_Process_Params();
6357 pars
: TParamStrValues
;
6360 LimT
, LimS
: Integer;
6371 s
:= Find_Param_Value(pars
, '--debug');
6373 g_Game_SetDebugMode();
6375 // Connect when game loads
6376 ip
:= Find_Param_Value(pars
, '-connect');
6380 s
:= Find_Param_Value(pars
, '-port');
6381 if (s
= '') or not TryStrToInt(s
, Port
) then
6384 s
:= Find_Param_Value(pars
, '-pw');
6386 g_Game_StartClient(ip
, Port
, s
);
6390 // Start map when game loads:
6391 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6392 if isWadPath(map
) then
6395 s
:= Find_Param_Value(pars
, '-gm');
6396 GMode
:= g_Game_TextToMode(s
);
6397 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6398 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6401 s
:= Find_Param_Value(pars
, '-limt');
6402 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6408 s
:= Find_Param_Value(pars
, '-lims');
6409 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6415 s
:= Find_Param_Value(pars
, '-lives');
6416 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6422 s
:= Find_Param_Value(pars
, '-opt');
6424 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6426 Opt
:= StrToIntDef(s
, 0);
6428 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6431 s
:= Find_Param_Value(pars
, '--close');
6435 // Delete test map after play:
6436 s
:= Find_Param_Value(pars
, '--testdelete');
6439 gMapToDelete
:= MapsDir
+ map
;
6440 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6444 // Delete temporary WAD after play:
6445 s
:= Find_Param_Value(pars
, '--tempdelete');
6448 gMapToDelete
:= MapsDir
+ map
;
6449 gTempDelete
:= True;
6452 // Number of players:
6453 s
:= Find_Param_Value(pars
, '-pl');
6457 n
:= StrToIntDef(s
, 1);
6460 s
:= Find_Param_Value(pars
, '-port');
6461 if (s
= '') or not TryStrToInt(s
, Port
) then
6462 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6464 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6467 // Execute script when game loads:
6468 s
:= Find_Param_Value(pars
, '-exec');
6471 if Pos(':\', s
) = 0 then
6472 s
:= GameDir
+ '/' + s
;
6477 if IOResult
<> 0 then
6479 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6480 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6484 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6485 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6490 if IOResult
<> 0 then
6492 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6493 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6497 if Pos('#', s
) <> 1 then // script comment
6498 g_Console_Process(s
, True);