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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_basic
, g_player
, e_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 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 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
106 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
107 procedure g_Game_ChangeMap(const MapPath
: String);
108 procedure g_Game_ExitLevel(const Map
: AnsiString);
109 function g_Game_GetFirstMap(WAD
: String): String;
110 function g_Game_GetNextMap(): String;
111 procedure g_Game_NextLevel();
112 procedure g_Game_Pause(Enable
: Boolean);
113 procedure g_Game_HolmesPause(Enable
: Boolean);
114 procedure g_Game_InGameMenu(Show
: Boolean);
115 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
116 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
117 procedure g_Game_Message(Msg
: String; Time
: Word);
118 procedure g_Game_LoadMapList(FileName
: String);
119 procedure g_Game_PauseAllSounds(Enable
: Boolean);
120 procedure g_Game_StopAllSounds(all
: Boolean);
121 procedure g_Game_UpdateTriggerSounds();
122 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
123 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
124 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
125 procedure g_Game_Announce_KillCombo(Param
: Integer);
126 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
127 procedure g_Game_StartVote(Command
, Initiator
: string);
128 procedure g_Game_CheckVote
;
129 procedure g_TakeScreenShot(Filename
: string = '');
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P
: SSArray
);
135 procedure GameCommands(P
: SSArray
);
136 procedure GameCheats(P
: SSArray
);
137 procedure DebugCommands(P
: SSArray
);
138 procedure g_Game_Process_Params
;
139 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
140 procedure g_Game_StepLoading(Value
: Integer = -1);
141 procedure g_Game_ClearLoading();
142 procedure g_Game_SetDebugMode();
143 procedure DrawLoadingStat();
144 procedure DrawMenuBackground(tex
: AnsiString);
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;
182 GAME_OPTION_DMKEYS
= 128;
183 GAME_OPTION_RESPAWNITEMS
= 256;
188 STATE_INTERCUSTOM
= 3;
189 STATE_INTERSINGLE
= 4;
195 LMS_RESPAWN_NONE
= 0;
196 LMS_RESPAWN_WARMUP
= 1;
197 LMS_RESPAWN_FINAL
= 2;
214 CONFIG_FILENAME
= 'Doom2DF.cfg';
216 TEST_MAP_NAME
= '$$$_TEST_$$$';
218 STD_PLAYER_MODEL
= 'Doomer';
226 STATFILE_VERSION
= $03;
230 gGameSettings
: TGameSettings
;
231 gPlayer1Settings
: TPlayerSettings
;
232 gPlayer2Settings
: TPlayerSettings
;
234 gPlayerScreenSize
: TDFPoint
;
235 gPlayer1ScreenCoord
: TDFPoint
;
236 gPlayer2ScreenCoord
: TDFPoint
;
237 gPlayer1
: TPlayer
= nil;
238 gPlayer2
: TPlayer
= nil;
239 gPlayerDrawn
: TPlayer
= nil;
241 gSwitchGameMode
: Byte = GM_DM
;
242 gHearPoint1
, gHearPoint2
: THearPoint
;
243 gSoundEffectsDF
: Boolean = False;
244 gSoundTriggerTime
: Word = 0;
245 gAnnouncer
: Integer = ANNOUNCE_NONE
;
246 goodsnd
: array[0..3] of TPlayableSound
;
247 killsnd
: array[0..3] of TPlayableSound
;
248 hahasnd
: array[0..2] of TPlayableSound
;
249 sound_get_flag
: array[0..1] of TPlayableSound
;
250 sound_lost_flag
: array[0..1] of TPlayableSound
;
251 sound_ret_flag
: array[0..1] of TPlayableSound
;
252 sound_cap_flag
: array[0..1] of TPlayableSound
;
253 gBodyKillEvent
: Integer = -1;
254 gDefInterTime
: ShortInt = -1;
255 gInterEndTime
: LongWord = 0;
256 gInterTime
: LongWord = 0;
257 gServInterTime
: Byte = 0;
258 gGameStartTime
: LongWord = 0;
259 gTotalMonsters
: Integer = 0;
260 gPauseMain
: Boolean = false;
261 gPauseHolmes
: Boolean = false;
262 gShowTime
: Boolean = False;
263 gShowFPS
: Boolean = False;
264 gShowGoals
: Boolean = True;
265 gShowStat
: Boolean = True;
266 gShowKillMsg
: Boolean = True;
267 gShowLives
: Boolean = True;
268 gShowPing
: Boolean = False;
269 gShowMap
: Boolean = False;
271 gState
: Byte = STATE_NONE
;
273 sWidth
, sHeight
: Word;
274 gSpectMode
: Byte = SPECT_NONE
;
275 gSpectHUD
: Boolean = True;
276 gSpectKeyPress
: Boolean = False;
277 gSpectX
: Integer = 0;
278 gSpectY
: Integer = 0;
279 gSpectStep
: Byte = 8;
280 gSpectViewTwo
: Boolean = False;
281 gSpectPID1
: Integer = -1;
282 gSpectPID2
: Integer = -1;
283 gSpectAuto
: Boolean = False;
284 gSpectAutoNext
: LongWord;
285 gSpectAutoStepX
: Integer;
286 gSpectAutoStepY
: Integer;
287 gMusic
: TMusic
= nil;
288 gLoadGameMode
: Boolean;
289 gCheats
: Boolean = False;
290 gMapOnce
: Boolean = False;
291 gMapToDelete
: String;
292 gTempDelete
: Boolean = False;
293 gLastMap
: Boolean = False;
296 gResolutionChange
: Boolean = False;
297 gRC_Width
, gRC_Height
: Integer;
298 gRC_FullScreen
, gRC_Maximized
: Boolean;
299 gLanguageChange
: Boolean = False;
300 gDebugMode
: Boolean = False;
301 g_debug_Sounds
: Boolean = False;
302 g_debug_Frames
: Boolean = False;
303 g_debug_WinMsgs
: Boolean = False;
304 g_debug_MonsterOff
: Boolean = False;
305 g_debug_BotAIOff
: Byte = 0;
306 g_debug_HealthBar
: Boolean = False;
307 g_Debug_Player
: Boolean = False;
308 gCoopMonstersKilled
: Word = 0;
309 gCoopSecretsFound
: Word = 0;
310 gCoopTotalMonstersKilled
: Word = 0;
311 gCoopTotalSecretsFound
: Word = 0;
312 gCoopTotalMonsters
: Word = 0;
313 gCoopTotalSecrets
: Word = 0;
314 gStatsOff
: Boolean = False;
315 gStatsPressed
: Boolean = False;
316 gExitByTrigger
: Boolean = False;
317 gNextMap
: String = '';
318 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
319 gLMSRespawnTime
: Cardinal = 0;
320 gLMSSoftSpawn
: Boolean = False;
321 gMissionFailed
: Boolean = False;
322 gVoteInProgress
: Boolean = False;
323 gVotePassed
: Boolean = False;
324 gVoteCommand
: string = '';
325 gVoteTimer
: Cardinal = 0;
326 gVoteCmdTimer
: Cardinal = 0;
327 gVoteCount
: Integer = 0;
328 gVoteTimeout
: Cardinal = 30;
329 gVoted
: Boolean = False;
330 gVotesEnabled
: Boolean = True;
331 gEvents
: Array of TGameEvent
;
332 gDelayedEvents
: Array of TDelayedEvent
;
333 gUseChatSounds
: Boolean = True;
334 gChatSounds
: Array of TChatSound
;
335 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
336 gInterReadyCount
: Integer = 0;
338 g_dbg_ignore_bounds
: Boolean = false;
339 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
340 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
342 // move button values:
343 // bits 0-1: l/r state:
344 // 0: neither left, nor right pressed
347 // bits 4-5: l/r state when strafe was pressed
348 P1MoveButton
: Byte = 0;
349 P2MoveButton
: Byte = 0;
351 g_profile_frame_update
: Boolean = false;
352 g_profile_frame_draw
: Boolean = false;
353 g_profile_collision
: Boolean = false;
354 g_profile_los
: Boolean = false;
355 g_profile_history_size
: Integer = 1000;
357 g_rlayer_back
: Boolean = true;
358 g_rlayer_step
: Boolean = true;
359 g_rlayer_wall
: Boolean = true;
360 g_rlayer_door
: Boolean = true;
361 g_rlayer_acid1
: Boolean = true;
362 g_rlayer_acid2
: Boolean = true;
363 g_rlayer_water
: Boolean = true;
364 g_rlayer_fore
: Boolean = true;
367 procedure g_ResetDynlights ();
368 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
369 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
371 function conIsCheatsEnabled (): Boolean; inline;
372 function gPause (): Boolean; inline;
378 {$INCLUDE ../nogl/noGLuses.inc}
379 {$IFDEF ENABLE_HOLMES}
382 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
383 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
384 g_playermodel
, g_gfx
, g_options
, Math
,
385 g_triggers
, g_monsters
, e_sound
, CONFIG
,
386 g_language
, g_net
, g_main
,
387 ENet
, e_msg
, g_netmsg
, g_netmaster
,
388 sfs
, wadreader
, g_system
;
392 hasPBarGfx
: Boolean = false;
395 // ////////////////////////////////////////////////////////////////////////// //
396 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
399 // ////////////////////////////////////////////////////////////////////////// //
400 function conIsCheatsEnabled (): Boolean; inline;
403 if g_Game_IsNet
then exit
;
404 if not gDebugMode
then
406 //if not gCheats then exit;
407 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
408 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
414 // ////////////////////////////////////////////////////////////////////////// //
416 profileFrameDraw
: TProfiler
= nil;
419 // ////////////////////////////////////////////////////////////////////////// //
422 x
, y
, radius
: Integer;
425 exploRadius
: Integer;
429 g_dynLights
: array of TDynLight
= nil;
430 g_dynLightCount
: Integer = 0;
431 g_playerLight
: Boolean = false;
433 procedure g_ResetDynlights ();
437 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
439 for idx
:= 0 to g_dynLightCount
-1 do
441 if g_dynLights
[idx
].exploCount
= -666 then
448 Inc(g_dynLights
[idx
].exploCount
);
449 if (g_dynLights
[idx
].exploCount
< 10) then
451 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
452 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
453 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
454 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
459 g_dynLightCount
:= lnum
;
462 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
464 if not gwin_has_stencil
then exit
;
465 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
466 g_dynLights
[g_dynLightCount
].x
:= x
;
467 g_dynLights
[g_dynLightCount
].y
:= y
;
468 g_dynLights
[g_dynLightCount
].radius
:= radius
;
469 g_dynLights
[g_dynLightCount
].r
:= r
;
470 g_dynLights
[g_dynLightCount
].g
:= g
;
471 g_dynLights
[g_dynLightCount
].b
:= b
;
472 g_dynLights
[g_dynLightCount
].a
:= a
;
473 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
474 Inc(g_dynLightCount
);
477 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
479 if not gwin_has_stencil
then exit
;
480 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
481 g_dynLights
[g_dynLightCount
].x
:= x
;
482 g_dynLights
[g_dynLightCount
].y
:= y
;
483 g_dynLights
[g_dynLightCount
].radius
:= 0;
484 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
485 g_dynLights
[g_dynLightCount
].r
:= r
;
486 g_dynLights
[g_dynLightCount
].g
:= g
;
487 g_dynLights
[g_dynLightCount
].b
:= b
;
488 g_dynLights
[g_dynLightCount
].a
:= 0;
489 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
490 Inc(g_dynLightCount
);
494 // ////////////////////////////////////////////////////////////////////////// //
495 function calcProfilesHeight (prof
: TProfiler
): Integer;
498 if (prof
= nil) then exit
;
499 if (length(prof
.bars
) = 0) then exit
;
500 result
:= length(prof
.bars
)*(16+2);
504 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
511 if (prof
= nil) then exit
;
513 if (length(prof
.bars
) = 0) then exit
;
515 hgt
:= calcProfilesHeight(prof
);
516 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
517 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
519 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
520 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
521 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
524 for ii
:= 0 to High(prof
.bars
) do
526 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);
533 // ////////////////////////////////////////////////////////////////////////// //
535 TEndCustomGameStat
= record
536 PlayerStat
: TPlayerStatArray
;
540 Map
, MapName
: String;
543 TEndSingleGameStat
= record
544 PlayerStat
: Array [0..1] of record
550 TotalSecrets
: Integer;
553 TLoadingStat
= record
557 Msgs
: Array of String;
559 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
562 TParamStrValue
= record
567 TParamStrValues
= Array of TParamStrValue
;
570 INTER_ACTION_TEXT
= 1;
571 INTER_ACTION_PIC
= 2;
572 INTER_ACTION_MUSIC
= 3;
576 FPSCounter
, UPSCounter
: Word;
577 FPSTime
, UPSTime
: LongWord;
578 DataLoaded
: Boolean = False;
579 IsDrawStat
: Boolean = False;
580 CustomStat
: TEndCustomGameStat
;
581 SingleStat
: TEndSingleGameStat
;
582 LoadingStat
: TLoadingStat
;
583 EndingGameCounter
: Byte = 0;
586 MessageLineLength
: Integer = 80;
587 MapList
: SSArray
= nil;
588 MapIndex
: Integer = -1;
589 InterReadyTime
: Integer = -1;
590 StatShotDone
: Boolean = False;
591 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
592 StatDate
: string = '';
598 text: Array of ShortString;
599 anim
: Array of ShortString;
600 pic
: Array of ShortString;
601 mus
: Array of ShortString;
603 triggers
: Array of record
605 actions
: Array of record
606 action
, p1
, p2
: Integer;
609 cur_trigger
: Integer;
622 function Compare(a
, b
: TPlayerStat
): Integer;
624 if a
.Spectator
then Result
:= 1
625 else if b
.Spectator
then Result
:= -1
626 else if a
.Frags
< b
.Frags
then Result
:= 1
627 else if a
.Frags
> b
.Frags
then Result
:= -1
628 else if a
.Deaths
< b
.Deaths
then Result
:= -1
629 else if a
.Deaths
> b
.Deaths
then Result
:= 1
630 else if a
.Kills
< b
.Kills
then Result
:= -1
634 procedure SortGameStat(var stat
: TPlayerStatArray
);
639 if stat
= nil then Exit
;
641 for I
:= High(stat
) downto Low(stat
) do
642 for J
:= Low(stat
) to High(stat
) - 1 do
643 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
646 stat
[J
] := stat
[J
+ 1];
651 // saves a shitty CSV containing the game stats passed to it
652 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
655 dir
, fname
, map
, mode
, etime
: String;
659 dir
:= e_GetWriteableDir(StatsDirs
);
660 // stats are placed in stats/yy/mm/dd/*.csv
661 fname
:= e_CatPath(dir
, Path
);
662 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
663 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
664 AssignFile(s
, fname
);
667 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
668 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
669 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
670 mode
:= g_Game_ModeToText(Stat
.GameMode
);
671 etime
:= Format('%d:%.2d:%.2d', [
672 Stat
.GameTime
div 1000 div 3600,
673 (Stat
.GameTime
div 1000 div 60) mod 60,
674 Stat
.GameTime
div 1000 mod 60
676 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
677 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
683 gGameSettings
.TimeLimit
,
684 gGameSettings
.GoalLimit
,
685 gGameSettings
.Options
,
687 Length(Stat
.PlayerStat
)
689 // line 2: game specific shit
690 // if it's a team game: red score, blue score
691 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
693 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
695 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
696 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
698 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
699 // lines 3-...: team, player name, frags, deaths
700 WriteLn(s
, 'team,name,frags,deaths');
701 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
702 with Stat
.PlayerStat
[I
] do
703 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
705 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
708 g_Console_Add('could not create gamestats file "' + fname
+ '"');
713 function g_Game_ModeToText(Mode
: Byte): string;
717 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
718 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
719 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
720 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
721 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
725 function g_Game_TextToMode(Mode
: string): Byte;
728 Mode
:= UpperCase(Mode
);
729 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
734 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
739 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
744 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
749 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
756 function g_Game_IsNet(): Boolean;
758 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
761 function g_Game_IsServer(): Boolean;
763 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
766 function g_Game_IsClient(): Boolean;
768 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
771 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
778 Result
.name
:= ExtractFileName(WAD
);
779 Result
.description
:= '';
782 w
:= TWADFile
.Create();
785 if not w
.GetResource('INTERSCRIPT', p
, len
) then
791 cfg
:= TConfig
.CreateMem(p
, len
);
792 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
793 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
794 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
795 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
801 procedure g_Game_FreeWAD();
805 for a
:= 0 to High(MegaWAD
.res
.pic
) do
806 if MegaWAD
.res
.pic
[a
] <> '' then
807 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
809 for a
:= 0 to High(MegaWAD
.res
.mus
) do
810 if MegaWAD
.res
.mus
[a
] <> '' then
811 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
813 MegaWAD
.res
.pic
:= nil;
814 MegaWAD
.res
.text := nil;
815 MegaWAD
.res
.anim
:= nil;
816 MegaWAD
.res
.mus
:= nil;
817 MegaWAD
.triggers
:= nil;
819 g_Texture_Delete('TEXTURE_endpic');
820 g_Sound_Delete('MUSIC_endmus');
822 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
823 gGameSettings
.WAD
:= '';
826 procedure g_Game_LoadWAD(WAD
: string);
835 gGameSettings
.WAD
:= WAD
;
836 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
839 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
841 w
:= TWADFile
.Create();
844 if not w
.GetResource('INTERSCRIPT', p
, len
) then
850 cfg
:= TConfig
.CreateMem(p
, len
);
855 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
856 if s = '' then Break;
859 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
860 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
862 g_Texture_CreateWADEx(s, s);
868 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
869 if s = '' then Break;
872 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
873 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
875 g_Music_CreateWADEx(s, s);
878 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
879 if MegaWAD
.endpic
<> '' then
881 TEXTUREFILTER
:= GL_LINEAR
;
882 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
883 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
884 TEXTUREFILTER
:= GL_NEAREST
;
886 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
887 if MegaWAD
.endmus
<> '' then
889 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
890 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
898 {procedure start_trigger(t: string);
902 function next_trigger(): Boolean;
906 procedure DisableCheats();
912 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
913 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
914 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
915 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
917 {$IF DEFINED(D2F_DEBUG)}
918 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
919 gAimLine
:= g_dbg_aimline_on
;
923 procedure g_Game_ExecuteEvent(Name
: String);
929 if gEvents
= nil then
931 for a
:= 0 to High(gEvents
) do
932 if gEvents
[a
].Name
= Name
then
934 if gEvents
[a
].Command
<> '' then
935 g_Console_Process(gEvents
[a
].Command
, True);
940 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
945 if gDelayedEvents
<> nil then
946 for a
:= 0 to High(gDelayedEvents
) do
947 if not gDelayedEvents
[a
].Pending
then
954 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
955 n
:= High(gDelayedEvents
);
957 gDelayedEvents
[n
].Pending
:= True;
958 gDelayedEvents
[n
].DEType
:= DEType
;
959 gDelayedEvents
[n
].DENum
:= Num
;
960 gDelayedEvents
[n
].DEStr
:= Str
;
961 if DEType
= DE_GLOBEVENT
then
962 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
964 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
974 if g_Game_IsNet
and g_Game_IsServer
then
975 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
979 gPauseHolmes
:= false;
982 g_Game_StopAllSounds(False);
987 EndingGameCounter
:= 0;
988 g_ActiveWindow
:= nil;
990 gLMSRespawn
:= LMS_RESPAWN_NONE
;
991 gLMSRespawnTime
:= 0;
994 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
999 begin // Ýòî áûë òåñò
1003 begin // Âûõîä â ãëàâíîå ìåíþ
1004 gMusic
.SetByName('MUSIC_MENU');
1006 if gState
<> STATE_SLIST
then
1008 g_GUI_ShowWindow('MainMenu');
1009 gState
:= STATE_MENU
;
1012 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1013 slReturnPressed
:= True;
1014 if g_Net_Slist_Fetch(slCurrent
) then
1016 if slCurrent
= nil then
1017 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1020 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1021 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1024 g_Game_ExecuteEvent('ongameend');
1028 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1030 if not g_Game_IsClient
then g_Game_Restart();
1033 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1035 // Ñòàòèñòèêà Ñâîåé èãðû:
1036 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1038 CustomStat
.GameTime
:= gTime
;
1039 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1040 CustomStat
.MapName
:= gMapInfo
.Name
;
1041 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1042 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1043 CustomStat
.TeamStat
:= gTeamStat
;
1045 CustomStat
.PlayerStat
:= nil;
1047 // Ñòàòèñòèêà èãðîêîâ:
1048 if gPlayers
<> nil then
1050 for a
:= 0 to High(gPlayers
) do
1051 if gPlayers
[a
] <> nil then
1053 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1054 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1057 Name
:= gPlayers
[a
].Name
;
1058 Frags
:= gPlayers
[a
].Frags
;
1059 Deaths
:= gPlayers
[a
].Death
;
1060 Kills
:= gPlayers
[a
].Kills
;
1061 Team
:= gPlayers
[a
].Team
;
1062 Color
:= gPlayers
[a
].Model
.Color
;
1063 Spectator
:= gPlayers
[a
].FSpectator
;
1067 SortGameStat(CustomStat
.PlayerStat
);
1069 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1072 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1073 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1074 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1075 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1077 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1080 StatShotDone
:= False;
1083 g_Game_ExecuteEvent('onmapend');
1084 if not g_Game_IsClient
then g_Player_ResetReady
;
1085 gInterReadyCount
:= 0;
1087 // Çàòóõàþùèé ýêðàí:
1088 EndingGameCounter
:= 255;
1089 gState
:= STATE_FOLD
;
1091 if gDefInterTime
< 0 then
1092 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1094 gInterEndTime
:= gDefInterTime
* 1000;
1097 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1099 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1100 SingleStat
.GameTime
:= gTime
;
1101 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1102 SingleStat
.TotalSecrets
:= gSecretsCount
;
1103 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1104 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1105 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1106 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1107 if SingleStat
.TwoPlayers
then
1109 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1110 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1113 g_Game_ExecuteEvent('onmapend');
1116 if gNextMap
<> '' then
1118 gMusic
.SetByName('MUSIC_INTERMUS');
1120 gState
:= STATE_INTERSINGLE
;
1123 g_Game_ExecuteEvent('oninter');
1125 else // Áîëüøå íåò êàðò
1127 // Çàòóõàþùèé ýêðàí:
1128 EndingGameCounter
:= 255;
1129 gState
:= STATE_FOLD
;
1134 // Îêîí÷àíèå îáðàáîòàíî:
1135 if gExit
<> EXIT_QUIT
then
1139 procedure drawTime(X
, Y
: Integer); inline;
1141 e_TextureFontPrint(x
, y
,
1142 Format('%d:%.2d:%.2d', [
1143 gTime
div 1000 div 3600,
1144 (gTime
div 1000 div 60) mod 60,
1145 gTime
div 1000 mod 60
1150 procedure DrawStat();
1152 pc
, x
, y
, w
, h
: Integer;
1153 w1
, w2
, w3
, w4
: Integer;
1155 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1158 stat
: TPlayerStatArray
;
1165 pc
:= g_Player_GetCount
;
1166 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1168 w
:= gScreenWidth
-(gScreenWidth
div 5);
1169 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1172 h
:= 40+ch
*5+(ch
+8)*pc
;
1173 x
:= (gScreenWidth
div 2)-(w
div 2);
1174 y
:= (gScreenHeight
div 2)-(h
div 2);
1176 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1177 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1179 drawTime(x
+w
-78, y
+8);
1181 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1182 map
:= g_ExtractFileName(gMapInfo
.Map
);
1183 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1185 case gGameSettings
.GameMode
of
1188 if gGameSettings
.MaxLives
= 0 then
1189 s1
:= _lc
[I_GAME_DM
]
1191 s1
:= _lc
[I_GAME_LMS
];
1192 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1193 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1198 if gGameSettings
.MaxLives
= 0 then
1199 s1
:= _lc
[I_GAME_TDM
]
1201 s1
:= _lc
[I_GAME_TLMS
];
1202 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1203 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1208 s1
:= _lc
[I_GAME_CTF
];
1209 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1210 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1215 if gGameSettings
.MaxLives
= 0 then
1216 s1
:= _lc
[I_GAME_COOP
]
1218 s1
:= _lc
[I_GAME_SURV
];
1219 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1220 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1231 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1233 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1235 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1237 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1238 gStdFont
, 200, 200, 200, 1);
1240 if NetMode
= NET_SERVER
then
1241 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1243 if NetMode
= NET_CLIENT
then
1244 e_TextureFontPrintEx(x
+8, y
+ 8,
1245 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1249 stat
:= g_Player_GetStats();
1252 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1253 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1255 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1257 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1261 for a
:= TEAM_RED
to TEAM_BLUE
do
1263 if a
= TEAM_RED
then
1265 s1
:= _lc
[I_GAME_TEAM_RED
];
1272 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1278 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1279 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1280 gStdFont
, r
, g
, b
, 1);
1282 _y
:= _y
+ch
+(ch
div 4);
1283 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1284 _y
:= _y
+(ch
div 4);
1286 for aa
:= 0 to High(stat
) do
1287 if stat
[aa
].Team
= a
then
1303 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1305 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1307 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1309 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1316 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1319 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1320 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1321 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1322 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1325 for aa
:= 0 to High(stat
) do
1339 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1340 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1342 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1344 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1346 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1348 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1354 procedure g_Game_Init();
1357 knownFiles
: array of AnsiString = nil;
1359 wext
, s
: AnsiString;
1364 gTempDelete
:= False;
1366 sfsGCDisable(); // temporary disable removing of temporary volumes
1369 TEXTUREFILTER
:= GL_LINEAR
;
1370 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1371 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1372 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1373 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1374 TEXTUREFILTER
:= GL_NEAREST
;
1376 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1377 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1378 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1380 g_Game_ClearLoading();
1381 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1382 g_Game_SetLoadingText('', 0, False);
1384 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1387 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1388 g_PlayerModel_LoadData();
1390 // load models from all possible wad types, in all known directories
1391 // this does a loosy job (linear search, ooph!), but meh
1392 for wext
in wadExtensions
do
1394 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1396 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1400 for s
in knownFiles
do
1402 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1410 SetLength(knownFiles
, length(knownFiles
)+1);
1411 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1413 until (FindNext(SR
) <> 0);
1419 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1421 if (length(knownFiles
) = 1) then e_LogWriteln('1 player model found.', TMsgType
.Notify
) else e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
1422 for s
in knownFiles
do
1424 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1428 gPauseMain
:= false;
1429 gPauseHolmes
:= false;
1432 {e_MouseInfo.Accel := 1.0;}
1434 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1437 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1438 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1439 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1440 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1441 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1444 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1448 gMusic
:= TMusic
.Create();
1449 gMusic
.SetByName('MUSIC_MENU');
1452 gGameSettings
.WarmupTime
:= 30;
1454 gState
:= STATE_MENU
;
1456 SetLength(gEvents
, 6);
1457 gEvents
[0].Name
:= 'ongamestart';
1458 gEvents
[1].Name
:= 'ongameend';
1459 gEvents
[2].Name
:= 'onmapstart';
1460 gEvents
[3].Name
:= 'onmapend';
1461 gEvents
[4].Name
:= 'oninter';
1462 gEvents
[5].Name
:= 'onwadend';
1464 sfsGCEnable(); // enable releasing unused volumes
1468 procedure g_Game_Free(freeTextures
: Boolean=true);
1470 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1471 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1473 g_Map_Free(freeTextures
);
1475 g_Player_RemoveAllCorpses();
1477 gGameSettings
.GameType
:= GT_NONE
;
1478 if gGameSettings
.GameMode
= GM_SINGLE
then
1479 gGameSettings
.GameMode
:= GM_DM
;
1480 gSwitchGameMode
:= gGameSettings
.GameMode
;
1483 gExitByTrigger
:= False;
1486 function IsActivePlayer(p
: TPlayer
): Boolean;
1491 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1494 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1501 if gPlayers
= nil then
1503 for a
:= Low(gPlayers
) to High(gPlayers
) do
1504 if IsActivePlayer(gPlayers
[a
]) then
1506 if gPlayers
[a
].UID
<> ID
then
1508 Result
:= gPlayers
[a
];
1513 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1519 if gPlayers
= nil then
1523 for a
:= Low(gPlayers
) to High(gPlayers
) do
1524 if IsActivePlayer(gPlayers
[a
]) then
1526 SetLength(ids
, Length(ids
) + 1);
1527 ids
[High(ids
)] := gPlayers
[a
].UID
;
1528 if gPlayers
[a
].UID
= Skip
then
1531 if Length(ids
) = 0 then
1536 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1539 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1545 if gPlayers
= nil then
1549 for a
:= Low(gPlayers
) to High(gPlayers
) do
1550 if IsActivePlayer(gPlayers
[a
]) then
1552 SetLength(ids
, Length(ids
) + 1);
1553 ids
[High(ids
)] := gPlayers
[a
].UID
;
1554 if gPlayers
[a
].UID
= Skip
then
1557 if Length(ids
) = 0 then
1560 Result
:= ids
[Length(ids
) - 1]
1562 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1565 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1571 if gPlayers
= nil then
1575 for a
:= Low(gPlayers
) to High(gPlayers
) do
1576 if IsActivePlayer(gPlayers
[a
]) then
1578 SetLength(ids
, Length(ids
) + 1);
1579 ids
[High(ids
)] := gPlayers
[a
].UID
;
1580 if gPlayers
[a
].UID
= Skip
then
1583 if Length(ids
) = 0 then
1585 if Length(ids
) = 1 then
1590 Result
:= ids
[Random(Length(ids
))];
1592 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1594 Result
:= ids
[Random(Length(ids
))];
1599 function GetRandomSpectMode(Current
: Byte): Byte;
1606 0: Result
:= SPECT_STATS
;
1607 1: Result
:= SPECT_MAPVIEW
;
1608 2: Result
:= SPECT_MAPVIEW
;
1609 3: Result
:= SPECT_PLAYERS
;
1610 4: Result
:= SPECT_PLAYERS
;
1611 5: Result
:= SPECT_PLAYERS
;
1612 6: Result
:= SPECT_PLAYERS
;
1614 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1618 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1624 if (plr
= nil) then exit
;
1625 if (p
= 2) then time
:= 1000 else time
:= 1;
1626 strafeDir
:= MoveButton
shr 4;
1627 MoveButton
:= MoveButton
and $0F;
1629 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1630 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1631 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1632 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1633 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1634 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1636 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1637 if MoveButton
= 1 then
1638 plr
.PressKey(KEY_LEFT
, time
)
1639 else if MoveButton
= 2 then
1640 plr
.PressKey(KEY_RIGHT
, time
);
1642 // if we have "strafe" key, turn off old strafe mechanics
1643 if gPlayerAction
[p
, ACTION_STRAFE
] then
1645 // new strafe mechanics
1646 if (strafeDir
= 0) then
1647 strafeDir
:= MoveButton
; // start strafing
1648 // now set direction according to strafe (reversed)
1649 if (strafeDir
= 2) then
1650 plr
.SetDirection(TDirection
.D_LEFT
)
1651 else if (strafeDir
= 1) then
1652 plr
.SetDirection(TDirection
.D_RIGHT
)
1656 strafeDir
:= 0; // not strafing anymore
1657 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1658 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1659 plr
.SetDirection(TDirection
.D_LEFT
)
1660 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1661 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1662 plr
.SetDirection(TDirection
.D_RIGHT
)
1663 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1664 else if MoveButton
<> 0 then
1665 plr
.SetDirection(TDirection(MoveButton
-1))
1668 // fix movebutton state
1669 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1671 // Îñòàëüíûå êëàâèøè:
1672 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1673 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1674 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1675 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1676 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1677 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1678 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1680 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1681 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1683 for i
:= WP_FIRST
to WP_LAST
do
1685 if gSelectWeapon
[p
, i
] then
1687 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1688 gSelectWeapon
[p
, i
] := False
1692 // HACK: add dynlight here
1693 if gwin_k8_enable_light_experiments
then
1695 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1697 g_playerLight
:= true;
1699 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1701 g_playerLight
:= false;
1705 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1708 // HACK: don't have a "key was pressed" function
1709 procedure InterReady();
1711 if InterReadyTime
> gTime
then Exit
;
1712 InterReadyTime
:= gTime
+ 3000;
1713 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1716 procedure g_Game_Update();
1718 Msg
: g_gui
.TMessage
;
1724 function sendMonsPos (mon
: TMonster
): Boolean;
1726 result
:= false; // don't stop
1727 // this will also reset "need-send" flag
1728 if mon
.gncNeedSend
then
1730 MH_SEND_MonsterPos(mon
.UID
);
1732 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1734 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1736 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1738 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1742 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1744 result
:= false; // don't stop
1745 // this will also reset "need-send" flag
1746 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1750 reliableUpdate
: Boolean;
1755 // Ïîðà âûêëþ÷àòü èãðó:
1756 if gExit
= EXIT_QUIT
then
1758 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1762 if gExit
= EXIT_QUIT
then
1766 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1767 // no need to, as we'll do it in event handler
1769 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1772 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1774 gExit
:= EXIT_SIMPLE
;
1779 // process master server communications
1780 g_Net_Slist_Pulse();
1783 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1784 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1785 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1786 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1788 if g_Game_IsNet
and g_Game_IsServer
then
1790 gInterTime
:= gInterTime
+ GAME_TICK
;
1791 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1792 if a
<> gServInterTime
then
1794 gServInterTime
:= a
;
1795 MH_SEND_TimeSync(gServInterTime
);
1799 if (not g_Game_IsClient
) and
1803 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1804 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1805 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1806 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1808 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1809 and (g_ActiveWindow
= nil)
1811 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1814 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1815 g_Game_StopAllSounds(True);
1817 if gMapOnce
then // Ýòî áûë òåñò
1818 gExit
:= EXIT_SIMPLE
1820 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1821 g_Game_ChangeMap(gNextMap
)
1822 else // Ñëåäóþùåé êàðòû íåò
1824 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1826 // Âûõîä â ãëàâíîå ìåíþ:
1828 g_GUI_ShowWindow('MainMenu');
1829 gMusic
.SetByName('MUSIC_MENU');
1831 gState
:= STATE_MENU
;
1834 // Ôèíàëüíàÿ êàðòèíêà:
1835 g_Game_ExecuteEvent('onwadend');
1837 if not gMusic
.SetByName('MUSIC_endmus') then
1838 gMusic
.SetByName('MUSIC_STDENDMUS');
1840 gState
:= STATE_ENDPIC
;
1842 g_Game_ExecuteEvent('ongameend');
1847 else if g_Game_IsClient
and
1850 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1851 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1852 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1853 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1855 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1856 and (g_ActiveWindow
= nil)
1864 if gState
= STATE_INTERTEXT
then
1865 if InterText
.counter
> 0 then
1866 InterText
.counter
:= InterText
.counter
- 1;
1869 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1871 if EndingGameCounter
= 0 then
1873 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1874 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1876 InterReadyTime
:= -1;
1877 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1879 g_Game_ExecuteEvent('onwadend');
1880 if not gMusic
.SetByName('MUSIC_endmus') then
1881 gMusic
.SetByName('MUSIC_STDENDMUS');
1884 gMusic
.SetByName('MUSIC_ROUNDMUS');
1887 gState
:= STATE_INTERCUSTOM
;
1890 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1892 gMusic
.SetByName('MUSIC_INTERMUS');
1894 gState
:= STATE_INTERSINGLE
;
1897 g_Game_ExecuteEvent('oninter');
1900 DecMin(EndingGameCounter
, 6, 0);
1903 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1905 if gMapOnce
then // Ýòî áûë òåñò
1907 gExit
:= EXIT_SIMPLE
;
1913 g_Serverlist_Control(slCurrent
, slTable
);
1916 // Ñòàòèñòèêà ïî Tab:
1918 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1921 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1923 // Âðåìÿ += 28 ìèëëèñåêóíä:
1924 gTime
:= gTime
+ GAME_TICK
;
1926 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1927 if MessageTime
= 0 then
1929 if MessageTime
> 0 then
1930 MessageTime
:= MessageTime
- 1;
1932 if (g_Game_IsServer
) then
1934 // Áûë çàäàí ëèìèò âðåìåíè:
1935 if (gGameSettings
.TimeLimit
> 0) then
1936 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1937 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1942 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1943 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1944 g_Game_RestartRound(gLMSSoftSpawn
);
1946 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1947 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1949 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1951 g_Console_Process(gVoteCommand
);
1953 gVotePassed
:= False;
1956 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1957 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1958 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1959 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1960 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1962 // Áûë çàäàí ëèìèò ïîáåä:
1963 if (gGameSettings
.GoalLimit
> 0) then
1967 if gGameSettings
.GameMode
= GM_DM
then
1968 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1969 for i
:= 0 to High(gPlayers
) do
1970 if gPlayers
[i
] <> nil then
1971 if gPlayers
[i
].Frags
> b
then
1972 b
:= gPlayers
[i
].Frags
;
1975 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1976 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1977 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1980 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1981 if b
>= gGameSettings
.GoalLimit
then
1988 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1989 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1990 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1991 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1993 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1994 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1995 end // if not console
1998 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2000 // process weapon switch queue
2004 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2005 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2007 if not gSpectKeyPress
then
2009 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2011 // switch spect mode
2013 SPECT_NONE
: ; // not spectator
2015 SPECT_MAPVIEW
: Inc(gSpectMode
);
2016 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2018 gSpectKeyPress
:= True;
2020 if (gSpectMode
= SPECT_MAPVIEW
)
2021 and (not gSpectAuto
) then
2023 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2024 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2025 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2026 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2027 if gPlayerAction
[0, ACTION_LOOKUP
] then
2028 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2029 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2030 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2031 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2034 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2035 gSpectKeyPress
:= True;
2037 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2040 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2041 gSpectKeyPress
:= True;
2044 if (gSpectMode
= SPECT_PLAYERS
)
2045 and (not gSpectAuto
) then
2047 if gPlayerAction
[0, ACTION_LOOKUP
] then
2050 gSpectViewTwo
:= True;
2051 gSpectKeyPress
:= True;
2053 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2055 // remove second view
2056 gSpectViewTwo
:= False;
2057 gSpectKeyPress
:= True;
2059 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2061 // prev player (view 1)
2062 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2063 gSpectKeyPress
:= True;
2065 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2067 // next player (view 1)
2068 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2069 gSpectKeyPress
:= True;
2071 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2073 // prev player (view 2)
2074 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2075 gSpectKeyPress
:= True;
2077 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2079 // next player (view 2)
2080 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2081 gSpectKeyPress
:= True;
2084 if gPlayerAction
[0, ACTION_ATTACK
] then
2086 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2089 gSpectAutoNext
:= 0;
2090 gSpectViewTwo
:= False;
2091 gSpectKeyPress
:= True;
2096 gSpectMode
:= SPECT_STATS
;
2097 gSpectAuto
:= False;
2098 gSpectKeyPress
:= True;
2103 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2104 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2105 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2106 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2107 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2108 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2109 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2110 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2111 gSpectKeyPress
:= False;
2115 if gSpectMode
= SPECT_MAPVIEW
then
2117 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2119 gSpectAutoNext
:= gTime
2122 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2124 gSpectAutoNext
:= gTime
2128 if gSpectAutoNext
<= gTime
then
2130 if gSpectAutoNext
> 0 then
2132 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2136 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2137 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2138 gSpectAutoStepX
:= Random(9) - 4;
2139 gSpectAutoStepY
:= Random(9) - 4;
2140 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2141 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2142 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2143 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2144 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2145 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2149 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2154 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2155 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2156 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2162 // Îáíîâëÿåì âñå îñòàëüíîå:
2165 g_Triggers_Update();
2167 g_Monsters_Update();
2169 g_Player_UpdateAll();
2170 g_Player_UpdatePhysicalObjects();
2172 // server: send newly spawned monsters unconditionally
2173 if (gGameSettings
.GameType
= GT_SERVER
) then
2175 if (Length(gMonstersSpawned
) > 0) then
2177 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2178 SetLength(gMonstersSpawned
, 0);
2182 if (gSoundTriggerTime
> 8) then
2184 g_Game_UpdateTriggerSounds();
2185 gSoundTriggerTime
:= 0;
2189 Inc(gSoundTriggerTime
);
2192 if (NetMode
= NET_SERVER
) then
2194 Inc(NetTimeToUpdate
);
2195 Inc(NetTimeToReliable
);
2197 // send monster updates
2198 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2200 // send all monsters (periodic sync)
2201 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2203 for I
:= 0 to High(gPlayers
) do
2205 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2208 g_Mons_ForEach(sendMonsPos
);
2210 if reliableUpdate
then
2212 NetTimeToReliable
:= 0;
2213 NetTimeToUpdate
:= NetUpdateRate
;
2217 NetTimeToUpdate
:= 0;
2222 // send only mosters with some unexpected changes
2223 g_Mons_ForEach(sendMonsPosUnexpected
);
2226 // send unexpected platform changes
2227 g_Map_NetSendInterestingPanels();
2229 g_Net_Slist_ServerUpdate();
2231 if NetUseMaster then
2233 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2235 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2237 NetTimeToMaster := gTime + NetMasterRate;
2242 else if (NetMode
= NET_CLIENT
) then
2244 MC_SEND_PlayerPos();
2246 end; // if gameOn ...
2248 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2249 if g_ActiveWindow
<> nil then
2251 w
:= e_GetFirstKeyPressed();
2253 if (w
<> IK_INVALID
) then
2255 Msg
.Msg
:= MESSAGE_DIKEY
;
2257 g_ActiveWindow
.OnMessage(Msg
);
2260 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2261 if g_ActiveWindow
<> nil then
2262 g_ActiveWindow
.Update();
2264 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2265 if gResolutionChange
then
2267 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2268 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2269 gResolutionChange
:= False;
2270 g_ActiveWindow
:= nil;
2273 // Íóæíî ñìåíèòü ÿçûê:
2274 if gLanguageChange
then
2276 //e_WriteLog('Read language file', MSG_NOTIFY);
2277 //g_Language_Load(DataDir + gLanguage + '.txt');
2278 g_Language_Set(gLanguage
);
2282 gLanguageChange
:= False;
2286 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2287 if e_KeyPressed(IK_F10
) and
2289 (not gConsoleShow
) and
2290 (g_ActiveWindow
= nil) then
2295 Time
:= sys_GetTicks() {div 1000};
2297 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2298 if gDelayedEvents
<> nil then
2299 for a
:= 0 to High(gDelayedEvents
) do
2300 if gDelayedEvents
[a
].Pending
and
2302 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2303 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2306 case gDelayedEvents
[a
].DEType
of
2308 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2311 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2315 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2316 if g_Game_IsNet
and g_Game_IsServer
then
2317 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2321 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2323 gDelayedEvents
[a
].Pending
:= False;
2326 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2327 UPSCounter
:= UPSCounter
+ 1;
2328 if Time
- UPSTime
>= 1000 then
2337 g_Weapon_AddDynLights();
2338 g_Items_AddDynLights();
2342 procedure g_Game_LoadChatSounds(Resource
: string);
2345 FileName
, Snd
: string;
2347 len
, cnt
, tags
, i
, j
: Integer;
2350 FileName
:= g_ExtractWadName(Resource
);
2352 WAD
:= TWADFile
.Create();
2353 WAD
.ReadFile(FileName
);
2355 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2362 cfg
:= TConfig
.CreateMem(p
, len
);
2363 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2365 SetLength(gChatSounds
, cnt
);
2366 for i
:= 0 to Length(gChatSounds
) - 1 do
2368 gChatSounds
[i
].Sound
:= nil;
2369 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2370 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2371 if (Snd
= '') or (Tags
<= 0) then
2373 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2374 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2375 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2376 SetLength(gChatSounds
[i
].Tags
, tags
);
2377 for j
:= 0 to tags
- 1 do
2378 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2379 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2386 procedure g_Game_FreeChatSounds();
2390 for i
:= 0 to Length(gChatSounds
) - 1 do
2392 gChatSounds
[i
].Sound
.Free();
2393 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2395 SetLength(gChatSounds
, 0);
2399 procedure g_Game_LoadData();
2406 if DataLoaded
then Exit
;
2408 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2410 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2411 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2412 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2413 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2414 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2415 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2416 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2417 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2418 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2419 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2420 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2421 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2422 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2423 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2424 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2427 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2428 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2429 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2430 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2434 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2435 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2436 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2437 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2438 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
2444 hasPBarGfx
:= false;
2448 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2449 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2450 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2451 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2452 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2453 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2454 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2455 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2456 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2457 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2458 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2459 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2460 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2461 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2462 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2463 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2464 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2465 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2466 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2467 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2472 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2473 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2474 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2475 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2476 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2477 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2478 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2479 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2480 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2481 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2482 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2483 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2484 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2485 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2486 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2488 goodsnd
[0] := TPlayableSound
.Create();
2489 goodsnd
[1] := TPlayableSound
.Create();
2490 goodsnd
[2] := TPlayableSound
.Create();
2491 goodsnd
[3] := TPlayableSound
.Create();
2493 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2494 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2495 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2496 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2498 killsnd
[0] := TPlayableSound
.Create();
2499 killsnd
[1] := TPlayableSound
.Create();
2500 killsnd
[2] := TPlayableSound
.Create();
2501 killsnd
[3] := TPlayableSound
.Create();
2503 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2504 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2505 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2506 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2508 hahasnd
[0] := TPlayableSound
.Create();
2509 hahasnd
[1] := TPlayableSound
.Create();
2510 hahasnd
[2] := TPlayableSound
.Create();
2512 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2513 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2514 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2516 sound_get_flag
[0] := TPlayableSound
.Create();
2517 sound_get_flag
[1] := TPlayableSound
.Create();
2518 sound_lost_flag
[0] := TPlayableSound
.Create();
2519 sound_lost_flag
[1] := TPlayableSound
.Create();
2520 sound_ret_flag
[0] := TPlayableSound
.Create();
2521 sound_ret_flag
[1] := TPlayableSound
.Create();
2522 sound_cap_flag
[0] := TPlayableSound
.Create();
2523 sound_cap_flag
[1] := TPlayableSound
.Create();
2525 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2526 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2527 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2528 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2529 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2530 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2531 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2532 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2534 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2536 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2539 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2540 g_Weapon_LoadData();
2542 g_Monsters_LoadData();
2547 procedure g_Game_FreeData();
2549 if not DataLoaded
then Exit
;
2552 g_Weapon_FreeData();
2553 g_Monsters_FreeData();
2555 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2557 g_Texture_Delete('NOTEXTURE');
2558 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2559 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2560 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2561 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2562 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2563 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2564 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2565 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2566 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2567 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2568 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2569 g_Frames_DeleteByName('FRAMES_TELEPORT');
2570 g_Frames_DeleteByName('FRAMES_PUNCH');
2571 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2572 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2573 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2574 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2575 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2576 g_Sound_Delete('SOUND_GAME_TELEPORT');
2577 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2578 g_Sound_Delete('SOUND_GAME_SECRET');
2579 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2580 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2581 g_Sound_Delete('SOUND_GAME_BULK1');
2582 g_Sound_Delete('SOUND_GAME_BULK2');
2583 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2584 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2585 g_Sound_Delete('SOUND_GAME_BURNING');
2586 g_Sound_Delete('SOUND_GAME_SWITCH1');
2587 g_Sound_Delete('SOUND_GAME_SWITCH0');
2594 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2595 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2596 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2597 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2604 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2605 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2606 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2607 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2613 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2614 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2615 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2617 sound_get_flag
[0].Free();
2618 sound_get_flag
[1].Free();
2619 sound_lost_flag
[0].Free();
2620 sound_lost_flag
[1].Free();
2621 sound_ret_flag
[0].Free();
2622 sound_ret_flag
[1].Free();
2623 sound_cap_flag
[0].Free();
2624 sound_cap_flag
[1].Free();
2626 g_Sound_Delete('SOUND_CTF_GET1');
2627 g_Sound_Delete('SOUND_CTF_GET2');
2628 g_Sound_Delete('SOUND_CTF_LOST1');
2629 g_Sound_Delete('SOUND_CTF_LOST2');
2630 g_Sound_Delete('SOUND_CTF_RETURN1');
2631 g_Sound_Delete('SOUND_CTF_RETURN2');
2632 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2633 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2635 g_Game_FreeChatSounds();
2637 DataLoaded
:= False;
2640 procedure DrawCustomStat();
2646 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2647 s1
, s2
, topstr
: String;
2649 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2653 if g_Console_Action(ACTION_SCORES
) then
2655 if not gStatsPressed
then
2657 gStatsOff
:= not gStatsOff
;
2658 gStatsPressed
:= True;
2662 gStatsPressed
:= False;
2666 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2667 w
:= (Length(s1
) * ww2
) div 2;
2668 x
:= gScreenWidth
div 2 - w
;
2670 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2674 if (gGameSettings
.GameMode
= GM_COOP
) then
2676 if gMissionFailed
then
2677 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2679 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2682 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2684 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2685 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2687 if g_Game_IsNet
then
2689 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2690 if not gChatShow
then
2691 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2692 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2695 if g_Game_IsClient
then
2696 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2698 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2699 if not gChatShow
then
2700 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2701 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2706 w
:= gScreenWidth
-x
*2;
2712 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2713 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2715 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2717 case CustomStat
.GameMode
of
2720 if gGameSettings
.MaxLives
= 0 then
2721 s1
:= _lc
[I_GAME_DM
]
2723 s1
:= _lc
[I_GAME_LMS
];
2727 if gGameSettings
.MaxLives
= 0 then
2728 s1
:= _lc
[I_GAME_TDM
]
2730 s1
:= _lc
[I_GAME_TLMS
];
2732 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2735 if gGameSettings
.MaxLives
= 0 then
2736 s1
:= _lc
[I_GAME_COOP
]
2738 s1
:= _lc
[I_GAME_SURV
];
2744 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2748 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2749 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2752 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2753 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2754 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2755 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2757 pc
:= Length(CustomStat
.PlayerStat
);
2758 if pc
= 0 then Exit
;
2760 if CustomStat
.GameMode
= GM_COOP
then
2762 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2764 s2
:= _lc
[I_GAME_MONSTERS
];
2765 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2766 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2768 s2
:= _lc
[I_GAME_SECRETS
];
2769 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2770 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2773 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2775 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2776 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2777 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2779 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2780 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2781 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2785 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2790 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2791 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2792 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2794 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2797 for t
:= TEAM_RED
to TEAM_BLUE
do
2799 if t
= TEAM_RED
then
2801 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2802 gStdFont
, 255, 0, 0, 1);
2803 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2804 gStdFont
, 255, 0, 0, 1);
2811 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2812 gStdFont
, 0, 0, 255, 1);
2813 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2814 gStdFont
, 0, 0, 255, 1);
2820 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2823 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2824 if CustomStat
.PlayerStat
[p
].Team
= t
then
2825 with CustomStat
.PlayerStat
[p
] do
2839 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2840 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2842 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2843 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2844 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2851 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2854 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2855 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2856 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2859 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2860 with CustomStat
.PlayerStat
[p
] do
2862 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2869 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2870 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2872 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2873 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2874 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2879 // HACK: take stats screenshot immediately after the first frame of the stats showing
2880 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2882 g_TakeScreenShot('stats/' + StatFilename
);
2883 StatShotDone
:= True;
2887 procedure DrawSingleStat();
2889 tm
, key_x
, val_x
, y
: Integer;
2893 procedure player_stat(n
: Integer);
2899 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2900 s2
:= Format(' %d', [gTotalMonsters
]);
2902 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2903 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2904 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2905 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2907 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2908 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2910 // "Kills-per-minute: ##.#":
2911 s1
:= _lc
[I_MENU_INTER_KPM
];
2913 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2915 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2916 s2
:= Format(' %.1f', [kpm
]);
2918 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2919 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2921 // "Secrets found: # / #":
2922 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2923 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2925 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2926 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2927 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2928 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2930 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2931 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2935 // "Level Complete":
2936 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2937 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2939 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2940 s1
:= _lc
[I_MENU_INTER_KPM
];
2941 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2944 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2946 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2947 val_x
:= key_x
+ w1
;
2950 tm
:= SingleStat
.GameTime
div 1000;
2951 s1
:= _lc
[I_MENU_INTER_TIME
];
2952 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2954 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2955 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2957 if SingleStat
.TwoPlayers
then
2960 s1
:= _lc
[I_MENU_PLAYER_1
];
2961 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2962 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2964 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2969 s1
:= _lc
[I_MENU_PLAYER_2
];
2970 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2971 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2973 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2979 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2985 procedure DrawLoadingStat();
2986 procedure drawRect (x
, y
, w
, h
: Integer);
2988 if (w
< 1) or (h
< 1) then exit
;
2990 glVertex2f(x
+0.375, y
+0.375);
2991 glVertex2f(x
+w
+0.375, y
+0.375);
2992 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2993 glVertex2f(x
+0.375, y
+h
+0.375);
2997 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2999 rectW
, rectH
: Integer;
3006 idl
, idr
, idb
, idm
: LongWord;
3010 if (total
< 1) then exit
;
3011 if (cur
< 1) then exit
; // don't blink
3012 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3013 //if (cur < 0) then cur := 0;
3014 //if (cur > total) then cur := total;
3017 if (hasPBarGfx
) then
3019 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3020 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3021 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3022 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3023 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3024 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3025 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3026 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3028 //rectW := gScreenWidth-360;
3029 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3032 x0
:= (gScreenWidth
-rectW
) div 2;
3033 y0
:= gScreenHeight
-rectH
-64;
3034 if (y0
< 2) then y0
:= 2;
3036 glEnable(GL_SCISSOR_TEST
);
3039 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3040 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3041 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3044 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3046 while (f
< x0
+rectW
) do
3048 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3053 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3054 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3057 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3058 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3062 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3068 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3072 rectW
:= gScreenWidth
-64;
3075 x0
:= (gScreenWidth
-rectW
) div 2;
3076 y0
:= gScreenHeight
-rectH
-64;
3077 if (y0
< 2) then y0
:= 2;
3079 glDisable(GL_BLEND
);
3080 glDisable(GL_TEXTURE_2D
);
3082 //glClearColor(0, 0, 0, 0);
3083 //glClear(GL_COLOR_BUFFER_BIT);
3085 glColor4ub(127, 127, 127, 255);
3086 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3088 glColor4ub(0, 0, 0, 255);
3089 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3091 glColor4ub(127, 127, 127, 255);
3092 wdt
:= rectW
*cur
div total
;
3093 if (wdt
> rectW
) then wdt
:= rectW
;
3094 drawRect(x0
, y0
, wdt
, rectH
);
3103 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3105 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3106 yy
:= (gScreenHeight
div 3);
3107 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3108 xx
:= (gScreenWidth
div 3);
3112 for i
:= 0 to NextMsg
-1 do
3114 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3115 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3119 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3120 yy
:= yy
+ LOADING_INTERLINE
;
3121 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3126 procedure DrawMenuBackground(tex
: AnsiString);
3132 if g_Texture_Get(tex
, ID
) then
3134 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3135 e_GetTextureSize(ID
, @w
, @h
);
3137 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3139 w
:= trunc(w
* (gScreenHeight
/ h
));
3140 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3142 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3145 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3147 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3149 function monDraw (mon
: TMonster
): Boolean;
3151 result
:= false; // don't stop
3156 // Ëåâûé âåðõíèé óãîë
3157 aX
:= Obj
.X
div ScaleSz
+ 1;
3158 aY
:= Obj
.Y
div ScaleSz
+ 1;
3160 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3161 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3162 // Ïðàâûé íèæíèé óãîë
3163 aX2
:= aX
+ aX2
- 1;
3164 aY2
:= aY
+ aY2
- 1;
3165 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3171 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3172 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3175 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3176 ScaleSz
:= 16 div Scale
;
3177 // Ðàçìåðû ìèíè-êàðòû:
3178 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3179 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3181 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3183 if gWalls
<> nil then
3186 for a
:= 0 to High(gWalls
) do
3188 if PanelType
<> 0 then
3190 // Ëåâûé âåðõíèé óãîë:
3191 aX
:= X
div ScaleSz
;
3192 aY
:= Y
div ScaleSz
;
3194 aX2
:= max(Width
div ScaleSz
, 1);
3195 aY2
:= max(Height
div ScaleSz
, 1);
3196 // Ïðàâûé íèæíèé óãîë:
3197 aX2
:= aX
+ aX2
- 1;
3198 aY2
:= aY
+ aY2
- 1;
3201 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3202 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3203 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3207 if gSteps
<> nil then
3210 for a
:= 0 to High(gSteps
) do
3212 if PanelType
<> 0 then
3214 // Ëåâûé âåðõíèé óãîë:
3215 aX
:= X
div ScaleSz
;
3216 aY
:= Y
div ScaleSz
;
3218 aX2
:= max(Width
div ScaleSz
, 1);
3219 aY2
:= max(Height
div ScaleSz
, 1);
3220 // Ïðàâûé íèæíèé óãîë:
3221 aX2
:= aX
+ aX2
- 1;
3222 aY2
:= aY
+ aY2
- 1;
3224 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3227 if gLifts
<> nil then
3230 for a
:= 0 to High(gLifts
) do
3232 if PanelType
<> 0 then
3234 // Ëåâûé âåðõíèé óãîë:
3235 aX
:= X
div ScaleSz
;
3236 aY
:= Y
div ScaleSz
;
3238 aX2
:= max(Width
div ScaleSz
, 1);
3239 aY2
:= max(Height
div ScaleSz
, 1);
3240 // Ïðàâûé íèæíèé óãîë:
3241 aX2
:= aX
+ aX2
- 1;
3242 aY2
:= aY
+ aY2
- 1;
3245 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3246 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3247 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3248 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3252 if gWater
<> nil then
3255 for a
:= 0 to High(gWater
) do
3257 if PanelType
<> 0 then
3259 // Ëåâûé âåðõíèé óãîë:
3260 aX
:= X
div ScaleSz
;
3261 aY
:= Y
div ScaleSz
;
3263 aX2
:= max(Width
div ScaleSz
, 1);
3264 aY2
:= max(Height
div ScaleSz
, 1);
3265 // Ïðàâûé íèæíèé óãîë:
3266 aX2
:= aX
+ aX2
- 1;
3267 aY2
:= aY
+ aY2
- 1;
3269 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3272 if gAcid1
<> nil then
3274 // Ðèñóåì êèñëîòó 1:
3275 for a
:= 0 to High(gAcid1
) do
3277 if PanelType
<> 0 then
3279 // Ëåâûé âåðõíèé óãîë:
3280 aX
:= X
div ScaleSz
;
3281 aY
:= Y
div ScaleSz
;
3283 aX2
:= max(Width
div ScaleSz
, 1);
3284 aY2
:= max(Height
div ScaleSz
, 1);
3285 // Ïðàâûé íèæíèé óãîë:
3286 aX2
:= aX
+ aX2
- 1;
3287 aY2
:= aY
+ aY2
- 1;
3289 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3292 if gAcid2
<> nil then
3294 // Ðèñóåì êèñëîòó 2:
3295 for a
:= 0 to High(gAcid2
) do
3297 if PanelType
<> 0 then
3299 // Ëåâûé âåðõíèé óãîë:
3300 aX
:= X
div ScaleSz
;
3301 aY
:= Y
div ScaleSz
;
3303 aX2
:= max(Width
div ScaleSz
, 1);
3304 aY2
:= max(Height
div ScaleSz
, 1);
3305 // Ïðàâûé íèæíèé óãîë:
3306 aX2
:= aX
+ aX2
- 1;
3307 aY2
:= aY
+ aY2
- 1;
3309 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3312 if gPlayers
<> nil then
3315 for a
:= 0 to High(gPlayers
) do
3316 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3318 // Ëåâûé âåðõíèé óãîë:
3319 aX
:= Obj
.X
div ScaleSz
+ 1;
3320 aY
:= Obj
.Y
div ScaleSz
+ 1;
3322 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3323 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3324 // Ïðàâûé íèæíèé óãîë:
3325 aX2
:= aX
+ aX2
- 1;
3326 aY2
:= aY
+ aY2
- 1;
3328 if gPlayers
[a
] = p
then
3329 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3332 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3333 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3334 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3339 g_Mons_ForEach(monDraw
);
3344 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3346 if not hasAmbient
then exit
;
3347 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3351 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3352 //FIXME: broken for splitscreen mode
3353 procedure renderDynLightsInternal ();
3355 //hasAmbient: Boolean;
3356 //ambColor: TDFColor;
3358 lx
, ly
, lrad
: Integer;
3359 scxywh
: array[0..3] of GLint
;
3362 if e_NoGraphics
then exit
;
3364 //TODO: lights should be in separate grid, i think
3365 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3366 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3369 //ambColor := gCurrentMap['light_ambient'].rgba;
3370 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3372 { // this will multiply incoming color to alpha from framebuffer
3374 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3378 * light rendering: (INVALID!)
3379 * glStencilFunc(GL_EQUAL, 0, $ff);
3381 * glClear(GL_STENCIL_BUFFER_BIT);
3382 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3383 * draw shadow volume into stencil buffer
3384 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3385 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3387 * draw color-less quad with light alpha (WARNING! don't touch color!)
3388 * glEnable(GL_BLEND);
3389 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3390 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3392 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3393 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3395 // setup OpenGL parameters
3396 glStencilMask($FFFFFFFF);
3397 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3398 glEnable(GL_STENCIL_TEST
);
3399 glEnable(GL_SCISSOR_TEST
);
3400 glClear(GL_STENCIL_BUFFER_BIT
);
3401 glStencilFunc(GL_EQUAL
, 0, $ff);
3403 for lln
:= 0 to g_dynLightCount
-1 do
3405 lx
:= g_dynLights
[lln
].x
;
3406 ly
:= g_dynLights
[lln
].y
;
3407 lrad
:= g_dynLights
[lln
].radius
;
3408 if (lrad
< 3) then continue
;
3410 if (lx
-sX
+lrad
< 0) then continue
;
3411 if (ly
-sY
+lrad
< 0) then continue
;
3412 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3413 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3415 // set scissor to optimize drawing
3416 if (g_dbg_scale
= 1.0) then
3418 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3422 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3424 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3425 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3426 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3427 // draw extruded panels
3428 glDisable(GL_TEXTURE_2D
);
3429 glDisable(GL_BLEND
);
3430 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3431 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3432 // render light texture
3433 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3434 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3437 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3438 glEnable(GL_TEXTURE_2D
);
3439 // color and opacity
3440 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3441 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3443 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3444 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3445 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3446 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3451 glDisable(GL_STENCIL_TEST
);
3452 glDisable(GL_BLEND
);
3453 glDisable(GL_SCISSOR_TEST
);
3454 //glScissor(0, 0, sWidth, sHeight);
3456 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3457 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3461 function fixViewportForScale (): Boolean;
3463 nx0
, ny0
, nw
, nh
: Integer;
3466 if (g_dbg_scale
<> 1.0) then
3469 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3470 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3471 nw
:= round(sWidth
/g_dbg_scale
);
3472 nh
:= round(sHeight
/g_dbg_scale
);
3481 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3482 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3483 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3485 TDrawCB
= procedure ();
3488 hasAmbient
: Boolean;
3490 doAmbient
: Boolean = false;
3492 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3497 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3498 if gdbg_map_use_accel_render
then
3500 tagmask
:= panelTypeToTag(panType
);
3501 while (gDrawPanelList
.count
> 0) do
3503 pan
:= TPanel(gDrawPanelList
.front());
3504 if ((pan
.tag
and tagmask
) = 0) then break
;
3505 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3506 gDrawPanelList
.popFront();
3511 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3513 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3516 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3518 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3519 if assigned(cb
) then cb();
3520 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3524 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3526 // our accelerated renderer will collect all panels to gDrawPanelList
3527 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3528 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3529 if gdbg_map_use_accel_render
then
3531 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3533 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3535 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3536 g_Map_DrawBack(backXOfs
, backYOfs
);
3537 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3539 if setTransMatrix
then
3541 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3542 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3543 glTranslatef(-sX
, -sY
, 0);
3547 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3548 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3553 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3554 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3555 glClear(GL_COLOR_BUFFER_BIT);
3558 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3561 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3562 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3563 drawOther('items', @g_Items_Draw
);
3564 drawOther('weapons', @g_Weapon_Draw
);
3565 drawOther('shells', @g_Player_DrawShells
);
3566 drawOther('drawall', @g_Player_DrawAll
);
3567 drawOther('corpses', @g_Player_DrawCorpses
);
3568 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3569 drawOther('monsters', @g_Monsters_Draw
);
3570 drawOther('itemdrop', @g_Items_DrawDrop
);
3571 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3572 drawOther('gfx', @g_GFX_Draw
);
3573 drawOther('flags', @g_Map_DrawFlags
);
3574 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3575 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3576 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3577 drawOther('dynlights', @renderDynLightsInternal
);
3579 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3581 renderAmbientQuad(hasAmbient
, ambColor
);
3585 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3588 if g_debug_HealthBar
then
3590 g_Monsters_DrawHealth();
3591 g_Player_DrawHealth();
3594 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3598 procedure DrawMapView(x
, y
, w
, h
: Integer);
3605 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3606 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3613 fixViewportForScale();
3614 renderMapInternal(-bx
, -by
, true);
3620 procedure DrawPlayer(p
: TPlayer
);
3622 px
, py
, a
, b
, c
, d
, i
: Integer;
3625 if (p
= nil) or (p
.FDummy
) then
3628 g_Map_DrawBack(0, 0);
3633 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3634 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3640 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3641 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3643 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3645 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3646 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3648 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3649 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3651 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3652 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3655 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3658 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3659 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3662 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3667 // scaled, ignore level bounds
3668 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3669 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3674 sWidth
:= gPlayerScreenSize
.X
;
3675 sHeight
:= gPlayerScreenSize
.Y
;
3676 fixViewportForScale();
3678 i
:= py
- (sY
+ sHeight
div 2);
3679 if (p
.IncCam
> 0) then
3681 // clamp to level bounds
3682 if (sY
- p
.IncCam
< 0) then
3683 p
.IncCam
:= nclamp(sY
, 0, 120);
3684 // clamp around player position
3686 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3688 else if (p
.IncCam
< 0) then
3690 // clamp to level bounds
3691 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3692 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3693 // clamp around player position
3695 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3698 sY
:= sY
- p
.IncCam
;
3700 if (not g_dbg_ignore_bounds
) then
3702 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3703 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3704 if (sX
< 0) then sX
:= 0;
3705 if (sY
< 0) then sY
:= 0;
3708 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3709 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3711 //r_smallmap_h: 0: left; 1: center; 2: right
3712 //r_smallmap_v: 0: top; 1: center; 2: bottom
3714 if (gMapInfo
.Width
= sWidth
) then
3718 else if (gMapInfo
.Width
< sWidth
) then
3720 case r_smallmap_h
of
3721 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3722 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3723 else sX
:= 0; // left
3727 if (gMapInfo
.Height
= sHeight
) then
3731 else if (gMapInfo
.Height
< sHeight
) then
3733 case r_smallmap_v
of
3734 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3735 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3736 else sY
:= 0; // top
3742 p
.viewPortW
:= sWidth
;
3743 p
.viewPortH
:= sHeight
;
3745 {$IFDEF ENABLE_HOLMES}
3746 if (p
= gPlayer1
) then
3748 g_Holmes_plrViewPos(sX
, sY
);
3749 g_Holmes_plrViewSize(sWidth
, sHeight
);
3753 renderMapInternal(-c
, -d
, true);
3755 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3756 case gPlayerIndicator
of
3758 p
.DrawIndicator(_RGB(255, 255, 255));
3761 for i
:= 0 to High(gPlayers
) do
3762 if gPlayers
[i
] <> nil then
3763 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3764 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3765 if gPlayerIndicatorStyle
= 1 then
3766 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3767 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3770 if p
.FSpectator
then
3771 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3772 p
.GameY
+ PLAYER_RECT_CY
- 4,
3773 'X', gStdFont
, 255, 255, 255, 1, True);
3775 for a := 0 to High(gCollideMap) do
3776 for b := 0 to High(gCollideMap[a]) do
3779 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3781 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3785 1: e_DrawPoint(1, b, a, 200, 200, 200);
3786 2: e_DrawPoint(1, b, a, 64, 64, 255);
3787 3: e_DrawPoint(1, b, a, 255, 0, 255);
3797 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3798 if g_Debug_Player
then
3799 g_Player_DrawDebug(p
);
3803 procedure drawProfilers ();
3808 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3809 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3810 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3813 procedure g_Game_Draw();
3820 plView1
, plView2
: TPlayer
;
3823 if gExit
= EXIT_QUIT
then Exit
;
3825 Time
:= sys_GetTicks() {div 1000};
3826 FPSCounter
:= FPSCounter
+1;
3827 if Time
- FPSTime
>= 1000 then
3834 if gGameOn
or (gState
= STATE_FOLD
) then
3836 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3838 gSpectMode
:= SPECT_NONE
;
3839 if not gRevertPlayers
then
3841 plView1
:= gPlayer1
;
3842 plView2
:= gPlayer2
;
3846 plView1
:= gPlayer2
;
3847 plView2
:= gPlayer1
;
3851 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3853 gSpectMode
:= SPECT_NONE
;
3854 if gPlayer2
= nil then
3857 plView1
:= gPlayer2
;
3866 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3867 gSpectMode
:= SPECT_STATS
;
3869 if gSpectMode
= SPECT_PLAYERS
then
3870 if gPlayers
<> nil then
3872 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3873 if plView1
= nil then
3875 gSpectPID1
:= GetActivePlayerID_Next();
3876 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3878 if gSpectViewTwo
then
3880 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3881 if plView2
= nil then
3883 gSpectPID2
:= GetActivePlayerID_Next();
3884 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3889 if gSpectMode
= SPECT_MAPVIEW
then
3891 // Ðåæèì ïðîñìîòðà êàðòû
3893 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3894 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3895 gHearPoint1
.Active
:= True;
3896 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3897 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3898 gHearPoint2
.Active
:= False;
3902 Split
:= (plView1
<> nil) and (plView2
<> nil);
3904 // Òî÷êè ñëóõà èãðîêîâ
3905 if plView1
<> nil then
3907 gHearPoint1
.Active
:= True;
3908 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3909 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3911 gHearPoint1
.Active
:= False;
3912 if plView2
<> nil then
3914 gHearPoint2
.Active
:= True;
3915 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3916 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3918 gHearPoint2
.Active
:= False;
3920 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3921 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3924 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3925 if gScreenHeight
mod 2 = 0 then
3926 Dec(gPlayerScreenSize
.Y
);
3929 gPlayerScreenSize
.Y
:= gScreenHeight
;
3932 if gScreenHeight
mod 2 = 0 then
3933 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3935 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3937 DrawPlayer(plView1
);
3938 gPlayer1ScreenCoord
.X
:= sX
;
3939 gPlayer1ScreenCoord
.Y
:= sY
;
3943 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3945 DrawPlayer(plView2
);
3946 gPlayer2ScreenCoord
.X
:= sX
;
3947 gPlayer2ScreenCoord
.Y
:= sY
;
3950 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3953 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3956 {$IFDEF ENABLE_HOLMES}
3958 if (g_holmes_enabled
) then g_Holmes_Draw();
3961 if MessageText
<> '' then
3965 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3967 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3968 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3970 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3971 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3974 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3976 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3978 // Draw spectator GUI
3981 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3984 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3986 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3988 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3990 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3991 if gSpectMode
= SPECT_STATS
then
3993 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3994 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
3996 if gSpectMode
= SPECT_MAPVIEW
then
3998 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3999 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4000 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4001 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4002 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4004 if gSpectMode
= SPECT_PLAYERS
then
4006 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4007 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4008 if gSpectViewTwo
then
4010 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4011 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4012 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4013 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4017 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4018 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4024 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4026 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4027 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4029 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4030 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4031 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4036 if (gState
= STATE_MENU
) then
4038 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4039 // F3 at menu will show game loading dialog
4040 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4041 if (g_ActiveWindow
<> nil) then
4043 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4044 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4048 // F3 at titlepic will show game loading dialog
4049 if e_KeyPressed(IK_F3
) then
4051 g_Menu_Show_LoadMenu(true);
4052 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4057 if gState
= STATE_FOLD
then
4059 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4062 if gState
= STATE_INTERCUSTOM
then
4064 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4066 back
:= 'TEXTURE_endpic';
4067 if not g_Texture_Get(back
, ID
) then
4068 back
:= _lc
[I_TEXTURE_ENDPIC
];
4073 DrawMenuBackground(back
);
4077 if g_ActiveWindow
<> nil then
4079 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4080 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4084 if gState
= STATE_INTERSINGLE
then
4086 if EndingGameCounter
> 0 then
4088 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4094 DrawMenuBackground(back
);
4098 if g_ActiveWindow
<> nil then
4100 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4101 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4106 if gState
= STATE_ENDPIC
then
4109 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4110 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4112 if g_ActiveWindow
<> nil then
4114 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4115 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4119 if gState
= STATE_SLIST
then
4121 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4123 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4124 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4126 DrawMenuBackground('MENU_BACKGROUND');
4127 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4128 g_Serverlist_Draw(slCurrent
, slTable
);
4132 if g_ActiveWindow
<> nil then
4136 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4137 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4139 g_ActiveWindow
.Draw();
4146 if g_debug_Sounds
and gGameOn
then
4148 for w
:= 0 to High(e_SoundsArray
) do
4149 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4150 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4155 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4156 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4159 if gGameOn
and gShowTime
then
4160 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4162 if gGameOn
then drawProfilers();
4164 {$IFDEF ENABLE_HOLMES}
4171 procedure g_Game_Quit();
4173 g_Game_StopAllSounds(True);
4176 g_PlayerModel_FreeData();
4177 g_Texture_DeleteAll();
4178 g_Frames_DeleteAll();
4180 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4183 if NetInitDone
then g_Net_Free
;
4185 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4186 if gMapToDelete
<> '' then
4187 g_Game_DeleteTestMap();
4193 procedure g_FatalError(Text: String);
4195 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4196 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4198 gExit
:= EXIT_SIMPLE
;
4201 procedure g_SimpleError(Text: String);
4203 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4204 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4207 procedure g_Game_SetupScreenSize();
4209 RES_FACTOR
= 4.0 / 3.0;
4215 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4216 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4217 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4218 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4220 gPlayerScreenSize
.Y
:= gScreenHeight
;
4222 // Ðàçìåð çàäíåãî ïëàíà:
4223 if BackID
<> DWORD(-1) then
4226 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4227 (gScreenHeight
*s
> gMapInfo
.Height
) then
4229 gBackSize
.X
:= gScreenWidth
;
4230 gBackSize
.Y
:= gScreenHeight
;
4234 e_GetTextureSize(BackID
, @bw
, @bh
);
4235 rf
:= Single(bw
) / Single(bh
);
4236 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4237 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4238 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4239 if (s
< 1.0) then s
:= 1.0;
4240 gBackSize
.X
:= Round(bw
*s
);
4241 gBackSize
.Y
:= Round(bh
*s
);
4246 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4248 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4251 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4253 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4254 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4256 if gPlayer1
= nil then
4258 if g_Game_IsClient
then
4260 if NetPlrUID1
> -1 then
4262 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4263 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4268 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4269 Team
:= gPlayer1Settings
.Team
;
4271 // Ñîçäàíèå ïåðâîãî èãðîêà:
4272 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4273 gPlayer1Settings
.Color
,
4275 if gPlayer1
= nil then
4276 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4279 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4280 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4281 if g_Game_IsServer
and g_Game_IsNet
then
4282 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4283 gPlayer1
.Respawn(False, True);
4284 g_Net_Slist_ServerPlayerComes();
4289 if gPlayer2
= nil then
4291 if g_Game_IsClient
then
4293 if NetPlrUID2
> -1 then
4294 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4298 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4299 Team
:= gPlayer2Settings
.Team
;
4301 // Ñîçäàíèå âòîðîãî èãðîêà:
4302 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4303 gPlayer2Settings
.Color
,
4305 if gPlayer2
= nil then
4306 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4309 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4310 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4311 if g_Game_IsServer
and g_Game_IsNet
then
4312 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4313 gPlayer2
.Respawn(False, True);
4314 g_Net_Slist_ServerPlayerComes();
4321 procedure g_Game_RemovePlayer();
4325 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4326 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4331 if g_Game_IsServer
then
4334 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4335 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4336 g_Player_Remove(Pl
.UID
);
4337 g_Net_Slist_ServerPlayerLeaves();
4345 if g_Game_IsServer
then
4348 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4349 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4350 g_Player_Remove(Pl
.UID
);
4351 g_Net_Slist_ServerPlayerLeaves();
4355 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4359 g_Net_Slist_ServerPlayerLeaves();
4362 procedure g_Game_Spectate();
4364 g_Game_RemovePlayer();
4365 if gPlayer1
<> nil then
4366 g_Game_RemovePlayer();
4369 procedure g_Game_SpectateCenterView();
4371 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4372 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4375 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4382 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4384 g_Game_ClearLoading();
4387 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4390 gGameSettings
.GameType
:= GT_SINGLE
;
4391 gGameSettings
.MaxLives
:= 0;
4392 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4393 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4394 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4395 gSwitchGameMode
:= GM_SINGLE
;
4397 g_Game_ExecuteEvent('ongamestart');
4399 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4400 g_Game_SetupScreenSize();
4402 // Ñîçäàíèå ïåðâîãî èãðîêà:
4403 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4404 gPlayer1Settings
.Color
,
4405 gPlayer1Settings
.Team
, False));
4406 if gPlayer1
= nil then
4408 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4412 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4415 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4418 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4419 gPlayer2Settings
.Color
,
4420 gPlayer2Settings
.Team
, False));
4421 if gPlayer2
= nil then
4423 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4427 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4431 // Çàãðóçêà è çàïóñê êàðòû:
4432 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4434 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4435 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4439 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4443 for i
:= nPl
+1 to nPlayers
do
4444 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4447 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4448 TimeLimit
, GoalLimit
: Word;
4450 Options
: LongWord; nPlayers
: Byte);
4456 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4458 g_Game_ClearLoading();
4461 gGameSettings
.GameType
:= GT_CUSTOM
;
4462 gGameSettings
.GameMode
:= GameMode
;
4463 gSwitchGameMode
:= GameMode
;
4464 gGameSettings
.TimeLimit
:= TimeLimit
;
4465 gGameSettings
.GoalLimit
:= GoalLimit
;
4466 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4467 gGameSettings
.Options
:= Options
;
4469 gCoopTotalMonstersKilled
:= 0;
4470 gCoopTotalSecretsFound
:= 0;
4471 gCoopTotalMonsters
:= 0;
4472 gCoopTotalSecrets
:= 0;
4476 g_Game_ExecuteEvent('ongamestart');
4478 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4479 g_Game_SetupScreenSize();
4481 // Ðåæèì íàáëþäàòåëÿ:
4482 if nPlayers
= 0 then
4489 if nPlayers
>= 1 then
4491 // Ñîçäàíèå ïåðâîãî èãðîêà:
4492 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4493 gPlayer1Settings
.Color
,
4494 gPlayer1Settings
.Team
, False));
4495 if gPlayer1
= nil then
4497 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4501 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4505 if nPlayers
>= 2 then
4507 // Ñîçäàíèå âòîðîãî èãðîêà:
4508 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4509 gPlayer2Settings
.Color
,
4510 gPlayer2Settings
.Team
, False));
4511 if gPlayer2
= nil then
4513 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4517 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4521 // Çàãðóçêà è çàïóñê êàðòû:
4522 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4524 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4528 // Íåò òî÷åê ïîÿâëåíèÿ:
4529 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4530 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4531 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4532 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4533 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4535 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4539 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4543 for i
:= nPl
+1 to nPlayers
do
4544 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4547 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4548 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4549 Options
: LongWord; nPlayers
: Byte;
4550 IPAddr
: LongWord; Port
: Word);
4553 g_Net_Slist_ServerClosed();
4555 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4557 g_Game_ClearLoading();
4560 gGameSettings
.GameType
:= GT_SERVER
;
4561 gGameSettings
.GameMode
:= GameMode
;
4562 gSwitchGameMode
:= GameMode
;
4563 gGameSettings
.TimeLimit
:= TimeLimit
;
4564 gGameSettings
.GoalLimit
:= GoalLimit
;
4565 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4566 gGameSettings
.Options
:= Options
;
4568 gCoopTotalMonstersKilled
:= 0;
4569 gCoopTotalSecretsFound
:= 0;
4570 gCoopTotalMonsters
:= 0;
4571 gCoopTotalSecrets
:= 0;
4575 g_Game_ExecuteEvent('ongamestart');
4577 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4578 g_Game_SetupScreenSize();
4580 // Ðåæèì íàáëþäàòåëÿ:
4581 if nPlayers
= 0 then
4587 if nPlayers
>= 1 then
4589 // Ñîçäàíèå ïåðâîãî èãðîêà:
4590 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4591 gPlayer1Settings
.Color
,
4592 gPlayer1Settings
.Team
, False));
4593 if gPlayer1
= nil then
4595 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4599 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4602 if nPlayers
>= 2 then
4604 // Ñîçäàíèå âòîðîãî èãðîêà:
4605 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4606 gPlayer2Settings
.Color
,
4607 gPlayer2Settings
.Team
, False));
4608 if gPlayer2
= nil then
4610 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4614 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4617 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4618 if NetForwardPorts
then
4619 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4622 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4624 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4628 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4630 g_Net_Slist_ServerStarted();
4632 // Çàãðóçêà è çàïóñê êàðòû:
4633 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4635 g_Net_Slist_ServerClosed();
4636 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4640 // Íåò òî÷åê ïîÿâëåíèÿ:
4641 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4642 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4643 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4644 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4645 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4647 g_Net_Slist_ServerClosed();
4648 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4652 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4655 g_Net_Slist_ServerMapStarted();
4656 NetState
:= NET_STATE_GAME
;
4659 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4674 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4675 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4677 g_Game_ClearLoading();
4680 gGameSettings
.GameType
:= GT_CLIENT
;
4682 gCoopTotalMonstersKilled
:= 0;
4683 gCoopTotalSecretsFound
:= 0;
4684 gCoopTotalMonsters
:= 0;
4685 gCoopTotalSecrets
:= 0;
4689 g_Game_ExecuteEvent('ongamestart');
4691 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4692 g_Game_SetupScreenSize();
4694 NetState
:= NET_STATE_AUTH
;
4696 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4698 // create (or update) map/resource databases
4699 g_Res_CreateDatabases(true);
4702 if not g_Net_Connect(Addr
, Port
) then
4704 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4705 NetState
:= NET_STATE_NONE
;
4709 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4711 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4716 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4717 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4718 // thank you, enet. let's ignore failures altogether then.
4719 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4721 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4723 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4725 // ignore all download packets, they're processed by separate code
4726 enet_packet_destroy(NetEvent
.packet
);
4729 Ptr
:= NetEvent
.packet
^.data
;
4730 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4732 enet_packet_destroy(NetEvent
.packet
);
4736 InMsg
.ReadLongWord(); // skip size
4737 MID
:= InMsg
.ReadByte();
4739 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4741 NetMyID
:= InMsg
.ReadByte();
4742 NetPlrUID1
:= InMsg
.ReadWord();
4744 WadName
:= InMsg
.ReadString();
4745 Map
:= InMsg
.ReadString();
4747 gWADHash
:= InMsg
.ReadMD5();
4749 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4750 gSwitchGameMode
:= gGameSettings
.GameMode
;
4751 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4752 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4753 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4754 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4755 T
:= InMsg
.ReadLongWord();
4757 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4758 //if newResPath = '' then
4760 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4761 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4762 if newResPath
= '' then
4764 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4765 enet_packet_destroy(NetEvent
.packet
);
4766 NetState
:= NET_STATE_NONE
;
4769 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4771 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4774 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4775 gPlayer1Settings
.Color
,
4776 gPlayer1Settings
.Team
, False));
4778 if gPlayer1
= nil then
4780 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4782 enet_packet_destroy(NetEvent
.packet
);
4783 NetState
:= NET_STATE_NONE
;
4787 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4788 gPlayer1
.UID
:= NetPlrUID1
;
4789 gPlayer1
.Reset(True);
4791 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4793 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4795 enet_packet_destroy(NetEvent
.packet
);
4796 NetState
:= NET_STATE_NONE
;
4804 enet_packet_destroy(NetEvent
.packet
);
4808 enet_packet_destroy(NetEvent
.packet
);
4812 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4815 if (NetEvent
.data
<= NET_DISC_MAX
) then
4816 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4817 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4824 ProcessLoading(true);
4826 if g_Net_UserRequestExit() then
4835 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4836 NetState
:= NET_STATE_NONE
;
4840 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4841 gLMSRespawnTime
:= 0;
4844 NetState
:= NET_STATE_GAME
;
4845 MC_SEND_FullStateRequest
;
4846 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4850 lastAsMegaWad
: Boolean = false;
4852 procedure g_Game_ChangeMap(const MapPath
: String);
4856 g_Game_ClearLoading();
4858 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4859 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4860 if gExitByTrigger
then
4863 gExitByTrigger
:= False;
4865 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4866 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4869 procedure g_Game_Restart();
4873 if g_Game_IsClient
then
4875 map
:= g_ExtractFileName(gMapInfo
.Map
);
4876 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4880 g_Game_ClearLoading();
4881 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4884 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4886 NewWAD
, ResName
: String;
4890 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4891 g_Player_RemoveAllCorpses();
4893 if (not g_Game_IsClient
) and
4894 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4895 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4897 if gSwitchGameMode
= GM_CTF
then
4898 gGameSettings
.MaxLives
:= 0;
4899 gGameSettings
.GameMode
:= gSwitchGameMode
;
4902 gSwitchGameMode
:= gGameSettings
.GameMode
;
4904 g_Player_ResetTeams();
4906 lastAsMegaWad
:= asMegawad
;
4907 if isWadPath(Map
) then
4909 NewWAD
:= g_ExtractWadName(Map
);
4910 ResName
:= g_ExtractFileName(Map
);
4911 if g_Game_IsServer
then
4913 nws
:= findDiskWad(NewWAD
);
4914 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4917 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4918 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4922 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4923 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4925 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4926 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4928 if (length(nws
) = 0) then
4930 ResName
:= ''; // failed
4935 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4936 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4937 g_Game_LoadWAD(NewWAD
);
4942 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4943 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
4948 NewWAD
:= gGameSettings
.WAD
;
4954 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4956 if (ResName
<> '') and (NewWAD
<> '') then
4958 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4959 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
4963 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4965 gState
:= STATE_NONE
;
4966 g_ActiveWindow
:= nil;
4972 if gGameSettings
.GameMode
= GM_CTF
then
4974 g_Map_ResetFlag(FLAG_RED
);
4975 g_Map_ResetFlag(FLAG_BLUE
);
4976 // CTF, à ôëàãîâ íåò:
4977 if not g_Map_HaveFlagPoints() then
4978 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4983 gState
:= STATE_MENU
;
4988 gPauseMain
:= false;
4989 gPauseHolmes
:= false;
4990 NetTimeToUpdate
:= 1;
4991 NetTimeToReliable
:= 0;
4992 NetTimeToMaster
:= NetMasterRate
;
4993 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4994 gLMSRespawnTime
:= 0;
4995 gMissionFailed
:= False;
4998 gCoopMonstersKilled
:= 0;
4999 gCoopSecretsFound
:= 0;
5001 gVoteInProgress
:= False;
5002 gVotePassed
:= False;
5008 if not gGameOn
then Exit
;
5010 g_Game_SpectateCenterView();
5012 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5014 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5015 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5016 gLMSSoftSpawn
:= True;
5017 if NetMode
= NET_SERVER
then
5018 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
5020 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
5023 if NetMode
= NET_SERVER
then
5025 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5028 g_Net_Slist_ServerMapStarted();
5030 if NetClients
<> nil then
5031 for I
:= 0 to High(NetClients
) do
5032 if NetClients
[I
].Used
then
5034 NetClients
[I
].Voted
:= False;
5035 if NetClients
[I
].RequestedFullUpdate
then
5037 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5038 NetClients
[I
].RequestedFullUpdate
:= False;
5042 g_Net_UnbanNonPermHosts();
5047 gCoopTotalMonstersKilled
:= 0;
5048 gCoopTotalSecretsFound
:= 0;
5049 gCoopTotalMonsters
:= 0;
5050 gCoopTotalSecrets
:= 0;
5054 g_Game_ExecuteEvent('onmapstart');
5057 procedure SetFirstLevel
;
5061 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5062 if MapList
= nil then
5065 SortSArray(MapList
);
5066 gNextMap
:= MapList
[Low(MapList
)];
5071 procedure g_Game_ExitLevel(const Map
: AnsiString);
5075 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5076 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5077 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5078 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5080 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5081 if gGameSettings
.GameType
= GT_SINGLE
then
5082 gExit
:= EXIT_ENDLEVELSINGLE
5083 else // Âûøëè â âûõîä â Ñâîåé èãðå
5085 gExit
:= EXIT_ENDLEVELCUSTOM
;
5086 if gGameSettings
.GameMode
= GM_COOP
then
5087 g_Player_RememberAll
;
5089 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5092 if gGameSettings
.GameMode
= GM_COOP
then
5095 gStatsPressed
:= True;
5096 gNextMap
:= 'MAP01';
5098 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5101 if g_Game_IsNet
then
5103 MH_SEND_GameStats();
5104 MH_SEND_CoopStats();
5110 procedure g_Game_RestartLevel();
5114 if gGameSettings
.GameMode
= GM_SINGLE
then
5119 gExit
:= EXIT_ENDLEVELCUSTOM
;
5120 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5124 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5126 gWAD
{, xwad}: String;
5129 if not g_Game_IsClient
then Exit
;
5130 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5132 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5137 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5141 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5144 g_Game_LoadWAD(NewWAD
);
5148 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5149 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5152 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5153 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5157 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5161 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5162 g_Game_LoadWAD(NewWAD);
5166 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5168 i
, n
, nb
, nr
: Integer;
5170 function monRespawn (mon
: TMonster
): Boolean;
5172 result
:= false; // don't stop
5173 if not mon
.FNoRespawn
then mon
.Respawn();
5177 if not g_Game_IsServer
then Exit
;
5178 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5179 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5180 gLMSRespawnTime
:= 0;
5183 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5185 gMissionFailed
:= True;
5186 g_Game_RestartLevel
;
5190 n
:= 0; nb
:= 0; nr
:= 0;
5191 for i
:= Low(gPlayers
) to High(gPlayers
) do
5192 if (gPlayers
[i
] <> nil) and
5193 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5194 (gPlayers
[i
] is TBot
)) then
5197 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5198 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5201 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5203 // wait a second until the fuckers finally decide to join
5204 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5205 gLMSRespawnTime
:= gTime
+ 1000;
5206 gLMSSoftSpawn
:= NoMapRestart
;
5210 g_Player_RemoveAllCorpses
;
5211 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5212 if g_Game_IsNet
then
5213 MH_SEND_GameEvent(NET_EV_LMS_START
);
5215 for i
:= Low(gPlayers
) to High(gPlayers
) do
5217 if gPlayers
[i
] = nil then continue
;
5218 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5219 // don't touch normal spectators
5220 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5222 gPlayers
[i
].FNoRespawn
:= True;
5223 gPlayers
[i
].Lives
:= 0;
5224 if g_Game_IsNet
then
5225 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5228 gPlayers
[i
].FNoRespawn
:= False;
5229 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5230 gPlayers
[i
].Respawn(False, True);
5231 if gGameSettings
.GameMode
= GM_COOP
then
5233 gPlayers
[i
].Frags
:= 0;
5234 gPlayers
[i
].RecallState
;
5236 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5237 gPlayer1
:= g_Player_Get(gLMSPID1
);
5238 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5239 gPlayer2
:= g_Player_Get(gLMSPID2
);
5242 g_Items_RestartRound();
5245 g_Mons_ForEach(monRespawn
);
5247 gLMSSoftSpawn
:= False;
5250 function g_Game_GetFirstMap(WAD
: String): String;
5254 MapList
:= g_Map_GetMapsList(WAD
);
5255 if MapList
= nil then
5258 SortSArray(MapList
);
5259 Result
:= MapList
[Low(MapList
)];
5261 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5267 function g_Game_GetNextMap(): String;
5274 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5275 if MapList
= nil then
5278 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5280 SortSArray(MapList
);
5282 for I
:= Low(MapList
) to High(MapList
) do
5283 if Map
= MapList
[I
] then
5289 if MapIndex
<> -255 then
5291 if MapIndex
= High(MapList
) then
5292 Result
:= MapList
[Low(MapList
)]
5294 Result
:= MapList
[MapIndex
+ 1];
5296 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5302 procedure g_Game_NextLevel();
5304 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5305 gExit
:= EXIT_ENDLEVELCUSTOM
5308 gExit
:= EXIT_ENDLEVELSINGLE
;
5312 if gNextMap
<> '' then Exit
;
5313 gNextMap
:= g_Game_GetNextMap();
5316 function g_Game_IsTestMap(): Boolean;
5318 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5321 procedure g_Game_DeleteTestMap();
5324 //MapName: AnsiString;
5332 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5333 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5334 if (a
= 0) then exit
;
5336 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5337 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5338 Delete(gMapToDelete
, 1, a
+5);
5339 gMapToDelete
:= UpperCase(gMapToDelete
);
5341 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5344 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5345 if MapName <> TEST_MAP_NAME then
5348 if not gTempDelete then
5350 time := g_GetFileTime(WadName);
5351 WAD := TWADFile.Create();
5354 if not WAD.ReadFile(WadName) then
5355 begin // Íåò òàêîãî WAD-ôàéëà
5360 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5362 MapList := WAD.GetResourcesList('');
5364 if MapList <> nil then
5365 for a := 0 to High(MapList) do
5366 if MapList[a] = MapName then
5368 // Óäàëÿåì è ñîõðàíÿåì:
5369 WAD.RemoveResource('', MapName);
5370 WAD.SaveTo(WadName);
5375 g_SetFileTime(WadName, time);
5378 if gTempDelete
then DeleteFile(WadName
);
5381 procedure GameCVars(P
: SSArray
);
5384 stat
: TPlayerStatArray
;
5389 cmd
:= LowerCase(P
[0]);
5390 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5392 with gGameSettings
do
5394 if (Length(P
) > 1) and
5395 ((P
[1] = '1') or (P
[1] = '0')) then
5397 if (P
[1][1] = '1') then
5398 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5400 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5403 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5404 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5406 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5408 if g_Game_IsNet
then MH_SEND_GameSettings
;
5411 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5413 with gGameSettings
do
5415 if (Length(P
) > 1) and
5416 ((P
[1] = '1') or (P
[1] = '0')) then
5418 if (P
[1][1] = '1') then
5419 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5421 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5424 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5425 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5427 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5429 if g_Game_IsNet
then MH_SEND_GameSettings
;
5432 else if cmd
= 'g_gamemode' then
5434 a
:= g_Game_TextToMode(P
[1]);
5435 if a
= GM_SINGLE
then a
:= GM_COOP
;
5436 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5438 gSwitchGameMode
:= a
;
5439 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5440 (gState
= STATE_INTERSINGLE
) then
5441 gSwitchGameMode
:= GM_SINGLE
;
5443 gGameSettings
.GameMode
:= gSwitchGameMode
;
5445 if gSwitchGameMode
= gGameSettings
.GameMode
then
5446 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5447 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5449 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5450 [g_Game_ModeToText(gGameSettings
.GameMode
),
5451 g_Game_ModeToText(gSwitchGameMode
)]));
5453 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5455 with gGameSettings
do
5457 if (Length(P
) > 1) and
5458 ((P
[1] = '1') or (P
[1] = '0')) then
5460 if (P
[1][1] = '1') then
5461 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5463 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5466 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5467 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5469 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5470 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5472 if g_Game_IsNet
then MH_SEND_GameSettings
;
5475 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5477 with gGameSettings
do
5479 if (Length(P
) > 1) and
5480 ((P
[1] = '1') or (P
[1] = '0')) then
5482 if (P
[1][1] = '1') then
5483 Options
:= Options
or GAME_OPTION_MONSTERS
5485 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5488 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5489 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5491 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5492 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5494 if g_Game_IsNet
then MH_SEND_GameSettings
;
5497 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5499 with gGameSettings
do
5501 if (Length(P
) > 1) and
5502 ((P
[1] = '1') or (P
[1] = '0')) then
5504 if (P
[1][1] = '1') then
5505 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5507 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5510 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5511 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5513 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5515 if g_Game_IsNet
then MH_SEND_GameSettings
;
5518 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5520 with gGameSettings
do
5522 if (Length(P
) > 1) and
5523 ((P
[1] = '1') or (P
[1] = '0')) then
5525 if (P
[1][1] = '1') then
5526 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5528 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5531 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5532 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5534 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5536 if g_Game_IsNet
then MH_SEND_GameSettings
;
5539 else if (cmd
= 'g_dm_keys') and not g_Game_IsClient
then
5541 with gGameSettings
do
5543 if (Length(P
) > 1) and
5544 ((P
[1] = '1') or (P
[1] = '0')) then
5546 if (P
[1][1] = '1') then
5547 Options
:= Options
or GAME_OPTION_DMKEYS
5549 Options
:= Options
and (not GAME_OPTION_DMKEYS
);
5552 if (LongBool(Options
and GAME_OPTION_DMKEYS
)) then
5553 g_Console_Add(_lc
[I_MSG_DMKEYS_ON
])
5555 g_Console_Add(_lc
[I_MSG_DMKEYS_OFF
]);
5557 if g_Game_IsNet
then MH_SEND_GameSettings
;
5560 else if (cmd
= 'g_respawn_items') and not g_Game_IsClient
then
5562 with gGameSettings
do
5564 if (Length(P
) > 1) and
5565 ((P
[1] = '1') or (P
[1] = '0')) then
5567 if (P
[1][1] = '1') then
5568 Options
:= Options
or GAME_OPTION_RESPAWNITEMS
5570 Options
:= Options
and (not GAME_OPTION_RESPAWNITEMS
);
5573 if (LongBool(Options
and GAME_OPTION_RESPAWNITEMS
)) then
5574 g_Console_Add(_lc
[I_MSG_RESPAWNITEMS_ON
])
5576 g_Console_Add(_lc
[I_MSG_RESPAWNITEMS_OFF
]);
5578 if g_Game_IsNet
then MH_SEND_GameSettings
;
5581 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5583 if Length(P
) > 1 then
5585 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5586 gGameSettings
.WarmupTime
:= 30
5588 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5591 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5592 [gGameSettings
.WarmupTime
]));
5593 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5595 else if (cmd
= 'g_spawn_invul') and not g_Game_IsClient
then
5597 if Length(P
) > 1 then
5599 if StrToIntDef(P
[1], gGameSettings
.SpawnInvul
) = 0 then
5600 gGameSettings
.SpawnInvul
:= 0
5602 gGameSettings
.SpawnInvul
:= StrToIntDef(P
[1], gGameSettings
.SpawnInvul
);
5605 g_Console_Add(Format(_lc
[I_MSG_SPAWNINVUL
],
5606 [gGameSettings
.SpawnInvul
]));
5607 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5609 else if cmd
= 'net_interp' then
5611 if (Length(P
) > 1) then
5612 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5613 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5614 s
:= e_GetWriteableDir(ConfigDirs
);
5617 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5618 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5619 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5623 else if cmd
= 'net_forceplayerupdate' then
5625 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5626 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5628 if NetForcePlayerUpdate
then
5629 g_Console_Add('net_forceplayerupdate = 1')
5631 g_Console_Add('net_forceplayerupdate = 0');
5633 s
:= e_GetWriteableDir(ConfigDirs
);
5636 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5637 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5638 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5642 else if cmd
= 'net_predictself' then
5644 if (Length(P
) > 1) and
5645 ((P
[1] = '1') or (P
[1] = '0')) then
5646 NetPredictSelf
:= (P
[1][1] = '1');
5648 if NetPredictSelf
then
5649 g_Console_Add('net_predictself = 1')
5651 g_Console_Add('net_predictself = 0');
5653 s
:= e_GetWriteableDir(ConfigDirs
);
5656 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5657 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5658 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5662 else if cmd
= 'sv_name' then
5664 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5666 NetServerName
:= P
[1];
5667 if Length(NetServerName
) > 64 then
5668 SetLength(NetServerName
, 64);
5669 g_Net_Slist_ServerRenamed();
5672 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5674 else if cmd
= 'sv_passwd' then
5676 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5678 NetPassword
:= P
[1];
5679 if Length(NetPassword
) > 24 then
5680 SetLength(NetPassword
, 24);
5681 g_Net_Slist_ServerRenamed();
5684 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5686 else if cmd
= 'sv_maxplrs' then
5688 if (Length(P
) > 1) then
5690 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5691 if g_Game_IsServer
and g_Game_IsNet
then
5694 for a
:= 0 to High(NetClients
) do
5696 if NetClients
[a
].Used
then
5699 if b
> NetMaxClients
then
5701 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5702 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5703 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5704 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5708 g_Net_Slist_ServerRenamed();
5712 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5714 else if cmd
= 'sv_public' then
5716 if (Length(P
) > 1) then
5718 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5719 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5722 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5724 else if cmd
= 'sv_intertime' then
5726 if (Length(P
) > 1) then
5727 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5729 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5731 else if cmd
= 'p1_name' then
5733 if (Length(P
) > 1) and gGameOn
then
5735 if g_Game_IsClient
then
5737 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5738 MC_SEND_PlayerSettings
;
5741 if gPlayer1
<> nil then
5743 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5744 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5747 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5750 else if cmd
= 'p2_name' then
5752 if (Length(P
) > 1) and gGameOn
then
5754 if g_Game_IsClient
then
5756 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5757 MC_SEND_PlayerSettings
;
5760 if gPlayer2
<> nil then
5762 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5763 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5766 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5769 else if cmd
= 'p1_color' then
5771 if Length(P
) > 3 then
5772 if g_Game_IsClient
then
5774 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5775 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5776 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5777 MC_SEND_PlayerSettings
;
5780 if gPlayer1
<> nil then
5782 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5783 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5784 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5785 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5788 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5789 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5790 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5792 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5794 if Length(P
) > 3 then
5795 if g_Game_IsClient
then
5797 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5798 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5799 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5800 MC_SEND_PlayerSettings
;
5803 if gPlayer2
<> nil then
5805 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5806 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5807 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5808 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5811 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5812 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5813 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5815 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5817 if cmd
= 'r_showscore' then
5819 if (Length(P
) > 1) and
5820 ((P
[1] = '1') or (P
[1] = '0')) then
5821 gShowGoals
:= (P
[1][1] = '1');
5824 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5826 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5828 else if cmd
= 'r_showstat' then
5830 if (Length(P
) > 1) and
5831 ((P
[1] = '1') or (P
[1] = '0')) then
5832 gShowStat
:= (P
[1][1] = '1');
5835 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5837 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5839 else if cmd
= 'r_showkillmsg' then
5841 if (Length(P
) > 1) and
5842 ((P
[1] = '1') or (P
[1] = '0')) then
5843 gShowKillMsg
:= (P
[1][1] = '1');
5845 if gShowKillMsg
then
5846 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5848 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5850 else if cmd
= 'r_showlives' then
5852 if (Length(P
) > 1) and
5853 ((P
[1] = '1') or (P
[1] = '0')) then
5854 gShowLives
:= (P
[1][1] = '1');
5857 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5859 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5861 else if cmd
= 'r_showspect' then
5863 if (Length(P
) > 1) and
5864 ((P
[1] = '1') or (P
[1] = '0')) then
5865 gSpectHUD
:= (P
[1][1] = '1');
5868 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5870 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5872 else if cmd
= 'r_showping' then
5874 if (Length(P
) > 1) and
5875 ((P
[1] = '1') or (P
[1] = '0')) then
5876 gShowPing
:= (P
[1][1] = '1');
5879 g_Console_Add(_lc
[I_MSG_PING_ON
])
5881 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5883 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5885 if Length(P
) > 1 then
5887 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5888 gGameSettings
.GoalLimit
:= 0
5893 if gGameSettings
.GameMode
= GM_DM
then
5895 stat
:= g_Player_GetStats();
5897 for a
:= 0 to High(stat
) do
5898 if stat
[a
].Frags
> b
then
5902 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5904 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5907 if g_Game_IsNet
then MH_SEND_GameSettings
;
5910 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5912 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5914 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5915 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5917 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5918 [gGameSettings
.TimeLimit
div 3600,
5919 (gGameSettings
.TimeLimit
div 60) mod 60,
5920 gGameSettings
.TimeLimit
mod 60]));
5921 if g_Game_IsNet
then MH_SEND_GameSettings
;
5923 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5925 if Length(P
) > 1 then
5927 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5928 gGameSettings
.MaxLives
:= 0
5932 stat
:= g_Player_GetStats();
5934 for a
:= 0 to High(stat
) do
5935 if stat
[a
].Lives
> b
then
5937 gGameSettings
.MaxLives
:=
5938 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5942 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5943 [gGameSettings
.MaxLives
]));
5944 if g_Game_IsNet
then MH_SEND_GameSettings
;
5949 procedure PrintHeapStats();
5953 hs
:= GetFPCHeapStatus();
5954 e_LogWriteLn ('v===== heap status =====v');
5955 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5956 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5957 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5958 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5959 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5960 e_LogWriteLn ('^=======================^');
5963 procedure DebugCommands(P
: SSArray
);
5970 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5971 if {gDebugMode}conIsCheatsEnabled
then
5973 cmd
:= LowerCase(P
[0]);
5974 if cmd
= 'd_window' then
5976 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5977 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5979 else if cmd
= 'd_sounds' then
5981 if (Length(P
) > 1) and
5982 ((P
[1] = '1') or (P
[1] = '0')) then
5983 g_Debug_Sounds
:= (P
[1][1] = '1');
5985 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5987 else if cmd
= 'd_frames' then
5989 if (Length(P
) > 1) and
5990 ((P
[1] = '1') or (P
[1] = '0')) then
5991 g_Debug_Frames
:= (P
[1][1] = '1');
5993 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5995 else if cmd
= 'd_winmsg' then
5997 if (Length(P
) > 1) and
5998 ((P
[1] = '1') or (P
[1] = '0')) then
5999 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6001 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6003 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6005 if (Length(P
) > 1) and
6006 ((P
[1] = '1') or (P
[1] = '0')) then
6007 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6009 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6011 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6013 if Length(P
) > 1 then
6015 '0': g_debug_BotAIOff
:= 0;
6016 '1': g_debug_BotAIOff
:= 1;
6017 '2': g_debug_BotAIOff
:= 2;
6018 '3': g_debug_BotAIOff
:= 3;
6021 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6023 else if cmd
= 'd_monster' then
6025 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6026 if Length(P
) < 2 then
6028 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6029 g_Console_Add('ID | Name');
6030 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6031 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6032 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6035 a
:= StrToIntDef(P
[1], 0);
6036 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6037 a
:= g_Mons_TypeIdByName(P
[1]);
6039 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6040 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6043 with gPlayer1
.Obj
do
6045 mon
:= g_Monsters_Create(a
,
6046 X
+ Rect
.X
+ (Rect
.Width
div 2),
6047 Y
+ Rect
.Y
+ Rect
.Height
,
6048 gPlayer1
.Direction
, True);
6050 if (Length(P
) > 2) and (mon
<> nil) then
6052 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6053 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6054 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6055 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6056 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6057 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6058 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6059 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6060 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6065 else if (cmd
= 'd_health') then
6067 if (Length(P
) > 1) and
6068 ((P
[1] = '1') or (P
[1] = '0')) then
6069 g_debug_HealthBar
:= (P
[1][1] = '1');
6071 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6073 else if (cmd
= 'd_player') then
6075 if (Length(P
) > 1) and
6076 ((P
[1] = '1') or (P
[1] = '0')) then
6077 g_debug_Player
:= (P
[1][1] = '1');
6079 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6081 else if (cmd
= 'd_mem') then
6087 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6091 procedure GameCheats(P
: SSArray
);
6097 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6099 g_Console_Add('not available');
6105 g_Console_Add('where is the player?!');
6108 cmd
:= LowerCase(P
[0]);
6112 plr
.GodMode
:= not plr
.GodMode
;
6113 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6116 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6117 if cmd
= 'give' then
6119 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6120 for f
:= 1 to High(P
) do
6122 cmd
:= LowerCase(P
[f
]);
6123 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6124 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6125 if cmd
= 'exit' then
6127 if gTriggers
<> nil then
6129 for a
:= 0 to High(gTriggers
) do
6131 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6133 g_Console_Add('player left the map');
6134 gExitByTrigger
:= True;
6135 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6136 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6144 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6145 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6146 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6147 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6148 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6150 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6151 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6153 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6154 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;
6156 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6157 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6159 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6160 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6162 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6163 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6165 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6166 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6167 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6169 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6170 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6171 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6172 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;
6173 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6174 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6176 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;
6177 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;
6178 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;
6179 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;
6180 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;
6181 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;
6183 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6184 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;
6186 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;
6187 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;
6189 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6191 if cmd
= 'ammo' then
6193 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6194 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6195 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6196 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6197 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6198 g_Console_Add('player got some ammo');
6202 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6203 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6205 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6206 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6208 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6209 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6211 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6212 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6214 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6216 if cmd
= 'weapons' then
6218 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6219 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6220 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6221 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6222 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6223 plr
.GiveItem(ITEM_WEAPON_BFG
);
6224 g_Console_Add('player got weapons');
6228 if cmd
= 'keys' then
6230 plr
.GiveItem(ITEM_KEY_RED
);
6231 plr
.GiveItem(ITEM_KEY_GREEN
);
6232 plr
.GiveItem(ITEM_KEY_BLUE
);
6233 g_Console_Add('player got all keys');
6237 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6242 if cmd
= 'open' then
6244 g_Console_Add('player activated sesame');
6245 g_Triggers_OpenAll();
6252 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6256 if cmd
= 'noclip' then
6259 g_Console_Add('wall hardeness adjusted');
6263 if cmd
= 'notarget' then
6265 plr
.NoTarget
:= not plr
.NoTarget
;
6266 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6270 if cmd
= 'noreload' then
6272 plr
.NoReload
:= not plr
.NoReload
;
6273 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6277 if cmd
= 'speedy' then
6279 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6280 g_Console_Add('speed adjusted');
6284 if cmd
= 'jumpy' then
6286 VEL_JUMP
:= 30-VEL_JUMP
;
6287 g_Console_Add('jump height adjusted');
6291 if cmd
= 'automap' then
6293 gShowMap
:= not gShowMap
;
6294 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6298 if cmd
= 'aimline' then
6300 gAimLine
:= not gAimLine
;
6301 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6306 procedure GameCommands(P
: SSArray
);
6312 pl
: pTNetClient
= nil;
6320 cmd
:= LowerCase(P
[0]);
6322 if (cmd
= 'quit') or
6329 else if cmd
= 'pause' then
6331 if (g_ActiveWindow
= nil) then
6332 g_Game_Pause(not gPauseMain
);
6334 else if cmd
= 'endgame' then
6335 gExit
:= EXIT_SIMPLE
6336 else if cmd
= 'restart' then
6338 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6340 if g_Game_IsClient
then
6342 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6347 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6349 else if cmd
= 'kick' then
6351 if g_Game_IsServer
then
6353 if Length(P
) < 2 then
6355 g_Console_Add('kick <name>');
6360 g_Console_Add('kick <name>');
6364 if g_Game_IsNet
then
6365 pl
:= g_Net_Client_ByName(P
[1]);
6368 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6369 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6370 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6371 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6372 g_Net_Slist_ServerPlayerLeaves();
6373 end else if gPlayers
<> nil then
6374 for a
:= Low(gPlayers
) to High(gPlayers
) do
6375 if gPlayers
[a
] <> nil then
6376 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6378 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6379 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6381 gPlayers
[a
].Lives
:= 0;
6382 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6383 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6384 g_Player_Remove(gPlayers
[a
].UID
);
6385 g_Net_Slist_ServerPlayerLeaves();
6386 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6390 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6392 else if cmd
= 'kick_id' then
6394 if g_Game_IsServer
and g_Game_IsNet
then
6396 if Length(P
) < 2 then
6398 g_Console_Add('kick_id <client ID>');
6403 g_Console_Add('kick_id <client ID>');
6407 a
:= StrToIntDef(P
[1], 0);
6408 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6410 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6412 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6413 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6414 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6415 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6416 g_Net_Slist_ServerPlayerLeaves();
6420 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6422 else if cmd
= 'ban' then
6424 if g_Game_IsServer
and g_Game_IsNet
then
6426 if Length(P
) < 2 then
6428 g_Console_Add('ban <name>');
6433 g_Console_Add('ban <name>');
6437 pl
:= g_Net_Client_ByName(P
[1]);
6440 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6441 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6442 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6443 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6444 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6445 g_Net_Slist_ServerPlayerLeaves();
6447 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6449 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6451 else if cmd
= 'ban_id' then
6453 if g_Game_IsServer
and g_Game_IsNet
then
6455 if Length(P
) < 2 then
6457 g_Console_Add('ban_id <client ID>');
6462 g_Console_Add('ban_id <client ID>');
6466 a
:= StrToIntDef(P
[1], 0);
6467 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6468 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6470 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6471 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6472 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6473 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6474 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6475 g_Net_Slist_ServerPlayerLeaves();
6478 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6480 else if cmd
= 'permban' then
6482 if g_Game_IsServer
and g_Game_IsNet
then
6484 if Length(P
) < 2 then
6486 g_Console_Add('permban <name>');
6491 g_Console_Add('permban <name>');
6495 pl
:= g_Net_Client_ByName(P
[1]);
6498 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6499 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6500 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6501 g_Net_SaveBanList();
6502 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6503 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6504 g_Net_Slist_ServerPlayerLeaves();
6506 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6508 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6510 else if cmd
= 'permban_id' then
6512 if g_Game_IsServer
and g_Game_IsNet
then
6514 if Length(P
) < 2 then
6516 g_Console_Add('permban_id <client ID>');
6521 g_Console_Add('permban_id <client ID>');
6525 a
:= StrToIntDef(P
[1], 0);
6526 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6527 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6529 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6530 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6531 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6532 g_Net_SaveBanList();
6533 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6534 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6535 g_Net_Slist_ServerPlayerLeaves();
6538 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6540 else if cmd
= 'unban' then
6542 if g_Game_IsServer
and g_Game_IsNet
then
6544 if Length(P
) < 2 then
6546 g_Console_Add('unban <IP Address>');
6551 g_Console_Add('unban <IP Address>');
6555 if g_Net_UnbanHost(P
[1]) then
6557 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6558 g_Net_SaveBanList();
6560 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6562 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6564 else if cmd
= 'clientlist' then
6566 if g_Game_IsServer
and g_Game_IsNet
then
6569 if NetClients
<> nil then
6570 for a
:= Low(NetClients
) to High(NetClients
) do
6571 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6573 plr
:= g_Player_Get(NetClients
[a
].Player
);
6574 if plr
= nil then continue
;
6576 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6577 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6580 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6582 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6584 else if cmd
= 'connect' then
6586 if (NetMode
= NET_NONE
) then
6588 if Length(P
) < 2 then
6590 g_Console_Add('connect <IP> [port] [password]');
6595 g_Console_Add('connect <IP> [port] [password]');
6599 if Length(P
) > 2 then
6600 prt
:= StrToIntDef(P
[2], 25666)
6604 if Length(P
) > 3 then
6609 g_Game_StartClient(P
[1], prt
, pw
);
6612 else if cmd
= 'disconnect' then
6614 if (NetMode
= NET_CLIENT
) then
6617 else if cmd
= 'reconnect' then
6619 if (NetMode
= NET_SERVER
) then
6622 if (NetMode
= NET_CLIENT
) then
6625 gExit
:= EXIT_SIMPLE
;
6629 //TODO: Use last successful password to reconnect, instead of ''
6630 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6632 else if (cmd
= 'addbot') or
6633 (cmd
= 'bot_add') then
6635 if Length(P
) > 2 then
6636 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6637 else if Length(P
) > 1 then
6638 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6640 g_Bot_Add(TEAM_NONE
, 2);
6642 else if cmd
= 'bot_addlist' then
6644 if Length(P
) > 1 then
6646 if Length(P
) = 2 then
6647 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6648 else if Length(P
) = 3 then
6649 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6651 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6654 else if cmd
= 'bot_removeall' then
6656 else if cmd
= 'chat' then
6658 if g_Game_IsNet
then
6660 if Length(P
) > 1 then
6662 for a
:= 1 to High(P
) do
6663 chstr
:= chstr
+ P
[a
] + ' ';
6665 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6667 if Length(chstr
) < 1 then
6669 g_Console_Add('chat <text>');
6673 chstr
:= b_Text_Format(chstr
);
6674 if g_Game_IsClient
then
6675 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6677 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6680 g_Console_Add('chat <text>');
6682 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6684 else if cmd
= 'teamchat' then
6686 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6688 if Length(P
) > 1 then
6690 for a
:= 1 to High(P
) do
6691 chstr
:= chstr
+ P
[a
] + ' ';
6693 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6695 if Length(chstr
) < 1 then
6697 g_Console_Add('teamchat <text>');
6701 chstr
:= b_Text_Format(chstr
);
6702 if g_Game_IsClient
then
6703 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6705 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6706 gPlayer1Settings
.Team
);
6709 g_Console_Add('teamchat <text>');
6711 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6713 else if cmd
= 'game' then
6715 if gGameSettings
.GameType
<> GT_NONE
then
6717 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6720 if Length(P
) = 1 then
6722 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6725 // game not started yet, load fist map from some wad
6727 s
:= addWadExtension(P
[1]);
6728 found
:= e_FindResource(AllMapDirs
, s
);
6732 P
[1] := ExpandFileName(P
[1]);
6733 // if map not choosed then set first map
6734 if Length(P
) < 3 then
6737 P
[2] := g_Game_GetFirstMap(P
[1]);
6740 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6742 if g_Map_Exist(s
) then
6746 with gGameSettings
do
6748 GameMode
:= g_Game_TextToMode(gcGameMode
);
6749 if gSwitchGameMode
<> GM_NONE
then
6750 GameMode
:= gSwitchGameMode
;
6751 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6752 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6754 if Length(P
) >= 4 then
6755 b
:= StrToIntDef(P
[3], 1);
6756 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6757 GoalLimit
, MaxLives
, Options
, b
);
6762 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6764 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6766 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6768 else if cmd
= 'host' then
6770 if gGameSettings
.GameType
<> GT_NONE
then
6772 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6775 if Length(P
) < 4 then
6777 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6780 if not StrToIp(P
[1], listen
) then
6782 prt
:= StrToIntDef(P
[2], 25666);
6784 s
:= addWadExtension(P
[3]);
6785 found
:= e_FindResource(AllMapDirs
, s
);
6789 // get first map in wad, if not specified
6790 if Length(P
) < 5 then
6793 P
[4] := g_Game_GetFirstMap(P
[1]);
6795 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6796 if g_Map_Exist(s
) then
6800 with gGameSettings
do
6802 GameMode
:= g_Game_TextToMode(gcGameMode
);
6803 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6804 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6805 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6807 if Length(P
) >= 6 then
6808 b
:= StrToIntDef(P
[5], 0);
6809 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6815 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6817 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6822 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6825 else if cmd
= 'map' then
6827 if Length(P
) = 1 then
6829 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6831 g_Console_Add(cmd
+ ' <MAP>');
6832 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6836 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6841 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6843 if Length(P
) < 3 then
6845 // first param is map or wad
6846 s
:= UpperCase(P
[1]);
6847 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6849 gExitByTrigger
:= False;
6852 // already in game, finish current map
6854 gExit
:= EXIT_ENDLEVELCUSTOM
;
6858 // intermission, so change map immediately
6865 found
:= e_FindResource(AllMapDirs
, s
);
6867 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6870 // no such map, found wad
6873 P
[1] := ExpandFileName(pw
);
6874 P
[2] := g_Game_GetFirstMap(P
[1]);
6875 s
:= P
[1] + ':\' + P
[2];
6876 if g_Map_Exist(s
) then
6878 gExitByTrigger
:= False;
6881 // already in game, finish current map
6883 gExit
:= EXIT_ENDLEVELCUSTOM
6887 // intermission, so change map immediately
6894 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6896 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6901 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6907 s
:= addWadExtension(P
[1]);
6908 found
:= e_FindResource(AllMapDirs
, s
);
6912 P
[2] := UpperCase(P
[2]);
6913 s
:= P
[1] + ':\' + P
[2];
6914 if g_Map_Exist(s
) then
6916 gExitByTrigger
:= False;
6920 gExit
:= EXIT_ENDLEVELCUSTOM
6929 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6934 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6940 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6944 else if cmd
= 'nextmap' then
6946 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6948 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6953 if Length(P
) = 1 then
6955 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6957 g_Console_Add(cmd
+ ' <MAP>');
6958 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6963 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6969 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6971 if Length(P
) < 3 then
6973 // first param is map or wad
6974 s
:= UpperCase(P
[1]);
6975 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6978 gExitByTrigger
:= False;
6984 // no such map, found wad
6985 pw
:= addWadExtension(P
[1]);
6986 found
:= e_FindResource(MapDirs
, pw
);
6988 found
:= e_FindResource(WadDirs
, pw
);
6990 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6993 // map not specified, select first map
6995 P
[2] := g_Game_GetFirstMap(P
[1]);
6996 s
:= P
[1] + ':\' + P
[2];
6997 if g_Map_Exist(s
) then
6999 gExitByTrigger
:= False;
7006 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7008 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7013 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7019 // specified two params wad + map
7020 pw
:= addWadExtension(P
[1]);
7021 found
:= e_FindResource(MapDirs
, pw
);
7023 found
:= e_FindResource(MapDirs
, pw
);
7027 P
[2] := UpperCase(P
[2]);
7028 s
:= P
[1] + ':\' + P
[2];
7029 if g_Map_Exist(s
) then
7031 gExitByTrigger
:= False;
7037 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7042 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7048 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7053 if gNextMap
= '' then
7054 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7056 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7060 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7064 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7068 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7070 gExitByTrigger
:= False;
7071 // next map not specified, try to find trigger EXIT
7072 if (gNextMap
= '') and (gTriggers
<> nil) then
7074 for a
:= 0 to High(gTriggers
) do
7076 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7078 gExitByTrigger
:= True;
7079 //gNextMap := gTriggers[a].Data.MapName;
7080 gNextMap
:= gTriggers
[a
].tgcMap
;
7085 if gNextMap
= '' then
7086 gNextMap
:= g_Game_GetNextMap();
7087 if not isWadPath(gNextMap
) then
7088 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7091 if g_Map_Exist(s
) then
7092 gExit
:= EXIT_ENDLEVELCUSTOM
7094 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7098 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7102 else if (cmd
= 'event') then
7104 if (Length(P
) <= 1) then
7106 for a
:= 0 to High(gEvents
) do
7107 if gEvents
[a
].Command
= '' then
7108 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7110 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7113 if (Length(P
) = 2) then
7115 for a
:= 0 to High(gEvents
) do
7116 if gEvents
[a
].Name
= P
[1] then
7117 if gEvents
[a
].Command
= '' then
7118 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7120 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7123 for a
:= 0 to High(gEvents
) do
7124 if gEvents
[a
].Name
= P
[1] then
7126 gEvents
[a
].Command
:= '';
7127 for b
:= 2 to High(P
) do
7128 if Pos(' ', P
[b
]) = 0 then
7129 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7131 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7132 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7136 else if cmd
= 'suicide' then
7140 if g_Game_IsClient
then
7141 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7144 if gPlayer1
<> nil then
7145 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7146 if gPlayer2
<> nil then
7147 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7151 else if cmd
= 'screenshot' then
7155 else if cmd
= 'weapon' then
7157 if Length(p
) = 2 then
7159 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7160 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7161 gSelectWeapon
[0, a
] := True
7164 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7166 if Length(p
) = 2 then
7168 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7169 b
:= ord(cmd
[2]) - ord('1');
7170 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7171 gSelectWeapon
[b
, a
] := True
7174 // Êîìàíäû Ñâîåé èãðû:
7175 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7177 if cmd
= 'bot_addred' then
7179 if Length(P
) > 1 then
7180 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7182 g_Bot_Add(TEAM_RED
, 2);
7184 else if cmd
= 'bot_addblue' then
7186 if Length(P
) > 1 then
7187 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7189 g_Bot_Add(TEAM_BLUE
, 2);
7191 else if cmd
= 'spectate' then
7197 else if cmd
= 'say' then
7199 if g_Game_IsServer
and g_Game_IsNet
then
7201 if Length(P
) > 1 then
7204 for a
:= 1 to High(P
) do
7205 chstr
:= chstr
+ P
[a
] + ' ';
7207 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7209 if Length(chstr
) < 1 then
7211 g_Console_Add('say <text>');
7215 chstr
:= b_Text_Format(chstr
);
7216 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7218 else g_Console_Add('say <text>');
7220 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7222 else if cmd
= 'tell' then
7224 if g_Game_IsServer
and g_Game_IsNet
then
7226 if (Length(P
) > 2) and (P
[1] <> '') then
7229 for a
:= 2 to High(P
) do
7230 chstr
:= chstr
+ P
[a
] + ' ';
7232 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7234 if Length(chstr
) < 1 then
7236 g_Console_Add('tell <playername> <text>');
7240 pl
:= g_Net_Client_ByName(P
[1]);
7242 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7244 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7246 else g_Console_Add('tell <playername> <text>');
7248 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7250 else if cmd
= 'centerprint' then
7252 if (Length(P
) > 2) and (P
[1] <> '') then
7255 for a
:= 2 to High(P
) do
7256 chstr
:= chstr
+ P
[a
] + ' ';
7258 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7260 if Length(chstr
) < 1 then
7262 g_Console_Add('centerprint <timeout> <text>');
7266 a
:= StrToIntDef(P
[1], 100);
7267 chstr
:= b_Text_Format(chstr
);
7268 g_Game_Message(chstr
, a
);
7269 if g_Game_IsNet
and g_Game_IsServer
then
7270 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7272 else g_Console_Add('centerprint <timeout> <text>');
7274 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7276 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7278 // Äîïîëíèòåëüíîå âðåìÿ:
7279 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7281 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7282 [gGameSettings
.TimeLimit
div 3600,
7283 (gGameSettings
.TimeLimit
div 60) mod 60,
7284 gGameSettings
.TimeLimit
mod 60]));
7285 if g_Game_IsNet
then MH_SEND_GameSettings
;
7287 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7289 if (Length(P
) <= 1) then
7290 g_Console_Add('rcon_password <password>')
7292 MC_SEND_RCONPassword(P
[1]);
7294 else if cmd
= 'rcon' then
7296 if g_Game_IsClient
then
7298 if Length(P
) > 1 then
7301 for a
:= 1 to High(P
) do
7302 chstr
:= chstr
+ P
[a
] + ' ';
7304 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7306 if Length(chstr
) < 1 then
7308 g_Console_Add('rcon <command>');
7312 MC_SEND_RCONCommand(chstr
);
7314 else g_Console_Add('rcon <command>');
7317 else if cmd
= 'ready' then
7319 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7320 gLMSRespawnTime
:= gTime
+ 100;
7322 else if (cmd
= 'callvote') and g_Game_IsNet
then
7324 if Length(P
) > 1 then
7327 for a
:= 1 to High(P
) do begin
7328 if a
> 1 then chstr
:= chstr
+ ' ';
7329 chstr
:= chstr
+ P
[a
];
7332 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7334 if Length(chstr
) < 1 then
7336 g_Console_Add('callvote <command>');
7340 if g_Game_IsClient
then
7341 MC_SEND_Vote(True, chstr
)
7343 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7344 g_Console_Process('vote', True);
7347 g_Console_Add('callvote <command>');
7349 else if (cmd
= 'vote') and g_Game_IsNet
then
7351 if g_Game_IsClient
then
7353 else if gVoteInProgress
then
7355 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7356 a
:= Floor((NetClientCount
+1)/2.0) + 1
7358 a
:= Floor(NetClientCount
/2.0) + 1;
7363 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7364 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7370 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7371 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7379 procedure g_TakeScreenShot(Filename
: string = '');
7380 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7382 if e_NoGraphics
then Exit
;
7384 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7386 if Filename
= '' then
7389 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7390 Filename
:= 'screenshot-' + date
;
7393 name
:= e_CatPath(dir
, Filename
+ '.png');
7394 s
:= createDiskFile(name
);
7396 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7398 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7400 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7405 g_Console_Add('oh shit, i can''t create screenshot!')
7409 procedure g_Game_InGameMenu(Show
: Boolean);
7411 if (g_ActiveWindow
= nil) and Show
then
7413 if gGameSettings
.GameType
= GT_SINGLE
then
7414 g_GUI_ShowWindow('GameSingleMenu')
7417 if g_Game_IsClient
then
7418 g_GUI_ShowWindow('GameClientMenu')
7420 if g_Game_IsNet
then
7421 g_GUI_ShowWindow('GameServerMenu')
7423 g_GUI_ShowWindow('GameCustomMenu');
7425 g_Sound_PlayEx('MENU_OPEN');
7427 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7428 if (not g_Game_IsNet
) then
7432 if (g_ActiveWindow
<> nil) and (not Show
) then
7434 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7435 if (not g_Game_IsNet
) then
7436 g_Game_Pause(False);
7440 procedure g_Game_Pause (Enable
: Boolean);
7444 if not gGameOn
then exit
;
7446 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7449 gPauseMain
:= Enable
;
7451 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7454 procedure g_Game_HolmesPause (Enable
: Boolean);
7458 if not gGameOn
then exit
;
7459 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7462 gPauseHolmes
:= Enable
;
7464 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7467 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7472 if gTriggers
<> nil then
7473 for i
:= 0 to High(gTriggers
) do
7474 with gTriggers
[i
] do
7475 if (TriggerType
= TRIGGER_SOUND
) and
7477 Sound
.IsPlaying() then
7479 Sound
.Pause(Enable
);
7483 if gPlayers
<> nil then
7484 for i
:= 0 to High(gPlayers
) do
7485 if gPlayers
[i
] <> nil then
7486 gPlayers
[i
].PauseSounds(Enable
);
7489 if gMusic
<> nil then
7490 gMusic
.Pause(Enable
);
7493 procedure g_Game_StopAllSounds(all
: Boolean);
7497 if gTriggers
<> nil then
7498 for i
:= 0 to High(gTriggers
) do
7499 with gTriggers
[i
] do
7500 if (TriggerType
= TRIGGER_SOUND
) and
7504 if gMusic
<> nil then
7511 procedure g_Game_UpdateTriggerSounds
;
7514 if gTriggers
<> nil then
7515 for i
:= 0 to High(gTriggers
) do
7516 with gTriggers
[i
] do
7517 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7518 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7521 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7524 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7529 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7534 if gSpectMode
<> SPECT_PLAYERS
then
7536 if gSpectPID1
= UID
then
7541 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7548 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7553 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7558 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7563 if gSpectMode
<> SPECT_PLAYERS
then
7565 Pl
:= g_Player_Get(gSpectPID1
);
7566 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7571 if gSpectViewTwo
then
7573 Pl
:= g_Player_Get(gSpectPID2
);
7574 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7582 procedure g_Game_Message(Msg
: string; Time
: Word);
7584 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7585 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7586 MessageTime
:= Time
;
7589 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7591 punct
: Array[0..13] of String =
7592 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7598 function IsPunctuation(S
: String): Boolean;
7603 if Length(S
) <> 1 then
7605 for i
:= Low(punct
) to High(punct
) do
7606 if S
= punct
[i
] then
7612 function FilterPunctuation(S
: String): String;
7616 for i
:= Low(punct
) to High(punct
) do
7617 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7623 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7625 // remove player name
7626 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7627 // for FullWord check
7628 Text := toLowerCase1251(' ' + Text + ' ');
7629 fpText
:= FilterPunctuation(Text);
7631 for i
:= 0 to Length(gChatSounds
) - 1 do
7634 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7636 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7637 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7639 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7645 gChatSounds
[i
].Sound
.Play();
7651 g_Sound_PlayEx('SOUND_GAME_RADIO');
7654 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7663 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7667 if goodsnd
[a
].IsPlaying() then
7670 goodsnd
[Random(4)].Play();
7673 procedure g_Game_Announce_KillCombo(Param
: Integer);
7680 UID
:= Param
and $FFFF;
7685 Pl
:= g_Player_Get(UID
);
7694 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7698 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7702 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7706 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7714 if not g_Game_IsWatchedPlayer(UID
) then
7717 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7721 if killsnd
[n
].IsPlaying() then
7726 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7735 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7739 if hahasnd
[a
].IsPlaying() then
7742 hahasnd
[Random(3)].Play();
7745 procedure g_Game_StartVote(Command
, Initiator
: string);
7749 if not gVotesEnabled
then Exit
;
7750 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7751 if gVoteInProgress
or gVotePassed
then
7753 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7754 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7757 gVoteInProgress
:= True;
7758 gVotePassed
:= False;
7759 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7762 gVoteCommand
:= Command
;
7764 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7765 Need
:= Floor((NetClientCount
+1)/2.0)+1
7767 Need
:= Floor(NetClientCount
/2.0)+1;
7768 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7769 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7772 procedure g_Game_CheckVote
;
7776 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7777 if not gVoteInProgress
then Exit
;
7779 if (gTime
>= gVoteTimer
) then
7781 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7782 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7784 Need
:= Floor(NetClientCount
/2.0) + 1;
7785 if gVoteCount
>= Need
then
7787 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7788 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7789 gVotePassed
:= True;
7790 gVoteCmdTimer
:= gTime
+ 5000;
7794 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7795 MH_SEND_VoteEvent(NET_VE_FAILED
);
7797 if NetClients
<> nil then
7798 for I
:= Low(NetClients
) to High(NetClients
) do
7799 if NetClients
[i
].Used
then
7800 NetClients
[i
].Voted
:= False;
7801 gVoteInProgress
:= False;
7807 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7808 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7810 Need
:= Floor(NetClientCount
/2.0) + 1;
7811 if gVoteCount
>= Need
then
7813 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7814 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7815 gVoteInProgress
:= False;
7816 gVotePassed
:= True;
7817 gVoteCmdTimer
:= gTime
+ 5000;
7820 if NetClients
<> nil then
7821 for I
:= Low(NetClients
) to High(NetClients
) do
7822 if NetClients
[i
].Used
then
7823 NetClients
[i
].Voted
:= False;
7828 procedure g_Game_LoadMapList(FileName
: string);
7836 if not FileExists(FileName
) then Exit
;
7838 AssignFile(ListFile
, FileName
);
7840 while not EOF(ListFile
) do
7842 ReadLn(ListFile
, s
);
7845 if s
= '' then Continue
;
7847 SetLength(MapList
, Length(MapList
)+1);
7848 MapList
[High(MapList
)] := s
;
7850 CloseFile(ListFile
);
7853 procedure g_Game_SetDebugMode();
7856 // ×èòû (äàæå â ñâîåé èãðå):
7860 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7864 if Length(LoadingStat
.Msgs
) = 0 then
7870 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7871 if NextMsg
= Length(Msgs
) then
7873 for i
:= 0 to High(Msgs
)-1 do
7874 Msgs
[i
] := Msgs
[i
+1];
7882 Msgs
[NextMsg
-1] := Text;
7886 PBarWasHere
:= false;
7889 g_ActiveWindow
:= nil;
7891 ProcessLoading(true);
7894 procedure g_Game_StepLoading(Value
: Integer = -1);
7905 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7913 procedure g_Game_ClearLoading();
7922 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7923 if len
< 1 then len
:= 1;
7924 SetLength(Msgs
, len
);
7925 for len
:= Low(Msgs
) to High(Msgs
) do
7928 PBarWasHere
:= false;
7932 procedure Parse_Params(var pars
: TParamStrValues
);
7939 while i
<= ParamCount
do
7942 if (s
[1] = '-') and (Length(s
) > 1) then
7944 if (s
[2] = '-') and (Length(s
) > 2) then
7945 begin // Îäèíî÷íûé ïàðàìåòð
7946 SetLength(pars
, Length(pars
) + 1);
7947 with pars
[High(pars
)] do
7949 Name
:= LowerCase(s
);
7954 if (i
< ParamCount
) then
7955 begin // Ïàðàìåòð ñî çíà÷åíèåì
7957 SetLength(pars
, Length(pars
) + 1);
7958 with pars
[High(pars
)] do
7960 Name
:= LowerCase(s
);
7961 Value
:= LowerCase(ParamStr(i
));
7970 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7975 for i
:= 0 to High(pars
) do
7976 if pars
[i
].Name
= aName
then
7978 Result
:= pars
[i
].Value
;
7983 procedure g_Game_Process_Params();
7985 pars
: TParamStrValues
;
7988 LimT
, LimS
: Integer;
7999 s
:= Find_Param_Value(pars
, '--debug');
8002 g_Game_SetDebugMode();
8003 s
:= Find_Param_Value(pars
, '--netdump');
8008 // Connect when game loads
8009 ip
:= Find_Param_Value(pars
, '-connect');
8013 s
:= Find_Param_Value(pars
, '-port');
8014 if (s
= '') or not TryStrToInt(s
, Port
) then
8017 s
:= Find_Param_Value(pars
, '-pw');
8019 g_Game_StartClient(ip
, Port
, s
);
8023 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8026 gDefaultMegawadStart
:= s
;
8029 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8030 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8032 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8035 // Start map when game loads:
8036 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8037 if isWadPath(map
) then
8040 s
:= Find_Param_Value(pars
, '-gm');
8041 GMode
:= g_Game_TextToMode(s
);
8042 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8043 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8046 s
:= Find_Param_Value(pars
, '-limt');
8047 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8053 s
:= Find_Param_Value(pars
, '-lims');
8054 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8060 s
:= Find_Param_Value(pars
, '-lives');
8061 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8067 s
:= Find_Param_Value(pars
, '-opt');
8069 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
8071 Opt
:= StrToIntDef(s
, 0);
8073 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
8076 s
:= Find_Param_Value(pars
, '--close');
8080 // Override map to test:
8081 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8084 if e_IsValidResourceName(s
) then
8085 e_FindResource(AllMapDirs
, s
);
8086 gTestMap
:= ExpandFileName(s
);
8089 // Delete test map after play:
8090 s
:= Find_Param_Value(pars
, '--testdelete');
8093 //gMapToDelete := MapsDir + map;
8094 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8098 // Delete temporary WAD after play:
8099 s
:= Find_Param_Value(pars
, '--tempdelete');
8100 if (s
<> '') and (gTestMap
<> '') then
8102 gMapToDelete
:= gTestMap
;
8103 gTempDelete
:= True;
8106 // Number of players:
8107 s
:= Find_Param_Value(pars
, '-pl');
8109 n
:= DEFAULT_PLAYERS
8111 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8114 s
:= Find_Param_Value(pars
, '-port');
8115 if (s
= '') or not TryStrToInt(s
, Port
) then
8116 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8118 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8121 // Execute script when game loads:
8122 s
:= Find_Param_Value(pars
, '-exec');
8125 // if not isWadPath(s) then
8126 // s := GameDir + '/' + s;
8131 if IOResult
<> 0 then
8133 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8134 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8138 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8139 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8144 if IOResult
<> 0 then
8146 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8147 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8151 if Pos('#', s
) <> 1 then // script comment
8152 g_Console_Process(s
, True);
8163 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8164 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8165 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8166 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8168 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8169 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8170 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8171 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8173 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8174 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8176 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8177 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8179 {$IFDEF ENABLE_HOLMES}
8180 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8183 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8185 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8186 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8188 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8189 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8191 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8192 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8194 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8195 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');