6 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
7 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, WADEDITOR
, md5
;
10 TGameSettings
= record
26 TDelayedEvent
= record
34 TPlayerSettings
= record
53 function g_Game_IsNet(): Boolean;
54 function g_Game_IsServer(): Boolean;
55 function g_Game_IsClient(): Boolean;
56 procedure g_Game_Init();
57 procedure g_Game_Free();
58 procedure g_Game_LoadData();
59 procedure g_Game_FreeData();
60 procedure g_Game_Update();
61 procedure g_Game_Draw();
62 procedure g_Game_Quit();
63 procedure g_Game_SetupScreenSize();
64 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
65 function g_Game_ModeToText(Mode
: Byte): string;
66 function g_Game_TextToMode(Mode
: string): Byte;
67 procedure g_Game_ExecuteEvent(Name
: String);
68 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
69 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
70 procedure g_Game_RemovePlayer();
71 procedure g_Game_Spectate();
72 procedure g_Game_SpectateCenterView();
73 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
74 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
75 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
76 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
77 procedure g_Game_Restart();
78 procedure g_Game_RestartLevel();
79 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
80 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
81 procedure g_Game_SaveOptions();
82 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
83 procedure g_Game_ChangeMap(MapPath
: String);
84 procedure g_Game_ExitLevel(Map
: Char16
);
85 function g_Game_GetFirstMap(WAD
: String): String;
86 function g_Game_GetNextMap(): String;
87 procedure g_Game_NextLevel();
88 procedure g_Game_Pause(Enable
: Boolean);
89 procedure g_Game_InGameMenu(Show
: Boolean);
90 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
91 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
92 procedure g_Game_Message(Msg
: String; Time
: Word);
93 procedure g_Game_LoadMapList(FileName
: String);
94 procedure g_Game_PauseAllSounds(Enable
: Boolean);
95 procedure g_Game_StopAllSounds(all
: Boolean);
96 procedure g_Game_UpdateTriggerSounds();
97 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
98 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
99 procedure g_Game_Announce_KillCombo(Param
: Integer);
100 procedure g_Game_StartVote(Command
, Initiator
: string);
101 procedure g_Game_CheckVote
;
102 procedure g_TakeScreenShot();
103 procedure g_FatalError(Text: String);
104 procedure g_SimpleError(Text: String);
105 function g_Game_IsTestMap(): Boolean;
106 procedure g_Game_DeleteTestMap();
107 procedure GameCVars(P
: SArray
);
108 procedure GameCommands(P
: SArray
);
109 procedure DebugCommands(P
: SArray
);
110 procedure g_Game_Process_Params
;
111 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
112 procedure g_Game_StepLoading();
113 procedure g_Game_ClearLoading();
114 procedure g_Game_SetDebugMode();
115 procedure DrawLoadingStat();
117 { procedure SetWinPause(Enable: Boolean); }
122 LOADING_SHOW_STEP
= 100;
123 LOADING_INTERLINE
= 20;
138 MESSAGE_DIKEY
= WM_USER
+ 1;
143 EXIT_ENDLEVELSINGLE
= 4;
144 EXIT_ENDLEVELCUSTOM
= 5;
146 GAME_OPTION_RESERVED
= 1;
147 GAME_OPTION_TEAMDAMAGE
= 2;
148 GAME_OPTION_ALLOWEXIT
= 4;
149 GAME_OPTION_WEAPONSTAY
= 8;
150 GAME_OPTION_MONSTERS
= 16;
151 GAME_OPTION_BOTVSPLAYER
= 32;
152 GAME_OPTION_BOTVSMONSTER
= 64;
157 STATE_INTERCUSTOM
= 3;
158 STATE_INTERSINGLE
= 4;
164 LMS_RESPAWN_NONE
= 0;
165 LMS_RESPAWN_WARMUP
= 1;
166 LMS_RESPAWN_FINAL
= 2;
182 CONFIG_FILENAME
= 'Doom2DF.cfg';
183 LOG_FILENAME
= 'Doom2DF.log';
185 TEST_MAP_NAME
= '$$$_TEST_$$$';
187 STD_PLAYER_MODEL
= 'Doomer';
191 gGameSettings
: TGameSettings
;
192 gPlayer1Settings
: TPlayerSettings
;
193 gPlayer2Settings
: TPlayerSettings
;
195 gPlayerScreenSize
: TPoint
;
196 gPlayer1ScreenCoord
: TPoint
;
197 gPlayer2ScreenCoord
: TPoint
;
198 gPlayer1
: TPlayer
= nil;
199 gPlayer2
: TPlayer
= nil;
200 gPlayerDrawn
: TPlayer
= nil;
202 gSwitchGameMode
: Byte = GM_DM
;
203 gHearPoint1
, gHearPoint2
: THearPoint
;
204 gSoundEffectsDF
: Boolean = False;
205 gSoundTriggerTime
: Word = 0;
206 gAnnouncer
: Byte = ANNOUNCE_NONE
;
207 goodsnd
: array[0..3] of TPlayableSound
;
208 killsnd
: array[0..3] of TPlayableSound
;
209 gDefInterTime
: ShortInt = -1;
210 gInterEndTime
: LongWord = 0;
211 gInterTime
: LongWord = 0;
212 gServInterTime
: Byte = 0;
213 gGameStartTime
: LongWord = 0;
214 gTotalMonsters
: Integer = 0;
216 gShowTime
: Boolean = True;
217 gShowFPS
: Boolean = False;
218 gShowGoals
: Boolean = True;
219 gShowStat
: Boolean = True;
220 gShowKillMsg
: Boolean = True;
221 gShowLives
: Boolean = True;
222 gShowPing
: Boolean = False;
223 gShowMap
: Boolean = False;
225 gState
: Byte = STATE_NONE
;
227 sWidth
, sHeight
: Word;
228 gSpectMode
: Byte = SPECT_NONE
;
229 gSpectHUD
: Boolean = True;
230 gSpectKeyPress
: Boolean = False;
231 gSpectX
: Integer = 0;
232 gSpectY
: Integer = 0;
233 gSpectStep
: Byte = 8;
234 gSpectViewTwo
: Boolean = False;
235 gSpectPID1
: Integer = -1;
236 gSpectPID2
: Integer = -1;
237 gMusic
: TMusic
= nil;
238 gLoadGameMode
: Boolean;
239 gCheats
: Boolean = False;
240 gMapOnce
: Boolean = False;
241 gMapToDelete
: String;
242 gTempDelete
: Boolean = False;
243 gLastMap
: Boolean = False;
244 gWinPosX
, gWinPosY
: Integer;
245 gWinSizeX
, gWinSizeY
: Integer;
246 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
247 gWinActive
: Boolean = False;
248 gResolutionChange
: Boolean = False;
249 gRC_Width
, gRC_Height
: Word;
250 gRC_FullScreen
, gRC_Maximized
: Boolean;
251 gLanguageChange
: Boolean = False;
252 gDebugMode
: Boolean = False;
253 g_debug_Sounds
: Boolean = False;
254 g_debug_Frames
: Boolean = False;
255 g_debug_WinMsgs
: Boolean = False;
256 g_debug_MonsterOff
: Boolean = False;
257 g_debug_BotAIOff
: Byte = 0;
258 g_debug_HealthBar
: Boolean = False;
259 g_Debug_Player
: Boolean = False;
260 gCoopMonstersKilled
: Word = 0;
261 gCoopSecretsFound
: Word = 0;
262 gCoopTotalMonstersKilled
: Word = 0;
263 gCoopTotalSecretsFound
: Word = 0;
264 gCoopTotalMonsters
: Word = 0;
265 gCoopTotalSecrets
: Word = 0;
266 gStatsOff
: Boolean = False;
267 gStatsPressed
: Boolean = False;
268 gExitByTrigger
: Boolean = False;
269 gNextMap
: String = '';
270 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
271 gLMSRespawnTime
: Cardinal = 0;
272 gLMSSoftSpawn
: Boolean = False;
273 gMissionFailed
: Boolean = False;
274 gVoteInProgress
: Boolean = False;
275 gVotePassed
: Boolean = False;
276 gVoteCommand
: string = '';
277 gVoteTimer
: Cardinal = 0;
278 gVoteCmdTimer
: Cardinal = 0;
279 gVoteCount
: Integer = 0;
280 gVoteTimeout
: Cardinal = 30;
281 gVoted
: Boolean = False;
282 gVotesEnabled
: Boolean = True;
283 gEvents
: Array of TGameEvent
;
284 gDelayedEvents
: Array of TDelayedEvent
;
286 P1MoveButton
: Byte = 0;
287 P2MoveButton
: Byte = 0;
292 g_textures
, g_main
, g_window
, g_menu
,
293 e_input
, e_log
, g_console
, g_items
, g_map
,
294 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
295 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
296 BinEditor
, g_language
, g_net
, SDL
,
297 ENet
, e_fixedbuffer
, g_netmsg
, g_netmaster
, GL
, GLExt
;
300 TEndCustomGameStat
= record
301 PlayerStat
: TPlayerStatArray
;
305 Map
, MapName
: String;
308 TEndSingleGameStat
= record
309 PlayerStat
: Array [0..1] of record
315 TotalSecrets
: Integer;
318 TLoadingStat
= record
322 Msgs
: Array of String;
326 TParamStrValue
= record
331 TParamStrValues
= Array of TParamStrValue
;
334 INTER_ACTION_TEXT
= 1;
335 INTER_ACTION_PIC
= 2;
336 INTER_ACTION_MUSIC
= 3;
340 FPSCounter
, UPSCounter
: Word;
341 FPSTime
, UPSTime
: LongWord;
342 DataLoaded
: Boolean = False;
343 LastScreenShot
: Int64;
344 IsDrawStat
: Boolean = False;
345 CustomStat
: TEndCustomGameStat
;
346 SingleStat
: TEndSingleGameStat
;
347 LoadingStat
: TLoadingStat
;
348 EndingGameCounter
: Byte = 0;
351 MapList
: SArray
= nil;
352 MapIndex
: Integer = -1;
358 text: Array of ShortString;
359 anim
: Array of ShortString;
360 pic
: Array of ShortString;
361 mus
: Array of ShortString;
363 triggers
: Array of record
365 actions
: Array of record
366 action
, p1
, p2
: Integer;
369 cur_trigger
: Integer;
382 function Compare(a
, b
: TPlayerStat
): Integer;
384 if a
.Spectator
then Result
:= 1
385 else if b
.Spectator
then Result
:= -1
386 else if a
.Frags
< b
.Frags
then Result
:= 1
387 else if a
.Frags
> b
.Frags
then Result
:= -1
388 else if a
.Deaths
< b
.Deaths
then Result
:= -1
389 else if a
.Deaths
> b
.Deaths
then Result
:= 1
390 else if a
.Kills
< b
.Kills
then Result
:= -1
394 procedure SortGameStat(var stat
: TPlayerStatArray
);
399 if stat
= nil then Exit
;
401 for I
:= High(stat
) downto Low(stat
) do
402 for J
:= Low(stat
) to High(stat
) - 1 do
403 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
406 stat
[J
] := stat
[J
+ 1];
411 function g_Game_ModeToText(Mode
: Byte): string;
415 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
416 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
417 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
418 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
419 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
423 function g_Game_TextToMode(Mode
: string): Byte;
426 Mode
:= UpperCase(Mode
);
427 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
432 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
437 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
442 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
447 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
454 function g_Game_IsNet(): Boolean;
456 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
459 function g_Game_IsServer(): Boolean;
461 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
464 function g_Game_IsClient(): Boolean;
466 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
469 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
476 Result
.name
:= ExtractFileName(WAD
);
477 Result
.description
:= '';
480 w
:= TWADEditor_1
.Create();
483 if not w
.GetResource('', 'INTERSCRIPT', p
, len
) then
489 cfg
:= TConfig
.CreateMem(p
, len
);
490 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
491 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
492 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
493 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
499 procedure g_Game_FreeWAD();
503 for a
:= 0 to High(MegaWAD
.res
.pic
) do
504 if MegaWAD
.res
.pic
[a
] <> '' then
505 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
507 for a
:= 0 to High(MegaWAD
.res
.mus
) do
508 if MegaWAD
.res
.mus
[a
] <> '' then
509 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
511 MegaWAD
.res
.pic
:= nil;
512 MegaWAD
.res
.text := nil;
513 MegaWAD
.res
.anim
:= nil;
514 MegaWAD
.res
.mus
:= nil;
515 MegaWAD
.triggers
:= nil;
517 g_Texture_Delete('TEXTURE_endpic');
518 g_Sound_Delete('MUSIC_endmus');
520 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
521 gGameSettings
.WAD
:= '';
524 procedure g_Game_LoadWAD(WAD
: string);
533 gGameSettings
.WAD
:= WAD
;
534 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
537 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
539 w
:= TWADEditor_1
.Create();
540 w
.ReadFile(MapsDir
+ WAD
);
542 if not w
.GetResource('', 'INTERSCRIPT', p
, len
) then
548 cfg
:= TConfig
.CreateMem(p
, len
);
553 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
554 if s = '' then Break;
557 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
558 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
560 g_Texture_CreateWADEx(s, s);
566 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
567 if s = '' then Break;
570 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
571 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
573 g_Music_CreateWADEx(s, s);
576 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
577 if MegaWAD
.endpic
<> '' then
579 g_ProcessResourceStr(MegaWAD
.endpic
, @s
, nil, nil);
580 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
581 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
583 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
584 if MegaWAD
.endmus
<> '' then
586 g_ProcessResourceStr(MegaWAD
.endmus
, @s
, nil, nil);
587 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
588 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
596 {procedure start_trigger(t: string);
600 function next_trigger(): Boolean;
604 procedure DisableCheats();
610 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
611 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
612 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
613 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
616 procedure g_Game_ExecuteEvent(Name
: String);
622 if gEvents
= nil then
624 for a
:= 0 to High(gEvents
) do
625 if gEvents
[a
].Name
= Name
then
627 if gEvents
[a
].Command
<> '' then
628 g_Console_Process(gEvents
[a
].Command
, True);
633 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
638 if gDelayedEvents
<> nil then
639 for a
:= 0 to High(gDelayedEvents
) do
640 if not gDelayedEvents
[a
].Pending
then
647 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
648 n
:= High(gDelayedEvents
);
650 gDelayedEvents
[n
].Pending
:= True;
651 gDelayedEvents
[n
].DEType
:= DEType
;
652 gDelayedEvents
[n
].DENum
:= Num
;
653 gDelayedEvents
[n
].DEStr
:= Str
;
654 if DEType
= DE_GLOBEVENT
then
655 gDelayedEvents
[n
].Time
:= (GetTimer() div 1000) + Time
657 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
664 FileName
, SectionName
, ResName
: string;
666 if g_Game_IsNet
and g_Game_IsServer
then
667 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
673 g_Game_StopAllSounds(False);
678 EndingGameCounter
:= 0;
679 g_ActiveWindow
:= nil;
681 gLMSRespawn
:= LMS_RESPAWN_NONE
;
682 gLMSRespawnTime
:= 0;
685 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
690 begin // Ýòî áûë òåñò
694 begin // Âûõîä â ãëàâíîå ìåíþ
695 gMusic
.SetByName('MUSIC_MENU');
697 if gState
<> STATE_SLIST
then
699 g_GUI_ShowWindow('MainMenu');
700 gState
:= STATE_MENU
;
703 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
704 slReturnPressed
:= True;
705 if g_Net_Slist_Fetch(slCurrent
) then
707 if slCurrent
= nil then
708 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
711 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
714 g_Game_ExecuteEvent('ongameend');
718 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
720 if not g_Game_IsClient
then g_Game_Restart();
723 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
725 // Ñòàòèñòèêà Ñâîåé èãðû:
726 g_ProcessResourceStr(gMapInfo
.Map
, FileName
, SectionName
, ResName
);
728 CustomStat
.GameTime
:= gTime
;
729 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+ResName
;
730 CustomStat
.MapName
:= gMapInfo
.Name
;
731 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
732 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
733 CustomStat
.TeamStat
:= gTeamStat
;
735 CustomStat
.PlayerStat
:= nil;
737 // Ñòàòèñòèêà èãðîêîâ:
738 if gPlayers
<> nil then
740 for a
:= 0 to High(gPlayers
) do
741 if gPlayers
[a
] <> nil then
743 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
744 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
746 Name
:= gPlayers
[a
].Name
;
747 Frags
:= gPlayers
[a
].Frags
;
748 Deaths
:= gPlayers
[a
].Death
;
749 Kills
:= gPlayers
[a
].Kills
;
750 Team
:= gPlayers
[a
].Team
;
751 Color
:= gPlayers
[a
].Model
.Color
;
752 Spectator
:= gPlayers
[a
].FSpectator
;
756 SortGameStat(CustomStat
.PlayerStat
);
759 g_Game_ExecuteEvent('onmapend');
762 EndingGameCounter
:= 255;
763 gState
:= STATE_FOLD
;
765 if gDefInterTime
< 0 then
766 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
768 gInterEndTime
:= gDefInterTime
* 1000;
771 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
773 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
774 SingleStat
.GameTime
:= gTime
;
775 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
776 SingleStat
.TotalSecrets
:= gSecretsCount
;
777 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
778 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
779 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
780 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
781 if SingleStat
.TwoPlayers
then
783 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
784 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
787 g_Game_ExecuteEvent('onmapend');
790 if gNextMap
<> '' then
792 gMusic
.SetByName('MUSIC_INTERMUS');
794 gState
:= STATE_INTERSINGLE
;
796 g_Game_ExecuteEvent('oninter');
798 else // Áîëüøå íåò êàðò
801 EndingGameCounter
:= 255;
802 gState
:= STATE_FOLD
;
807 // Îêîí÷àíèå îáðàáîòàíî:
808 if gExit
<> EXIT_QUIT
then
812 procedure DrawStat();
814 pc
, x
, y
, w
, h
: Integer;
815 w1
, w2
, w3
, w4
: Integer;
817 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
820 stat
: TPlayerStatArray
;
827 pc
:= g_Player_GetCount
;
828 e_TextureFontGetSize(gStdFont
, cw
, ch
);
830 w
:= gScreenWidth
-(gScreenWidth
div 5);
831 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
834 h
:= 40+ch
*5+(ch
+8)*pc
;
835 x
:= (gScreenWidth
div 2)-(w
div 2);
836 y
:= (gScreenHeight
div 2)-(h
div 2);
838 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
839 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
841 g_ProcessResourceStr(gMapInfo
.Map
, @wad
, nil, @map
);
842 wad
:= ExtractFileName(wad
);
843 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
845 case gGameSettings
.GameMode
of
848 if gGameSettings
.MaxLives
= 0 then
851 s1
:= _lc
[I_GAME_LMS
];
852 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
853 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
858 if gGameSettings
.MaxLives
= 0 then
859 s1
:= _lc
[I_GAME_TDM
]
861 s1
:= _lc
[I_GAME_TLMS
];
862 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
863 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
868 s1
:= _lc
[I_GAME_CTF
];
869 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
870 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
875 if gGameSettings
.MaxLives
= 0 then
876 s1
:= _lc
[I_GAME_COOP
]
878 s1
:= _lc
[I_GAME_SURV
];
879 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
880 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
891 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
893 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
895 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
897 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
898 gStdFont
, 200, 200, 200, 1);
900 if NetMode
= NET_SERVER
then
901 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
903 if NetMode
= NET_CLIENT
then
904 e_TextureFontPrintEx(x
+8, y
+ 8,
905 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
909 stat
:= g_Player_GetStats();
912 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
913 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
915 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
917 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
921 for a
:= TEAM_RED
to TEAM_BLUE
do
925 s1
:= _lc
[I_GAME_TEAM_RED
];
932 s1
:= _lc
[I_GAME_TEAM_BLUE
];
938 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
939 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
940 gStdFont
, r
, g
, b
, 1);
942 _y
:= _y
+ch
+(ch
div 4);
943 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
946 for aa
:= 0 to High(stat
) do
947 if stat
[aa
].Team
= a
then
963 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
965 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
967 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
969 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
976 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
979 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
980 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
981 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
982 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
985 for aa
:= 0 to High(stat
) do
999 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1000 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1002 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1004 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1006 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1008 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1014 procedure g_Game_Init();
1020 gTempDelete
:= False;
1022 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1023 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1024 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1025 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1027 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1028 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1029 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1031 g_Game_ClearLoading();
1032 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1033 g_Game_SetLoadingText('', 0, False);
1035 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1038 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1039 g_PlayerModel_LoadData();
1041 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1043 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1044 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1045 until FindNext(SR
) <> 0;
1048 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1050 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1051 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1052 until FindNext(SR
) <> 0;
1058 LastScreenShot
:= 0;
1060 {e_MouseInfo.Accel := 1.0;}
1062 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1065 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1066 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1067 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1068 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1069 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1071 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1074 gMusic
:= TMusic
.Create();
1075 gMusic
.SetByName('MUSIC_MENU');
1078 gGameSettings
.WarmupTime
:= 30;
1080 gState
:= STATE_MENU
;
1082 SetLength(gEvents
, 6);
1083 gEvents
[0].Name
:= 'ongamestart';
1084 gEvents
[1].Name
:= 'ongameend';
1085 gEvents
[2].Name
:= 'onmapstart';
1086 gEvents
[3].Name
:= 'onmapend';
1087 gEvents
[4].Name
:= 'oninter';
1088 gEvents
[5].Name
:= 'onwadend';
1091 procedure g_Game_Free();
1093 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1094 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1098 g_Player_RemoveAllCorpses();
1100 gGameSettings
.GameType
:= GT_NONE
;
1101 if gGameSettings
.GameMode
= GM_SINGLE
then
1102 gGameSettings
.GameMode
:= GM_DM
;
1103 gSwitchGameMode
:= gGameSettings
.GameMode
;
1106 gExitByTrigger
:= False;
1109 function IsActivePlayer(p
: TPlayer
): Boolean;
1114 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1117 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1124 if gPlayers
= nil then
1126 for a
:= Low(gPlayers
) to High(gPlayers
) do
1127 if IsActivePlayer(gPlayers
[a
]) then
1129 if gPlayers
[a
].UID
<> ID
then
1131 Result
:= gPlayers
[a
];
1136 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1142 if gPlayers
= nil then
1146 for a
:= Low(gPlayers
) to High(gPlayers
) do
1147 if IsActivePlayer(gPlayers
[a
]) then
1149 SetLength(ids
, Length(ids
) + 1);
1150 ids
[High(ids
)] := gPlayers
[a
].UID
;
1151 if gPlayers
[a
].UID
= Skip
then
1154 if Length(ids
) = 0 then
1159 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1162 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1168 if gPlayers
= nil then
1172 for a
:= Low(gPlayers
) to High(gPlayers
) do
1173 if IsActivePlayer(gPlayers
[a
]) then
1175 SetLength(ids
, Length(ids
) + 1);
1176 ids
[High(ids
)] := gPlayers
[a
].UID
;
1177 if gPlayers
[a
].UID
= Skip
then
1180 if Length(ids
) = 0 then
1183 Result
:= ids
[Length(ids
) - 1]
1185 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1188 procedure g_Game_Update();
1190 Msg
: g_gui
.TMessage
;
1196 // Ïîðà âûêëþ÷àòü èãðó:
1197 if gExit
= EXIT_QUIT
then
1199 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1203 if gExit
= EXIT_QUIT
then
1207 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1210 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1213 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1215 gExit
:= EXIT_SIMPLE
;
1221 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1222 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1223 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1224 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1226 if g_Game_IsNet
and g_Game_IsServer
then
1228 gInterTime
:= gInterTime
+ GAME_TICK
;
1229 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1230 if a
<> gServInterTime
then
1232 gServInterTime
:= a
;
1233 MH_SEND_TimeSync(gServInterTime
);
1237 if (not g_Game_IsClient
) and
1240 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1241 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1242 and (g_ActiveWindow
= nil)
1244 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1247 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1248 g_Game_StopAllSounds(True);
1250 if gMapOnce
then // Ýòî áûë òåñò
1251 gExit
:= EXIT_SIMPLE
1253 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1254 g_Game_ChangeMap(gNextMap
)
1255 else // Ñëåäóþùåé êàðòû íåò
1257 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1259 // Âûõîä â ãëàâíîå ìåíþ:
1261 g_GUI_ShowWindow('MainMenu');
1262 gMusic
.SetByName('MUSIC_MENU');
1264 gState
:= STATE_MENU
;
1267 // Ôèíàëüíàÿ êàðòèíêà:
1268 g_Game_ExecuteEvent('onwadend');
1270 if not gMusic
.SetByName('MUSIC_endmus') then
1271 gMusic
.SetByName('MUSIC_STDENDMUS');
1273 gState
:= STATE_ENDPIC
;
1275 g_Game_ExecuteEvent('ongameend');
1281 if gState
= STATE_INTERTEXT
then
1282 if InterText
.counter
> 0 then
1283 InterText
.counter
:= InterText
.counter
- 1;
1286 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1288 if EndingGameCounter
= 0 then
1290 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1291 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1293 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1295 g_Game_ExecuteEvent('onwadend');
1296 if not gMusic
.SetByName('MUSIC_endmus') then
1297 gMusic
.SetByName('MUSIC_STDENDMUS');
1300 gMusic
.SetByName('MUSIC_ROUNDMUS');
1303 gState
:= STATE_INTERCUSTOM
;
1305 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1307 gMusic
.SetByName('MUSIC_INTERMUS');
1309 gState
:= STATE_INTERSINGLE
;
1311 g_Game_ExecuteEvent('oninter');
1314 DecMin(EndingGameCounter
, 6, 0);
1317 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1319 if gMapOnce
then // Ýòî áûë òåñò
1321 gExit
:= EXIT_SIMPLE
;
1327 g_Serverlist_Control(slCurrent
);
1330 if g_Game_IsNet
then
1331 if not gConsoleShow
then
1332 if not gChatShow
then
1334 if g_ActiveWindow
= nil then
1336 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1337 g_Console_Chat_Switch(False)
1338 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1339 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1340 g_Console_Chat_Switch(True);
1343 if not gChatEnter
then
1344 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1345 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1348 // Ñòàòèñòèêà ïî Tab:
1350 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1351 (gGameSettings
.GameType
<> GT_SINGLE
) and
1352 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1355 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1357 // Âðåìÿ += 28 ìèëëèñåêóíä:
1358 gTime
:= gTime
+ GAME_TICK
;
1360 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1361 if MessageTime
= 0 then
1363 if MessageTime
> 0 then
1364 MessageTime
:= MessageTime
- 1;
1366 if (g_Game_IsServer
) then
1368 // Áûë çàäàí ëèìèò âðåìåíè:
1369 if (gGameSettings
.TimeLimit
> 0) then
1370 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1371 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1376 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1377 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1378 g_Game_RestartRound(gLMSSoftSpawn
);
1380 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1381 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1383 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1385 g_Console_Process(gVoteCommand
);
1387 gVotePassed
:= False;
1390 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1391 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1392 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1393 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1394 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1396 // Áûë çàäàí ëèìèò ïîáåä:
1397 if (gGameSettings
.GoalLimit
> 0) then
1401 if gGameSettings
.GameMode
= GM_DM
then
1402 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1403 for i
:= 0 to High(gPlayers
) do
1404 if gPlayers
[i
] <> nil then
1405 if gPlayers
[i
].Frags
> b
then
1406 b
:= gPlayers
[i
].Frags
;
1409 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1410 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1411 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1414 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1415 if b
>= gGameSettings
.GoalLimit
then
1422 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1423 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1424 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1425 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1428 if gPlayer1
<> nil then
1429 with gGameControls
.P1Control
do
1431 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1432 P1MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1434 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1435 P1MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1437 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1438 P1MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1440 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1441 if P1MoveButton
= 1 then
1442 gPlayer1
.PressKey(KEY_LEFT
)
1444 if P1MoveButton
= 2 then
1445 gPlayer1
.PressKey(KEY_RIGHT
);
1447 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1448 if (P1MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1449 gPlayer1
.SetDirection(D_LEFT
)
1451 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1452 if (P1MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1453 gPlayer1
.SetDirection(D_RIGHT
)
1455 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1456 if P1MoveButton
<> 0 then
1457 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
1459 // Îñòàëüíûå êëàâèøè:
1460 if e_KeyPressed(KeyJump
) then gPlayer1
.PressKey(KEY_JUMP
);
1461 if e_KeyPressed(KeyUp
) then gPlayer1
.PressKey(KEY_UP
);
1462 if e_KeyPressed(KeyDown
) then gPlayer1
.PressKey(KEY_DOWN
);
1463 if e_KeyPressed(KeyFire
) then gPlayer1
.PressKey(KEY_FIRE
);
1464 if e_KeyPressed(KeyNextWeapon
) then gPlayer1
.PressKey(KEY_NEXTWEAPON
);
1465 if e_KeyPressed(KeyPrevWeapon
) then gPlayer1
.PressKey(KEY_PREVWEAPON
);
1466 if e_KeyPressed(KeyOpen
) then gPlayer1
.PressKey(KEY_OPEN
);
1469 if gPlayer2
<> nil then
1470 with gGameControls
.P2Control
do
1472 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1473 P2MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1475 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1476 P2MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1478 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1479 P2MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1481 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1482 if P2MoveButton
= 1 then
1483 gPlayer2
.PressKey(KEY_LEFT
, 1000)
1485 if P2MoveButton
= 2 then
1486 gPlayer2
.PressKey(KEY_RIGHT
, 1000);
1488 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1489 if (P2MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1490 gPlayer2
.SetDirection(D_LEFT
)
1492 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1493 if (P2MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1494 gPlayer2
.SetDirection(D_RIGHT
)
1496 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1497 if P2MoveButton
<> 0 then
1498 gPlayer2
.SetDirection(TDirection(P2MoveButton
-1));
1500 // Îñòàëüíûå êëàâèøè:
1501 if e_KeyPressed(KeyJump
) then gPlayer2
.PressKey(KEY_JUMP
, 1000);
1502 if e_KeyPressed(KeyUp
) then gPlayer2
.PressKey(KEY_UP
, 1000);
1503 if e_KeyPressed(KeyDown
) then gPlayer2
.PressKey(KEY_DOWN
, 1000);
1504 if e_KeyPressed(KeyFire
) then gPlayer2
.PressKey(KEY_FIRE
);
1505 if e_KeyPressed(KeyNextWeapon
) then gPlayer2
.PressKey(KEY_NEXTWEAPON
);
1506 if e_KeyPressed(KeyPrevWeapon
) then gPlayer2
.PressKey(KEY_PREVWEAPON
);
1507 if e_KeyPressed(KeyOpen
) then gPlayer2
.PressKey(KEY_OPEN
);
1509 end // if not console
1511 if g_Game_IsNet
and (gPlayer1
<> nil) then
1512 gPlayer1
.PressKey(KEY_CHAT
, 10000);
1517 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1518 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1520 if not gSpectKeyPress
then
1522 if e_KeyPressed(gGameControls
.P1Control
.KeyJump
) then
1524 // switch spect mode
1526 SPECT_NONE
: ; // not spectator
1528 SPECT_MAPVIEW
: Inc(gSpectMode
);
1529 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1531 gSpectKeyPress
:= True;
1533 if gSpectMode
= SPECT_MAPVIEW
then
1535 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1536 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1537 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1538 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1539 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1540 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1541 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1542 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1543 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1546 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1547 gSpectKeyPress
:= True;
1549 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1552 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1553 gSpectKeyPress
:= True;
1556 if gSpectMode
= SPECT_PLAYERS
then
1558 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1561 gSpectViewTwo
:= True;
1562 gSpectKeyPress
:= True;
1564 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1566 // remove second view
1567 gSpectViewTwo
:= False;
1568 gSpectKeyPress
:= True;
1570 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1572 // prev player (view 1)
1573 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1574 gSpectKeyPress
:= True;
1576 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1578 // next player (view 1)
1579 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1580 gSpectKeyPress
:= True;
1582 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1584 // prev player (view 2)
1585 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1586 gSpectKeyPress
:= True;
1588 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1590 // next player (view 2)
1591 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1592 gSpectKeyPress
:= True;
1597 if (not e_KeyPressed(gGameControls
.P1Control
.KeyJump
)) and
1598 (not e_KeyPressed(gGameControls
.P1Control
.KeyLeft
)) and
1599 (not e_KeyPressed(gGameControls
.P1Control
.KeyRight
)) and
1600 (not e_KeyPressed(gGameControls
.P1Control
.KeyUp
)) and
1601 (not e_KeyPressed(gGameControls
.P1Control
.KeyDown
)) and
1602 (not e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
)) and
1603 (not e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
)) then
1604 gSpectKeyPress
:= False;
1607 // Îáíîâëÿåì âñå îñòàëüíîå:
1610 g_Triggers_Update();
1612 g_Monsters_Update();
1614 g_Player_UpdateAll();
1615 g_Player_UpdatePhysicalObjects();
1616 if gGameSettings
.GameType
= GT_SERVER
then
1617 if Length(gMonstersSpawned
) > 0 then
1619 for I
:= 0 to High(gMonstersSpawned
) do
1620 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1621 SetLength(gMonstersSpawned
, 0);
1624 if (gSoundTriggerTime
> 8) then
1626 g_Game_UpdateTriggerSounds();
1627 gSoundTriggerTime
:= 0;
1630 Inc(gSoundTriggerTime
);
1632 if (NetMode
= NET_SERVER
) then
1634 Inc(NetTimeToUpdate
);
1635 Inc(NetTimeToReliable
);
1636 if NetTimeToReliable
>= NetRelupdRate
then
1638 for I
:= 0 to High(gPlayers
) do
1639 if gPlayers
[I
] <> nil then
1640 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1642 if gMonsters
<> nil then
1643 for I
:= 0 to High(gMonsters
) do
1644 if gMonsters
[I
] <> nil then
1646 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1648 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1649 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1652 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1653 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1654 (gMonsters
[I
].GameVelX
<> 0) or
1655 (gMonsters
[I
].GameVelY
<> 0) then
1656 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1659 NetTimeToReliable
:= 0;
1660 NetTimeToUpdate
:= NetUpdateRate
;
1662 else if NetTimeToUpdate
>= NetUpdateRate
then
1664 if gPlayers
<> nil then
1665 for I
:= 0 to High(gPlayers
) do
1666 if gPlayers
[I
] <> nil then
1667 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1669 if gMonsters
<> nil then
1670 for I
:= 0 to High(gMonsters
) do
1671 if gMonsters
[I
] <> nil then
1673 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1675 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1676 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1679 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1680 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1681 (gMonsters
[I
].GameVelX
<> 0) or
1682 (gMonsters
[I
].GameVelY
<> 0) then
1683 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1686 NetTimeToUpdate
:= 0;
1689 if NetUseMaster
then
1690 if gTime
>= NetTimeToMaster
then
1692 if (NetMHost
= nil) or (NetMPeer
= nil) then
1693 if not g_Net_Slist_Connect
then
1694 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1697 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1701 if NetMode
= NET_CLIENT
then
1702 MC_SEND_PlayerPos();
1703 end; // if gameOn ...
1705 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1706 if g_ActiveWindow
<> nil then
1708 w
:= e_GetFirstKeyPressed();
1710 if (w
<> IK_INVALID
) then
1712 Msg
.Msg
:= MESSAGE_DIKEY
;
1714 g_ActiveWindow
.OnMessage(Msg
);
1717 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1718 if g_ActiveWindow
<> nil then
1719 g_ActiveWindow
.Update();
1721 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1722 if gResolutionChange
then
1724 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1725 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1726 gResolutionChange
:= False;
1729 // Íóæíî ñìåíèòü ÿçûê:
1730 if gLanguageChange
then
1732 //e_WriteLog('Read language file', MSG_NOTIFY);
1733 //g_Language_Load(DataDir + gLanguage + '.txt');
1734 g_Language_Set(gLanguage
);
1736 gLanguageChange
:= False;
1740 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1741 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1742 if (GetTimer()-LastScreenShot
) > 200000 then
1745 LastScreenShot
:= GetTimer();
1748 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1749 if e_KeyPressed(IK_F10
) and
1751 (not gConsoleShow
) and
1752 (g_ActiveWindow
= nil) then
1757 Time
:= GetTimer() div 1000;
1759 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1760 if gDelayedEvents
<> nil then
1761 for a
:= 0 to High(gDelayedEvents
) do
1762 if gDelayedEvents
[a
].Pending
and
1764 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1765 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1768 case gDelayedEvents
[a
].DEType
of
1770 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1773 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1777 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1778 if g_Game_IsNet
and g_Game_IsServer
then
1779 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1782 gDelayedEvents
[a
].Pending
:= False;
1785 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1786 UPSCounter
:= UPSCounter
+ 1;
1787 if Time
- UPSTime
>= 1000 then
1795 procedure g_Game_LoadData();
1797 if DataLoaded
then Exit
;
1799 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1801 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1802 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1803 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1804 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1805 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1806 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1807 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1808 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1809 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1810 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1811 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1812 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1813 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1814 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1815 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1816 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1817 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1818 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1819 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1820 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1821 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1822 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1823 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1824 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1825 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1826 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1827 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1828 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1829 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1830 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1831 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1832 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1833 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1834 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1836 goodsnd
[0] := TPlayableSound
.Create();
1837 goodsnd
[1] := TPlayableSound
.Create();
1838 goodsnd
[2] := TPlayableSound
.Create();
1839 goodsnd
[3] := TPlayableSound
.Create();
1841 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1842 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1843 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1844 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1846 killsnd
[0] := TPlayableSound
.Create();
1847 killsnd
[1] := TPlayableSound
.Create();
1848 killsnd
[2] := TPlayableSound
.Create();
1849 killsnd
[3] := TPlayableSound
.Create();
1851 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1852 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1853 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1854 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1856 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1859 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1860 g_Weapon_LoadData();
1862 g_Monsters_LoadData();
1867 procedure g_Game_FreeData();
1869 if not DataLoaded
then Exit
;
1872 g_Weapon_FreeData();
1873 g_Monsters_FreeData();
1875 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1877 g_Texture_Delete('NOTEXTURE');
1878 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1879 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1880 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1881 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1882 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1883 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1884 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1885 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1886 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1887 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1888 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1889 g_Frames_DeleteByName('FRAMES_TELEPORT');
1890 g_Sound_Delete('SOUND_GAME_TELEPORT');
1891 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1892 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1893 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1894 g_Sound_Delete('SOUND_GAME_BULK1');
1895 g_Sound_Delete('SOUND_GAME_BULK2');
1896 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1897 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1898 g_Sound_Delete('SOUND_GAME_SWITCH1');
1899 g_Sound_Delete('SOUND_GAME_SWITCH0');
1906 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1907 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1908 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1909 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1916 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1917 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1918 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1919 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1921 DataLoaded
:= False;
1924 procedure DrawCustomStat();
1930 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1931 s1
, s2
, topstr
: String;
1933 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1936 if e_KeyPressed(IK_TAB
) then
1938 if not gStatsPressed
then
1940 gStatsOff
:= not gStatsOff
;
1941 gStatsPressed
:= True;
1945 gStatsPressed
:= False;
1949 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1950 w
:= (Length(s1
) * ww2
) div 2;
1951 x
:= gScreenWidth
div 2 - w
;
1953 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1957 if (gGameSettings
.GameMode
= GM_COOP
) then
1959 if gMissionFailed
then
1960 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1962 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1965 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1967 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1968 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
1970 if g_Game_IsNet
then
1972 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
1973 if not gChatShow
then
1974 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1975 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
1978 if g_Game_IsClient
then
1979 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
1981 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
1982 if not gChatShow
then
1983 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1984 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
1989 w
:= gScreenWidth
-x
*2;
1995 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
1996 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
1998 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2000 case CustomStat
.GameMode
of
2003 if gGameSettings
.MaxLives
= 0 then
2004 s1
:= _lc
[I_GAME_DM
]
2006 s1
:= _lc
[I_GAME_LMS
];
2010 if gGameSettings
.MaxLives
= 0 then
2011 s1
:= _lc
[I_GAME_TDM
]
2013 s1
:= _lc
[I_GAME_TLMS
];
2015 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2018 if gGameSettings
.MaxLives
= 0 then
2019 s1
:= _lc
[I_GAME_COOP
]
2021 s1
:= _lc
[I_GAME_SURV
];
2027 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2031 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2032 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2035 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2036 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2037 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2038 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2040 pc
:= Length(CustomStat
.PlayerStat
);
2041 if pc
= 0 then Exit
;
2043 if CustomStat
.GameMode
= GM_COOP
then
2045 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2047 s2
:= _lc
[I_GAME_MONSTERS
];
2048 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2049 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2051 s2
:= _lc
[I_GAME_SECRETS
];
2052 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2053 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2056 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2058 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2059 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2060 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2062 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2063 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2064 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2068 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2073 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2074 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2075 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2077 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2080 for t
:= TEAM_RED
to TEAM_BLUE
do
2082 if t
= TEAM_RED
then
2084 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2085 gStdFont
, 255, 0, 0, 1);
2086 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2087 gStdFont
, 255, 0, 0, 1);
2094 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2095 gStdFont
, 0, 0, 255, 1);
2096 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2097 gStdFont
, 0, 0, 255, 1);
2103 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2106 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2107 if CustomStat
.PlayerStat
[p
].Team
= t
then
2108 with CustomStat
.PlayerStat
[p
] do
2122 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2123 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2124 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2131 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2134 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2135 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2136 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2139 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2140 with CustomStat
.PlayerStat
[p
] do
2142 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2149 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2150 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2151 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2157 procedure DrawSingleStat();
2159 tm
, key_x
, val_x
, y
: Integer;
2163 procedure player_stat(n
: Integer);
2169 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2170 s2
:= Format(' %d', [gTotalMonsters
]);
2172 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2173 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2174 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2175 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2177 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2178 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2180 // "Kills-per-minute: ##.#":
2181 s1
:= _lc
[I_MENU_INTER_KPM
];
2183 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2185 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2186 s2
:= Format(' %.1f', [kpm
]);
2188 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2189 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2191 // "Secrets found: # / #":
2192 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2193 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2195 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2196 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2197 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2198 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2200 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2201 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2205 // "Level Complete":
2206 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2207 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2209 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2210 s1
:= _lc
[I_MENU_INTER_KPM
];
2211 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2214 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2216 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2217 val_x
:= key_x
+ w1
;
2220 tm
:= SingleStat
.GameTime
div 1000;
2221 s1
:= _lc
[I_MENU_INTER_TIME
];
2222 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2224 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2225 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2227 if SingleStat
.TwoPlayers
then
2230 s1
:= _lc
[I_MENU_PLAYER_1
];
2231 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2232 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2234 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2239 s1
:= _lc
[I_MENU_PLAYER_2
];
2240 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2241 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2243 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2249 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2255 procedure DrawLoadingStat();
2261 if Length(LoadingStat
.Msgs
) = 0 then
2264 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2265 yy
:= (gScreenHeight
div 3);
2266 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2267 xx
:= (gScreenWidth
div 3);
2270 for i
:= 0 to NextMsg
-1 do
2272 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2273 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2277 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2278 yy
:= yy
+ LOADING_INTERLINE
;
2282 procedure DrawMinimap(p
: TPlayer
; RenderRect
: TRect
);
2284 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2286 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2287 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2290 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2291 ScaleSz
:= 16 div Scale
;
2292 // Ðàçìåðû ìèíè-êàðòû:
2293 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2294 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2296 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2298 if gWalls
<> nil then
2301 for a
:= 0 to High(gWalls
) do
2303 if PanelType
<> 0 then
2305 // Ëåâûé âåðõíèé óãîë:
2306 aX
:= X
div ScaleSz
;
2307 aY
:= Y
div ScaleSz
;
2309 aX2
:= max(Width
div ScaleSz
, 1);
2310 aY2
:= max(Height
div ScaleSz
, 1);
2311 // Ïðàâûé íèæíèé óãîë:
2312 aX2
:= aX
+ aX2
- 1;
2313 aY2
:= aY
+ aY2
- 1;
2316 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2317 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2318 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2322 if gSteps
<> nil then
2325 for a
:= 0 to High(gSteps
) do
2327 if PanelType
<> 0 then
2329 // Ëåâûé âåðõíèé óãîë:
2330 aX
:= X
div ScaleSz
;
2331 aY
:= Y
div ScaleSz
;
2333 aX2
:= max(Width
div ScaleSz
, 1);
2334 aY2
:= max(Height
div ScaleSz
, 1);
2335 // Ïðàâûé íèæíèé óãîë:
2336 aX2
:= aX
+ aX2
- 1;
2337 aY2
:= aY
+ aY2
- 1;
2339 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2342 if gLifts
<> nil then
2345 for a
:= 0 to High(gLifts
) do
2347 if PanelType
<> 0 then
2349 // Ëåâûé âåðõíèé óãîë:
2350 aX
:= X
div ScaleSz
;
2351 aY
:= Y
div ScaleSz
;
2353 aX2
:= max(Width
div ScaleSz
, 1);
2354 aY2
:= max(Height
div ScaleSz
, 1);
2355 // Ïðàâûé íèæíèé óãîë:
2356 aX2
:= aX
+ aX2
- 1;
2357 aY2
:= aY
+ aY2
- 1;
2360 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2361 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2362 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2363 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2367 if gWater
<> nil then
2370 for a
:= 0 to High(gWater
) do
2372 if PanelType
<> 0 then
2374 // Ëåâûé âåðõíèé óãîë:
2375 aX
:= X
div ScaleSz
;
2376 aY
:= Y
div ScaleSz
;
2378 aX2
:= max(Width
div ScaleSz
, 1);
2379 aY2
:= max(Height
div ScaleSz
, 1);
2380 // Ïðàâûé íèæíèé óãîë:
2381 aX2
:= aX
+ aX2
- 1;
2382 aY2
:= aY
+ aY2
- 1;
2384 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2387 if gAcid1
<> nil then
2389 // Ðèñóåì êèñëîòó 1:
2390 for a
:= 0 to High(gAcid1
) do
2392 if PanelType
<> 0 then
2394 // Ëåâûé âåðõíèé óãîë:
2395 aX
:= X
div ScaleSz
;
2396 aY
:= Y
div ScaleSz
;
2398 aX2
:= max(Width
div ScaleSz
, 1);
2399 aY2
:= max(Height
div ScaleSz
, 1);
2400 // Ïðàâûé íèæíèé óãîë:
2401 aX2
:= aX
+ aX2
- 1;
2402 aY2
:= aY
+ aY2
- 1;
2404 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2407 if gAcid2
<> nil then
2409 // Ðèñóåì êèñëîòó 2:
2410 for a
:= 0 to High(gAcid2
) do
2412 if PanelType
<> 0 then
2414 // Ëåâûé âåðõíèé óãîë:
2415 aX
:= X
div ScaleSz
;
2416 aY
:= Y
div ScaleSz
;
2418 aX2
:= max(Width
div ScaleSz
, 1);
2419 aY2
:= max(Height
div ScaleSz
, 1);
2420 // Ïðàâûé íèæíèé óãîë:
2421 aX2
:= aX
+ aX2
- 1;
2422 aY2
:= aY
+ aY2
- 1;
2424 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2427 if gPlayers
<> nil then
2430 for a
:= 0 to High(gPlayers
) do
2431 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2433 // Ëåâûé âåðõíèé óãîë:
2434 aX
:= Obj
.X
div ScaleSz
+ 1;
2435 aY
:= Obj
.Y
div ScaleSz
+ 1;
2437 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2438 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2439 // Ïðàâûé íèæíèé óãîë:
2440 aX2
:= aX
+ aX2
- 1;
2441 aY2
:= aY
+ aY2
- 1;
2443 if gPlayers
[a
] = p
then
2444 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2447 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2448 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2449 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2453 if gMonsters
<> nil then
2456 for a
:= 0 to High(gMonsters
) do
2457 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2459 // Ëåâûé âåðõíèé óãîë:
2460 aX
:= Obj
.X
div ScaleSz
+ 1;
2461 aY
:= Obj
.Y
div ScaleSz
+ 1;
2463 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2464 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2465 // Ïðàâûé íèæíèé óãîë:
2466 aX2
:= aX
+ aX2
- 1;
2467 aY2
:= aY
+ aY2
- 1;
2469 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2475 procedure DrawMapView(x
, y
, w
, h
: Integer);
2481 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2482 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2483 g_Map_DrawBack(-bx
, -by
);
2490 glTranslatef(-x
, -y
, 0);
2492 g_Map_DrawPanels(PANEL_BACK
);
2493 g_Map_DrawPanels(PANEL_STEP
);
2496 g_Player_DrawShells();
2498 g_Player_DrawCorpses();
2499 g_Map_DrawPanels(PANEL_WALL
);
2501 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2504 g_Map_DrawPanels(PANEL_ACID1
);
2505 g_Map_DrawPanels(PANEL_ACID2
);
2506 g_Map_DrawPanels(PANEL_WATER
);
2507 g_Map_DrawPanels(PANEL_FORE
);
2508 if g_debug_HealthBar
then
2510 g_Monsters_DrawHealth();
2511 g_Player_DrawHealth();
2517 procedure DrawPlayer(p
: TPlayer
);
2519 px
, py
, a
, b
, c
, d
: Integer;
2522 if (p
= nil) or (p
.FDummy
) then
2525 g_Map_DrawBack(0, 0);
2534 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2535 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2537 if px
> (gPlayerScreenSize
.X
div 2) then
2538 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2541 if py
> (gPlayerScreenSize
.Y
div 2) then
2542 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2545 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2546 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2547 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2548 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2549 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2551 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2554 if p
.IncCam
<> 0 then
2556 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2558 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2559 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2562 if py
< (gPlayerScreenSize
.Y
div 2) then
2564 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2565 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2568 if p
.IncCam
< 0 then
2569 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2571 p
.IncCam
:= p
.IncCam
+ 1;
2573 if p
.IncCam
> 0 then
2574 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2576 p
.IncCam
:= p
.IncCam
- 1;
2579 if (px
< gPlayerScreenSize
.X
div 2) or
2580 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2583 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2584 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2586 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2588 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2589 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2592 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2593 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2595 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2597 g_Map_DrawBack(-c
, -d
);
2600 sY
:= -(b
+p
.IncCam
);
2601 sWidth
:= gPlayerScreenSize
.X
;
2602 sHeight
:= gPlayerScreenSize
.Y
;
2604 glTranslatef(a
, b
+p
.IncCam
, 0);
2606 g_Map_DrawPanels(PANEL_BACK
);
2607 g_Map_DrawPanels(PANEL_STEP
);
2610 g_Player_DrawShells();
2612 g_Player_DrawCorpses();
2613 g_Map_DrawPanels(PANEL_WALL
);
2615 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2618 g_Map_DrawPanels(PANEL_ACID1
);
2619 g_Map_DrawPanels(PANEL_ACID2
);
2620 g_Map_DrawPanels(PANEL_WATER
);
2621 g_Map_DrawPanels(PANEL_FORE
);
2622 if g_debug_HealthBar
then
2624 g_Monsters_DrawHealth();
2625 g_Player_DrawHealth();
2628 if p
.FSpectator
then
2629 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2630 p
.GameY
+ PLAYER_RECT_CY
- 4,
2631 'X', gStdFont
, 255, 255, 255, 1, True);
2633 for a := 0 to High(gCollideMap) do
2634 for b := 0 to High(gCollideMap[a]) do
2637 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2639 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2643 1: e_DrawPoint(1, b, a, 200, 200, 200);
2644 2: e_DrawPoint(1, b, a, 64, 64, 255);
2645 3: e_DrawPoint(1, b, a, 255, 0, 255);
2656 //DrawMinimap(p, _TRect(0, 0, 128, 128));
2657 if g_Debug_Player
then
2658 g_Player_DrawDebug(p
);
2662 procedure g_Game_Draw();
2669 plView1
, plView2
: TPlayer
;
2672 if gExit
= EXIT_QUIT
then Exit
;
2674 Time
:= GetTimer() div 1000;
2675 FPSCounter
:= FPSCounter
+1;
2676 if Time
- FPSTime
>= 1000 then
2683 if gGameOn
or (gState
= STATE_FOLD
) then
2685 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2687 gSpectMode
:= SPECT_NONE
;
2688 if not gRevertPlayers
then
2690 plView1
:= gPlayer1
;
2691 plView2
:= gPlayer2
;
2695 plView1
:= gPlayer2
;
2696 plView2
:= gPlayer1
;
2700 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2702 gSpectMode
:= SPECT_NONE
;
2703 if gPlayer2
= nil then
2706 plView1
:= gPlayer2
;
2715 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2716 gSpectMode
:= SPECT_STATS
;
2718 if gSpectMode
= SPECT_PLAYERS
then
2719 if gPlayers
<> nil then
2721 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2722 if plView1
= nil then
2724 gSpectPID1
:= GetActivePlayerID_Next();
2725 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2727 if gSpectViewTwo
then
2729 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2730 if plView2
= nil then
2732 gSpectPID2
:= GetActivePlayerID_Next();
2733 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2738 if gSpectMode
= SPECT_MAPVIEW
then
2740 // Ðåæèì ïðîñìîòðà êàðòû
2742 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2743 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2744 gHearPoint1
.Active
:= True;
2745 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2746 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2747 gHearPoint2
.Active
:= False;
2751 Split
:= (plView1
<> nil) and (plView2
<> nil);
2753 // Òî÷êè ñëóõà èãðîêîâ
2754 if plView1
<> nil then
2756 gHearPoint1
.Active
:= True;
2757 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2758 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2760 gHearPoint1
.Active
:= False;
2761 if plView2
<> nil then
2763 gHearPoint2
.Active
:= True;
2764 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2765 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2767 gHearPoint2
.Active
:= False;
2769 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2770 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2773 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2774 if gScreenHeight
mod 2 = 0 then
2775 Dec(gPlayerScreenSize
.Y
);
2778 gPlayerScreenSize
.Y
:= gScreenHeight
;
2781 if gScreenHeight
mod 2 = 0 then
2782 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2784 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2786 DrawPlayer(plView1
);
2787 gPlayer1ScreenCoord
.X
:= sX
;
2788 gPlayer1ScreenCoord
.Y
:= sY
;
2792 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2794 DrawPlayer(plView2
);
2795 gPlayer2ScreenCoord
.X
:= sX
;
2796 gPlayer2ScreenCoord
.Y
:= sY
;
2799 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2802 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2805 if MessageText
<> '' then
2809 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2811 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2812 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2814 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2815 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2818 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2820 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2822 // Draw spectator GUI
2825 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2828 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2830 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2832 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2834 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2835 if gSpectMode
= SPECT_MAPVIEW
then
2837 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2838 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2839 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2840 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2841 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2843 if gSpectMode
= SPECT_PLAYERS
then
2845 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2846 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2847 if gSpectViewTwo
then
2849 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2850 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2851 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2852 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2856 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2857 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2863 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2865 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2867 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2868 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2869 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2874 if (gState
= STATE_MENU
) then
2876 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2878 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2879 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2880 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2882 if g_ActiveWindow
<> nil then
2883 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2886 if gState
= STATE_FOLD
then
2887 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2889 if gState
= STATE_INTERCUSTOM
then
2891 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2893 back
:= 'TEXTURE_endpic';
2894 if not g_Texture_Get(back
, ID
) then
2895 back
:= _lc
[I_TEXTURE_ENDPIC
];
2900 if g_Texture_Get(back
, ID
) then
2901 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2903 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2907 if g_ActiveWindow
<> nil then
2908 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2911 if gState
= STATE_INTERSINGLE
then
2913 if EndingGameCounter
> 0 then
2914 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2919 if g_Texture_Get(back
, ID
) then
2920 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2922 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2926 if g_ActiveWindow
<> nil then
2927 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2931 if gState
= STATE_ENDPIC
then
2934 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2935 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2937 if ID
<> DWORD(-1) then
2938 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2940 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2942 if g_ActiveWindow
<> nil then
2943 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2946 if gState
= STATE_SLIST
then
2948 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2950 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2951 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2953 g_Serverlist_Draw(slCurrent
);
2957 if g_ActiveWindow
<> nil then
2960 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2961 g_ActiveWindow
.Draw();
2966 if g_debug_Sounds
and gGameOn
then
2968 for w
:= 0 to High(e_SoundsArray
) do
2969 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2970 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
2975 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
2976 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
2979 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
2980 e_TextureFontPrint(gScreenWidth
-72, 0,
2981 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
2985 procedure g_Game_Quit();
2987 g_Game_StopAllSounds(True);
2989 g_Game_SaveOptions();
2991 g_PlayerModel_FreeData();
2992 g_Texture_DeleteAll();
2993 g_Frames_DeleteAll();
2996 if NetInitDone
then g_Net_Free
;
2998 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
2999 if gMapToDelete
<> '' then
3000 g_Game_DeleteTestMap();
3006 procedure g_FatalError(Text: String);
3008 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3009 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3011 gExit
:= EXIT_SIMPLE
;
3014 procedure g_SimpleError(Text: String);
3016 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3017 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3020 procedure g_Game_SetupScreenSize();
3024 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3025 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3026 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3027 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3029 gPlayerScreenSize
.Y
:= gScreenHeight
;
3031 // Ðàçìåð çàäíåãî ïëàíà:
3032 if BackID
<> DWORD(-1) then
3036 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3037 (gScreenHeight
*d
> gMapInfo
.Height
) then
3040 gBackSize
.X
:= Round(gScreenWidth
*d
);
3041 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3045 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3047 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3050 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3052 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3053 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3055 if gPlayer1
= nil then
3057 if g_Game_IsClient
then
3059 if NetPlrUID1
> -1 then
3061 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3062 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3067 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3068 Team
:= gPlayer1Settings
.Team
;
3070 // Ñîçäàíèå ïåðâîãî èãðîêà:
3071 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3072 gPlayer1Settings
.Color
,
3074 if gPlayer1
= nil then
3075 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3078 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3079 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3080 if g_Game_IsServer
and g_Game_IsNet
then
3081 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3082 gPlayer1
.Respawn(False, True);
3084 if g_Game_IsNet
and NetUseMaster
then
3090 if gPlayer2
= nil then
3092 if g_Game_IsClient
then
3094 if NetPlrUID2
> -1 then
3095 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3099 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3100 Team
:= gPlayer2Settings
.Team
;
3102 // Ñîçäàíèå âòîðîãî èãðîêà:
3103 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3104 gPlayer2Settings
.Color
,
3106 if gPlayer2
= nil then
3107 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3110 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3111 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3112 if g_Game_IsServer
and g_Game_IsNet
then
3113 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3114 gPlayer2
.Respawn(False, True);
3116 if g_Game_IsNet
and NetUseMaster
then
3124 procedure g_Game_RemovePlayer();
3128 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3129 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3134 if g_Game_IsServer
then
3137 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3138 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3139 g_Player_Remove(Pl
.UID
);
3141 if g_Game_IsNet
and NetUseMaster
then
3150 if g_Game_IsServer
then
3153 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3154 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3155 g_Player_Remove(Pl
.UID
);
3157 if g_Game_IsNet
and NetUseMaster
then
3162 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3168 procedure g_Game_Spectate();
3170 g_Game_RemovePlayer();
3171 if gPlayer1
<> nil then
3172 g_Game_RemovePlayer();
3175 procedure g_Game_SpectateCenterView();
3177 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3178 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3181 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3187 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3189 g_Game_ClearLoading();
3192 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3195 gGameSettings
.GameType
:= GT_SINGLE
;
3196 gGameSettings
.MaxLives
:= 0;
3197 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3198 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3199 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3200 gSwitchGameMode
:= GM_SINGLE
;
3202 g_Game_ExecuteEvent('ongamestart');
3204 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3205 g_Game_SetupScreenSize();
3207 // Ñîçäàíèå ïåðâîãî èãðîêà:
3208 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3209 gPlayer1Settings
.Color
,
3210 gPlayer1Settings
.Team
, False));
3211 if gPlayer1
= nil then
3213 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3217 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3220 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3223 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3224 gPlayer2Settings
.Color
,
3225 gPlayer2Settings
.Team
, False));
3226 if gPlayer2
= nil then
3228 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3232 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3236 // Çàãðóçêà è çàïóñê êàðòû:
3237 if not g_Game_StartMap(MAP
, True) then
3239 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3243 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3247 for i
:= nPl
+1 to nPlayers
do
3248 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3251 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3252 TimeLimit
, GoalLimit
: Word;
3254 Options
: LongWord; nPlayers
: Byte);
3260 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3262 g_Game_ClearLoading();
3265 gGameSettings
.GameType
:= GT_CUSTOM
;
3266 gGameSettings
.GameMode
:= GameMode
;
3267 gSwitchGameMode
:= GameMode
;
3268 gGameSettings
.TimeLimit
:= TimeLimit
;
3269 gGameSettings
.GoalLimit
:= GoalLimit
;
3270 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3271 gGameSettings
.Options
:= Options
;
3273 gCoopTotalMonstersKilled
:= 0;
3274 gCoopTotalSecretsFound
:= 0;
3275 gCoopTotalMonsters
:= 0;
3276 gCoopTotalSecrets
:= 0;
3280 g_Game_ExecuteEvent('ongamestart');
3282 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3283 g_Game_SetupScreenSize();
3285 // Ðåæèì íàáëþäàòåëÿ:
3286 if nPlayers
= 0 then
3293 if nPlayers
>= 1 then
3295 // Ñîçäàíèå ïåðâîãî èãðîêà:
3296 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3297 gPlayer1Settings
.Color
,
3298 gPlayer1Settings
.Team
, False));
3299 if gPlayer1
= nil then
3301 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3305 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3309 if nPlayers
>= 2 then
3311 // Ñîçäàíèå âòîðîãî èãðîêà:
3312 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3313 gPlayer2Settings
.Color
,
3314 gPlayer2Settings
.Team
, False));
3315 if gPlayer2
= nil then
3317 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3321 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3325 // Çàãðóçêà è çàïóñê êàðòû:
3326 if not g_Game_StartMap(Map
, True) then
3328 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3332 // Íåò òî÷åê ïîÿâëåíèÿ:
3333 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3334 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3335 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3336 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3337 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3339 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3343 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3347 for i
:= nPl
+1 to nPlayers
do
3348 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3351 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3352 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3353 Options
: LongWord; nPlayers
: Byte;
3354 IPAddr
: LongWord; Port
: Word);
3358 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3360 g_Game_ClearLoading();
3363 gGameSettings
.GameType
:= GT_SERVER
;
3364 gGameSettings
.GameMode
:= GameMode
;
3365 gSwitchGameMode
:= GameMode
;
3366 gGameSettings
.TimeLimit
:= TimeLimit
;
3367 gGameSettings
.GoalLimit
:= GoalLimit
;
3368 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3369 gGameSettings
.Options
:= Options
;
3371 gCoopTotalMonstersKilled
:= 0;
3372 gCoopTotalSecretsFound
:= 0;
3373 gCoopTotalMonsters
:= 0;
3374 gCoopTotalSecrets
:= 0;
3378 g_Game_ExecuteEvent('ongamestart');
3380 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3381 g_Game_SetupScreenSize();
3383 // Ðåæèì íàáëþäàòåëÿ:
3384 if nPlayers
= 0 then
3390 if nPlayers
>= 1 then
3392 // Ñîçäàíèå ïåðâîãî èãðîêà:
3393 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3394 gPlayer1Settings
.Color
,
3395 gPlayer1Settings
.Team
, False));
3396 if gPlayer1
= nil then
3398 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3402 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3405 if nPlayers
>= 2 then
3407 // Ñîçäàíèå âòîðîãî èãðîêà:
3408 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3409 gPlayer2Settings
.Color
,
3410 gPlayer2Settings
.Team
, False));
3411 if gPlayer2
= nil then
3413 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3417 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3421 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3423 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3427 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3429 // Çàãðóçêà è çàïóñê êàðòû:
3430 if not g_Game_StartMap(Map
, True) then
3432 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3436 // Íåò òî÷åê ïîÿâëåíèÿ:
3437 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3438 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3439 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3440 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3441 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3443 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3447 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3450 NetState
:= NET_STATE_GAME
;
3453 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3467 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3468 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3470 g_Game_ClearLoading();
3473 gGameSettings
.GameType
:= GT_CLIENT
;
3475 gCoopTotalMonstersKilled
:= 0;
3476 gCoopTotalSecretsFound
:= 0;
3477 gCoopTotalMonsters
:= 0;
3478 gCoopTotalSecrets
:= 0;
3482 g_Game_ExecuteEvent('ongamestart');
3484 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3485 g_Game_SetupScreenSize();
3487 NetState
:= NET_STATE_AUTH
;
3489 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3491 if not g_Net_Connect(Addr
, Port
) then
3493 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3494 NetState
:= NET_STATE_NONE
;
3498 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3500 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3505 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3507 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3509 Ptr
:= NetEvent
.packet
^.data
;
3512 MID
:= e_Raw_Read_Byte(Ptr
);
3514 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3516 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3517 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3519 WadName
:= e_Raw_Read_String(Ptr
);
3520 Map
:= e_Raw_Read_String(Ptr
);
3522 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3524 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3525 gSwitchGameMode
:= gGameSettings
.GameMode
;
3526 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3527 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3528 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3529 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3530 T
:= e_Raw_Read_LongWord(Ptr
);
3532 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3533 if newResPath
= '' then
3535 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3536 newResPath
:= g_Res_DownloadWAD(WadName
);
3537 if newResPath
= '' then
3539 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3540 enet_packet_destroy(NetEvent
.packet
);
3541 NetState
:= NET_STATE_NONE
;
3545 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3547 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3548 gPlayer1Settings
.Color
,
3549 gPlayer1Settings
.Team
, False));
3551 if gPlayer1
= nil then
3553 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3555 enet_packet_destroy(NetEvent
.packet
);
3556 NetState
:= NET_STATE_NONE
;
3560 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3561 gPlayer1
.UID
:= NetPlrUID1
;
3562 gPlayer1
.Reset(True);
3564 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3566 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3568 enet_packet_destroy(NetEvent
.packet
);
3569 NetState
:= NET_STATE_NONE
;
3577 enet_packet_destroy(NetEvent
.packet
);
3581 enet_packet_destroy(NetEvent
.packet
);
3584 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3587 if (NetEvent
.data
<= NET_DISC_MAX
) then
3588 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3589 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3599 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3608 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3609 NetState
:= NET_STATE_NONE
;
3613 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3614 gLMSRespawnTime
:= 0;
3617 NetState
:= NET_STATE_GAME
;
3618 MC_SEND_FullStateRequest
;
3619 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3622 procedure g_Game_SaveOptions();
3624 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3627 procedure g_Game_ChangeMap(MapPath
: String);
3631 g_Game_ClearLoading();
3633 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3634 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3635 if gExitByTrigger
then
3638 gExitByTrigger
:= False;
3640 if not g_Game_StartMap(MapPath
, Force
) then
3641 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3644 procedure g_Game_Restart();
3648 if g_Game_IsClient
then
3650 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
3654 g_Game_ClearLoading();
3655 g_Game_StartMap(Map
, True);
3658 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3660 NewWAD
, ResName
: String;
3664 g_Player_RemoveAllCorpses();
3666 if (not g_Game_IsClient
) and
3667 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3668 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3670 if gSwitchGameMode
= GM_CTF
then
3671 gGameSettings
.MaxLives
:= 0;
3672 gGameSettings
.GameMode
:= gSwitchGameMode
;
3675 gSwitchGameMode
:= gGameSettings
.GameMode
;
3677 g_Player_ResetTeams();
3679 if Pos(':\', Map
) > 0 then
3681 g_ProcessResourceStr(Map
, @NewWAD
, nil, @ResName
);
3682 if g_Game_IsServer
then
3684 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3685 g_Game_LoadWAD(NewWAD
);
3687 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3688 g_Game_ClientWAD(NewWAD
, gWADHash
);
3692 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3695 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3697 gState
:= STATE_NONE
;
3698 g_ActiveWindow
:= nil;
3704 if gGameSettings
.GameMode
= GM_CTF
then
3706 g_Map_ResetFlag(FLAG_RED
);
3707 g_Map_ResetFlag(FLAG_BLUE
);
3708 // CTF, à ôëàãîâ íåò:
3709 if not g_Map_HaveFlagPoints() then
3710 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3715 gState
:= STATE_MENU
;
3722 NetTimeToUpdate
:= 1;
3723 NetTimeToReliable
:= 0;
3724 NetTimeToMaster
:= NetMasterRate
;
3725 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3726 gLMSRespawnTime
:= 0;
3727 gMissionFailed
:= False;
3730 gCoopMonstersKilled
:= 0;
3731 gCoopSecretsFound
:= 0;
3733 gVoteInProgress
:= False;
3734 gVotePassed
:= False;
3740 if not gGameOn
then Exit
;
3742 g_Game_SpectateCenterView();
3744 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3746 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3747 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3748 gLMSSoftSpawn
:= True;
3749 if NetMode
= NET_SERVER
then
3750 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3752 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3755 if NetMode
= NET_SERVER
then
3757 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3760 if NetUseMaster
then
3762 if (NetMHost
= nil) or (NetMPeer
= nil) then
3763 if not g_Net_Slist_Connect
then
3764 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3769 if NetClients
<> nil then
3770 for I
:= 0 to High(NetClients
) do
3771 if NetClients
[I
].Used
then
3773 NetClients
[I
].Voted
:= False;
3774 if NetClients
[I
].RequestedFullUpdate
then
3776 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3777 NetClients
[I
].RequestedFullUpdate
:= False;
3781 g_Net_UnbanNonPermHosts();
3786 gCoopTotalMonstersKilled
:= 0;
3787 gCoopTotalSecretsFound
:= 0;
3788 gCoopTotalMonsters
:= 0;
3789 gCoopTotalSecrets
:= 0;
3793 g_Game_ExecuteEvent('onmapstart');
3796 procedure SetFirstLevel();
3800 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3801 if MapList
= nil then
3804 SortSArray(MapList
);
3805 gNextMap
:= MapList
[Low(MapList
)];
3810 procedure g_Game_ExitLevel(Map
: Char16
);
3814 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3815 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3816 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3817 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3819 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3820 if gGameSettings
.GameType
= GT_SINGLE
then
3821 gExit
:= EXIT_ENDLEVELSINGLE
3822 else // Âûøëè â âûõîä â Ñâîåé èãðå
3824 gExit
:= EXIT_ENDLEVELCUSTOM
;
3825 if gGameSettings
.GameMode
= GM_COOP
then
3826 g_Player_RememberAll
;
3828 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3831 if gGameSettings
.GameMode
= GM_COOP
then
3834 gStatsPressed
:= True;
3835 gNextMap
:= 'MAP01';
3837 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3840 if g_Game_IsNet
then
3842 MH_SEND_GameStats();
3843 MH_SEND_CoopStats();
3849 procedure g_Game_RestartLevel();
3853 if gGameSettings
.GameMode
= GM_SINGLE
then
3858 gExit
:= EXIT_ENDLEVELCUSTOM
;
3859 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
3863 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3867 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3869 if not g_Game_IsClient
then
3871 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3874 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3875 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3879 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3883 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3884 g_Game_LoadWAD(NewWAD
);
3887 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3889 i
, n
, nb
, nr
: Integer;
3891 if not g_Game_IsServer
then Exit
;
3892 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3893 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3894 gLMSRespawnTime
:= 0;
3897 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3899 gMissionFailed
:= True;
3900 g_Game_RestartLevel
;
3904 n
:= 0; nb
:= 0; nr
:= 0;
3905 for i
:= Low(gPlayers
) to High(gPlayers
) do
3906 if (gPlayers
[i
] <> nil) and
3907 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3908 (gPlayers
[i
] is TBot
)) then
3911 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3912 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3915 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3917 // wait a second until the fuckers finally decide to join
3918 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3919 gLMSRespawnTime
:= gTime
+ 1000;
3920 gLMSSoftSpawn
:= NoMapRestart
;
3924 g_Player_RemoveAllCorpses
;
3925 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3926 if g_Game_IsNet
then
3927 MH_SEND_GameEvent(NET_EV_LMS_START
);
3929 for i
:= Low(gPlayers
) to High(gPlayers
) do
3931 if gPlayers
[i
] = nil then continue
;
3932 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3933 // don't touch normal spectators
3934 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3936 gPlayers
[i
].FNoRespawn
:= True;
3937 gPlayers
[i
].Lives
:= 0;
3938 if g_Game_IsNet
then
3939 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3942 gPlayers
[i
].FNoRespawn
:= False;
3943 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3944 gPlayers
[i
].Respawn(False, True);
3945 if gGameSettings
.GameMode
= GM_COOP
then
3947 gPlayers
[i
].Frags
:= 0;
3948 gPlayers
[i
].RecallState
;
3950 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3951 gPlayer1
:= g_Player_Get(gLMSPID1
);
3952 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3953 gPlayer2
:= g_Player_Get(gLMSPID2
);
3956 for i
:= Low(gItems
) to High(gItems
) do
3958 if gItems
[i
].Respawnable
then
3960 gItems
[i
].QuietRespawn
:= True;
3961 gItems
[i
].RespawnTime
:= 0;
3966 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3970 for i
:= Low(gMonsters
) to High(gMonsters
) do
3972 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
3973 gMonsters
[i
].Respawn
;
3976 gLMSSoftSpawn
:= False;
3979 function g_Game_GetFirstMap(WAD
: String): String;
3983 MapList
:= g_Map_GetMapsList(WAD
);
3984 if MapList
= nil then
3987 SortSArray(MapList
);
3988 Result
:= MapList
[Low(MapList
)];
3990 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3996 function g_Game_GetNextMap(): String;
4003 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4004 if MapList
= nil then
4007 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
4009 SortSArray(MapList
);
4011 for I
:= Low(MapList
) to High(MapList
) do
4012 if Map
= MapList
[I
] then
4018 if MapIndex
<> -255 then
4020 if MapIndex
= High(MapList
) then
4021 Result
:= MapList
[Low(MapList
)]
4023 Result
:= MapList
[MapIndex
+ 1];
4025 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4031 procedure g_Game_NextLevel();
4033 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4034 gExit
:= EXIT_ENDLEVELCUSTOM
4037 gExit
:= EXIT_ENDLEVELSINGLE
;
4041 if gNextMap
<> '' then Exit
;
4042 gNextMap
:= g_Game_GetNextMap();
4045 function g_Game_IsTestMap(): Boolean;
4047 FName
, Sect
, Res
: String;
4049 g_ProcessResourceStr(gMapInfo
.Map
, FName
, Sect
, Res
);
4050 Result
:= UpperCase(Res
) = TEST_MAP_NAME
;
4053 procedure g_Game_DeleteTestMap();
4064 a
:= Pos('.wad:\', gMapToDelete
);
4068 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4069 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4070 Delete(gMapToDelete
, 1, a
+ 5);
4071 gMapToDelete
:= UpperCase(gMapToDelete
);
4073 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4076 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4077 if MapName <> TEST_MAP_NAME then
4080 if not gTempDelete then
4082 time := g_GetFileTime(WadName);
4083 WAD := TWADEditor_1.Create();
4086 if not WAD.ReadFile(WadName) then
4087 begin // Íåò òàêîãî WAD-ôàéëà
4092 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4094 MapList := WAD.GetResourcesList('');
4096 if MapList <> nil then
4097 for a := 0 to High(MapList) do
4098 if MapList[a] = MapName then
4100 // Óäàëÿåì è ñîõðàíÿåì:
4101 WAD.RemoveResource('', MapName);
4102 WAD.SaveTo(WadName);
4107 g_SetFileTime(WadName, time);
4110 if gTempDelete
then DeleteFile(WadName
);
4113 procedure GameCVars(P
: SArray
);
4116 stat
: TPlayerStatArray
;
4121 cmd
:= LowerCase(P
[0]);
4122 if cmd
= 'r_showfps' then
4124 if (Length(P
) > 1) and
4125 ((P
[1] = '1') or (P
[1] = '0')) then
4126 gShowFPS
:= (P
[1][1] = '1');
4129 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4131 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4133 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4135 with gGameSettings
do
4137 if (Length(P
) > 1) and
4138 ((P
[1] = '1') or (P
[1] = '0')) then
4140 if (P
[1][1] = '1') then
4141 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4143 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4146 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4147 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4149 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4151 if g_Game_IsNet
then MH_SEND_GameSettings
;
4154 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4156 with gGameSettings
do
4158 if (Length(P
) > 1) and
4159 ((P
[1] = '1') or (P
[1] = '0')) then
4161 if (P
[1][1] = '1') then
4162 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4164 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4167 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4168 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4170 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4172 if g_Game_IsNet
then MH_SEND_GameSettings
;
4175 else if cmd
= 'g_gamemode' then
4177 a
:= g_Game_TextToMode(P
[1]);
4178 if a
= GM_SINGLE
then a
:= GM_COOP
;
4179 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4181 gSwitchGameMode
:= a
;
4182 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4183 (gState
= STATE_INTERSINGLE
) then
4184 gSwitchGameMode
:= GM_SINGLE
;
4186 gGameSettings
.GameMode
:= gSwitchGameMode
;
4188 if gSwitchGameMode
= gGameSettings
.GameMode
then
4189 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4190 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4192 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4193 [g_Game_ModeToText(gGameSettings
.GameMode
),
4194 g_Game_ModeToText(gSwitchGameMode
)]));
4196 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4198 with gGameSettings
do
4200 if (Length(P
) > 1) and
4201 ((P
[1] = '1') or (P
[1] = '0')) then
4203 if (P
[1][1] = '1') then
4204 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4206 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4209 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4210 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4212 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4213 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4215 if g_Game_IsNet
then MH_SEND_GameSettings
;
4218 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4220 with gGameSettings
do
4222 if (Length(P
) > 1) and
4223 ((P
[1] = '1') or (P
[1] = '0')) then
4225 if (P
[1][1] = '1') then
4226 Options
:= Options
or GAME_OPTION_MONSTERS
4228 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4231 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4232 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4234 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4235 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4237 if g_Game_IsNet
then MH_SEND_GameSettings
;
4240 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4242 with gGameSettings
do
4244 if (Length(P
) > 1) and
4245 ((P
[1] = '1') or (P
[1] = '0')) then
4247 if (P
[1][1] = '1') then
4248 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4250 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4253 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4254 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4256 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4258 if g_Game_IsNet
then MH_SEND_GameSettings
;
4261 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4263 with gGameSettings
do
4265 if (Length(P
) > 1) and
4266 ((P
[1] = '1') or (P
[1] = '0')) then
4268 if (P
[1][1] = '1') then
4269 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4271 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4274 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4275 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4277 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4279 if g_Game_IsNet
then MH_SEND_GameSettings
;
4282 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4284 if Length(P
) > 1 then
4286 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4287 gGameSettings
.WarmupTime
:= 30
4289 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4292 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4293 [gGameSettings
.WarmupTime
]));
4294 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4296 else if cmd
= 'net_interp' then
4298 if (Length(P
) > 1) then
4299 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4301 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4302 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4303 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4304 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4307 else if cmd
= 'net_forceplayerupdate' then
4309 if (Length(P
) > 1) and
4310 ((P
[1] = '1') or (P
[1] = '0')) then
4311 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4313 if NetForcePlayerUpdate
then
4314 g_Console_Add('net_forceplayerupdate = 1')
4316 g_Console_Add('net_forceplayerupdate = 0');
4317 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4318 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4319 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4322 else if cmd
= 'net_predictself' then
4324 if (Length(P
) > 1) and
4325 ((P
[1] = '1') or (P
[1] = '0')) then
4326 NetPredictSelf
:= (P
[1][1] = '1');
4328 if NetPredictSelf
then
4329 g_Console_Add('net_predictself = 1')
4331 g_Console_Add('net_predictself = 0');
4332 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4333 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4334 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4337 else if cmd
= 'sv_name' then
4339 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4341 NetServerName
:= P
[1];
4342 if Length(NetServerName
) > 64 then
4343 SetLength(NetServerName
, 64);
4344 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4348 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4350 else if cmd
= 'sv_passwd' then
4352 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4354 NetPassword
:= P
[1];
4355 if Length(NetPassword
) > 24 then
4356 SetLength(NetPassword
, 24);
4357 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4361 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4363 else if cmd
= 'sv_maxplrs' then
4365 if (Length(P
) > 1) then
4367 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4368 if g_Game_IsServer
and g_Game_IsNet
then
4371 for a
:= 0 to High(NetClients
) do
4372 if NetClients
[a
].Used
then
4375 if b
> NetMaxClients
then
4377 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4378 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4379 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4380 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4383 if NetUseMaster
then
4388 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4390 else if cmd
= 'sv_public' then
4392 if (Length(P
) > 1) then
4394 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4395 if g_Game_IsServer
and g_Game_IsNet
then
4396 if NetUseMaster
then
4398 if NetMPeer
= nil then
4399 if not g_Net_Slist_Connect() then
4400 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4401 g_Net_Slist_Update();
4404 if NetMPeer
<> nil then
4405 g_Net_Slist_Disconnect();
4408 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4410 else if cmd
= 'sv_intertime' then
4412 if (Length(P
) > 1) then
4413 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4415 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4417 else if cmd
= 'p1_name' then
4419 if (Length(P
) > 1) and gGameOn
then
4421 if g_Game_IsClient
then
4423 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4424 MC_SEND_PlayerSettings
;
4427 if gPlayer1
<> nil then
4429 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4430 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4433 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4436 else if cmd
= 'p2_name' then
4438 if (Length(P
) > 1) and gGameOn
then
4440 if g_Game_IsClient
then
4442 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4443 MC_SEND_PlayerSettings
;
4446 if gPlayer2
<> nil then
4448 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4449 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4452 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4455 else if cmd
= 'p1_color' then
4457 if Length(P
) > 3 then
4458 if g_Game_IsClient
then
4460 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4461 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4462 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4463 MC_SEND_PlayerSettings
;
4466 if gPlayer1
<> nil then
4468 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4469 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4470 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4471 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4474 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4475 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4476 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4478 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4480 if Length(P
) > 3 then
4481 if g_Game_IsClient
then
4483 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4484 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4485 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4486 MC_SEND_PlayerSettings
;
4489 if gPlayer2
<> nil then
4491 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4492 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4493 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4494 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4497 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4498 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4499 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4501 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4503 if cmd
= 'r_showtime' then
4505 if (Length(P
) > 1) and
4506 ((P
[1] = '1') or (P
[1] = '0')) then
4507 gShowTime
:= (P
[1][1] = '1');
4510 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4512 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4514 else if cmd
= 'r_showscore' then
4516 if (Length(P
) > 1) and
4517 ((P
[1] = '1') or (P
[1] = '0')) then
4518 gShowGoals
:= (P
[1][1] = '1');
4521 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4523 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4525 else if cmd
= 'r_showstat' then
4527 if (Length(P
) > 1) and
4528 ((P
[1] = '1') or (P
[1] = '0')) then
4529 gShowStat
:= (P
[1][1] = '1');
4532 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4534 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4536 else if cmd
= 'r_showkillmsg' then
4538 if (Length(P
) > 1) and
4539 ((P
[1] = '1') or (P
[1] = '0')) then
4540 gShowKillMsg
:= (P
[1][1] = '1');
4542 if gShowKillMsg
then
4543 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4545 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4547 else if cmd
= 'r_showlives' then
4549 if (Length(P
) > 1) and
4550 ((P
[1] = '1') or (P
[1] = '0')) then
4551 gShowLives
:= (P
[1][1] = '1');
4554 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4556 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4558 else if cmd
= 'r_showspect' then
4560 if (Length(P
) > 1) and
4561 ((P
[1] = '1') or (P
[1] = '0')) then
4562 gSpectHUD
:= (P
[1][1] = '1');
4565 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4567 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4569 else if cmd
= 'r_showping' then
4571 if (Length(P
) > 1) and
4572 ((P
[1] = '1') or (P
[1] = '0')) then
4573 gShowPing
:= (P
[1][1] = '1');
4576 g_Console_Add(_lc
[I_MSG_PING_ON
])
4578 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4580 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4582 if Length(P
) > 1 then
4584 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4585 gGameSettings
.GoalLimit
:= 0
4590 if gGameSettings
.GameMode
= GM_DM
then
4592 stat
:= g_Player_GetStats();
4594 for a
:= 0 to High(stat
) do
4595 if stat
[a
].Frags
> b
then
4599 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4601 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4604 if g_Game_IsNet
then MH_SEND_GameSettings
;
4607 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4609 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4611 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4612 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4614 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4615 [gGameSettings
.TimeLimit
div 3600,
4616 (gGameSettings
.TimeLimit
div 60) mod 60,
4617 gGameSettings
.TimeLimit
mod 60]));
4618 if g_Game_IsNet
then MH_SEND_GameSettings
;
4620 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4622 if Length(P
) > 1 then
4624 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4625 gGameSettings
.MaxLives
:= 0
4629 stat
:= g_Player_GetStats();
4631 for a
:= 0 to High(stat
) do
4632 if stat
[a
].Lives
> b
then
4634 gGameSettings
.MaxLives
:=
4635 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4639 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4640 [gGameSettings
.MaxLives
]));
4641 if g_Game_IsNet
then MH_SEND_GameSettings
;
4646 procedure DebugCommands(P
: SArray
);
4652 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4655 cmd
:= LowerCase(P
[0]);
4656 if cmd
= 'd_window' then
4658 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4659 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4660 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4661 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4662 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4664 else if cmd
= 'd_sounds' then
4666 if (Length(P
) > 1) and
4667 ((P
[1] = '1') or (P
[1] = '0')) then
4668 g_Debug_Sounds
:= (P
[1][1] = '1');
4670 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4672 else if cmd
= 'd_frames' then
4674 if (Length(P
) > 1) and
4675 ((P
[1] = '1') or (P
[1] = '0')) then
4676 g_Debug_Frames
:= (P
[1][1] = '1');
4678 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4680 else if cmd
= 'd_winmsg' then
4682 if (Length(P
) > 1) and
4683 ((P
[1] = '1') or (P
[1] = '0')) then
4684 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4686 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4688 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4690 if (Length(P
) > 1) and
4691 ((P
[1] = '1') or (P
[1] = '0')) then
4692 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4694 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4696 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4698 if Length(P
) > 1 then
4700 '0': g_debug_BotAIOff
:= 0;
4701 '1': g_debug_BotAIOff
:= 1;
4702 '2': g_debug_BotAIOff
:= 2;
4703 '3': g_debug_BotAIOff
:= 3;
4706 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4708 else if cmd
= 'd_monster' then
4710 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4711 if Length(P
) < 2 then
4713 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4714 g_Console_Add('ID | Name');
4715 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4716 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4719 a
:= StrToIntDef(P
[1], 0);
4720 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4721 a
:= g_Monsters_GetIDByName(P
[1]);
4723 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4724 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4727 with gPlayer1
.Obj
do
4728 b
:= g_Monsters_Create(a
,
4729 X
+ Rect
.X
+ (Rect
.Width
div 2),
4730 Y
+ Rect
.Y
+ Rect
.Height
,
4731 gPlayer1
.Direction
, True);
4732 if (Length(P
) > 2) and (b
>= 0) then
4733 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4737 else if (cmd
= 'd_health') then
4739 if (Length(P
) > 1) and
4740 ((P
[1] = '1') or (P
[1] = '0')) then
4741 g_debug_HealthBar
:= (P
[1][1] = '1');
4743 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4745 else if (cmd
= 'd_player') then
4747 if (Length(P
) > 1) and
4748 ((P
[1] = '1') or (P
[1] = '0')) then
4749 g_debug_Player
:= (P
[1][1] = '1');
4751 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4753 else if (cmd
= 'd_joy') then
4756 g_Console_Add(e_JoystickStateToString(a
));
4760 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4763 procedure GameCommands(P
: SArray
);
4769 pl
: pTNetClient
= nil;
4776 cmd
:= LowerCase(P
[0]);
4778 if (cmd
= 'quit') or
4785 else if cmd
= 'pause' then
4787 if (g_ActiveWindow
= nil) then
4788 g_Game_Pause(not gPause
);
4790 else if cmd
= 'endgame' then
4791 gExit
:= EXIT_SIMPLE
4792 else if cmd
= 'restart' then
4794 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4796 if g_Game_IsClient
then
4798 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4803 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4805 else if cmd
= 'kick' then
4807 if g_Game_IsServer
then
4809 if Length(P
) < 2 then
4811 g_Console_Add('kick <name>');
4816 g_Console_Add('kick <name>');
4820 if g_Game_IsNet
then
4821 pl
:= g_Net_Client_ByName(P
[1]);
4824 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4825 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4826 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4827 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4828 if NetUseMaster
then
4830 end else if gPlayers
<> nil then
4831 for a
:= Low(gPlayers
) to High(gPlayers
) do
4832 if gPlayers
[a
] <> nil then
4833 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4835 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4836 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4838 gPlayers
[a
].Lives
:= 0;
4839 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4840 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4841 g_Player_Remove(gPlayers
[a
].UID
);
4842 if NetUseMaster
then
4844 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4848 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4850 else if cmd
= 'kick_id' then
4852 if g_Game_IsServer
and g_Game_IsNet
then
4854 if Length(P
) < 2 then
4856 g_Console_Add('kick_id <client ID>');
4861 g_Console_Add('kick_id <client ID>');
4865 a
:= StrToIntDef(P
[1], 0);
4866 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4868 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4870 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4871 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4872 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4873 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4874 if NetUseMaster
then
4879 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4881 else if cmd
= 'ban' then
4883 if g_Game_IsServer
and g_Game_IsNet
then
4885 if Length(P
) < 2 then
4887 g_Console_Add('ban <name>');
4892 g_Console_Add('ban <name>');
4896 pl
:= g_Net_Client_ByName(P
[1]);
4899 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4900 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4901 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4902 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4903 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4904 if NetUseMaster
then
4907 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4909 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4911 else if cmd
= 'ban_id' then
4913 if g_Game_IsServer
and g_Game_IsNet
then
4915 if Length(P
) < 2 then
4917 g_Console_Add('ban_id <client ID>');
4922 g_Console_Add('ban_id <client ID>');
4926 a
:= StrToIntDef(P
[1], 0);
4927 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4928 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4930 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4931 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4932 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4933 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4934 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4935 if NetUseMaster
then
4939 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4941 else if cmd
= 'permban' then
4943 if g_Game_IsServer
and g_Game_IsNet
then
4945 if Length(P
) < 2 then
4947 g_Console_Add('permban <name>');
4952 g_Console_Add('permban <name>');
4956 pl
:= g_Net_Client_ByName(P
[1]);
4959 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4960 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4961 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4962 g_Net_SaveBanList();
4963 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4964 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4965 if NetUseMaster
then
4968 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4970 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4972 else if cmd
= 'permban_id' then
4974 if g_Game_IsServer
and g_Game_IsNet
then
4976 if Length(P
) < 2 then
4978 g_Console_Add('permban_id <client ID>');
4983 g_Console_Add('permban_id <client ID>');
4987 a
:= StrToIntDef(P
[1], 0);
4988 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4989 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4991 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4992 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4993 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
4994 g_Net_SaveBanList();
4995 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4996 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4997 if NetUseMaster
then
5001 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5003 else if cmd
= 'unban' then
5005 if g_Game_IsServer
and g_Game_IsNet
then
5007 if Length(P
) < 2 then
5009 g_Console_Add('unban <IP Address>');
5014 g_Console_Add('unban <IP Address>');
5018 if g_Net_UnbanHost(P
[1]) then
5020 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5021 g_Net_SaveBanList();
5023 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5025 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5027 else if cmd
= 'clientlist' then
5029 if g_Game_IsServer
and g_Game_IsNet
then
5032 if NetClients
<> nil then
5033 for a
:= Low(NetClients
) to High(NetClients
) do
5034 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5036 plr
:= g_Player_Get(NetClients
[a
].Player
);
5037 if plr
= nil then continue
;
5039 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5040 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5043 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5045 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5047 else if cmd
= 'connect' then
5049 if (NetMode
= NET_NONE
) then
5051 if Length(P
) < 2 then
5053 g_Console_Add('connect <IP> [port] [password]');
5058 g_Console_Add('connect <IP> [port] [password]');
5062 if Length(P
) > 2 then
5063 prt
:= StrToIntDef(P
[2], 25666)
5067 if Length(P
) > 3 then
5072 g_Game_StartClient(P
[1], prt
, pw
);
5075 else if cmd
= 'disconnect' then
5077 if (NetMode
= NET_CLIENT
) then
5080 else if cmd
= 'reconnect' then
5082 if (NetMode
= NET_SERVER
) then
5085 if (NetMode
= NET_CLIENT
) then
5088 gExit
:= EXIT_SIMPLE
;
5092 //TODO: Use last successful password to reconnect, instead of ''
5093 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5095 else if (cmd
= 'addbot') or
5096 (cmd
= 'bot_add') then
5098 if Length(P
) > 1 then
5099 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5101 g_Bot_Add(TEAM_NONE
, 2);
5103 else if cmd
= 'bot_addlist' then
5105 if Length(P
) > 1 then
5106 if Length(P
) = 2 then
5107 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5109 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5111 else if cmd
= 'bot_removeall' then
5113 else if cmd
= 'chat' then
5115 if g_Game_IsNet
then
5117 if Length(P
) > 1 then
5119 for a
:= 1 to High(P
) do
5120 chstr
:= chstr
+ P
[a
] + ' ';
5122 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5124 if Length(chstr
) < 1 then
5126 g_Console_Add('chat <text>');
5130 chstr
:= b_Text_Format(chstr
);
5131 if g_Game_IsClient
then
5132 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5134 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5137 g_Console_Add('chat <text>');
5139 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5141 else if cmd
= 'teamchat' then
5143 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5145 if Length(P
) > 1 then
5147 for a
:= 1 to High(P
) do
5148 chstr
:= chstr
+ P
[a
] + ' ';
5150 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5152 if Length(chstr
) < 1 then
5154 g_Console_Add('teamchat <text>');
5158 chstr
:= b_Text_Format(chstr
);
5159 if g_Game_IsClient
then
5160 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5162 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5163 gPlayer1Settings
.Team
);
5166 g_Console_Add('teamchat <text>');
5168 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5170 else if cmd
= 'game' then
5172 if gGameSettings
.GameType
<> GT_NONE
then
5174 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5177 if Length(P
) = 1 then
5179 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5182 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5183 if (Pos('.wad', LowerCase(P
[1])) = 0) and (Pos('.pk3', LowerCase(P
[1])) = 0) then
5184 P
[1] := P
[1] + '.wad';
5186 if FileExists(MapsDir
+ P
[1]) then
5188 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5189 if Length(P
) < 3 then
5192 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5195 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5197 if g_Map_Exist(MapsDir
+ s
) then
5199 // Çàïóñêàåì ñâîþ èãðó
5201 with gGameSettings
do
5203 GameMode
:= g_Game_TextToMode(gcGameMode
);
5204 if gSwitchGameMode
<> GM_NONE
then
5205 GameMode
:= gSwitchGameMode
;
5206 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5207 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5209 if Length(P
) >= 4 then
5210 b
:= StrToIntDef(P
[3], 1);
5211 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5212 GoalLimit
, MaxLives
, Options
, b
);
5217 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5219 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5221 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5223 else if cmd
= 'host' then
5225 if gGameSettings
.GameType
<> GT_NONE
then
5227 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5230 if Length(P
) < 4 then
5232 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5235 if not StrToIp(P
[1], listen
) then
5237 prt
:= StrToIntDef(P
[2], 25666);
5239 if (Pos('.wad', LowerCase(P
[3])) = 0) and (Pos('.pk3', LowerCase(P
[3])) = 0) then
5240 P
[3] := P
[3] + '.wad';
5242 if FileExists(MapsDir
+ P
[3]) then
5244 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5245 if Length(P
) < 5 then
5248 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5251 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5253 if g_Map_Exist(MapsDir
+ s
) then
5255 // Çàïóñêàåì ñâîþ èãðó
5257 with gGameSettings
do
5259 GameMode
:= g_Game_TextToMode(gcGameMode
);
5260 if gSwitchGameMode
<> GM_NONE
then
5261 GameMode
:= gSwitchGameMode
;
5262 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5263 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5265 if Length(P
) >= 6 then
5266 b
:= StrToIntDef(P
[5], 0);
5267 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5268 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5273 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5275 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5277 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5279 else if cmd
= 'map' then
5281 if Length(P
) = 1 then
5283 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5285 g_Console_Add(cmd
+ ' <MAP>');
5286 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5288 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5290 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5292 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5293 if Length(P
) < 3 then
5295 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5296 s
:= UpperCase(P
[1]);
5297 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5298 begin // Êàðòà íàøëàñü
5299 gExitByTrigger
:= False;
5301 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5303 gExit
:= EXIT_ENDLEVELCUSTOM
;
5305 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5306 g_Game_ChangeMap(s
);
5309 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5310 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5311 if (Pos('.wad', LowerCase(P
[1])) = 0) and (Pos('.pk3', LowerCase(P
[1])) = 0) then
5312 P
[1] := P
[1] + '.wad';
5314 if FileExists(MapsDir
+ P
[1]) then
5316 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5318 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5320 s
:= P
[1] + ':\' + P
[2];
5322 if g_Map_Exist(MapsDir
+ s
) then
5324 gExitByTrigger
:= False;
5326 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5328 gExit
:= EXIT_ENDLEVELCUSTOM
;
5330 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5331 g_Game_ChangeMap(s
);
5334 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5336 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5338 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5342 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5343 if (Pos('.wad', LowerCase(P
[1])) = 0) and (Pos('.pk3', LowerCase(P
[1])) = 0) then
5344 P
[1] := P
[1] + '.wad';
5346 if FileExists(MapsDir
+ P
[1]) then
5349 P
[2] := UpperCase(P
[2]);
5350 s
:= P
[1] + ':\' + P
[2];
5352 if g_Map_Exist(MapsDir
+ s
) then
5353 begin // Íàøëè êàðòó
5354 gExitByTrigger
:= False;
5356 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5358 gExit
:= EXIT_ENDLEVELCUSTOM
;
5360 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5361 g_Game_ChangeMap(s
);
5363 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5365 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5368 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5370 else if cmd
= 'nextmap' then
5372 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5373 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5376 if Length(P
) = 1 then
5378 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5380 g_Console_Add(cmd
+ ' <MAP>');
5381 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5384 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5389 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5391 if Length(P
) < 3 then
5393 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5394 s
:= UpperCase(P
[1]);
5395 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5396 begin // Êàðòà íàøëàñü
5397 gExitByTrigger
:= False;
5402 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5403 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5404 if (Pos('.wad', LowerCase(P
[1])) = 0) and (Pos('.pk3', LowerCase(P
[1])) = 0) then
5405 P
[1] := P
[1] + '.wad';
5407 if FileExists(MapsDir
+ P
[1]) then
5409 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5411 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5413 s
:= P
[1] + ':\' + P
[2];
5415 if g_Map_Exist(MapsDir
+ s
) then
5416 begin // Óñòàíàâëèâàåì êàðòó
5417 gExitByTrigger
:= False;
5422 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5424 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5426 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5430 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5431 if (Pos('.wad', LowerCase(P
[1])) = 0) and (Pos('.pk3', LowerCase(P
[1])) = 0) then
5432 P
[1] := P
[1] + '.wad';
5434 if FileExists(MapsDir
+ P
[1]) then
5437 P
[2] := UpperCase(P
[2]);
5438 s
:= P
[1] + ':\' + P
[2];
5440 if g_Map_Exist(MapsDir
+ s
) then
5441 begin // Íàøëè êàðòó
5442 gExitByTrigger
:= False;
5446 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5448 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5451 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5454 if gNextMap
= '' then
5455 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5457 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5460 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5463 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5465 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5467 gExitByTrigger
:= False;
5468 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5469 if (gNextMap
= '') and (gTriggers
<> nil) then
5470 for a
:= 0 to High(gTriggers
) do
5471 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5473 gExitByTrigger
:= True;
5474 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5477 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5478 if gNextMap
= '' then
5479 gNextMap
:= g_Game_GetNextMap();
5480 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5481 if Pos(':\', gNextMap
) = 0 then
5482 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5485 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5486 if g_Map_Exist(MapsDir
+ s
) then
5487 gExit
:= EXIT_ENDLEVELCUSTOM
5489 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5491 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5493 else if (cmd
= 'event') then
5495 if (Length(P
) <= 1) then
5497 for a
:= 0 to High(gEvents
) do
5498 if gEvents
[a
].Command
= '' then
5499 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5501 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5504 if (Length(P
) = 2) then
5506 for a
:= 0 to High(gEvents
) do
5507 if gEvents
[a
].Name
= P
[1] then
5508 if gEvents
[a
].Command
= '' then
5509 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5511 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5514 for a
:= 0 to High(gEvents
) do
5515 if gEvents
[a
].Name
= P
[1] then
5517 gEvents
[a
].Command
:= '';
5518 for b
:= 2 to High(P
) do
5519 if Pos(' ', P
[b
]) = 0 then
5520 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5522 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5523 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5527 // Êîìàíäû Ñâîåé èãðû:
5528 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5530 if cmd
= 'bot_addred' then
5532 if Length(P
) > 1 then
5533 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5535 g_Bot_Add(TEAM_RED
, 2);
5537 else if cmd
= 'bot_addblue' then
5539 if Length(P
) > 1 then
5540 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5542 g_Bot_Add(TEAM_BLUE
, 2);
5544 else if cmd
= 'suicide' then
5548 if g_Game_IsClient
then
5549 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5552 if gPlayer1
<> nil then
5553 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5554 if gPlayer2
<> nil then
5555 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5559 else if cmd
= 'spectate' then
5565 else if cmd
= 'say' then
5567 if g_Game_IsServer
and g_Game_IsNet
then
5569 if Length(P
) > 1 then
5572 for a
:= 1 to High(P
) do
5573 chstr
:= chstr
+ P
[a
] + ' ';
5575 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5577 if Length(chstr
) < 1 then
5579 g_Console_Add('say <text>');
5583 chstr
:= b_Text_Format(chstr
);
5584 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5586 else g_Console_Add('say <text>');
5588 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5590 else if cmd
= 'tell' then
5592 if g_Game_IsServer
and g_Game_IsNet
then
5594 if (Length(P
) > 2) and (P
[1] <> '') then
5597 for a
:= 2 to High(P
) do
5598 chstr
:= chstr
+ P
[a
] + ' ';
5600 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5602 if Length(chstr
) < 1 then
5604 g_Console_Add('tell <playername> <text>');
5608 pl
:= g_Net_Client_ByName(P
[1]);
5610 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5612 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5614 else g_Console_Add('tell <playername> <text>');
5616 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5618 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5620 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5622 // Äîïîëíèòåëüíîå âðåìÿ:
5623 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5625 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5626 [gGameSettings
.TimeLimit
div 3600,
5627 (gGameSettings
.TimeLimit
div 60) mod 60,
5628 gGameSettings
.TimeLimit
mod 60]));
5629 if g_Game_IsNet
then MH_SEND_GameSettings
;
5631 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5633 if (Length(P
) <= 1) then
5634 g_Console_Add('rcon_password <password>')
5636 MC_SEND_RCONPassword(P
[1]);
5638 else if cmd
= 'rcon' then
5640 if g_Game_IsClient
then
5642 if Length(P
) > 1 then
5645 for a
:= 1 to High(P
) do
5646 chstr
:= chstr
+ P
[a
] + ' ';
5648 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5650 if Length(chstr
) < 1 then
5652 g_Console_Add('rcon <command>');
5656 MC_SEND_RCONCommand(chstr
);
5658 else g_Console_Add('rcon <command>');
5661 else if cmd
= 'ready' then
5663 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5664 gLMSRespawnTime
:= gTime
+ 100;
5666 else if (cmd
= 'callvote') and g_Game_IsNet
then
5668 if Length(P
) > 1 then
5671 for a
:= 1 to High(P
) do begin
5672 if a
> 1 then chstr
:= chstr
+ ' ';
5673 chstr
:= chstr
+ P
[a
];
5676 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5678 if Length(chstr
) < 1 then
5680 g_Console_Add('callvote <command>');
5684 if g_Game_IsClient
then
5685 MC_SEND_Vote(True, chstr
)
5687 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5688 g_Console_Process('vote', True);
5691 g_Console_Add('callvote <command>');
5693 else if (cmd
= 'vote') and g_Game_IsNet
then
5695 if g_Game_IsClient
then
5697 else if gVoteInProgress
then
5699 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5700 a
:= Floor((NetClientCount
+1)/2.0) + 1
5702 a
:= Floor(NetClientCount
/2.0) + 1;
5707 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5708 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5714 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5715 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5723 procedure g_TakeScreenShot();
5728 for a
:= 1 to High(Word) do
5730 FileName
:= Format(GameDir
+'/Screenshots/Screenshot%.3d.bmp', [a
]);
5731 if not FileExists(FileName
) then
5733 e_MakeScreenshot(FileName
, gScreenWidth
, gScreenHeight
);
5734 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5740 procedure g_Game_InGameMenu(Show
: Boolean);
5742 if (g_ActiveWindow
= nil) and Show
then
5744 if gGameSettings
.GameType
= GT_SINGLE
then
5745 g_GUI_ShowWindow('GameSingleMenu')
5748 if g_Game_IsClient
then
5749 g_GUI_ShowWindow('GameClientMenu')
5751 if g_Game_IsNet
then
5752 g_GUI_ShowWindow('GameServerMenu')
5754 g_GUI_ShowWindow('GameCustomMenu');
5756 g_Sound_PlayEx('MENU_OPEN');
5758 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5759 if (not g_Game_IsNet
) then
5763 if (g_ActiveWindow
<> nil) and (not Show
) then
5765 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5766 if (not g_Game_IsNet
) then
5767 g_Game_Pause(False);
5771 procedure g_Game_Pause(Enable
: Boolean);
5776 if gPause
= Enable
then
5779 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5783 g_Game_PauseAllSounds(Enable
);
5786 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5791 if gTriggers
<> nil then
5792 for i
:= 0 to High(gTriggers
) do
5793 with gTriggers
[i
] do
5794 if (TriggerType
= TRIGGER_SOUND
) and
5796 Sound
.IsPlaying() then
5798 Sound
.Pause(Enable
);
5802 if gPlayers
<> nil then
5803 for i
:= 0 to High(gPlayers
) do
5804 if gPlayers
[i
] <> nil then
5805 gPlayers
[i
].PauseSounds(Enable
);
5808 if gMusic
<> nil then
5809 gMusic
.Pause(Enable
);
5812 procedure g_Game_StopAllSounds(all
: Boolean);
5816 if gTriggers
<> nil then
5817 for i
:= 0 to High(gTriggers
) do
5818 with gTriggers
[i
] do
5819 if (TriggerType
= TRIGGER_SOUND
) and
5823 if gMusic
<> nil then
5830 procedure g_Game_UpdateTriggerSounds();
5834 if gTriggers
<> nil then
5835 for i
:= 0 to High(gTriggers
) do
5836 with gTriggers
[i
] do
5837 if (TriggerType
= TRIGGER_SOUND
) and
5840 Sound
.IsPlaying() then
5842 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
5843 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
5845 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
5846 Sound
.SetVolume(Data
.Volume
/255.0);
5849 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
5853 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
5856 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
5861 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
5866 if gSpectMode
<> SPECT_PLAYERS
then
5868 if gSpectPID1
= UID
then
5873 if gSpectViewTwo
and (gSpectPID2
= UID
) then
5880 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
5885 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
5890 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
5895 if gSpectMode
<> SPECT_PLAYERS
then
5897 Pl
:= g_Player_Get(gSpectPID1
);
5898 if (Pl
<> nil) and (Pl
.Team
= Team
) then
5903 if gSpectViewTwo
then
5905 Pl
:= g_Player_Get(gSpectPID2
);
5906 if (Pl
<> nil) and (Pl
.Team
= Team
) then
5914 procedure g_Game_Message(Msg
: string; Time
: Word);
5916 MessageText
:= b_Text_Format(Msg
);
5917 MessageTime
:= Time
;
5920 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
5929 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
5933 if goodsnd
[a
].IsPlaying() then
5936 goodsnd
[Random(4)].Play();
5939 procedure g_Game_Announce_KillCombo(Param
: Integer);
5946 UID
:= Param
and $FFFF;
5951 Pl
:= g_Player_Get(UID
);
5960 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
5964 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
5968 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
5972 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
5980 if not g_Game_IsWatchedPlayer(UID
) then
5983 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
5987 if killsnd
[n
].IsPlaying() then
5992 procedure g_Game_StartVote(Command
, Initiator
: string);
5996 if not gVotesEnabled
then Exit
;
5997 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
5998 if gVoteInProgress
or gVotePassed
then
6000 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6001 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6004 gVoteInProgress
:= True;
6005 gVotePassed
:= False;
6006 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6009 gVoteCommand
:= Command
;
6011 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6012 Need
:= Floor((NetClientCount
+1)/2.0)+1
6014 Need
:= Floor(NetClientCount
/2.0)+1;
6015 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6016 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6019 procedure g_Game_CheckVote
;
6023 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6024 if not gVoteInProgress
then Exit
;
6026 if (gTime
>= gVoteTimer
) then
6028 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6029 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6031 Need
:= Floor(NetClientCount
/2.0) + 1;
6032 if gVoteCount
>= Need
then
6034 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6035 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6036 gVotePassed
:= True;
6037 gVoteCmdTimer
:= gTime
+ 5000;
6041 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6042 MH_SEND_VoteEvent(NET_VE_FAILED
);
6044 if NetClients
<> nil then
6045 for I
:= Low(NetClients
) to High(NetClients
) do
6046 if NetClients
[i
].Used
then
6047 NetClients
[i
].Voted
:= False;
6048 gVoteInProgress
:= False;
6054 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6055 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6057 Need
:= Floor(NetClientCount
/2.0) + 1;
6058 if gVoteCount
>= Need
then
6060 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6061 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6062 gVoteInProgress
:= False;
6063 gVotePassed
:= True;
6064 gVoteCmdTimer
:= gTime
+ 5000;
6067 if NetClients
<> nil then
6068 for I
:= Low(NetClients
) to High(NetClients
) do
6069 if NetClients
[i
].Used
then
6070 NetClients
[i
].Voted
:= False;
6075 procedure g_Game_LoadMapList(FileName
: string);
6083 if not FileExists(FileName
) then Exit
;
6085 AssignFile(ListFile
, FileName
);
6087 while not EOF(ListFile
) do
6089 ReadLn(ListFile
, s
);
6092 if s
= '' then Continue
;
6094 SetLength(MapList
, Length(MapList
)+1);
6095 MapList
[High(MapList
)] := s
;
6097 CloseFile(ListFile
);
6100 procedure g_Game_SetDebugMode();
6103 // ×èòû (äàæå â ñâîåé èãðå):
6107 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6111 if Length(LoadingStat
.Msgs
) = 0 then
6117 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6118 if NextMsg
= Length(Msgs
) then
6120 for i
:= 0 to High(Msgs
)-1 do
6121 Msgs
[i
] := Msgs
[i
+1];
6129 Msgs
[NextMsg
-1] := Text;
6135 g_ActiveWindow
:= nil;
6140 procedure g_Game_StepLoading();
6146 if (ShowCount
> LOADING_SHOW_STEP
) then
6154 procedure g_Game_ClearLoading();
6163 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6164 if len
< 1 then len
:= 1;
6165 SetLength(Msgs
, len
);
6166 for len
:= Low(Msgs
) to High(Msgs
) do
6172 procedure Parse_Params(var pars
: TParamStrValues
);
6179 while i
<= ParamCount
do
6182 if (s
[1] = '-') and (Length(s
) > 1) then
6184 if (s
[2] = '-') and (Length(s
) > 2) then
6185 begin // Îäèíî÷íûé ïàðàìåòð
6186 SetLength(pars
, Length(pars
) + 1);
6187 with pars
[High(pars
)] do
6189 Name
:= LowerCase(s
);
6194 if (i
< ParamCount
) then
6195 begin // Ïàðàìåòð ñî çíà÷åíèåì
6197 SetLength(pars
, Length(pars
) + 1);
6198 with pars
[High(pars
)] do
6200 Name
:= LowerCase(s
);
6201 Value
:= LowerCase(ParamStr(i
));
6210 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6215 for i
:= 0 to High(pars
) do
6216 if pars
[i
].Name
= aName
then
6218 Result
:= pars
[i
].Value
;
6223 procedure g_Game_Process_Params();
6225 pars
: TParamStrValues
;
6228 LimT
, LimS
: Integer;
6239 s
:= Find_Param_Value(pars
, '--debug');
6241 g_Game_SetDebugMode();
6243 // Connect when game loads
6244 ip
:= Find_Param_Value(pars
, '-connect');
6248 s
:= Find_Param_Value(pars
, '-port');
6249 if (s
= '') or not TryStrToInt(s
, Port
) then
6252 s
:= Find_Param_Value(pars
, '-pw');
6254 g_Game_StartClient(ip
, Port
, s
);
6258 // Start map when game loads:
6259 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6260 if (map
<> '') and ((Pos('.wad:\', map
) > 0) or (Pos('.pk3:\', map
) > 0)) then
6263 s
:= Find_Param_Value(pars
, '-gm');
6264 GMode
:= g_Game_TextToMode(s
);
6265 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6266 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6269 s
:= Find_Param_Value(pars
, '-limt');
6270 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6276 s
:= Find_Param_Value(pars
, '-lims');
6277 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6283 s
:= Find_Param_Value(pars
, '-lives');
6284 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6290 s
:= Find_Param_Value(pars
, '-opt');
6292 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6294 Opt
:= StrToIntDef(s
, 0);
6296 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6299 s
:= Find_Param_Value(pars
, '--close');
6303 // Delete test map after play:
6304 s
:= Find_Param_Value(pars
, '--testdelete');
6307 gMapToDelete
:= MapsDir
+ map
;
6308 e_WriteLog('"--testdelete" argument doesn''t supported anymore!', MSG_FATALERROR
);
6312 // Delete temporary WAD after play:
6313 s
:= Find_Param_Value(pars
, '--tempdelete');
6316 gMapToDelete
:= MapsDir
+ map
;
6317 gTempDelete
:= True;
6320 // Number of players:
6321 s
:= Find_Param_Value(pars
, '-pl');
6325 n
:= StrToIntDef(s
, 1);
6328 s
:= Find_Param_Value(pars
, '-port');
6329 if (s
= '') or not TryStrToInt(s
, Port
) then
6330 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6332 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6335 // Execute script when game loads:
6336 s
:= Find_Param_Value(pars
, '-exec');
6339 if Pos(':\', s
) = 0 then
6340 s
:= GameDir
+ '/' + s
;
6345 if IOResult
<> 0 then
6347 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6348 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6352 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6353 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6358 if IOResult
<> 0 then
6360 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6361 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6365 if Pos('#', s
) <> 1 then // script comment
6366 g_Console_Process(s
, True);