7 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
8 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, wadreader
, md5
;
11 TGameSettings
= record
27 TDelayedEvent
= record
35 TPlayerSettings
= record
54 function g_Game_IsNet(): Boolean;
55 function g_Game_IsServer(): Boolean;
56 function g_Game_IsClient(): Boolean;
57 procedure g_Game_Init();
58 procedure g_Game_Free();
59 procedure g_Game_LoadData();
60 procedure g_Game_FreeData();
61 procedure g_Game_Update();
62 procedure g_Game_Draw();
63 procedure g_Game_Quit();
64 procedure g_Game_SetupScreenSize();
65 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
66 function g_Game_ModeToText(Mode
: Byte): string;
67 function g_Game_TextToMode(Mode
: string): Byte;
68 procedure g_Game_ExecuteEvent(Name
: String);
69 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
70 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
71 procedure g_Game_RemovePlayer();
72 procedure g_Game_Spectate();
73 procedure g_Game_SpectateCenterView();
74 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
75 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
76 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
77 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
78 procedure g_Game_Restart();
79 procedure g_Game_RestartLevel();
80 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
81 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
82 procedure g_Game_SaveOptions();
83 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
84 procedure g_Game_ChangeMap(MapPath
: String);
85 procedure g_Game_ExitLevel(Map
: Char16
);
86 function g_Game_GetFirstMap(WAD
: String): String;
87 function g_Game_GetNextMap(): String;
88 procedure g_Game_NextLevel();
89 procedure g_Game_Pause(Enable
: Boolean);
90 procedure g_Game_InGameMenu(Show
: Boolean);
91 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
92 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
93 procedure g_Game_Message(Msg
: String; Time
: Word);
94 procedure g_Game_LoadMapList(FileName
: String);
95 procedure g_Game_PauseAllSounds(Enable
: Boolean);
96 procedure g_Game_StopAllSounds(all
: Boolean);
97 procedure g_Game_UpdateTriggerSounds();
98 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
99 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
100 procedure g_Game_Announce_KillCombo(Param
: Integer);
101 procedure g_Game_StartVote(Command
, Initiator
: string);
102 procedure g_Game_CheckVote
;
103 procedure g_TakeScreenShot();
104 procedure g_FatalError(Text: String);
105 procedure g_SimpleError(Text: String);
106 function g_Game_IsTestMap(): Boolean;
107 procedure g_Game_DeleteTestMap();
108 procedure GameCVars(P
: SArray
);
109 procedure GameCommands(P
: SArray
);
110 procedure GameCheats(P
: SArray
);
111 procedure DebugCommands(P
: SArray
);
112 procedure g_Game_Process_Params
;
113 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
114 procedure g_Game_StepLoading();
115 procedure g_Game_ClearLoading();
116 procedure g_Game_SetDebugMode();
117 procedure DrawLoadingStat();
119 { procedure SetWinPause(Enable: Boolean); }
124 LOADING_SHOW_STEP
= 100;
125 LOADING_INTERLINE
= 20;
140 MESSAGE_DIKEY
= WM_USER
+ 1;
145 EXIT_ENDLEVELSINGLE
= 4;
146 EXIT_ENDLEVELCUSTOM
= 5;
148 GAME_OPTION_RESERVED
= 1;
149 GAME_OPTION_TEAMDAMAGE
= 2;
150 GAME_OPTION_ALLOWEXIT
= 4;
151 GAME_OPTION_WEAPONSTAY
= 8;
152 GAME_OPTION_MONSTERS
= 16;
153 GAME_OPTION_BOTVSPLAYER
= 32;
154 GAME_OPTION_BOTVSMONSTER
= 64;
159 STATE_INTERCUSTOM
= 3;
160 STATE_INTERSINGLE
= 4;
166 LMS_RESPAWN_NONE
= 0;
167 LMS_RESPAWN_WARMUP
= 1;
168 LMS_RESPAWN_FINAL
= 2;
184 CONFIG_FILENAME
= 'Doom2DF.cfg';
185 LOG_FILENAME
= 'Doom2DF.log';
187 TEST_MAP_NAME
= '$$$_TEST_$$$';
189 STD_PLAYER_MODEL
= 'Doomer';
193 gGameSettings
: TGameSettings
;
194 gPlayer1Settings
: TPlayerSettings
;
195 gPlayer2Settings
: TPlayerSettings
;
197 gPlayerScreenSize
: TPoint
;
198 gPlayer1ScreenCoord
: TPoint
;
199 gPlayer2ScreenCoord
: TPoint
;
200 gPlayer1
: TPlayer
= nil;
201 gPlayer2
: TPlayer
= nil;
202 gPlayerDrawn
: TPlayer
= nil;
204 gSwitchGameMode
: Byte = GM_DM
;
205 gHearPoint1
, gHearPoint2
: THearPoint
;
206 gSoundEffectsDF
: Boolean = False;
207 gSoundTriggerTime
: Word = 0;
208 gAnnouncer
: Byte = ANNOUNCE_NONE
;
209 goodsnd
: array[0..3] of TPlayableSound
;
210 killsnd
: array[0..3] of TPlayableSound
;
211 gDefInterTime
: ShortInt = -1;
212 gInterEndTime
: LongWord = 0;
213 gInterTime
: LongWord = 0;
214 gServInterTime
: Byte = 0;
215 gGameStartTime
: LongWord = 0;
216 gTotalMonsters
: Integer = 0;
218 gShowTime
: Boolean = True;
219 gShowFPS
: Boolean = False;
220 gShowGoals
: Boolean = True;
221 gShowStat
: Boolean = True;
222 gShowKillMsg
: Boolean = True;
223 gShowLives
: Boolean = True;
224 gShowPing
: Boolean = False;
225 gShowMap
: Boolean = False;
227 gState
: Byte = STATE_NONE
;
229 sWidth
, sHeight
: Word;
230 gSpectMode
: Byte = SPECT_NONE
;
231 gSpectHUD
: Boolean = True;
232 gSpectKeyPress
: Boolean = False;
233 gSpectX
: Integer = 0;
234 gSpectY
: Integer = 0;
235 gSpectStep
: Byte = 8;
236 gSpectViewTwo
: Boolean = False;
237 gSpectPID1
: Integer = -1;
238 gSpectPID2
: Integer = -1;
239 gMusic
: TMusic
= nil;
240 gLoadGameMode
: Boolean;
241 gCheats
: Boolean = False;
242 gMapOnce
: Boolean = False;
243 gMapToDelete
: String;
244 gTempDelete
: Boolean = False;
245 gLastMap
: Boolean = False;
246 gWinPosX
, gWinPosY
: Integer;
247 gWinSizeX
, gWinSizeY
: Integer;
248 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
249 gWinActive
: Boolean = True; // by default window is active, lol
250 gResolutionChange
: Boolean = False;
251 gRC_Width
, gRC_Height
: Word;
252 gRC_FullScreen
, gRC_Maximized
: Boolean;
253 gLanguageChange
: Boolean = False;
254 gDebugMode
: Boolean = False;
255 g_debug_Sounds
: Boolean = False;
256 g_debug_Frames
: Boolean = False;
257 g_debug_WinMsgs
: Boolean = False;
258 g_debug_MonsterOff
: Boolean = False;
259 g_debug_BotAIOff
: Byte = 0;
260 g_debug_HealthBar
: Boolean = False;
261 g_Debug_Player
: Boolean = False;
262 gCoopMonstersKilled
: Word = 0;
263 gCoopSecretsFound
: Word = 0;
264 gCoopTotalMonstersKilled
: Word = 0;
265 gCoopTotalSecretsFound
: Word = 0;
266 gCoopTotalMonsters
: Word = 0;
267 gCoopTotalSecrets
: Word = 0;
268 gStatsOff
: Boolean = False;
269 gStatsPressed
: Boolean = False;
270 gExitByTrigger
: Boolean = False;
271 gNextMap
: String = '';
272 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
273 gLMSRespawnTime
: Cardinal = 0;
274 gLMSSoftSpawn
: Boolean = False;
275 gMissionFailed
: Boolean = False;
276 gVoteInProgress
: Boolean = False;
277 gVotePassed
: Boolean = False;
278 gVoteCommand
: string = '';
279 gVoteTimer
: Cardinal = 0;
280 gVoteCmdTimer
: Cardinal = 0;
281 gVoteCount
: Integer = 0;
282 gVoteTimeout
: Cardinal = 30;
283 gVoted
: Boolean = False;
284 gVotesEnabled
: Boolean = True;
285 gEvents
: Array of TGameEvent
;
286 gDelayedEvents
: Array of TDelayedEvent
;
288 P1MoveButton
: Byte = 0;
289 P2MoveButton
: Byte = 0;
294 g_textures
, g_main
, g_window
, g_menu
,
295 e_input
, e_log
, g_console
, g_items
, g_map
,
296 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
297 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
298 BinEditor
, g_language
, g_net
, SDL
,
299 ENet
, e_fixedbuffer
, g_netmsg
, g_netmaster
, GL
, GLExt
,
303 TEndCustomGameStat
= record
304 PlayerStat
: TPlayerStatArray
;
308 Map
, MapName
: String;
311 TEndSingleGameStat
= record
312 PlayerStat
: Array [0..1] of record
318 TotalSecrets
: Integer;
321 TLoadingStat
= record
325 Msgs
: Array of String;
329 TParamStrValue
= record
334 TParamStrValues
= Array of TParamStrValue
;
337 INTER_ACTION_TEXT
= 1;
338 INTER_ACTION_PIC
= 2;
339 INTER_ACTION_MUSIC
= 3;
343 FPSCounter
, UPSCounter
: Word;
344 FPSTime
, UPSTime
: LongWord;
345 DataLoaded
: Boolean = False;
346 LastScreenShot
: Int64;
347 IsDrawStat
: Boolean = False;
348 CustomStat
: TEndCustomGameStat
;
349 SingleStat
: TEndSingleGameStat
;
350 LoadingStat
: TLoadingStat
;
351 EndingGameCounter
: Byte = 0;
354 MapList
: SArray
= nil;
355 MapIndex
: Integer = -1;
361 text: Array of ShortString;
362 anim
: Array of ShortString;
363 pic
: Array of ShortString;
364 mus
: Array of ShortString;
366 triggers
: Array of record
368 actions
: Array of record
369 action
, p1
, p2
: Integer;
372 cur_trigger
: Integer;
385 function Compare(a
, b
: TPlayerStat
): Integer;
387 if a
.Spectator
then Result
:= 1
388 else if b
.Spectator
then Result
:= -1
389 else if a
.Frags
< b
.Frags
then Result
:= 1
390 else if a
.Frags
> b
.Frags
then Result
:= -1
391 else if a
.Deaths
< b
.Deaths
then Result
:= -1
392 else if a
.Deaths
> b
.Deaths
then Result
:= 1
393 else if a
.Kills
< b
.Kills
then Result
:= -1
397 procedure SortGameStat(var stat
: TPlayerStatArray
);
402 if stat
= nil then Exit
;
404 for I
:= High(stat
) downto Low(stat
) do
405 for J
:= Low(stat
) to High(stat
) - 1 do
406 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
409 stat
[J
] := stat
[J
+ 1];
414 function g_Game_ModeToText(Mode
: Byte): string;
418 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
419 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
420 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
421 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
422 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
426 function g_Game_TextToMode(Mode
: string): Byte;
429 Mode
:= UpperCase(Mode
);
430 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
435 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
440 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
445 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
450 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
457 function g_Game_IsNet(): Boolean;
459 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
462 function g_Game_IsServer(): Boolean;
464 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
467 function g_Game_IsClient(): Boolean;
469 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
472 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
479 Result
.name
:= ExtractFileName(WAD
);
480 Result
.description
:= '';
483 w
:= TWADFile
.Create();
486 if not w
.GetResource('', 'INTERSCRIPT', p
, len
) then
492 cfg
:= TConfig
.CreateMem(p
, len
);
493 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
494 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
495 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
496 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
502 procedure g_Game_FreeWAD();
506 for a
:= 0 to High(MegaWAD
.res
.pic
) do
507 if MegaWAD
.res
.pic
[a
] <> '' then
508 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
510 for a
:= 0 to High(MegaWAD
.res
.mus
) do
511 if MegaWAD
.res
.mus
[a
] <> '' then
512 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
514 MegaWAD
.res
.pic
:= nil;
515 MegaWAD
.res
.text := nil;
516 MegaWAD
.res
.anim
:= nil;
517 MegaWAD
.res
.mus
:= nil;
518 MegaWAD
.triggers
:= nil;
520 g_Texture_Delete('TEXTURE_endpic');
521 g_Sound_Delete('MUSIC_endmus');
523 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
524 gGameSettings
.WAD
:= '';
527 procedure g_Game_LoadWAD(WAD
: string);
536 gGameSettings
.WAD
:= WAD
;
537 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
540 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
542 w
:= TWADFile
.Create();
543 w
.ReadFile(MapsDir
+ WAD
);
545 if not w
.GetResource('', 'INTERSCRIPT', p
, len
) then
551 cfg
:= TConfig
.CreateMem(p
, len
);
556 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
557 if s = '' then Break;
560 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
561 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
563 g_Texture_CreateWADEx(s, s);
569 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
570 if s = '' then Break;
573 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
574 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
576 g_Music_CreateWADEx(s, s);
579 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
580 if MegaWAD
.endpic
<> '' then
582 g_ProcessResourceStr(MegaWAD
.endpic
, @s
, nil, nil);
583 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
584 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
586 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
587 if MegaWAD
.endmus
<> '' then
589 g_ProcessResourceStr(MegaWAD
.endmus
, @s
, nil, nil);
590 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
591 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
599 {procedure start_trigger(t: string);
603 function next_trigger(): Boolean;
607 procedure DisableCheats();
613 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
614 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
615 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
616 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
619 procedure g_Game_ExecuteEvent(Name
: String);
625 if gEvents
= nil then
627 for a
:= 0 to High(gEvents
) do
628 if gEvents
[a
].Name
= Name
then
630 if gEvents
[a
].Command
<> '' then
631 g_Console_Process(gEvents
[a
].Command
, True);
636 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
641 if gDelayedEvents
<> nil then
642 for a
:= 0 to High(gDelayedEvents
) do
643 if not gDelayedEvents
[a
].Pending
then
650 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
651 n
:= High(gDelayedEvents
);
653 gDelayedEvents
[n
].Pending
:= True;
654 gDelayedEvents
[n
].DEType
:= DEType
;
655 gDelayedEvents
[n
].DENum
:= Num
;
656 gDelayedEvents
[n
].DEStr
:= Str
;
657 if DEType
= DE_GLOBEVENT
then
658 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
660 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
667 FileName
, SectionName
, ResName
: string;
669 if g_Game_IsNet
and g_Game_IsServer
then
670 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
676 g_Game_StopAllSounds(False);
681 EndingGameCounter
:= 0;
682 g_ActiveWindow
:= nil;
684 gLMSRespawn
:= LMS_RESPAWN_NONE
;
685 gLMSRespawnTime
:= 0;
688 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
693 begin // Ýòî áûë òåñò
697 begin // Âûõîä â ãëàâíîå ìåíþ
698 gMusic
.SetByName('MUSIC_MENU');
700 if gState
<> STATE_SLIST
then
702 g_GUI_ShowWindow('MainMenu');
703 gState
:= STATE_MENU
;
706 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
707 slReturnPressed
:= True;
708 if g_Net_Slist_Fetch(slCurrent
) then
710 if slCurrent
= nil then
711 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
714 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
717 g_Game_ExecuteEvent('ongameend');
721 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
723 if not g_Game_IsClient
then g_Game_Restart();
726 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
728 // Ñòàòèñòèêà Ñâîåé èãðû:
729 g_ProcessResourceStr(gMapInfo
.Map
, FileName
, SectionName
, ResName
);
731 CustomStat
.GameTime
:= gTime
;
732 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+ResName
;
733 CustomStat
.MapName
:= gMapInfo
.Name
;
734 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
735 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
736 CustomStat
.TeamStat
:= gTeamStat
;
738 CustomStat
.PlayerStat
:= nil;
740 // Ñòàòèñòèêà èãðîêîâ:
741 if gPlayers
<> nil then
743 for a
:= 0 to High(gPlayers
) do
744 if gPlayers
[a
] <> nil then
746 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
747 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
749 Name
:= gPlayers
[a
].Name
;
750 Frags
:= gPlayers
[a
].Frags
;
751 Deaths
:= gPlayers
[a
].Death
;
752 Kills
:= gPlayers
[a
].Kills
;
753 Team
:= gPlayers
[a
].Team
;
754 Color
:= gPlayers
[a
].Model
.Color
;
755 Spectator
:= gPlayers
[a
].FSpectator
;
759 SortGameStat(CustomStat
.PlayerStat
);
762 g_Game_ExecuteEvent('onmapend');
765 EndingGameCounter
:= 255;
766 gState
:= STATE_FOLD
;
768 if gDefInterTime
< 0 then
769 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
771 gInterEndTime
:= gDefInterTime
* 1000;
774 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
776 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
777 SingleStat
.GameTime
:= gTime
;
778 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
779 SingleStat
.TotalSecrets
:= gSecretsCount
;
780 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
781 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
782 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
783 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
784 if SingleStat
.TwoPlayers
then
786 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
787 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
790 g_Game_ExecuteEvent('onmapend');
793 if gNextMap
<> '' then
795 gMusic
.SetByName('MUSIC_INTERMUS');
797 gState
:= STATE_INTERSINGLE
;
799 g_Game_ExecuteEvent('oninter');
801 else // Áîëüøå íåò êàðò
804 EndingGameCounter
:= 255;
805 gState
:= STATE_FOLD
;
810 // Îêîí÷àíèå îáðàáîòàíî:
811 if gExit
<> EXIT_QUIT
then
815 procedure DrawStat();
817 pc
, x
, y
, w
, h
: Integer;
818 w1
, w2
, w3
, w4
: Integer;
820 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
823 stat
: TPlayerStatArray
;
830 pc
:= g_Player_GetCount
;
831 e_TextureFontGetSize(gStdFont
, cw
, ch
);
833 w
:= gScreenWidth
-(gScreenWidth
div 5);
834 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
837 h
:= 40+ch
*5+(ch
+8)*pc
;
838 x
:= (gScreenWidth
div 2)-(w
div 2);
839 y
:= (gScreenHeight
div 2)-(h
div 2);
841 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
842 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
844 g_ProcessResourceStr(gMapInfo
.Map
, @wad
, nil, @map
);
845 wad
:= ExtractFileName(wad
);
846 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
848 case gGameSettings
.GameMode
of
851 if gGameSettings
.MaxLives
= 0 then
854 s1
:= _lc
[I_GAME_LMS
];
855 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
856 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
861 if gGameSettings
.MaxLives
= 0 then
862 s1
:= _lc
[I_GAME_TDM
]
864 s1
:= _lc
[I_GAME_TLMS
];
865 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
866 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
871 s1
:= _lc
[I_GAME_CTF
];
872 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
873 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
878 if gGameSettings
.MaxLives
= 0 then
879 s1
:= _lc
[I_GAME_COOP
]
881 s1
:= _lc
[I_GAME_SURV
];
882 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
883 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
894 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
896 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
898 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
900 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
901 gStdFont
, 200, 200, 200, 1);
903 if NetMode
= NET_SERVER
then
904 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
906 if NetMode
= NET_CLIENT
then
907 e_TextureFontPrintEx(x
+8, y
+ 8,
908 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
912 stat
:= g_Player_GetStats();
915 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
916 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
918 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
920 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
924 for a
:= TEAM_RED
to TEAM_BLUE
do
928 s1
:= _lc
[I_GAME_TEAM_RED
];
935 s1
:= _lc
[I_GAME_TEAM_BLUE
];
941 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
942 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
943 gStdFont
, r
, g
, b
, 1);
945 _y
:= _y
+ch
+(ch
div 4);
946 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
949 for aa
:= 0 to High(stat
) do
950 if stat
[aa
].Team
= a
then
966 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
968 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
970 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
972 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
979 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
982 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
983 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
984 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
985 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
988 for aa
:= 0 to High(stat
) do
1002 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1003 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1005 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1007 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1009 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1011 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1017 procedure g_Game_Init();
1023 gTempDelete
:= False;
1025 sfsGCDisable(); // temporary disable removing of temporary volumes
1028 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1029 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1030 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1031 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1033 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1034 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1035 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1037 g_Game_ClearLoading();
1038 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1039 g_Game_SetLoadingText('', 0, False);
1041 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1044 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1045 g_PlayerModel_LoadData();
1047 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1049 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1050 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1051 until FindNext(SR
) <> 0;
1054 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1056 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1057 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1058 until FindNext(SR
) <> 0;
1061 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1063 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1064 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1065 until FindNext(SR
) <> 0;
1071 LastScreenShot
:= 0;
1073 {e_MouseInfo.Accel := 1.0;}
1075 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1078 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1079 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1080 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1081 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1082 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1084 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1087 gMusic
:= TMusic
.Create();
1088 gMusic
.SetByName('MUSIC_MENU');
1091 gGameSettings
.WarmupTime
:= 30;
1093 gState
:= STATE_MENU
;
1095 SetLength(gEvents
, 6);
1096 gEvents
[0].Name
:= 'ongamestart';
1097 gEvents
[1].Name
:= 'ongameend';
1098 gEvents
[2].Name
:= 'onmapstart';
1099 gEvents
[3].Name
:= 'onmapend';
1100 gEvents
[4].Name
:= 'oninter';
1101 gEvents
[5].Name
:= 'onwadend';
1103 sfsGCEnable(); // enable releasing unused volumes
1107 procedure g_Game_Free();
1109 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1110 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1114 g_Player_RemoveAllCorpses();
1116 gGameSettings
.GameType
:= GT_NONE
;
1117 if gGameSettings
.GameMode
= GM_SINGLE
then
1118 gGameSettings
.GameMode
:= GM_DM
;
1119 gSwitchGameMode
:= gGameSettings
.GameMode
;
1122 gExitByTrigger
:= False;
1125 function IsActivePlayer(p
: TPlayer
): Boolean;
1130 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1133 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1140 if gPlayers
= nil then
1142 for a
:= Low(gPlayers
) to High(gPlayers
) do
1143 if IsActivePlayer(gPlayers
[a
]) then
1145 if gPlayers
[a
].UID
<> ID
then
1147 Result
:= gPlayers
[a
];
1152 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1158 if gPlayers
= nil then
1162 for a
:= Low(gPlayers
) to High(gPlayers
) do
1163 if IsActivePlayer(gPlayers
[a
]) then
1165 SetLength(ids
, Length(ids
) + 1);
1166 ids
[High(ids
)] := gPlayers
[a
].UID
;
1167 if gPlayers
[a
].UID
= Skip
then
1170 if Length(ids
) = 0 then
1175 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1178 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1184 if gPlayers
= nil then
1188 for a
:= Low(gPlayers
) to High(gPlayers
) do
1189 if IsActivePlayer(gPlayers
[a
]) then
1191 SetLength(ids
, Length(ids
) + 1);
1192 ids
[High(ids
)] := gPlayers
[a
].UID
;
1193 if gPlayers
[a
].UID
= Skip
then
1196 if Length(ids
) = 0 then
1199 Result
:= ids
[Length(ids
) - 1]
1201 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1204 procedure g_Game_Update();
1206 Msg
: g_gui
.TMessage
;
1212 // Ïîðà âûêëþ÷àòü èãðó:
1213 if gExit
= EXIT_QUIT
then
1215 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1219 if gExit
= EXIT_QUIT
then
1223 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1226 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1229 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1231 gExit
:= EXIT_SIMPLE
;
1237 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1238 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1239 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1240 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1242 if g_Game_IsNet
and g_Game_IsServer
then
1244 gInterTime
:= gInterTime
+ GAME_TICK
;
1245 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1246 if a
<> gServInterTime
then
1248 gServInterTime
:= a
;
1249 MH_SEND_TimeSync(gServInterTime
);
1253 if (not g_Game_IsClient
) and
1256 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1257 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1258 and (g_ActiveWindow
= nil)
1260 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1263 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1264 g_Game_StopAllSounds(True);
1266 if gMapOnce
then // Ýòî áûë òåñò
1267 gExit
:= EXIT_SIMPLE
1269 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1270 g_Game_ChangeMap(gNextMap
)
1271 else // Ñëåäóþùåé êàðòû íåò
1273 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1275 // Âûõîä â ãëàâíîå ìåíþ:
1277 g_GUI_ShowWindow('MainMenu');
1278 gMusic
.SetByName('MUSIC_MENU');
1280 gState
:= STATE_MENU
;
1283 // Ôèíàëüíàÿ êàðòèíêà:
1284 g_Game_ExecuteEvent('onwadend');
1286 if not gMusic
.SetByName('MUSIC_endmus') then
1287 gMusic
.SetByName('MUSIC_STDENDMUS');
1289 gState
:= STATE_ENDPIC
;
1291 g_Game_ExecuteEvent('ongameend');
1297 if gState
= STATE_INTERTEXT
then
1298 if InterText
.counter
> 0 then
1299 InterText
.counter
:= InterText
.counter
- 1;
1302 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1304 if EndingGameCounter
= 0 then
1306 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1307 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1309 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1311 g_Game_ExecuteEvent('onwadend');
1312 if not gMusic
.SetByName('MUSIC_endmus') then
1313 gMusic
.SetByName('MUSIC_STDENDMUS');
1316 gMusic
.SetByName('MUSIC_ROUNDMUS');
1319 gState
:= STATE_INTERCUSTOM
;
1321 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1323 gMusic
.SetByName('MUSIC_INTERMUS');
1325 gState
:= STATE_INTERSINGLE
;
1327 g_Game_ExecuteEvent('oninter');
1330 DecMin(EndingGameCounter
, 6, 0);
1333 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1335 if gMapOnce
then // Ýòî áûë òåñò
1337 gExit
:= EXIT_SIMPLE
;
1343 g_Serverlist_Control(slCurrent
);
1346 if g_Game_IsNet
then
1347 if not gConsoleShow
then
1348 if not gChatShow
then
1350 if g_ActiveWindow
= nil then
1352 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1353 g_Console_Chat_Switch(False)
1354 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1355 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1356 g_Console_Chat_Switch(True);
1359 if not gChatEnter
then
1360 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1361 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1364 // Ñòàòèñòèêà ïî Tab:
1366 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1367 (gGameSettings
.GameType
<> GT_SINGLE
) and
1368 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1371 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1373 // Âðåìÿ += 28 ìèëëèñåêóíä:
1374 gTime
:= gTime
+ GAME_TICK
;
1376 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1377 if MessageTime
= 0 then
1379 if MessageTime
> 0 then
1380 MessageTime
:= MessageTime
- 1;
1382 if (g_Game_IsServer
) then
1384 // Áûë çàäàí ëèìèò âðåìåíè:
1385 if (gGameSettings
.TimeLimit
> 0) then
1386 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1387 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1392 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1393 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1394 g_Game_RestartRound(gLMSSoftSpawn
);
1396 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1397 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1399 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1401 g_Console_Process(gVoteCommand
);
1403 gVotePassed
:= False;
1406 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1407 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1408 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1409 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1410 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1412 // Áûë çàäàí ëèìèò ïîáåä:
1413 if (gGameSettings
.GoalLimit
> 0) then
1417 if gGameSettings
.GameMode
= GM_DM
then
1418 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1419 for i
:= 0 to High(gPlayers
) do
1420 if gPlayers
[i
] <> nil then
1421 if gPlayers
[i
].Frags
> b
then
1422 b
:= gPlayers
[i
].Frags
;
1425 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1426 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1427 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1430 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1431 if b
>= gGameSettings
.GoalLimit
then
1438 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1439 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1440 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1441 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1444 if gPlayer1
<> nil then
1445 with gGameControls
.P1Control
do
1447 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1448 P1MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1450 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1451 P1MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1453 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1454 P1MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1456 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1457 if P1MoveButton
= 1 then
1458 gPlayer1
.PressKey(KEY_LEFT
)
1460 if P1MoveButton
= 2 then
1461 gPlayer1
.PressKey(KEY_RIGHT
);
1463 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1464 if (P1MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1465 gPlayer1
.SetDirection(D_LEFT
)
1467 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1468 if (P1MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1469 gPlayer1
.SetDirection(D_RIGHT
)
1471 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1472 if P1MoveButton
<> 0 then
1473 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
1475 // Îñòàëüíûå êëàâèøè:
1476 if e_KeyPressed(KeyJump
) then gPlayer1
.PressKey(KEY_JUMP
);
1477 if e_KeyPressed(KeyUp
) then gPlayer1
.PressKey(KEY_UP
);
1478 if e_KeyPressed(KeyDown
) then gPlayer1
.PressKey(KEY_DOWN
);
1479 if e_KeyPressed(KeyFire
) then gPlayer1
.PressKey(KEY_FIRE
);
1480 if e_KeyPressed(KeyNextWeapon
) then gPlayer1
.PressKey(KEY_NEXTWEAPON
);
1481 if e_KeyPressed(KeyPrevWeapon
) then gPlayer1
.PressKey(KEY_PREVWEAPON
);
1482 if e_KeyPressed(KeyOpen
) then gPlayer1
.PressKey(KEY_OPEN
);
1485 if gPlayer2
<> nil then
1486 with gGameControls
.P2Control
do
1488 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
1489 P2MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1491 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
1492 P2MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1494 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
1495 P2MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1497 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1498 if P2MoveButton
= 1 then
1499 gPlayer2
.PressKey(KEY_LEFT
, 1000)
1501 if P2MoveButton
= 2 then
1502 gPlayer2
.PressKey(KEY_RIGHT
, 1000);
1504 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1505 if (P2MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
1506 gPlayer2
.SetDirection(D_LEFT
)
1508 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1509 if (P2MoveButton
= 1) and e_KeyPressed(KeyRight
) then
1510 gPlayer2
.SetDirection(D_RIGHT
)
1512 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1513 if P2MoveButton
<> 0 then
1514 gPlayer2
.SetDirection(TDirection(P2MoveButton
-1));
1516 // Îñòàëüíûå êëàâèøè:
1517 if e_KeyPressed(KeyJump
) then gPlayer2
.PressKey(KEY_JUMP
, 1000);
1518 if e_KeyPressed(KeyUp
) then gPlayer2
.PressKey(KEY_UP
, 1000);
1519 if e_KeyPressed(KeyDown
) then gPlayer2
.PressKey(KEY_DOWN
, 1000);
1520 if e_KeyPressed(KeyFire
) then gPlayer2
.PressKey(KEY_FIRE
);
1521 if e_KeyPressed(KeyNextWeapon
) then gPlayer2
.PressKey(KEY_NEXTWEAPON
);
1522 if e_KeyPressed(KeyPrevWeapon
) then gPlayer2
.PressKey(KEY_PREVWEAPON
);
1523 if e_KeyPressed(KeyOpen
) then gPlayer2
.PressKey(KEY_OPEN
);
1525 end // if not console
1527 if g_Game_IsNet
and (gPlayer1
<> nil) then
1528 gPlayer1
.PressKey(KEY_CHAT
, 10000);
1533 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1534 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1536 if not gSpectKeyPress
then
1538 if e_KeyPressed(gGameControls
.P1Control
.KeyJump
) then
1540 // switch spect mode
1542 SPECT_NONE
: ; // not spectator
1544 SPECT_MAPVIEW
: Inc(gSpectMode
);
1545 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1547 gSpectKeyPress
:= True;
1549 if gSpectMode
= SPECT_MAPVIEW
then
1551 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1552 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1553 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1554 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1555 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1556 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1557 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1558 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1559 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1562 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1563 gSpectKeyPress
:= True;
1565 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1568 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1569 gSpectKeyPress
:= True;
1572 if gSpectMode
= SPECT_PLAYERS
then
1574 if e_KeyPressed(gGameControls
.P1Control
.KeyUp
) then
1577 gSpectViewTwo
:= True;
1578 gSpectKeyPress
:= True;
1580 if e_KeyPressed(gGameControls
.P1Control
.KeyDown
) then
1582 // remove second view
1583 gSpectViewTwo
:= False;
1584 gSpectKeyPress
:= True;
1586 if e_KeyPressed(gGameControls
.P1Control
.KeyLeft
) then
1588 // prev player (view 1)
1589 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1590 gSpectKeyPress
:= True;
1592 if e_KeyPressed(gGameControls
.P1Control
.KeyRight
) then
1594 // next player (view 1)
1595 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1596 gSpectKeyPress
:= True;
1598 if e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
) then
1600 // prev player (view 2)
1601 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1602 gSpectKeyPress
:= True;
1604 if e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
) then
1606 // next player (view 2)
1607 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1608 gSpectKeyPress
:= True;
1613 if (not e_KeyPressed(gGameControls
.P1Control
.KeyJump
)) and
1614 (not e_KeyPressed(gGameControls
.P1Control
.KeyLeft
)) and
1615 (not e_KeyPressed(gGameControls
.P1Control
.KeyRight
)) and
1616 (not e_KeyPressed(gGameControls
.P1Control
.KeyUp
)) and
1617 (not e_KeyPressed(gGameControls
.P1Control
.KeyDown
)) and
1618 (not e_KeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
)) and
1619 (not e_KeyPressed(gGameControls
.P1Control
.KeyNextWeapon
)) then
1620 gSpectKeyPress
:= False;
1623 // Îáíîâëÿåì âñå îñòàëüíîå:
1626 g_Triggers_Update();
1628 g_Monsters_Update();
1630 g_Player_UpdateAll();
1631 g_Player_UpdatePhysicalObjects();
1632 if gGameSettings
.GameType
= GT_SERVER
then
1633 if Length(gMonstersSpawned
) > 0 then
1635 for I
:= 0 to High(gMonstersSpawned
) do
1636 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1637 SetLength(gMonstersSpawned
, 0);
1640 if (gSoundTriggerTime
> 8) then
1642 g_Game_UpdateTriggerSounds();
1643 gSoundTriggerTime
:= 0;
1646 Inc(gSoundTriggerTime
);
1648 if (NetMode
= NET_SERVER
) then
1650 Inc(NetTimeToUpdate
);
1651 Inc(NetTimeToReliable
);
1652 if NetTimeToReliable
>= NetRelupdRate
then
1654 for I
:= 0 to High(gPlayers
) do
1655 if gPlayers
[I
] <> nil then
1656 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1658 if gMonsters
<> nil then
1659 for I
:= 0 to High(gMonsters
) do
1660 if gMonsters
[I
] <> nil then
1662 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1664 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1665 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1668 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1669 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1670 (gMonsters
[I
].GameVelX
<> 0) or
1671 (gMonsters
[I
].GameVelY
<> 0) then
1672 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1675 NetTimeToReliable
:= 0;
1676 NetTimeToUpdate
:= NetUpdateRate
;
1678 else if NetTimeToUpdate
>= NetUpdateRate
then
1680 if gPlayers
<> nil then
1681 for I
:= 0 to High(gPlayers
) do
1682 if gPlayers
[I
] <> nil then
1683 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1685 if gMonsters
<> nil then
1686 for I
:= 0 to High(gMonsters
) do
1687 if gMonsters
[I
] <> nil then
1689 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1691 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1692 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1695 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1696 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1697 (gMonsters
[I
].GameVelX
<> 0) or
1698 (gMonsters
[I
].GameVelY
<> 0) then
1699 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1702 NetTimeToUpdate
:= 0;
1705 if NetUseMaster
then
1706 if gTime
>= NetTimeToMaster
then
1708 if (NetMHost
= nil) or (NetMPeer
= nil) then
1709 if not g_Net_Slist_Connect
then
1710 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1713 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1717 if NetMode
= NET_CLIENT
then
1718 MC_SEND_PlayerPos();
1719 end; // if gameOn ...
1721 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1722 if g_ActiveWindow
<> nil then
1724 w
:= e_GetFirstKeyPressed();
1726 if (w
<> IK_INVALID
) then
1728 Msg
.Msg
:= MESSAGE_DIKEY
;
1730 g_ActiveWindow
.OnMessage(Msg
);
1733 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1734 if g_ActiveWindow
<> nil then
1735 g_ActiveWindow
.Update();
1737 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1738 if gResolutionChange
then
1740 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1741 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1742 gResolutionChange
:= False;
1745 // Íóæíî ñìåíèòü ÿçûê:
1746 if gLanguageChange
then
1748 //e_WriteLog('Read language file', MSG_NOTIFY);
1749 //g_Language_Load(DataDir + gLanguage + '.txt');
1750 g_Language_Set(gLanguage
);
1752 gLanguageChange
:= False;
1756 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1757 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1758 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1761 LastScreenShot
:= GetTimer();
1764 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1765 if e_KeyPressed(IK_F10
) and
1767 (not gConsoleShow
) and
1768 (g_ActiveWindow
= nil) then
1773 Time
:= GetTimer() {div 1000};
1775 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1776 if gDelayedEvents
<> nil then
1777 for a
:= 0 to High(gDelayedEvents
) do
1778 if gDelayedEvents
[a
].Pending
and
1780 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1781 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1784 case gDelayedEvents
[a
].DEType
of
1786 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1789 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1793 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1794 if g_Game_IsNet
and g_Game_IsServer
then
1795 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1798 gDelayedEvents
[a
].Pending
:= False;
1801 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1802 UPSCounter
:= UPSCounter
+ 1;
1803 if Time
- UPSTime
>= 1000 then
1811 procedure g_Game_LoadData();
1813 if DataLoaded
then Exit
;
1815 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1817 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1818 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1819 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1820 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1821 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1822 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1823 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1824 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1825 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1826 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1827 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1828 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1829 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1830 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1831 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1832 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1833 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1834 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1835 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1836 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1837 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1838 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1839 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1840 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1841 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1842 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1843 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1844 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1845 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1846 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1847 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1848 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1849 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1850 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1852 goodsnd
[0] := TPlayableSound
.Create();
1853 goodsnd
[1] := TPlayableSound
.Create();
1854 goodsnd
[2] := TPlayableSound
.Create();
1855 goodsnd
[3] := TPlayableSound
.Create();
1857 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1858 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1859 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1860 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1862 killsnd
[0] := TPlayableSound
.Create();
1863 killsnd
[1] := TPlayableSound
.Create();
1864 killsnd
[2] := TPlayableSound
.Create();
1865 killsnd
[3] := TPlayableSound
.Create();
1867 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1868 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1869 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1870 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1872 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
1875 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1876 g_Weapon_LoadData();
1878 g_Monsters_LoadData();
1883 procedure g_Game_FreeData();
1885 if not DataLoaded
then Exit
;
1888 g_Weapon_FreeData();
1889 g_Monsters_FreeData();
1891 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
1893 g_Texture_Delete('NOTEXTURE');
1894 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1895 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1896 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1897 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1898 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1899 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1900 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1901 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1902 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1903 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1904 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1905 g_Frames_DeleteByName('FRAMES_TELEPORT');
1906 g_Sound_Delete('SOUND_GAME_TELEPORT');
1907 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1908 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1909 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1910 g_Sound_Delete('SOUND_GAME_BULK1');
1911 g_Sound_Delete('SOUND_GAME_BULK2');
1912 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1913 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1914 g_Sound_Delete('SOUND_GAME_SWITCH1');
1915 g_Sound_Delete('SOUND_GAME_SWITCH0');
1922 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1923 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1924 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1925 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1932 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1933 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1934 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1935 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1937 DataLoaded
:= False;
1940 procedure DrawCustomStat();
1946 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
1947 s1
, s2
, topstr
: String;
1949 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
1952 if e_KeyPressed(IK_TAB
) then
1954 if not gStatsPressed
then
1956 gStatsOff
:= not gStatsOff
;
1957 gStatsPressed
:= True;
1961 gStatsPressed
:= False;
1965 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
1966 w
:= (Length(s1
) * ww2
) div 2;
1967 x
:= gScreenWidth
div 2 - w
;
1969 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
1973 if (gGameSettings
.GameMode
= GM_COOP
) then
1975 if gMissionFailed
then
1976 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
1978 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
1981 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
1983 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
1984 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
1986 if g_Game_IsNet
then
1988 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
1989 if not gChatShow
then
1990 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
1991 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
1994 if g_Game_IsClient
then
1995 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
1997 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
1998 if not gChatShow
then
1999 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2000 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2005 w
:= gScreenWidth
-x
*2;
2011 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2012 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2014 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2016 case CustomStat
.GameMode
of
2019 if gGameSettings
.MaxLives
= 0 then
2020 s1
:= _lc
[I_GAME_DM
]
2022 s1
:= _lc
[I_GAME_LMS
];
2026 if gGameSettings
.MaxLives
= 0 then
2027 s1
:= _lc
[I_GAME_TDM
]
2029 s1
:= _lc
[I_GAME_TLMS
];
2031 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2034 if gGameSettings
.MaxLives
= 0 then
2035 s1
:= _lc
[I_GAME_COOP
]
2037 s1
:= _lc
[I_GAME_SURV
];
2043 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2047 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2048 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2051 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2052 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2053 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2054 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2056 pc
:= Length(CustomStat
.PlayerStat
);
2057 if pc
= 0 then Exit
;
2059 if CustomStat
.GameMode
= GM_COOP
then
2061 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2063 s2
:= _lc
[I_GAME_MONSTERS
];
2064 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2065 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2067 s2
:= _lc
[I_GAME_SECRETS
];
2068 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2069 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2072 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2074 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2075 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2076 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2078 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2079 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2080 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2084 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2089 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2090 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2091 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2093 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2096 for t
:= TEAM_RED
to TEAM_BLUE
do
2098 if t
= TEAM_RED
then
2100 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2101 gStdFont
, 255, 0, 0, 1);
2102 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2103 gStdFont
, 255, 0, 0, 1);
2110 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2111 gStdFont
, 0, 0, 255, 1);
2112 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2113 gStdFont
, 0, 0, 255, 1);
2119 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2122 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2123 if CustomStat
.PlayerStat
[p
].Team
= t
then
2124 with CustomStat
.PlayerStat
[p
] do
2138 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2139 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2140 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2147 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2150 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2151 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2152 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2155 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2156 with CustomStat
.PlayerStat
[p
] do
2158 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2165 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2166 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2167 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2173 procedure DrawSingleStat();
2175 tm
, key_x
, val_x
, y
: Integer;
2179 procedure player_stat(n
: Integer);
2185 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2186 s2
:= Format(' %d', [gTotalMonsters
]);
2188 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2189 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2190 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2191 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2193 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2194 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2196 // "Kills-per-minute: ##.#":
2197 s1
:= _lc
[I_MENU_INTER_KPM
];
2199 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2201 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2202 s2
:= Format(' %.1f', [kpm
]);
2204 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2205 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2207 // "Secrets found: # / #":
2208 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2209 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2211 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2212 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2213 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2214 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2216 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2217 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2221 // "Level Complete":
2222 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2223 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2225 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2226 s1
:= _lc
[I_MENU_INTER_KPM
];
2227 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2230 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2232 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2233 val_x
:= key_x
+ w1
;
2236 tm
:= SingleStat
.GameTime
div 1000;
2237 s1
:= _lc
[I_MENU_INTER_TIME
];
2238 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2240 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2241 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2243 if SingleStat
.TwoPlayers
then
2246 s1
:= _lc
[I_MENU_PLAYER_1
];
2247 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2248 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2250 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2255 s1
:= _lc
[I_MENU_PLAYER_2
];
2256 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2257 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2259 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2265 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2271 procedure DrawLoadingStat();
2277 if Length(LoadingStat
.Msgs
) = 0 then
2280 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2281 yy
:= (gScreenHeight
div 3);
2282 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2283 xx
:= (gScreenWidth
div 3);
2286 for i
:= 0 to NextMsg
-1 do
2288 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2289 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2293 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2294 yy
:= yy
+ LOADING_INTERLINE
;
2298 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2300 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2302 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2303 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2306 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2307 ScaleSz
:= 16 div Scale
;
2308 // Ðàçìåðû ìèíè-êàðòû:
2309 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2310 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2312 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2314 if gWalls
<> nil then
2317 for a
:= 0 to High(gWalls
) do
2319 if PanelType
<> 0 then
2321 // Ëåâûé âåðõíèé óãîë:
2322 aX
:= X
div ScaleSz
;
2323 aY
:= Y
div ScaleSz
;
2325 aX2
:= max(Width
div ScaleSz
, 1);
2326 aY2
:= max(Height
div ScaleSz
, 1);
2327 // Ïðàâûé íèæíèé óãîë:
2328 aX2
:= aX
+ aX2
- 1;
2329 aY2
:= aY
+ aY2
- 1;
2332 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2333 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2334 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2338 if gSteps
<> nil then
2341 for a
:= 0 to High(gSteps
) do
2343 if PanelType
<> 0 then
2345 // Ëåâûé âåðõíèé óãîë:
2346 aX
:= X
div ScaleSz
;
2347 aY
:= Y
div ScaleSz
;
2349 aX2
:= max(Width
div ScaleSz
, 1);
2350 aY2
:= max(Height
div ScaleSz
, 1);
2351 // Ïðàâûé íèæíèé óãîë:
2352 aX2
:= aX
+ aX2
- 1;
2353 aY2
:= aY
+ aY2
- 1;
2355 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2358 if gLifts
<> nil then
2361 for a
:= 0 to High(gLifts
) do
2363 if PanelType
<> 0 then
2365 // Ëåâûé âåðõíèé óãîë:
2366 aX
:= X
div ScaleSz
;
2367 aY
:= Y
div ScaleSz
;
2369 aX2
:= max(Width
div ScaleSz
, 1);
2370 aY2
:= max(Height
div ScaleSz
, 1);
2371 // Ïðàâûé íèæíèé óãîë:
2372 aX2
:= aX
+ aX2
- 1;
2373 aY2
:= aY
+ aY2
- 1;
2376 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2377 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2378 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2379 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2383 if gWater
<> nil then
2386 for a
:= 0 to High(gWater
) do
2388 if PanelType
<> 0 then
2390 // Ëåâûé âåðõíèé óãîë:
2391 aX
:= X
div ScaleSz
;
2392 aY
:= Y
div ScaleSz
;
2394 aX2
:= max(Width
div ScaleSz
, 1);
2395 aY2
:= max(Height
div ScaleSz
, 1);
2396 // Ïðàâûé íèæíèé óãîë:
2397 aX2
:= aX
+ aX2
- 1;
2398 aY2
:= aY
+ aY2
- 1;
2400 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2403 if gAcid1
<> nil then
2405 // Ðèñóåì êèñëîòó 1:
2406 for a
:= 0 to High(gAcid1
) do
2408 if PanelType
<> 0 then
2410 // Ëåâûé âåðõíèé óãîë:
2411 aX
:= X
div ScaleSz
;
2412 aY
:= Y
div ScaleSz
;
2414 aX2
:= max(Width
div ScaleSz
, 1);
2415 aY2
:= max(Height
div ScaleSz
, 1);
2416 // Ïðàâûé íèæíèé óãîë:
2417 aX2
:= aX
+ aX2
- 1;
2418 aY2
:= aY
+ aY2
- 1;
2420 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2423 if gAcid2
<> nil then
2425 // Ðèñóåì êèñëîòó 2:
2426 for a
:= 0 to High(gAcid2
) do
2428 if PanelType
<> 0 then
2430 // Ëåâûé âåðõíèé óãîë:
2431 aX
:= X
div ScaleSz
;
2432 aY
:= Y
div ScaleSz
;
2434 aX2
:= max(Width
div ScaleSz
, 1);
2435 aY2
:= max(Height
div ScaleSz
, 1);
2436 // Ïðàâûé íèæíèé óãîë:
2437 aX2
:= aX
+ aX2
- 1;
2438 aY2
:= aY
+ aY2
- 1;
2440 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2443 if gPlayers
<> nil then
2446 for a
:= 0 to High(gPlayers
) do
2447 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2449 // Ëåâûé âåðõíèé óãîë:
2450 aX
:= Obj
.X
div ScaleSz
+ 1;
2451 aY
:= Obj
.Y
div ScaleSz
+ 1;
2453 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2454 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2455 // Ïðàâûé íèæíèé óãîë:
2456 aX2
:= aX
+ aX2
- 1;
2457 aY2
:= aY
+ aY2
- 1;
2459 if gPlayers
[a
] = p
then
2460 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2463 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2464 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2465 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2469 if gMonsters
<> nil then
2472 for a
:= 0 to High(gMonsters
) do
2473 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2475 // Ëåâûé âåðõíèé óãîë:
2476 aX
:= Obj
.X
div ScaleSz
+ 1;
2477 aY
:= Obj
.Y
div ScaleSz
+ 1;
2479 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2480 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2481 // Ïðàâûé íèæíèé óãîë:
2482 aX2
:= aX
+ aX2
- 1;
2483 aY2
:= aY
+ aY2
- 1;
2485 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2491 procedure DrawMapView(x
, y
, w
, h
: Integer);
2497 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2498 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2499 g_Map_DrawBack(-bx
, -by
);
2506 glTranslatef(-x
, -y
, 0);
2508 g_Map_DrawPanels(PANEL_BACK
);
2509 g_Map_DrawPanels(PANEL_STEP
);
2512 g_Player_DrawShells();
2514 g_Player_DrawCorpses();
2515 g_Map_DrawPanels(PANEL_WALL
);
2517 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2520 g_Map_DrawPanels(PANEL_ACID1
);
2521 g_Map_DrawPanels(PANEL_ACID2
);
2522 g_Map_DrawPanels(PANEL_WATER
);
2523 g_Map_DrawPanels(PANEL_FORE
);
2524 if g_debug_HealthBar
then
2526 g_Monsters_DrawHealth();
2527 g_Player_DrawHealth();
2533 procedure DrawPlayer(p
: TPlayer
);
2535 px
, py
, a
, b
, c
, d
: Integer;
2538 if (p
= nil) or (p
.FDummy
) then
2541 g_Map_DrawBack(0, 0);
2550 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2551 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2553 if px
> (gPlayerScreenSize
.X
div 2) then
2554 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2557 if py
> (gPlayerScreenSize
.Y
div 2) then
2558 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2561 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2562 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2563 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2564 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2565 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2567 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2570 if p
.IncCam
<> 0 then
2572 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2574 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2575 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2578 if py
< (gPlayerScreenSize
.Y
div 2) then
2580 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2581 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2584 if p
.IncCam
< 0 then
2585 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2587 p
.IncCam
:= p
.IncCam
+ 1;
2589 if p
.IncCam
> 0 then
2590 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2592 p
.IncCam
:= p
.IncCam
- 1;
2595 if (px
< gPlayerScreenSize
.X
div 2) or
2596 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2599 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2600 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2602 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2604 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2605 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2608 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2609 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2611 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2613 g_Map_DrawBack(-c
, -d
);
2616 sY
:= -(b
+p
.IncCam
);
2617 sWidth
:= gPlayerScreenSize
.X
;
2618 sHeight
:= gPlayerScreenSize
.Y
;
2620 glTranslatef(a
, b
+p
.IncCam
, 0);
2622 g_Map_DrawPanels(PANEL_BACK
);
2623 g_Map_DrawPanels(PANEL_STEP
);
2626 g_Player_DrawShells();
2628 g_Player_DrawCorpses();
2629 g_Map_DrawPanels(PANEL_WALL
);
2631 g_Map_DrawPanels(PANEL_CLOSEDOOR
);
2634 g_Map_DrawPanels(PANEL_ACID1
);
2635 g_Map_DrawPanels(PANEL_ACID2
);
2636 g_Map_DrawPanels(PANEL_WATER
);
2637 g_Map_DrawPanels(PANEL_FORE
);
2638 if g_debug_HealthBar
then
2640 g_Monsters_DrawHealth();
2641 g_Player_DrawHealth();
2644 if p
.FSpectator
then
2645 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2646 p
.GameY
+ PLAYER_RECT_CY
- 4,
2647 'X', gStdFont
, 255, 255, 255, 1, True);
2649 for a := 0 to High(gCollideMap) do
2650 for b := 0 to High(gCollideMap[a]) do
2653 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2655 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2659 1: e_DrawPoint(1, b, a, 200, 200, 200);
2660 2: e_DrawPoint(1, b, a, 64, 64, 255);
2661 3: e_DrawPoint(1, b, a, 255, 0, 255);
2671 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2672 if g_Debug_Player
then
2673 g_Player_DrawDebug(p
);
2677 procedure g_Game_Draw();
2684 plView1
, plView2
: TPlayer
;
2687 if gExit
= EXIT_QUIT
then Exit
;
2689 Time
:= GetTimer() {div 1000};
2690 FPSCounter
:= FPSCounter
+1;
2691 if Time
- FPSTime
>= 1000 then
2698 if gGameOn
or (gState
= STATE_FOLD
) then
2700 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2702 gSpectMode
:= SPECT_NONE
;
2703 if not gRevertPlayers
then
2705 plView1
:= gPlayer1
;
2706 plView2
:= gPlayer2
;
2710 plView1
:= gPlayer2
;
2711 plView2
:= gPlayer1
;
2715 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2717 gSpectMode
:= SPECT_NONE
;
2718 if gPlayer2
= nil then
2721 plView1
:= gPlayer2
;
2730 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2731 gSpectMode
:= SPECT_STATS
;
2733 if gSpectMode
= SPECT_PLAYERS
then
2734 if gPlayers
<> nil then
2736 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2737 if plView1
= nil then
2739 gSpectPID1
:= GetActivePlayerID_Next();
2740 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
2742 if gSpectViewTwo
then
2744 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2745 if plView2
= nil then
2747 gSpectPID2
:= GetActivePlayerID_Next();
2748 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
2753 if gSpectMode
= SPECT_MAPVIEW
then
2755 // Ðåæèì ïðîñìîòðà êàðòû
2757 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2758 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
2759 gHearPoint1
.Active
:= True;
2760 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
2761 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
2762 gHearPoint2
.Active
:= False;
2766 Split
:= (plView1
<> nil) and (plView2
<> nil);
2768 // Òî÷êè ñëóõà èãðîêîâ
2769 if plView1
<> nil then
2771 gHearPoint1
.Active
:= True;
2772 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
2773 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
2775 gHearPoint1
.Active
:= False;
2776 if plView2
<> nil then
2778 gHearPoint2
.Active
:= True;
2779 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
2780 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
2782 gHearPoint2
.Active
:= False;
2784 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2785 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2788 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
2789 if gScreenHeight
mod 2 = 0 then
2790 Dec(gPlayerScreenSize
.Y
);
2793 gPlayerScreenSize
.Y
:= gScreenHeight
;
2796 if gScreenHeight
mod 2 = 0 then
2797 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
2799 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2801 DrawPlayer(plView1
);
2802 gPlayer1ScreenCoord
.X
:= sX
;
2803 gPlayer1ScreenCoord
.Y
:= sY
;
2807 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
2809 DrawPlayer(plView2
);
2810 gPlayer2ScreenCoord
.X
:= sX
;
2811 gPlayer2ScreenCoord
.Y
:= sY
;
2814 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
2817 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
2820 if MessageText
<> '' then
2824 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
2826 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2827 (gScreenHeight
div 2)-(h
div 2), MessageText
)
2829 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2830 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
2833 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
2835 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
2837 // Draw spectator GUI
2840 e_TextureFontGetSize(gStdFont
, ww
, hh
);
2843 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
2845 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
2847 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
2849 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
2850 if gSpectMode
= SPECT_MAPVIEW
then
2852 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
2853 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
2854 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
2855 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
2856 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
2858 if gSpectMode
= SPECT_PLAYERS
then
2860 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
2861 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
2862 if gSpectViewTwo
then
2864 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
2865 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
2866 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2867 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2871 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
2872 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
2878 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
2880 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2882 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
2883 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
2884 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
2889 if (gState
= STATE_MENU
) then
2891 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
2893 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2894 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2895 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2897 if g_ActiveWindow
<> nil then
2898 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2901 if gState
= STATE_FOLD
then
2902 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
2904 if gState
= STATE_INTERCUSTOM
then
2906 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
2908 back
:= 'TEXTURE_endpic';
2909 if not g_Texture_Get(back
, ID
) then
2910 back
:= _lc
[I_TEXTURE_ENDPIC
];
2915 if g_Texture_Get(back
, ID
) then
2916 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2918 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2922 if g_ActiveWindow
<> nil then
2923 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2926 if gState
= STATE_INTERSINGLE
then
2928 if EndingGameCounter
> 0 then
2929 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
2934 if g_Texture_Get(back
, ID
) then
2935 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2937 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2941 if g_ActiveWindow
<> nil then
2942 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2946 if gState
= STATE_ENDPIC
then
2949 if not g_Texture_Get('TEXTURE_endpic', ID
) then
2950 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
2952 if ID
<> DWORD(-1) then
2953 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
2955 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2957 if g_ActiveWindow
<> nil then
2958 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2961 if gState
= STATE_SLIST
then
2963 if g_Texture_Get('MENU_BACKGROUND', ID
) then
2965 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
2966 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2968 g_Serverlist_Draw(slCurrent
);
2972 if g_ActiveWindow
<> nil then
2975 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
2976 g_ActiveWindow
.Draw();
2981 if g_debug_Sounds
and gGameOn
then
2983 for w
:= 0 to High(e_SoundsArray
) do
2984 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
2985 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
2990 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
2991 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
2994 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
2995 e_TextureFontPrint(gScreenWidth
-72, 0,
2996 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3000 procedure g_Game_Quit();
3002 g_Game_StopAllSounds(True);
3004 g_Game_SaveOptions();
3006 g_PlayerModel_FreeData();
3007 g_Texture_DeleteAll();
3008 g_Frames_DeleteAll();
3011 if NetInitDone
then g_Net_Free
;
3013 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3014 if gMapToDelete
<> '' then
3015 g_Game_DeleteTestMap();
3021 procedure g_FatalError(Text: String);
3023 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3024 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3026 gExit
:= EXIT_SIMPLE
;
3029 procedure g_SimpleError(Text: String);
3031 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3032 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3035 procedure g_Game_SetupScreenSize();
3039 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3040 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3041 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3042 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3044 gPlayerScreenSize
.Y
:= gScreenHeight
;
3046 // Ðàçìåð çàäíåãî ïëàíà:
3047 if BackID
<> DWORD(-1) then
3051 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3052 (gScreenHeight
*d
> gMapInfo
.Height
) then
3055 gBackSize
.X
:= Round(gScreenWidth
*d
);
3056 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3060 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3062 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3065 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3067 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3068 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3070 if gPlayer1
= nil then
3072 if g_Game_IsClient
then
3074 if NetPlrUID1
> -1 then
3076 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3077 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3082 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3083 Team
:= gPlayer1Settings
.Team
;
3085 // Ñîçäàíèå ïåðâîãî èãðîêà:
3086 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3087 gPlayer1Settings
.Color
,
3089 if gPlayer1
= nil then
3090 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3093 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3094 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3095 if g_Game_IsServer
and g_Game_IsNet
then
3096 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3097 gPlayer1
.Respawn(False, True);
3099 if g_Game_IsNet
and NetUseMaster
then
3105 if gPlayer2
= nil then
3107 if g_Game_IsClient
then
3109 if NetPlrUID2
> -1 then
3110 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3114 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3115 Team
:= gPlayer2Settings
.Team
;
3117 // Ñîçäàíèå âòîðîãî èãðîêà:
3118 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3119 gPlayer2Settings
.Color
,
3121 if gPlayer2
= nil then
3122 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3125 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3126 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3127 if g_Game_IsServer
and g_Game_IsNet
then
3128 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3129 gPlayer2
.Respawn(False, True);
3131 if g_Game_IsNet
and NetUseMaster
then
3139 procedure g_Game_RemovePlayer();
3143 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3144 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3149 if g_Game_IsServer
then
3152 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3153 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3154 g_Player_Remove(Pl
.UID
);
3156 if g_Game_IsNet
and NetUseMaster
then
3165 if g_Game_IsServer
then
3168 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3169 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3170 g_Player_Remove(Pl
.UID
);
3172 if g_Game_IsNet
and NetUseMaster
then
3177 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3183 procedure g_Game_Spectate();
3185 g_Game_RemovePlayer();
3186 if gPlayer1
<> nil then
3187 g_Game_RemovePlayer();
3190 procedure g_Game_SpectateCenterView();
3192 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3193 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3196 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3202 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3204 g_Game_ClearLoading();
3207 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3210 gGameSettings
.GameType
:= GT_SINGLE
;
3211 gGameSettings
.MaxLives
:= 0;
3212 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3213 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3214 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3215 gSwitchGameMode
:= GM_SINGLE
;
3217 g_Game_ExecuteEvent('ongamestart');
3219 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3220 g_Game_SetupScreenSize();
3222 // Ñîçäàíèå ïåðâîãî èãðîêà:
3223 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3224 gPlayer1Settings
.Color
,
3225 gPlayer1Settings
.Team
, False));
3226 if gPlayer1
= nil then
3228 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3232 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3235 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3238 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3239 gPlayer2Settings
.Color
,
3240 gPlayer2Settings
.Team
, False));
3241 if gPlayer2
= nil then
3243 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3247 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3251 // Çàãðóçêà è çàïóñê êàðòû:
3252 if not g_Game_StartMap(MAP
, True) then
3254 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3258 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3262 for i
:= nPl
+1 to nPlayers
do
3263 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3266 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3267 TimeLimit
, GoalLimit
: Word;
3269 Options
: LongWord; nPlayers
: Byte);
3275 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3277 g_Game_ClearLoading();
3280 gGameSettings
.GameType
:= GT_CUSTOM
;
3281 gGameSettings
.GameMode
:= GameMode
;
3282 gSwitchGameMode
:= GameMode
;
3283 gGameSettings
.TimeLimit
:= TimeLimit
;
3284 gGameSettings
.GoalLimit
:= GoalLimit
;
3285 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3286 gGameSettings
.Options
:= Options
;
3288 gCoopTotalMonstersKilled
:= 0;
3289 gCoopTotalSecretsFound
:= 0;
3290 gCoopTotalMonsters
:= 0;
3291 gCoopTotalSecrets
:= 0;
3295 g_Game_ExecuteEvent('ongamestart');
3297 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3298 g_Game_SetupScreenSize();
3300 // Ðåæèì íàáëþäàòåëÿ:
3301 if nPlayers
= 0 then
3308 if nPlayers
>= 1 then
3310 // Ñîçäàíèå ïåðâîãî èãðîêà:
3311 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3312 gPlayer1Settings
.Color
,
3313 gPlayer1Settings
.Team
, False));
3314 if gPlayer1
= nil then
3316 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3320 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3324 if nPlayers
>= 2 then
3326 // Ñîçäàíèå âòîðîãî èãðîêà:
3327 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3328 gPlayer2Settings
.Color
,
3329 gPlayer2Settings
.Team
, False));
3330 if gPlayer2
= nil then
3332 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3336 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3340 // Çàãðóçêà è çàïóñê êàðòû:
3341 if not g_Game_StartMap(Map
, True) then
3343 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3347 // Íåò òî÷åê ïîÿâëåíèÿ:
3348 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3349 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3350 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3351 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3352 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3354 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3358 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3362 for i
:= nPl
+1 to nPlayers
do
3363 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3366 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3367 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3368 Options
: LongWord; nPlayers
: Byte;
3369 IPAddr
: LongWord; Port
: Word);
3373 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3375 g_Game_ClearLoading();
3378 gGameSettings
.GameType
:= GT_SERVER
;
3379 gGameSettings
.GameMode
:= GameMode
;
3380 gSwitchGameMode
:= GameMode
;
3381 gGameSettings
.TimeLimit
:= TimeLimit
;
3382 gGameSettings
.GoalLimit
:= GoalLimit
;
3383 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3384 gGameSettings
.Options
:= Options
;
3386 gCoopTotalMonstersKilled
:= 0;
3387 gCoopTotalSecretsFound
:= 0;
3388 gCoopTotalMonsters
:= 0;
3389 gCoopTotalSecrets
:= 0;
3393 g_Game_ExecuteEvent('ongamestart');
3395 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3396 g_Game_SetupScreenSize();
3398 // Ðåæèì íàáëþäàòåëÿ:
3399 if nPlayers
= 0 then
3405 if nPlayers
>= 1 then
3407 // Ñîçäàíèå ïåðâîãî èãðîêà:
3408 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3409 gPlayer1Settings
.Color
,
3410 gPlayer1Settings
.Team
, False));
3411 if gPlayer1
= nil then
3413 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3417 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3420 if nPlayers
>= 2 then
3422 // Ñîçäàíèå âòîðîãî èãðîêà:
3423 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3424 gPlayer2Settings
.Color
,
3425 gPlayer2Settings
.Team
, False));
3426 if gPlayer2
= nil then
3428 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3432 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3436 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3438 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3442 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3444 // Çàãðóçêà è çàïóñê êàðòû:
3445 if not g_Game_StartMap(Map
, True) then
3447 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3451 // Íåò òî÷åê ïîÿâëåíèÿ:
3452 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3453 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3454 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3455 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3456 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3458 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3462 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3465 NetState
:= NET_STATE_GAME
;
3468 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3482 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3483 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3485 g_Game_ClearLoading();
3488 gGameSettings
.GameType
:= GT_CLIENT
;
3490 gCoopTotalMonstersKilled
:= 0;
3491 gCoopTotalSecretsFound
:= 0;
3492 gCoopTotalMonsters
:= 0;
3493 gCoopTotalSecrets
:= 0;
3497 g_Game_ExecuteEvent('ongamestart');
3499 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3500 g_Game_SetupScreenSize();
3502 NetState
:= NET_STATE_AUTH
;
3504 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3506 if not g_Net_Connect(Addr
, Port
) then
3508 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3509 NetState
:= NET_STATE_NONE
;
3513 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3515 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3520 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3522 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3524 Ptr
:= NetEvent
.packet
^.data
;
3527 MID
:= e_Raw_Read_Byte(Ptr
);
3529 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3531 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3532 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3534 WadName
:= e_Raw_Read_String(Ptr
);
3535 Map
:= e_Raw_Read_String(Ptr
);
3537 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3539 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3540 gSwitchGameMode
:= gGameSettings
.GameMode
;
3541 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3542 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3543 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3544 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3545 T
:= e_Raw_Read_LongWord(Ptr
);
3547 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3548 if newResPath
= '' then
3550 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3551 newResPath
:= g_Res_DownloadWAD(WadName
);
3552 if newResPath
= '' then
3554 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3555 enet_packet_destroy(NetEvent
.packet
);
3556 NetState
:= NET_STATE_NONE
;
3560 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3562 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3563 gPlayer1Settings
.Color
,
3564 gPlayer1Settings
.Team
, False));
3566 if gPlayer1
= nil then
3568 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3570 enet_packet_destroy(NetEvent
.packet
);
3571 NetState
:= NET_STATE_NONE
;
3575 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3576 gPlayer1
.UID
:= NetPlrUID1
;
3577 gPlayer1
.Reset(True);
3579 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3581 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3583 enet_packet_destroy(NetEvent
.packet
);
3584 NetState
:= NET_STATE_NONE
;
3592 enet_packet_destroy(NetEvent
.packet
);
3596 enet_packet_destroy(NetEvent
.packet
);
3599 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3602 if (NetEvent
.data
<= NET_DISC_MAX
) then
3603 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3604 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3614 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3623 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3624 NetState
:= NET_STATE_NONE
;
3628 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3629 gLMSRespawnTime
:= 0;
3632 NetState
:= NET_STATE_GAME
;
3633 MC_SEND_FullStateRequest
;
3634 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3637 procedure g_Game_SaveOptions();
3639 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3642 procedure g_Game_ChangeMap(MapPath
: String);
3646 g_Game_ClearLoading();
3648 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3649 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3650 if gExitByTrigger
then
3653 gExitByTrigger
:= False;
3655 if not g_Game_StartMap(MapPath
, Force
) then
3656 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3659 procedure g_Game_Restart();
3663 if g_Game_IsClient
then
3665 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
3669 g_Game_ClearLoading();
3670 g_Game_StartMap(Map
, True);
3673 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3675 NewWAD
, ResName
: String;
3679 g_Player_RemoveAllCorpses();
3681 if (not g_Game_IsClient
) and
3682 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3683 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3685 if gSwitchGameMode
= GM_CTF
then
3686 gGameSettings
.MaxLives
:= 0;
3687 gGameSettings
.GameMode
:= gSwitchGameMode
;
3690 gSwitchGameMode
:= gGameSettings
.GameMode
;
3692 g_Player_ResetTeams();
3694 if Pos(':\', Map
) > 0 then
3696 g_ProcessResourceStr(Map
, @NewWAD
, nil, @ResName
);
3697 if g_Game_IsServer
then
3699 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3700 g_Game_LoadWAD(NewWAD
);
3702 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3703 g_Game_ClientWAD(NewWAD
, gWADHash
);
3707 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3710 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3712 gState
:= STATE_NONE
;
3713 g_ActiveWindow
:= nil;
3719 if gGameSettings
.GameMode
= GM_CTF
then
3721 g_Map_ResetFlag(FLAG_RED
);
3722 g_Map_ResetFlag(FLAG_BLUE
);
3723 // CTF, à ôëàãîâ íåò:
3724 if not g_Map_HaveFlagPoints() then
3725 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3730 gState
:= STATE_MENU
;
3737 NetTimeToUpdate
:= 1;
3738 NetTimeToReliable
:= 0;
3739 NetTimeToMaster
:= NetMasterRate
;
3740 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3741 gLMSRespawnTime
:= 0;
3742 gMissionFailed
:= False;
3745 gCoopMonstersKilled
:= 0;
3746 gCoopSecretsFound
:= 0;
3748 gVoteInProgress
:= False;
3749 gVotePassed
:= False;
3755 if not gGameOn
then Exit
;
3757 g_Game_SpectateCenterView();
3759 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3761 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3762 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3763 gLMSSoftSpawn
:= True;
3764 if NetMode
= NET_SERVER
then
3765 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3767 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3770 if NetMode
= NET_SERVER
then
3772 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3775 if NetUseMaster
then
3777 if (NetMHost
= nil) or (NetMPeer
= nil) then
3778 if not g_Net_Slist_Connect
then
3779 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
3784 if NetClients
<> nil then
3785 for I
:= 0 to High(NetClients
) do
3786 if NetClients
[I
].Used
then
3788 NetClients
[I
].Voted
:= False;
3789 if NetClients
[I
].RequestedFullUpdate
then
3791 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3792 NetClients
[I
].RequestedFullUpdate
:= False;
3796 g_Net_UnbanNonPermHosts();
3801 gCoopTotalMonstersKilled
:= 0;
3802 gCoopTotalSecretsFound
:= 0;
3803 gCoopTotalMonsters
:= 0;
3804 gCoopTotalSecrets
:= 0;
3808 g_Game_ExecuteEvent('onmapstart');
3811 procedure SetFirstLevel();
3815 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
3816 if MapList
= nil then
3819 SortSArray(MapList
);
3820 gNextMap
:= MapList
[Low(MapList
)];
3825 procedure g_Game_ExitLevel(Map
: Char16
);
3829 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3830 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3831 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3832 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3834 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3835 if gGameSettings
.GameType
= GT_SINGLE
then
3836 gExit
:= EXIT_ENDLEVELSINGLE
3837 else // Âûøëè â âûõîä â Ñâîåé èãðå
3839 gExit
:= EXIT_ENDLEVELCUSTOM
;
3840 if gGameSettings
.GameMode
= GM_COOP
then
3841 g_Player_RememberAll
;
3843 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3846 if gGameSettings
.GameMode
= GM_COOP
then
3849 gStatsPressed
:= True;
3850 gNextMap
:= 'MAP01';
3852 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
3855 if g_Game_IsNet
then
3857 MH_SEND_GameStats();
3858 MH_SEND_CoopStats();
3864 procedure g_Game_RestartLevel();
3868 if gGameSettings
.GameMode
= GM_SINGLE
then
3873 gExit
:= EXIT_ENDLEVELCUSTOM
;
3874 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
3878 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
3882 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
3884 if not g_Game_IsClient
then
3886 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
3889 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3890 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
3894 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3898 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
3899 g_Game_LoadWAD(NewWAD
);
3902 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3904 i
, n
, nb
, nr
: Integer;
3906 if not g_Game_IsServer
then Exit
;
3907 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3908 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3909 gLMSRespawnTime
:= 0;
3912 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3914 gMissionFailed
:= True;
3915 g_Game_RestartLevel
;
3919 n
:= 0; nb
:= 0; nr
:= 0;
3920 for i
:= Low(gPlayers
) to High(gPlayers
) do
3921 if (gPlayers
[i
] <> nil) and
3922 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3923 (gPlayers
[i
] is TBot
)) then
3926 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3927 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3930 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3932 // wait a second until the fuckers finally decide to join
3933 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3934 gLMSRespawnTime
:= gTime
+ 1000;
3935 gLMSSoftSpawn
:= NoMapRestart
;
3939 g_Player_RemoveAllCorpses
;
3940 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3941 if g_Game_IsNet
then
3942 MH_SEND_GameEvent(NET_EV_LMS_START
);
3944 for i
:= Low(gPlayers
) to High(gPlayers
) do
3946 if gPlayers
[i
] = nil then continue
;
3947 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3948 // don't touch normal spectators
3949 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3951 gPlayers
[i
].FNoRespawn
:= True;
3952 gPlayers
[i
].Lives
:= 0;
3953 if g_Game_IsNet
then
3954 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3957 gPlayers
[i
].FNoRespawn
:= False;
3958 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3959 gPlayers
[i
].Respawn(False, True);
3960 if gGameSettings
.GameMode
= GM_COOP
then
3962 gPlayers
[i
].Frags
:= 0;
3963 gPlayers
[i
].RecallState
;
3965 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
3966 gPlayer1
:= g_Player_Get(gLMSPID1
);
3967 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
3968 gPlayer2
:= g_Player_Get(gLMSPID2
);
3971 for i
:= Low(gItems
) to High(gItems
) do
3973 if gItems
[i
].Respawnable
then
3975 gItems
[i
].QuietRespawn
:= True;
3976 gItems
[i
].RespawnTime
:= 0;
3981 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
3985 for i
:= Low(gMonsters
) to High(gMonsters
) do
3987 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
3988 gMonsters
[i
].Respawn
;
3991 gLMSSoftSpawn
:= False;
3994 function g_Game_GetFirstMap(WAD
: String): String;
3998 MapList
:= g_Map_GetMapsList(WAD
);
3999 if MapList
= nil then
4002 SortSArray(MapList
);
4003 Result
:= MapList
[Low(MapList
)];
4005 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4011 function g_Game_GetNextMap(): String;
4018 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4019 if MapList
= nil then
4022 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
4024 SortSArray(MapList
);
4026 for I
:= Low(MapList
) to High(MapList
) do
4027 if Map
= MapList
[I
] then
4033 if MapIndex
<> -255 then
4035 if MapIndex
= High(MapList
) then
4036 Result
:= MapList
[Low(MapList
)]
4038 Result
:= MapList
[MapIndex
+ 1];
4040 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4046 procedure g_Game_NextLevel();
4048 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4049 gExit
:= EXIT_ENDLEVELCUSTOM
4052 gExit
:= EXIT_ENDLEVELSINGLE
;
4056 if gNextMap
<> '' then Exit
;
4057 gNextMap
:= g_Game_GetNextMap();
4060 function g_Game_IsTestMap(): Boolean;
4062 FName
, Sect
, Res
: String;
4064 g_ProcessResourceStr(gMapInfo
.Map
, FName
, Sect
, Res
);
4065 Result
:= UpperCase(Res
) = TEST_MAP_NAME
;
4068 procedure g_Game_DeleteTestMap();
4079 a
:= Pos('.wad:\', gMapToDelete
);
4083 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4084 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4085 Delete(gMapToDelete
, 1, a
+ 5);
4086 gMapToDelete
:= UpperCase(gMapToDelete
);
4088 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4091 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4092 if MapName <> TEST_MAP_NAME then
4095 if not gTempDelete then
4097 time := g_GetFileTime(WadName);
4098 WAD := TWADFile.Create();
4101 if not WAD.ReadFile(WadName) then
4102 begin // Íåò òàêîãî WAD-ôàéëà
4107 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4109 MapList := WAD.GetResourcesList('');
4111 if MapList <> nil then
4112 for a := 0 to High(MapList) do
4113 if MapList[a] = MapName then
4115 // Óäàëÿåì è ñîõðàíÿåì:
4116 WAD.RemoveResource('', MapName);
4117 WAD.SaveTo(WadName);
4122 g_SetFileTime(WadName, time);
4125 if gTempDelete
then DeleteFile(WadName
);
4128 procedure GameCVars(P
: SArray
);
4131 stat
: TPlayerStatArray
;
4136 cmd
:= LowerCase(P
[0]);
4137 if cmd
= 'r_showfps' then
4139 if (Length(P
) > 1) and
4140 ((P
[1] = '1') or (P
[1] = '0')) then
4141 gShowFPS
:= (P
[1][1] = '1');
4144 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4146 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4148 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4150 with gGameSettings
do
4152 if (Length(P
) > 1) and
4153 ((P
[1] = '1') or (P
[1] = '0')) then
4155 if (P
[1][1] = '1') then
4156 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4158 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4161 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4162 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4164 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4166 if g_Game_IsNet
then MH_SEND_GameSettings
;
4169 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4171 with gGameSettings
do
4173 if (Length(P
) > 1) and
4174 ((P
[1] = '1') or (P
[1] = '0')) then
4176 if (P
[1][1] = '1') then
4177 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4179 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4182 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4183 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4185 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4187 if g_Game_IsNet
then MH_SEND_GameSettings
;
4190 else if cmd
= 'g_gamemode' then
4192 a
:= g_Game_TextToMode(P
[1]);
4193 if a
= GM_SINGLE
then a
:= GM_COOP
;
4194 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4196 gSwitchGameMode
:= a
;
4197 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4198 (gState
= STATE_INTERSINGLE
) then
4199 gSwitchGameMode
:= GM_SINGLE
;
4201 gGameSettings
.GameMode
:= gSwitchGameMode
;
4203 if gSwitchGameMode
= gGameSettings
.GameMode
then
4204 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4205 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4207 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4208 [g_Game_ModeToText(gGameSettings
.GameMode
),
4209 g_Game_ModeToText(gSwitchGameMode
)]));
4211 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4213 with gGameSettings
do
4215 if (Length(P
) > 1) and
4216 ((P
[1] = '1') or (P
[1] = '0')) then
4218 if (P
[1][1] = '1') then
4219 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4221 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4224 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4225 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4227 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4228 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4230 if g_Game_IsNet
then MH_SEND_GameSettings
;
4233 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4235 with gGameSettings
do
4237 if (Length(P
) > 1) and
4238 ((P
[1] = '1') or (P
[1] = '0')) then
4240 if (P
[1][1] = '1') then
4241 Options
:= Options
or GAME_OPTION_MONSTERS
4243 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4246 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4247 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4249 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4250 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4252 if g_Game_IsNet
then MH_SEND_GameSettings
;
4255 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4257 with gGameSettings
do
4259 if (Length(P
) > 1) and
4260 ((P
[1] = '1') or (P
[1] = '0')) then
4262 if (P
[1][1] = '1') then
4263 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4265 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4268 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4269 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4271 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4273 if g_Game_IsNet
then MH_SEND_GameSettings
;
4276 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4278 with gGameSettings
do
4280 if (Length(P
) > 1) and
4281 ((P
[1] = '1') or (P
[1] = '0')) then
4283 if (P
[1][1] = '1') then
4284 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4286 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4289 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4290 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4292 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4294 if g_Game_IsNet
then MH_SEND_GameSettings
;
4297 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4299 if Length(P
) > 1 then
4301 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4302 gGameSettings
.WarmupTime
:= 30
4304 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4307 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4308 [gGameSettings
.WarmupTime
]));
4309 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4311 else if cmd
= 'net_interp' then
4313 if (Length(P
) > 1) then
4314 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4316 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4317 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4318 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4319 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4322 else if cmd
= 'net_forceplayerupdate' then
4324 if (Length(P
) > 1) and
4325 ((P
[1] = '1') or (P
[1] = '0')) then
4326 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4328 if NetForcePlayerUpdate
then
4329 g_Console_Add('net_forceplayerupdate = 1')
4331 g_Console_Add('net_forceplayerupdate = 0');
4332 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4333 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4334 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4337 else if cmd
= 'net_predictself' then
4339 if (Length(P
) > 1) and
4340 ((P
[1] = '1') or (P
[1] = '0')) then
4341 NetPredictSelf
:= (P
[1][1] = '1');
4343 if NetPredictSelf
then
4344 g_Console_Add('net_predictself = 1')
4346 g_Console_Add('net_predictself = 0');
4347 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4348 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4349 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4352 else if cmd
= 'sv_name' then
4354 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4356 NetServerName
:= P
[1];
4357 if Length(NetServerName
) > 64 then
4358 SetLength(NetServerName
, 64);
4359 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4363 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4365 else if cmd
= 'sv_passwd' then
4367 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4369 NetPassword
:= P
[1];
4370 if Length(NetPassword
) > 24 then
4371 SetLength(NetPassword
, 24);
4372 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4376 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4378 else if cmd
= 'sv_maxplrs' then
4380 if (Length(P
) > 1) then
4382 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4383 if g_Game_IsServer
and g_Game_IsNet
then
4386 for a
:= 0 to High(NetClients
) do
4387 if NetClients
[a
].Used
then
4390 if b
> NetMaxClients
then
4392 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4393 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4394 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4395 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4398 if NetUseMaster
then
4403 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4405 else if cmd
= 'sv_public' then
4407 if (Length(P
) > 1) then
4409 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4410 if g_Game_IsServer
and g_Game_IsNet
then
4411 if NetUseMaster
then
4413 if NetMPeer
= nil then
4414 if not g_Net_Slist_Connect() then
4415 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4416 g_Net_Slist_Update();
4419 if NetMPeer
<> nil then
4420 g_Net_Slist_Disconnect();
4423 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4425 else if cmd
= 'sv_intertime' then
4427 if (Length(P
) > 1) then
4428 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4430 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4432 else if cmd
= 'p1_name' then
4434 if (Length(P
) > 1) and gGameOn
then
4436 if g_Game_IsClient
then
4438 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4439 MC_SEND_PlayerSettings
;
4442 if gPlayer1
<> nil then
4444 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4445 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4448 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4451 else if cmd
= 'p2_name' then
4453 if (Length(P
) > 1) and gGameOn
then
4455 if g_Game_IsClient
then
4457 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4458 MC_SEND_PlayerSettings
;
4461 if gPlayer2
<> nil then
4463 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4464 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4467 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4470 else if cmd
= 'p1_color' then
4472 if Length(P
) > 3 then
4473 if g_Game_IsClient
then
4475 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4476 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4477 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4478 MC_SEND_PlayerSettings
;
4481 if gPlayer1
<> nil then
4483 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4484 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4485 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4486 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4489 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4490 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4491 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4493 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4495 if Length(P
) > 3 then
4496 if g_Game_IsClient
then
4498 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4499 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4500 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4501 MC_SEND_PlayerSettings
;
4504 if gPlayer2
<> nil then
4506 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4507 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4508 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4509 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4512 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4513 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4514 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4516 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4518 if cmd
= 'r_showtime' then
4520 if (Length(P
) > 1) and
4521 ((P
[1] = '1') or (P
[1] = '0')) then
4522 gShowTime
:= (P
[1][1] = '1');
4525 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4527 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4529 else if cmd
= 'r_showscore' then
4531 if (Length(P
) > 1) and
4532 ((P
[1] = '1') or (P
[1] = '0')) then
4533 gShowGoals
:= (P
[1][1] = '1');
4536 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4538 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4540 else if cmd
= 'r_showstat' then
4542 if (Length(P
) > 1) and
4543 ((P
[1] = '1') or (P
[1] = '0')) then
4544 gShowStat
:= (P
[1][1] = '1');
4547 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4549 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4551 else if cmd
= 'r_showkillmsg' then
4553 if (Length(P
) > 1) and
4554 ((P
[1] = '1') or (P
[1] = '0')) then
4555 gShowKillMsg
:= (P
[1][1] = '1');
4557 if gShowKillMsg
then
4558 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4560 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4562 else if cmd
= 'r_showlives' then
4564 if (Length(P
) > 1) and
4565 ((P
[1] = '1') or (P
[1] = '0')) then
4566 gShowLives
:= (P
[1][1] = '1');
4569 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4571 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4573 else if cmd
= 'r_showspect' then
4575 if (Length(P
) > 1) and
4576 ((P
[1] = '1') or (P
[1] = '0')) then
4577 gSpectHUD
:= (P
[1][1] = '1');
4580 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4582 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4584 else if cmd
= 'r_showping' then
4586 if (Length(P
) > 1) and
4587 ((P
[1] = '1') or (P
[1] = '0')) then
4588 gShowPing
:= (P
[1][1] = '1');
4591 g_Console_Add(_lc
[I_MSG_PING_ON
])
4593 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4595 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4597 if Length(P
) > 1 then
4599 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4600 gGameSettings
.GoalLimit
:= 0
4605 if gGameSettings
.GameMode
= GM_DM
then
4607 stat
:= g_Player_GetStats();
4609 for a
:= 0 to High(stat
) do
4610 if stat
[a
].Frags
> b
then
4614 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4616 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4619 if g_Game_IsNet
then MH_SEND_GameSettings
;
4622 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4624 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4626 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4627 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4629 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4630 [gGameSettings
.TimeLimit
div 3600,
4631 (gGameSettings
.TimeLimit
div 60) mod 60,
4632 gGameSettings
.TimeLimit
mod 60]));
4633 if g_Game_IsNet
then MH_SEND_GameSettings
;
4635 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4637 if Length(P
) > 1 then
4639 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4640 gGameSettings
.MaxLives
:= 0
4644 stat
:= g_Player_GetStats();
4646 for a
:= 0 to High(stat
) do
4647 if stat
[a
].Lives
> b
then
4649 gGameSettings
.MaxLives
:=
4650 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4654 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4655 [gGameSettings
.MaxLives
]));
4656 if g_Game_IsNet
then MH_SEND_GameSettings
;
4661 procedure DebugCommands(P
: SArray
);
4667 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4670 cmd
:= LowerCase(P
[0]);
4671 if cmd
= 'd_window' then
4673 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
4674 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
4675 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4676 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
4677 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
4679 else if cmd
= 'd_sounds' then
4681 if (Length(P
) > 1) and
4682 ((P
[1] = '1') or (P
[1] = '0')) then
4683 g_Debug_Sounds
:= (P
[1][1] = '1');
4685 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4687 else if cmd
= 'd_frames' then
4689 if (Length(P
) > 1) and
4690 ((P
[1] = '1') or (P
[1] = '0')) then
4691 g_Debug_Frames
:= (P
[1][1] = '1');
4693 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4695 else if cmd
= 'd_winmsg' then
4697 if (Length(P
) > 1) and
4698 ((P
[1] = '1') or (P
[1] = '0')) then
4699 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4701 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4703 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4705 if (Length(P
) > 1) and
4706 ((P
[1] = '1') or (P
[1] = '0')) then
4707 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4709 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4711 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4713 if Length(P
) > 1 then
4715 '0': g_debug_BotAIOff
:= 0;
4716 '1': g_debug_BotAIOff
:= 1;
4717 '2': g_debug_BotAIOff
:= 2;
4718 '3': g_debug_BotAIOff
:= 3;
4721 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4723 else if cmd
= 'd_monster' then
4725 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
4726 if Length(P
) < 2 then
4728 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4729 g_Console_Add('ID | Name');
4730 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4731 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
4734 a
:= StrToIntDef(P
[1], 0);
4735 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4736 a
:= g_Monsters_GetIDByName(P
[1]);
4738 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4739 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4742 with gPlayer1
.Obj
do
4743 b
:= g_Monsters_Create(a
,
4744 X
+ Rect
.X
+ (Rect
.Width
div 2),
4745 Y
+ Rect
.Y
+ Rect
.Height
,
4746 gPlayer1
.Direction
, True);
4747 if (Length(P
) > 2) and (b
>= 0) then
4748 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4752 else if (cmd
= 'd_health') then
4754 if (Length(P
) > 1) and
4755 ((P
[1] = '1') or (P
[1] = '0')) then
4756 g_debug_HealthBar
:= (P
[1][1] = '1');
4758 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4760 else if (cmd
= 'd_player') then
4762 if (Length(P
) > 1) and
4763 ((P
[1] = '1') or (P
[1] = '0')) then
4764 g_debug_Player
:= (P
[1][1] = '1');
4766 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4768 else if (cmd
= 'd_joy') then
4771 g_Console_Add(e_JoystickStateToString(a
));
4775 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4779 procedure GameCheats(P
: SArray
);
4785 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
4786 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
4788 g_Console_Add('not available');
4794 g_Console_Add('where is the player?!');
4797 cmd
:= LowerCase(P
[0]);
4801 plr
.GodMode
:= not plr
.GodMode
;
4802 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4805 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4806 if cmd
= 'give' then
4808 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4809 for f
:= 1 to High(P
) do
4811 cmd
:= LowerCase(P
[f
]);
4812 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4813 if (cmd
= 'all') or (cmd
= 'weapons') then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4814 if cmd
= 'exit' then
4816 if gTriggers
<> nil then
4818 for a
:= 0 to High(gTriggers
) do
4820 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4822 g_Console_Add('player left the map');
4823 gExitByTrigger
:= True;
4824 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
4831 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4832 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got jetpack'); continue
; end;
4833 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got envirosuit'); continue
; end;
4834 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got berserk pack'); continue
; end;
4835 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4840 if cmd
= 'open' then
4842 g_Console_Add('player activated sesame');
4843 g_Triggers_OpenAll();
4850 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4854 if cmd
= 'noclip' then
4857 g_Console_Add('wall hardeness adjusted');
4861 if cmd
= 'notarget' then
4863 plr
.NoTarget
:= not plr
.NoTarget
;
4864 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4868 if cmd
= 'noreload' then
4870 plr
.NoReload
:= not plr
.NoReload
;
4871 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4875 if cmd
= 'speedy' then
4877 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4878 g_Console_Add('speed adjusted');
4882 if cmd
= 'jumpy' then
4884 VEL_JUMP
:= 30-VEL_JUMP
;
4885 g_Console_Add('jump height adjusted');
4889 if cmd
= 'automap' then
4891 gShowMap
:= not gShowMap
;
4892 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4896 if cmd
= 'aimline' then
4898 gAimLine
:= not gAimLine
;
4899 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4904 procedure GameCommands(P
: SArray
);
4910 pl
: pTNetClient
= nil;
4917 cmd
:= LowerCase(P
[0]);
4919 if (cmd
= 'quit') or
4926 else if cmd
= 'pause' then
4928 if (g_ActiveWindow
= nil) then
4929 g_Game_Pause(not gPause
);
4931 else if cmd
= 'endgame' then
4932 gExit
:= EXIT_SIMPLE
4933 else if cmd
= 'restart' then
4935 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4937 if g_Game_IsClient
then
4939 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4944 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4946 else if cmd
= 'kick' then
4948 if g_Game_IsServer
then
4950 if Length(P
) < 2 then
4952 g_Console_Add('kick <name>');
4957 g_Console_Add('kick <name>');
4961 if g_Game_IsNet
then
4962 pl
:= g_Net_Client_ByName(P
[1]);
4965 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4966 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4967 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4968 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4969 if NetUseMaster
then
4971 end else if gPlayers
<> nil then
4972 for a
:= Low(gPlayers
) to High(gPlayers
) do
4973 if gPlayers
[a
] <> nil then
4974 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4976 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4977 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4979 gPlayers
[a
].Lives
:= 0;
4980 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4981 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4982 g_Player_Remove(gPlayers
[a
].UID
);
4983 if NetUseMaster
then
4985 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4989 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4991 else if cmd
= 'kick_id' then
4993 if g_Game_IsServer
and g_Game_IsNet
then
4995 if Length(P
) < 2 then
4997 g_Console_Add('kick_id <client ID>');
5002 g_Console_Add('kick_id <client ID>');
5006 a
:= StrToIntDef(P
[1], 0);
5007 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5009 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5011 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5012 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5013 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5014 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5015 if NetUseMaster
then
5020 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5022 else if cmd
= 'ban' then
5024 if g_Game_IsServer
and g_Game_IsNet
then
5026 if Length(P
) < 2 then
5028 g_Console_Add('ban <name>');
5033 g_Console_Add('ban <name>');
5037 pl
:= g_Net_Client_ByName(P
[1]);
5040 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5041 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5042 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5043 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5044 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5045 if NetUseMaster
then
5048 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5050 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5052 else if cmd
= 'ban_id' then
5054 if g_Game_IsServer
and g_Game_IsNet
then
5056 if Length(P
) < 2 then
5058 g_Console_Add('ban_id <client ID>');
5063 g_Console_Add('ban_id <client ID>');
5067 a
:= StrToIntDef(P
[1], 0);
5068 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5069 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5071 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5072 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5073 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5074 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5075 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5076 if NetUseMaster
then
5080 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5082 else if cmd
= 'permban' then
5084 if g_Game_IsServer
and g_Game_IsNet
then
5086 if Length(P
) < 2 then
5088 g_Console_Add('permban <name>');
5093 g_Console_Add('permban <name>');
5097 pl
:= g_Net_Client_ByName(P
[1]);
5100 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5101 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5102 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5103 g_Net_SaveBanList();
5104 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5105 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5106 if NetUseMaster
then
5109 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5111 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5113 else if cmd
= 'permban_id' then
5115 if g_Game_IsServer
and g_Game_IsNet
then
5117 if Length(P
) < 2 then
5119 g_Console_Add('permban_id <client ID>');
5124 g_Console_Add('permban_id <client ID>');
5128 a
:= StrToIntDef(P
[1], 0);
5129 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5130 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5132 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5133 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5134 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5135 g_Net_SaveBanList();
5136 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5137 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5138 if NetUseMaster
then
5142 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5144 else if cmd
= 'unban' then
5146 if g_Game_IsServer
and g_Game_IsNet
then
5148 if Length(P
) < 2 then
5150 g_Console_Add('unban <IP Address>');
5155 g_Console_Add('unban <IP Address>');
5159 if g_Net_UnbanHost(P
[1]) then
5161 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5162 g_Net_SaveBanList();
5164 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5166 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5168 else if cmd
= 'clientlist' then
5170 if g_Game_IsServer
and g_Game_IsNet
then
5173 if NetClients
<> nil then
5174 for a
:= Low(NetClients
) to High(NetClients
) do
5175 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5177 plr
:= g_Player_Get(NetClients
[a
].Player
);
5178 if plr
= nil then continue
;
5180 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5181 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5184 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5186 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5188 else if cmd
= 'connect' then
5190 if (NetMode
= NET_NONE
) then
5192 if Length(P
) < 2 then
5194 g_Console_Add('connect <IP> [port] [password]');
5199 g_Console_Add('connect <IP> [port] [password]');
5203 if Length(P
) > 2 then
5204 prt
:= StrToIntDef(P
[2], 25666)
5208 if Length(P
) > 3 then
5213 g_Game_StartClient(P
[1], prt
, pw
);
5216 else if cmd
= 'disconnect' then
5218 if (NetMode
= NET_CLIENT
) then
5221 else if cmd
= 'reconnect' then
5223 if (NetMode
= NET_SERVER
) then
5226 if (NetMode
= NET_CLIENT
) then
5229 gExit
:= EXIT_SIMPLE
;
5233 //TODO: Use last successful password to reconnect, instead of ''
5234 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5236 else if (cmd
= 'addbot') or
5237 (cmd
= 'bot_add') then
5239 if Length(P
) > 1 then
5240 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5242 g_Bot_Add(TEAM_NONE
, 2);
5244 else if cmd
= 'bot_addlist' then
5246 if Length(P
) > 1 then
5247 if Length(P
) = 2 then
5248 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5250 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5252 else if cmd
= 'bot_removeall' then
5254 else if cmd
= 'chat' then
5256 if g_Game_IsNet
then
5258 if Length(P
) > 1 then
5260 for a
:= 1 to High(P
) do
5261 chstr
:= chstr
+ P
[a
] + ' ';
5263 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5265 if Length(chstr
) < 1 then
5267 g_Console_Add('chat <text>');
5271 chstr
:= b_Text_Format(chstr
);
5272 if g_Game_IsClient
then
5273 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5275 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5278 g_Console_Add('chat <text>');
5280 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5282 else if cmd
= 'teamchat' then
5284 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5286 if Length(P
) > 1 then
5288 for a
:= 1 to High(P
) do
5289 chstr
:= chstr
+ P
[a
] + ' ';
5291 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5293 if Length(chstr
) < 1 then
5295 g_Console_Add('teamchat <text>');
5299 chstr
:= b_Text_Format(chstr
);
5300 if g_Game_IsClient
then
5301 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5303 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5304 gPlayer1Settings
.Team
);
5307 g_Console_Add('teamchat <text>');
5309 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5311 else if cmd
= 'game' then
5313 if gGameSettings
.GameType
<> GT_NONE
then
5315 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5318 if Length(P
) = 1 then
5320 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5323 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5324 P
[1] := addWadExtension(P
[1]);
5325 if FileExists(MapsDir
+ P
[1]) then
5327 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5328 if Length(P
) < 3 then
5331 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5334 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5336 if g_Map_Exist(MapsDir
+ s
) then
5338 // Çàïóñêàåì ñâîþ èãðó
5340 with gGameSettings
do
5342 GameMode
:= g_Game_TextToMode(gcGameMode
);
5343 if gSwitchGameMode
<> GM_NONE
then
5344 GameMode
:= gSwitchGameMode
;
5345 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5346 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5348 if Length(P
) >= 4 then
5349 b
:= StrToIntDef(P
[3], 1);
5350 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5351 GoalLimit
, MaxLives
, Options
, b
);
5356 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5358 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5360 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5362 else if cmd
= 'host' then
5364 if gGameSettings
.GameType
<> GT_NONE
then
5366 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5369 if Length(P
) < 4 then
5371 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5374 if not StrToIp(P
[1], listen
) then
5376 prt
:= StrToIntDef(P
[2], 25666);
5378 P
[3] := addWadExtension(P
[3]);
5379 if FileExists(MapsDir
+ P
[3]) then
5381 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5382 if Length(P
) < 5 then
5385 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5388 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5390 if g_Map_Exist(MapsDir
+ s
) then
5392 // Çàïóñêàåì ñâîþ èãðó
5394 with gGameSettings
do
5396 GameMode
:= g_Game_TextToMode(gcGameMode
);
5397 if gSwitchGameMode
<> GM_NONE
then
5398 GameMode
:= gSwitchGameMode
;
5399 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5400 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5402 if Length(P
) >= 6 then
5403 b
:= StrToIntDef(P
[5], 0);
5404 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5405 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5410 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5412 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5414 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5416 else if cmd
= 'map' then
5418 if Length(P
) = 1 then
5420 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5422 g_Console_Add(cmd
+ ' <MAP>');
5423 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5425 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5427 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5429 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5430 if Length(P
) < 3 then
5432 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5433 s
:= UpperCase(P
[1]);
5434 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5435 begin // Êàðòà íàøëàñü
5436 gExitByTrigger
:= False;
5438 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5440 gExit
:= EXIT_ENDLEVELCUSTOM
;
5442 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5443 g_Game_ChangeMap(s
);
5446 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5447 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5448 P
[1] := addWadExtension(P
[1]);
5449 if FileExists(MapsDir
+ P
[1]) then
5451 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5453 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5455 s
:= P
[1] + ':\' + P
[2];
5457 if g_Map_Exist(MapsDir
+ s
) then
5459 gExitByTrigger
:= False;
5461 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5463 gExit
:= EXIT_ENDLEVELCUSTOM
;
5465 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5466 g_Game_ChangeMap(s
);
5469 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5471 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5473 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5477 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5478 P
[1] := addWadExtension(P
[1]);
5479 if FileExists(MapsDir
+ P
[1]) then
5482 P
[2] := UpperCase(P
[2]);
5483 s
:= P
[1] + ':\' + P
[2];
5485 if g_Map_Exist(MapsDir
+ s
) then
5486 begin // Íàøëè êàðòó
5487 gExitByTrigger
:= False;
5489 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5491 gExit
:= EXIT_ENDLEVELCUSTOM
;
5493 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5494 g_Game_ChangeMap(s
);
5496 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5498 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5501 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5503 else if cmd
= 'nextmap' then
5505 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5506 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5509 if Length(P
) = 1 then
5511 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5513 g_Console_Add(cmd
+ ' <MAP>');
5514 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5517 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5522 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5524 if Length(P
) < 3 then
5526 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5527 s
:= UpperCase(P
[1]);
5528 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5529 begin // Êàðòà íàøëàñü
5530 gExitByTrigger
:= False;
5535 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5536 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5537 P
[1] := addWadExtension(P
[1]);
5538 if FileExists(MapsDir
+ P
[1]) then
5540 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5542 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5544 s
:= P
[1] + ':\' + P
[2];
5546 if g_Map_Exist(MapsDir
+ s
) then
5547 begin // Óñòàíàâëèâàåì êàðòó
5548 gExitByTrigger
:= False;
5553 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5555 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5557 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5561 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5562 P
[1] := addWadExtension(P
[1]);
5563 if FileExists(MapsDir
+ P
[1]) then
5566 P
[2] := UpperCase(P
[2]);
5567 s
:= P
[1] + ':\' + P
[2];
5569 if g_Map_Exist(MapsDir
+ s
) then
5570 begin // Íàøëè êàðòó
5571 gExitByTrigger
:= False;
5575 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5577 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5580 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5583 if gNextMap
= '' then
5584 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5586 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
5589 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5592 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5594 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5596 gExitByTrigger
:= False;
5597 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5598 if (gNextMap
= '') and (gTriggers
<> nil) then
5599 for a
:= 0 to High(gTriggers
) do
5600 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5602 gExitByTrigger
:= True;
5603 gNextMap
:= gTriggers
[a
].Data
.MapName
;
5606 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5607 if gNextMap
= '' then
5608 gNextMap
:= g_Game_GetNextMap();
5609 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5610 if Pos(':\', gNextMap
) = 0 then
5611 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5614 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5615 if g_Map_Exist(MapsDir
+ s
) then
5616 gExit
:= EXIT_ENDLEVELCUSTOM
5618 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
5620 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5622 else if (cmd
= 'event') then
5624 if (Length(P
) <= 1) then
5626 for a
:= 0 to High(gEvents
) do
5627 if gEvents
[a
].Command
= '' then
5628 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5630 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5633 if (Length(P
) = 2) then
5635 for a
:= 0 to High(gEvents
) do
5636 if gEvents
[a
].Name
= P
[1] then
5637 if gEvents
[a
].Command
= '' then
5638 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5640 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5643 for a
:= 0 to High(gEvents
) do
5644 if gEvents
[a
].Name
= P
[1] then
5646 gEvents
[a
].Command
:= '';
5647 for b
:= 2 to High(P
) do
5648 if Pos(' ', P
[b
]) = 0 then
5649 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5651 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5652 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5656 // Êîìàíäû Ñâîåé èãðû:
5657 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5659 if cmd
= 'bot_addred' then
5661 if Length(P
) > 1 then
5662 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5664 g_Bot_Add(TEAM_RED
, 2);
5666 else if cmd
= 'bot_addblue' then
5668 if Length(P
) > 1 then
5669 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5671 g_Bot_Add(TEAM_BLUE
, 2);
5673 else if cmd
= 'suicide' then
5677 if g_Game_IsClient
then
5678 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5681 if gPlayer1
<> nil then
5682 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5683 if gPlayer2
<> nil then
5684 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5688 else if cmd
= 'spectate' then
5694 else if cmd
= 'say' then
5696 if g_Game_IsServer
and g_Game_IsNet
then
5698 if Length(P
) > 1 then
5701 for a
:= 1 to High(P
) do
5702 chstr
:= chstr
+ P
[a
] + ' ';
5704 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5706 if Length(chstr
) < 1 then
5708 g_Console_Add('say <text>');
5712 chstr
:= b_Text_Format(chstr
);
5713 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5715 else g_Console_Add('say <text>');
5717 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5719 else if cmd
= 'tell' then
5721 if g_Game_IsServer
and g_Game_IsNet
then
5723 if (Length(P
) > 2) and (P
[1] <> '') then
5726 for a
:= 2 to High(P
) do
5727 chstr
:= chstr
+ P
[a
] + ' ';
5729 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5731 if Length(chstr
) < 1 then
5733 g_Console_Add('tell <playername> <text>');
5737 pl
:= g_Net_Client_ByName(P
[1]);
5739 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5741 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5743 else g_Console_Add('tell <playername> <text>');
5745 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5747 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5749 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5751 // Äîïîëíèòåëüíîå âðåìÿ:
5752 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5754 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5755 [gGameSettings
.TimeLimit
div 3600,
5756 (gGameSettings
.TimeLimit
div 60) mod 60,
5757 gGameSettings
.TimeLimit
mod 60]));
5758 if g_Game_IsNet
then MH_SEND_GameSettings
;
5760 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5762 if (Length(P
) <= 1) then
5763 g_Console_Add('rcon_password <password>')
5765 MC_SEND_RCONPassword(P
[1]);
5767 else if cmd
= 'rcon' then
5769 if g_Game_IsClient
then
5771 if Length(P
) > 1 then
5774 for a
:= 1 to High(P
) do
5775 chstr
:= chstr
+ P
[a
] + ' ';
5777 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5779 if Length(chstr
) < 1 then
5781 g_Console_Add('rcon <command>');
5785 MC_SEND_RCONCommand(chstr
);
5787 else g_Console_Add('rcon <command>');
5790 else if cmd
= 'ready' then
5792 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5793 gLMSRespawnTime
:= gTime
+ 100;
5795 else if (cmd
= 'callvote') and g_Game_IsNet
then
5797 if Length(P
) > 1 then
5800 for a
:= 1 to High(P
) do begin
5801 if a
> 1 then chstr
:= chstr
+ ' ';
5802 chstr
:= chstr
+ P
[a
];
5805 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5807 if Length(chstr
) < 1 then
5809 g_Console_Add('callvote <command>');
5813 if g_Game_IsClient
then
5814 MC_SEND_Vote(True, chstr
)
5816 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5817 g_Console_Process('vote', True);
5820 g_Console_Add('callvote <command>');
5822 else if (cmd
= 'vote') and g_Game_IsNet
then
5824 if g_Game_IsClient
then
5826 else if gVoteInProgress
then
5828 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5829 a
:= Floor((NetClientCount
+1)/2.0) + 1
5831 a
:= Floor(NetClientCount
/2.0) + 1;
5836 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5837 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5843 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5844 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5852 procedure g_TakeScreenShot();
5858 ssdir
:= GameDir
+'/screenshots';
5859 if not findFileCI(ssdir
, true) then
5861 // try to create dir
5866 if not findFileCI(ssdir
, true) then exit
; // alas
5869 for a
:= 1 to High(Word) do
5871 FileName
:= Format(ssdir
+'screenshot%.3d.bmp', [a
]);
5873 if findFileCI(t
, true) then continue
;
5874 if not findFileCI(FileName
) then
5876 e_MakeScreenshot(FileName
, gScreenWidth
, gScreenHeight
);
5877 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
5885 procedure g_Game_InGameMenu(Show
: Boolean);
5887 if (g_ActiveWindow
= nil) and Show
then
5889 if gGameSettings
.GameType
= GT_SINGLE
then
5890 g_GUI_ShowWindow('GameSingleMenu')
5893 if g_Game_IsClient
then
5894 g_GUI_ShowWindow('GameClientMenu')
5896 if g_Game_IsNet
then
5897 g_GUI_ShowWindow('GameServerMenu')
5899 g_GUI_ShowWindow('GameCustomMenu');
5901 g_Sound_PlayEx('MENU_OPEN');
5903 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5904 if (not g_Game_IsNet
) then
5908 if (g_ActiveWindow
<> nil) and (not Show
) then
5910 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5911 if (not g_Game_IsNet
) then
5912 g_Game_Pause(False);
5916 procedure g_Game_Pause(Enable
: Boolean);
5921 if gPause
= Enable
then
5924 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
5928 g_Game_PauseAllSounds(Enable
);
5931 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5936 if gTriggers
<> nil then
5937 for i
:= 0 to High(gTriggers
) do
5938 with gTriggers
[i
] do
5939 if (TriggerType
= TRIGGER_SOUND
) and
5941 Sound
.IsPlaying() then
5943 Sound
.Pause(Enable
);
5947 if gPlayers
<> nil then
5948 for i
:= 0 to High(gPlayers
) do
5949 if gPlayers
[i
] <> nil then
5950 gPlayers
[i
].PauseSounds(Enable
);
5953 if gMusic
<> nil then
5954 gMusic
.Pause(Enable
);
5957 procedure g_Game_StopAllSounds(all
: Boolean);
5961 if gTriggers
<> nil then
5962 for i
:= 0 to High(gTriggers
) do
5963 with gTriggers
[i
] do
5964 if (TriggerType
= TRIGGER_SOUND
) and
5968 if gMusic
<> nil then
5975 procedure g_Game_UpdateTriggerSounds();
5979 if gTriggers
<> nil then
5980 for i
:= 0 to High(gTriggers
) do
5981 with gTriggers
[i
] do
5982 if (TriggerType
= TRIGGER_SOUND
) and
5985 Sound
.IsPlaying() then
5987 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
5988 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
5990 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
5991 Sound
.SetVolume(Data
.Volume
/255.0);
5994 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
5998 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6001 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6006 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6011 if gSpectMode
<> SPECT_PLAYERS
then
6013 if gSpectPID1
= UID
then
6018 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6025 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6030 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6035 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6040 if gSpectMode
<> SPECT_PLAYERS
then
6042 Pl
:= g_Player_Get(gSpectPID1
);
6043 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6048 if gSpectViewTwo
then
6050 Pl
:= g_Player_Get(gSpectPID2
);
6051 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6059 procedure g_Game_Message(Msg
: string; Time
: Word);
6061 MessageText
:= b_Text_Format(Msg
);
6062 MessageTime
:= Time
;
6065 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6074 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6078 if goodsnd
[a
].IsPlaying() then
6081 goodsnd
[Random(4)].Play();
6084 procedure g_Game_Announce_KillCombo(Param
: Integer);
6091 UID
:= Param
and $FFFF;
6096 Pl
:= g_Player_Get(UID
);
6105 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6109 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6113 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6117 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6125 if not g_Game_IsWatchedPlayer(UID
) then
6128 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6132 if killsnd
[n
].IsPlaying() then
6137 procedure g_Game_StartVote(Command
, Initiator
: string);
6141 if not gVotesEnabled
then Exit
;
6142 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6143 if gVoteInProgress
or gVotePassed
then
6145 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6146 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6149 gVoteInProgress
:= True;
6150 gVotePassed
:= False;
6151 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6154 gVoteCommand
:= Command
;
6156 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6157 Need
:= Floor((NetClientCount
+1)/2.0)+1
6159 Need
:= Floor(NetClientCount
/2.0)+1;
6160 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6161 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6164 procedure g_Game_CheckVote
;
6168 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6169 if not gVoteInProgress
then Exit
;
6171 if (gTime
>= gVoteTimer
) then
6173 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6174 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6176 Need
:= Floor(NetClientCount
/2.0) + 1;
6177 if gVoteCount
>= Need
then
6179 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6180 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6181 gVotePassed
:= True;
6182 gVoteCmdTimer
:= gTime
+ 5000;
6186 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6187 MH_SEND_VoteEvent(NET_VE_FAILED
);
6189 if NetClients
<> nil then
6190 for I
:= Low(NetClients
) to High(NetClients
) do
6191 if NetClients
[i
].Used
then
6192 NetClients
[i
].Voted
:= False;
6193 gVoteInProgress
:= False;
6199 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6200 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6202 Need
:= Floor(NetClientCount
/2.0) + 1;
6203 if gVoteCount
>= Need
then
6205 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6206 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6207 gVoteInProgress
:= False;
6208 gVotePassed
:= True;
6209 gVoteCmdTimer
:= gTime
+ 5000;
6212 if NetClients
<> nil then
6213 for I
:= Low(NetClients
) to High(NetClients
) do
6214 if NetClients
[i
].Used
then
6215 NetClients
[i
].Voted
:= False;
6220 procedure g_Game_LoadMapList(FileName
: string);
6228 if not FileExists(FileName
) then Exit
;
6230 AssignFile(ListFile
, FileName
);
6232 while not EOF(ListFile
) do
6234 ReadLn(ListFile
, s
);
6237 if s
= '' then Continue
;
6239 SetLength(MapList
, Length(MapList
)+1);
6240 MapList
[High(MapList
)] := s
;
6242 CloseFile(ListFile
);
6245 procedure g_Game_SetDebugMode();
6248 // ×èòû (äàæå â ñâîåé èãðå):
6252 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6256 if Length(LoadingStat
.Msgs
) = 0 then
6262 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6263 if NextMsg
= Length(Msgs
) then
6265 for i
:= 0 to High(Msgs
)-1 do
6266 Msgs
[i
] := Msgs
[i
+1];
6274 Msgs
[NextMsg
-1] := Text;
6280 g_ActiveWindow
:= nil;
6285 procedure g_Game_StepLoading();
6291 if (ShowCount
> LOADING_SHOW_STEP
) then
6299 procedure g_Game_ClearLoading();
6308 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6309 if len
< 1 then len
:= 1;
6310 SetLength(Msgs
, len
);
6311 for len
:= Low(Msgs
) to High(Msgs
) do
6317 procedure Parse_Params(var pars
: TParamStrValues
);
6324 while i
<= ParamCount
do
6327 if (s
[1] = '-') and (Length(s
) > 1) then
6329 if (s
[2] = '-') and (Length(s
) > 2) then
6330 begin // Îäèíî÷íûé ïàðàìåòð
6331 SetLength(pars
, Length(pars
) + 1);
6332 with pars
[High(pars
)] do
6334 Name
:= LowerCase(s
);
6339 if (i
< ParamCount
) then
6340 begin // Ïàðàìåòð ñî çíà÷åíèåì
6342 SetLength(pars
, Length(pars
) + 1);
6343 with pars
[High(pars
)] do
6345 Name
:= LowerCase(s
);
6346 Value
:= LowerCase(ParamStr(i
));
6355 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6360 for i
:= 0 to High(pars
) do
6361 if pars
[i
].Name
= aName
then
6363 Result
:= pars
[i
].Value
;
6368 procedure g_Game_Process_Params();
6370 pars
: TParamStrValues
;
6373 LimT
, LimS
: Integer;
6384 s
:= Find_Param_Value(pars
, '--debug');
6386 g_Game_SetDebugMode();
6388 // Connect when game loads
6389 ip
:= Find_Param_Value(pars
, '-connect');
6393 s
:= Find_Param_Value(pars
, '-port');
6394 if (s
= '') or not TryStrToInt(s
, Port
) then
6397 s
:= Find_Param_Value(pars
, '-pw');
6399 g_Game_StartClient(ip
, Port
, s
);
6403 // Start map when game loads:
6404 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6405 if isWadPath(map
) then
6408 s
:= Find_Param_Value(pars
, '-gm');
6409 GMode
:= g_Game_TextToMode(s
);
6410 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6411 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6414 s
:= Find_Param_Value(pars
, '-limt');
6415 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6421 s
:= Find_Param_Value(pars
, '-lims');
6422 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6428 s
:= Find_Param_Value(pars
, '-lives');
6429 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6435 s
:= Find_Param_Value(pars
, '-opt');
6437 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6439 Opt
:= StrToIntDef(s
, 0);
6441 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6444 s
:= Find_Param_Value(pars
, '--close');
6448 // Delete test map after play:
6449 s
:= Find_Param_Value(pars
, '--testdelete');
6452 gMapToDelete
:= MapsDir
+ map
;
6453 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6457 // Delete temporary WAD after play:
6458 s
:= Find_Param_Value(pars
, '--tempdelete');
6461 gMapToDelete
:= MapsDir
+ map
;
6462 gTempDelete
:= True;
6465 // Number of players:
6466 s
:= Find_Param_Value(pars
, '-pl');
6470 n
:= StrToIntDef(s
, 1);
6473 s
:= Find_Param_Value(pars
, '-port');
6474 if (s
= '') or not TryStrToInt(s
, Port
) then
6475 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6477 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6480 // Execute script when game loads:
6481 s
:= Find_Param_Value(pars
, '-exec');
6484 if Pos(':\', s
) = 0 then
6485 s
:= GameDir
+ '/' + s
;
6490 if IOResult
<> 0 then
6492 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6493 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6497 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6498 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6503 if IOResult
<> 0 then
6505 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6506 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6510 if Pos('#', s
) <> 1 then // script comment
6511 g_Console_Process(s
, True);