1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, wadreader
, md5
, xprofiler
;
26 TGameSettings
= record
42 TDelayedEvent
= record
50 TPlayerSettings
= record
69 function g_Game_IsNet(): Boolean;
70 function g_Game_IsServer(): Boolean;
71 function g_Game_IsClient(): Boolean;
72 procedure g_Game_Init();
73 procedure g_Game_Free();
74 procedure g_Game_LoadData();
75 procedure g_Game_FreeData();
76 procedure g_Game_Update();
77 procedure g_Game_Draw();
78 procedure g_Game_Quit();
79 procedure g_Game_SetupScreenSize();
80 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
81 function g_Game_ModeToText(Mode
: Byte): string;
82 function g_Game_TextToMode(Mode
: string): Byte;
83 procedure g_Game_ExecuteEvent(Name
: String);
84 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
85 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
86 procedure g_Game_RemovePlayer();
87 procedure g_Game_Spectate();
88 procedure g_Game_SpectateCenterView();
89 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
90 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
91 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
92 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
93 procedure g_Game_Restart();
94 procedure g_Game_RestartLevel();
95 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
96 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
97 procedure g_Game_SaveOptions();
98 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
99 procedure g_Game_ChangeMap(MapPath
: String);
100 procedure g_Game_ExitLevel(Map
: Char16
);
101 function g_Game_GetFirstMap(WAD
: String): String;
102 function g_Game_GetNextMap(): String;
103 procedure g_Game_NextLevel();
104 procedure g_Game_Pause(Enable
: Boolean);
105 procedure g_Game_InGameMenu(Show
: Boolean);
106 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
107 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
108 procedure g_Game_Message(Msg
: String; Time
: Word);
109 procedure g_Game_LoadMapList(FileName
: String);
110 procedure g_Game_PauseAllSounds(Enable
: Boolean);
111 procedure g_Game_StopAllSounds(all
: Boolean);
112 procedure g_Game_UpdateTriggerSounds();
113 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
114 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
115 procedure g_Game_Announce_KillCombo(Param
: Integer);
116 procedure g_Game_StartVote(Command
, Initiator
: string);
117 procedure g_Game_CheckVote
;
118 procedure g_TakeScreenShot();
119 procedure g_FatalError(Text: String);
120 procedure g_SimpleError(Text: String);
121 function g_Game_IsTestMap(): Boolean;
122 procedure g_Game_DeleteTestMap();
123 procedure GameCVars(P
: SArray
);
124 procedure GameCommands(P
: SArray
);
125 procedure GameCheats(P
: SArray
);
126 procedure DebugCommands(P
: SArray
);
127 procedure ProfilerCommands(P
: SArray
);
128 procedure g_Game_Process_Params
;
129 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
130 procedure g_Game_StepLoading();
131 procedure g_Game_ClearLoading();
132 procedure g_Game_SetDebugMode();
133 procedure DrawLoadingStat();
135 { procedure SetWinPause(Enable: Boolean); }
140 LOADING_SHOW_STEP
= 100;
141 LOADING_INTERLINE
= 20;
156 MESSAGE_DIKEY
= WM_USER
+ 1;
161 EXIT_ENDLEVELSINGLE
= 4;
162 EXIT_ENDLEVELCUSTOM
= 5;
164 GAME_OPTION_RESERVED
= 1;
165 GAME_OPTION_TEAMDAMAGE
= 2;
166 GAME_OPTION_ALLOWEXIT
= 4;
167 GAME_OPTION_WEAPONSTAY
= 8;
168 GAME_OPTION_MONSTERS
= 16;
169 GAME_OPTION_BOTVSPLAYER
= 32;
170 GAME_OPTION_BOTVSMONSTER
= 64;
175 STATE_INTERCUSTOM
= 3;
176 STATE_INTERSINGLE
= 4;
182 LMS_RESPAWN_NONE
= 0;
183 LMS_RESPAWN_WARMUP
= 1;
184 LMS_RESPAWN_FINAL
= 2;
200 CONFIG_FILENAME
= 'Doom2DF.cfg';
201 LOG_FILENAME
= 'Doom2DF.log';
203 TEST_MAP_NAME
= '$$$_TEST_$$$';
205 STD_PLAYER_MODEL
= 'Doomer';
209 gGameSettings
: TGameSettings
;
210 gPlayer1Settings
: TPlayerSettings
;
211 gPlayer2Settings
: TPlayerSettings
;
213 gPlayerScreenSize
: TPoint
;
214 gPlayer1ScreenCoord
: TPoint
;
215 gPlayer2ScreenCoord
: TPoint
;
216 gPlayer1
: TPlayer
= nil;
217 gPlayer2
: TPlayer
= nil;
218 gPlayerDrawn
: TPlayer
= nil;
220 gSwitchGameMode
: Byte = GM_DM
;
221 gHearPoint1
, gHearPoint2
: THearPoint
;
222 gSoundEffectsDF
: Boolean = False;
223 gSoundTriggerTime
: Word = 0;
224 gAnnouncer
: Byte = ANNOUNCE_NONE
;
225 goodsnd
: array[0..3] of TPlayableSound
;
226 killsnd
: array[0..3] of TPlayableSound
;
227 gDefInterTime
: ShortInt = -1;
228 gInterEndTime
: LongWord = 0;
229 gInterTime
: LongWord = 0;
230 gServInterTime
: Byte = 0;
231 gGameStartTime
: LongWord = 0;
232 gTotalMonsters
: Integer = 0;
234 gShowTime
: Boolean = True;
235 gShowFPS
: Boolean = False;
236 gShowGoals
: Boolean = True;
237 gShowStat
: Boolean = True;
238 gShowKillMsg
: Boolean = True;
239 gShowLives
: Boolean = True;
240 gShowPing
: Boolean = False;
241 gShowMap
: Boolean = False;
243 gState
: Byte = STATE_NONE
;
245 sWidth
, sHeight
: Word;
246 gSpectMode
: Byte = SPECT_NONE
;
247 gSpectHUD
: Boolean = True;
248 gSpectKeyPress
: Boolean = False;
249 gSpectX
: Integer = 0;
250 gSpectY
: Integer = 0;
251 gSpectStep
: Byte = 8;
252 gSpectViewTwo
: Boolean = False;
253 gSpectPID1
: Integer = -1;
254 gSpectPID2
: Integer = -1;
255 gMusic
: TMusic
= nil;
256 gLoadGameMode
: Boolean;
257 gCheats
: Boolean = False;
258 gMapOnce
: Boolean = False;
259 gMapToDelete
: String;
260 gTempDelete
: Boolean = False;
261 gLastMap
: Boolean = False;
262 gWinPosX
, gWinPosY
: Integer;
263 gWinSizeX
, gWinSizeY
: Integer;
264 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
265 gWinActive
: Boolean = True; // by default window is active, lol
266 gResolutionChange
: Boolean = False;
267 gRC_Width
, gRC_Height
: Word;
268 gRC_FullScreen
, gRC_Maximized
: Boolean;
269 gLanguageChange
: Boolean = False;
270 gDebugMode
: Boolean = False;
271 g_debug_Sounds
: Boolean = False;
272 g_debug_Frames
: Boolean = False;
273 g_debug_WinMsgs
: Boolean = False;
274 g_debug_MonsterOff
: Boolean = False;
275 g_debug_BotAIOff
: Byte = 0;
276 g_debug_HealthBar
: Boolean = False;
277 g_Debug_Player
: Boolean = False;
278 gCoopMonstersKilled
: Word = 0;
279 gCoopSecretsFound
: Word = 0;
280 gCoopTotalMonstersKilled
: Word = 0;
281 gCoopTotalSecretsFound
: Word = 0;
282 gCoopTotalMonsters
: Word = 0;
283 gCoopTotalSecrets
: Word = 0;
284 gStatsOff
: Boolean = False;
285 gStatsPressed
: Boolean = False;
286 gExitByTrigger
: Boolean = False;
287 gNextMap
: String = '';
288 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
289 gLMSRespawnTime
: Cardinal = 0;
290 gLMSSoftSpawn
: Boolean = False;
291 gMissionFailed
: Boolean = False;
292 gVoteInProgress
: Boolean = False;
293 gVotePassed
: Boolean = False;
294 gVoteCommand
: string = '';
295 gVoteTimer
: Cardinal = 0;
296 gVoteCmdTimer
: Cardinal = 0;
297 gVoteCount
: Integer = 0;
298 gVoteTimeout
: Cardinal = 30;
299 gVoted
: Boolean = False;
300 gVotesEnabled
: Boolean = True;
301 gEvents
: Array of TGameEvent
;
302 gDelayedEvents
: Array of TDelayedEvent
;
304 // move button values:
305 // bits 0-1: l/r state:
306 // 0: neither left, nor right pressed
309 // bits 4-5: l/r state when strafe was pressed
310 P1MoveButton
: Byte = 0;
311 P2MoveButton
: Byte = 0;
313 g_profile_frame_update
: Boolean = false;
314 g_profile_frame_draw
: Boolean = true;
316 procedure g_ResetDynlights ();
317 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
318 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
323 g_textures
, g_main
, g_window
, g_menu
,
324 e_input
, e_log
, g_console
, g_items
, g_map
,
325 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
326 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
327 BinEditor
, g_language
, g_net
, SDL
,
328 ENet
, e_fixedbuffer
, g_netmsg
, g_netmaster
, GL
, GLExt
,
332 // ////////////////////////////////////////////////////////////////////////// //
334 profileFrameDraw
: TProfiler
= nil;
337 // ////////////////////////////////////////////////////////////////////////// //
340 x
, y
, radius
: Integer;
343 exploRadius
: Integer;
347 g_dynLights
: array of TDynLight
= nil;
348 g_dynLightCount
: Integer = 0;
349 g_playerLight
: Boolean = false;
351 procedure g_ResetDynlights ();
355 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
357 for idx
:= 0 to g_dynLightCount
-1 do
359 if g_dynLights
[idx
].exploCount
= -666 then
366 Inc(g_dynLights
[idx
].exploCount
);
367 if (g_dynLights
[idx
].exploCount
< 10) then
369 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
370 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
371 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
372 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
377 g_dynLightCount
:= lnum
;
380 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
382 if not gwin_has_stencil
then exit
;
383 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
384 g_dynLights
[g_dynLightCount
].x
:= x
;
385 g_dynLights
[g_dynLightCount
].y
:= y
;
386 g_dynLights
[g_dynLightCount
].radius
:= radius
;
387 g_dynLights
[g_dynLightCount
].r
:= r
;
388 g_dynLights
[g_dynLightCount
].g
:= g
;
389 g_dynLights
[g_dynLightCount
].b
:= b
;
390 g_dynLights
[g_dynLightCount
].a
:= a
;
391 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
392 Inc(g_dynLightCount
);
395 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
397 if not gwin_has_stencil
then exit
;
398 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
399 g_dynLights
[g_dynLightCount
].x
:= x
;
400 g_dynLights
[g_dynLightCount
].y
:= y
;
401 g_dynLights
[g_dynLightCount
].radius
:= 0;
402 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
403 g_dynLights
[g_dynLightCount
].r
:= r
;
404 g_dynLights
[g_dynLightCount
].g
:= g
;
405 g_dynLights
[g_dynLightCount
].b
:= b
;
406 g_dynLights
[g_dynLightCount
].a
:= 0;
407 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
408 Inc(g_dynLightCount
);
412 // ////////////////////////////////////////////////////////////////////////// //
414 procedure drawProfiles (x, y: Integer; title: AnsiString); overload;
420 procedure drawItems ();
423 e_TextureFontPrintEx(x+2+4*xprofItLevel, yy, Format('%s: %d', [xprofItName, Integer(xprofItMicro)]), gStdFont, 255, 255, 0, 1, false);
425 if xprofItHasChildren then
431 until not xprofItNext();
435 procedure drawItems ();
439 for ii := 0 to xprofTotalCount-1 do
441 e_TextureFontPrintEx(x+2+4*xprofLevelAt(ii), yy, Format('%s: %d', [xprofNameAt(ii), Integer(xprofMicroAt(ii))]), gStdFont, 255, 255, 0, 1, false);
448 //if not xprofItReset() then exit;
449 if (xprofTotalCount = 0) then exit;
451 hgt := 16+2+xprofTotalCount*(16+2); // title, items
453 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
454 e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
456 e_TextureFontPrintEx(x+2, y+2, Format('%s: %d', [title, Integer(xprofTotalMicro)]), gStdFont, 255, 255, 0, 1, false);
463 procedure drawProfiles (x
, y
: Integer; prof
: TProfiler
);
469 if (prof
= nil) then exit
;
471 if (length(prof
.bars
) = 0) then exit
;
473 hgt
:= length(prof
.bars
)*(16+2);
474 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
475 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
477 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
478 e_DrawFillQuad(x
, y
, x
+wdt
-1, y
+hgt
-1, 20, 20, 20, 0, B_NONE
);
481 for ii
:= 0 to High(prof
.bars
) do
483 e_TextureFontPrintEx(x
+2+4*prof
.bars
[ii
].level
, yy
, Format('%s: %d', [prof
.bars
[ii
].name
, prof
.bars
[ii
].value
]), gStdFont
, 255, 255, 0, 1, false);
489 // ////////////////////////////////////////////////////////////////////////// //
491 TEndCustomGameStat
= record
492 PlayerStat
: TPlayerStatArray
;
496 Map
, MapName
: String;
499 TEndSingleGameStat
= record
500 PlayerStat
: Array [0..1] of record
506 TotalSecrets
: Integer;
509 TLoadingStat
= record
513 Msgs
: Array of String;
517 TParamStrValue
= record
522 TParamStrValues
= Array of TParamStrValue
;
525 INTER_ACTION_TEXT
= 1;
526 INTER_ACTION_PIC
= 2;
527 INTER_ACTION_MUSIC
= 3;
531 FPSCounter
, UPSCounter
: Word;
532 FPSTime
, UPSTime
: LongWord;
533 DataLoaded
: Boolean = False;
534 LastScreenShot
: Int64;
535 IsDrawStat
: Boolean = False;
536 CustomStat
: TEndCustomGameStat
;
537 SingleStat
: TEndSingleGameStat
;
538 LoadingStat
: TLoadingStat
;
539 EndingGameCounter
: Byte = 0;
542 MapList
: SArray
= nil;
543 MapIndex
: Integer = -1;
549 text: Array of ShortString;
550 anim
: Array of ShortString;
551 pic
: Array of ShortString;
552 mus
: Array of ShortString;
554 triggers
: Array of record
556 actions
: Array of record
557 action
, p1
, p2
: Integer;
560 cur_trigger
: Integer;
573 function Compare(a
, b
: TPlayerStat
): Integer;
575 if a
.Spectator
then Result
:= 1
576 else if b
.Spectator
then Result
:= -1
577 else if a
.Frags
< b
.Frags
then Result
:= 1
578 else if a
.Frags
> b
.Frags
then Result
:= -1
579 else if a
.Deaths
< b
.Deaths
then Result
:= -1
580 else if a
.Deaths
> b
.Deaths
then Result
:= 1
581 else if a
.Kills
< b
.Kills
then Result
:= -1
585 procedure SortGameStat(var stat
: TPlayerStatArray
);
590 if stat
= nil then Exit
;
592 for I
:= High(stat
) downto Low(stat
) do
593 for J
:= Low(stat
) to High(stat
) - 1 do
594 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
597 stat
[J
] := stat
[J
+ 1];
602 function g_Game_ModeToText(Mode
: Byte): string;
606 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
607 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
608 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
609 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
610 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
614 function g_Game_TextToMode(Mode
: string): Byte;
617 Mode
:= UpperCase(Mode
);
618 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
623 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
628 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
633 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
638 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
645 function g_Game_IsNet(): Boolean;
647 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
650 function g_Game_IsServer(): Boolean;
652 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
655 function g_Game_IsClient(): Boolean;
657 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
660 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
667 Result
.name
:= ExtractFileName(WAD
);
668 Result
.description
:= '';
671 w
:= TWADFile
.Create();
674 if not w
.GetResource('INTERSCRIPT', p
, len
) then
680 cfg
:= TConfig
.CreateMem(p
, len
);
681 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
682 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
683 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
684 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
690 procedure g_Game_FreeWAD();
694 for a
:= 0 to High(MegaWAD
.res
.pic
) do
695 if MegaWAD
.res
.pic
[a
] <> '' then
696 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
698 for a
:= 0 to High(MegaWAD
.res
.mus
) do
699 if MegaWAD
.res
.mus
[a
] <> '' then
700 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
702 MegaWAD
.res
.pic
:= nil;
703 MegaWAD
.res
.text := nil;
704 MegaWAD
.res
.anim
:= nil;
705 MegaWAD
.res
.mus
:= nil;
706 MegaWAD
.triggers
:= nil;
708 g_Texture_Delete('TEXTURE_endpic');
709 g_Sound_Delete('MUSIC_endmus');
711 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
712 gGameSettings
.WAD
:= '';
715 procedure g_Game_LoadWAD(WAD
: string);
724 gGameSettings
.WAD
:= WAD
;
725 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
728 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
730 w
:= TWADFile
.Create();
731 w
.ReadFile(MapsDir
+ WAD
);
733 if not w
.GetResource('INTERSCRIPT', p
, len
) then
739 cfg
:= TConfig
.CreateMem(p
, len
);
744 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
745 if s = '' then Break;
748 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
749 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
751 g_Texture_CreateWADEx(s, s);
757 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
758 if s = '' then Break;
761 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
762 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
764 g_Music_CreateWADEx(s, s);
767 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
768 if MegaWAD
.endpic
<> '' then
770 s
:= g_ExtractWadName(MegaWAD
.endpic
);
771 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
772 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
774 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
775 if MegaWAD
.endmus
<> '' then
777 s
:= g_ExtractWadName(MegaWAD
.endmus
);
778 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
779 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
787 {procedure start_trigger(t: string);
791 function next_trigger(): Boolean;
795 procedure DisableCheats();
801 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
802 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
803 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
804 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
807 procedure g_Game_ExecuteEvent(Name
: String);
813 if gEvents
= nil then
815 for a
:= 0 to High(gEvents
) do
816 if gEvents
[a
].Name
= Name
then
818 if gEvents
[a
].Command
<> '' then
819 g_Console_Process(gEvents
[a
].Command
, True);
824 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
829 if gDelayedEvents
<> nil then
830 for a
:= 0 to High(gDelayedEvents
) do
831 if not gDelayedEvents
[a
].Pending
then
838 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
839 n
:= High(gDelayedEvents
);
841 gDelayedEvents
[n
].Pending
:= True;
842 gDelayedEvents
[n
].DEType
:= DEType
;
843 gDelayedEvents
[n
].DENum
:= Num
;
844 gDelayedEvents
[n
].DEStr
:= Str
;
845 if DEType
= DE_GLOBEVENT
then
846 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
848 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
857 if g_Game_IsNet
and g_Game_IsServer
then
858 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
864 g_Game_StopAllSounds(False);
869 EndingGameCounter
:= 0;
870 g_ActiveWindow
:= nil;
872 gLMSRespawn
:= LMS_RESPAWN_NONE
;
873 gLMSRespawnTime
:= 0;
876 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
881 begin // Ýòî áûë òåñò
885 begin // Âûõîä â ãëàâíîå ìåíþ
886 gMusic
.SetByName('MUSIC_MENU');
888 if gState
<> STATE_SLIST
then
890 g_GUI_ShowWindow('MainMenu');
891 gState
:= STATE_MENU
;
894 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
895 slReturnPressed
:= True;
896 if g_Net_Slist_Fetch(slCurrent
) then
898 if slCurrent
= nil then
899 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
902 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
905 g_Game_ExecuteEvent('ongameend');
909 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
911 if not g_Game_IsClient
then g_Game_Restart();
914 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
916 // Ñòàòèñòèêà Ñâîåé èãðû:
917 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
919 CustomStat
.GameTime
:= gTime
;
920 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
921 CustomStat
.MapName
:= gMapInfo
.Name
;
922 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
923 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
924 CustomStat
.TeamStat
:= gTeamStat
;
926 CustomStat
.PlayerStat
:= nil;
928 // Ñòàòèñòèêà èãðîêîâ:
929 if gPlayers
<> nil then
931 for a
:= 0 to High(gPlayers
) do
932 if gPlayers
[a
] <> nil then
934 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
935 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
937 Name
:= gPlayers
[a
].Name
;
938 Frags
:= gPlayers
[a
].Frags
;
939 Deaths
:= gPlayers
[a
].Death
;
940 Kills
:= gPlayers
[a
].Kills
;
941 Team
:= gPlayers
[a
].Team
;
942 Color
:= gPlayers
[a
].Model
.Color
;
943 Spectator
:= gPlayers
[a
].FSpectator
;
947 SortGameStat(CustomStat
.PlayerStat
);
950 g_Game_ExecuteEvent('onmapend');
953 EndingGameCounter
:= 255;
954 gState
:= STATE_FOLD
;
956 if gDefInterTime
< 0 then
957 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
959 gInterEndTime
:= gDefInterTime
* 1000;
962 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
964 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
965 SingleStat
.GameTime
:= gTime
;
966 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
967 SingleStat
.TotalSecrets
:= gSecretsCount
;
968 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
969 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
970 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
971 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
972 if SingleStat
.TwoPlayers
then
974 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
975 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
978 g_Game_ExecuteEvent('onmapend');
981 if gNextMap
<> '' then
983 gMusic
.SetByName('MUSIC_INTERMUS');
985 gState
:= STATE_INTERSINGLE
;
987 g_Game_ExecuteEvent('oninter');
989 else // Áîëüøå íåò êàðò
992 EndingGameCounter
:= 255;
993 gState
:= STATE_FOLD
;
998 // Îêîí÷àíèå îáðàáîòàíî:
999 if gExit
<> EXIT_QUIT
then
1003 procedure DrawStat();
1005 pc
, x
, y
, w
, h
: Integer;
1006 w1
, w2
, w3
, w4
: Integer;
1008 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1011 stat
: TPlayerStatArray
;
1018 pc
:= g_Player_GetCount
;
1019 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1021 w
:= gScreenWidth
-(gScreenWidth
div 5);
1022 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1025 h
:= 40+ch
*5+(ch
+8)*pc
;
1026 x
:= (gScreenWidth
div 2)-(w
div 2);
1027 y
:= (gScreenHeight
div 2)-(h
div 2);
1029 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1030 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1032 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1033 map
:= g_ExtractFileName(gMapInfo
.Map
);
1034 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1036 case gGameSettings
.GameMode
of
1039 if gGameSettings
.MaxLives
= 0 then
1040 s1
:= _lc
[I_GAME_DM
]
1042 s1
:= _lc
[I_GAME_LMS
];
1043 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1044 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1049 if gGameSettings
.MaxLives
= 0 then
1050 s1
:= _lc
[I_GAME_TDM
]
1052 s1
:= _lc
[I_GAME_TLMS
];
1053 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1054 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1059 s1
:= _lc
[I_GAME_CTF
];
1060 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1061 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1066 if gGameSettings
.MaxLives
= 0 then
1067 s1
:= _lc
[I_GAME_COOP
]
1069 s1
:= _lc
[I_GAME_SURV
];
1070 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1071 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1082 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1084 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1086 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1088 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1089 gStdFont
, 200, 200, 200, 1);
1091 if NetMode
= NET_SERVER
then
1092 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1094 if NetMode
= NET_CLIENT
then
1095 e_TextureFontPrintEx(x
+8, y
+ 8,
1096 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1100 stat
:= g_Player_GetStats();
1103 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1104 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1106 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1108 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1112 for a
:= TEAM_RED
to TEAM_BLUE
do
1114 if a
= TEAM_RED
then
1116 s1
:= _lc
[I_GAME_TEAM_RED
];
1123 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1129 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1130 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1131 gStdFont
, r
, g
, b
, 1);
1133 _y
:= _y
+ch
+(ch
div 4);
1134 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1135 _y
:= _y
+(ch
div 4);
1137 for aa
:= 0 to High(stat
) do
1138 if stat
[aa
].Team
= a
then
1154 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1156 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1158 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1160 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1167 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1170 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1171 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1172 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1173 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1176 for aa
:= 0 to High(stat
) do
1190 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1191 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1193 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1195 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1197 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1199 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1205 procedure g_Game_Init();
1211 gTempDelete
:= False;
1213 sfsGCDisable(); // temporary disable removing of temporary volumes
1216 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1217 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1218 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1219 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1221 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1222 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1223 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1225 g_Game_ClearLoading();
1226 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1227 g_Game_SetLoadingText('', 0, False);
1229 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1232 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1233 g_PlayerModel_LoadData();
1235 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1237 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1238 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1239 until FindNext(SR
) <> 0;
1242 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1244 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1245 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1246 until FindNext(SR
) <> 0;
1249 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1251 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1252 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1253 until FindNext(SR
) <> 0;
1259 LastScreenShot
:= 0;
1261 {e_MouseInfo.Accel := 1.0;}
1263 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1266 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1267 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1268 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1269 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1270 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1272 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1275 gMusic
:= TMusic
.Create();
1276 gMusic
.SetByName('MUSIC_MENU');
1279 gGameSettings
.WarmupTime
:= 30;
1281 gState
:= STATE_MENU
;
1283 SetLength(gEvents
, 6);
1284 gEvents
[0].Name
:= 'ongamestart';
1285 gEvents
[1].Name
:= 'ongameend';
1286 gEvents
[2].Name
:= 'onmapstart';
1287 gEvents
[3].Name
:= 'onmapend';
1288 gEvents
[4].Name
:= 'oninter';
1289 gEvents
[5].Name
:= 'onwadend';
1291 sfsGCEnable(); // enable releasing unused volumes
1295 procedure g_Game_Free();
1297 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1298 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1302 g_Player_RemoveAllCorpses();
1304 gGameSettings
.GameType
:= GT_NONE
;
1305 if gGameSettings
.GameMode
= GM_SINGLE
then
1306 gGameSettings
.GameMode
:= GM_DM
;
1307 gSwitchGameMode
:= gGameSettings
.GameMode
;
1310 gExitByTrigger
:= False;
1313 function IsActivePlayer(p
: TPlayer
): Boolean;
1318 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1321 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1328 if gPlayers
= nil then
1330 for a
:= Low(gPlayers
) to High(gPlayers
) do
1331 if IsActivePlayer(gPlayers
[a
]) then
1333 if gPlayers
[a
].UID
<> ID
then
1335 Result
:= gPlayers
[a
];
1340 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1346 if gPlayers
= nil then
1350 for a
:= Low(gPlayers
) to High(gPlayers
) do
1351 if IsActivePlayer(gPlayers
[a
]) then
1353 SetLength(ids
, Length(ids
) + 1);
1354 ids
[High(ids
)] := gPlayers
[a
].UID
;
1355 if gPlayers
[a
].UID
= Skip
then
1358 if Length(ids
) = 0 then
1363 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1366 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1372 if gPlayers
= nil then
1376 for a
:= Low(gPlayers
) to High(gPlayers
) do
1377 if IsActivePlayer(gPlayers
[a
]) then
1379 SetLength(ids
, Length(ids
) + 1);
1380 ids
[High(ids
)] := gPlayers
[a
].UID
;
1381 if gPlayers
[a
].UID
= Skip
then
1384 if Length(ids
) = 0 then
1387 Result
:= ids
[Length(ids
) - 1]
1389 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1392 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1394 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1395 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1399 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1405 if (plr
= nil) then exit
;
1406 if (p2hack
) then time
:= 1000 else time
:= 1;
1407 strafeDir
:= MoveButton
shr 4;
1408 MoveButton
:= MoveButton
and $0F;
1411 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1412 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1413 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1415 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1416 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1417 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1419 // if we have "strafe" key, turn off old strafe mechanics
1420 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1422 // new strafe mechanics
1423 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1424 // now set direction according to strafe (reversed)
1425 if (strafeDir
= 2) then plr
.SetDirection(D_LEFT
)
1426 else if (strafeDir
= 1) then plr
.SetDirection(D_RIGHT
);
1430 strafeDir
:= 0; // not strafing anymore
1431 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1432 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1433 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1434 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1435 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1436 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1439 // fix movebutton state
1440 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1442 // Îñòàëüíûå êëàâèøè:
1443 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1444 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1445 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1446 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1447 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1448 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1449 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1451 for i
:= 0 to High(KeyWeapon
) do
1452 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1453 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1456 // HACK: add dynlight here
1457 if gwin_k8_enable_light_experiments
then
1459 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1461 g_playerLight
:= true;
1463 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1465 g_playerLight
:= false;
1469 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1472 procedure g_Game_Update();
1474 Msg
: g_gui
.TMessage
;
1481 // Ïîðà âûêëþ÷àòü èãðó:
1482 if gExit
= EXIT_QUIT
then
1484 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1488 if gExit
= EXIT_QUIT
then
1492 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1495 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1498 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1500 gExit
:= EXIT_SIMPLE
;
1506 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1507 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1508 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1509 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1511 if g_Game_IsNet
and g_Game_IsServer
then
1513 gInterTime
:= gInterTime
+ GAME_TICK
;
1514 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1515 if a
<> gServInterTime
then
1517 gServInterTime
:= a
;
1518 MH_SEND_TimeSync(gServInterTime
);
1522 if (not g_Game_IsClient
) and
1525 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1526 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1527 and (g_ActiveWindow
= nil)
1529 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1532 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1533 g_Game_StopAllSounds(True);
1535 if gMapOnce
then // Ýòî áûë òåñò
1536 gExit
:= EXIT_SIMPLE
1538 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1539 g_Game_ChangeMap(gNextMap
)
1540 else // Ñëåäóþùåé êàðòû íåò
1542 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1544 // Âûõîä â ãëàâíîå ìåíþ:
1546 g_GUI_ShowWindow('MainMenu');
1547 gMusic
.SetByName('MUSIC_MENU');
1549 gState
:= STATE_MENU
;
1552 // Ôèíàëüíàÿ êàðòèíêà:
1553 g_Game_ExecuteEvent('onwadend');
1555 if not gMusic
.SetByName('MUSIC_endmus') then
1556 gMusic
.SetByName('MUSIC_STDENDMUS');
1558 gState
:= STATE_ENDPIC
;
1560 g_Game_ExecuteEvent('ongameend');
1566 if gState
= STATE_INTERTEXT
then
1567 if InterText
.counter
> 0 then
1568 InterText
.counter
:= InterText
.counter
- 1;
1571 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1573 if EndingGameCounter
= 0 then
1575 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1576 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1578 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1580 g_Game_ExecuteEvent('onwadend');
1581 if not gMusic
.SetByName('MUSIC_endmus') then
1582 gMusic
.SetByName('MUSIC_STDENDMUS');
1585 gMusic
.SetByName('MUSIC_ROUNDMUS');
1588 gState
:= STATE_INTERCUSTOM
;
1590 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1592 gMusic
.SetByName('MUSIC_INTERMUS');
1594 gState
:= STATE_INTERSINGLE
;
1596 g_Game_ExecuteEvent('oninter');
1599 DecMin(EndingGameCounter
, 6, 0);
1602 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1604 if gMapOnce
then // Ýòî áûë òåñò
1606 gExit
:= EXIT_SIMPLE
;
1612 g_Serverlist_Control(slCurrent
);
1615 if g_Game_IsNet
then
1616 if not gConsoleShow
then
1617 if not gChatShow
then
1619 if g_ActiveWindow
= nil then
1621 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1622 g_Console_Chat_Switch(False)
1623 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1624 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1625 g_Console_Chat_Switch(True);
1628 if not gChatEnter
then
1629 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1630 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1633 // Ñòàòèñòèêà ïî Tab:
1635 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1636 (gGameSettings
.GameType
<> GT_SINGLE
) and
1637 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1640 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1642 // Âðåìÿ += 28 ìèëëèñåêóíä:
1643 gTime
:= gTime
+ GAME_TICK
;
1645 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1646 if MessageTime
= 0 then
1648 if MessageTime
> 0 then
1649 MessageTime
:= MessageTime
- 1;
1651 if (g_Game_IsServer
) then
1653 // Áûë çàäàí ëèìèò âðåìåíè:
1654 if (gGameSettings
.TimeLimit
> 0) then
1655 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1656 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1661 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1662 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1663 g_Game_RestartRound(gLMSSoftSpawn
);
1665 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1666 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1668 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1670 g_Console_Process(gVoteCommand
);
1672 gVotePassed
:= False;
1675 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1676 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1677 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1678 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1679 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1681 // Áûë çàäàí ëèìèò ïîáåä:
1682 if (gGameSettings
.GoalLimit
> 0) then
1686 if gGameSettings
.GameMode
= GM_DM
then
1687 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1688 for i
:= 0 to High(gPlayers
) do
1689 if gPlayers
[i
] <> nil then
1690 if gPlayers
[i
].Frags
> b
then
1691 b
:= gPlayers
[i
].Frags
;
1694 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1695 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1696 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1699 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1700 if b
>= gGameSettings
.GoalLimit
then
1707 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1708 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1709 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1710 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1712 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1713 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1714 end // if not console
1717 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1719 // process weapon switch queue
1723 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1724 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1726 if not gSpectKeyPress
then
1728 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1730 // switch spect mode
1732 SPECT_NONE
: ; // not spectator
1734 SPECT_MAPVIEW
: Inc(gSpectMode
);
1735 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1737 gSpectKeyPress
:= True;
1739 if gSpectMode
= SPECT_MAPVIEW
then
1741 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1742 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1743 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1744 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1745 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1746 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1747 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1748 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1749 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1752 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1753 gSpectKeyPress
:= True;
1755 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1758 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1759 gSpectKeyPress
:= True;
1762 if gSpectMode
= SPECT_PLAYERS
then
1764 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1767 gSpectViewTwo
:= True;
1768 gSpectKeyPress
:= True;
1770 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1772 // remove second view
1773 gSpectViewTwo
:= False;
1774 gSpectKeyPress
:= True;
1776 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1778 // prev player (view 1)
1779 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1780 gSpectKeyPress
:= True;
1782 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1784 // next player (view 1)
1785 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1786 gSpectKeyPress
:= True;
1788 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1790 // prev player (view 2)
1791 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1792 gSpectKeyPress
:= True;
1794 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1796 // next player (view 2)
1797 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1798 gSpectKeyPress
:= True;
1803 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1804 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1805 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1806 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1807 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1808 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1809 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1810 gSpectKeyPress
:= False;
1813 // Îáíîâëÿåì âñå îñòàëüíîå:
1816 g_Triggers_Update();
1818 g_Monsters_Update();
1820 g_Player_UpdateAll();
1821 g_Player_UpdatePhysicalObjects();
1822 if gGameSettings
.GameType
= GT_SERVER
then
1823 if Length(gMonstersSpawned
) > 0 then
1825 for I
:= 0 to High(gMonstersSpawned
) do
1826 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1827 SetLength(gMonstersSpawned
, 0);
1830 if (gSoundTriggerTime
> 8) then
1832 g_Game_UpdateTriggerSounds();
1833 gSoundTriggerTime
:= 0;
1836 Inc(gSoundTriggerTime
);
1838 if (NetMode
= NET_SERVER
) then
1840 Inc(NetTimeToUpdate
);
1841 Inc(NetTimeToReliable
);
1842 if NetTimeToReliable
>= NetRelupdRate
then
1844 for I
:= 0 to High(gPlayers
) do
1845 if gPlayers
[I
] <> nil then
1846 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1848 if gMonsters
<> nil then
1849 for I
:= 0 to High(gMonsters
) do
1850 if gMonsters
[I
] <> nil then
1852 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1854 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1855 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1858 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1859 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1860 (gMonsters
[I
].GameVelX
<> 0) or
1861 (gMonsters
[I
].GameVelY
<> 0) then
1862 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1865 NetTimeToReliable
:= 0;
1866 NetTimeToUpdate
:= NetUpdateRate
;
1868 else if NetTimeToUpdate
>= NetUpdateRate
then
1870 if gPlayers
<> nil then
1871 for I
:= 0 to High(gPlayers
) do
1872 if gPlayers
[I
] <> nil then
1873 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1875 if gMonsters
<> nil then
1876 for I
:= 0 to High(gMonsters
) do
1877 if gMonsters
[I
] <> nil then
1879 if (gMonsters
[I
].MonsterType
= MONSTER_BARREL
) then
1881 if (gMonsters
[I
].GameVelX
<> 0) or (gMonsters
[I
].GameVelY
<> 0) then
1882 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1885 if (gMonsters
[I
].MonsterState
<> MONSTATE_SLEEP
) then
1886 if (gMonsters
[I
].MonsterState
<> MONSTATE_DEAD
) or
1887 (gMonsters
[I
].GameVelX
<> 0) or
1888 (gMonsters
[I
].GameVelY
<> 0) then
1889 MH_SEND_MonsterPos(gMonsters
[I
].UID
);
1892 NetTimeToUpdate
:= 0;
1895 if NetUseMaster
then
1896 if gTime
>= NetTimeToMaster
then
1898 if (NetMHost
= nil) or (NetMPeer
= nil) then
1899 if not g_Net_Slist_Connect
then
1900 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1903 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1907 if NetMode
= NET_CLIENT
then
1908 MC_SEND_PlayerPos();
1909 end; // if gameOn ...
1911 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1912 if g_ActiveWindow
<> nil then
1914 w
:= e_GetFirstKeyPressed();
1916 if (w
<> IK_INVALID
) then
1918 Msg
.Msg
:= MESSAGE_DIKEY
;
1920 g_ActiveWindow
.OnMessage(Msg
);
1923 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1924 if g_ActiveWindow
<> nil then
1925 g_ActiveWindow
.Update();
1927 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1928 if gResolutionChange
then
1930 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1931 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1932 gResolutionChange
:= False;
1935 // Íóæíî ñìåíèòü ÿçûê:
1936 if gLanguageChange
then
1938 //e_WriteLog('Read language file', MSG_NOTIFY);
1939 //g_Language_Load(DataDir + gLanguage + '.txt');
1940 g_Language_Set(gLanguage
);
1942 gLanguageChange
:= False;
1946 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1947 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1948 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1951 LastScreenShot
:= GetTimer();
1954 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1955 if e_KeyPressed(IK_F10
) and
1957 (not gConsoleShow
) and
1958 (g_ActiveWindow
= nil) then
1963 Time
:= GetTimer() {div 1000};
1965 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1966 if gDelayedEvents
<> nil then
1967 for a
:= 0 to High(gDelayedEvents
) do
1968 if gDelayedEvents
[a
].Pending
and
1970 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1971 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1974 case gDelayedEvents
[a
].DEType
of
1976 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1979 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1983 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1984 if g_Game_IsNet
and g_Game_IsServer
then
1985 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1988 gDelayedEvents
[a
].Pending
:= False;
1991 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1992 UPSCounter
:= UPSCounter
+ 1;
1993 if Time
- UPSTime
>= 1000 then
2000 if gGameOn
then g_Weapon_AddDynLights();
2003 procedure g_Game_LoadData();
2005 if DataLoaded
then Exit
;
2007 e_WriteLog('Loading game data...', MSG_NOTIFY
);
2009 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2010 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2011 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2012 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2013 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2014 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2015 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
2016 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
2017 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
2018 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
2019 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
2020 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
2021 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2022 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2023 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2024 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2025 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2026 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2027 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2028 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2029 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2030 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2031 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2032 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2033 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2034 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2035 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2036 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2037 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2038 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2039 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2040 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2041 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2042 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2044 goodsnd
[0] := TPlayableSound
.Create();
2045 goodsnd
[1] := TPlayableSound
.Create();
2046 goodsnd
[2] := TPlayableSound
.Create();
2047 goodsnd
[3] := TPlayableSound
.Create();
2049 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2050 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2051 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2052 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2054 killsnd
[0] := TPlayableSound
.Create();
2055 killsnd
[1] := TPlayableSound
.Create();
2056 killsnd
[2] := TPlayableSound
.Create();
2057 killsnd
[3] := TPlayableSound
.Create();
2059 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2060 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2061 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2062 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2064 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2067 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2068 g_Weapon_LoadData();
2070 g_Monsters_LoadData();
2075 procedure g_Game_FreeData();
2077 if not DataLoaded
then Exit
;
2080 g_Weapon_FreeData();
2081 g_Monsters_FreeData();
2083 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
2085 g_Texture_Delete('NOTEXTURE');
2086 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2087 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2088 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2089 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2090 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2091 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2092 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2093 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2094 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2095 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2096 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2097 g_Frames_DeleteByName('FRAMES_TELEPORT');
2098 g_Sound_Delete('SOUND_GAME_TELEPORT');
2099 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2100 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2101 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2102 g_Sound_Delete('SOUND_GAME_BULK1');
2103 g_Sound_Delete('SOUND_GAME_BULK2');
2104 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2105 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2106 g_Sound_Delete('SOUND_GAME_SWITCH1');
2107 g_Sound_Delete('SOUND_GAME_SWITCH0');
2114 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2115 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2116 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2117 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2124 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2125 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2126 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2127 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2129 DataLoaded
:= False;
2132 procedure DrawCustomStat();
2138 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2139 s1
, s2
, topstr
: String;
2141 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2144 if e_KeyPressed(IK_TAB
) then
2146 if not gStatsPressed
then
2148 gStatsOff
:= not gStatsOff
;
2149 gStatsPressed
:= True;
2153 gStatsPressed
:= False;
2157 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2158 w
:= (Length(s1
) * ww2
) div 2;
2159 x
:= gScreenWidth
div 2 - w
;
2161 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2165 if (gGameSettings
.GameMode
= GM_COOP
) then
2167 if gMissionFailed
then
2168 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2170 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2173 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2175 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2176 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2178 if g_Game_IsNet
then
2180 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2181 if not gChatShow
then
2182 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2183 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2186 if g_Game_IsClient
then
2187 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2189 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2190 if not gChatShow
then
2191 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2192 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2197 w
:= gScreenWidth
-x
*2;
2203 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2204 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2206 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2208 case CustomStat
.GameMode
of
2211 if gGameSettings
.MaxLives
= 0 then
2212 s1
:= _lc
[I_GAME_DM
]
2214 s1
:= _lc
[I_GAME_LMS
];
2218 if gGameSettings
.MaxLives
= 0 then
2219 s1
:= _lc
[I_GAME_TDM
]
2221 s1
:= _lc
[I_GAME_TLMS
];
2223 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2226 if gGameSettings
.MaxLives
= 0 then
2227 s1
:= _lc
[I_GAME_COOP
]
2229 s1
:= _lc
[I_GAME_SURV
];
2235 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2239 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2240 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2243 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2244 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2245 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2246 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2248 pc
:= Length(CustomStat
.PlayerStat
);
2249 if pc
= 0 then Exit
;
2251 if CustomStat
.GameMode
= GM_COOP
then
2253 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2255 s2
:= _lc
[I_GAME_MONSTERS
];
2256 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2257 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2259 s2
:= _lc
[I_GAME_SECRETS
];
2260 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2261 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2264 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2266 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2267 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2268 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2270 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2271 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2272 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2276 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2281 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2282 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2283 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2285 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2288 for t
:= TEAM_RED
to TEAM_BLUE
do
2290 if t
= TEAM_RED
then
2292 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2293 gStdFont
, 255, 0, 0, 1);
2294 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2295 gStdFont
, 255, 0, 0, 1);
2302 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2303 gStdFont
, 0, 0, 255, 1);
2304 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2305 gStdFont
, 0, 0, 255, 1);
2311 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2314 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2315 if CustomStat
.PlayerStat
[p
].Team
= t
then
2316 with CustomStat
.PlayerStat
[p
] do
2330 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2331 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2332 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2339 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2342 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2343 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2344 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2347 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2348 with CustomStat
.PlayerStat
[p
] do
2350 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2357 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2358 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2359 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2365 procedure DrawSingleStat();
2367 tm
, key_x
, val_x
, y
: Integer;
2371 procedure player_stat(n
: Integer);
2377 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2378 s2
:= Format(' %d', [gTotalMonsters
]);
2380 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2381 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2382 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2383 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2385 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2386 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2388 // "Kills-per-minute: ##.#":
2389 s1
:= _lc
[I_MENU_INTER_KPM
];
2391 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2393 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2394 s2
:= Format(' %.1f', [kpm
]);
2396 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2397 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2399 // "Secrets found: # / #":
2400 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2401 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2403 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2404 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2405 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2406 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2408 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2409 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2413 // "Level Complete":
2414 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2415 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2417 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2418 s1
:= _lc
[I_MENU_INTER_KPM
];
2419 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2422 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2424 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2425 val_x
:= key_x
+ w1
;
2428 tm
:= SingleStat
.GameTime
div 1000;
2429 s1
:= _lc
[I_MENU_INTER_TIME
];
2430 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2432 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2433 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2435 if SingleStat
.TwoPlayers
then
2438 s1
:= _lc
[I_MENU_PLAYER_1
];
2439 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2440 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2442 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2447 s1
:= _lc
[I_MENU_PLAYER_2
];
2448 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2449 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2451 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2457 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2463 procedure DrawLoadingStat();
2469 if Length(LoadingStat
.Msgs
) = 0 then
2472 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2473 yy
:= (gScreenHeight
div 3);
2474 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2475 xx
:= (gScreenWidth
div 3);
2478 for i
:= 0 to NextMsg
-1 do
2480 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2481 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2485 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2486 yy
:= yy
+ LOADING_INTERLINE
;
2490 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2492 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2494 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2495 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2498 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2499 ScaleSz
:= 16 div Scale
;
2500 // Ðàçìåðû ìèíè-êàðòû:
2501 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2502 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2504 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2506 if gWalls
<> nil then
2509 for a
:= 0 to High(gWalls
) do
2511 if PanelType
<> 0 then
2513 // Ëåâûé âåðõíèé óãîë:
2514 aX
:= X
div ScaleSz
;
2515 aY
:= Y
div ScaleSz
;
2517 aX2
:= max(Width
div ScaleSz
, 1);
2518 aY2
:= max(Height
div ScaleSz
, 1);
2519 // Ïðàâûé íèæíèé óãîë:
2520 aX2
:= aX
+ aX2
- 1;
2521 aY2
:= aY
+ aY2
- 1;
2524 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2525 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2526 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2530 if gSteps
<> nil then
2533 for a
:= 0 to High(gSteps
) do
2535 if PanelType
<> 0 then
2537 // Ëåâûé âåðõíèé óãîë:
2538 aX
:= X
div ScaleSz
;
2539 aY
:= Y
div ScaleSz
;
2541 aX2
:= max(Width
div ScaleSz
, 1);
2542 aY2
:= max(Height
div ScaleSz
, 1);
2543 // Ïðàâûé íèæíèé óãîë:
2544 aX2
:= aX
+ aX2
- 1;
2545 aY2
:= aY
+ aY2
- 1;
2547 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2550 if gLifts
<> nil then
2553 for a
:= 0 to High(gLifts
) do
2555 if PanelType
<> 0 then
2557 // Ëåâûé âåðõíèé óãîë:
2558 aX
:= X
div ScaleSz
;
2559 aY
:= Y
div ScaleSz
;
2561 aX2
:= max(Width
div ScaleSz
, 1);
2562 aY2
:= max(Height
div ScaleSz
, 1);
2563 // Ïðàâûé íèæíèé óãîë:
2564 aX2
:= aX
+ aX2
- 1;
2565 aY2
:= aY
+ aY2
- 1;
2568 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2569 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2570 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2571 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2575 if gWater
<> nil then
2578 for a
:= 0 to High(gWater
) do
2580 if PanelType
<> 0 then
2582 // Ëåâûé âåðõíèé óãîë:
2583 aX
:= X
div ScaleSz
;
2584 aY
:= Y
div ScaleSz
;
2586 aX2
:= max(Width
div ScaleSz
, 1);
2587 aY2
:= max(Height
div ScaleSz
, 1);
2588 // Ïðàâûé íèæíèé óãîë:
2589 aX2
:= aX
+ aX2
- 1;
2590 aY2
:= aY
+ aY2
- 1;
2592 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2595 if gAcid1
<> nil then
2597 // Ðèñóåì êèñëîòó 1:
2598 for a
:= 0 to High(gAcid1
) do
2600 if PanelType
<> 0 then
2602 // Ëåâûé âåðõíèé óãîë:
2603 aX
:= X
div ScaleSz
;
2604 aY
:= Y
div ScaleSz
;
2606 aX2
:= max(Width
div ScaleSz
, 1);
2607 aY2
:= max(Height
div ScaleSz
, 1);
2608 // Ïðàâûé íèæíèé óãîë:
2609 aX2
:= aX
+ aX2
- 1;
2610 aY2
:= aY
+ aY2
- 1;
2612 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2615 if gAcid2
<> nil then
2617 // Ðèñóåì êèñëîòó 2:
2618 for a
:= 0 to High(gAcid2
) do
2620 if PanelType
<> 0 then
2622 // Ëåâûé âåðõíèé óãîë:
2623 aX
:= X
div ScaleSz
;
2624 aY
:= Y
div ScaleSz
;
2626 aX2
:= max(Width
div ScaleSz
, 1);
2627 aY2
:= max(Height
div ScaleSz
, 1);
2628 // Ïðàâûé íèæíèé óãîë:
2629 aX2
:= aX
+ aX2
- 1;
2630 aY2
:= aY
+ aY2
- 1;
2632 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2635 if gPlayers
<> nil then
2638 for a
:= 0 to High(gPlayers
) do
2639 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2641 // Ëåâûé âåðõíèé óãîë:
2642 aX
:= Obj
.X
div ScaleSz
+ 1;
2643 aY
:= Obj
.Y
div ScaleSz
+ 1;
2645 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2646 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2647 // Ïðàâûé íèæíèé óãîë:
2648 aX2
:= aX
+ aX2
- 1;
2649 aY2
:= aY
+ aY2
- 1;
2651 if gPlayers
[a
] = p
then
2652 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2655 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2656 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2657 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2661 if gMonsters
<> nil then
2664 for a
:= 0 to High(gMonsters
) do
2665 if gMonsters
[a
] <> nil then with gMonsters
[a
] do
2667 // Ëåâûé âåðõíèé óãîë:
2668 aX
:= Obj
.X
div ScaleSz
+ 1;
2669 aY
:= Obj
.Y
div ScaleSz
+ 1;
2671 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2672 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2673 // Ïðàâûé íèæíèé óãîë:
2674 aX2
:= aX
+ aX2
- 1;
2675 aY2
:= aY
+ aY2
- 1;
2677 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2683 procedure DrawMapView(x
, y
, w
, h
: Integer);
2689 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2690 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2691 g_Map_DrawBack(-bx
, -by
);
2698 glTranslatef(-x
, -y
, 0);
2700 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_BACK
);
2701 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_STEP
);
2704 g_Player_DrawShells();
2706 g_Player_DrawCorpses();
2707 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WALL
);
2709 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_CLOSEDOOR
);
2712 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID1
);
2713 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID2
);
2714 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WATER
);
2715 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_FORE
);
2716 if g_debug_HealthBar
then
2718 g_Monsters_DrawHealth();
2719 g_Player_DrawHealth();
2725 procedure DrawPlayer(p
: TPlayer
);
2727 px
, py
, a
, b
, c
, d
: Integer;
2730 lx
, ly
, lrad
: Integer;
2732 if (p
= nil) or (p
.FDummy
) then
2735 g_Map_DrawBack(0, 0);
2740 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('MAP RENDER');
2741 profileFrameDraw
.mainBegin(g_profile_frame_draw
);
2747 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2748 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2750 if px
> (gPlayerScreenSize
.X
div 2) then
2751 a
:= -px
+ (gPlayerScreenSize
.X
div 2)
2754 if py
> (gPlayerScreenSize
.Y
div 2) then
2755 b
:= -py
+ (gPlayerScreenSize
.Y
div 2)
2758 if px
> (gMapInfo
.Width
- (gPlayerScreenSize
.X
div 2)) then
2759 a
:= -gMapInfo
.Width
+ gPlayerScreenSize
.X
;
2760 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2761 b
:= -gMapInfo
.Height
+ gPlayerScreenSize
.Y
;
2762 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then
2764 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then
2767 if p
.IncCam
<> 0 then
2769 if py
> (gMapInfo
.Height
- (gPlayerScreenSize
.Y
div 2)) then
2771 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2772 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2775 if py
< (gPlayerScreenSize
.Y
div 2) then
2777 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2778 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2781 if p
.IncCam
< 0 then
2782 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and
2784 p
.IncCam
:= p
.IncCam
+ 1;
2786 if p
.IncCam
> 0 then
2787 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and
2789 p
.IncCam
:= p
.IncCam
- 1;
2792 if (px
< gPlayerScreenSize
.X
div 2) or
2793 (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then
2796 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then
2797 c
:= gBackSize
.X
- gPlayerScreenSize
.X
2799 c
:= Round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2801 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or
2802 (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then
2805 if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then
2806 d
:= gBackSize
.Y
- gPlayerScreenSize
.Y
2808 d
:= Round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2810 profileFrameDraw
.sectionBegin('map background');
2811 g_Map_DrawBack(-c
, -d
);
2812 profileFrameDraw
.sectionEnd();
2815 sY
:= -(b
+p
.IncCam
);
2816 sWidth
:= gPlayerScreenSize
.X
;
2817 sHeight
:= gPlayerScreenSize
.Y
;
2819 glTranslatef(a
, b
+p
.IncCam
, 0);
2821 profileFrameDraw
.sectionBegin('map rendering');
2823 profileFrameDraw
.sectionBegin('panel_back');
2824 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_BACK
);
2825 profileFrameDraw
.sectionEnd();
2827 profileFrameDraw
.sectionBegin('panel_step');
2828 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_STEP
);
2829 profileFrameDraw
.sectionEnd();
2831 profileFrameDraw
.sectionBegin('items');
2833 profileFrameDraw
.sectionEnd();
2835 profileFrameDraw
.sectionBegin('weapons');
2837 profileFrameDraw
.sectionEnd();
2839 profileFrameDraw
.sectionBegin('shells');
2840 g_Player_DrawShells();
2841 profileFrameDraw
.sectionEnd();
2843 profileFrameDraw
.sectionBegin('drawall');
2845 profileFrameDraw
.sectionEnd();
2847 profileFrameDraw
.sectionBegin('corpses');
2848 g_Player_DrawCorpses();
2849 profileFrameDraw
.sectionEnd();
2851 profileFrameDraw
.sectionBegin('panel_wall');
2852 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WALL
);
2853 profileFrameDraw
.sectionEnd();
2855 profileFrameDraw
.sectionBegin('monsters');
2857 profileFrameDraw
.sectionEnd();
2859 profileFrameDraw
.sectionBegin('panel_closedoor');
2860 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_CLOSEDOOR
);
2861 profileFrameDraw
.sectionEnd();
2863 profileFrameDraw
.sectionBegin('gfx');
2865 profileFrameDraw
.sectionEnd();
2867 profileFrameDraw
.sectionBegin('flags');
2869 profileFrameDraw
.sectionEnd();
2871 profileFrameDraw
.sectionBegin('panel_acid1');
2872 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID1
);
2873 profileFrameDraw
.sectionEnd();
2875 profileFrameDraw
.sectionBegin('panel_acid2');
2876 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_ACID2
);
2877 profileFrameDraw
.sectionEnd();
2879 profileFrameDraw
.sectionBegin('panel_water');
2880 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_WATER
);
2881 profileFrameDraw
.sectionEnd();
2883 //TODO: lights should be in separate grid, i think
2884 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2885 if gwin_has_stencil
and (g_dynLightCount
> 0) then
2887 profileFrameDraw
.sectionBegin('dynlights');
2889 // setup OpenGL parameters
2890 glStencilMask($FFFFFFFF);
2891 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
2892 glEnable(GL_STENCIL_TEST
);
2893 glEnable(GL_SCISSOR_TEST
);
2894 glClear(GL_STENCIL_BUFFER_BIT
);
2895 glStencilFunc(GL_EQUAL
, 0, $ff);
2897 for lln
:= 0 to g_dynLightCount
-1 do
2899 lx
:= g_dynLights
[lln
].x
;
2900 ly
:= g_dynLights
[lln
].y
;
2901 lrad
:= g_dynLights
[lln
].radius
;
2902 if lrad
< 3 then continue
;
2904 if lx
-sX
+lrad
< 0 then continue
;
2905 if ly
-sY
+lrad
< 0 then continue
;
2906 if lx
-sX
-lrad
>= gPlayerScreenSize
.X
then continue
;
2907 if ly
-sY
-lrad
>= gPlayerScreenSize
.Y
then continue
;
2909 // set scissor to optimize drawing
2910 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
2911 // no need to clear stencil buffer, light blitting will do it for us
2912 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
2913 // draw extruded panels
2914 glDisable(GL_TEXTURE_2D
);
2915 glDisable(GL_BLEND
);
2916 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
2917 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
2918 // render light texture
2919 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
2920 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
2923 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2924 glEnable(GL_TEXTURE_2D
);
2925 // color and opacity
2926 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
2927 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
2929 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
2930 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
2931 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
2932 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
2937 glDisable(GL_STENCIL_TEST
);
2938 glDisable(GL_BLEND
);
2939 glDisable(GL_SCISSOR_TEST
);
2940 glScissor(0, 0, sWidth
, sHeight
);
2942 profileFrameDraw
.sectionEnd();
2946 profileFrameDraw
.sectionBegin('dynlights');
2947 profileFrameDraw
.sectionEnd();
2950 profileFrameDraw
.sectionBegin('panel_fore');
2951 g_Map_DrawPanels(sX
, sY
, sWidth
, sHeight
, PANEL_FORE
);
2952 profileFrameDraw
.sectionEnd();
2954 if g_debug_HealthBar
then
2956 profileFrameDraw
.sectionBegin('monster health');
2957 g_Monsters_DrawHealth();
2958 profileFrameDraw
.sectionEnd();
2960 profileFrameDraw
.sectionBegin('player health');
2961 g_Player_DrawHealth();
2962 profileFrameDraw
.sectionEnd();
2965 if p
.FSpectator
then
2966 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2967 p
.GameY
+ PLAYER_RECT_CY
- 4,
2968 'X', gStdFont
, 255, 255, 255, 1, True);
2970 for a := 0 to High(gCollideMap) do
2971 for b := 0 to High(gCollideMap[a]) do
2974 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2976 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2980 1: e_DrawPoint(1, b, a, 200, 200, 200);
2981 2: e_DrawPoint(1, b, a, 64, 64, 255);
2982 3: e_DrawPoint(1, b, a, 255, 0, 255);
2989 profileFrameDraw
.mainEnd(); // map rendering
2994 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2995 if g_Debug_Player
then
2996 g_Player_DrawDebug(p
);
3000 procedure g_Game_Draw();
3007 plView1
, plView2
: TPlayer
;
3010 if gExit
= EXIT_QUIT
then Exit
;
3012 Time
:= GetTimer() {div 1000};
3013 FPSCounter
:= FPSCounter
+1;
3014 if Time
- FPSTime
>= 1000 then
3021 if gGameOn
or (gState
= STATE_FOLD
) then
3023 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3025 gSpectMode
:= SPECT_NONE
;
3026 if not gRevertPlayers
then
3028 plView1
:= gPlayer1
;
3029 plView2
:= gPlayer2
;
3033 plView1
:= gPlayer2
;
3034 plView2
:= gPlayer1
;
3038 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3040 gSpectMode
:= SPECT_NONE
;
3041 if gPlayer2
= nil then
3044 plView1
:= gPlayer2
;
3053 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3054 gSpectMode
:= SPECT_STATS
;
3056 if gSpectMode
= SPECT_PLAYERS
then
3057 if gPlayers
<> nil then
3059 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3060 if plView1
= nil then
3062 gSpectPID1
:= GetActivePlayerID_Next();
3063 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3065 if gSpectViewTwo
then
3067 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3068 if plView2
= nil then
3070 gSpectPID2
:= GetActivePlayerID_Next();
3071 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3076 if gSpectMode
= SPECT_MAPVIEW
then
3078 // Ðåæèì ïðîñìîòðà êàðòû
3080 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3081 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3082 gHearPoint1
.Active
:= True;
3083 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3084 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3085 gHearPoint2
.Active
:= False;
3089 Split
:= (plView1
<> nil) and (plView2
<> nil);
3091 // Òî÷êè ñëóõà èãðîêîâ
3092 if plView1
<> nil then
3094 gHearPoint1
.Active
:= True;
3095 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3096 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3098 gHearPoint1
.Active
:= False;
3099 if plView2
<> nil then
3101 gHearPoint2
.Active
:= True;
3102 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3103 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3105 gHearPoint2
.Active
:= False;
3107 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3108 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3111 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3112 if gScreenHeight
mod 2 = 0 then
3113 Dec(gPlayerScreenSize
.Y
);
3116 gPlayerScreenSize
.Y
:= gScreenHeight
;
3119 if gScreenHeight
mod 2 = 0 then
3120 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3122 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3124 DrawPlayer(plView1
);
3125 gPlayer1ScreenCoord
.X
:= sX
;
3126 gPlayer1ScreenCoord
.Y
:= sY
;
3130 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3132 DrawPlayer(plView2
);
3133 gPlayer2ScreenCoord
.X
:= sX
;
3134 gPlayer2ScreenCoord
.Y
:= sY
;
3137 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3140 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3143 if MessageText
<> '' then
3147 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3149 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3150 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3152 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3153 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3156 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3158 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3160 // Draw spectator GUI
3163 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3166 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3168 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3170 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3172 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3173 if gSpectMode
= SPECT_MAPVIEW
then
3175 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3176 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3177 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3178 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3179 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3181 if gSpectMode
= SPECT_PLAYERS
then
3183 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3184 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3185 if gSpectViewTwo
then
3187 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3188 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3189 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3190 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3194 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3195 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3201 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
3203 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3205 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3206 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3207 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3212 if (gState
= STATE_MENU
) then
3214 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
3216 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3217 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3218 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3220 if g_ActiveWindow
<> nil then
3221 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3224 if gState
= STATE_FOLD
then
3225 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3227 if gState
= STATE_INTERCUSTOM
then
3229 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3231 back
:= 'TEXTURE_endpic';
3232 if not g_Texture_Get(back
, ID
) then
3233 back
:= _lc
[I_TEXTURE_ENDPIC
];
3238 if g_Texture_Get(back
, ID
) then
3239 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3241 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3245 if g_ActiveWindow
<> nil then
3246 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3249 if gState
= STATE_INTERSINGLE
then
3251 if EndingGameCounter
> 0 then
3252 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
3257 if g_Texture_Get(back
, ID
) then
3258 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3260 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3264 if g_ActiveWindow
<> nil then
3265 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3269 if gState
= STATE_ENDPIC
then
3272 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3273 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3275 if ID
<> DWORD(-1) then
3276 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3278 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3280 if g_ActiveWindow
<> nil then
3281 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3284 if gState
= STATE_SLIST
then
3286 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3288 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3289 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3291 g_Serverlist_Draw(slCurrent
);
3295 if g_ActiveWindow
<> nil then
3298 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3299 g_ActiveWindow
.Draw();
3304 if g_debug_Sounds
and gGameOn
then
3306 for w
:= 0 to High(e_SoundsArray
) do
3307 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3308 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3313 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3314 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3317 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3318 e_TextureFontPrint(gScreenWidth
-72, 0,
3319 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3322 if g_profile_frame_draw
then drawProfiles(-1, -1, profileFrameDraw
); //drawProfiles(-1, -1, 'MAP RENDER');
3325 procedure g_Game_Quit();
3327 g_Game_StopAllSounds(True);
3329 g_Game_SaveOptions();
3331 g_PlayerModel_FreeData();
3332 g_Texture_DeleteAll();
3333 g_Frames_DeleteAll();
3336 if NetInitDone
then g_Net_Free
;
3338 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3339 if gMapToDelete
<> '' then
3340 g_Game_DeleteTestMap();
3346 procedure g_FatalError(Text: String);
3348 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3349 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3351 gExit
:= EXIT_SIMPLE
;
3354 procedure g_SimpleError(Text: String);
3356 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3357 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3360 procedure g_Game_SetupScreenSize();
3364 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3365 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3366 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3367 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3369 gPlayerScreenSize
.Y
:= gScreenHeight
;
3371 // Ðàçìåð çàäíåãî ïëàíà:
3372 if BackID
<> DWORD(-1) then
3376 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3377 (gScreenHeight
*d
> gMapInfo
.Height
) then
3380 gBackSize
.X
:= Round(gScreenWidth
*d
);
3381 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3385 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3387 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3390 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3392 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3393 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3395 if gPlayer1
= nil then
3397 if g_Game_IsClient
then
3399 if NetPlrUID1
> -1 then
3401 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3402 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3407 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3408 Team
:= gPlayer1Settings
.Team
;
3410 // Ñîçäàíèå ïåðâîãî èãðîêà:
3411 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3412 gPlayer1Settings
.Color
,
3414 if gPlayer1
= nil then
3415 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3418 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3419 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3420 if g_Game_IsServer
and g_Game_IsNet
then
3421 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3422 gPlayer1
.Respawn(False, True);
3424 if g_Game_IsNet
and NetUseMaster
then
3430 if gPlayer2
= nil then
3432 if g_Game_IsClient
then
3434 if NetPlrUID2
> -1 then
3435 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3439 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3440 Team
:= gPlayer2Settings
.Team
;
3442 // Ñîçäàíèå âòîðîãî èãðîêà:
3443 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3444 gPlayer2Settings
.Color
,
3446 if gPlayer2
= nil then
3447 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3450 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3451 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3452 if g_Game_IsServer
and g_Game_IsNet
then
3453 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3454 gPlayer2
.Respawn(False, True);
3456 if g_Game_IsNet
and NetUseMaster
then
3464 procedure g_Game_RemovePlayer();
3468 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3469 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3474 if g_Game_IsServer
then
3477 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3478 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3479 g_Player_Remove(Pl
.UID
);
3481 if g_Game_IsNet
and NetUseMaster
then
3490 if g_Game_IsServer
then
3493 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3494 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3495 g_Player_Remove(Pl
.UID
);
3497 if g_Game_IsNet
and NetUseMaster
then
3502 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3508 procedure g_Game_Spectate();
3510 g_Game_RemovePlayer();
3511 if gPlayer1
<> nil then
3512 g_Game_RemovePlayer();
3515 procedure g_Game_SpectateCenterView();
3517 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3518 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3521 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3527 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3529 g_Game_ClearLoading();
3532 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3535 gGameSettings
.GameType
:= GT_SINGLE
;
3536 gGameSettings
.MaxLives
:= 0;
3537 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3538 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3539 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3540 gSwitchGameMode
:= GM_SINGLE
;
3542 g_Game_ExecuteEvent('ongamestart');
3544 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3545 g_Game_SetupScreenSize();
3547 // Ñîçäàíèå ïåðâîãî èãðîêà:
3548 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3549 gPlayer1Settings
.Color
,
3550 gPlayer1Settings
.Team
, False));
3551 if gPlayer1
= nil then
3553 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3557 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3560 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3563 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3564 gPlayer2Settings
.Color
,
3565 gPlayer2Settings
.Team
, False));
3566 if gPlayer2
= nil then
3568 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3572 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3576 // Çàãðóçêà è çàïóñê êàðòû:
3577 if not g_Game_StartMap(MAP
, True) then
3579 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3583 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3587 for i
:= nPl
+1 to nPlayers
do
3588 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3591 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3592 TimeLimit
, GoalLimit
: Word;
3594 Options
: LongWord; nPlayers
: Byte);
3600 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3602 g_Game_ClearLoading();
3605 gGameSettings
.GameType
:= GT_CUSTOM
;
3606 gGameSettings
.GameMode
:= GameMode
;
3607 gSwitchGameMode
:= GameMode
;
3608 gGameSettings
.TimeLimit
:= TimeLimit
;
3609 gGameSettings
.GoalLimit
:= GoalLimit
;
3610 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3611 gGameSettings
.Options
:= Options
;
3613 gCoopTotalMonstersKilled
:= 0;
3614 gCoopTotalSecretsFound
:= 0;
3615 gCoopTotalMonsters
:= 0;
3616 gCoopTotalSecrets
:= 0;
3620 g_Game_ExecuteEvent('ongamestart');
3622 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3623 g_Game_SetupScreenSize();
3625 // Ðåæèì íàáëþäàòåëÿ:
3626 if nPlayers
= 0 then
3633 if nPlayers
>= 1 then
3635 // Ñîçäàíèå ïåðâîãî èãðîêà:
3636 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3637 gPlayer1Settings
.Color
,
3638 gPlayer1Settings
.Team
, False));
3639 if gPlayer1
= nil then
3641 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3645 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3649 if nPlayers
>= 2 then
3651 // Ñîçäàíèå âòîðîãî èãðîêà:
3652 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3653 gPlayer2Settings
.Color
,
3654 gPlayer2Settings
.Team
, False));
3655 if gPlayer2
= nil then
3657 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3661 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3665 // Çàãðóçêà è çàïóñê êàðòû:
3666 if not g_Game_StartMap(Map
, True) then
3668 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3672 // Íåò òî÷åê ïîÿâëåíèÿ:
3673 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3674 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3675 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3676 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3677 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3679 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3683 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3687 for i
:= nPl
+1 to nPlayers
do
3688 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3691 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3692 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3693 Options
: LongWord; nPlayers
: Byte;
3694 IPAddr
: LongWord; Port
: Word);
3698 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3700 g_Game_ClearLoading();
3703 gGameSettings
.GameType
:= GT_SERVER
;
3704 gGameSettings
.GameMode
:= GameMode
;
3705 gSwitchGameMode
:= GameMode
;
3706 gGameSettings
.TimeLimit
:= TimeLimit
;
3707 gGameSettings
.GoalLimit
:= GoalLimit
;
3708 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3709 gGameSettings
.Options
:= Options
;
3711 gCoopTotalMonstersKilled
:= 0;
3712 gCoopTotalSecretsFound
:= 0;
3713 gCoopTotalMonsters
:= 0;
3714 gCoopTotalSecrets
:= 0;
3718 g_Game_ExecuteEvent('ongamestart');
3720 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3721 g_Game_SetupScreenSize();
3723 // Ðåæèì íàáëþäàòåëÿ:
3724 if nPlayers
= 0 then
3730 if nPlayers
>= 1 then
3732 // Ñîçäàíèå ïåðâîãî èãðîêà:
3733 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3734 gPlayer1Settings
.Color
,
3735 gPlayer1Settings
.Team
, False));
3736 if gPlayer1
= nil then
3738 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3742 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3745 if nPlayers
>= 2 then
3747 // Ñîçäàíèå âòîðîãî èãðîêà:
3748 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3749 gPlayer2Settings
.Color
,
3750 gPlayer2Settings
.Team
, False));
3751 if gPlayer2
= nil then
3753 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3757 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3761 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3763 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3767 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3769 // Çàãðóçêà è çàïóñê êàðòû:
3770 if not g_Game_StartMap(Map
, True) then
3772 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3776 // Íåò òî÷åê ïîÿâëåíèÿ:
3777 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3778 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3779 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3780 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3781 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3783 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3787 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3790 NetState
:= NET_STATE_GAME
;
3793 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3807 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3808 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3810 g_Game_ClearLoading();
3813 gGameSettings
.GameType
:= GT_CLIENT
;
3815 gCoopTotalMonstersKilled
:= 0;
3816 gCoopTotalSecretsFound
:= 0;
3817 gCoopTotalMonsters
:= 0;
3818 gCoopTotalSecrets
:= 0;
3822 g_Game_ExecuteEvent('ongamestart');
3824 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3825 g_Game_SetupScreenSize();
3827 NetState
:= NET_STATE_AUTH
;
3829 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3831 if not g_Net_Connect(Addr
, Port
) then
3833 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3834 NetState
:= NET_STATE_NONE
;
3838 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3840 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3845 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3847 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3849 Ptr
:= NetEvent
.packet
^.data
;
3852 MID
:= e_Raw_Read_Byte(Ptr
);
3854 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3856 NetMyID
:= e_Raw_Read_Byte(Ptr
);
3857 NetPlrUID1
:= e_Raw_Read_Word(Ptr
);
3859 WadName
:= e_Raw_Read_String(Ptr
);
3860 Map
:= e_Raw_Read_String(Ptr
);
3862 gWADHash
:= e_Raw_Read_MD5(Ptr
);
3864 gGameSettings
.GameMode
:= e_Raw_Read_Byte(Ptr
);
3865 gSwitchGameMode
:= gGameSettings
.GameMode
;
3866 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(Ptr
);
3867 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(Ptr
);
3868 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(Ptr
);
3869 gGameSettings
.Options
:= e_Raw_Read_LongWord(Ptr
);
3870 T
:= e_Raw_Read_LongWord(Ptr
);
3872 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3873 if newResPath
= '' then
3875 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3876 newResPath
:= g_Res_DownloadWAD(WadName
);
3877 if newResPath
= '' then
3879 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3880 enet_packet_destroy(NetEvent
.packet
);
3881 NetState
:= NET_STATE_NONE
;
3885 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3887 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3888 gPlayer1Settings
.Color
,
3889 gPlayer1Settings
.Team
, False));
3891 if gPlayer1
= nil then
3893 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3895 enet_packet_destroy(NetEvent
.packet
);
3896 NetState
:= NET_STATE_NONE
;
3900 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3901 gPlayer1
.UID
:= NetPlrUID1
;
3902 gPlayer1
.Reset(True);
3904 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3906 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3908 enet_packet_destroy(NetEvent
.packet
);
3909 NetState
:= NET_STATE_NONE
;
3917 enet_packet_destroy(NetEvent
.packet
);
3921 enet_packet_destroy(NetEvent
.packet
);
3924 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3927 if (NetEvent
.data
<= NET_DISC_MAX
) then
3928 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3929 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3939 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3948 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3949 NetState
:= NET_STATE_NONE
;
3953 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3954 gLMSRespawnTime
:= 0;
3957 NetState
:= NET_STATE_GAME
;
3958 MC_SEND_FullStateRequest
;
3959 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3962 procedure g_Game_SaveOptions();
3964 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3967 procedure g_Game_ChangeMap(MapPath
: String);
3971 g_Game_ClearLoading();
3973 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3974 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3975 if gExitByTrigger
then
3978 gExitByTrigger
:= False;
3980 if not g_Game_StartMap(MapPath
, Force
) then
3981 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3984 procedure g_Game_Restart();
3988 if g_Game_IsClient
then
3990 map
:= g_ExtractFileName(gMapInfo
.Map
);
3994 g_Game_ClearLoading();
3995 g_Game_StartMap(Map
, True);
3998 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
4000 NewWAD
, ResName
: String;
4004 g_Player_RemoveAllCorpses();
4006 if (not g_Game_IsClient
) and
4007 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4008 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4010 if gSwitchGameMode
= GM_CTF
then
4011 gGameSettings
.MaxLives
:= 0;
4012 gGameSettings
.GameMode
:= gSwitchGameMode
;
4015 gSwitchGameMode
:= gGameSettings
.GameMode
;
4017 g_Player_ResetTeams();
4019 if Pos(':\', Map
) > 0 then
4021 NewWAD
:= g_ExtractWadName(Map
);
4022 ResName
:= g_ExtractFileName(Map
);
4023 if g_Game_IsServer
then
4025 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4026 g_Game_LoadWAD(NewWAD
);
4028 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
4029 g_Game_ClientWAD(NewWAD
, gWADHash
);
4033 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4036 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4038 gState
:= STATE_NONE
;
4039 g_ActiveWindow
:= nil;
4045 if gGameSettings
.GameMode
= GM_CTF
then
4047 g_Map_ResetFlag(FLAG_RED
);
4048 g_Map_ResetFlag(FLAG_BLUE
);
4049 // CTF, à ôëàãîâ íåò:
4050 if not g_Map_HaveFlagPoints() then
4051 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4056 gState
:= STATE_MENU
;
4063 NetTimeToUpdate
:= 1;
4064 NetTimeToReliable
:= 0;
4065 NetTimeToMaster
:= NetMasterRate
;
4066 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4067 gLMSRespawnTime
:= 0;
4068 gMissionFailed
:= False;
4071 gCoopMonstersKilled
:= 0;
4072 gCoopSecretsFound
:= 0;
4074 gVoteInProgress
:= False;
4075 gVotePassed
:= False;
4081 if not gGameOn
then Exit
;
4083 g_Game_SpectateCenterView();
4085 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4087 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4088 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4089 gLMSSoftSpawn
:= True;
4090 if NetMode
= NET_SERVER
then
4091 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4093 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4096 if NetMode
= NET_SERVER
then
4098 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4101 if NetUseMaster
then
4103 if (NetMHost
= nil) or (NetMPeer
= nil) then
4104 if not g_Net_Slist_Connect
then
4105 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4110 if NetClients
<> nil then
4111 for I
:= 0 to High(NetClients
) do
4112 if NetClients
[I
].Used
then
4114 NetClients
[I
].Voted
:= False;
4115 if NetClients
[I
].RequestedFullUpdate
then
4117 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4118 NetClients
[I
].RequestedFullUpdate
:= False;
4122 g_Net_UnbanNonPermHosts();
4127 gCoopTotalMonstersKilled
:= 0;
4128 gCoopTotalSecretsFound
:= 0;
4129 gCoopTotalMonsters
:= 0;
4130 gCoopTotalSecrets
:= 0;
4134 g_Game_ExecuteEvent('onmapstart');
4137 procedure SetFirstLevel();
4141 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4142 if MapList
= nil then
4145 SortSArray(MapList
);
4146 gNextMap
:= MapList
[Low(MapList
)];
4151 procedure g_Game_ExitLevel(Map
: Char16
);
4155 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4156 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4157 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4158 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4160 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4161 if gGameSettings
.GameType
= GT_SINGLE
then
4162 gExit
:= EXIT_ENDLEVELSINGLE
4163 else // Âûøëè â âûõîä â Ñâîåé èãðå
4165 gExit
:= EXIT_ENDLEVELCUSTOM
;
4166 if gGameSettings
.GameMode
= GM_COOP
then
4167 g_Player_RememberAll
;
4169 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4172 if gGameSettings
.GameMode
= GM_COOP
then
4175 gStatsPressed
:= True;
4176 gNextMap
:= 'MAP01';
4178 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4181 if g_Game_IsNet
then
4183 MH_SEND_GameStats();
4184 MH_SEND_CoopStats();
4190 procedure g_Game_RestartLevel();
4194 if gGameSettings
.GameMode
= GM_SINGLE
then
4199 gExit
:= EXIT_ENDLEVELCUSTOM
;
4200 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4204 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4208 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4210 if not g_Game_IsClient
then
4212 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4215 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4216 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4220 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4224 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4225 g_Game_LoadWAD(NewWAD
);
4228 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4230 i
, n
, nb
, nr
: Integer;
4232 if not g_Game_IsServer
then Exit
;
4233 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4234 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4235 gLMSRespawnTime
:= 0;
4238 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4240 gMissionFailed
:= True;
4241 g_Game_RestartLevel
;
4245 n
:= 0; nb
:= 0; nr
:= 0;
4246 for i
:= Low(gPlayers
) to High(gPlayers
) do
4247 if (gPlayers
[i
] <> nil) and
4248 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4249 (gPlayers
[i
] is TBot
)) then
4252 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4253 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4256 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4258 // wait a second until the fuckers finally decide to join
4259 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4260 gLMSRespawnTime
:= gTime
+ 1000;
4261 gLMSSoftSpawn
:= NoMapRestart
;
4265 g_Player_RemoveAllCorpses
;
4266 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4267 if g_Game_IsNet
then
4268 MH_SEND_GameEvent(NET_EV_LMS_START
);
4270 for i
:= Low(gPlayers
) to High(gPlayers
) do
4272 if gPlayers
[i
] = nil then continue
;
4273 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4274 // don't touch normal spectators
4275 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4277 gPlayers
[i
].FNoRespawn
:= True;
4278 gPlayers
[i
].Lives
:= 0;
4279 if g_Game_IsNet
then
4280 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4283 gPlayers
[i
].FNoRespawn
:= False;
4284 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4285 gPlayers
[i
].Respawn(False, True);
4286 if gGameSettings
.GameMode
= GM_COOP
then
4288 gPlayers
[i
].Frags
:= 0;
4289 gPlayers
[i
].RecallState
;
4291 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4292 gPlayer1
:= g_Player_Get(gLMSPID1
);
4293 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4294 gPlayer2
:= g_Player_Get(gLMSPID2
);
4297 for i
:= Low(gItems
) to High(gItems
) do
4299 if gItems
[i
].Respawnable
then
4301 gItems
[i
].QuietRespawn
:= True;
4302 gItems
[i
].RespawnTime
:= 0;
4307 if g_Game_IsNet
then MH_SEND_ItemDestroy(True, i
);
4311 for i
:= Low(gMonsters
) to High(gMonsters
) do
4313 if (gMonsters
[i
] <> nil) and not gMonsters
[i
].FNoRespawn
then
4314 gMonsters
[i
].Respawn
;
4317 gLMSSoftSpawn
:= False;
4320 function g_Game_GetFirstMap(WAD
: String): String;
4324 MapList
:= g_Map_GetMapsList(WAD
);
4325 if MapList
= nil then
4328 SortSArray(MapList
);
4329 Result
:= MapList
[Low(MapList
)];
4331 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4337 function g_Game_GetNextMap(): String;
4344 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4345 if MapList
= nil then
4348 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4350 SortSArray(MapList
);
4352 for I
:= Low(MapList
) to High(MapList
) do
4353 if Map
= MapList
[I
] then
4359 if MapIndex
<> -255 then
4361 if MapIndex
= High(MapList
) then
4362 Result
:= MapList
[Low(MapList
)]
4364 Result
:= MapList
[MapIndex
+ 1];
4366 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4372 procedure g_Game_NextLevel();
4374 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4375 gExit
:= EXIT_ENDLEVELCUSTOM
4378 gExit
:= EXIT_ENDLEVELSINGLE
;
4382 if gNextMap
<> '' then Exit
;
4383 gNextMap
:= g_Game_GetNextMap();
4386 function g_Game_IsTestMap(): Boolean;
4388 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4391 procedure g_Game_DeleteTestMap();
4402 a
:= Pos('.wad:\', gMapToDelete
);
4406 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4407 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4408 Delete(gMapToDelete
, 1, a
+ 5);
4409 gMapToDelete
:= UpperCase(gMapToDelete
);
4411 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4414 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4415 if MapName <> TEST_MAP_NAME then
4418 if not gTempDelete then
4420 time := g_GetFileTime(WadName);
4421 WAD := TWADFile.Create();
4424 if not WAD.ReadFile(WadName) then
4425 begin // Íåò òàêîãî WAD-ôàéëà
4430 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4432 MapList := WAD.GetResourcesList('');
4434 if MapList <> nil then
4435 for a := 0 to High(MapList) do
4436 if MapList[a] = MapName then
4438 // Óäàëÿåì è ñîõðàíÿåì:
4439 WAD.RemoveResource('', MapName);
4440 WAD.SaveTo(WadName);
4445 g_SetFileTime(WadName, time);
4448 if gTempDelete
then DeleteFile(WadName
);
4451 procedure GameCVars(P
: SArray
);
4454 stat
: TPlayerStatArray
;
4459 cmd
:= LowerCase(P
[0]);
4460 if cmd
= 'r_showfps' then
4462 if (Length(P
) > 1) and
4463 ((P
[1] = '1') or (P
[1] = '0')) then
4464 gShowFPS
:= (P
[1][1] = '1');
4467 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4469 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4471 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4473 with gGameSettings
do
4475 if (Length(P
) > 1) and
4476 ((P
[1] = '1') or (P
[1] = '0')) then
4478 if (P
[1][1] = '1') then
4479 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4481 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4484 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4485 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4487 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4489 if g_Game_IsNet
then MH_SEND_GameSettings
;
4492 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4494 with gGameSettings
do
4496 if (Length(P
) > 1) and
4497 ((P
[1] = '1') or (P
[1] = '0')) then
4499 if (P
[1][1] = '1') then
4500 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4502 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4505 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4506 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4508 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4510 if g_Game_IsNet
then MH_SEND_GameSettings
;
4513 else if cmd
= 'g_gamemode' then
4515 a
:= g_Game_TextToMode(P
[1]);
4516 if a
= GM_SINGLE
then a
:= GM_COOP
;
4517 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4519 gSwitchGameMode
:= a
;
4520 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4521 (gState
= STATE_INTERSINGLE
) then
4522 gSwitchGameMode
:= GM_SINGLE
;
4524 gGameSettings
.GameMode
:= gSwitchGameMode
;
4526 if gSwitchGameMode
= gGameSettings
.GameMode
then
4527 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4528 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4530 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4531 [g_Game_ModeToText(gGameSettings
.GameMode
),
4532 g_Game_ModeToText(gSwitchGameMode
)]));
4534 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4536 with gGameSettings
do
4538 if (Length(P
) > 1) and
4539 ((P
[1] = '1') or (P
[1] = '0')) then
4541 if (P
[1][1] = '1') then
4542 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4544 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4547 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4548 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4550 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4551 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4553 if g_Game_IsNet
then MH_SEND_GameSettings
;
4556 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4558 with gGameSettings
do
4560 if (Length(P
) > 1) and
4561 ((P
[1] = '1') or (P
[1] = '0')) then
4563 if (P
[1][1] = '1') then
4564 Options
:= Options
or GAME_OPTION_MONSTERS
4566 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4569 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4570 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4572 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4573 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4575 if g_Game_IsNet
then MH_SEND_GameSettings
;
4578 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4580 with gGameSettings
do
4582 if (Length(P
) > 1) and
4583 ((P
[1] = '1') or (P
[1] = '0')) then
4585 if (P
[1][1] = '1') then
4586 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4588 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4591 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4592 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4594 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4596 if g_Game_IsNet
then MH_SEND_GameSettings
;
4599 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4601 with gGameSettings
do
4603 if (Length(P
) > 1) and
4604 ((P
[1] = '1') or (P
[1] = '0')) then
4606 if (P
[1][1] = '1') then
4607 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4609 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4612 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4613 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4615 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4617 if g_Game_IsNet
then MH_SEND_GameSettings
;
4620 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4622 if Length(P
) > 1 then
4624 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4625 gGameSettings
.WarmupTime
:= 30
4627 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4630 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4631 [gGameSettings
.WarmupTime
]));
4632 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4634 else if cmd
= 'net_interp' then
4636 if (Length(P
) > 1) then
4637 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4639 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4640 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4641 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4642 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4645 else if cmd
= 'net_forceplayerupdate' then
4647 if (Length(P
) > 1) and
4648 ((P
[1] = '1') or (P
[1] = '0')) then
4649 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4651 if NetForcePlayerUpdate
then
4652 g_Console_Add('net_forceplayerupdate = 1')
4654 g_Console_Add('net_forceplayerupdate = 0');
4655 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4656 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4657 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4660 else if cmd
= 'net_predictself' then
4662 if (Length(P
) > 1) and
4663 ((P
[1] = '1') or (P
[1] = '0')) then
4664 NetPredictSelf
:= (P
[1][1] = '1');
4666 if NetPredictSelf
then
4667 g_Console_Add('net_predictself = 1')
4669 g_Console_Add('net_predictself = 0');
4670 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4671 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4672 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4675 else if cmd
= 'sv_name' then
4677 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4679 NetServerName
:= P
[1];
4680 if Length(NetServerName
) > 64 then
4681 SetLength(NetServerName
, 64);
4682 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4686 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4688 else if cmd
= 'sv_passwd' then
4690 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4692 NetPassword
:= P
[1];
4693 if Length(NetPassword
) > 24 then
4694 SetLength(NetPassword
, 24);
4695 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4699 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4701 else if cmd
= 'sv_maxplrs' then
4703 if (Length(P
) > 1) then
4705 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4706 if g_Game_IsServer
and g_Game_IsNet
then
4709 for a
:= 0 to High(NetClients
) do
4710 if NetClients
[a
].Used
then
4713 if b
> NetMaxClients
then
4715 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4716 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4717 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4718 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4721 if NetUseMaster
then
4726 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4728 else if cmd
= 'sv_public' then
4730 if (Length(P
) > 1) then
4732 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4733 if g_Game_IsServer
and g_Game_IsNet
then
4734 if NetUseMaster
then
4736 if NetMPeer
= nil then
4737 if not g_Net_Slist_Connect() then
4738 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4739 g_Net_Slist_Update();
4742 if NetMPeer
<> nil then
4743 g_Net_Slist_Disconnect();
4746 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4748 else if cmd
= 'sv_intertime' then
4750 if (Length(P
) > 1) then
4751 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4753 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4755 else if cmd
= 'p1_name' then
4757 if (Length(P
) > 1) and gGameOn
then
4759 if g_Game_IsClient
then
4761 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4762 MC_SEND_PlayerSettings
;
4765 if gPlayer1
<> nil then
4767 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4768 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4771 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4774 else if cmd
= 'p2_name' then
4776 if (Length(P
) > 1) and gGameOn
then
4778 if g_Game_IsClient
then
4780 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4781 MC_SEND_PlayerSettings
;
4784 if gPlayer2
<> nil then
4786 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4787 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4790 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4793 else if cmd
= 'p1_color' then
4795 if Length(P
) > 3 then
4796 if g_Game_IsClient
then
4798 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4799 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4800 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4801 MC_SEND_PlayerSettings
;
4804 if gPlayer1
<> nil then
4806 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4807 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4808 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4809 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4812 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4813 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4814 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4816 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4818 if Length(P
) > 3 then
4819 if g_Game_IsClient
then
4821 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4822 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4823 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4824 MC_SEND_PlayerSettings
;
4827 if gPlayer2
<> nil then
4829 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4830 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4831 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4832 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4835 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4836 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4837 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4839 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4841 if cmd
= 'r_showtime' then
4843 if (Length(P
) > 1) and
4844 ((P
[1] = '1') or (P
[1] = '0')) then
4845 gShowTime
:= (P
[1][1] = '1');
4848 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4850 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4852 else if cmd
= 'r_showscore' then
4854 if (Length(P
) > 1) and
4855 ((P
[1] = '1') or (P
[1] = '0')) then
4856 gShowGoals
:= (P
[1][1] = '1');
4859 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4861 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4863 else if cmd
= 'r_showstat' then
4865 if (Length(P
) > 1) and
4866 ((P
[1] = '1') or (P
[1] = '0')) then
4867 gShowStat
:= (P
[1][1] = '1');
4870 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4872 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4874 else if cmd
= 'r_showkillmsg' then
4876 if (Length(P
) > 1) and
4877 ((P
[1] = '1') or (P
[1] = '0')) then
4878 gShowKillMsg
:= (P
[1][1] = '1');
4880 if gShowKillMsg
then
4881 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4883 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4885 else if cmd
= 'r_showlives' then
4887 if (Length(P
) > 1) and
4888 ((P
[1] = '1') or (P
[1] = '0')) then
4889 gShowLives
:= (P
[1][1] = '1');
4892 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4894 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4896 else if cmd
= 'r_showspect' then
4898 if (Length(P
) > 1) and
4899 ((P
[1] = '1') or (P
[1] = '0')) then
4900 gSpectHUD
:= (P
[1][1] = '1');
4903 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4905 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4907 else if cmd
= 'r_showping' then
4909 if (Length(P
) > 1) and
4910 ((P
[1] = '1') or (P
[1] = '0')) then
4911 gShowPing
:= (P
[1][1] = '1');
4914 g_Console_Add(_lc
[I_MSG_PING_ON
])
4916 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4918 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4920 if Length(P
) > 1 then
4922 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4923 gGameSettings
.GoalLimit
:= 0
4928 if gGameSettings
.GameMode
= GM_DM
then
4930 stat
:= g_Player_GetStats();
4932 for a
:= 0 to High(stat
) do
4933 if stat
[a
].Frags
> b
then
4937 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4939 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4942 if g_Game_IsNet
then MH_SEND_GameSettings
;
4945 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4947 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4949 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4950 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4952 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4953 [gGameSettings
.TimeLimit
div 3600,
4954 (gGameSettings
.TimeLimit
div 60) mod 60,
4955 gGameSettings
.TimeLimit
mod 60]));
4956 if g_Game_IsNet
then MH_SEND_GameSettings
;
4958 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4960 if Length(P
) > 1 then
4962 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4963 gGameSettings
.MaxLives
:= 0
4967 stat
:= g_Player_GetStats();
4969 for a
:= 0 to High(stat
) do
4970 if stat
[a
].Lives
> b
then
4972 gGameSettings
.MaxLives
:=
4973 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4977 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4978 [gGameSettings
.MaxLives
]));
4979 if g_Game_IsNet
then MH_SEND_GameSettings
;
4984 // profiler console commands
4985 procedure ProfilerCommands (P
: SArray
);
4989 //if not gDebugMode then exit;
4990 cmd
:= LowerCase(P
[0]);
4993 g_profile_frame_draw
:= not g_profile_frame_draw
;
4998 g_profile_frame_update
:= not g_profile_frame_update
;
5003 procedure DebugCommands(P
: SArray
);
5009 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5012 cmd
:= LowerCase(P
[0]);
5013 if cmd
= 'd_window' then
5015 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5016 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5017 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5018 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5019 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5021 else if cmd
= 'd_sounds' then
5023 if (Length(P
) > 1) and
5024 ((P
[1] = '1') or (P
[1] = '0')) then
5025 g_Debug_Sounds
:= (P
[1][1] = '1');
5027 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5029 else if cmd
= 'd_frames' then
5031 if (Length(P
) > 1) and
5032 ((P
[1] = '1') or (P
[1] = '0')) then
5033 g_Debug_Frames
:= (P
[1][1] = '1');
5035 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5037 else if cmd
= 'd_winmsg' then
5039 if (Length(P
) > 1) and
5040 ((P
[1] = '1') or (P
[1] = '0')) then
5041 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5043 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5045 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5047 if (Length(P
) > 1) and
5048 ((P
[1] = '1') or (P
[1] = '0')) then
5049 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5051 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5053 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5055 if Length(P
) > 1 then
5057 '0': g_debug_BotAIOff
:= 0;
5058 '1': g_debug_BotAIOff
:= 1;
5059 '2': g_debug_BotAIOff
:= 2;
5060 '3': g_debug_BotAIOff
:= 3;
5063 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5065 else if cmd
= 'd_monster' then
5067 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
5068 if Length(P
) < 2 then
5070 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5071 g_Console_Add('ID | Name');
5072 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5073 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
5076 a
:= StrToIntDef(P
[1], 0);
5077 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5078 a
:= g_Monsters_GetIDByName(P
[1]);
5080 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5081 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5084 with gPlayer1
.Obj
do
5085 b
:= g_Monsters_Create(a
,
5086 X
+ Rect
.X
+ (Rect
.Width
div 2),
5087 Y
+ Rect
.Y
+ Rect
.Height
,
5088 gPlayer1
.Direction
, True);
5089 if (Length(P
) > 2) and (b
>= 0) then
5090 gMonsters
[b
].MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5094 else if (cmd
= 'd_health') then
5096 if (Length(P
) > 1) and
5097 ((P
[1] = '1') or (P
[1] = '0')) then
5098 g_debug_HealthBar
:= (P
[1][1] = '1');
5100 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5102 else if (cmd
= 'd_player') then
5104 if (Length(P
) > 1) and
5105 ((P
[1] = '1') or (P
[1] = '0')) then
5106 g_debug_Player
:= (P
[1][1] = '1');
5108 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5110 else if (cmd
= 'd_joy') then
5113 g_Console_Add(e_JoystickStateToString(a
));
5117 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5121 procedure GameCheats(P
: SArray
);
5127 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
5128 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
5130 g_Console_Add('not available');
5136 g_Console_Add('where is the player?!');
5139 cmd
:= LowerCase(P
[0]);
5143 plr
.GodMode
:= not plr
.GodMode
;
5144 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5147 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5148 if cmd
= 'give' then
5150 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5151 for f
:= 1 to High(P
) do
5153 cmd
:= LowerCase(P
[f
]);
5154 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5155 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5156 if cmd
= 'exit' then
5158 if gTriggers
<> nil then
5160 for a
:= 0 to High(gTriggers
) do
5162 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5164 g_Console_Add('player left the map');
5165 gExitByTrigger
:= True;
5166 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
5174 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5175 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5176 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5177 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5178 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5180 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5181 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5183 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5184 if (cmd
= 'medkit') or (cmd
= 'medikit') or (cmd
= 'medpack') or (cmd
= 'medipack') then begin plr
.GiveItem(ITEM_MEDKIT_LARGE
); g_Console_Add('player got a '+cmd
); continue
; end;
5186 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5187 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5189 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5190 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5192 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5193 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5195 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5196 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5197 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5199 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5200 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5201 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5202 if (cmd
= 'launcher') or (cmd
= 'rocketlauncher') or (cmd
= 'rl') then begin plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
); g_Console_Add('player got a rocket launcher'); continue
; end;
5203 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5204 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5206 if (cmd
= 'shotgunzz') or (cmd
= 'sgzz') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a shotgun'); continue
; end;
5207 if (cmd
= 'supershotgunzz') or (cmd
= 'ssgzz') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a supershotgun'); continue
; end;
5208 if cmd
= 'chaingunzz' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a chaingun'); continue
; end;
5209 if (cmd
= 'launcherzz') or (cmd
= 'rocketlauncherzz') or (cmd
= 'rlzz') then begin plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
); plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got a rocket launcher'); continue
; end;
5210 if cmd
= 'plasmagunzz' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got a plasma gun'); continue
; end;
5211 if cmd
= 'bfgzz' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5213 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5214 if cmd
= 'superchaingunzz' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a superchaingun'); continue
; end;
5216 if (cmd
= 'flamer') or (cmd
= 'flamethrower') or (cmd
= 'ft') then begin plr
.GiveItem(ITEM_WEAPON_FLAMETHROWER
); g_Console_Add('player got a flame thrower'); continue
; end;
5217 if (cmd
= 'flamerzz') or (cmd
= 'flamethrowerzz') or (cmd
= 'ftzz') then begin plr
.GiveItem(ITEM_WEAPON_FLAMETHROWER
); plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got a flame thrower'); continue
; end;
5219 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5221 if cmd
= 'ammo' then
5223 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5224 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5225 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5226 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5227 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5228 g_Console_Add('player got some ammo');
5232 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5233 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5235 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5236 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5238 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5239 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5241 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5242 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5244 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5246 if cmd
= 'weapons' then
5248 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5249 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5250 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5251 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5252 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5253 plr
.GiveItem(ITEM_WEAPON_BFG
);
5254 g_Console_Add('player got weapons');
5258 if cmd
= 'keys' then
5260 plr
.GiveItem(ITEM_KEY_RED
);
5261 plr
.GiveItem(ITEM_KEY_GREEN
);
5262 plr
.GiveItem(ITEM_KEY_BLUE
);
5263 g_Console_Add('player got all keys');
5267 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5272 if cmd
= 'open' then
5274 g_Console_Add('player activated sesame');
5275 g_Triggers_OpenAll();
5282 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5286 if cmd
= 'noclip' then
5289 g_Console_Add('wall hardeness adjusted');
5293 if cmd
= 'notarget' then
5295 plr
.NoTarget
:= not plr
.NoTarget
;
5296 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5300 if cmd
= 'noreload' then
5302 plr
.NoReload
:= not plr
.NoReload
;
5303 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5307 if cmd
= 'speedy' then
5309 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5310 g_Console_Add('speed adjusted');
5314 if cmd
= 'jumpy' then
5316 VEL_JUMP
:= 30-VEL_JUMP
;
5317 g_Console_Add('jump height adjusted');
5321 if cmd
= 'automap' then
5323 gShowMap
:= not gShowMap
;
5324 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5328 if cmd
= 'aimline' then
5330 gAimLine
:= not gAimLine
;
5331 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5336 procedure GameCommands(P
: SArray
);
5342 pl
: pTNetClient
= nil;
5349 cmd
:= LowerCase(P
[0]);
5351 if (cmd
= 'quit') or
5358 else if cmd
= 'pause' then
5360 if (g_ActiveWindow
= nil) then
5361 g_Game_Pause(not gPause
);
5363 else if cmd
= 'endgame' then
5364 gExit
:= EXIT_SIMPLE
5365 else if cmd
= 'restart' then
5367 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5369 if g_Game_IsClient
then
5371 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5376 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5378 else if cmd
= 'kick' then
5380 if g_Game_IsServer
then
5382 if Length(P
) < 2 then
5384 g_Console_Add('kick <name>');
5389 g_Console_Add('kick <name>');
5393 if g_Game_IsNet
then
5394 pl
:= g_Net_Client_ByName(P
[1]);
5397 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5398 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5399 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5400 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5401 if NetUseMaster
then
5403 end else if gPlayers
<> nil then
5404 for a
:= Low(gPlayers
) to High(gPlayers
) do
5405 if gPlayers
[a
] <> nil then
5406 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5408 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5409 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5411 gPlayers
[a
].Lives
:= 0;
5412 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5413 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5414 g_Player_Remove(gPlayers
[a
].UID
);
5415 if NetUseMaster
then
5417 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5421 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5423 else if cmd
= 'kick_id' then
5425 if g_Game_IsServer
and g_Game_IsNet
then
5427 if Length(P
) < 2 then
5429 g_Console_Add('kick_id <client ID>');
5434 g_Console_Add('kick_id <client ID>');
5438 a
:= StrToIntDef(P
[1], 0);
5439 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5441 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5443 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5444 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5445 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5446 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5447 if NetUseMaster
then
5452 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5454 else if cmd
= 'ban' then
5456 if g_Game_IsServer
and g_Game_IsNet
then
5458 if Length(P
) < 2 then
5460 g_Console_Add('ban <name>');
5465 g_Console_Add('ban <name>');
5469 pl
:= g_Net_Client_ByName(P
[1]);
5472 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5473 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5474 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5475 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5476 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5477 if NetUseMaster
then
5480 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5482 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5484 else if cmd
= 'ban_id' then
5486 if g_Game_IsServer
and g_Game_IsNet
then
5488 if Length(P
) < 2 then
5490 g_Console_Add('ban_id <client ID>');
5495 g_Console_Add('ban_id <client ID>');
5499 a
:= StrToIntDef(P
[1], 0);
5500 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5501 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5503 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5504 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5505 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5506 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5507 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5508 if NetUseMaster
then
5512 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5514 else if cmd
= 'permban' then
5516 if g_Game_IsServer
and g_Game_IsNet
then
5518 if Length(P
) < 2 then
5520 g_Console_Add('permban <name>');
5525 g_Console_Add('permban <name>');
5529 pl
:= g_Net_Client_ByName(P
[1]);
5532 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5533 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5534 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5535 g_Net_SaveBanList();
5536 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5537 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5538 if NetUseMaster
then
5541 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5543 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5545 else if cmd
= 'permban_id' then
5547 if g_Game_IsServer
and g_Game_IsNet
then
5549 if Length(P
) < 2 then
5551 g_Console_Add('permban_id <client ID>');
5556 g_Console_Add('permban_id <client ID>');
5560 a
:= StrToIntDef(P
[1], 0);
5561 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5562 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5564 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5565 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5566 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5567 g_Net_SaveBanList();
5568 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5569 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5570 if NetUseMaster
then
5574 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5576 else if cmd
= 'unban' then
5578 if g_Game_IsServer
and g_Game_IsNet
then
5580 if Length(P
) < 2 then
5582 g_Console_Add('unban <IP Address>');
5587 g_Console_Add('unban <IP Address>');
5591 if g_Net_UnbanHost(P
[1]) then
5593 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5594 g_Net_SaveBanList();
5596 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5598 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5600 else if cmd
= 'clientlist' then
5602 if g_Game_IsServer
and g_Game_IsNet
then
5605 if NetClients
<> nil then
5606 for a
:= Low(NetClients
) to High(NetClients
) do
5607 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5609 plr
:= g_Player_Get(NetClients
[a
].Player
);
5610 if plr
= nil then continue
;
5612 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5613 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5616 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5618 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5620 else if cmd
= 'connect' then
5622 if (NetMode
= NET_NONE
) then
5624 if Length(P
) < 2 then
5626 g_Console_Add('connect <IP> [port] [password]');
5631 g_Console_Add('connect <IP> [port] [password]');
5635 if Length(P
) > 2 then
5636 prt
:= StrToIntDef(P
[2], 25666)
5640 if Length(P
) > 3 then
5645 g_Game_StartClient(P
[1], prt
, pw
);
5648 else if cmd
= 'disconnect' then
5650 if (NetMode
= NET_CLIENT
) then
5653 else if cmd
= 'reconnect' then
5655 if (NetMode
= NET_SERVER
) then
5658 if (NetMode
= NET_CLIENT
) then
5661 gExit
:= EXIT_SIMPLE
;
5665 //TODO: Use last successful password to reconnect, instead of ''
5666 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5668 else if (cmd
= 'addbot') or
5669 (cmd
= 'bot_add') then
5671 if Length(P
) > 1 then
5672 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5674 g_Bot_Add(TEAM_NONE
, 2);
5676 else if cmd
= 'bot_addlist' then
5678 if Length(P
) > 1 then
5679 if Length(P
) = 2 then
5680 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5682 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5684 else if cmd
= 'bot_removeall' then
5686 else if cmd
= 'chat' then
5688 if g_Game_IsNet
then
5690 if Length(P
) > 1 then
5692 for a
:= 1 to High(P
) do
5693 chstr
:= chstr
+ P
[a
] + ' ';
5695 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5697 if Length(chstr
) < 1 then
5699 g_Console_Add('chat <text>');
5703 chstr
:= b_Text_Format(chstr
);
5704 if g_Game_IsClient
then
5705 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5707 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5710 g_Console_Add('chat <text>');
5712 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5714 else if cmd
= 'teamchat' then
5716 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5718 if Length(P
) > 1 then
5720 for a
:= 1 to High(P
) do
5721 chstr
:= chstr
+ P
[a
] + ' ';
5723 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5725 if Length(chstr
) < 1 then
5727 g_Console_Add('teamchat <text>');
5731 chstr
:= b_Text_Format(chstr
);
5732 if g_Game_IsClient
then
5733 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5735 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5736 gPlayer1Settings
.Team
);
5739 g_Console_Add('teamchat <text>');
5741 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5743 else if cmd
= 'game' then
5745 if gGameSettings
.GameType
<> GT_NONE
then
5747 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5750 if Length(P
) = 1 then
5752 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5755 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5756 P
[1] := addWadExtension(P
[1]);
5757 if FileExists(MapsDir
+ P
[1]) then
5759 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5760 if Length(P
) < 3 then
5763 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5766 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5768 if g_Map_Exist(MapsDir
+ s
) then
5770 // Çàïóñêàåì ñâîþ èãðó
5772 with gGameSettings
do
5774 GameMode
:= g_Game_TextToMode(gcGameMode
);
5775 if gSwitchGameMode
<> GM_NONE
then
5776 GameMode
:= gSwitchGameMode
;
5777 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5778 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5780 if Length(P
) >= 4 then
5781 b
:= StrToIntDef(P
[3], 1);
5782 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5783 GoalLimit
, MaxLives
, Options
, b
);
5788 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5790 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5792 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5794 else if cmd
= 'host' then
5796 if gGameSettings
.GameType
<> GT_NONE
then
5798 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5801 if Length(P
) < 4 then
5803 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5806 if not StrToIp(P
[1], listen
) then
5808 prt
:= StrToIntDef(P
[2], 25666);
5810 P
[3] := addWadExtension(P
[3]);
5811 if FileExists(MapsDir
+ P
[3]) then
5813 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5814 if Length(P
) < 5 then
5817 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5820 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5822 if g_Map_Exist(MapsDir
+ s
) then
5824 // Çàïóñêàåì ñâîþ èãðó
5826 with gGameSettings
do
5828 GameMode
:= g_Game_TextToMode(gcGameMode
);
5829 if gSwitchGameMode
<> GM_NONE
then
5830 GameMode
:= gSwitchGameMode
;
5831 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5832 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5834 if Length(P
) >= 6 then
5835 b
:= StrToIntDef(P
[5], 0);
5836 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5837 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5842 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5844 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5846 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5848 else if cmd
= 'map' then
5850 if Length(P
) = 1 then
5852 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5854 g_Console_Add(cmd
+ ' <MAP>');
5855 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5857 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5859 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5861 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5862 if Length(P
) < 3 then
5864 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5865 s
:= UpperCase(P
[1]);
5866 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5867 begin // Êàðòà íàøëàñü
5868 gExitByTrigger
:= False;
5870 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5872 gExit
:= EXIT_ENDLEVELCUSTOM
;
5874 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5875 g_Game_ChangeMap(s
);
5878 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5879 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5880 P
[1] := addWadExtension(P
[1]);
5881 if FileExists(MapsDir
+ P
[1]) then
5883 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5885 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5887 s
:= P
[1] + ':\' + P
[2];
5889 if g_Map_Exist(MapsDir
+ s
) then
5891 gExitByTrigger
:= False;
5893 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5895 gExit
:= EXIT_ENDLEVELCUSTOM
;
5897 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5898 g_Game_ChangeMap(s
);
5901 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5903 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5905 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5909 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5910 P
[1] := addWadExtension(P
[1]);
5911 if FileExists(MapsDir
+ P
[1]) then
5914 P
[2] := UpperCase(P
[2]);
5915 s
:= P
[1] + ':\' + P
[2];
5917 if g_Map_Exist(MapsDir
+ s
) then
5918 begin // Íàøëè êàðòó
5919 gExitByTrigger
:= False;
5921 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5923 gExit
:= EXIT_ENDLEVELCUSTOM
;
5925 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5926 g_Game_ChangeMap(s
);
5928 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5930 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5933 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5935 else if cmd
= 'nextmap' then
5937 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5938 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5941 if Length(P
) = 1 then
5943 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5945 g_Console_Add(cmd
+ ' <MAP>');
5946 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5949 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5954 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5956 if Length(P
) < 3 then
5958 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5959 s
:= UpperCase(P
[1]);
5960 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5961 begin // Êàðòà íàøëàñü
5962 gExitByTrigger
:= False;
5967 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5968 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5969 P
[1] := addWadExtension(P
[1]);
5970 if FileExists(MapsDir
+ P
[1]) then
5972 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5974 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5976 s
:= P
[1] + ':\' + P
[2];
5978 if g_Map_Exist(MapsDir
+ s
) then
5979 begin // Óñòàíàâëèâàåì êàðòó
5980 gExitByTrigger
:= False;
5985 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5987 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5989 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5993 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5994 P
[1] := addWadExtension(P
[1]);
5995 if FileExists(MapsDir
+ P
[1]) then
5998 P
[2] := UpperCase(P
[2]);
5999 s
:= P
[1] + ':\' + P
[2];
6001 if g_Map_Exist(MapsDir
+ s
) then
6002 begin // Íàøëè êàðòó
6003 gExitByTrigger
:= False;
6007 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6009 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6012 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6015 if gNextMap
= '' then
6016 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6018 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6021 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6024 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6026 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6028 gExitByTrigger
:= False;
6029 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6030 if (gNextMap
= '') and (gTriggers
<> nil) then
6031 for a
:= 0 to High(gTriggers
) do
6032 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6034 gExitByTrigger
:= True;
6035 gNextMap
:= gTriggers
[a
].Data
.MapName
;
6038 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6039 if gNextMap
= '' then
6040 gNextMap
:= g_Game_GetNextMap();
6041 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6042 if Pos(':\', gNextMap
) = 0 then
6043 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6046 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6047 if g_Map_Exist(MapsDir
+ s
) then
6048 gExit
:= EXIT_ENDLEVELCUSTOM
6050 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6052 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6054 else if (cmd
= 'event') then
6056 if (Length(P
) <= 1) then
6058 for a
:= 0 to High(gEvents
) do
6059 if gEvents
[a
].Command
= '' then
6060 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6062 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6065 if (Length(P
) = 2) then
6067 for a
:= 0 to High(gEvents
) do
6068 if gEvents
[a
].Name
= P
[1] then
6069 if gEvents
[a
].Command
= '' then
6070 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6072 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6075 for a
:= 0 to High(gEvents
) do
6076 if gEvents
[a
].Name
= P
[1] then
6078 gEvents
[a
].Command
:= '';
6079 for b
:= 2 to High(P
) do
6080 if Pos(' ', P
[b
]) = 0 then
6081 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6083 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6084 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6088 // Êîìàíäû Ñâîåé èãðû:
6089 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6091 if cmd
= 'bot_addred' then
6093 if Length(P
) > 1 then
6094 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6096 g_Bot_Add(TEAM_RED
, 2);
6098 else if cmd
= 'bot_addblue' then
6100 if Length(P
) > 1 then
6101 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6103 g_Bot_Add(TEAM_BLUE
, 2);
6105 else if cmd
= 'suicide' then
6109 if g_Game_IsClient
then
6110 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6113 if gPlayer1
<> nil then
6114 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6115 if gPlayer2
<> nil then
6116 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6120 else if cmd
= 'spectate' then
6126 else if cmd
= 'say' then
6128 if g_Game_IsServer
and g_Game_IsNet
then
6130 if Length(P
) > 1 then
6133 for a
:= 1 to High(P
) do
6134 chstr
:= chstr
+ P
[a
] + ' ';
6136 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6138 if Length(chstr
) < 1 then
6140 g_Console_Add('say <text>');
6144 chstr
:= b_Text_Format(chstr
);
6145 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6147 else g_Console_Add('say <text>');
6149 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6151 else if cmd
= 'tell' then
6153 if g_Game_IsServer
and g_Game_IsNet
then
6155 if (Length(P
) > 2) and (P
[1] <> '') then
6158 for a
:= 2 to High(P
) do
6159 chstr
:= chstr
+ P
[a
] + ' ';
6161 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6163 if Length(chstr
) < 1 then
6165 g_Console_Add('tell <playername> <text>');
6169 pl
:= g_Net_Client_ByName(P
[1]);
6171 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6173 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6175 else g_Console_Add('tell <playername> <text>');
6177 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6179 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6181 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6183 // Äîïîëíèòåëüíîå âðåìÿ:
6184 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6186 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6187 [gGameSettings
.TimeLimit
div 3600,
6188 (gGameSettings
.TimeLimit
div 60) mod 60,
6189 gGameSettings
.TimeLimit
mod 60]));
6190 if g_Game_IsNet
then MH_SEND_GameSettings
;
6192 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6194 if (Length(P
) <= 1) then
6195 g_Console_Add('rcon_password <password>')
6197 MC_SEND_RCONPassword(P
[1]);
6199 else if cmd
= 'rcon' then
6201 if g_Game_IsClient
then
6203 if Length(P
) > 1 then
6206 for a
:= 1 to High(P
) do
6207 chstr
:= chstr
+ P
[a
] + ' ';
6209 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6211 if Length(chstr
) < 1 then
6213 g_Console_Add('rcon <command>');
6217 MC_SEND_RCONCommand(chstr
);
6219 else g_Console_Add('rcon <command>');
6222 else if cmd
= 'ready' then
6224 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6225 gLMSRespawnTime
:= gTime
+ 100;
6227 else if (cmd
= 'callvote') and g_Game_IsNet
then
6229 if Length(P
) > 1 then
6232 for a
:= 1 to High(P
) do begin
6233 if a
> 1 then chstr
:= chstr
+ ' ';
6234 chstr
:= chstr
+ P
[a
];
6237 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6239 if Length(chstr
) < 1 then
6241 g_Console_Add('callvote <command>');
6245 if g_Game_IsClient
then
6246 MC_SEND_Vote(True, chstr
)
6248 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6249 g_Console_Process('vote', True);
6252 g_Console_Add('callvote <command>');
6254 else if (cmd
= 'vote') and g_Game_IsNet
then
6256 if g_Game_IsClient
then
6258 else if gVoteInProgress
then
6260 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6261 a
:= Floor((NetClientCount
+1)/2.0) + 1
6263 a
:= Floor(NetClientCount
/2.0) + 1;
6268 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6269 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6275 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6276 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6284 procedure g_TakeScreenShot();
6292 if e_NoGraphics
then Exit
;
6293 ssdir
:= GameDir
+'/screenshots';
6294 if not findFileCI(ssdir
, true) then
6296 // try to create dir
6301 if not findFileCI(ssdir
, true) then exit
; // alas
6304 for a
:= 1 to High(Word) do
6306 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6308 if findFileCI(t
, true) then continue
;
6309 if not findFileCI(FileName
) then
6312 st
:= createDiskFile(FileName
);
6314 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6319 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6327 procedure g_Game_InGameMenu(Show
: Boolean);
6329 if (g_ActiveWindow
= nil) and Show
then
6331 if gGameSettings
.GameType
= GT_SINGLE
then
6332 g_GUI_ShowWindow('GameSingleMenu')
6335 if g_Game_IsClient
then
6336 g_GUI_ShowWindow('GameClientMenu')
6338 if g_Game_IsNet
then
6339 g_GUI_ShowWindow('GameServerMenu')
6341 g_GUI_ShowWindow('GameCustomMenu');
6343 g_Sound_PlayEx('MENU_OPEN');
6345 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6346 if (not g_Game_IsNet
) then
6350 if (g_ActiveWindow
<> nil) and (not Show
) then
6352 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6353 if (not g_Game_IsNet
) then
6354 g_Game_Pause(False);
6358 procedure g_Game_Pause(Enable
: Boolean);
6363 if gPause
= Enable
then
6366 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6370 g_Game_PauseAllSounds(Enable
);
6373 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6378 if gTriggers
<> nil then
6379 for i
:= 0 to High(gTriggers
) do
6380 with gTriggers
[i
] do
6381 if (TriggerType
= TRIGGER_SOUND
) and
6383 Sound
.IsPlaying() then
6385 Sound
.Pause(Enable
);
6389 if gPlayers
<> nil then
6390 for i
:= 0 to High(gPlayers
) do
6391 if gPlayers
[i
] <> nil then
6392 gPlayers
[i
].PauseSounds(Enable
);
6395 if gMusic
<> nil then
6396 gMusic
.Pause(Enable
);
6399 procedure g_Game_StopAllSounds(all
: Boolean);
6403 if gTriggers
<> nil then
6404 for i
:= 0 to High(gTriggers
) do
6405 with gTriggers
[i
] do
6406 if (TriggerType
= TRIGGER_SOUND
) and
6410 if gMusic
<> nil then
6417 procedure g_Game_UpdateTriggerSounds();
6421 if gTriggers
<> nil then
6422 for i
:= 0 to High(gTriggers
) do
6423 with gTriggers
[i
] do
6424 if (TriggerType
= TRIGGER_SOUND
) and
6427 Sound
.IsPlaying() then
6429 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6430 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6432 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6433 Sound
.SetVolume(Data
.Volume
/255.0);
6436 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6440 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6443 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6448 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6453 if gSpectMode
<> SPECT_PLAYERS
then
6455 if gSpectPID1
= UID
then
6460 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6467 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6472 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6477 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6482 if gSpectMode
<> SPECT_PLAYERS
then
6484 Pl
:= g_Player_Get(gSpectPID1
);
6485 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6490 if gSpectViewTwo
then
6492 Pl
:= g_Player_Get(gSpectPID2
);
6493 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6501 procedure g_Game_Message(Msg
: string; Time
: Word);
6503 MessageText
:= b_Text_Format(Msg
);
6504 MessageTime
:= Time
;
6507 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6516 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6520 if goodsnd
[a
].IsPlaying() then
6523 goodsnd
[Random(4)].Play();
6526 procedure g_Game_Announce_KillCombo(Param
: Integer);
6533 UID
:= Param
and $FFFF;
6538 Pl
:= g_Player_Get(UID
);
6547 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6551 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6555 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6559 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6567 if not g_Game_IsWatchedPlayer(UID
) then
6570 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6574 if killsnd
[n
].IsPlaying() then
6579 procedure g_Game_StartVote(Command
, Initiator
: string);
6583 if not gVotesEnabled
then Exit
;
6584 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6585 if gVoteInProgress
or gVotePassed
then
6587 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6588 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6591 gVoteInProgress
:= True;
6592 gVotePassed
:= False;
6593 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6596 gVoteCommand
:= Command
;
6598 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6599 Need
:= Floor((NetClientCount
+1)/2.0)+1
6601 Need
:= Floor(NetClientCount
/2.0)+1;
6602 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6603 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6606 procedure g_Game_CheckVote
;
6610 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6611 if not gVoteInProgress
then Exit
;
6613 if (gTime
>= gVoteTimer
) then
6615 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6616 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6618 Need
:= Floor(NetClientCount
/2.0) + 1;
6619 if gVoteCount
>= Need
then
6621 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6622 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6623 gVotePassed
:= True;
6624 gVoteCmdTimer
:= gTime
+ 5000;
6628 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6629 MH_SEND_VoteEvent(NET_VE_FAILED
);
6631 if NetClients
<> nil then
6632 for I
:= Low(NetClients
) to High(NetClients
) do
6633 if NetClients
[i
].Used
then
6634 NetClients
[i
].Voted
:= False;
6635 gVoteInProgress
:= False;
6641 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6642 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6644 Need
:= Floor(NetClientCount
/2.0) + 1;
6645 if gVoteCount
>= Need
then
6647 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6648 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6649 gVoteInProgress
:= False;
6650 gVotePassed
:= True;
6651 gVoteCmdTimer
:= gTime
+ 5000;
6654 if NetClients
<> nil then
6655 for I
:= Low(NetClients
) to High(NetClients
) do
6656 if NetClients
[i
].Used
then
6657 NetClients
[i
].Voted
:= False;
6662 procedure g_Game_LoadMapList(FileName
: string);
6670 if not FileExists(FileName
) then Exit
;
6672 AssignFile(ListFile
, FileName
);
6674 while not EOF(ListFile
) do
6676 ReadLn(ListFile
, s
);
6679 if s
= '' then Continue
;
6681 SetLength(MapList
, Length(MapList
)+1);
6682 MapList
[High(MapList
)] := s
;
6684 CloseFile(ListFile
);
6687 procedure g_Game_SetDebugMode();
6690 // ×èòû (äàæå â ñâîåé èãðå):
6694 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6698 if Length(LoadingStat
.Msgs
) = 0 then
6704 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6705 if NextMsg
= Length(Msgs
) then
6707 for i
:= 0 to High(Msgs
)-1 do
6708 Msgs
[i
] := Msgs
[i
+1];
6716 Msgs
[NextMsg
-1] := Text;
6722 g_ActiveWindow
:= nil;
6727 procedure g_Game_StepLoading();
6733 if (ShowCount
> LOADING_SHOW_STEP
) then
6741 procedure g_Game_ClearLoading();
6750 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6751 if len
< 1 then len
:= 1;
6752 SetLength(Msgs
, len
);
6753 for len
:= Low(Msgs
) to High(Msgs
) do
6759 procedure Parse_Params(var pars
: TParamStrValues
);
6766 while i
<= ParamCount
do
6769 if (s
[1] = '-') and (Length(s
) > 1) then
6771 if (s
[2] = '-') and (Length(s
) > 2) then
6772 begin // Îäèíî÷íûé ïàðàìåòð
6773 SetLength(pars
, Length(pars
) + 1);
6774 with pars
[High(pars
)] do
6776 Name
:= LowerCase(s
);
6781 if (i
< ParamCount
) then
6782 begin // Ïàðàìåòð ñî çíà÷åíèåì
6784 SetLength(pars
, Length(pars
) + 1);
6785 with pars
[High(pars
)] do
6787 Name
:= LowerCase(s
);
6788 Value
:= LowerCase(ParamStr(i
));
6797 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6802 for i
:= 0 to High(pars
) do
6803 if pars
[i
].Name
= aName
then
6805 Result
:= pars
[i
].Value
;
6810 procedure g_Game_Process_Params();
6812 pars
: TParamStrValues
;
6815 LimT
, LimS
: Integer;
6826 s
:= Find_Param_Value(pars
, '--debug');
6829 g_Game_SetDebugMode();
6830 s
:= Find_Param_Value(pars
, '--netdump');
6835 // Connect when game loads
6836 ip
:= Find_Param_Value(pars
, '-connect');
6840 s
:= Find_Param_Value(pars
, '-port');
6841 if (s
= '') or not TryStrToInt(s
, Port
) then
6844 s
:= Find_Param_Value(pars
, '-pw');
6846 g_Game_StartClient(ip
, Port
, s
);
6850 // Start map when game loads:
6851 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6852 if isWadPath(map
) then
6855 s
:= Find_Param_Value(pars
, '-gm');
6856 GMode
:= g_Game_TextToMode(s
);
6857 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6858 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6861 s
:= Find_Param_Value(pars
, '-limt');
6862 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6868 s
:= Find_Param_Value(pars
, '-lims');
6869 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6875 s
:= Find_Param_Value(pars
, '-lives');
6876 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6882 s
:= Find_Param_Value(pars
, '-opt');
6884 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6886 Opt
:= StrToIntDef(s
, 0);
6888 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6891 s
:= Find_Param_Value(pars
, '--close');
6895 // Delete test map after play:
6896 s
:= Find_Param_Value(pars
, '--testdelete');
6899 gMapToDelete
:= MapsDir
+ map
;
6900 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6904 // Delete temporary WAD after play:
6905 s
:= Find_Param_Value(pars
, '--tempdelete');
6908 gMapToDelete
:= MapsDir
+ map
;
6909 gTempDelete
:= True;
6912 // Number of players:
6913 s
:= Find_Param_Value(pars
, '-pl');
6917 n
:= StrToIntDef(s
, 1);
6920 s
:= Find_Param_Value(pars
, '-port');
6921 if (s
= '') or not TryStrToInt(s
, Port
) then
6922 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6924 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6927 // Execute script when game loads:
6928 s
:= Find_Param_Value(pars
, '-exec');
6931 if Pos(':\', s
) = 0 then
6932 s
:= GameDir
+ '/' + s
;
6937 if IOResult
<> 0 then
6939 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6940 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6944 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6945 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6950 if IOResult
<> 0 then
6952 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6953 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6957 if Pos('#', s
) <> 1 then // script comment
6958 g_Console_Process(s
, True);