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}
24 g_basic
, g_player
, e_graphics
, g_res_downloader
,
25 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
29 TGameSettings
= record
45 TDelayedEvent
= record
54 Sound
: TPlayableSound
;
55 Tags
: Array of String;
59 TPlayerSettings
= record
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures
: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
90 function g_Game_ModeToText(Mode
: Byte): string;
91 function g_Game_TextToMode(Mode
: string): Byte;
92 procedure g_Game_ExecuteEvent(Name
: String);
93 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
99 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
100 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
105 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
106 procedure g_Game_SaveOptions();
107 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath
: String);
109 procedure g_Game_ExitLevel(const Map
: AnsiString);
110 function g_Game_GetFirstMap(WAD
: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable
: Boolean);
114 procedure g_Game_HolmesPause(Enable
: Boolean);
115 procedure g_Game_InGameMenu(Show
: Boolean);
116 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
118 procedure g_Game_Message(Msg
: String; Time
: Word);
119 procedure g_Game_LoadMapList(FileName
: String);
120 procedure g_Game_PauseAllSounds(Enable
: Boolean);
121 procedure g_Game_StopAllSounds(all
: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
124 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
126 procedure g_Game_Announce_KillCombo(Param
: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
128 procedure g_Game_StartVote(Command
, Initiator
: string);
129 procedure g_Game_CheckVote
;
130 procedure g_TakeScreenShot();
131 procedure g_FatalError(Text: String);
132 procedure g_SimpleError(Text: String);
133 function g_Game_IsTestMap(): Boolean;
134 procedure g_Game_DeleteTestMap();
135 procedure GameCVars(P
: SSArray
);
136 procedure GameCommands(P
: SSArray
);
137 procedure GameCheats(P
: SSArray
);
138 procedure DebugCommands(P
: SSArray
);
139 procedure g_Game_Process_Params
;
140 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
141 procedure g_Game_StepLoading(Value
: Integer = -1);
142 procedure g_Game_ClearLoading();
143 procedure g_Game_SetDebugMode();
144 procedure DrawLoadingStat();
146 { procedure SetWinPause(Enable: Boolean); }
151 LOADING_SHOW_STEP
= 100;
152 LOADING_INTERLINE
= 20;
167 MESSAGE_DIKEY
= WM_USER
+ 1;
172 EXIT_ENDLEVELSINGLE
= 4;
173 EXIT_ENDLEVELCUSTOM
= 5;
175 GAME_OPTION_RESERVED
= 1;
176 GAME_OPTION_TEAMDAMAGE
= 2;
177 GAME_OPTION_ALLOWEXIT
= 4;
178 GAME_OPTION_WEAPONSTAY
= 8;
179 GAME_OPTION_MONSTERS
= 16;
180 GAME_OPTION_BOTVSPLAYER
= 32;
181 GAME_OPTION_BOTVSMONSTER
= 64;
186 STATE_INTERCUSTOM
= 3;
187 STATE_INTERSINGLE
= 4;
193 LMS_RESPAWN_NONE
= 0;
194 LMS_RESPAWN_WARMUP
= 1;
195 LMS_RESPAWN_FINAL
= 2;
212 CONFIG_FILENAME
= 'Doom2DF.cfg';
213 LOG_FILENAME
= 'Doom2DF.log';
215 TEST_MAP_NAME
= '$$$_TEST_$$$';
217 STD_PLAYER_MODEL
= 'Doomer';
221 gGameSettings
: TGameSettings
;
222 gPlayer1Settings
: TPlayerSettings
;
223 gPlayer2Settings
: TPlayerSettings
;
225 gPlayerScreenSize
: TDFPoint
;
226 gPlayer1ScreenCoord
: TDFPoint
;
227 gPlayer2ScreenCoord
: TDFPoint
;
228 gPlayer1
: TPlayer
= nil;
229 gPlayer2
: TPlayer
= nil;
230 gPlayerDrawn
: TPlayer
= nil;
232 gSwitchGameMode
: Byte = GM_DM
;
233 gHearPoint1
, gHearPoint2
: THearPoint
;
234 gSoundEffectsDF
: Boolean = False;
235 gSoundTriggerTime
: Word = 0;
236 gAnnouncer
: Byte = ANNOUNCE_NONE
;
237 goodsnd
: array[0..3] of TPlayableSound
;
238 killsnd
: array[0..3] of TPlayableSound
;
239 hahasnd
: array[0..2] of TPlayableSound
;
240 gBodyKillEvent
: Integer = -1;
241 gDefInterTime
: ShortInt = -1;
242 gInterEndTime
: LongWord = 0;
243 gInterTime
: LongWord = 0;
244 gServInterTime
: Byte = 0;
245 gGameStartTime
: LongWord = 0;
246 gTotalMonsters
: Integer = 0;
247 gPauseMain
: Boolean = false;
248 gPauseHolmes
: Boolean = false;
249 gShowTime
: Boolean = True;
250 gShowFPS
: Boolean = False;
251 gShowGoals
: Boolean = True;
252 gShowStat
: Boolean = True;
253 gShowKillMsg
: Boolean = True;
254 gShowLives
: Boolean = True;
255 gShowPing
: Boolean = False;
256 gShowMap
: Boolean = False;
258 gState
: Byte = STATE_NONE
;
260 sWidth
, sHeight
: Word;
261 gSpectMode
: Byte = SPECT_NONE
;
262 gSpectHUD
: Boolean = True;
263 gSpectKeyPress
: Boolean = False;
264 gSpectX
: Integer = 0;
265 gSpectY
: Integer = 0;
266 gSpectStep
: Byte = 8;
267 gSpectViewTwo
: Boolean = False;
268 gSpectPID1
: Integer = -1;
269 gSpectPID2
: Integer = -1;
270 gSpectAuto
: Boolean = False;
271 gSpectAutoNext
: LongWord;
272 gSpectAutoStepX
: Integer;
273 gSpectAutoStepY
: Integer;
274 gMusic
: TMusic
= nil;
275 gLoadGameMode
: Boolean;
276 gCheats
: Boolean = False;
277 gMapOnce
: Boolean = False;
278 gMapToDelete
: String;
279 gTempDelete
: Boolean = False;
280 gLastMap
: Boolean = False;
281 gWinPosX
, gWinPosY
: Integer;
282 gWinSizeX
, gWinSizeY
: Integer;
283 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
284 gWinActive
: Boolean = True; // by default window is active, lol
285 gResolutionChange
: Boolean = False;
286 gRC_Width
, gRC_Height
: Word;
287 gRC_FullScreen
, gRC_Maximized
: Boolean;
288 gLanguageChange
: Boolean = False;
289 gDebugMode
: Boolean = False;
290 g_debug_Sounds
: Boolean = False;
291 g_debug_Frames
: Boolean = False;
292 g_debug_WinMsgs
: Boolean = False;
293 g_debug_MonsterOff
: Boolean = False;
294 g_debug_BotAIOff
: Byte = 0;
295 g_debug_HealthBar
: Boolean = False;
296 g_Debug_Player
: Boolean = False;
297 gCoopMonstersKilled
: Word = 0;
298 gCoopSecretsFound
: Word = 0;
299 gCoopTotalMonstersKilled
: Word = 0;
300 gCoopTotalSecretsFound
: Word = 0;
301 gCoopTotalMonsters
: Word = 0;
302 gCoopTotalSecrets
: Word = 0;
303 gStatsOff
: Boolean = False;
304 gStatsPressed
: Boolean = False;
305 gExitByTrigger
: Boolean = False;
306 gNextMap
: String = '';
307 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
308 gLMSRespawnTime
: Cardinal = 0;
309 gLMSSoftSpawn
: Boolean = False;
310 gMissionFailed
: Boolean = False;
311 gVoteInProgress
: Boolean = False;
312 gVotePassed
: Boolean = False;
313 gVoteCommand
: string = '';
314 gVoteTimer
: Cardinal = 0;
315 gVoteCmdTimer
: Cardinal = 0;
316 gVoteCount
: Integer = 0;
317 gVoteTimeout
: Cardinal = 30;
318 gVoted
: Boolean = False;
319 gVotesEnabled
: Boolean = True;
320 gEvents
: Array of TGameEvent
;
321 gDelayedEvents
: Array of TDelayedEvent
;
322 gUseChatSounds
: Boolean = True;
323 gChatSounds
: Array of TChatSound
;
325 g_dbg_ignore_bounds
: Boolean = false;
326 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
327 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
329 // move button values:
330 // bits 0-1: l/r state:
331 // 0: neither left, nor right pressed
334 // bits 4-5: l/r state when strafe was pressed
335 P1MoveButton
: Byte = 0;
336 P2MoveButton
: Byte = 0;
338 g_profile_frame_update
: Boolean = false;
339 g_profile_frame_draw
: Boolean = false;
340 g_profile_collision
: Boolean = false;
341 g_profile_los
: Boolean = false;
342 g_profile_history_size
: Integer = 1000;
344 g_rlayer_back
: Boolean = true;
345 g_rlayer_step
: Boolean = true;
346 g_rlayer_wall
: Boolean = true;
347 g_rlayer_door
: Boolean = true;
348 g_rlayer_acid1
: Boolean = true;
349 g_rlayer_acid2
: Boolean = true;
350 g_rlayer_water
: Boolean = true;
351 g_rlayer_fore
: Boolean = true;
354 procedure g_ResetDynlights ();
355 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
356 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
358 function conIsCheatsEnabled (): Boolean; inline;
359 function gPause (): Boolean; inline;
365 {$INCLUDE ../nogl/noGLuses.inc}
366 {$IFDEF ENABLE_HOLMES}
369 e_texture
, g_textures
, g_main
, g_window
, g_menu
,
370 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
371 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
372 g_triggers
, g_monsters
, e_sound
, CONFIG
,
374 ENet
, e_msg
, g_netmsg
, g_netmaster
,
379 hasPBarGfx
: Boolean = false;
382 // ////////////////////////////////////////////////////////////////////////// //
383 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
386 // ////////////////////////////////////////////////////////////////////////// //
387 function conIsCheatsEnabled (): Boolean; inline;
390 if g_Game_IsNet
then exit
;
391 if not gDebugMode
then
393 //if not gCheats then exit;
394 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
395 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
401 // ////////////////////////////////////////////////////////////////////////// //
403 profileFrameDraw
: TProfiler
= nil;
406 // ////////////////////////////////////////////////////////////////////////// //
409 x
, y
, radius
: Integer;
412 exploRadius
: Integer;
416 g_dynLights
: array of TDynLight
= nil;
417 g_dynLightCount
: Integer = 0;
418 g_playerLight
: Boolean = false;
420 procedure g_ResetDynlights ();
424 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
426 for idx
:= 0 to g_dynLightCount
-1 do
428 if g_dynLights
[idx
].exploCount
= -666 then
435 Inc(g_dynLights
[idx
].exploCount
);
436 if (g_dynLights
[idx
].exploCount
< 10) then
438 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
439 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
440 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
441 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
446 g_dynLightCount
:= lnum
;
449 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
451 if not gwin_has_stencil
then exit
;
452 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
453 g_dynLights
[g_dynLightCount
].x
:= x
;
454 g_dynLights
[g_dynLightCount
].y
:= y
;
455 g_dynLights
[g_dynLightCount
].radius
:= radius
;
456 g_dynLights
[g_dynLightCount
].r
:= r
;
457 g_dynLights
[g_dynLightCount
].g
:= g
;
458 g_dynLights
[g_dynLightCount
].b
:= b
;
459 g_dynLights
[g_dynLightCount
].a
:= a
;
460 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
461 Inc(g_dynLightCount
);
464 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
466 if not gwin_has_stencil
then exit
;
467 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
468 g_dynLights
[g_dynLightCount
].x
:= x
;
469 g_dynLights
[g_dynLightCount
].y
:= y
;
470 g_dynLights
[g_dynLightCount
].radius
:= 0;
471 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
472 g_dynLights
[g_dynLightCount
].r
:= r
;
473 g_dynLights
[g_dynLightCount
].g
:= g
;
474 g_dynLights
[g_dynLightCount
].b
:= b
;
475 g_dynLights
[g_dynLightCount
].a
:= 0;
476 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
477 Inc(g_dynLightCount
);
481 // ////////////////////////////////////////////////////////////////////////// //
482 function calcProfilesHeight (prof
: TProfiler
): Integer;
485 if (prof
= nil) then exit
;
486 if (length(prof
.bars
) = 0) then exit
;
487 result
:= length(prof
.bars
)*(16+2);
491 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
498 if (prof
= nil) then exit
;
500 if (length(prof
.bars
) = 0) then exit
;
502 hgt
:= calcProfilesHeight(prof
);
503 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
504 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
506 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
507 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
508 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
511 for ii
:= 0 to High(prof
.bars
) do
513 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);
520 // ////////////////////////////////////////////////////////////////////////// //
522 TEndCustomGameStat
= record
523 PlayerStat
: TPlayerStatArray
;
527 Map
, MapName
: String;
530 TEndSingleGameStat
= record
531 PlayerStat
: Array [0..1] of record
537 TotalSecrets
: Integer;
540 TLoadingStat
= record
544 Msgs
: Array of String;
546 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
549 TParamStrValue
= record
554 TParamStrValues
= Array of TParamStrValue
;
557 INTER_ACTION_TEXT
= 1;
558 INTER_ACTION_PIC
= 2;
559 INTER_ACTION_MUSIC
= 3;
563 FPSCounter
, UPSCounter
: Word;
564 FPSTime
, UPSTime
: LongWord;
565 DataLoaded
: Boolean = False;
566 LastScreenShot
: Int64;
567 IsDrawStat
: Boolean = False;
568 CustomStat
: TEndCustomGameStat
;
569 SingleStat
: TEndSingleGameStat
;
570 LoadingStat
: TLoadingStat
;
571 EndingGameCounter
: Byte = 0;
574 MessageLineLength
: Integer = 80;
575 MapList
: SSArray
= nil;
576 MapIndex
: Integer = -1;
582 text: Array of ShortString;
583 anim
: Array of ShortString;
584 pic
: Array of ShortString;
585 mus
: Array of ShortString;
587 triggers
: Array of record
589 actions
: Array of record
590 action
, p1
, p2
: Integer;
593 cur_trigger
: Integer;
606 function Compare(a
, b
: TPlayerStat
): Integer;
608 if a
.Spectator
then Result
:= 1
609 else if b
.Spectator
then Result
:= -1
610 else if a
.Frags
< b
.Frags
then Result
:= 1
611 else if a
.Frags
> b
.Frags
then Result
:= -1
612 else if a
.Deaths
< b
.Deaths
then Result
:= -1
613 else if a
.Deaths
> b
.Deaths
then Result
:= 1
614 else if a
.Kills
< b
.Kills
then Result
:= -1
618 procedure SortGameStat(var stat
: TPlayerStatArray
);
623 if stat
= nil then Exit
;
625 for I
:= High(stat
) downto Low(stat
) do
626 for J
:= Low(stat
) to High(stat
) - 1 do
627 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
630 stat
[J
] := stat
[J
+ 1];
635 function g_Game_ModeToText(Mode
: Byte): string;
639 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
640 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
641 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
642 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
643 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
647 function g_Game_TextToMode(Mode
: string): Byte;
650 Mode
:= UpperCase(Mode
);
651 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
656 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
661 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
666 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
671 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
678 function g_Game_IsNet(): Boolean;
680 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
683 function g_Game_IsServer(): Boolean;
685 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
688 function g_Game_IsClient(): Boolean;
690 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
693 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
700 Result
.name
:= ExtractFileName(WAD
);
701 Result
.description
:= '';
704 w
:= TWADFile
.Create();
707 if not w
.GetResource('INTERSCRIPT', p
, len
) then
713 cfg
:= TConfig
.CreateMem(p
, len
);
714 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
715 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
716 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
717 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
723 procedure g_Game_FreeWAD();
727 for a
:= 0 to High(MegaWAD
.res
.pic
) do
728 if MegaWAD
.res
.pic
[a
] <> '' then
729 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
731 for a
:= 0 to High(MegaWAD
.res
.mus
) do
732 if MegaWAD
.res
.mus
[a
] <> '' then
733 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
735 MegaWAD
.res
.pic
:= nil;
736 MegaWAD
.res
.text := nil;
737 MegaWAD
.res
.anim
:= nil;
738 MegaWAD
.res
.mus
:= nil;
739 MegaWAD
.triggers
:= nil;
741 g_Texture_Delete('TEXTURE_endpic');
742 g_Sound_Delete('MUSIC_endmus');
744 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
745 gGameSettings
.WAD
:= '';
748 procedure g_Game_LoadWAD(WAD
: string);
757 gGameSettings
.WAD
:= WAD
;
758 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
761 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
763 w
:= TWADFile
.Create();
764 w
.ReadFile(MapsDir
+ WAD
);
766 if not w
.GetResource('INTERSCRIPT', p
, len
) then
772 cfg
:= TConfig
.CreateMem(p
, len
);
777 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
778 if s = '' then Break;
781 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
782 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
784 g_Texture_CreateWADEx(s, s);
790 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
791 if s = '' then Break;
794 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
795 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
797 g_Music_CreateWADEx(s, s);
800 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
801 if MegaWAD
.endpic
<> '' then
803 s
:= g_ExtractWadName(MegaWAD
.endpic
);
804 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
805 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
807 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
808 if MegaWAD
.endmus
<> '' then
810 s
:= g_ExtractWadName(MegaWAD
.endmus
);
811 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
812 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
820 {procedure start_trigger(t: string);
824 function next_trigger(): Boolean;
828 procedure DisableCheats();
834 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
835 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
836 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
837 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
839 {$IF DEFINED(D2F_DEBUG)}
840 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
841 gAimLine
:= g_dbg_aimline_on
;
845 procedure g_Game_ExecuteEvent(Name
: String);
851 if gEvents
= nil then
853 for a
:= 0 to High(gEvents
) do
854 if gEvents
[a
].Name
= Name
then
856 if gEvents
[a
].Command
<> '' then
857 g_Console_Process(gEvents
[a
].Command
, True);
862 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
867 if gDelayedEvents
<> nil then
868 for a
:= 0 to High(gDelayedEvents
) do
869 if not gDelayedEvents
[a
].Pending
then
876 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
877 n
:= High(gDelayedEvents
);
879 gDelayedEvents
[n
].Pending
:= True;
880 gDelayedEvents
[n
].DEType
:= DEType
;
881 gDelayedEvents
[n
].DENum
:= Num
;
882 gDelayedEvents
[n
].DEStr
:= Str
;
883 if DEType
= DE_GLOBEVENT
then
884 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
886 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
895 if g_Game_IsNet
and g_Game_IsServer
then
896 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
900 gPauseHolmes
:= false;
903 g_Game_StopAllSounds(False);
908 EndingGameCounter
:= 0;
909 g_ActiveWindow
:= nil;
911 gLMSRespawn
:= LMS_RESPAWN_NONE
;
912 gLMSRespawnTime
:= 0;
915 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
920 begin // Ýòî áûë òåñò
924 begin // Âûõîä â ãëàâíîå ìåíþ
925 gMusic
.SetByName('MUSIC_MENU');
927 if gState
<> STATE_SLIST
then
929 g_GUI_ShowWindow('MainMenu');
930 gState
:= STATE_MENU
;
933 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
934 slReturnPressed
:= True;
935 if g_Net_Slist_Fetch(slCurrent
) then
937 if slCurrent
= nil then
938 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
941 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
942 g_Serverlist_GenerateTable(slCurrent
, slTable
);
945 g_Game_ExecuteEvent('ongameend');
949 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
951 if not g_Game_IsClient
then g_Game_Restart();
954 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
956 // Ñòàòèñòèêà Ñâîåé èãðû:
957 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
959 CustomStat
.GameTime
:= gTime
;
960 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
961 CustomStat
.MapName
:= gMapInfo
.Name
;
962 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
963 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
964 CustomStat
.TeamStat
:= gTeamStat
;
966 CustomStat
.PlayerStat
:= nil;
968 // Ñòàòèñòèêà èãðîêîâ:
969 if gPlayers
<> nil then
971 for a
:= 0 to High(gPlayers
) do
972 if gPlayers
[a
] <> nil then
974 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
975 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
977 Name
:= gPlayers
[a
].Name
;
978 Frags
:= gPlayers
[a
].Frags
;
979 Deaths
:= gPlayers
[a
].Death
;
980 Kills
:= gPlayers
[a
].Kills
;
981 Team
:= gPlayers
[a
].Team
;
982 Color
:= gPlayers
[a
].Model
.Color
;
983 Spectator
:= gPlayers
[a
].FSpectator
;
987 SortGameStat(CustomStat
.PlayerStat
);
990 g_Game_ExecuteEvent('onmapend');
993 EndingGameCounter
:= 255;
994 gState
:= STATE_FOLD
;
996 if gDefInterTime
< 0 then
997 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
999 gInterEndTime
:= gDefInterTime
* 1000;
1002 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1004 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1005 SingleStat
.GameTime
:= gTime
;
1006 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1007 SingleStat
.TotalSecrets
:= gSecretsCount
;
1008 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1009 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1010 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1011 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1012 if SingleStat
.TwoPlayers
then
1014 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1015 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1018 g_Game_ExecuteEvent('onmapend');
1021 if gNextMap
<> '' then
1023 gMusic
.SetByName('MUSIC_INTERMUS');
1025 gState
:= STATE_INTERSINGLE
;
1028 g_Game_ExecuteEvent('oninter');
1030 else // Áîëüøå íåò êàðò
1032 // Çàòóõàþùèé ýêðàí:
1033 EndingGameCounter
:= 255;
1034 gState
:= STATE_FOLD
;
1039 // Îêîí÷àíèå îáðàáîòàíî:
1040 if gExit
<> EXIT_QUIT
then
1044 procedure drawTime(X
, Y
: Integer); inline;
1046 e_TextureFontPrint(x
, y
,
1047 Format('%d:%.2d:%.2d', [
1048 gTime
div 1000 div 3600,
1049 (gTime
div 1000 div 60) mod 60,
1050 gTime
div 1000 mod 60
1055 procedure DrawStat();
1057 pc
, x
, y
, w
, h
: Integer;
1058 w1
, w2
, w3
, w4
: Integer;
1060 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1063 stat
: TPlayerStatArray
;
1070 pc
:= g_Player_GetCount
;
1071 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1073 w
:= gScreenWidth
-(gScreenWidth
div 5);
1074 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1077 h
:= 40+ch
*5+(ch
+8)*pc
;
1078 x
:= (gScreenWidth
div 2)-(w
div 2);
1079 y
:= (gScreenHeight
div 2)-(h
div 2);
1081 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1082 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1084 drawTime(x
+w
-78, y
+8);
1086 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1087 map
:= g_ExtractFileName(gMapInfo
.Map
);
1088 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1090 case gGameSettings
.GameMode
of
1093 if gGameSettings
.MaxLives
= 0 then
1094 s1
:= _lc
[I_GAME_DM
]
1096 s1
:= _lc
[I_GAME_LMS
];
1097 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1098 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1103 if gGameSettings
.MaxLives
= 0 then
1104 s1
:= _lc
[I_GAME_TDM
]
1106 s1
:= _lc
[I_GAME_TLMS
];
1107 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1108 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1113 s1
:= _lc
[I_GAME_CTF
];
1114 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1115 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1120 if gGameSettings
.MaxLives
= 0 then
1121 s1
:= _lc
[I_GAME_COOP
]
1123 s1
:= _lc
[I_GAME_SURV
];
1124 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1125 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1136 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1138 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1140 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1142 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1143 gStdFont
, 200, 200, 200, 1);
1145 if NetMode
= NET_SERVER
then
1146 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1148 if NetMode
= NET_CLIENT
then
1149 e_TextureFontPrintEx(x
+8, y
+ 8,
1150 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1154 stat
:= g_Player_GetStats();
1157 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1158 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1160 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1162 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1166 for a
:= TEAM_RED
to TEAM_BLUE
do
1168 if a
= TEAM_RED
then
1170 s1
:= _lc
[I_GAME_TEAM_RED
];
1177 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1183 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1184 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1185 gStdFont
, r
, g
, b
, 1);
1187 _y
:= _y
+ch
+(ch
div 4);
1188 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1189 _y
:= _y
+(ch
div 4);
1191 for aa
:= 0 to High(stat
) do
1192 if stat
[aa
].Team
= a
then
1208 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1210 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1212 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1214 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1221 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1224 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1225 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1226 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1227 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1230 for aa
:= 0 to High(stat
) do
1244 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1245 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1247 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1249 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1251 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1253 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1259 procedure g_Game_Init();
1265 gTempDelete
:= False;
1267 sfsGCDisable(); // temporary disable removing of temporary volumes
1270 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1271 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1272 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1273 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1275 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1276 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1277 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1279 g_Game_ClearLoading();
1280 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1281 g_Game_SetLoadingText('', 0, False);
1283 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1286 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1287 g_PlayerModel_LoadData();
1289 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1291 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1292 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1293 until FindNext(SR
) <> 0;
1296 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1298 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1299 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1300 until FindNext(SR
) <> 0;
1303 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1305 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1306 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1307 until FindNext(SR
) <> 0;
1311 gPauseMain
:= false;
1312 gPauseHolmes
:= false;
1314 LastScreenShot
:= 0;
1316 {e_MouseInfo.Accel := 1.0;}
1318 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1321 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1322 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1323 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1324 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1325 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1327 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1330 gMusic
:= TMusic
.Create();
1331 gMusic
.SetByName('MUSIC_MENU');
1334 gGameSettings
.WarmupTime
:= 30;
1336 gState
:= STATE_MENU
;
1338 SetLength(gEvents
, 6);
1339 gEvents
[0].Name
:= 'ongamestart';
1340 gEvents
[1].Name
:= 'ongameend';
1341 gEvents
[2].Name
:= 'onmapstart';
1342 gEvents
[3].Name
:= 'onmapend';
1343 gEvents
[4].Name
:= 'oninter';
1344 gEvents
[5].Name
:= 'onwadend';
1346 sfsGCEnable(); // enable releasing unused volumes
1350 procedure g_Game_Free(freeTextures
: Boolean=true);
1352 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1353 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1355 g_Map_Free(freeTextures
);
1357 g_Player_RemoveAllCorpses();
1359 gGameSettings
.GameType
:= GT_NONE
;
1360 if gGameSettings
.GameMode
= GM_SINGLE
then
1361 gGameSettings
.GameMode
:= GM_DM
;
1362 gSwitchGameMode
:= gGameSettings
.GameMode
;
1365 gExitByTrigger
:= False;
1368 function IsActivePlayer(p
: TPlayer
): Boolean;
1373 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1376 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1383 if gPlayers
= nil then
1385 for a
:= Low(gPlayers
) to High(gPlayers
) do
1386 if IsActivePlayer(gPlayers
[a
]) then
1388 if gPlayers
[a
].UID
<> ID
then
1390 Result
:= gPlayers
[a
];
1395 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1401 if gPlayers
= nil then
1405 for a
:= Low(gPlayers
) to High(gPlayers
) do
1406 if IsActivePlayer(gPlayers
[a
]) then
1408 SetLength(ids
, Length(ids
) + 1);
1409 ids
[High(ids
)] := gPlayers
[a
].UID
;
1410 if gPlayers
[a
].UID
= Skip
then
1413 if Length(ids
) = 0 then
1418 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1421 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1427 if gPlayers
= nil then
1431 for a
:= Low(gPlayers
) to High(gPlayers
) do
1432 if IsActivePlayer(gPlayers
[a
]) then
1434 SetLength(ids
, Length(ids
) + 1);
1435 ids
[High(ids
)] := gPlayers
[a
].UID
;
1436 if gPlayers
[a
].UID
= Skip
then
1439 if Length(ids
) = 0 then
1442 Result
:= ids
[Length(ids
) - 1]
1444 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1447 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1453 if gPlayers
= nil then
1457 for a
:= Low(gPlayers
) to High(gPlayers
) do
1458 if IsActivePlayer(gPlayers
[a
]) then
1460 SetLength(ids
, Length(ids
) + 1);
1461 ids
[High(ids
)] := gPlayers
[a
].UID
;
1462 if gPlayers
[a
].UID
= Skip
then
1465 if Length(ids
) = 0 then
1467 if Length(ids
) = 1 then
1472 Result
:= ids
[Random(Length(ids
))];
1474 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1476 Result
:= ids
[Random(Length(ids
))];
1481 function GetRandomSpectMode(Current
: Byte): Byte;
1488 0: Result
:= SPECT_STATS
;
1489 1: Result
:= SPECT_MAPVIEW
;
1490 2: Result
:= SPECT_MAPVIEW
;
1491 3: Result
:= SPECT_PLAYERS
;
1492 4: Result
:= SPECT_PLAYERS
;
1493 5: Result
:= SPECT_PLAYERS
;
1494 6: Result
:= SPECT_PLAYERS
;
1496 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1500 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1502 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1503 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1507 function isOneKeyPressed (key1
: Word): Boolean;
1509 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1513 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1520 if (plr
= nil) then exit
;
1521 if (p2hack
) then time
:= 1000 else time
:= 1;
1522 strafeDir
:= MoveButton
shr 4;
1523 MoveButton
:= MoveButton
and $0F;
1526 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1527 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1528 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1530 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1531 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1532 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1534 // if we have "strafe" key, turn off old strafe mechanics
1535 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1537 // new strafe mechanics
1538 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1539 // now set direction according to strafe (reversed)
1540 if (strafeDir
= 2) then plr
.SetDirection(TDirection
.D_LEFT
)
1541 else if (strafeDir
= 1) then plr
.SetDirection(TDirection
.D_RIGHT
);
1545 strafeDir
:= 0; // not strafing anymore
1546 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1547 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(TDirection
.D_LEFT
)
1548 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1549 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(TDirection
.D_RIGHT
)
1550 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1551 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1554 // fix movebutton state
1555 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1557 // Îñòàëüíûå êëàâèøè:
1558 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1559 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1560 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1561 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1562 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then
1564 rwk
:= plr
.isWeaponSwitchKeyReleased(-1);
1565 if rwk
then plr
.PressKey(KEY_NEXTWEAPON
);
1566 plr
.weaponSwitchKeysStateChange(-1, true);
1570 plr
.weaponSwitchKeysStateChange(-1, false);
1572 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then
1574 rwk
:= plr
.isWeaponSwitchKeyReleased(-2);
1575 if rwk
then plr
.PressKey(KEY_PREVWEAPON
);
1576 plr
.weaponSwitchKeysStateChange(-2, true);
1580 plr
.weaponSwitchKeysStateChange(-2, false);
1582 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1584 for i
:= 0 to High(KeyWeapon
) do
1586 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1588 rwk
:= plr
.isWeaponSwitchKeyReleased(i
);
1589 //writeln('rwk:', rwk);
1590 plr
.weaponSwitchKeysStateChange(i
, true);
1591 if rwk
then plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1595 plr
.weaponSwitchKeysStateChange(i
, false);
1600 // HACK: add dynlight here
1601 if gwin_k8_enable_light_experiments
then
1603 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1605 g_playerLight
:= true;
1607 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1609 g_playerLight
:= false;
1613 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1616 procedure g_Game_Update();
1618 Msg
: g_gui
.TMessage
;
1624 function sendMonsPos (mon
: TMonster
): Boolean;
1626 result
:= false; // don't stop
1627 // this will also reset "need-send" flag
1628 if mon
.gncNeedSend
then
1630 MH_SEND_MonsterPos(mon
.UID
);
1632 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1634 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1636 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1638 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1642 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1644 result
:= false; // don't stop
1645 // this will also reset "need-send" flag
1646 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1650 reliableUpdate
: Boolean;
1655 // Ïîðà âûêëþ÷àòü èãðó:
1656 if gExit
= EXIT_QUIT
then
1658 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1662 if gExit
= EXIT_QUIT
then
1666 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1667 // no need to, as we'll do it in event handler
1669 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1672 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1674 gExit
:= EXIT_SIMPLE
;
1680 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1681 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1682 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1683 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1685 if g_Game_IsNet
and g_Game_IsServer
then
1687 gInterTime
:= gInterTime
+ GAME_TICK
;
1688 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1689 if a
<> gServInterTime
then
1691 gServInterTime
:= a
;
1692 MH_SEND_TimeSync(gServInterTime
);
1696 if (not g_Game_IsClient
) and
1700 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1701 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
)
1703 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1704 and (g_ActiveWindow
= nil)
1706 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1709 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1710 g_Game_StopAllSounds(True);
1712 if gMapOnce
then // Ýòî áûë òåñò
1713 gExit
:= EXIT_SIMPLE
1715 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1716 g_Game_ChangeMap(gNextMap
)
1717 else // Ñëåäóþùåé êàðòû íåò
1719 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1721 // Âûõîä â ãëàâíîå ìåíþ:
1723 g_GUI_ShowWindow('MainMenu');
1724 gMusic
.SetByName('MUSIC_MENU');
1726 gState
:= STATE_MENU
;
1729 // Ôèíàëüíàÿ êàðòèíêà:
1730 g_Game_ExecuteEvent('onwadend');
1732 if not gMusic
.SetByName('MUSIC_endmus') then
1733 gMusic
.SetByName('MUSIC_STDENDMUS');
1735 gState
:= STATE_ENDPIC
;
1737 g_Game_ExecuteEvent('ongameend');
1743 if gState
= STATE_INTERTEXT
then
1744 if InterText
.counter
> 0 then
1745 InterText
.counter
:= InterText
.counter
- 1;
1748 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1750 if EndingGameCounter
= 0 then
1752 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1753 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1755 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1757 g_Game_ExecuteEvent('onwadend');
1758 if not gMusic
.SetByName('MUSIC_endmus') then
1759 gMusic
.SetByName('MUSIC_STDENDMUS');
1762 gMusic
.SetByName('MUSIC_ROUNDMUS');
1765 gState
:= STATE_INTERCUSTOM
;
1768 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1770 gMusic
.SetByName('MUSIC_INTERMUS');
1772 gState
:= STATE_INTERSINGLE
;
1775 g_Game_ExecuteEvent('oninter');
1778 DecMin(EndingGameCounter
, 6, 0);
1781 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1783 if gMapOnce
then // Ýòî áûë òåñò
1785 gExit
:= EXIT_SIMPLE
;
1791 g_Serverlist_Control(slCurrent
, slTable
);
1794 if g_Game_IsNet
then
1795 if not gConsoleShow
then
1796 if not gChatShow
then
1798 if g_ActiveWindow
= nil then
1800 if e_KeyPressed(gGameControls
.GameControls
.Chat
) or e_KeyPressed(VK_CHAT
) then
1801 g_Console_Chat_Switch(False)
1802 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
) or e_KeyPressed(VK_TEAM
)) and
1803 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1804 g_Console_Chat_Switch(True);
1807 if not gChatEnter
then
1808 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1809 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
))
1810 and (not e_KeyPressed(VK_CHAT
))
1811 and (not e_KeyPressed(VK_TEAM
)) then
1814 // Ñòàòèñòèêà ïî Tab:
1816 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1817 (gGameSettings
.GameType
<> GT_SINGLE
) and
1818 (e_KeyPressed(gGameControls
.GameControls
.Stat
) or e_KeyPressed(VK_STATUS
));
1821 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1823 // Âðåìÿ += 28 ìèëëèñåêóíä:
1824 gTime
:= gTime
+ GAME_TICK
;
1826 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1827 if MessageTime
= 0 then
1829 if MessageTime
> 0 then
1830 MessageTime
:= MessageTime
- 1;
1832 if (g_Game_IsServer
) then
1834 // Áûë çàäàí ëèìèò âðåìåíè:
1835 if (gGameSettings
.TimeLimit
> 0) then
1836 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1837 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1842 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1843 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1844 g_Game_RestartRound(gLMSSoftSpawn
);
1846 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1847 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1849 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1851 g_Console_Process(gVoteCommand
);
1853 gVotePassed
:= False;
1856 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1857 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1858 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1859 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1860 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1862 // Áûë çàäàí ëèìèò ïîáåä:
1863 if (gGameSettings
.GoalLimit
> 0) then
1867 if gGameSettings
.GameMode
= GM_DM
then
1868 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1869 for i
:= 0 to High(gPlayers
) do
1870 if gPlayers
[i
] <> nil then
1871 if gPlayers
[i
].Frags
> b
then
1872 b
:= gPlayers
[i
].Frags
;
1875 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1876 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1877 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1880 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1881 if b
>= gGameSettings
.GoalLimit
then
1888 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1889 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1890 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1891 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1893 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1894 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1895 end // if not console
1898 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1900 // process weapon switch queue
1904 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1905 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1907 if not gSpectKeyPress
then
1909 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)
1910 and (not gSpectAuto
) then
1912 // switch spect mode
1914 SPECT_NONE
: ; // not spectator
1916 SPECT_MAPVIEW
: Inc(gSpectMode
);
1917 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1919 gSpectKeyPress
:= True;
1921 if (gSpectMode
= SPECT_MAPVIEW
)
1922 and (not gSpectAuto
) then
1924 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1925 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1926 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1927 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1928 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1929 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1930 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1931 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1932 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1935 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1936 gSpectKeyPress
:= True;
1938 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1941 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1942 gSpectKeyPress
:= True;
1945 if (gSpectMode
= SPECT_PLAYERS
)
1946 and (not gSpectAuto
) then
1948 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1951 gSpectViewTwo
:= True;
1952 gSpectKeyPress
:= True;
1954 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1956 // remove second view
1957 gSpectViewTwo
:= False;
1958 gSpectKeyPress
:= True;
1960 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1962 // prev player (view 1)
1963 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1964 gSpectKeyPress
:= True;
1966 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1968 // next player (view 1)
1969 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1970 gSpectKeyPress
:= True;
1972 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1974 // prev player (view 2)
1975 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1976 gSpectKeyPress
:= True;
1978 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1980 // next player (view 2)
1981 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1982 gSpectKeyPress
:= True;
1985 if isKeyPressed(gGameControls
.P1Control
.KeyFire
, gGameControls
.P1Control
.KeyFire2
) then
1987 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1990 gSpectAutoNext
:= 0;
1991 gSpectViewTwo
:= False;
1992 gSpectKeyPress
:= True;
1997 gSpectMode
:= SPECT_STATS
;
1998 gSpectAuto
:= False;
1999 gSpectKeyPress
:= True;
2004 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
2005 (not isKeyPressed(gGameControls
.P1Control
.KeyFire
, gGameControls
.P1Control
.KeyFire2
)) and
2006 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
2007 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
2008 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
2009 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
2010 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
2011 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
2012 gSpectKeyPress
:= False;
2016 if gSpectMode
= SPECT_MAPVIEW
then
2018 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2020 gSpectAutoNext
:= gTime
2023 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2025 gSpectAutoNext
:= gTime
2029 if gSpectAutoNext
<= gTime
then
2031 if gSpectAutoNext
> 0 then
2033 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2037 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2038 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2039 gSpectAutoStepX
:= Random(9) - 4;
2040 gSpectAutoStepY
:= Random(9) - 4;
2041 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2042 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2043 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2044 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2045 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2046 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2050 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2055 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2056 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2057 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2063 // Îáíîâëÿåì âñå îñòàëüíîå:
2066 g_Triggers_Update();
2068 g_Monsters_Update();
2070 g_Player_UpdateAll();
2071 g_Player_UpdatePhysicalObjects();
2073 // server: send newly spawned monsters unconditionally
2074 if (gGameSettings
.GameType
= GT_SERVER
) then
2076 if (Length(gMonstersSpawned
) > 0) then
2078 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2079 SetLength(gMonstersSpawned
, 0);
2083 if (gSoundTriggerTime
> 8) then
2085 g_Game_UpdateTriggerSounds();
2086 gSoundTriggerTime
:= 0;
2090 Inc(gSoundTriggerTime
);
2093 if (NetMode
= NET_SERVER
) then
2095 Inc(NetTimeToUpdate
);
2096 Inc(NetTimeToReliable
);
2098 // send monster updates
2099 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2101 // send all monsters (periodic sync)
2102 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2104 for I
:= 0 to High(gPlayers
) do
2106 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2109 g_Mons_ForEach(sendMonsPos
);
2111 if reliableUpdate
then
2113 NetTimeToReliable
:= 0;
2114 NetTimeToUpdate
:= NetUpdateRate
;
2118 NetTimeToUpdate
:= 0;
2123 // send only mosters with some unexpected changes
2124 g_Mons_ForEach(sendMonsPosUnexpected
);
2127 // send unexpected platform changes
2128 g_Map_NetSendInterestingPanels();
2130 if NetUseMaster
then
2132 if gTime
>= NetTimeToMaster
then
2134 if (NetMHost
= nil) or (NetMPeer
= nil) then
2136 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
2140 NetTimeToMaster
:= gTime
+ NetMasterRate
;
2144 else if (NetMode
= NET_CLIENT
) then
2146 MC_SEND_PlayerPos();
2148 end; // if gameOn ...
2150 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2151 if g_ActiveWindow
<> nil then
2153 w
:= e_GetFirstKeyPressed();
2155 if (w
<> IK_INVALID
) then
2157 Msg
.Msg
:= MESSAGE_DIKEY
;
2159 g_ActiveWindow
.OnMessage(Msg
);
2162 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2163 if g_ActiveWindow
<> nil then
2164 g_ActiveWindow
.Update();
2166 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2167 if gResolutionChange
then
2169 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2170 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2171 gResolutionChange
:= False;
2172 g_ActiveWindow
:= nil;
2175 // Íóæíî ñìåíèòü ÿçûê:
2176 if gLanguageChange
then
2178 //e_WriteLog('Read language file', MSG_NOTIFY);
2179 //g_Language_Load(DataDir + gLanguage + '.txt');
2180 g_Language_Set(gLanguage
);
2182 gLanguageChange
:= False;
2186 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
2187 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) or e_KeyPressed(VK_PRINTSCR
) then
2188 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
2191 LastScreenShot
:= GetTimer();
2194 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2195 if e_KeyPressed(IK_F10
) and
2197 (not gConsoleShow
) and
2198 (g_ActiveWindow
= nil) then
2203 Time
:= GetTimer() {div 1000};
2205 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2206 if gDelayedEvents
<> nil then
2207 for a
:= 0 to High(gDelayedEvents
) do
2208 if gDelayedEvents
[a
].Pending
and
2210 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2211 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2214 case gDelayedEvents
[a
].DEType
of
2216 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2219 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2223 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2224 if g_Game_IsNet
and g_Game_IsServer
then
2225 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2229 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2231 gDelayedEvents
[a
].Pending
:= False;
2234 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2235 UPSCounter
:= UPSCounter
+ 1;
2236 if Time
- UPSTime
>= 1000 then
2245 g_Weapon_AddDynLights();
2246 g_Items_AddDynLights();
2250 procedure g_Game_LoadChatSounds(Resource
: string);
2253 FileName
, Snd
: string;
2255 len
, cnt
, tags
, i
, j
: Integer;
2258 FileName
:= g_ExtractWadName(Resource
);
2260 WAD
:= TWADFile
.Create();
2261 WAD
.ReadFile(FileName
);
2263 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2270 cfg
:= TConfig
.CreateMem(p
, len
);
2271 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2273 SetLength(gChatSounds
, cnt
);
2274 for i
:= 0 to Length(gChatSounds
) - 1 do
2276 gChatSounds
[i
].Sound
:= nil;
2277 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2278 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2279 if (Snd
= '') or (Tags
<= 0) then
2281 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2282 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2283 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2284 SetLength(gChatSounds
[i
].Tags
, tags
);
2285 for j
:= 0 to tags
- 1 do
2286 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2287 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2294 procedure g_Game_FreeChatSounds();
2298 for i
:= 0 to Length(gChatSounds
) - 1 do
2300 gChatSounds
[i
].Sound
.Free();
2301 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2303 SetLength(gChatSounds
, 0);
2307 procedure g_Game_LoadData();
2314 if DataLoaded
then Exit
;
2316 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2318 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2319 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2320 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2321 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2322 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2323 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2324 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2325 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2326 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2327 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2328 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2329 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2330 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2331 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2332 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2335 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2336 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2337 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2338 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2342 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2343 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2344 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2345 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2346 if (wl
> 0) and (hl
> 0) and (wr
> 0) and (hr
= hl
) and (wb
> 0) and (hb
= hl
) and (wm
> 0) and (hm
> 0) and (hm
<= hl
) then
2352 hasPBarGfx
:= false;
2356 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2357 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2358 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2359 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2360 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2361 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2362 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2363 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2364 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2365 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2366 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2367 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2368 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2369 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2370 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2371 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2372 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2373 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2374 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2375 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2376 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2377 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2378 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2379 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2380 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2381 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2382 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2383 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2384 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2386 goodsnd
[0] := TPlayableSound
.Create();
2387 goodsnd
[1] := TPlayableSound
.Create();
2388 goodsnd
[2] := TPlayableSound
.Create();
2389 goodsnd
[3] := TPlayableSound
.Create();
2391 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2392 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2393 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2394 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2396 killsnd
[0] := TPlayableSound
.Create();
2397 killsnd
[1] := TPlayableSound
.Create();
2398 killsnd
[2] := TPlayableSound
.Create();
2399 killsnd
[3] := TPlayableSound
.Create();
2401 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2402 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2403 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2404 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2406 hahasnd
[0] := TPlayableSound
.Create();
2407 hahasnd
[1] := TPlayableSound
.Create();
2408 hahasnd
[2] := TPlayableSound
.Create();
2410 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2411 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2412 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2414 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2416 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2419 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2420 g_Weapon_LoadData();
2422 g_Monsters_LoadData();
2427 procedure g_Game_FreeData();
2429 if not DataLoaded
then Exit
;
2432 g_Weapon_FreeData();
2433 g_Monsters_FreeData();
2435 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2437 g_Texture_Delete('NOTEXTURE');
2438 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2439 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2440 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2441 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2442 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2443 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2444 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2445 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2446 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2447 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2448 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2449 g_Frames_DeleteByName('FRAMES_TELEPORT');
2450 g_Frames_DeleteByName('FRAMES_PUNCH');
2451 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2452 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2453 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2454 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2455 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2456 g_Sound_Delete('SOUND_GAME_TELEPORT');
2457 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2458 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2459 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2460 g_Sound_Delete('SOUND_GAME_BULK1');
2461 g_Sound_Delete('SOUND_GAME_BULK2');
2462 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2463 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2464 g_Sound_Delete('SOUND_GAME_SWITCH1');
2465 g_Sound_Delete('SOUND_GAME_SWITCH0');
2472 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2473 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2474 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2475 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2482 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2483 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2484 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2485 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2491 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2492 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2493 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2495 g_Game_FreeChatSounds();
2497 DataLoaded
:= False;
2500 procedure DrawCustomStat();
2506 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2507 s1
, s2
, topstr
: String;
2509 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2511 g_ProcessMessages();
2513 if e_KeyPressed(IK_TAB
) or e_KeyPressed(VK_STATUS
) then
2515 if not gStatsPressed
then
2517 gStatsOff
:= not gStatsOff
;
2518 gStatsPressed
:= True;
2522 gStatsPressed
:= False;
2526 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2527 w
:= (Length(s1
) * ww2
) div 2;
2528 x
:= gScreenWidth
div 2 - w
;
2530 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2534 if (gGameSettings
.GameMode
= GM_COOP
) then
2536 if gMissionFailed
then
2537 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2539 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2542 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2544 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2545 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2547 if g_Game_IsNet
then
2549 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2550 if not gChatShow
then
2551 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2552 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2555 if g_Game_IsClient
then
2556 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2558 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2559 if not gChatShow
then
2560 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2561 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2566 w
:= gScreenWidth
-x
*2;
2572 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2573 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2575 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2577 case CustomStat
.GameMode
of
2580 if gGameSettings
.MaxLives
= 0 then
2581 s1
:= _lc
[I_GAME_DM
]
2583 s1
:= _lc
[I_GAME_LMS
];
2587 if gGameSettings
.MaxLives
= 0 then
2588 s1
:= _lc
[I_GAME_TDM
]
2590 s1
:= _lc
[I_GAME_TLMS
];
2592 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2595 if gGameSettings
.MaxLives
= 0 then
2596 s1
:= _lc
[I_GAME_COOP
]
2598 s1
:= _lc
[I_GAME_SURV
];
2604 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2608 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2609 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2612 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2613 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2614 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2615 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2617 pc
:= Length(CustomStat
.PlayerStat
);
2618 if pc
= 0 then Exit
;
2620 if CustomStat
.GameMode
= GM_COOP
then
2622 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2624 s2
:= _lc
[I_GAME_MONSTERS
];
2625 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2626 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2628 s2
:= _lc
[I_GAME_SECRETS
];
2629 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2630 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2633 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2635 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2636 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2637 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2639 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2640 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2641 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2645 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2650 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2651 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2652 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2654 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2657 for t
:= TEAM_RED
to TEAM_BLUE
do
2659 if t
= TEAM_RED
then
2661 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2662 gStdFont
, 255, 0, 0, 1);
2663 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2664 gStdFont
, 255, 0, 0, 1);
2671 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2672 gStdFont
, 0, 0, 255, 1);
2673 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2674 gStdFont
, 0, 0, 255, 1);
2680 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2683 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2684 if CustomStat
.PlayerStat
[p
].Team
= t
then
2685 with CustomStat
.PlayerStat
[p
] do
2699 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2700 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2701 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2708 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2711 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2712 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2713 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2716 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2717 with CustomStat
.PlayerStat
[p
] do
2719 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2726 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2727 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2728 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2734 procedure DrawSingleStat();
2736 tm
, key_x
, val_x
, y
: Integer;
2740 procedure player_stat(n
: Integer);
2746 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2747 s2
:= Format(' %d', [gTotalMonsters
]);
2749 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2750 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2751 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2752 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2754 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2755 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2757 // "Kills-per-minute: ##.#":
2758 s1
:= _lc
[I_MENU_INTER_KPM
];
2760 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2762 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2763 s2
:= Format(' %.1f', [kpm
]);
2765 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2766 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2768 // "Secrets found: # / #":
2769 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2770 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2772 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2773 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2774 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2775 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2777 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2778 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2782 // "Level Complete":
2783 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2784 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2786 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2787 s1
:= _lc
[I_MENU_INTER_KPM
];
2788 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2791 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2793 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2794 val_x
:= key_x
+ w1
;
2797 tm
:= SingleStat
.GameTime
div 1000;
2798 s1
:= _lc
[I_MENU_INTER_TIME
];
2799 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2801 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2802 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2804 if SingleStat
.TwoPlayers
then
2807 s1
:= _lc
[I_MENU_PLAYER_1
];
2808 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2809 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2811 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2816 s1
:= _lc
[I_MENU_PLAYER_2
];
2817 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2818 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2820 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2826 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2832 procedure DrawLoadingStat();
2833 procedure drawRect (x
, y
, w
, h
: Integer);
2835 if (w
< 1) or (h
< 1) then exit
;
2837 glVertex2f(x
+0.375, y
+0.375);
2838 glVertex2f(x
+w
+0.375, y
+0.375);
2839 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2840 glVertex2f(x
+0.375, y
+h
+0.375);
2844 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2846 rectW
, rectH
: Integer;
2853 idl
, idr
, idb
, idm
: LongWord;
2857 if (total
< 1) then exit
;
2858 if (cur
< 1) then exit
; // don't blink
2859 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2860 //if (cur < 0) then cur := 0;
2861 //if (cur > total) then cur := total;
2864 if (hasPBarGfx
) then
2866 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2867 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2868 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2869 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2870 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2871 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2872 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2873 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2875 //rectW := gScreenWidth-360;
2876 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2879 x0
:= (gScreenWidth
-rectW
) div 2;
2880 y0
:= gScreenHeight
-rectH
-64;
2881 if (y0
< 2) then y0
:= 2;
2883 glEnable(GL_SCISSOR_TEST
);
2886 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2887 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2888 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2891 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2893 while (f
< x0
+rectW
) do
2895 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2900 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2901 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2904 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2905 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2909 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2915 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2919 rectW
:= gScreenWidth
-64;
2922 x0
:= (gScreenWidth
-rectW
) div 2;
2923 y0
:= gScreenHeight
-rectH
-64;
2924 if (y0
< 2) then y0
:= 2;
2926 glDisable(GL_BLEND
);
2927 glDisable(GL_TEXTURE_2D
);
2929 //glClearColor(0, 0, 0, 0);
2930 //glClear(GL_COLOR_BUFFER_BIT);
2932 glColor4ub(127, 127, 127, 255);
2933 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2935 glColor4ub(0, 0, 0, 255);
2936 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2938 glColor4ub(127, 127, 127, 255);
2939 wdt
:= rectW
*cur
div total
;
2940 if (wdt
> rectW
) then wdt
:= rectW
;
2941 drawRect(x0
, y0
, wdt
, rectH
);
2950 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2952 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2953 yy
:= (gScreenHeight
div 3);
2954 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2955 xx
:= (gScreenWidth
div 3);
2959 for i
:= 0 to NextMsg
-1 do
2961 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2962 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2966 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2967 yy
:= yy
+ LOADING_INTERLINE
;
2968 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2973 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2975 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2977 function monDraw (mon
: TMonster
): Boolean;
2979 result
:= false; // don't stop
2984 // Ëåâûé âåðõíèé óãîë
2985 aX
:= Obj
.X
div ScaleSz
+ 1;
2986 aY
:= Obj
.Y
div ScaleSz
+ 1;
2988 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2989 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2990 // Ïðàâûé íèæíèé óãîë
2991 aX2
:= aX
+ aX2
- 1;
2992 aY2
:= aY
+ aY2
- 1;
2993 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2999 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3000 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3003 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3004 ScaleSz
:= 16 div Scale
;
3005 // Ðàçìåðû ìèíè-êàðòû:
3006 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3007 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3009 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3011 if gWalls
<> nil then
3014 for a
:= 0 to High(gWalls
) do
3016 if PanelType
<> 0 then
3018 // Ëåâûé âåðõíèé óãîë:
3019 aX
:= X
div ScaleSz
;
3020 aY
:= Y
div ScaleSz
;
3022 aX2
:= max(Width
div ScaleSz
, 1);
3023 aY2
:= max(Height
div ScaleSz
, 1);
3024 // Ïðàâûé íèæíèé óãîë:
3025 aX2
:= aX
+ aX2
- 1;
3026 aY2
:= aY
+ aY2
- 1;
3029 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3030 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3031 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3035 if gSteps
<> nil then
3038 for a
:= 0 to High(gSteps
) do
3040 if PanelType
<> 0 then
3042 // Ëåâûé âåðõíèé óãîë:
3043 aX
:= X
div ScaleSz
;
3044 aY
:= Y
div ScaleSz
;
3046 aX2
:= max(Width
div ScaleSz
, 1);
3047 aY2
:= max(Height
div ScaleSz
, 1);
3048 // Ïðàâûé íèæíèé óãîë:
3049 aX2
:= aX
+ aX2
- 1;
3050 aY2
:= aY
+ aY2
- 1;
3052 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3055 if gLifts
<> nil then
3058 for a
:= 0 to High(gLifts
) do
3060 if PanelType
<> 0 then
3062 // Ëåâûé âåðõíèé óãîë:
3063 aX
:= X
div ScaleSz
;
3064 aY
:= Y
div ScaleSz
;
3066 aX2
:= max(Width
div ScaleSz
, 1);
3067 aY2
:= max(Height
div ScaleSz
, 1);
3068 // Ïðàâûé íèæíèé óãîë:
3069 aX2
:= aX
+ aX2
- 1;
3070 aY2
:= aY
+ aY2
- 1;
3073 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3074 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3075 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3076 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3080 if gWater
<> nil then
3083 for a
:= 0 to High(gWater
) do
3085 if PanelType
<> 0 then
3087 // Ëåâûé âåðõíèé óãîë:
3088 aX
:= X
div ScaleSz
;
3089 aY
:= Y
div ScaleSz
;
3091 aX2
:= max(Width
div ScaleSz
, 1);
3092 aY2
:= max(Height
div ScaleSz
, 1);
3093 // Ïðàâûé íèæíèé óãîë:
3094 aX2
:= aX
+ aX2
- 1;
3095 aY2
:= aY
+ aY2
- 1;
3097 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3100 if gAcid1
<> nil then
3102 // Ðèñóåì êèñëîòó 1:
3103 for a
:= 0 to High(gAcid1
) do
3105 if PanelType
<> 0 then
3107 // Ëåâûé âåðõíèé óãîë:
3108 aX
:= X
div ScaleSz
;
3109 aY
:= Y
div ScaleSz
;
3111 aX2
:= max(Width
div ScaleSz
, 1);
3112 aY2
:= max(Height
div ScaleSz
, 1);
3113 // Ïðàâûé íèæíèé óãîë:
3114 aX2
:= aX
+ aX2
- 1;
3115 aY2
:= aY
+ aY2
- 1;
3117 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3120 if gAcid2
<> nil then
3122 // Ðèñóåì êèñëîòó 2:
3123 for a
:= 0 to High(gAcid2
) do
3125 if PanelType
<> 0 then
3127 // Ëåâûé âåðõíèé óãîë:
3128 aX
:= X
div ScaleSz
;
3129 aY
:= Y
div ScaleSz
;
3131 aX2
:= max(Width
div ScaleSz
, 1);
3132 aY2
:= max(Height
div ScaleSz
, 1);
3133 // Ïðàâûé íèæíèé óãîë:
3134 aX2
:= aX
+ aX2
- 1;
3135 aY2
:= aY
+ aY2
- 1;
3137 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3140 if gPlayers
<> nil then
3143 for a
:= 0 to High(gPlayers
) do
3144 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3146 // Ëåâûé âåðõíèé óãîë:
3147 aX
:= Obj
.X
div ScaleSz
+ 1;
3148 aY
:= Obj
.Y
div ScaleSz
+ 1;
3150 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3151 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3152 // Ïðàâûé íèæíèé óãîë:
3153 aX2
:= aX
+ aX2
- 1;
3154 aY2
:= aY
+ aY2
- 1;
3156 if gPlayers
[a
] = p
then
3157 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3160 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3161 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3162 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3167 g_Mons_ForEach(monDraw
);
3172 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3174 if not hasAmbient
then exit
;
3175 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3179 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3180 //FIXME: broken for splitscreen mode
3181 procedure renderDynLightsInternal ();
3183 //hasAmbient: Boolean;
3184 //ambColor: TDFColor;
3186 lx
, ly
, lrad
: Integer;
3187 scxywh
: array[0..3] of GLint
;
3190 if e_NoGraphics
then exit
;
3192 //TODO: lights should be in separate grid, i think
3193 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3194 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3197 //ambColor := gCurrentMap['light_ambient'].rgba;
3198 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3200 { // this will multiply incoming color to alpha from framebuffer
3202 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3206 * light rendering: (INVALID!)
3207 * glStencilFunc(GL_EQUAL, 0, $ff);
3209 * glClear(GL_STENCIL_BUFFER_BIT);
3210 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3211 * draw shadow volume into stencil buffer
3212 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3213 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3215 * draw color-less quad with light alpha (WARNING! don't touch color!)
3216 * glEnable(GL_BLEND);
3217 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3218 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3220 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3221 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3223 // setup OpenGL parameters
3224 glStencilMask($FFFFFFFF);
3225 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3226 glEnable(GL_STENCIL_TEST
);
3227 glEnable(GL_SCISSOR_TEST
);
3228 glClear(GL_STENCIL_BUFFER_BIT
);
3229 glStencilFunc(GL_EQUAL
, 0, $ff);
3231 for lln
:= 0 to g_dynLightCount
-1 do
3233 lx
:= g_dynLights
[lln
].x
;
3234 ly
:= g_dynLights
[lln
].y
;
3235 lrad
:= g_dynLights
[lln
].radius
;
3236 if (lrad
< 3) then continue
;
3238 if (lx
-sX
+lrad
< 0) then continue
;
3239 if (ly
-sY
+lrad
< 0) then continue
;
3240 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3241 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3243 // set scissor to optimize drawing
3244 if (g_dbg_scale
= 1.0) then
3246 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3250 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3252 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3253 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3254 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3255 // draw extruded panels
3256 glDisable(GL_TEXTURE_2D
);
3257 glDisable(GL_BLEND
);
3258 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3259 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3260 // render light texture
3261 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3262 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3265 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3266 glEnable(GL_TEXTURE_2D
);
3267 // color and opacity
3268 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3269 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3271 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3272 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3273 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3274 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3279 glDisable(GL_STENCIL_TEST
);
3280 glDisable(GL_BLEND
);
3281 glDisable(GL_SCISSOR_TEST
);
3282 //glScissor(0, 0, sWidth, sHeight);
3284 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3285 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3289 function fixViewportForScale (): Boolean;
3291 nx0
, ny0
, nw
, nh
: Integer;
3294 if (g_dbg_scale
<> 1.0) then
3297 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3298 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3299 nw
:= round(sWidth
/g_dbg_scale
);
3300 nh
:= round(sHeight
/g_dbg_scale
);
3309 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3310 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3311 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3313 TDrawCB
= procedure ();
3316 hasAmbient
: Boolean;
3318 doAmbient
: Boolean = false;
3320 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3325 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3326 if gdbg_map_use_accel_render
then
3328 tagmask
:= panelTypeToTag(panType
);
3329 while (gDrawPanelList
.count
> 0) do
3331 pan
:= TPanel(gDrawPanelList
.front());
3332 if ((pan
.tag
and tagmask
) = 0) then break
;
3333 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3334 gDrawPanelList
.popFront();
3339 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3341 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3344 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3346 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3347 if assigned(cb
) then cb();
3348 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3352 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3354 // our accelerated renderer will collect all panels to gDrawPanelList
3355 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3356 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3357 if gdbg_map_use_accel_render
then
3359 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3361 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3363 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3364 g_Map_DrawBack(backXOfs
, backYOfs
);
3365 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3367 if setTransMatrix
then
3369 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3370 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3371 glTranslatef(-sX
, -sY
, 0);
3375 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3376 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3381 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3382 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3383 glClear(GL_COLOR_BUFFER_BIT);
3386 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3389 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3390 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3391 drawOther('items', @g_Items_Draw
);
3392 drawOther('weapons', @g_Weapon_Draw
);
3393 drawOther('shells', @g_Player_DrawShells
);
3394 drawOther('drawall', @g_Player_DrawAll
);
3395 drawOther('corpses', @g_Player_DrawCorpses
);
3396 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3397 drawOther('monsters', @g_Monsters_Draw
);
3398 drawOther('itemdrop', @g_Items_DrawDrop
);
3399 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3400 drawOther('gfx', @g_GFX_Draw
);
3401 drawOther('flags', @g_Map_DrawFlags
);
3402 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3403 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3404 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3405 drawOther('dynlights', @renderDynLightsInternal
);
3407 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3409 renderAmbientQuad(hasAmbient
, ambColor
);
3413 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3416 if g_debug_HealthBar
then
3418 g_Monsters_DrawHealth();
3419 g_Player_DrawHealth();
3422 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3426 procedure DrawMapView(x
, y
, w
, h
: Integer);
3433 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3434 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3441 fixViewportForScale();
3442 renderMapInternal(-bx
, -by
, true);
3448 procedure DrawPlayer(p
: TPlayer
);
3450 px
, py
, a
, b
, c
, d
: Integer;
3453 if (p
= nil) or (p
.FDummy
) then
3456 g_Map_DrawBack(0, 0);
3461 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3462 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3468 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3469 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3471 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3473 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3474 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3476 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3477 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3479 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3480 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3483 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3486 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3487 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3490 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3495 // scaled, ignore level bounds
3496 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3497 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3500 if p
.IncCam
<> 0 then
3502 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3504 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3506 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3510 if py
< gPlayerScreenSize
.Y
div 2 then
3512 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3514 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3518 if p
.IncCam
< 0 then
3520 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3523 if p
.IncCam
> 0 then
3525 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3529 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3530 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3531 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3533 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3534 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3535 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3538 sY
:= -(b
+p
.IncCam
);
3539 sWidth
:= gPlayerScreenSize
.X
;
3540 sHeight
:= gPlayerScreenSize
.Y
;
3542 //glTranslatef(a, b+p.IncCam, 0);
3544 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3546 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3547 fixViewportForScale();
3548 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3550 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3552 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3553 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3554 if (sX
< 0) then sX
:= 0;
3555 if (sY
< 0) then sY
:= 0;
3557 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3558 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3561 //r_smallmap_h: 0: left; 1: center; 2: right
3562 //r_smallmap_v: 0: top; 1: center; 2: bottom
3564 if (gMapInfo
.Width
= sWidth
) then
3568 else if (gMapInfo
.Width
< sWidth
) then
3570 case r_smallmap_h
of
3571 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3572 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3573 else sX
:= 0; // left
3577 if (gMapInfo
.Height
= sHeight
) then
3581 else if (gMapInfo
.Height
< sHeight
) then
3583 case r_smallmap_v
of
3584 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3585 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3586 else sY
:= 0; // top
3592 p
.viewPortW
:= sWidth
;
3593 p
.viewPortH
:= sHeight
;
3595 {$IFDEF ENABLE_HOLMES}
3596 if (p
= gPlayer1
) then
3598 g_Holmes_plrViewPos(sX
, sY
);
3599 g_Holmes_plrViewSize(sWidth
, sHeight
);
3603 renderMapInternal(-c
, -d
, true);
3605 if (gGameSettings
.GameMode
<> GM_SINGLE
) and gPlayerIndicator
then
3607 if p
.FSpectator
then
3608 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3609 p
.GameY
+ PLAYER_RECT_CY
- 4,
3610 'X', gStdFont
, 255, 255, 255, 1, True);
3612 for a := 0 to High(gCollideMap) do
3613 for b := 0 to High(gCollideMap[a]) do
3616 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3618 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3622 1: e_DrawPoint(1, b, a, 200, 200, 200);
3623 2: e_DrawPoint(1, b, a, 64, 64, 255);
3624 3: e_DrawPoint(1, b, a, 255, 0, 255);
3634 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3635 if g_Debug_Player
then
3636 g_Player_DrawDebug(p
);
3640 procedure drawProfilers ();
3645 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3646 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3647 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3650 procedure g_Game_Draw();
3657 plView1
, plView2
: TPlayer
;
3660 if gExit
= EXIT_QUIT
then Exit
;
3662 Time
:= GetTimer() {div 1000};
3663 FPSCounter
:= FPSCounter
+1;
3664 if Time
- FPSTime
>= 1000 then
3671 if gGameOn
or (gState
= STATE_FOLD
) then
3673 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3675 gSpectMode
:= SPECT_NONE
;
3676 if not gRevertPlayers
then
3678 plView1
:= gPlayer1
;
3679 plView2
:= gPlayer2
;
3683 plView1
:= gPlayer2
;
3684 plView2
:= gPlayer1
;
3688 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3690 gSpectMode
:= SPECT_NONE
;
3691 if gPlayer2
= nil then
3694 plView1
:= gPlayer2
;
3703 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3704 gSpectMode
:= SPECT_STATS
;
3706 if gSpectMode
= SPECT_PLAYERS
then
3707 if gPlayers
<> nil then
3709 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3710 if plView1
= nil then
3712 gSpectPID1
:= GetActivePlayerID_Next();
3713 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3715 if gSpectViewTwo
then
3717 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3718 if plView2
= nil then
3720 gSpectPID2
:= GetActivePlayerID_Next();
3721 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3726 if gSpectMode
= SPECT_MAPVIEW
then
3728 // Ðåæèì ïðîñìîòðà êàðòû
3730 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3731 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3732 gHearPoint1
.Active
:= True;
3733 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3734 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3735 gHearPoint2
.Active
:= False;
3739 Split
:= (plView1
<> nil) and (plView2
<> nil);
3741 // Òî÷êè ñëóõà èãðîêîâ
3742 if plView1
<> nil then
3744 gHearPoint1
.Active
:= True;
3745 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3746 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3748 gHearPoint1
.Active
:= False;
3749 if plView2
<> nil then
3751 gHearPoint2
.Active
:= True;
3752 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3753 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3755 gHearPoint2
.Active
:= False;
3757 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3758 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3761 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3762 if gScreenHeight
mod 2 = 0 then
3763 Dec(gPlayerScreenSize
.Y
);
3766 gPlayerScreenSize
.Y
:= gScreenHeight
;
3769 if gScreenHeight
mod 2 = 0 then
3770 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3772 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3774 DrawPlayer(plView1
);
3775 gPlayer1ScreenCoord
.X
:= sX
;
3776 gPlayer1ScreenCoord
.Y
:= sY
;
3780 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3782 DrawPlayer(plView2
);
3783 gPlayer2ScreenCoord
.X
:= sX
;
3784 gPlayer2ScreenCoord
.Y
:= sY
;
3787 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3790 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3793 {$IFDEF ENABLE_HOLMES}
3795 if (g_holmes_enabled
) then g_Holmes_Draw();
3798 if MessageText
<> '' then
3802 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3804 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3805 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3807 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3808 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3811 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3813 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3815 // Draw spectator GUI
3818 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3821 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3823 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3825 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3827 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3828 if gSpectMode
= SPECT_STATS
then
3830 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3831 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
3833 if gSpectMode
= SPECT_MAPVIEW
then
3835 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3836 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3837 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3838 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3839 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3841 if gSpectMode
= SPECT_PLAYERS
then
3843 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3844 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3845 if gSpectViewTwo
then
3847 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3848 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3849 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3850 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3854 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3855 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3861 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3863 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3864 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3866 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3867 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3868 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3873 if (gState
= STATE_MENU
) then
3875 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3877 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3878 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3880 // F3 at menu will show game loading dialog
3881 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3882 if (g_ActiveWindow
<> nil) then
3884 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3885 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3889 // F3 at titlepic will show game loading dialog
3890 if e_KeyPressed(IK_F3
) then
3892 g_Menu_Show_LoadMenu(true);
3893 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3898 if gState
= STATE_FOLD
then
3900 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3903 if gState
= STATE_INTERCUSTOM
then
3905 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3907 back
:= 'TEXTURE_endpic';
3908 if not g_Texture_Get(back
, ID
) then
3909 back
:= _lc
[I_TEXTURE_ENDPIC
];
3914 if g_Texture_Get(back
, ID
) then
3915 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3917 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3921 if g_ActiveWindow
<> nil then
3923 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3924 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3928 if gState
= STATE_INTERSINGLE
then
3930 if EndingGameCounter
> 0 then
3932 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3938 if g_Texture_Get(back
, ID
) then
3939 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3941 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3945 if g_ActiveWindow
<> nil then
3947 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3948 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3953 if gState
= STATE_ENDPIC
then
3956 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3957 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3959 if ID
<> DWORD(-1) then
3960 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3962 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3964 if g_ActiveWindow
<> nil then
3966 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3967 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3971 if gState
= STATE_SLIST
then
3973 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3975 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3976 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3977 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3979 g_Serverlist_Draw(slCurrent
, slTable
);
3983 if g_ActiveWindow
<> nil then
3987 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3988 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3990 g_ActiveWindow
.Draw();
3995 if g_debug_Sounds
and gGameOn
then
3997 for w
:= 0 to High(e_SoundsArray
) do
3998 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3999 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4004 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4005 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4008 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
4009 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4011 if gGameOn
then drawProfilers();
4013 {$IFDEF ENABLE_HOLMES}
4020 procedure g_Game_Quit();
4022 g_Game_StopAllSounds(True);
4024 g_Game_SaveOptions();
4026 g_PlayerModel_FreeData();
4027 g_Texture_DeleteAll();
4028 g_Frames_DeleteAll();
4029 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4031 if NetInitDone
then g_Net_Free
;
4033 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4034 if gMapToDelete
<> '' then
4035 g_Game_DeleteTestMap();
4041 procedure g_FatalError(Text: String);
4043 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4044 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4046 gExit
:= EXIT_SIMPLE
;
4049 procedure g_SimpleError(Text: String);
4051 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4052 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4055 procedure g_Game_SetupScreenSize();
4057 RES_FACTOR
= 4.0 / 3.0;
4063 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4064 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4065 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4066 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4068 gPlayerScreenSize
.Y
:= gScreenHeight
;
4070 // Ðàçìåð çàäíåãî ïëàíà:
4071 if BackID
<> DWORD(-1) then
4074 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4075 (gScreenHeight
*s
> gMapInfo
.Height
) then
4077 gBackSize
.X
:= gScreenWidth
;
4078 gBackSize
.Y
:= gScreenHeight
;
4082 e_GetTextureSize(BackID
, @bw
, @bh
);
4083 rf
:= Single(bw
) / Single(bh
);
4084 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4085 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4086 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4087 if (s
< 1.0) then s
:= 1.0;
4088 gBackSize
.X
:= Round(bw
*s
);
4089 gBackSize
.Y
:= Round(bh
*s
);
4094 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4096 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
4099 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4101 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4102 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4104 if gPlayer1
= nil then
4106 if g_Game_IsClient
then
4108 if NetPlrUID1
> -1 then
4110 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4111 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4116 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4117 Team
:= gPlayer1Settings
.Team
;
4119 // Ñîçäàíèå ïåðâîãî èãðîêà:
4120 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4121 gPlayer1Settings
.Color
,
4123 if gPlayer1
= nil then
4124 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4127 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4128 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4129 if g_Game_IsServer
and g_Game_IsNet
then
4130 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4131 gPlayer1
.Respawn(False, True);
4133 if g_Game_IsNet
and NetUseMaster
then
4139 if gPlayer2
= nil then
4141 if g_Game_IsClient
then
4143 if NetPlrUID2
> -1 then
4144 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4148 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4149 Team
:= gPlayer2Settings
.Team
;
4151 // Ñîçäàíèå âòîðîãî èãðîêà:
4152 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4153 gPlayer2Settings
.Color
,
4155 if gPlayer2
= nil then
4156 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4159 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4160 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4161 if g_Game_IsServer
and g_Game_IsNet
then
4162 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4163 gPlayer2
.Respawn(False, True);
4165 if g_Game_IsNet
and NetUseMaster
then
4173 procedure g_Game_RemovePlayer();
4177 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4178 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4183 if g_Game_IsServer
then
4186 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4187 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4188 g_Player_Remove(Pl
.UID
);
4190 if g_Game_IsNet
and NetUseMaster
then
4199 if g_Game_IsServer
then
4202 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4203 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4204 g_Player_Remove(Pl
.UID
);
4206 if g_Game_IsNet
and NetUseMaster
then
4211 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4217 procedure g_Game_Spectate();
4219 g_Game_RemovePlayer();
4220 if gPlayer1
<> nil then
4221 g_Game_RemovePlayer();
4224 procedure g_Game_SpectateCenterView();
4226 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4227 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4230 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4237 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4239 g_Game_ClearLoading();
4242 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4245 gGameSettings
.GameType
:= GT_SINGLE
;
4246 gGameSettings
.MaxLives
:= 0;
4247 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4248 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4249 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4250 gSwitchGameMode
:= GM_SINGLE
;
4252 g_Game_ExecuteEvent('ongamestart');
4254 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4255 g_Game_SetupScreenSize();
4257 // Ñîçäàíèå ïåðâîãî èãðîêà:
4258 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4259 gPlayer1Settings
.Color
,
4260 gPlayer1Settings
.Team
, False));
4261 if gPlayer1
= nil then
4263 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4267 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4270 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4273 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4274 gPlayer2Settings
.Color
,
4275 gPlayer2Settings
.Team
, False));
4276 if gPlayer2
= nil then
4278 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4282 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4286 // Çàãðóçêà è çàïóñê êàðòû:
4287 if not g_Game_StartMap(MAP
, True) then
4289 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4290 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4294 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4298 for i
:= nPl
+1 to nPlayers
do
4299 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4302 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4303 TimeLimit
, GoalLimit
: Word;
4305 Options
: LongWord; nPlayers
: Byte);
4311 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4313 g_Game_ClearLoading();
4316 gGameSettings
.GameType
:= GT_CUSTOM
;
4317 gGameSettings
.GameMode
:= GameMode
;
4318 gSwitchGameMode
:= GameMode
;
4319 gGameSettings
.TimeLimit
:= TimeLimit
;
4320 gGameSettings
.GoalLimit
:= GoalLimit
;
4321 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4322 gGameSettings
.Options
:= Options
;
4324 gCoopTotalMonstersKilled
:= 0;
4325 gCoopTotalSecretsFound
:= 0;
4326 gCoopTotalMonsters
:= 0;
4327 gCoopTotalSecrets
:= 0;
4331 g_Game_ExecuteEvent('ongamestart');
4333 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4334 g_Game_SetupScreenSize();
4336 // Ðåæèì íàáëþäàòåëÿ:
4337 if nPlayers
= 0 then
4344 if nPlayers
>= 1 then
4346 // Ñîçäàíèå ïåðâîãî èãðîêà:
4347 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4348 gPlayer1Settings
.Color
,
4349 gPlayer1Settings
.Team
, False));
4350 if gPlayer1
= nil then
4352 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4356 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4360 if nPlayers
>= 2 then
4362 // Ñîçäàíèå âòîðîãî èãðîêà:
4363 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4364 gPlayer2Settings
.Color
,
4365 gPlayer2Settings
.Team
, False));
4366 if gPlayer2
= nil then
4368 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4372 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4376 // Çàãðóçêà è çàïóñê êàðòû:
4377 if not g_Game_StartMap(Map
, True) then
4379 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4383 // Íåò òî÷åê ïîÿâëåíèÿ:
4384 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4385 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4386 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4387 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4388 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4390 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4394 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4398 for i
:= nPl
+1 to nPlayers
do
4399 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4402 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4403 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4404 Options
: LongWord; nPlayers
: Byte;
4405 IPAddr
: LongWord; Port
: Word);
4409 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4411 g_Game_ClearLoading();
4414 gGameSettings
.GameType
:= GT_SERVER
;
4415 gGameSettings
.GameMode
:= GameMode
;
4416 gSwitchGameMode
:= GameMode
;
4417 gGameSettings
.TimeLimit
:= TimeLimit
;
4418 gGameSettings
.GoalLimit
:= GoalLimit
;
4419 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4420 gGameSettings
.Options
:= Options
;
4422 gCoopTotalMonstersKilled
:= 0;
4423 gCoopTotalSecretsFound
:= 0;
4424 gCoopTotalMonsters
:= 0;
4425 gCoopTotalSecrets
:= 0;
4429 g_Game_ExecuteEvent('ongamestart');
4431 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4432 g_Game_SetupScreenSize();
4434 // Ðåæèì íàáëþäàòåëÿ:
4435 if nPlayers
= 0 then
4441 if nPlayers
>= 1 then
4443 // Ñîçäàíèå ïåðâîãî èãðîêà:
4444 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4445 gPlayer1Settings
.Color
,
4446 gPlayer1Settings
.Team
, False));
4447 if gPlayer1
= nil then
4449 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4453 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4456 if nPlayers
>= 2 then
4458 // Ñîçäàíèå âòîðîãî èãðîêà:
4459 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4460 gPlayer2Settings
.Color
,
4461 gPlayer2Settings
.Team
, False));
4462 if gPlayer2
= nil then
4464 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4468 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4471 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4472 if NetForwardPorts
then
4473 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4476 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4478 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4482 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4484 // Çàãðóçêà è çàïóñê êàðòû:
4485 if not g_Game_StartMap(Map
, True) then
4487 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4491 // Íåò òî÷åê ïîÿâëåíèÿ:
4492 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4493 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4494 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4495 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4496 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4498 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4502 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4505 NetState
:= NET_STATE_GAME
;
4508 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4523 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4524 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4526 g_Game_ClearLoading();
4529 gGameSettings
.GameType
:= GT_CLIENT
;
4531 gCoopTotalMonstersKilled
:= 0;
4532 gCoopTotalSecretsFound
:= 0;
4533 gCoopTotalMonsters
:= 0;
4534 gCoopTotalSecrets
:= 0;
4538 g_Game_ExecuteEvent('ongamestart');
4540 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4541 g_Game_SetupScreenSize();
4543 NetState
:= NET_STATE_AUTH
;
4545 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4547 if not g_Net_Connect(Addr
, Port
) then
4549 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4550 NetState
:= NET_STATE_NONE
;
4554 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4556 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4561 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4563 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4565 Ptr
:= NetEvent
.packet
^.data
;
4566 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4569 MID
:= InMsg
.ReadByte();
4571 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4573 NetMyID
:= InMsg
.ReadByte();
4574 NetPlrUID1
:= InMsg
.ReadWord();
4576 WadName
:= InMsg
.ReadString();
4577 Map
:= InMsg
.ReadString();
4579 gWADHash
:= InMsg
.ReadMD5();
4581 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4582 gSwitchGameMode
:= gGameSettings
.GameMode
;
4583 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4584 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4585 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4586 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4587 T
:= InMsg
.ReadLongWord();
4589 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4590 if newResPath
= '' then
4592 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4593 newResPath
:= g_Res_DownloadWAD(WadName
);
4594 if newResPath
= '' then
4596 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4597 enet_packet_destroy(NetEvent
.packet
);
4598 NetState
:= NET_STATE_NONE
;
4602 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4604 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4605 gPlayer1Settings
.Color
,
4606 gPlayer1Settings
.Team
, False));
4608 if gPlayer1
= nil then
4610 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4612 enet_packet_destroy(NetEvent
.packet
);
4613 NetState
:= NET_STATE_NONE
;
4617 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4618 gPlayer1
.UID
:= NetPlrUID1
;
4619 gPlayer1
.Reset(True);
4621 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4623 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4625 enet_packet_destroy(NetEvent
.packet
);
4626 NetState
:= NET_STATE_NONE
;
4634 enet_packet_destroy(NetEvent
.packet
);
4638 enet_packet_destroy(NetEvent
.packet
);
4642 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4645 if (NetEvent
.data
<= NET_DISC_MAX
) then
4646 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4647 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4654 ProcessLoading(true);
4656 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_ESCAPE
) then
4665 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4666 NetState
:= NET_STATE_NONE
;
4670 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4671 gLMSRespawnTime
:= 0;
4674 NetState
:= NET_STATE_GAME
;
4675 MC_SEND_FullStateRequest
;
4676 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4679 procedure g_Game_SaveOptions();
4681 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4684 procedure g_Game_ChangeMap(const MapPath
: String);
4688 g_Game_ClearLoading();
4690 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4691 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4692 if gExitByTrigger
then
4695 gExitByTrigger
:= False;
4697 if not g_Game_StartMap(MapPath
, Force
) then
4698 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4701 procedure g_Game_Restart();
4705 if g_Game_IsClient
then
4707 map
:= g_ExtractFileName(gMapInfo
.Map
);
4711 g_Game_ClearLoading();
4712 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4715 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4717 NewWAD
, ResName
: String;
4720 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4721 g_Player_RemoveAllCorpses();
4723 if (not g_Game_IsClient
) and
4724 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4725 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4727 if gSwitchGameMode
= GM_CTF
then
4728 gGameSettings
.MaxLives
:= 0;
4729 gGameSettings
.GameMode
:= gSwitchGameMode
;
4732 gSwitchGameMode
:= gGameSettings
.GameMode
;
4734 g_Player_ResetTeams();
4736 if isWadPath(Map
) then
4738 NewWAD
:= g_ExtractWadName(Map
);
4739 ResName
:= g_ExtractFileName(Map
);
4740 if g_Game_IsServer
then
4742 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4743 g_Game_LoadWAD(NewWAD
);
4745 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4746 g_Game_ClientWAD(NewWAD
, gWADHash
);
4750 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4753 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4755 gState
:= STATE_NONE
;
4756 g_ActiveWindow
:= nil;
4762 if gGameSettings
.GameMode
= GM_CTF
then
4764 g_Map_ResetFlag(FLAG_RED
);
4765 g_Map_ResetFlag(FLAG_BLUE
);
4766 // CTF, à ôëàãîâ íåò:
4767 if not g_Map_HaveFlagPoints() then
4768 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4773 gState
:= STATE_MENU
;
4778 gPauseMain
:= false;
4779 gPauseHolmes
:= false;
4781 NetTimeToUpdate
:= 1;
4782 NetTimeToReliable
:= 0;
4783 NetTimeToMaster
:= NetMasterRate
;
4784 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4785 gLMSRespawnTime
:= 0;
4786 gMissionFailed
:= False;
4789 gCoopMonstersKilled
:= 0;
4790 gCoopSecretsFound
:= 0;
4792 gVoteInProgress
:= False;
4793 gVotePassed
:= False;
4799 if not gGameOn
then Exit
;
4801 g_Game_SpectateCenterView();
4803 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4805 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4806 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4807 gLMSSoftSpawn
:= True;
4808 if NetMode
= NET_SERVER
then
4809 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4811 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4814 if NetMode
= NET_SERVER
then
4816 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4819 if NetUseMaster
then
4821 if (NetMHost
= nil) or (NetMPeer
= nil) then
4822 if not g_Net_Slist_Connect
then
4823 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4828 if NetClients
<> nil then
4829 for I
:= 0 to High(NetClients
) do
4830 if NetClients
[I
].Used
then
4832 NetClients
[I
].Voted
:= False;
4833 if NetClients
[I
].RequestedFullUpdate
then
4835 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4836 NetClients
[I
].RequestedFullUpdate
:= False;
4840 g_Net_UnbanNonPermHosts();
4845 gCoopTotalMonstersKilled
:= 0;
4846 gCoopTotalSecretsFound
:= 0;
4847 gCoopTotalMonsters
:= 0;
4848 gCoopTotalSecrets
:= 0;
4852 g_Game_ExecuteEvent('onmapstart');
4855 procedure SetFirstLevel();
4859 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4860 if MapList
= nil then
4863 SortSArray(MapList
);
4864 gNextMap
:= MapList
[Low(MapList
)];
4869 procedure g_Game_ExitLevel(const Map
: AnsiString);
4873 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4874 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4875 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4876 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4878 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4879 if gGameSettings
.GameType
= GT_SINGLE
then
4880 gExit
:= EXIT_ENDLEVELSINGLE
4881 else // Âûøëè â âûõîä â Ñâîåé èãðå
4883 gExit
:= EXIT_ENDLEVELCUSTOM
;
4884 if gGameSettings
.GameMode
= GM_COOP
then
4885 g_Player_RememberAll
;
4887 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4890 if gGameSettings
.GameMode
= GM_COOP
then
4893 gStatsPressed
:= True;
4894 gNextMap
:= 'MAP01';
4896 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4899 if g_Game_IsNet
then
4901 MH_SEND_GameStats();
4902 MH_SEND_CoopStats();
4908 procedure g_Game_RestartLevel();
4912 if gGameSettings
.GameMode
= GM_SINGLE
then
4917 gExit
:= EXIT_ENDLEVELCUSTOM
;
4918 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4922 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4926 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4928 if not g_Game_IsClient
then
4930 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4933 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4934 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4938 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4942 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4943 g_Game_LoadWAD(NewWAD
);
4946 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4948 i
, n
, nb
, nr
: Integer;
4950 function monRespawn (mon
: TMonster
): Boolean;
4952 result
:= false; // don't stop
4953 if not mon
.FNoRespawn
then mon
.Respawn();
4957 if not g_Game_IsServer
then Exit
;
4958 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4959 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4960 gLMSRespawnTime
:= 0;
4963 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4965 gMissionFailed
:= True;
4966 g_Game_RestartLevel
;
4970 n
:= 0; nb
:= 0; nr
:= 0;
4971 for i
:= Low(gPlayers
) to High(gPlayers
) do
4972 if (gPlayers
[i
] <> nil) and
4973 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4974 (gPlayers
[i
] is TBot
)) then
4977 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4978 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4981 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4983 // wait a second until the fuckers finally decide to join
4984 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4985 gLMSRespawnTime
:= gTime
+ 1000;
4986 gLMSSoftSpawn
:= NoMapRestart
;
4990 g_Player_RemoveAllCorpses
;
4991 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4992 if g_Game_IsNet
then
4993 MH_SEND_GameEvent(NET_EV_LMS_START
);
4995 for i
:= Low(gPlayers
) to High(gPlayers
) do
4997 if gPlayers
[i
] = nil then continue
;
4998 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4999 // don't touch normal spectators
5000 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5002 gPlayers
[i
].FNoRespawn
:= True;
5003 gPlayers
[i
].Lives
:= 0;
5004 if g_Game_IsNet
then
5005 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5008 gPlayers
[i
].FNoRespawn
:= False;
5009 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5010 gPlayers
[i
].Respawn(False, True);
5011 if gGameSettings
.GameMode
= GM_COOP
then
5013 gPlayers
[i
].Frags
:= 0;
5014 gPlayers
[i
].RecallState
;
5016 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5017 gPlayer1
:= g_Player_Get(gLMSPID1
);
5018 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5019 gPlayer2
:= g_Player_Get(gLMSPID2
);
5022 g_Items_RestartRound();
5025 g_Mons_ForEach(monRespawn
);
5027 gLMSSoftSpawn
:= False;
5030 function g_Game_GetFirstMap(WAD
: String): String;
5034 MapList
:= g_Map_GetMapsList(WAD
);
5035 if MapList
= nil then
5038 SortSArray(MapList
);
5039 Result
:= MapList
[Low(MapList
)];
5041 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5047 function g_Game_GetNextMap(): String;
5054 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
5055 if MapList
= nil then
5058 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5060 SortSArray(MapList
);
5062 for I
:= Low(MapList
) to High(MapList
) do
5063 if Map
= MapList
[I
] then
5069 if MapIndex
<> -255 then
5071 if MapIndex
= High(MapList
) then
5072 Result
:= MapList
[Low(MapList
)]
5074 Result
:= MapList
[MapIndex
+ 1];
5076 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5082 procedure g_Game_NextLevel();
5084 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5085 gExit
:= EXIT_ENDLEVELCUSTOM
5088 gExit
:= EXIT_ENDLEVELSINGLE
;
5092 if gNextMap
<> '' then Exit
;
5093 gNextMap
:= g_Game_GetNextMap();
5096 function g_Game_IsTestMap(): Boolean;
5098 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5101 procedure g_Game_DeleteTestMap();
5104 //MapName: AnsiString;
5112 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5113 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5114 if (a
= 0) then exit
;
5116 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5117 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5118 Delete(gMapToDelete
, 1, a
+5);
5119 gMapToDelete
:= UpperCase(gMapToDelete
);
5121 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5124 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5125 if MapName <> TEST_MAP_NAME then
5128 if not gTempDelete then
5130 time := g_GetFileTime(WadName);
5131 WAD := TWADFile.Create();
5134 if not WAD.ReadFile(WadName) then
5135 begin // Íåò òàêîãî WAD-ôàéëà
5140 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5142 MapList := WAD.GetResourcesList('');
5144 if MapList <> nil then
5145 for a := 0 to High(MapList) do
5146 if MapList[a] = MapName then
5148 // Óäàëÿåì è ñîõðàíÿåì:
5149 WAD.RemoveResource('', MapName);
5150 WAD.SaveTo(WadName);
5155 g_SetFileTime(WadName, time);
5158 if gTempDelete
then DeleteFile(WadName
);
5161 procedure GameCVars(P
: SSArray
);
5164 stat
: TPlayerStatArray
;
5169 cmd
:= LowerCase(P
[0]);
5170 if cmd
= 'r_showfps' then
5172 if (Length(P
) > 1) and
5173 ((P
[1] = '1') or (P
[1] = '0')) then
5174 gShowFPS
:= (P
[1][1] = '1');
5177 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
5179 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
5181 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5183 with gGameSettings
do
5185 if (Length(P
) > 1) and
5186 ((P
[1] = '1') or (P
[1] = '0')) then
5188 if (P
[1][1] = '1') then
5189 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5191 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5194 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5195 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5197 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5199 if g_Game_IsNet
then MH_SEND_GameSettings
;
5202 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5204 with gGameSettings
do
5206 if (Length(P
) > 1) and
5207 ((P
[1] = '1') or (P
[1] = '0')) then
5209 if (P
[1][1] = '1') then
5210 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5212 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5215 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5216 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5218 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5220 if g_Game_IsNet
then MH_SEND_GameSettings
;
5223 else if cmd
= 'g_gamemode' then
5225 a
:= g_Game_TextToMode(P
[1]);
5226 if a
= GM_SINGLE
then a
:= GM_COOP
;
5227 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5229 gSwitchGameMode
:= a
;
5230 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5231 (gState
= STATE_INTERSINGLE
) then
5232 gSwitchGameMode
:= GM_SINGLE
;
5234 gGameSettings
.GameMode
:= gSwitchGameMode
;
5236 if gSwitchGameMode
= gGameSettings
.GameMode
then
5237 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5238 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5240 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5241 [g_Game_ModeToText(gGameSettings
.GameMode
),
5242 g_Game_ModeToText(gSwitchGameMode
)]));
5244 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5246 with gGameSettings
do
5248 if (Length(P
) > 1) and
5249 ((P
[1] = '1') or (P
[1] = '0')) then
5251 if (P
[1][1] = '1') then
5252 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5254 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5257 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5258 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5260 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5261 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5263 if g_Game_IsNet
then MH_SEND_GameSettings
;
5266 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5268 with gGameSettings
do
5270 if (Length(P
) > 1) and
5271 ((P
[1] = '1') or (P
[1] = '0')) then
5273 if (P
[1][1] = '1') then
5274 Options
:= Options
or GAME_OPTION_MONSTERS
5276 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5279 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5280 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5282 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5283 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5285 if g_Game_IsNet
then MH_SEND_GameSettings
;
5288 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5290 with gGameSettings
do
5292 if (Length(P
) > 1) and
5293 ((P
[1] = '1') or (P
[1] = '0')) then
5295 if (P
[1][1] = '1') then
5296 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5298 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5301 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5302 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5304 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5306 if g_Game_IsNet
then MH_SEND_GameSettings
;
5309 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5311 with gGameSettings
do
5313 if (Length(P
) > 1) and
5314 ((P
[1] = '1') or (P
[1] = '0')) then
5316 if (P
[1][1] = '1') then
5317 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5319 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5322 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5323 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5325 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5327 if g_Game_IsNet
then MH_SEND_GameSettings
;
5330 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5332 if Length(P
) > 1 then
5334 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5335 gGameSettings
.WarmupTime
:= 30
5337 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5340 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5341 [gGameSettings
.WarmupTime
]));
5342 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5344 else if cmd
= 'net_interp' then
5346 if (Length(P
) > 1) then
5347 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5349 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5350 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5351 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5352 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5355 else if cmd
= 'net_forceplayerupdate' then
5357 if (Length(P
) > 1) and
5358 ((P
[1] = '1') or (P
[1] = '0')) then
5359 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5361 if NetForcePlayerUpdate
then
5362 g_Console_Add('net_forceplayerupdate = 1')
5364 g_Console_Add('net_forceplayerupdate = 0');
5365 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5366 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5367 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5370 else if cmd
= 'net_predictself' then
5372 if (Length(P
) > 1) and
5373 ((P
[1] = '1') or (P
[1] = '0')) then
5374 NetPredictSelf
:= (P
[1][1] = '1');
5376 if NetPredictSelf
then
5377 g_Console_Add('net_predictself = 1')
5379 g_Console_Add('net_predictself = 0');
5380 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5381 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5382 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5385 else if cmd
= 'sv_name' then
5387 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5389 NetServerName
:= P
[1];
5390 if Length(NetServerName
) > 64 then
5391 SetLength(NetServerName
, 64);
5392 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5396 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5398 else if cmd
= 'sv_passwd' then
5400 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5402 NetPassword
:= P
[1];
5403 if Length(NetPassword
) > 24 then
5404 SetLength(NetPassword
, 24);
5405 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5409 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5411 else if cmd
= 'sv_maxplrs' then
5413 if (Length(P
) > 1) then
5415 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5416 if g_Game_IsServer
and g_Game_IsNet
then
5419 for a
:= 0 to High(NetClients
) do
5420 if NetClients
[a
].Used
then
5423 if b
> NetMaxClients
then
5425 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5426 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5427 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5428 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5431 if NetUseMaster
then
5436 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5438 else if cmd
= 'sv_public' then
5440 if (Length(P
) > 1) then
5442 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5443 if g_Game_IsServer
and g_Game_IsNet
then
5444 if NetUseMaster
then
5446 if NetMPeer
= nil then
5447 if not g_Net_Slist_Connect() then
5448 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5449 g_Net_Slist_Update();
5452 if NetMPeer
<> nil then
5453 g_Net_Slist_Disconnect();
5456 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5458 else if cmd
= 'sv_intertime' then
5460 if (Length(P
) > 1) then
5461 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5463 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5465 else if cmd
= 'p1_name' then
5467 if (Length(P
) > 1) and gGameOn
then
5469 if g_Game_IsClient
then
5471 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5472 MC_SEND_PlayerSettings
;
5475 if gPlayer1
<> nil then
5477 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5478 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5481 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5484 else if cmd
= 'p2_name' then
5486 if (Length(P
) > 1) and gGameOn
then
5488 if g_Game_IsClient
then
5490 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5491 MC_SEND_PlayerSettings
;
5494 if gPlayer2
<> nil then
5496 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5497 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5500 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5503 else if cmd
= 'p1_color' then
5505 if Length(P
) > 3 then
5506 if g_Game_IsClient
then
5508 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5509 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5510 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5511 MC_SEND_PlayerSettings
;
5514 if gPlayer1
<> nil then
5516 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5517 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5518 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5519 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5522 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5523 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5524 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5526 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5528 if Length(P
) > 3 then
5529 if g_Game_IsClient
then
5531 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5532 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5533 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5534 MC_SEND_PlayerSettings
;
5537 if gPlayer2
<> nil then
5539 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5540 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5541 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5542 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5545 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5546 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5547 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5549 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5551 if cmd
= 'r_showtime' then
5553 if (Length(P
) > 1) and
5554 ((P
[1] = '1') or (P
[1] = '0')) then
5555 gShowTime
:= (P
[1][1] = '1');
5558 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5560 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5562 else if cmd
= 'r_showscore' then
5564 if (Length(P
) > 1) and
5565 ((P
[1] = '1') or (P
[1] = '0')) then
5566 gShowGoals
:= (P
[1][1] = '1');
5569 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5571 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5573 else if cmd
= 'r_showstat' then
5575 if (Length(P
) > 1) and
5576 ((P
[1] = '1') or (P
[1] = '0')) then
5577 gShowStat
:= (P
[1][1] = '1');
5580 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5582 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5584 else if cmd
= 'r_showkillmsg' then
5586 if (Length(P
) > 1) and
5587 ((P
[1] = '1') or (P
[1] = '0')) then
5588 gShowKillMsg
:= (P
[1][1] = '1');
5590 if gShowKillMsg
then
5591 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5593 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5595 else if cmd
= 'r_showlives' then
5597 if (Length(P
) > 1) and
5598 ((P
[1] = '1') or (P
[1] = '0')) then
5599 gShowLives
:= (P
[1][1] = '1');
5602 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5604 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5606 else if cmd
= 'r_showspect' then
5608 if (Length(P
) > 1) and
5609 ((P
[1] = '1') or (P
[1] = '0')) then
5610 gSpectHUD
:= (P
[1][1] = '1');
5613 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5615 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5617 else if cmd
= 'r_showping' then
5619 if (Length(P
) > 1) and
5620 ((P
[1] = '1') or (P
[1] = '0')) then
5621 gShowPing
:= (P
[1][1] = '1');
5624 g_Console_Add(_lc
[I_MSG_PING_ON
])
5626 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5628 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5630 if Length(P
) > 1 then
5632 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5633 gGameSettings
.GoalLimit
:= 0
5638 if gGameSettings
.GameMode
= GM_DM
then
5640 stat
:= g_Player_GetStats();
5642 for a
:= 0 to High(stat
) do
5643 if stat
[a
].Frags
> b
then
5647 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5649 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5652 if g_Game_IsNet
then MH_SEND_GameSettings
;
5655 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5657 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5659 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5660 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5662 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5663 [gGameSettings
.TimeLimit
div 3600,
5664 (gGameSettings
.TimeLimit
div 60) mod 60,
5665 gGameSettings
.TimeLimit
mod 60]));
5666 if g_Game_IsNet
then MH_SEND_GameSettings
;
5668 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5670 if Length(P
) > 1 then
5672 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5673 gGameSettings
.MaxLives
:= 0
5677 stat
:= g_Player_GetStats();
5679 for a
:= 0 to High(stat
) do
5680 if stat
[a
].Lives
> b
then
5682 gGameSettings
.MaxLives
:=
5683 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5687 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5688 [gGameSettings
.MaxLives
]));
5689 if g_Game_IsNet
then MH_SEND_GameSettings
;
5694 procedure PrintHeapStats();
5698 hs
:= GetFPCHeapStatus();
5699 e_LogWriteLn ('v===== heap status =====v');
5700 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5701 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5702 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5703 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5704 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5705 e_LogWriteLn ('^=======================^');
5708 procedure DebugCommands(P
: SSArray
);
5715 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5716 if {gDebugMode}conIsCheatsEnabled
then
5718 cmd
:= LowerCase(P
[0]);
5719 if cmd
= 'd_window' then
5721 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5722 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5723 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5724 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5725 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5727 else if cmd
= 'd_sounds' then
5729 if (Length(P
) > 1) and
5730 ((P
[1] = '1') or (P
[1] = '0')) then
5731 g_Debug_Sounds
:= (P
[1][1] = '1');
5733 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5735 else if cmd
= 'd_frames' then
5737 if (Length(P
) > 1) and
5738 ((P
[1] = '1') or (P
[1] = '0')) then
5739 g_Debug_Frames
:= (P
[1][1] = '1');
5741 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5743 else if cmd
= 'd_winmsg' then
5745 if (Length(P
) > 1) and
5746 ((P
[1] = '1') or (P
[1] = '0')) then
5747 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5749 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5751 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5753 if (Length(P
) > 1) and
5754 ((P
[1] = '1') or (P
[1] = '0')) then
5755 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5757 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5759 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5761 if Length(P
) > 1 then
5763 '0': g_debug_BotAIOff
:= 0;
5764 '1': g_debug_BotAIOff
:= 1;
5765 '2': g_debug_BotAIOff
:= 2;
5766 '3': g_debug_BotAIOff
:= 3;
5769 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5771 else if cmd
= 'd_monster' then
5773 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5774 if Length(P
) < 2 then
5776 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5777 g_Console_Add('ID | Name');
5778 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5779 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5780 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5783 a
:= StrToIntDef(P
[1], 0);
5784 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5785 a
:= g_Mons_TypeIdByName(P
[1]);
5787 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5788 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5791 with gPlayer1
.Obj
do
5793 mon
:= g_Monsters_Create(a
,
5794 X
+ Rect
.X
+ (Rect
.Width
div 2),
5795 Y
+ Rect
.Y
+ Rect
.Height
,
5796 gPlayer1
.Direction
, True);
5798 if (Length(P
) > 2) and (mon
<> nil) then
5800 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5801 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5802 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5803 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5804 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5805 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5806 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5807 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5808 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5813 else if (cmd
= 'd_health') then
5815 if (Length(P
) > 1) and
5816 ((P
[1] = '1') or (P
[1] = '0')) then
5817 g_debug_HealthBar
:= (P
[1][1] = '1');
5819 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5821 else if (cmd
= 'd_player') then
5823 if (Length(P
) > 1) and
5824 ((P
[1] = '1') or (P
[1] = '0')) then
5825 g_debug_Player
:= (P
[1][1] = '1');
5827 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5829 else if (cmd
= 'd_joy') then
5832 g_Console_Add(e_JoystickStateToString(a
));
5834 else if (cmd
= 'd_mem') then
5840 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5844 procedure GameCheats(P
: SSArray
);
5850 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5852 g_Console_Add('not available');
5858 g_Console_Add('where is the player?!');
5861 cmd
:= LowerCase(P
[0]);
5865 plr
.GodMode
:= not plr
.GodMode
;
5866 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5869 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5870 if cmd
= 'give' then
5872 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5873 for f
:= 1 to High(P
) do
5875 cmd
:= LowerCase(P
[f
]);
5876 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5877 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5878 if cmd
= 'exit' then
5880 if gTriggers
<> nil then
5882 for a
:= 0 to High(gTriggers
) do
5884 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5886 g_Console_Add('player left the map');
5887 gExitByTrigger
:= True;
5888 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5889 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5897 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5898 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5899 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5900 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5901 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5903 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5904 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5906 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5907 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;
5909 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5910 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5912 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5913 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5915 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5916 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5918 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5919 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5920 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5922 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5923 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5924 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5925 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;
5926 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5927 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5929 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;
5930 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;
5931 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;
5932 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;
5933 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;
5934 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;
5936 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5937 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;
5939 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;
5940 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;
5942 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5944 if cmd
= 'ammo' then
5946 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5947 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5948 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5949 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5950 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5951 g_Console_Add('player got some ammo');
5955 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5956 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5958 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5959 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5961 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5962 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5964 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5965 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5967 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5969 if cmd
= 'weapons' then
5971 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5972 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5973 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5974 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5975 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5976 plr
.GiveItem(ITEM_WEAPON_BFG
);
5977 g_Console_Add('player got weapons');
5981 if cmd
= 'keys' then
5983 plr
.GiveItem(ITEM_KEY_RED
);
5984 plr
.GiveItem(ITEM_KEY_GREEN
);
5985 plr
.GiveItem(ITEM_KEY_BLUE
);
5986 g_Console_Add('player got all keys');
5990 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5995 if cmd
= 'open' then
5997 g_Console_Add('player activated sesame');
5998 g_Triggers_OpenAll();
6005 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6009 if cmd
= 'noclip' then
6012 g_Console_Add('wall hardeness adjusted');
6016 if cmd
= 'notarget' then
6018 plr
.NoTarget
:= not plr
.NoTarget
;
6019 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6023 if cmd
= 'noreload' then
6025 plr
.NoReload
:= not plr
.NoReload
;
6026 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6030 if cmd
= 'speedy' then
6032 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6033 g_Console_Add('speed adjusted');
6037 if cmd
= 'jumpy' then
6039 VEL_JUMP
:= 30-VEL_JUMP
;
6040 g_Console_Add('jump height adjusted');
6044 if cmd
= 'automap' then
6046 gShowMap
:= not gShowMap
;
6047 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6051 if cmd
= 'aimline' then
6053 gAimLine
:= not gAimLine
;
6054 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6059 procedure GameCommands(P
: SSArray
);
6065 pl
: pTNetClient
= nil;
6072 cmd
:= LowerCase(P
[0]);
6074 if (cmd
= 'quit') or
6081 else if cmd
= 'pause' then
6083 if (g_ActiveWindow
= nil) then
6084 g_Game_Pause(not gPauseMain
);
6086 else if cmd
= 'endgame' then
6087 gExit
:= EXIT_SIMPLE
6088 else if cmd
= 'restart' then
6090 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6092 if g_Game_IsClient
then
6094 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6099 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6101 else if cmd
= 'kick' then
6103 if g_Game_IsServer
then
6105 if Length(P
) < 2 then
6107 g_Console_Add('kick <name>');
6112 g_Console_Add('kick <name>');
6116 if g_Game_IsNet
then
6117 pl
:= g_Net_Client_ByName(P
[1]);
6120 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6121 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6122 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6123 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6124 if NetUseMaster
then
6126 end else if gPlayers
<> nil then
6127 for a
:= Low(gPlayers
) to High(gPlayers
) do
6128 if gPlayers
[a
] <> nil then
6129 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6131 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6132 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6134 gPlayers
[a
].Lives
:= 0;
6135 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6136 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6137 g_Player_Remove(gPlayers
[a
].UID
);
6138 if NetUseMaster
then
6140 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6144 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6146 else if cmd
= 'kick_id' then
6148 if g_Game_IsServer
and g_Game_IsNet
then
6150 if Length(P
) < 2 then
6152 g_Console_Add('kick_id <client ID>');
6157 g_Console_Add('kick_id <client ID>');
6161 a
:= StrToIntDef(P
[1], 0);
6162 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6164 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6166 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6167 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6168 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6169 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6170 if NetUseMaster
then
6175 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6177 else if cmd
= 'ban' then
6179 if g_Game_IsServer
and g_Game_IsNet
then
6181 if Length(P
) < 2 then
6183 g_Console_Add('ban <name>');
6188 g_Console_Add('ban <name>');
6192 pl
:= g_Net_Client_ByName(P
[1]);
6195 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6196 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6197 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6198 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6199 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6200 if NetUseMaster
then
6203 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6205 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6207 else if cmd
= 'ban_id' then
6209 if g_Game_IsServer
and g_Game_IsNet
then
6211 if Length(P
) < 2 then
6213 g_Console_Add('ban_id <client ID>');
6218 g_Console_Add('ban_id <client ID>');
6222 a
:= StrToIntDef(P
[1], 0);
6223 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6224 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6226 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6227 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6228 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6229 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6230 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6231 if NetUseMaster
then
6235 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6237 else if cmd
= 'permban' then
6239 if g_Game_IsServer
and g_Game_IsNet
then
6241 if Length(P
) < 2 then
6243 g_Console_Add('permban <name>');
6248 g_Console_Add('permban <name>');
6252 pl
:= g_Net_Client_ByName(P
[1]);
6255 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6256 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6257 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6258 g_Net_SaveBanList();
6259 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6260 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6261 if NetUseMaster
then
6264 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6266 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6268 else if cmd
= 'permban_id' then
6270 if g_Game_IsServer
and g_Game_IsNet
then
6272 if Length(P
) < 2 then
6274 g_Console_Add('permban_id <client ID>');
6279 g_Console_Add('permban_id <client ID>');
6283 a
:= StrToIntDef(P
[1], 0);
6284 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6285 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6287 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6288 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6289 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6290 g_Net_SaveBanList();
6291 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6292 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6293 if NetUseMaster
then
6297 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6299 else if cmd
= 'unban' then
6301 if g_Game_IsServer
and g_Game_IsNet
then
6303 if Length(P
) < 2 then
6305 g_Console_Add('unban <IP Address>');
6310 g_Console_Add('unban <IP Address>');
6314 if g_Net_UnbanHost(P
[1]) then
6316 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6317 g_Net_SaveBanList();
6319 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6321 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6323 else if cmd
= 'clientlist' then
6325 if g_Game_IsServer
and g_Game_IsNet
then
6328 if NetClients
<> nil then
6329 for a
:= Low(NetClients
) to High(NetClients
) do
6330 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6332 plr
:= g_Player_Get(NetClients
[a
].Player
);
6333 if plr
= nil then continue
;
6335 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6336 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6339 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6341 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6343 else if cmd
= 'connect' then
6345 if (NetMode
= NET_NONE
) then
6347 if Length(P
) < 2 then
6349 g_Console_Add('connect <IP> [port] [password]');
6354 g_Console_Add('connect <IP> [port] [password]');
6358 if Length(P
) > 2 then
6359 prt
:= StrToIntDef(P
[2], 25666)
6363 if Length(P
) > 3 then
6368 g_Game_StartClient(P
[1], prt
, pw
);
6371 else if cmd
= 'disconnect' then
6373 if (NetMode
= NET_CLIENT
) then
6376 else if cmd
= 'reconnect' then
6378 if (NetMode
= NET_SERVER
) then
6381 if (NetMode
= NET_CLIENT
) then
6384 gExit
:= EXIT_SIMPLE
;
6388 //TODO: Use last successful password to reconnect, instead of ''
6389 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6391 else if (cmd
= 'addbot') or
6392 (cmd
= 'bot_add') then
6394 if Length(P
) > 1 then
6395 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6397 g_Bot_Add(TEAM_NONE
, 2);
6399 else if cmd
= 'bot_addlist' then
6401 if Length(P
) > 1 then
6402 if Length(P
) = 2 then
6403 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6405 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6407 else if cmd
= 'bot_removeall' then
6409 else if cmd
= 'chat' then
6411 if g_Game_IsNet
then
6413 if Length(P
) > 1 then
6415 for a
:= 1 to High(P
) do
6416 chstr
:= chstr
+ P
[a
] + ' ';
6418 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6420 if Length(chstr
) < 1 then
6422 g_Console_Add('chat <text>');
6426 chstr
:= b_Text_Format(chstr
);
6427 if g_Game_IsClient
then
6428 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6430 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6433 g_Console_Add('chat <text>');
6435 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6437 else if cmd
= 'teamchat' then
6439 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6441 if Length(P
) > 1 then
6443 for a
:= 1 to High(P
) do
6444 chstr
:= chstr
+ P
[a
] + ' ';
6446 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6448 if Length(chstr
) < 1 then
6450 g_Console_Add('teamchat <text>');
6454 chstr
:= b_Text_Format(chstr
);
6455 if g_Game_IsClient
then
6456 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6458 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6459 gPlayer1Settings
.Team
);
6462 g_Console_Add('teamchat <text>');
6464 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6466 else if cmd
= 'game' then
6468 if gGameSettings
.GameType
<> GT_NONE
then
6470 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6473 if Length(P
) = 1 then
6475 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6478 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6479 P
[1] := addWadExtension(P
[1]);
6480 if FileExists(MapsDir
+ P
[1]) then
6482 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6483 if Length(P
) < 3 then
6486 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6489 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6491 if g_Map_Exist(MapsDir
+ s
) then
6493 // Çàïóñêàåì ñâîþ èãðó
6495 with gGameSettings
do
6497 GameMode
:= g_Game_TextToMode(gcGameMode
);
6498 if gSwitchGameMode
<> GM_NONE
then
6499 GameMode
:= gSwitchGameMode
;
6500 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6501 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6503 if Length(P
) >= 4 then
6504 b
:= StrToIntDef(P
[3], 1);
6505 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6506 GoalLimit
, MaxLives
, Options
, b
);
6511 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6513 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6515 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6517 else if cmd
= 'host' then
6519 if gGameSettings
.GameType
<> GT_NONE
then
6521 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6524 if Length(P
) < 4 then
6526 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6529 if not StrToIp(P
[1], listen
) then
6531 prt
:= StrToIntDef(P
[2], 25666);
6533 P
[3] := addWadExtension(P
[3]);
6534 if FileExists(MapsDir
+ P
[3]) then
6536 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6537 if Length(P
) < 5 then
6540 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6543 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6545 if g_Map_Exist(MapsDir
+ s
) then
6547 // Çàïóñêàåì ñâîþ èãðó
6549 with gGameSettings
do
6551 GameMode
:= g_Game_TextToMode(gcGameMode
);
6552 if gSwitchGameMode
<> GM_NONE
then
6553 GameMode
:= gSwitchGameMode
;
6554 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6555 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6557 if Length(P
) >= 6 then
6558 b
:= StrToIntDef(P
[5], 0);
6559 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6560 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6565 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6567 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6569 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6571 else if cmd
= 'map' then
6573 if Length(P
) = 1 then
6575 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6577 g_Console_Add(cmd
+ ' <MAP>');
6578 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6580 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6582 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6584 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6585 if Length(P
) < 3 then
6587 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6588 s
:= UpperCase(P
[1]);
6589 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6590 begin // Êàðòà íàøëàñü
6591 gExitByTrigger
:= False;
6593 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6595 gExit
:= EXIT_ENDLEVELCUSTOM
;
6597 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6598 g_Game_ChangeMap(s
);
6601 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6602 P
[1] := addWadExtension(P
[1]);
6603 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6604 if FileExists(MapsDir
+ P
[1]) then
6606 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6608 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6610 s
:= P
[1] + ':\' + P
[2];
6612 if g_Map_Exist(MapsDir
+ s
) then
6614 gExitByTrigger
:= False;
6616 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6618 gExit
:= EXIT_ENDLEVELCUSTOM
;
6620 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6621 g_Game_ChangeMap(s
);
6624 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6626 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6628 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6632 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6633 P
[1] := addWadExtension(P
[1]);
6634 if FileExists(MapsDir
+ P
[1]) then
6637 P
[2] := UpperCase(P
[2]);
6638 s
:= P
[1] + ':\' + P
[2];
6640 if g_Map_Exist(MapsDir
+ s
) then
6641 begin // Íàøëè êàðòó
6642 gExitByTrigger
:= False;
6644 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6646 gExit
:= EXIT_ENDLEVELCUSTOM
;
6648 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6649 g_Game_ChangeMap(s
);
6651 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6653 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6656 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6658 else if cmd
= 'nextmap' then
6660 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6661 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6664 if Length(P
) = 1 then
6666 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6668 g_Console_Add(cmd
+ ' <MAP>');
6669 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6672 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6677 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6679 if Length(P
) < 3 then
6681 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6682 s
:= UpperCase(P
[1]);
6683 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6684 begin // Êàðòà íàøëàñü
6685 gExitByTrigger
:= False;
6690 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6691 P
[1] := addWadExtension(P
[1]);
6692 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6693 if FileExists(MapsDir
+ P
[1]) then
6695 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6697 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6699 s
:= P
[1] + ':\' + P
[2];
6701 if g_Map_Exist(MapsDir
+ s
) then
6702 begin // Óñòàíàâëèâàåì êàðòó
6703 gExitByTrigger
:= False;
6708 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6710 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6712 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6716 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6717 P
[1] := addWadExtension(P
[1]);
6718 if FileExists(MapsDir
+ P
[1]) then
6721 P
[2] := UpperCase(P
[2]);
6722 s
:= P
[1] + ':\' + P
[2];
6724 if g_Map_Exist(MapsDir
+ s
) then
6725 begin // Íàøëè êàðòó
6726 gExitByTrigger
:= False;
6730 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6732 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6735 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6738 if gNextMap
= '' then
6739 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6741 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6744 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6747 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6749 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6751 gExitByTrigger
:= False;
6752 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6753 if (gNextMap
= '') and (gTriggers
<> nil) then
6754 for a
:= 0 to High(gTriggers
) do
6755 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6757 gExitByTrigger
:= True;
6758 //gNextMap := gTriggers[a].Data.MapName;
6759 gNextMap
:= gTriggers
[a
].tgcMap
;
6762 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6763 if gNextMap
= '' then
6764 gNextMap
:= g_Game_GetNextMap();
6765 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6766 if not isWadPath(gNextMap
) then
6767 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6770 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6771 if g_Map_Exist(MapsDir
+ s
) then
6772 gExit
:= EXIT_ENDLEVELCUSTOM
6774 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6776 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6778 else if (cmd
= 'event') then
6780 if (Length(P
) <= 1) then
6782 for a
:= 0 to High(gEvents
) do
6783 if gEvents
[a
].Command
= '' then
6784 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6786 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6789 if (Length(P
) = 2) then
6791 for a
:= 0 to High(gEvents
) do
6792 if gEvents
[a
].Name
= P
[1] then
6793 if gEvents
[a
].Command
= '' then
6794 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6796 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6799 for a
:= 0 to High(gEvents
) do
6800 if gEvents
[a
].Name
= P
[1] then
6802 gEvents
[a
].Command
:= '';
6803 for b
:= 2 to High(P
) do
6804 if Pos(' ', P
[b
]) = 0 then
6805 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6807 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6808 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6812 else if cmd
= 'suicide' then
6816 if g_Game_IsClient
then
6817 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6820 if gPlayer1
<> nil then
6821 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6822 if gPlayer2
<> nil then
6823 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6827 // Êîìàíäû Ñâîåé èãðû:
6828 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6830 if cmd
= 'bot_addred' then
6832 if Length(P
) > 1 then
6833 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6835 g_Bot_Add(TEAM_RED
, 2);
6837 else if cmd
= 'bot_addblue' then
6839 if Length(P
) > 1 then
6840 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6842 g_Bot_Add(TEAM_BLUE
, 2);
6844 else if cmd
= 'spectate' then
6850 else if cmd
= 'say' then
6852 if g_Game_IsServer
and g_Game_IsNet
then
6854 if Length(P
) > 1 then
6857 for a
:= 1 to High(P
) do
6858 chstr
:= chstr
+ P
[a
] + ' ';
6860 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6862 if Length(chstr
) < 1 then
6864 g_Console_Add('say <text>');
6868 chstr
:= b_Text_Format(chstr
);
6869 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6871 else g_Console_Add('say <text>');
6873 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6875 else if cmd
= 'tell' then
6877 if g_Game_IsServer
and g_Game_IsNet
then
6879 if (Length(P
) > 2) and (P
[1] <> '') then
6882 for a
:= 2 to High(P
) do
6883 chstr
:= chstr
+ P
[a
] + ' ';
6885 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6887 if Length(chstr
) < 1 then
6889 g_Console_Add('tell <playername> <text>');
6893 pl
:= g_Net_Client_ByName(P
[1]);
6895 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6897 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6899 else g_Console_Add('tell <playername> <text>');
6901 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6903 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6905 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6907 // Äîïîëíèòåëüíîå âðåìÿ:
6908 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6910 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6911 [gGameSettings
.TimeLimit
div 3600,
6912 (gGameSettings
.TimeLimit
div 60) mod 60,
6913 gGameSettings
.TimeLimit
mod 60]));
6914 if g_Game_IsNet
then MH_SEND_GameSettings
;
6916 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6918 if (Length(P
) <= 1) then
6919 g_Console_Add('rcon_password <password>')
6921 MC_SEND_RCONPassword(P
[1]);
6923 else if cmd
= 'rcon' then
6925 if g_Game_IsClient
then
6927 if Length(P
) > 1 then
6930 for a
:= 1 to High(P
) do
6931 chstr
:= chstr
+ P
[a
] + ' ';
6933 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6935 if Length(chstr
) < 1 then
6937 g_Console_Add('rcon <command>');
6941 MC_SEND_RCONCommand(chstr
);
6943 else g_Console_Add('rcon <command>');
6946 else if cmd
= 'ready' then
6948 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6949 gLMSRespawnTime
:= gTime
+ 100;
6951 else if (cmd
= 'callvote') and g_Game_IsNet
then
6953 if Length(P
) > 1 then
6956 for a
:= 1 to High(P
) do begin
6957 if a
> 1 then chstr
:= chstr
+ ' ';
6958 chstr
:= chstr
+ P
[a
];
6961 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6963 if Length(chstr
) < 1 then
6965 g_Console_Add('callvote <command>');
6969 if g_Game_IsClient
then
6970 MC_SEND_Vote(True, chstr
)
6972 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6973 g_Console_Process('vote', True);
6976 g_Console_Add('callvote <command>');
6978 else if (cmd
= 'vote') and g_Game_IsNet
then
6980 if g_Game_IsClient
then
6982 else if gVoteInProgress
then
6984 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6985 a
:= Floor((NetClientCount
+1)/2.0) + 1
6987 a
:= Floor(NetClientCount
/2.0) + 1;
6992 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6993 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6999 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7000 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7008 procedure g_TakeScreenShot();
7016 if e_NoGraphics
then Exit
;
7017 ssdir
:= GameDir
+'/screenshots';
7018 if not findFileCI(ssdir
, true) then
7020 // try to create dir
7025 if not findFileCI(ssdir
, true) then exit
; // alas
7028 for a
:= 1 to High(Word) do
7030 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
7032 if findFileCI(t
, true) then continue
;
7033 if not findFileCI(FileName
) then
7036 st
:= createDiskFile(FileName
);
7038 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
7043 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
7051 procedure g_Game_InGameMenu(Show
: Boolean);
7053 if (g_ActiveWindow
= nil) and Show
then
7055 if gGameSettings
.GameType
= GT_SINGLE
then
7056 g_GUI_ShowWindow('GameSingleMenu')
7059 if g_Game_IsClient
then
7060 g_GUI_ShowWindow('GameClientMenu')
7062 if g_Game_IsNet
then
7063 g_GUI_ShowWindow('GameServerMenu')
7065 g_GUI_ShowWindow('GameCustomMenu');
7067 g_Sound_PlayEx('MENU_OPEN');
7069 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7070 if (not g_Game_IsNet
) then
7074 if (g_ActiveWindow
<> nil) and (not Show
) then
7076 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7077 if (not g_Game_IsNet
) then
7078 g_Game_Pause(False);
7082 procedure g_Game_Pause (Enable
: Boolean);
7086 if not gGameOn
then exit
;
7088 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7091 gPauseMain
:= Enable
;
7093 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7096 procedure g_Game_HolmesPause (Enable
: Boolean);
7100 if not gGameOn
then exit
;
7101 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7104 gPauseHolmes
:= Enable
;
7106 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7109 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7114 if gTriggers
<> nil then
7115 for i
:= 0 to High(gTriggers
) do
7116 with gTriggers
[i
] do
7117 if (TriggerType
= TRIGGER_SOUND
) and
7119 Sound
.IsPlaying() then
7121 Sound
.Pause(Enable
);
7125 if gPlayers
<> nil then
7126 for i
:= 0 to High(gPlayers
) do
7127 if gPlayers
[i
] <> nil then
7128 gPlayers
[i
].PauseSounds(Enable
);
7131 if gMusic
<> nil then
7132 gMusic
.Pause(Enable
);
7135 procedure g_Game_StopAllSounds(all
: Boolean);
7139 if gTriggers
<> nil then
7140 for i
:= 0 to High(gTriggers
) do
7141 with gTriggers
[i
] do
7142 if (TriggerType
= TRIGGER_SOUND
) and
7146 if gMusic
<> nil then
7153 procedure g_Game_UpdateTriggerSounds();
7157 if gTriggers
<> nil then
7158 for i
:= 0 to High(gTriggers
) do
7159 with gTriggers
[i
] do
7160 if (TriggerType
= TRIGGER_SOUND
) and
7163 Sound
.IsPlaying() then
7165 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
7166 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
7168 Sound
.SetPan(0.5 - tgcPan
/255.0);
7169 Sound
.SetVolume(tgcVolume
/255.0);
7172 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
7176 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7179 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7184 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7189 if gSpectMode
<> SPECT_PLAYERS
then
7191 if gSpectPID1
= UID
then
7196 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7203 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7208 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7213 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7218 if gSpectMode
<> SPECT_PLAYERS
then
7220 Pl
:= g_Player_Get(gSpectPID1
);
7221 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7226 if gSpectViewTwo
then
7228 Pl
:= g_Player_Get(gSpectPID2
);
7229 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7237 procedure g_Game_Message(Msg
: string; Time
: Word);
7239 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7240 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7241 MessageTime
:= Time
;
7244 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7246 punct
: Array[0..13] of String =
7247 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7253 function IsPunctuation(S
: String): Boolean;
7258 if Length(S
) <> 1 then
7260 for i
:= Low(punct
) to High(punct
) do
7261 if S
= punct
[i
] then
7267 function FilterPunctuation(S
: String): String;
7271 for i
:= Low(punct
) to High(punct
) do
7272 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7278 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7280 // remove player name
7281 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7282 // for FullWord check
7283 Text := toLowerCase1251(' ' + Text + ' ');
7284 fpText
:= FilterPunctuation(Text);
7286 for i
:= 0 to Length(gChatSounds
) - 1 do
7289 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7291 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7292 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7294 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7300 gChatSounds
[i
].Sound
.Play();
7306 g_Sound_PlayEx('SOUND_GAME_RADIO');
7309 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7318 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7322 if goodsnd
[a
].IsPlaying() then
7325 goodsnd
[Random(4)].Play();
7328 procedure g_Game_Announce_KillCombo(Param
: Integer);
7335 UID
:= Param
and $FFFF;
7340 Pl
:= g_Player_Get(UID
);
7349 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7353 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7357 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7361 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7369 if not g_Game_IsWatchedPlayer(UID
) then
7372 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7376 if killsnd
[n
].IsPlaying() then
7381 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7390 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7394 if hahasnd
[a
].IsPlaying() then
7397 hahasnd
[Random(3)].Play();
7400 procedure g_Game_StartVote(Command
, Initiator
: string);
7404 if not gVotesEnabled
then Exit
;
7405 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7406 if gVoteInProgress
or gVotePassed
then
7408 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7409 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7412 gVoteInProgress
:= True;
7413 gVotePassed
:= False;
7414 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7417 gVoteCommand
:= Command
;
7419 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7420 Need
:= Floor((NetClientCount
+1)/2.0)+1
7422 Need
:= Floor(NetClientCount
/2.0)+1;
7423 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7424 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7427 procedure g_Game_CheckVote
;
7431 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7432 if not gVoteInProgress
then Exit
;
7434 if (gTime
>= gVoteTimer
) then
7436 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7437 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7439 Need
:= Floor(NetClientCount
/2.0) + 1;
7440 if gVoteCount
>= Need
then
7442 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7443 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7444 gVotePassed
:= True;
7445 gVoteCmdTimer
:= gTime
+ 5000;
7449 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7450 MH_SEND_VoteEvent(NET_VE_FAILED
);
7452 if NetClients
<> nil then
7453 for I
:= Low(NetClients
) to High(NetClients
) do
7454 if NetClients
[i
].Used
then
7455 NetClients
[i
].Voted
:= False;
7456 gVoteInProgress
:= False;
7462 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7463 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7465 Need
:= Floor(NetClientCount
/2.0) + 1;
7466 if gVoteCount
>= Need
then
7468 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7469 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7470 gVoteInProgress
:= False;
7471 gVotePassed
:= True;
7472 gVoteCmdTimer
:= gTime
+ 5000;
7475 if NetClients
<> nil then
7476 for I
:= Low(NetClients
) to High(NetClients
) do
7477 if NetClients
[i
].Used
then
7478 NetClients
[i
].Voted
:= False;
7483 procedure g_Game_LoadMapList(FileName
: string);
7491 if not FileExists(FileName
) then Exit
;
7493 AssignFile(ListFile
, FileName
);
7495 while not EOF(ListFile
) do
7497 ReadLn(ListFile
, s
);
7500 if s
= '' then Continue
;
7502 SetLength(MapList
, Length(MapList
)+1);
7503 MapList
[High(MapList
)] := s
;
7505 CloseFile(ListFile
);
7508 procedure g_Game_SetDebugMode();
7511 // ×èòû (äàæå â ñâîåé èãðå):
7515 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7519 if Length(LoadingStat
.Msgs
) = 0 then
7525 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7526 if NextMsg
= Length(Msgs
) then
7528 for i
:= 0 to High(Msgs
)-1 do
7529 Msgs
[i
] := Msgs
[i
+1];
7537 Msgs
[NextMsg
-1] := Text;
7541 PBarWasHere
:= false;
7544 g_ActiveWindow
:= nil;
7546 ProcessLoading(true);
7549 procedure g_Game_StepLoading(Value
: Integer = -1);
7560 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7568 procedure g_Game_ClearLoading();
7577 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7578 if len
< 1 then len
:= 1;
7579 SetLength(Msgs
, len
);
7580 for len
:= Low(Msgs
) to High(Msgs
) do
7583 PBarWasHere
:= false;
7587 procedure Parse_Params(var pars
: TParamStrValues
);
7594 while i
<= ParamCount
do
7597 if (s
[1] = '-') and (Length(s
) > 1) then
7599 if (s
[2] = '-') and (Length(s
) > 2) then
7600 begin // Îäèíî÷íûé ïàðàìåòð
7601 SetLength(pars
, Length(pars
) + 1);
7602 with pars
[High(pars
)] do
7604 Name
:= LowerCase(s
);
7609 if (i
< ParamCount
) then
7610 begin // Ïàðàìåòð ñî çíà÷åíèåì
7612 SetLength(pars
, Length(pars
) + 1);
7613 with pars
[High(pars
)] do
7615 Name
:= LowerCase(s
);
7616 Value
:= LowerCase(ParamStr(i
));
7625 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7630 for i
:= 0 to High(pars
) do
7631 if pars
[i
].Name
= aName
then
7633 Result
:= pars
[i
].Value
;
7638 procedure g_Game_Process_Params();
7640 pars
: TParamStrValues
;
7643 LimT
, LimS
: Integer;
7654 s
:= Find_Param_Value(pars
, '--debug');
7657 g_Game_SetDebugMode();
7658 s
:= Find_Param_Value(pars
, '--netdump');
7663 // Connect when game loads
7664 ip
:= Find_Param_Value(pars
, '-connect');
7668 s
:= Find_Param_Value(pars
, '-port');
7669 if (s
= '') or not TryStrToInt(s
, Port
) then
7672 s
:= Find_Param_Value(pars
, '-pw');
7674 g_Game_StartClient(ip
, Port
, s
);
7678 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7681 gDefaultMegawadStart
:= s
;
7684 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7685 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7687 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7690 // Start map when game loads:
7691 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7692 if isWadPath(map
) then
7695 s
:= Find_Param_Value(pars
, '-gm');
7696 GMode
:= g_Game_TextToMode(s
);
7697 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7698 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7701 s
:= Find_Param_Value(pars
, '-limt');
7702 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7708 s
:= Find_Param_Value(pars
, '-lims');
7709 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7715 s
:= Find_Param_Value(pars
, '-lives');
7716 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7722 s
:= Find_Param_Value(pars
, '-opt');
7724 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7726 Opt
:= StrToIntDef(s
, 0);
7728 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7731 s
:= Find_Param_Value(pars
, '--close');
7735 // Override map to test:
7736 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7738 gTestMap
:= MapsDir
+ s
;
7740 // Delete test map after play:
7741 s
:= Find_Param_Value(pars
, '--testdelete');
7744 gMapToDelete
:= MapsDir
+ map
;
7745 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7749 // Delete temporary WAD after play:
7750 s
:= Find_Param_Value(pars
, '--tempdelete');
7751 if (s
<> '') and (gTestMap
<> '') then
7753 gMapToDelete
:= gTestMap
;
7754 gTempDelete
:= True;
7757 // Number of players:
7758 s
:= Find_Param_Value(pars
, '-pl');
7762 n
:= StrToIntDef(s
, 1);
7765 s
:= Find_Param_Value(pars
, '-port');
7766 if (s
= '') or not TryStrToInt(s
, Port
) then
7767 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7769 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7772 // Execute script when game loads:
7773 s
:= Find_Param_Value(pars
, '-exec');
7776 if not isWadPath(s
) then
7777 s
:= GameDir
+ '/' + s
;
7782 if IOResult
<> 0 then
7784 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7785 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7789 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7790 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7795 if IOResult
<> 0 then
7797 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7798 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7802 if Pos('#', s
) <> 1 then // script comment
7803 g_Console_Process(s
, True);
7814 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7815 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7816 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7817 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7819 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7820 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7821 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7822 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7824 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7825 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7827 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7828 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7830 {$IFDEF ENABLE_HOLMES}
7831 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7834 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7836 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7838 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7839 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7841 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7842 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');