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, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
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
, 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);
1509 if (plr
= nil) then exit
;
1510 if (p
= 2) then time
:= 1000 else time
:= 1;
1511 strafeDir
:= MoveButton
shr 4;
1512 MoveButton
:= MoveButton
and $0F;
1514 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1515 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1516 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1517 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1518 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1519 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1521 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1522 if MoveButton
= 1 then
1523 plr
.PressKey(KEY_LEFT
, time
)
1524 else if MoveButton
= 2 then
1525 plr
.PressKey(KEY_RIGHT
, time
);
1527 // if we have "strafe" key, turn off old strafe mechanics
1528 if gPlayerAction
[p
, ACTION_STRAFE
] then
1530 // new strafe mechanics
1531 if (strafeDir
= 0) then
1532 strafeDir
:= MoveButton
; // start strafing
1533 // now set direction according to strafe (reversed)
1534 if (strafeDir
= 2) then
1535 plr
.SetDirection(TDirection
.D_LEFT
)
1536 else if (strafeDir
= 1) then
1537 plr
.SetDirection(TDirection
.D_RIGHT
)
1541 strafeDir
:= 0; // not strafing anymore
1542 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1543 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1544 plr
.SetDirection(TDirection
.D_LEFT
)
1545 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1546 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1547 plr
.SetDirection(TDirection
.D_RIGHT
)
1548 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1549 else if MoveButton
<> 0 then
1550 plr
.SetDirection(TDirection(MoveButton
-1))
1553 // fix movebutton state
1554 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1556 // Îñòàëüíûå êëàâèøè:
1557 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1558 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1559 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1560 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1561 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1562 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1563 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1565 for i
:= WP_FIRST
to WP_LAST
do
1567 if gSelectWeapon
[p
, i
] then
1569 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1570 gSelectWeapon
[p
, i
] := False
1574 // HACK: add dynlight here
1575 if gwin_k8_enable_light_experiments
then
1577 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1579 g_playerLight
:= true;
1581 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1583 g_playerLight
:= false;
1587 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1590 procedure g_Game_Update();
1592 Msg
: g_gui
.TMessage
;
1598 function sendMonsPos (mon
: TMonster
): Boolean;
1600 result
:= false; // don't stop
1601 // this will also reset "need-send" flag
1602 if mon
.gncNeedSend
then
1604 MH_SEND_MonsterPos(mon
.UID
);
1606 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1608 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1610 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1612 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1616 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1618 result
:= false; // don't stop
1619 // this will also reset "need-send" flag
1620 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1624 reliableUpdate
: Boolean;
1629 // Ïîðà âûêëþ÷àòü èãðó:
1630 if gExit
= EXIT_QUIT
then
1632 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1636 if gExit
= EXIT_QUIT
then
1640 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1641 // no need to, as we'll do it in event handler
1643 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1646 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1648 gExit
:= EXIT_SIMPLE
;
1654 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1655 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1656 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1657 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1659 if g_Game_IsNet
and g_Game_IsServer
then
1661 gInterTime
:= gInterTime
+ GAME_TICK
;
1662 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1663 if a
<> gServInterTime
then
1665 gServInterTime
:= a
;
1666 MH_SEND_TimeSync(gServInterTime
);
1670 if (not g_Game_IsClient
) and
1674 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1675 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1676 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1677 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1679 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1680 and (g_ActiveWindow
= nil)
1682 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1685 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1686 g_Game_StopAllSounds(True);
1688 if gMapOnce
then // Ýòî áûë òåñò
1689 gExit
:= EXIT_SIMPLE
1691 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1692 g_Game_ChangeMap(gNextMap
)
1693 else // Ñëåäóþùåé êàðòû íåò
1695 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1697 // Âûõîä â ãëàâíîå ìåíþ:
1699 g_GUI_ShowWindow('MainMenu');
1700 gMusic
.SetByName('MUSIC_MENU');
1702 gState
:= STATE_MENU
;
1705 // Ôèíàëüíàÿ êàðòèíêà:
1706 g_Game_ExecuteEvent('onwadend');
1708 if not gMusic
.SetByName('MUSIC_endmus') then
1709 gMusic
.SetByName('MUSIC_STDENDMUS');
1711 gState
:= STATE_ENDPIC
;
1713 g_Game_ExecuteEvent('ongameend');
1719 if gState
= STATE_INTERTEXT
then
1720 if InterText
.counter
> 0 then
1721 InterText
.counter
:= InterText
.counter
- 1;
1724 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1726 if EndingGameCounter
= 0 then
1728 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1729 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1731 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1733 g_Game_ExecuteEvent('onwadend');
1734 if not gMusic
.SetByName('MUSIC_endmus') then
1735 gMusic
.SetByName('MUSIC_STDENDMUS');
1738 gMusic
.SetByName('MUSIC_ROUNDMUS');
1741 gState
:= STATE_INTERCUSTOM
;
1744 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1746 gMusic
.SetByName('MUSIC_INTERMUS');
1748 gState
:= STATE_INTERSINGLE
;
1751 g_Game_ExecuteEvent('oninter');
1754 DecMin(EndingGameCounter
, 6, 0);
1757 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1759 if gMapOnce
then // Ýòî áûë òåñò
1761 gExit
:= EXIT_SIMPLE
;
1767 g_Serverlist_Control(slCurrent
, slTable
);
1770 // Ñòàòèñòèêà ïî Tab:
1772 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1775 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1777 // Âðåìÿ += 28 ìèëëèñåêóíä:
1778 gTime
:= gTime
+ GAME_TICK
;
1780 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1781 if MessageTime
= 0 then
1783 if MessageTime
> 0 then
1784 MessageTime
:= MessageTime
- 1;
1786 if (g_Game_IsServer
) then
1788 // Áûë çàäàí ëèìèò âðåìåíè:
1789 if (gGameSettings
.TimeLimit
> 0) then
1790 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1791 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1796 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1797 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1798 g_Game_RestartRound(gLMSSoftSpawn
);
1800 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1801 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1803 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1805 g_Console_Process(gVoteCommand
);
1807 gVotePassed
:= False;
1810 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1811 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1812 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1813 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1814 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1816 // Áûë çàäàí ëèìèò ïîáåä:
1817 if (gGameSettings
.GoalLimit
> 0) then
1821 if gGameSettings
.GameMode
= GM_DM
then
1822 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1823 for i
:= 0 to High(gPlayers
) do
1824 if gPlayers
[i
] <> nil then
1825 if gPlayers
[i
].Frags
> b
then
1826 b
:= gPlayers
[i
].Frags
;
1829 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1830 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1831 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1834 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1835 if b
>= gGameSettings
.GoalLimit
then
1842 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1843 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1844 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1845 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1847 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1848 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1849 end // if not console
1852 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1854 // process weapon switch queue
1858 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1859 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1861 if not gSpectKeyPress
then
1863 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1865 // switch spect mode
1867 SPECT_NONE
: ; // not spectator
1869 SPECT_MAPVIEW
: Inc(gSpectMode
);
1870 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1872 gSpectKeyPress
:= True;
1874 if (gSpectMode
= SPECT_MAPVIEW
)
1875 and (not gSpectAuto
) then
1877 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1878 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1879 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1880 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1881 if gPlayerAction
[0, ACTION_LOOKUP
] then
1882 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1883 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1884 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1885 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1888 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1889 gSpectKeyPress
:= True;
1891 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1894 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1895 gSpectKeyPress
:= True;
1898 if (gSpectMode
= SPECT_PLAYERS
)
1899 and (not gSpectAuto
) then
1901 if gPlayerAction
[0, ACTION_LOOKUP
] then
1904 gSpectViewTwo
:= True;
1905 gSpectKeyPress
:= True;
1907 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1909 // remove second view
1910 gSpectViewTwo
:= False;
1911 gSpectKeyPress
:= True;
1913 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1915 // prev player (view 1)
1916 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1917 gSpectKeyPress
:= True;
1919 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1921 // next player (view 1)
1922 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1923 gSpectKeyPress
:= True;
1925 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1927 // prev player (view 2)
1928 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1929 gSpectKeyPress
:= True;
1931 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1933 // next player (view 2)
1934 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1935 gSpectKeyPress
:= True;
1938 if gPlayerAction
[0, ACTION_ATTACK
] then
1940 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1943 gSpectAutoNext
:= 0;
1944 gSpectViewTwo
:= False;
1945 gSpectKeyPress
:= True;
1950 gSpectMode
:= SPECT_STATS
;
1951 gSpectAuto
:= False;
1952 gSpectKeyPress
:= True;
1957 if (not gPlayerAction
[0, ACTION_JUMP
]) and
1958 (not gPlayerAction
[0, ACTION_ATTACK
]) and
1959 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
1960 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
1961 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
1962 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
1963 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
1964 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
1965 gSpectKeyPress
:= False;
1969 if gSpectMode
= SPECT_MAPVIEW
then
1971 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
1973 gSpectAutoNext
:= gTime
1976 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
1978 gSpectAutoNext
:= gTime
1982 if gSpectAutoNext
<= gTime
then
1984 if gSpectAutoNext
> 0 then
1986 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
1990 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
1991 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
1992 gSpectAutoStepX
:= Random(9) - 4;
1993 gSpectAutoStepY
:= Random(9) - 4;
1994 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
1995 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
1996 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
1997 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
1998 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
1999 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2003 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2008 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2009 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2010 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2016 // Îáíîâëÿåì âñå îñòàëüíîå:
2019 g_Triggers_Update();
2021 g_Monsters_Update();
2023 g_Player_UpdateAll();
2024 g_Player_UpdatePhysicalObjects();
2026 // server: send newly spawned monsters unconditionally
2027 if (gGameSettings
.GameType
= GT_SERVER
) then
2029 if (Length(gMonstersSpawned
) > 0) then
2031 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2032 SetLength(gMonstersSpawned
, 0);
2036 if (gSoundTriggerTime
> 8) then
2038 g_Game_UpdateTriggerSounds();
2039 gSoundTriggerTime
:= 0;
2043 Inc(gSoundTriggerTime
);
2046 if (NetMode
= NET_SERVER
) then
2048 Inc(NetTimeToUpdate
);
2049 Inc(NetTimeToReliable
);
2051 // send monster updates
2052 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2054 // send all monsters (periodic sync)
2055 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2057 for I
:= 0 to High(gPlayers
) do
2059 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2062 g_Mons_ForEach(sendMonsPos
);
2064 if reliableUpdate
then
2066 NetTimeToReliable
:= 0;
2067 NetTimeToUpdate
:= NetUpdateRate
;
2071 NetTimeToUpdate
:= 0;
2076 // send only mosters with some unexpected changes
2077 g_Mons_ForEach(sendMonsPosUnexpected
);
2080 // send unexpected platform changes
2081 g_Map_NetSendInterestingPanels();
2083 if NetUseMaster
then
2085 if gTime
>= NetTimeToMaster
then
2087 if (NetMHost
= nil) or (NetMPeer
= nil) then
2089 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
2093 NetTimeToMaster
:= gTime
+ NetMasterRate
;
2097 else if (NetMode
= NET_CLIENT
) then
2099 MC_SEND_PlayerPos();
2101 end; // if gameOn ...
2103 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2104 if g_ActiveWindow
<> nil then
2106 w
:= e_GetFirstKeyPressed();
2108 if (w
<> IK_INVALID
) then
2110 Msg
.Msg
:= MESSAGE_DIKEY
;
2112 g_ActiveWindow
.OnMessage(Msg
);
2115 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2116 if g_ActiveWindow
<> nil then
2117 g_ActiveWindow
.Update();
2119 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2120 if gResolutionChange
then
2122 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2123 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2124 gResolutionChange
:= False;
2125 g_ActiveWindow
:= nil;
2128 // Íóæíî ñìåíèòü ÿçûê:
2129 if gLanguageChange
then
2131 //e_WriteLog('Read language file', MSG_NOTIFY);
2132 //g_Language_Load(DataDir + gLanguage + '.txt');
2133 g_Language_Set(gLanguage
);
2135 gLanguageChange
:= False;
2139 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2140 if e_KeyPressed(IK_F10
) and
2142 (not gConsoleShow
) and
2143 (g_ActiveWindow
= nil) then
2148 Time
:= GetTimer() {div 1000};
2150 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2151 if gDelayedEvents
<> nil then
2152 for a
:= 0 to High(gDelayedEvents
) do
2153 if gDelayedEvents
[a
].Pending
and
2155 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2156 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2159 case gDelayedEvents
[a
].DEType
of
2161 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2164 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2168 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2169 if g_Game_IsNet
and g_Game_IsServer
then
2170 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2174 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2176 gDelayedEvents
[a
].Pending
:= False;
2179 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2180 UPSCounter
:= UPSCounter
+ 1;
2181 if Time
- UPSTime
>= 1000 then
2190 g_Weapon_AddDynLights();
2191 g_Items_AddDynLights();
2195 procedure g_Game_LoadChatSounds(Resource
: string);
2198 FileName
, Snd
: string;
2200 len
, cnt
, tags
, i
, j
: Integer;
2203 FileName
:= g_ExtractWadName(Resource
);
2205 WAD
:= TWADFile
.Create();
2206 WAD
.ReadFile(FileName
);
2208 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2215 cfg
:= TConfig
.CreateMem(p
, len
);
2216 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2218 SetLength(gChatSounds
, cnt
);
2219 for i
:= 0 to Length(gChatSounds
) - 1 do
2221 gChatSounds
[i
].Sound
:= nil;
2222 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2223 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2224 if (Snd
= '') or (Tags
<= 0) then
2226 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2227 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2228 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2229 SetLength(gChatSounds
[i
].Tags
, tags
);
2230 for j
:= 0 to tags
- 1 do
2231 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2232 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2239 procedure g_Game_FreeChatSounds();
2243 for i
:= 0 to Length(gChatSounds
) - 1 do
2245 gChatSounds
[i
].Sound
.Free();
2246 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2248 SetLength(gChatSounds
, 0);
2252 procedure g_Game_LoadData();
2259 if DataLoaded
then Exit
;
2261 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2263 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2264 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2265 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2266 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2267 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2268 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2269 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2270 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2271 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2272 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2273 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2274 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2275 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2276 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2277 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2280 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2281 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2282 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2283 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2287 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2288 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2289 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2290 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2291 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
2297 hasPBarGfx
:= false;
2301 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2302 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2303 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2304 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2305 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2306 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2307 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2308 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2309 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2310 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2311 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2312 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2313 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2314 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2315 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2316 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2317 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2318 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2319 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2320 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2321 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2322 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2323 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2324 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2325 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2326 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2327 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2328 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2329 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2330 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2331 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2332 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2333 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2334 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2335 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2336 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2337 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2338 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2339 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2341 goodsnd
[0] := TPlayableSound
.Create();
2342 goodsnd
[1] := TPlayableSound
.Create();
2343 goodsnd
[2] := TPlayableSound
.Create();
2344 goodsnd
[3] := TPlayableSound
.Create();
2346 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2347 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2348 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2349 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2351 killsnd
[0] := TPlayableSound
.Create();
2352 killsnd
[1] := TPlayableSound
.Create();
2353 killsnd
[2] := TPlayableSound
.Create();
2354 killsnd
[3] := TPlayableSound
.Create();
2356 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2357 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2358 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2359 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2361 hahasnd
[0] := TPlayableSound
.Create();
2362 hahasnd
[1] := TPlayableSound
.Create();
2363 hahasnd
[2] := TPlayableSound
.Create();
2365 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2366 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2367 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2369 sound_get_flag
[0] := TPlayableSound
.Create();
2370 sound_get_flag
[1] := TPlayableSound
.Create();
2371 sound_lost_flag
[0] := TPlayableSound
.Create();
2372 sound_lost_flag
[1] := TPlayableSound
.Create();
2373 sound_ret_flag
[0] := TPlayableSound
.Create();
2374 sound_ret_flag
[1] := TPlayableSound
.Create();
2375 sound_cap_flag
[0] := TPlayableSound
.Create();
2376 sound_cap_flag
[1] := TPlayableSound
.Create();
2378 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2379 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2380 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2381 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2382 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2383 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2384 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2385 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2387 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2389 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2392 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2393 g_Weapon_LoadData();
2395 g_Monsters_LoadData();
2400 procedure g_Game_FreeData();
2402 if not DataLoaded
then Exit
;
2405 g_Weapon_FreeData();
2406 g_Monsters_FreeData();
2408 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2410 g_Texture_Delete('NOTEXTURE');
2411 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2412 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2413 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2414 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2415 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2416 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2417 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2418 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2419 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2420 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2421 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2422 g_Frames_DeleteByName('FRAMES_TELEPORT');
2423 g_Frames_DeleteByName('FRAMES_PUNCH');
2424 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2425 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2426 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2427 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2428 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2429 g_Sound_Delete('SOUND_GAME_TELEPORT');
2430 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2431 g_Sound_Delete('SOUND_GAME_SECRET');
2432 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2433 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2434 g_Sound_Delete('SOUND_GAME_BULK1');
2435 g_Sound_Delete('SOUND_GAME_BULK2');
2436 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2437 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2438 g_Sound_Delete('SOUND_GAME_BURNING');
2439 g_Sound_Delete('SOUND_GAME_SWITCH1');
2440 g_Sound_Delete('SOUND_GAME_SWITCH0');
2447 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2448 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2449 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2450 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2457 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2458 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2459 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2460 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2466 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2467 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2468 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2470 sound_get_flag
[0].Free();
2471 sound_get_flag
[1].Free();
2472 sound_lost_flag
[0].Free();
2473 sound_lost_flag
[1].Free();
2474 sound_ret_flag
[0].Free();
2475 sound_ret_flag
[1].Free();
2476 sound_cap_flag
[0].Free();
2477 sound_cap_flag
[1].Free();
2479 g_Sound_Delete('SOUND_CTF_GET1');
2480 g_Sound_Delete('SOUND_CTF_GET2');
2481 g_Sound_Delete('SOUND_CTF_LOST1');
2482 g_Sound_Delete('SOUND_CTF_LOST2');
2483 g_Sound_Delete('SOUND_CTF_RETURN1');
2484 g_Sound_Delete('SOUND_CTF_RETURN2');
2485 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2486 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2488 g_Game_FreeChatSounds();
2490 DataLoaded
:= False;
2493 procedure DrawCustomStat();
2499 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2500 s1
, s2
, topstr
: String;
2502 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2504 g_ProcessMessages();
2506 if g_Console_Action(ACTION_SCORES
) then
2508 if not gStatsPressed
then
2510 gStatsOff
:= not gStatsOff
;
2511 gStatsPressed
:= True;
2515 gStatsPressed
:= False;
2519 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2520 w
:= (Length(s1
) * ww2
) div 2;
2521 x
:= gScreenWidth
div 2 - w
;
2523 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2527 if (gGameSettings
.GameMode
= GM_COOP
) then
2529 if gMissionFailed
then
2530 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2532 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2535 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2537 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2538 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2540 if g_Game_IsNet
then
2542 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2543 if not gChatShow
then
2544 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2545 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2548 if g_Game_IsClient
then
2549 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2551 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2552 if not gChatShow
then
2553 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2554 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2559 w
:= gScreenWidth
-x
*2;
2565 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2566 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2568 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2570 case CustomStat
.GameMode
of
2573 if gGameSettings
.MaxLives
= 0 then
2574 s1
:= _lc
[I_GAME_DM
]
2576 s1
:= _lc
[I_GAME_LMS
];
2580 if gGameSettings
.MaxLives
= 0 then
2581 s1
:= _lc
[I_GAME_TDM
]
2583 s1
:= _lc
[I_GAME_TLMS
];
2585 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2588 if gGameSettings
.MaxLives
= 0 then
2589 s1
:= _lc
[I_GAME_COOP
]
2591 s1
:= _lc
[I_GAME_SURV
];
2597 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2601 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2602 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2605 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2606 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2607 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2608 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2610 pc
:= Length(CustomStat
.PlayerStat
);
2611 if pc
= 0 then Exit
;
2613 if CustomStat
.GameMode
= GM_COOP
then
2615 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2617 s2
:= _lc
[I_GAME_MONSTERS
];
2618 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2619 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2621 s2
:= _lc
[I_GAME_SECRETS
];
2622 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2623 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2626 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2628 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2629 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2630 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2632 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2633 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2634 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2638 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2643 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2644 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2645 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2647 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2650 for t
:= TEAM_RED
to TEAM_BLUE
do
2652 if t
= TEAM_RED
then
2654 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2655 gStdFont
, 255, 0, 0, 1);
2656 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2657 gStdFont
, 255, 0, 0, 1);
2664 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2665 gStdFont
, 0, 0, 255, 1);
2666 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2667 gStdFont
, 0, 0, 255, 1);
2673 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2676 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2677 if CustomStat
.PlayerStat
[p
].Team
= t
then
2678 with CustomStat
.PlayerStat
[p
] do
2692 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2693 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2694 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2701 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2704 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2705 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2706 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2709 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2710 with CustomStat
.PlayerStat
[p
] do
2712 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2719 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2720 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2721 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2727 procedure DrawSingleStat();
2729 tm
, key_x
, val_x
, y
: Integer;
2733 procedure player_stat(n
: Integer);
2739 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2740 s2
:= Format(' %d', [gTotalMonsters
]);
2742 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2743 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2744 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2745 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2747 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2748 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2750 // "Kills-per-minute: ##.#":
2751 s1
:= _lc
[I_MENU_INTER_KPM
];
2753 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2755 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2756 s2
:= Format(' %.1f', [kpm
]);
2758 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2759 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2761 // "Secrets found: # / #":
2762 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2763 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2765 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2766 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2767 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2768 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2770 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2771 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2775 // "Level Complete":
2776 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2777 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2779 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2780 s1
:= _lc
[I_MENU_INTER_KPM
];
2781 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2784 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2786 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2787 val_x
:= key_x
+ w1
;
2790 tm
:= SingleStat
.GameTime
div 1000;
2791 s1
:= _lc
[I_MENU_INTER_TIME
];
2792 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2794 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2795 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2797 if SingleStat
.TwoPlayers
then
2800 s1
:= _lc
[I_MENU_PLAYER_1
];
2801 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2802 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2804 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2809 s1
:= _lc
[I_MENU_PLAYER_2
];
2810 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2811 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2813 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2819 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2825 procedure DrawLoadingStat();
2826 procedure drawRect (x
, y
, w
, h
: Integer);
2828 if (w
< 1) or (h
< 1) then exit
;
2830 glVertex2f(x
+0.375, y
+0.375);
2831 glVertex2f(x
+w
+0.375, y
+0.375);
2832 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2833 glVertex2f(x
+0.375, y
+h
+0.375);
2837 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2839 rectW
, rectH
: Integer;
2846 idl
, idr
, idb
, idm
: LongWord;
2850 if (total
< 1) then exit
;
2851 if (cur
< 1) then exit
; // don't blink
2852 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2853 //if (cur < 0) then cur := 0;
2854 //if (cur > total) then cur := total;
2857 if (hasPBarGfx
) then
2859 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2860 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2861 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2862 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2863 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2864 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2865 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2866 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2868 //rectW := gScreenWidth-360;
2869 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2872 x0
:= (gScreenWidth
-rectW
) div 2;
2873 y0
:= gScreenHeight
-rectH
-64;
2874 if (y0
< 2) then y0
:= 2;
2876 glEnable(GL_SCISSOR_TEST
);
2879 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2880 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2881 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2884 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2886 while (f
< x0
+rectW
) do
2888 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2893 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2894 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2897 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2898 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2902 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2908 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2912 rectW
:= gScreenWidth
-64;
2915 x0
:= (gScreenWidth
-rectW
) div 2;
2916 y0
:= gScreenHeight
-rectH
-64;
2917 if (y0
< 2) then y0
:= 2;
2919 glDisable(GL_BLEND
);
2920 glDisable(GL_TEXTURE_2D
);
2922 //glClearColor(0, 0, 0, 0);
2923 //glClear(GL_COLOR_BUFFER_BIT);
2925 glColor4ub(127, 127, 127, 255);
2926 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2928 glColor4ub(0, 0, 0, 255);
2929 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2931 glColor4ub(127, 127, 127, 255);
2932 wdt
:= rectW
*cur
div total
;
2933 if (wdt
> rectW
) then wdt
:= rectW
;
2934 drawRect(x0
, y0
, wdt
, rectH
);
2943 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2945 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2946 yy
:= (gScreenHeight
div 3);
2947 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2948 xx
:= (gScreenWidth
div 3);
2952 for i
:= 0 to NextMsg
-1 do
2954 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2955 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2959 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2960 yy
:= yy
+ LOADING_INTERLINE
;
2961 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2966 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2968 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2970 function monDraw (mon
: TMonster
): Boolean;
2972 result
:= false; // don't stop
2977 // Ëåâûé âåðõíèé óãîë
2978 aX
:= Obj
.X
div ScaleSz
+ 1;
2979 aY
:= Obj
.Y
div ScaleSz
+ 1;
2981 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2982 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2983 // Ïðàâûé íèæíèé óãîë
2984 aX2
:= aX
+ aX2
- 1;
2985 aY2
:= aY
+ aY2
- 1;
2986 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2992 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2993 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2996 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2997 ScaleSz
:= 16 div Scale
;
2998 // Ðàçìåðû ìèíè-êàðòû:
2999 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3000 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3002 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3004 if gWalls
<> nil then
3007 for a
:= 0 to High(gWalls
) do
3009 if PanelType
<> 0 then
3011 // Ëåâûé âåðõíèé óãîë:
3012 aX
:= X
div ScaleSz
;
3013 aY
:= Y
div ScaleSz
;
3015 aX2
:= max(Width
div ScaleSz
, 1);
3016 aY2
:= max(Height
div ScaleSz
, 1);
3017 // Ïðàâûé íèæíèé óãîë:
3018 aX2
:= aX
+ aX2
- 1;
3019 aY2
:= aY
+ aY2
- 1;
3022 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3023 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3024 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3028 if gSteps
<> nil then
3031 for a
:= 0 to High(gSteps
) do
3033 if PanelType
<> 0 then
3035 // Ëåâûé âåðõíèé óãîë:
3036 aX
:= X
div ScaleSz
;
3037 aY
:= Y
div ScaleSz
;
3039 aX2
:= max(Width
div ScaleSz
, 1);
3040 aY2
:= max(Height
div ScaleSz
, 1);
3041 // Ïðàâûé íèæíèé óãîë:
3042 aX2
:= aX
+ aX2
- 1;
3043 aY2
:= aY
+ aY2
- 1;
3045 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3048 if gLifts
<> nil then
3051 for a
:= 0 to High(gLifts
) do
3053 if PanelType
<> 0 then
3055 // Ëåâûé âåðõíèé óãîë:
3056 aX
:= X
div ScaleSz
;
3057 aY
:= Y
div ScaleSz
;
3059 aX2
:= max(Width
div ScaleSz
, 1);
3060 aY2
:= max(Height
div ScaleSz
, 1);
3061 // Ïðàâûé íèæíèé óãîë:
3062 aX2
:= aX
+ aX2
- 1;
3063 aY2
:= aY
+ aY2
- 1;
3066 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3067 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3068 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3069 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3073 if gWater
<> nil then
3076 for a
:= 0 to High(gWater
) do
3078 if PanelType
<> 0 then
3080 // Ëåâûé âåðõíèé óãîë:
3081 aX
:= X
div ScaleSz
;
3082 aY
:= Y
div ScaleSz
;
3084 aX2
:= max(Width
div ScaleSz
, 1);
3085 aY2
:= max(Height
div ScaleSz
, 1);
3086 // Ïðàâûé íèæíèé óãîë:
3087 aX2
:= aX
+ aX2
- 1;
3088 aY2
:= aY
+ aY2
- 1;
3090 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3093 if gAcid1
<> nil then
3095 // Ðèñóåì êèñëîòó 1:
3096 for a
:= 0 to High(gAcid1
) do
3098 if PanelType
<> 0 then
3100 // Ëåâûé âåðõíèé óãîë:
3101 aX
:= X
div ScaleSz
;
3102 aY
:= Y
div ScaleSz
;
3104 aX2
:= max(Width
div ScaleSz
, 1);
3105 aY2
:= max(Height
div ScaleSz
, 1);
3106 // Ïðàâûé íèæíèé óãîë:
3107 aX2
:= aX
+ aX2
- 1;
3108 aY2
:= aY
+ aY2
- 1;
3110 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3113 if gAcid2
<> nil then
3115 // Ðèñóåì êèñëîòó 2:
3116 for a
:= 0 to High(gAcid2
) do
3118 if PanelType
<> 0 then
3120 // Ëåâûé âåðõíèé óãîë:
3121 aX
:= X
div ScaleSz
;
3122 aY
:= Y
div ScaleSz
;
3124 aX2
:= max(Width
div ScaleSz
, 1);
3125 aY2
:= max(Height
div ScaleSz
, 1);
3126 // Ïðàâûé íèæíèé óãîë:
3127 aX2
:= aX
+ aX2
- 1;
3128 aY2
:= aY
+ aY2
- 1;
3130 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3133 if gPlayers
<> nil then
3136 for a
:= 0 to High(gPlayers
) do
3137 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3139 // Ëåâûé âåðõíèé óãîë:
3140 aX
:= Obj
.X
div ScaleSz
+ 1;
3141 aY
:= Obj
.Y
div ScaleSz
+ 1;
3143 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3144 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3145 // Ïðàâûé íèæíèé óãîë:
3146 aX2
:= aX
+ aX2
- 1;
3147 aY2
:= aY
+ aY2
- 1;
3149 if gPlayers
[a
] = p
then
3150 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3153 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3154 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3155 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3160 g_Mons_ForEach(monDraw
);
3165 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3167 if not hasAmbient
then exit
;
3168 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3172 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3173 //FIXME: broken for splitscreen mode
3174 procedure renderDynLightsInternal ();
3176 //hasAmbient: Boolean;
3177 //ambColor: TDFColor;
3179 lx
, ly
, lrad
: Integer;
3180 scxywh
: array[0..3] of GLint
;
3183 if e_NoGraphics
then exit
;
3185 //TODO: lights should be in separate grid, i think
3186 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3187 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3190 //ambColor := gCurrentMap['light_ambient'].rgba;
3191 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3193 { // this will multiply incoming color to alpha from framebuffer
3195 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3199 * light rendering: (INVALID!)
3200 * glStencilFunc(GL_EQUAL, 0, $ff);
3202 * glClear(GL_STENCIL_BUFFER_BIT);
3203 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3204 * draw shadow volume into stencil buffer
3205 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3206 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3208 * draw color-less quad with light alpha (WARNING! don't touch color!)
3209 * glEnable(GL_BLEND);
3210 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3211 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3213 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3214 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3216 // setup OpenGL parameters
3217 glStencilMask($FFFFFFFF);
3218 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3219 glEnable(GL_STENCIL_TEST
);
3220 glEnable(GL_SCISSOR_TEST
);
3221 glClear(GL_STENCIL_BUFFER_BIT
);
3222 glStencilFunc(GL_EQUAL
, 0, $ff);
3224 for lln
:= 0 to g_dynLightCount
-1 do
3226 lx
:= g_dynLights
[lln
].x
;
3227 ly
:= g_dynLights
[lln
].y
;
3228 lrad
:= g_dynLights
[lln
].radius
;
3229 if (lrad
< 3) then continue
;
3231 if (lx
-sX
+lrad
< 0) then continue
;
3232 if (ly
-sY
+lrad
< 0) then continue
;
3233 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3234 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3236 // set scissor to optimize drawing
3237 if (g_dbg_scale
= 1.0) then
3239 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3243 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3245 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3246 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3247 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3248 // draw extruded panels
3249 glDisable(GL_TEXTURE_2D
);
3250 glDisable(GL_BLEND
);
3251 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3252 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3253 // render light texture
3254 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3255 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3258 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3259 glEnable(GL_TEXTURE_2D
);
3260 // color and opacity
3261 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3262 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3264 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3265 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3266 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3267 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3272 glDisable(GL_STENCIL_TEST
);
3273 glDisable(GL_BLEND
);
3274 glDisable(GL_SCISSOR_TEST
);
3275 //glScissor(0, 0, sWidth, sHeight);
3277 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3278 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3282 function fixViewportForScale (): Boolean;
3284 nx0
, ny0
, nw
, nh
: Integer;
3287 if (g_dbg_scale
<> 1.0) then
3290 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3291 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3292 nw
:= round(sWidth
/g_dbg_scale
);
3293 nh
:= round(sHeight
/g_dbg_scale
);
3302 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3303 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3304 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3306 TDrawCB
= procedure ();
3309 hasAmbient
: Boolean;
3311 doAmbient
: Boolean = false;
3313 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3318 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3319 if gdbg_map_use_accel_render
then
3321 tagmask
:= panelTypeToTag(panType
);
3322 while (gDrawPanelList
.count
> 0) do
3324 pan
:= TPanel(gDrawPanelList
.front());
3325 if ((pan
.tag
and tagmask
) = 0) then break
;
3326 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3327 gDrawPanelList
.popFront();
3332 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3334 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3337 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3339 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3340 if assigned(cb
) then cb();
3341 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3345 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3347 // our accelerated renderer will collect all panels to gDrawPanelList
3348 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3349 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3350 if gdbg_map_use_accel_render
then
3352 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3354 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3356 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3357 g_Map_DrawBack(backXOfs
, backYOfs
);
3358 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3360 if setTransMatrix
then
3362 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3363 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3364 glTranslatef(-sX
, -sY
, 0);
3368 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3369 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3374 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3375 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3376 glClear(GL_COLOR_BUFFER_BIT);
3379 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3382 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3383 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3384 drawOther('items', @g_Items_Draw
);
3385 drawOther('weapons', @g_Weapon_Draw
);
3386 drawOther('shells', @g_Player_DrawShells
);
3387 drawOther('drawall', @g_Player_DrawAll
);
3388 drawOther('corpses', @g_Player_DrawCorpses
);
3389 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3390 drawOther('monsters', @g_Monsters_Draw
);
3391 drawOther('itemdrop', @g_Items_DrawDrop
);
3392 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3393 drawOther('gfx', @g_GFX_Draw
);
3394 drawOther('flags', @g_Map_DrawFlags
);
3395 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3396 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3397 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3398 drawOther('dynlights', @renderDynLightsInternal
);
3400 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3402 renderAmbientQuad(hasAmbient
, ambColor
);
3406 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3409 if g_debug_HealthBar
then
3411 g_Monsters_DrawHealth();
3412 g_Player_DrawHealth();
3415 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3419 procedure DrawMapView(x
, y
, w
, h
: Integer);
3426 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3427 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3434 fixViewportForScale();
3435 renderMapInternal(-bx
, -by
, true);
3441 procedure DrawPlayer(p
: TPlayer
);
3443 px
, py
, a
, b
, c
, d
: Integer;
3446 if (p
= nil) or (p
.FDummy
) then
3449 g_Map_DrawBack(0, 0);
3454 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3455 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3461 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3462 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3464 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3466 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3467 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3469 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3470 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3472 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3473 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3476 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3479 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3480 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3483 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3488 // scaled, ignore level bounds
3489 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3490 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3493 if p
.IncCam
<> 0 then
3495 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3497 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3499 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3503 if py
< gPlayerScreenSize
.Y
div 2 then
3505 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3507 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3511 if p
.IncCam
< 0 then
3513 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3516 if p
.IncCam
> 0 then
3518 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3522 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3523 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3524 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3526 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3527 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3528 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3531 sY
:= -(b
+p
.IncCam
);
3532 sWidth
:= gPlayerScreenSize
.X
;
3533 sHeight
:= gPlayerScreenSize
.Y
;
3535 //glTranslatef(a, b+p.IncCam, 0);
3537 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3539 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3540 fixViewportForScale();
3541 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3543 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3545 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3546 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3547 if (sX
< 0) then sX
:= 0;
3548 if (sY
< 0) then sY
:= 0;
3550 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3551 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3554 //r_smallmap_h: 0: left; 1: center; 2: right
3555 //r_smallmap_v: 0: top; 1: center; 2: bottom
3557 if (gMapInfo
.Width
= sWidth
) then
3561 else if (gMapInfo
.Width
< sWidth
) then
3563 case r_smallmap_h
of
3564 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3565 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3566 else sX
:= 0; // left
3570 if (gMapInfo
.Height
= sHeight
) then
3574 else if (gMapInfo
.Height
< sHeight
) then
3576 case r_smallmap_v
of
3577 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3578 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3579 else sY
:= 0; // top
3585 p
.viewPortW
:= sWidth
;
3586 p
.viewPortH
:= sHeight
;
3588 {$IFDEF ENABLE_HOLMES}
3589 if (p
= gPlayer1
) then
3591 g_Holmes_plrViewPos(sX
, sY
);
3592 g_Holmes_plrViewSize(sWidth
, sHeight
);
3596 renderMapInternal(-c
, -d
, true);
3598 if (gGameSettings
.GameMode
<> GM_SINGLE
) and gPlayerIndicator
then
3600 if p
.FSpectator
then
3601 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3602 p
.GameY
+ PLAYER_RECT_CY
- 4,
3603 'X', gStdFont
, 255, 255, 255, 1, True);
3605 for a := 0 to High(gCollideMap) do
3606 for b := 0 to High(gCollideMap[a]) do
3609 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3611 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3615 1: e_DrawPoint(1, b, a, 200, 200, 200);
3616 2: e_DrawPoint(1, b, a, 64, 64, 255);
3617 3: e_DrawPoint(1, b, a, 255, 0, 255);
3627 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3628 if g_Debug_Player
then
3629 g_Player_DrawDebug(p
);
3633 procedure drawProfilers ();
3638 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3639 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3640 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3643 procedure g_Game_Draw();
3650 plView1
, plView2
: TPlayer
;
3653 if gExit
= EXIT_QUIT
then Exit
;
3655 Time
:= GetTimer() {div 1000};
3656 FPSCounter
:= FPSCounter
+1;
3657 if Time
- FPSTime
>= 1000 then
3664 if gGameOn
or (gState
= STATE_FOLD
) then
3666 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3668 gSpectMode
:= SPECT_NONE
;
3669 if not gRevertPlayers
then
3671 plView1
:= gPlayer1
;
3672 plView2
:= gPlayer2
;
3676 plView1
:= gPlayer2
;
3677 plView2
:= gPlayer1
;
3681 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3683 gSpectMode
:= SPECT_NONE
;
3684 if gPlayer2
= nil then
3687 plView1
:= gPlayer2
;
3696 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3697 gSpectMode
:= SPECT_STATS
;
3699 if gSpectMode
= SPECT_PLAYERS
then
3700 if gPlayers
<> nil then
3702 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3703 if plView1
= nil then
3705 gSpectPID1
:= GetActivePlayerID_Next();
3706 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3708 if gSpectViewTwo
then
3710 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3711 if plView2
= nil then
3713 gSpectPID2
:= GetActivePlayerID_Next();
3714 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3719 if gSpectMode
= SPECT_MAPVIEW
then
3721 // Ðåæèì ïðîñìîòðà êàðòû
3723 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3724 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3725 gHearPoint1
.Active
:= True;
3726 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3727 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3728 gHearPoint2
.Active
:= False;
3732 Split
:= (plView1
<> nil) and (plView2
<> nil);
3734 // Òî÷êè ñëóõà èãðîêîâ
3735 if plView1
<> nil then
3737 gHearPoint1
.Active
:= True;
3738 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3739 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3741 gHearPoint1
.Active
:= False;
3742 if plView2
<> nil then
3744 gHearPoint2
.Active
:= True;
3745 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3746 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3748 gHearPoint2
.Active
:= False;
3750 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3751 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3754 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3755 if gScreenHeight
mod 2 = 0 then
3756 Dec(gPlayerScreenSize
.Y
);
3759 gPlayerScreenSize
.Y
:= gScreenHeight
;
3762 if gScreenHeight
mod 2 = 0 then
3763 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3765 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3767 DrawPlayer(plView1
);
3768 gPlayer1ScreenCoord
.X
:= sX
;
3769 gPlayer1ScreenCoord
.Y
:= sY
;
3773 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3775 DrawPlayer(plView2
);
3776 gPlayer2ScreenCoord
.X
:= sX
;
3777 gPlayer2ScreenCoord
.Y
:= sY
;
3780 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3783 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3786 {$IFDEF ENABLE_HOLMES}
3788 if (g_holmes_enabled
) then g_Holmes_Draw();
3791 if MessageText
<> '' then
3795 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3797 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3798 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3800 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3801 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3804 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3806 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3808 // Draw spectator GUI
3811 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3814 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3816 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3818 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3820 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3821 if gSpectMode
= SPECT_STATS
then
3823 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3824 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
3826 if gSpectMode
= SPECT_MAPVIEW
then
3828 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3829 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3830 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3831 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3832 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3834 if gSpectMode
= SPECT_PLAYERS
then
3836 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3837 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3838 if gSpectViewTwo
then
3840 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3841 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3842 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3843 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3847 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3848 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3854 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3856 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3857 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3859 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3860 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3861 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3866 if (gState
= STATE_MENU
) then
3868 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3870 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3871 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3873 // F3 at menu will show game loading dialog
3874 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3875 if (g_ActiveWindow
<> nil) then
3877 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3878 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3882 // F3 at titlepic will show game loading dialog
3883 if e_KeyPressed(IK_F3
) then
3885 g_Menu_Show_LoadMenu(true);
3886 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3891 if gState
= STATE_FOLD
then
3893 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3896 if gState
= STATE_INTERCUSTOM
then
3898 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3900 back
:= 'TEXTURE_endpic';
3901 if not g_Texture_Get(back
, ID
) then
3902 back
:= _lc
[I_TEXTURE_ENDPIC
];
3907 if g_Texture_Get(back
, ID
) then
3908 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3910 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3914 if g_ActiveWindow
<> nil then
3916 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3917 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3921 if gState
= STATE_INTERSINGLE
then
3923 if EndingGameCounter
> 0 then
3925 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3931 if g_Texture_Get(back
, ID
) then
3932 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3934 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3938 if g_ActiveWindow
<> nil then
3940 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3941 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3946 if gState
= STATE_ENDPIC
then
3949 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3950 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3952 if ID
<> DWORD(-1) then
3953 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3955 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3957 if g_ActiveWindow
<> nil then
3959 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3960 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3964 if gState
= STATE_SLIST
then
3966 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3968 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3969 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3970 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3972 g_Serverlist_Draw(slCurrent
, slTable
);
3976 if g_ActiveWindow
<> nil then
3980 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3981 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3983 g_ActiveWindow
.Draw();
3988 if g_debug_Sounds
and gGameOn
then
3990 for w
:= 0 to High(e_SoundsArray
) do
3991 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3992 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3997 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3998 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4001 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
4002 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4004 if gGameOn
then drawProfilers();
4006 {$IFDEF ENABLE_HOLMES}
4013 procedure g_Game_Quit();
4015 g_Game_StopAllSounds(True);
4017 g_Game_SaveOptions();
4019 g_PlayerModel_FreeData();
4020 g_Texture_DeleteAll();
4021 g_Frames_DeleteAll();
4022 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4024 if NetInitDone
then g_Net_Free
;
4026 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4027 if gMapToDelete
<> '' then
4028 g_Game_DeleteTestMap();
4034 procedure g_FatalError(Text: String);
4036 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4037 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4039 gExit
:= EXIT_SIMPLE
;
4042 procedure g_SimpleError(Text: String);
4044 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4045 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4048 procedure g_Game_SetupScreenSize();
4050 RES_FACTOR
= 4.0 / 3.0;
4056 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4057 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4058 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4059 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4061 gPlayerScreenSize
.Y
:= gScreenHeight
;
4063 // Ðàçìåð çàäíåãî ïëàíà:
4064 if BackID
<> DWORD(-1) then
4067 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4068 (gScreenHeight
*s
> gMapInfo
.Height
) then
4070 gBackSize
.X
:= gScreenWidth
;
4071 gBackSize
.Y
:= gScreenHeight
;
4075 e_GetTextureSize(BackID
, @bw
, @bh
);
4076 rf
:= Single(bw
) / Single(bh
);
4077 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4078 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4079 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4080 if (s
< 1.0) then s
:= 1.0;
4081 gBackSize
.X
:= Round(bw
*s
);
4082 gBackSize
.Y
:= Round(bh
*s
);
4087 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4089 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
4092 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4094 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4095 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4097 if gPlayer1
= nil then
4099 if g_Game_IsClient
then
4101 if NetPlrUID1
> -1 then
4103 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4104 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4109 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4110 Team
:= gPlayer1Settings
.Team
;
4112 // Ñîçäàíèå ïåðâîãî èãðîêà:
4113 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4114 gPlayer1Settings
.Color
,
4116 if gPlayer1
= nil then
4117 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4120 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4121 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4122 if g_Game_IsServer
and g_Game_IsNet
then
4123 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4124 gPlayer1
.Respawn(False, True);
4126 if g_Game_IsNet
and NetUseMaster
then
4132 if gPlayer2
= nil then
4134 if g_Game_IsClient
then
4136 if NetPlrUID2
> -1 then
4137 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4141 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4142 Team
:= gPlayer2Settings
.Team
;
4144 // Ñîçäàíèå âòîðîãî èãðîêà:
4145 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4146 gPlayer2Settings
.Color
,
4148 if gPlayer2
= nil then
4149 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4152 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4153 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4154 if g_Game_IsServer
and g_Game_IsNet
then
4155 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4156 gPlayer2
.Respawn(False, True);
4158 if g_Game_IsNet
and NetUseMaster
then
4166 procedure g_Game_RemovePlayer();
4170 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4171 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4176 if g_Game_IsServer
then
4179 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4180 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4181 g_Player_Remove(Pl
.UID
);
4183 if g_Game_IsNet
and NetUseMaster
then
4192 if g_Game_IsServer
then
4195 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4196 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4197 g_Player_Remove(Pl
.UID
);
4199 if g_Game_IsNet
and NetUseMaster
then
4204 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4210 procedure g_Game_Spectate();
4212 g_Game_RemovePlayer();
4213 if gPlayer1
<> nil then
4214 g_Game_RemovePlayer();
4217 procedure g_Game_SpectateCenterView();
4219 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4220 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4223 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4230 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4232 g_Game_ClearLoading();
4235 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4238 gGameSettings
.GameType
:= GT_SINGLE
;
4239 gGameSettings
.MaxLives
:= 0;
4240 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4241 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4242 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4243 gSwitchGameMode
:= GM_SINGLE
;
4245 g_Game_ExecuteEvent('ongamestart');
4247 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4248 g_Game_SetupScreenSize();
4250 // Ñîçäàíèå ïåðâîãî èãðîêà:
4251 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4252 gPlayer1Settings
.Color
,
4253 gPlayer1Settings
.Team
, False));
4254 if gPlayer1
= nil then
4256 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4260 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4263 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4266 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4267 gPlayer2Settings
.Color
,
4268 gPlayer2Settings
.Team
, False));
4269 if gPlayer2
= nil then
4271 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4275 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4279 // Çàãðóçêà è çàïóñê êàðòû:
4280 if not g_Game_StartMap(MAP
, True) then
4282 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4283 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4287 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4291 for i
:= nPl
+1 to nPlayers
do
4292 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4295 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4296 TimeLimit
, GoalLimit
: Word;
4298 Options
: LongWord; nPlayers
: Byte);
4304 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4306 g_Game_ClearLoading();
4309 gGameSettings
.GameType
:= GT_CUSTOM
;
4310 gGameSettings
.GameMode
:= GameMode
;
4311 gSwitchGameMode
:= GameMode
;
4312 gGameSettings
.TimeLimit
:= TimeLimit
;
4313 gGameSettings
.GoalLimit
:= GoalLimit
;
4314 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4315 gGameSettings
.Options
:= Options
;
4317 gCoopTotalMonstersKilled
:= 0;
4318 gCoopTotalSecretsFound
:= 0;
4319 gCoopTotalMonsters
:= 0;
4320 gCoopTotalSecrets
:= 0;
4324 g_Game_ExecuteEvent('ongamestart');
4326 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4327 g_Game_SetupScreenSize();
4329 // Ðåæèì íàáëþäàòåëÿ:
4330 if nPlayers
= 0 then
4337 if nPlayers
>= 1 then
4339 // Ñîçäàíèå ïåðâîãî èãðîêà:
4340 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4341 gPlayer1Settings
.Color
,
4342 gPlayer1Settings
.Team
, False));
4343 if gPlayer1
= nil then
4345 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4349 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4353 if nPlayers
>= 2 then
4355 // Ñîçäàíèå âòîðîãî èãðîêà:
4356 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4357 gPlayer2Settings
.Color
,
4358 gPlayer2Settings
.Team
, False));
4359 if gPlayer2
= nil then
4361 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4365 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4369 // Çàãðóçêà è çàïóñê êàðòû:
4370 if not g_Game_StartMap(Map
, True) then
4372 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4376 // Íåò òî÷åê ïîÿâëåíèÿ:
4377 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4378 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4379 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4380 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4381 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4383 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4387 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4391 for i
:= nPl
+1 to nPlayers
do
4392 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4395 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4396 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4397 Options
: LongWord; nPlayers
: Byte;
4398 IPAddr
: LongWord; Port
: Word);
4402 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4404 g_Game_ClearLoading();
4407 gGameSettings
.GameType
:= GT_SERVER
;
4408 gGameSettings
.GameMode
:= GameMode
;
4409 gSwitchGameMode
:= GameMode
;
4410 gGameSettings
.TimeLimit
:= TimeLimit
;
4411 gGameSettings
.GoalLimit
:= GoalLimit
;
4412 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4413 gGameSettings
.Options
:= Options
;
4415 gCoopTotalMonstersKilled
:= 0;
4416 gCoopTotalSecretsFound
:= 0;
4417 gCoopTotalMonsters
:= 0;
4418 gCoopTotalSecrets
:= 0;
4422 g_Game_ExecuteEvent('ongamestart');
4424 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4425 g_Game_SetupScreenSize();
4427 // Ðåæèì íàáëþäàòåëÿ:
4428 if nPlayers
= 0 then
4434 if nPlayers
>= 1 then
4436 // Ñîçäàíèå ïåðâîãî èãðîêà:
4437 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4438 gPlayer1Settings
.Color
,
4439 gPlayer1Settings
.Team
, False));
4440 if gPlayer1
= nil then
4442 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4446 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4449 if nPlayers
>= 2 then
4451 // Ñîçäàíèå âòîðîãî èãðîêà:
4452 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4453 gPlayer2Settings
.Color
,
4454 gPlayer2Settings
.Team
, False));
4455 if gPlayer2
= nil then
4457 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4461 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4464 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4465 if NetForwardPorts
then
4466 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4469 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4471 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4475 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4477 // Çàãðóçêà è çàïóñê êàðòû:
4478 if not g_Game_StartMap(Map
, True) then
4480 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4484 // Íåò òî÷åê ïîÿâëåíèÿ:
4485 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4486 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4487 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4488 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4489 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4491 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4495 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4498 NetState
:= NET_STATE_GAME
;
4501 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4516 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4517 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4519 g_Game_ClearLoading();
4522 gGameSettings
.GameType
:= GT_CLIENT
;
4524 gCoopTotalMonstersKilled
:= 0;
4525 gCoopTotalSecretsFound
:= 0;
4526 gCoopTotalMonsters
:= 0;
4527 gCoopTotalSecrets
:= 0;
4531 g_Game_ExecuteEvent('ongamestart');
4533 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4534 g_Game_SetupScreenSize();
4536 NetState
:= NET_STATE_AUTH
;
4538 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4540 if not g_Net_Connect(Addr
, Port
) then
4542 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4543 NetState
:= NET_STATE_NONE
;
4547 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4549 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4554 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4556 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4558 Ptr
:= NetEvent
.packet
^.data
;
4559 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4562 MID
:= InMsg
.ReadByte();
4564 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4566 NetMyID
:= InMsg
.ReadByte();
4567 NetPlrUID1
:= InMsg
.ReadWord();
4569 WadName
:= InMsg
.ReadString();
4570 Map
:= InMsg
.ReadString();
4572 gWADHash
:= InMsg
.ReadMD5();
4574 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4575 gSwitchGameMode
:= gGameSettings
.GameMode
;
4576 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4577 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4578 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4579 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4580 T
:= InMsg
.ReadLongWord();
4582 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4583 if newResPath
= '' then
4585 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4586 newResPath
:= g_Res_DownloadWAD(WadName
);
4587 if newResPath
= '' then
4589 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4590 enet_packet_destroy(NetEvent
.packet
);
4591 NetState
:= NET_STATE_NONE
;
4595 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4597 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4598 gPlayer1Settings
.Color
,
4599 gPlayer1Settings
.Team
, False));
4601 if gPlayer1
= nil then
4603 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4605 enet_packet_destroy(NetEvent
.packet
);
4606 NetState
:= NET_STATE_NONE
;
4610 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4611 gPlayer1
.UID
:= NetPlrUID1
;
4612 gPlayer1
.Reset(True);
4614 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4616 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4618 enet_packet_destroy(NetEvent
.packet
);
4619 NetState
:= NET_STATE_NONE
;
4627 enet_packet_destroy(NetEvent
.packet
);
4631 enet_packet_destroy(NetEvent
.packet
);
4635 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4638 if (NetEvent
.data
<= NET_DISC_MAX
) then
4639 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4640 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4647 ProcessLoading(true);
4649 if e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_ESCAPE
) then
4658 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4659 NetState
:= NET_STATE_NONE
;
4663 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4664 gLMSRespawnTime
:= 0;
4667 NetState
:= NET_STATE_GAME
;
4668 MC_SEND_FullStateRequest
;
4669 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4672 procedure g_Game_SaveOptions();
4674 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4677 procedure g_Game_ChangeMap(const MapPath
: String);
4681 g_Game_ClearLoading();
4683 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4684 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4685 if gExitByTrigger
then
4688 gExitByTrigger
:= False;
4690 if not g_Game_StartMap(MapPath
, Force
) then
4691 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4694 procedure g_Game_Restart();
4698 if g_Game_IsClient
then
4700 map
:= g_ExtractFileName(gMapInfo
.Map
);
4704 g_Game_ClearLoading();
4705 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4708 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4710 NewWAD
, ResName
: String;
4713 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4714 g_Player_RemoveAllCorpses();
4716 if (not g_Game_IsClient
) and
4717 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4718 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4720 if gSwitchGameMode
= GM_CTF
then
4721 gGameSettings
.MaxLives
:= 0;
4722 gGameSettings
.GameMode
:= gSwitchGameMode
;
4725 gSwitchGameMode
:= gGameSettings
.GameMode
;
4727 g_Player_ResetTeams();
4729 if isWadPath(Map
) then
4731 NewWAD
:= g_ExtractWadName(Map
);
4732 ResName
:= g_ExtractFileName(Map
);
4733 if g_Game_IsServer
then
4735 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4736 g_Game_LoadWAD(NewWAD
);
4738 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4739 g_Game_ClientWAD(NewWAD
, gWADHash
);
4743 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4746 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4748 gState
:= STATE_NONE
;
4749 g_ActiveWindow
:= nil;
4755 if gGameSettings
.GameMode
= GM_CTF
then
4757 g_Map_ResetFlag(FLAG_RED
);
4758 g_Map_ResetFlag(FLAG_BLUE
);
4759 // CTF, à ôëàãîâ íåò:
4760 if not g_Map_HaveFlagPoints() then
4761 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4766 gState
:= STATE_MENU
;
4771 gPauseMain
:= false;
4772 gPauseHolmes
:= false;
4774 NetTimeToUpdate
:= 1;
4775 NetTimeToReliable
:= 0;
4776 NetTimeToMaster
:= NetMasterRate
;
4777 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4778 gLMSRespawnTime
:= 0;
4779 gMissionFailed
:= False;
4782 gCoopMonstersKilled
:= 0;
4783 gCoopSecretsFound
:= 0;
4785 gVoteInProgress
:= False;
4786 gVotePassed
:= False;
4792 if not gGameOn
then Exit
;
4794 g_Game_SpectateCenterView();
4796 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4798 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4799 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4800 gLMSSoftSpawn
:= True;
4801 if NetMode
= NET_SERVER
then
4802 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4804 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4807 if NetMode
= NET_SERVER
then
4809 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4812 if NetUseMaster
then
4814 if (NetMHost
= nil) or (NetMPeer
= nil) then
4815 if not g_Net_Slist_Connect
then
4816 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4821 if NetClients
<> nil then
4822 for I
:= 0 to High(NetClients
) do
4823 if NetClients
[I
].Used
then
4825 NetClients
[I
].Voted
:= False;
4826 if NetClients
[I
].RequestedFullUpdate
then
4828 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4829 NetClients
[I
].RequestedFullUpdate
:= False;
4833 g_Net_UnbanNonPermHosts();
4838 gCoopTotalMonstersKilled
:= 0;
4839 gCoopTotalSecretsFound
:= 0;
4840 gCoopTotalMonsters
:= 0;
4841 gCoopTotalSecrets
:= 0;
4845 g_Game_ExecuteEvent('onmapstart');
4848 procedure SetFirstLevel();
4852 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4853 if MapList
= nil then
4856 SortSArray(MapList
);
4857 gNextMap
:= MapList
[Low(MapList
)];
4862 procedure g_Game_ExitLevel(const Map
: AnsiString);
4866 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4867 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4868 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4869 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4871 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4872 if gGameSettings
.GameType
= GT_SINGLE
then
4873 gExit
:= EXIT_ENDLEVELSINGLE
4874 else // Âûøëè â âûõîä â Ñâîåé èãðå
4876 gExit
:= EXIT_ENDLEVELCUSTOM
;
4877 if gGameSettings
.GameMode
= GM_COOP
then
4878 g_Player_RememberAll
;
4880 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4883 if gGameSettings
.GameMode
= GM_COOP
then
4886 gStatsPressed
:= True;
4887 gNextMap
:= 'MAP01';
4889 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4892 if g_Game_IsNet
then
4894 MH_SEND_GameStats();
4895 MH_SEND_CoopStats();
4901 procedure g_Game_RestartLevel();
4905 if gGameSettings
.GameMode
= GM_SINGLE
then
4910 gExit
:= EXIT_ENDLEVELCUSTOM
;
4911 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4915 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4919 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4921 if not g_Game_IsClient
then
4923 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4926 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4927 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4931 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4935 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4936 g_Game_LoadWAD(NewWAD
);
4939 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4941 i
, n
, nb
, nr
: Integer;
4943 function monRespawn (mon
: TMonster
): Boolean;
4945 result
:= false; // don't stop
4946 if not mon
.FNoRespawn
then mon
.Respawn();
4950 if not g_Game_IsServer
then Exit
;
4951 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4952 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4953 gLMSRespawnTime
:= 0;
4956 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4958 gMissionFailed
:= True;
4959 g_Game_RestartLevel
;
4963 n
:= 0; nb
:= 0; nr
:= 0;
4964 for i
:= Low(gPlayers
) to High(gPlayers
) do
4965 if (gPlayers
[i
] <> nil) and
4966 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4967 (gPlayers
[i
] is TBot
)) then
4970 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4971 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4974 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4976 // wait a second until the fuckers finally decide to join
4977 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4978 gLMSRespawnTime
:= gTime
+ 1000;
4979 gLMSSoftSpawn
:= NoMapRestart
;
4983 g_Player_RemoveAllCorpses
;
4984 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4985 if g_Game_IsNet
then
4986 MH_SEND_GameEvent(NET_EV_LMS_START
);
4988 for i
:= Low(gPlayers
) to High(gPlayers
) do
4990 if gPlayers
[i
] = nil then continue
;
4991 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4992 // don't touch normal spectators
4993 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4995 gPlayers
[i
].FNoRespawn
:= True;
4996 gPlayers
[i
].Lives
:= 0;
4997 if g_Game_IsNet
then
4998 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5001 gPlayers
[i
].FNoRespawn
:= False;
5002 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5003 gPlayers
[i
].Respawn(False, True);
5004 if gGameSettings
.GameMode
= GM_COOP
then
5006 gPlayers
[i
].Frags
:= 0;
5007 gPlayers
[i
].RecallState
;
5009 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5010 gPlayer1
:= g_Player_Get(gLMSPID1
);
5011 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5012 gPlayer2
:= g_Player_Get(gLMSPID2
);
5015 g_Items_RestartRound();
5018 g_Mons_ForEach(monRespawn
);
5020 gLMSSoftSpawn
:= False;
5023 function g_Game_GetFirstMap(WAD
: String): String;
5027 MapList
:= g_Map_GetMapsList(WAD
);
5028 if MapList
= nil then
5031 SortSArray(MapList
);
5032 Result
:= MapList
[Low(MapList
)];
5034 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5040 function g_Game_GetNextMap(): String;
5047 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
5048 if MapList
= nil then
5051 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5053 SortSArray(MapList
);
5055 for I
:= Low(MapList
) to High(MapList
) do
5056 if Map
= MapList
[I
] then
5062 if MapIndex
<> -255 then
5064 if MapIndex
= High(MapList
) then
5065 Result
:= MapList
[Low(MapList
)]
5067 Result
:= MapList
[MapIndex
+ 1];
5069 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5075 procedure g_Game_NextLevel();
5077 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5078 gExit
:= EXIT_ENDLEVELCUSTOM
5081 gExit
:= EXIT_ENDLEVELSINGLE
;
5085 if gNextMap
<> '' then Exit
;
5086 gNextMap
:= g_Game_GetNextMap();
5089 function g_Game_IsTestMap(): Boolean;
5091 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5094 procedure g_Game_DeleteTestMap();
5097 //MapName: AnsiString;
5105 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5106 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5107 if (a
= 0) then exit
;
5109 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5110 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5111 Delete(gMapToDelete
, 1, a
+5);
5112 gMapToDelete
:= UpperCase(gMapToDelete
);
5114 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5117 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5118 if MapName <> TEST_MAP_NAME then
5121 if not gTempDelete then
5123 time := g_GetFileTime(WadName);
5124 WAD := TWADFile.Create();
5127 if not WAD.ReadFile(WadName) then
5128 begin // Íåò òàêîãî WAD-ôàéëà
5133 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5135 MapList := WAD.GetResourcesList('');
5137 if MapList <> nil then
5138 for a := 0 to High(MapList) do
5139 if MapList[a] = MapName then
5141 // Óäàëÿåì è ñîõðàíÿåì:
5142 WAD.RemoveResource('', MapName);
5143 WAD.SaveTo(WadName);
5148 g_SetFileTime(WadName, time);
5151 if gTempDelete
then DeleteFile(WadName
);
5154 procedure GameCVars(P
: SSArray
);
5157 stat
: TPlayerStatArray
;
5162 cmd
:= LowerCase(P
[0]);
5163 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5165 with gGameSettings
do
5167 if (Length(P
) > 1) and
5168 ((P
[1] = '1') or (P
[1] = '0')) then
5170 if (P
[1][1] = '1') then
5171 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5173 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5176 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5177 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5179 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5181 if g_Game_IsNet
then MH_SEND_GameSettings
;
5184 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5186 with gGameSettings
do
5188 if (Length(P
) > 1) and
5189 ((P
[1] = '1') or (P
[1] = '0')) then
5191 if (P
[1][1] = '1') then
5192 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5194 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5197 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5198 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5200 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5202 if g_Game_IsNet
then MH_SEND_GameSettings
;
5205 else if cmd
= 'g_gamemode' then
5207 a
:= g_Game_TextToMode(P
[1]);
5208 if a
= GM_SINGLE
then a
:= GM_COOP
;
5209 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5211 gSwitchGameMode
:= a
;
5212 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5213 (gState
= STATE_INTERSINGLE
) then
5214 gSwitchGameMode
:= GM_SINGLE
;
5216 gGameSettings
.GameMode
:= gSwitchGameMode
;
5218 if gSwitchGameMode
= gGameSettings
.GameMode
then
5219 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5220 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5222 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5223 [g_Game_ModeToText(gGameSettings
.GameMode
),
5224 g_Game_ModeToText(gSwitchGameMode
)]));
5226 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5228 with gGameSettings
do
5230 if (Length(P
) > 1) and
5231 ((P
[1] = '1') or (P
[1] = '0')) then
5233 if (P
[1][1] = '1') then
5234 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5236 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5239 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5240 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5242 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5243 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5245 if g_Game_IsNet
then MH_SEND_GameSettings
;
5248 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5250 with gGameSettings
do
5252 if (Length(P
) > 1) and
5253 ((P
[1] = '1') or (P
[1] = '0')) then
5255 if (P
[1][1] = '1') then
5256 Options
:= Options
or GAME_OPTION_MONSTERS
5258 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5261 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5262 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5264 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5265 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5267 if g_Game_IsNet
then MH_SEND_GameSettings
;
5270 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5272 with gGameSettings
do
5274 if (Length(P
) > 1) and
5275 ((P
[1] = '1') or (P
[1] = '0')) then
5277 if (P
[1][1] = '1') then
5278 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5280 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5283 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5284 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5286 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5288 if g_Game_IsNet
then MH_SEND_GameSettings
;
5291 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5293 with gGameSettings
do
5295 if (Length(P
) > 1) and
5296 ((P
[1] = '1') or (P
[1] = '0')) then
5298 if (P
[1][1] = '1') then
5299 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5301 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5304 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5305 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5307 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5309 if g_Game_IsNet
then MH_SEND_GameSettings
;
5312 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5314 if Length(P
) > 1 then
5316 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5317 gGameSettings
.WarmupTime
:= 30
5319 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5322 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5323 [gGameSettings
.WarmupTime
]));
5324 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5326 else if cmd
= 'net_interp' then
5328 if (Length(P
) > 1) then
5329 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5331 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5332 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5333 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5334 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5337 else if cmd
= 'net_forceplayerupdate' then
5339 if (Length(P
) > 1) and
5340 ((P
[1] = '1') or (P
[1] = '0')) then
5341 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5343 if NetForcePlayerUpdate
then
5344 g_Console_Add('net_forceplayerupdate = 1')
5346 g_Console_Add('net_forceplayerupdate = 0');
5347 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5348 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5349 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5352 else if cmd
= 'net_predictself' then
5354 if (Length(P
) > 1) and
5355 ((P
[1] = '1') or (P
[1] = '0')) then
5356 NetPredictSelf
:= (P
[1][1] = '1');
5358 if NetPredictSelf
then
5359 g_Console_Add('net_predictself = 1')
5361 g_Console_Add('net_predictself = 0');
5362 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5363 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5364 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5367 else if cmd
= 'sv_name' then
5369 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5371 NetServerName
:= P
[1];
5372 if Length(NetServerName
) > 64 then
5373 SetLength(NetServerName
, 64);
5374 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5378 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5380 else if cmd
= 'sv_passwd' then
5382 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5384 NetPassword
:= P
[1];
5385 if Length(NetPassword
) > 24 then
5386 SetLength(NetPassword
, 24);
5387 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5391 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5393 else if cmd
= 'sv_maxplrs' then
5395 if (Length(P
) > 1) then
5397 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5398 if g_Game_IsServer
and g_Game_IsNet
then
5401 for a
:= 0 to High(NetClients
) do
5402 if NetClients
[a
].Used
then
5405 if b
> NetMaxClients
then
5407 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5408 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5409 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5410 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5413 if NetUseMaster
then
5418 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5420 else if cmd
= 'sv_public' then
5422 if (Length(P
) > 1) then
5424 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5425 if g_Game_IsServer
and g_Game_IsNet
then
5426 if NetUseMaster
then
5428 if NetMPeer
= nil then
5429 if not g_Net_Slist_Connect() then
5430 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5431 g_Net_Slist_Update();
5434 if NetMPeer
<> nil then
5435 g_Net_Slist_Disconnect();
5438 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5440 else if cmd
= 'sv_intertime' then
5442 if (Length(P
) > 1) then
5443 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5445 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5447 else if cmd
= 'p1_name' then
5449 if (Length(P
) > 1) and gGameOn
then
5451 if g_Game_IsClient
then
5453 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5454 MC_SEND_PlayerSettings
;
5457 if gPlayer1
<> nil then
5459 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5460 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5463 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5466 else if cmd
= 'p2_name' then
5468 if (Length(P
) > 1) and gGameOn
then
5470 if g_Game_IsClient
then
5472 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5473 MC_SEND_PlayerSettings
;
5476 if gPlayer2
<> nil then
5478 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5479 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5482 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5485 else if cmd
= 'p1_color' then
5487 if Length(P
) > 3 then
5488 if g_Game_IsClient
then
5490 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5491 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5492 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5493 MC_SEND_PlayerSettings
;
5496 if gPlayer1
<> nil then
5498 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5499 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5500 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5501 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5504 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5505 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5506 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5508 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5510 if Length(P
) > 3 then
5511 if g_Game_IsClient
then
5513 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5514 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5515 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5516 MC_SEND_PlayerSettings
;
5519 if gPlayer2
<> nil then
5521 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5522 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5523 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5524 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5527 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5528 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5529 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5531 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5533 if cmd
= 'r_showtime' then
5535 if (Length(P
) > 1) and
5536 ((P
[1] = '1') or (P
[1] = '0')) then
5537 gShowTime
:= (P
[1][1] = '1');
5540 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5542 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5544 else if cmd
= 'r_showscore' then
5546 if (Length(P
) > 1) and
5547 ((P
[1] = '1') or (P
[1] = '0')) then
5548 gShowGoals
:= (P
[1][1] = '1');
5551 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5553 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5555 else if cmd
= 'r_showstat' then
5557 if (Length(P
) > 1) and
5558 ((P
[1] = '1') or (P
[1] = '0')) then
5559 gShowStat
:= (P
[1][1] = '1');
5562 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5564 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5566 else if cmd
= 'r_showkillmsg' then
5568 if (Length(P
) > 1) and
5569 ((P
[1] = '1') or (P
[1] = '0')) then
5570 gShowKillMsg
:= (P
[1][1] = '1');
5572 if gShowKillMsg
then
5573 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5575 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5577 else if cmd
= 'r_showlives' then
5579 if (Length(P
) > 1) and
5580 ((P
[1] = '1') or (P
[1] = '0')) then
5581 gShowLives
:= (P
[1][1] = '1');
5584 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5586 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5588 else if cmd
= 'r_showspect' then
5590 if (Length(P
) > 1) and
5591 ((P
[1] = '1') or (P
[1] = '0')) then
5592 gSpectHUD
:= (P
[1][1] = '1');
5595 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5597 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5599 else if cmd
= 'r_showping' then
5601 if (Length(P
) > 1) and
5602 ((P
[1] = '1') or (P
[1] = '0')) then
5603 gShowPing
:= (P
[1][1] = '1');
5606 g_Console_Add(_lc
[I_MSG_PING_ON
])
5608 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5610 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5612 if Length(P
) > 1 then
5614 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5615 gGameSettings
.GoalLimit
:= 0
5620 if gGameSettings
.GameMode
= GM_DM
then
5622 stat
:= g_Player_GetStats();
5624 for a
:= 0 to High(stat
) do
5625 if stat
[a
].Frags
> b
then
5629 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5631 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5634 if g_Game_IsNet
then MH_SEND_GameSettings
;
5637 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5639 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5641 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5642 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5644 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5645 [gGameSettings
.TimeLimit
div 3600,
5646 (gGameSettings
.TimeLimit
div 60) mod 60,
5647 gGameSettings
.TimeLimit
mod 60]));
5648 if g_Game_IsNet
then MH_SEND_GameSettings
;
5650 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5652 if Length(P
) > 1 then
5654 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5655 gGameSettings
.MaxLives
:= 0
5659 stat
:= g_Player_GetStats();
5661 for a
:= 0 to High(stat
) do
5662 if stat
[a
].Lives
> b
then
5664 gGameSettings
.MaxLives
:=
5665 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5669 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5670 [gGameSettings
.MaxLives
]));
5671 if g_Game_IsNet
then MH_SEND_GameSettings
;
5676 procedure PrintHeapStats();
5680 hs
:= GetFPCHeapStatus();
5681 e_LogWriteLn ('v===== heap status =====v');
5682 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5683 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5684 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5685 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5686 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5687 e_LogWriteLn ('^=======================^');
5690 procedure DebugCommands(P
: SSArray
);
5697 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5698 if {gDebugMode}conIsCheatsEnabled
then
5700 cmd
:= LowerCase(P
[0]);
5701 if cmd
= 'd_window' then
5703 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5704 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5705 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5706 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5707 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5709 else if cmd
= 'd_sounds' then
5711 if (Length(P
) > 1) and
5712 ((P
[1] = '1') or (P
[1] = '0')) then
5713 g_Debug_Sounds
:= (P
[1][1] = '1');
5715 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5717 else if cmd
= 'd_frames' then
5719 if (Length(P
) > 1) and
5720 ((P
[1] = '1') or (P
[1] = '0')) then
5721 g_Debug_Frames
:= (P
[1][1] = '1');
5723 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5725 else if cmd
= 'd_winmsg' then
5727 if (Length(P
) > 1) and
5728 ((P
[1] = '1') or (P
[1] = '0')) then
5729 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5731 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5733 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5735 if (Length(P
) > 1) and
5736 ((P
[1] = '1') or (P
[1] = '0')) then
5737 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5739 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5741 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5743 if Length(P
) > 1 then
5745 '0': g_debug_BotAIOff
:= 0;
5746 '1': g_debug_BotAIOff
:= 1;
5747 '2': g_debug_BotAIOff
:= 2;
5748 '3': g_debug_BotAIOff
:= 3;
5751 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5753 else if cmd
= 'd_monster' then
5755 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5756 if Length(P
) < 2 then
5758 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5759 g_Console_Add('ID | Name');
5760 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5761 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5762 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5765 a
:= StrToIntDef(P
[1], 0);
5766 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5767 a
:= g_Mons_TypeIdByName(P
[1]);
5769 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5770 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5773 with gPlayer1
.Obj
do
5775 mon
:= g_Monsters_Create(a
,
5776 X
+ Rect
.X
+ (Rect
.Width
div 2),
5777 Y
+ Rect
.Y
+ Rect
.Height
,
5778 gPlayer1
.Direction
, True);
5780 if (Length(P
) > 2) and (mon
<> nil) then
5782 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5783 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5784 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5785 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5786 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5787 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5788 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5789 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5790 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5795 else if (cmd
= 'd_health') then
5797 if (Length(P
) > 1) and
5798 ((P
[1] = '1') or (P
[1] = '0')) then
5799 g_debug_HealthBar
:= (P
[1][1] = '1');
5801 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5803 else if (cmd
= 'd_player') then
5805 if (Length(P
) > 1) and
5806 ((P
[1] = '1') or (P
[1] = '0')) then
5807 g_debug_Player
:= (P
[1][1] = '1');
5809 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5811 else if (cmd
= 'd_mem') then
5817 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5821 procedure GameCheats(P
: SSArray
);
5827 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5829 g_Console_Add('not available');
5835 g_Console_Add('where is the player?!');
5838 cmd
:= LowerCase(P
[0]);
5842 plr
.GodMode
:= not plr
.GodMode
;
5843 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5846 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5847 if cmd
= 'give' then
5849 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5850 for f
:= 1 to High(P
) do
5852 cmd
:= LowerCase(P
[f
]);
5853 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5854 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5855 if cmd
= 'exit' then
5857 if gTriggers
<> nil then
5859 for a
:= 0 to High(gTriggers
) do
5861 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5863 g_Console_Add('player left the map');
5864 gExitByTrigger
:= True;
5865 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5866 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5874 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5875 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5876 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5877 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5878 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5880 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5881 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5883 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5884 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;
5886 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5887 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5889 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5890 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5892 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5893 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5895 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5896 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5897 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5899 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5900 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5901 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5902 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;
5903 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5904 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5906 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;
5907 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;
5908 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;
5909 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;
5910 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;
5911 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;
5913 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5914 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;
5916 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;
5917 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;
5919 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5921 if cmd
= 'ammo' then
5923 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5924 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5925 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5926 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5927 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5928 g_Console_Add('player got some ammo');
5932 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5933 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5935 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5936 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5938 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5939 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5941 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5942 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5944 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5946 if cmd
= 'weapons' then
5948 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5949 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5950 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5951 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5952 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5953 plr
.GiveItem(ITEM_WEAPON_BFG
);
5954 g_Console_Add('player got weapons');
5958 if cmd
= 'keys' then
5960 plr
.GiveItem(ITEM_KEY_RED
);
5961 plr
.GiveItem(ITEM_KEY_GREEN
);
5962 plr
.GiveItem(ITEM_KEY_BLUE
);
5963 g_Console_Add('player got all keys');
5967 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5972 if cmd
= 'open' then
5974 g_Console_Add('player activated sesame');
5975 g_Triggers_OpenAll();
5982 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5986 if cmd
= 'noclip' then
5989 g_Console_Add('wall hardeness adjusted');
5993 if cmd
= 'notarget' then
5995 plr
.NoTarget
:= not plr
.NoTarget
;
5996 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6000 if cmd
= 'noreload' then
6002 plr
.NoReload
:= not plr
.NoReload
;
6003 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6007 if cmd
= 'speedy' then
6009 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6010 g_Console_Add('speed adjusted');
6014 if cmd
= 'jumpy' then
6016 VEL_JUMP
:= 30-VEL_JUMP
;
6017 g_Console_Add('jump height adjusted');
6021 if cmd
= 'automap' then
6023 gShowMap
:= not gShowMap
;
6024 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6028 if cmd
= 'aimline' then
6030 gAimLine
:= not gAimLine
;
6031 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6036 procedure GameCommands(P
: SSArray
);
6042 pl
: pTNetClient
= nil;
6049 cmd
:= LowerCase(P
[0]);
6051 if (cmd
= 'quit') or
6058 else if cmd
= 'pause' then
6060 if (g_ActiveWindow
= nil) then
6061 g_Game_Pause(not gPauseMain
);
6063 else if cmd
= 'endgame' then
6064 gExit
:= EXIT_SIMPLE
6065 else if cmd
= 'restart' then
6067 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6069 if g_Game_IsClient
then
6071 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6076 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6078 else if cmd
= 'kick' then
6080 if g_Game_IsServer
then
6082 if Length(P
) < 2 then
6084 g_Console_Add('kick <name>');
6089 g_Console_Add('kick <name>');
6093 if g_Game_IsNet
then
6094 pl
:= g_Net_Client_ByName(P
[1]);
6097 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6098 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6099 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6100 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6101 if NetUseMaster
then
6103 end else if gPlayers
<> nil then
6104 for a
:= Low(gPlayers
) to High(gPlayers
) do
6105 if gPlayers
[a
] <> nil then
6106 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6108 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6109 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6111 gPlayers
[a
].Lives
:= 0;
6112 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6113 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6114 g_Player_Remove(gPlayers
[a
].UID
);
6115 if NetUseMaster
then
6117 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6121 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6123 else if cmd
= 'kick_id' then
6125 if g_Game_IsServer
and g_Game_IsNet
then
6127 if Length(P
) < 2 then
6129 g_Console_Add('kick_id <client ID>');
6134 g_Console_Add('kick_id <client ID>');
6138 a
:= StrToIntDef(P
[1], 0);
6139 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6141 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6143 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6144 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6145 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6146 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6147 if NetUseMaster
then
6152 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6154 else if cmd
= 'ban' then
6156 if g_Game_IsServer
and g_Game_IsNet
then
6158 if Length(P
) < 2 then
6160 g_Console_Add('ban <name>');
6165 g_Console_Add('ban <name>');
6169 pl
:= g_Net_Client_ByName(P
[1]);
6172 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6173 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6174 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6175 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6176 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6177 if NetUseMaster
then
6180 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6182 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6184 else if cmd
= 'ban_id' then
6186 if g_Game_IsServer
and g_Game_IsNet
then
6188 if Length(P
) < 2 then
6190 g_Console_Add('ban_id <client ID>');
6195 g_Console_Add('ban_id <client ID>');
6199 a
:= StrToIntDef(P
[1], 0);
6200 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6201 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6203 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6204 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6205 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6206 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6207 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6208 if NetUseMaster
then
6212 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6214 else if cmd
= 'permban' then
6216 if g_Game_IsServer
and g_Game_IsNet
then
6218 if Length(P
) < 2 then
6220 g_Console_Add('permban <name>');
6225 g_Console_Add('permban <name>');
6229 pl
:= g_Net_Client_ByName(P
[1]);
6232 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6233 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6234 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6235 g_Net_SaveBanList();
6236 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6237 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6238 if NetUseMaster
then
6241 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6243 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6245 else if cmd
= 'permban_id' then
6247 if g_Game_IsServer
and g_Game_IsNet
then
6249 if Length(P
) < 2 then
6251 g_Console_Add('permban_id <client ID>');
6256 g_Console_Add('permban_id <client ID>');
6260 a
:= StrToIntDef(P
[1], 0);
6261 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6262 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6264 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6265 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6266 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6267 g_Net_SaveBanList();
6268 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6269 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6270 if NetUseMaster
then
6274 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6276 else if cmd
= 'unban' then
6278 if g_Game_IsServer
and g_Game_IsNet
then
6280 if Length(P
) < 2 then
6282 g_Console_Add('unban <IP Address>');
6287 g_Console_Add('unban <IP Address>');
6291 if g_Net_UnbanHost(P
[1]) then
6293 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6294 g_Net_SaveBanList();
6296 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6298 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6300 else if cmd
= 'clientlist' then
6302 if g_Game_IsServer
and g_Game_IsNet
then
6305 if NetClients
<> nil then
6306 for a
:= Low(NetClients
) to High(NetClients
) do
6307 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6309 plr
:= g_Player_Get(NetClients
[a
].Player
);
6310 if plr
= nil then continue
;
6312 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6313 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6316 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6318 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6320 else if cmd
= 'connect' then
6322 if (NetMode
= NET_NONE
) then
6324 if Length(P
) < 2 then
6326 g_Console_Add('connect <IP> [port] [password]');
6331 g_Console_Add('connect <IP> [port] [password]');
6335 if Length(P
) > 2 then
6336 prt
:= StrToIntDef(P
[2], 25666)
6340 if Length(P
) > 3 then
6345 g_Game_StartClient(P
[1], prt
, pw
);
6348 else if cmd
= 'disconnect' then
6350 if (NetMode
= NET_CLIENT
) then
6353 else if cmd
= 'reconnect' then
6355 if (NetMode
= NET_SERVER
) then
6358 if (NetMode
= NET_CLIENT
) then
6361 gExit
:= EXIT_SIMPLE
;
6365 //TODO: Use last successful password to reconnect, instead of ''
6366 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6368 else if (cmd
= 'addbot') or
6369 (cmd
= 'bot_add') then
6371 if Length(P
) > 1 then
6372 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6374 g_Bot_Add(TEAM_NONE
, 2);
6376 else if cmd
= 'bot_addlist' then
6378 if Length(P
) > 1 then
6379 if Length(P
) = 2 then
6380 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6382 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6384 else if cmd
= 'bot_removeall' then
6386 else if cmd
= 'chat' then
6388 if g_Game_IsNet
then
6390 if Length(P
) > 1 then
6392 for a
:= 1 to High(P
) do
6393 chstr
:= chstr
+ P
[a
] + ' ';
6395 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6397 if Length(chstr
) < 1 then
6399 g_Console_Add('chat <text>');
6403 chstr
:= b_Text_Format(chstr
);
6404 if g_Game_IsClient
then
6405 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6407 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6410 g_Console_Add('chat <text>');
6412 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6414 else if cmd
= 'teamchat' then
6416 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6418 if Length(P
) > 1 then
6420 for a
:= 1 to High(P
) do
6421 chstr
:= chstr
+ P
[a
] + ' ';
6423 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6425 if Length(chstr
) < 1 then
6427 g_Console_Add('teamchat <text>');
6431 chstr
:= b_Text_Format(chstr
);
6432 if g_Game_IsClient
then
6433 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6435 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6436 gPlayer1Settings
.Team
);
6439 g_Console_Add('teamchat <text>');
6441 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6443 else if cmd
= 'game' then
6445 if gGameSettings
.GameType
<> GT_NONE
then
6447 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6450 if Length(P
) = 1 then
6452 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6455 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6456 P
[1] := addWadExtension(P
[1]);
6457 if FileExists(MapsDir
+ P
[1]) then
6459 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6460 if Length(P
) < 3 then
6463 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6466 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6468 if g_Map_Exist(MapsDir
+ s
) then
6470 // Çàïóñêàåì ñâîþ èãðó
6472 with gGameSettings
do
6474 GameMode
:= g_Game_TextToMode(gcGameMode
);
6475 if gSwitchGameMode
<> GM_NONE
then
6476 GameMode
:= gSwitchGameMode
;
6477 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6478 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6480 if Length(P
) >= 4 then
6481 b
:= StrToIntDef(P
[3], 1);
6482 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6483 GoalLimit
, MaxLives
, Options
, b
);
6488 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6490 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6492 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6494 else if cmd
= 'host' then
6496 if gGameSettings
.GameType
<> GT_NONE
then
6498 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6501 if Length(P
) < 4 then
6503 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6506 if not StrToIp(P
[1], listen
) then
6508 prt
:= StrToIntDef(P
[2], 25666);
6510 P
[3] := addWadExtension(P
[3]);
6511 if FileExists(MapsDir
+ P
[3]) then
6513 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6514 if Length(P
) < 5 then
6517 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6520 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6522 if g_Map_Exist(MapsDir
+ s
) then
6524 // Çàïóñêàåì ñâîþ èãðó
6526 with gGameSettings
do
6528 GameMode
:= g_Game_TextToMode(gcGameMode
);
6529 if gSwitchGameMode
<> GM_NONE
then
6530 GameMode
:= gSwitchGameMode
;
6531 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6532 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6534 if Length(P
) >= 6 then
6535 b
:= StrToIntDef(P
[5], 0);
6536 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6537 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6542 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6544 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6546 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6548 else if cmd
= 'map' then
6550 if Length(P
) = 1 then
6552 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6554 g_Console_Add(cmd
+ ' <MAP>');
6555 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6557 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6559 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6561 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6562 if Length(P
) < 3 then
6564 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6565 s
:= UpperCase(P
[1]);
6566 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6567 begin // Êàðòà íàøëàñü
6568 gExitByTrigger
:= False;
6570 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6572 gExit
:= EXIT_ENDLEVELCUSTOM
;
6574 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6575 g_Game_ChangeMap(s
);
6578 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6579 P
[1] := addWadExtension(P
[1]);
6580 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6581 if FileExists(MapsDir
+ P
[1]) then
6583 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6585 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6587 s
:= P
[1] + ':\' + P
[2];
6589 if g_Map_Exist(MapsDir
+ s
) then
6591 gExitByTrigger
:= False;
6593 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6595 gExit
:= EXIT_ENDLEVELCUSTOM
;
6597 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6598 g_Game_ChangeMap(s
);
6601 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6603 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6605 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6609 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6610 P
[1] := addWadExtension(P
[1]);
6611 if FileExists(MapsDir
+ P
[1]) then
6614 P
[2] := UpperCase(P
[2]);
6615 s
:= P
[1] + ':\' + P
[2];
6617 if g_Map_Exist(MapsDir
+ s
) then
6618 begin // Íàøëè êàðòó
6619 gExitByTrigger
:= False;
6621 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6623 gExit
:= EXIT_ENDLEVELCUSTOM
;
6625 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6626 g_Game_ChangeMap(s
);
6628 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6630 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6633 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6635 else if cmd
= 'nextmap' then
6637 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6638 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6641 if Length(P
) = 1 then
6643 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6645 g_Console_Add(cmd
+ ' <MAP>');
6646 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6649 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6654 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6656 if Length(P
) < 3 then
6658 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6659 s
:= UpperCase(P
[1]);
6660 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6661 begin // Êàðòà íàøëàñü
6662 gExitByTrigger
:= False;
6667 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6668 P
[1] := addWadExtension(P
[1]);
6669 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6670 if FileExists(MapsDir
+ P
[1]) then
6672 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6674 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6676 s
:= P
[1] + ':\' + P
[2];
6678 if g_Map_Exist(MapsDir
+ s
) then
6679 begin // Óñòàíàâëèâàåì êàðòó
6680 gExitByTrigger
:= False;
6685 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6687 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6689 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6693 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6694 P
[1] := addWadExtension(P
[1]);
6695 if FileExists(MapsDir
+ P
[1]) then
6698 P
[2] := UpperCase(P
[2]);
6699 s
:= P
[1] + ':\' + P
[2];
6701 if g_Map_Exist(MapsDir
+ s
) then
6702 begin // Íàøëè êàðòó
6703 gExitByTrigger
:= False;
6707 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6709 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6712 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6715 if gNextMap
= '' then
6716 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6718 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6721 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6724 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6726 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6728 gExitByTrigger
:= False;
6729 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6730 if (gNextMap
= '') and (gTriggers
<> nil) then
6731 for a
:= 0 to High(gTriggers
) do
6732 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6734 gExitByTrigger
:= True;
6735 //gNextMap := gTriggers[a].Data.MapName;
6736 gNextMap
:= gTriggers
[a
].tgcMap
;
6739 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6740 if gNextMap
= '' then
6741 gNextMap
:= g_Game_GetNextMap();
6742 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6743 if not isWadPath(gNextMap
) then
6744 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6747 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6748 if g_Map_Exist(MapsDir
+ s
) then
6749 gExit
:= EXIT_ENDLEVELCUSTOM
6751 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6753 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6755 else if (cmd
= 'event') then
6757 if (Length(P
) <= 1) then
6759 for a
:= 0 to High(gEvents
) do
6760 if gEvents
[a
].Command
= '' then
6761 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6763 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6766 if (Length(P
) = 2) then
6768 for a
:= 0 to High(gEvents
) do
6769 if gEvents
[a
].Name
= P
[1] then
6770 if gEvents
[a
].Command
= '' then
6771 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6773 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6776 for a
:= 0 to High(gEvents
) do
6777 if gEvents
[a
].Name
= P
[1] then
6779 gEvents
[a
].Command
:= '';
6780 for b
:= 2 to High(P
) do
6781 if Pos(' ', P
[b
]) = 0 then
6782 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6784 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6785 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6789 else if cmd
= 'suicide' then
6793 if g_Game_IsClient
then
6794 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6797 if gPlayer1
<> nil then
6798 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6799 if gPlayer2
<> nil then
6800 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6804 else if cmd
= 'screenshot' then
6808 else if cmd
= 'togglechat' then
6810 g_Console_Chat_Switch(False);
6811 gSkipFirstChar
:= not g_Console_Interactive()
6813 else if cmd
= 'toggleteamchat' then
6815 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6817 g_Console_Chat_Switch(True);
6818 gSkipFirstChar
:= not g_Console_Interactive()
6821 else if cmd
= 'weapon' then
6823 if Length(p
) = 2 then
6825 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
6826 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6827 gSelectWeapon
[0, a
] := True
6830 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6832 if Length(p
) = 2 then
6834 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
6835 b
:= ord(cmd
[2]) - ord('1');
6836 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6837 gSelectWeapon
[b
, a
] := True
6840 // Êîìàíäû Ñâîåé èãðû:
6841 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6843 if cmd
= 'bot_addred' then
6845 if Length(P
) > 1 then
6846 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6848 g_Bot_Add(TEAM_RED
, 2);
6850 else if cmd
= 'bot_addblue' then
6852 if Length(P
) > 1 then
6853 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6855 g_Bot_Add(TEAM_BLUE
, 2);
6857 else if cmd
= 'spectate' then
6863 else if cmd
= 'say' then
6865 if g_Game_IsServer
and g_Game_IsNet
then
6867 if Length(P
) > 1 then
6870 for a
:= 1 to High(P
) do
6871 chstr
:= chstr
+ P
[a
] + ' ';
6873 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6875 if Length(chstr
) < 1 then
6877 g_Console_Add('say <text>');
6881 chstr
:= b_Text_Format(chstr
);
6882 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6884 else g_Console_Add('say <text>');
6886 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6888 else if cmd
= 'tell' then
6890 if g_Game_IsServer
and g_Game_IsNet
then
6892 if (Length(P
) > 2) and (P
[1] <> '') then
6895 for a
:= 2 to High(P
) do
6896 chstr
:= chstr
+ P
[a
] + ' ';
6898 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6900 if Length(chstr
) < 1 then
6902 g_Console_Add('tell <playername> <text>');
6906 pl
:= g_Net_Client_ByName(P
[1]);
6908 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6910 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6912 else g_Console_Add('tell <playername> <text>');
6914 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6916 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6918 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6920 // Äîïîëíèòåëüíîå âðåìÿ:
6921 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6923 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6924 [gGameSettings
.TimeLimit
div 3600,
6925 (gGameSettings
.TimeLimit
div 60) mod 60,
6926 gGameSettings
.TimeLimit
mod 60]));
6927 if g_Game_IsNet
then MH_SEND_GameSettings
;
6929 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6931 if (Length(P
) <= 1) then
6932 g_Console_Add('rcon_password <password>')
6934 MC_SEND_RCONPassword(P
[1]);
6936 else if cmd
= 'rcon' then
6938 if g_Game_IsClient
then
6940 if Length(P
) > 1 then
6943 for a
:= 1 to High(P
) do
6944 chstr
:= chstr
+ P
[a
] + ' ';
6946 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6948 if Length(chstr
) < 1 then
6950 g_Console_Add('rcon <command>');
6954 MC_SEND_RCONCommand(chstr
);
6956 else g_Console_Add('rcon <command>');
6959 else if cmd
= 'ready' then
6961 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6962 gLMSRespawnTime
:= gTime
+ 100;
6964 else if (cmd
= 'callvote') and g_Game_IsNet
then
6966 if Length(P
) > 1 then
6969 for a
:= 1 to High(P
) do begin
6970 if a
> 1 then chstr
:= chstr
+ ' ';
6971 chstr
:= chstr
+ P
[a
];
6974 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6976 if Length(chstr
) < 1 then
6978 g_Console_Add('callvote <command>');
6982 if g_Game_IsClient
then
6983 MC_SEND_Vote(True, chstr
)
6985 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6986 g_Console_Process('vote', True);
6989 g_Console_Add('callvote <command>');
6991 else if (cmd
= 'vote') and g_Game_IsNet
then
6993 if g_Game_IsClient
then
6995 else if gVoteInProgress
then
6997 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6998 a
:= Floor((NetClientCount
+1)/2.0) + 1
7000 a
:= Floor(NetClientCount
/2.0) + 1;
7005 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7006 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7012 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7013 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7021 procedure g_TakeScreenShot();
7029 if e_NoGraphics
then Exit
;
7030 ssdir
:= GameDir
+'/screenshots';
7031 if not findFileCI(ssdir
, true) then
7033 // try to create dir
7038 if not findFileCI(ssdir
, true) then exit
; // alas
7041 for a
:= 1 to High(Word) do
7043 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
7045 if findFileCI(t
, true) then continue
;
7046 if not findFileCI(FileName
) then
7049 st
:= createDiskFile(FileName
);
7051 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
7056 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
7064 procedure g_Game_InGameMenu(Show
: Boolean);
7066 if (g_ActiveWindow
= nil) and Show
then
7068 if gGameSettings
.GameType
= GT_SINGLE
then
7069 g_GUI_ShowWindow('GameSingleMenu')
7072 if g_Game_IsClient
then
7073 g_GUI_ShowWindow('GameClientMenu')
7075 if g_Game_IsNet
then
7076 g_GUI_ShowWindow('GameServerMenu')
7078 g_GUI_ShowWindow('GameCustomMenu');
7080 g_Sound_PlayEx('MENU_OPEN');
7082 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7083 if (not g_Game_IsNet
) then
7087 if (g_ActiveWindow
<> nil) and (not Show
) then
7089 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7090 if (not g_Game_IsNet
) then
7091 g_Game_Pause(False);
7095 procedure g_Game_Pause (Enable
: Boolean);
7099 if not gGameOn
then exit
;
7101 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7104 gPauseMain
:= Enable
;
7106 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7109 procedure g_Game_HolmesPause (Enable
: Boolean);
7113 if not gGameOn
then exit
;
7114 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7117 gPauseHolmes
:= Enable
;
7119 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7122 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7127 if gTriggers
<> nil then
7128 for i
:= 0 to High(gTriggers
) do
7129 with gTriggers
[i
] do
7130 if (TriggerType
= TRIGGER_SOUND
) and
7132 Sound
.IsPlaying() then
7134 Sound
.Pause(Enable
);
7138 if gPlayers
<> nil then
7139 for i
:= 0 to High(gPlayers
) do
7140 if gPlayers
[i
] <> nil then
7141 gPlayers
[i
].PauseSounds(Enable
);
7144 if gMusic
<> nil then
7145 gMusic
.Pause(Enable
);
7148 procedure g_Game_StopAllSounds(all
: Boolean);
7152 if gTriggers
<> nil then
7153 for i
:= 0 to High(gTriggers
) do
7154 with gTriggers
[i
] do
7155 if (TriggerType
= TRIGGER_SOUND
) and
7159 if gMusic
<> nil then
7166 procedure g_Game_UpdateTriggerSounds();
7170 if gTriggers
<> nil then
7171 for i
:= 0 to High(gTriggers
) do
7172 with gTriggers
[i
] do
7173 if (TriggerType
= TRIGGER_SOUND
) and
7176 Sound
.IsPlaying() then
7178 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
7179 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
7181 Sound
.SetPan(0.5 - tgcPan
/255.0);
7182 Sound
.SetVolume(tgcVolume
/255.0);
7185 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
7189 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7192 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7197 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7202 if gSpectMode
<> SPECT_PLAYERS
then
7204 if gSpectPID1
= UID
then
7209 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7216 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7221 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7226 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7231 if gSpectMode
<> SPECT_PLAYERS
then
7233 Pl
:= g_Player_Get(gSpectPID1
);
7234 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7239 if gSpectViewTwo
then
7241 Pl
:= g_Player_Get(gSpectPID2
);
7242 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7250 procedure g_Game_Message(Msg
: string; Time
: Word);
7252 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7253 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7254 MessageTime
:= Time
;
7257 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7259 punct
: Array[0..13] of String =
7260 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7266 function IsPunctuation(S
: String): Boolean;
7271 if Length(S
) <> 1 then
7273 for i
:= Low(punct
) to High(punct
) do
7274 if S
= punct
[i
] then
7280 function FilterPunctuation(S
: String): String;
7284 for i
:= Low(punct
) to High(punct
) do
7285 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7291 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7293 // remove player name
7294 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7295 // for FullWord check
7296 Text := toLowerCase1251(' ' + Text + ' ');
7297 fpText
:= FilterPunctuation(Text);
7299 for i
:= 0 to Length(gChatSounds
) - 1 do
7302 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7304 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7305 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7307 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7313 gChatSounds
[i
].Sound
.Play();
7319 g_Sound_PlayEx('SOUND_GAME_RADIO');
7322 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7331 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7335 if goodsnd
[a
].IsPlaying() then
7338 goodsnd
[Random(4)].Play();
7341 procedure g_Game_Announce_KillCombo(Param
: Integer);
7348 UID
:= Param
and $FFFF;
7353 Pl
:= g_Player_Get(UID
);
7362 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7366 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7370 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7374 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7382 if not g_Game_IsWatchedPlayer(UID
) then
7385 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7389 if killsnd
[n
].IsPlaying() then
7394 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7403 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7407 if hahasnd
[a
].IsPlaying() then
7410 hahasnd
[Random(3)].Play();
7413 procedure g_Game_StartVote(Command
, Initiator
: string);
7417 if not gVotesEnabled
then Exit
;
7418 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7419 if gVoteInProgress
or gVotePassed
then
7421 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7422 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7425 gVoteInProgress
:= True;
7426 gVotePassed
:= False;
7427 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7430 gVoteCommand
:= Command
;
7432 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7433 Need
:= Floor((NetClientCount
+1)/2.0)+1
7435 Need
:= Floor(NetClientCount
/2.0)+1;
7436 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7437 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7440 procedure g_Game_CheckVote
;
7444 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7445 if not gVoteInProgress
then Exit
;
7447 if (gTime
>= gVoteTimer
) then
7449 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7450 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7452 Need
:= Floor(NetClientCount
/2.0) + 1;
7453 if gVoteCount
>= Need
then
7455 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7456 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7457 gVotePassed
:= True;
7458 gVoteCmdTimer
:= gTime
+ 5000;
7462 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7463 MH_SEND_VoteEvent(NET_VE_FAILED
);
7465 if NetClients
<> nil then
7466 for I
:= Low(NetClients
) to High(NetClients
) do
7467 if NetClients
[i
].Used
then
7468 NetClients
[i
].Voted
:= False;
7469 gVoteInProgress
:= False;
7475 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7476 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7478 Need
:= Floor(NetClientCount
/2.0) + 1;
7479 if gVoteCount
>= Need
then
7481 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7482 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7483 gVoteInProgress
:= False;
7484 gVotePassed
:= True;
7485 gVoteCmdTimer
:= gTime
+ 5000;
7488 if NetClients
<> nil then
7489 for I
:= Low(NetClients
) to High(NetClients
) do
7490 if NetClients
[i
].Used
then
7491 NetClients
[i
].Voted
:= False;
7496 procedure g_Game_LoadMapList(FileName
: string);
7504 if not FileExists(FileName
) then Exit
;
7506 AssignFile(ListFile
, FileName
);
7508 while not EOF(ListFile
) do
7510 ReadLn(ListFile
, s
);
7513 if s
= '' then Continue
;
7515 SetLength(MapList
, Length(MapList
)+1);
7516 MapList
[High(MapList
)] := s
;
7518 CloseFile(ListFile
);
7521 procedure g_Game_SetDebugMode();
7524 // ×èòû (äàæå â ñâîåé èãðå):
7528 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7532 if Length(LoadingStat
.Msgs
) = 0 then
7538 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7539 if NextMsg
= Length(Msgs
) then
7541 for i
:= 0 to High(Msgs
)-1 do
7542 Msgs
[i
] := Msgs
[i
+1];
7550 Msgs
[NextMsg
-1] := Text;
7554 PBarWasHere
:= false;
7557 g_ActiveWindow
:= nil;
7559 ProcessLoading(true);
7562 procedure g_Game_StepLoading(Value
: Integer = -1);
7573 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7581 procedure g_Game_ClearLoading();
7590 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7591 if len
< 1 then len
:= 1;
7592 SetLength(Msgs
, len
);
7593 for len
:= Low(Msgs
) to High(Msgs
) do
7596 PBarWasHere
:= false;
7600 procedure Parse_Params(var pars
: TParamStrValues
);
7607 while i
<= ParamCount
do
7610 if (s
[1] = '-') and (Length(s
) > 1) then
7612 if (s
[2] = '-') and (Length(s
) > 2) then
7613 begin // Îäèíî÷íûé ïàðàìåòð
7614 SetLength(pars
, Length(pars
) + 1);
7615 with pars
[High(pars
)] do
7617 Name
:= LowerCase(s
);
7622 if (i
< ParamCount
) then
7623 begin // Ïàðàìåòð ñî çíà÷åíèåì
7625 SetLength(pars
, Length(pars
) + 1);
7626 with pars
[High(pars
)] do
7628 Name
:= LowerCase(s
);
7629 Value
:= LowerCase(ParamStr(i
));
7638 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7643 for i
:= 0 to High(pars
) do
7644 if pars
[i
].Name
= aName
then
7646 Result
:= pars
[i
].Value
;
7651 procedure g_Game_Process_Params();
7653 pars
: TParamStrValues
;
7656 LimT
, LimS
: Integer;
7667 s
:= Find_Param_Value(pars
, '--debug');
7670 g_Game_SetDebugMode();
7671 s
:= Find_Param_Value(pars
, '--netdump');
7676 // Connect when game loads
7677 ip
:= Find_Param_Value(pars
, '-connect');
7681 s
:= Find_Param_Value(pars
, '-port');
7682 if (s
= '') or not TryStrToInt(s
, Port
) then
7685 s
:= Find_Param_Value(pars
, '-pw');
7687 g_Game_StartClient(ip
, Port
, s
);
7691 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7694 gDefaultMegawadStart
:= s
;
7697 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7698 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7700 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7703 // Start map when game loads:
7704 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7705 if isWadPath(map
) then
7708 s
:= Find_Param_Value(pars
, '-gm');
7709 GMode
:= g_Game_TextToMode(s
);
7710 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7711 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7714 s
:= Find_Param_Value(pars
, '-limt');
7715 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7721 s
:= Find_Param_Value(pars
, '-lims');
7722 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7728 s
:= Find_Param_Value(pars
, '-lives');
7729 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7735 s
:= Find_Param_Value(pars
, '-opt');
7737 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7739 Opt
:= StrToIntDef(s
, 0);
7741 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7744 s
:= Find_Param_Value(pars
, '--close');
7748 // Override map to test:
7749 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7751 gTestMap
:= MapsDir
+ s
;
7753 // Delete test map after play:
7754 s
:= Find_Param_Value(pars
, '--testdelete');
7757 gMapToDelete
:= MapsDir
+ map
;
7758 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7762 // Delete temporary WAD after play:
7763 s
:= Find_Param_Value(pars
, '--tempdelete');
7764 if (s
<> '') and (gTestMap
<> '') then
7766 gMapToDelete
:= gTestMap
;
7767 gTempDelete
:= True;
7770 // Number of players:
7771 s
:= Find_Param_Value(pars
, '-pl');
7775 n
:= StrToIntDef(s
, 1);
7778 s
:= Find_Param_Value(pars
, '-port');
7779 if (s
= '') or not TryStrToInt(s
, Port
) then
7780 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7782 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7785 // Execute script when game loads:
7786 s
:= Find_Param_Value(pars
, '-exec');
7789 if not isWadPath(s
) then
7790 s
:= GameDir
+ '/' + s
;
7795 if IOResult
<> 0 then
7797 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7798 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7802 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7803 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7808 if IOResult
<> 0 then
7810 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7811 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7815 if Pos('#', s
) <> 1 then // script comment
7816 g_Console_Process(s
, True);
7827 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7828 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7829 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7830 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7832 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7833 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7834 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7835 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7837 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7838 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7840 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7841 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7843 {$IFDEF ENABLE_HOLMES}
7844 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7847 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7849 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7851 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7852 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7854 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7855 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7857 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');