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
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures
: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Draw();
89 procedure g_Game_Quit();
90 procedure g_Game_SetupScreenSize();
91 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
92 function g_Game_ModeToText(Mode
: Byte): string;
93 function g_Game_TextToMode(Mode
: string): Byte;
94 procedure g_Game_ExecuteEvent(Name
: String);
95 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
96 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
97 procedure g_Game_RemovePlayer();
98 procedure g_Game_Spectate();
99 procedure g_Game_SpectateCenterView();
100 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
101 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
102 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
103 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
104 procedure g_Game_Restart();
105 procedure g_Game_RestartLevel();
106 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
107 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
108 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
109 procedure g_Game_ChangeMap(const MapPath
: String);
110 procedure g_Game_ExitLevel(const Map
: AnsiString);
111 function g_Game_GetFirstMap(WAD
: String): String;
112 function g_Game_GetNextMap(): String;
113 procedure g_Game_NextLevel();
114 procedure g_Game_Pause(Enable
: Boolean);
115 procedure g_Game_HolmesPause(Enable
: Boolean);
116 procedure g_Game_InGameMenu(Show
: Boolean);
117 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
118 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
119 procedure g_Game_Message(Msg
: String; Time
: Word);
120 procedure g_Game_LoadMapList(FileName
: String);
121 procedure g_Game_PauseAllSounds(Enable
: Boolean);
122 procedure g_Game_StopAllSounds(all
: Boolean);
123 procedure g_Game_UpdateTriggerSounds();
124 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
125 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
126 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
127 procedure g_Game_Announce_KillCombo(Param
: Integer);
128 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
129 procedure g_Game_StartVote(Command
, Initiator
: string);
130 procedure g_Game_CheckVote
;
131 procedure g_TakeScreenShot(Filename
: string = '');
132 procedure g_FatalError(Text: String);
133 procedure g_SimpleError(Text: String);
134 function g_Game_IsTestMap(): Boolean;
135 procedure g_Game_DeleteTestMap();
136 procedure GameCVars(P
: SSArray
);
137 procedure PlayerSettingsCVars(P
: SSArray
);
138 procedure SystemCommands(P
: SSArray
);
139 procedure GameCommands(P
: SSArray
);
140 procedure GameCheats(P
: SSArray
);
141 procedure DebugCommands(P
: SSArray
);
142 procedure g_Game_Process_Params
;
143 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
144 procedure g_Game_StepLoading(Value
: Integer = -1);
145 procedure g_Game_ClearLoading();
146 procedure g_Game_SetDebugMode();
147 procedure DrawLoadingStat();
148 procedure DrawMenuBackground(tex
: AnsiString);
150 { procedure SetWinPause(Enable: Boolean); }
155 LOADING_SHOW_STEP
= 100;
156 LOADING_INTERLINE
= 20;
171 MESSAGE_DIKEY
= WM_USER
+ 1;
176 EXIT_ENDLEVELSINGLE
= 4;
177 EXIT_ENDLEVELCUSTOM
= 5;
179 GAME_OPTION_RESERVED
= 1;
180 GAME_OPTION_TEAMDAMAGE
= 2;
181 GAME_OPTION_ALLOWEXIT
= 4;
182 GAME_OPTION_WEAPONSTAY
= 8;
183 GAME_OPTION_MONSTERS
= 16;
184 GAME_OPTION_BOTVSPLAYER
= 32;
185 GAME_OPTION_BOTVSMONSTER
= 64;
186 GAME_OPTION_DMKEYS
= 128;
191 STATE_INTERCUSTOM
= 3;
192 STATE_INTERSINGLE
= 4;
198 LMS_RESPAWN_NONE
= 0;
199 LMS_RESPAWN_WARMUP
= 1;
200 LMS_RESPAWN_FINAL
= 2;
217 CONFIG_FILENAME
= 'Doom2DF.cfg';
219 TEST_MAP_NAME
= '$$$_TEST_$$$';
221 STD_PLAYER_MODEL
= 'Doomer';
229 STATFILE_VERSION
= $03;
233 gGameSettings
: TGameSettings
;
234 gPlayer1Settings
: TPlayerSettings
;
235 gPlayer2Settings
: TPlayerSettings
;
237 gPlayerScreenSize
: TDFPoint
;
238 gPlayer1ScreenCoord
: TDFPoint
;
239 gPlayer2ScreenCoord
: TDFPoint
;
240 gPlayer1
: TPlayer
= nil;
241 gPlayer2
: TPlayer
= nil;
242 gPlayerDrawn
: TPlayer
= nil;
244 gLerpFactor
: Single = 1.0;
245 gSwitchGameMode
: Byte = GM_DM
;
246 gHearPoint1
, gHearPoint2
: THearPoint
;
247 gSoundEffectsDF
: Boolean = False;
248 gSoundTriggerTime
: Word = 0;
249 gAnnouncer
: Integer = ANNOUNCE_NONE
;
250 goodsnd
: array[0..3] of TPlayableSound
;
251 killsnd
: array[0..3] of TPlayableSound
;
252 hahasnd
: array[0..2] of TPlayableSound
;
253 sound_get_flag
: array[0..1] of TPlayableSound
;
254 sound_lost_flag
: array[0..1] of TPlayableSound
;
255 sound_ret_flag
: array[0..1] of TPlayableSound
;
256 sound_cap_flag
: array[0..1] of TPlayableSound
;
257 gBodyKillEvent
: Integer = -1;
258 gDefInterTime
: ShortInt = -1;
259 gInterEndTime
: LongWord = 0;
260 gInterTime
: LongWord = 0;
261 gServInterTime
: Byte = 0;
262 gGameStartTime
: LongWord = 0;
263 gTotalMonsters
: Integer = 0;
264 gPauseMain
: Boolean = false;
265 gPauseHolmes
: Boolean = false;
266 gShowTime
: Boolean = False;
267 gShowFPS
: Boolean = False;
268 gShowGoals
: Boolean = True;
269 gShowStat
: Boolean = True;
270 gShowPIDs
: Boolean = False;
271 gShowKillMsg
: Boolean = True;
272 gShowLives
: Boolean = True;
273 gShowPing
: Boolean = False;
274 gShowMap
: Boolean = False;
276 gState
: Byte = STATE_NONE
;
278 sWidth
, sHeight
: Word;
279 gSpectMode
: Byte = SPECT_NONE
;
280 gSpectHUD
: Boolean = True;
281 gSpectKeyPress
: Boolean = False;
282 gSpectX
: Integer = 0;
283 gSpectY
: Integer = 0;
284 gSpectStep
: Byte = 8;
285 gSpectViewTwo
: Boolean = False;
286 gSpectPID1
: Integer = -1;
287 gSpectPID2
: Integer = -1;
288 gSpectAuto
: Boolean = False;
289 gSpectAutoNext
: LongWord;
290 gSpectAutoStepX
: Integer;
291 gSpectAutoStepY
: Integer;
292 gMusic
: TMusic
= nil;
293 gLoadGameMode
: Boolean;
294 gCheats
: Boolean = False;
295 gMapOnce
: Boolean = False;
296 gMapToDelete
: String;
297 gTempDelete
: Boolean = False;
298 gLastMap
: Boolean = False;
301 gResolutionChange
: Boolean = False;
302 gRC_Width
, gRC_Height
: Integer;
303 gRC_FullScreen
, gRC_Maximized
: Boolean;
304 gLanguageChange
: Boolean = False;
305 gDebugMode
: Boolean = False;
306 g_debug_Sounds
: Boolean = False;
307 g_debug_Frames
: Boolean = False;
308 g_debug_WinMsgs
: Boolean = False;
309 g_debug_MonsterOff
: Boolean = False;
310 g_debug_BotAIOff
: Byte = 0;
311 g_debug_HealthBar
: Boolean = False;
312 g_Debug_Player
: Boolean = False;
313 gCoopMonstersKilled
: Word = 0;
314 gCoopSecretsFound
: Word = 0;
315 gCoopTotalMonstersKilled
: Word = 0;
316 gCoopTotalSecretsFound
: Word = 0;
317 gCoopTotalMonsters
: Word = 0;
318 gCoopTotalSecrets
: Word = 0;
319 gStatsOff
: Boolean = False;
320 gStatsPressed
: Boolean = False;
321 gExitByTrigger
: Boolean = False;
322 gNextMap
: String = '';
323 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
324 gLMSRespawnTime
: Cardinal = 0;
325 gLMSSoftSpawn
: Boolean = False;
326 gMissionFailed
: Boolean = False;
327 gVoteInProgress
: Boolean = False;
328 gVotePassed
: Boolean = False;
329 gVoteCommand
: string = '';
330 gVoteTimer
: Cardinal = 0;
331 gVoteCmdTimer
: Cardinal = 0;
332 gVoteCount
: Integer = 0;
333 gVoteTimeout
: Cardinal = 30;
334 gVoted
: Boolean = False;
335 gVotesEnabled
: Boolean = True;
336 gEvents
: Array of TGameEvent
;
337 gDelayedEvents
: Array of TDelayedEvent
;
338 gUseChatSounds
: Boolean = True;
339 gChatSounds
: Array of TChatSound
;
340 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
341 gInterReadyCount
: Integer = 0;
343 g_dbg_ignore_bounds
: Boolean = false;
344 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
345 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
347 // move button values:
348 // bits 0-1: l/r state:
349 // 0: neither left, nor right pressed
352 // bits 4-5: l/r state when strafe was pressed
353 P1MoveButton
: Byte = 0;
354 P2MoveButton
: Byte = 0;
356 g_profile_frame_update
: Boolean = false;
357 g_profile_frame_draw
: Boolean = false;
358 g_profile_collision
: Boolean = false;
359 g_profile_los
: Boolean = false;
360 g_profile_history_size
: Integer = 1000;
362 g_rlayer_back
: Boolean = true;
363 g_rlayer_step
: Boolean = true;
364 g_rlayer_wall
: Boolean = true;
365 g_rlayer_door
: Boolean = true;
366 g_rlayer_acid1
: Boolean = true;
367 g_rlayer_acid2
: Boolean = true;
368 g_rlayer_water
: Boolean = true;
369 g_rlayer_fore
: Boolean = true;
372 procedure g_ResetDynlights ();
373 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
374 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
376 function conIsCheatsEnabled (): Boolean; inline;
377 function gPause (): Boolean; inline;
383 {$INCLUDE ../nogl/noGLuses.inc}
384 {$IFDEF ENABLE_HOLMES}
387 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
388 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
389 g_playermodel
, g_gfx
, g_options
, Math
,
390 g_triggers
, g_monsters
, e_sound
, CONFIG
,
391 g_language
, g_net
, g_main
, g_phys
,
392 ENet
, e_msg
, g_netmsg
, g_netmaster
,
393 sfs
, wadreader
, g_system
;
397 hasPBarGfx
: Boolean = false;
400 // ////////////////////////////////////////////////////////////////////////// //
401 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
404 // ////////////////////////////////////////////////////////////////////////// //
405 function conIsCheatsEnabled (): Boolean; inline;
408 if g_Game_IsNet
then exit
;
409 if not gDebugMode
then
411 //if not gCheats then exit;
412 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
413 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
419 // ////////////////////////////////////////////////////////////////////////// //
421 profileFrameDraw
: TProfiler
= nil;
424 // ////////////////////////////////////////////////////////////////////////// //
427 x
, y
, radius
: Integer;
430 exploRadius
: Integer;
434 g_dynLights
: array of TDynLight
= nil;
435 g_dynLightCount
: Integer = 0;
436 g_playerLight
: Boolean = false;
438 procedure g_ResetDynlights ();
442 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
444 for idx
:= 0 to g_dynLightCount
-1 do
446 if g_dynLights
[idx
].exploCount
= -666 then
453 Inc(g_dynLights
[idx
].exploCount
);
454 if (g_dynLights
[idx
].exploCount
< 10) then
456 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
457 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
458 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
459 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
464 g_dynLightCount
:= lnum
;
467 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
469 if not gwin_has_stencil
then exit
;
470 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
471 g_dynLights
[g_dynLightCount
].x
:= x
;
472 g_dynLights
[g_dynLightCount
].y
:= y
;
473 g_dynLights
[g_dynLightCount
].radius
:= radius
;
474 g_dynLights
[g_dynLightCount
].r
:= r
;
475 g_dynLights
[g_dynLightCount
].g
:= g
;
476 g_dynLights
[g_dynLightCount
].b
:= b
;
477 g_dynLights
[g_dynLightCount
].a
:= a
;
478 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
479 Inc(g_dynLightCount
);
482 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
484 if not gwin_has_stencil
then exit
;
485 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
486 g_dynLights
[g_dynLightCount
].x
:= x
;
487 g_dynLights
[g_dynLightCount
].y
:= y
;
488 g_dynLights
[g_dynLightCount
].radius
:= 0;
489 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
490 g_dynLights
[g_dynLightCount
].r
:= r
;
491 g_dynLights
[g_dynLightCount
].g
:= g
;
492 g_dynLights
[g_dynLightCount
].b
:= b
;
493 g_dynLights
[g_dynLightCount
].a
:= 0;
494 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
495 Inc(g_dynLightCount
);
499 // ////////////////////////////////////////////////////////////////////////// //
500 function calcProfilesHeight (prof
: TProfiler
): Integer;
503 if (prof
= nil) then exit
;
504 if (length(prof
.bars
) = 0) then exit
;
505 result
:= length(prof
.bars
)*(16+2);
509 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
516 if (prof
= nil) then exit
;
518 if (length(prof
.bars
) = 0) then exit
;
520 hgt
:= calcProfilesHeight(prof
);
521 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
522 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
524 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
525 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
526 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
529 for ii
:= 0 to High(prof
.bars
) do
531 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);
538 // ////////////////////////////////////////////////////////////////////////// //
540 TEndCustomGameStat
= record
541 PlayerStat
: TPlayerStatArray
;
545 Map
, MapName
: String;
548 TEndSingleGameStat
= record
549 PlayerStat
: Array [0..1] of record
555 TotalSecrets
: Integer;
558 TLoadingStat
= record
562 Msgs
: Array of String;
564 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
567 TParamStrValue
= record
572 TParamStrValues
= Array of TParamStrValue
;
575 INTER_ACTION_TEXT
= 1;
576 INTER_ACTION_PIC
= 2;
577 INTER_ACTION_MUSIC
= 3;
581 FPSCounter
, UPSCounter
: Word;
582 FPSTime
, UPSTime
: LongWord;
583 DataLoaded
: Boolean = False;
584 IsDrawStat
: Boolean = False;
585 CustomStat
: TEndCustomGameStat
;
586 SingleStat
: TEndSingleGameStat
;
587 LoadingStat
: TLoadingStat
;
588 EndingGameCounter
: Byte = 0;
591 MessageLineLength
: Integer = 80;
592 MapList
: SSArray
= nil;
593 MapIndex
: Integer = -1;
594 InterReadyTime
: Integer = -1;
595 StatShotDone
: Boolean = False;
596 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
597 StatDate
: string = '';
603 text: Array of ShortString;
604 anim
: Array of ShortString;
605 pic
: Array of ShortString;
606 mus
: Array of ShortString;
608 triggers
: Array of record
610 actions
: Array of record
611 action
, p1
, p2
: Integer;
614 cur_trigger
: Integer;
627 function Compare(a
, b
: TPlayerStat
): Integer;
629 if a
.Spectator
then Result
:= 1
630 else if b
.Spectator
then Result
:= -1
631 else if a
.Frags
< b
.Frags
then Result
:= 1
632 else if a
.Frags
> b
.Frags
then Result
:= -1
633 else if a
.Deaths
< b
.Deaths
then Result
:= -1
634 else if a
.Deaths
> b
.Deaths
then Result
:= 1
635 else if a
.Kills
< b
.Kills
then Result
:= -1
639 procedure SortGameStat(var stat
: TPlayerStatArray
);
644 if stat
= nil then Exit
;
646 for I
:= High(stat
) downto Low(stat
) do
647 for J
:= Low(stat
) to High(stat
) - 1 do
648 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
651 stat
[J
] := stat
[J
+ 1];
656 // saves a shitty CSV containing the game stats passed to it
657 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
660 dir
, fname
, map
, mode
, etime
: String;
664 dir
:= e_GetWriteableDir(StatsDirs
);
665 // stats are placed in stats/yy/mm/dd/*.csv
666 fname
:= e_CatPath(dir
, Path
);
667 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
668 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
669 AssignFile(s
, fname
);
672 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
673 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
674 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
675 mode
:= g_Game_ModeToText(Stat
.GameMode
);
676 etime
:= Format('%d:%.2d:%.2d', [
677 Stat
.GameTime
div 1000 div 3600,
678 (Stat
.GameTime
div 1000 div 60) mod 60,
679 Stat
.GameTime
div 1000 mod 60
681 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
682 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
688 gGameSettings
.TimeLimit
,
689 gGameSettings
.GoalLimit
,
690 gGameSettings
.Options
,
692 Length(Stat
.PlayerStat
)
694 // line 2: game specific shit
695 // if it's a team game: red score, blue score
696 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
698 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
700 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
701 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
703 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
704 // lines 3-...: team, player name, frags, deaths
705 WriteLn(s
, 'team,name,frags,deaths');
706 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
707 with Stat
.PlayerStat
[I
] do
708 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
710 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
713 g_Console_Add('could not create gamestats file "' + fname
+ '"');
718 function g_Game_ModeToText(Mode
: Byte): string;
722 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
723 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
724 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
725 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
726 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
730 function g_Game_TextToMode(Mode
: string): Byte;
733 Mode
:= UpperCase(Mode
);
734 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
739 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
744 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
749 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
754 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
761 function g_Game_IsNet(): Boolean;
763 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
766 function g_Game_IsServer(): Boolean;
768 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
771 function g_Game_IsClient(): Boolean;
773 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
776 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
783 Result
.name
:= ExtractFileName(WAD
);
784 Result
.description
:= '';
787 w
:= TWADFile
.Create();
790 if not w
.GetResource('INTERSCRIPT', p
, len
) then
796 cfg
:= TConfig
.CreateMem(p
, len
);
797 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
798 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
799 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
800 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
806 procedure g_Game_FreeWAD();
810 for a
:= 0 to High(MegaWAD
.res
.pic
) do
811 if MegaWAD
.res
.pic
[a
] <> '' then
812 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
814 for a
:= 0 to High(MegaWAD
.res
.mus
) do
815 if MegaWAD
.res
.mus
[a
] <> '' then
816 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
818 MegaWAD
.res
.pic
:= nil;
819 MegaWAD
.res
.text := nil;
820 MegaWAD
.res
.anim
:= nil;
821 MegaWAD
.res
.mus
:= nil;
822 MegaWAD
.triggers
:= nil;
824 g_Texture_Delete('TEXTURE_endpic');
825 g_Sound_Delete('MUSIC_endmus');
827 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
828 gGameSettings
.WAD
:= '';
831 procedure g_Game_LoadWAD(WAD
: string);
840 gGameSettings
.WAD
:= WAD
;
841 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
844 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
846 w
:= TWADFile
.Create();
849 if not w
.GetResource('INTERSCRIPT', p
, len
) then
855 cfg
:= TConfig
.CreateMem(p
, len
);
860 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
861 if s = '' then Break;
864 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
865 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
867 g_Texture_CreateWADEx(s, s);
873 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
874 if s = '' then Break;
877 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
878 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
880 g_Music_CreateWADEx(s, s);
883 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
884 if MegaWAD
.endpic
<> '' then
886 TEXTUREFILTER
:= GL_LINEAR
;
887 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
888 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
889 TEXTUREFILTER
:= GL_NEAREST
;
891 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
892 if MegaWAD
.endmus
<> '' then
894 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
895 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
903 {procedure start_trigger(t: string);
907 function next_trigger(): Boolean;
911 procedure DisableCheats();
917 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
918 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
919 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
920 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
922 {$IF DEFINED(D2F_DEBUG)}
923 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
924 gAimLine
:= g_dbg_aimline_on
;
928 procedure g_Game_ExecuteEvent(Name
: String);
934 if gEvents
= nil then
936 for a
:= 0 to High(gEvents
) do
937 if gEvents
[a
].Name
= Name
then
939 if gEvents
[a
].Command
<> '' then
940 g_Console_Process(gEvents
[a
].Command
, True);
945 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
950 if gDelayedEvents
<> nil then
951 for a
:= 0 to High(gDelayedEvents
) do
952 if not gDelayedEvents
[a
].Pending
then
959 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
960 n
:= High(gDelayedEvents
);
962 gDelayedEvents
[n
].Pending
:= True;
963 gDelayedEvents
[n
].DEType
:= DEType
;
964 gDelayedEvents
[n
].DENum
:= Num
;
965 gDelayedEvents
[n
].DEStr
:= Str
;
966 if DEType
= DE_GLOBEVENT
then
967 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
969 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
979 if g_Game_IsNet
and g_Game_IsServer
then
980 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
984 gPauseHolmes
:= false;
987 g_Game_StopAllSounds(False);
992 EndingGameCounter
:= 0;
993 g_ActiveWindow
:= nil;
995 gLMSRespawn
:= LMS_RESPAWN_NONE
;
996 gLMSRespawnTime
:= 0;
999 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1004 begin // Ýòî áûë òåñò
1008 begin // Âûõîä â ãëàâíîå ìåíþ
1009 gMusic
.SetByName('MUSIC_MENU');
1011 if gState
<> STATE_SLIST
then
1013 g_GUI_ShowWindow('MainMenu');
1014 gState
:= STATE_MENU
;
1017 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1018 slReturnPressed
:= True;
1019 if g_Net_Slist_Fetch(slCurrent
) then
1021 if slCurrent
= nil then
1022 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1025 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1026 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1029 g_Game_ExecuteEvent('ongameend');
1033 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1035 if not g_Game_IsClient
then g_Game_Restart();
1038 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1040 // Ñòàòèñòèêà Ñâîåé èãðû:
1041 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1043 CustomStat
.GameTime
:= gTime
;
1044 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1045 CustomStat
.MapName
:= gMapInfo
.Name
;
1046 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1047 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1048 CustomStat
.TeamStat
:= gTeamStat
;
1050 CustomStat
.PlayerStat
:= nil;
1052 // Ñòàòèñòèêà èãðîêîâ:
1053 if gPlayers
<> nil then
1055 for a
:= 0 to High(gPlayers
) do
1056 if gPlayers
[a
] <> nil then
1058 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1059 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1062 Name
:= gPlayers
[a
].Name
;
1063 Frags
:= gPlayers
[a
].Frags
;
1064 Deaths
:= gPlayers
[a
].Death
;
1065 Kills
:= gPlayers
[a
].Kills
;
1066 Team
:= gPlayers
[a
].Team
;
1067 Color
:= gPlayers
[a
].Model
.Color
;
1068 Spectator
:= gPlayers
[a
].FSpectator
;
1072 SortGameStat(CustomStat
.PlayerStat
);
1074 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1077 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1078 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1079 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1080 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1082 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1085 StatShotDone
:= False;
1088 g_Game_ExecuteEvent('onmapend');
1089 if not g_Game_IsClient
then g_Player_ResetReady
;
1090 gInterReadyCount
:= 0;
1092 // Çàòóõàþùèé ýêðàí:
1093 EndingGameCounter
:= 255;
1094 gState
:= STATE_FOLD
;
1096 if gDefInterTime
< 0 then
1097 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1099 gInterEndTime
:= gDefInterTime
* 1000;
1102 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1104 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1105 SingleStat
.GameTime
:= gTime
;
1106 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1107 SingleStat
.TotalSecrets
:= gSecretsCount
;
1108 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1109 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1110 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1111 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1112 if SingleStat
.TwoPlayers
then
1114 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1115 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1118 g_Game_ExecuteEvent('onmapend');
1121 if gNextMap
<> '' then
1123 gMusic
.SetByName('MUSIC_INTERMUS');
1125 gState
:= STATE_INTERSINGLE
;
1128 g_Game_ExecuteEvent('oninter');
1130 else // Áîëüøå íåò êàðò
1132 // Çàòóõàþùèé ýêðàí:
1133 EndingGameCounter
:= 255;
1134 gState
:= STATE_FOLD
;
1139 // Îêîí÷àíèå îáðàáîòàíî:
1140 if gExit
<> EXIT_QUIT
then
1144 procedure drawTime(X
, Y
: Integer); inline;
1146 e_TextureFontPrint(x
, y
,
1147 Format('%d:%.2d:%.2d', [
1148 gTime
div 1000 div 3600,
1149 (gTime
div 1000 div 60) mod 60,
1150 gTime
div 1000 mod 60
1155 procedure DrawStat();
1157 pc
, x
, y
, w
, h
: Integer;
1158 w1
, w2
, w3
, w4
: Integer;
1160 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1163 stat
: TPlayerStatArray
;
1171 pc
:= g_Player_GetCount
;
1172 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1174 w
:= gScreenWidth
-(gScreenWidth
div 5);
1175 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1178 h
:= 40+ch
*5+(ch
+8)*pc
;
1179 x
:= (gScreenWidth
div 2)-(w
div 2);
1180 y
:= (gScreenHeight
div 2)-(h
div 2);
1182 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1183 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1185 drawTime(x
+w
-78, y
+8);
1187 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1188 map
:= g_ExtractFileName(gMapInfo
.Map
);
1189 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1191 case gGameSettings
.GameMode
of
1194 if gGameSettings
.MaxLives
= 0 then
1195 s1
:= _lc
[I_GAME_DM
]
1197 s1
:= _lc
[I_GAME_LMS
];
1198 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1199 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1204 if gGameSettings
.MaxLives
= 0 then
1205 s1
:= _lc
[I_GAME_TDM
]
1207 s1
:= _lc
[I_GAME_TLMS
];
1208 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1209 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1214 s1
:= _lc
[I_GAME_CTF
];
1215 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1216 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1221 if gGameSettings
.MaxLives
= 0 then
1222 s1
:= _lc
[I_GAME_COOP
]
1224 s1
:= _lc
[I_GAME_SURV
];
1225 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1226 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1237 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1239 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1241 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1243 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1244 gStdFont
, 200, 200, 200, 1);
1246 if NetMode
= NET_SERVER
then
1247 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1249 if NetMode
= NET_CLIENT
then
1250 e_TextureFontPrintEx(x
+8, y
+ 8,
1251 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1255 stat
:= g_Player_GetStats();
1258 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1259 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1261 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1263 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1267 for a
:= TEAM_RED
to TEAM_BLUE
do
1269 if a
= TEAM_RED
then
1271 s1
:= _lc
[I_GAME_TEAM_RED
];
1278 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1284 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1285 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1286 gStdFont
, r
, g
, b
, 1);
1288 _y
:= _y
+ch
+(ch
div 4);
1289 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1290 _y
:= _y
+(ch
div 4);
1292 for aa
:= 0 to High(stat
) do
1293 if stat
[aa
].Team
= a
then
1309 namestr
:= Format('[%5d] %s', [UID
, Name
])
1313 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1315 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1317 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1319 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1326 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1329 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1330 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1331 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1332 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1335 for aa
:= 0 to High(stat
) do
1349 namestr
:= Format('[%5d] %s', [UID
, Name
])
1353 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1354 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1356 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1358 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1360 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1362 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1368 procedure g_Game_Init();
1371 knownFiles
: array of AnsiString = nil;
1373 wext
, s
: AnsiString;
1378 gTempDelete
:= False;
1380 sfsGCDisable(); // temporary disable removing of temporary volumes
1383 TEXTUREFILTER
:= GL_LINEAR
;
1384 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1385 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1386 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1387 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1388 TEXTUREFILTER
:= GL_NEAREST
;
1390 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1391 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1392 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1394 g_Game_ClearLoading();
1395 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1396 g_Game_SetLoadingText('', 0, False);
1398 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1401 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1402 g_PlayerModel_LoadData();
1404 // load models from all possible wad types, in all known directories
1405 // this does a loosy job (linear search, ooph!), but meh
1406 for wext
in wadExtensions
do
1408 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1410 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1414 for s
in knownFiles
do
1416 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1424 SetLength(knownFiles
, length(knownFiles
)+1);
1425 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1427 until (FindNext(SR
) <> 0);
1433 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1435 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
);
1436 for s
in knownFiles
do
1438 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1442 gPauseMain
:= false;
1443 gPauseHolmes
:= false;
1446 {e_MouseInfo.Accel := 1.0;}
1448 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1451 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1452 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1453 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1454 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1455 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1458 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1462 gMusic
:= TMusic
.Create();
1463 gMusic
.SetByName('MUSIC_MENU');
1466 gGameSettings
.WarmupTime
:= 30;
1468 gState
:= STATE_MENU
;
1470 SetLength(gEvents
, 6);
1471 gEvents
[0].Name
:= 'ongamestart';
1472 gEvents
[1].Name
:= 'ongameend';
1473 gEvents
[2].Name
:= 'onmapstart';
1474 gEvents
[3].Name
:= 'onmapend';
1475 gEvents
[4].Name
:= 'oninter';
1476 gEvents
[5].Name
:= 'onwadend';
1478 sfsGCEnable(); // enable releasing unused volumes
1482 procedure g_Game_Free(freeTextures
: Boolean=true);
1484 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1485 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1487 g_Map_Free(freeTextures
);
1489 g_Player_RemoveAllCorpses();
1491 gGameSettings
.GameType
:= GT_NONE
;
1492 if gGameSettings
.GameMode
= GM_SINGLE
then
1493 gGameSettings
.GameMode
:= GM_DM
;
1494 gSwitchGameMode
:= gGameSettings
.GameMode
;
1497 gExitByTrigger
:= False;
1500 function IsActivePlayer(p
: TPlayer
): Boolean;
1505 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1508 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1515 if gPlayers
= nil then
1517 for a
:= Low(gPlayers
) to High(gPlayers
) do
1518 if IsActivePlayer(gPlayers
[a
]) then
1520 if gPlayers
[a
].UID
<> ID
then
1522 Result
:= gPlayers
[a
];
1527 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1533 if gPlayers
= nil then
1537 for a
:= Low(gPlayers
) to High(gPlayers
) do
1538 if IsActivePlayer(gPlayers
[a
]) then
1540 SetLength(ids
, Length(ids
) + 1);
1541 ids
[High(ids
)] := gPlayers
[a
].UID
;
1542 if gPlayers
[a
].UID
= Skip
then
1545 if Length(ids
) = 0 then
1550 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1553 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1559 if gPlayers
= nil then
1563 for a
:= Low(gPlayers
) to High(gPlayers
) do
1564 if IsActivePlayer(gPlayers
[a
]) then
1566 SetLength(ids
, Length(ids
) + 1);
1567 ids
[High(ids
)] := gPlayers
[a
].UID
;
1568 if gPlayers
[a
].UID
= Skip
then
1571 if Length(ids
) = 0 then
1574 Result
:= ids
[Length(ids
) - 1]
1576 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1579 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1585 if gPlayers
= nil then
1589 for a
:= Low(gPlayers
) to High(gPlayers
) do
1590 if IsActivePlayer(gPlayers
[a
]) then
1592 SetLength(ids
, Length(ids
) + 1);
1593 ids
[High(ids
)] := gPlayers
[a
].UID
;
1594 if gPlayers
[a
].UID
= Skip
then
1597 if Length(ids
) = 0 then
1599 if Length(ids
) = 1 then
1604 Result
:= ids
[Random(Length(ids
))];
1606 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1608 Result
:= ids
[Random(Length(ids
))];
1613 function GetRandomSpectMode(Current
: Byte): Byte;
1620 0: Result
:= SPECT_STATS
;
1621 1: Result
:= SPECT_MAPVIEW
;
1622 2: Result
:= SPECT_MAPVIEW
;
1623 3: Result
:= SPECT_PLAYERS
;
1624 4: Result
:= SPECT_PLAYERS
;
1625 5: Result
:= SPECT_PLAYERS
;
1626 6: Result
:= SPECT_PLAYERS
;
1628 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1632 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1638 if (plr
= nil) then exit
;
1639 if (p
= 2) then time
:= 1000 else time
:= 1;
1640 strafeDir
:= MoveButton
shr 4;
1641 MoveButton
:= MoveButton
and $0F;
1643 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1644 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1645 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1646 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1647 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1648 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1650 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1651 if MoveButton
= 1 then
1652 plr
.PressKey(KEY_LEFT
, time
)
1653 else if MoveButton
= 2 then
1654 plr
.PressKey(KEY_RIGHT
, time
);
1656 // if we have "strafe" key, turn off old strafe mechanics
1657 if gPlayerAction
[p
, ACTION_STRAFE
] then
1659 // new strafe mechanics
1660 if (strafeDir
= 0) then
1661 strafeDir
:= MoveButton
; // start strafing
1662 // now set direction according to strafe (reversed)
1663 if (strafeDir
= 2) then
1664 plr
.SetDirection(TDirection
.D_LEFT
)
1665 else if (strafeDir
= 1) then
1666 plr
.SetDirection(TDirection
.D_RIGHT
)
1670 strafeDir
:= 0; // not strafing anymore
1671 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1672 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1673 plr
.SetDirection(TDirection
.D_LEFT
)
1674 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1675 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1676 plr
.SetDirection(TDirection
.D_RIGHT
)
1677 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1678 else if MoveButton
<> 0 then
1679 plr
.SetDirection(TDirection(MoveButton
-1))
1682 // fix movebutton state
1683 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1685 // Îñòàëüíûå êëàâèøè:
1686 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1687 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1688 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1689 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1690 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1691 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1692 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1694 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1695 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1697 for i
:= WP_FIRST
to WP_LAST
do
1699 if gSelectWeapon
[p
, i
] then
1701 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1702 gSelectWeapon
[p
, i
] := False
1706 // HACK: add dynlight here
1707 if gwin_k8_enable_light_experiments
then
1709 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1711 g_playerLight
:= true;
1713 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1715 g_playerLight
:= false;
1719 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1722 // HACK: don't have a "key was pressed" function
1723 procedure InterReady();
1725 if InterReadyTime
> gTime
then Exit
;
1726 InterReadyTime
:= gTime
+ 3000;
1727 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1730 procedure g_Game_PreUpdate();
1732 // these are in separate PreUpdate functions because they can interact during Update()
1733 // and are synced over the net
1734 // we don't care that much about corpses and gibs
1735 g_Player_PreUpdate();
1736 g_Monsters_PreUpdate();
1737 g_Items_PreUpdate();
1738 g_Weapon_PreUpdate();
1741 procedure g_Game_Update();
1743 Msg
: g_gui
.TMessage
;
1749 function sendMonsPos (mon
: TMonster
): Boolean;
1751 result
:= false; // don't stop
1752 // this will also reset "need-send" flag
1753 if mon
.gncNeedSend
then
1755 MH_SEND_MonsterPos(mon
.UID
);
1757 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1759 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1761 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1763 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1767 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1769 result
:= false; // don't stop
1770 // this will also reset "need-send" flag
1771 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1775 reliableUpdate
: Boolean;
1780 // Ïîðà âûêëþ÷àòü èãðó:
1781 if gExit
= EXIT_QUIT
then
1783 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1787 if gExit
= EXIT_QUIT
then
1791 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1792 // no need to, as we'll do it in event handler
1794 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1797 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1799 gExit
:= EXIT_SIMPLE
;
1804 // process master server communications
1805 g_Net_Slist_Pulse();
1808 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1809 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1810 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1811 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1813 if g_Game_IsNet
and g_Game_IsServer
then
1815 gInterTime
:= gInterTime
+ GAME_TICK
;
1816 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1817 if a
<> gServInterTime
then
1819 gServInterTime
:= a
;
1820 MH_SEND_TimeSync(gServInterTime
);
1824 if (not g_Game_IsClient
) and
1828 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1829 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1830 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1831 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1833 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1834 and (g_ActiveWindow
= nil)
1836 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1839 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1840 g_Game_StopAllSounds(True);
1842 if gMapOnce
then // Ýòî áûë òåñò
1843 gExit
:= EXIT_SIMPLE
1845 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1846 g_Game_ChangeMap(gNextMap
)
1847 else // Ñëåäóþùåé êàðòû íåò
1849 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1851 // Âûõîä â ãëàâíîå ìåíþ:
1853 g_GUI_ShowWindow('MainMenu');
1854 gMusic
.SetByName('MUSIC_MENU');
1856 gState
:= STATE_MENU
;
1859 // Ôèíàëüíàÿ êàðòèíêà:
1860 g_Game_ExecuteEvent('onwadend');
1862 if not gMusic
.SetByName('MUSIC_endmus') then
1863 gMusic
.SetByName('MUSIC_STDENDMUS');
1865 gState
:= STATE_ENDPIC
;
1867 g_Game_ExecuteEvent('ongameend');
1872 else if g_Game_IsClient
and
1875 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1876 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1877 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1878 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1880 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1881 and (g_ActiveWindow
= nil)
1889 if gState
= STATE_INTERTEXT
then
1890 if InterText
.counter
> 0 then
1891 InterText
.counter
:= InterText
.counter
- 1;
1894 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1896 if EndingGameCounter
= 0 then
1898 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1899 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1901 InterReadyTime
:= -1;
1902 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1904 g_Game_ExecuteEvent('onwadend');
1905 if not gMusic
.SetByName('MUSIC_endmus') then
1906 gMusic
.SetByName('MUSIC_STDENDMUS');
1909 gMusic
.SetByName('MUSIC_ROUNDMUS');
1912 gState
:= STATE_INTERCUSTOM
;
1915 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1917 gMusic
.SetByName('MUSIC_INTERMUS');
1919 gState
:= STATE_INTERSINGLE
;
1922 g_Game_ExecuteEvent('oninter');
1925 DecMin(EndingGameCounter
, 6, 0);
1928 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1930 if gMapOnce
then // Ýòî áûë òåñò
1932 gExit
:= EXIT_SIMPLE
;
1938 g_Serverlist_Control(slCurrent
, slTable
);
1941 // Ñòàòèñòèêà ïî Tab:
1943 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1946 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1948 // Âðåìÿ += 28 ìèëëèñåêóíä:
1949 gTime
:= gTime
+ GAME_TICK
;
1951 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1952 if MessageTime
= 0 then
1954 if MessageTime
> 0 then
1955 MessageTime
:= MessageTime
- 1;
1957 if (g_Game_IsServer
) then
1959 // Áûë çàäàí ëèìèò âðåìåíè:
1960 if (gGameSettings
.TimeLimit
> 0) then
1961 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1962 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1967 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1968 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1969 g_Game_RestartRound(gLMSSoftSpawn
);
1971 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1972 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1974 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1976 g_Console_Process(gVoteCommand
);
1978 gVotePassed
:= False;
1981 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1982 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1983 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1984 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1985 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1987 // Áûë çàäàí ëèìèò ïîáåä:
1988 if (gGameSettings
.GoalLimit
> 0) then
1992 if gGameSettings
.GameMode
= GM_DM
then
1993 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1994 for i
:= 0 to High(gPlayers
) do
1995 if gPlayers
[i
] <> nil then
1996 if gPlayers
[i
].Frags
> b
then
1997 b
:= gPlayers
[i
].Frags
;
2000 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2001 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2002 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2005 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2006 if b
>= gGameSettings
.GoalLimit
then
2013 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2014 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2015 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2016 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2018 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2019 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2020 end // if not console
2023 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2025 // process weapon switch queue
2029 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2030 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2032 if not gSpectKeyPress
then
2034 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2036 // switch spect mode
2038 SPECT_NONE
: ; // not spectator
2040 SPECT_MAPVIEW
: Inc(gSpectMode
);
2041 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2043 gSpectKeyPress
:= True;
2045 if (gSpectMode
= SPECT_MAPVIEW
)
2046 and (not gSpectAuto
) then
2048 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2049 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2050 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2051 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2052 if gPlayerAction
[0, ACTION_LOOKUP
] then
2053 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2054 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2055 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2056 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2059 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2060 gSpectKeyPress
:= True;
2062 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2065 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2066 gSpectKeyPress
:= True;
2069 if (gSpectMode
= SPECT_PLAYERS
)
2070 and (not gSpectAuto
) then
2072 if gPlayerAction
[0, ACTION_LOOKUP
] then
2075 gSpectViewTwo
:= True;
2076 gSpectKeyPress
:= True;
2078 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2080 // remove second view
2081 gSpectViewTwo
:= False;
2082 gSpectKeyPress
:= True;
2084 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2086 // prev player (view 1)
2087 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2088 gSpectKeyPress
:= True;
2090 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2092 // next player (view 1)
2093 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2094 gSpectKeyPress
:= True;
2096 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2098 // prev player (view 2)
2099 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2100 gSpectKeyPress
:= True;
2102 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2104 // next player (view 2)
2105 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2106 gSpectKeyPress
:= True;
2109 if gPlayerAction
[0, ACTION_ATTACK
] then
2111 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2114 gSpectAutoNext
:= 0;
2115 gSpectViewTwo
:= False;
2116 gSpectKeyPress
:= True;
2121 gSpectMode
:= SPECT_STATS
;
2122 gSpectAuto
:= False;
2123 gSpectKeyPress
:= True;
2128 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2129 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2130 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2131 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2132 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2133 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2134 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2135 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2136 gSpectKeyPress
:= False;
2140 if gSpectMode
= SPECT_MAPVIEW
then
2142 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2144 gSpectAutoNext
:= gTime
2147 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2149 gSpectAutoNext
:= gTime
2153 if gSpectAutoNext
<= gTime
then
2155 if gSpectAutoNext
> 0 then
2157 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2161 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2162 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2163 gSpectAutoStepX
:= Random(9) - 4;
2164 gSpectAutoStepY
:= Random(9) - 4;
2165 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2166 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2167 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2168 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2169 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2170 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2174 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2179 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2180 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2181 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2187 // Îáíîâëÿåì âñå îñòàëüíîå:
2190 g_Triggers_Update();
2192 g_Monsters_Update();
2194 g_Player_UpdateAll();
2195 g_Player_UpdatePhysicalObjects();
2197 // server: send newly spawned monsters unconditionally
2198 if (gGameSettings
.GameType
= GT_SERVER
) then
2200 if (Length(gMonstersSpawned
) > 0) then
2202 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2203 SetLength(gMonstersSpawned
, 0);
2207 if (gSoundTriggerTime
> 8) then
2209 g_Game_UpdateTriggerSounds();
2210 gSoundTriggerTime
:= 0;
2214 Inc(gSoundTriggerTime
);
2217 if (NetMode
= NET_SERVER
) then
2219 Inc(NetTimeToUpdate
);
2220 Inc(NetTimeToReliable
);
2222 // send monster updates
2223 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2225 // send all monsters (periodic sync)
2226 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2228 for I
:= 0 to High(gPlayers
) do
2230 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2233 g_Mons_ForEach(sendMonsPos
);
2235 if reliableUpdate
then
2237 NetTimeToReliable
:= 0;
2238 NetTimeToUpdate
:= NetUpdateRate
;
2242 NetTimeToUpdate
:= 0;
2247 // send only mosters with some unexpected changes
2248 g_Mons_ForEach(sendMonsPosUnexpected
);
2251 // send unexpected platform changes
2252 g_Map_NetSendInterestingPanels();
2254 g_Net_Slist_ServerUpdate();
2256 if NetUseMaster then
2258 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2260 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2262 NetTimeToMaster := gTime + NetMasterRate;
2267 else if (NetMode
= NET_CLIENT
) then
2269 MC_SEND_PlayerPos();
2271 end; // if gameOn ...
2273 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2274 if g_ActiveWindow
<> nil then
2276 w
:= e_GetFirstKeyPressed();
2278 if (w
<> IK_INVALID
) then
2280 Msg
.Msg
:= MESSAGE_DIKEY
;
2282 g_ActiveWindow
.OnMessage(Msg
);
2285 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2286 if g_ActiveWindow
<> nil then
2287 g_ActiveWindow
.Update();
2289 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2290 if gResolutionChange
then
2292 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2293 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2294 gResolutionChange
:= False;
2295 g_ActiveWindow
:= nil;
2298 // Íóæíî ñìåíèòü ÿçûê:
2299 if gLanguageChange
then
2301 //e_WriteLog('Read language file', MSG_NOTIFY);
2302 //g_Language_Load(DataDir + gLanguage + '.txt');
2303 g_Language_Set(gLanguage
);
2307 gLanguageChange
:= False;
2311 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2312 if e_KeyPressed(IK_F10
) and
2314 (not gConsoleShow
) and
2315 (g_ActiveWindow
= nil) then
2320 Time
:= sys_GetTicks() {div 1000};
2322 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2323 if gDelayedEvents
<> nil then
2324 for a
:= 0 to High(gDelayedEvents
) do
2325 if gDelayedEvents
[a
].Pending
and
2327 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2328 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2331 case gDelayedEvents
[a
].DEType
of
2333 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2336 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2340 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2341 if g_Game_IsNet
and g_Game_IsServer
then
2342 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2346 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2348 gDelayedEvents
[a
].Pending
:= False;
2351 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2352 UPSCounter
:= UPSCounter
+ 1;
2353 if Time
- UPSTime
>= 1000 then
2362 g_Weapon_AddDynLights();
2363 g_Items_AddDynLights();
2367 procedure g_Game_LoadChatSounds(Resource
: string);
2370 FileName
, Snd
: string;
2372 len
, cnt
, tags
, i
, j
: Integer;
2375 FileName
:= g_ExtractWadName(Resource
);
2377 WAD
:= TWADFile
.Create();
2378 WAD
.ReadFile(FileName
);
2380 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2387 cfg
:= TConfig
.CreateMem(p
, len
);
2388 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2390 SetLength(gChatSounds
, cnt
);
2391 for i
:= 0 to Length(gChatSounds
) - 1 do
2393 gChatSounds
[i
].Sound
:= nil;
2394 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2395 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2396 if (Snd
= '') or (Tags
<= 0) then
2398 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2399 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2400 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2401 SetLength(gChatSounds
[i
].Tags
, tags
);
2402 for j
:= 0 to tags
- 1 do
2403 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2404 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2411 procedure g_Game_FreeChatSounds();
2415 for i
:= 0 to Length(gChatSounds
) - 1 do
2417 gChatSounds
[i
].Sound
.Free();
2418 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2420 SetLength(gChatSounds
, 0);
2424 procedure g_Game_LoadData();
2431 if DataLoaded
then Exit
;
2433 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2435 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2436 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2437 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2438 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2439 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2440 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2441 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2442 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2443 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2444 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2445 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2446 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2447 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2448 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2449 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2452 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2453 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2454 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2455 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2459 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2460 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2461 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2462 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2463 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
2469 hasPBarGfx
:= false;
2473 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2474 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2475 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2476 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2477 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2478 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2479 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2480 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2481 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2482 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2483 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2484 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2485 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2486 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2487 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2488 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2489 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2490 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2491 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2492 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2493 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2494 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2495 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2496 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2497 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2498 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2499 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2500 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2504 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2505 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2506 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2507 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2508 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2509 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2510 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2511 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2513 goodsnd
[0] := TPlayableSound
.Create();
2514 goodsnd
[1] := TPlayableSound
.Create();
2515 goodsnd
[2] := TPlayableSound
.Create();
2516 goodsnd
[3] := TPlayableSound
.Create();
2518 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2519 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2520 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2521 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2523 killsnd
[0] := TPlayableSound
.Create();
2524 killsnd
[1] := TPlayableSound
.Create();
2525 killsnd
[2] := TPlayableSound
.Create();
2526 killsnd
[3] := TPlayableSound
.Create();
2528 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2529 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2530 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2531 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2533 hahasnd
[0] := TPlayableSound
.Create();
2534 hahasnd
[1] := TPlayableSound
.Create();
2535 hahasnd
[2] := TPlayableSound
.Create();
2537 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2538 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2539 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2541 sound_get_flag
[0] := TPlayableSound
.Create();
2542 sound_get_flag
[1] := TPlayableSound
.Create();
2543 sound_lost_flag
[0] := TPlayableSound
.Create();
2544 sound_lost_flag
[1] := TPlayableSound
.Create();
2545 sound_ret_flag
[0] := TPlayableSound
.Create();
2546 sound_ret_flag
[1] := TPlayableSound
.Create();
2547 sound_cap_flag
[0] := TPlayableSound
.Create();
2548 sound_cap_flag
[1] := TPlayableSound
.Create();
2550 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2551 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2552 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2553 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2554 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2555 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2556 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2557 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2559 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2561 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2564 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2565 g_Weapon_LoadData();
2567 g_Monsters_LoadData();
2572 procedure g_Game_FreeData();
2574 if not DataLoaded
then Exit
;
2577 g_Weapon_FreeData();
2578 g_Monsters_FreeData();
2580 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2582 g_Texture_Delete('NOTEXTURE');
2583 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2584 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2585 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2586 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2587 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2588 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2589 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2590 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2591 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2592 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2593 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2594 g_Frames_DeleteByName('FRAMES_TELEPORT');
2595 g_Frames_DeleteByName('FRAMES_PUNCH');
2596 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2597 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2598 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2599 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2600 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2601 g_Sound_Delete('SOUND_GAME_TELEPORT');
2602 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2603 g_Sound_Delete('SOUND_GAME_SECRET');
2604 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2605 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2606 g_Sound_Delete('SOUND_GAME_BULK1');
2607 g_Sound_Delete('SOUND_GAME_BULK2');
2608 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2609 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2610 g_Sound_Delete('SOUND_GAME_BURNING');
2611 g_Sound_Delete('SOUND_GAME_SWITCH1');
2612 g_Sound_Delete('SOUND_GAME_SWITCH0');
2619 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2620 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2621 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2622 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2629 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2630 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2631 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2632 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2638 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2639 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2640 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2642 sound_get_flag
[0].Free();
2643 sound_get_flag
[1].Free();
2644 sound_lost_flag
[0].Free();
2645 sound_lost_flag
[1].Free();
2646 sound_ret_flag
[0].Free();
2647 sound_ret_flag
[1].Free();
2648 sound_cap_flag
[0].Free();
2649 sound_cap_flag
[1].Free();
2651 g_Sound_Delete('SOUND_CTF_GET1');
2652 g_Sound_Delete('SOUND_CTF_GET2');
2653 g_Sound_Delete('SOUND_CTF_LOST1');
2654 g_Sound_Delete('SOUND_CTF_LOST2');
2655 g_Sound_Delete('SOUND_CTF_RETURN1');
2656 g_Sound_Delete('SOUND_CTF_RETURN2');
2657 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2658 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2660 g_Game_FreeChatSounds();
2662 DataLoaded
:= False;
2665 procedure DrawCustomStat();
2671 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2672 s1
, s2
, topstr
: String;
2674 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2678 if g_Console_Action(ACTION_SCORES
) then
2680 if not gStatsPressed
then
2682 gStatsOff
:= not gStatsOff
;
2683 gStatsPressed
:= True;
2687 gStatsPressed
:= False;
2691 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2692 w
:= (Length(s1
) * ww2
) div 2;
2693 x
:= gScreenWidth
div 2 - w
;
2695 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2699 if (gGameSettings
.GameMode
= GM_COOP
) then
2701 if gMissionFailed
then
2702 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2704 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2707 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2709 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2710 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2712 if g_Game_IsNet
then
2714 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2715 if not gChatShow
then
2716 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2717 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2720 if g_Game_IsClient
then
2721 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2723 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2724 if not gChatShow
then
2725 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2726 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2731 w
:= gScreenWidth
-x
*2;
2737 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2738 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2740 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2742 case CustomStat
.GameMode
of
2745 if gGameSettings
.MaxLives
= 0 then
2746 s1
:= _lc
[I_GAME_DM
]
2748 s1
:= _lc
[I_GAME_LMS
];
2752 if gGameSettings
.MaxLives
= 0 then
2753 s1
:= _lc
[I_GAME_TDM
]
2755 s1
:= _lc
[I_GAME_TLMS
];
2757 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2760 if gGameSettings
.MaxLives
= 0 then
2761 s1
:= _lc
[I_GAME_COOP
]
2763 s1
:= _lc
[I_GAME_SURV
];
2769 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2773 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2774 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2777 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2778 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2779 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2780 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2782 pc
:= Length(CustomStat
.PlayerStat
);
2783 if pc
= 0 then Exit
;
2785 if CustomStat
.GameMode
= GM_COOP
then
2787 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2789 s2
:= _lc
[I_GAME_MONSTERS
];
2790 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2791 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2793 s2
:= _lc
[I_GAME_SECRETS
];
2794 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2795 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2798 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2800 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2801 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2802 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2804 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2805 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2806 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2810 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2815 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2816 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2817 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2819 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2822 for t
:= TEAM_RED
to TEAM_BLUE
do
2824 if t
= TEAM_RED
then
2826 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2827 gStdFont
, 255, 0, 0, 1);
2828 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2829 gStdFont
, 255, 0, 0, 1);
2836 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2837 gStdFont
, 0, 0, 255, 1);
2838 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2839 gStdFont
, 0, 0, 255, 1);
2845 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2848 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2849 if CustomStat
.PlayerStat
[p
].Team
= t
then
2850 with CustomStat
.PlayerStat
[p
] do
2864 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2865 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2867 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2868 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2869 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2876 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2879 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2880 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2881 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2884 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2885 with CustomStat
.PlayerStat
[p
] do
2887 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2894 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2895 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2897 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2898 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2899 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2904 // HACK: take stats screenshot immediately after the first frame of the stats showing
2905 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2907 g_TakeScreenShot('stats/' + StatFilename
);
2908 StatShotDone
:= True;
2912 procedure DrawSingleStat();
2914 tm
, key_x
, val_x
, y
: Integer;
2918 procedure player_stat(n
: Integer);
2924 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2925 s2
:= Format(' %d', [gTotalMonsters
]);
2927 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2928 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2929 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2930 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2932 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2933 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2935 // "Kills-per-minute: ##.#":
2936 s1
:= _lc
[I_MENU_INTER_KPM
];
2938 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2940 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2941 s2
:= Format(' %.1f', [kpm
]);
2943 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2944 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2946 // "Secrets found: # / #":
2947 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2948 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2950 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2951 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2952 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2953 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2955 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2956 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2960 // "Level Complete":
2961 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2962 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2964 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2965 s1
:= _lc
[I_MENU_INTER_KPM
];
2966 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2969 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2971 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2972 val_x
:= key_x
+ w1
;
2975 tm
:= SingleStat
.GameTime
div 1000;
2976 s1
:= _lc
[I_MENU_INTER_TIME
];
2977 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2979 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2980 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2982 if SingleStat
.TwoPlayers
then
2985 s1
:= _lc
[I_MENU_PLAYER_1
];
2986 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2987 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2989 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2994 s1
:= _lc
[I_MENU_PLAYER_2
];
2995 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2996 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2998 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3004 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3010 procedure DrawLoadingStat();
3011 procedure drawRect (x
, y
, w
, h
: Integer);
3013 if (w
< 1) or (h
< 1) then exit
;
3015 glVertex2f(x
+0.375, y
+0.375);
3016 glVertex2f(x
+w
+0.375, y
+0.375);
3017 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3018 glVertex2f(x
+0.375, y
+h
+0.375);
3022 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3024 rectW
, rectH
: Integer;
3031 idl
, idr
, idb
, idm
: LongWord;
3035 if (total
< 1) then exit
;
3036 if (cur
< 1) then exit
; // don't blink
3037 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3038 //if (cur < 0) then cur := 0;
3039 //if (cur > total) then cur := total;
3042 if (hasPBarGfx
) then
3044 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3045 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3046 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3047 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3048 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3049 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3050 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3051 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3053 //rectW := gScreenWidth-360;
3054 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3057 x0
:= (gScreenWidth
-rectW
) div 2;
3058 y0
:= gScreenHeight
-rectH
-64;
3059 if (y0
< 2) then y0
:= 2;
3061 glEnable(GL_SCISSOR_TEST
);
3064 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3065 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3066 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3069 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3071 while (f
< x0
+rectW
) do
3073 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3078 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3079 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3082 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3083 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3087 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3093 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3097 rectW
:= gScreenWidth
-64;
3100 x0
:= (gScreenWidth
-rectW
) div 2;
3101 y0
:= gScreenHeight
-rectH
-64;
3102 if (y0
< 2) then y0
:= 2;
3104 glDisable(GL_BLEND
);
3105 glDisable(GL_TEXTURE_2D
);
3107 //glClearColor(0, 0, 0, 0);
3108 //glClear(GL_COLOR_BUFFER_BIT);
3110 glColor4ub(127, 127, 127, 255);
3111 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3113 glColor4ub(0, 0, 0, 255);
3114 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3116 glColor4ub(127, 127, 127, 255);
3117 wdt
:= rectW
*cur
div total
;
3118 if (wdt
> rectW
) then wdt
:= rectW
;
3119 drawRect(x0
, y0
, wdt
, rectH
);
3128 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3130 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3131 yy
:= (gScreenHeight
div 3);
3132 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3133 xx
:= (gScreenWidth
div 3);
3137 for i
:= 0 to NextMsg
-1 do
3139 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3140 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3144 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3145 yy
:= yy
+ LOADING_INTERLINE
;
3146 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3151 procedure DrawMenuBackground(tex
: AnsiString);
3157 if g_Texture_Get(tex
, ID
) then
3159 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3160 e_GetTextureSize(ID
, @w
, @h
);
3162 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3164 w
:= trunc(w
* (gScreenHeight
/ h
));
3165 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3167 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3170 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3172 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3174 function monDraw (mon
: TMonster
): Boolean;
3176 result
:= false; // don't stop
3181 // Ëåâûé âåðõíèé óãîë
3182 aX
:= Obj
.X
div ScaleSz
+ 1;
3183 aY
:= Obj
.Y
div ScaleSz
+ 1;
3185 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3186 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3187 // Ïðàâûé íèæíèé óãîë
3188 aX2
:= aX
+ aX2
- 1;
3189 aY2
:= aY
+ aY2
- 1;
3190 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3196 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3197 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3200 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3201 ScaleSz
:= 16 div Scale
;
3202 // Ðàçìåðû ìèíè-êàðòû:
3203 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3204 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3206 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3208 if gWalls
<> nil then
3211 for a
:= 0 to High(gWalls
) do
3213 if PanelType
<> 0 then
3215 // Ëåâûé âåðõíèé óãîë:
3216 aX
:= X
div ScaleSz
;
3217 aY
:= Y
div ScaleSz
;
3219 aX2
:= max(Width
div ScaleSz
, 1);
3220 aY2
:= max(Height
div ScaleSz
, 1);
3221 // Ïðàâûé íèæíèé óãîë:
3222 aX2
:= aX
+ aX2
- 1;
3223 aY2
:= aY
+ aY2
- 1;
3226 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3227 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3228 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3232 if gSteps
<> nil then
3235 for a
:= 0 to High(gSteps
) do
3237 if PanelType
<> 0 then
3239 // Ëåâûé âåðõíèé óãîë:
3240 aX
:= X
div ScaleSz
;
3241 aY
:= Y
div ScaleSz
;
3243 aX2
:= max(Width
div ScaleSz
, 1);
3244 aY2
:= max(Height
div ScaleSz
, 1);
3245 // Ïðàâûé íèæíèé óãîë:
3246 aX2
:= aX
+ aX2
- 1;
3247 aY2
:= aY
+ aY2
- 1;
3249 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3252 if gLifts
<> nil then
3255 for a
:= 0 to High(gLifts
) 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;
3270 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3271 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3272 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3273 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3277 if gWater
<> nil then
3280 for a
:= 0 to High(gWater
) do
3282 if PanelType
<> 0 then
3284 // Ëåâûé âåðõíèé óãîë:
3285 aX
:= X
div ScaleSz
;
3286 aY
:= Y
div ScaleSz
;
3288 aX2
:= max(Width
div ScaleSz
, 1);
3289 aY2
:= max(Height
div ScaleSz
, 1);
3290 // Ïðàâûé íèæíèé óãîë:
3291 aX2
:= aX
+ aX2
- 1;
3292 aY2
:= aY
+ aY2
- 1;
3294 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3297 if gAcid1
<> nil then
3299 // Ðèñóåì êèñëîòó 1:
3300 for a
:= 0 to High(gAcid1
) do
3302 if PanelType
<> 0 then
3304 // Ëåâûé âåðõíèé óãîë:
3305 aX
:= X
div ScaleSz
;
3306 aY
:= Y
div ScaleSz
;
3308 aX2
:= max(Width
div ScaleSz
, 1);
3309 aY2
:= max(Height
div ScaleSz
, 1);
3310 // Ïðàâûé íèæíèé óãîë:
3311 aX2
:= aX
+ aX2
- 1;
3312 aY2
:= aY
+ aY2
- 1;
3314 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3317 if gAcid2
<> nil then
3319 // Ðèñóåì êèñëîòó 2:
3320 for a
:= 0 to High(gAcid2
) do
3322 if PanelType
<> 0 then
3324 // Ëåâûé âåðõíèé óãîë:
3325 aX
:= X
div ScaleSz
;
3326 aY
:= Y
div ScaleSz
;
3328 aX2
:= max(Width
div ScaleSz
, 1);
3329 aY2
:= max(Height
div ScaleSz
, 1);
3330 // Ïðàâûé íèæíèé óãîë:
3331 aX2
:= aX
+ aX2
- 1;
3332 aY2
:= aY
+ aY2
- 1;
3334 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3337 if gPlayers
<> nil then
3340 for a
:= 0 to High(gPlayers
) do
3341 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3343 // Ëåâûé âåðõíèé óãîë:
3344 aX
:= Obj
.X
div ScaleSz
+ 1;
3345 aY
:= Obj
.Y
div ScaleSz
+ 1;
3347 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3348 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3349 // Ïðàâûé íèæíèé óãîë:
3350 aX2
:= aX
+ aX2
- 1;
3351 aY2
:= aY
+ aY2
- 1;
3353 if gPlayers
[a
] = p
then
3354 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3357 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3358 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3359 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3364 g_Mons_ForEach(monDraw
);
3369 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3371 if not hasAmbient
then exit
;
3372 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3376 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3377 //FIXME: broken for splitscreen mode
3378 procedure renderDynLightsInternal ();
3380 //hasAmbient: Boolean;
3381 //ambColor: TDFColor;
3383 lx
, ly
, lrad
: Integer;
3384 scxywh
: array[0..3] of GLint
;
3387 if e_NoGraphics
then exit
;
3389 //TODO: lights should be in separate grid, i think
3390 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3391 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3394 //ambColor := gCurrentMap['light_ambient'].rgba;
3395 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3397 { // this will multiply incoming color to alpha from framebuffer
3399 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3403 * light rendering: (INVALID!)
3404 * glStencilFunc(GL_EQUAL, 0, $ff);
3406 * glClear(GL_STENCIL_BUFFER_BIT);
3407 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3408 * draw shadow volume into stencil buffer
3409 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3410 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3412 * draw color-less quad with light alpha (WARNING! don't touch color!)
3413 * glEnable(GL_BLEND);
3414 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3415 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3417 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3418 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3420 // setup OpenGL parameters
3421 glStencilMask($FFFFFFFF);
3422 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3423 glEnable(GL_STENCIL_TEST
);
3424 glEnable(GL_SCISSOR_TEST
);
3425 glClear(GL_STENCIL_BUFFER_BIT
);
3426 glStencilFunc(GL_EQUAL
, 0, $ff);
3428 for lln
:= 0 to g_dynLightCount
-1 do
3430 lx
:= g_dynLights
[lln
].x
;
3431 ly
:= g_dynLights
[lln
].y
;
3432 lrad
:= g_dynLights
[lln
].radius
;
3433 if (lrad
< 3) then continue
;
3435 if (lx
-sX
+lrad
< 0) then continue
;
3436 if (ly
-sY
+lrad
< 0) then continue
;
3437 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3438 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3440 // set scissor to optimize drawing
3441 if (g_dbg_scale
= 1.0) then
3443 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3447 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3449 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3450 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3451 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3452 // draw extruded panels
3453 glDisable(GL_TEXTURE_2D
);
3454 glDisable(GL_BLEND
);
3455 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3456 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3457 // render light texture
3458 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3459 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3462 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3463 glEnable(GL_TEXTURE_2D
);
3464 // color and opacity
3465 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3466 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3468 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3469 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3470 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3471 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3476 glDisable(GL_STENCIL_TEST
);
3477 glDisable(GL_BLEND
);
3478 glDisable(GL_SCISSOR_TEST
);
3479 //glScissor(0, 0, sWidth, sHeight);
3481 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3482 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3486 function fixViewportForScale (): Boolean;
3488 nx0
, ny0
, nw
, nh
: Integer;
3491 if (g_dbg_scale
<> 1.0) then
3494 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3495 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3496 nw
:= round(sWidth
/g_dbg_scale
);
3497 nh
:= round(sHeight
/g_dbg_scale
);
3506 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3507 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3508 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3510 TDrawCB
= procedure ();
3513 hasAmbient
: Boolean;
3515 doAmbient
: Boolean = false;
3517 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3522 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3523 if gdbg_map_use_accel_render
then
3525 tagmask
:= panelTypeToTag(panType
);
3526 while (gDrawPanelList
.count
> 0) do
3528 pan
:= TPanel(gDrawPanelList
.front());
3529 if ((pan
.tag
and tagmask
) = 0) then break
;
3530 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3531 gDrawPanelList
.popFront();
3536 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3538 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3541 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3543 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3544 if assigned(cb
) then cb();
3545 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3549 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3551 // our accelerated renderer will collect all panels to gDrawPanelList
3552 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3553 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3554 if gdbg_map_use_accel_render
then
3556 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3558 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3560 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3561 g_Map_DrawBack(backXOfs
, backYOfs
);
3562 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3564 if setTransMatrix
then
3566 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3567 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3568 glTranslatef(-sX
, -sY
, 0);
3572 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3573 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3578 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3579 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3580 glClear(GL_COLOR_BUFFER_BIT);
3583 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3586 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3587 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3588 drawOther('items', @g_Items_Draw
);
3589 drawOther('weapons', @g_Weapon_Draw
);
3590 drawOther('shells', @g_Player_DrawShells
);
3591 drawOther('drawall', @g_Player_DrawAll
);
3592 drawOther('corpses', @g_Player_DrawCorpses
);
3593 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3594 drawOther('monsters', @g_Monsters_Draw
);
3595 drawOther('itemdrop', @g_Items_DrawDrop
);
3596 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3597 drawOther('gfx', @g_GFX_Draw
);
3598 drawOther('flags', @g_Map_DrawFlags
);
3599 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3600 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3601 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3602 drawOther('dynlights', @renderDynLightsInternal
);
3604 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3606 renderAmbientQuad(hasAmbient
, ambColor
);
3610 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3613 if g_debug_HealthBar
then
3615 g_Monsters_DrawHealth();
3616 g_Player_DrawHealth();
3619 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3623 procedure DrawMapView(x
, y
, w
, h
: Integer);
3630 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3631 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3638 fixViewportForScale();
3639 renderMapInternal(-bx
, -by
, true);
3645 procedure DrawPlayer(p
: TPlayer
);
3647 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3651 if (p
= nil) or (p
.FDummy
) then
3654 g_Map_DrawBack(0, 0);
3659 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3660 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3666 camObj
:= p
.getCameraObj();
3667 camObj
.lerp(gLerpFactor
, fX
, fY
);
3668 px
:= fX
+ PLAYER_RECT_CX
;
3669 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3671 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3673 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3674 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3676 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3677 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3679 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3680 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3683 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3686 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3687 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3690 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3695 // scaled, ignore level bounds
3696 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3697 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3702 sWidth
:= gPlayerScreenSize
.X
;
3703 sHeight
:= gPlayerScreenSize
.Y
;
3704 fixViewportForScale();
3706 i
:= py
- (sY
+ sHeight
div 2);
3707 if (p
.IncCam
> 0) then
3709 // clamp to level bounds
3710 if (sY
- p
.IncCam
< 0) then
3711 p
.IncCam
:= nclamp(sY
, 0, 120);
3712 // clamp around player position
3714 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3716 else if (p
.IncCam
< 0) then
3718 // clamp to level bounds
3719 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3720 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3721 // clamp around player position
3723 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3726 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3728 if (not g_dbg_ignore_bounds
) then
3730 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3731 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3732 if (sX
< 0) then sX
:= 0;
3733 if (sY
< 0) then sY
:= 0;
3736 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3737 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3739 //r_smallmap_h: 0: left; 1: center; 2: right
3740 //r_smallmap_v: 0: top; 1: center; 2: bottom
3742 if (gMapInfo
.Width
= sWidth
) then
3746 else if (gMapInfo
.Width
< sWidth
) then
3748 case r_smallmap_h
of
3749 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3750 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3751 else sX
:= 0; // left
3755 if (gMapInfo
.Height
= sHeight
) then
3759 else if (gMapInfo
.Height
< sHeight
) then
3761 case r_smallmap_v
of
3762 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3763 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3764 else sY
:= 0; // top
3770 p
.viewPortW
:= sWidth
;
3771 p
.viewPortH
:= sHeight
;
3773 {$IFDEF ENABLE_HOLMES}
3774 if (p
= gPlayer1
) then
3776 g_Holmes_plrViewPos(sX
, sY
);
3777 g_Holmes_plrViewSize(sWidth
, sHeight
);
3781 renderMapInternal(-c
, -d
, true);
3783 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3784 case gPlayerIndicator
of
3786 p
.DrawIndicator(_RGB(255, 255, 255));
3789 for i
:= 0 to High(gPlayers
) do
3790 if gPlayers
[i
] <> nil then
3791 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3792 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3793 if gPlayerIndicatorStyle
= 1 then
3794 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3795 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3799 for a := 0 to High(gCollideMap) do
3800 for b := 0 to High(gCollideMap[a]) do
3803 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3805 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3809 1: e_DrawPoint(1, b, a, 200, 200, 200);
3810 2: e_DrawPoint(1, b, a, 64, 64, 255);
3811 3: e_DrawPoint(1, b, a, 255, 0, 255);
3821 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3822 if g_Debug_Player
then
3823 g_Player_DrawDebug(p
);
3827 procedure drawProfilers ();
3832 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3833 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3834 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3837 procedure g_Game_Draw();
3844 plView1
, plView2
: TPlayer
;
3847 if gExit
= EXIT_QUIT
then Exit
;
3849 Time
:= sys_GetTicks() {div 1000};
3850 FPSCounter
:= FPSCounter
+1;
3851 if Time
- FPSTime
>= 1000 then
3858 e_SetRendertarget(True);
3859 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3861 if gGameOn
or (gState
= STATE_FOLD
) then
3863 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3865 gSpectMode
:= SPECT_NONE
;
3866 if not gRevertPlayers
then
3868 plView1
:= gPlayer1
;
3869 plView2
:= gPlayer2
;
3873 plView1
:= gPlayer2
;
3874 plView2
:= gPlayer1
;
3878 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3880 gSpectMode
:= SPECT_NONE
;
3881 if gPlayer2
= nil then
3884 plView1
:= gPlayer2
;
3893 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3894 gSpectMode
:= SPECT_STATS
;
3896 if gSpectMode
= SPECT_PLAYERS
then
3897 if gPlayers
<> nil then
3899 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3900 if plView1
= nil then
3902 gSpectPID1
:= GetActivePlayerID_Next();
3903 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3905 if gSpectViewTwo
then
3907 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3908 if plView2
= nil then
3910 gSpectPID2
:= GetActivePlayerID_Next();
3911 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3916 if gSpectMode
= SPECT_MAPVIEW
then
3918 // Ðåæèì ïðîñìîòðà êàðòû
3920 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3921 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3922 gHearPoint1
.Active
:= True;
3923 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3924 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3925 gHearPoint2
.Active
:= False;
3929 Split
:= (plView1
<> nil) and (plView2
<> nil);
3931 // Òî÷êè ñëóõà èãðîêîâ
3932 if plView1
<> nil then
3934 gHearPoint1
.Active
:= True;
3935 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3936 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3938 gHearPoint1
.Active
:= False;
3939 if plView2
<> nil then
3941 gHearPoint2
.Active
:= True;
3942 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3943 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3945 gHearPoint2
.Active
:= False;
3947 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3948 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3951 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3952 if gScreenHeight
mod 2 = 0 then
3953 Dec(gPlayerScreenSize
.Y
);
3956 gPlayerScreenSize
.Y
:= gScreenHeight
;
3959 if gScreenHeight
mod 2 = 0 then
3960 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3962 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3964 DrawPlayer(plView1
);
3965 gPlayer1ScreenCoord
.X
:= sX
;
3966 gPlayer1ScreenCoord
.Y
:= sY
;
3970 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3972 DrawPlayer(plView2
);
3973 gPlayer2ScreenCoord
.X
:= sX
;
3974 gPlayer2ScreenCoord
.Y
:= sY
;
3977 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3980 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3983 {$IFDEF ENABLE_HOLMES}
3985 if (g_holmes_enabled
) then g_Holmes_Draw();
3988 if MessageText
<> '' then
3992 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3994 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3995 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3997 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3998 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4001 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4004 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4006 // Draw spectator GUI
4009 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4012 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4014 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4016 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4018 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4019 if gSpectMode
= SPECT_STATS
then
4021 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4022 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4024 if gSpectMode
= SPECT_MAPVIEW
then
4026 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4027 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4028 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4029 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4030 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4032 if gSpectMode
= SPECT_PLAYERS
then
4034 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4035 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4036 if gSpectViewTwo
then
4038 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4039 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4040 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4041 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4045 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4046 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4052 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4054 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4055 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4057 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4058 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4059 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4064 if (gState
= STATE_MENU
) then
4066 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4067 // F3 at menu will show game loading dialog
4068 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4069 if (g_ActiveWindow
<> nil) then
4071 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4072 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4076 // F3 at titlepic will show game loading dialog
4077 if e_KeyPressed(IK_F3
) then
4079 g_Menu_Show_LoadMenu(true);
4080 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4085 if gState
= STATE_FOLD
then
4087 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4090 if gState
= STATE_INTERCUSTOM
then
4092 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4094 back
:= 'TEXTURE_endpic';
4095 if not g_Texture_Get(back
, ID
) then
4096 back
:= _lc
[I_TEXTURE_ENDPIC
];
4101 DrawMenuBackground(back
);
4105 if g_ActiveWindow
<> nil then
4107 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4108 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4112 if gState
= STATE_INTERSINGLE
then
4114 if EndingGameCounter
> 0 then
4116 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4122 DrawMenuBackground(back
);
4126 if g_ActiveWindow
<> nil then
4128 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4129 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4134 if gState
= STATE_ENDPIC
then
4137 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4138 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4140 if g_ActiveWindow
<> nil then
4142 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4143 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4147 if gState
= STATE_SLIST
then
4149 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4151 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4152 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4154 DrawMenuBackground('MENU_BACKGROUND');
4155 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4156 g_Serverlist_Draw(slCurrent
, slTable
);
4160 if g_ActiveWindow
<> nil then
4164 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4165 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4167 g_ActiveWindow
.Draw();
4174 if g_debug_Sounds
and gGameOn
then
4176 for w
:= 0 to High(e_SoundsArray
) do
4177 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4178 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4183 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4184 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4187 if gGameOn
and gShowTime
then
4188 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4190 if gGameOn
then drawProfilers();
4192 // TODO: draw this after the FBO and remap mouse click coordinates
4194 {$IFDEF ENABLE_HOLMES}
4198 // blit framebuffer to screen
4200 e_SetRendertarget(False);
4201 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4202 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4204 // draw the overlay stuff on top of it
4209 procedure g_Game_Quit();
4211 g_Game_StopAllSounds(True);
4214 g_PlayerModel_FreeData();
4215 g_Texture_DeleteAll();
4216 g_Frames_DeleteAll();
4218 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4221 if NetInitDone
then g_Net_Free
;
4223 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4224 if gMapToDelete
<> '' then
4225 g_Game_DeleteTestMap();
4231 procedure g_FatalError(Text: String);
4233 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4234 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4236 gExit
:= EXIT_SIMPLE
;
4237 if gGameOn
then EndGame
;
4240 procedure g_SimpleError(Text: String);
4242 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4243 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4246 procedure g_Game_SetupScreenSize();
4248 RES_FACTOR
= 4.0 / 3.0;
4254 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4255 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4256 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4257 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4259 gPlayerScreenSize
.Y
:= gScreenHeight
;
4261 // Ðàçìåð çàäíåãî ïëàíà:
4262 if BackID
<> DWORD(-1) then
4265 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4266 (gScreenHeight
*s
> gMapInfo
.Height
) then
4268 gBackSize
.X
:= gScreenWidth
;
4269 gBackSize
.Y
:= gScreenHeight
;
4273 e_GetTextureSize(BackID
, @bw
, @bh
);
4274 rf
:= Single(bw
) / Single(bh
);
4275 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4276 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4277 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4278 if (s
< 1.0) then s
:= 1.0;
4279 gBackSize
.X
:= Round(bw
*s
);
4280 gBackSize
.Y
:= Round(bh
*s
);
4285 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4287 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4290 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4292 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4293 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4296 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4299 if gPlayer1
= nil then
4301 if g_Game_IsClient
then
4303 if NetPlrUID1
> -1 then
4304 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4308 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4309 Team
:= gPlayer1Settings
.Team
;
4311 // Ñîçäàíèå ïåðâîãî èãðîêà:
4312 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4313 gPlayer1Settings
.Color
,
4315 if gPlayer1
= nil then
4316 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4319 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4320 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4321 if g_Game_IsServer
and g_Game_IsNet
then
4322 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4323 gPlayer1
.Respawn(False, True);
4324 g_Net_Slist_ServerPlayerComes();
4329 if gPlayer2
= nil then
4331 if g_Game_IsClient
then
4333 if NetPlrUID2
> -1 then
4334 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4338 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4339 Team
:= gPlayer2Settings
.Team
;
4341 // Ñîçäàíèå âòîðîãî èãðîêà:
4342 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4343 gPlayer2Settings
.Color
,
4345 if gPlayer2
= nil then
4346 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4349 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4350 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4351 if g_Game_IsServer
and g_Game_IsNet
then
4352 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4353 gPlayer2
.Respawn(False, True);
4354 g_Net_Slist_ServerPlayerComes();
4361 procedure g_Game_RemovePlayer();
4365 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4366 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4371 if g_Game_IsServer
then
4374 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4375 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4376 g_Player_Remove(Pl
.UID
);
4377 g_Net_Slist_ServerPlayerLeaves();
4381 gSpectLatchPID2
:= Pl
.UID
;
4389 if g_Game_IsServer
then
4392 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4393 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4394 g_Player_Remove(Pl
.UID
);
4395 g_Net_Slist_ServerPlayerLeaves();
4398 gSpectLatchPID1
:= Pl
.UID
;
4400 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4404 g_Net_Slist_ServerPlayerLeaves();
4407 procedure g_Game_Spectate();
4409 g_Game_RemovePlayer();
4410 if gPlayer1
<> nil then
4411 g_Game_RemovePlayer();
4414 procedure g_Game_SpectateCenterView();
4416 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4417 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4420 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4427 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4429 g_Game_ClearLoading();
4432 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4435 gGameSettings
.GameType
:= GT_SINGLE
;
4436 gGameSettings
.MaxLives
:= 0;
4437 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4438 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4439 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4440 gSwitchGameMode
:= GM_SINGLE
;
4442 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4443 gLMSRespawnTime
:= 0;
4444 gSpectLatchPID1
:= 0;
4445 gSpectLatchPID2
:= 0;
4447 g_Game_ExecuteEvent('ongamestart');
4449 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4450 g_Game_SetupScreenSize();
4452 // Ñîçäàíèå ïåðâîãî èãðîêà:
4453 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4454 gPlayer1Settings
.Color
,
4455 gPlayer1Settings
.Team
, False));
4456 if gPlayer1
= nil then
4458 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4462 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4465 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4468 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4469 gPlayer2Settings
.Color
,
4470 gPlayer2Settings
.Team
, False));
4471 if gPlayer2
= nil then
4473 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4477 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4481 // Çàãðóçêà è çàïóñê êàðòû:
4482 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4484 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4485 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4489 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4493 for i
:= nPl
+1 to nPlayers
do
4494 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4497 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4498 TimeLimit
, GoalLimit
: Word;
4500 Options
: LongWord; nPlayers
: Byte);
4506 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4508 g_Game_ClearLoading();
4511 gGameSettings
.GameType
:= GT_CUSTOM
;
4512 gGameSettings
.GameMode
:= GameMode
;
4513 gSwitchGameMode
:= GameMode
;
4514 gGameSettings
.TimeLimit
:= TimeLimit
;
4515 gGameSettings
.GoalLimit
:= GoalLimit
;
4516 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4517 gGameSettings
.Options
:= Options
;
4519 gCoopTotalMonstersKilled
:= 0;
4520 gCoopTotalSecretsFound
:= 0;
4521 gCoopTotalMonsters
:= 0;
4522 gCoopTotalSecrets
:= 0;
4526 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4527 gLMSRespawnTime
:= 0;
4528 gSpectLatchPID1
:= 0;
4529 gSpectLatchPID2
:= 0;
4531 g_Game_ExecuteEvent('ongamestart');
4533 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4534 g_Game_SetupScreenSize();
4536 // Ðåæèì íàáëþäàòåëÿ:
4537 if nPlayers
= 0 then
4544 if nPlayers
>= 1 then
4546 // Ñîçäàíèå ïåðâîãî èãðîêà:
4547 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4548 gPlayer1Settings
.Color
,
4549 gPlayer1Settings
.Team
, False));
4550 if gPlayer1
= nil then
4552 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4556 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4560 if nPlayers
>= 2 then
4562 // Ñîçäàíèå âòîðîãî èãðîêà:
4563 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4564 gPlayer2Settings
.Color
,
4565 gPlayer2Settings
.Team
, False));
4566 if gPlayer2
= nil then
4568 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4572 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4576 // Çàãðóçêà è çàïóñê êàðòû:
4577 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4579 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4583 // Íåò òî÷åê ïîÿâëåíèÿ:
4584 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4585 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4586 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4587 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4588 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4590 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4594 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4598 for i
:= nPl
+1 to nPlayers
do
4599 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4602 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4603 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4604 Options
: LongWord; nPlayers
: Byte;
4605 IPAddr
: LongWord; Port
: Word);
4608 g_Net_Slist_ServerClosed();
4610 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4612 g_Game_ClearLoading();
4615 gGameSettings
.GameType
:= GT_SERVER
;
4616 gGameSettings
.GameMode
:= GameMode
;
4617 gSwitchGameMode
:= GameMode
;
4618 gGameSettings
.TimeLimit
:= TimeLimit
;
4619 gGameSettings
.GoalLimit
:= GoalLimit
;
4620 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4621 gGameSettings
.Options
:= Options
;
4623 gCoopTotalMonstersKilled
:= 0;
4624 gCoopTotalSecretsFound
:= 0;
4625 gCoopTotalMonsters
:= 0;
4626 gCoopTotalSecrets
:= 0;
4630 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4631 gLMSRespawnTime
:= 0;
4632 gSpectLatchPID1
:= 0;
4633 gSpectLatchPID2
:= 0;
4635 g_Game_ExecuteEvent('ongamestart');
4637 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4638 g_Game_SetupScreenSize();
4640 // Ðåæèì íàáëþäàòåëÿ:
4641 if nPlayers
= 0 then
4647 if nPlayers
>= 1 then
4649 // Ñîçäàíèå ïåðâîãî èãðîêà:
4650 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4651 gPlayer1Settings
.Color
,
4652 gPlayer1Settings
.Team
, False));
4653 if gPlayer1
= nil then
4655 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4659 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4662 if nPlayers
>= 2 then
4664 // Ñîçäàíèå âòîðîãî èãðîêà:
4665 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4666 gPlayer2Settings
.Color
,
4667 gPlayer2Settings
.Team
, False));
4668 if gPlayer2
= nil then
4670 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4674 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4677 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4678 if NetForwardPorts
then
4679 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4682 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4684 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4688 g_Net_Slist_Set(NetMasterList
);
4690 g_Net_Slist_ServerStarted();
4692 // Çàãðóçêà è çàïóñê êàðòû:
4693 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4695 g_Net_Slist_ServerClosed();
4696 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4700 // Íåò òî÷åê ïîÿâëåíèÿ:
4701 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4702 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4703 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4704 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4705 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4707 g_Net_Slist_ServerClosed();
4708 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4712 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4715 g_Net_Slist_ServerMapStarted();
4716 NetState
:= NET_STATE_GAME
;
4719 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4734 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4735 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4737 g_Game_ClearLoading();
4740 gGameSettings
.GameType
:= GT_CLIENT
;
4742 gCoopTotalMonstersKilled
:= 0;
4743 gCoopTotalSecretsFound
:= 0;
4744 gCoopTotalMonsters
:= 0;
4745 gCoopTotalSecrets
:= 0;
4749 g_Game_ExecuteEvent('ongamestart');
4751 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4752 g_Game_SetupScreenSize();
4754 NetState
:= NET_STATE_AUTH
;
4756 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4758 // create (or update) map/resource databases
4759 g_Res_CreateDatabases(true);
4761 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4762 gLMSRespawnTime
:= 0;
4763 gSpectLatchPID1
:= 0;
4764 gSpectLatchPID2
:= 0;
4767 if not g_Net_Connect(Addr
, Port
) then
4769 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4770 NetState
:= NET_STATE_NONE
;
4774 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4776 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4781 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4782 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4783 // thank you, enet. let's ignore failures altogether then.
4784 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4786 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4788 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4790 // ignore all download packets, they're processed by separate code
4791 enet_packet_destroy(NetEvent
.packet
);
4794 Ptr
:= NetEvent
.packet
^.data
;
4795 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4797 enet_packet_destroy(NetEvent
.packet
);
4801 InMsg
.ReadLongWord(); // skip size
4802 MID
:= InMsg
.ReadByte();
4804 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4806 NetMyID
:= InMsg
.ReadByte();
4807 NetPlrUID1
:= InMsg
.ReadWord();
4809 WadName
:= InMsg
.ReadString();
4810 Map
:= InMsg
.ReadString();
4812 gWADHash
:= InMsg
.ReadMD5();
4814 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4815 gSwitchGameMode
:= gGameSettings
.GameMode
;
4816 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4817 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4818 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4819 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4820 T
:= InMsg
.ReadLongWord();
4822 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4823 //if newResPath = '' then
4825 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4826 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4827 if newResPath
= '' then
4829 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4830 enet_packet_destroy(NetEvent
.packet
);
4831 NetState
:= NET_STATE_NONE
;
4834 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4836 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4839 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4840 gPlayer1Settings
.Color
,
4841 gPlayer1Settings
.Team
, False));
4843 if gPlayer1
= nil then
4845 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4847 enet_packet_destroy(NetEvent
.packet
);
4848 NetState
:= NET_STATE_NONE
;
4852 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4853 gPlayer1
.UID
:= NetPlrUID1
;
4854 gPlayer1
.Reset(True);
4856 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4858 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4860 enet_packet_destroy(NetEvent
.packet
);
4861 NetState
:= NET_STATE_NONE
;
4869 enet_packet_destroy(NetEvent
.packet
);
4873 enet_packet_destroy(NetEvent
.packet
);
4877 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4880 if (NetEvent
.data
<= NET_DISC_MAX
) then
4881 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4882 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4889 ProcessLoading(true);
4891 if g_Net_UserRequestExit() then
4900 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4901 NetState
:= NET_STATE_NONE
;
4906 NetState
:= NET_STATE_GAME
;
4907 MC_SEND_FullStateRequest
;
4908 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4912 lastAsMegaWad
: Boolean = false;
4914 procedure g_Game_ChangeMap(const MapPath
: String);
4918 g_Game_ClearLoading();
4920 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4921 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4922 if gExitByTrigger
then
4925 gExitByTrigger
:= False;
4927 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4928 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4931 procedure g_Game_Restart();
4935 if g_Game_IsClient
then
4937 map
:= g_ExtractFileName(gMapInfo
.Map
);
4938 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4942 g_Game_ClearLoading();
4943 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4946 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4948 NewWAD
, ResName
: String;
4952 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4953 g_Player_RemoveAllCorpses();
4955 if (not g_Game_IsClient
) and
4956 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4957 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4959 if gSwitchGameMode
= GM_CTF
then
4960 gGameSettings
.MaxLives
:= 0;
4961 gGameSettings
.GameMode
:= gSwitchGameMode
;
4964 gSwitchGameMode
:= gGameSettings
.GameMode
;
4966 g_Player_ResetTeams();
4968 lastAsMegaWad
:= asMegawad
;
4969 if isWadPath(Map
) then
4971 NewWAD
:= g_ExtractWadName(Map
);
4972 ResName
:= g_ExtractFileName(Map
);
4973 if g_Game_IsServer
then
4975 nws
:= findDiskWad(NewWAD
);
4976 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4979 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4980 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4984 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4985 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4987 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4988 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4990 if (length(nws
) = 0) then
4992 ResName
:= ''; // failed
4997 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4998 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4999 g_Game_LoadWAD(NewWAD
);
5004 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5005 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5010 NewWAD
:= gGameSettings
.WAD
;
5016 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5018 if (ResName
<> '') and (NewWAD
<> '') then
5020 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5021 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5025 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5027 gState
:= STATE_NONE
;
5028 g_ActiveWindow
:= nil;
5034 if gGameSettings
.GameMode
= GM_CTF
then
5036 g_Map_ResetFlag(FLAG_RED
);
5037 g_Map_ResetFlag(FLAG_BLUE
);
5038 // CTF, à ôëàãîâ íåò:
5039 if not g_Map_HaveFlagPoints() then
5040 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5045 gState
:= STATE_MENU
;
5050 gPauseMain
:= false;
5051 gPauseHolmes
:= false;
5052 NetTimeToUpdate
:= 1;
5053 NetTimeToReliable
:= 0;
5054 NetTimeToMaster
:= NetMasterRate
;
5055 gSpectLatchPID1
:= 0;
5056 gSpectLatchPID2
:= 0;
5057 gMissionFailed
:= False;
5060 gCoopMonstersKilled
:= 0;
5061 gCoopSecretsFound
:= 0;
5063 gVoteInProgress
:= False;
5064 gVotePassed
:= False;
5070 if not gGameOn
then Exit
;
5072 g_Game_SpectateCenterView();
5074 if g_Game_IsServer
then
5076 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5078 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5079 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5080 gLMSSoftSpawn
:= True;
5081 if g_Game_IsNet
then
5082 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5086 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5087 gLMSRespawnTime
:= 0;
5091 if NetMode
= NET_SERVER
then
5093 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5096 g_Net_Slist_ServerMapStarted();
5098 if NetClients
<> nil then
5099 for I
:= 0 to High(NetClients
) do
5100 if NetClients
[I
].Used
then
5102 NetClients
[I
].Voted
:= False;
5103 if NetClients
[I
].RequestedFullUpdate
then
5105 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5106 NetClients
[I
].RequestedFullUpdate
:= False;
5110 g_Net_UnbanNonPermHosts();
5115 gCoopTotalMonstersKilled
:= 0;
5116 gCoopTotalSecretsFound
:= 0;
5117 gCoopTotalMonsters
:= 0;
5118 gCoopTotalSecrets
:= 0;
5122 g_Game_ExecuteEvent('onmapstart');
5125 procedure SetFirstLevel
;
5129 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5130 if MapList
= nil then
5133 SortSArray(MapList
);
5134 gNextMap
:= MapList
[Low(MapList
)];
5139 procedure g_Game_ExitLevel(const Map
: AnsiString);
5143 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5144 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5145 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5146 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5148 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5149 if gGameSettings
.GameType
= GT_SINGLE
then
5150 gExit
:= EXIT_ENDLEVELSINGLE
5151 else // Âûøëè â âûõîä â Ñâîåé èãðå
5153 gExit
:= EXIT_ENDLEVELCUSTOM
;
5154 if gGameSettings
.GameMode
= GM_COOP
then
5155 g_Player_RememberAll
;
5157 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5160 if gGameSettings
.GameMode
= GM_COOP
then
5163 gStatsPressed
:= True;
5164 gNextMap
:= 'MAP01';
5166 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5169 if g_Game_IsNet
then
5171 MH_SEND_GameStats();
5172 MH_SEND_CoopStats();
5178 procedure g_Game_RestartLevel();
5182 if gGameSettings
.GameMode
= GM_SINGLE
then
5187 gExit
:= EXIT_ENDLEVELCUSTOM
;
5188 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5192 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5194 gWAD
{, xwad}: String;
5197 if not g_Game_IsClient
then Exit
;
5198 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5200 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5205 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5209 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5212 g_Game_LoadWAD(NewWAD
);
5216 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5217 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5220 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5221 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5225 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5229 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5230 g_Game_LoadWAD(NewWAD);
5234 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5236 i
, n
, nb
, nr
: Integer;
5238 if not g_Game_IsServer
then Exit
;
5239 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5240 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5241 gLMSRespawnTime
:= 0;
5244 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5246 gMissionFailed
:= True;
5247 g_Game_RestartLevel
;
5251 n
:= 0; nb
:= 0; nr
:= 0;
5252 for i
:= Low(gPlayers
) to High(gPlayers
) do
5253 if (gPlayers
[i
] <> nil) and
5254 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5255 (gPlayers
[i
] is TBot
)) then
5258 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5259 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5262 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5264 // wait a second until the fuckers finally decide to join
5265 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5266 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5267 gLMSSoftSpawn
:= NoMapRestart
;
5268 if g_Game_IsNet
then
5269 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5273 g_Player_RemoveAllCorpses
;
5274 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5275 if g_Game_IsNet
then
5276 MH_SEND_GameEvent(NET_EV_LMS_START
);
5278 for i
:= Low(gPlayers
) to High(gPlayers
) do
5280 if gPlayers
[i
] = nil then continue
;
5281 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5282 // don't touch normal spectators
5283 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5285 gPlayers
[i
].FNoRespawn
:= True;
5286 gPlayers
[i
].Lives
:= 0;
5287 if g_Game_IsNet
then
5288 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5291 gPlayers
[i
].FNoRespawn
:= False;
5292 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5293 gPlayers
[i
].Respawn(False, True);
5294 if gGameSettings
.GameMode
= GM_COOP
then
5296 gPlayers
[i
].Frags
:= 0;
5297 gPlayers
[i
].RecallState
;
5299 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5300 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5301 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5302 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5305 g_Items_RestartRound();
5307 gLMSSoftSpawn
:= False;
5310 function g_Game_GetFirstMap(WAD
: String): String;
5314 MapList
:= g_Map_GetMapsList(WAD
);
5315 if MapList
= nil then
5318 SortSArray(MapList
);
5319 Result
:= MapList
[Low(MapList
)];
5321 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5327 function g_Game_GetNextMap(): String;
5334 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5335 if MapList
= nil then
5338 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5340 SortSArray(MapList
);
5342 for I
:= Low(MapList
) to High(MapList
) do
5343 if Map
= MapList
[I
] then
5349 if MapIndex
<> -255 then
5351 if MapIndex
= High(MapList
) then
5352 Result
:= MapList
[Low(MapList
)]
5354 Result
:= MapList
[MapIndex
+ 1];
5356 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5362 procedure g_Game_NextLevel();
5364 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5365 gExit
:= EXIT_ENDLEVELCUSTOM
5368 gExit
:= EXIT_ENDLEVELSINGLE
;
5372 if gNextMap
<> '' then Exit
;
5373 gNextMap
:= g_Game_GetNextMap();
5376 function g_Game_IsTestMap(): Boolean;
5378 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5381 procedure g_Game_DeleteTestMap();
5384 //MapName: AnsiString;
5392 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5393 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5394 if (a
= 0) then exit
;
5396 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5397 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5398 Delete(gMapToDelete
, 1, a
+5);
5399 gMapToDelete
:= UpperCase(gMapToDelete
);
5401 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5404 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5405 if MapName <> TEST_MAP_NAME then
5408 if not gTempDelete then
5410 time := g_GetFileTime(WadName);
5411 WAD := TWADFile.Create();
5414 if not WAD.ReadFile(WadName) then
5415 begin // Íåò òàêîãî WAD-ôàéëà
5420 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5422 MapList := WAD.GetResourcesList('');
5424 if MapList <> nil then
5425 for a := 0 to High(MapList) do
5426 if MapList[a] = MapName then
5428 // Óäàëÿåì è ñîõðàíÿåì:
5429 WAD.RemoveResource('', MapName);
5430 WAD.SaveTo(WadName);
5435 g_SetFileTime(WadName, time);
5438 if gTempDelete
then DeleteFile(WadName
);
5441 procedure GameCVars(P
: SSArray
);
5444 stat
: TPlayerStatArray
;
5447 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5451 if Length(P
) > 1 then
5456 gsGameFlags
:= gsGameFlags
or Flag
5458 gsGameFlags
:= gsGameFlags
and (not Flag
);
5460 if g_Game_IsServer
then
5463 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5465 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5466 if g_Game_IsNet
then MH_SEND_GameSettings
;
5470 if LongBool(gsGameFlags
and Flag
) then
5471 g_Console_Add(_lc
[OnMsg
])
5473 g_Console_Add(_lc
[OffMsg
]);
5475 if OnMapChange
and g_Game_IsServer
then
5476 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5481 cmd
:= LowerCase(P
[0]);
5483 if cmd
= 'g_gamemode' then
5485 if (Length(P
) > 1) then
5487 a
:= g_Game_TextToMode(P
[1]);
5488 if a
= GM_SINGLE
then a
:= GM_COOP
;
5489 gsGameMode
:= g_Game_ModeToText(a
);
5490 if g_Game_IsServer
then
5492 gSwitchGameMode
:= a
;
5493 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5494 (gState
= STATE_INTERSINGLE
) then
5495 gSwitchGameMode
:= GM_SINGLE
;
5497 gGameSettings
.GameMode
:= gSwitchGameMode
;
5501 if gSwitchGameMode
= gGameSettings
.GameMode
then
5502 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5503 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5505 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5506 [g_Game_ModeToText(gGameSettings
.GameMode
),
5507 g_Game_ModeToText(gSwitchGameMode
)]));
5509 else if cmd
= 'g_friendlyfire' then
5511 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5513 else if cmd
= 'g_weaponstay' then
5515 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5517 else if cmd
= 'g_allow_exit' then
5519 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5521 else if cmd
= 'g_allow_monsters' then
5523 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5525 else if cmd
= 'g_bot_vsplayers' then
5527 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5529 else if cmd
= 'g_bot_vsmonsters' then
5531 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5533 else if cmd
= 'g_dm_keys' then
5535 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5537 else if cmd
= 'g_gameflags' then
5539 if Length(P
) > 1 then
5541 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5542 if g_Game_IsServer
then
5544 gGameSettings
.Options
:= gsGameFlags
;
5545 if g_Game_IsNet
then MH_SEND_GameSettings
;
5549 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5551 else if cmd
= 'g_warmup_time' then
5553 if Length(P
) > 1 then
5555 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5556 if g_Game_IsServer
then
5558 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5559 // extend warmup if it's already going
5560 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5562 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5563 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5565 if g_Game_IsNet
then MH_SEND_GameSettings
;
5569 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5570 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5572 else if cmd
= 'g_spawn_invul' then
5574 if Length(P
) > 1 then
5576 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5577 if g_Game_IsServer
then
5579 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5580 if g_Game_IsNet
then MH_SEND_GameSettings
;
5584 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5586 else if cmd
= 'g_item_respawn_time' then
5588 if Length(P
) > 1 then
5590 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5591 if g_Game_IsServer
then
5593 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5594 if g_Game_IsNet
then MH_SEND_GameSettings
;
5598 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5599 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5601 else if cmd
= 'sv_intertime' then
5603 if (Length(P
) > 1) then
5604 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5606 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5608 else if cmd
= 'g_max_particles' then
5610 if Length(p
) = 2 then
5612 a
:= Max(0, StrToInt(p
[1]));
5615 else if Length(p
) = 1 then
5617 e_LogWritefln('%s', [g_GFX_GetMax()])
5621 e_LogWritefln('usage: %s <n>', [cmd
])
5624 else if cmd
= 'g_max_shells' then
5626 if Length(p
) = 2 then
5628 a
:= Max(0, StrToInt(p
[1]));
5631 else if Length(p
) = 1 then
5633 e_LogWritefln('%s', [g_Shells_GetMax()])
5637 e_LogWritefln('usage: %s <n>', [cmd
])
5640 else if cmd
= 'g_max_gibs' then
5642 if Length(p
) = 2 then
5644 a
:= Max(0, StrToInt(p
[1]));
5647 else if Length(p
) = 1 then
5649 e_LogWritefln('%s', [g_Gibs_GetMax()])
5653 e_LogWritefln('usage: %s <n>', [cmd
])
5656 else if cmd
= 'g_max_corpses' then
5658 if Length(p
) = 2 then
5660 a
:= Max(0, StrToInt(p
[1]));
5663 else if Length(p
) = 1 then
5665 e_LogWritefln('%s', [g_Corpses_GetMax()])
5669 e_LogWritefln('usage: %s <n>', [cmd
])
5672 else if cmd
= 'g_scorelimit' then
5674 if Length(P
) > 1 then
5676 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5678 if g_Game_IsServer
then
5681 if gGameSettings
.GameMode
= GM_DM
then
5683 stat
:= g_Player_GetStats();
5685 for a
:= 0 to High(stat
) do
5686 if stat
[a
].Frags
> b
then
5690 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5692 // if someone has a higher score, set it to that instead
5693 gsGoalLimit
:= max(gsGoalLimit
, b
);
5694 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5696 if g_Game_IsNet
then MH_SEND_GameSettings
;
5700 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5702 else if cmd
= 'g_timelimit' then
5704 if Length(P
) > 1 then
5706 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5707 if g_Game_IsServer
then
5709 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5710 if g_Game_IsNet
then MH_SEND_GameSettings
;
5713 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5714 [gsTimeLimit
div 3600,
5715 (gsTimeLimit
div 60) mod 60,
5716 gsTimeLimit
mod 60]));
5718 else if cmd
= 'g_maxlives' then
5720 if Length(P
) > 1 then
5722 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5723 if g_Game_IsServer
then
5725 gGameSettings
.MaxLives
:= gsMaxLives
;
5726 if g_Game_IsNet
then MH_SEND_GameSettings
;
5730 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5734 procedure PlayerSettingsCVars(P
: SSArray
);
5738 cmd
:= LowerCase(P
[0]);
5742 if (Length(P
) > 1) then
5744 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5745 if g_Game_IsClient
then
5746 MC_SEND_PlayerSettings
5747 else if gGameOn
and (gPlayer1
<> nil) then
5749 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5750 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5756 if (Length(P
) > 1) then
5758 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5759 if g_Game_IsClient
then
5760 MC_SEND_PlayerSettings
5761 else if gGameOn
and (gPlayer2
<> nil) then
5763 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5764 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5770 if Length(P
) > 3 then
5772 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5773 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5774 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5775 if g_Game_IsClient
then
5776 MC_SEND_PlayerSettings
5777 else if gGameOn
and (gPlayer1
<> nil) then
5779 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5780 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5786 if Length(P
) > 3 then
5788 gPlayer2Settings
.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));
5791 if g_Game_IsClient
then
5792 MC_SEND_PlayerSettings
5793 else if gGameOn
and (gPlayer2
<> nil) then
5795 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5796 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5802 if (Length(P
) > 1) then
5804 gPlayer1Settings
.Model
:= P
[1];
5805 if g_Game_IsClient
then
5806 MC_SEND_PlayerSettings
5807 else if gGameOn
and (gPlayer1
<> nil) then
5809 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5810 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5811 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5817 if (Length(P
) > 1) then
5819 gPlayer2Settings
.Model
:= P
[1];
5820 if g_Game_IsClient
then
5821 MC_SEND_PlayerSettings
5822 else if gGameOn
and (gPlayer2
<> nil) then
5824 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5825 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5826 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5833 procedure PrintHeapStats();
5837 hs
:= GetFPCHeapStatus();
5838 e_LogWriteLn ('v===== heap status =====v');
5839 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5840 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5841 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5842 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5843 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5844 e_LogWriteLn ('^=======================^');
5847 procedure DebugCommands(P
: SSArray
);
5854 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5855 if {gDebugMode}conIsCheatsEnabled
then
5857 cmd
:= LowerCase(P
[0]);
5858 if cmd
= 'd_window' then
5860 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5861 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5863 else if cmd
= 'd_sounds' then
5865 if (Length(P
) > 1) and
5866 ((P
[1] = '1') or (P
[1] = '0')) then
5867 g_Debug_Sounds
:= (P
[1][1] = '1');
5869 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5871 else if cmd
= 'd_frames' then
5873 if (Length(P
) > 1) and
5874 ((P
[1] = '1') or (P
[1] = '0')) then
5875 g_Debug_Frames
:= (P
[1][1] = '1');
5877 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5879 else if cmd
= 'd_winmsg' then
5881 if (Length(P
) > 1) and
5882 ((P
[1] = '1') or (P
[1] = '0')) then
5883 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5885 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5887 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5889 if (Length(P
) > 1) and
5890 ((P
[1] = '1') or (P
[1] = '0')) then
5891 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5893 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5895 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5897 if Length(P
) > 1 then
5899 '0': g_debug_BotAIOff
:= 0;
5900 '1': g_debug_BotAIOff
:= 1;
5901 '2': g_debug_BotAIOff
:= 2;
5902 '3': g_debug_BotAIOff
:= 3;
5905 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5907 else if cmd
= 'd_monster' then
5909 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5910 if Length(P
) < 2 then
5912 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5913 g_Console_Add('ID | Name');
5914 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5915 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5916 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5919 a
:= StrToIntDef(P
[1], 0);
5920 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5921 a
:= g_Mons_TypeIdByName(P
[1]);
5923 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5924 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5927 with gPlayer1
.Obj
do
5929 mon
:= g_Monsters_Create(a
,
5930 X
+ Rect
.X
+ (Rect
.Width
div 2),
5931 Y
+ Rect
.Y
+ Rect
.Height
,
5932 gPlayer1
.Direction
, True);
5934 if (Length(P
) > 2) and (mon
<> nil) then
5936 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5937 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5938 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5939 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5940 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5941 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5942 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5943 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5944 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5949 else if (cmd
= 'd_health') then
5951 if (Length(P
) > 1) and
5952 ((P
[1] = '1') or (P
[1] = '0')) then
5953 g_debug_HealthBar
:= (P
[1][1] = '1');
5955 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5957 else if (cmd
= 'd_player') then
5959 if (Length(P
) > 1) and
5960 ((P
[1] = '1') or (P
[1] = '0')) then
5961 g_debug_Player
:= (P
[1][1] = '1');
5963 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5965 else if (cmd
= 'd_mem') then
5971 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5975 procedure GameCheats(P
: SSArray
);
5981 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5983 g_Console_Add('not available');
5989 g_Console_Add('where is the player?!');
5992 cmd
:= LowerCase(P
[0]);
5996 plr
.GodMode
:= not plr
.GodMode
;
5997 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6000 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6001 if cmd
= 'give' then
6003 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6004 for f
:= 1 to High(P
) do
6006 cmd
:= LowerCase(P
[f
]);
6007 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6008 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6009 if cmd
= 'exit' then
6011 if gTriggers
<> nil then
6013 for a
:= 0 to High(gTriggers
) do
6015 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6017 g_Console_Add('player left the map');
6018 gExitByTrigger
:= True;
6019 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6020 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6028 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6029 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6030 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6031 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6032 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6034 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6035 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6037 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6038 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;
6040 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6041 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6043 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6044 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6046 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6047 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6049 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6050 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6051 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6053 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6054 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6055 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6056 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;
6057 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6058 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6060 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;
6061 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;
6062 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;
6063 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;
6064 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;
6065 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;
6067 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6068 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;
6070 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;
6071 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;
6073 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6075 if cmd
= 'ammo' then
6077 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6078 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6079 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6080 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6081 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6082 g_Console_Add('player got some ammo');
6086 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6087 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6089 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6090 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6092 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6093 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6095 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6096 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6098 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6100 if cmd
= 'weapons' then
6102 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6103 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6104 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6105 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6106 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6107 plr
.GiveItem(ITEM_WEAPON_BFG
);
6108 g_Console_Add('player got weapons');
6112 if cmd
= 'keys' then
6114 plr
.GiveItem(ITEM_KEY_RED
);
6115 plr
.GiveItem(ITEM_KEY_GREEN
);
6116 plr
.GiveItem(ITEM_KEY_BLUE
);
6117 g_Console_Add('player got all keys');
6121 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6126 if cmd
= 'open' then
6128 g_Console_Add('player activated sesame');
6129 g_Triggers_OpenAll();
6136 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6140 if cmd
= 'noclip' then
6143 g_Console_Add('wall hardeness adjusted');
6147 if cmd
= 'notarget' then
6149 plr
.NoTarget
:= not plr
.NoTarget
;
6150 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6154 if cmd
= 'noreload' then
6156 plr
.NoReload
:= not plr
.NoReload
;
6157 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6161 if cmd
= 'speedy' then
6163 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6164 g_Console_Add('speed adjusted');
6168 if cmd
= 'jumpy' then
6170 VEL_JUMP
:= 30-VEL_JUMP
;
6171 g_Console_Add('jump height adjusted');
6175 if cmd
= 'automap' then
6177 gShowMap
:= not gShowMap
;
6178 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6182 if cmd
= 'aimline' then
6184 gAimLine
:= not gAimLine
;
6185 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6190 procedure GameCommands(P
: SSArray
);
6196 pl
: pTNetClient
= nil;
6204 cmd
:= LowerCase(P
[0]);
6206 if cmd
= 'pause' then
6208 if (g_ActiveWindow
= nil) then
6209 g_Game_Pause(not gPauseMain
);
6211 else if cmd
= 'endgame' then
6212 gExit
:= EXIT_SIMPLE
6213 else if cmd
= 'restart' then
6215 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6217 if g_Game_IsClient
then
6219 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6224 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6226 else if cmd
= 'kick' then
6228 if g_Game_IsServer
then
6230 if Length(P
) < 2 then
6232 g_Console_Add('kick <name>');
6237 g_Console_Add('kick <name>');
6241 if g_Game_IsNet
then
6242 pl
:= g_Net_Client_ByName(P
[1]);
6245 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6246 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6247 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6248 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6249 g_Net_Slist_ServerPlayerLeaves();
6250 end else if gPlayers
<> nil then
6251 for a
:= Low(gPlayers
) to High(gPlayers
) do
6252 if gPlayers
[a
] <> nil then
6253 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6255 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6256 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6258 gPlayers
[a
].Lives
:= 0;
6259 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6260 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6261 g_Player_Remove(gPlayers
[a
].UID
);
6262 g_Net_Slist_ServerPlayerLeaves();
6263 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6267 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6269 else if cmd
= 'kick_id' then
6271 if g_Game_IsServer
and g_Game_IsNet
then
6273 if Length(P
) < 2 then
6275 g_Console_Add('kick_id <client ID>');
6280 g_Console_Add('kick_id <client ID>');
6284 a
:= StrToIntDef(P
[1], 0);
6285 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6287 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6289 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6290 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6291 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6292 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6293 g_Net_Slist_ServerPlayerLeaves();
6297 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6299 else if cmd
= 'kick_pid' then
6301 if g_Game_IsServer
and g_Game_IsNet
then
6303 if Length(P
) < 2 then
6305 g_Console_Add('kick_pid <player ID>');
6310 g_Console_Add('kick_pid <player ID>');
6314 a
:= StrToIntDef(P
[1], 0);
6315 pl
:= g_Net_Client_ByPlayer(a
);
6316 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6318 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6319 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6320 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6321 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6322 g_Net_Slist_ServerPlayerLeaves();
6325 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6327 else if cmd
= 'ban' then
6329 if g_Game_IsServer
and g_Game_IsNet
then
6331 if Length(P
) < 2 then
6333 g_Console_Add('ban <name>');
6338 g_Console_Add('ban <name>');
6342 pl
:= g_Net_Client_ByName(P
[1]);
6345 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6346 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6347 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6348 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6349 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6350 g_Net_Slist_ServerPlayerLeaves();
6352 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6354 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6356 else if cmd
= 'ban_id' then
6358 if g_Game_IsServer
and g_Game_IsNet
then
6360 if Length(P
) < 2 then
6362 g_Console_Add('ban_id <client ID>');
6367 g_Console_Add('ban_id <client ID>');
6371 a
:= StrToIntDef(P
[1], 0);
6372 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6373 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6375 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6376 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6377 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6378 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6379 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6380 g_Net_Slist_ServerPlayerLeaves();
6383 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6385 else if cmd
= 'ban_pid' then
6387 if g_Game_IsServer
and g_Game_IsNet
then
6389 if Length(P
) < 2 then
6391 g_Console_Add('ban_pid <player ID>');
6396 g_Console_Add('ban_pid <player ID>');
6400 a
:= StrToIntDef(P
[1], 0);
6401 pl
:= g_Net_Client_ByPlayer(a
);
6402 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6404 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6405 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6406 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6407 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6408 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6409 g_Net_Slist_ServerPlayerLeaves();
6412 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6414 else if cmd
= 'permban' then
6416 if g_Game_IsServer
and g_Game_IsNet
then
6418 if Length(P
) < 2 then
6420 g_Console_Add('permban <name>');
6425 g_Console_Add('permban <name>');
6429 pl
:= g_Net_Client_ByName(P
[1]);
6432 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6433 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6434 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6435 g_Net_SaveBanList();
6436 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6437 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6438 g_Net_Slist_ServerPlayerLeaves();
6440 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6442 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6444 else if cmd
= 'permban_id' then
6446 if g_Game_IsServer
and g_Game_IsNet
then
6448 if Length(P
) < 2 then
6450 g_Console_Add('permban_id <client ID>');
6455 g_Console_Add('permban_id <client ID>');
6459 a
:= StrToIntDef(P
[1], 0);
6460 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6461 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6463 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6464 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6465 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6466 g_Net_SaveBanList();
6467 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6468 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6469 g_Net_Slist_ServerPlayerLeaves();
6472 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6474 else if cmd
= 'permban_pid' then
6476 if g_Game_IsServer
and g_Game_IsNet
then
6478 if Length(P
) < 2 then
6480 g_Console_Add('permban_pid <player ID>');
6485 g_Console_Add('permban_pid <player ID>');
6489 a
:= StrToIntDef(P
[1], 0);
6490 pl
:= g_Net_Client_ByPlayer(a
);
6491 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6493 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6494 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6495 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6496 g_Net_SaveBanList();
6497 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6498 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6499 g_Net_Slist_ServerPlayerLeaves();
6502 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6504 else if cmd
= 'permban_ip' then
6506 if g_Game_IsServer
and g_Game_IsNet
then
6508 if Length(P
) < 2 then
6510 g_Console_Add('permban_ip <IP address>');
6515 g_Console_Add('permban_ip <IP address>');
6519 g_Net_BanHost(P
[1]);
6520 g_Net_SaveBanList();
6521 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6523 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6525 else if cmd
= 'unban' then
6527 if g_Game_IsServer
and g_Game_IsNet
then
6529 if Length(P
) < 2 then
6531 g_Console_Add('unban <IP Address>');
6536 g_Console_Add('unban <IP Address>');
6540 if g_Net_UnbanHost(P
[1]) then
6542 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6543 g_Net_SaveBanList();
6545 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6547 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6549 else if cmd
= 'clientlist' then
6551 if g_Game_IsServer
and g_Game_IsNet
then
6554 if NetClients
<> nil then
6555 for a
:= Low(NetClients
) to High(NetClients
) do
6556 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6558 plr
:= g_Player_Get(NetClients
[a
].Player
);
6559 if plr
= nil then continue
;
6561 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6562 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6565 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6567 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6569 else if cmd
= 'connect' then
6571 if (NetMode
= NET_NONE
) then
6573 if Length(P
) < 2 then
6575 g_Console_Add('connect <IP> [port] [password]');
6580 g_Console_Add('connect <IP> [port] [password]');
6584 if Length(P
) > 2 then
6585 prt
:= StrToIntDef(P
[2], 25666)
6589 if Length(P
) > 3 then
6594 g_Game_StartClient(P
[1], prt
, pw
);
6597 else if cmd
= 'disconnect' then
6599 if (NetMode
= NET_CLIENT
) then
6602 else if cmd
= 'reconnect' then
6604 if (NetMode
= NET_SERVER
) then
6607 if (NetMode
= NET_CLIENT
) then
6610 gExit
:= EXIT_SIMPLE
;
6614 //TODO: Use last successful password to reconnect, instead of ''
6615 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6617 else if (cmd
= 'addbot') or
6618 (cmd
= 'bot_add') then
6620 if Length(P
) > 2 then
6621 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6622 else if Length(P
) > 1 then
6623 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6625 g_Bot_Add(TEAM_NONE
, 2);
6627 else if cmd
= 'bot_addlist' then
6629 if Length(P
) > 1 then
6631 if Length(P
) = 2 then
6632 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6633 else if Length(P
) = 3 then
6634 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6636 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6639 else if cmd
= 'bot_removeall' then
6641 else if cmd
= 'chat' then
6643 if g_Game_IsNet
then
6645 if Length(P
) > 1 then
6647 for a
:= 1 to High(P
) do
6648 chstr
:= chstr
+ P
[a
] + ' ';
6650 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6652 if Length(chstr
) < 1 then
6654 g_Console_Add('chat <text>');
6658 chstr
:= b_Text_Format(chstr
);
6659 if g_Game_IsClient
then
6660 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6662 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6665 g_Console_Add('chat <text>');
6667 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6669 else if cmd
= 'teamchat' then
6671 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6673 if Length(P
) > 1 then
6675 for a
:= 1 to High(P
) do
6676 chstr
:= chstr
+ P
[a
] + ' ';
6678 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6680 if Length(chstr
) < 1 then
6682 g_Console_Add('teamchat <text>');
6686 chstr
:= b_Text_Format(chstr
);
6687 if g_Game_IsClient
then
6688 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6690 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6691 gPlayer1Settings
.Team
);
6694 g_Console_Add('teamchat <text>');
6696 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6698 else if cmd
= 'game' then
6700 if gGameSettings
.GameType
<> GT_NONE
then
6702 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6705 if Length(P
) = 1 then
6707 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6710 // game not started yet, load fist map from some wad
6712 s
:= addWadExtension(P
[1]);
6713 found
:= e_FindResource(AllMapDirs
, s
);
6717 P
[1] := ExpandFileName(P
[1]);
6718 // if map not choosed then set first map
6719 if Length(P
) < 3 then
6722 P
[2] := g_Game_GetFirstMap(P
[1]);
6725 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6727 if g_Map_Exist(s
) then
6731 with gGameSettings
do
6733 Options
:= gsGameFlags
;
6734 GameMode
:= g_Game_TextToMode(gsGameMode
);
6735 if gSwitchGameMode
<> GM_NONE
then
6736 GameMode
:= gSwitchGameMode
;
6737 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6738 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6740 if Length(P
) >= 4 then
6741 b
:= StrToIntDef(P
[3], 1);
6742 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6743 GoalLimit
, MaxLives
, Options
, b
);
6748 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6750 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6752 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6754 else if cmd
= 'host' then
6756 if gGameSettings
.GameType
<> GT_NONE
then
6758 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6761 if Length(P
) < 4 then
6763 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6766 if not StrToIp(P
[1], listen
) then
6768 prt
:= StrToIntDef(P
[2], 25666);
6770 s
:= addWadExtension(P
[3]);
6771 found
:= e_FindResource(AllMapDirs
, s
);
6775 // get first map in wad, if not specified
6776 if Length(P
) < 5 then
6779 P
[4] := g_Game_GetFirstMap(P
[1]);
6781 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6782 if g_Map_Exist(s
) then
6786 with gGameSettings
do
6788 Options
:= gsGameFlags
;
6789 GameMode
:= g_Game_TextToMode(gsGameMode
);
6790 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6791 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6792 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6794 if Length(P
) >= 6 then
6795 b
:= StrToIntDef(P
[5], 0);
6796 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6802 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6804 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6809 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6812 else if cmd
= 'map' then
6814 if Length(P
) = 1 then
6816 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6818 g_Console_Add(cmd
+ ' <MAP>');
6819 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6823 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6828 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6830 if Length(P
) < 3 then
6832 // first param is map or wad
6833 s
:= UpperCase(P
[1]);
6834 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6836 gExitByTrigger
:= False;
6839 // already in game, finish current map
6841 gExit
:= EXIT_ENDLEVELCUSTOM
;
6845 // intermission, so change map immediately
6852 found
:= e_FindResource(AllMapDirs
, s
);
6854 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6857 // no such map, found wad
6860 P
[1] := ExpandFileName(pw
);
6861 P
[2] := g_Game_GetFirstMap(P
[1]);
6862 s
:= P
[1] + ':\' + P
[2];
6863 if g_Map_Exist(s
) then
6865 gExitByTrigger
:= False;
6868 // already in game, finish current map
6870 gExit
:= EXIT_ENDLEVELCUSTOM
6874 // intermission, so change map immediately
6881 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6883 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6888 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6894 s
:= addWadExtension(P
[1]);
6895 found
:= e_FindResource(AllMapDirs
, s
);
6899 P
[2] := UpperCase(P
[2]);
6900 s
:= P
[1] + ':\' + P
[2];
6901 if g_Map_Exist(s
) then
6903 gExitByTrigger
:= False;
6907 gExit
:= EXIT_ENDLEVELCUSTOM
6916 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6921 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6927 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6931 else if cmd
= 'nextmap' then
6933 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6935 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6940 if Length(P
) = 1 then
6942 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6944 g_Console_Add(cmd
+ ' <MAP>');
6945 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6950 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6956 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6958 if Length(P
) < 3 then
6960 // first param is map or wad
6961 s
:= UpperCase(P
[1]);
6962 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6965 gExitByTrigger
:= False;
6971 // no such map, found wad
6972 pw
:= addWadExtension(P
[1]);
6973 found
:= e_FindResource(MapDirs
, pw
);
6975 found
:= e_FindResource(WadDirs
, pw
);
6977 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6980 // map not specified, select first map
6982 P
[2] := g_Game_GetFirstMap(P
[1]);
6983 s
:= P
[1] + ':\' + P
[2];
6984 if g_Map_Exist(s
) then
6986 gExitByTrigger
:= False;
6993 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6995 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7000 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7006 // specified two params wad + map
7007 pw
:= addWadExtension(P
[1]);
7008 found
:= e_FindResource(MapDirs
, pw
);
7010 found
:= e_FindResource(MapDirs
, pw
);
7014 P
[2] := UpperCase(P
[2]);
7015 s
:= P
[1] + ':\' + P
[2];
7016 if g_Map_Exist(s
) then
7018 gExitByTrigger
:= False;
7024 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7029 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7035 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7040 if gNextMap
= '' then
7041 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7043 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7047 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7051 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7055 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7057 gExitByTrigger
:= False;
7058 // next map not specified, try to find trigger EXIT
7059 if (gNextMap
= '') and (gTriggers
<> nil) then
7061 for a
:= 0 to High(gTriggers
) do
7063 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7065 gExitByTrigger
:= True;
7066 //gNextMap := gTriggers[a].Data.MapName;
7067 gNextMap
:= gTriggers
[a
].tgcMap
;
7072 if gNextMap
= '' then
7073 gNextMap
:= g_Game_GetNextMap();
7074 if not isWadPath(gNextMap
) then
7075 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7078 if g_Map_Exist(s
) then
7079 gExit
:= EXIT_ENDLEVELCUSTOM
7081 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7085 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7089 else if (cmd
= 'event') then
7091 if (Length(P
) <= 1) then
7093 for a
:= 0 to High(gEvents
) do
7094 if gEvents
[a
].Command
= '' then
7095 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7097 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7100 if (Length(P
) = 2) then
7102 for a
:= 0 to High(gEvents
) do
7103 if gEvents
[a
].Name
= P
[1] then
7104 if gEvents
[a
].Command
= '' then
7105 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7107 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7110 for a
:= 0 to High(gEvents
) do
7111 if gEvents
[a
].Name
= P
[1] then
7113 gEvents
[a
].Command
:= '';
7114 for b
:= 2 to High(P
) do
7115 if Pos(' ', P
[b
]) = 0 then
7116 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7118 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7119 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7123 else if cmd
= 'suicide' then
7127 if g_Game_IsClient
then
7128 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7131 if gPlayer1
<> nil then
7132 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7133 if gPlayer2
<> nil then
7134 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7138 else if cmd
= 'screenshot' then
7142 else if cmd
= 'weapon' then
7144 if Length(p
) = 2 then
7146 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7147 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7148 gSelectWeapon
[0, a
] := True
7151 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7153 if Length(p
) = 2 then
7155 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7156 b
:= ord(cmd
[2]) - ord('1');
7157 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7158 gSelectWeapon
[b
, a
] := True
7161 // Êîìàíäû Ñâîåé èãðû:
7162 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7164 if cmd
= 'bot_addred' then
7166 if Length(P
) > 1 then
7167 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7169 g_Bot_Add(TEAM_RED
, 2);
7171 else if cmd
= 'bot_addblue' then
7173 if Length(P
) > 1 then
7174 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7176 g_Bot_Add(TEAM_BLUE
, 2);
7178 else if cmd
= 'spectate' then
7184 else if cmd
= 'say' then
7186 if g_Game_IsServer
and g_Game_IsNet
then
7188 if Length(P
) > 1 then
7191 for a
:= 1 to High(P
) do
7192 chstr
:= chstr
+ P
[a
] + ' ';
7194 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7196 if Length(chstr
) < 1 then
7198 g_Console_Add('say <text>');
7202 chstr
:= b_Text_Format(chstr
);
7203 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7205 else g_Console_Add('say <text>');
7207 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7209 else if cmd
= 'tell' then
7211 if g_Game_IsServer
and g_Game_IsNet
then
7213 if (Length(P
) > 2) and (P
[1] <> '') then
7216 for a
:= 2 to High(P
) do
7217 chstr
:= chstr
+ P
[a
] + ' ';
7219 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7221 if Length(chstr
) < 1 then
7223 g_Console_Add('tell <playername> <text>');
7227 pl
:= g_Net_Client_ByName(P
[1]);
7229 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7231 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7233 else g_Console_Add('tell <playername> <text>');
7235 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7237 else if cmd
= 'centerprint' then
7239 if (Length(P
) > 2) and (P
[1] <> '') then
7242 for a
:= 2 to High(P
) do
7243 chstr
:= chstr
+ P
[a
] + ' ';
7245 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7247 if Length(chstr
) < 1 then
7249 g_Console_Add('centerprint <timeout> <text>');
7253 a
:= StrToIntDef(P
[1], 100);
7254 chstr
:= b_Text_Format(chstr
);
7255 g_Game_Message(chstr
, a
);
7256 if g_Game_IsNet
and g_Game_IsServer
then
7257 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7259 else g_Console_Add('centerprint <timeout> <text>');
7261 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7263 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7265 // Äîïîëíèòåëüíîå âðåìÿ:
7266 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7268 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7269 [gGameSettings
.TimeLimit
div 3600,
7270 (gGameSettings
.TimeLimit
div 60) mod 60,
7271 gGameSettings
.TimeLimit
mod 60]));
7272 if g_Game_IsNet
then MH_SEND_GameSettings
;
7274 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7276 if (Length(P
) <= 1) then
7277 g_Console_Add('rcon_password <password>')
7279 MC_SEND_RCONPassword(P
[1]);
7281 else if cmd
= 'rcon' then
7283 if g_Game_IsClient
then
7285 if Length(P
) > 1 then
7288 for a
:= 1 to High(P
) do
7289 chstr
:= chstr
+ P
[a
] + ' ';
7291 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7293 if Length(chstr
) < 1 then
7295 g_Console_Add('rcon <command>');
7299 MC_SEND_RCONCommand(chstr
);
7301 else g_Console_Add('rcon <command>');
7304 else if cmd
= 'ready' then
7306 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7307 gLMSRespawnTime
:= gTime
+ 100;
7309 else if (cmd
= 'callvote') and g_Game_IsNet
then
7311 if Length(P
) > 1 then
7314 for a
:= 1 to High(P
) do begin
7315 if a
> 1 then chstr
:= chstr
+ ' ';
7316 chstr
:= chstr
+ P
[a
];
7319 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7321 if Length(chstr
) < 1 then
7323 g_Console_Add('callvote <command>');
7327 if g_Game_IsClient
then
7328 MC_SEND_Vote(True, chstr
)
7330 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7331 g_Console_Process('vote', True);
7334 g_Console_Add('callvote <command>');
7336 else if (cmd
= 'vote') and g_Game_IsNet
then
7338 if g_Game_IsClient
then
7340 else if gVoteInProgress
then
7342 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7343 a
:= Floor((NetClientCount
+1)/2.0) + 1
7345 a
:= Floor(NetClientCount
/2.0) + 1;
7350 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7351 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7357 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7358 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7366 procedure SystemCommands(P
: SSArray
);
7370 cmd
:= LowerCase(P
[0]);
7379 gRC_Width
:= Max(1, gRC_Width
);
7380 gRC_Height
:= Max(1, gRC_Height
);
7381 gBPP
:= Max(1, gBPP
);
7382 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7383 e_LogWriteln('resolution changed')
7385 e_LogWriteln('resolution not changed');
7386 sys_EnableVSync(gVSync
);
7390 if Length(p
) = 2 then
7392 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7394 gFrameTime
:= 1000 div gMaxFPS
7398 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7402 if Length(p
) = 2 then
7404 gAskLanguage
:= true;
7405 gLanguage
:= LANGUAGE_ENGLISH
;
7406 case LowerCase(p
[1]) of
7409 gAskLanguage
:= false;
7410 gLanguage
:= LANGUAGE_ENGLISH
;
7414 gAskLanguage
:= false;
7415 gLanguage
:= LANGUAGE_RUSSIAN
;
7419 gAskLanguage
:= true;
7420 gLanguage
:= LANGUAGE_ENGLISH
;
7423 g_Language_Set(gLanguage
);
7427 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7433 procedure g_TakeScreenShot(Filename
: string = '');
7434 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7436 if e_NoGraphics
then Exit
;
7438 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7440 if Filename
= '' then
7443 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7444 Filename
:= 'screenshot-' + date
;
7447 name
:= e_CatPath(dir
, Filename
+ '.png');
7448 s
:= createDiskFile(name
);
7450 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7452 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7454 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7459 g_Console_Add('oh shit, i can''t create screenshot!')
7463 procedure g_Game_InGameMenu(Show
: Boolean);
7465 if (g_ActiveWindow
= nil) and Show
then
7467 if gGameSettings
.GameType
= GT_SINGLE
then
7468 g_GUI_ShowWindow('GameSingleMenu')
7471 if g_Game_IsClient
then
7472 g_GUI_ShowWindow('GameClientMenu')
7474 if g_Game_IsNet
then
7475 g_GUI_ShowWindow('GameServerMenu')
7477 g_GUI_ShowWindow('GameCustomMenu');
7479 g_Sound_PlayEx('MENU_OPEN');
7481 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7482 if (not g_Game_IsNet
) then
7486 if (g_ActiveWindow
<> nil) and (not Show
) then
7488 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7489 if (not g_Game_IsNet
) then
7490 g_Game_Pause(False);
7494 procedure g_Game_Pause (Enable
: Boolean);
7498 if not gGameOn
then exit
;
7500 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7503 gPauseMain
:= Enable
;
7505 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7508 procedure g_Game_HolmesPause (Enable
: Boolean);
7512 if not gGameOn
then exit
;
7513 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7516 gPauseHolmes
:= Enable
;
7518 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7521 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7526 if gTriggers
<> nil then
7527 for i
:= 0 to High(gTriggers
) do
7528 with gTriggers
[i
] do
7529 if (TriggerType
= TRIGGER_SOUND
) and
7531 Sound
.IsPlaying() then
7533 Sound
.Pause(Enable
);
7537 if gPlayers
<> nil then
7538 for i
:= 0 to High(gPlayers
) do
7539 if gPlayers
[i
] <> nil then
7540 gPlayers
[i
].PauseSounds(Enable
);
7543 if gMusic
<> nil then
7544 gMusic
.Pause(Enable
);
7547 procedure g_Game_StopAllSounds(all
: Boolean);
7551 if gTriggers
<> nil then
7552 for i
:= 0 to High(gTriggers
) do
7553 with gTriggers
[i
] do
7554 if (TriggerType
= TRIGGER_SOUND
) and
7558 if gMusic
<> nil then
7565 procedure g_Game_UpdateTriggerSounds
;
7568 if gTriggers
<> nil then
7569 for i
:= 0 to High(gTriggers
) do
7570 with gTriggers
[i
] do
7571 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7572 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7575 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7578 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7583 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7588 if gSpectMode
<> SPECT_PLAYERS
then
7590 if gSpectPID1
= UID
then
7595 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7602 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7607 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7612 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7617 if gSpectMode
<> SPECT_PLAYERS
then
7619 Pl
:= g_Player_Get(gSpectPID1
);
7620 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7625 if gSpectViewTwo
then
7627 Pl
:= g_Player_Get(gSpectPID2
);
7628 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7636 procedure g_Game_Message(Msg
: string; Time
: Word);
7638 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7639 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7640 MessageTime
:= Time
;
7643 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7645 punct
: Array[0..13] of String =
7646 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7652 function IsPunctuation(S
: String): Boolean;
7657 if Length(S
) <> 1 then
7659 for i
:= Low(punct
) to High(punct
) do
7660 if S
= punct
[i
] then
7666 function FilterPunctuation(S
: String): String;
7670 for i
:= Low(punct
) to High(punct
) do
7671 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7677 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7679 // remove player name
7680 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7681 // for FullWord check
7682 Text := toLowerCase1251(' ' + Text + ' ');
7683 fpText
:= FilterPunctuation(Text);
7685 for i
:= 0 to Length(gChatSounds
) - 1 do
7688 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7690 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7691 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7693 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7699 gChatSounds
[i
].Sound
.Play();
7705 g_Sound_PlayEx('SOUND_GAME_RADIO');
7708 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7717 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7721 if goodsnd
[a
].IsPlaying() then
7724 goodsnd
[Random(4)].Play();
7727 procedure g_Game_Announce_KillCombo(Param
: Integer);
7734 UID
:= Param
and $FFFF;
7739 Pl
:= g_Player_Get(UID
);
7748 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7752 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7756 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7760 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7768 if not g_Game_IsWatchedPlayer(UID
) then
7771 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7775 if killsnd
[n
].IsPlaying() then
7780 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7788 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7792 if hahasnd
[a
].IsPlaying() then
7795 hahasnd
[Random(3)].Play();
7798 procedure g_Game_StartVote(Command
, Initiator
: string);
7802 if not gVotesEnabled
then Exit
;
7803 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7804 if gVoteInProgress
or gVotePassed
then
7806 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7807 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7810 gVoteInProgress
:= True;
7811 gVotePassed
:= False;
7812 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7815 gVoteCommand
:= Command
;
7817 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7818 Need
:= Floor((NetClientCount
+1)/2.0)+1
7820 Need
:= Floor(NetClientCount
/2.0)+1;
7821 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7822 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7825 procedure g_Game_CheckVote
;
7829 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7830 if not gVoteInProgress
then Exit
;
7832 if (gTime
>= gVoteTimer
) then
7834 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7835 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7837 Need
:= Floor(NetClientCount
/2.0) + 1;
7838 if gVoteCount
>= Need
then
7840 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7841 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7842 gVotePassed
:= True;
7843 gVoteCmdTimer
:= gTime
+ 5000;
7847 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7848 MH_SEND_VoteEvent(NET_VE_FAILED
);
7850 if NetClients
<> nil then
7851 for I
:= Low(NetClients
) to High(NetClients
) do
7852 if NetClients
[i
].Used
then
7853 NetClients
[i
].Voted
:= False;
7854 gVoteInProgress
:= False;
7860 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7861 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7863 Need
:= Floor(NetClientCount
/2.0) + 1;
7864 if gVoteCount
>= Need
then
7866 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7867 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7868 gVoteInProgress
:= False;
7869 gVotePassed
:= True;
7870 gVoteCmdTimer
:= gTime
+ 5000;
7873 if NetClients
<> nil then
7874 for I
:= Low(NetClients
) to High(NetClients
) do
7875 if NetClients
[i
].Used
then
7876 NetClients
[i
].Voted
:= False;
7881 procedure g_Game_LoadMapList(FileName
: string);
7889 if not FileExists(FileName
) then Exit
;
7891 AssignFile(ListFile
, FileName
);
7893 while not EOF(ListFile
) do
7895 ReadLn(ListFile
, s
);
7898 if s
= '' then Continue
;
7900 SetLength(MapList
, Length(MapList
)+1);
7901 MapList
[High(MapList
)] := s
;
7903 CloseFile(ListFile
);
7906 procedure g_Game_SetDebugMode();
7909 // ×èòû (äàæå â ñâîåé èãðå):
7913 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7917 if Length(LoadingStat
.Msgs
) = 0 then
7923 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7924 if NextMsg
= Length(Msgs
) then
7926 for i
:= 0 to High(Msgs
)-1 do
7927 Msgs
[i
] := Msgs
[i
+1];
7935 Msgs
[NextMsg
-1] := Text;
7939 PBarWasHere
:= false;
7942 g_ActiveWindow
:= nil;
7944 ProcessLoading(true);
7947 procedure g_Game_StepLoading(Value
: Integer = -1);
7958 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7966 procedure g_Game_ClearLoading();
7975 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7976 if len
< 1 then len
:= 1;
7977 SetLength(Msgs
, len
);
7978 for len
:= Low(Msgs
) to High(Msgs
) do
7981 PBarWasHere
:= false;
7985 procedure Parse_Params(var pars
: TParamStrValues
);
7992 while i
<= ParamCount
do
7995 if (s
[1] = '-') and (Length(s
) > 1) then
7997 if (s
[2] = '-') and (Length(s
) > 2) then
7998 begin // Îäèíî÷íûé ïàðàìåòð
7999 SetLength(pars
, Length(pars
) + 1);
8000 with pars
[High(pars
)] do
8002 Name
:= LowerCase(s
);
8007 if (i
< ParamCount
) then
8008 begin // Ïàðàìåòð ñî çíà÷åíèåì
8010 SetLength(pars
, Length(pars
) + 1);
8011 with pars
[High(pars
)] do
8013 Name
:= LowerCase(s
);
8014 Value
:= LowerCase(ParamStr(i
));
8023 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8028 for i
:= 0 to High(pars
) do
8029 if pars
[i
].Name
= aName
then
8031 Result
:= pars
[i
].Value
;
8036 procedure g_Game_Process_Params();
8038 pars
: TParamStrValues
;
8041 LimT
, LimS
: Integer;
8052 s
:= Find_Param_Value(pars
, '--debug');
8055 g_Game_SetDebugMode();
8056 s
:= Find_Param_Value(pars
, '--netdump');
8061 // Connect when game loads
8062 ip
:= Find_Param_Value(pars
, '-connect');
8066 s
:= Find_Param_Value(pars
, '-port');
8067 if (s
= '') or not TryStrToInt(s
, Port
) then
8070 s
:= Find_Param_Value(pars
, '-pw');
8072 g_Game_StartClient(ip
, Port
, s
);
8076 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8079 gDefaultMegawadStart
:= s
;
8082 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8083 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8085 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8088 // Start map when game loads:
8089 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8090 if isWadPath(map
) then
8093 s
:= Find_Param_Value(pars
, '-gm');
8094 GMode
:= g_Game_TextToMode(s
);
8095 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8096 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8099 s
:= Find_Param_Value(pars
, '-limt');
8100 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8106 s
:= Find_Param_Value(pars
, '-lims');
8107 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8113 s
:= Find_Param_Value(pars
, '-lives');
8114 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8120 s
:= Find_Param_Value(pars
, '-opt');
8124 Opt
:= StrToIntDef(s
, 0);
8127 s
:= Find_Param_Value(pars
, '--close');
8131 // Override map to test:
8132 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8135 if e_IsValidResourceName(s
) then
8136 e_FindResource(AllMapDirs
, s
);
8137 gTestMap
:= ExpandFileName(s
);
8140 // Delete test map after play:
8141 s
:= Find_Param_Value(pars
, '--testdelete');
8144 //gMapToDelete := MapsDir + map;
8145 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8149 // Delete temporary WAD after play:
8150 s
:= Find_Param_Value(pars
, '--tempdelete');
8151 if (s
<> '') and (gTestMap
<> '') then
8153 gMapToDelete
:= gTestMap
;
8154 gTempDelete
:= True;
8157 // Number of players:
8158 s
:= Find_Param_Value(pars
, '-pl');
8160 n
:= DEFAULT_PLAYERS
8162 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8165 s
:= Find_Param_Value(pars
, '-port');
8166 if (s
= '') or not TryStrToInt(s
, Port
) then
8167 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8169 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8172 // Execute script when game loads:
8173 s
:= Find_Param_Value(pars
, '-exec');
8176 // if not isWadPath(s) then
8177 // s := GameDir + '/' + s;
8182 if IOResult
<> 0 then
8184 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8185 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8189 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8190 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8195 if IOResult
<> 0 then
8197 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8198 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8202 if Pos('#', s
) <> 1 then // script comment
8203 g_Console_Process(s
, True);
8214 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8215 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8216 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8217 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8219 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8220 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8221 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8222 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8224 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8225 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8227 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8228 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8230 {$IFDEF ENABLE_HOLMES}
8231 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8234 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8236 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8237 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8239 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8240 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8242 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8243 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8245 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8246 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8247 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8248 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8249 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8250 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8251 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8252 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8253 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');