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_StartVote(Command
, Initiator
: string);
128 procedure g_Game_CheckVote
;
129 procedure g_TakeScreenShot();
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P
: SSArray
);
135 procedure GameCommands(P
: SSArray
);
136 procedure GameCheats(P
: SSArray
);
137 procedure DebugCommands(P
: SSArray
);
138 procedure g_Game_Process_Params
;
139 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
140 procedure g_Game_StepLoading(Value
: Integer = -1);
141 procedure g_Game_ClearLoading();
142 procedure g_Game_SetDebugMode();
143 procedure DrawLoadingStat();
145 { procedure SetWinPause(Enable: Boolean); }
150 LOADING_SHOW_STEP
= 100;
151 LOADING_INTERLINE
= 20;
166 MESSAGE_DIKEY
= WM_USER
+ 1;
171 EXIT_ENDLEVELSINGLE
= 4;
172 EXIT_ENDLEVELCUSTOM
= 5;
174 GAME_OPTION_RESERVED
= 1;
175 GAME_OPTION_TEAMDAMAGE
= 2;
176 GAME_OPTION_ALLOWEXIT
= 4;
177 GAME_OPTION_WEAPONSTAY
= 8;
178 GAME_OPTION_MONSTERS
= 16;
179 GAME_OPTION_BOTVSPLAYER
= 32;
180 GAME_OPTION_BOTVSMONSTER
= 64;
185 STATE_INTERCUSTOM
= 3;
186 STATE_INTERSINGLE
= 4;
192 LMS_RESPAWN_NONE
= 0;
193 LMS_RESPAWN_WARMUP
= 1;
194 LMS_RESPAWN_FINAL
= 2;
210 CONFIG_FILENAME
= 'Doom2DF.cfg';
211 LOG_FILENAME
= 'Doom2DF.log';
213 TEST_MAP_NAME
= '$$$_TEST_$$$';
215 STD_PLAYER_MODEL
= 'Doomer';
219 gGameSettings
: TGameSettings
;
220 gPlayer1Settings
: TPlayerSettings
;
221 gPlayer2Settings
: TPlayerSettings
;
223 gPlayerScreenSize
: TDFPoint
;
224 gPlayer1ScreenCoord
: TDFPoint
;
225 gPlayer2ScreenCoord
: TDFPoint
;
226 gPlayer1
: TPlayer
= nil;
227 gPlayer2
: TPlayer
= nil;
228 gPlayerDrawn
: TPlayer
= nil;
230 gSwitchGameMode
: Byte = GM_DM
;
231 gHearPoint1
, gHearPoint2
: THearPoint
;
232 gSoundEffectsDF
: Boolean = False;
233 gSoundTriggerTime
: Word = 0;
234 gAnnouncer
: Byte = ANNOUNCE_NONE
;
235 goodsnd
: array[0..3] of TPlayableSound
;
236 killsnd
: array[0..3] of TPlayableSound
;
237 gDefInterTime
: ShortInt = -1;
238 gInterEndTime
: LongWord = 0;
239 gInterTime
: LongWord = 0;
240 gServInterTime
: Byte = 0;
241 gGameStartTime
: LongWord = 0;
242 gTotalMonsters
: Integer = 0;
243 gPauseMain
: Boolean = false;
244 gPauseHolmes
: Boolean = false;
245 gShowTime
: Boolean = True;
246 gShowFPS
: Boolean = False;
247 gShowGoals
: Boolean = True;
248 gShowStat
: Boolean = True;
249 gShowKillMsg
: Boolean = True;
250 gShowLives
: Boolean = True;
251 gShowPing
: Boolean = False;
252 gShowMap
: Boolean = False;
254 gState
: Byte = STATE_NONE
;
256 sWidth
, sHeight
: Word;
257 gSpectMode
: Byte = SPECT_NONE
;
258 gSpectHUD
: Boolean = True;
259 gSpectKeyPress
: Boolean = False;
260 gSpectX
: Integer = 0;
261 gSpectY
: Integer = 0;
262 gSpectStep
: Byte = 8;
263 gSpectViewTwo
: Boolean = False;
264 gSpectPID1
: Integer = -1;
265 gSpectPID2
: Integer = -1;
266 gSpectAuto
: Boolean = False;
267 gSpectAutoNext
: LongWord;
268 gSpectAutoStepX
: Integer;
269 gSpectAutoStepY
: Integer;
270 gMusic
: TMusic
= nil;
271 gLoadGameMode
: Boolean;
272 gCheats
: Boolean = False;
273 gMapOnce
: Boolean = False;
274 gMapToDelete
: String;
275 gTempDelete
: Boolean = False;
276 gLastMap
: Boolean = False;
277 gWinPosX
, gWinPosY
: Integer;
278 gWinSizeX
, gWinSizeY
: Integer;
279 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
280 gWinActive
: Boolean = True; // by default window is active, lol
281 gResolutionChange
: Boolean = False;
282 gRC_Width
, gRC_Height
: Word;
283 gRC_FullScreen
, gRC_Maximized
: Boolean;
284 gLanguageChange
: Boolean = False;
285 gDebugMode
: Boolean = False;
286 g_debug_Sounds
: Boolean = False;
287 g_debug_Frames
: Boolean = False;
288 g_debug_WinMsgs
: Boolean = False;
289 g_debug_MonsterOff
: Boolean = False;
290 g_debug_BotAIOff
: Byte = 0;
291 g_debug_HealthBar
: Boolean = False;
292 g_Debug_Player
: Boolean = False;
293 gCoopMonstersKilled
: Word = 0;
294 gCoopSecretsFound
: Word = 0;
295 gCoopTotalMonstersKilled
: Word = 0;
296 gCoopTotalSecretsFound
: Word = 0;
297 gCoopTotalMonsters
: Word = 0;
298 gCoopTotalSecrets
: Word = 0;
299 gStatsOff
: Boolean = False;
300 gStatsPressed
: Boolean = False;
301 gExitByTrigger
: Boolean = False;
302 gNextMap
: String = '';
303 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
304 gLMSRespawnTime
: Cardinal = 0;
305 gLMSSoftSpawn
: Boolean = False;
306 gMissionFailed
: Boolean = False;
307 gVoteInProgress
: Boolean = False;
308 gVotePassed
: Boolean = False;
309 gVoteCommand
: string = '';
310 gVoteTimer
: Cardinal = 0;
311 gVoteCmdTimer
: Cardinal = 0;
312 gVoteCount
: Integer = 0;
313 gVoteTimeout
: Cardinal = 30;
314 gVoted
: Boolean = False;
315 gVotesEnabled
: Boolean = True;
316 gEvents
: Array of TGameEvent
;
317 gDelayedEvents
: Array of TDelayedEvent
;
318 gUseChatSounds
: Boolean = True;
319 gChatSounds
: Array of TChatSound
;
321 g_dbg_ignore_bounds
: Boolean = false;
322 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
323 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
325 // move button values:
326 // bits 0-1: l/r state:
327 // 0: neither left, nor right pressed
330 // bits 4-5: l/r state when strafe was pressed
331 P1MoveButton
: Byte = 0;
332 P2MoveButton
: Byte = 0;
334 g_profile_frame_update
: Boolean = false;
335 g_profile_frame_draw
: Boolean = false;
336 g_profile_collision
: Boolean = false;
337 g_profile_los
: Boolean = false;
338 g_profile_history_size
: Integer = 1000;
340 g_rlayer_back
: Boolean = true;
341 g_rlayer_step
: Boolean = true;
342 g_rlayer_wall
: Boolean = true;
343 g_rlayer_door
: Boolean = true;
344 g_rlayer_acid1
: Boolean = true;
345 g_rlayer_acid2
: Boolean = true;
346 g_rlayer_water
: Boolean = true;
347 g_rlayer_fore
: Boolean = true;
350 procedure g_ResetDynlights ();
351 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
352 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
354 function conIsCheatsEnabled (): Boolean; inline;
355 function gPause (): Boolean; inline;
361 {$INCLUDE ../nogl/noGLuses.inc}
362 {$IFDEF ENABLE_HOLMES}
365 e_texture
, g_textures
, g_main
, g_window
, g_menu
,
366 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
367 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
368 g_triggers
, g_monsters
, e_sound
, CONFIG
,
370 ENet
, e_msg
, g_netmsg
, g_netmaster
,
375 hasPBarGfx
: Boolean = false;
378 // ////////////////////////////////////////////////////////////////////////// //
379 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
382 // ////////////////////////////////////////////////////////////////////////// //
383 function conIsCheatsEnabled (): Boolean; inline;
386 if g_Game_IsNet
then exit
;
387 if not gDebugMode
then
389 //if not gCheats then exit;
390 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
391 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
397 // ////////////////////////////////////////////////////////////////////////// //
399 profileFrameDraw
: TProfiler
= nil;
402 // ////////////////////////////////////////////////////////////////////////// //
405 x
, y
, radius
: Integer;
408 exploRadius
: Integer;
412 g_dynLights
: array of TDynLight
= nil;
413 g_dynLightCount
: Integer = 0;
414 g_playerLight
: Boolean = false;
416 procedure g_ResetDynlights ();
420 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
422 for idx
:= 0 to g_dynLightCount
-1 do
424 if g_dynLights
[idx
].exploCount
= -666 then
431 Inc(g_dynLights
[idx
].exploCount
);
432 if (g_dynLights
[idx
].exploCount
< 10) then
434 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
435 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
436 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
437 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
442 g_dynLightCount
:= lnum
;
445 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
447 if not gwin_has_stencil
then exit
;
448 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
449 g_dynLights
[g_dynLightCount
].x
:= x
;
450 g_dynLights
[g_dynLightCount
].y
:= y
;
451 g_dynLights
[g_dynLightCount
].radius
:= radius
;
452 g_dynLights
[g_dynLightCount
].r
:= r
;
453 g_dynLights
[g_dynLightCount
].g
:= g
;
454 g_dynLights
[g_dynLightCount
].b
:= b
;
455 g_dynLights
[g_dynLightCount
].a
:= a
;
456 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
457 Inc(g_dynLightCount
);
460 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
462 if not gwin_has_stencil
then exit
;
463 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
464 g_dynLights
[g_dynLightCount
].x
:= x
;
465 g_dynLights
[g_dynLightCount
].y
:= y
;
466 g_dynLights
[g_dynLightCount
].radius
:= 0;
467 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
468 g_dynLights
[g_dynLightCount
].r
:= r
;
469 g_dynLights
[g_dynLightCount
].g
:= g
;
470 g_dynLights
[g_dynLightCount
].b
:= b
;
471 g_dynLights
[g_dynLightCount
].a
:= 0;
472 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
473 Inc(g_dynLightCount
);
477 // ////////////////////////////////////////////////////////////////////////// //
478 function calcProfilesHeight (prof
: TProfiler
): Integer;
481 if (prof
= nil) then exit
;
482 if (length(prof
.bars
) = 0) then exit
;
483 result
:= length(prof
.bars
)*(16+2);
487 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
494 if (prof
= nil) then exit
;
496 if (length(prof
.bars
) = 0) then exit
;
498 hgt
:= calcProfilesHeight(prof
);
499 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
500 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
502 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
503 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
504 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
507 for ii
:= 0 to High(prof
.bars
) do
509 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);
516 // ////////////////////////////////////////////////////////////////////////// //
518 TEndCustomGameStat
= record
519 PlayerStat
: TPlayerStatArray
;
523 Map
, MapName
: String;
526 TEndSingleGameStat
= record
527 PlayerStat
: Array [0..1] of record
533 TotalSecrets
: Integer;
536 TLoadingStat
= record
540 Msgs
: Array of String;
542 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
545 TParamStrValue
= record
550 TParamStrValues
= Array of TParamStrValue
;
553 INTER_ACTION_TEXT
= 1;
554 INTER_ACTION_PIC
= 2;
555 INTER_ACTION_MUSIC
= 3;
559 FPSCounter
, UPSCounter
: Word;
560 FPSTime
, UPSTime
: LongWord;
561 DataLoaded
: Boolean = False;
562 LastScreenShot
: Int64;
563 IsDrawStat
: Boolean = False;
564 CustomStat
: TEndCustomGameStat
;
565 SingleStat
: TEndSingleGameStat
;
566 LoadingStat
: TLoadingStat
;
567 EndingGameCounter
: Byte = 0;
570 MessageLineLength
: Integer = 80;
571 MapList
: SSArray
= nil;
572 MapIndex
: Integer = -1;
578 text: Array of ShortString;
579 anim
: Array of ShortString;
580 pic
: Array of ShortString;
581 mus
: Array of ShortString;
583 triggers
: Array of record
585 actions
: Array of record
586 action
, p1
, p2
: Integer;
589 cur_trigger
: Integer;
602 function Compare(a
, b
: TPlayerStat
): Integer;
604 if a
.Spectator
then Result
:= 1
605 else if b
.Spectator
then Result
:= -1
606 else if a
.Frags
< b
.Frags
then Result
:= 1
607 else if a
.Frags
> b
.Frags
then Result
:= -1
608 else if a
.Deaths
< b
.Deaths
then Result
:= -1
609 else if a
.Deaths
> b
.Deaths
then Result
:= 1
610 else if a
.Kills
< b
.Kills
then Result
:= -1
614 procedure SortGameStat(var stat
: TPlayerStatArray
);
619 if stat
= nil then Exit
;
621 for I
:= High(stat
) downto Low(stat
) do
622 for J
:= Low(stat
) to High(stat
) - 1 do
623 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
626 stat
[J
] := stat
[J
+ 1];
631 function g_Game_ModeToText(Mode
: Byte): string;
635 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
636 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
637 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
638 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
639 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
643 function g_Game_TextToMode(Mode
: string): Byte;
646 Mode
:= UpperCase(Mode
);
647 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
652 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
657 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
662 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
667 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
674 function g_Game_IsNet(): Boolean;
676 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
679 function g_Game_IsServer(): Boolean;
681 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
684 function g_Game_IsClient(): Boolean;
686 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
689 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
696 Result
.name
:= ExtractFileName(WAD
);
697 Result
.description
:= '';
700 w
:= TWADFile
.Create();
703 if not w
.GetResource('INTERSCRIPT', p
, len
) then
709 cfg
:= TConfig
.CreateMem(p
, len
);
710 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
711 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
712 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
713 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
719 procedure g_Game_FreeWAD();
723 for a
:= 0 to High(MegaWAD
.res
.pic
) do
724 if MegaWAD
.res
.pic
[a
] <> '' then
725 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
727 for a
:= 0 to High(MegaWAD
.res
.mus
) do
728 if MegaWAD
.res
.mus
[a
] <> '' then
729 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
731 MegaWAD
.res
.pic
:= nil;
732 MegaWAD
.res
.text := nil;
733 MegaWAD
.res
.anim
:= nil;
734 MegaWAD
.res
.mus
:= nil;
735 MegaWAD
.triggers
:= nil;
737 g_Texture_Delete('TEXTURE_endpic');
738 g_Sound_Delete('MUSIC_endmus');
740 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
741 gGameSettings
.WAD
:= '';
744 procedure g_Game_LoadWAD(WAD
: string);
753 gGameSettings
.WAD
:= WAD
;
754 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
757 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
759 w
:= TWADFile
.Create();
760 w
.ReadFile(MapsDir
+ WAD
);
762 if not w
.GetResource('INTERSCRIPT', p
, len
) then
768 cfg
:= TConfig
.CreateMem(p
, len
);
773 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
774 if s = '' then Break;
777 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
778 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
780 g_Texture_CreateWADEx(s, s);
786 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
787 if s = '' then Break;
790 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
791 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
793 g_Music_CreateWADEx(s, s);
796 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
797 if MegaWAD
.endpic
<> '' then
799 s
:= g_ExtractWadName(MegaWAD
.endpic
);
800 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
801 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
803 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
804 if MegaWAD
.endmus
<> '' then
806 s
:= g_ExtractWadName(MegaWAD
.endmus
);
807 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
808 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
816 {procedure start_trigger(t: string);
820 function next_trigger(): Boolean;
824 procedure DisableCheats();
830 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
831 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
832 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
833 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
835 {$IF DEFINED(D2F_DEBUG)}
836 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
837 gAimLine
:= g_dbg_aimline_on
;
841 procedure g_Game_ExecuteEvent(Name
: String);
847 if gEvents
= nil then
849 for a
:= 0 to High(gEvents
) do
850 if gEvents
[a
].Name
= Name
then
852 if gEvents
[a
].Command
<> '' then
853 g_Console_Process(gEvents
[a
].Command
, True);
858 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
863 if gDelayedEvents
<> nil then
864 for a
:= 0 to High(gDelayedEvents
) do
865 if not gDelayedEvents
[a
].Pending
then
872 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
873 n
:= High(gDelayedEvents
);
875 gDelayedEvents
[n
].Pending
:= True;
876 gDelayedEvents
[n
].DEType
:= DEType
;
877 gDelayedEvents
[n
].DENum
:= Num
;
878 gDelayedEvents
[n
].DEStr
:= Str
;
879 if DEType
= DE_GLOBEVENT
then
880 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
882 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
891 if g_Game_IsNet
and g_Game_IsServer
then
892 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
896 gPauseHolmes
:= false;
899 g_Game_StopAllSounds(False);
904 EndingGameCounter
:= 0;
905 g_ActiveWindow
:= nil;
907 gLMSRespawn
:= LMS_RESPAWN_NONE
;
908 gLMSRespawnTime
:= 0;
911 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
916 begin // Ýòî áûë òåñò
920 begin // Âûõîä â ãëàâíîå ìåíþ
921 gMusic
.SetByName('MUSIC_MENU');
923 if gState
<> STATE_SLIST
then
925 g_GUI_ShowWindow('MainMenu');
926 gState
:= STATE_MENU
;
929 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
930 slReturnPressed
:= True;
931 if g_Net_Slist_Fetch(slCurrent
) then
933 if slCurrent
= nil then
934 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
937 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
938 g_Serverlist_GenerateTable(slCurrent
, slTable
);
941 g_Game_ExecuteEvent('ongameend');
945 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
947 if not g_Game_IsClient
then g_Game_Restart();
950 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
952 // Ñòàòèñòèêà Ñâîåé èãðû:
953 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
955 CustomStat
.GameTime
:= gTime
;
956 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
957 CustomStat
.MapName
:= gMapInfo
.Name
;
958 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
959 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
960 CustomStat
.TeamStat
:= gTeamStat
;
962 CustomStat
.PlayerStat
:= nil;
964 // Ñòàòèñòèêà èãðîêîâ:
965 if gPlayers
<> nil then
967 for a
:= 0 to High(gPlayers
) do
968 if gPlayers
[a
] <> nil then
970 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
971 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
973 Name
:= gPlayers
[a
].Name
;
974 Frags
:= gPlayers
[a
].Frags
;
975 Deaths
:= gPlayers
[a
].Death
;
976 Kills
:= gPlayers
[a
].Kills
;
977 Team
:= gPlayers
[a
].Team
;
978 Color
:= gPlayers
[a
].Model
.Color
;
979 Spectator
:= gPlayers
[a
].FSpectator
;
983 SortGameStat(CustomStat
.PlayerStat
);
986 g_Game_ExecuteEvent('onmapend');
989 EndingGameCounter
:= 255;
990 gState
:= STATE_FOLD
;
992 if gDefInterTime
< 0 then
993 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
995 gInterEndTime
:= gDefInterTime
* 1000;
998 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1000 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1001 SingleStat
.GameTime
:= gTime
;
1002 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1003 SingleStat
.TotalSecrets
:= gSecretsCount
;
1004 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1005 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1006 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1007 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1008 if SingleStat
.TwoPlayers
then
1010 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1011 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1014 g_Game_ExecuteEvent('onmapend');
1017 if gNextMap
<> '' then
1019 gMusic
.SetByName('MUSIC_INTERMUS');
1021 gState
:= STATE_INTERSINGLE
;
1024 g_Game_ExecuteEvent('oninter');
1026 else // Áîëüøå íåò êàðò
1028 // Çàòóõàþùèé ýêðàí:
1029 EndingGameCounter
:= 255;
1030 gState
:= STATE_FOLD
;
1035 // Îêîí÷àíèå îáðàáîòàíî:
1036 if gExit
<> EXIT_QUIT
then
1040 procedure drawTime(X
, Y
: Integer); inline;
1042 e_TextureFontPrint(x
, y
,
1043 Format('%d:%.2d:%.2d', [
1044 gTime
div 1000 div 3600,
1045 (gTime
div 1000 div 60) mod 60,
1046 gTime
div 1000 mod 60
1051 procedure DrawStat();
1053 pc
, x
, y
, w
, h
: Integer;
1054 w1
, w2
, w3
, w4
: Integer;
1056 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1059 stat
: TPlayerStatArray
;
1066 pc
:= g_Player_GetCount
;
1067 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1069 w
:= gScreenWidth
-(gScreenWidth
div 5);
1070 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1073 h
:= 40+ch
*5+(ch
+8)*pc
;
1074 x
:= (gScreenWidth
div 2)-(w
div 2);
1075 y
:= (gScreenHeight
div 2)-(h
div 2);
1077 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1078 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1080 drawTime(x
+w
-78, y
+8);
1082 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1083 map
:= g_ExtractFileName(gMapInfo
.Map
);
1084 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1086 case gGameSettings
.GameMode
of
1089 if gGameSettings
.MaxLives
= 0 then
1090 s1
:= _lc
[I_GAME_DM
]
1092 s1
:= _lc
[I_GAME_LMS
];
1093 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1094 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1099 if gGameSettings
.MaxLives
= 0 then
1100 s1
:= _lc
[I_GAME_TDM
]
1102 s1
:= _lc
[I_GAME_TLMS
];
1103 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1104 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1109 s1
:= _lc
[I_GAME_CTF
];
1110 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1111 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1116 if gGameSettings
.MaxLives
= 0 then
1117 s1
:= _lc
[I_GAME_COOP
]
1119 s1
:= _lc
[I_GAME_SURV
];
1120 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1121 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1132 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1134 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1136 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1138 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1139 gStdFont
, 200, 200, 200, 1);
1141 if NetMode
= NET_SERVER
then
1142 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1144 if NetMode
= NET_CLIENT
then
1145 e_TextureFontPrintEx(x
+8, y
+ 8,
1146 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1150 stat
:= g_Player_GetStats();
1153 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1154 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1156 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1158 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1162 for a
:= TEAM_RED
to TEAM_BLUE
do
1164 if a
= TEAM_RED
then
1166 s1
:= _lc
[I_GAME_TEAM_RED
];
1173 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1179 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1180 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1181 gStdFont
, r
, g
, b
, 1);
1183 _y
:= _y
+ch
+(ch
div 4);
1184 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1185 _y
:= _y
+(ch
div 4);
1187 for aa
:= 0 to High(stat
) do
1188 if stat
[aa
].Team
= a
then
1204 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1206 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1208 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1210 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1217 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1220 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1221 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1222 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1223 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1226 for aa
:= 0 to High(stat
) do
1240 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1241 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1243 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1245 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1247 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1249 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1255 procedure g_Game_Init();
1261 gTempDelete
:= False;
1263 sfsGCDisable(); // temporary disable removing of temporary volumes
1266 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1267 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1268 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1269 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1271 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1272 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1273 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1275 g_Game_ClearLoading();
1276 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1277 g_Game_SetLoadingText('', 0, False);
1279 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1282 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1283 g_PlayerModel_LoadData();
1285 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1287 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1288 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1289 until FindNext(SR
) <> 0;
1292 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1294 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1295 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1296 until FindNext(SR
) <> 0;
1299 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1301 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1302 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1303 until FindNext(SR
) <> 0;
1307 gPauseMain
:= false;
1308 gPauseHolmes
:= false;
1310 LastScreenShot
:= 0;
1312 {e_MouseInfo.Accel := 1.0;}
1314 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1317 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1318 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1319 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1320 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1321 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1323 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1326 gMusic
:= TMusic
.Create();
1327 gMusic
.SetByName('MUSIC_MENU');
1330 gGameSettings
.WarmupTime
:= 30;
1332 gState
:= STATE_MENU
;
1334 SetLength(gEvents
, 6);
1335 gEvents
[0].Name
:= 'ongamestart';
1336 gEvents
[1].Name
:= 'ongameend';
1337 gEvents
[2].Name
:= 'onmapstart';
1338 gEvents
[3].Name
:= 'onmapend';
1339 gEvents
[4].Name
:= 'oninter';
1340 gEvents
[5].Name
:= 'onwadend';
1342 sfsGCEnable(); // enable releasing unused volumes
1346 procedure g_Game_Free(freeTextures
: Boolean=true);
1348 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1349 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1351 g_Map_Free(freeTextures
);
1353 g_Player_RemoveAllCorpses();
1355 gGameSettings
.GameType
:= GT_NONE
;
1356 if gGameSettings
.GameMode
= GM_SINGLE
then
1357 gGameSettings
.GameMode
:= GM_DM
;
1358 gSwitchGameMode
:= gGameSettings
.GameMode
;
1361 gExitByTrigger
:= False;
1364 function IsActivePlayer(p
: TPlayer
): Boolean;
1369 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1372 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1379 if gPlayers
= nil then
1381 for a
:= Low(gPlayers
) to High(gPlayers
) do
1382 if IsActivePlayer(gPlayers
[a
]) then
1384 if gPlayers
[a
].UID
<> ID
then
1386 Result
:= gPlayers
[a
];
1391 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1397 if gPlayers
= nil then
1401 for a
:= Low(gPlayers
) to High(gPlayers
) do
1402 if IsActivePlayer(gPlayers
[a
]) then
1404 SetLength(ids
, Length(ids
) + 1);
1405 ids
[High(ids
)] := gPlayers
[a
].UID
;
1406 if gPlayers
[a
].UID
= Skip
then
1409 if Length(ids
) = 0 then
1414 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1417 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1423 if gPlayers
= nil then
1427 for a
:= Low(gPlayers
) to High(gPlayers
) do
1428 if IsActivePlayer(gPlayers
[a
]) then
1430 SetLength(ids
, Length(ids
) + 1);
1431 ids
[High(ids
)] := gPlayers
[a
].UID
;
1432 if gPlayers
[a
].UID
= Skip
then
1435 if Length(ids
) = 0 then
1438 Result
:= ids
[Length(ids
) - 1]
1440 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1443 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1449 if gPlayers
= nil then
1453 for a
:= Low(gPlayers
) to High(gPlayers
) do
1454 if IsActivePlayer(gPlayers
[a
]) then
1456 SetLength(ids
, Length(ids
) + 1);
1457 ids
[High(ids
)] := gPlayers
[a
].UID
;
1458 if gPlayers
[a
].UID
= Skip
then
1461 if Length(ids
) = 0 then
1463 if Length(ids
) = 1 then
1468 Result
:= ids
[Random(Length(ids
))];
1470 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1472 Result
:= ids
[Random(Length(ids
))];
1477 function GetRandomSpectMode(Current
: Byte): Byte;
1484 0: Result
:= SPECT_STATS
;
1485 1: Result
:= SPECT_MAPVIEW
;
1486 2: Result
:= SPECT_MAPVIEW
;
1487 3: Result
:= SPECT_PLAYERS
;
1488 4: Result
:= SPECT_PLAYERS
;
1489 5: Result
:= SPECT_PLAYERS
;
1490 6: Result
:= SPECT_PLAYERS
;
1492 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1496 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1498 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1499 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1503 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1509 if (plr
= nil) then exit
;
1510 if (p2hack
) then time
:= 1000 else time
:= 1;
1511 strafeDir
:= MoveButton
shr 4;
1512 MoveButton
:= MoveButton
and $0F;
1515 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1516 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1517 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1519 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1520 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1521 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1523 // if we have "strafe" key, turn off old strafe mechanics
1524 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1526 // new strafe mechanics
1527 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1528 // now set direction according to strafe (reversed)
1529 if (strafeDir
= 2) then plr
.SetDirection(TDirection
.D_LEFT
)
1530 else if (strafeDir
= 1) then plr
.SetDirection(TDirection
.D_RIGHT
);
1534 strafeDir
:= 0; // not strafing anymore
1535 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1536 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(TDirection
.D_LEFT
)
1537 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1538 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(TDirection
.D_RIGHT
)
1539 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1540 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1543 // fix movebutton state
1544 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1546 // Îñòàëüíûå êëàâèøè:
1547 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1548 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1549 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1550 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1551 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1552 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1553 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1555 for i
:= 0 to High(KeyWeapon
) do
1556 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1557 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1560 // HACK: add dynlight here
1561 if gwin_k8_enable_light_experiments
then
1563 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1565 g_playerLight
:= true;
1567 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1569 g_playerLight
:= false;
1573 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1576 procedure g_Game_Update();
1578 Msg
: g_gui
.TMessage
;
1584 function sendMonsPos (mon
: TMonster
): Boolean;
1586 result
:= false; // don't stop
1587 // this will also reset "need-send" flag
1588 if mon
.gncNeedSend
then
1590 MH_SEND_MonsterPos(mon
.UID
);
1592 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1594 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1596 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1598 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1602 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1604 result
:= false; // don't stop
1605 // this will also reset "need-send" flag
1606 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1610 reliableUpdate
: Boolean;
1615 // Ïîðà âûêëþ÷àòü èãðó:
1616 if gExit
= EXIT_QUIT
then
1618 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1622 if gExit
= EXIT_QUIT
then
1626 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1627 // no need to, as we'll do it in event handler
1629 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1632 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1634 gExit
:= EXIT_SIMPLE
;
1640 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1641 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1642 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1643 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1645 if g_Game_IsNet
and g_Game_IsServer
then
1647 gInterTime
:= gInterTime
+ GAME_TICK
;
1648 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1649 if a
<> gServInterTime
then
1651 gServInterTime
:= a
;
1652 MH_SEND_TimeSync(gServInterTime
);
1656 if (not g_Game_IsClient
) and
1660 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1661 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
)
1663 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1664 and (g_ActiveWindow
= nil)
1666 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1669 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1670 g_Game_StopAllSounds(True);
1672 if gMapOnce
then // Ýòî áûë òåñò
1673 gExit
:= EXIT_SIMPLE
1675 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1676 g_Game_ChangeMap(gNextMap
)
1677 else // Ñëåäóþùåé êàðòû íåò
1679 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1681 // Âûõîä â ãëàâíîå ìåíþ:
1683 g_GUI_ShowWindow('MainMenu');
1684 gMusic
.SetByName('MUSIC_MENU');
1686 gState
:= STATE_MENU
;
1689 // Ôèíàëüíàÿ êàðòèíêà:
1690 g_Game_ExecuteEvent('onwadend');
1692 if not gMusic
.SetByName('MUSIC_endmus') then
1693 gMusic
.SetByName('MUSIC_STDENDMUS');
1695 gState
:= STATE_ENDPIC
;
1697 g_Game_ExecuteEvent('ongameend');
1703 if gState
= STATE_INTERTEXT
then
1704 if InterText
.counter
> 0 then
1705 InterText
.counter
:= InterText
.counter
- 1;
1708 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1710 if EndingGameCounter
= 0 then
1712 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1713 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1715 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1717 g_Game_ExecuteEvent('onwadend');
1718 if not gMusic
.SetByName('MUSIC_endmus') then
1719 gMusic
.SetByName('MUSIC_STDENDMUS');
1722 gMusic
.SetByName('MUSIC_ROUNDMUS');
1725 gState
:= STATE_INTERCUSTOM
;
1728 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1730 gMusic
.SetByName('MUSIC_INTERMUS');
1732 gState
:= STATE_INTERSINGLE
;
1735 g_Game_ExecuteEvent('oninter');
1738 DecMin(EndingGameCounter
, 6, 0);
1741 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1743 if gMapOnce
then // Ýòî áûë òåñò
1745 gExit
:= EXIT_SIMPLE
;
1751 g_Serverlist_Control(slCurrent
, slTable
);
1754 if g_Game_IsNet
then
1755 if not gConsoleShow
then
1756 if not gChatShow
then
1758 if g_ActiveWindow
= nil then
1760 if e_KeyPressed(gGameControls
.GameControls
.Chat
) or e_KeyPressed(VK_CHAT
) then
1761 g_Console_Chat_Switch(False)
1762 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
) or e_KeyPressed(VK_TEAM
)) and
1763 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1764 g_Console_Chat_Switch(True);
1767 if not gChatEnter
then
1768 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1769 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
))
1770 and (not e_KeyPressed(VK_CHAT
))
1771 and (not e_KeyPressed(VK_TEAM
)) then
1774 // Ñòàòèñòèêà ïî Tab:
1776 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1777 (gGameSettings
.GameType
<> GT_SINGLE
) and
1778 (e_KeyPressed(gGameControls
.GameControls
.Stat
) or e_KeyPressed(VK_STATUS
));
1781 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1783 // Âðåìÿ += 28 ìèëëèñåêóíä:
1784 gTime
:= gTime
+ GAME_TICK
;
1786 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1787 if MessageTime
= 0 then
1789 if MessageTime
> 0 then
1790 MessageTime
:= MessageTime
- 1;
1792 if (g_Game_IsServer
) then
1794 // Áûë çàäàí ëèìèò âðåìåíè:
1795 if (gGameSettings
.TimeLimit
> 0) then
1796 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1797 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1802 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1803 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1804 g_Game_RestartRound(gLMSSoftSpawn
);
1806 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1807 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1809 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1811 g_Console_Process(gVoteCommand
);
1813 gVotePassed
:= False;
1816 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1817 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1818 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1819 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1820 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1822 // Áûë çàäàí ëèìèò ïîáåä:
1823 if (gGameSettings
.GoalLimit
> 0) then
1827 if gGameSettings
.GameMode
= GM_DM
then
1828 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1829 for i
:= 0 to High(gPlayers
) do
1830 if gPlayers
[i
] <> nil then
1831 if gPlayers
[i
].Frags
> b
then
1832 b
:= gPlayers
[i
].Frags
;
1835 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1836 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1837 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1840 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1841 if b
>= gGameSettings
.GoalLimit
then
1848 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1849 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1850 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1851 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1853 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1854 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1855 end // if not console
1858 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1860 // process weapon switch queue
1864 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1865 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1867 if not gSpectKeyPress
then
1869 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)
1870 and (not gSpectAuto
) then
1872 // switch spect mode
1874 SPECT_NONE
: ; // not spectator
1876 SPECT_MAPVIEW
: Inc(gSpectMode
);
1877 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1879 gSpectKeyPress
:= True;
1881 if (gSpectMode
= SPECT_MAPVIEW
)
1882 and (not gSpectAuto
) then
1884 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1885 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1886 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1887 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1888 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1889 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1890 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1891 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1892 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1895 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1896 gSpectKeyPress
:= True;
1898 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1901 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1902 gSpectKeyPress
:= True;
1905 if (gSpectMode
= SPECT_PLAYERS
)
1906 and (not gSpectAuto
) then
1908 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1911 gSpectViewTwo
:= True;
1912 gSpectKeyPress
:= True;
1914 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1916 // remove second view
1917 gSpectViewTwo
:= False;
1918 gSpectKeyPress
:= True;
1920 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1922 // prev player (view 1)
1923 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1924 gSpectKeyPress
:= True;
1926 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1928 // next player (view 1)
1929 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1930 gSpectKeyPress
:= True;
1932 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1934 // prev player (view 2)
1935 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1936 gSpectKeyPress
:= True;
1938 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1940 // next player (view 2)
1941 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1942 gSpectKeyPress
:= True;
1945 if isKeyPressed(gGameControls
.P1Control
.KeyFire
, gGameControls
.P1Control
.KeyFire2
) then
1947 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1950 gSpectAutoNext
:= 0;
1951 gSpectViewTwo
:= False;
1952 gSpectKeyPress
:= True;
1957 gSpectMode
:= SPECT_STATS
;
1958 gSpectAuto
:= False;
1959 gSpectKeyPress
:= True;
1964 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1965 (not isKeyPressed(gGameControls
.P1Control
.KeyFire
, gGameControls
.P1Control
.KeyFire2
)) and
1966 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1967 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1968 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1969 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1970 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1971 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1972 gSpectKeyPress
:= False;
1976 if gSpectMode
= SPECT_MAPVIEW
then
1978 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
1980 gSpectAutoNext
:= gTime
1983 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
1985 gSpectAutoNext
:= gTime
1989 if gSpectAutoNext
<= gTime
then
1991 if gSpectAutoNext
> 0 then
1993 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
1997 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
1998 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
1999 gSpectAutoStepX
:= Random(9) - 4;
2000 gSpectAutoStepY
:= Random(9) - 4;
2001 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2002 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2003 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2004 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2005 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2006 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2010 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2015 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2016 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2017 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2023 // Îáíîâëÿåì âñå îñòàëüíîå:
2026 g_Triggers_Update();
2028 g_Monsters_Update();
2030 g_Player_UpdateAll();
2031 g_Player_UpdatePhysicalObjects();
2033 // server: send newly spawned monsters unconditionally
2034 if (gGameSettings
.GameType
= GT_SERVER
) then
2036 if (Length(gMonstersSpawned
) > 0) then
2038 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2039 SetLength(gMonstersSpawned
, 0);
2043 if (gSoundTriggerTime
> 8) then
2045 g_Game_UpdateTriggerSounds();
2046 gSoundTriggerTime
:= 0;
2050 Inc(gSoundTriggerTime
);
2053 if (NetMode
= NET_SERVER
) then
2055 Inc(NetTimeToUpdate
);
2056 Inc(NetTimeToReliable
);
2058 // send monster updates
2059 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2061 // send all monsters (periodic sync)
2062 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2064 for I
:= 0 to High(gPlayers
) do
2066 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2069 g_Mons_ForEach(sendMonsPos
);
2071 if reliableUpdate
then
2073 NetTimeToReliable
:= 0;
2074 NetTimeToUpdate
:= NetUpdateRate
;
2078 NetTimeToUpdate
:= 0;
2083 // send only mosters with some unexpected changes
2084 g_Mons_ForEach(sendMonsPosUnexpected
);
2087 // send unexpected platform changes
2088 g_Map_NetSendInterestingPanels();
2090 if NetUseMaster
then
2092 if gTime
>= NetTimeToMaster
then
2094 if (NetMHost
= nil) or (NetMPeer
= nil) then
2096 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
2100 NetTimeToMaster
:= gTime
+ NetMasterRate
;
2104 else if (NetMode
= NET_CLIENT
) then
2106 MC_SEND_PlayerPos();
2108 end; // if gameOn ...
2110 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2111 if g_ActiveWindow
<> nil then
2113 w
:= e_GetFirstKeyPressed();
2115 if (w
<> IK_INVALID
) then
2117 Msg
.Msg
:= MESSAGE_DIKEY
;
2119 g_ActiveWindow
.OnMessage(Msg
);
2122 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2123 if g_ActiveWindow
<> nil then
2124 g_ActiveWindow
.Update();
2126 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2127 if gResolutionChange
then
2129 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2130 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2131 gResolutionChange
:= False;
2132 g_ActiveWindow
:= nil;
2135 // Íóæíî ñìåíèòü ÿçûê:
2136 if gLanguageChange
then
2138 //e_WriteLog('Read language file', MSG_NOTIFY);
2139 //g_Language_Load(DataDir + gLanguage + '.txt');
2140 g_Language_Set(gLanguage
);
2142 gLanguageChange
:= False;
2146 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
2147 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) or e_KeyPressed(VK_PRINTSCR
) then
2148 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
2151 LastScreenShot
:= GetTimer();
2154 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2155 if e_KeyPressed(IK_F10
) and
2157 (not gConsoleShow
) and
2158 (g_ActiveWindow
= nil) then
2163 Time
:= GetTimer() {div 1000};
2165 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2166 if gDelayedEvents
<> nil then
2167 for a
:= 0 to High(gDelayedEvents
) do
2168 if gDelayedEvents
[a
].Pending
and
2170 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2171 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2174 case gDelayedEvents
[a
].DEType
of
2176 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2179 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2183 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2184 if g_Game_IsNet
and g_Game_IsServer
then
2185 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2188 gDelayedEvents
[a
].Pending
:= False;
2191 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2192 UPSCounter
:= UPSCounter
+ 1;
2193 if Time
- UPSTime
>= 1000 then
2202 g_Weapon_AddDynLights();
2203 g_Items_AddDynLights();
2207 procedure g_Game_LoadChatSounds(Resource
: string);
2210 FileName
, Snd
: string;
2212 len
, cnt
, tags
, i
, j
: Integer;
2215 FileName
:= g_ExtractWadName(Resource
);
2217 WAD
:= TWADFile
.Create();
2218 WAD
.ReadFile(FileName
);
2220 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2227 cfg
:= TConfig
.CreateMem(p
, len
);
2228 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2230 SetLength(gChatSounds
, cnt
);
2231 for i
:= 0 to Length(gChatSounds
) - 1 do
2233 gChatSounds
[i
].Sound
:= nil;
2234 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2235 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2236 if (Snd
= '') or (Tags
<= 0) then
2238 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2239 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2240 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2241 SetLength(gChatSounds
[i
].Tags
, tags
);
2242 for j
:= 0 to tags
- 1 do
2243 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2244 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2251 procedure g_Game_FreeChatSounds();
2255 for i
:= 0 to Length(gChatSounds
) - 1 do
2257 gChatSounds
[i
].Sound
.Free();
2258 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2260 SetLength(gChatSounds
, 0);
2264 procedure g_Game_LoadData();
2271 if DataLoaded
then Exit
;
2273 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2275 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2276 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2277 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2278 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2279 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2280 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2281 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2282 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2283 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2284 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2285 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2286 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2287 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2288 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2291 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2292 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2293 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2294 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2298 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2299 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2300 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2301 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2302 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
2308 hasPBarGfx
:= false;
2312 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2313 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2314 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2315 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2316 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2317 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2318 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2319 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2320 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2321 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2322 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2323 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2324 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2325 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2326 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2327 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2328 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2329 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2330 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2331 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2332 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2333 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2334 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2335 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2336 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2337 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2339 goodsnd
[0] := TPlayableSound
.Create();
2340 goodsnd
[1] := TPlayableSound
.Create();
2341 goodsnd
[2] := TPlayableSound
.Create();
2342 goodsnd
[3] := TPlayableSound
.Create();
2344 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2345 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2346 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2347 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2349 killsnd
[0] := TPlayableSound
.Create();
2350 killsnd
[1] := TPlayableSound
.Create();
2351 killsnd
[2] := TPlayableSound
.Create();
2352 killsnd
[3] := TPlayableSound
.Create();
2354 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2355 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2356 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2357 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2359 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2361 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2364 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2365 g_Weapon_LoadData();
2367 g_Monsters_LoadData();
2372 procedure g_Game_FreeData();
2374 if not DataLoaded
then Exit
;
2377 g_Weapon_FreeData();
2378 g_Monsters_FreeData();
2380 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2382 g_Texture_Delete('NOTEXTURE');
2383 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2384 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2385 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2386 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2387 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2388 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2389 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2390 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2391 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2392 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2393 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2394 g_Frames_DeleteByName('FRAMES_TELEPORT');
2395 g_Frames_DeleteByName('FRAMES_PUNCH');
2396 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2397 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2398 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2399 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2400 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2401 g_Sound_Delete('SOUND_GAME_TELEPORT');
2402 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2403 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2404 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2405 g_Sound_Delete('SOUND_GAME_BULK1');
2406 g_Sound_Delete('SOUND_GAME_BULK2');
2407 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2408 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2409 g_Sound_Delete('SOUND_GAME_SWITCH1');
2410 g_Sound_Delete('SOUND_GAME_SWITCH0');
2417 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2418 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2419 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2420 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2427 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2428 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2429 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2430 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2432 g_Game_FreeChatSounds();
2434 DataLoaded
:= False;
2437 procedure DrawCustomStat();
2443 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2444 s1
, s2
, topstr
: String;
2446 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2448 g_ProcessMessages();
2450 if e_KeyPressed(IK_TAB
) or e_KeyPressed(VK_STATUS
) then
2452 if not gStatsPressed
then
2454 gStatsOff
:= not gStatsOff
;
2455 gStatsPressed
:= True;
2459 gStatsPressed
:= False;
2463 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2464 w
:= (Length(s1
) * ww2
) div 2;
2465 x
:= gScreenWidth
div 2 - w
;
2467 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2471 if (gGameSettings
.GameMode
= GM_COOP
) then
2473 if gMissionFailed
then
2474 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2476 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2479 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2481 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2482 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2484 if g_Game_IsNet
then
2486 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2487 if not gChatShow
then
2488 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2489 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2492 if g_Game_IsClient
then
2493 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2495 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2496 if not gChatShow
then
2497 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2498 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2503 w
:= gScreenWidth
-x
*2;
2509 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2510 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2512 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2514 case CustomStat
.GameMode
of
2517 if gGameSettings
.MaxLives
= 0 then
2518 s1
:= _lc
[I_GAME_DM
]
2520 s1
:= _lc
[I_GAME_LMS
];
2524 if gGameSettings
.MaxLives
= 0 then
2525 s1
:= _lc
[I_GAME_TDM
]
2527 s1
:= _lc
[I_GAME_TLMS
];
2529 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2532 if gGameSettings
.MaxLives
= 0 then
2533 s1
:= _lc
[I_GAME_COOP
]
2535 s1
:= _lc
[I_GAME_SURV
];
2541 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2545 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2546 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2549 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2550 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2551 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2552 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2554 pc
:= Length(CustomStat
.PlayerStat
);
2555 if pc
= 0 then Exit
;
2557 if CustomStat
.GameMode
= GM_COOP
then
2559 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2561 s2
:= _lc
[I_GAME_MONSTERS
];
2562 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2563 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2565 s2
:= _lc
[I_GAME_SECRETS
];
2566 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2567 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2570 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2572 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2573 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2574 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2576 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2577 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2578 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2582 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2587 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2588 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2589 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2591 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2594 for t
:= TEAM_RED
to TEAM_BLUE
do
2596 if t
= TEAM_RED
then
2598 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2599 gStdFont
, 255, 0, 0, 1);
2600 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2601 gStdFont
, 255, 0, 0, 1);
2608 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2609 gStdFont
, 0, 0, 255, 1);
2610 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2611 gStdFont
, 0, 0, 255, 1);
2617 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2620 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2621 if CustomStat
.PlayerStat
[p
].Team
= t
then
2622 with CustomStat
.PlayerStat
[p
] do
2636 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2637 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2638 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2645 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2648 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2649 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2650 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2653 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2654 with CustomStat
.PlayerStat
[p
] do
2656 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2663 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2664 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2665 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2671 procedure DrawSingleStat();
2673 tm
, key_x
, val_x
, y
: Integer;
2677 procedure player_stat(n
: Integer);
2683 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2684 s2
:= Format(' %d', [gTotalMonsters
]);
2686 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2687 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2688 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2689 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2691 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2692 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2694 // "Kills-per-minute: ##.#":
2695 s1
:= _lc
[I_MENU_INTER_KPM
];
2697 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2699 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2700 s2
:= Format(' %.1f', [kpm
]);
2702 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2703 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2705 // "Secrets found: # / #":
2706 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2707 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2709 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2710 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2711 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2712 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2714 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2715 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2719 // "Level Complete":
2720 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2721 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2723 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2724 s1
:= _lc
[I_MENU_INTER_KPM
];
2725 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2728 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2730 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2731 val_x
:= key_x
+ w1
;
2734 tm
:= SingleStat
.GameTime
div 1000;
2735 s1
:= _lc
[I_MENU_INTER_TIME
];
2736 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2738 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2739 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2741 if SingleStat
.TwoPlayers
then
2744 s1
:= _lc
[I_MENU_PLAYER_1
];
2745 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2746 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2748 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2753 s1
:= _lc
[I_MENU_PLAYER_2
];
2754 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2755 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2757 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2763 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2769 procedure DrawLoadingStat();
2770 procedure drawRect (x
, y
, w
, h
: Integer);
2772 if (w
< 1) or (h
< 1) then exit
;
2774 glVertex2f(x
+0.375, y
+0.375);
2775 glVertex2f(x
+w
+0.375, y
+0.375);
2776 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2777 glVertex2f(x
+0.375, y
+h
+0.375);
2781 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2783 rectW
, rectH
: Integer;
2790 idl
, idr
, idb
, idm
: LongWord;
2794 if (total
< 1) then exit
;
2795 if (cur
< 1) then exit
; // don't blink
2796 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2797 //if (cur < 0) then cur := 0;
2798 //if (cur > total) then cur := total;
2801 if (hasPBarGfx
) then
2803 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2804 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2805 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2806 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2807 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2808 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2809 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2810 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2812 //rectW := gScreenWidth-360;
2813 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2816 x0
:= (gScreenWidth
-rectW
) div 2;
2817 y0
:= gScreenHeight
-rectH
-64;
2818 if (y0
< 2) then y0
:= 2;
2820 glEnable(GL_SCISSOR_TEST
);
2823 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2824 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2825 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2828 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2830 while (f
< x0
+rectW
) do
2832 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2837 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2838 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2841 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2842 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2846 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2852 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2856 rectW
:= gScreenWidth
-64;
2859 x0
:= (gScreenWidth
-rectW
) div 2;
2860 y0
:= gScreenHeight
-rectH
-64;
2861 if (y0
< 2) then y0
:= 2;
2863 glDisable(GL_BLEND
);
2864 glDisable(GL_TEXTURE_2D
);
2866 //glClearColor(0, 0, 0, 0);
2867 //glClear(GL_COLOR_BUFFER_BIT);
2869 glColor4ub(127, 127, 127, 255);
2870 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2872 glColor4ub(0, 0, 0, 255);
2873 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2875 glColor4ub(127, 127, 127, 255);
2876 wdt
:= rectW
*cur
div total
;
2877 if (wdt
> rectW
) then wdt
:= rectW
;
2878 drawRect(x0
, y0
, wdt
, rectH
);
2887 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2889 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2890 yy
:= (gScreenHeight
div 3);
2891 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2892 xx
:= (gScreenWidth
div 3);
2896 for i
:= 0 to NextMsg
-1 do
2898 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2899 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2903 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2904 yy
:= yy
+ LOADING_INTERLINE
;
2905 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2910 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2912 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2914 function monDraw (mon
: TMonster
): Boolean;
2916 result
:= false; // don't stop
2921 // Ëåâûé âåðõíèé óãîë
2922 aX
:= Obj
.X
div ScaleSz
+ 1;
2923 aY
:= Obj
.Y
div ScaleSz
+ 1;
2925 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2926 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2927 // Ïðàâûé íèæíèé óãîë
2928 aX2
:= aX
+ aX2
- 1;
2929 aY2
:= aY
+ aY2
- 1;
2930 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2936 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2937 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2940 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2941 ScaleSz
:= 16 div Scale
;
2942 // Ðàçìåðû ìèíè-êàðòû:
2943 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2944 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2946 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2948 if gWalls
<> nil then
2951 for a
:= 0 to High(gWalls
) do
2953 if PanelType
<> 0 then
2955 // Ëåâûé âåðõíèé óãîë:
2956 aX
:= X
div ScaleSz
;
2957 aY
:= Y
div ScaleSz
;
2959 aX2
:= max(Width
div ScaleSz
, 1);
2960 aY2
:= max(Height
div ScaleSz
, 1);
2961 // Ïðàâûé íèæíèé óãîë:
2962 aX2
:= aX
+ aX2
- 1;
2963 aY2
:= aY
+ aY2
- 1;
2966 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2967 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2968 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2972 if gSteps
<> nil then
2975 for a
:= 0 to High(gSteps
) do
2977 if PanelType
<> 0 then
2979 // Ëåâûé âåðõíèé óãîë:
2980 aX
:= X
div ScaleSz
;
2981 aY
:= Y
div ScaleSz
;
2983 aX2
:= max(Width
div ScaleSz
, 1);
2984 aY2
:= max(Height
div ScaleSz
, 1);
2985 // Ïðàâûé íèæíèé óãîë:
2986 aX2
:= aX
+ aX2
- 1;
2987 aY2
:= aY
+ aY2
- 1;
2989 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2992 if gLifts
<> nil then
2995 for a
:= 0 to High(gLifts
) do
2997 if PanelType
<> 0 then
2999 // Ëåâûé âåðõíèé óãîë:
3000 aX
:= X
div ScaleSz
;
3001 aY
:= Y
div ScaleSz
;
3003 aX2
:= max(Width
div ScaleSz
, 1);
3004 aY2
:= max(Height
div ScaleSz
, 1);
3005 // Ïðàâûé íèæíèé óãîë:
3006 aX2
:= aX
+ aX2
- 1;
3007 aY2
:= aY
+ aY2
- 1;
3010 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3011 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3012 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3013 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3017 if gWater
<> nil then
3020 for a
:= 0 to High(gWater
) do
3022 if PanelType
<> 0 then
3024 // Ëåâûé âåðõíèé óãîë:
3025 aX
:= X
div ScaleSz
;
3026 aY
:= Y
div ScaleSz
;
3028 aX2
:= max(Width
div ScaleSz
, 1);
3029 aY2
:= max(Height
div ScaleSz
, 1);
3030 // Ïðàâûé íèæíèé óãîë:
3031 aX2
:= aX
+ aX2
- 1;
3032 aY2
:= aY
+ aY2
- 1;
3034 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3037 if gAcid1
<> nil then
3039 // Ðèñóåì êèñëîòó 1:
3040 for a
:= 0 to High(gAcid1
) do
3042 if PanelType
<> 0 then
3044 // Ëåâûé âåðõíèé óãîë:
3045 aX
:= X
div ScaleSz
;
3046 aY
:= Y
div ScaleSz
;
3048 aX2
:= max(Width
div ScaleSz
, 1);
3049 aY2
:= max(Height
div ScaleSz
, 1);
3050 // Ïðàâûé íèæíèé óãîë:
3051 aX2
:= aX
+ aX2
- 1;
3052 aY2
:= aY
+ aY2
- 1;
3054 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3057 if gAcid2
<> nil then
3059 // Ðèñóåì êèñëîòó 2:
3060 for a
:= 0 to High(gAcid2
) do
3062 if PanelType
<> 0 then
3064 // Ëåâûé âåðõíèé óãîë:
3065 aX
:= X
div ScaleSz
;
3066 aY
:= Y
div ScaleSz
;
3068 aX2
:= max(Width
div ScaleSz
, 1);
3069 aY2
:= max(Height
div ScaleSz
, 1);
3070 // Ïðàâûé íèæíèé óãîë:
3071 aX2
:= aX
+ aX2
- 1;
3072 aY2
:= aY
+ aY2
- 1;
3074 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3077 if gPlayers
<> nil then
3080 for a
:= 0 to High(gPlayers
) do
3081 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3083 // Ëåâûé âåðõíèé óãîë:
3084 aX
:= Obj
.X
div ScaleSz
+ 1;
3085 aY
:= Obj
.Y
div ScaleSz
+ 1;
3087 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3088 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3089 // Ïðàâûé íèæíèé óãîë:
3090 aX2
:= aX
+ aX2
- 1;
3091 aY2
:= aY
+ aY2
- 1;
3093 if gPlayers
[a
] = p
then
3094 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3097 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3098 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3099 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3104 g_Mons_ForEach(monDraw
);
3109 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3111 if not hasAmbient
then exit
;
3112 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3116 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3117 //FIXME: broken for splitscreen mode
3118 procedure renderDynLightsInternal ();
3120 //hasAmbient: Boolean;
3121 //ambColor: TDFColor;
3123 lx
, ly
, lrad
: Integer;
3124 scxywh
: array[0..3] of GLint
;
3127 if e_NoGraphics
then exit
;
3129 //TODO: lights should be in separate grid, i think
3130 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3131 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3134 //ambColor := gCurrentMap['light_ambient'].rgba;
3135 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3137 { // this will multiply incoming color to alpha from framebuffer
3139 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3143 * light rendering: (INVALID!)
3144 * glStencilFunc(GL_EQUAL, 0, $ff);
3146 * glClear(GL_STENCIL_BUFFER_BIT);
3147 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3148 * draw shadow volume into stencil buffer
3149 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3150 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3152 * draw color-less quad with light alpha (WARNING! don't touch color!)
3153 * glEnable(GL_BLEND);
3154 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3155 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3157 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3158 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3160 // setup OpenGL parameters
3161 glStencilMask($FFFFFFFF);
3162 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3163 glEnable(GL_STENCIL_TEST
);
3164 glEnable(GL_SCISSOR_TEST
);
3165 glClear(GL_STENCIL_BUFFER_BIT
);
3166 glStencilFunc(GL_EQUAL
, 0, $ff);
3168 for lln
:= 0 to g_dynLightCount
-1 do
3170 lx
:= g_dynLights
[lln
].x
;
3171 ly
:= g_dynLights
[lln
].y
;
3172 lrad
:= g_dynLights
[lln
].radius
;
3173 if (lrad
< 3) then continue
;
3175 if (lx
-sX
+lrad
< 0) then continue
;
3176 if (ly
-sY
+lrad
< 0) then continue
;
3177 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3178 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3180 // set scissor to optimize drawing
3181 if (g_dbg_scale
= 1.0) then
3183 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3187 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3189 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3190 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3191 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3192 // draw extruded panels
3193 glDisable(GL_TEXTURE_2D
);
3194 glDisable(GL_BLEND
);
3195 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3196 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3197 // render light texture
3198 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3199 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3202 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3203 glEnable(GL_TEXTURE_2D
);
3204 // color and opacity
3205 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3206 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3208 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3209 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3210 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3211 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3216 glDisable(GL_STENCIL_TEST
);
3217 glDisable(GL_BLEND
);
3218 glDisable(GL_SCISSOR_TEST
);
3219 //glScissor(0, 0, sWidth, sHeight);
3221 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3222 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3226 function fixViewportForScale (): Boolean;
3228 nx0
, ny0
, nw
, nh
: Integer;
3231 if (g_dbg_scale
<> 1.0) then
3234 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3235 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3236 nw
:= round(sWidth
/g_dbg_scale
);
3237 nh
:= round(sHeight
/g_dbg_scale
);
3246 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3247 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3248 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3250 TDrawCB
= procedure ();
3253 hasAmbient
: Boolean;
3255 doAmbient
: Boolean = false;
3257 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3262 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3263 if gdbg_map_use_accel_render
then
3265 tagmask
:= panelTypeToTag(panType
);
3266 while (gDrawPanelList
.count
> 0) do
3268 pan
:= TPanel(gDrawPanelList
.front());
3269 if ((pan
.tag
and tagmask
) = 0) then break
;
3270 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3271 gDrawPanelList
.popFront();
3276 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3278 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3281 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3283 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3284 if assigned(cb
) then cb();
3285 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3289 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3291 // our accelerated renderer will collect all panels to gDrawPanelList
3292 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3293 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3294 if gdbg_map_use_accel_render
then
3296 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3298 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3300 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3301 g_Map_DrawBack(backXOfs
, backYOfs
);
3302 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3304 if setTransMatrix
then
3306 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3307 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3308 glTranslatef(-sX
, -sY
, 0);
3312 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3313 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3318 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3319 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3320 glClear(GL_COLOR_BUFFER_BIT);
3323 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3326 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3327 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3328 drawOther('items', @g_Items_Draw
);
3329 drawOther('weapons', @g_Weapon_Draw
);
3330 drawOther('shells', @g_Player_DrawShells
);
3331 drawOther('drawall', @g_Player_DrawAll
);
3332 drawOther('corpses', @g_Player_DrawCorpses
);
3333 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3334 drawOther('monsters', @g_Monsters_Draw
);
3335 drawOther('itemdrop', @g_Items_DrawDrop
);
3336 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3337 drawOther('gfx', @g_GFX_Draw
);
3338 drawOther('flags', @g_Map_DrawFlags
);
3339 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3340 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3341 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3342 drawOther('dynlights', @renderDynLightsInternal
);
3344 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3346 renderAmbientQuad(hasAmbient
, ambColor
);
3350 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3353 if g_debug_HealthBar
then
3355 g_Monsters_DrawHealth();
3356 g_Player_DrawHealth();
3359 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3363 procedure DrawMapView(x
, y
, w
, h
: Integer);
3370 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3371 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3378 fixViewportForScale();
3379 renderMapInternal(-bx
, -by
, true);
3385 procedure DrawPlayer(p
: TPlayer
);
3387 px
, py
, a
, b
, c
, d
: Integer;
3390 if (p
= nil) or (p
.FDummy
) then
3393 g_Map_DrawBack(0, 0);
3398 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3399 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3405 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3406 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3408 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3410 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3411 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3413 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3414 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3416 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3417 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3420 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3423 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3424 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3427 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3432 // scaled, ignore level bounds
3433 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3434 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3437 if p
.IncCam
<> 0 then
3439 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3441 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3443 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3447 if py
< gPlayerScreenSize
.Y
div 2 then
3449 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3451 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3455 if p
.IncCam
< 0 then
3457 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3460 if p
.IncCam
> 0 then
3462 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3466 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3467 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3468 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3470 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3471 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3472 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3475 sY
:= -(b
+p
.IncCam
);
3476 sWidth
:= gPlayerScreenSize
.X
;
3477 sHeight
:= gPlayerScreenSize
.Y
;
3479 //glTranslatef(a, b+p.IncCam, 0);
3481 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3483 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3484 fixViewportForScale();
3485 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3487 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3489 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3490 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3491 if (sX
< 0) then sX
:= 0;
3492 if (sY
< 0) then sY
:= 0;
3494 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3495 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3498 //r_smallmap_h: 0: left; 1: center; 2: right
3499 //r_smallmap_v: 0: top; 1: center; 2: bottom
3501 if (gMapInfo
.Width
= sWidth
) then
3505 else if (gMapInfo
.Width
< sWidth
) then
3507 case r_smallmap_h
of
3508 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3509 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3510 else sX
:= 0; // left
3514 if (gMapInfo
.Height
= sHeight
) then
3518 else if (gMapInfo
.Height
< sHeight
) then
3520 case r_smallmap_v
of
3521 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3522 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3523 else sY
:= 0; // top
3529 p
.viewPortW
:= sWidth
;
3530 p
.viewPortH
:= sHeight
;
3532 {$IFDEF ENABLE_HOLMES}
3533 if (p
= gPlayer1
) then
3535 g_Holmes_plrViewPos(sX
, sY
);
3536 g_Holmes_plrViewSize(sWidth
, sHeight
);
3540 renderMapInternal(-c
, -d
, true);
3542 if p
.FSpectator
then
3543 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3544 p
.GameY
+ PLAYER_RECT_CY
- 4,
3545 'X', gStdFont
, 255, 255, 255, 1, True);
3547 for a := 0 to High(gCollideMap) do
3548 for b := 0 to High(gCollideMap[a]) do
3551 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3553 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3557 1: e_DrawPoint(1, b, a, 200, 200, 200);
3558 2: e_DrawPoint(1, b, a, 64, 64, 255);
3559 3: e_DrawPoint(1, b, a, 255, 0, 255);
3569 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3570 if g_Debug_Player
then
3571 g_Player_DrawDebug(p
);
3575 procedure drawProfilers ();
3580 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3581 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3582 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3585 procedure g_Game_Draw();
3592 plView1
, plView2
: TPlayer
;
3595 if gExit
= EXIT_QUIT
then Exit
;
3597 Time
:= GetTimer() {div 1000};
3598 FPSCounter
:= FPSCounter
+1;
3599 if Time
- FPSTime
>= 1000 then
3606 if gGameOn
or (gState
= STATE_FOLD
) then
3608 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3610 gSpectMode
:= SPECT_NONE
;
3611 if not gRevertPlayers
then
3613 plView1
:= gPlayer1
;
3614 plView2
:= gPlayer2
;
3618 plView1
:= gPlayer2
;
3619 plView2
:= gPlayer1
;
3623 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3625 gSpectMode
:= SPECT_NONE
;
3626 if gPlayer2
= nil then
3629 plView1
:= gPlayer2
;
3638 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3639 gSpectMode
:= SPECT_STATS
;
3641 if gSpectMode
= SPECT_PLAYERS
then
3642 if gPlayers
<> nil then
3644 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3645 if plView1
= nil then
3647 gSpectPID1
:= GetActivePlayerID_Next();
3648 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3650 if gSpectViewTwo
then
3652 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3653 if plView2
= nil then
3655 gSpectPID2
:= GetActivePlayerID_Next();
3656 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3661 if gSpectMode
= SPECT_MAPVIEW
then
3663 // Ðåæèì ïðîñìîòðà êàðòû
3665 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3666 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3667 gHearPoint1
.Active
:= True;
3668 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3669 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3670 gHearPoint2
.Active
:= False;
3674 Split
:= (plView1
<> nil) and (plView2
<> nil);
3676 // Òî÷êè ñëóõà èãðîêîâ
3677 if plView1
<> nil then
3679 gHearPoint1
.Active
:= True;
3680 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3681 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3683 gHearPoint1
.Active
:= False;
3684 if plView2
<> nil then
3686 gHearPoint2
.Active
:= True;
3687 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3688 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3690 gHearPoint2
.Active
:= False;
3692 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3693 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3696 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3697 if gScreenHeight
mod 2 = 0 then
3698 Dec(gPlayerScreenSize
.Y
);
3701 gPlayerScreenSize
.Y
:= gScreenHeight
;
3704 if gScreenHeight
mod 2 = 0 then
3705 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3707 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3709 DrawPlayer(plView1
);
3710 gPlayer1ScreenCoord
.X
:= sX
;
3711 gPlayer1ScreenCoord
.Y
:= sY
;
3715 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3717 DrawPlayer(plView2
);
3718 gPlayer2ScreenCoord
.X
:= sX
;
3719 gPlayer2ScreenCoord
.Y
:= sY
;
3722 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3725 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3728 {$IFDEF ENABLE_HOLMES}
3730 if (g_holmes_enabled
) then g_Holmes_Draw();
3733 if MessageText
<> '' then
3737 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3739 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3740 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3742 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3743 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3746 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3748 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3750 // Draw spectator GUI
3753 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3756 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3758 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3760 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3762 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3763 if gSpectMode
= SPECT_STATS
then
3765 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3766 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
3768 if gSpectMode
= SPECT_MAPVIEW
then
3770 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3771 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3772 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3773 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3774 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3776 if gSpectMode
= SPECT_PLAYERS
then
3778 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3779 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3780 if gSpectViewTwo
then
3782 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3783 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3784 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3785 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3789 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3790 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3796 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3798 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3799 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3801 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3802 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3803 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3808 if (gState
= STATE_MENU
) then
3810 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3812 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3813 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3815 // F3 at menu will show game loading dialog
3816 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3817 if (g_ActiveWindow
<> nil) then
3819 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3820 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3824 // F3 at titlepic will show game loading dialog
3825 if e_KeyPressed(IK_F3
) then
3827 g_Menu_Show_LoadMenu(true);
3828 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3833 if gState
= STATE_FOLD
then
3835 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3838 if gState
= STATE_INTERCUSTOM
then
3840 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3842 back
:= 'TEXTURE_endpic';
3843 if not g_Texture_Get(back
, ID
) then
3844 back
:= _lc
[I_TEXTURE_ENDPIC
];
3849 if g_Texture_Get(back
, ID
) then
3850 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3852 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3856 if g_ActiveWindow
<> nil then
3858 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3859 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3863 if gState
= STATE_INTERSINGLE
then
3865 if EndingGameCounter
> 0 then
3867 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3873 if g_Texture_Get(back
, ID
) then
3874 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3876 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3880 if g_ActiveWindow
<> nil then
3882 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3883 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3888 if gState
= STATE_ENDPIC
then
3891 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3892 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3894 if ID
<> DWORD(-1) then
3895 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3897 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3899 if g_ActiveWindow
<> nil then
3901 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3902 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3906 if gState
= STATE_SLIST
then
3908 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3910 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3911 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3912 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3914 g_Serverlist_Draw(slCurrent
, slTable
);
3918 if g_ActiveWindow
<> nil then
3922 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3923 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3925 g_ActiveWindow
.Draw();
3930 if g_debug_Sounds
and gGameOn
then
3932 for w
:= 0 to High(e_SoundsArray
) do
3933 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3934 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3939 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3940 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3943 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3944 drawTime(gScreenWidth
-72, gScreenHeight
-16);
3946 if gGameOn
then drawProfilers();
3948 {$IFDEF ENABLE_HOLMES}
3955 procedure g_Game_Quit();
3957 g_Game_StopAllSounds(True);
3959 g_Game_SaveOptions();
3961 g_PlayerModel_FreeData();
3962 g_Texture_DeleteAll();
3963 g_Frames_DeleteAll();
3964 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
3966 if NetInitDone
then g_Net_Free
;
3968 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3969 if gMapToDelete
<> '' then
3970 g_Game_DeleteTestMap();
3976 procedure g_FatalError(Text: String);
3978 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3979 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
3981 gExit
:= EXIT_SIMPLE
;
3984 procedure g_SimpleError(Text: String);
3986 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3987 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
3990 procedure g_Game_SetupScreenSize();
3992 RES_FACTOR
= 4.0 / 3.0;
3998 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3999 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4000 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4001 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4003 gPlayerScreenSize
.Y
:= gScreenHeight
;
4005 // Ðàçìåð çàäíåãî ïëàíà:
4006 if BackID
<> DWORD(-1) then
4009 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4010 (gScreenHeight
*s
> gMapInfo
.Height
) then
4012 gBackSize
.X
:= gScreenWidth
;
4013 gBackSize
.Y
:= gScreenHeight
;
4017 e_GetTextureSize(BackID
, @bw
, @bh
);
4018 rf
:= Single(bw
) / Single(bh
);
4019 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4020 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4021 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4022 if (s
< 1.0) then s
:= 1.0;
4023 gBackSize
.X
:= Round(bw
*s
);
4024 gBackSize
.Y
:= Round(bh
*s
);
4029 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4031 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
4034 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4036 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4037 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4039 if gPlayer1
= nil then
4041 if g_Game_IsClient
then
4043 if NetPlrUID1
> -1 then
4045 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4046 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4051 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4052 Team
:= gPlayer1Settings
.Team
;
4054 // Ñîçäàíèå ïåðâîãî èãðîêà:
4055 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4056 gPlayer1Settings
.Color
,
4058 if gPlayer1
= nil then
4059 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4062 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4063 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4064 if g_Game_IsServer
and g_Game_IsNet
then
4065 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4066 gPlayer1
.Respawn(False, True);
4068 if g_Game_IsNet
and NetUseMaster
then
4074 if gPlayer2
= nil then
4076 if g_Game_IsClient
then
4078 if NetPlrUID2
> -1 then
4079 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4083 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4084 Team
:= gPlayer2Settings
.Team
;
4086 // Ñîçäàíèå âòîðîãî èãðîêà:
4087 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4088 gPlayer2Settings
.Color
,
4090 if gPlayer2
= nil then
4091 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4094 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4095 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4096 if g_Game_IsServer
and g_Game_IsNet
then
4097 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4098 gPlayer2
.Respawn(False, True);
4100 if g_Game_IsNet
and NetUseMaster
then
4108 procedure g_Game_RemovePlayer();
4112 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4113 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4118 if g_Game_IsServer
then
4121 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4122 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4123 g_Player_Remove(Pl
.UID
);
4125 if g_Game_IsNet
and NetUseMaster
then
4134 if g_Game_IsServer
then
4137 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4138 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4139 g_Player_Remove(Pl
.UID
);
4141 if g_Game_IsNet
and NetUseMaster
then
4146 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4152 procedure g_Game_Spectate();
4154 g_Game_RemovePlayer();
4155 if gPlayer1
<> nil then
4156 g_Game_RemovePlayer();
4159 procedure g_Game_SpectateCenterView();
4161 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4162 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4165 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4172 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4174 g_Game_ClearLoading();
4177 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4180 gGameSettings
.GameType
:= GT_SINGLE
;
4181 gGameSettings
.MaxLives
:= 0;
4182 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4183 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4184 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4185 gSwitchGameMode
:= GM_SINGLE
;
4187 g_Game_ExecuteEvent('ongamestart');
4189 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4190 g_Game_SetupScreenSize();
4192 // Ñîçäàíèå ïåðâîãî èãðîêà:
4193 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4194 gPlayer1Settings
.Color
,
4195 gPlayer1Settings
.Team
, False));
4196 if gPlayer1
= nil then
4198 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4202 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4205 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4208 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4209 gPlayer2Settings
.Color
,
4210 gPlayer2Settings
.Team
, False));
4211 if gPlayer2
= nil then
4213 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4217 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4221 // Çàãðóçêà è çàïóñê êàðòû:
4222 if not g_Game_StartMap(MAP
, True) then
4224 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4225 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4229 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4233 for i
:= nPl
+1 to nPlayers
do
4234 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4237 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4238 TimeLimit
, GoalLimit
: Word;
4240 Options
: LongWord; nPlayers
: Byte);
4246 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4248 g_Game_ClearLoading();
4251 gGameSettings
.GameType
:= GT_CUSTOM
;
4252 gGameSettings
.GameMode
:= GameMode
;
4253 gSwitchGameMode
:= GameMode
;
4254 gGameSettings
.TimeLimit
:= TimeLimit
;
4255 gGameSettings
.GoalLimit
:= GoalLimit
;
4256 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4257 gGameSettings
.Options
:= Options
;
4259 gCoopTotalMonstersKilled
:= 0;
4260 gCoopTotalSecretsFound
:= 0;
4261 gCoopTotalMonsters
:= 0;
4262 gCoopTotalSecrets
:= 0;
4266 g_Game_ExecuteEvent('ongamestart');
4268 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4269 g_Game_SetupScreenSize();
4271 // Ðåæèì íàáëþäàòåëÿ:
4272 if nPlayers
= 0 then
4279 if nPlayers
>= 1 then
4281 // Ñîçäàíèå ïåðâîãî èãðîêà:
4282 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4283 gPlayer1Settings
.Color
,
4284 gPlayer1Settings
.Team
, False));
4285 if gPlayer1
= nil then
4287 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4291 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4295 if nPlayers
>= 2 then
4297 // Ñîçäàíèå âòîðîãî èãðîêà:
4298 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4299 gPlayer2Settings
.Color
,
4300 gPlayer2Settings
.Team
, False));
4301 if gPlayer2
= nil then
4303 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4307 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4311 // Çàãðóçêà è çàïóñê êàðòû:
4312 if not g_Game_StartMap(Map
, True) then
4314 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4318 // Íåò òî÷åê ïîÿâëåíèÿ:
4319 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4320 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4321 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4322 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4323 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4325 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4329 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4333 for i
:= nPl
+1 to nPlayers
do
4334 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4337 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4338 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4339 Options
: LongWord; nPlayers
: Byte;
4340 IPAddr
: LongWord; Port
: Word);
4344 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4346 g_Game_ClearLoading();
4349 gGameSettings
.GameType
:= GT_SERVER
;
4350 gGameSettings
.GameMode
:= GameMode
;
4351 gSwitchGameMode
:= GameMode
;
4352 gGameSettings
.TimeLimit
:= TimeLimit
;
4353 gGameSettings
.GoalLimit
:= GoalLimit
;
4354 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4355 gGameSettings
.Options
:= Options
;
4357 gCoopTotalMonstersKilled
:= 0;
4358 gCoopTotalSecretsFound
:= 0;
4359 gCoopTotalMonsters
:= 0;
4360 gCoopTotalSecrets
:= 0;
4364 g_Game_ExecuteEvent('ongamestart');
4366 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4367 g_Game_SetupScreenSize();
4369 // Ðåæèì íàáëþäàòåëÿ:
4370 if nPlayers
= 0 then
4376 if nPlayers
>= 1 then
4378 // Ñîçäàíèå ïåðâîãî èãðîêà:
4379 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4380 gPlayer1Settings
.Color
,
4381 gPlayer1Settings
.Team
, False));
4382 if gPlayer1
= nil then
4384 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4388 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4391 if nPlayers
>= 2 then
4393 // Ñîçäàíèå âòîðîãî èãðîêà:
4394 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4395 gPlayer2Settings
.Color
,
4396 gPlayer2Settings
.Team
, False));
4397 if gPlayer2
= nil then
4399 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4403 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4406 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4407 if NetForwardPorts
then
4408 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4411 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4413 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4417 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4419 // Çàãðóçêà è çàïóñê êàðòû:
4420 if not g_Game_StartMap(Map
, True) then
4422 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4426 // Íåò òî÷åê ïîÿâëåíèÿ:
4427 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4428 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4429 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4430 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4431 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4433 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4437 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4440 NetState
:= NET_STATE_GAME
;
4443 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4458 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4459 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4461 g_Game_ClearLoading();
4464 gGameSettings
.GameType
:= GT_CLIENT
;
4466 gCoopTotalMonstersKilled
:= 0;
4467 gCoopTotalSecretsFound
:= 0;
4468 gCoopTotalMonsters
:= 0;
4469 gCoopTotalSecrets
:= 0;
4473 g_Game_ExecuteEvent('ongamestart');
4475 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4476 g_Game_SetupScreenSize();
4478 NetState
:= NET_STATE_AUTH
;
4480 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4482 if not g_Net_Connect(Addr
, Port
) then
4484 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4485 NetState
:= NET_STATE_NONE
;
4489 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4491 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4496 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4498 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4500 Ptr
:= NetEvent
.packet
^.data
;
4501 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4504 MID
:= InMsg
.ReadByte();
4506 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4508 NetMyID
:= InMsg
.ReadByte();
4509 NetPlrUID1
:= InMsg
.ReadWord();
4511 WadName
:= InMsg
.ReadString();
4512 Map
:= InMsg
.ReadString();
4514 gWADHash
:= InMsg
.ReadMD5();
4516 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4517 gSwitchGameMode
:= gGameSettings
.GameMode
;
4518 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4519 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4520 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4521 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4522 T
:= InMsg
.ReadLongWord();
4524 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4525 if newResPath
= '' then
4527 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4528 newResPath
:= g_Res_DownloadWAD(WadName
);
4529 if newResPath
= '' then
4531 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4532 enet_packet_destroy(NetEvent
.packet
);
4533 NetState
:= NET_STATE_NONE
;
4537 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4539 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4540 gPlayer1Settings
.Color
,
4541 gPlayer1Settings
.Team
, False));
4543 if gPlayer1
= nil then
4545 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4547 enet_packet_destroy(NetEvent
.packet
);
4548 NetState
:= NET_STATE_NONE
;
4552 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4553 gPlayer1
.UID
:= NetPlrUID1
;
4554 gPlayer1
.Reset(True);
4556 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4558 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4560 enet_packet_destroy(NetEvent
.packet
);
4561 NetState
:= NET_STATE_NONE
;
4569 enet_packet_destroy(NetEvent
.packet
);
4573 enet_packet_destroy(NetEvent
.packet
);
4577 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4580 if (NetEvent
.data
<= NET_DISC_MAX
) then
4581 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4582 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4589 ProcessLoading(true);
4591 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_ESCAPE
) then
4600 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4601 NetState
:= NET_STATE_NONE
;
4605 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4606 gLMSRespawnTime
:= 0;
4609 NetState
:= NET_STATE_GAME
;
4610 MC_SEND_FullStateRequest
;
4611 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4614 procedure g_Game_SaveOptions();
4616 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4619 procedure g_Game_ChangeMap(const MapPath
: String);
4623 g_Game_ClearLoading();
4625 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4626 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4627 if gExitByTrigger
then
4630 gExitByTrigger
:= False;
4632 if not g_Game_StartMap(MapPath
, Force
) then
4633 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4636 procedure g_Game_Restart();
4640 if g_Game_IsClient
then
4642 map
:= g_ExtractFileName(gMapInfo
.Map
);
4646 g_Game_ClearLoading();
4647 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4650 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4652 NewWAD
, ResName
: String;
4655 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4656 g_Player_RemoveAllCorpses();
4658 if (not g_Game_IsClient
) and
4659 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4660 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4662 if gSwitchGameMode
= GM_CTF
then
4663 gGameSettings
.MaxLives
:= 0;
4664 gGameSettings
.GameMode
:= gSwitchGameMode
;
4667 gSwitchGameMode
:= gGameSettings
.GameMode
;
4669 g_Player_ResetTeams();
4671 if isWadPath(Map
) then
4673 NewWAD
:= g_ExtractWadName(Map
);
4674 ResName
:= g_ExtractFileName(Map
);
4675 if g_Game_IsServer
then
4677 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4678 g_Game_LoadWAD(NewWAD
);
4680 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4681 g_Game_ClientWAD(NewWAD
, gWADHash
);
4685 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4688 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4690 gState
:= STATE_NONE
;
4691 g_ActiveWindow
:= nil;
4697 if gGameSettings
.GameMode
= GM_CTF
then
4699 g_Map_ResetFlag(FLAG_RED
);
4700 g_Map_ResetFlag(FLAG_BLUE
);
4701 // CTF, à ôëàãîâ íåò:
4702 if not g_Map_HaveFlagPoints() then
4703 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4708 gState
:= STATE_MENU
;
4713 gPauseMain
:= false;
4714 gPauseHolmes
:= false;
4716 NetTimeToUpdate
:= 1;
4717 NetTimeToReliable
:= 0;
4718 NetTimeToMaster
:= NetMasterRate
;
4719 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4720 gLMSRespawnTime
:= 0;
4721 gMissionFailed
:= False;
4724 gCoopMonstersKilled
:= 0;
4725 gCoopSecretsFound
:= 0;
4727 gVoteInProgress
:= False;
4728 gVotePassed
:= False;
4734 if not gGameOn
then Exit
;
4736 g_Game_SpectateCenterView();
4738 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4740 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4741 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4742 gLMSSoftSpawn
:= True;
4743 if NetMode
= NET_SERVER
then
4744 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4746 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4749 if NetMode
= NET_SERVER
then
4751 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4754 if NetUseMaster
then
4756 if (NetMHost
= nil) or (NetMPeer
= nil) then
4757 if not g_Net_Slist_Connect
then
4758 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4763 if NetClients
<> nil then
4764 for I
:= 0 to High(NetClients
) do
4765 if NetClients
[I
].Used
then
4767 NetClients
[I
].Voted
:= False;
4768 if NetClients
[I
].RequestedFullUpdate
then
4770 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4771 NetClients
[I
].RequestedFullUpdate
:= False;
4775 g_Net_UnbanNonPermHosts();
4780 gCoopTotalMonstersKilled
:= 0;
4781 gCoopTotalSecretsFound
:= 0;
4782 gCoopTotalMonsters
:= 0;
4783 gCoopTotalSecrets
:= 0;
4787 g_Game_ExecuteEvent('onmapstart');
4790 procedure SetFirstLevel();
4794 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4795 if MapList
= nil then
4798 SortSArray(MapList
);
4799 gNextMap
:= MapList
[Low(MapList
)];
4804 procedure g_Game_ExitLevel(const Map
: AnsiString);
4808 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4809 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4810 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4811 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4813 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4814 if gGameSettings
.GameType
= GT_SINGLE
then
4815 gExit
:= EXIT_ENDLEVELSINGLE
4816 else // Âûøëè â âûõîä â Ñâîåé èãðå
4818 gExit
:= EXIT_ENDLEVELCUSTOM
;
4819 if gGameSettings
.GameMode
= GM_COOP
then
4820 g_Player_RememberAll
;
4822 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4825 if gGameSettings
.GameMode
= GM_COOP
then
4828 gStatsPressed
:= True;
4829 gNextMap
:= 'MAP01';
4831 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4834 if g_Game_IsNet
then
4836 MH_SEND_GameStats();
4837 MH_SEND_CoopStats();
4843 procedure g_Game_RestartLevel();
4847 if gGameSettings
.GameMode
= GM_SINGLE
then
4852 gExit
:= EXIT_ENDLEVELCUSTOM
;
4853 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4857 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4861 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4863 if not g_Game_IsClient
then
4865 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4868 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4869 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4873 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4877 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4878 g_Game_LoadWAD(NewWAD
);
4881 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4883 i
, n
, nb
, nr
: Integer;
4885 function monRespawn (mon
: TMonster
): Boolean;
4887 result
:= false; // don't stop
4888 if not mon
.FNoRespawn
then mon
.Respawn();
4892 if not g_Game_IsServer
then Exit
;
4893 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4894 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4895 gLMSRespawnTime
:= 0;
4898 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4900 gMissionFailed
:= True;
4901 g_Game_RestartLevel
;
4905 n
:= 0; nb
:= 0; nr
:= 0;
4906 for i
:= Low(gPlayers
) to High(gPlayers
) do
4907 if (gPlayers
[i
] <> nil) and
4908 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4909 (gPlayers
[i
] is TBot
)) then
4912 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4913 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4916 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4918 // wait a second until the fuckers finally decide to join
4919 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4920 gLMSRespawnTime
:= gTime
+ 1000;
4921 gLMSSoftSpawn
:= NoMapRestart
;
4925 g_Player_RemoveAllCorpses
;
4926 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4927 if g_Game_IsNet
then
4928 MH_SEND_GameEvent(NET_EV_LMS_START
);
4930 for i
:= Low(gPlayers
) to High(gPlayers
) do
4932 if gPlayers
[i
] = nil then continue
;
4933 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4934 // don't touch normal spectators
4935 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4937 gPlayers
[i
].FNoRespawn
:= True;
4938 gPlayers
[i
].Lives
:= 0;
4939 if g_Game_IsNet
then
4940 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4943 gPlayers
[i
].FNoRespawn
:= False;
4944 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4945 gPlayers
[i
].Respawn(False, True);
4946 if gGameSettings
.GameMode
= GM_COOP
then
4948 gPlayers
[i
].Frags
:= 0;
4949 gPlayers
[i
].RecallState
;
4951 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4952 gPlayer1
:= g_Player_Get(gLMSPID1
);
4953 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4954 gPlayer2
:= g_Player_Get(gLMSPID2
);
4957 g_Items_RestartRound();
4960 g_Mons_ForEach(monRespawn
);
4962 gLMSSoftSpawn
:= False;
4965 function g_Game_GetFirstMap(WAD
: String): String;
4969 MapList
:= g_Map_GetMapsList(WAD
);
4970 if MapList
= nil then
4973 SortSArray(MapList
);
4974 Result
:= MapList
[Low(MapList
)];
4976 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4982 function g_Game_GetNextMap(): String;
4989 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4990 if MapList
= nil then
4993 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4995 SortSArray(MapList
);
4997 for I
:= Low(MapList
) to High(MapList
) do
4998 if Map
= MapList
[I
] then
5004 if MapIndex
<> -255 then
5006 if MapIndex
= High(MapList
) then
5007 Result
:= MapList
[Low(MapList
)]
5009 Result
:= MapList
[MapIndex
+ 1];
5011 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5017 procedure g_Game_NextLevel();
5019 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5020 gExit
:= EXIT_ENDLEVELCUSTOM
5023 gExit
:= EXIT_ENDLEVELSINGLE
;
5027 if gNextMap
<> '' then Exit
;
5028 gNextMap
:= g_Game_GetNextMap();
5031 function g_Game_IsTestMap(): Boolean;
5033 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5036 procedure g_Game_DeleteTestMap();
5039 //MapName: AnsiString;
5047 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5048 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5049 if (a
= 0) then exit
;
5051 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5052 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5053 Delete(gMapToDelete
, 1, a
+5);
5054 gMapToDelete
:= UpperCase(gMapToDelete
);
5056 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5059 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5060 if MapName <> TEST_MAP_NAME then
5063 if not gTempDelete then
5065 time := g_GetFileTime(WadName);
5066 WAD := TWADFile.Create();
5069 if not WAD.ReadFile(WadName) then
5070 begin // Íåò òàêîãî WAD-ôàéëà
5075 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5077 MapList := WAD.GetResourcesList('');
5079 if MapList <> nil then
5080 for a := 0 to High(MapList) do
5081 if MapList[a] = MapName then
5083 // Óäàëÿåì è ñîõðàíÿåì:
5084 WAD.RemoveResource('', MapName);
5085 WAD.SaveTo(WadName);
5090 g_SetFileTime(WadName, time);
5093 if gTempDelete
then DeleteFile(WadName
);
5096 procedure GameCVars(P
: SSArray
);
5099 stat
: TPlayerStatArray
;
5104 cmd
:= LowerCase(P
[0]);
5105 if cmd
= 'r_showfps' then
5107 if (Length(P
) > 1) and
5108 ((P
[1] = '1') or (P
[1] = '0')) then
5109 gShowFPS
:= (P
[1][1] = '1');
5112 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
5114 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
5116 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5118 with gGameSettings
do
5120 if (Length(P
) > 1) and
5121 ((P
[1] = '1') or (P
[1] = '0')) then
5123 if (P
[1][1] = '1') then
5124 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5126 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5129 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5130 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5132 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5134 if g_Game_IsNet
then MH_SEND_GameSettings
;
5137 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5139 with gGameSettings
do
5141 if (Length(P
) > 1) and
5142 ((P
[1] = '1') or (P
[1] = '0')) then
5144 if (P
[1][1] = '1') then
5145 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5147 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5150 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5151 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5153 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5155 if g_Game_IsNet
then MH_SEND_GameSettings
;
5158 else if cmd
= 'g_gamemode' then
5160 a
:= g_Game_TextToMode(P
[1]);
5161 if a
= GM_SINGLE
then a
:= GM_COOP
;
5162 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5164 gSwitchGameMode
:= a
;
5165 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5166 (gState
= STATE_INTERSINGLE
) then
5167 gSwitchGameMode
:= GM_SINGLE
;
5169 gGameSettings
.GameMode
:= gSwitchGameMode
;
5171 if gSwitchGameMode
= gGameSettings
.GameMode
then
5172 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5173 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5175 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5176 [g_Game_ModeToText(gGameSettings
.GameMode
),
5177 g_Game_ModeToText(gSwitchGameMode
)]));
5179 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5181 with gGameSettings
do
5183 if (Length(P
) > 1) and
5184 ((P
[1] = '1') or (P
[1] = '0')) then
5186 if (P
[1][1] = '1') then
5187 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5189 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5192 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5193 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5195 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5196 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5198 if g_Game_IsNet
then MH_SEND_GameSettings
;
5201 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5203 with gGameSettings
do
5205 if (Length(P
) > 1) and
5206 ((P
[1] = '1') or (P
[1] = '0')) then
5208 if (P
[1][1] = '1') then
5209 Options
:= Options
or GAME_OPTION_MONSTERS
5211 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5214 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5215 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5217 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5218 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5220 if g_Game_IsNet
then MH_SEND_GameSettings
;
5223 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5225 with gGameSettings
do
5227 if (Length(P
) > 1) and
5228 ((P
[1] = '1') or (P
[1] = '0')) then
5230 if (P
[1][1] = '1') then
5231 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5233 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5236 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5237 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5239 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5241 if g_Game_IsNet
then MH_SEND_GameSettings
;
5244 else if (cmd
= 'g_bot_vsmonsters') 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_BOTVSMONSTER
5254 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5257 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5258 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5260 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5262 if g_Game_IsNet
then MH_SEND_GameSettings
;
5265 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5267 if Length(P
) > 1 then
5269 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5270 gGameSettings
.WarmupTime
:= 30
5272 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5275 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5276 [gGameSettings
.WarmupTime
]));
5277 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5279 else if cmd
= 'net_interp' then
5281 if (Length(P
) > 1) then
5282 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5284 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5285 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5286 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5287 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5290 else if cmd
= 'net_forceplayerupdate' then
5292 if (Length(P
) > 1) and
5293 ((P
[1] = '1') or (P
[1] = '0')) then
5294 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5296 if NetForcePlayerUpdate
then
5297 g_Console_Add('net_forceplayerupdate = 1')
5299 g_Console_Add('net_forceplayerupdate = 0');
5300 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5301 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5302 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5305 else if cmd
= 'net_predictself' then
5307 if (Length(P
) > 1) and
5308 ((P
[1] = '1') or (P
[1] = '0')) then
5309 NetPredictSelf
:= (P
[1][1] = '1');
5311 if NetPredictSelf
then
5312 g_Console_Add('net_predictself = 1')
5314 g_Console_Add('net_predictself = 0');
5315 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5316 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5317 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5320 else if cmd
= 'sv_name' then
5322 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5324 NetServerName
:= P
[1];
5325 if Length(NetServerName
) > 64 then
5326 SetLength(NetServerName
, 64);
5327 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5331 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5333 else if cmd
= 'sv_passwd' then
5335 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5337 NetPassword
:= P
[1];
5338 if Length(NetPassword
) > 24 then
5339 SetLength(NetPassword
, 24);
5340 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5344 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5346 else if cmd
= 'sv_maxplrs' then
5348 if (Length(P
) > 1) then
5350 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5351 if g_Game_IsServer
and g_Game_IsNet
then
5354 for a
:= 0 to High(NetClients
) do
5355 if NetClients
[a
].Used
then
5358 if b
> NetMaxClients
then
5360 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5361 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5362 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5363 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5366 if NetUseMaster
then
5371 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5373 else if cmd
= 'sv_public' then
5375 if (Length(P
) > 1) then
5377 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5378 if g_Game_IsServer
and g_Game_IsNet
then
5379 if NetUseMaster
then
5381 if NetMPeer
= nil then
5382 if not g_Net_Slist_Connect() then
5383 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5384 g_Net_Slist_Update();
5387 if NetMPeer
<> nil then
5388 g_Net_Slist_Disconnect();
5391 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5393 else if cmd
= 'sv_intertime' then
5395 if (Length(P
) > 1) then
5396 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5398 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5400 else if cmd
= 'p1_name' then
5402 if (Length(P
) > 1) and gGameOn
then
5404 if g_Game_IsClient
then
5406 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5407 MC_SEND_PlayerSettings
;
5410 if gPlayer1
<> nil then
5412 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5413 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5416 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5419 else if cmd
= 'p2_name' then
5421 if (Length(P
) > 1) and gGameOn
then
5423 if g_Game_IsClient
then
5425 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5426 MC_SEND_PlayerSettings
;
5429 if gPlayer2
<> nil then
5431 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5432 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5435 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5438 else if cmd
= 'p1_color' then
5440 if Length(P
) > 3 then
5441 if g_Game_IsClient
then
5443 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5444 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5445 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5446 MC_SEND_PlayerSettings
;
5449 if gPlayer1
<> nil then
5451 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5452 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5453 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5454 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5457 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5458 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5459 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5461 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5463 if Length(P
) > 3 then
5464 if g_Game_IsClient
then
5466 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5467 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5468 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5469 MC_SEND_PlayerSettings
;
5472 if gPlayer2
<> nil then
5474 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5475 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5476 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5477 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5480 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5481 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5482 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5484 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5486 if cmd
= 'r_showtime' then
5488 if (Length(P
) > 1) and
5489 ((P
[1] = '1') or (P
[1] = '0')) then
5490 gShowTime
:= (P
[1][1] = '1');
5493 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5495 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5497 else if cmd
= 'r_showscore' then
5499 if (Length(P
) > 1) and
5500 ((P
[1] = '1') or (P
[1] = '0')) then
5501 gShowGoals
:= (P
[1][1] = '1');
5504 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5506 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5508 else if cmd
= 'r_showstat' then
5510 if (Length(P
) > 1) and
5511 ((P
[1] = '1') or (P
[1] = '0')) then
5512 gShowStat
:= (P
[1][1] = '1');
5515 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5517 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5519 else if cmd
= 'r_showkillmsg' then
5521 if (Length(P
) > 1) and
5522 ((P
[1] = '1') or (P
[1] = '0')) then
5523 gShowKillMsg
:= (P
[1][1] = '1');
5525 if gShowKillMsg
then
5526 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5528 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5530 else if cmd
= 'r_showlives' then
5532 if (Length(P
) > 1) and
5533 ((P
[1] = '1') or (P
[1] = '0')) then
5534 gShowLives
:= (P
[1][1] = '1');
5537 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5539 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5541 else if cmd
= 'r_showspect' then
5543 if (Length(P
) > 1) and
5544 ((P
[1] = '1') or (P
[1] = '0')) then
5545 gSpectHUD
:= (P
[1][1] = '1');
5548 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5550 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5552 else if cmd
= 'r_showping' then
5554 if (Length(P
) > 1) and
5555 ((P
[1] = '1') or (P
[1] = '0')) then
5556 gShowPing
:= (P
[1][1] = '1');
5559 g_Console_Add(_lc
[I_MSG_PING_ON
])
5561 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5563 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5565 if Length(P
) > 1 then
5567 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5568 gGameSettings
.GoalLimit
:= 0
5573 if gGameSettings
.GameMode
= GM_DM
then
5575 stat
:= g_Player_GetStats();
5577 for a
:= 0 to High(stat
) do
5578 if stat
[a
].Frags
> b
then
5582 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5584 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5587 if g_Game_IsNet
then MH_SEND_GameSettings
;
5590 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5592 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5594 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5595 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5597 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5598 [gGameSettings
.TimeLimit
div 3600,
5599 (gGameSettings
.TimeLimit
div 60) mod 60,
5600 gGameSettings
.TimeLimit
mod 60]));
5601 if g_Game_IsNet
then MH_SEND_GameSettings
;
5603 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5605 if Length(P
) > 1 then
5607 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5608 gGameSettings
.MaxLives
:= 0
5612 stat
:= g_Player_GetStats();
5614 for a
:= 0 to High(stat
) do
5615 if stat
[a
].Lives
> b
then
5617 gGameSettings
.MaxLives
:=
5618 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5622 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5623 [gGameSettings
.MaxLives
]));
5624 if g_Game_IsNet
then MH_SEND_GameSettings
;
5629 procedure PrintHeapStats();
5633 hs
:= GetFPCHeapStatus();
5634 e_LogWriteLn ('v===== heap status =====v');
5635 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5636 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5637 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5638 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5639 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5640 e_LogWriteLn ('^=======================^');
5643 procedure DebugCommands(P
: SSArray
);
5650 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5651 if {gDebugMode}conIsCheatsEnabled
then
5653 cmd
:= LowerCase(P
[0]);
5654 if cmd
= 'd_window' then
5656 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5657 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5658 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5659 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5660 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5662 else if cmd
= 'd_sounds' then
5664 if (Length(P
) > 1) and
5665 ((P
[1] = '1') or (P
[1] = '0')) then
5666 g_Debug_Sounds
:= (P
[1][1] = '1');
5668 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5670 else if cmd
= 'd_frames' then
5672 if (Length(P
) > 1) and
5673 ((P
[1] = '1') or (P
[1] = '0')) then
5674 g_Debug_Frames
:= (P
[1][1] = '1');
5676 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5678 else if cmd
= 'd_winmsg' then
5680 if (Length(P
) > 1) and
5681 ((P
[1] = '1') or (P
[1] = '0')) then
5682 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5684 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5686 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5688 if (Length(P
) > 1) and
5689 ((P
[1] = '1') or (P
[1] = '0')) then
5690 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5692 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5694 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5696 if Length(P
) > 1 then
5698 '0': g_debug_BotAIOff
:= 0;
5699 '1': g_debug_BotAIOff
:= 1;
5700 '2': g_debug_BotAIOff
:= 2;
5701 '3': g_debug_BotAIOff
:= 3;
5704 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5706 else if cmd
= 'd_monster' then
5708 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5709 if Length(P
) < 2 then
5711 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5712 g_Console_Add('ID | Name');
5713 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5714 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5715 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5718 a
:= StrToIntDef(P
[1], 0);
5719 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5720 a
:= g_Mons_TypeIdByName(P
[1]);
5722 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5723 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5726 with gPlayer1
.Obj
do
5728 mon
:= g_Monsters_Create(a
,
5729 X
+ Rect
.X
+ (Rect
.Width
div 2),
5730 Y
+ Rect
.Y
+ Rect
.Height
,
5731 gPlayer1
.Direction
, True);
5733 if (Length(P
) > 2) and (mon
<> nil) then
5735 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5736 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5737 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5738 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5739 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5740 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5741 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5742 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5743 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5748 else if (cmd
= 'd_health') then
5750 if (Length(P
) > 1) and
5751 ((P
[1] = '1') or (P
[1] = '0')) then
5752 g_debug_HealthBar
:= (P
[1][1] = '1');
5754 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5756 else if (cmd
= 'd_player') then
5758 if (Length(P
) > 1) and
5759 ((P
[1] = '1') or (P
[1] = '0')) then
5760 g_debug_Player
:= (P
[1][1] = '1');
5762 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5764 else if (cmd
= 'd_joy') then
5767 g_Console_Add(e_JoystickStateToString(a
));
5769 else if (cmd
= 'd_mem') then
5775 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5779 procedure GameCheats(P
: SSArray
);
5785 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5787 g_Console_Add('not available');
5793 g_Console_Add('where is the player?!');
5796 cmd
:= LowerCase(P
[0]);
5800 plr
.GodMode
:= not plr
.GodMode
;
5801 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5804 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5805 if cmd
= 'give' then
5807 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5808 for f
:= 1 to High(P
) do
5810 cmd
:= LowerCase(P
[f
]);
5811 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5812 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5813 if cmd
= 'exit' then
5815 if gTriggers
<> nil then
5817 for a
:= 0 to High(gTriggers
) do
5819 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5821 g_Console_Add('player left the map');
5822 gExitByTrigger
:= True;
5823 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5824 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5832 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5833 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5834 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5835 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5836 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5838 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5839 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5841 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5842 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;
5844 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5845 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5847 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5848 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5850 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5851 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5853 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5854 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5855 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5857 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5858 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5859 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5860 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;
5861 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5862 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5864 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;
5865 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;
5866 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;
5867 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;
5868 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;
5869 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;
5871 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5872 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;
5874 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;
5875 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;
5877 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5879 if cmd
= 'ammo' then
5881 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5882 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5883 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5884 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5885 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5886 g_Console_Add('player got some ammo');
5890 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5891 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5893 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5894 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5896 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5897 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5899 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5900 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5902 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5904 if cmd
= 'weapons' then
5906 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5907 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5908 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5909 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5910 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5911 plr
.GiveItem(ITEM_WEAPON_BFG
);
5912 g_Console_Add('player got weapons');
5916 if cmd
= 'keys' then
5918 plr
.GiveItem(ITEM_KEY_RED
);
5919 plr
.GiveItem(ITEM_KEY_GREEN
);
5920 plr
.GiveItem(ITEM_KEY_BLUE
);
5921 g_Console_Add('player got all keys');
5925 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5930 if cmd
= 'open' then
5932 g_Console_Add('player activated sesame');
5933 g_Triggers_OpenAll();
5940 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5944 if cmd
= 'noclip' then
5947 g_Console_Add('wall hardeness adjusted');
5951 if cmd
= 'notarget' then
5953 plr
.NoTarget
:= not plr
.NoTarget
;
5954 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5958 if cmd
= 'noreload' then
5960 plr
.NoReload
:= not plr
.NoReload
;
5961 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5965 if cmd
= 'speedy' then
5967 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5968 g_Console_Add('speed adjusted');
5972 if cmd
= 'jumpy' then
5974 VEL_JUMP
:= 30-VEL_JUMP
;
5975 g_Console_Add('jump height adjusted');
5979 if cmd
= 'automap' then
5981 gShowMap
:= not gShowMap
;
5982 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5986 if cmd
= 'aimline' then
5988 gAimLine
:= not gAimLine
;
5989 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5994 procedure GameCommands(P
: SSArray
);
6000 pl
: pTNetClient
= nil;
6007 cmd
:= LowerCase(P
[0]);
6009 if (cmd
= 'quit') or
6016 else if cmd
= 'pause' then
6018 if (g_ActiveWindow
= nil) then
6019 g_Game_Pause(not gPauseMain
);
6021 else if cmd
= 'endgame' then
6022 gExit
:= EXIT_SIMPLE
6023 else if cmd
= 'restart' then
6025 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6027 if g_Game_IsClient
then
6029 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6034 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6036 else if cmd
= 'kick' then
6038 if g_Game_IsServer
then
6040 if Length(P
) < 2 then
6042 g_Console_Add('kick <name>');
6047 g_Console_Add('kick <name>');
6051 if g_Game_IsNet
then
6052 pl
:= g_Net_Client_ByName(P
[1]);
6055 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6056 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6057 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6058 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6059 if NetUseMaster
then
6061 end else if gPlayers
<> nil then
6062 for a
:= Low(gPlayers
) to High(gPlayers
) do
6063 if gPlayers
[a
] <> nil then
6064 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6066 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6067 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6069 gPlayers
[a
].Lives
:= 0;
6070 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6071 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6072 g_Player_Remove(gPlayers
[a
].UID
);
6073 if NetUseMaster
then
6075 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6079 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6081 else if cmd
= 'kick_id' then
6083 if g_Game_IsServer
and g_Game_IsNet
then
6085 if Length(P
) < 2 then
6087 g_Console_Add('kick_id <client ID>');
6092 g_Console_Add('kick_id <client ID>');
6096 a
:= StrToIntDef(P
[1], 0);
6097 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6099 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6101 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6102 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6103 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6104 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6105 if NetUseMaster
then
6110 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6112 else if cmd
= 'ban' then
6114 if g_Game_IsServer
and g_Game_IsNet
then
6116 if Length(P
) < 2 then
6118 g_Console_Add('ban <name>');
6123 g_Console_Add('ban <name>');
6127 pl
:= g_Net_Client_ByName(P
[1]);
6130 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6131 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6132 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6133 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6134 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6135 if NetUseMaster
then
6138 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6140 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6142 else if cmd
= 'ban_id' then
6144 if g_Game_IsServer
and g_Game_IsNet
then
6146 if Length(P
) < 2 then
6148 g_Console_Add('ban_id <client ID>');
6153 g_Console_Add('ban_id <client ID>');
6157 a
:= StrToIntDef(P
[1], 0);
6158 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6159 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6161 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6162 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6163 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6164 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6165 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6166 if NetUseMaster
then
6170 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6172 else if cmd
= 'permban' then
6174 if g_Game_IsServer
and g_Game_IsNet
then
6176 if Length(P
) < 2 then
6178 g_Console_Add('permban <name>');
6183 g_Console_Add('permban <name>');
6187 pl
:= g_Net_Client_ByName(P
[1]);
6190 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6191 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6192 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6193 g_Net_SaveBanList();
6194 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6195 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6196 if NetUseMaster
then
6199 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6201 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6203 else if cmd
= 'permban_id' then
6205 if g_Game_IsServer
and g_Game_IsNet
then
6207 if Length(P
) < 2 then
6209 g_Console_Add('permban_id <client ID>');
6214 g_Console_Add('permban_id <client ID>');
6218 a
:= StrToIntDef(P
[1], 0);
6219 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6220 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6222 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6223 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6224 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6225 g_Net_SaveBanList();
6226 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6227 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6228 if NetUseMaster
then
6232 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6234 else if cmd
= 'unban' then
6236 if g_Game_IsServer
and g_Game_IsNet
then
6238 if Length(P
) < 2 then
6240 g_Console_Add('unban <IP Address>');
6245 g_Console_Add('unban <IP Address>');
6249 if g_Net_UnbanHost(P
[1]) then
6251 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6252 g_Net_SaveBanList();
6254 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6256 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6258 else if cmd
= 'clientlist' then
6260 if g_Game_IsServer
and g_Game_IsNet
then
6263 if NetClients
<> nil then
6264 for a
:= Low(NetClients
) to High(NetClients
) do
6265 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6267 plr
:= g_Player_Get(NetClients
[a
].Player
);
6268 if plr
= nil then continue
;
6270 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6271 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6274 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6276 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6278 else if cmd
= 'connect' then
6280 if (NetMode
= NET_NONE
) then
6282 if Length(P
) < 2 then
6284 g_Console_Add('connect <IP> [port] [password]');
6289 g_Console_Add('connect <IP> [port] [password]');
6293 if Length(P
) > 2 then
6294 prt
:= StrToIntDef(P
[2], 25666)
6298 if Length(P
) > 3 then
6303 g_Game_StartClient(P
[1], prt
, pw
);
6306 else if cmd
= 'disconnect' then
6308 if (NetMode
= NET_CLIENT
) then
6311 else if cmd
= 'reconnect' then
6313 if (NetMode
= NET_SERVER
) then
6316 if (NetMode
= NET_CLIENT
) then
6319 gExit
:= EXIT_SIMPLE
;
6323 //TODO: Use last successful password to reconnect, instead of ''
6324 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6326 else if (cmd
= 'addbot') or
6327 (cmd
= 'bot_add') then
6329 if Length(P
) > 1 then
6330 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6332 g_Bot_Add(TEAM_NONE
, 2);
6334 else if cmd
= 'bot_addlist' then
6336 if Length(P
) > 1 then
6337 if Length(P
) = 2 then
6338 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6340 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6342 else if cmd
= 'bot_removeall' then
6344 else if cmd
= 'chat' then
6346 if g_Game_IsNet
then
6348 if Length(P
) > 1 then
6350 for a
:= 1 to High(P
) do
6351 chstr
:= chstr
+ P
[a
] + ' ';
6353 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6355 if Length(chstr
) < 1 then
6357 g_Console_Add('chat <text>');
6361 chstr
:= b_Text_Format(chstr
);
6362 if g_Game_IsClient
then
6363 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6365 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6368 g_Console_Add('chat <text>');
6370 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6372 else if cmd
= 'teamchat' then
6374 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6376 if Length(P
) > 1 then
6378 for a
:= 1 to High(P
) do
6379 chstr
:= chstr
+ P
[a
] + ' ';
6381 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6383 if Length(chstr
) < 1 then
6385 g_Console_Add('teamchat <text>');
6389 chstr
:= b_Text_Format(chstr
);
6390 if g_Game_IsClient
then
6391 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6393 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6394 gPlayer1Settings
.Team
);
6397 g_Console_Add('teamchat <text>');
6399 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6401 else if cmd
= 'game' then
6403 if gGameSettings
.GameType
<> GT_NONE
then
6405 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6408 if Length(P
) = 1 then
6410 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6413 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6414 P
[1] := addWadExtension(P
[1]);
6415 if FileExists(MapsDir
+ P
[1]) then
6417 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6418 if Length(P
) < 3 then
6421 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6424 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6426 if g_Map_Exist(MapsDir
+ s
) then
6428 // Çàïóñêàåì ñâîþ èãðó
6430 with gGameSettings
do
6432 GameMode
:= g_Game_TextToMode(gcGameMode
);
6433 if gSwitchGameMode
<> GM_NONE
then
6434 GameMode
:= gSwitchGameMode
;
6435 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6436 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6438 if Length(P
) >= 4 then
6439 b
:= StrToIntDef(P
[3], 1);
6440 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6441 GoalLimit
, MaxLives
, Options
, b
);
6446 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6448 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6450 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6452 else if cmd
= 'host' then
6454 if gGameSettings
.GameType
<> GT_NONE
then
6456 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6459 if Length(P
) < 4 then
6461 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6464 if not StrToIp(P
[1], listen
) then
6466 prt
:= StrToIntDef(P
[2], 25666);
6468 P
[3] := addWadExtension(P
[3]);
6469 if FileExists(MapsDir
+ P
[3]) then
6471 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6472 if Length(P
) < 5 then
6475 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6478 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6480 if g_Map_Exist(MapsDir
+ s
) then
6482 // Çàïóñêàåì ñâîþ èãðó
6484 with gGameSettings
do
6486 GameMode
:= g_Game_TextToMode(gcGameMode
);
6487 if gSwitchGameMode
<> GM_NONE
then
6488 GameMode
:= gSwitchGameMode
;
6489 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6490 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6492 if Length(P
) >= 6 then
6493 b
:= StrToIntDef(P
[5], 0);
6494 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6495 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6500 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6502 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6504 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6506 else if cmd
= 'map' then
6508 if Length(P
) = 1 then
6510 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6512 g_Console_Add(cmd
+ ' <MAP>');
6513 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6515 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6517 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6519 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6520 if Length(P
) < 3 then
6522 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6523 s
:= UpperCase(P
[1]);
6524 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6525 begin // Êàðòà íàøëàñü
6526 gExitByTrigger
:= False;
6528 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6530 gExit
:= EXIT_ENDLEVELCUSTOM
;
6532 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6533 g_Game_ChangeMap(s
);
6536 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6537 P
[1] := addWadExtension(P
[1]);
6538 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6539 if FileExists(MapsDir
+ P
[1]) then
6541 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6543 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6545 s
:= P
[1] + ':\' + P
[2];
6547 if g_Map_Exist(MapsDir
+ s
) then
6549 gExitByTrigger
:= False;
6551 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6553 gExit
:= EXIT_ENDLEVELCUSTOM
;
6555 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6556 g_Game_ChangeMap(s
);
6559 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6561 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6563 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6567 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6568 P
[1] := addWadExtension(P
[1]);
6569 if FileExists(MapsDir
+ P
[1]) then
6572 P
[2] := UpperCase(P
[2]);
6573 s
:= P
[1] + ':\' + P
[2];
6575 if g_Map_Exist(MapsDir
+ s
) then
6576 begin // Íàøëè êàðòó
6577 gExitByTrigger
:= False;
6579 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6581 gExit
:= EXIT_ENDLEVELCUSTOM
;
6583 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6584 g_Game_ChangeMap(s
);
6586 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6588 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6591 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6593 else if cmd
= 'nextmap' then
6595 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6596 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6599 if Length(P
) = 1 then
6601 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6603 g_Console_Add(cmd
+ ' <MAP>');
6604 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6607 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6612 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6614 if Length(P
) < 3 then
6616 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6617 s
:= UpperCase(P
[1]);
6618 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6619 begin // Êàðòà íàøëàñü
6620 gExitByTrigger
:= False;
6625 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6626 P
[1] := addWadExtension(P
[1]);
6627 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6628 if FileExists(MapsDir
+ P
[1]) then
6630 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6632 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6634 s
:= P
[1] + ':\' + P
[2];
6636 if g_Map_Exist(MapsDir
+ s
) then
6637 begin // Óñòàíàâëèâàåì êàðòó
6638 gExitByTrigger
:= False;
6643 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6645 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6647 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6651 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6652 P
[1] := addWadExtension(P
[1]);
6653 if FileExists(MapsDir
+ P
[1]) then
6656 P
[2] := UpperCase(P
[2]);
6657 s
:= P
[1] + ':\' + P
[2];
6659 if g_Map_Exist(MapsDir
+ s
) then
6660 begin // Íàøëè êàðòó
6661 gExitByTrigger
:= False;
6665 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6667 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6670 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6673 if gNextMap
= '' then
6674 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6676 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6679 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6682 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6684 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6686 gExitByTrigger
:= False;
6687 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6688 if (gNextMap
= '') and (gTriggers
<> nil) then
6689 for a
:= 0 to High(gTriggers
) do
6690 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6692 gExitByTrigger
:= True;
6693 //gNextMap := gTriggers[a].Data.MapName;
6694 gNextMap
:= gTriggers
[a
].tgcMap
;
6697 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6698 if gNextMap
= '' then
6699 gNextMap
:= g_Game_GetNextMap();
6700 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6701 if not isWadPath(gNextMap
) then
6702 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6705 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6706 if g_Map_Exist(MapsDir
+ s
) then
6707 gExit
:= EXIT_ENDLEVELCUSTOM
6709 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6711 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6713 else if (cmd
= 'event') then
6715 if (Length(P
) <= 1) then
6717 for a
:= 0 to High(gEvents
) do
6718 if gEvents
[a
].Command
= '' then
6719 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6721 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6724 if (Length(P
) = 2) then
6726 for a
:= 0 to High(gEvents
) do
6727 if gEvents
[a
].Name
= P
[1] then
6728 if gEvents
[a
].Command
= '' then
6729 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6731 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6734 for a
:= 0 to High(gEvents
) do
6735 if gEvents
[a
].Name
= P
[1] then
6737 gEvents
[a
].Command
:= '';
6738 for b
:= 2 to High(P
) do
6739 if Pos(' ', P
[b
]) = 0 then
6740 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6742 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6743 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6747 else if cmd
= 'suicide' then
6751 if g_Game_IsClient
then
6752 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6755 if gPlayer1
<> nil then
6756 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6757 if gPlayer2
<> nil then
6758 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6762 // Êîìàíäû Ñâîåé èãðû:
6763 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6765 if cmd
= 'bot_addred' then
6767 if Length(P
) > 1 then
6768 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6770 g_Bot_Add(TEAM_RED
, 2);
6772 else if cmd
= 'bot_addblue' then
6774 if Length(P
) > 1 then
6775 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6777 g_Bot_Add(TEAM_BLUE
, 2);
6779 else if cmd
= 'spectate' then
6785 else if cmd
= 'say' then
6787 if g_Game_IsServer
and g_Game_IsNet
then
6789 if Length(P
) > 1 then
6792 for a
:= 1 to High(P
) do
6793 chstr
:= chstr
+ P
[a
] + ' ';
6795 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6797 if Length(chstr
) < 1 then
6799 g_Console_Add('say <text>');
6803 chstr
:= b_Text_Format(chstr
);
6804 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6806 else g_Console_Add('say <text>');
6808 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6810 else if cmd
= 'tell' then
6812 if g_Game_IsServer
and g_Game_IsNet
then
6814 if (Length(P
) > 2) and (P
[1] <> '') then
6817 for a
:= 2 to High(P
) do
6818 chstr
:= chstr
+ P
[a
] + ' ';
6820 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6822 if Length(chstr
) < 1 then
6824 g_Console_Add('tell <playername> <text>');
6828 pl
:= g_Net_Client_ByName(P
[1]);
6830 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6832 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6834 else g_Console_Add('tell <playername> <text>');
6836 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6838 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6840 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6842 // Äîïîëíèòåëüíîå âðåìÿ:
6843 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6845 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6846 [gGameSettings
.TimeLimit
div 3600,
6847 (gGameSettings
.TimeLimit
div 60) mod 60,
6848 gGameSettings
.TimeLimit
mod 60]));
6849 if g_Game_IsNet
then MH_SEND_GameSettings
;
6851 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6853 if (Length(P
) <= 1) then
6854 g_Console_Add('rcon_password <password>')
6856 MC_SEND_RCONPassword(P
[1]);
6858 else if cmd
= 'rcon' then
6860 if g_Game_IsClient
then
6862 if Length(P
) > 1 then
6865 for a
:= 1 to High(P
) do
6866 chstr
:= chstr
+ P
[a
] + ' ';
6868 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6870 if Length(chstr
) < 1 then
6872 g_Console_Add('rcon <command>');
6876 MC_SEND_RCONCommand(chstr
);
6878 else g_Console_Add('rcon <command>');
6881 else if cmd
= 'ready' then
6883 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6884 gLMSRespawnTime
:= gTime
+ 100;
6886 else if (cmd
= 'callvote') and g_Game_IsNet
then
6888 if Length(P
) > 1 then
6891 for a
:= 1 to High(P
) do begin
6892 if a
> 1 then chstr
:= chstr
+ ' ';
6893 chstr
:= chstr
+ P
[a
];
6896 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6898 if Length(chstr
) < 1 then
6900 g_Console_Add('callvote <command>');
6904 if g_Game_IsClient
then
6905 MC_SEND_Vote(True, chstr
)
6907 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6908 g_Console_Process('vote', True);
6911 g_Console_Add('callvote <command>');
6913 else if (cmd
= 'vote') and g_Game_IsNet
then
6915 if g_Game_IsClient
then
6917 else if gVoteInProgress
then
6919 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6920 a
:= Floor((NetClientCount
+1)/2.0) + 1
6922 a
:= Floor(NetClientCount
/2.0) + 1;
6927 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6928 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6934 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6935 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6943 procedure g_TakeScreenShot();
6951 if e_NoGraphics
then Exit
;
6952 ssdir
:= GameDir
+'/screenshots';
6953 if not findFileCI(ssdir
, true) then
6955 // try to create dir
6960 if not findFileCI(ssdir
, true) then exit
; // alas
6963 for a
:= 1 to High(Word) do
6965 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6967 if findFileCI(t
, true) then continue
;
6968 if not findFileCI(FileName
) then
6971 st
:= createDiskFile(FileName
);
6973 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6978 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6986 procedure g_Game_InGameMenu(Show
: Boolean);
6988 if (g_ActiveWindow
= nil) and Show
then
6990 if gGameSettings
.GameType
= GT_SINGLE
then
6991 g_GUI_ShowWindow('GameSingleMenu')
6994 if g_Game_IsClient
then
6995 g_GUI_ShowWindow('GameClientMenu')
6997 if g_Game_IsNet
then
6998 g_GUI_ShowWindow('GameServerMenu')
7000 g_GUI_ShowWindow('GameCustomMenu');
7002 g_Sound_PlayEx('MENU_OPEN');
7004 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7005 if (not g_Game_IsNet
) then
7009 if (g_ActiveWindow
<> nil) and (not Show
) then
7011 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7012 if (not g_Game_IsNet
) then
7013 g_Game_Pause(False);
7017 procedure g_Game_Pause (Enable
: Boolean);
7021 if not gGameOn
then exit
;
7023 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7026 gPauseMain
:= Enable
;
7028 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7031 procedure g_Game_HolmesPause (Enable
: Boolean);
7035 if not gGameOn
then exit
;
7036 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7039 gPauseHolmes
:= Enable
;
7041 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7044 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7049 if gTriggers
<> nil then
7050 for i
:= 0 to High(gTriggers
) do
7051 with gTriggers
[i
] do
7052 if (TriggerType
= TRIGGER_SOUND
) and
7054 Sound
.IsPlaying() then
7056 Sound
.Pause(Enable
);
7060 if gPlayers
<> nil then
7061 for i
:= 0 to High(gPlayers
) do
7062 if gPlayers
[i
] <> nil then
7063 gPlayers
[i
].PauseSounds(Enable
);
7066 if gMusic
<> nil then
7067 gMusic
.Pause(Enable
);
7070 procedure g_Game_StopAllSounds(all
: Boolean);
7074 if gTriggers
<> nil then
7075 for i
:= 0 to High(gTriggers
) do
7076 with gTriggers
[i
] do
7077 if (TriggerType
= TRIGGER_SOUND
) and
7081 if gMusic
<> nil then
7088 procedure g_Game_UpdateTriggerSounds();
7092 if gTriggers
<> nil then
7093 for i
:= 0 to High(gTriggers
) do
7094 with gTriggers
[i
] do
7095 if (TriggerType
= TRIGGER_SOUND
) and
7098 Sound
.IsPlaying() then
7100 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
7101 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
7103 Sound
.SetPan(0.5 - tgcPan
/255.0);
7104 Sound
.SetVolume(tgcVolume
/255.0);
7107 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
7111 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7114 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7119 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7124 if gSpectMode
<> SPECT_PLAYERS
then
7126 if gSpectPID1
= UID
then
7131 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7138 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7143 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7148 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7153 if gSpectMode
<> SPECT_PLAYERS
then
7155 Pl
:= g_Player_Get(gSpectPID1
);
7156 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7161 if gSpectViewTwo
then
7163 Pl
:= g_Player_Get(gSpectPID2
);
7164 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7172 procedure g_Game_Message(Msg
: string; Time
: Word);
7174 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7175 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7176 MessageTime
:= Time
;
7179 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7181 punct
: Array[0..13] of String =
7182 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7188 function IsPunctuation(S
: String): Boolean;
7193 if Length(S
) <> 1 then
7195 for i
:= Low(punct
) to High(punct
) do
7196 if S
= punct
[i
] then
7202 function FilterPunctuation(S
: String): String;
7206 for i
:= Low(punct
) to High(punct
) do
7207 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7213 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7215 // remove player name
7216 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7217 // for FullWord check
7218 Text := toLowerCase1251(' ' + Text + ' ');
7219 fpText
:= FilterPunctuation(Text);
7221 for i
:= 0 to Length(gChatSounds
) - 1 do
7224 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7226 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7227 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7229 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7235 gChatSounds
[i
].Sound
.Play();
7241 g_Sound_PlayEx('SOUND_GAME_RADIO');
7244 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7253 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7257 if goodsnd
[a
].IsPlaying() then
7260 goodsnd
[Random(4)].Play();
7263 procedure g_Game_Announce_KillCombo(Param
: Integer);
7270 UID
:= Param
and $FFFF;
7275 Pl
:= g_Player_Get(UID
);
7284 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7288 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7292 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7296 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7304 if not g_Game_IsWatchedPlayer(UID
) then
7307 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7311 if killsnd
[n
].IsPlaying() then
7316 procedure g_Game_StartVote(Command
, Initiator
: string);
7320 if not gVotesEnabled
then Exit
;
7321 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7322 if gVoteInProgress
or gVotePassed
then
7324 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7325 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7328 gVoteInProgress
:= True;
7329 gVotePassed
:= False;
7330 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7333 gVoteCommand
:= Command
;
7335 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7336 Need
:= Floor((NetClientCount
+1)/2.0)+1
7338 Need
:= Floor(NetClientCount
/2.0)+1;
7339 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7340 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7343 procedure g_Game_CheckVote
;
7347 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7348 if not gVoteInProgress
then Exit
;
7350 if (gTime
>= gVoteTimer
) then
7352 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7353 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7355 Need
:= Floor(NetClientCount
/2.0) + 1;
7356 if gVoteCount
>= Need
then
7358 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7359 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7360 gVotePassed
:= True;
7361 gVoteCmdTimer
:= gTime
+ 5000;
7365 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7366 MH_SEND_VoteEvent(NET_VE_FAILED
);
7368 if NetClients
<> nil then
7369 for I
:= Low(NetClients
) to High(NetClients
) do
7370 if NetClients
[i
].Used
then
7371 NetClients
[i
].Voted
:= False;
7372 gVoteInProgress
:= False;
7378 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7379 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7381 Need
:= Floor(NetClientCount
/2.0) + 1;
7382 if gVoteCount
>= Need
then
7384 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7385 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7386 gVoteInProgress
:= False;
7387 gVotePassed
:= True;
7388 gVoteCmdTimer
:= gTime
+ 5000;
7391 if NetClients
<> nil then
7392 for I
:= Low(NetClients
) to High(NetClients
) do
7393 if NetClients
[i
].Used
then
7394 NetClients
[i
].Voted
:= False;
7399 procedure g_Game_LoadMapList(FileName
: string);
7407 if not FileExists(FileName
) then Exit
;
7409 AssignFile(ListFile
, FileName
);
7411 while not EOF(ListFile
) do
7413 ReadLn(ListFile
, s
);
7416 if s
= '' then Continue
;
7418 SetLength(MapList
, Length(MapList
)+1);
7419 MapList
[High(MapList
)] := s
;
7421 CloseFile(ListFile
);
7424 procedure g_Game_SetDebugMode();
7427 // ×èòû (äàæå â ñâîåé èãðå):
7431 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7435 if Length(LoadingStat
.Msgs
) = 0 then
7441 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7442 if NextMsg
= Length(Msgs
) then
7444 for i
:= 0 to High(Msgs
)-1 do
7445 Msgs
[i
] := Msgs
[i
+1];
7453 Msgs
[NextMsg
-1] := Text;
7457 PBarWasHere
:= false;
7460 g_ActiveWindow
:= nil;
7462 ProcessLoading(true);
7465 procedure g_Game_StepLoading(Value
: Integer = -1);
7476 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7484 procedure g_Game_ClearLoading();
7493 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7494 if len
< 1 then len
:= 1;
7495 SetLength(Msgs
, len
);
7496 for len
:= Low(Msgs
) to High(Msgs
) do
7499 PBarWasHere
:= false;
7503 procedure Parse_Params(var pars
: TParamStrValues
);
7510 while i
<= ParamCount
do
7513 if (s
[1] = '-') and (Length(s
) > 1) then
7515 if (s
[2] = '-') and (Length(s
) > 2) then
7516 begin // Îäèíî÷íûé ïàðàìåòð
7517 SetLength(pars
, Length(pars
) + 1);
7518 with pars
[High(pars
)] do
7520 Name
:= LowerCase(s
);
7525 if (i
< ParamCount
) then
7526 begin // Ïàðàìåòð ñî çíà÷åíèåì
7528 SetLength(pars
, Length(pars
) + 1);
7529 with pars
[High(pars
)] do
7531 Name
:= LowerCase(s
);
7532 Value
:= LowerCase(ParamStr(i
));
7541 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7546 for i
:= 0 to High(pars
) do
7547 if pars
[i
].Name
= aName
then
7549 Result
:= pars
[i
].Value
;
7554 procedure g_Game_Process_Params();
7556 pars
: TParamStrValues
;
7559 LimT
, LimS
: Integer;
7570 s
:= Find_Param_Value(pars
, '--debug');
7573 g_Game_SetDebugMode();
7574 s
:= Find_Param_Value(pars
, '--netdump');
7579 // Connect when game loads
7580 ip
:= Find_Param_Value(pars
, '-connect');
7584 s
:= Find_Param_Value(pars
, '-port');
7585 if (s
= '') or not TryStrToInt(s
, Port
) then
7588 s
:= Find_Param_Value(pars
, '-pw');
7590 g_Game_StartClient(ip
, Port
, s
);
7594 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7597 gDefaultMegawadStart
:= s
;
7600 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7601 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7603 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7606 // Start map when game loads:
7607 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7608 if isWadPath(map
) then
7611 s
:= Find_Param_Value(pars
, '-gm');
7612 GMode
:= g_Game_TextToMode(s
);
7613 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7614 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7617 s
:= Find_Param_Value(pars
, '-limt');
7618 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7624 s
:= Find_Param_Value(pars
, '-lims');
7625 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7631 s
:= Find_Param_Value(pars
, '-lives');
7632 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7638 s
:= Find_Param_Value(pars
, '-opt');
7640 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7642 Opt
:= StrToIntDef(s
, 0);
7644 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7647 s
:= Find_Param_Value(pars
, '--close');
7651 // Override map to test:
7652 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7654 gTestMap
:= MapsDir
+ s
;
7656 // Delete test map after play:
7657 s
:= Find_Param_Value(pars
, '--testdelete');
7660 gMapToDelete
:= MapsDir
+ map
;
7661 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7665 // Delete temporary WAD after play:
7666 s
:= Find_Param_Value(pars
, '--tempdelete');
7667 if (s
<> '') and (gTestMap
<> '') then
7669 gMapToDelete
:= gTestMap
;
7670 gTempDelete
:= True;
7673 // Number of players:
7674 s
:= Find_Param_Value(pars
, '-pl');
7678 n
:= StrToIntDef(s
, 1);
7681 s
:= Find_Param_Value(pars
, '-port');
7682 if (s
= '') or not TryStrToInt(s
, Port
) then
7683 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7685 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7688 // Execute script when game loads:
7689 s
:= Find_Param_Value(pars
, '-exec');
7692 if not isWadPath(s
) then
7693 s
:= GameDir
+ '/' + s
;
7698 if IOResult
<> 0 then
7700 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7701 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7705 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7706 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7711 if IOResult
<> 0 then
7713 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7714 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7718 if Pos('#', s
) <> 1 then // script comment
7719 g_Console_Process(s
, True);
7730 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7731 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7732 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7733 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7735 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7736 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7737 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7738 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7740 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7741 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7743 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7744 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7746 {$IFDEF ENABLE_HOLMES}
7747 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7750 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7752 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7754 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7755 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7757 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7758 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');