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
= 1) then DrawStat();
4003 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4005 // Draw spectator GUI
4008 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4011 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4013 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4015 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4017 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4018 if gSpectMode
= SPECT_STATS
then
4020 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4023 if gSpectMode
= SPECT_MAPVIEW
then
4025 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4026 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4027 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4028 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4029 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4031 if gSpectMode
= SPECT_PLAYERS
then
4033 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4034 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4035 if gSpectViewTwo
then
4037 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4038 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4039 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4040 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4044 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4045 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4051 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4053 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4054 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4056 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4057 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4058 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4063 if (gState
= STATE_MENU
) then
4065 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4066 // F3 at menu will show game loading dialog
4067 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4068 if (g_ActiveWindow
<> nil) then
4070 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4071 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4075 // F3 at titlepic will show game loading dialog
4076 if e_KeyPressed(IK_F3
) then
4078 g_Menu_Show_LoadMenu(true);
4079 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4084 if gState
= STATE_FOLD
then
4086 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4089 if gState
= STATE_INTERCUSTOM
then
4091 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4093 back
:= 'TEXTURE_endpic';
4094 if not g_Texture_Get(back
, ID
) then
4095 back
:= _lc
[I_TEXTURE_ENDPIC
];
4100 DrawMenuBackground(back
);
4104 if g_ActiveWindow
<> nil then
4106 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4107 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4111 if gState
= STATE_INTERSINGLE
then
4113 if EndingGameCounter
> 0 then
4115 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4121 DrawMenuBackground(back
);
4125 if g_ActiveWindow
<> nil then
4127 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4128 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4133 if gState
= STATE_ENDPIC
then
4136 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4137 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4139 if g_ActiveWindow
<> nil then
4141 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4142 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4146 if gState
= STATE_SLIST
then
4148 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4150 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4151 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4153 DrawMenuBackground('MENU_BACKGROUND');
4154 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4155 g_Serverlist_Draw(slCurrent
, slTable
);
4159 if g_ActiveWindow
<> nil then
4163 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4164 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4166 g_ActiveWindow
.Draw();
4173 if g_debug_Sounds
and gGameOn
then
4175 for w
:= 0 to High(e_SoundsArray
) do
4176 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4177 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4182 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4183 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4186 if gGameOn
and gShowTime
then
4187 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4189 if gGameOn
then drawProfilers();
4191 // TODO: draw this after the FBO and remap mouse click coordinates
4193 {$IFDEF ENABLE_HOLMES}
4197 // blit framebuffer to screen
4199 e_SetRendertarget(False);
4200 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4201 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4203 // draw the overlay stuff on top of it
4208 procedure g_Game_Quit();
4210 g_Game_StopAllSounds(True);
4213 g_PlayerModel_FreeData();
4214 g_Texture_DeleteAll();
4215 g_Frames_DeleteAll();
4217 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4220 if NetInitDone
then g_Net_Free
;
4222 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4223 if gMapToDelete
<> '' then
4224 g_Game_DeleteTestMap();
4230 procedure g_FatalError(Text: String);
4232 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4233 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4235 gExit
:= EXIT_SIMPLE
;
4236 if gGameOn
then EndGame
;
4239 procedure g_SimpleError(Text: String);
4241 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4242 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4245 procedure g_Game_SetupScreenSize();
4247 RES_FACTOR
= 4.0 / 3.0;
4253 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4254 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4255 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4256 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4258 gPlayerScreenSize
.Y
:= gScreenHeight
;
4260 // Ðàçìåð çàäíåãî ïëàíà:
4261 if BackID
<> DWORD(-1) then
4264 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4265 (gScreenHeight
*s
> gMapInfo
.Height
) then
4267 gBackSize
.X
:= gScreenWidth
;
4268 gBackSize
.Y
:= gScreenHeight
;
4272 e_GetTextureSize(BackID
, @bw
, @bh
);
4273 rf
:= Single(bw
) / Single(bh
);
4274 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4275 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4276 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4277 if (s
< 1.0) then s
:= 1.0;
4278 gBackSize
.X
:= Round(bw
*s
);
4279 gBackSize
.Y
:= Round(bh
*s
);
4284 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4286 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4289 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4291 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4292 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4295 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4298 if gPlayer1
= nil then
4300 if g_Game_IsClient
then
4302 if NetPlrUID1
> -1 then
4303 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4307 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4308 Team
:= gPlayer1Settings
.Team
;
4310 // Ñîçäàíèå ïåðâîãî èãðîêà:
4311 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4312 gPlayer1Settings
.Color
,
4314 if gPlayer1
= nil then
4315 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4318 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4319 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4320 if g_Game_IsServer
and g_Game_IsNet
then
4321 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4322 gPlayer1
.Respawn(False, True);
4323 g_Net_Slist_ServerPlayerComes();
4328 if gPlayer2
= nil then
4330 if g_Game_IsClient
then
4332 if NetPlrUID2
> -1 then
4333 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4337 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4338 Team
:= gPlayer2Settings
.Team
;
4340 // Ñîçäàíèå âòîðîãî èãðîêà:
4341 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4342 gPlayer2Settings
.Color
,
4344 if gPlayer2
= nil then
4345 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4348 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4349 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4350 if g_Game_IsServer
and g_Game_IsNet
then
4351 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4352 gPlayer2
.Respawn(False, True);
4353 g_Net_Slist_ServerPlayerComes();
4360 procedure g_Game_RemovePlayer();
4364 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4365 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4370 if g_Game_IsServer
then
4373 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4374 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4375 g_Player_Remove(Pl
.UID
);
4376 g_Net_Slist_ServerPlayerLeaves();
4380 gSpectLatchPID2
:= Pl
.UID
;
4388 if g_Game_IsServer
then
4391 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4392 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4393 g_Player_Remove(Pl
.UID
);
4394 g_Net_Slist_ServerPlayerLeaves();
4397 gSpectLatchPID1
:= Pl
.UID
;
4399 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4403 g_Net_Slist_ServerPlayerLeaves();
4406 procedure g_Game_Spectate();
4408 g_Game_RemovePlayer();
4409 if gPlayer1
<> nil then
4410 g_Game_RemovePlayer();
4413 procedure g_Game_SpectateCenterView();
4415 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4416 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4419 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4426 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4428 g_Game_ClearLoading();
4431 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4434 gGameSettings
.GameType
:= GT_SINGLE
;
4435 gGameSettings
.MaxLives
:= 0;
4436 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4437 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4438 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4439 gSwitchGameMode
:= GM_SINGLE
;
4441 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4442 gLMSRespawnTime
:= 0;
4443 gSpectLatchPID1
:= 0;
4444 gSpectLatchPID2
:= 0;
4446 g_Game_ExecuteEvent('ongamestart');
4448 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4449 g_Game_SetupScreenSize();
4451 // Ñîçäàíèå ïåðâîãî èãðîêà:
4452 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4453 gPlayer1Settings
.Color
,
4454 gPlayer1Settings
.Team
, False));
4455 if gPlayer1
= nil then
4457 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4461 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4464 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4467 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4468 gPlayer2Settings
.Color
,
4469 gPlayer2Settings
.Team
, False));
4470 if gPlayer2
= nil then
4472 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4476 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4480 // Çàãðóçêà è çàïóñê êàðòû:
4481 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4483 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4484 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4488 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4492 for i
:= nPl
+1 to nPlayers
do
4493 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4496 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4497 TimeLimit
, GoalLimit
: Word;
4499 Options
: LongWord; nPlayers
: Byte);
4505 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4507 g_Game_ClearLoading();
4510 gGameSettings
.GameType
:= GT_CUSTOM
;
4511 gGameSettings
.GameMode
:= GameMode
;
4512 gSwitchGameMode
:= GameMode
;
4513 gGameSettings
.TimeLimit
:= TimeLimit
;
4514 gGameSettings
.GoalLimit
:= GoalLimit
;
4515 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4516 gGameSettings
.Options
:= Options
;
4518 gCoopTotalMonstersKilled
:= 0;
4519 gCoopTotalSecretsFound
:= 0;
4520 gCoopTotalMonsters
:= 0;
4521 gCoopTotalSecrets
:= 0;
4525 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4526 gLMSRespawnTime
:= 0;
4527 gSpectLatchPID1
:= 0;
4528 gSpectLatchPID2
:= 0;
4530 g_Game_ExecuteEvent('ongamestart');
4532 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4533 g_Game_SetupScreenSize();
4535 // Ðåæèì íàáëþäàòåëÿ:
4536 if nPlayers
= 0 then
4543 if nPlayers
>= 1 then
4545 // Ñîçäàíèå ïåðâîãî èãðîêà:
4546 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4547 gPlayer1Settings
.Color
,
4548 gPlayer1Settings
.Team
, False));
4549 if gPlayer1
= nil then
4551 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4555 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4559 if nPlayers
>= 2 then
4561 // Ñîçäàíèå âòîðîãî èãðîêà:
4562 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4563 gPlayer2Settings
.Color
,
4564 gPlayer2Settings
.Team
, False));
4565 if gPlayer2
= nil then
4567 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4571 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4575 // Çàãðóçêà è çàïóñê êàðòû:
4576 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4578 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4582 // Íåò òî÷åê ïîÿâëåíèÿ:
4583 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4584 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4585 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4586 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4587 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4589 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4593 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4597 for i
:= nPl
+1 to nPlayers
do
4598 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4601 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4602 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4603 Options
: LongWord; nPlayers
: Byte;
4604 IPAddr
: LongWord; Port
: Word);
4607 g_Net_Slist_ServerClosed();
4609 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4611 g_Game_ClearLoading();
4614 gGameSettings
.GameType
:= GT_SERVER
;
4615 gGameSettings
.GameMode
:= GameMode
;
4616 gSwitchGameMode
:= GameMode
;
4617 gGameSettings
.TimeLimit
:= TimeLimit
;
4618 gGameSettings
.GoalLimit
:= GoalLimit
;
4619 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4620 gGameSettings
.Options
:= Options
;
4622 gCoopTotalMonstersKilled
:= 0;
4623 gCoopTotalSecretsFound
:= 0;
4624 gCoopTotalMonsters
:= 0;
4625 gCoopTotalSecrets
:= 0;
4629 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4630 gLMSRespawnTime
:= 0;
4631 gSpectLatchPID1
:= 0;
4632 gSpectLatchPID2
:= 0;
4634 g_Game_ExecuteEvent('ongamestart');
4636 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4637 g_Game_SetupScreenSize();
4639 // Ðåæèì íàáëþäàòåëÿ:
4640 if nPlayers
= 0 then
4646 if nPlayers
>= 1 then
4648 // Ñîçäàíèå ïåðâîãî èãðîêà:
4649 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4650 gPlayer1Settings
.Color
,
4651 gPlayer1Settings
.Team
, False));
4652 if gPlayer1
= nil then
4654 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4658 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4661 if nPlayers
>= 2 then
4663 // Ñîçäàíèå âòîðîãî èãðîêà:
4664 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4665 gPlayer2Settings
.Color
,
4666 gPlayer2Settings
.Team
, False));
4667 if gPlayer2
= nil then
4669 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4673 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4676 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4677 if NetForwardPorts
then
4678 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4681 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4683 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4687 g_Net_Slist_Set(NetMasterList
);
4689 g_Net_Slist_ServerStarted();
4691 // Çàãðóçêà è çàïóñê êàðòû:
4692 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4694 g_Net_Slist_ServerClosed();
4695 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4699 // Íåò òî÷åê ïîÿâëåíèÿ:
4700 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4701 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4702 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4703 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4704 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4706 g_Net_Slist_ServerClosed();
4707 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4711 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4714 g_Net_Slist_ServerMapStarted();
4715 NetState
:= NET_STATE_GAME
;
4718 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4733 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4734 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4736 g_Game_ClearLoading();
4739 gGameSettings
.GameType
:= GT_CLIENT
;
4741 gCoopTotalMonstersKilled
:= 0;
4742 gCoopTotalSecretsFound
:= 0;
4743 gCoopTotalMonsters
:= 0;
4744 gCoopTotalSecrets
:= 0;
4748 g_Game_ExecuteEvent('ongamestart');
4750 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4751 g_Game_SetupScreenSize();
4753 NetState
:= NET_STATE_AUTH
;
4755 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4757 // create (or update) map/resource databases
4758 g_Res_CreateDatabases(true);
4760 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4761 gLMSRespawnTime
:= 0;
4762 gSpectLatchPID1
:= 0;
4763 gSpectLatchPID2
:= 0;
4766 if not g_Net_Connect(Addr
, Port
) then
4768 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4769 NetState
:= NET_STATE_NONE
;
4773 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4775 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4780 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4781 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4782 // thank you, enet. let's ignore failures altogether then.
4783 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4785 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4787 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4789 // ignore all download packets, they're processed by separate code
4790 enet_packet_destroy(NetEvent
.packet
);
4793 Ptr
:= NetEvent
.packet
^.data
;
4794 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4796 enet_packet_destroy(NetEvent
.packet
);
4800 InMsg
.ReadLongWord(); // skip size
4801 MID
:= InMsg
.ReadByte();
4803 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4805 NetMyID
:= InMsg
.ReadByte();
4806 NetPlrUID1
:= InMsg
.ReadWord();
4808 WadName
:= InMsg
.ReadString();
4809 Map
:= InMsg
.ReadString();
4811 gWADHash
:= InMsg
.ReadMD5();
4813 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4814 gSwitchGameMode
:= gGameSettings
.GameMode
;
4815 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4816 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4817 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4818 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4819 T
:= InMsg
.ReadLongWord();
4821 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4822 //if newResPath = '' then
4824 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4825 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4826 if newResPath
= '' then
4828 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4829 enet_packet_destroy(NetEvent
.packet
);
4830 NetState
:= NET_STATE_NONE
;
4833 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4835 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4838 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4839 gPlayer1Settings
.Color
,
4840 gPlayer1Settings
.Team
, False));
4842 if gPlayer1
= nil then
4844 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4846 enet_packet_destroy(NetEvent
.packet
);
4847 NetState
:= NET_STATE_NONE
;
4851 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4852 gPlayer1
.UID
:= NetPlrUID1
;
4853 gPlayer1
.Reset(True);
4855 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4857 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4859 enet_packet_destroy(NetEvent
.packet
);
4860 NetState
:= NET_STATE_NONE
;
4868 enet_packet_destroy(NetEvent
.packet
);
4872 enet_packet_destroy(NetEvent
.packet
);
4876 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4879 if (NetEvent
.data
<= NET_DISC_MAX
) then
4880 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4881 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4888 ProcessLoading(true);
4890 if g_Net_UserRequestExit() then
4899 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4900 NetState
:= NET_STATE_NONE
;
4905 NetState
:= NET_STATE_GAME
;
4906 MC_SEND_FullStateRequest
;
4907 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4911 lastAsMegaWad
: Boolean = false;
4913 procedure g_Game_ChangeMap(const MapPath
: String);
4917 g_Game_ClearLoading();
4919 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4920 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4921 if gExitByTrigger
then
4924 gExitByTrigger
:= False;
4926 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4927 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4930 procedure g_Game_Restart();
4934 if g_Game_IsClient
then
4936 map
:= g_ExtractFileName(gMapInfo
.Map
);
4937 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4941 g_Game_ClearLoading();
4942 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4945 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4947 NewWAD
, ResName
: String;
4951 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4952 g_Player_RemoveAllCorpses();
4954 if (not g_Game_IsClient
) and
4955 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4956 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4958 if gSwitchGameMode
= GM_CTF
then
4959 gGameSettings
.MaxLives
:= 0;
4960 gGameSettings
.GameMode
:= gSwitchGameMode
;
4963 gSwitchGameMode
:= gGameSettings
.GameMode
;
4965 g_Player_ResetTeams();
4967 lastAsMegaWad
:= asMegawad
;
4968 if isWadPath(Map
) then
4970 NewWAD
:= g_ExtractWadName(Map
);
4971 ResName
:= g_ExtractFileName(Map
);
4972 if g_Game_IsServer
then
4974 nws
:= findDiskWad(NewWAD
);
4975 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4978 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4979 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4983 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4984 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4986 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4987 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4989 if (length(nws
) = 0) then
4991 ResName
:= ''; // failed
4996 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4997 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4998 g_Game_LoadWAD(NewWAD
);
5003 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5004 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5009 NewWAD
:= gGameSettings
.WAD
;
5015 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5017 if (ResName
<> '') and (NewWAD
<> '') then
5019 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5020 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5024 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5026 gState
:= STATE_NONE
;
5027 g_ActiveWindow
:= nil;
5033 if gGameSettings
.GameMode
= GM_CTF
then
5035 g_Map_ResetFlag(FLAG_RED
);
5036 g_Map_ResetFlag(FLAG_BLUE
);
5037 // CTF, à ôëàãîâ íåò:
5038 if not g_Map_HaveFlagPoints() then
5039 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5044 gState
:= STATE_MENU
;
5049 gPauseMain
:= false;
5050 gPauseHolmes
:= false;
5051 NetTimeToUpdate
:= 1;
5052 NetTimeToReliable
:= 0;
5053 NetTimeToMaster
:= NetMasterRate
;
5054 gSpectLatchPID1
:= 0;
5055 gSpectLatchPID2
:= 0;
5056 gMissionFailed
:= False;
5059 gCoopMonstersKilled
:= 0;
5060 gCoopSecretsFound
:= 0;
5062 gVoteInProgress
:= False;
5063 gVotePassed
:= False;
5069 if not gGameOn
then Exit
;
5071 g_Game_SpectateCenterView();
5073 if g_Game_IsServer
then
5075 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5077 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5078 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5079 gLMSSoftSpawn
:= True;
5080 if g_Game_IsNet
then
5081 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5085 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5086 gLMSRespawnTime
:= 0;
5090 if NetMode
= NET_SERVER
then
5092 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5095 g_Net_Slist_ServerMapStarted();
5097 if NetClients
<> nil then
5098 for I
:= 0 to High(NetClients
) do
5099 if NetClients
[I
].Used
then
5101 NetClients
[I
].Voted
:= False;
5102 if NetClients
[I
].RequestedFullUpdate
then
5104 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5105 NetClients
[I
].RequestedFullUpdate
:= False;
5109 g_Net_UnbanNonPermHosts();
5114 gCoopTotalMonstersKilled
:= 0;
5115 gCoopTotalSecretsFound
:= 0;
5116 gCoopTotalMonsters
:= 0;
5117 gCoopTotalSecrets
:= 0;
5121 g_Game_ExecuteEvent('onmapstart');
5124 procedure SetFirstLevel
;
5128 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5129 if MapList
= nil then
5132 SortSArray(MapList
);
5133 gNextMap
:= MapList
[Low(MapList
)];
5138 procedure g_Game_ExitLevel(const Map
: AnsiString);
5142 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5143 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5144 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5145 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5147 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5148 if gGameSettings
.GameType
= GT_SINGLE
then
5149 gExit
:= EXIT_ENDLEVELSINGLE
5150 else // Âûøëè â âûõîä â Ñâîåé èãðå
5152 gExit
:= EXIT_ENDLEVELCUSTOM
;
5153 if gGameSettings
.GameMode
= GM_COOP
then
5154 g_Player_RememberAll
;
5156 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5159 if gGameSettings
.GameMode
= GM_COOP
then
5162 gStatsPressed
:= True;
5163 gNextMap
:= 'MAP01';
5165 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5168 if g_Game_IsNet
then
5170 MH_SEND_GameStats();
5171 MH_SEND_CoopStats();
5177 procedure g_Game_RestartLevel();
5181 if gGameSettings
.GameMode
= GM_SINGLE
then
5186 gExit
:= EXIT_ENDLEVELCUSTOM
;
5187 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5191 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5193 gWAD
{, xwad}: String;
5196 if not g_Game_IsClient
then Exit
;
5197 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5199 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5204 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5208 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5211 g_Game_LoadWAD(NewWAD
);
5215 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5216 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5219 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5220 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5224 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5228 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5229 g_Game_LoadWAD(NewWAD);
5233 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5235 i
, n
, nb
, nr
: Integer;
5237 if not g_Game_IsServer
then Exit
;
5238 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5239 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5240 gLMSRespawnTime
:= 0;
5243 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5245 gMissionFailed
:= True;
5246 g_Game_RestartLevel
;
5250 n
:= 0; nb
:= 0; nr
:= 0;
5251 for i
:= Low(gPlayers
) to High(gPlayers
) do
5252 if (gPlayers
[i
] <> nil) and
5253 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5254 (gPlayers
[i
] is TBot
)) then
5257 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5258 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5261 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5263 // wait a second until the fuckers finally decide to join
5264 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5265 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5266 gLMSSoftSpawn
:= NoMapRestart
;
5267 if g_Game_IsNet
then
5268 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5272 g_Player_RemoveAllCorpses
;
5273 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5274 if g_Game_IsNet
then
5275 MH_SEND_GameEvent(NET_EV_LMS_START
);
5277 for i
:= Low(gPlayers
) to High(gPlayers
) do
5279 if gPlayers
[i
] = nil then continue
;
5280 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5281 // don't touch normal spectators
5282 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5284 gPlayers
[i
].FNoRespawn
:= True;
5285 gPlayers
[i
].Lives
:= 0;
5286 if g_Game_IsNet
then
5287 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5290 gPlayers
[i
].FNoRespawn
:= False;
5291 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5292 gPlayers
[i
].Respawn(False, True);
5293 if gGameSettings
.GameMode
= GM_COOP
then
5295 gPlayers
[i
].Frags
:= 0;
5296 gPlayers
[i
].RecallState
;
5298 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5299 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5300 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5301 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5304 g_Items_RestartRound();
5306 gLMSSoftSpawn
:= False;
5309 function g_Game_GetFirstMap(WAD
: String): String;
5313 MapList
:= g_Map_GetMapsList(WAD
);
5314 if MapList
= nil then
5317 SortSArray(MapList
);
5318 Result
:= MapList
[Low(MapList
)];
5320 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5326 function g_Game_GetNextMap(): String;
5333 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5334 if MapList
= nil then
5337 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5339 SortSArray(MapList
);
5341 for I
:= Low(MapList
) to High(MapList
) do
5342 if Map
= MapList
[I
] then
5348 if MapIndex
<> -255 then
5350 if MapIndex
= High(MapList
) then
5351 Result
:= MapList
[Low(MapList
)]
5353 Result
:= MapList
[MapIndex
+ 1];
5355 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5361 procedure g_Game_NextLevel();
5363 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5364 gExit
:= EXIT_ENDLEVELCUSTOM
5367 gExit
:= EXIT_ENDLEVELSINGLE
;
5371 if gNextMap
<> '' then Exit
;
5372 gNextMap
:= g_Game_GetNextMap();
5375 function g_Game_IsTestMap(): Boolean;
5377 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5380 procedure g_Game_DeleteTestMap();
5383 //MapName: AnsiString;
5391 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5392 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5393 if (a
= 0) then exit
;
5395 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5396 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5397 Delete(gMapToDelete
, 1, a
+5);
5398 gMapToDelete
:= UpperCase(gMapToDelete
);
5400 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5403 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5404 if MapName <> TEST_MAP_NAME then
5407 if not gTempDelete then
5409 time := g_GetFileTime(WadName);
5410 WAD := TWADFile.Create();
5413 if not WAD.ReadFile(WadName) then
5414 begin // Íåò òàêîãî WAD-ôàéëà
5419 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5421 MapList := WAD.GetResourcesList('');
5423 if MapList <> nil then
5424 for a := 0 to High(MapList) do
5425 if MapList[a] = MapName then
5427 // Óäàëÿåì è ñîõðàíÿåì:
5428 WAD.RemoveResource('', MapName);
5429 WAD.SaveTo(WadName);
5434 g_SetFileTime(WadName, time);
5437 if gTempDelete
then DeleteFile(WadName
);
5440 procedure GameCVars(P
: SSArray
);
5443 stat
: TPlayerStatArray
;
5446 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5450 if Length(P
) > 1 then
5455 gsGameFlags
:= gsGameFlags
or Flag
5457 gsGameFlags
:= gsGameFlags
and (not Flag
);
5459 if g_Game_IsServer
then
5462 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5464 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5465 if g_Game_IsNet
then MH_SEND_GameSettings
;
5469 if LongBool(gsGameFlags
and Flag
) then
5470 g_Console_Add(_lc
[OnMsg
])
5472 g_Console_Add(_lc
[OffMsg
]);
5474 if OnMapChange
and g_Game_IsServer
then
5475 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5480 cmd
:= LowerCase(P
[0]);
5482 if cmd
= 'g_gamemode' then
5484 if (Length(P
) > 1) then
5486 a
:= g_Game_TextToMode(P
[1]);
5487 if a
= GM_SINGLE
then a
:= GM_COOP
;
5488 gsGameMode
:= g_Game_ModeToText(a
);
5489 if g_Game_IsServer
then
5491 gSwitchGameMode
:= a
;
5492 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5493 (gState
= STATE_INTERSINGLE
) then
5494 gSwitchGameMode
:= GM_SINGLE
;
5496 gGameSettings
.GameMode
:= gSwitchGameMode
;
5500 if gSwitchGameMode
= gGameSettings
.GameMode
then
5501 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5502 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5504 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5505 [g_Game_ModeToText(gGameSettings
.GameMode
),
5506 g_Game_ModeToText(gSwitchGameMode
)]));
5508 else if cmd
= 'g_friendlyfire' then
5510 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5512 else if cmd
= 'g_weaponstay' then
5514 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5516 else if cmd
= 'g_allow_exit' then
5518 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5520 else if cmd
= 'g_allow_monsters' then
5522 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5524 else if cmd
= 'g_bot_vsplayers' then
5526 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5528 else if cmd
= 'g_bot_vsmonsters' then
5530 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5532 else if cmd
= 'g_dm_keys' then
5534 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5536 else if cmd
= 'g_gameflags' then
5538 if Length(P
) > 1 then
5540 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5541 if g_Game_IsServer
then
5543 gGameSettings
.Options
:= gsGameFlags
;
5544 if g_Game_IsNet
then MH_SEND_GameSettings
;
5548 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5550 else if cmd
= 'g_warmup_time' then
5552 if Length(P
) > 1 then
5554 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5555 if g_Game_IsServer
then
5557 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5558 // extend warmup if it's already going
5559 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5561 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5562 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5564 if g_Game_IsNet
then MH_SEND_GameSettings
;
5568 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5569 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5571 else if cmd
= 'g_spawn_invul' then
5573 if Length(P
) > 1 then
5575 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5576 if g_Game_IsServer
then
5578 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5579 if g_Game_IsNet
then MH_SEND_GameSettings
;
5583 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5585 else if cmd
= 'g_item_respawn_time' then
5587 if Length(P
) > 1 then
5589 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5590 if g_Game_IsServer
then
5592 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5593 if g_Game_IsNet
then MH_SEND_GameSettings
;
5597 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5598 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5600 else if cmd
= 'sv_intertime' then
5602 if (Length(P
) > 1) then
5603 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5605 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5607 else if cmd
= 'g_max_particles' then
5609 if Length(p
) = 2 then
5611 a
:= Max(0, StrToInt(p
[1]));
5614 else if Length(p
) = 1 then
5616 e_LogWritefln('%s', [g_GFX_GetMax()])
5620 e_LogWritefln('usage: %s <n>', [cmd
])
5623 else if cmd
= 'g_max_shells' then
5625 if Length(p
) = 2 then
5627 a
:= Max(0, StrToInt(p
[1]));
5630 else if Length(p
) = 1 then
5632 e_LogWritefln('%s', [g_Shells_GetMax()])
5636 e_LogWritefln('usage: %s <n>', [cmd
])
5639 else if cmd
= 'g_max_gibs' then
5641 if Length(p
) = 2 then
5643 a
:= Max(0, StrToInt(p
[1]));
5646 else if Length(p
) = 1 then
5648 e_LogWritefln('%s', [g_Gibs_GetMax()])
5652 e_LogWritefln('usage: %s <n>', [cmd
])
5655 else if cmd
= 'g_max_corpses' then
5657 if Length(p
) = 2 then
5659 a
:= Max(0, StrToInt(p
[1]));
5662 else if Length(p
) = 1 then
5664 e_LogWritefln('%s', [g_Corpses_GetMax()])
5668 e_LogWritefln('usage: %s <n>', [cmd
])
5671 else if cmd
= 'g_scorelimit' then
5673 if Length(P
) > 1 then
5675 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5677 if g_Game_IsServer
then
5680 if gGameSettings
.GameMode
= GM_DM
then
5682 stat
:= g_Player_GetStats();
5684 for a
:= 0 to High(stat
) do
5685 if stat
[a
].Frags
> b
then
5689 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5691 // if someone has a higher score, set it to that instead
5692 gsGoalLimit
:= max(gsGoalLimit
, b
);
5693 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5695 if g_Game_IsNet
then MH_SEND_GameSettings
;
5699 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5701 else if cmd
= 'g_timelimit' then
5703 if Length(P
) > 1 then
5705 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5706 if g_Game_IsServer
then
5708 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5709 if g_Game_IsNet
then MH_SEND_GameSettings
;
5712 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5713 [gsTimeLimit
div 3600,
5714 (gsTimeLimit
div 60) mod 60,
5715 gsTimeLimit
mod 60]));
5717 else if cmd
= 'g_maxlives' then
5719 if Length(P
) > 1 then
5721 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5722 if g_Game_IsServer
then
5724 gGameSettings
.MaxLives
:= gsMaxLives
;
5725 if g_Game_IsNet
then MH_SEND_GameSettings
;
5729 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5733 procedure PlayerSettingsCVars(P
: SSArray
);
5737 cmd
:= LowerCase(P
[0]);
5741 if (Length(P
) > 1) then
5743 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5744 if g_Game_IsClient
then
5745 MC_SEND_PlayerSettings
5746 else if gGameOn
and (gPlayer1
<> nil) then
5748 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5749 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5755 if (Length(P
) > 1) then
5757 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5758 if g_Game_IsClient
then
5759 MC_SEND_PlayerSettings
5760 else if gGameOn
and (gPlayer2
<> nil) then
5762 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5763 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5769 if Length(P
) > 3 then
5771 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5772 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5773 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5774 if g_Game_IsClient
then
5775 MC_SEND_PlayerSettings
5776 else if gGameOn
and (gPlayer1
<> nil) then
5778 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5779 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5785 if Length(P
) > 3 then
5787 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5788 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5789 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5790 if g_Game_IsClient
then
5791 MC_SEND_PlayerSettings
5792 else if gGameOn
and (gPlayer2
<> nil) then
5794 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5795 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5801 if (Length(P
) > 1) then
5803 gPlayer1Settings
.Model
:= P
[1];
5804 if g_Game_IsClient
then
5805 MC_SEND_PlayerSettings
5806 else if gGameOn
and (gPlayer1
<> nil) then
5808 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5809 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5810 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5816 if (Length(P
) > 1) then
5818 gPlayer2Settings
.Model
:= P
[1];
5819 if g_Game_IsClient
then
5820 MC_SEND_PlayerSettings
5821 else if gGameOn
and (gPlayer2
<> nil) then
5823 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5824 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5825 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5832 procedure PrintHeapStats();
5836 hs
:= GetFPCHeapStatus();
5837 e_LogWriteLn ('v===== heap status =====v');
5838 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5839 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5840 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5841 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5842 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5843 e_LogWriteLn ('^=======================^');
5846 procedure DebugCommands(P
: SSArray
);
5853 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5854 if {gDebugMode}conIsCheatsEnabled
then
5856 cmd
:= LowerCase(P
[0]);
5857 if cmd
= 'd_window' then
5859 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5860 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5862 else if cmd
= 'd_sounds' then
5864 if (Length(P
) > 1) and
5865 ((P
[1] = '1') or (P
[1] = '0')) then
5866 g_Debug_Sounds
:= (P
[1][1] = '1');
5868 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5870 else if cmd
= 'd_frames' then
5872 if (Length(P
) > 1) and
5873 ((P
[1] = '1') or (P
[1] = '0')) then
5874 g_Debug_Frames
:= (P
[1][1] = '1');
5876 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5878 else if cmd
= 'd_winmsg' then
5880 if (Length(P
) > 1) and
5881 ((P
[1] = '1') or (P
[1] = '0')) then
5882 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5884 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5886 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5888 if (Length(P
) > 1) and
5889 ((P
[1] = '1') or (P
[1] = '0')) then
5890 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5892 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5894 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5896 if Length(P
) > 1 then
5898 '0': g_debug_BotAIOff
:= 0;
5899 '1': g_debug_BotAIOff
:= 1;
5900 '2': g_debug_BotAIOff
:= 2;
5901 '3': g_debug_BotAIOff
:= 3;
5904 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5906 else if cmd
= 'd_monster' then
5908 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5909 if Length(P
) < 2 then
5911 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5912 g_Console_Add('ID | Name');
5913 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5914 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5915 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5918 a
:= StrToIntDef(P
[1], 0);
5919 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5920 a
:= g_Mons_TypeIdByName(P
[1]);
5922 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5923 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5926 with gPlayer1
.Obj
do
5928 mon
:= g_Monsters_Create(a
,
5929 X
+ Rect
.X
+ (Rect
.Width
div 2),
5930 Y
+ Rect
.Y
+ Rect
.Height
,
5931 gPlayer1
.Direction
, True);
5933 if (Length(P
) > 2) and (mon
<> nil) then
5935 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5936 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5937 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5938 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5939 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5940 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5941 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5942 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5943 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5948 else if (cmd
= 'd_health') then
5950 if (Length(P
) > 1) and
5951 ((P
[1] = '1') or (P
[1] = '0')) then
5952 g_debug_HealthBar
:= (P
[1][1] = '1');
5954 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5956 else if (cmd
= 'd_player') then
5958 if (Length(P
) > 1) and
5959 ((P
[1] = '1') or (P
[1] = '0')) then
5960 g_debug_Player
:= (P
[1][1] = '1');
5962 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5964 else if (cmd
= 'd_mem') then
5970 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5974 procedure GameCheats(P
: SSArray
);
5980 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5982 g_Console_Add('not available');
5988 g_Console_Add('where is the player?!');
5991 cmd
:= LowerCase(P
[0]);
5995 plr
.GodMode
:= not plr
.GodMode
;
5996 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5999 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6000 if cmd
= 'give' then
6002 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6003 for f
:= 1 to High(P
) do
6005 cmd
:= LowerCase(P
[f
]);
6006 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6007 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6008 if cmd
= 'exit' then
6010 if gTriggers
<> nil then
6012 for a
:= 0 to High(gTriggers
) do
6014 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6016 g_Console_Add('player left the map');
6017 gExitByTrigger
:= True;
6018 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6019 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6027 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6028 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6029 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6030 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6031 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6033 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6034 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6036 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6037 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;
6039 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6040 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6042 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6043 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6045 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6046 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6048 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6049 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6050 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6052 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6053 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6054 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6055 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;
6056 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6057 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6059 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;
6060 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;
6061 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;
6062 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;
6063 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;
6064 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;
6066 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6067 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;
6069 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;
6070 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;
6072 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6074 if cmd
= 'ammo' then
6076 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6077 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6078 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6079 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6080 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6081 g_Console_Add('player got some ammo');
6085 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6086 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6088 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6089 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6091 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6092 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6094 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6095 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6097 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6099 if cmd
= 'weapons' then
6101 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6102 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6103 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6104 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6105 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6106 plr
.GiveItem(ITEM_WEAPON_BFG
);
6107 g_Console_Add('player got weapons');
6111 if cmd
= 'keys' then
6113 plr
.GiveItem(ITEM_KEY_RED
);
6114 plr
.GiveItem(ITEM_KEY_GREEN
);
6115 plr
.GiveItem(ITEM_KEY_BLUE
);
6116 g_Console_Add('player got all keys');
6120 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6125 if cmd
= 'open' then
6127 g_Console_Add('player activated sesame');
6128 g_Triggers_OpenAll();
6135 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6139 if cmd
= 'noclip' then
6142 g_Console_Add('wall hardeness adjusted');
6146 if cmd
= 'notarget' then
6148 plr
.NoTarget
:= not plr
.NoTarget
;
6149 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6153 if cmd
= 'noreload' then
6155 plr
.NoReload
:= not plr
.NoReload
;
6156 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6160 if cmd
= 'speedy' then
6162 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6163 g_Console_Add('speed adjusted');
6167 if cmd
= 'jumpy' then
6169 VEL_JUMP
:= 30-VEL_JUMP
;
6170 g_Console_Add('jump height adjusted');
6174 if cmd
= 'automap' then
6176 gShowMap
:= not gShowMap
;
6177 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6181 if cmd
= 'aimline' then
6183 gAimLine
:= not gAimLine
;
6184 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6189 procedure GameCommands(P
: SSArray
);
6195 pl
: pTNetClient
= nil;
6203 cmd
:= LowerCase(P
[0]);
6205 if cmd
= 'pause' then
6207 if (g_ActiveWindow
= nil) then
6208 g_Game_Pause(not gPauseMain
);
6210 else if cmd
= 'endgame' then
6211 gExit
:= EXIT_SIMPLE
6212 else if cmd
= 'restart' then
6214 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6216 if g_Game_IsClient
then
6218 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6223 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6225 else if cmd
= 'kick' then
6227 if g_Game_IsServer
then
6229 if Length(P
) < 2 then
6231 g_Console_Add('kick <name>');
6236 g_Console_Add('kick <name>');
6240 if g_Game_IsNet
then
6241 pl
:= g_Net_Client_ByName(P
[1]);
6244 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6245 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6246 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6247 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6248 g_Net_Slist_ServerPlayerLeaves();
6249 end else if gPlayers
<> nil then
6250 for a
:= Low(gPlayers
) to High(gPlayers
) do
6251 if gPlayers
[a
] <> nil then
6252 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6254 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6255 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6257 gPlayers
[a
].Lives
:= 0;
6258 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6259 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6260 g_Player_Remove(gPlayers
[a
].UID
);
6261 g_Net_Slist_ServerPlayerLeaves();
6262 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6266 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6268 else if cmd
= 'kick_id' then
6270 if g_Game_IsServer
and g_Game_IsNet
then
6272 if Length(P
) < 2 then
6274 g_Console_Add('kick_id <client ID>');
6279 g_Console_Add('kick_id <client ID>');
6283 a
:= StrToIntDef(P
[1], 0);
6284 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6286 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6288 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6289 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6290 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6291 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6292 g_Net_Slist_ServerPlayerLeaves();
6296 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6298 else if cmd
= 'kick_pid' then
6300 if g_Game_IsServer
and g_Game_IsNet
then
6302 if Length(P
) < 2 then
6304 g_Console_Add('kick_pid <player ID>');
6309 g_Console_Add('kick_pid <player ID>');
6313 a
:= StrToIntDef(P
[1], 0);
6314 pl
:= g_Net_Client_ByPlayer(a
);
6315 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6317 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6318 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6319 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6320 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6321 g_Net_Slist_ServerPlayerLeaves();
6324 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6326 else if cmd
= 'ban' then
6328 if g_Game_IsServer
and g_Game_IsNet
then
6330 if Length(P
) < 2 then
6332 g_Console_Add('ban <name>');
6337 g_Console_Add('ban <name>');
6341 pl
:= g_Net_Client_ByName(P
[1]);
6344 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6345 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6346 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6347 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6348 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6349 g_Net_Slist_ServerPlayerLeaves();
6351 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6353 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6355 else if cmd
= 'ban_id' then
6357 if g_Game_IsServer
and g_Game_IsNet
then
6359 if Length(P
) < 2 then
6361 g_Console_Add('ban_id <client ID>');
6366 g_Console_Add('ban_id <client ID>');
6370 a
:= StrToIntDef(P
[1], 0);
6371 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6372 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6374 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6375 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6376 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6377 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6378 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6379 g_Net_Slist_ServerPlayerLeaves();
6382 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6384 else if cmd
= 'ban_pid' then
6386 if g_Game_IsServer
and g_Game_IsNet
then
6388 if Length(P
) < 2 then
6390 g_Console_Add('ban_pid <player ID>');
6395 g_Console_Add('ban_pid <player ID>');
6399 a
:= StrToIntDef(P
[1], 0);
6400 pl
:= g_Net_Client_ByPlayer(a
);
6401 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6403 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6404 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6405 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6406 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6407 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6408 g_Net_Slist_ServerPlayerLeaves();
6411 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6413 else if cmd
= 'permban' then
6415 if g_Game_IsServer
and g_Game_IsNet
then
6417 if Length(P
) < 2 then
6419 g_Console_Add('permban <name>');
6424 g_Console_Add('permban <name>');
6428 pl
:= g_Net_Client_ByName(P
[1]);
6431 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6432 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6433 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6434 g_Net_SaveBanList();
6435 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6436 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6437 g_Net_Slist_ServerPlayerLeaves();
6439 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6441 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6443 else if cmd
= 'permban_id' then
6445 if g_Game_IsServer
and g_Game_IsNet
then
6447 if Length(P
) < 2 then
6449 g_Console_Add('permban_id <client ID>');
6454 g_Console_Add('permban_id <client ID>');
6458 a
:= StrToIntDef(P
[1], 0);
6459 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6460 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6462 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6463 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6464 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6465 g_Net_SaveBanList();
6466 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6467 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6468 g_Net_Slist_ServerPlayerLeaves();
6471 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6473 else if cmd
= 'permban_pid' then
6475 if g_Game_IsServer
and g_Game_IsNet
then
6477 if Length(P
) < 2 then
6479 g_Console_Add('permban_pid <player ID>');
6484 g_Console_Add('permban_pid <player ID>');
6488 a
:= StrToIntDef(P
[1], 0);
6489 pl
:= g_Net_Client_ByPlayer(a
);
6490 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6492 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6493 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6494 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6495 g_Net_SaveBanList();
6496 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6497 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6498 g_Net_Slist_ServerPlayerLeaves();
6501 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6503 else if cmd
= 'permban_ip' then
6505 if g_Game_IsServer
and g_Game_IsNet
then
6507 if Length(P
) < 2 then
6509 g_Console_Add('permban_ip <IP address>');
6514 g_Console_Add('permban_ip <IP address>');
6518 g_Net_BanHost(P
[1]);
6519 g_Net_SaveBanList();
6520 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6522 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6524 else if cmd
= 'unban' then
6526 if g_Game_IsServer
and g_Game_IsNet
then
6528 if Length(P
) < 2 then
6530 g_Console_Add('unban <IP Address>');
6535 g_Console_Add('unban <IP Address>');
6539 if g_Net_UnbanHost(P
[1]) then
6541 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6542 g_Net_SaveBanList();
6544 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6546 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6548 else if cmd
= 'clientlist' then
6550 if g_Game_IsServer
and g_Game_IsNet
then
6553 if NetClients
<> nil then
6554 for a
:= Low(NetClients
) to High(NetClients
) do
6555 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6557 plr
:= g_Player_Get(NetClients
[a
].Player
);
6558 if plr
= nil then continue
;
6560 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6561 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6564 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6566 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6568 else if cmd
= 'connect' then
6570 if (NetMode
= NET_NONE
) then
6572 if Length(P
) < 2 then
6574 g_Console_Add('connect <IP> [port] [password]');
6579 g_Console_Add('connect <IP> [port] [password]');
6583 if Length(P
) > 2 then
6584 prt
:= StrToIntDef(P
[2], 25666)
6588 if Length(P
) > 3 then
6593 g_Game_StartClient(P
[1], prt
, pw
);
6596 else if cmd
= 'disconnect' then
6598 if (NetMode
= NET_CLIENT
) then
6601 else if cmd
= 'reconnect' then
6603 if (NetMode
= NET_SERVER
) then
6606 if (NetMode
= NET_CLIENT
) then
6609 gExit
:= EXIT_SIMPLE
;
6613 //TODO: Use last successful password to reconnect, instead of ''
6614 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6616 else if (cmd
= 'addbot') or
6617 (cmd
= 'bot_add') then
6619 if Length(P
) > 2 then
6620 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6621 else if Length(P
) > 1 then
6622 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6624 g_Bot_Add(TEAM_NONE
, 2);
6626 else if cmd
= 'bot_addlist' then
6628 if Length(P
) > 1 then
6630 if Length(P
) = 2 then
6631 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6632 else if Length(P
) = 3 then
6633 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6635 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6638 else if cmd
= 'bot_removeall' then
6640 else if cmd
= 'chat' then
6642 if g_Game_IsNet
then
6644 if Length(P
) > 1 then
6646 for a
:= 1 to High(P
) do
6647 chstr
:= chstr
+ P
[a
] + ' ';
6649 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6651 if Length(chstr
) < 1 then
6653 g_Console_Add('chat <text>');
6657 chstr
:= b_Text_Format(chstr
);
6658 if g_Game_IsClient
then
6659 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6661 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6664 g_Console_Add('chat <text>');
6666 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6668 else if cmd
= 'teamchat' then
6670 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6672 if Length(P
) > 1 then
6674 for a
:= 1 to High(P
) do
6675 chstr
:= chstr
+ P
[a
] + ' ';
6677 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6679 if Length(chstr
) < 1 then
6681 g_Console_Add('teamchat <text>');
6685 chstr
:= b_Text_Format(chstr
);
6686 if g_Game_IsClient
then
6687 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6689 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6690 gPlayer1Settings
.Team
);
6693 g_Console_Add('teamchat <text>');
6695 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6697 else if cmd
= 'game' then
6699 if gGameSettings
.GameType
<> GT_NONE
then
6701 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6704 if Length(P
) = 1 then
6706 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6709 // game not started yet, load fist map from some wad
6711 s
:= addWadExtension(P
[1]);
6712 found
:= e_FindResource(AllMapDirs
, s
);
6716 P
[1] := ExpandFileName(P
[1]);
6717 // if map not choosed then set first map
6718 if Length(P
) < 3 then
6721 P
[2] := g_Game_GetFirstMap(P
[1]);
6724 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6726 if g_Map_Exist(s
) then
6730 with gGameSettings
do
6732 Options
:= gsGameFlags
;
6733 GameMode
:= g_Game_TextToMode(gsGameMode
);
6734 if gSwitchGameMode
<> GM_NONE
then
6735 GameMode
:= gSwitchGameMode
;
6736 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6737 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6739 if Length(P
) >= 4 then
6740 b
:= StrToIntDef(P
[3], 1);
6741 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6742 GoalLimit
, MaxLives
, Options
, b
);
6747 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6749 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6751 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6753 else if cmd
= 'host' then
6755 if gGameSettings
.GameType
<> GT_NONE
then
6757 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6760 if Length(P
) < 4 then
6762 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6765 if not StrToIp(P
[1], listen
) then
6767 prt
:= StrToIntDef(P
[2], 25666);
6769 s
:= addWadExtension(P
[3]);
6770 found
:= e_FindResource(AllMapDirs
, s
);
6774 // get first map in wad, if not specified
6775 if Length(P
) < 5 then
6778 P
[4] := g_Game_GetFirstMap(P
[1]);
6780 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6781 if g_Map_Exist(s
) then
6785 with gGameSettings
do
6787 Options
:= gsGameFlags
;
6788 GameMode
:= g_Game_TextToMode(gsGameMode
);
6789 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6790 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6791 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6793 if Length(P
) >= 6 then
6794 b
:= StrToIntDef(P
[5], 0);
6795 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6801 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6803 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6808 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6811 else if cmd
= 'map' then
6813 if Length(P
) = 1 then
6815 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6817 g_Console_Add(cmd
+ ' <MAP>');
6818 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6822 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6827 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6829 if Length(P
) < 3 then
6831 // first param is map or wad
6832 s
:= UpperCase(P
[1]);
6833 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6835 gExitByTrigger
:= False;
6838 // already in game, finish current map
6840 gExit
:= EXIT_ENDLEVELCUSTOM
;
6844 // intermission, so change map immediately
6851 found
:= e_FindResource(AllMapDirs
, s
);
6853 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6856 // no such map, found wad
6859 P
[1] := ExpandFileName(pw
);
6860 P
[2] := g_Game_GetFirstMap(P
[1]);
6861 s
:= P
[1] + ':\' + P
[2];
6862 if g_Map_Exist(s
) then
6864 gExitByTrigger
:= False;
6867 // already in game, finish current map
6869 gExit
:= EXIT_ENDLEVELCUSTOM
6873 // intermission, so change map immediately
6880 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6882 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6887 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6893 s
:= addWadExtension(P
[1]);
6894 found
:= e_FindResource(AllMapDirs
, s
);
6898 P
[2] := UpperCase(P
[2]);
6899 s
:= P
[1] + ':\' + P
[2];
6900 if g_Map_Exist(s
) then
6902 gExitByTrigger
:= False;
6906 gExit
:= EXIT_ENDLEVELCUSTOM
6915 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6920 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6926 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6930 else if cmd
= 'nextmap' then
6932 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6934 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6939 if Length(P
) = 1 then
6941 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6943 g_Console_Add(cmd
+ ' <MAP>');
6944 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6949 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6955 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6957 if Length(P
) < 3 then
6959 // first param is map or wad
6960 s
:= UpperCase(P
[1]);
6961 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6964 gExitByTrigger
:= False;
6970 // no such map, found wad
6971 pw
:= addWadExtension(P
[1]);
6972 found
:= e_FindResource(MapDirs
, pw
);
6974 found
:= e_FindResource(WadDirs
, pw
);
6976 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6979 // map not specified, select first map
6981 P
[2] := g_Game_GetFirstMap(P
[1]);
6982 s
:= P
[1] + ':\' + P
[2];
6983 if g_Map_Exist(s
) then
6985 gExitByTrigger
:= False;
6992 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6994 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6999 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7005 // specified two params wad + map
7006 pw
:= addWadExtension(P
[1]);
7007 found
:= e_FindResource(MapDirs
, pw
);
7009 found
:= e_FindResource(MapDirs
, pw
);
7013 P
[2] := UpperCase(P
[2]);
7014 s
:= P
[1] + ':\' + P
[2];
7015 if g_Map_Exist(s
) then
7017 gExitByTrigger
:= False;
7023 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7028 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7034 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7039 if gNextMap
= '' then
7040 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7042 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7046 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7050 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7054 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7056 gExitByTrigger
:= False;
7057 // next map not specified, try to find trigger EXIT
7058 if (gNextMap
= '') and (gTriggers
<> nil) then
7060 for a
:= 0 to High(gTriggers
) do
7062 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7064 gExitByTrigger
:= True;
7065 //gNextMap := gTriggers[a].Data.MapName;
7066 gNextMap
:= gTriggers
[a
].tgcMap
;
7071 if gNextMap
= '' then
7072 gNextMap
:= g_Game_GetNextMap();
7073 if not isWadPath(gNextMap
) then
7074 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7077 if g_Map_Exist(s
) then
7078 gExit
:= EXIT_ENDLEVELCUSTOM
7080 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7084 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7088 else if (cmd
= 'event') then
7090 if (Length(P
) <= 1) then
7092 for a
:= 0 to High(gEvents
) do
7093 if gEvents
[a
].Command
= '' then
7094 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7096 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7099 if (Length(P
) = 2) then
7101 for a
:= 0 to High(gEvents
) do
7102 if gEvents
[a
].Name
= P
[1] then
7103 if gEvents
[a
].Command
= '' then
7104 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7106 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7109 for a
:= 0 to High(gEvents
) do
7110 if gEvents
[a
].Name
= P
[1] then
7112 gEvents
[a
].Command
:= '';
7113 for b
:= 2 to High(P
) do
7114 if Pos(' ', P
[b
]) = 0 then
7115 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7117 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7118 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7122 else if cmd
= 'suicide' then
7126 if g_Game_IsClient
then
7127 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7130 if gPlayer1
<> nil then
7131 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7132 if gPlayer2
<> nil then
7133 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7137 else if cmd
= 'screenshot' then
7141 else if cmd
= 'weapon' then
7143 if Length(p
) = 2 then
7145 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7146 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7147 gSelectWeapon
[0, a
] := True
7150 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7152 if Length(p
) = 2 then
7154 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7155 b
:= ord(cmd
[2]) - ord('1');
7156 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7157 gSelectWeapon
[b
, a
] := True
7160 // Êîìàíäû Ñâîåé èãðû:
7161 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7163 if cmd
= 'bot_addred' then
7165 if Length(P
) > 1 then
7166 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7168 g_Bot_Add(TEAM_RED
, 2);
7170 else if cmd
= 'bot_addblue' then
7172 if Length(P
) > 1 then
7173 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7175 g_Bot_Add(TEAM_BLUE
, 2);
7177 else if cmd
= 'spectate' then
7183 else if cmd
= 'say' then
7185 if g_Game_IsServer
and g_Game_IsNet
then
7187 if Length(P
) > 1 then
7190 for a
:= 1 to High(P
) do
7191 chstr
:= chstr
+ P
[a
] + ' ';
7193 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7195 if Length(chstr
) < 1 then
7197 g_Console_Add('say <text>');
7201 chstr
:= b_Text_Format(chstr
);
7202 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7204 else g_Console_Add('say <text>');
7206 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7208 else if cmd
= 'tell' then
7210 if g_Game_IsServer
and g_Game_IsNet
then
7212 if (Length(P
) > 2) and (P
[1] <> '') then
7215 for a
:= 2 to High(P
) do
7216 chstr
:= chstr
+ P
[a
] + ' ';
7218 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7220 if Length(chstr
) < 1 then
7222 g_Console_Add('tell <playername> <text>');
7226 pl
:= g_Net_Client_ByName(P
[1]);
7228 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7230 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7232 else g_Console_Add('tell <playername> <text>');
7234 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7236 else if cmd
= 'centerprint' then
7238 if (Length(P
) > 2) and (P
[1] <> '') then
7241 for a
:= 2 to High(P
) do
7242 chstr
:= chstr
+ P
[a
] + ' ';
7244 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7246 if Length(chstr
) < 1 then
7248 g_Console_Add('centerprint <timeout> <text>');
7252 a
:= StrToIntDef(P
[1], 100);
7253 chstr
:= b_Text_Format(chstr
);
7254 g_Game_Message(chstr
, a
);
7255 if g_Game_IsNet
and g_Game_IsServer
then
7256 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7258 else g_Console_Add('centerprint <timeout> <text>');
7260 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7262 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7264 // Äîïîëíèòåëüíîå âðåìÿ:
7265 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7267 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7268 [gGameSettings
.TimeLimit
div 3600,
7269 (gGameSettings
.TimeLimit
div 60) mod 60,
7270 gGameSettings
.TimeLimit
mod 60]));
7271 if g_Game_IsNet
then MH_SEND_GameSettings
;
7273 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7275 if (Length(P
) <= 1) then
7276 g_Console_Add('rcon_password <password>')
7278 MC_SEND_RCONPassword(P
[1]);
7280 else if cmd
= 'rcon' then
7282 if g_Game_IsClient
then
7284 if Length(P
) > 1 then
7287 for a
:= 1 to High(P
) do
7288 chstr
:= chstr
+ P
[a
] + ' ';
7290 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7292 if Length(chstr
) < 1 then
7294 g_Console_Add('rcon <command>');
7298 MC_SEND_RCONCommand(chstr
);
7300 else g_Console_Add('rcon <command>');
7303 else if cmd
= 'ready' then
7305 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7306 gLMSRespawnTime
:= gTime
+ 100;
7308 else if (cmd
= 'callvote') and g_Game_IsNet
then
7310 if Length(P
) > 1 then
7313 for a
:= 1 to High(P
) do begin
7314 if a
> 1 then chstr
:= chstr
+ ' ';
7315 chstr
:= chstr
+ P
[a
];
7318 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7320 if Length(chstr
) < 1 then
7322 g_Console_Add('callvote <command>');
7326 if g_Game_IsClient
then
7327 MC_SEND_Vote(True, chstr
)
7329 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7330 g_Console_Process('vote', True);
7333 g_Console_Add('callvote <command>');
7335 else if (cmd
= 'vote') and g_Game_IsNet
then
7337 if g_Game_IsClient
then
7339 else if gVoteInProgress
then
7341 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7342 a
:= Floor((NetClientCount
+1)/2.0) + 1
7344 a
:= Floor(NetClientCount
/2.0) + 1;
7349 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7350 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7356 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7357 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7365 procedure SystemCommands(P
: SSArray
);
7369 cmd
:= LowerCase(P
[0]);
7378 gRC_Width
:= Max(1, gRC_Width
);
7379 gRC_Height
:= Max(1, gRC_Height
);
7380 gBPP
:= Max(1, gBPP
);
7381 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7382 e_LogWriteln('resolution changed')
7384 e_LogWriteln('resolution not changed');
7385 sys_EnableVSync(gVSync
);
7389 if Length(p
) = 2 then
7391 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7393 gFrameTime
:= 1000 div gMaxFPS
7397 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7401 if Length(p
) = 2 then
7403 gAskLanguage
:= true;
7404 gLanguage
:= LANGUAGE_ENGLISH
;
7405 case LowerCase(p
[1]) of
7408 gAskLanguage
:= false;
7409 gLanguage
:= LANGUAGE_ENGLISH
;
7413 gAskLanguage
:= false;
7414 gLanguage
:= LANGUAGE_RUSSIAN
;
7418 gAskLanguage
:= true;
7419 gLanguage
:= LANGUAGE_ENGLISH
;
7422 g_Language_Set(gLanguage
);
7426 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7432 procedure g_TakeScreenShot(Filename
: string = '');
7433 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7435 if e_NoGraphics
then Exit
;
7437 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7439 if Filename
= '' then
7442 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7443 Filename
:= 'screenshot-' + date
;
7446 name
:= e_CatPath(dir
, Filename
+ '.png');
7447 s
:= createDiskFile(name
);
7449 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7451 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7453 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7458 g_Console_Add('oh shit, i can''t create screenshot!')
7462 procedure g_Game_InGameMenu(Show
: Boolean);
7464 if (g_ActiveWindow
= nil) and Show
then
7466 if gGameSettings
.GameType
= GT_SINGLE
then
7467 g_GUI_ShowWindow('GameSingleMenu')
7470 if g_Game_IsClient
then
7471 g_GUI_ShowWindow('GameClientMenu')
7473 if g_Game_IsNet
then
7474 g_GUI_ShowWindow('GameServerMenu')
7476 g_GUI_ShowWindow('GameCustomMenu');
7478 g_Sound_PlayEx('MENU_OPEN');
7480 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7481 if (not g_Game_IsNet
) then
7485 if (g_ActiveWindow
<> nil) and (not Show
) then
7487 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7488 if (not g_Game_IsNet
) then
7489 g_Game_Pause(False);
7493 procedure g_Game_Pause (Enable
: Boolean);
7497 if not gGameOn
then exit
;
7499 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7502 gPauseMain
:= Enable
;
7504 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7507 procedure g_Game_HolmesPause (Enable
: Boolean);
7511 if not gGameOn
then exit
;
7512 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7515 gPauseHolmes
:= Enable
;
7517 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7520 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7525 if gTriggers
<> nil then
7526 for i
:= 0 to High(gTriggers
) do
7527 with gTriggers
[i
] do
7528 if (TriggerType
= TRIGGER_SOUND
) and
7530 Sound
.IsPlaying() then
7532 Sound
.Pause(Enable
);
7536 if gPlayers
<> nil then
7537 for i
:= 0 to High(gPlayers
) do
7538 if gPlayers
[i
] <> nil then
7539 gPlayers
[i
].PauseSounds(Enable
);
7542 if gMusic
<> nil then
7543 gMusic
.Pause(Enable
);
7546 procedure g_Game_StopAllSounds(all
: Boolean);
7550 if gTriggers
<> nil then
7551 for i
:= 0 to High(gTriggers
) do
7552 with gTriggers
[i
] do
7553 if (TriggerType
= TRIGGER_SOUND
) and
7557 if gMusic
<> nil then
7564 procedure g_Game_UpdateTriggerSounds
;
7567 if gTriggers
<> nil then
7568 for i
:= 0 to High(gTriggers
) do
7569 with gTriggers
[i
] do
7570 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7571 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7574 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7577 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7582 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7587 if gSpectMode
<> SPECT_PLAYERS
then
7589 if gSpectPID1
= UID
then
7594 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7601 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7606 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7611 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7616 if gSpectMode
<> SPECT_PLAYERS
then
7618 Pl
:= g_Player_Get(gSpectPID1
);
7619 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7624 if gSpectViewTwo
then
7626 Pl
:= g_Player_Get(gSpectPID2
);
7627 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7635 procedure g_Game_Message(Msg
: string; Time
: Word);
7637 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7638 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7639 MessageTime
:= Time
;
7642 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7644 punct
: Array[0..13] of String =
7645 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7651 function IsPunctuation(S
: String): Boolean;
7656 if Length(S
) <> 1 then
7658 for i
:= Low(punct
) to High(punct
) do
7659 if S
= punct
[i
] then
7665 function FilterPunctuation(S
: String): String;
7669 for i
:= Low(punct
) to High(punct
) do
7670 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7676 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7678 // remove player name
7679 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7680 // for FullWord check
7681 Text := toLowerCase1251(' ' + Text + ' ');
7682 fpText
:= FilterPunctuation(Text);
7684 for i
:= 0 to Length(gChatSounds
) - 1 do
7687 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7689 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7690 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7692 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7698 gChatSounds
[i
].Sound
.Play();
7704 g_Sound_PlayEx('SOUND_GAME_RADIO');
7707 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7716 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7720 if goodsnd
[a
].IsPlaying() then
7723 goodsnd
[Random(4)].Play();
7726 procedure g_Game_Announce_KillCombo(Param
: Integer);
7733 UID
:= Param
and $FFFF;
7738 Pl
:= g_Player_Get(UID
);
7747 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7751 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7755 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7759 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7767 if not g_Game_IsWatchedPlayer(UID
) then
7770 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7774 if killsnd
[n
].IsPlaying() then
7779 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7787 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7791 if hahasnd
[a
].IsPlaying() then
7794 hahasnd
[Random(3)].Play();
7797 procedure g_Game_StartVote(Command
, Initiator
: string);
7801 if not gVotesEnabled
then Exit
;
7802 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7803 if gVoteInProgress
or gVotePassed
then
7805 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7806 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7809 gVoteInProgress
:= True;
7810 gVotePassed
:= False;
7811 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7814 gVoteCommand
:= Command
;
7816 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7817 Need
:= Floor((NetClientCount
+1)/2.0)+1
7819 Need
:= Floor(NetClientCount
/2.0)+1;
7820 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7821 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7824 procedure g_Game_CheckVote
;
7828 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7829 if not gVoteInProgress
then Exit
;
7831 if (gTime
>= gVoteTimer
) then
7833 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7834 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7836 Need
:= Floor(NetClientCount
/2.0) + 1;
7837 if gVoteCount
>= Need
then
7839 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7840 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7841 gVotePassed
:= True;
7842 gVoteCmdTimer
:= gTime
+ 5000;
7846 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7847 MH_SEND_VoteEvent(NET_VE_FAILED
);
7849 if NetClients
<> nil then
7850 for I
:= Low(NetClients
) to High(NetClients
) do
7851 if NetClients
[i
].Used
then
7852 NetClients
[i
].Voted
:= False;
7853 gVoteInProgress
:= False;
7859 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7860 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7862 Need
:= Floor(NetClientCount
/2.0) + 1;
7863 if gVoteCount
>= Need
then
7865 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7866 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7867 gVoteInProgress
:= False;
7868 gVotePassed
:= True;
7869 gVoteCmdTimer
:= gTime
+ 5000;
7872 if NetClients
<> nil then
7873 for I
:= Low(NetClients
) to High(NetClients
) do
7874 if NetClients
[i
].Used
then
7875 NetClients
[i
].Voted
:= False;
7880 procedure g_Game_LoadMapList(FileName
: string);
7888 if not FileExists(FileName
) then Exit
;
7890 AssignFile(ListFile
, FileName
);
7892 while not EOF(ListFile
) do
7894 ReadLn(ListFile
, s
);
7897 if s
= '' then Continue
;
7899 SetLength(MapList
, Length(MapList
)+1);
7900 MapList
[High(MapList
)] := s
;
7902 CloseFile(ListFile
);
7905 procedure g_Game_SetDebugMode();
7908 // ×èòû (äàæå â ñâîåé èãðå):
7912 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7916 if Length(LoadingStat
.Msgs
) = 0 then
7922 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7923 if NextMsg
= Length(Msgs
) then
7925 for i
:= 0 to High(Msgs
)-1 do
7926 Msgs
[i
] := Msgs
[i
+1];
7934 Msgs
[NextMsg
-1] := Text;
7938 PBarWasHere
:= false;
7941 g_ActiveWindow
:= nil;
7943 ProcessLoading(true);
7946 procedure g_Game_StepLoading(Value
: Integer = -1);
7957 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7965 procedure g_Game_ClearLoading();
7974 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7975 if len
< 1 then len
:= 1;
7976 SetLength(Msgs
, len
);
7977 for len
:= Low(Msgs
) to High(Msgs
) do
7980 PBarWasHere
:= false;
7984 procedure Parse_Params(var pars
: TParamStrValues
);
7991 while i
<= ParamCount
do
7994 if (s
[1] = '-') and (Length(s
) > 1) then
7996 if (s
[2] = '-') and (Length(s
) > 2) then
7997 begin // Îäèíî÷íûé ïàðàìåòð
7998 SetLength(pars
, Length(pars
) + 1);
7999 with pars
[High(pars
)] do
8001 Name
:= LowerCase(s
);
8006 if (i
< ParamCount
) then
8007 begin // Ïàðàìåòð ñî çíà÷åíèåì
8009 SetLength(pars
, Length(pars
) + 1);
8010 with pars
[High(pars
)] do
8012 Name
:= LowerCase(s
);
8013 Value
:= LowerCase(ParamStr(i
));
8022 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8027 for i
:= 0 to High(pars
) do
8028 if pars
[i
].Name
= aName
then
8030 Result
:= pars
[i
].Value
;
8035 procedure g_Game_Process_Params();
8037 pars
: TParamStrValues
;
8040 LimT
, LimS
: Integer;
8051 s
:= Find_Param_Value(pars
, '--debug');
8054 g_Game_SetDebugMode();
8055 s
:= Find_Param_Value(pars
, '--netdump');
8060 // Connect when game loads
8061 ip
:= Find_Param_Value(pars
, '-connect');
8065 s
:= Find_Param_Value(pars
, '-port');
8066 if (s
= '') or not TryStrToInt(s
, Port
) then
8069 s
:= Find_Param_Value(pars
, '-pw');
8071 g_Game_StartClient(ip
, Port
, s
);
8075 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8078 gDefaultMegawadStart
:= s
;
8081 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8082 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8084 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8087 // Start map when game loads:
8088 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8089 if isWadPath(map
) then
8092 s
:= Find_Param_Value(pars
, '-gm');
8093 GMode
:= g_Game_TextToMode(s
);
8094 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8095 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8098 s
:= Find_Param_Value(pars
, '-limt');
8099 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8105 s
:= Find_Param_Value(pars
, '-lims');
8106 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8112 s
:= Find_Param_Value(pars
, '-lives');
8113 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8119 s
:= Find_Param_Value(pars
, '-opt');
8123 Opt
:= StrToIntDef(s
, 0);
8126 s
:= Find_Param_Value(pars
, '--close');
8130 // Override map to test:
8131 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8134 if e_IsValidResourceName(s
) then
8135 e_FindResource(AllMapDirs
, s
);
8136 gTestMap
:= ExpandFileName(s
);
8139 // Delete test map after play:
8140 s
:= Find_Param_Value(pars
, '--testdelete');
8143 //gMapToDelete := MapsDir + map;
8144 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8148 // Delete temporary WAD after play:
8149 s
:= Find_Param_Value(pars
, '--tempdelete');
8150 if (s
<> '') and (gTestMap
<> '') then
8152 gMapToDelete
:= gTestMap
;
8153 gTempDelete
:= True;
8156 // Number of players:
8157 s
:= Find_Param_Value(pars
, '-pl');
8159 n
:= DEFAULT_PLAYERS
8161 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8164 s
:= Find_Param_Value(pars
, '-port');
8165 if (s
= '') or not TryStrToInt(s
, Port
) then
8166 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8168 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8171 // Execute script when game loads:
8172 s
:= Find_Param_Value(pars
, '-exec');
8175 // if not isWadPath(s) then
8176 // s := GameDir + '/' + s;
8181 if IOResult
<> 0 then
8183 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8184 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8188 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8189 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8194 if IOResult
<> 0 then
8196 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8197 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8201 if Pos('#', s
) <> 1 then // script comment
8202 g_Console_Process(s
, True);
8213 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8214 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8215 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8216 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8218 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8219 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8220 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8221 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8223 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8224 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8226 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8227 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8229 {$IFDEF ENABLE_HOLMES}
8230 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8233 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8235 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8236 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8238 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8239 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8241 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8242 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8244 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8245 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8246 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8247 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8248 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8249 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8250 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8251 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8252 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');