1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 g_basic
, g_player
, e_graphics
, g_res_downloader
,
25 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
29 TGameSettings
= record
45 TDelayedEvent
= record
54 Sound
: TPlayableSound
;
55 Tags
: Array of String;
59 TPlayerSettings
= record
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures
: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
90 function g_Game_ModeToText(Mode
: Byte): string;
91 function g_Game_TextToMode(Mode
: string): Byte;
92 procedure g_Game_ExecuteEvent(Name
: String);
93 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
99 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
100 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
105 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
106 procedure g_Game_SaveOptions();
107 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath
: String);
109 procedure g_Game_ExitLevel(const Map
: AnsiString);
110 function g_Game_GetFirstMap(WAD
: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable
: Boolean);
114 procedure g_Game_HolmesPause(Enable
: Boolean);
115 procedure g_Game_InGameMenu(Show
: Boolean);
116 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
118 procedure g_Game_Message(Msg
: String; Time
: Word);
119 procedure g_Game_LoadMapList(FileName
: String);
120 procedure g_Game_PauseAllSounds(Enable
: Boolean);
121 procedure g_Game_StopAllSounds(all
: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
124 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
126 procedure g_Game_Announce_KillCombo(Param
: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
128 procedure g_Game_StartVote(Command
, Initiator
: string);
129 procedure g_Game_CheckVote
;
130 procedure g_TakeScreenShot();
131 procedure g_FatalError(Text: String);
132 procedure g_SimpleError(Text: String);
133 function g_Game_IsTestMap(): Boolean;
134 procedure g_Game_DeleteTestMap();
135 procedure GameCVars(P
: SSArray
);
136 procedure GameCommands(P
: SSArray
);
137 procedure GameCheats(P
: SSArray
);
138 procedure DebugCommands(P
: SSArray
);
139 procedure g_Game_Process_Params
;
140 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
141 procedure g_Game_StepLoading(Value
: Integer = -1);
142 procedure g_Game_ClearLoading();
143 procedure g_Game_SetDebugMode();
144 procedure DrawLoadingStat();
146 { procedure SetWinPause(Enable: Boolean); }
151 LOADING_SHOW_STEP
= 100;
152 LOADING_INTERLINE
= 20;
167 MESSAGE_DIKEY
= WM_USER
+ 1;
172 EXIT_ENDLEVELSINGLE
= 4;
173 EXIT_ENDLEVELCUSTOM
= 5;
175 GAME_OPTION_RESERVED
= 1;
176 GAME_OPTION_TEAMDAMAGE
= 2;
177 GAME_OPTION_ALLOWEXIT
= 4;
178 GAME_OPTION_WEAPONSTAY
= 8;
179 GAME_OPTION_MONSTERS
= 16;
180 GAME_OPTION_BOTVSPLAYER
= 32;
181 GAME_OPTION_BOTVSMONSTER
= 64;
186 STATE_INTERCUSTOM
= 3;
187 STATE_INTERSINGLE
= 4;
193 LMS_RESPAWN_NONE
= 0;
194 LMS_RESPAWN_WARMUP
= 1;
195 LMS_RESPAWN_FINAL
= 2;
212 CONFIG_FILENAME
= 'Doom2DF.cfg';
213 LOG_FILENAME
= 'Doom2DF.log';
215 TEST_MAP_NAME
= '$$$_TEST_$$$';
217 STD_PLAYER_MODEL
= 'Doomer';
221 gGameSettings
: TGameSettings
;
222 gPlayer1Settings
: TPlayerSettings
;
223 gPlayer2Settings
: TPlayerSettings
;
225 gPlayerScreenSize
: TDFPoint
;
226 gPlayer1ScreenCoord
: TDFPoint
;
227 gPlayer2ScreenCoord
: TDFPoint
;
228 gPlayer1
: TPlayer
= nil;
229 gPlayer2
: TPlayer
= nil;
230 gPlayerDrawn
: TPlayer
= nil;
232 gSwitchGameMode
: Byte = GM_DM
;
233 gHearPoint1
, gHearPoint2
: THearPoint
;
234 gSoundEffectsDF
: Boolean = False;
235 gSoundTriggerTime
: Word = 0;
236 gAnnouncer
: Byte = ANNOUNCE_NONE
;
237 goodsnd
: array[0..3] of TPlayableSound
;
238 killsnd
: array[0..3] of TPlayableSound
;
239 hahasnd
: array[0..2] of TPlayableSound
;
240 sound_get_flag
: array[0..1] of TPlayableSound
;
241 sound_lost_flag
: array[0..1] of TPlayableSound
;
242 sound_ret_flag
: array[0..1] of TPlayableSound
;
243 sound_cap_flag
: array[0..1] of TPlayableSound
;
244 gBodyKillEvent
: Integer = -1;
245 gDefInterTime
: ShortInt = -1;
246 gInterEndTime
: LongWord = 0;
247 gInterTime
: LongWord = 0;
248 gServInterTime
: Byte = 0;
249 gGameStartTime
: LongWord = 0;
250 gTotalMonsters
: Integer = 0;
251 gPauseMain
: Boolean = false;
252 gPauseHolmes
: Boolean = false;
253 gShowTime
: Boolean = True;
254 gShowFPS
: Boolean = False;
255 gShowGoals
: Boolean = True;
256 gShowStat
: Boolean = True;
257 gShowKillMsg
: Boolean = True;
258 gShowLives
: Boolean = True;
259 gShowPing
: Boolean = False;
260 gShowMap
: Boolean = False;
262 gState
: Byte = STATE_NONE
;
264 sWidth
, sHeight
: Word;
265 gSpectMode
: Byte = SPECT_NONE
;
266 gSpectHUD
: Boolean = True;
267 gSpectKeyPress
: Boolean = False;
268 gSpectX
: Integer = 0;
269 gSpectY
: Integer = 0;
270 gSpectStep
: Byte = 8;
271 gSpectViewTwo
: Boolean = False;
272 gSpectPID1
: Integer = -1;
273 gSpectPID2
: Integer = -1;
274 gSpectAuto
: Boolean = False;
275 gSpectAutoNext
: LongWord;
276 gSpectAutoStepX
: Integer;
277 gSpectAutoStepY
: Integer;
278 gMusic
: TMusic
= nil;
279 gLoadGameMode
: Boolean;
280 gCheats
: Boolean = False;
281 gMapOnce
: Boolean = False;
282 gMapToDelete
: String;
283 gTempDelete
: Boolean = False;
284 gLastMap
: Boolean = False;
285 gWinPosX
, gWinPosY
: Integer;
286 gWinSizeX
, gWinSizeY
: Integer;
287 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
288 gWinActive
: Boolean = True; // by default window is active, lol
289 gResolutionChange
: Boolean = False;
290 gRC_Width
, gRC_Height
: Word;
291 gRC_FullScreen
, gRC_Maximized
: Boolean;
292 gLanguageChange
: Boolean = False;
293 gDebugMode
: Boolean = False;
294 g_debug_Sounds
: Boolean = False;
295 g_debug_Frames
: Boolean = False;
296 g_debug_WinMsgs
: Boolean = False;
297 g_debug_MonsterOff
: Boolean = False;
298 g_debug_BotAIOff
: Byte = 0;
299 g_debug_HealthBar
: Boolean = False;
300 g_Debug_Player
: Boolean = False;
301 gCoopMonstersKilled
: Word = 0;
302 gCoopSecretsFound
: Word = 0;
303 gCoopTotalMonstersKilled
: Word = 0;
304 gCoopTotalSecretsFound
: Word = 0;
305 gCoopTotalMonsters
: Word = 0;
306 gCoopTotalSecrets
: Word = 0;
307 gStatsOff
: Boolean = False;
308 gStatsPressed
: Boolean = False;
309 gExitByTrigger
: Boolean = False;
310 gNextMap
: String = '';
311 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
312 gLMSRespawnTime
: Cardinal = 0;
313 gLMSSoftSpawn
: Boolean = False;
314 gMissionFailed
: Boolean = False;
315 gVoteInProgress
: Boolean = False;
316 gVotePassed
: Boolean = False;
317 gVoteCommand
: string = '';
318 gVoteTimer
: Cardinal = 0;
319 gVoteCmdTimer
: Cardinal = 0;
320 gVoteCount
: Integer = 0;
321 gVoteTimeout
: Cardinal = 30;
322 gVoted
: Boolean = False;
323 gVotesEnabled
: Boolean = True;
324 gEvents
: Array of TGameEvent
;
325 gDelayedEvents
: Array of TDelayedEvent
;
326 gUseChatSounds
: Boolean = True;
327 gChatSounds
: Array of TChatSound
;
328 gSelectWeapon
: Array [0..1] of Integer = (-1, -1); // [player]
330 g_dbg_ignore_bounds
: Boolean = false;
331 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
332 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
334 // move button values:
335 // bits 0-1: l/r state:
336 // 0: neither left, nor right pressed
339 // bits 4-5: l/r state when strafe was pressed
340 P1MoveButton
: Byte = 0;
341 P2MoveButton
: Byte = 0;
343 g_profile_frame_update
: Boolean = false;
344 g_profile_frame_draw
: Boolean = false;
345 g_profile_collision
: Boolean = false;
346 g_profile_los
: Boolean = false;
347 g_profile_history_size
: Integer = 1000;
349 g_rlayer_back
: Boolean = true;
350 g_rlayer_step
: Boolean = true;
351 g_rlayer_wall
: Boolean = true;
352 g_rlayer_door
: Boolean = true;
353 g_rlayer_acid1
: Boolean = true;
354 g_rlayer_acid2
: Boolean = true;
355 g_rlayer_water
: Boolean = true;
356 g_rlayer_fore
: Boolean = true;
359 procedure g_ResetDynlights ();
360 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
361 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
363 function conIsCheatsEnabled (): Boolean; inline;
364 function gPause (): Boolean; inline;
370 {$INCLUDE ../nogl/noGLuses.inc}
371 {$IFDEF ENABLE_HOLMES}
374 e_texture
, g_textures
, g_main
, g_window
, g_menu
,
375 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
376 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
377 g_triggers
, g_monsters
, e_sound
, CONFIG
,
379 ENet
, e_msg
, g_netmsg
, g_netmaster
,
384 hasPBarGfx
: Boolean = false;
387 // ////////////////////////////////////////////////////////////////////////// //
388 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
391 // ////////////////////////////////////////////////////////////////////////// //
392 function conIsCheatsEnabled (): Boolean; inline;
395 if g_Game_IsNet
then exit
;
396 if not gDebugMode
then
398 //if not gCheats then exit;
399 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
400 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
406 // ////////////////////////////////////////////////////////////////////////// //
408 profileFrameDraw
: TProfiler
= nil;
411 // ////////////////////////////////////////////////////////////////////////// //
414 x
, y
, radius
: Integer;
417 exploRadius
: Integer;
421 g_dynLights
: array of TDynLight
= nil;
422 g_dynLightCount
: Integer = 0;
423 g_playerLight
: Boolean = false;
425 procedure g_ResetDynlights ();
429 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
431 for idx
:= 0 to g_dynLightCount
-1 do
433 if g_dynLights
[idx
].exploCount
= -666 then
440 Inc(g_dynLights
[idx
].exploCount
);
441 if (g_dynLights
[idx
].exploCount
< 10) then
443 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
444 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
445 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
446 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
451 g_dynLightCount
:= lnum
;
454 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
456 if not gwin_has_stencil
then exit
;
457 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
458 g_dynLights
[g_dynLightCount
].x
:= x
;
459 g_dynLights
[g_dynLightCount
].y
:= y
;
460 g_dynLights
[g_dynLightCount
].radius
:= radius
;
461 g_dynLights
[g_dynLightCount
].r
:= r
;
462 g_dynLights
[g_dynLightCount
].g
:= g
;
463 g_dynLights
[g_dynLightCount
].b
:= b
;
464 g_dynLights
[g_dynLightCount
].a
:= a
;
465 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
466 Inc(g_dynLightCount
);
469 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
471 if not gwin_has_stencil
then exit
;
472 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
473 g_dynLights
[g_dynLightCount
].x
:= x
;
474 g_dynLights
[g_dynLightCount
].y
:= y
;
475 g_dynLights
[g_dynLightCount
].radius
:= 0;
476 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
477 g_dynLights
[g_dynLightCount
].r
:= r
;
478 g_dynLights
[g_dynLightCount
].g
:= g
;
479 g_dynLights
[g_dynLightCount
].b
:= b
;
480 g_dynLights
[g_dynLightCount
].a
:= 0;
481 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
482 Inc(g_dynLightCount
);
486 // ////////////////////////////////////////////////////////////////////////// //
487 function calcProfilesHeight (prof
: TProfiler
): Integer;
490 if (prof
= nil) then exit
;
491 if (length(prof
.bars
) = 0) then exit
;
492 result
:= length(prof
.bars
)*(16+2);
496 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
503 if (prof
= nil) then exit
;
505 if (length(prof
.bars
) = 0) then exit
;
507 hgt
:= calcProfilesHeight(prof
);
508 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
509 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
511 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
512 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
513 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
516 for ii
:= 0 to High(prof
.bars
) do
518 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);
525 // ////////////////////////////////////////////////////////////////////////// //
527 TEndCustomGameStat
= record
528 PlayerStat
: TPlayerStatArray
;
532 Map
, MapName
: String;
535 TEndSingleGameStat
= record
536 PlayerStat
: Array [0..1] of record
542 TotalSecrets
: Integer;
545 TLoadingStat
= record
549 Msgs
: Array of String;
551 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
554 TParamStrValue
= record
559 TParamStrValues
= Array of TParamStrValue
;
562 INTER_ACTION_TEXT
= 1;
563 INTER_ACTION_PIC
= 2;
564 INTER_ACTION_MUSIC
= 3;
568 FPSCounter
, UPSCounter
: Word;
569 FPSTime
, UPSTime
: LongWord;
570 DataLoaded
: Boolean = False;
571 IsDrawStat
: Boolean = False;
572 CustomStat
: TEndCustomGameStat
;
573 SingleStat
: TEndSingleGameStat
;
574 LoadingStat
: TLoadingStat
;
575 EndingGameCounter
: Byte = 0;
578 MessageLineLength
: Integer = 80;
579 MapList
: SSArray
= nil;
580 MapIndex
: Integer = -1;
586 text: Array of ShortString;
587 anim
: Array of ShortString;
588 pic
: Array of ShortString;
589 mus
: Array of ShortString;
591 triggers
: Array of record
593 actions
: Array of record
594 action
, p1
, p2
: Integer;
597 cur_trigger
: Integer;
610 function Compare(a
, b
: TPlayerStat
): Integer;
612 if a
.Spectator
then Result
:= 1
613 else if b
.Spectator
then Result
:= -1
614 else if a
.Frags
< b
.Frags
then Result
:= 1
615 else if a
.Frags
> b
.Frags
then Result
:= -1
616 else if a
.Deaths
< b
.Deaths
then Result
:= -1
617 else if a
.Deaths
> b
.Deaths
then Result
:= 1
618 else if a
.Kills
< b
.Kills
then Result
:= -1
622 procedure SortGameStat(var stat
: TPlayerStatArray
);
627 if stat
= nil then Exit
;
629 for I
:= High(stat
) downto Low(stat
) do
630 for J
:= Low(stat
) to High(stat
) - 1 do
631 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
634 stat
[J
] := stat
[J
+ 1];
639 function g_Game_ModeToText(Mode
: Byte): string;
643 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
644 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
645 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
646 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
647 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
651 function g_Game_TextToMode(Mode
: string): Byte;
654 Mode
:= UpperCase(Mode
);
655 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
660 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
665 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
670 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
675 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
682 function g_Game_IsNet(): Boolean;
684 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
687 function g_Game_IsServer(): Boolean;
689 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
692 function g_Game_IsClient(): Boolean;
694 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
697 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
704 Result
.name
:= ExtractFileName(WAD
);
705 Result
.description
:= '';
708 w
:= TWADFile
.Create();
711 if not w
.GetResource('INTERSCRIPT', p
, len
) then
717 cfg
:= TConfig
.CreateMem(p
, len
);
718 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
719 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
720 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
721 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
727 procedure g_Game_FreeWAD();
731 for a
:= 0 to High(MegaWAD
.res
.pic
) do
732 if MegaWAD
.res
.pic
[a
] <> '' then
733 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
735 for a
:= 0 to High(MegaWAD
.res
.mus
) do
736 if MegaWAD
.res
.mus
[a
] <> '' then
737 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
739 MegaWAD
.res
.pic
:= nil;
740 MegaWAD
.res
.text := nil;
741 MegaWAD
.res
.anim
:= nil;
742 MegaWAD
.res
.mus
:= nil;
743 MegaWAD
.triggers
:= nil;
745 g_Texture_Delete('TEXTURE_endpic');
746 g_Sound_Delete('MUSIC_endmus');
748 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
749 gGameSettings
.WAD
:= '';
752 procedure g_Game_LoadWAD(WAD
: string);
761 gGameSettings
.WAD
:= WAD
;
762 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
765 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
767 w
:= TWADFile
.Create();
768 w
.ReadFile(MapsDir
+ WAD
);
770 if not w
.GetResource('INTERSCRIPT', p
, len
) then
776 cfg
:= TConfig
.CreateMem(p
, len
);
781 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
782 if s = '' then Break;
785 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
786 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
788 g_Texture_CreateWADEx(s, s);
794 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
795 if s = '' then Break;
798 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
799 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
801 g_Music_CreateWADEx(s, s);
804 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
805 if MegaWAD
.endpic
<> '' then
807 s
:= g_ExtractWadName(MegaWAD
.endpic
);
808 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
809 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
811 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
812 if MegaWAD
.endmus
<> '' then
814 s
:= g_ExtractWadName(MegaWAD
.endmus
);
815 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
816 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
824 {procedure start_trigger(t: string);
828 function next_trigger(): Boolean;
832 procedure DisableCheats();
838 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
839 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
840 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
841 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
843 {$IF DEFINED(D2F_DEBUG)}
844 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
845 gAimLine
:= g_dbg_aimline_on
;
849 procedure g_Game_ExecuteEvent(Name
: String);
855 if gEvents
= nil then
857 for a
:= 0 to High(gEvents
) do
858 if gEvents
[a
].Name
= Name
then
860 if gEvents
[a
].Command
<> '' then
861 g_Console_Process(gEvents
[a
].Command
, True);
866 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
871 if gDelayedEvents
<> nil then
872 for a
:= 0 to High(gDelayedEvents
) do
873 if not gDelayedEvents
[a
].Pending
then
880 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
881 n
:= High(gDelayedEvents
);
883 gDelayedEvents
[n
].Pending
:= True;
884 gDelayedEvents
[n
].DEType
:= DEType
;
885 gDelayedEvents
[n
].DENum
:= Num
;
886 gDelayedEvents
[n
].DEStr
:= Str
;
887 if DEType
= DE_GLOBEVENT
then
888 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
890 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
899 if g_Game_IsNet
and g_Game_IsServer
then
900 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
904 gPauseHolmes
:= false;
907 g_Game_StopAllSounds(False);
912 EndingGameCounter
:= 0;
913 g_ActiveWindow
:= nil;
915 gLMSRespawn
:= LMS_RESPAWN_NONE
;
916 gLMSRespawnTime
:= 0;
919 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
924 begin // Ýòî áûë òåñò
928 begin // Âûõîä â ãëàâíîå ìåíþ
929 gMusic
.SetByName('MUSIC_MENU');
931 if gState
<> STATE_SLIST
then
933 g_GUI_ShowWindow('MainMenu');
934 gState
:= STATE_MENU
;
937 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
938 slReturnPressed
:= True;
939 if g_Net_Slist_Fetch(slCurrent
) then
941 if slCurrent
= nil then
942 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
945 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
946 g_Serverlist_GenerateTable(slCurrent
, slTable
);
949 g_Game_ExecuteEvent('ongameend');
953 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
955 if not g_Game_IsClient
then g_Game_Restart();
958 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
960 // Ñòàòèñòèêà Ñâîåé èãðû:
961 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
963 CustomStat
.GameTime
:= gTime
;
964 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
965 CustomStat
.MapName
:= gMapInfo
.Name
;
966 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
967 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
968 CustomStat
.TeamStat
:= gTeamStat
;
970 CustomStat
.PlayerStat
:= nil;
972 // Ñòàòèñòèêà èãðîêîâ:
973 if gPlayers
<> nil then
975 for a
:= 0 to High(gPlayers
) do
976 if gPlayers
[a
] <> nil then
978 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
979 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
981 Name
:= gPlayers
[a
].Name
;
982 Frags
:= gPlayers
[a
].Frags
;
983 Deaths
:= gPlayers
[a
].Death
;
984 Kills
:= gPlayers
[a
].Kills
;
985 Team
:= gPlayers
[a
].Team
;
986 Color
:= gPlayers
[a
].Model
.Color
;
987 Spectator
:= gPlayers
[a
].FSpectator
;
991 SortGameStat(CustomStat
.PlayerStat
);
994 g_Game_ExecuteEvent('onmapend');
997 EndingGameCounter
:= 255;
998 gState
:= STATE_FOLD
;
1000 if gDefInterTime
< 0 then
1001 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1003 gInterEndTime
:= gDefInterTime
* 1000;
1006 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1008 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1009 SingleStat
.GameTime
:= gTime
;
1010 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1011 SingleStat
.TotalSecrets
:= gSecretsCount
;
1012 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1013 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1014 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1015 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1016 if SingleStat
.TwoPlayers
then
1018 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1019 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1022 g_Game_ExecuteEvent('onmapend');
1025 if gNextMap
<> '' then
1027 gMusic
.SetByName('MUSIC_INTERMUS');
1029 gState
:= STATE_INTERSINGLE
;
1032 g_Game_ExecuteEvent('oninter');
1034 else // Áîëüøå íåò êàðò
1036 // Çàòóõàþùèé ýêðàí:
1037 EndingGameCounter
:= 255;
1038 gState
:= STATE_FOLD
;
1043 // Îêîí÷àíèå îáðàáîòàíî:
1044 if gExit
<> EXIT_QUIT
then
1048 procedure drawTime(X
, Y
: Integer); inline;
1050 e_TextureFontPrint(x
, y
,
1051 Format('%d:%.2d:%.2d', [
1052 gTime
div 1000 div 3600,
1053 (gTime
div 1000 div 60) mod 60,
1054 gTime
div 1000 mod 60
1059 procedure DrawStat();
1061 pc
, x
, y
, w
, h
: Integer;
1062 w1
, w2
, w3
, w4
: Integer;
1064 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1067 stat
: TPlayerStatArray
;
1074 pc
:= g_Player_GetCount
;
1075 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1077 w
:= gScreenWidth
-(gScreenWidth
div 5);
1078 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1081 h
:= 40+ch
*5+(ch
+8)*pc
;
1082 x
:= (gScreenWidth
div 2)-(w
div 2);
1083 y
:= (gScreenHeight
div 2)-(h
div 2);
1085 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1086 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1088 drawTime(x
+w
-78, y
+8);
1090 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1091 map
:= g_ExtractFileName(gMapInfo
.Map
);
1092 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1094 case gGameSettings
.GameMode
of
1097 if gGameSettings
.MaxLives
= 0 then
1098 s1
:= _lc
[I_GAME_DM
]
1100 s1
:= _lc
[I_GAME_LMS
];
1101 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1102 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1107 if gGameSettings
.MaxLives
= 0 then
1108 s1
:= _lc
[I_GAME_TDM
]
1110 s1
:= _lc
[I_GAME_TLMS
];
1111 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1112 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1117 s1
:= _lc
[I_GAME_CTF
];
1118 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1119 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1124 if gGameSettings
.MaxLives
= 0 then
1125 s1
:= _lc
[I_GAME_COOP
]
1127 s1
:= _lc
[I_GAME_SURV
];
1128 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1129 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1140 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1142 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1144 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1146 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1147 gStdFont
, 200, 200, 200, 1);
1149 if NetMode
= NET_SERVER
then
1150 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1152 if NetMode
= NET_CLIENT
then
1153 e_TextureFontPrintEx(x
+8, y
+ 8,
1154 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1158 stat
:= g_Player_GetStats();
1161 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1162 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1164 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1166 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1170 for a
:= TEAM_RED
to TEAM_BLUE
do
1172 if a
= TEAM_RED
then
1174 s1
:= _lc
[I_GAME_TEAM_RED
];
1181 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1187 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1188 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1189 gStdFont
, r
, g
, b
, 1);
1191 _y
:= _y
+ch
+(ch
div 4);
1192 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1193 _y
:= _y
+(ch
div 4);
1195 for aa
:= 0 to High(stat
) do
1196 if stat
[aa
].Team
= a
then
1212 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1214 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1216 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1218 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1225 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1228 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1229 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1230 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1231 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1234 for aa
:= 0 to High(stat
) do
1248 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1249 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1251 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1253 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1255 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1257 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1263 procedure g_Game_Init();
1269 gTempDelete
:= False;
1271 sfsGCDisable(); // temporary disable removing of temporary volumes
1274 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1275 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1276 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1277 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1279 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1280 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1281 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1283 g_Game_ClearLoading();
1284 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1285 g_Game_SetLoadingText('', 0, False);
1287 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1290 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1291 g_PlayerModel_LoadData();
1293 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1295 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1296 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1297 until FindNext(SR
) <> 0;
1300 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1302 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1303 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1304 until FindNext(SR
) <> 0;
1307 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1309 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1310 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1311 until FindNext(SR
) <> 0;
1315 gPauseMain
:= false;
1316 gPauseHolmes
:= false;
1319 {e_MouseInfo.Accel := 1.0;}
1321 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1324 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1325 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1326 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1327 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1328 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1330 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1333 gMusic
:= TMusic
.Create();
1334 gMusic
.SetByName('MUSIC_MENU');
1337 gGameSettings
.WarmupTime
:= 30;
1339 gState
:= STATE_MENU
;
1341 SetLength(gEvents
, 6);
1342 gEvents
[0].Name
:= 'ongamestart';
1343 gEvents
[1].Name
:= 'ongameend';
1344 gEvents
[2].Name
:= 'onmapstart';
1345 gEvents
[3].Name
:= 'onmapend';
1346 gEvents
[4].Name
:= 'oninter';
1347 gEvents
[5].Name
:= 'onwadend';
1349 sfsGCEnable(); // enable releasing unused volumes
1353 procedure g_Game_Free(freeTextures
: Boolean=true);
1355 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1356 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1358 g_Map_Free(freeTextures
);
1360 g_Player_RemoveAllCorpses();
1362 gGameSettings
.GameType
:= GT_NONE
;
1363 if gGameSettings
.GameMode
= GM_SINGLE
then
1364 gGameSettings
.GameMode
:= GM_DM
;
1365 gSwitchGameMode
:= gGameSettings
.GameMode
;
1368 gExitByTrigger
:= False;
1371 function IsActivePlayer(p
: TPlayer
): Boolean;
1376 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1379 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1386 if gPlayers
= nil then
1388 for a
:= Low(gPlayers
) to High(gPlayers
) do
1389 if IsActivePlayer(gPlayers
[a
]) then
1391 if gPlayers
[a
].UID
<> ID
then
1393 Result
:= gPlayers
[a
];
1398 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1404 if gPlayers
= nil then
1408 for a
:= Low(gPlayers
) to High(gPlayers
) do
1409 if IsActivePlayer(gPlayers
[a
]) then
1411 SetLength(ids
, Length(ids
) + 1);
1412 ids
[High(ids
)] := gPlayers
[a
].UID
;
1413 if gPlayers
[a
].UID
= Skip
then
1416 if Length(ids
) = 0 then
1421 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1424 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1430 if gPlayers
= nil then
1434 for a
:= Low(gPlayers
) to High(gPlayers
) do
1435 if IsActivePlayer(gPlayers
[a
]) then
1437 SetLength(ids
, Length(ids
) + 1);
1438 ids
[High(ids
)] := gPlayers
[a
].UID
;
1439 if gPlayers
[a
].UID
= Skip
then
1442 if Length(ids
) = 0 then
1445 Result
:= ids
[Length(ids
) - 1]
1447 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1450 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1456 if gPlayers
= nil then
1460 for a
:= Low(gPlayers
) to High(gPlayers
) do
1461 if IsActivePlayer(gPlayers
[a
]) then
1463 SetLength(ids
, Length(ids
) + 1);
1464 ids
[High(ids
)] := gPlayers
[a
].UID
;
1465 if gPlayers
[a
].UID
= Skip
then
1468 if Length(ids
) = 0 then
1470 if Length(ids
) = 1 then
1475 Result
:= ids
[Random(Length(ids
))];
1477 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1479 Result
:= ids
[Random(Length(ids
))];
1484 function GetRandomSpectMode(Current
: Byte): Byte;
1491 0: Result
:= SPECT_STATS
;
1492 1: Result
:= SPECT_MAPVIEW
;
1493 2: Result
:= SPECT_MAPVIEW
;
1494 3: Result
:= SPECT_PLAYERS
;
1495 4: Result
:= SPECT_PLAYERS
;
1496 5: Result
:= SPECT_PLAYERS
;
1497 6: Result
:= SPECT_PLAYERS
;
1499 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1503 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1508 if (plr
= nil) then exit
;
1509 if (p
= 2) then time
:= 1000 else time
:= 1;
1510 strafeDir
:= MoveButton
shr 4;
1511 MoveButton
:= MoveButton
and $0F;
1513 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1514 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1515 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1516 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1517 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1518 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1520 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1521 if MoveButton
= 1 then
1522 plr
.PressKey(KEY_LEFT
, time
)
1523 else if MoveButton
= 2 then
1524 plr
.PressKey(KEY_RIGHT
, time
);
1526 // if we have "strafe" key, turn off old strafe mechanics
1527 if gPlayerAction
[p
, ACTION_STRAFE
] then
1529 // new strafe mechanics
1530 if (strafeDir
= 0) then
1531 strafeDir
:= MoveButton
; // start strafing
1532 // now set direction according to strafe (reversed)
1533 if (strafeDir
= 2) then
1534 plr
.SetDirection(TDirection
.D_LEFT
)
1535 else if (strafeDir
= 1) then
1536 plr
.SetDirection(TDirection
.D_RIGHT
)
1540 strafeDir
:= 0; // not strafing anymore
1541 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1542 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1543 plr
.SetDirection(TDirection
.D_LEFT
)
1544 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1545 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1546 plr
.SetDirection(TDirection
.D_RIGHT
)
1547 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1548 else if MoveButton
<> 0 then
1549 plr
.SetDirection(TDirection(MoveButton
-1))
1552 // fix movebutton state
1553 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1555 // Îñòàëüíûå êëàâèøè:
1556 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1557 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1558 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1559 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1560 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1561 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1562 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1564 if gSelectWeapon
[p
] >= 0 then
1566 plr
.QueueWeaponSwitch(gSelectWeapon
[p
]);
1567 gSelectWeapon
[p
] := -1
1570 // HACK: add dynlight here
1571 if gwin_k8_enable_light_experiments
then
1573 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1575 g_playerLight
:= true;
1577 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1579 g_playerLight
:= false;
1583 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1586 procedure g_Game_Update();
1588 Msg
: g_gui
.TMessage
;
1594 function sendMonsPos (mon
: TMonster
): Boolean;
1596 result
:= false; // don't stop
1597 // this will also reset "need-send" flag
1598 if mon
.gncNeedSend
then
1600 MH_SEND_MonsterPos(mon
.UID
);
1602 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1604 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1606 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1608 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1612 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1614 result
:= false; // don't stop
1615 // this will also reset "need-send" flag
1616 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1620 reliableUpdate
: Boolean;
1625 // Ïîðà âûêëþ÷àòü èãðó:
1626 if gExit
= EXIT_QUIT
then
1628 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1632 if gExit
= EXIT_QUIT
then
1636 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1637 // no need to, as we'll do it in event handler
1639 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1642 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1644 gExit
:= EXIT_SIMPLE
;
1650 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1651 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1652 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1653 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1655 if g_Game_IsNet
and g_Game_IsServer
then
1657 gInterTime
:= gInterTime
+ GAME_TICK
;
1658 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1659 if a
<> gServInterTime
then
1661 gServInterTime
:= a
;
1662 MH_SEND_TimeSync(gServInterTime
);
1666 if (not g_Game_IsClient
) and
1670 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1671 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1672 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1673 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1675 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1676 and (g_ActiveWindow
= nil)
1678 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1681 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1682 g_Game_StopAllSounds(True);
1684 if gMapOnce
then // Ýòî áûë òåñò
1685 gExit
:= EXIT_SIMPLE
1687 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1688 g_Game_ChangeMap(gNextMap
)
1689 else // Ñëåäóþùåé êàðòû íåò
1691 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1693 // Âûõîä â ãëàâíîå ìåíþ:
1695 g_GUI_ShowWindow('MainMenu');
1696 gMusic
.SetByName('MUSIC_MENU');
1698 gState
:= STATE_MENU
;
1701 // Ôèíàëüíàÿ êàðòèíêà:
1702 g_Game_ExecuteEvent('onwadend');
1704 if not gMusic
.SetByName('MUSIC_endmus') then
1705 gMusic
.SetByName('MUSIC_STDENDMUS');
1707 gState
:= STATE_ENDPIC
;
1709 g_Game_ExecuteEvent('ongameend');
1715 if gState
= STATE_INTERTEXT
then
1716 if InterText
.counter
> 0 then
1717 InterText
.counter
:= InterText
.counter
- 1;
1720 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1722 if EndingGameCounter
= 0 then
1724 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1725 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1727 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1729 g_Game_ExecuteEvent('onwadend');
1730 if not gMusic
.SetByName('MUSIC_endmus') then
1731 gMusic
.SetByName('MUSIC_STDENDMUS');
1734 gMusic
.SetByName('MUSIC_ROUNDMUS');
1737 gState
:= STATE_INTERCUSTOM
;
1740 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1742 gMusic
.SetByName('MUSIC_INTERMUS');
1744 gState
:= STATE_INTERSINGLE
;
1747 g_Game_ExecuteEvent('oninter');
1750 DecMin(EndingGameCounter
, 6, 0);
1753 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1755 if gMapOnce
then // Ýòî áûë òåñò
1757 gExit
:= EXIT_SIMPLE
;
1763 g_Serverlist_Control(slCurrent
, slTable
);
1766 // Ñòàòèñòèêà ïî Tab:
1768 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1771 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1773 // Âðåìÿ += 28 ìèëëèñåêóíä:
1774 gTime
:= gTime
+ GAME_TICK
;
1776 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1777 if MessageTime
= 0 then
1779 if MessageTime
> 0 then
1780 MessageTime
:= MessageTime
- 1;
1782 if (g_Game_IsServer
) then
1784 // Áûë çàäàí ëèìèò âðåìåíè:
1785 if (gGameSettings
.TimeLimit
> 0) then
1786 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1787 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1792 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1793 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1794 g_Game_RestartRound(gLMSSoftSpawn
);
1796 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1797 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1799 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1801 g_Console_Process(gVoteCommand
);
1803 gVotePassed
:= False;
1806 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1807 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1808 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1809 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1810 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1812 // Áûë çàäàí ëèìèò ïîáåä:
1813 if (gGameSettings
.GoalLimit
> 0) then
1817 if gGameSettings
.GameMode
= GM_DM
then
1818 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1819 for i
:= 0 to High(gPlayers
) do
1820 if gPlayers
[i
] <> nil then
1821 if gPlayers
[i
].Frags
> b
then
1822 b
:= gPlayers
[i
].Frags
;
1825 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1826 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1827 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1830 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1831 if b
>= gGameSettings
.GoalLimit
then
1838 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1839 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1840 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1841 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1843 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1844 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1845 end // if not console
1848 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1850 // process weapon switch queue
1854 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1855 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1857 if not gSpectKeyPress
then
1859 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1861 // switch spect mode
1863 SPECT_NONE
: ; // not spectator
1865 SPECT_MAPVIEW
: Inc(gSpectMode
);
1866 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1868 gSpectKeyPress
:= True;
1870 if (gSpectMode
= SPECT_MAPVIEW
)
1871 and (not gSpectAuto
) then
1873 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1874 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1875 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1876 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1877 if gPlayerAction
[0, ACTION_LOOKUP
] then
1878 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1879 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1880 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1881 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1884 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1885 gSpectKeyPress
:= True;
1887 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1890 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1891 gSpectKeyPress
:= True;
1894 if (gSpectMode
= SPECT_PLAYERS
)
1895 and (not gSpectAuto
) then
1897 if gPlayerAction
[0, ACTION_LOOKUP
] then
1900 gSpectViewTwo
:= True;
1901 gSpectKeyPress
:= True;
1903 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1905 // remove second view
1906 gSpectViewTwo
:= False;
1907 gSpectKeyPress
:= True;
1909 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1911 // prev player (view 1)
1912 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1913 gSpectKeyPress
:= True;
1915 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1917 // next player (view 1)
1918 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1919 gSpectKeyPress
:= True;
1921 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1923 // prev player (view 2)
1924 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1925 gSpectKeyPress
:= True;
1927 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1929 // next player (view 2)
1930 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1931 gSpectKeyPress
:= True;
1934 if gPlayerAction
[0, ACTION_ATTACK
] then
1936 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1939 gSpectAutoNext
:= 0;
1940 gSpectViewTwo
:= False;
1941 gSpectKeyPress
:= True;
1946 gSpectMode
:= SPECT_STATS
;
1947 gSpectAuto
:= False;
1948 gSpectKeyPress
:= True;
1953 if (not gPlayerAction
[0, ACTION_JUMP
]) and
1954 (not gPlayerAction
[0, ACTION_ATTACK
]) and
1955 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
1956 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
1957 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
1958 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
1959 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
1960 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
1961 gSpectKeyPress
:= False;
1965 if gSpectMode
= SPECT_MAPVIEW
then
1967 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
1969 gSpectAutoNext
:= gTime
1972 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
1974 gSpectAutoNext
:= gTime
1978 if gSpectAutoNext
<= gTime
then
1980 if gSpectAutoNext
> 0 then
1982 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
1986 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
1987 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
1988 gSpectAutoStepX
:= Random(9) - 4;
1989 gSpectAutoStepY
:= Random(9) - 4;
1990 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
1991 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
1992 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
1993 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
1994 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
1995 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
1999 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2004 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2005 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2006 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2012 // Îáíîâëÿåì âñå îñòàëüíîå:
2015 g_Triggers_Update();
2017 g_Monsters_Update();
2019 g_Player_UpdateAll();
2020 g_Player_UpdatePhysicalObjects();
2022 // server: send newly spawned monsters unconditionally
2023 if (gGameSettings
.GameType
= GT_SERVER
) then
2025 if (Length(gMonstersSpawned
) > 0) then
2027 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2028 SetLength(gMonstersSpawned
, 0);
2032 if (gSoundTriggerTime
> 8) then
2034 g_Game_UpdateTriggerSounds();
2035 gSoundTriggerTime
:= 0;
2039 Inc(gSoundTriggerTime
);
2042 if (NetMode
= NET_SERVER
) then
2044 Inc(NetTimeToUpdate
);
2045 Inc(NetTimeToReliable
);
2047 // send monster updates
2048 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2050 // send all monsters (periodic sync)
2051 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2053 for I
:= 0 to High(gPlayers
) do
2055 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2058 g_Mons_ForEach(sendMonsPos
);
2060 if reliableUpdate
then
2062 NetTimeToReliable
:= 0;
2063 NetTimeToUpdate
:= NetUpdateRate
;
2067 NetTimeToUpdate
:= 0;
2072 // send only mosters with some unexpected changes
2073 g_Mons_ForEach(sendMonsPosUnexpected
);
2076 // send unexpected platform changes
2077 g_Map_NetSendInterestingPanels();
2079 if NetUseMaster
then
2081 if gTime
>= NetTimeToMaster
then
2083 if (NetMHost
= nil) or (NetMPeer
= nil) then
2085 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
2089 NetTimeToMaster
:= gTime
+ NetMasterRate
;
2093 else if (NetMode
= NET_CLIENT
) then
2095 MC_SEND_PlayerPos();
2097 end; // if gameOn ...
2099 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2100 if g_ActiveWindow
<> nil then
2102 w
:= e_GetFirstKeyPressed();
2104 if (w
<> IK_INVALID
) then
2106 Msg
.Msg
:= MESSAGE_DIKEY
;
2108 g_ActiveWindow
.OnMessage(Msg
);
2111 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2112 if g_ActiveWindow
<> nil then
2113 g_ActiveWindow
.Update();
2115 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2116 if gResolutionChange
then
2118 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2119 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2120 gResolutionChange
:= False;
2121 g_ActiveWindow
:= nil;
2124 // Íóæíî ñìåíèòü ÿçûê:
2125 if gLanguageChange
then
2127 //e_WriteLog('Read language file', MSG_NOTIFY);
2128 //g_Language_Load(DataDir + gLanguage + '.txt');
2129 g_Language_Set(gLanguage
);
2131 gLanguageChange
:= False;
2135 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2136 if e_KeyPressed(IK_F10
) and
2138 (not gConsoleShow
) and
2139 (g_ActiveWindow
= nil) then
2144 Time
:= GetTimer() {div 1000};
2146 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2147 if gDelayedEvents
<> nil then
2148 for a
:= 0 to High(gDelayedEvents
) do
2149 if gDelayedEvents
[a
].Pending
and
2151 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2152 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2155 case gDelayedEvents
[a
].DEType
of
2157 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2160 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2164 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2165 if g_Game_IsNet
and g_Game_IsServer
then
2166 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2170 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2172 gDelayedEvents
[a
].Pending
:= False;
2175 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2176 UPSCounter
:= UPSCounter
+ 1;
2177 if Time
- UPSTime
>= 1000 then
2186 g_Weapon_AddDynLights();
2187 g_Items_AddDynLights();
2191 procedure g_Game_LoadChatSounds(Resource
: string);
2194 FileName
, Snd
: string;
2196 len
, cnt
, tags
, i
, j
: Integer;
2199 FileName
:= g_ExtractWadName(Resource
);
2201 WAD
:= TWADFile
.Create();
2202 WAD
.ReadFile(FileName
);
2204 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2211 cfg
:= TConfig
.CreateMem(p
, len
);
2212 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2214 SetLength(gChatSounds
, cnt
);
2215 for i
:= 0 to Length(gChatSounds
) - 1 do
2217 gChatSounds
[i
].Sound
:= nil;
2218 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2219 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2220 if (Snd
= '') or (Tags
<= 0) then
2222 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2223 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2224 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2225 SetLength(gChatSounds
[i
].Tags
, tags
);
2226 for j
:= 0 to tags
- 1 do
2227 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2228 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2235 procedure g_Game_FreeChatSounds();
2239 for i
:= 0 to Length(gChatSounds
) - 1 do
2241 gChatSounds
[i
].Sound
.Free();
2242 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2244 SetLength(gChatSounds
, 0);
2248 procedure g_Game_LoadData();
2255 if DataLoaded
then Exit
;
2257 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2259 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2260 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2261 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2262 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2263 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2264 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2265 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2266 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2267 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2268 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2269 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2270 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2271 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2272 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2273 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2276 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2277 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2278 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2279 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2283 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2284 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2285 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2286 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2287 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
2293 hasPBarGfx
:= false;
2297 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2298 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2299 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2300 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2301 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2302 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2303 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2304 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2305 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2306 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2307 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2308 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2309 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2310 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2311 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2312 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2313 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2314 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2315 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2316 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2317 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2318 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2319 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2320 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2321 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2322 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2323 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2324 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2325 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2326 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2327 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2328 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2329 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2330 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2331 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2332 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2333 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2334 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2335 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2337 goodsnd
[0] := TPlayableSound
.Create();
2338 goodsnd
[1] := TPlayableSound
.Create();
2339 goodsnd
[2] := TPlayableSound
.Create();
2340 goodsnd
[3] := TPlayableSound
.Create();
2342 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2343 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2344 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2345 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2347 killsnd
[0] := TPlayableSound
.Create();
2348 killsnd
[1] := TPlayableSound
.Create();
2349 killsnd
[2] := TPlayableSound
.Create();
2350 killsnd
[3] := TPlayableSound
.Create();
2352 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2353 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2354 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2355 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2357 hahasnd
[0] := TPlayableSound
.Create();
2358 hahasnd
[1] := TPlayableSound
.Create();
2359 hahasnd
[2] := TPlayableSound
.Create();
2361 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2362 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2363 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2365 sound_get_flag
[0] := TPlayableSound
.Create();
2366 sound_get_flag
[1] := TPlayableSound
.Create();
2367 sound_lost_flag
[0] := TPlayableSound
.Create();
2368 sound_lost_flag
[1] := TPlayableSound
.Create();
2369 sound_ret_flag
[0] := TPlayableSound
.Create();
2370 sound_ret_flag
[1] := TPlayableSound
.Create();
2371 sound_cap_flag
[0] := TPlayableSound
.Create();
2372 sound_cap_flag
[1] := TPlayableSound
.Create();
2374 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2375 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2376 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2377 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2378 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2379 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2380 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2381 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2383 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2385 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2388 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2389 g_Weapon_LoadData();
2391 g_Monsters_LoadData();
2396 procedure g_Game_FreeData();
2398 if not DataLoaded
then Exit
;
2401 g_Weapon_FreeData();
2402 g_Monsters_FreeData();
2404 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2406 g_Texture_Delete('NOTEXTURE');
2407 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2408 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2409 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2410 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2411 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2412 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2413 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2414 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2415 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2416 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2417 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2418 g_Frames_DeleteByName('FRAMES_TELEPORT');
2419 g_Frames_DeleteByName('FRAMES_PUNCH');
2420 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2421 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2422 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2423 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2424 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2425 g_Sound_Delete('SOUND_GAME_TELEPORT');
2426 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2427 g_Sound_Delete('SOUND_GAME_SECRET');
2428 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2429 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2430 g_Sound_Delete('SOUND_GAME_BULK1');
2431 g_Sound_Delete('SOUND_GAME_BULK2');
2432 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2433 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2434 g_Sound_Delete('SOUND_GAME_BURNING');
2435 g_Sound_Delete('SOUND_GAME_SWITCH1');
2436 g_Sound_Delete('SOUND_GAME_SWITCH0');
2443 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2444 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2445 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2446 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2453 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2454 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2455 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2456 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2462 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2463 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2464 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2466 sound_get_flag
[0].Free();
2467 sound_get_flag
[1].Free();
2468 sound_lost_flag
[0].Free();
2469 sound_lost_flag
[1].Free();
2470 sound_ret_flag
[0].Free();
2471 sound_ret_flag
[1].Free();
2472 sound_cap_flag
[0].Free();
2473 sound_cap_flag
[1].Free();
2475 g_Sound_Delete('SOUND_CTF_GET1');
2476 g_Sound_Delete('SOUND_CTF_GET2');
2477 g_Sound_Delete('SOUND_CTF_LOST1');
2478 g_Sound_Delete('SOUND_CTF_LOST2');
2479 g_Sound_Delete('SOUND_CTF_RETURN1');
2480 g_Sound_Delete('SOUND_CTF_RETURN2');
2481 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2482 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2484 g_Game_FreeChatSounds();
2486 DataLoaded
:= False;
2489 procedure DrawCustomStat();
2495 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2496 s1
, s2
, topstr
: String;
2498 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2500 g_ProcessMessages();
2502 if g_Console_Action(ACTION_SCORES
) then
2504 if not gStatsPressed
then
2506 gStatsOff
:= not gStatsOff
;
2507 gStatsPressed
:= True;
2511 gStatsPressed
:= False;
2515 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2516 w
:= (Length(s1
) * ww2
) div 2;
2517 x
:= gScreenWidth
div 2 - w
;
2519 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2523 if (gGameSettings
.GameMode
= GM_COOP
) then
2525 if gMissionFailed
then
2526 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2528 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2531 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2533 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2534 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2536 if g_Game_IsNet
then
2538 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2539 if not gChatShow
then
2540 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2541 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2544 if g_Game_IsClient
then
2545 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2547 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2548 if not gChatShow
then
2549 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2550 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2555 w
:= gScreenWidth
-x
*2;
2561 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2562 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2564 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2566 case CustomStat
.GameMode
of
2569 if gGameSettings
.MaxLives
= 0 then
2570 s1
:= _lc
[I_GAME_DM
]
2572 s1
:= _lc
[I_GAME_LMS
];
2576 if gGameSettings
.MaxLives
= 0 then
2577 s1
:= _lc
[I_GAME_TDM
]
2579 s1
:= _lc
[I_GAME_TLMS
];
2581 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2584 if gGameSettings
.MaxLives
= 0 then
2585 s1
:= _lc
[I_GAME_COOP
]
2587 s1
:= _lc
[I_GAME_SURV
];
2593 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2597 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2598 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2601 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2602 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2603 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2604 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2606 pc
:= Length(CustomStat
.PlayerStat
);
2607 if pc
= 0 then Exit
;
2609 if CustomStat
.GameMode
= GM_COOP
then
2611 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2613 s2
:= _lc
[I_GAME_MONSTERS
];
2614 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2615 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2617 s2
:= _lc
[I_GAME_SECRETS
];
2618 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2619 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2622 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2624 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2625 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2626 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2628 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2629 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2630 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2634 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2639 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2640 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2641 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2643 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2646 for t
:= TEAM_RED
to TEAM_BLUE
do
2648 if t
= TEAM_RED
then
2650 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2651 gStdFont
, 255, 0, 0, 1);
2652 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2653 gStdFont
, 255, 0, 0, 1);
2660 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2661 gStdFont
, 0, 0, 255, 1);
2662 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2663 gStdFont
, 0, 0, 255, 1);
2669 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2672 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2673 if CustomStat
.PlayerStat
[p
].Team
= t
then
2674 with CustomStat
.PlayerStat
[p
] do
2688 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2689 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2690 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2697 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2700 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2701 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2702 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2705 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2706 with CustomStat
.PlayerStat
[p
] do
2708 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2715 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2716 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2717 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2723 procedure DrawSingleStat();
2725 tm
, key_x
, val_x
, y
: Integer;
2729 procedure player_stat(n
: Integer);
2735 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2736 s2
:= Format(' %d', [gTotalMonsters
]);
2738 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2739 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2740 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2741 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2743 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2744 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2746 // "Kills-per-minute: ##.#":
2747 s1
:= _lc
[I_MENU_INTER_KPM
];
2749 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2751 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2752 s2
:= Format(' %.1f', [kpm
]);
2754 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2755 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2757 // "Secrets found: # / #":
2758 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2759 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2761 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2762 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2763 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2764 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2766 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2767 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2771 // "Level Complete":
2772 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2773 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2775 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2776 s1
:= _lc
[I_MENU_INTER_KPM
];
2777 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2780 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2782 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2783 val_x
:= key_x
+ w1
;
2786 tm
:= SingleStat
.GameTime
div 1000;
2787 s1
:= _lc
[I_MENU_INTER_TIME
];
2788 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2790 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2791 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2793 if SingleStat
.TwoPlayers
then
2796 s1
:= _lc
[I_MENU_PLAYER_1
];
2797 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2798 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2800 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2805 s1
:= _lc
[I_MENU_PLAYER_2
];
2806 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2807 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2809 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2815 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2821 procedure DrawLoadingStat();
2822 procedure drawRect (x
, y
, w
, h
: Integer);
2824 if (w
< 1) or (h
< 1) then exit
;
2826 glVertex2f(x
+0.375, y
+0.375);
2827 glVertex2f(x
+w
+0.375, y
+0.375);
2828 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2829 glVertex2f(x
+0.375, y
+h
+0.375);
2833 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2835 rectW
, rectH
: Integer;
2842 idl
, idr
, idb
, idm
: LongWord;
2846 if (total
< 1) then exit
;
2847 if (cur
< 1) then exit
; // don't blink
2848 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2849 //if (cur < 0) then cur := 0;
2850 //if (cur > total) then cur := total;
2853 if (hasPBarGfx
) then
2855 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2856 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2857 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2858 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2859 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2860 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2861 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2862 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2864 //rectW := gScreenWidth-360;
2865 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2868 x0
:= (gScreenWidth
-rectW
) div 2;
2869 y0
:= gScreenHeight
-rectH
-64;
2870 if (y0
< 2) then y0
:= 2;
2872 glEnable(GL_SCISSOR_TEST
);
2875 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2876 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2877 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2880 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2882 while (f
< x0
+rectW
) do
2884 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2889 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2890 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2893 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2894 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2898 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2904 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2908 rectW
:= gScreenWidth
-64;
2911 x0
:= (gScreenWidth
-rectW
) div 2;
2912 y0
:= gScreenHeight
-rectH
-64;
2913 if (y0
< 2) then y0
:= 2;
2915 glDisable(GL_BLEND
);
2916 glDisable(GL_TEXTURE_2D
);
2918 //glClearColor(0, 0, 0, 0);
2919 //glClear(GL_COLOR_BUFFER_BIT);
2921 glColor4ub(127, 127, 127, 255);
2922 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2924 glColor4ub(0, 0, 0, 255);
2925 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2927 glColor4ub(127, 127, 127, 255);
2928 wdt
:= rectW
*cur
div total
;
2929 if (wdt
> rectW
) then wdt
:= rectW
;
2930 drawRect(x0
, y0
, wdt
, rectH
);
2939 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2941 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2942 yy
:= (gScreenHeight
div 3);
2943 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2944 xx
:= (gScreenWidth
div 3);
2948 for i
:= 0 to NextMsg
-1 do
2950 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2951 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2955 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2956 yy
:= yy
+ LOADING_INTERLINE
;
2957 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2962 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2964 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2966 function monDraw (mon
: TMonster
): Boolean;
2968 result
:= false; // don't stop
2973 // Ëåâûé âåðõíèé óãîë
2974 aX
:= Obj
.X
div ScaleSz
+ 1;
2975 aY
:= Obj
.Y
div ScaleSz
+ 1;
2977 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2978 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2979 // Ïðàâûé íèæíèé óãîë
2980 aX2
:= aX
+ aX2
- 1;
2981 aY2
:= aY
+ aY2
- 1;
2982 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2988 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2989 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2992 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2993 ScaleSz
:= 16 div Scale
;
2994 // Ðàçìåðû ìèíè-êàðòû:
2995 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2996 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2998 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3000 if gWalls
<> nil then
3003 for a
:= 0 to High(gWalls
) do
3005 if PanelType
<> 0 then
3007 // Ëåâûé âåðõíèé óãîë:
3008 aX
:= X
div ScaleSz
;
3009 aY
:= Y
div ScaleSz
;
3011 aX2
:= max(Width
div ScaleSz
, 1);
3012 aY2
:= max(Height
div ScaleSz
, 1);
3013 // Ïðàâûé íèæíèé óãîë:
3014 aX2
:= aX
+ aX2
- 1;
3015 aY2
:= aY
+ aY2
- 1;
3018 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3019 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3020 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3024 if gSteps
<> nil then
3027 for a
:= 0 to High(gSteps
) do
3029 if PanelType
<> 0 then
3031 // Ëåâûé âåðõíèé óãîë:
3032 aX
:= X
div ScaleSz
;
3033 aY
:= Y
div ScaleSz
;
3035 aX2
:= max(Width
div ScaleSz
, 1);
3036 aY2
:= max(Height
div ScaleSz
, 1);
3037 // Ïðàâûé íèæíèé óãîë:
3038 aX2
:= aX
+ aX2
- 1;
3039 aY2
:= aY
+ aY2
- 1;
3041 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3044 if gLifts
<> nil then
3047 for a
:= 0 to High(gLifts
) do
3049 if PanelType
<> 0 then
3051 // Ëåâûé âåðõíèé óãîë:
3052 aX
:= X
div ScaleSz
;
3053 aY
:= Y
div ScaleSz
;
3055 aX2
:= max(Width
div ScaleSz
, 1);
3056 aY2
:= max(Height
div ScaleSz
, 1);
3057 // Ïðàâûé íèæíèé óãîë:
3058 aX2
:= aX
+ aX2
- 1;
3059 aY2
:= aY
+ aY2
- 1;
3062 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3063 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3064 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3065 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3069 if gWater
<> nil then
3072 for a
:= 0 to High(gWater
) do
3074 if PanelType
<> 0 then
3076 // Ëåâûé âåðõíèé óãîë:
3077 aX
:= X
div ScaleSz
;
3078 aY
:= Y
div ScaleSz
;
3080 aX2
:= max(Width
div ScaleSz
, 1);
3081 aY2
:= max(Height
div ScaleSz
, 1);
3082 // Ïðàâûé íèæíèé óãîë:
3083 aX2
:= aX
+ aX2
- 1;
3084 aY2
:= aY
+ aY2
- 1;
3086 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3089 if gAcid1
<> nil then
3091 // Ðèñóåì êèñëîòó 1:
3092 for a
:= 0 to High(gAcid1
) do
3094 if PanelType
<> 0 then
3096 // Ëåâûé âåðõíèé óãîë:
3097 aX
:= X
div ScaleSz
;
3098 aY
:= Y
div ScaleSz
;
3100 aX2
:= max(Width
div ScaleSz
, 1);
3101 aY2
:= max(Height
div ScaleSz
, 1);
3102 // Ïðàâûé íèæíèé óãîë:
3103 aX2
:= aX
+ aX2
- 1;
3104 aY2
:= aY
+ aY2
- 1;
3106 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3109 if gAcid2
<> nil then
3111 // Ðèñóåì êèñëîòó 2:
3112 for a
:= 0 to High(gAcid2
) do
3114 if PanelType
<> 0 then
3116 // Ëåâûé âåðõíèé óãîë:
3117 aX
:= X
div ScaleSz
;
3118 aY
:= Y
div ScaleSz
;
3120 aX2
:= max(Width
div ScaleSz
, 1);
3121 aY2
:= max(Height
div ScaleSz
, 1);
3122 // Ïðàâûé íèæíèé óãîë:
3123 aX2
:= aX
+ aX2
- 1;
3124 aY2
:= aY
+ aY2
- 1;
3126 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3129 if gPlayers
<> nil then
3132 for a
:= 0 to High(gPlayers
) do
3133 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3135 // Ëåâûé âåðõíèé óãîë:
3136 aX
:= Obj
.X
div ScaleSz
+ 1;
3137 aY
:= Obj
.Y
div ScaleSz
+ 1;
3139 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3140 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3141 // Ïðàâûé íèæíèé óãîë:
3142 aX2
:= aX
+ aX2
- 1;
3143 aY2
:= aY
+ aY2
- 1;
3145 if gPlayers
[a
] = p
then
3146 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3149 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3150 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3151 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3156 g_Mons_ForEach(monDraw
);
3161 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3163 if not hasAmbient
then exit
;
3164 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3168 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3169 //FIXME: broken for splitscreen mode
3170 procedure renderDynLightsInternal ();
3172 //hasAmbient: Boolean;
3173 //ambColor: TDFColor;
3175 lx
, ly
, lrad
: Integer;
3176 scxywh
: array[0..3] of GLint
;
3179 if e_NoGraphics
then exit
;
3181 //TODO: lights should be in separate grid, i think
3182 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3183 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3186 //ambColor := gCurrentMap['light_ambient'].rgba;
3187 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3189 { // this will multiply incoming color to alpha from framebuffer
3191 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3195 * light rendering: (INVALID!)
3196 * glStencilFunc(GL_EQUAL, 0, $ff);
3198 * glClear(GL_STENCIL_BUFFER_BIT);
3199 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3200 * draw shadow volume into stencil buffer
3201 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3202 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3204 * draw color-less quad with light alpha (WARNING! don't touch color!)
3205 * glEnable(GL_BLEND);
3206 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3207 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3209 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3210 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3212 // setup OpenGL parameters
3213 glStencilMask($FFFFFFFF);
3214 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3215 glEnable(GL_STENCIL_TEST
);
3216 glEnable(GL_SCISSOR_TEST
);
3217 glClear(GL_STENCIL_BUFFER_BIT
);
3218 glStencilFunc(GL_EQUAL
, 0, $ff);
3220 for lln
:= 0 to g_dynLightCount
-1 do
3222 lx
:= g_dynLights
[lln
].x
;
3223 ly
:= g_dynLights
[lln
].y
;
3224 lrad
:= g_dynLights
[lln
].radius
;
3225 if (lrad
< 3) then continue
;
3227 if (lx
-sX
+lrad
< 0) then continue
;
3228 if (ly
-sY
+lrad
< 0) then continue
;
3229 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3230 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3232 // set scissor to optimize drawing
3233 if (g_dbg_scale
= 1.0) then
3235 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3239 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3241 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3242 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3243 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3244 // draw extruded panels
3245 glDisable(GL_TEXTURE_2D
);
3246 glDisable(GL_BLEND
);
3247 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3248 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3249 // render light texture
3250 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3251 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3254 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3255 glEnable(GL_TEXTURE_2D
);
3256 // color and opacity
3257 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3258 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3260 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3261 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3262 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3263 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3268 glDisable(GL_STENCIL_TEST
);
3269 glDisable(GL_BLEND
);
3270 glDisable(GL_SCISSOR_TEST
);
3271 //glScissor(0, 0, sWidth, sHeight);
3273 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3274 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3278 function fixViewportForScale (): Boolean;
3280 nx0
, ny0
, nw
, nh
: Integer;
3283 if (g_dbg_scale
<> 1.0) then
3286 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3287 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3288 nw
:= round(sWidth
/g_dbg_scale
);
3289 nh
:= round(sHeight
/g_dbg_scale
);
3298 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3299 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3300 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3302 TDrawCB
= procedure ();
3305 hasAmbient
: Boolean;
3307 doAmbient
: Boolean = false;
3309 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3314 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3315 if gdbg_map_use_accel_render
then
3317 tagmask
:= panelTypeToTag(panType
);
3318 while (gDrawPanelList
.count
> 0) do
3320 pan
:= TPanel(gDrawPanelList
.front());
3321 if ((pan
.tag
and tagmask
) = 0) then break
;
3322 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3323 gDrawPanelList
.popFront();
3328 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3330 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3333 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3335 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3336 if assigned(cb
) then cb();
3337 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3341 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3343 // our accelerated renderer will collect all panels to gDrawPanelList
3344 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3345 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3346 if gdbg_map_use_accel_render
then
3348 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3350 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3352 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3353 g_Map_DrawBack(backXOfs
, backYOfs
);
3354 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3356 if setTransMatrix
then
3358 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3359 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3360 glTranslatef(-sX
, -sY
, 0);
3364 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3365 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3370 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3371 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3372 glClear(GL_COLOR_BUFFER_BIT);
3375 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3378 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3379 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3380 drawOther('items', @g_Items_Draw
);
3381 drawOther('weapons', @g_Weapon_Draw
);
3382 drawOther('shells', @g_Player_DrawShells
);
3383 drawOther('drawall', @g_Player_DrawAll
);
3384 drawOther('corpses', @g_Player_DrawCorpses
);
3385 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3386 drawOther('monsters', @g_Monsters_Draw
);
3387 drawOther('itemdrop', @g_Items_DrawDrop
);
3388 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3389 drawOther('gfx', @g_GFX_Draw
);
3390 drawOther('flags', @g_Map_DrawFlags
);
3391 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3392 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3393 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3394 drawOther('dynlights', @renderDynLightsInternal
);
3396 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3398 renderAmbientQuad(hasAmbient
, ambColor
);
3402 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3405 if g_debug_HealthBar
then
3407 g_Monsters_DrawHealth();
3408 g_Player_DrawHealth();
3411 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3415 procedure DrawMapView(x
, y
, w
, h
: Integer);
3422 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3423 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3430 fixViewportForScale();
3431 renderMapInternal(-bx
, -by
, true);
3437 procedure DrawPlayer(p
: TPlayer
);
3439 px
, py
, a
, b
, c
, d
: Integer;
3442 if (p
= nil) or (p
.FDummy
) then
3445 g_Map_DrawBack(0, 0);
3450 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3451 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3457 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3458 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3460 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3462 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3463 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3465 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3466 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3468 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3469 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3472 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3475 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3476 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3479 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3484 // scaled, ignore level bounds
3485 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3486 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3489 if p
.IncCam
<> 0 then
3491 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3493 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3495 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3499 if py
< gPlayerScreenSize
.Y
div 2 then
3501 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3503 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3507 if p
.IncCam
< 0 then
3509 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3512 if p
.IncCam
> 0 then
3514 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3518 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3519 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3520 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3522 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3523 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3524 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3527 sY
:= -(b
+p
.IncCam
);
3528 sWidth
:= gPlayerScreenSize
.X
;
3529 sHeight
:= gPlayerScreenSize
.Y
;
3531 //glTranslatef(a, b+p.IncCam, 0);
3533 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3535 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3536 fixViewportForScale();
3537 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3539 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3541 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3542 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3543 if (sX
< 0) then sX
:= 0;
3544 if (sY
< 0) then sY
:= 0;
3546 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3547 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3550 //r_smallmap_h: 0: left; 1: center; 2: right
3551 //r_smallmap_v: 0: top; 1: center; 2: bottom
3553 if (gMapInfo
.Width
= sWidth
) then
3557 else if (gMapInfo
.Width
< sWidth
) then
3559 case r_smallmap_h
of
3560 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3561 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3562 else sX
:= 0; // left
3566 if (gMapInfo
.Height
= sHeight
) then
3570 else if (gMapInfo
.Height
< sHeight
) then
3572 case r_smallmap_v
of
3573 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3574 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3575 else sY
:= 0; // top
3581 p
.viewPortW
:= sWidth
;
3582 p
.viewPortH
:= sHeight
;
3584 {$IFDEF ENABLE_HOLMES}
3585 if (p
= gPlayer1
) then
3587 g_Holmes_plrViewPos(sX
, sY
);
3588 g_Holmes_plrViewSize(sWidth
, sHeight
);
3592 renderMapInternal(-c
, -d
, true);
3594 if (gGameSettings
.GameMode
<> GM_SINGLE
) and gPlayerIndicator
then
3596 if p
.FSpectator
then
3597 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3598 p
.GameY
+ PLAYER_RECT_CY
- 4,
3599 'X', gStdFont
, 255, 255, 255, 1, True);
3601 for a := 0 to High(gCollideMap) do
3602 for b := 0 to High(gCollideMap[a]) do
3605 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3607 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3611 1: e_DrawPoint(1, b, a, 200, 200, 200);
3612 2: e_DrawPoint(1, b, a, 64, 64, 255);
3613 3: e_DrawPoint(1, b, a, 255, 0, 255);
3623 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3624 if g_Debug_Player
then
3625 g_Player_DrawDebug(p
);
3629 procedure drawProfilers ();
3634 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3635 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3636 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3639 procedure g_Game_Draw();
3646 plView1
, plView2
: TPlayer
;
3649 if gExit
= EXIT_QUIT
then Exit
;
3651 Time
:= GetTimer() {div 1000};
3652 FPSCounter
:= FPSCounter
+1;
3653 if Time
- FPSTime
>= 1000 then
3660 if gGameOn
or (gState
= STATE_FOLD
) then
3662 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3664 gSpectMode
:= SPECT_NONE
;
3665 if not gRevertPlayers
then
3667 plView1
:= gPlayer1
;
3668 plView2
:= gPlayer2
;
3672 plView1
:= gPlayer2
;
3673 plView2
:= gPlayer1
;
3677 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3679 gSpectMode
:= SPECT_NONE
;
3680 if gPlayer2
= nil then
3683 plView1
:= gPlayer2
;
3692 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3693 gSpectMode
:= SPECT_STATS
;
3695 if gSpectMode
= SPECT_PLAYERS
then
3696 if gPlayers
<> nil then
3698 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3699 if plView1
= nil then
3701 gSpectPID1
:= GetActivePlayerID_Next();
3702 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3704 if gSpectViewTwo
then
3706 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3707 if plView2
= nil then
3709 gSpectPID2
:= GetActivePlayerID_Next();
3710 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3715 if gSpectMode
= SPECT_MAPVIEW
then
3717 // Ðåæèì ïðîñìîòðà êàðòû
3719 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3720 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3721 gHearPoint1
.Active
:= True;
3722 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3723 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3724 gHearPoint2
.Active
:= False;
3728 Split
:= (plView1
<> nil) and (plView2
<> nil);
3730 // Òî÷êè ñëóõà èãðîêîâ
3731 if plView1
<> nil then
3733 gHearPoint1
.Active
:= True;
3734 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3735 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3737 gHearPoint1
.Active
:= False;
3738 if plView2
<> nil then
3740 gHearPoint2
.Active
:= True;
3741 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3742 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3744 gHearPoint2
.Active
:= False;
3746 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3747 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3750 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3751 if gScreenHeight
mod 2 = 0 then
3752 Dec(gPlayerScreenSize
.Y
);
3755 gPlayerScreenSize
.Y
:= gScreenHeight
;
3758 if gScreenHeight
mod 2 = 0 then
3759 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3761 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3763 DrawPlayer(plView1
);
3764 gPlayer1ScreenCoord
.X
:= sX
;
3765 gPlayer1ScreenCoord
.Y
:= sY
;
3769 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3771 DrawPlayer(plView2
);
3772 gPlayer2ScreenCoord
.X
:= sX
;
3773 gPlayer2ScreenCoord
.Y
:= sY
;
3776 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3779 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3782 {$IFDEF ENABLE_HOLMES}
3784 if (g_holmes_enabled
) then g_Holmes_Draw();
3787 if MessageText
<> '' then
3791 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3793 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3794 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3796 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3797 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3800 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3802 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3804 // Draw spectator GUI
3807 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3810 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3812 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3814 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3816 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3817 if gSpectMode
= SPECT_STATS
then
3819 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3820 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
3822 if gSpectMode
= SPECT_MAPVIEW
then
3824 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3825 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3826 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3827 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3828 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3830 if gSpectMode
= SPECT_PLAYERS
then
3832 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3833 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3834 if gSpectViewTwo
then
3836 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3837 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3838 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3839 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3843 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3844 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3850 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3852 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3853 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3855 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3856 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3857 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3862 if (gState
= STATE_MENU
) then
3864 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3866 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3867 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3869 // F3 at menu will show game loading dialog
3870 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3871 if (g_ActiveWindow
<> nil) then
3873 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3874 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3878 // F3 at titlepic will show game loading dialog
3879 if e_KeyPressed(IK_F3
) then
3881 g_Menu_Show_LoadMenu(true);
3882 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3887 if gState
= STATE_FOLD
then
3889 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3892 if gState
= STATE_INTERCUSTOM
then
3894 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3896 back
:= 'TEXTURE_endpic';
3897 if not g_Texture_Get(back
, ID
) then
3898 back
:= _lc
[I_TEXTURE_ENDPIC
];
3903 if g_Texture_Get(back
, ID
) then
3904 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3906 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3910 if g_ActiveWindow
<> nil then
3912 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3913 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3917 if gState
= STATE_INTERSINGLE
then
3919 if EndingGameCounter
> 0 then
3921 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3927 if g_Texture_Get(back
, ID
) then
3928 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3930 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3934 if g_ActiveWindow
<> nil then
3936 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3937 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3942 if gState
= STATE_ENDPIC
then
3945 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3946 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3948 if ID
<> DWORD(-1) then
3949 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3951 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3953 if g_ActiveWindow
<> nil then
3955 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3956 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3960 if gState
= STATE_SLIST
then
3962 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3964 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3965 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3966 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3968 g_Serverlist_Draw(slCurrent
, slTable
);
3972 if g_ActiveWindow
<> nil then
3976 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3977 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3979 g_ActiveWindow
.Draw();
3984 if g_debug_Sounds
and gGameOn
then
3986 for w
:= 0 to High(e_SoundsArray
) do
3987 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3988 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3993 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3994 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3997 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3998 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4000 if gGameOn
then drawProfilers();
4002 {$IFDEF ENABLE_HOLMES}
4009 procedure g_Game_Quit();
4011 g_Game_StopAllSounds(True);
4013 g_Game_SaveOptions();
4015 g_PlayerModel_FreeData();
4016 g_Texture_DeleteAll();
4017 g_Frames_DeleteAll();
4018 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4020 if NetInitDone
then g_Net_Free
;
4022 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4023 if gMapToDelete
<> '' then
4024 g_Game_DeleteTestMap();
4030 procedure g_FatalError(Text: String);
4032 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4033 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4035 gExit
:= EXIT_SIMPLE
;
4038 procedure g_SimpleError(Text: String);
4040 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4041 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4044 procedure g_Game_SetupScreenSize();
4046 RES_FACTOR
= 4.0 / 3.0;
4052 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4053 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4054 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4055 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4057 gPlayerScreenSize
.Y
:= gScreenHeight
;
4059 // Ðàçìåð çàäíåãî ïëàíà:
4060 if BackID
<> DWORD(-1) then
4063 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4064 (gScreenHeight
*s
> gMapInfo
.Height
) then
4066 gBackSize
.X
:= gScreenWidth
;
4067 gBackSize
.Y
:= gScreenHeight
;
4071 e_GetTextureSize(BackID
, @bw
, @bh
);
4072 rf
:= Single(bw
) / Single(bh
);
4073 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4074 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4075 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4076 if (s
< 1.0) then s
:= 1.0;
4077 gBackSize
.X
:= Round(bw
*s
);
4078 gBackSize
.Y
:= Round(bh
*s
);
4083 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4085 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
4088 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4090 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4091 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4093 if gPlayer1
= nil then
4095 if g_Game_IsClient
then
4097 if NetPlrUID1
> -1 then
4099 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4100 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4105 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4106 Team
:= gPlayer1Settings
.Team
;
4108 // Ñîçäàíèå ïåðâîãî èãðîêà:
4109 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4110 gPlayer1Settings
.Color
,
4112 if gPlayer1
= nil then
4113 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4116 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4117 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4118 if g_Game_IsServer
and g_Game_IsNet
then
4119 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4120 gPlayer1
.Respawn(False, True);
4122 if g_Game_IsNet
and NetUseMaster
then
4128 if gPlayer2
= nil then
4130 if g_Game_IsClient
then
4132 if NetPlrUID2
> -1 then
4133 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4137 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4138 Team
:= gPlayer2Settings
.Team
;
4140 // Ñîçäàíèå âòîðîãî èãðîêà:
4141 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4142 gPlayer2Settings
.Color
,
4144 if gPlayer2
= nil then
4145 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4148 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4149 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4150 if g_Game_IsServer
and g_Game_IsNet
then
4151 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4152 gPlayer2
.Respawn(False, True);
4154 if g_Game_IsNet
and NetUseMaster
then
4162 procedure g_Game_RemovePlayer();
4166 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4167 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4172 if g_Game_IsServer
then
4175 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4176 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4177 g_Player_Remove(Pl
.UID
);
4179 if g_Game_IsNet
and NetUseMaster
then
4188 if g_Game_IsServer
then
4191 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4192 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4193 g_Player_Remove(Pl
.UID
);
4195 if g_Game_IsNet
and NetUseMaster
then
4200 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4206 procedure g_Game_Spectate();
4208 g_Game_RemovePlayer();
4209 if gPlayer1
<> nil then
4210 g_Game_RemovePlayer();
4213 procedure g_Game_SpectateCenterView();
4215 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4216 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4219 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4226 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4228 g_Game_ClearLoading();
4231 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4234 gGameSettings
.GameType
:= GT_SINGLE
;
4235 gGameSettings
.MaxLives
:= 0;
4236 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4237 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4238 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4239 gSwitchGameMode
:= GM_SINGLE
;
4241 g_Game_ExecuteEvent('ongamestart');
4243 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4244 g_Game_SetupScreenSize();
4246 // Ñîçäàíèå ïåðâîãî èãðîêà:
4247 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4248 gPlayer1Settings
.Color
,
4249 gPlayer1Settings
.Team
, False));
4250 if gPlayer1
= nil then
4252 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4256 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4259 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4262 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4263 gPlayer2Settings
.Color
,
4264 gPlayer2Settings
.Team
, False));
4265 if gPlayer2
= nil then
4267 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4271 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4275 // Çàãðóçêà è çàïóñê êàðòû:
4276 if not g_Game_StartMap(MAP
, True) then
4278 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4279 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4283 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4287 for i
:= nPl
+1 to nPlayers
do
4288 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4291 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4292 TimeLimit
, GoalLimit
: Word;
4294 Options
: LongWord; nPlayers
: Byte);
4300 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4302 g_Game_ClearLoading();
4305 gGameSettings
.GameType
:= GT_CUSTOM
;
4306 gGameSettings
.GameMode
:= GameMode
;
4307 gSwitchGameMode
:= GameMode
;
4308 gGameSettings
.TimeLimit
:= TimeLimit
;
4309 gGameSettings
.GoalLimit
:= GoalLimit
;
4310 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4311 gGameSettings
.Options
:= Options
;
4313 gCoopTotalMonstersKilled
:= 0;
4314 gCoopTotalSecretsFound
:= 0;
4315 gCoopTotalMonsters
:= 0;
4316 gCoopTotalSecrets
:= 0;
4320 g_Game_ExecuteEvent('ongamestart');
4322 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4323 g_Game_SetupScreenSize();
4325 // Ðåæèì íàáëþäàòåëÿ:
4326 if nPlayers
= 0 then
4333 if nPlayers
>= 1 then
4335 // Ñîçäàíèå ïåðâîãî èãðîêà:
4336 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4337 gPlayer1Settings
.Color
,
4338 gPlayer1Settings
.Team
, False));
4339 if gPlayer1
= nil then
4341 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4345 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4349 if nPlayers
>= 2 then
4351 // Ñîçäàíèå âòîðîãî èãðîêà:
4352 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4353 gPlayer2Settings
.Color
,
4354 gPlayer2Settings
.Team
, False));
4355 if gPlayer2
= nil then
4357 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4361 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4365 // Çàãðóçêà è çàïóñê êàðòû:
4366 if not g_Game_StartMap(Map
, True) then
4368 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4372 // Íåò òî÷åê ïîÿâëåíèÿ:
4373 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4374 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4375 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4376 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4377 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4379 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4383 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4387 for i
:= nPl
+1 to nPlayers
do
4388 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4391 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4392 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4393 Options
: LongWord; nPlayers
: Byte;
4394 IPAddr
: LongWord; Port
: Word);
4398 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4400 g_Game_ClearLoading();
4403 gGameSettings
.GameType
:= GT_SERVER
;
4404 gGameSettings
.GameMode
:= GameMode
;
4405 gSwitchGameMode
:= GameMode
;
4406 gGameSettings
.TimeLimit
:= TimeLimit
;
4407 gGameSettings
.GoalLimit
:= GoalLimit
;
4408 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4409 gGameSettings
.Options
:= Options
;
4411 gCoopTotalMonstersKilled
:= 0;
4412 gCoopTotalSecretsFound
:= 0;
4413 gCoopTotalMonsters
:= 0;
4414 gCoopTotalSecrets
:= 0;
4418 g_Game_ExecuteEvent('ongamestart');
4420 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4421 g_Game_SetupScreenSize();
4423 // Ðåæèì íàáëþäàòåëÿ:
4424 if nPlayers
= 0 then
4430 if nPlayers
>= 1 then
4432 // Ñîçäàíèå ïåðâîãî èãðîêà:
4433 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4434 gPlayer1Settings
.Color
,
4435 gPlayer1Settings
.Team
, False));
4436 if gPlayer1
= nil then
4438 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4442 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4445 if nPlayers
>= 2 then
4447 // Ñîçäàíèå âòîðîãî èãðîêà:
4448 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4449 gPlayer2Settings
.Color
,
4450 gPlayer2Settings
.Team
, False));
4451 if gPlayer2
= nil then
4453 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4457 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4460 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4461 if NetForwardPorts
then
4462 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4465 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4467 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4471 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4473 // Çàãðóçêà è çàïóñê êàðòû:
4474 if not g_Game_StartMap(Map
, True) then
4476 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4480 // Íåò òî÷åê ïîÿâëåíèÿ:
4481 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4482 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4483 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4484 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4485 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4487 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4491 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4494 NetState
:= NET_STATE_GAME
;
4497 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4512 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4513 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4515 g_Game_ClearLoading();
4518 gGameSettings
.GameType
:= GT_CLIENT
;
4520 gCoopTotalMonstersKilled
:= 0;
4521 gCoopTotalSecretsFound
:= 0;
4522 gCoopTotalMonsters
:= 0;
4523 gCoopTotalSecrets
:= 0;
4527 g_Game_ExecuteEvent('ongamestart');
4529 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4530 g_Game_SetupScreenSize();
4532 NetState
:= NET_STATE_AUTH
;
4534 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4536 if not g_Net_Connect(Addr
, Port
) then
4538 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4539 NetState
:= NET_STATE_NONE
;
4543 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4545 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4550 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4552 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4554 Ptr
:= NetEvent
.packet
^.data
;
4555 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4558 MID
:= InMsg
.ReadByte();
4560 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4562 NetMyID
:= InMsg
.ReadByte();
4563 NetPlrUID1
:= InMsg
.ReadWord();
4565 WadName
:= InMsg
.ReadString();
4566 Map
:= InMsg
.ReadString();
4568 gWADHash
:= InMsg
.ReadMD5();
4570 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4571 gSwitchGameMode
:= gGameSettings
.GameMode
;
4572 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4573 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4574 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4575 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4576 T
:= InMsg
.ReadLongWord();
4578 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4579 if newResPath
= '' then
4581 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4582 newResPath
:= g_Res_DownloadWAD(WadName
);
4583 if newResPath
= '' then
4585 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4586 enet_packet_destroy(NetEvent
.packet
);
4587 NetState
:= NET_STATE_NONE
;
4591 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4593 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4594 gPlayer1Settings
.Color
,
4595 gPlayer1Settings
.Team
, False));
4597 if gPlayer1
= nil then
4599 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4601 enet_packet_destroy(NetEvent
.packet
);
4602 NetState
:= NET_STATE_NONE
;
4606 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4607 gPlayer1
.UID
:= NetPlrUID1
;
4608 gPlayer1
.Reset(True);
4610 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4612 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4614 enet_packet_destroy(NetEvent
.packet
);
4615 NetState
:= NET_STATE_NONE
;
4623 enet_packet_destroy(NetEvent
.packet
);
4627 enet_packet_destroy(NetEvent
.packet
);
4631 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4634 if (NetEvent
.data
<= NET_DISC_MAX
) then
4635 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4636 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4643 ProcessLoading(true);
4645 if e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_ESCAPE
) then
4654 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4655 NetState
:= NET_STATE_NONE
;
4659 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4660 gLMSRespawnTime
:= 0;
4663 NetState
:= NET_STATE_GAME
;
4664 MC_SEND_FullStateRequest
;
4665 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4668 procedure g_Game_SaveOptions();
4670 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4673 procedure g_Game_ChangeMap(const MapPath
: String);
4677 g_Game_ClearLoading();
4679 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4680 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4681 if gExitByTrigger
then
4684 gExitByTrigger
:= False;
4686 if not g_Game_StartMap(MapPath
, Force
) then
4687 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4690 procedure g_Game_Restart();
4694 if g_Game_IsClient
then
4696 map
:= g_ExtractFileName(gMapInfo
.Map
);
4700 g_Game_ClearLoading();
4701 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4704 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4706 NewWAD
, ResName
: String;
4709 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4710 g_Player_RemoveAllCorpses();
4712 if (not g_Game_IsClient
) and
4713 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4714 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4716 if gSwitchGameMode
= GM_CTF
then
4717 gGameSettings
.MaxLives
:= 0;
4718 gGameSettings
.GameMode
:= gSwitchGameMode
;
4721 gSwitchGameMode
:= gGameSettings
.GameMode
;
4723 g_Player_ResetTeams();
4725 if isWadPath(Map
) then
4727 NewWAD
:= g_ExtractWadName(Map
);
4728 ResName
:= g_ExtractFileName(Map
);
4729 if g_Game_IsServer
then
4731 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4732 g_Game_LoadWAD(NewWAD
);
4734 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4735 g_Game_ClientWAD(NewWAD
, gWADHash
);
4739 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4742 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4744 gState
:= STATE_NONE
;
4745 g_ActiveWindow
:= nil;
4751 if gGameSettings
.GameMode
= GM_CTF
then
4753 g_Map_ResetFlag(FLAG_RED
);
4754 g_Map_ResetFlag(FLAG_BLUE
);
4755 // CTF, à ôëàãîâ íåò:
4756 if not g_Map_HaveFlagPoints() then
4757 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4762 gState
:= STATE_MENU
;
4767 gPauseMain
:= false;
4768 gPauseHolmes
:= false;
4770 NetTimeToUpdate
:= 1;
4771 NetTimeToReliable
:= 0;
4772 NetTimeToMaster
:= NetMasterRate
;
4773 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4774 gLMSRespawnTime
:= 0;
4775 gMissionFailed
:= False;
4778 gCoopMonstersKilled
:= 0;
4779 gCoopSecretsFound
:= 0;
4781 gVoteInProgress
:= False;
4782 gVotePassed
:= False;
4788 if not gGameOn
then Exit
;
4790 g_Game_SpectateCenterView();
4792 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4794 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4795 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4796 gLMSSoftSpawn
:= True;
4797 if NetMode
= NET_SERVER
then
4798 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4800 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4803 if NetMode
= NET_SERVER
then
4805 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4808 if NetUseMaster
then
4810 if (NetMHost
= nil) or (NetMPeer
= nil) then
4811 if not g_Net_Slist_Connect
then
4812 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4817 if NetClients
<> nil then
4818 for I
:= 0 to High(NetClients
) do
4819 if NetClients
[I
].Used
then
4821 NetClients
[I
].Voted
:= False;
4822 if NetClients
[I
].RequestedFullUpdate
then
4824 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4825 NetClients
[I
].RequestedFullUpdate
:= False;
4829 g_Net_UnbanNonPermHosts();
4834 gCoopTotalMonstersKilled
:= 0;
4835 gCoopTotalSecretsFound
:= 0;
4836 gCoopTotalMonsters
:= 0;
4837 gCoopTotalSecrets
:= 0;
4841 g_Game_ExecuteEvent('onmapstart');
4844 procedure SetFirstLevel();
4848 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4849 if MapList
= nil then
4852 SortSArray(MapList
);
4853 gNextMap
:= MapList
[Low(MapList
)];
4858 procedure g_Game_ExitLevel(const Map
: AnsiString);
4862 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4863 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4864 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4865 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4867 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4868 if gGameSettings
.GameType
= GT_SINGLE
then
4869 gExit
:= EXIT_ENDLEVELSINGLE
4870 else // Âûøëè â âûõîä â Ñâîåé èãðå
4872 gExit
:= EXIT_ENDLEVELCUSTOM
;
4873 if gGameSettings
.GameMode
= GM_COOP
then
4874 g_Player_RememberAll
;
4876 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4879 if gGameSettings
.GameMode
= GM_COOP
then
4882 gStatsPressed
:= True;
4883 gNextMap
:= 'MAP01';
4885 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4888 if g_Game_IsNet
then
4890 MH_SEND_GameStats();
4891 MH_SEND_CoopStats();
4897 procedure g_Game_RestartLevel();
4901 if gGameSettings
.GameMode
= GM_SINGLE
then
4906 gExit
:= EXIT_ENDLEVELCUSTOM
;
4907 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4911 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4915 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4917 if not g_Game_IsClient
then
4919 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4922 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4923 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4927 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4931 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4932 g_Game_LoadWAD(NewWAD
);
4935 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4937 i
, n
, nb
, nr
: Integer;
4939 function monRespawn (mon
: TMonster
): Boolean;
4941 result
:= false; // don't stop
4942 if not mon
.FNoRespawn
then mon
.Respawn();
4946 if not g_Game_IsServer
then Exit
;
4947 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4948 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4949 gLMSRespawnTime
:= 0;
4952 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4954 gMissionFailed
:= True;
4955 g_Game_RestartLevel
;
4959 n
:= 0; nb
:= 0; nr
:= 0;
4960 for i
:= Low(gPlayers
) to High(gPlayers
) do
4961 if (gPlayers
[i
] <> nil) and
4962 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4963 (gPlayers
[i
] is TBot
)) then
4966 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4967 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4970 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4972 // wait a second until the fuckers finally decide to join
4973 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4974 gLMSRespawnTime
:= gTime
+ 1000;
4975 gLMSSoftSpawn
:= NoMapRestart
;
4979 g_Player_RemoveAllCorpses
;
4980 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4981 if g_Game_IsNet
then
4982 MH_SEND_GameEvent(NET_EV_LMS_START
);
4984 for i
:= Low(gPlayers
) to High(gPlayers
) do
4986 if gPlayers
[i
] = nil then continue
;
4987 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4988 // don't touch normal spectators
4989 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4991 gPlayers
[i
].FNoRespawn
:= True;
4992 gPlayers
[i
].Lives
:= 0;
4993 if g_Game_IsNet
then
4994 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4997 gPlayers
[i
].FNoRespawn
:= False;
4998 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4999 gPlayers
[i
].Respawn(False, True);
5000 if gGameSettings
.GameMode
= GM_COOP
then
5002 gPlayers
[i
].Frags
:= 0;
5003 gPlayers
[i
].RecallState
;
5005 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5006 gPlayer1
:= g_Player_Get(gLMSPID1
);
5007 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5008 gPlayer2
:= g_Player_Get(gLMSPID2
);
5011 g_Items_RestartRound();
5014 g_Mons_ForEach(monRespawn
);
5016 gLMSSoftSpawn
:= False;
5019 function g_Game_GetFirstMap(WAD
: String): String;
5023 MapList
:= g_Map_GetMapsList(WAD
);
5024 if MapList
= nil then
5027 SortSArray(MapList
);
5028 Result
:= MapList
[Low(MapList
)];
5030 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5036 function g_Game_GetNextMap(): String;
5043 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
5044 if MapList
= nil then
5047 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5049 SortSArray(MapList
);
5051 for I
:= Low(MapList
) to High(MapList
) do
5052 if Map
= MapList
[I
] then
5058 if MapIndex
<> -255 then
5060 if MapIndex
= High(MapList
) then
5061 Result
:= MapList
[Low(MapList
)]
5063 Result
:= MapList
[MapIndex
+ 1];
5065 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5071 procedure g_Game_NextLevel();
5073 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5074 gExit
:= EXIT_ENDLEVELCUSTOM
5077 gExit
:= EXIT_ENDLEVELSINGLE
;
5081 if gNextMap
<> '' then Exit
;
5082 gNextMap
:= g_Game_GetNextMap();
5085 function g_Game_IsTestMap(): Boolean;
5087 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5090 procedure g_Game_DeleteTestMap();
5093 //MapName: AnsiString;
5101 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5102 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5103 if (a
= 0) then exit
;
5105 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5106 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5107 Delete(gMapToDelete
, 1, a
+5);
5108 gMapToDelete
:= UpperCase(gMapToDelete
);
5110 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5113 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5114 if MapName <> TEST_MAP_NAME then
5117 if not gTempDelete then
5119 time := g_GetFileTime(WadName);
5120 WAD := TWADFile.Create();
5123 if not WAD.ReadFile(WadName) then
5124 begin // Íåò òàêîãî WAD-ôàéëà
5129 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5131 MapList := WAD.GetResourcesList('');
5133 if MapList <> nil then
5134 for a := 0 to High(MapList) do
5135 if MapList[a] = MapName then
5137 // Óäàëÿåì è ñîõðàíÿåì:
5138 WAD.RemoveResource('', MapName);
5139 WAD.SaveTo(WadName);
5144 g_SetFileTime(WadName, time);
5147 if gTempDelete
then DeleteFile(WadName
);
5150 procedure GameCVars(P
: SSArray
);
5153 stat
: TPlayerStatArray
;
5158 cmd
:= LowerCase(P
[0]);
5159 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5161 with gGameSettings
do
5163 if (Length(P
) > 1) and
5164 ((P
[1] = '1') or (P
[1] = '0')) then
5166 if (P
[1][1] = '1') then
5167 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5169 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5172 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5173 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5175 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5177 if g_Game_IsNet
then MH_SEND_GameSettings
;
5180 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5182 with gGameSettings
do
5184 if (Length(P
) > 1) and
5185 ((P
[1] = '1') or (P
[1] = '0')) then
5187 if (P
[1][1] = '1') then
5188 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5190 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5193 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5194 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5196 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5198 if g_Game_IsNet
then MH_SEND_GameSettings
;
5201 else if cmd
= 'g_gamemode' then
5203 a
:= g_Game_TextToMode(P
[1]);
5204 if a
= GM_SINGLE
then a
:= GM_COOP
;
5205 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5207 gSwitchGameMode
:= a
;
5208 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5209 (gState
= STATE_INTERSINGLE
) then
5210 gSwitchGameMode
:= GM_SINGLE
;
5212 gGameSettings
.GameMode
:= gSwitchGameMode
;
5214 if gSwitchGameMode
= gGameSettings
.GameMode
then
5215 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5216 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5218 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5219 [g_Game_ModeToText(gGameSettings
.GameMode
),
5220 g_Game_ModeToText(gSwitchGameMode
)]));
5222 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5224 with gGameSettings
do
5226 if (Length(P
) > 1) and
5227 ((P
[1] = '1') or (P
[1] = '0')) then
5229 if (P
[1][1] = '1') then
5230 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5232 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5235 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5236 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5238 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5239 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5241 if g_Game_IsNet
then MH_SEND_GameSettings
;
5244 else if (cmd
= 'g_allow_monsters') 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_MONSTERS
5254 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5257 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5258 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5260 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5261 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5263 if g_Game_IsNet
then MH_SEND_GameSettings
;
5266 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5268 with gGameSettings
do
5270 if (Length(P
) > 1) and
5271 ((P
[1] = '1') or (P
[1] = '0')) then
5273 if (P
[1][1] = '1') then
5274 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5276 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5279 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5280 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5282 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5284 if g_Game_IsNet
then MH_SEND_GameSettings
;
5287 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5289 with gGameSettings
do
5291 if (Length(P
) > 1) and
5292 ((P
[1] = '1') or (P
[1] = '0')) then
5294 if (P
[1][1] = '1') then
5295 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5297 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5300 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5301 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5303 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5305 if g_Game_IsNet
then MH_SEND_GameSettings
;
5308 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5310 if Length(P
) > 1 then
5312 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5313 gGameSettings
.WarmupTime
:= 30
5315 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5318 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5319 [gGameSettings
.WarmupTime
]));
5320 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5322 else if cmd
= 'net_interp' then
5324 if (Length(P
) > 1) then
5325 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5327 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5328 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5329 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5330 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5333 else if cmd
= 'net_forceplayerupdate' then
5335 if (Length(P
) > 1) and
5336 ((P
[1] = '1') or (P
[1] = '0')) then
5337 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5339 if NetForcePlayerUpdate
then
5340 g_Console_Add('net_forceplayerupdate = 1')
5342 g_Console_Add('net_forceplayerupdate = 0');
5343 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5344 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5345 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5348 else if cmd
= 'net_predictself' then
5350 if (Length(P
) > 1) and
5351 ((P
[1] = '1') or (P
[1] = '0')) then
5352 NetPredictSelf
:= (P
[1][1] = '1');
5354 if NetPredictSelf
then
5355 g_Console_Add('net_predictself = 1')
5357 g_Console_Add('net_predictself = 0');
5358 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5359 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5360 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5363 else if cmd
= 'sv_name' then
5365 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5367 NetServerName
:= P
[1];
5368 if Length(NetServerName
) > 64 then
5369 SetLength(NetServerName
, 64);
5370 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5374 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5376 else if cmd
= 'sv_passwd' then
5378 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5380 NetPassword
:= P
[1];
5381 if Length(NetPassword
) > 24 then
5382 SetLength(NetPassword
, 24);
5383 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5387 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5389 else if cmd
= 'sv_maxplrs' then
5391 if (Length(P
) > 1) then
5393 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5394 if g_Game_IsServer
and g_Game_IsNet
then
5397 for a
:= 0 to High(NetClients
) do
5398 if NetClients
[a
].Used
then
5401 if b
> NetMaxClients
then
5403 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5404 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5405 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5406 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5409 if NetUseMaster
then
5414 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5416 else if cmd
= 'sv_public' then
5418 if (Length(P
) > 1) then
5420 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5421 if g_Game_IsServer
and g_Game_IsNet
then
5422 if NetUseMaster
then
5424 if NetMPeer
= nil then
5425 if not g_Net_Slist_Connect() then
5426 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5427 g_Net_Slist_Update();
5430 if NetMPeer
<> nil then
5431 g_Net_Slist_Disconnect();
5434 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5436 else if cmd
= 'sv_intertime' then
5438 if (Length(P
) > 1) then
5439 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5441 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5443 else if cmd
= 'p1_name' then
5445 if (Length(P
) > 1) and gGameOn
then
5447 if g_Game_IsClient
then
5449 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5450 MC_SEND_PlayerSettings
;
5453 if gPlayer1
<> nil then
5455 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5456 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5459 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5462 else if cmd
= 'p2_name' then
5464 if (Length(P
) > 1) and gGameOn
then
5466 if g_Game_IsClient
then
5468 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5469 MC_SEND_PlayerSettings
;
5472 if gPlayer2
<> nil then
5474 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5475 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5478 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5481 else if cmd
= 'p1_color' then
5483 if Length(P
) > 3 then
5484 if g_Game_IsClient
then
5486 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5487 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5488 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5489 MC_SEND_PlayerSettings
;
5492 if gPlayer1
<> nil then
5494 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5495 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5496 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5497 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5500 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5501 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5502 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5504 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5506 if Length(P
) > 3 then
5507 if g_Game_IsClient
then
5509 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5510 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5511 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5512 MC_SEND_PlayerSettings
;
5515 if gPlayer2
<> nil then
5517 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5518 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5519 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5520 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5523 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5524 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5525 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5527 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5529 if cmd
= 'r_showtime' then
5531 if (Length(P
) > 1) and
5532 ((P
[1] = '1') or (P
[1] = '0')) then
5533 gShowTime
:= (P
[1][1] = '1');
5536 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5538 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5540 else if cmd
= 'r_showscore' then
5542 if (Length(P
) > 1) and
5543 ((P
[1] = '1') or (P
[1] = '0')) then
5544 gShowGoals
:= (P
[1][1] = '1');
5547 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5549 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5551 else if cmd
= 'r_showstat' then
5553 if (Length(P
) > 1) and
5554 ((P
[1] = '1') or (P
[1] = '0')) then
5555 gShowStat
:= (P
[1][1] = '1');
5558 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5560 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5562 else if cmd
= 'r_showkillmsg' then
5564 if (Length(P
) > 1) and
5565 ((P
[1] = '1') or (P
[1] = '0')) then
5566 gShowKillMsg
:= (P
[1][1] = '1');
5568 if gShowKillMsg
then
5569 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5571 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5573 else if cmd
= 'r_showlives' then
5575 if (Length(P
) > 1) and
5576 ((P
[1] = '1') or (P
[1] = '0')) then
5577 gShowLives
:= (P
[1][1] = '1');
5580 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5582 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5584 else if cmd
= 'r_showspect' then
5586 if (Length(P
) > 1) and
5587 ((P
[1] = '1') or (P
[1] = '0')) then
5588 gSpectHUD
:= (P
[1][1] = '1');
5591 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5593 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5595 else if cmd
= 'r_showping' then
5597 if (Length(P
) > 1) and
5598 ((P
[1] = '1') or (P
[1] = '0')) then
5599 gShowPing
:= (P
[1][1] = '1');
5602 g_Console_Add(_lc
[I_MSG_PING_ON
])
5604 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5606 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5608 if Length(P
) > 1 then
5610 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5611 gGameSettings
.GoalLimit
:= 0
5616 if gGameSettings
.GameMode
= GM_DM
then
5618 stat
:= g_Player_GetStats();
5620 for a
:= 0 to High(stat
) do
5621 if stat
[a
].Frags
> b
then
5625 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5627 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5630 if g_Game_IsNet
then MH_SEND_GameSettings
;
5633 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5635 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5637 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5638 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5640 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5641 [gGameSettings
.TimeLimit
div 3600,
5642 (gGameSettings
.TimeLimit
div 60) mod 60,
5643 gGameSettings
.TimeLimit
mod 60]));
5644 if g_Game_IsNet
then MH_SEND_GameSettings
;
5646 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5648 if Length(P
) > 1 then
5650 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5651 gGameSettings
.MaxLives
:= 0
5655 stat
:= g_Player_GetStats();
5657 for a
:= 0 to High(stat
) do
5658 if stat
[a
].Lives
> b
then
5660 gGameSettings
.MaxLives
:=
5661 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5665 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5666 [gGameSettings
.MaxLives
]));
5667 if g_Game_IsNet
then MH_SEND_GameSettings
;
5672 procedure PrintHeapStats();
5676 hs
:= GetFPCHeapStatus();
5677 e_LogWriteLn ('v===== heap status =====v');
5678 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5679 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5680 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5681 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5682 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5683 e_LogWriteLn ('^=======================^');
5686 procedure DebugCommands(P
: SSArray
);
5693 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5694 if {gDebugMode}conIsCheatsEnabled
then
5696 cmd
:= LowerCase(P
[0]);
5697 if cmd
= 'd_window' then
5699 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5700 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5701 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5702 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5703 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5705 else if cmd
= 'd_sounds' then
5707 if (Length(P
) > 1) and
5708 ((P
[1] = '1') or (P
[1] = '0')) then
5709 g_Debug_Sounds
:= (P
[1][1] = '1');
5711 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5713 else if cmd
= 'd_frames' then
5715 if (Length(P
) > 1) and
5716 ((P
[1] = '1') or (P
[1] = '0')) then
5717 g_Debug_Frames
:= (P
[1][1] = '1');
5719 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5721 else if cmd
= 'd_winmsg' then
5723 if (Length(P
) > 1) and
5724 ((P
[1] = '1') or (P
[1] = '0')) then
5725 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5727 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5729 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5731 if (Length(P
) > 1) and
5732 ((P
[1] = '1') or (P
[1] = '0')) then
5733 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5735 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5737 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5739 if Length(P
) > 1 then
5741 '0': g_debug_BotAIOff
:= 0;
5742 '1': g_debug_BotAIOff
:= 1;
5743 '2': g_debug_BotAIOff
:= 2;
5744 '3': g_debug_BotAIOff
:= 3;
5747 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5749 else if cmd
= 'd_monster' then
5751 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5752 if Length(P
) < 2 then
5754 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5755 g_Console_Add('ID | Name');
5756 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5757 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5758 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5761 a
:= StrToIntDef(P
[1], 0);
5762 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5763 a
:= g_Mons_TypeIdByName(P
[1]);
5765 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5766 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5769 with gPlayer1
.Obj
do
5771 mon
:= g_Monsters_Create(a
,
5772 X
+ Rect
.X
+ (Rect
.Width
div 2),
5773 Y
+ Rect
.Y
+ Rect
.Height
,
5774 gPlayer1
.Direction
, True);
5776 if (Length(P
) > 2) and (mon
<> nil) then
5778 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5779 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5780 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5781 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5782 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5783 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5784 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5785 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5786 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5791 else if (cmd
= 'd_health') then
5793 if (Length(P
) > 1) and
5794 ((P
[1] = '1') or (P
[1] = '0')) then
5795 g_debug_HealthBar
:= (P
[1][1] = '1');
5797 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5799 else if (cmd
= 'd_player') then
5801 if (Length(P
) > 1) and
5802 ((P
[1] = '1') or (P
[1] = '0')) then
5803 g_debug_Player
:= (P
[1][1] = '1');
5805 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5807 else if (cmd
= 'd_mem') then
5813 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5817 procedure GameCheats(P
: SSArray
);
5823 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5825 g_Console_Add('not available');
5831 g_Console_Add('where is the player?!');
5834 cmd
:= LowerCase(P
[0]);
5838 plr
.GodMode
:= not plr
.GodMode
;
5839 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5842 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5843 if cmd
= 'give' then
5845 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5846 for f
:= 1 to High(P
) do
5848 cmd
:= LowerCase(P
[f
]);
5849 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5850 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5851 if cmd
= 'exit' then
5853 if gTriggers
<> nil then
5855 for a
:= 0 to High(gTriggers
) do
5857 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5859 g_Console_Add('player left the map');
5860 gExitByTrigger
:= True;
5861 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5862 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5870 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5871 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5872 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5873 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5874 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5876 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5877 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5879 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5880 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;
5882 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5883 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5885 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5886 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5888 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5889 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5891 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5892 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5893 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5895 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5896 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5897 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5898 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;
5899 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5900 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5902 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;
5903 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;
5904 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;
5905 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;
5906 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;
5907 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;
5909 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5910 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;
5912 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;
5913 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;
5915 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5917 if cmd
= 'ammo' then
5919 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5920 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5921 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5922 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5923 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5924 g_Console_Add('player got some ammo');
5928 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5929 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5931 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5932 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5934 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5935 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5937 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5938 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5940 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5942 if cmd
= 'weapons' then
5944 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5945 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5946 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5947 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5948 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5949 plr
.GiveItem(ITEM_WEAPON_BFG
);
5950 g_Console_Add('player got weapons');
5954 if cmd
= 'keys' then
5956 plr
.GiveItem(ITEM_KEY_RED
);
5957 plr
.GiveItem(ITEM_KEY_GREEN
);
5958 plr
.GiveItem(ITEM_KEY_BLUE
);
5959 g_Console_Add('player got all keys');
5963 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5968 if cmd
= 'open' then
5970 g_Console_Add('player activated sesame');
5971 g_Triggers_OpenAll();
5978 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5982 if cmd
= 'noclip' then
5985 g_Console_Add('wall hardeness adjusted');
5989 if cmd
= 'notarget' then
5991 plr
.NoTarget
:= not plr
.NoTarget
;
5992 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5996 if cmd
= 'noreload' then
5998 plr
.NoReload
:= not plr
.NoReload
;
5999 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6003 if cmd
= 'speedy' then
6005 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6006 g_Console_Add('speed adjusted');
6010 if cmd
= 'jumpy' then
6012 VEL_JUMP
:= 30-VEL_JUMP
;
6013 g_Console_Add('jump height adjusted');
6017 if cmd
= 'automap' then
6019 gShowMap
:= not gShowMap
;
6020 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6024 if cmd
= 'aimline' then
6026 gAimLine
:= not gAimLine
;
6027 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6032 procedure GameCommands(P
: SSArray
);
6038 pl
: pTNetClient
= nil;
6045 cmd
:= LowerCase(P
[0]);
6047 if (cmd
= 'quit') or
6054 else if cmd
= 'pause' then
6056 if (g_ActiveWindow
= nil) then
6057 g_Game_Pause(not gPauseMain
);
6059 else if cmd
= 'endgame' then
6060 gExit
:= EXIT_SIMPLE
6061 else if cmd
= 'restart' then
6063 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6065 if g_Game_IsClient
then
6067 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6072 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6074 else if cmd
= 'kick' then
6076 if g_Game_IsServer
then
6078 if Length(P
) < 2 then
6080 g_Console_Add('kick <name>');
6085 g_Console_Add('kick <name>');
6089 if g_Game_IsNet
then
6090 pl
:= g_Net_Client_ByName(P
[1]);
6093 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6094 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6095 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6096 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6097 if NetUseMaster
then
6099 end else if gPlayers
<> nil then
6100 for a
:= Low(gPlayers
) to High(gPlayers
) do
6101 if gPlayers
[a
] <> nil then
6102 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6104 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6105 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6107 gPlayers
[a
].Lives
:= 0;
6108 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6109 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6110 g_Player_Remove(gPlayers
[a
].UID
);
6111 if NetUseMaster
then
6113 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6117 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6119 else if cmd
= 'kick_id' then
6121 if g_Game_IsServer
and g_Game_IsNet
then
6123 if Length(P
) < 2 then
6125 g_Console_Add('kick_id <client ID>');
6130 g_Console_Add('kick_id <client ID>');
6134 a
:= StrToIntDef(P
[1], 0);
6135 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6137 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6139 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6140 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6141 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6142 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6143 if NetUseMaster
then
6148 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6150 else if cmd
= 'ban' then
6152 if g_Game_IsServer
and g_Game_IsNet
then
6154 if Length(P
) < 2 then
6156 g_Console_Add('ban <name>');
6161 g_Console_Add('ban <name>');
6165 pl
:= g_Net_Client_ByName(P
[1]);
6168 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6169 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6170 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6171 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6172 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6173 if NetUseMaster
then
6176 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6178 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6180 else if cmd
= 'ban_id' then
6182 if g_Game_IsServer
and g_Game_IsNet
then
6184 if Length(P
) < 2 then
6186 g_Console_Add('ban_id <client ID>');
6191 g_Console_Add('ban_id <client ID>');
6195 a
:= StrToIntDef(P
[1], 0);
6196 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6197 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6199 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6200 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6201 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6202 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6203 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6204 if NetUseMaster
then
6208 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6210 else if cmd
= 'permban' then
6212 if g_Game_IsServer
and g_Game_IsNet
then
6214 if Length(P
) < 2 then
6216 g_Console_Add('permban <name>');
6221 g_Console_Add('permban <name>');
6225 pl
:= g_Net_Client_ByName(P
[1]);
6228 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6229 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6230 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6231 g_Net_SaveBanList();
6232 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6233 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6234 if NetUseMaster
then
6237 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6239 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6241 else if cmd
= 'permban_id' then
6243 if g_Game_IsServer
and g_Game_IsNet
then
6245 if Length(P
) < 2 then
6247 g_Console_Add('permban_id <client ID>');
6252 g_Console_Add('permban_id <client ID>');
6256 a
:= StrToIntDef(P
[1], 0);
6257 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6258 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6260 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6261 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6262 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6263 g_Net_SaveBanList();
6264 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6265 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6266 if NetUseMaster
then
6270 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6272 else if cmd
= 'unban' then
6274 if g_Game_IsServer
and g_Game_IsNet
then
6276 if Length(P
) < 2 then
6278 g_Console_Add('unban <IP Address>');
6283 g_Console_Add('unban <IP Address>');
6287 if g_Net_UnbanHost(P
[1]) then
6289 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6290 g_Net_SaveBanList();
6292 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6294 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6296 else if cmd
= 'clientlist' then
6298 if g_Game_IsServer
and g_Game_IsNet
then
6301 if NetClients
<> nil then
6302 for a
:= Low(NetClients
) to High(NetClients
) do
6303 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6305 plr
:= g_Player_Get(NetClients
[a
].Player
);
6306 if plr
= nil then continue
;
6308 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6309 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6312 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6314 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6316 else if cmd
= 'connect' then
6318 if (NetMode
= NET_NONE
) then
6320 if Length(P
) < 2 then
6322 g_Console_Add('connect <IP> [port] [password]');
6327 g_Console_Add('connect <IP> [port] [password]');
6331 if Length(P
) > 2 then
6332 prt
:= StrToIntDef(P
[2], 25666)
6336 if Length(P
) > 3 then
6341 g_Game_StartClient(P
[1], prt
, pw
);
6344 else if cmd
= 'disconnect' then
6346 if (NetMode
= NET_CLIENT
) then
6349 else if cmd
= 'reconnect' then
6351 if (NetMode
= NET_SERVER
) then
6354 if (NetMode
= NET_CLIENT
) then
6357 gExit
:= EXIT_SIMPLE
;
6361 //TODO: Use last successful password to reconnect, instead of ''
6362 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6364 else if (cmd
= 'addbot') or
6365 (cmd
= 'bot_add') then
6367 if Length(P
) > 1 then
6368 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6370 g_Bot_Add(TEAM_NONE
, 2);
6372 else if cmd
= 'bot_addlist' then
6374 if Length(P
) > 1 then
6375 if Length(P
) = 2 then
6376 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6378 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6380 else if cmd
= 'bot_removeall' then
6382 else if cmd
= 'chat' then
6384 if g_Game_IsNet
then
6386 if Length(P
) > 1 then
6388 for a
:= 1 to High(P
) do
6389 chstr
:= chstr
+ P
[a
] + ' ';
6391 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6393 if Length(chstr
) < 1 then
6395 g_Console_Add('chat <text>');
6399 chstr
:= b_Text_Format(chstr
);
6400 if g_Game_IsClient
then
6401 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6403 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6406 g_Console_Add('chat <text>');
6408 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6410 else if cmd
= 'teamchat' then
6412 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6414 if Length(P
) > 1 then
6416 for a
:= 1 to High(P
) do
6417 chstr
:= chstr
+ P
[a
] + ' ';
6419 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6421 if Length(chstr
) < 1 then
6423 g_Console_Add('teamchat <text>');
6427 chstr
:= b_Text_Format(chstr
);
6428 if g_Game_IsClient
then
6429 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6431 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6432 gPlayer1Settings
.Team
);
6435 g_Console_Add('teamchat <text>');
6437 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6439 else if cmd
= 'game' then
6441 if gGameSettings
.GameType
<> GT_NONE
then
6443 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6446 if Length(P
) = 1 then
6448 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6451 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6452 P
[1] := addWadExtension(P
[1]);
6453 if FileExists(MapsDir
+ P
[1]) then
6455 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6456 if Length(P
) < 3 then
6459 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6462 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6464 if g_Map_Exist(MapsDir
+ s
) then
6466 // Çàïóñêàåì ñâîþ èãðó
6468 with gGameSettings
do
6470 GameMode
:= g_Game_TextToMode(gcGameMode
);
6471 if gSwitchGameMode
<> GM_NONE
then
6472 GameMode
:= gSwitchGameMode
;
6473 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6474 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6476 if Length(P
) >= 4 then
6477 b
:= StrToIntDef(P
[3], 1);
6478 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6479 GoalLimit
, MaxLives
, Options
, b
);
6484 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6486 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6488 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6490 else if cmd
= 'host' then
6492 if gGameSettings
.GameType
<> GT_NONE
then
6494 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6497 if Length(P
) < 4 then
6499 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6502 if not StrToIp(P
[1], listen
) then
6504 prt
:= StrToIntDef(P
[2], 25666);
6506 P
[3] := addWadExtension(P
[3]);
6507 if FileExists(MapsDir
+ P
[3]) then
6509 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6510 if Length(P
) < 5 then
6513 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6516 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6518 if g_Map_Exist(MapsDir
+ s
) then
6520 // Çàïóñêàåì ñâîþ èãðó
6522 with gGameSettings
do
6524 GameMode
:= g_Game_TextToMode(gcGameMode
);
6525 if gSwitchGameMode
<> GM_NONE
then
6526 GameMode
:= gSwitchGameMode
;
6527 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6528 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6530 if Length(P
) >= 6 then
6531 b
:= StrToIntDef(P
[5], 0);
6532 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6533 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6538 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6540 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6542 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6544 else if cmd
= 'map' then
6546 if Length(P
) = 1 then
6548 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6550 g_Console_Add(cmd
+ ' <MAP>');
6551 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6553 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6555 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6557 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6558 if Length(P
) < 3 then
6560 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6561 s
:= UpperCase(P
[1]);
6562 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6563 begin // Êàðòà íàøëàñü
6564 gExitByTrigger
:= False;
6566 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6568 gExit
:= EXIT_ENDLEVELCUSTOM
;
6570 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6571 g_Game_ChangeMap(s
);
6574 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6575 P
[1] := addWadExtension(P
[1]);
6576 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6577 if FileExists(MapsDir
+ P
[1]) then
6579 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6581 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6583 s
:= P
[1] + ':\' + P
[2];
6585 if g_Map_Exist(MapsDir
+ s
) then
6587 gExitByTrigger
:= False;
6589 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6591 gExit
:= EXIT_ENDLEVELCUSTOM
;
6593 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6594 g_Game_ChangeMap(s
);
6597 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6599 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6601 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6605 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6606 P
[1] := addWadExtension(P
[1]);
6607 if FileExists(MapsDir
+ P
[1]) then
6610 P
[2] := UpperCase(P
[2]);
6611 s
:= P
[1] + ':\' + P
[2];
6613 if g_Map_Exist(MapsDir
+ s
) then
6614 begin // Íàøëè êàðòó
6615 gExitByTrigger
:= False;
6617 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6619 gExit
:= EXIT_ENDLEVELCUSTOM
;
6621 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6622 g_Game_ChangeMap(s
);
6624 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6626 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6629 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6631 else if cmd
= 'nextmap' then
6633 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6634 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6637 if Length(P
) = 1 then
6639 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6641 g_Console_Add(cmd
+ ' <MAP>');
6642 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6645 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6650 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6652 if Length(P
) < 3 then
6654 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6655 s
:= UpperCase(P
[1]);
6656 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6657 begin // Êàðòà íàøëàñü
6658 gExitByTrigger
:= False;
6663 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6664 P
[1] := addWadExtension(P
[1]);
6665 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6666 if FileExists(MapsDir
+ P
[1]) then
6668 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6670 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6672 s
:= P
[1] + ':\' + P
[2];
6674 if g_Map_Exist(MapsDir
+ s
) then
6675 begin // Óñòàíàâëèâàåì êàðòó
6676 gExitByTrigger
:= False;
6681 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6683 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6685 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6689 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6690 P
[1] := addWadExtension(P
[1]);
6691 if FileExists(MapsDir
+ P
[1]) then
6694 P
[2] := UpperCase(P
[2]);
6695 s
:= P
[1] + ':\' + P
[2];
6697 if g_Map_Exist(MapsDir
+ s
) then
6698 begin // Íàøëè êàðòó
6699 gExitByTrigger
:= False;
6703 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6705 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6708 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6711 if gNextMap
= '' then
6712 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6714 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6717 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6720 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6722 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6724 gExitByTrigger
:= False;
6725 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6726 if (gNextMap
= '') and (gTriggers
<> nil) then
6727 for a
:= 0 to High(gTriggers
) do
6728 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6730 gExitByTrigger
:= True;
6731 //gNextMap := gTriggers[a].Data.MapName;
6732 gNextMap
:= gTriggers
[a
].tgcMap
;
6735 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6736 if gNextMap
= '' then
6737 gNextMap
:= g_Game_GetNextMap();
6738 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6739 if not isWadPath(gNextMap
) then
6740 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6743 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6744 if g_Map_Exist(MapsDir
+ s
) then
6745 gExit
:= EXIT_ENDLEVELCUSTOM
6747 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6749 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6751 else if (cmd
= 'event') then
6753 if (Length(P
) <= 1) then
6755 for a
:= 0 to High(gEvents
) do
6756 if gEvents
[a
].Command
= '' then
6757 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6759 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6762 if (Length(P
) = 2) then
6764 for a
:= 0 to High(gEvents
) do
6765 if gEvents
[a
].Name
= P
[1] then
6766 if gEvents
[a
].Command
= '' then
6767 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6769 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6772 for a
:= 0 to High(gEvents
) do
6773 if gEvents
[a
].Name
= P
[1] then
6775 gEvents
[a
].Command
:= '';
6776 for b
:= 2 to High(P
) do
6777 if Pos(' ', P
[b
]) = 0 then
6778 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6780 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6781 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6785 else if cmd
= 'suicide' then
6789 if g_Game_IsClient
then
6790 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6793 if gPlayer1
<> nil then
6794 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6795 if gPlayer2
<> nil then
6796 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6800 else if cmd
= 'screenshot' then
6804 else if cmd
= 'togglechat' then
6806 g_Console_Chat_Switch(False);
6807 gSkipFirstChar
:= not g_Console_Interactive()
6809 else if cmd
= 'toggleteamchat' then
6811 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6813 g_Console_Chat_Switch(True);
6814 gSkipFirstChar
:= not g_Console_Interactive()
6817 else if cmd
= 'weapon' then
6819 if Length(p
) = 2 then
6821 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
6822 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6823 gSelectWeapon
[0] := a
6826 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6828 if Length(p
) = 2 then
6830 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
6831 b
:= ord(cmd
[2]) - ord('1');
6832 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6833 gSelectWeapon
[b
] := a
6836 // Êîìàíäû Ñâîåé èãðû:
6837 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6839 if cmd
= 'bot_addred' then
6841 if Length(P
) > 1 then
6842 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6844 g_Bot_Add(TEAM_RED
, 2);
6846 else if cmd
= 'bot_addblue' then
6848 if Length(P
) > 1 then
6849 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6851 g_Bot_Add(TEAM_BLUE
, 2);
6853 else if cmd
= 'spectate' then
6859 else if cmd
= 'say' then
6861 if g_Game_IsServer
and g_Game_IsNet
then
6863 if Length(P
) > 1 then
6866 for a
:= 1 to High(P
) do
6867 chstr
:= chstr
+ P
[a
] + ' ';
6869 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6871 if Length(chstr
) < 1 then
6873 g_Console_Add('say <text>');
6877 chstr
:= b_Text_Format(chstr
);
6878 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6880 else g_Console_Add('say <text>');
6882 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6884 else if cmd
= 'tell' then
6886 if g_Game_IsServer
and g_Game_IsNet
then
6888 if (Length(P
) > 2) and (P
[1] <> '') then
6891 for a
:= 2 to High(P
) do
6892 chstr
:= chstr
+ P
[a
] + ' ';
6894 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6896 if Length(chstr
) < 1 then
6898 g_Console_Add('tell <playername> <text>');
6902 pl
:= g_Net_Client_ByName(P
[1]);
6904 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6906 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6908 else g_Console_Add('tell <playername> <text>');
6910 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6912 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6914 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6916 // Äîïîëíèòåëüíîå âðåìÿ:
6917 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6919 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6920 [gGameSettings
.TimeLimit
div 3600,
6921 (gGameSettings
.TimeLimit
div 60) mod 60,
6922 gGameSettings
.TimeLimit
mod 60]));
6923 if g_Game_IsNet
then MH_SEND_GameSettings
;
6925 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6927 if (Length(P
) <= 1) then
6928 g_Console_Add('rcon_password <password>')
6930 MC_SEND_RCONPassword(P
[1]);
6932 else if cmd
= 'rcon' then
6934 if g_Game_IsClient
then
6936 if Length(P
) > 1 then
6939 for a
:= 1 to High(P
) do
6940 chstr
:= chstr
+ P
[a
] + ' ';
6942 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6944 if Length(chstr
) < 1 then
6946 g_Console_Add('rcon <command>');
6950 MC_SEND_RCONCommand(chstr
);
6952 else g_Console_Add('rcon <command>');
6955 else if cmd
= 'ready' then
6957 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6958 gLMSRespawnTime
:= gTime
+ 100;
6960 else if (cmd
= 'callvote') and g_Game_IsNet
then
6962 if Length(P
) > 1 then
6965 for a
:= 1 to High(P
) do begin
6966 if a
> 1 then chstr
:= chstr
+ ' ';
6967 chstr
:= chstr
+ P
[a
];
6970 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6972 if Length(chstr
) < 1 then
6974 g_Console_Add('callvote <command>');
6978 if g_Game_IsClient
then
6979 MC_SEND_Vote(True, chstr
)
6981 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6982 g_Console_Process('vote', True);
6985 g_Console_Add('callvote <command>');
6987 else if (cmd
= 'vote') and g_Game_IsNet
then
6989 if g_Game_IsClient
then
6991 else if gVoteInProgress
then
6993 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6994 a
:= Floor((NetClientCount
+1)/2.0) + 1
6996 a
:= Floor(NetClientCount
/2.0) + 1;
7001 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7002 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7008 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7009 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7017 procedure g_TakeScreenShot();
7025 if e_NoGraphics
then Exit
;
7026 ssdir
:= GameDir
+'/screenshots';
7027 if not findFileCI(ssdir
, true) then
7029 // try to create dir
7034 if not findFileCI(ssdir
, true) then exit
; // alas
7037 for a
:= 1 to High(Word) do
7039 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
7041 if findFileCI(t
, true) then continue
;
7042 if not findFileCI(FileName
) then
7045 st
:= createDiskFile(FileName
);
7047 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
7052 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
7060 procedure g_Game_InGameMenu(Show
: Boolean);
7062 if (g_ActiveWindow
= nil) and Show
then
7064 if gGameSettings
.GameType
= GT_SINGLE
then
7065 g_GUI_ShowWindow('GameSingleMenu')
7068 if g_Game_IsClient
then
7069 g_GUI_ShowWindow('GameClientMenu')
7071 if g_Game_IsNet
then
7072 g_GUI_ShowWindow('GameServerMenu')
7074 g_GUI_ShowWindow('GameCustomMenu');
7076 g_Sound_PlayEx('MENU_OPEN');
7078 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7079 if (not g_Game_IsNet
) then
7083 if (g_ActiveWindow
<> nil) and (not Show
) then
7085 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7086 if (not g_Game_IsNet
) then
7087 g_Game_Pause(False);
7091 procedure g_Game_Pause (Enable
: Boolean);
7095 if not gGameOn
then exit
;
7097 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7100 gPauseMain
:= Enable
;
7102 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7105 procedure g_Game_HolmesPause (Enable
: Boolean);
7109 if not gGameOn
then exit
;
7110 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7113 gPauseHolmes
:= Enable
;
7115 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7118 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7123 if gTriggers
<> nil then
7124 for i
:= 0 to High(gTriggers
) do
7125 with gTriggers
[i
] do
7126 if (TriggerType
= TRIGGER_SOUND
) and
7128 Sound
.IsPlaying() then
7130 Sound
.Pause(Enable
);
7134 if gPlayers
<> nil then
7135 for i
:= 0 to High(gPlayers
) do
7136 if gPlayers
[i
] <> nil then
7137 gPlayers
[i
].PauseSounds(Enable
);
7140 if gMusic
<> nil then
7141 gMusic
.Pause(Enable
);
7144 procedure g_Game_StopAllSounds(all
: Boolean);
7148 if gTriggers
<> nil then
7149 for i
:= 0 to High(gTriggers
) do
7150 with gTriggers
[i
] do
7151 if (TriggerType
= TRIGGER_SOUND
) and
7155 if gMusic
<> nil then
7162 procedure g_Game_UpdateTriggerSounds();
7166 if gTriggers
<> nil then
7167 for i
:= 0 to High(gTriggers
) do
7168 with gTriggers
[i
] do
7169 if (TriggerType
= TRIGGER_SOUND
) and
7172 Sound
.IsPlaying() then
7174 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
7175 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
7177 Sound
.SetPan(0.5 - tgcPan
/255.0);
7178 Sound
.SetVolume(tgcVolume
/255.0);
7181 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
7185 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7188 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7193 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7198 if gSpectMode
<> SPECT_PLAYERS
then
7200 if gSpectPID1
= UID
then
7205 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7212 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7217 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7222 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7227 if gSpectMode
<> SPECT_PLAYERS
then
7229 Pl
:= g_Player_Get(gSpectPID1
);
7230 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7235 if gSpectViewTwo
then
7237 Pl
:= g_Player_Get(gSpectPID2
);
7238 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7246 procedure g_Game_Message(Msg
: string; Time
: Word);
7248 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7249 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7250 MessageTime
:= Time
;
7253 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7255 punct
: Array[0..13] of String =
7256 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7262 function IsPunctuation(S
: String): Boolean;
7267 if Length(S
) <> 1 then
7269 for i
:= Low(punct
) to High(punct
) do
7270 if S
= punct
[i
] then
7276 function FilterPunctuation(S
: String): String;
7280 for i
:= Low(punct
) to High(punct
) do
7281 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7287 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7289 // remove player name
7290 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7291 // for FullWord check
7292 Text := toLowerCase1251(' ' + Text + ' ');
7293 fpText
:= FilterPunctuation(Text);
7295 for i
:= 0 to Length(gChatSounds
) - 1 do
7298 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7300 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7301 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7303 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7309 gChatSounds
[i
].Sound
.Play();
7315 g_Sound_PlayEx('SOUND_GAME_RADIO');
7318 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7327 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7331 if goodsnd
[a
].IsPlaying() then
7334 goodsnd
[Random(4)].Play();
7337 procedure g_Game_Announce_KillCombo(Param
: Integer);
7344 UID
:= Param
and $FFFF;
7349 Pl
:= g_Player_Get(UID
);
7358 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7362 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7366 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7370 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7378 if not g_Game_IsWatchedPlayer(UID
) then
7381 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7385 if killsnd
[n
].IsPlaying() then
7390 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7399 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7403 if hahasnd
[a
].IsPlaying() then
7406 hahasnd
[Random(3)].Play();
7409 procedure g_Game_StartVote(Command
, Initiator
: string);
7413 if not gVotesEnabled
then Exit
;
7414 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7415 if gVoteInProgress
or gVotePassed
then
7417 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7418 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7421 gVoteInProgress
:= True;
7422 gVotePassed
:= False;
7423 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7426 gVoteCommand
:= Command
;
7428 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7429 Need
:= Floor((NetClientCount
+1)/2.0)+1
7431 Need
:= Floor(NetClientCount
/2.0)+1;
7432 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7433 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7436 procedure g_Game_CheckVote
;
7440 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7441 if not gVoteInProgress
then Exit
;
7443 if (gTime
>= gVoteTimer
) then
7445 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7446 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7448 Need
:= Floor(NetClientCount
/2.0) + 1;
7449 if gVoteCount
>= Need
then
7451 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7452 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7453 gVotePassed
:= True;
7454 gVoteCmdTimer
:= gTime
+ 5000;
7458 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7459 MH_SEND_VoteEvent(NET_VE_FAILED
);
7461 if NetClients
<> nil then
7462 for I
:= Low(NetClients
) to High(NetClients
) do
7463 if NetClients
[i
].Used
then
7464 NetClients
[i
].Voted
:= False;
7465 gVoteInProgress
:= False;
7471 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7472 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7474 Need
:= Floor(NetClientCount
/2.0) + 1;
7475 if gVoteCount
>= Need
then
7477 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7478 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7479 gVoteInProgress
:= False;
7480 gVotePassed
:= True;
7481 gVoteCmdTimer
:= gTime
+ 5000;
7484 if NetClients
<> nil then
7485 for I
:= Low(NetClients
) to High(NetClients
) do
7486 if NetClients
[i
].Used
then
7487 NetClients
[i
].Voted
:= False;
7492 procedure g_Game_LoadMapList(FileName
: string);
7500 if not FileExists(FileName
) then Exit
;
7502 AssignFile(ListFile
, FileName
);
7504 while not EOF(ListFile
) do
7506 ReadLn(ListFile
, s
);
7509 if s
= '' then Continue
;
7511 SetLength(MapList
, Length(MapList
)+1);
7512 MapList
[High(MapList
)] := s
;
7514 CloseFile(ListFile
);
7517 procedure g_Game_SetDebugMode();
7520 // ×èòû (äàæå â ñâîåé èãðå):
7524 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7528 if Length(LoadingStat
.Msgs
) = 0 then
7534 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7535 if NextMsg
= Length(Msgs
) then
7537 for i
:= 0 to High(Msgs
)-1 do
7538 Msgs
[i
] := Msgs
[i
+1];
7546 Msgs
[NextMsg
-1] := Text;
7550 PBarWasHere
:= false;
7553 g_ActiveWindow
:= nil;
7555 ProcessLoading(true);
7558 procedure g_Game_StepLoading(Value
: Integer = -1);
7569 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7577 procedure g_Game_ClearLoading();
7586 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7587 if len
< 1 then len
:= 1;
7588 SetLength(Msgs
, len
);
7589 for len
:= Low(Msgs
) to High(Msgs
) do
7592 PBarWasHere
:= false;
7596 procedure Parse_Params(var pars
: TParamStrValues
);
7603 while i
<= ParamCount
do
7606 if (s
[1] = '-') and (Length(s
) > 1) then
7608 if (s
[2] = '-') and (Length(s
) > 2) then
7609 begin // Îäèíî÷íûé ïàðàìåòð
7610 SetLength(pars
, Length(pars
) + 1);
7611 with pars
[High(pars
)] do
7613 Name
:= LowerCase(s
);
7618 if (i
< ParamCount
) then
7619 begin // Ïàðàìåòð ñî çíà÷åíèåì
7621 SetLength(pars
, Length(pars
) + 1);
7622 with pars
[High(pars
)] do
7624 Name
:= LowerCase(s
);
7625 Value
:= LowerCase(ParamStr(i
));
7634 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7639 for i
:= 0 to High(pars
) do
7640 if pars
[i
].Name
= aName
then
7642 Result
:= pars
[i
].Value
;
7647 procedure g_Game_Process_Params();
7649 pars
: TParamStrValues
;
7652 LimT
, LimS
: Integer;
7663 s
:= Find_Param_Value(pars
, '--debug');
7666 g_Game_SetDebugMode();
7667 s
:= Find_Param_Value(pars
, '--netdump');
7672 // Connect when game loads
7673 ip
:= Find_Param_Value(pars
, '-connect');
7677 s
:= Find_Param_Value(pars
, '-port');
7678 if (s
= '') or not TryStrToInt(s
, Port
) then
7681 s
:= Find_Param_Value(pars
, '-pw');
7683 g_Game_StartClient(ip
, Port
, s
);
7687 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7690 gDefaultMegawadStart
:= s
;
7693 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7694 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7696 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7699 // Start map when game loads:
7700 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7701 if isWadPath(map
) then
7704 s
:= Find_Param_Value(pars
, '-gm');
7705 GMode
:= g_Game_TextToMode(s
);
7706 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7707 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7710 s
:= Find_Param_Value(pars
, '-limt');
7711 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7717 s
:= Find_Param_Value(pars
, '-lims');
7718 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7724 s
:= Find_Param_Value(pars
, '-lives');
7725 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7731 s
:= Find_Param_Value(pars
, '-opt');
7733 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7735 Opt
:= StrToIntDef(s
, 0);
7737 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7740 s
:= Find_Param_Value(pars
, '--close');
7744 // Override map to test:
7745 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7747 gTestMap
:= MapsDir
+ s
;
7749 // Delete test map after play:
7750 s
:= Find_Param_Value(pars
, '--testdelete');
7753 gMapToDelete
:= MapsDir
+ map
;
7754 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7758 // Delete temporary WAD after play:
7759 s
:= Find_Param_Value(pars
, '--tempdelete');
7760 if (s
<> '') and (gTestMap
<> '') then
7762 gMapToDelete
:= gTestMap
;
7763 gTempDelete
:= True;
7766 // Number of players:
7767 s
:= Find_Param_Value(pars
, '-pl');
7771 n
:= StrToIntDef(s
, 1);
7774 s
:= Find_Param_Value(pars
, '-port');
7775 if (s
= '') or not TryStrToInt(s
, Port
) then
7776 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7778 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7781 // Execute script when game loads:
7782 s
:= Find_Param_Value(pars
, '-exec');
7785 if not isWadPath(s
) then
7786 s
:= GameDir
+ '/' + s
;
7791 if IOResult
<> 0 then
7793 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7794 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7798 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7799 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7804 if IOResult
<> 0 then
7806 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7807 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7811 if Pos('#', s
) <> 1 then // script comment
7812 g_Console_Process(s
, True);
7823 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7824 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7825 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7826 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7828 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7829 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7830 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7831 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7833 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7834 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7836 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7837 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7839 {$IFDEF ENABLE_HOLMES}
7840 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7843 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7845 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7847 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7848 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7850 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7851 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7853 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');