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;
187 GAME_OPTION_TEAMHITTRACE
= 256;
188 GAME_OPTION_TEAMHITPROJECTILE
= 512;
189 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
194 STATE_INTERCUSTOM
= 3;
195 STATE_INTERSINGLE
= 4;
201 LMS_RESPAWN_NONE
= 0;
202 LMS_RESPAWN_WARMUP
= 1;
203 LMS_RESPAWN_FINAL
= 2;
220 CONFIG_FILENAME
= 'Doom2DF.cfg';
222 TEST_MAP_NAME
= '$$$_TEST_$$$';
224 STD_PLAYER_MODEL
= 'Doomer';
232 STATFILE_VERSION
= $03;
236 gGameSettings
: TGameSettings
;
237 gPlayer1Settings
: TPlayerSettings
;
238 gPlayer2Settings
: TPlayerSettings
;
240 gPlayerScreenSize
: TDFPoint
;
241 gPlayer1ScreenCoord
: TDFPoint
;
242 gPlayer2ScreenCoord
: TDFPoint
;
243 gPlayer1
: TPlayer
= nil;
244 gPlayer2
: TPlayer
= nil;
245 gPlayerDrawn
: TPlayer
= nil;
247 gLerpFactor
: Single = 1.0;
248 gSwitchGameMode
: Byte = GM_DM
;
249 gHearPoint1
, gHearPoint2
: THearPoint
;
250 gSoundEffectsDF
: Boolean = False;
251 gSoundTriggerTime
: Word = 0;
252 gAnnouncer
: Integer = ANNOUNCE_NONE
;
253 goodsnd
: array[0..3] of TPlayableSound
;
254 killsnd
: array[0..3] of TPlayableSound
;
255 hahasnd
: array[0..2] of TPlayableSound
;
256 sound_get_flag
: array[0..1] of TPlayableSound
;
257 sound_lost_flag
: array[0..1] of TPlayableSound
;
258 sound_ret_flag
: array[0..1] of TPlayableSound
;
259 sound_cap_flag
: array[0..1] of TPlayableSound
;
260 gBodyKillEvent
: Integer = -1;
261 gDefInterTime
: ShortInt = -1;
262 gInterEndTime
: LongWord = 0;
263 gInterTime
: LongWord = 0;
264 gServInterTime
: Byte = 0;
265 gGameStartTime
: LongWord = 0;
266 gTotalMonsters
: Integer = 0;
267 gPauseMain
: Boolean = false;
268 gPauseHolmes
: Boolean = false;
269 gShowTime
: Boolean = False;
270 gShowFPS
: Boolean = False;
271 gShowGoals
: Boolean = True;
272 gShowStat
: Boolean = True;
273 gShowPIDs
: Boolean = False;
274 gShowKillMsg
: Boolean = True;
275 gShowLives
: Boolean = True;
276 gShowPing
: Boolean = False;
277 gShowMap
: Boolean = False;
279 gState
: Byte = STATE_NONE
;
281 sWidth
, sHeight
: Word;
282 gSpectMode
: Byte = SPECT_NONE
;
283 gSpectHUD
: Boolean = True;
284 gSpectKeyPress
: Boolean = False;
285 gSpectX
: Integer = 0;
286 gSpectY
: Integer = 0;
287 gSpectStep
: Byte = 8;
288 gSpectViewTwo
: Boolean = False;
289 gSpectPID1
: Integer = -1;
290 gSpectPID2
: Integer = -1;
291 gSpectAuto
: Boolean = False;
292 gSpectAutoNext
: LongWord;
293 gSpectAutoStepX
: Integer;
294 gSpectAutoStepY
: Integer;
295 gMusic
: TMusic
= nil;
296 gLoadGameMode
: Boolean;
297 gCheats
: Boolean = False;
298 gMapOnce
: Boolean = False;
299 gMapToDelete
: String;
300 gTempDelete
: Boolean = False;
301 gLastMap
: Boolean = False;
304 gResolutionChange
: Boolean = False;
305 gRC_Width
, gRC_Height
: Integer;
306 gRC_FullScreen
, gRC_Maximized
: Boolean;
307 gLanguageChange
: Boolean = False;
308 gDebugMode
: Boolean = False;
309 g_debug_Sounds
: Boolean = False;
310 g_debug_Frames
: Boolean = False;
311 g_debug_WinMsgs
: Boolean = False;
312 g_debug_MonsterOff
: Boolean = False;
313 g_debug_BotAIOff
: Byte = 0;
314 g_debug_HealthBar
: Boolean = False;
315 g_Debug_Player
: Boolean = False;
316 gCoopMonstersKilled
: Word = 0;
317 gCoopSecretsFound
: Word = 0;
318 gCoopTotalMonstersKilled
: Word = 0;
319 gCoopTotalSecretsFound
: Word = 0;
320 gCoopTotalMonsters
: Word = 0;
321 gCoopTotalSecrets
: Word = 0;
322 gStatsOff
: Boolean = False;
323 gStatsPressed
: Boolean = False;
324 gExitByTrigger
: Boolean = False;
325 gNextMap
: String = '';
326 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
327 gLMSRespawnTime
: Cardinal = 0;
328 gLMSSoftSpawn
: Boolean = False;
329 gMissionFailed
: Boolean = False;
330 gVoteInProgress
: Boolean = False;
331 gVotePassed
: Boolean = False;
332 gVoteCommand
: string = '';
333 gVoteTimer
: Cardinal = 0;
334 gVoteCmdTimer
: Cardinal = 0;
335 gVoteCount
: Integer = 0;
336 gVoteTimeout
: Cardinal = 30;
337 gVoted
: Boolean = False;
338 gVotesEnabled
: Boolean = True;
339 gEvents
: Array of TGameEvent
;
340 gDelayedEvents
: Array of TDelayedEvent
;
341 gUseChatSounds
: Boolean = True;
342 gChatSounds
: Array of TChatSound
;
343 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
344 gInterReadyCount
: Integer = 0;
346 g_dbg_ignore_bounds
: Boolean = false;
347 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
348 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
350 // move button values:
351 // bits 0-1: l/r state:
352 // 0: neither left, nor right pressed
355 // bits 4-5: l/r state when strafe was pressed
356 P1MoveButton
: Byte = 0;
357 P2MoveButton
: Byte = 0;
359 g_profile_frame_update
: Boolean = false;
360 g_profile_frame_draw
: Boolean = false;
361 g_profile_collision
: Boolean = false;
362 g_profile_los
: Boolean = false;
363 g_profile_history_size
: Integer = 1000;
365 g_rlayer_back
: Boolean = true;
366 g_rlayer_step
: Boolean = true;
367 g_rlayer_wall
: Boolean = true;
368 g_rlayer_door
: Boolean = true;
369 g_rlayer_acid1
: Boolean = true;
370 g_rlayer_acid2
: Boolean = true;
371 g_rlayer_water
: Boolean = true;
372 g_rlayer_fore
: Boolean = true;
375 procedure g_ResetDynlights ();
376 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
377 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
379 function conIsCheatsEnabled (): Boolean; inline;
380 function gPause (): Boolean; inline;
386 {$INCLUDE ../nogl/noGLuses.inc}
387 {$IFDEF ENABLE_HOLMES}
390 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
391 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
392 g_playermodel
, g_gfx
, g_options
, Math
,
393 g_triggers
, g_monsters
, e_sound
, CONFIG
,
394 g_language
, g_net
, g_main
, g_phys
,
395 ENet
, e_msg
, g_netmsg
, g_netmaster
,
396 sfs
, wadreader
, g_system
;
400 hasPBarGfx
: Boolean = false;
403 // ////////////////////////////////////////////////////////////////////////// //
404 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
407 // ////////////////////////////////////////////////////////////////////////// //
408 function conIsCheatsEnabled (): Boolean; inline;
411 if g_Game_IsNet
then exit
;
412 if not gDebugMode
then
414 //if not gCheats then exit;
415 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
416 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
422 // ////////////////////////////////////////////////////////////////////////// //
424 profileFrameDraw
: TProfiler
= nil;
427 // ////////////////////////////////////////////////////////////////////////// //
430 x
, y
, radius
: Integer;
433 exploRadius
: Integer;
437 g_dynLights
: array of TDynLight
= nil;
438 g_dynLightCount
: Integer = 0;
439 g_playerLight
: Boolean = false;
441 procedure g_ResetDynlights ();
445 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
447 for idx
:= 0 to g_dynLightCount
-1 do
449 if g_dynLights
[idx
].exploCount
= -666 then
456 Inc(g_dynLights
[idx
].exploCount
);
457 if (g_dynLights
[idx
].exploCount
< 10) then
459 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
460 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
461 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
462 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
467 g_dynLightCount
:= lnum
;
470 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
472 if not gwin_has_stencil
then exit
;
473 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
474 g_dynLights
[g_dynLightCount
].x
:= x
;
475 g_dynLights
[g_dynLightCount
].y
:= y
;
476 g_dynLights
[g_dynLightCount
].radius
:= radius
;
477 g_dynLights
[g_dynLightCount
].r
:= r
;
478 g_dynLights
[g_dynLightCount
].g
:= g
;
479 g_dynLights
[g_dynLightCount
].b
:= b
;
480 g_dynLights
[g_dynLightCount
].a
:= a
;
481 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
482 Inc(g_dynLightCount
);
485 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
487 if not gwin_has_stencil
then exit
;
488 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
489 g_dynLights
[g_dynLightCount
].x
:= x
;
490 g_dynLights
[g_dynLightCount
].y
:= y
;
491 g_dynLights
[g_dynLightCount
].radius
:= 0;
492 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
493 g_dynLights
[g_dynLightCount
].r
:= r
;
494 g_dynLights
[g_dynLightCount
].g
:= g
;
495 g_dynLights
[g_dynLightCount
].b
:= b
;
496 g_dynLights
[g_dynLightCount
].a
:= 0;
497 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
498 Inc(g_dynLightCount
);
502 // ////////////////////////////////////////////////////////////////////////// //
503 function calcProfilesHeight (prof
: TProfiler
): Integer;
506 if (prof
= nil) then exit
;
507 if (length(prof
.bars
) = 0) then exit
;
508 result
:= length(prof
.bars
)*(16+2);
512 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
519 if (prof
= nil) then exit
;
521 if (length(prof
.bars
) = 0) then exit
;
523 hgt
:= calcProfilesHeight(prof
);
524 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
525 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
527 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
528 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
529 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
532 for ii
:= 0 to High(prof
.bars
) do
534 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);
541 // ////////////////////////////////////////////////////////////////////////// //
543 TEndCustomGameStat
= record
544 PlayerStat
: TPlayerStatArray
;
548 Map
, MapName
: String;
551 TEndSingleGameStat
= record
552 PlayerStat
: Array [0..1] of record
558 TotalSecrets
: Integer;
561 TLoadingStat
= record
565 Msgs
: Array of String;
567 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
570 TParamStrValue
= record
575 TParamStrValues
= Array of TParamStrValue
;
578 INTER_ACTION_TEXT
= 1;
579 INTER_ACTION_PIC
= 2;
580 INTER_ACTION_MUSIC
= 3;
584 FPSCounter
, UPSCounter
: Word;
585 FPSTime
, UPSTime
: LongWord;
586 DataLoaded
: Boolean = False;
587 IsDrawStat
: Boolean = False;
588 CustomStat
: TEndCustomGameStat
;
589 SingleStat
: TEndSingleGameStat
;
590 LoadingStat
: TLoadingStat
;
591 EndingGameCounter
: Byte = 0;
594 MessageLineLength
: Integer = 80;
595 MapList
: SSArray
= nil;
596 MapIndex
: Integer = -1;
597 InterReadyTime
: Integer = -1;
598 StatShotDone
: Boolean = False;
599 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
600 StatDate
: string = '';
606 text: Array of ShortString;
607 anim
: Array of ShortString;
608 pic
: Array of ShortString;
609 mus
: Array of ShortString;
611 triggers
: Array of record
613 actions
: Array of record
614 action
, p1
, p2
: Integer;
617 cur_trigger
: Integer;
630 function Compare(a
, b
: TPlayerStat
): Integer;
632 if a
.Spectator
then Result
:= 1
633 else if b
.Spectator
then Result
:= -1
634 else if a
.Frags
< b
.Frags
then Result
:= 1
635 else if a
.Frags
> b
.Frags
then Result
:= -1
636 else if a
.Deaths
< b
.Deaths
then Result
:= -1
637 else if a
.Deaths
> b
.Deaths
then Result
:= 1
638 else if a
.Kills
< b
.Kills
then Result
:= -1
642 procedure SortGameStat(var stat
: TPlayerStatArray
);
647 if stat
= nil then Exit
;
649 for I
:= High(stat
) downto Low(stat
) do
650 for J
:= Low(stat
) to High(stat
) - 1 do
651 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
654 stat
[J
] := stat
[J
+ 1];
659 // saves a shitty CSV containing the game stats passed to it
660 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
663 dir
, fname
, map
, mode
, etime
: String;
667 dir
:= e_GetWriteableDir(StatsDirs
);
668 // stats are placed in stats/yy/mm/dd/*.csv
669 fname
:= e_CatPath(dir
, Path
);
670 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
671 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
672 AssignFile(s
, fname
);
675 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
676 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
677 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
678 mode
:= g_Game_ModeToText(Stat
.GameMode
);
679 etime
:= Format('%d:%.2d:%.2d', [
680 Stat
.GameTime
div 1000 div 3600,
681 (Stat
.GameTime
div 1000 div 60) mod 60,
682 Stat
.GameTime
div 1000 mod 60
684 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
685 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
691 gGameSettings
.TimeLimit
,
692 gGameSettings
.GoalLimit
,
693 gGameSettings
.Options
,
695 Length(Stat
.PlayerStat
)
697 // line 2: game specific shit
698 // if it's a team game: red score, blue score
699 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
701 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
703 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
704 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
706 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
707 // lines 3-...: team, player name, frags, deaths
708 WriteLn(s
, 'team,name,frags,deaths');
709 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
710 with Stat
.PlayerStat
[I
] do
711 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
713 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
716 g_Console_Add('could not create gamestats file "' + fname
+ '"');
721 function g_Game_ModeToText(Mode
: Byte): string;
725 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
726 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
727 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
728 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
729 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
733 function g_Game_TextToMode(Mode
: string): Byte;
736 Mode
:= UpperCase(Mode
);
737 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
742 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
747 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
752 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
757 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
764 function g_Game_IsNet(): Boolean;
766 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
769 function g_Game_IsServer(): Boolean;
771 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
774 function g_Game_IsClient(): Boolean;
776 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
779 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
786 Result
.name
:= ExtractFileName(WAD
);
787 Result
.description
:= '';
790 w
:= TWADFile
.Create();
793 if not w
.GetResource('INTERSCRIPT', p
, len
) then
799 cfg
:= TConfig
.CreateMem(p
, len
);
800 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
801 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
802 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
803 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
809 procedure g_Game_FreeWAD();
813 for a
:= 0 to High(MegaWAD
.res
.pic
) do
814 if MegaWAD
.res
.pic
[a
] <> '' then
815 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
817 for a
:= 0 to High(MegaWAD
.res
.mus
) do
818 if MegaWAD
.res
.mus
[a
] <> '' then
819 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
821 MegaWAD
.res
.pic
:= nil;
822 MegaWAD
.res
.text := nil;
823 MegaWAD
.res
.anim
:= nil;
824 MegaWAD
.res
.mus
:= nil;
825 MegaWAD
.triggers
:= nil;
827 g_Texture_Delete('TEXTURE_endpic');
828 g_Sound_Delete('MUSIC_endmus');
830 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
831 gGameSettings
.WAD
:= '';
834 procedure g_Game_LoadWAD(WAD
: string);
843 gGameSettings
.WAD
:= WAD
;
844 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
847 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
849 w
:= TWADFile
.Create();
852 if not w
.GetResource('INTERSCRIPT', p
, len
) then
858 cfg
:= TConfig
.CreateMem(p
, len
);
863 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
864 if s = '' then Break;
867 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
868 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
870 g_Texture_CreateWADEx(s, s);
876 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
877 if s = '' then Break;
880 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
881 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
883 g_Music_CreateWADEx(s, s);
886 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
887 if MegaWAD
.endpic
<> '' then
889 TEXTUREFILTER
:= GL_LINEAR
;
890 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
891 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
892 TEXTUREFILTER
:= GL_NEAREST
;
894 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
895 if MegaWAD
.endmus
<> '' then
897 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
898 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
906 {procedure start_trigger(t: string);
910 function next_trigger(): Boolean;
914 procedure DisableCheats();
920 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
921 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
922 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
923 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
925 {$IF DEFINED(D2F_DEBUG)}
926 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
927 gAimLine
:= g_dbg_aimline_on
;
931 procedure g_Game_ExecuteEvent(Name
: String);
937 if gEvents
= nil then
939 for a
:= 0 to High(gEvents
) do
940 if gEvents
[a
].Name
= Name
then
942 if gEvents
[a
].Command
<> '' then
943 g_Console_Process(gEvents
[a
].Command
, True);
948 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
953 if gDelayedEvents
<> nil then
954 for a
:= 0 to High(gDelayedEvents
) do
955 if not gDelayedEvents
[a
].Pending
then
962 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
963 n
:= High(gDelayedEvents
);
965 gDelayedEvents
[n
].Pending
:= True;
966 gDelayedEvents
[n
].DEType
:= DEType
;
967 gDelayedEvents
[n
].DENum
:= Num
;
968 gDelayedEvents
[n
].DEStr
:= Str
;
969 if DEType
= DE_GLOBEVENT
then
970 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
972 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
982 if g_Game_IsNet
and g_Game_IsServer
then
983 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
987 gPauseHolmes
:= false;
990 g_Game_StopAllSounds(False);
995 EndingGameCounter
:= 0;
996 g_ActiveWindow
:= nil;
998 gLMSRespawn
:= LMS_RESPAWN_NONE
;
999 gLMSRespawnTime
:= 0;
1002 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1007 begin // Ýòî áûë òåñò
1011 begin // Âûõîä â ãëàâíîå ìåíþ
1012 gMusic
.SetByName('MUSIC_MENU');
1014 if gState
<> STATE_SLIST
then
1016 g_GUI_ShowWindow('MainMenu');
1017 gState
:= STATE_MENU
;
1020 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1021 slReturnPressed
:= True;
1022 if g_Net_Slist_Fetch(slCurrent
) then
1024 if slCurrent
= nil then
1025 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1028 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1029 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1032 g_Game_ExecuteEvent('ongameend');
1036 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1038 if not g_Game_IsClient
then g_Game_Restart();
1041 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1043 // Ñòàòèñòèêà Ñâîåé èãðû:
1044 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1046 CustomStat
.GameTime
:= gTime
;
1047 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1048 CustomStat
.MapName
:= gMapInfo
.Name
;
1049 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1050 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1051 CustomStat
.TeamStat
:= gTeamStat
;
1053 CustomStat
.PlayerStat
:= nil;
1055 // Ñòàòèñòèêà èãðîêîâ:
1056 if gPlayers
<> nil then
1058 for a
:= 0 to High(gPlayers
) do
1059 if gPlayers
[a
] <> nil then
1061 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1062 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1065 Name
:= gPlayers
[a
].Name
;
1066 Frags
:= gPlayers
[a
].Frags
;
1067 Deaths
:= gPlayers
[a
].Death
;
1068 Kills
:= gPlayers
[a
].Kills
;
1069 Team
:= gPlayers
[a
].Team
;
1070 Color
:= gPlayers
[a
].Model
.Color
;
1071 Spectator
:= gPlayers
[a
].FSpectator
;
1075 SortGameStat(CustomStat
.PlayerStat
);
1077 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1080 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1081 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1082 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1083 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1085 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1088 StatShotDone
:= False;
1091 g_Game_ExecuteEvent('onmapend');
1092 if not g_Game_IsClient
then g_Player_ResetReady
;
1093 gInterReadyCount
:= 0;
1095 // Çàòóõàþùèé ýêðàí:
1096 EndingGameCounter
:= 255;
1097 gState
:= STATE_FOLD
;
1099 if gDefInterTime
< 0 then
1100 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1102 gInterEndTime
:= gDefInterTime
* 1000;
1105 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1107 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1108 SingleStat
.GameTime
:= gTime
;
1109 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1110 SingleStat
.TotalSecrets
:= gSecretsCount
;
1111 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1112 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1113 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1114 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1115 if SingleStat
.TwoPlayers
then
1117 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1118 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1121 g_Game_ExecuteEvent('onmapend');
1124 if gNextMap
<> '' then
1126 gMusic
.SetByName('MUSIC_INTERMUS');
1128 gState
:= STATE_INTERSINGLE
;
1131 g_Game_ExecuteEvent('oninter');
1133 else // Áîëüøå íåò êàðò
1135 // Çàòóõàþùèé ýêðàí:
1136 EndingGameCounter
:= 255;
1137 gState
:= STATE_FOLD
;
1142 // Îêîí÷àíèå îáðàáîòàíî:
1143 if gExit
<> EXIT_QUIT
then
1147 procedure drawTime(X
, Y
: Integer); inline;
1149 e_TextureFontPrint(x
, y
,
1150 Format('%d:%.2d:%.2d', [
1151 gTime
div 1000 div 3600,
1152 (gTime
div 1000 div 60) mod 60,
1153 gTime
div 1000 mod 60
1158 procedure DrawStat();
1160 pc
, x
, y
, w
, h
: Integer;
1161 w1
, w2
, w3
, w4
: Integer;
1163 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1166 stat
: TPlayerStatArray
;
1174 pc
:= g_Player_GetCount
;
1175 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1177 w
:= gScreenWidth
-(gScreenWidth
div 5);
1178 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1181 h
:= 40+ch
*5+(ch
+8)*pc
;
1182 x
:= (gScreenWidth
div 2)-(w
div 2);
1183 y
:= (gScreenHeight
div 2)-(h
div 2);
1185 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1186 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1188 drawTime(x
+w
-78, y
+8);
1190 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1191 map
:= g_ExtractFileName(gMapInfo
.Map
);
1192 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1194 case gGameSettings
.GameMode
of
1197 if gGameSettings
.MaxLives
= 0 then
1198 s1
:= _lc
[I_GAME_DM
]
1200 s1
:= _lc
[I_GAME_LMS
];
1201 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1202 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1207 if gGameSettings
.MaxLives
= 0 then
1208 s1
:= _lc
[I_GAME_TDM
]
1210 s1
:= _lc
[I_GAME_TLMS
];
1211 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1212 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1217 s1
:= _lc
[I_GAME_CTF
];
1218 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1219 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1224 if gGameSettings
.MaxLives
= 0 then
1225 s1
:= _lc
[I_GAME_COOP
]
1227 s1
:= _lc
[I_GAME_SURV
];
1228 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1229 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1240 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1242 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1244 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1246 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1247 gStdFont
, 200, 200, 200, 1);
1249 if NetMode
= NET_SERVER
then
1250 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1252 if NetMode
= NET_CLIENT
then
1253 e_TextureFontPrintEx(x
+8, y
+ 8,
1254 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1258 stat
:= g_Player_GetStats();
1261 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1262 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1264 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1266 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1270 for a
:= TEAM_RED
to TEAM_BLUE
do
1272 if a
= TEAM_RED
then
1274 s1
:= _lc
[I_GAME_TEAM_RED
];
1281 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1287 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1288 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1289 gStdFont
, r
, g
, b
, 1);
1291 _y
:= _y
+ch
+(ch
div 4);
1292 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1293 _y
:= _y
+(ch
div 4);
1295 for aa
:= 0 to High(stat
) do
1296 if stat
[aa
].Team
= a
then
1312 namestr
:= Format('[%5d] %s', [UID
, Name
])
1316 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1318 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1320 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1322 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1329 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1332 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1333 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1334 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1335 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1338 for aa
:= 0 to High(stat
) do
1352 namestr
:= Format('[%5d] %s', [UID
, Name
])
1356 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1357 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1359 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1361 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1363 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1365 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1371 procedure g_Game_Init();
1374 knownFiles
: array of AnsiString = nil;
1376 wext
, s
: AnsiString;
1381 gTempDelete
:= False;
1383 sfsGCDisable(); // temporary disable removing of temporary volumes
1386 TEXTUREFILTER
:= GL_LINEAR
;
1387 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1388 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1389 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1390 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1391 TEXTUREFILTER
:= GL_NEAREST
;
1393 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1394 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1395 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1397 g_Game_ClearLoading();
1398 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1399 g_Game_SetLoadingText('', 0, False);
1401 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1404 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1405 g_PlayerModel_LoadData();
1407 // load models from all possible wad types, in all known directories
1408 // this does a loosy job (linear search, ooph!), but meh
1409 for wext
in wadExtensions
do
1411 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1413 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1417 for s
in knownFiles
do
1419 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1427 SetLength(knownFiles
, length(knownFiles
)+1);
1428 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1430 until (FindNext(SR
) <> 0);
1436 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1438 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
);
1439 for s
in knownFiles
do
1441 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1445 gPauseMain
:= false;
1446 gPauseHolmes
:= false;
1449 {e_MouseInfo.Accel := 1.0;}
1451 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1454 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1455 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1456 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1457 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1458 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1461 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1465 gMusic
:= TMusic
.Create();
1466 gMusic
.SetByName('MUSIC_MENU');
1469 gGameSettings
.WarmupTime
:= 30;
1471 gState
:= STATE_MENU
;
1473 SetLength(gEvents
, 6);
1474 gEvents
[0].Name
:= 'ongamestart';
1475 gEvents
[1].Name
:= 'ongameend';
1476 gEvents
[2].Name
:= 'onmapstart';
1477 gEvents
[3].Name
:= 'onmapend';
1478 gEvents
[4].Name
:= 'oninter';
1479 gEvents
[5].Name
:= 'onwadend';
1481 sfsGCEnable(); // enable releasing unused volumes
1485 procedure g_Game_Free(freeTextures
: Boolean=true);
1487 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1488 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1490 g_Map_Free(freeTextures
);
1492 g_Player_RemoveAllCorpses();
1494 gGameSettings
.GameType
:= GT_NONE
;
1495 if gGameSettings
.GameMode
= GM_SINGLE
then
1496 gGameSettings
.GameMode
:= GM_DM
;
1497 gSwitchGameMode
:= gGameSettings
.GameMode
;
1500 gExitByTrigger
:= False;
1503 function IsActivePlayer(p
: TPlayer
): Boolean;
1508 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1511 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1518 if gPlayers
= nil then
1520 for a
:= Low(gPlayers
) to High(gPlayers
) do
1521 if IsActivePlayer(gPlayers
[a
]) then
1523 if gPlayers
[a
].UID
<> ID
then
1525 Result
:= gPlayers
[a
];
1530 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1536 if gPlayers
= nil then
1540 for a
:= Low(gPlayers
) to High(gPlayers
) do
1541 if IsActivePlayer(gPlayers
[a
]) then
1543 SetLength(ids
, Length(ids
) + 1);
1544 ids
[High(ids
)] := gPlayers
[a
].UID
;
1545 if gPlayers
[a
].UID
= Skip
then
1548 if Length(ids
) = 0 then
1553 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1556 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1562 if gPlayers
= nil then
1566 for a
:= Low(gPlayers
) to High(gPlayers
) do
1567 if IsActivePlayer(gPlayers
[a
]) then
1569 SetLength(ids
, Length(ids
) + 1);
1570 ids
[High(ids
)] := gPlayers
[a
].UID
;
1571 if gPlayers
[a
].UID
= Skip
then
1574 if Length(ids
) = 0 then
1577 Result
:= ids
[Length(ids
) - 1]
1579 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1582 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1588 if gPlayers
= nil then
1592 for a
:= Low(gPlayers
) to High(gPlayers
) do
1593 if IsActivePlayer(gPlayers
[a
]) then
1595 SetLength(ids
, Length(ids
) + 1);
1596 ids
[High(ids
)] := gPlayers
[a
].UID
;
1597 if gPlayers
[a
].UID
= Skip
then
1600 if Length(ids
) = 0 then
1602 if Length(ids
) = 1 then
1607 Result
:= ids
[Random(Length(ids
))];
1609 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1611 Result
:= ids
[Random(Length(ids
))];
1616 function GetRandomSpectMode(Current
: Byte): Byte;
1623 0: Result
:= SPECT_STATS
;
1624 1: Result
:= SPECT_MAPVIEW
;
1625 2: Result
:= SPECT_MAPVIEW
;
1626 3: Result
:= SPECT_PLAYERS
;
1627 4: Result
:= SPECT_PLAYERS
;
1628 5: Result
:= SPECT_PLAYERS
;
1629 6: Result
:= SPECT_PLAYERS
;
1631 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1635 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1641 if (plr
= nil) then exit
;
1642 if (p
= 2) then time
:= 1000 else time
:= 1;
1643 strafeDir
:= MoveButton
shr 4;
1644 MoveButton
:= MoveButton
and $0F;
1646 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1647 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1648 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1649 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1650 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1651 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1653 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1654 if MoveButton
= 1 then
1655 plr
.PressKey(KEY_LEFT
, time
)
1656 else if MoveButton
= 2 then
1657 plr
.PressKey(KEY_RIGHT
, time
);
1659 // if we have "strafe" key, turn off old strafe mechanics
1660 if gPlayerAction
[p
, ACTION_STRAFE
] then
1662 // new strafe mechanics
1663 if (strafeDir
= 0) then
1664 strafeDir
:= MoveButton
; // start strafing
1665 // now set direction according to strafe (reversed)
1666 if (strafeDir
= 2) then
1667 plr
.SetDirection(TDirection
.D_LEFT
)
1668 else if (strafeDir
= 1) then
1669 plr
.SetDirection(TDirection
.D_RIGHT
)
1673 strafeDir
:= 0; // not strafing anymore
1674 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1675 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1676 plr
.SetDirection(TDirection
.D_LEFT
)
1677 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1678 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1679 plr
.SetDirection(TDirection
.D_RIGHT
)
1680 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1681 else if MoveButton
<> 0 then
1682 plr
.SetDirection(TDirection(MoveButton
-1))
1685 // fix movebutton state
1686 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1688 // Îñòàëüíûå êëàâèøè:
1689 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1690 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1691 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1692 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1693 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1694 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1695 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1697 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1698 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1700 for i
:= WP_FIRST
to WP_LAST
do
1702 if gSelectWeapon
[p
, i
] then
1704 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1705 gSelectWeapon
[p
, i
] := False
1709 // HACK: add dynlight here
1710 if gwin_k8_enable_light_experiments
then
1712 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1714 g_playerLight
:= true;
1716 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1718 g_playerLight
:= false;
1722 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1725 // HACK: don't have a "key was pressed" function
1726 procedure InterReady();
1728 if InterReadyTime
> gTime
then Exit
;
1729 InterReadyTime
:= gTime
+ 3000;
1730 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1733 procedure g_Game_PreUpdate();
1735 // these are in separate PreUpdate functions because they can interact during Update()
1736 // and are synced over the net
1737 // we don't care that much about corpses and gibs
1738 g_Player_PreUpdate();
1739 g_Monsters_PreUpdate();
1740 g_Items_PreUpdate();
1741 g_Weapon_PreUpdate();
1744 procedure g_Game_Update();
1746 Msg
: g_gui
.TMessage
;
1752 function sendMonsPos (mon
: TMonster
): Boolean;
1754 result
:= false; // don't stop
1755 // this will also reset "need-send" flag
1756 if mon
.gncNeedSend
then
1758 MH_SEND_MonsterPos(mon
.UID
);
1760 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1762 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1764 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1766 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1770 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1772 result
:= false; // don't stop
1773 // this will also reset "need-send" flag
1774 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1778 reliableUpdate
: Boolean;
1783 // Ïîðà âûêëþ÷àòü èãðó:
1784 if gExit
= EXIT_QUIT
then
1786 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1790 if gExit
= EXIT_QUIT
then
1794 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1795 // no need to, as we'll do it in event handler
1797 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1800 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1802 gExit
:= EXIT_SIMPLE
;
1807 // process master server communications
1808 g_Net_Slist_Pulse();
1811 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1812 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1813 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1814 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1816 if g_Game_IsNet
and g_Game_IsServer
then
1818 gInterTime
:= gInterTime
+ GAME_TICK
;
1819 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1820 if a
<> gServInterTime
then
1822 gServInterTime
:= a
;
1823 MH_SEND_TimeSync(gServInterTime
);
1827 if (not g_Game_IsClient
) and
1831 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1832 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1833 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1834 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1836 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1837 and (g_ActiveWindow
= nil)
1839 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1842 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1843 g_Game_StopAllSounds(True);
1845 if gMapOnce
then // Ýòî áûë òåñò
1846 gExit
:= EXIT_SIMPLE
1848 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1849 g_Game_ChangeMap(gNextMap
)
1850 else // Ñëåäóþùåé êàðòû íåò
1852 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1854 // Âûõîä â ãëàâíîå ìåíþ:
1856 g_GUI_ShowWindow('MainMenu');
1857 gMusic
.SetByName('MUSIC_MENU');
1859 gState
:= STATE_MENU
;
1862 // Ôèíàëüíàÿ êàðòèíêà:
1863 g_Game_ExecuteEvent('onwadend');
1865 if not gMusic
.SetByName('MUSIC_endmus') then
1866 gMusic
.SetByName('MUSIC_STDENDMUS');
1868 gState
:= STATE_ENDPIC
;
1870 g_Game_ExecuteEvent('ongameend');
1875 else if g_Game_IsClient
and
1878 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1879 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1880 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1881 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1883 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1884 and (g_ActiveWindow
= nil)
1892 if gState
= STATE_INTERTEXT
then
1893 if InterText
.counter
> 0 then
1894 InterText
.counter
:= InterText
.counter
- 1;
1897 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1899 if EndingGameCounter
= 0 then
1901 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1902 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1904 InterReadyTime
:= -1;
1905 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1907 g_Game_ExecuteEvent('onwadend');
1908 if not gMusic
.SetByName('MUSIC_endmus') then
1909 gMusic
.SetByName('MUSIC_STDENDMUS');
1912 gMusic
.SetByName('MUSIC_ROUNDMUS');
1915 gState
:= STATE_INTERCUSTOM
;
1918 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1920 gMusic
.SetByName('MUSIC_INTERMUS');
1922 gState
:= STATE_INTERSINGLE
;
1925 g_Game_ExecuteEvent('oninter');
1928 DecMin(EndingGameCounter
, 6, 0);
1931 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1933 if gMapOnce
then // Ýòî áûë òåñò
1935 gExit
:= EXIT_SIMPLE
;
1941 g_Serverlist_Control(slCurrent
, slTable
);
1944 // Ñòàòèñòèêà ïî Tab:
1946 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1949 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1951 // Âðåìÿ += 28 ìèëëèñåêóíä:
1952 gTime
:= gTime
+ GAME_TICK
;
1954 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1955 if MessageTime
= 0 then
1957 if MessageTime
> 0 then
1958 MessageTime
:= MessageTime
- 1;
1960 if (g_Game_IsServer
) then
1962 // Áûë çàäàí ëèìèò âðåìåíè:
1963 if (gGameSettings
.TimeLimit
> 0) then
1964 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1965 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1970 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1971 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1972 g_Game_RestartRound(gLMSSoftSpawn
);
1974 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1975 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1977 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1979 g_Console_Process(gVoteCommand
);
1981 gVotePassed
:= False;
1984 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1985 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1986 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1987 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1988 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1990 // Áûë çàäàí ëèìèò ïîáåä:
1991 if (gGameSettings
.GoalLimit
> 0) then
1995 if gGameSettings
.GameMode
= GM_DM
then
1996 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1997 for i
:= 0 to High(gPlayers
) do
1998 if gPlayers
[i
] <> nil then
1999 if gPlayers
[i
].Frags
> b
then
2000 b
:= gPlayers
[i
].Frags
;
2003 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2004 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2005 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2008 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2009 if b
>= gGameSettings
.GoalLimit
then
2016 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2017 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2018 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2019 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2021 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2022 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2023 end // if not console
2026 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2028 // process weapon switch queue
2032 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2033 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2035 if not gSpectKeyPress
then
2037 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2039 // switch spect mode
2041 SPECT_NONE
: ; // not spectator
2043 SPECT_MAPVIEW
: Inc(gSpectMode
);
2044 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2046 gSpectKeyPress
:= True;
2048 if (gSpectMode
= SPECT_MAPVIEW
)
2049 and (not gSpectAuto
) then
2051 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2052 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2053 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2054 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2055 if gPlayerAction
[0, ACTION_LOOKUP
] then
2056 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2057 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2058 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2059 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2062 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2063 gSpectKeyPress
:= True;
2065 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2068 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2069 gSpectKeyPress
:= True;
2072 if (gSpectMode
= SPECT_PLAYERS
)
2073 and (not gSpectAuto
) then
2075 if gPlayerAction
[0, ACTION_LOOKUP
] then
2078 gSpectViewTwo
:= True;
2079 gSpectKeyPress
:= True;
2081 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2083 // remove second view
2084 gSpectViewTwo
:= False;
2085 gSpectKeyPress
:= True;
2087 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2089 // prev player (view 1)
2090 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2091 gSpectKeyPress
:= True;
2093 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2095 // next player (view 1)
2096 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2097 gSpectKeyPress
:= True;
2099 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2101 // prev player (view 2)
2102 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2103 gSpectKeyPress
:= True;
2105 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2107 // next player (view 2)
2108 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2109 gSpectKeyPress
:= True;
2112 if gPlayerAction
[0, ACTION_ATTACK
] then
2114 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2117 gSpectAutoNext
:= 0;
2118 gSpectViewTwo
:= False;
2119 gSpectKeyPress
:= True;
2124 gSpectMode
:= SPECT_STATS
;
2125 gSpectAuto
:= False;
2126 gSpectKeyPress
:= True;
2131 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2132 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2133 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2134 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2135 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2136 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2137 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2138 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2139 gSpectKeyPress
:= False;
2143 if gSpectMode
= SPECT_MAPVIEW
then
2145 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2147 gSpectAutoNext
:= gTime
2150 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2152 gSpectAutoNext
:= gTime
2156 if gSpectAutoNext
<= gTime
then
2158 if gSpectAutoNext
> 0 then
2160 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2164 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2165 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2166 gSpectAutoStepX
:= Random(9) - 4;
2167 gSpectAutoStepY
:= Random(9) - 4;
2168 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2169 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2170 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2171 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2172 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2173 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2177 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2182 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2183 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2184 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2190 // Îáíîâëÿåì âñå îñòàëüíîå:
2193 g_Triggers_Update();
2195 g_Monsters_Update();
2197 g_Player_UpdateAll();
2198 g_Player_UpdatePhysicalObjects();
2200 // server: send newly spawned monsters unconditionally
2201 if (gGameSettings
.GameType
= GT_SERVER
) then
2203 if (Length(gMonstersSpawned
) > 0) then
2205 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2206 SetLength(gMonstersSpawned
, 0);
2210 if (gSoundTriggerTime
> 8) then
2212 g_Game_UpdateTriggerSounds();
2213 gSoundTriggerTime
:= 0;
2217 Inc(gSoundTriggerTime
);
2220 if (NetMode
= NET_SERVER
) then
2222 Inc(NetTimeToUpdate
);
2223 Inc(NetTimeToReliable
);
2225 // send monster updates
2226 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2228 // send all monsters (periodic sync)
2229 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2231 for I
:= 0 to High(gPlayers
) do
2233 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2236 g_Mons_ForEach(sendMonsPos
);
2238 if reliableUpdate
then
2240 NetTimeToReliable
:= 0;
2241 NetTimeToUpdate
:= NetUpdateRate
;
2245 NetTimeToUpdate
:= 0;
2250 // send only mosters with some unexpected changes
2251 g_Mons_ForEach(sendMonsPosUnexpected
);
2254 // send unexpected platform changes
2255 g_Map_NetSendInterestingPanels();
2257 g_Net_Slist_ServerUpdate();
2259 if NetUseMaster then
2261 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2263 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2265 NetTimeToMaster := gTime + NetMasterRate;
2270 else if (NetMode
= NET_CLIENT
) then
2272 MC_SEND_PlayerPos();
2274 end; // if gameOn ...
2276 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2277 if g_ActiveWindow
<> nil then
2279 w
:= e_GetFirstKeyPressed();
2281 if (w
<> IK_INVALID
) then
2283 Msg
.Msg
:= MESSAGE_DIKEY
;
2285 g_ActiveWindow
.OnMessage(Msg
);
2288 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2289 if g_ActiveWindow
<> nil then
2290 g_ActiveWindow
.Update();
2292 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2293 if gResolutionChange
then
2295 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2296 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2297 gResolutionChange
:= False;
2298 g_ActiveWindow
:= nil;
2301 // Íóæíî ñìåíèòü ÿçûê:
2302 if gLanguageChange
then
2304 //e_WriteLog('Read language file', MSG_NOTIFY);
2305 //g_Language_Load(DataDir + gLanguage + '.txt');
2306 g_Language_Set(gLanguage
);
2310 gLanguageChange
:= False;
2314 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2315 if e_KeyPressed(IK_F10
) and
2317 (not gConsoleShow
) and
2318 (g_ActiveWindow
= nil) then
2323 Time
:= sys_GetTicks() {div 1000};
2325 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2326 if gDelayedEvents
<> nil then
2327 for a
:= 0 to High(gDelayedEvents
) do
2328 if gDelayedEvents
[a
].Pending
and
2330 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2331 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2334 case gDelayedEvents
[a
].DEType
of
2336 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2339 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2343 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2344 if g_Game_IsNet
and g_Game_IsServer
then
2345 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2349 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2351 gDelayedEvents
[a
].Pending
:= False;
2354 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2355 UPSCounter
:= UPSCounter
+ 1;
2356 if Time
- UPSTime
>= 1000 then
2365 g_Weapon_AddDynLights();
2366 g_Items_AddDynLights();
2370 procedure g_Game_LoadChatSounds(Resource
: string);
2373 FileName
, Snd
: string;
2375 len
, cnt
, tags
, i
, j
: Integer;
2378 FileName
:= g_ExtractWadName(Resource
);
2380 WAD
:= TWADFile
.Create();
2381 WAD
.ReadFile(FileName
);
2383 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2390 cfg
:= TConfig
.CreateMem(p
, len
);
2391 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2393 SetLength(gChatSounds
, cnt
);
2394 for i
:= 0 to Length(gChatSounds
) - 1 do
2396 gChatSounds
[i
].Sound
:= nil;
2397 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2398 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2399 if (Snd
= '') or (Tags
<= 0) then
2401 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2402 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2403 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2404 SetLength(gChatSounds
[i
].Tags
, tags
);
2405 for j
:= 0 to tags
- 1 do
2406 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2407 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2414 procedure g_Game_FreeChatSounds();
2418 for i
:= 0 to Length(gChatSounds
) - 1 do
2420 gChatSounds
[i
].Sound
.Free();
2421 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2423 SetLength(gChatSounds
, 0);
2427 procedure g_Game_LoadData();
2434 if DataLoaded
then Exit
;
2436 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2438 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2439 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2440 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2441 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2442 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2443 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2444 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2445 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2446 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2447 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2448 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2449 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2450 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2451 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2452 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2455 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2456 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2457 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2458 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2462 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2463 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2464 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2465 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2466 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
2472 hasPBarGfx
:= false;
2476 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2477 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2478 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2479 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2480 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2481 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2482 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2483 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2484 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2485 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2486 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2487 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2488 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2489 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2490 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2491 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2492 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2493 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2494 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2495 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2496 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2497 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2498 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2499 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2500 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2507 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2508 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2509 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2510 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2511 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2512 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2513 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2514 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2516 goodsnd
[0] := TPlayableSound
.Create();
2517 goodsnd
[1] := TPlayableSound
.Create();
2518 goodsnd
[2] := TPlayableSound
.Create();
2519 goodsnd
[3] := TPlayableSound
.Create();
2521 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2522 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2523 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2524 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2526 killsnd
[0] := TPlayableSound
.Create();
2527 killsnd
[1] := TPlayableSound
.Create();
2528 killsnd
[2] := TPlayableSound
.Create();
2529 killsnd
[3] := TPlayableSound
.Create();
2531 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2532 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2533 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2534 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2536 hahasnd
[0] := TPlayableSound
.Create();
2537 hahasnd
[1] := TPlayableSound
.Create();
2538 hahasnd
[2] := TPlayableSound
.Create();
2540 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2541 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2542 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2544 sound_get_flag
[0] := TPlayableSound
.Create();
2545 sound_get_flag
[1] := TPlayableSound
.Create();
2546 sound_lost_flag
[0] := TPlayableSound
.Create();
2547 sound_lost_flag
[1] := TPlayableSound
.Create();
2548 sound_ret_flag
[0] := TPlayableSound
.Create();
2549 sound_ret_flag
[1] := TPlayableSound
.Create();
2550 sound_cap_flag
[0] := TPlayableSound
.Create();
2551 sound_cap_flag
[1] := TPlayableSound
.Create();
2553 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2554 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2555 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2556 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2557 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2558 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2559 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2560 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2562 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2564 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2567 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2568 g_Weapon_LoadData();
2570 g_Monsters_LoadData();
2575 procedure g_Game_FreeData();
2577 if not DataLoaded
then Exit
;
2580 g_Weapon_FreeData();
2581 g_Monsters_FreeData();
2583 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2585 g_Texture_Delete('NOTEXTURE');
2586 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2587 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2588 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2589 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2590 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2591 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2592 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2593 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2594 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2595 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2596 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2597 g_Frames_DeleteByName('FRAMES_TELEPORT');
2598 g_Frames_DeleteByName('FRAMES_PUNCH');
2599 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2600 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2601 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2602 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2603 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2604 g_Sound_Delete('SOUND_GAME_TELEPORT');
2605 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2606 g_Sound_Delete('SOUND_GAME_SECRET');
2607 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2608 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2609 g_Sound_Delete('SOUND_GAME_BULK1');
2610 g_Sound_Delete('SOUND_GAME_BULK2');
2611 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2612 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2613 g_Sound_Delete('SOUND_GAME_BURNING');
2614 g_Sound_Delete('SOUND_GAME_SWITCH1');
2615 g_Sound_Delete('SOUND_GAME_SWITCH0');
2622 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2623 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2624 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2625 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2632 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2633 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2634 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2635 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2641 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2642 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2643 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2645 sound_get_flag
[0].Free();
2646 sound_get_flag
[1].Free();
2647 sound_lost_flag
[0].Free();
2648 sound_lost_flag
[1].Free();
2649 sound_ret_flag
[0].Free();
2650 sound_ret_flag
[1].Free();
2651 sound_cap_flag
[0].Free();
2652 sound_cap_flag
[1].Free();
2654 g_Sound_Delete('SOUND_CTF_GET1');
2655 g_Sound_Delete('SOUND_CTF_GET2');
2656 g_Sound_Delete('SOUND_CTF_LOST1');
2657 g_Sound_Delete('SOUND_CTF_LOST2');
2658 g_Sound_Delete('SOUND_CTF_RETURN1');
2659 g_Sound_Delete('SOUND_CTF_RETURN2');
2660 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2661 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2663 g_Game_FreeChatSounds();
2665 DataLoaded
:= False;
2668 procedure DrawCustomStat();
2674 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2675 s1
, s2
, topstr
: String;
2677 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2681 if g_Console_Action(ACTION_SCORES
) then
2683 if not gStatsPressed
then
2685 gStatsOff
:= not gStatsOff
;
2686 gStatsPressed
:= True;
2690 gStatsPressed
:= False;
2694 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2695 w
:= (Length(s1
) * ww2
) div 2;
2696 x
:= gScreenWidth
div 2 - w
;
2698 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2702 if (gGameSettings
.GameMode
= GM_COOP
) then
2704 if gMissionFailed
then
2705 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2707 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2710 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2712 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2713 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2715 if g_Game_IsNet
then
2717 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2718 if not gChatShow
then
2719 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2720 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2723 if g_Game_IsClient
then
2724 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2726 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2727 if not gChatShow
then
2728 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2729 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2734 w
:= gScreenWidth
-x
*2;
2740 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2741 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2743 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2745 case CustomStat
.GameMode
of
2748 if gGameSettings
.MaxLives
= 0 then
2749 s1
:= _lc
[I_GAME_DM
]
2751 s1
:= _lc
[I_GAME_LMS
];
2755 if gGameSettings
.MaxLives
= 0 then
2756 s1
:= _lc
[I_GAME_TDM
]
2758 s1
:= _lc
[I_GAME_TLMS
];
2760 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2763 if gGameSettings
.MaxLives
= 0 then
2764 s1
:= _lc
[I_GAME_COOP
]
2766 s1
:= _lc
[I_GAME_SURV
];
2772 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2776 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2777 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2780 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2781 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2782 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2783 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2785 pc
:= Length(CustomStat
.PlayerStat
);
2786 if pc
= 0 then Exit
;
2788 if CustomStat
.GameMode
= GM_COOP
then
2790 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2792 s2
:= _lc
[I_GAME_MONSTERS
];
2793 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2794 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2796 s2
:= _lc
[I_GAME_SECRETS
];
2797 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2798 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2801 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2803 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2804 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2805 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2807 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2808 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2809 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2813 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2818 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2819 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2820 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2822 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2825 for t
:= TEAM_RED
to TEAM_BLUE
do
2827 if t
= TEAM_RED
then
2829 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2830 gStdFont
, 255, 0, 0, 1);
2831 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2832 gStdFont
, 255, 0, 0, 1);
2839 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2840 gStdFont
, 0, 0, 255, 1);
2841 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2842 gStdFont
, 0, 0, 255, 1);
2848 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2851 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2852 if CustomStat
.PlayerStat
[p
].Team
= t
then
2853 with CustomStat
.PlayerStat
[p
] do
2867 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2868 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2870 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2871 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2872 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2879 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2882 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2883 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2884 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2887 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2888 with CustomStat
.PlayerStat
[p
] do
2890 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2897 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2898 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2900 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2901 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2902 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2907 // HACK: take stats screenshot immediately after the first frame of the stats showing
2908 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2910 g_TakeScreenShot('stats/' + StatFilename
);
2911 StatShotDone
:= True;
2915 procedure DrawSingleStat();
2917 tm
, key_x
, val_x
, y
: Integer;
2921 procedure player_stat(n
: Integer);
2927 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2928 s2
:= Format(' %d', [gTotalMonsters
]);
2930 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2931 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2932 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2933 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2935 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2936 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2938 // "Kills-per-minute: ##.#":
2939 s1
:= _lc
[I_MENU_INTER_KPM
];
2941 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2943 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2944 s2
:= Format(' %.1f', [kpm
]);
2946 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2947 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2949 // "Secrets found: # / #":
2950 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2951 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2953 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2954 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2955 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2956 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2958 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2959 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2963 // "Level Complete":
2964 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2965 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2967 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2968 s1
:= _lc
[I_MENU_INTER_KPM
];
2969 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2972 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2974 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2975 val_x
:= key_x
+ w1
;
2978 tm
:= SingleStat
.GameTime
div 1000;
2979 s1
:= _lc
[I_MENU_INTER_TIME
];
2980 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2982 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2983 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2985 if SingleStat
.TwoPlayers
then
2988 s1
:= _lc
[I_MENU_PLAYER_1
];
2989 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2990 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2992 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2997 s1
:= _lc
[I_MENU_PLAYER_2
];
2998 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2999 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3001 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3007 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3013 procedure DrawLoadingStat();
3014 procedure drawRect (x
, y
, w
, h
: Integer);
3016 if (w
< 1) or (h
< 1) then exit
;
3018 glVertex2f(x
+0.375, y
+0.375);
3019 glVertex2f(x
+w
+0.375, y
+0.375);
3020 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3021 glVertex2f(x
+0.375, y
+h
+0.375);
3025 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3027 rectW
, rectH
: Integer;
3034 idl
, idr
, idb
, idm
: LongWord;
3038 if (total
< 1) then exit
;
3039 if (cur
< 1) then exit
; // don't blink
3040 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3041 //if (cur < 0) then cur := 0;
3042 //if (cur > total) then cur := total;
3045 if (hasPBarGfx
) then
3047 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3048 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3049 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3050 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3051 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3052 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3053 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3054 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3056 //rectW := gScreenWidth-360;
3057 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3060 x0
:= (gScreenWidth
-rectW
) div 2;
3061 y0
:= gScreenHeight
-rectH
-64;
3062 if (y0
< 2) then y0
:= 2;
3064 glEnable(GL_SCISSOR_TEST
);
3067 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3068 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3069 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3072 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3074 while (f
< x0
+rectW
) do
3076 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3081 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3082 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3085 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3086 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3090 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3096 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3100 rectW
:= gScreenWidth
-64;
3103 x0
:= (gScreenWidth
-rectW
) div 2;
3104 y0
:= gScreenHeight
-rectH
-64;
3105 if (y0
< 2) then y0
:= 2;
3107 glDisable(GL_BLEND
);
3108 glDisable(GL_TEXTURE_2D
);
3110 //glClearColor(0, 0, 0, 0);
3111 //glClear(GL_COLOR_BUFFER_BIT);
3113 glColor4ub(127, 127, 127, 255);
3114 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3116 glColor4ub(0, 0, 0, 255);
3117 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3119 glColor4ub(127, 127, 127, 255);
3120 wdt
:= rectW
*cur
div total
;
3121 if (wdt
> rectW
) then wdt
:= rectW
;
3122 drawRect(x0
, y0
, wdt
, rectH
);
3131 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3133 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3134 yy
:= (gScreenHeight
div 3);
3135 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3136 xx
:= (gScreenWidth
div 3);
3140 for i
:= 0 to NextMsg
-1 do
3142 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3143 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3147 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3148 yy
:= yy
+ LOADING_INTERLINE
;
3149 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3154 procedure DrawMenuBackground(tex
: AnsiString);
3160 if g_Texture_Get(tex
, ID
) then
3162 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3163 e_GetTextureSize(ID
, @w
, @h
);
3165 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3167 w
:= trunc(w
* (gScreenHeight
/ h
));
3168 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3170 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3173 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3175 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3177 function monDraw (mon
: TMonster
): Boolean;
3179 result
:= false; // don't stop
3184 // Ëåâûé âåðõíèé óãîë
3185 aX
:= Obj
.X
div ScaleSz
+ 1;
3186 aY
:= Obj
.Y
div ScaleSz
+ 1;
3188 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3189 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3190 // Ïðàâûé íèæíèé óãîë
3191 aX2
:= aX
+ aX2
- 1;
3192 aY2
:= aY
+ aY2
- 1;
3193 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3199 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3200 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3203 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3204 ScaleSz
:= 16 div Scale
;
3205 // Ðàçìåðû ìèíè-êàðòû:
3206 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3207 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3209 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3211 if gWalls
<> nil then
3214 for a
:= 0 to High(gWalls
) do
3216 if PanelType
<> 0 then
3218 // Ëåâûé âåðõíèé óãîë:
3219 aX
:= X
div ScaleSz
;
3220 aY
:= Y
div ScaleSz
;
3222 aX2
:= max(Width
div ScaleSz
, 1);
3223 aY2
:= max(Height
div ScaleSz
, 1);
3224 // Ïðàâûé íèæíèé óãîë:
3225 aX2
:= aX
+ aX2
- 1;
3226 aY2
:= aY
+ aY2
- 1;
3229 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3230 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3231 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3235 if gSteps
<> nil then
3238 for a
:= 0 to High(gSteps
) do
3240 if PanelType
<> 0 then
3242 // Ëåâûé âåðõíèé óãîë:
3243 aX
:= X
div ScaleSz
;
3244 aY
:= Y
div ScaleSz
;
3246 aX2
:= max(Width
div ScaleSz
, 1);
3247 aY2
:= max(Height
div ScaleSz
, 1);
3248 // Ïðàâûé íèæíèé óãîë:
3249 aX2
:= aX
+ aX2
- 1;
3250 aY2
:= aY
+ aY2
- 1;
3252 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3255 if gLifts
<> nil then
3258 for a
:= 0 to High(gLifts
) do
3260 if PanelType
<> 0 then
3262 // Ëåâûé âåðõíèé óãîë:
3263 aX
:= X
div ScaleSz
;
3264 aY
:= Y
div ScaleSz
;
3266 aX2
:= max(Width
div ScaleSz
, 1);
3267 aY2
:= max(Height
div ScaleSz
, 1);
3268 // Ïðàâûé íèæíèé óãîë:
3269 aX2
:= aX
+ aX2
- 1;
3270 aY2
:= aY
+ aY2
- 1;
3273 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3274 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3275 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3276 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3280 if gWater
<> nil then
3283 for a
:= 0 to High(gWater
) do
3285 if PanelType
<> 0 then
3287 // Ëåâûé âåðõíèé óãîë:
3288 aX
:= X
div ScaleSz
;
3289 aY
:= Y
div ScaleSz
;
3291 aX2
:= max(Width
div ScaleSz
, 1);
3292 aY2
:= max(Height
div ScaleSz
, 1);
3293 // Ïðàâûé íèæíèé óãîë:
3294 aX2
:= aX
+ aX2
- 1;
3295 aY2
:= aY
+ aY2
- 1;
3297 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3300 if gAcid1
<> nil then
3302 // Ðèñóåì êèñëîòó 1:
3303 for a
:= 0 to High(gAcid1
) do
3305 if PanelType
<> 0 then
3307 // Ëåâûé âåðõíèé óãîë:
3308 aX
:= X
div ScaleSz
;
3309 aY
:= Y
div ScaleSz
;
3311 aX2
:= max(Width
div ScaleSz
, 1);
3312 aY2
:= max(Height
div ScaleSz
, 1);
3313 // Ïðàâûé íèæíèé óãîë:
3314 aX2
:= aX
+ aX2
- 1;
3315 aY2
:= aY
+ aY2
- 1;
3317 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3320 if gAcid2
<> nil then
3322 // Ðèñóåì êèñëîòó 2:
3323 for a
:= 0 to High(gAcid2
) do
3325 if PanelType
<> 0 then
3327 // Ëåâûé âåðõíèé óãîë:
3328 aX
:= X
div ScaleSz
;
3329 aY
:= Y
div ScaleSz
;
3331 aX2
:= max(Width
div ScaleSz
, 1);
3332 aY2
:= max(Height
div ScaleSz
, 1);
3333 // Ïðàâûé íèæíèé óãîë:
3334 aX2
:= aX
+ aX2
- 1;
3335 aY2
:= aY
+ aY2
- 1;
3337 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3340 if gPlayers
<> nil then
3343 for a
:= 0 to High(gPlayers
) do
3344 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3346 // Ëåâûé âåðõíèé óãîë:
3347 aX
:= Obj
.X
div ScaleSz
+ 1;
3348 aY
:= Obj
.Y
div ScaleSz
+ 1;
3350 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3351 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3352 // Ïðàâûé íèæíèé óãîë:
3353 aX2
:= aX
+ aX2
- 1;
3354 aY2
:= aY
+ aY2
- 1;
3356 if gPlayers
[a
] = p
then
3357 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3360 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3361 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3362 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3367 g_Mons_ForEach(monDraw
);
3372 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3374 if not hasAmbient
then exit
;
3375 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3379 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3380 //FIXME: broken for splitscreen mode
3381 procedure renderDynLightsInternal ();
3383 //hasAmbient: Boolean;
3384 //ambColor: TDFColor;
3386 lx
, ly
, lrad
: Integer;
3387 scxywh
: array[0..3] of GLint
;
3390 if e_NoGraphics
then exit
;
3392 //TODO: lights should be in separate grid, i think
3393 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3394 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3397 //ambColor := gCurrentMap['light_ambient'].rgba;
3398 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3400 { // this will multiply incoming color to alpha from framebuffer
3402 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3406 * light rendering: (INVALID!)
3407 * glStencilFunc(GL_EQUAL, 0, $ff);
3409 * glClear(GL_STENCIL_BUFFER_BIT);
3410 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3411 * draw shadow volume into stencil buffer
3412 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3413 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3415 * draw color-less quad with light alpha (WARNING! don't touch color!)
3416 * glEnable(GL_BLEND);
3417 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3418 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3420 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3421 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3423 // setup OpenGL parameters
3424 glStencilMask($FFFFFFFF);
3425 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3426 glEnable(GL_STENCIL_TEST
);
3427 glEnable(GL_SCISSOR_TEST
);
3428 glClear(GL_STENCIL_BUFFER_BIT
);
3429 glStencilFunc(GL_EQUAL
, 0, $ff);
3431 for lln
:= 0 to g_dynLightCount
-1 do
3433 lx
:= g_dynLights
[lln
].x
;
3434 ly
:= g_dynLights
[lln
].y
;
3435 lrad
:= g_dynLights
[lln
].radius
;
3436 if (lrad
< 3) then continue
;
3438 if (lx
-sX
+lrad
< 0) then continue
;
3439 if (ly
-sY
+lrad
< 0) then continue
;
3440 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3441 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3443 // set scissor to optimize drawing
3444 if (g_dbg_scale
= 1.0) then
3446 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3450 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3452 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3453 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3454 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3455 // draw extruded panels
3456 glDisable(GL_TEXTURE_2D
);
3457 glDisable(GL_BLEND
);
3458 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3459 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3460 // render light texture
3461 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3462 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3465 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3466 glEnable(GL_TEXTURE_2D
);
3467 // color and opacity
3468 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3469 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3471 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3472 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3473 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3474 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3479 glDisable(GL_STENCIL_TEST
);
3480 glDisable(GL_BLEND
);
3481 glDisable(GL_SCISSOR_TEST
);
3482 //glScissor(0, 0, sWidth, sHeight);
3484 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3485 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3489 function fixViewportForScale (): Boolean;
3491 nx0
, ny0
, nw
, nh
: Integer;
3494 if (g_dbg_scale
<> 1.0) then
3497 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3498 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3499 nw
:= round(sWidth
/g_dbg_scale
);
3500 nh
:= round(sHeight
/g_dbg_scale
);
3509 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3510 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3511 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3513 TDrawCB
= procedure ();
3516 hasAmbient
: Boolean;
3518 doAmbient
: Boolean = false;
3520 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3525 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3526 if gdbg_map_use_accel_render
then
3528 tagmask
:= panelTypeToTag(panType
);
3529 while (gDrawPanelList
.count
> 0) do
3531 pan
:= TPanel(gDrawPanelList
.front());
3532 if ((pan
.tag
and tagmask
) = 0) then break
;
3533 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3534 gDrawPanelList
.popFront();
3539 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3541 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3544 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3546 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3547 if assigned(cb
) then cb();
3548 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3552 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3554 // our accelerated renderer will collect all panels to gDrawPanelList
3555 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3556 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3557 if gdbg_map_use_accel_render
then
3559 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3561 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3563 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3564 g_Map_DrawBack(backXOfs
, backYOfs
);
3565 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3567 if setTransMatrix
then
3569 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3570 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3571 glTranslatef(-sX
, -sY
, 0);
3575 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3576 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3581 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3582 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3583 glClear(GL_COLOR_BUFFER_BIT);
3586 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3589 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3590 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3591 drawOther('items', @g_Items_Draw
);
3592 drawOther('weapons', @g_Weapon_Draw
);
3593 drawOther('shells', @g_Player_DrawShells
);
3594 drawOther('drawall', @g_Player_DrawAll
);
3595 drawOther('corpses', @g_Player_DrawCorpses
);
3596 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3597 drawOther('monsters', @g_Monsters_Draw
);
3598 drawOther('itemdrop', @g_Items_DrawDrop
);
3599 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3600 drawOther('gfx', @g_GFX_Draw
);
3601 drawOther('flags', @g_Map_DrawFlags
);
3602 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3603 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3604 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3605 drawOther('dynlights', @renderDynLightsInternal
);
3607 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3609 renderAmbientQuad(hasAmbient
, ambColor
);
3613 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3616 if g_debug_HealthBar
then
3618 g_Monsters_DrawHealth();
3619 g_Player_DrawHealth();
3622 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3626 procedure DrawMapView(x
, y
, w
, h
: Integer);
3633 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3634 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3641 fixViewportForScale();
3642 renderMapInternal(-bx
, -by
, true);
3648 procedure DrawPlayer(p
: TPlayer
);
3650 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3654 if (p
= nil) or (p
.FDummy
) then
3657 g_Map_DrawBack(0, 0);
3662 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3663 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3669 camObj
:= p
.getCameraObj();
3670 camObj
.lerp(gLerpFactor
, fX
, fY
);
3671 px
:= fX
+ PLAYER_RECT_CX
;
3672 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3674 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3676 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3677 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3679 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3680 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3682 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3683 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3686 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3689 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3690 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3693 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3698 // scaled, ignore level bounds
3699 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3700 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3705 sWidth
:= gPlayerScreenSize
.X
;
3706 sHeight
:= gPlayerScreenSize
.Y
;
3707 fixViewportForScale();
3709 i
:= py
- (sY
+ sHeight
div 2);
3710 if (p
.IncCam
> 0) then
3712 // clamp to level bounds
3713 if (sY
- p
.IncCam
< 0) then
3714 p
.IncCam
:= nclamp(sY
, 0, 120);
3715 // clamp around player position
3717 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3719 else if (p
.IncCam
< 0) then
3721 // clamp to level bounds
3722 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3723 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3724 // clamp around player position
3726 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3729 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3731 if (not g_dbg_ignore_bounds
) then
3733 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3734 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3735 if (sX
< 0) then sX
:= 0;
3736 if (sY
< 0) then sY
:= 0;
3739 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3740 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3742 //r_smallmap_h: 0: left; 1: center; 2: right
3743 //r_smallmap_v: 0: top; 1: center; 2: bottom
3745 if (gMapInfo
.Width
= sWidth
) then
3749 else if (gMapInfo
.Width
< sWidth
) then
3751 case r_smallmap_h
of
3752 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3753 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3754 else sX
:= 0; // left
3758 if (gMapInfo
.Height
= sHeight
) then
3762 else if (gMapInfo
.Height
< sHeight
) then
3764 case r_smallmap_v
of
3765 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3766 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3767 else sY
:= 0; // top
3773 p
.viewPortW
:= sWidth
;
3774 p
.viewPortH
:= sHeight
;
3776 {$IFDEF ENABLE_HOLMES}
3777 if (p
= gPlayer1
) then
3779 g_Holmes_plrViewPos(sX
, sY
);
3780 g_Holmes_plrViewSize(sWidth
, sHeight
);
3784 renderMapInternal(-c
, -d
, true);
3786 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3787 case gPlayerIndicator
of
3789 p
.DrawIndicator(_RGB(255, 255, 255));
3792 for i
:= 0 to High(gPlayers
) do
3793 if gPlayers
[i
] <> nil then
3794 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3795 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3796 if gPlayerIndicatorStyle
= 1 then
3797 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3798 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3802 for a := 0 to High(gCollideMap) do
3803 for b := 0 to High(gCollideMap[a]) do
3806 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3808 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3812 1: e_DrawPoint(1, b, a, 200, 200, 200);
3813 2: e_DrawPoint(1, b, a, 64, 64, 255);
3814 3: e_DrawPoint(1, b, a, 255, 0, 255);
3824 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3825 if g_Debug_Player
then
3826 g_Player_DrawDebug(p
);
3830 procedure drawProfilers ();
3835 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3836 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3837 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3840 procedure g_Game_Draw();
3847 plView1
, plView2
: TPlayer
;
3850 if gExit
= EXIT_QUIT
then Exit
;
3852 Time
:= sys_GetTicks() {div 1000};
3853 FPSCounter
:= FPSCounter
+1;
3854 if Time
- FPSTime
>= 1000 then
3861 e_SetRendertarget(True);
3862 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3864 if gGameOn
or (gState
= STATE_FOLD
) then
3866 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3868 gSpectMode
:= SPECT_NONE
;
3869 if not gRevertPlayers
then
3871 plView1
:= gPlayer1
;
3872 plView2
:= gPlayer2
;
3876 plView1
:= gPlayer2
;
3877 plView2
:= gPlayer1
;
3881 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3883 gSpectMode
:= SPECT_NONE
;
3884 if gPlayer2
= nil then
3887 plView1
:= gPlayer2
;
3896 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3897 gSpectMode
:= SPECT_STATS
;
3899 if gSpectMode
= SPECT_PLAYERS
then
3900 if gPlayers
<> nil then
3902 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3903 if plView1
= nil then
3905 gSpectPID1
:= GetActivePlayerID_Next();
3906 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3908 if gSpectViewTwo
then
3910 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3911 if plView2
= nil then
3913 gSpectPID2
:= GetActivePlayerID_Next();
3914 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3919 if gSpectMode
= SPECT_MAPVIEW
then
3921 // Ðåæèì ïðîñìîòðà êàðòû
3923 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3924 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3925 gHearPoint1
.Active
:= True;
3926 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3927 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3928 gHearPoint2
.Active
:= False;
3932 Split
:= (plView1
<> nil) and (plView2
<> nil);
3934 // Òî÷êè ñëóõà èãðîêîâ
3935 if plView1
<> nil then
3937 gHearPoint1
.Active
:= True;
3938 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3939 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3941 gHearPoint1
.Active
:= False;
3942 if plView2
<> nil then
3944 gHearPoint2
.Active
:= True;
3945 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3946 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3948 gHearPoint2
.Active
:= False;
3950 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3951 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3954 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3955 if gScreenHeight
mod 2 = 0 then
3956 Dec(gPlayerScreenSize
.Y
);
3959 gPlayerScreenSize
.Y
:= gScreenHeight
;
3962 if gScreenHeight
mod 2 = 0 then
3963 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3965 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3967 DrawPlayer(plView1
);
3968 gPlayer1ScreenCoord
.X
:= sX
;
3969 gPlayer1ScreenCoord
.Y
:= sY
;
3973 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3975 DrawPlayer(plView2
);
3976 gPlayer2ScreenCoord
.X
:= sX
;
3977 gPlayer2ScreenCoord
.Y
:= sY
;
3980 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3983 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3986 {$IFDEF ENABLE_HOLMES}
3988 if (g_holmes_enabled
) then g_Holmes_Draw();
3991 if MessageText
<> '' then
3995 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3997 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3998 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4000 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4001 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4004 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4007 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4009 // Draw spectator GUI
4012 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4015 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4017 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4019 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4022 if gSpectMode
= SPECT_STATS
then
4024 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4025 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4027 if gSpectMode
= SPECT_MAPVIEW
then
4029 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4030 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4031 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4032 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4033 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4035 if gSpectMode
= SPECT_PLAYERS
then
4037 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4038 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4039 if gSpectViewTwo
then
4041 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4042 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4043 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4044 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4048 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4049 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4055 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4057 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4058 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4060 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4061 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4062 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4067 if (gState
= STATE_MENU
) then
4069 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4070 // F3 at menu will show game loading dialog
4071 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4072 if (g_ActiveWindow
<> nil) then
4074 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4075 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4079 // F3 at titlepic will show game loading dialog
4080 if e_KeyPressed(IK_F3
) then
4082 g_Menu_Show_LoadMenu(true);
4083 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4088 if gState
= STATE_FOLD
then
4090 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4093 if gState
= STATE_INTERCUSTOM
then
4095 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4097 back
:= 'TEXTURE_endpic';
4098 if not g_Texture_Get(back
, ID
) then
4099 back
:= _lc
[I_TEXTURE_ENDPIC
];
4104 DrawMenuBackground(back
);
4108 if g_ActiveWindow
<> nil then
4110 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4111 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4115 if gState
= STATE_INTERSINGLE
then
4117 if EndingGameCounter
> 0 then
4119 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4125 DrawMenuBackground(back
);
4129 if g_ActiveWindow
<> nil then
4131 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4132 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4137 if gState
= STATE_ENDPIC
then
4140 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4141 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4143 if g_ActiveWindow
<> nil then
4145 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4146 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4150 if gState
= STATE_SLIST
then
4152 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4154 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4155 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4157 DrawMenuBackground('MENU_BACKGROUND');
4158 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4159 g_Serverlist_Draw(slCurrent
, slTable
);
4163 if g_ActiveWindow
<> nil then
4167 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4168 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4170 g_ActiveWindow
.Draw();
4177 if g_debug_Sounds
and gGameOn
then
4179 for w
:= 0 to High(e_SoundsArray
) do
4180 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4181 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4186 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4187 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4190 if gGameOn
and gShowTime
then
4191 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4193 if gGameOn
then drawProfilers();
4195 // TODO: draw this after the FBO and remap mouse click coordinates
4197 {$IFDEF ENABLE_HOLMES}
4201 // blit framebuffer to screen
4203 e_SetRendertarget(False);
4204 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4205 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4207 // draw the overlay stuff on top of it
4212 procedure g_Game_Quit();
4214 g_Game_StopAllSounds(True);
4217 g_PlayerModel_FreeData();
4218 g_Texture_DeleteAll();
4219 g_Frames_DeleteAll();
4221 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4224 if NetInitDone
then g_Net_Free
;
4226 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4227 if gMapToDelete
<> '' then
4228 g_Game_DeleteTestMap();
4234 procedure g_FatalError(Text: String);
4236 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4237 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4239 gExit
:= EXIT_SIMPLE
;
4240 if gGameOn
then EndGame
;
4243 procedure g_SimpleError(Text: String);
4245 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4246 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4249 procedure g_Game_SetupScreenSize();
4251 RES_FACTOR
= 4.0 / 3.0;
4257 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4258 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4259 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4260 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4262 gPlayerScreenSize
.Y
:= gScreenHeight
;
4264 // Ðàçìåð çàäíåãî ïëàíà:
4265 if BackID
<> DWORD(-1) then
4268 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4269 (gScreenHeight
*s
> gMapInfo
.Height
) then
4271 gBackSize
.X
:= gScreenWidth
;
4272 gBackSize
.Y
:= gScreenHeight
;
4276 e_GetTextureSize(BackID
, @bw
, @bh
);
4277 rf
:= Single(bw
) / Single(bh
);
4278 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4279 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4280 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4281 if (s
< 1.0) then s
:= 1.0;
4282 gBackSize
.X
:= Round(bw
*s
);
4283 gBackSize
.Y
:= Round(bh
*s
);
4288 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4290 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4293 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4295 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4296 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4299 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4302 if gPlayer1
= nil then
4304 if g_Game_IsClient
then
4306 if NetPlrUID1
> -1 then
4307 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4311 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4312 Team
:= gPlayer1Settings
.Team
;
4314 // Ñîçäàíèå ïåðâîãî èãðîêà:
4315 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4316 gPlayer1Settings
.Color
,
4318 if gPlayer1
= nil then
4319 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4322 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4323 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4324 if g_Game_IsServer
and g_Game_IsNet
then
4325 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4326 gPlayer1
.Respawn(False, True);
4327 g_Net_Slist_ServerPlayerComes();
4332 if gPlayer2
= nil then
4334 if g_Game_IsClient
then
4336 if NetPlrUID2
> -1 then
4337 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4341 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4342 Team
:= gPlayer2Settings
.Team
;
4344 // Ñîçäàíèå âòîðîãî èãðîêà:
4345 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4346 gPlayer2Settings
.Color
,
4348 if gPlayer2
= nil then
4349 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4352 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4353 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4354 if g_Game_IsServer
and g_Game_IsNet
then
4355 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4356 gPlayer2
.Respawn(False, True);
4357 g_Net_Slist_ServerPlayerComes();
4364 procedure g_Game_RemovePlayer();
4368 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4369 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4374 if g_Game_IsServer
then
4377 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4378 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4379 g_Player_Remove(Pl
.UID
);
4380 g_Net_Slist_ServerPlayerLeaves();
4384 gSpectLatchPID2
:= Pl
.UID
;
4392 if g_Game_IsServer
then
4395 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4396 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4397 g_Player_Remove(Pl
.UID
);
4398 g_Net_Slist_ServerPlayerLeaves();
4401 gSpectLatchPID1
:= Pl
.UID
;
4403 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4407 g_Net_Slist_ServerPlayerLeaves();
4410 procedure g_Game_Spectate();
4412 g_Game_RemovePlayer();
4413 if gPlayer1
<> nil then
4414 g_Game_RemovePlayer();
4417 procedure g_Game_SpectateCenterView();
4419 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4420 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4423 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4430 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4432 g_Game_ClearLoading();
4435 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4438 gGameSettings
.GameType
:= GT_SINGLE
;
4439 gGameSettings
.MaxLives
:= 0;
4440 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4441 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4442 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4443 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4444 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4445 gSwitchGameMode
:= GM_SINGLE
;
4447 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4448 gLMSRespawnTime
:= 0;
4449 gSpectLatchPID1
:= 0;
4450 gSpectLatchPID2
:= 0;
4452 g_Game_ExecuteEvent('ongamestart');
4454 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4455 g_Game_SetupScreenSize();
4457 // Ñîçäàíèå ïåðâîãî èãðîêà:
4458 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4459 gPlayer1Settings
.Color
,
4460 gPlayer1Settings
.Team
, False));
4461 if gPlayer1
= nil then
4463 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4467 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4470 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4473 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4474 gPlayer2Settings
.Color
,
4475 gPlayer2Settings
.Team
, False));
4476 if gPlayer2
= nil then
4478 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4482 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4486 // Çàãðóçêà è çàïóñê êàðòû:
4487 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4489 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4490 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4494 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4498 for i
:= nPl
+1 to nPlayers
do
4499 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4502 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4503 TimeLimit
, GoalLimit
: Word;
4505 Options
: LongWord; nPlayers
: Byte);
4511 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4513 g_Game_ClearLoading();
4516 gGameSettings
.GameType
:= GT_CUSTOM
;
4517 gGameSettings
.GameMode
:= GameMode
;
4518 gSwitchGameMode
:= GameMode
;
4519 gGameSettings
.TimeLimit
:= TimeLimit
;
4520 gGameSettings
.GoalLimit
:= GoalLimit
;
4521 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4522 gGameSettings
.Options
:= Options
;
4524 gCoopTotalMonstersKilled
:= 0;
4525 gCoopTotalSecretsFound
:= 0;
4526 gCoopTotalMonsters
:= 0;
4527 gCoopTotalSecrets
:= 0;
4531 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4532 gLMSRespawnTime
:= 0;
4533 gSpectLatchPID1
:= 0;
4534 gSpectLatchPID2
:= 0;
4536 g_Game_ExecuteEvent('ongamestart');
4538 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4539 g_Game_SetupScreenSize();
4541 // Ðåæèì íàáëþäàòåëÿ:
4542 if nPlayers
= 0 then
4549 if nPlayers
>= 1 then
4551 // Ñîçäàíèå ïåðâîãî èãðîêà:
4552 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4553 gPlayer1Settings
.Color
,
4554 gPlayer1Settings
.Team
, False));
4555 if gPlayer1
= nil then
4557 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4561 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4565 if nPlayers
>= 2 then
4567 // Ñîçäàíèå âòîðîãî èãðîêà:
4568 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4569 gPlayer2Settings
.Color
,
4570 gPlayer2Settings
.Team
, False));
4571 if gPlayer2
= nil then
4573 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4577 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4581 // Çàãðóçêà è çàïóñê êàðòû:
4582 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4584 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4588 // Íåò òî÷åê ïîÿâëåíèÿ:
4589 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4590 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4591 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4592 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4593 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4595 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4599 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4603 for i
:= nPl
+1 to nPlayers
do
4604 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4607 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4608 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4609 Options
: LongWord; nPlayers
: Byte;
4610 IPAddr
: LongWord; Port
: Word);
4613 g_Net_Slist_ServerClosed();
4615 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4617 g_Game_ClearLoading();
4620 gGameSettings
.GameType
:= GT_SERVER
;
4621 gGameSettings
.GameMode
:= GameMode
;
4622 gSwitchGameMode
:= GameMode
;
4623 gGameSettings
.TimeLimit
:= TimeLimit
;
4624 gGameSettings
.GoalLimit
:= GoalLimit
;
4625 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4626 gGameSettings
.Options
:= Options
;
4628 gCoopTotalMonstersKilled
:= 0;
4629 gCoopTotalSecretsFound
:= 0;
4630 gCoopTotalMonsters
:= 0;
4631 gCoopTotalSecrets
:= 0;
4635 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4636 gLMSRespawnTime
:= 0;
4637 gSpectLatchPID1
:= 0;
4638 gSpectLatchPID2
:= 0;
4640 g_Game_ExecuteEvent('ongamestart');
4642 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4643 g_Game_SetupScreenSize();
4645 // Ðåæèì íàáëþäàòåëÿ:
4646 if nPlayers
= 0 then
4652 if nPlayers
>= 1 then
4654 // Ñîçäàíèå ïåðâîãî èãðîêà:
4655 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4656 gPlayer1Settings
.Color
,
4657 gPlayer1Settings
.Team
, False));
4658 if gPlayer1
= nil then
4660 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4664 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4667 if nPlayers
>= 2 then
4669 // Ñîçäàíèå âòîðîãî èãðîêà:
4670 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4671 gPlayer2Settings
.Color
,
4672 gPlayer2Settings
.Team
, False));
4673 if gPlayer2
= nil then
4675 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4679 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4682 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4683 if NetForwardPorts
then
4684 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4687 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4689 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4693 g_Net_Slist_Set(NetMasterList
);
4695 g_Net_Slist_ServerStarted();
4697 // Çàãðóçêà è çàïóñê êàðòû:
4698 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4700 g_Net_Slist_ServerClosed();
4701 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4705 // Íåò òî÷åê ïîÿâëåíèÿ:
4706 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4707 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4708 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4709 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4710 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4712 g_Net_Slist_ServerClosed();
4713 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4717 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4720 g_Net_Slist_ServerMapStarted();
4721 NetState
:= NET_STATE_GAME
;
4724 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4739 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4740 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4742 g_Game_ClearLoading();
4745 gGameSettings
.GameType
:= GT_CLIENT
;
4747 gCoopTotalMonstersKilled
:= 0;
4748 gCoopTotalSecretsFound
:= 0;
4749 gCoopTotalMonsters
:= 0;
4750 gCoopTotalSecrets
:= 0;
4754 g_Game_ExecuteEvent('ongamestart');
4756 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4757 g_Game_SetupScreenSize();
4759 NetState
:= NET_STATE_AUTH
;
4761 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4763 // create (or update) map/resource databases
4764 g_Res_CreateDatabases(true);
4766 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4767 gLMSRespawnTime
:= 0;
4768 gSpectLatchPID1
:= 0;
4769 gSpectLatchPID2
:= 0;
4772 if not g_Net_Connect(Addr
, Port
) then
4774 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4775 NetState
:= NET_STATE_NONE
;
4779 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4781 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4786 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4787 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4788 // thank you, enet. let's ignore failures altogether then.
4789 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4791 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4793 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4795 // ignore all download packets, they're processed by separate code
4796 enet_packet_destroy(NetEvent
.packet
);
4799 Ptr
:= NetEvent
.packet
^.data
;
4800 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4802 enet_packet_destroy(NetEvent
.packet
);
4806 InMsg
.ReadLongWord(); // skip size
4807 MID
:= InMsg
.ReadByte();
4809 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4811 NetMyID
:= InMsg
.ReadByte();
4812 NetPlrUID1
:= InMsg
.ReadWord();
4814 WadName
:= InMsg
.ReadString();
4815 Map
:= InMsg
.ReadString();
4817 gWADHash
:= InMsg
.ReadMD5();
4819 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4820 gSwitchGameMode
:= gGameSettings
.GameMode
;
4821 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4822 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4823 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4824 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4825 T
:= InMsg
.ReadLongWord();
4827 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4828 //if newResPath = '' then
4830 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4831 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4832 if newResPath
= '' then
4834 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4835 enet_packet_destroy(NetEvent
.packet
);
4836 NetState
:= NET_STATE_NONE
;
4839 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4841 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4844 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4845 gPlayer1Settings
.Color
,
4846 gPlayer1Settings
.Team
, False));
4848 if gPlayer1
= nil then
4850 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4852 enet_packet_destroy(NetEvent
.packet
);
4853 NetState
:= NET_STATE_NONE
;
4857 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4858 gPlayer1
.UID
:= NetPlrUID1
;
4859 gPlayer1
.Reset(True);
4861 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4863 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4865 enet_packet_destroy(NetEvent
.packet
);
4866 NetState
:= NET_STATE_NONE
;
4874 enet_packet_destroy(NetEvent
.packet
);
4878 enet_packet_destroy(NetEvent
.packet
);
4882 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4885 if (NetEvent
.data
<= NET_DISC_MAX
) then
4886 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4887 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4894 ProcessLoading(true);
4896 if g_Net_UserRequestExit() then
4905 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4906 NetState
:= NET_STATE_NONE
;
4911 NetState
:= NET_STATE_GAME
;
4912 MC_SEND_FullStateRequest
;
4913 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4917 lastAsMegaWad
: Boolean = false;
4919 procedure g_Game_ChangeMap(const MapPath
: String);
4923 g_Game_ClearLoading();
4925 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4926 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4927 if gExitByTrigger
then
4930 gExitByTrigger
:= False;
4932 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4933 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4936 procedure g_Game_Restart();
4940 if g_Game_IsClient
then
4942 map
:= g_ExtractFileName(gMapInfo
.Map
);
4943 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4947 g_Game_ClearLoading();
4948 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4951 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4953 NewWAD
, ResName
: String;
4957 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4958 g_Player_RemoveAllCorpses();
4960 if (not g_Game_IsClient
) and
4961 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4962 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4964 if gSwitchGameMode
= GM_CTF
then
4965 gGameSettings
.MaxLives
:= 0;
4966 gGameSettings
.GameMode
:= gSwitchGameMode
;
4969 gSwitchGameMode
:= gGameSettings
.GameMode
;
4971 g_Player_ResetTeams();
4973 lastAsMegaWad
:= asMegawad
;
4974 if isWadPath(Map
) then
4976 NewWAD
:= g_ExtractWadName(Map
);
4977 ResName
:= g_ExtractFileName(Map
);
4978 if g_Game_IsServer
then
4980 nws
:= findDiskWad(NewWAD
);
4981 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4984 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4985 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4989 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4990 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4992 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4993 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4995 if (length(nws
) = 0) then
4997 ResName
:= ''; // failed
5002 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5003 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5004 g_Game_LoadWAD(NewWAD
);
5009 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5010 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5015 NewWAD
:= gGameSettings
.WAD
;
5021 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5023 if (ResName
<> '') and (NewWAD
<> '') then
5025 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5026 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5030 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5032 gState
:= STATE_NONE
;
5033 g_ActiveWindow
:= nil;
5039 if gGameSettings
.GameMode
= GM_CTF
then
5041 g_Map_ResetFlag(FLAG_RED
);
5042 g_Map_ResetFlag(FLAG_BLUE
);
5043 // CTF, à ôëàãîâ íåò:
5044 if not g_Map_HaveFlagPoints() then
5045 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5050 gState
:= STATE_MENU
;
5055 gPauseMain
:= false;
5056 gPauseHolmes
:= false;
5057 NetTimeToUpdate
:= 1;
5058 NetTimeToReliable
:= 0;
5059 NetTimeToMaster
:= NetMasterRate
;
5060 gSpectLatchPID1
:= 0;
5061 gSpectLatchPID2
:= 0;
5062 gMissionFailed
:= False;
5065 gCoopMonstersKilled
:= 0;
5066 gCoopSecretsFound
:= 0;
5068 gVoteInProgress
:= False;
5069 gVotePassed
:= False;
5075 if not gGameOn
then Exit
;
5077 g_Game_SpectateCenterView();
5079 if g_Game_IsServer
then
5081 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5083 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5084 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5085 gLMSSoftSpawn
:= True;
5086 if g_Game_IsNet
then
5087 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5091 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5092 gLMSRespawnTime
:= 0;
5096 if NetMode
= NET_SERVER
then
5098 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5101 g_Net_Slist_ServerMapStarted();
5103 if NetClients
<> nil then
5104 for I
:= 0 to High(NetClients
) do
5105 if NetClients
[I
].Used
then
5107 NetClients
[I
].Voted
:= False;
5108 if NetClients
[I
].RequestedFullUpdate
then
5110 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5111 NetClients
[I
].RequestedFullUpdate
:= False;
5115 g_Net_UnbanNonPermHosts();
5120 gCoopTotalMonstersKilled
:= 0;
5121 gCoopTotalSecretsFound
:= 0;
5122 gCoopTotalMonsters
:= 0;
5123 gCoopTotalSecrets
:= 0;
5127 g_Game_ExecuteEvent('onmapstart');
5130 procedure SetFirstLevel
;
5134 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5135 if MapList
= nil then
5138 SortSArray(MapList
);
5139 gNextMap
:= MapList
[Low(MapList
)];
5144 procedure g_Game_ExitLevel(const Map
: AnsiString);
5148 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5149 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5150 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5151 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5153 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5154 if gGameSettings
.GameType
= GT_SINGLE
then
5155 gExit
:= EXIT_ENDLEVELSINGLE
5156 else // Âûøëè â âûõîä â Ñâîåé èãðå
5158 gExit
:= EXIT_ENDLEVELCUSTOM
;
5159 if gGameSettings
.GameMode
= GM_COOP
then
5160 g_Player_RememberAll
;
5162 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5165 if gGameSettings
.GameMode
= GM_COOP
then
5168 gStatsPressed
:= True;
5169 gNextMap
:= 'MAP01';
5171 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5174 if g_Game_IsNet
then
5176 MH_SEND_GameStats();
5177 MH_SEND_CoopStats();
5183 procedure g_Game_RestartLevel();
5187 if gGameSettings
.GameMode
= GM_SINGLE
then
5192 gExit
:= EXIT_ENDLEVELCUSTOM
;
5193 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5197 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5199 gWAD
{, xwad}: String;
5202 if not g_Game_IsClient
then Exit
;
5203 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5205 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5210 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5214 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5217 g_Game_LoadWAD(NewWAD
);
5221 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5222 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5225 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5226 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5230 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5234 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5235 g_Game_LoadWAD(NewWAD);
5239 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5241 i
, n
, nb
, nr
: Integer;
5243 if not g_Game_IsServer
then Exit
;
5244 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5245 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5246 gLMSRespawnTime
:= 0;
5249 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5251 gMissionFailed
:= True;
5252 g_Game_RestartLevel
;
5256 n
:= 0; nb
:= 0; nr
:= 0;
5257 for i
:= Low(gPlayers
) to High(gPlayers
) do
5258 if (gPlayers
[i
] <> nil) and
5259 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5260 (gPlayers
[i
] is TBot
)) then
5263 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5264 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5267 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5269 // wait a second until the fuckers finally decide to join
5270 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5271 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5272 gLMSSoftSpawn
:= NoMapRestart
;
5273 if g_Game_IsNet
then
5274 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5278 g_Player_RemoveAllCorpses
;
5279 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5280 if g_Game_IsNet
then
5281 MH_SEND_GameEvent(NET_EV_LMS_START
);
5283 for i
:= Low(gPlayers
) to High(gPlayers
) do
5285 if gPlayers
[i
] = nil then continue
;
5286 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5287 // don't touch normal spectators
5288 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5290 gPlayers
[i
].FNoRespawn
:= True;
5291 gPlayers
[i
].Lives
:= 0;
5292 if g_Game_IsNet
then
5293 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5296 gPlayers
[i
].FNoRespawn
:= False;
5297 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5298 gPlayers
[i
].Respawn(False, True);
5299 if gGameSettings
.GameMode
= GM_COOP
then
5301 gPlayers
[i
].Frags
:= 0;
5302 gPlayers
[i
].RecallState
;
5304 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5305 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5306 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5307 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5310 g_Items_RestartRound();
5312 gLMSSoftSpawn
:= False;
5315 function g_Game_GetFirstMap(WAD
: String): String;
5319 MapList
:= g_Map_GetMapsList(WAD
);
5320 if MapList
= nil then
5323 SortSArray(MapList
);
5324 Result
:= MapList
[Low(MapList
)];
5326 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5332 function g_Game_GetNextMap(): String;
5339 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5340 if MapList
= nil then
5343 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5345 SortSArray(MapList
);
5347 for I
:= Low(MapList
) to High(MapList
) do
5348 if Map
= MapList
[I
] then
5354 if MapIndex
<> -255 then
5356 if MapIndex
= High(MapList
) then
5357 Result
:= MapList
[Low(MapList
)]
5359 Result
:= MapList
[MapIndex
+ 1];
5361 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5367 procedure g_Game_NextLevel();
5369 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5370 gExit
:= EXIT_ENDLEVELCUSTOM
5373 gExit
:= EXIT_ENDLEVELSINGLE
;
5377 if gNextMap
<> '' then Exit
;
5378 gNextMap
:= g_Game_GetNextMap();
5381 function g_Game_IsTestMap(): Boolean;
5383 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5386 procedure g_Game_DeleteTestMap();
5389 //MapName: AnsiString;
5397 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5398 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5399 if (a
= 0) then exit
;
5401 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5402 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5403 Delete(gMapToDelete
, 1, a
+5);
5404 gMapToDelete
:= UpperCase(gMapToDelete
);
5406 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5409 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5410 if MapName <> TEST_MAP_NAME then
5413 if not gTempDelete then
5415 time := g_GetFileTime(WadName);
5416 WAD := TWADFile.Create();
5419 if not WAD.ReadFile(WadName) then
5420 begin // Íåò òàêîãî WAD-ôàéëà
5425 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5427 MapList := WAD.GetResourcesList('');
5429 if MapList <> nil then
5430 for a := 0 to High(MapList) do
5431 if MapList[a] = MapName then
5433 // Óäàëÿåì è ñîõðàíÿåì:
5434 WAD.RemoveResource('', MapName);
5435 WAD.SaveTo(WadName);
5440 g_SetFileTime(WadName, time);
5443 if gTempDelete
then DeleteFile(WadName
);
5446 procedure GameCVars(P
: SSArray
);
5449 stat
: TPlayerStatArray
;
5452 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5456 if Length(P
) > 1 then
5461 gsGameFlags
:= gsGameFlags
or Flag
5463 gsGameFlags
:= gsGameFlags
and (not Flag
);
5465 if g_Game_IsServer
then
5468 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5470 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5471 if g_Game_IsNet
then MH_SEND_GameSettings
;
5475 if LongBool(gsGameFlags
and Flag
) then
5476 g_Console_Add(_lc
[OnMsg
])
5478 g_Console_Add(_lc
[OffMsg
]);
5480 if OnMapChange
and g_Game_IsServer
then
5481 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5486 cmd
:= LowerCase(P
[0]);
5488 if cmd
= 'g_gamemode' then
5490 if (Length(P
) > 1) then
5492 a
:= g_Game_TextToMode(P
[1]);
5493 if a
= GM_SINGLE
then a
:= GM_COOP
;
5494 gsGameMode
:= g_Game_ModeToText(a
);
5495 if g_Game_IsServer
then
5497 gSwitchGameMode
:= a
;
5498 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5499 (gState
= STATE_INTERSINGLE
) then
5500 gSwitchGameMode
:= GM_SINGLE
;
5502 gGameSettings
.GameMode
:= gSwitchGameMode
;
5506 if gSwitchGameMode
= gGameSettings
.GameMode
then
5507 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5508 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5510 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5511 [g_Game_ModeToText(gGameSettings
.GameMode
),
5512 g_Game_ModeToText(gSwitchGameMode
)]));
5514 else if cmd
= 'g_friendlyfire' then
5516 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5518 else if cmd
= 'g_friendly_absorb_damage' then
5520 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5522 else if cmd
= 'g_friendly_hit_trace' then
5524 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5526 else if cmd
= 'g_friendly_hit_projectile' then
5528 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5530 else if cmd
= 'g_weaponstay' then
5532 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5534 else if cmd
= 'g_allow_exit' then
5536 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5538 else if cmd
= 'g_allow_monsters' then
5540 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5542 else if cmd
= 'g_bot_vsplayers' then
5544 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5546 else if cmd
= 'g_bot_vsmonsters' then
5548 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5550 else if cmd
= 'g_dm_keys' then
5552 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5554 else if cmd
= 'g_gameflags' then
5556 if Length(P
) > 1 then
5558 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5559 if g_Game_IsServer
then
5561 gGameSettings
.Options
:= gsGameFlags
;
5562 if g_Game_IsNet
then MH_SEND_GameSettings
;
5566 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5568 else if cmd
= 'g_warmup_time' then
5570 if Length(P
) > 1 then
5572 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5573 if g_Game_IsServer
then
5575 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5576 // extend warmup if it's already going
5577 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5579 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5580 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5582 if g_Game_IsNet
then MH_SEND_GameSettings
;
5586 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5587 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5589 else if cmd
= 'g_spawn_invul' then
5591 if Length(P
) > 1 then
5593 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5594 if g_Game_IsServer
then
5596 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5597 if g_Game_IsNet
then MH_SEND_GameSettings
;
5601 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5603 else if cmd
= 'g_item_respawn_time' then
5605 if Length(P
) > 1 then
5607 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5608 if g_Game_IsServer
then
5610 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5611 if g_Game_IsNet
then MH_SEND_GameSettings
;
5615 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5616 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5618 else if cmd
= 'sv_intertime' then
5620 if (Length(P
) > 1) then
5621 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5623 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5625 else if cmd
= 'g_max_particles' then
5627 if Length(p
) = 2 then
5629 a
:= Max(0, StrToInt(p
[1]));
5632 else if Length(p
) = 1 then
5634 e_LogWritefln('%s', [g_GFX_GetMax()])
5638 e_LogWritefln('usage: %s <n>', [cmd
])
5641 else if cmd
= 'g_max_shells' then
5643 if Length(p
) = 2 then
5645 a
:= Max(0, StrToInt(p
[1]));
5648 else if Length(p
) = 1 then
5650 e_LogWritefln('%s', [g_Shells_GetMax()])
5654 e_LogWritefln('usage: %s <n>', [cmd
])
5657 else if cmd
= 'g_max_gibs' then
5659 if Length(p
) = 2 then
5661 a
:= Max(0, StrToInt(p
[1]));
5664 else if Length(p
) = 1 then
5666 e_LogWritefln('%s', [g_Gibs_GetMax()])
5670 e_LogWritefln('usage: %s <n>', [cmd
])
5673 else if cmd
= 'g_max_corpses' then
5675 if Length(p
) = 2 then
5677 a
:= Max(0, StrToInt(p
[1]));
5680 else if Length(p
) = 1 then
5682 e_LogWritefln('%s', [g_Corpses_GetMax()])
5686 e_LogWritefln('usage: %s <n>', [cmd
])
5689 else if cmd
= 'g_scorelimit' then
5691 if Length(P
) > 1 then
5693 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5695 if g_Game_IsServer
then
5698 if gGameSettings
.GameMode
= GM_DM
then
5700 stat
:= g_Player_GetStats();
5702 for a
:= 0 to High(stat
) do
5703 if stat
[a
].Frags
> b
then
5707 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5709 // if someone has a higher score, set it to that instead
5710 gsGoalLimit
:= max(gsGoalLimit
, b
);
5711 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5713 if g_Game_IsNet
then MH_SEND_GameSettings
;
5717 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5719 else if cmd
= 'g_timelimit' then
5721 if Length(P
) > 1 then
5723 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5724 if g_Game_IsServer
then
5726 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5727 if g_Game_IsNet
then MH_SEND_GameSettings
;
5730 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5731 [gsTimeLimit
div 3600,
5732 (gsTimeLimit
div 60) mod 60,
5733 gsTimeLimit
mod 60]));
5735 else if cmd
= 'g_maxlives' then
5737 if Length(P
) > 1 then
5739 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5740 if g_Game_IsServer
then
5742 gGameSettings
.MaxLives
:= gsMaxLives
;
5743 if g_Game_IsNet
then MH_SEND_GameSettings
;
5747 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5751 procedure PlayerSettingsCVars(P
: SSArray
);
5756 function ParseTeam(s
: string): Byte;
5760 'red', '1': result
:= TEAM_RED
;
5761 'blue', '2': result
:= TEAM_BLUE
;
5762 else result
:= TEAM_NONE
;
5766 cmd
:= LowerCase(P
[0]);
5770 if (Length(P
) > 1) then
5772 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5773 if g_Game_IsClient
then
5774 MC_SEND_PlayerSettings
5775 else if gGameOn
and (gPlayer1
<> nil) then
5777 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5778 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5784 if (Length(P
) > 1) then
5786 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5787 if g_Game_IsClient
then
5788 MC_SEND_PlayerSettings
5789 else if gGameOn
and (gPlayer2
<> nil) then
5791 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5792 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5798 if Length(P
) > 3 then
5800 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5801 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5802 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5803 if g_Game_IsClient
then
5804 MC_SEND_PlayerSettings
5805 else if gGameOn
and (gPlayer1
<> nil) then
5807 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5808 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5814 if Length(P
) > 3 then
5816 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5817 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5818 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5819 if g_Game_IsClient
then
5820 MC_SEND_PlayerSettings
5821 else if gGameOn
and (gPlayer2
<> nil) then
5823 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5824 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5830 if (Length(P
) > 1) then
5832 gPlayer1Settings
.Model
:= P
[1];
5833 if g_Game_IsClient
then
5834 MC_SEND_PlayerSettings
5835 else if gGameOn
and (gPlayer1
<> nil) then
5837 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5838 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5839 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5845 if (Length(P
) > 1) then
5847 gPlayer2Settings
.Model
:= P
[1];
5848 if g_Game_IsClient
then
5849 MC_SEND_PlayerSettings
5850 else if gGameOn
and (gPlayer2
<> nil) then
5852 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5853 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5854 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5860 // TODO: switch teams if in game or store this separately
5861 if (Length(P
) > 1) then
5863 team
:= ParseTeam(P
[1]);
5864 if team
= TEAM_NONE
then
5865 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5866 else if not gGameOn
and not g_Game_IsNet
then
5867 gPlayer1Settings
.Team
:= team
5869 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5874 // TODO: switch teams if in game or store this separately
5875 if (Length(P
) > 1) then
5877 team
:= ParseTeam(P
[1]);
5878 if team
= TEAM_NONE
then
5879 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5880 else if not gGameOn
and not g_Game_IsNet
then
5881 gPlayer2Settings
.Team
:= team
5883 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5889 procedure PrintHeapStats();
5893 hs
:= GetFPCHeapStatus();
5894 e_LogWriteLn ('v===== heap status =====v');
5895 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5896 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5897 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5898 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5899 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5900 e_LogWriteLn ('^=======================^');
5903 procedure DebugCommands(P
: SSArray
);
5910 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5911 if {gDebugMode}conIsCheatsEnabled
then
5913 cmd
:= LowerCase(P
[0]);
5914 if cmd
= 'd_window' then
5916 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5917 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5919 else if cmd
= 'd_sounds' then
5921 if (Length(P
) > 1) and
5922 ((P
[1] = '1') or (P
[1] = '0')) then
5923 g_Debug_Sounds
:= (P
[1][1] = '1');
5925 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5927 else if cmd
= 'd_frames' then
5929 if (Length(P
) > 1) and
5930 ((P
[1] = '1') or (P
[1] = '0')) then
5931 g_Debug_Frames
:= (P
[1][1] = '1');
5933 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5935 else if cmd
= 'd_winmsg' then
5937 if (Length(P
) > 1) and
5938 ((P
[1] = '1') or (P
[1] = '0')) then
5939 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5941 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5943 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5945 if (Length(P
) > 1) and
5946 ((P
[1] = '1') or (P
[1] = '0')) then
5947 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5949 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5951 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5953 if Length(P
) > 1 then
5955 '0': g_debug_BotAIOff
:= 0;
5956 '1': g_debug_BotAIOff
:= 1;
5957 '2': g_debug_BotAIOff
:= 2;
5958 '3': g_debug_BotAIOff
:= 3;
5961 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5963 else if cmd
= 'd_monster' then
5965 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5966 if Length(P
) < 2 then
5968 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5969 g_Console_Add('ID | Name');
5970 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5971 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5972 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5975 a
:= StrToIntDef(P
[1], 0);
5976 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5977 a
:= g_Mons_TypeIdByName(P
[1]);
5979 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5980 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5983 with gPlayer1
.Obj
do
5985 mon
:= g_Monsters_Create(a
,
5986 X
+ Rect
.X
+ (Rect
.Width
div 2),
5987 Y
+ Rect
.Y
+ Rect
.Height
,
5988 gPlayer1
.Direction
, True);
5990 if (Length(P
) > 2) and (mon
<> nil) then
5992 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5993 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5994 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5995 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5996 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5997 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5998 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5999 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6000 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6005 else if (cmd
= 'd_health') then
6007 if (Length(P
) > 1) and
6008 ((P
[1] = '1') or (P
[1] = '0')) then
6009 g_debug_HealthBar
:= (P
[1][1] = '1');
6011 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6013 else if (cmd
= 'd_player') then
6015 if (Length(P
) > 1) and
6016 ((P
[1] = '1') or (P
[1] = '0')) then
6017 g_debug_Player
:= (P
[1][1] = '1');
6019 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6021 else if (cmd
= 'd_mem') then
6027 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6031 procedure GameCheats(P
: SSArray
);
6037 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6039 g_Console_Add('not available');
6045 g_Console_Add('where is the player?!');
6048 cmd
:= LowerCase(P
[0]);
6052 plr
.GodMode
:= not plr
.GodMode
;
6053 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6056 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6057 if cmd
= 'give' then
6059 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6060 for f
:= 1 to High(P
) do
6062 cmd
:= LowerCase(P
[f
]);
6063 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6064 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6065 if cmd
= 'exit' then
6067 if gTriggers
<> nil then
6069 for a
:= 0 to High(gTriggers
) do
6071 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6073 g_Console_Add('player left the map');
6074 gExitByTrigger
:= True;
6075 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6076 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6084 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6085 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6086 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6087 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6088 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6090 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6091 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6093 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6094 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;
6096 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6097 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6099 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6100 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6102 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6103 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6105 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6106 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6107 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6109 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6110 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6111 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6112 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;
6113 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6114 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6116 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;
6117 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;
6118 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;
6119 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;
6120 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;
6121 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;
6123 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6124 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;
6126 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;
6127 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;
6129 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6131 if cmd
= 'ammo' then
6133 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6134 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6135 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6136 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6137 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6138 g_Console_Add('player got some ammo');
6142 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6143 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6145 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6146 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6148 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6149 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6151 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6152 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6154 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6156 if cmd
= 'weapons' then
6158 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6159 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6160 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6161 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6162 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6163 plr
.GiveItem(ITEM_WEAPON_BFG
);
6164 g_Console_Add('player got weapons');
6168 if cmd
= 'keys' then
6170 plr
.GiveItem(ITEM_KEY_RED
);
6171 plr
.GiveItem(ITEM_KEY_GREEN
);
6172 plr
.GiveItem(ITEM_KEY_BLUE
);
6173 g_Console_Add('player got all keys');
6177 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6182 if cmd
= 'open' then
6184 g_Console_Add('player activated sesame');
6185 g_Triggers_OpenAll();
6192 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6196 if cmd
= 'noclip' then
6199 g_Console_Add('wall hardeness adjusted');
6203 if cmd
= 'notarget' then
6205 plr
.NoTarget
:= not plr
.NoTarget
;
6206 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6210 if cmd
= 'noreload' then
6212 plr
.NoReload
:= not plr
.NoReload
;
6213 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6217 if cmd
= 'speedy' then
6219 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6220 g_Console_Add('speed adjusted');
6224 if cmd
= 'jumpy' then
6226 VEL_JUMP
:= 30-VEL_JUMP
;
6227 g_Console_Add('jump height adjusted');
6231 if cmd
= 'automap' then
6233 gShowMap
:= not gShowMap
;
6234 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6238 if cmd
= 'aimline' then
6240 gAimLine
:= not gAimLine
;
6241 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6246 procedure GameCommands(P
: SSArray
);
6252 pl
: pTNetClient
= nil;
6260 cmd
:= LowerCase(P
[0]);
6262 if cmd
= 'pause' then
6264 if (g_ActiveWindow
= nil) then
6265 g_Game_Pause(not gPauseMain
);
6267 else if cmd
= 'endgame' then
6268 gExit
:= EXIT_SIMPLE
6269 else if cmd
= 'restart' then
6271 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6273 if g_Game_IsClient
then
6275 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6280 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6282 else if cmd
= 'kick' then
6284 if g_Game_IsServer
then
6286 if Length(P
) < 2 then
6288 g_Console_Add('kick <name>');
6293 g_Console_Add('kick <name>');
6297 if g_Game_IsNet
then
6298 pl
:= g_Net_Client_ByName(P
[1]);
6301 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6302 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6303 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6304 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6305 g_Net_Slist_ServerPlayerLeaves();
6306 end else if gPlayers
<> nil then
6307 for a
:= Low(gPlayers
) to High(gPlayers
) do
6308 if gPlayers
[a
] <> nil then
6309 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6311 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6312 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6314 gPlayers
[a
].Lives
:= 0;
6315 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6316 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6317 g_Player_Remove(gPlayers
[a
].UID
);
6318 g_Net_Slist_ServerPlayerLeaves();
6319 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6323 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6325 else if cmd
= 'kick_id' then
6327 if g_Game_IsServer
and g_Game_IsNet
then
6329 if Length(P
) < 2 then
6331 g_Console_Add('kick_id <client ID>');
6336 g_Console_Add('kick_id <client ID>');
6340 a
:= StrToIntDef(P
[1], 0);
6341 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6343 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6345 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6346 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6347 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6348 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6349 g_Net_Slist_ServerPlayerLeaves();
6353 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6355 else if cmd
= 'kick_pid' then
6357 if g_Game_IsServer
and g_Game_IsNet
then
6359 if Length(P
) < 2 then
6361 g_Console_Add('kick_pid <player ID>');
6366 g_Console_Add('kick_pid <player ID>');
6370 a
:= StrToIntDef(P
[1], 0);
6371 pl
:= g_Net_Client_ByPlayer(a
);
6372 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6374 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6375 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6376 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6377 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6378 g_Net_Slist_ServerPlayerLeaves();
6381 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6383 else if cmd
= 'ban' then
6385 if g_Game_IsServer
and g_Game_IsNet
then
6387 if Length(P
) < 2 then
6389 g_Console_Add('ban <name>');
6394 g_Console_Add('ban <name>');
6398 pl
:= g_Net_Client_ByName(P
[1]);
6401 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6402 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6403 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6404 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6405 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6406 g_Net_Slist_ServerPlayerLeaves();
6408 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6410 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6412 else if cmd
= 'ban_id' then
6414 if g_Game_IsServer
and g_Game_IsNet
then
6416 if Length(P
) < 2 then
6418 g_Console_Add('ban_id <client ID>');
6423 g_Console_Add('ban_id <client ID>');
6427 a
:= StrToIntDef(P
[1], 0);
6428 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6429 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6431 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6432 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6433 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6434 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6435 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6436 g_Net_Slist_ServerPlayerLeaves();
6439 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6441 else if cmd
= 'ban_pid' then
6443 if g_Game_IsServer
and g_Game_IsNet
then
6445 if Length(P
) < 2 then
6447 g_Console_Add('ban_pid <player ID>');
6452 g_Console_Add('ban_pid <player ID>');
6456 a
:= StrToIntDef(P
[1], 0);
6457 pl
:= g_Net_Client_ByPlayer(a
);
6458 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6460 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6461 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6462 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6463 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6464 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6465 g_Net_Slist_ServerPlayerLeaves();
6468 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6470 else if cmd
= 'permban' then
6472 if g_Game_IsServer
and g_Game_IsNet
then
6474 if Length(P
) < 2 then
6476 g_Console_Add('permban <name>');
6481 g_Console_Add('permban <name>');
6485 pl
:= g_Net_Client_ByName(P
[1]);
6488 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6489 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6490 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6491 g_Net_SaveBanList();
6492 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6493 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6494 g_Net_Slist_ServerPlayerLeaves();
6496 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6498 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6500 else if cmd
= 'permban_id' then
6502 if g_Game_IsServer
and g_Game_IsNet
then
6504 if Length(P
) < 2 then
6506 g_Console_Add('permban_id <client ID>');
6511 g_Console_Add('permban_id <client ID>');
6515 a
:= StrToIntDef(P
[1], 0);
6516 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6517 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6519 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6520 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6521 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6522 g_Net_SaveBanList();
6523 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6524 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6525 g_Net_Slist_ServerPlayerLeaves();
6528 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6530 else if cmd
= 'permban_pid' then
6532 if g_Game_IsServer
and g_Game_IsNet
then
6534 if Length(P
) < 2 then
6536 g_Console_Add('permban_pid <player ID>');
6541 g_Console_Add('permban_pid <player ID>');
6545 a
:= StrToIntDef(P
[1], 0);
6546 pl
:= g_Net_Client_ByPlayer(a
);
6547 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6549 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6550 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6551 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6552 g_Net_SaveBanList();
6553 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6554 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6555 g_Net_Slist_ServerPlayerLeaves();
6558 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6560 else if cmd
= 'permban_ip' then
6562 if g_Game_IsServer
and g_Game_IsNet
then
6564 if Length(P
) < 2 then
6566 g_Console_Add('permban_ip <IP address>');
6571 g_Console_Add('permban_ip <IP address>');
6575 g_Net_BanHost(P
[1]);
6576 g_Net_SaveBanList();
6577 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6579 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6581 else if cmd
= 'unban' then
6583 if g_Game_IsServer
and g_Game_IsNet
then
6585 if Length(P
) < 2 then
6587 g_Console_Add('unban <IP Address>');
6592 g_Console_Add('unban <IP Address>');
6596 if g_Net_UnbanHost(P
[1]) then
6598 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6599 g_Net_SaveBanList();
6601 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6603 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6605 else if cmd
= 'clientlist' then
6607 if g_Game_IsServer
and g_Game_IsNet
then
6610 if NetClients
<> nil then
6611 for a
:= Low(NetClients
) to High(NetClients
) do
6612 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6614 plr
:= g_Player_Get(NetClients
[a
].Player
);
6615 if plr
= nil then continue
;
6617 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6618 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6621 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6623 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6625 else if cmd
= 'connect' then
6627 if (NetMode
= NET_NONE
) then
6629 if Length(P
) < 2 then
6631 g_Console_Add('connect <IP> [port] [password]');
6636 g_Console_Add('connect <IP> [port] [password]');
6640 if Length(P
) > 2 then
6641 prt
:= StrToIntDef(P
[2], 25666)
6645 if Length(P
) > 3 then
6650 g_Game_StartClient(P
[1], prt
, pw
);
6653 else if cmd
= 'disconnect' then
6655 if (NetMode
= NET_CLIENT
) then
6658 else if cmd
= 'reconnect' then
6660 if (NetMode
= NET_SERVER
) then
6663 if (NetMode
= NET_CLIENT
) then
6666 gExit
:= EXIT_SIMPLE
;
6670 //TODO: Use last successful password to reconnect, instead of ''
6671 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6673 else if (cmd
= 'addbot') or
6674 (cmd
= 'bot_add') then
6676 if Length(P
) > 2 then
6677 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6678 else if Length(P
) > 1 then
6679 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6681 g_Bot_Add(TEAM_NONE
, 2);
6683 else if cmd
= 'bot_addlist' then
6685 if Length(P
) > 1 then
6687 if Length(P
) = 2 then
6688 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6689 else if Length(P
) = 3 then
6690 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6692 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6695 else if cmd
= 'bot_removeall' then
6697 else if cmd
= 'chat' then
6699 if g_Game_IsNet
then
6701 if Length(P
) > 1 then
6703 for a
:= 1 to High(P
) do
6704 chstr
:= chstr
+ P
[a
] + ' ';
6706 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6708 if Length(chstr
) < 1 then
6710 g_Console_Add('chat <text>');
6714 chstr
:= b_Text_Format(chstr
);
6715 if g_Game_IsClient
then
6716 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6718 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6721 g_Console_Add('chat <text>');
6723 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6725 else if cmd
= 'teamchat' then
6727 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6729 if Length(P
) > 1 then
6731 for a
:= 1 to High(P
) do
6732 chstr
:= chstr
+ P
[a
] + ' ';
6734 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6736 if Length(chstr
) < 1 then
6738 g_Console_Add('teamchat <text>');
6742 chstr
:= b_Text_Format(chstr
);
6743 if g_Game_IsClient
then
6744 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6746 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6747 gPlayer1Settings
.Team
);
6750 g_Console_Add('teamchat <text>');
6752 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6754 else if cmd
= 'game' then
6756 if gGameSettings
.GameType
<> GT_NONE
then
6758 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6761 if Length(P
) = 1 then
6763 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6766 // game not started yet, load fist map from some wad
6768 s
:= addWadExtension(P
[1]);
6769 found
:= e_FindResource(AllMapDirs
, s
);
6773 P
[1] := ExpandFileName(P
[1]);
6774 // if map not choosed then set first map
6775 if Length(P
) < 3 then
6778 P
[2] := g_Game_GetFirstMap(P
[1]);
6781 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6783 if g_Map_Exist(s
) then
6787 with gGameSettings
do
6789 Options
:= gsGameFlags
;
6790 GameMode
:= g_Game_TextToMode(gsGameMode
);
6791 if gSwitchGameMode
<> GM_NONE
then
6792 GameMode
:= gSwitchGameMode
;
6793 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6794 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6796 if Length(P
) >= 4 then
6797 b
:= StrToIntDef(P
[3], 1);
6798 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6799 GoalLimit
, MaxLives
, Options
, b
);
6804 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6806 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6808 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6810 else if cmd
= 'host' then
6812 if gGameSettings
.GameType
<> GT_NONE
then
6814 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6817 if Length(P
) < 4 then
6819 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6822 if not StrToIp(P
[1], listen
) then
6824 prt
:= StrToIntDef(P
[2], 25666);
6826 s
:= addWadExtension(P
[3]);
6827 found
:= e_FindResource(AllMapDirs
, s
);
6831 // get first map in wad, if not specified
6832 if Length(P
) < 5 then
6835 P
[4] := g_Game_GetFirstMap(P
[1]);
6837 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6838 if g_Map_Exist(s
) then
6842 with gGameSettings
do
6844 Options
:= gsGameFlags
;
6845 GameMode
:= g_Game_TextToMode(gsGameMode
);
6846 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6847 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6848 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6850 if Length(P
) >= 6 then
6851 b
:= StrToIntDef(P
[5], 0);
6852 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6858 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6860 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6865 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6868 else if cmd
= 'map' then
6870 if Length(P
) = 1 then
6872 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6874 g_Console_Add(cmd
+ ' <MAP>');
6875 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6879 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6884 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6886 if Length(P
) < 3 then
6888 // first param is map or wad
6889 s
:= UpperCase(P
[1]);
6890 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6892 gExitByTrigger
:= False;
6895 // already in game, finish current map
6897 gExit
:= EXIT_ENDLEVELCUSTOM
;
6901 // intermission, so change map immediately
6908 found
:= e_FindResource(AllMapDirs
, s
);
6910 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6913 // no such map, found wad
6916 P
[1] := ExpandFileName(pw
);
6917 P
[2] := g_Game_GetFirstMap(P
[1]);
6918 s
:= P
[1] + ':\' + P
[2];
6919 if g_Map_Exist(s
) then
6921 gExitByTrigger
:= False;
6924 // already in game, finish current map
6926 gExit
:= EXIT_ENDLEVELCUSTOM
6930 // intermission, so change map immediately
6937 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6939 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6944 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6950 s
:= addWadExtension(P
[1]);
6951 found
:= e_FindResource(AllMapDirs
, s
);
6955 P
[2] := UpperCase(P
[2]);
6956 s
:= P
[1] + ':\' + P
[2];
6957 if g_Map_Exist(s
) then
6959 gExitByTrigger
:= False;
6963 gExit
:= EXIT_ENDLEVELCUSTOM
6972 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6977 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6983 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6987 else if cmd
= 'nextmap' then
6989 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6991 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6996 if Length(P
) = 1 then
6998 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7000 g_Console_Add(cmd
+ ' <MAP>');
7001 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7006 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7012 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7014 if Length(P
) < 3 then
7016 // first param is map or wad
7017 s
:= UpperCase(P
[1]);
7018 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7021 gExitByTrigger
:= False;
7027 // no such map, found wad
7028 pw
:= addWadExtension(P
[1]);
7029 found
:= e_FindResource(MapDirs
, pw
);
7031 found
:= e_FindResource(WadDirs
, pw
);
7033 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7036 // map not specified, select first map
7038 P
[2] := g_Game_GetFirstMap(P
[1]);
7039 s
:= P
[1] + ':\' + P
[2];
7040 if g_Map_Exist(s
) then
7042 gExitByTrigger
:= False;
7049 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7051 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7056 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7062 // specified two params wad + map
7063 pw
:= addWadExtension(P
[1]);
7064 found
:= e_FindResource(MapDirs
, pw
);
7066 found
:= e_FindResource(MapDirs
, pw
);
7070 P
[2] := UpperCase(P
[2]);
7071 s
:= P
[1] + ':\' + P
[2];
7072 if g_Map_Exist(s
) then
7074 gExitByTrigger
:= False;
7080 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7085 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7091 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7096 if gNextMap
= '' then
7097 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7099 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7103 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7107 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7111 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7113 gExitByTrigger
:= False;
7114 // next map not specified, try to find trigger EXIT
7115 if (gNextMap
= '') and (gTriggers
<> nil) then
7117 for a
:= 0 to High(gTriggers
) do
7119 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7121 gExitByTrigger
:= True;
7122 //gNextMap := gTriggers[a].Data.MapName;
7123 gNextMap
:= gTriggers
[a
].tgcMap
;
7128 if gNextMap
= '' then
7129 gNextMap
:= g_Game_GetNextMap();
7130 if not isWadPath(gNextMap
) then
7131 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7134 if g_Map_Exist(s
) then
7135 gExit
:= EXIT_ENDLEVELCUSTOM
7137 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7141 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7145 else if (cmd
= 'event') then
7147 if (Length(P
) <= 1) then
7149 for a
:= 0 to High(gEvents
) do
7150 if gEvents
[a
].Command
= '' then
7151 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7153 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7156 if (Length(P
) = 2) then
7158 for a
:= 0 to High(gEvents
) do
7159 if gEvents
[a
].Name
= P
[1] then
7160 if gEvents
[a
].Command
= '' then
7161 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7163 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7166 for a
:= 0 to High(gEvents
) do
7167 if gEvents
[a
].Name
= P
[1] then
7169 gEvents
[a
].Command
:= '';
7170 for b
:= 2 to High(P
) do
7171 if Pos(' ', P
[b
]) = 0 then
7172 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7174 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7175 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7179 else if cmd
= 'suicide' then
7183 if g_Game_IsClient
then
7184 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7187 if gPlayer1
<> nil then
7188 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7189 if gPlayer2
<> nil then
7190 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7194 else if cmd
= 'screenshot' then
7198 else if cmd
= 'weapon' then
7200 if Length(p
) = 2 then
7202 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7203 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7204 gSelectWeapon
[0, a
] := True
7207 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7209 if Length(p
) = 2 then
7211 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7212 b
:= ord(cmd
[2]) - ord('1');
7213 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7214 gSelectWeapon
[b
, a
] := True
7217 // Êîìàíäû Ñâîåé èãðû:
7218 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7220 if cmd
= 'bot_addred' then
7222 if Length(P
) > 1 then
7223 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7225 g_Bot_Add(TEAM_RED
, 2);
7227 else if cmd
= 'bot_addblue' then
7229 if Length(P
) > 1 then
7230 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7232 g_Bot_Add(TEAM_BLUE
, 2);
7234 else if cmd
= 'spectate' then
7240 else if cmd
= 'say' then
7242 if g_Game_IsServer
and g_Game_IsNet
then
7244 if Length(P
) > 1 then
7247 for a
:= 1 to High(P
) do
7248 chstr
:= chstr
+ P
[a
] + ' ';
7250 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7252 if Length(chstr
) < 1 then
7254 g_Console_Add('say <text>');
7258 chstr
:= b_Text_Format(chstr
);
7259 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7261 else g_Console_Add('say <text>');
7263 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7265 else if cmd
= 'tell' then
7267 if g_Game_IsServer
and g_Game_IsNet
then
7269 if (Length(P
) > 2) and (P
[1] <> '') then
7272 for a
:= 2 to High(P
) do
7273 chstr
:= chstr
+ P
[a
] + ' ';
7275 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7277 if Length(chstr
) < 1 then
7279 g_Console_Add('tell <playername> <text>');
7283 pl
:= g_Net_Client_ByName(P
[1]);
7285 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7287 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7289 else g_Console_Add('tell <playername> <text>');
7291 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7293 else if cmd
= 'centerprint' then
7295 if (Length(P
) > 2) and (P
[1] <> '') then
7298 for a
:= 2 to High(P
) do
7299 chstr
:= chstr
+ P
[a
] + ' ';
7301 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7303 if Length(chstr
) < 1 then
7305 g_Console_Add('centerprint <timeout> <text>');
7309 a
:= StrToIntDef(P
[1], 100);
7310 chstr
:= b_Text_Format(chstr
);
7311 g_Game_Message(chstr
, a
);
7312 if g_Game_IsNet
and g_Game_IsServer
then
7313 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7315 else g_Console_Add('centerprint <timeout> <text>');
7317 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7319 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7321 // Äîïîëíèòåëüíîå âðåìÿ:
7322 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7324 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7325 [gGameSettings
.TimeLimit
div 3600,
7326 (gGameSettings
.TimeLimit
div 60) mod 60,
7327 gGameSettings
.TimeLimit
mod 60]));
7328 if g_Game_IsNet
then MH_SEND_GameSettings
;
7330 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7332 if (Length(P
) <= 1) then
7333 g_Console_Add('rcon_password <password>')
7335 MC_SEND_RCONPassword(P
[1]);
7337 else if cmd
= 'rcon' then
7339 if g_Game_IsClient
then
7341 if Length(P
) > 1 then
7344 for a
:= 1 to High(P
) do
7345 chstr
:= chstr
+ P
[a
] + ' ';
7347 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7349 if Length(chstr
) < 1 then
7351 g_Console_Add('rcon <command>');
7355 MC_SEND_RCONCommand(chstr
);
7357 else g_Console_Add('rcon <command>');
7360 else if cmd
= 'ready' then
7362 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7363 gLMSRespawnTime
:= gTime
+ 100;
7365 else if (cmd
= 'callvote') and g_Game_IsNet
then
7367 if Length(P
) > 1 then
7370 for a
:= 1 to High(P
) do begin
7371 if a
> 1 then chstr
:= chstr
+ ' ';
7372 chstr
:= chstr
+ P
[a
];
7375 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7377 if Length(chstr
) < 1 then
7379 g_Console_Add('callvote <command>');
7383 if g_Game_IsClient
then
7384 MC_SEND_Vote(True, chstr
)
7386 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7387 g_Console_Process('vote', True);
7390 g_Console_Add('callvote <command>');
7392 else if (cmd
= 'vote') and g_Game_IsNet
then
7394 if g_Game_IsClient
then
7396 else if gVoteInProgress
then
7398 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7399 a
:= Floor((NetClientCount
+1)/2.0) + 1
7401 a
:= Floor(NetClientCount
/2.0) + 1;
7406 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7407 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7413 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7414 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7422 procedure SystemCommands(P
: SSArray
);
7426 cmd
:= LowerCase(P
[0]);
7435 gRC_Width
:= Max(1, gRC_Width
);
7436 gRC_Height
:= Max(1, gRC_Height
);
7437 gBPP
:= Max(1, gBPP
);
7438 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7439 e_LogWriteln('resolution changed')
7441 e_LogWriteln('resolution not changed');
7442 sys_EnableVSync(gVSync
);
7446 if Length(p
) = 2 then
7448 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7450 gFrameTime
:= 1000 div gMaxFPS
7454 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7458 if Length(p
) = 2 then
7460 gAskLanguage
:= true;
7461 gLanguage
:= LANGUAGE_ENGLISH
;
7462 case LowerCase(p
[1]) of
7465 gAskLanguage
:= false;
7466 gLanguage
:= LANGUAGE_ENGLISH
;
7470 gAskLanguage
:= false;
7471 gLanguage
:= LANGUAGE_RUSSIAN
;
7475 gAskLanguage
:= true;
7476 gLanguage
:= LANGUAGE_ENGLISH
;
7479 g_Language_Set(gLanguage
);
7483 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7489 procedure g_TakeScreenShot(Filename
: string = '');
7490 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7492 if e_NoGraphics
then Exit
;
7494 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7496 if Filename
= '' then
7499 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7500 Filename
:= 'screenshot-' + date
;
7503 name
:= e_CatPath(dir
, Filename
+ '.png');
7504 s
:= createDiskFile(name
);
7506 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7508 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7510 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7515 g_Console_Add('oh shit, i can''t create screenshot!')
7519 procedure g_Game_InGameMenu(Show
: Boolean);
7521 if (g_ActiveWindow
= nil) and Show
then
7523 if gGameSettings
.GameType
= GT_SINGLE
then
7524 g_GUI_ShowWindow('GameSingleMenu')
7527 if g_Game_IsClient
then
7528 g_GUI_ShowWindow('GameClientMenu')
7530 if g_Game_IsNet
then
7531 g_GUI_ShowWindow('GameServerMenu')
7533 g_GUI_ShowWindow('GameCustomMenu');
7535 g_Sound_PlayEx('MENU_OPEN');
7537 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7538 if (not g_Game_IsNet
) then
7542 if (g_ActiveWindow
<> nil) and (not Show
) then
7544 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7545 if (not g_Game_IsNet
) then
7546 g_Game_Pause(False);
7550 procedure g_Game_Pause (Enable
: Boolean);
7554 if not gGameOn
then exit
;
7556 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7559 gPauseMain
:= Enable
;
7561 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7564 procedure g_Game_HolmesPause (Enable
: Boolean);
7568 if not gGameOn
then exit
;
7569 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7572 gPauseHolmes
:= Enable
;
7574 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7577 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7582 if gTriggers
<> nil then
7583 for i
:= 0 to High(gTriggers
) do
7584 with gTriggers
[i
] do
7585 if (TriggerType
= TRIGGER_SOUND
) and
7587 Sound
.IsPlaying() then
7589 Sound
.Pause(Enable
);
7593 if gPlayers
<> nil then
7594 for i
:= 0 to High(gPlayers
) do
7595 if gPlayers
[i
] <> nil then
7596 gPlayers
[i
].PauseSounds(Enable
);
7599 if gMusic
<> nil then
7600 gMusic
.Pause(Enable
);
7603 procedure g_Game_StopAllSounds(all
: Boolean);
7607 if gTriggers
<> nil then
7608 for i
:= 0 to High(gTriggers
) do
7609 with gTriggers
[i
] do
7610 if (TriggerType
= TRIGGER_SOUND
) and
7614 if gMusic
<> nil then
7621 procedure g_Game_UpdateTriggerSounds
;
7624 if gTriggers
<> nil then
7625 for i
:= 0 to High(gTriggers
) do
7626 with gTriggers
[i
] do
7627 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7628 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7631 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7634 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7639 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7644 if gSpectMode
<> SPECT_PLAYERS
then
7646 if gSpectPID1
= UID
then
7651 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7658 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7663 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7668 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7673 if gSpectMode
<> SPECT_PLAYERS
then
7675 Pl
:= g_Player_Get(gSpectPID1
);
7676 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7681 if gSpectViewTwo
then
7683 Pl
:= g_Player_Get(gSpectPID2
);
7684 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7692 procedure g_Game_Message(Msg
: string; Time
: Word);
7694 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7695 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7696 MessageTime
:= Time
;
7699 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7701 punct
: Array[0..13] of String =
7702 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7708 function IsPunctuation(S
: String): Boolean;
7713 if Length(S
) <> 1 then
7715 for i
:= Low(punct
) to High(punct
) do
7716 if S
= punct
[i
] then
7722 function FilterPunctuation(S
: String): String;
7726 for i
:= Low(punct
) to High(punct
) do
7727 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7733 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7735 // remove player name
7736 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7737 // for FullWord check
7738 Text := toLowerCase1251(' ' + Text + ' ');
7739 fpText
:= FilterPunctuation(Text);
7741 for i
:= 0 to Length(gChatSounds
) - 1 do
7744 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7746 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7747 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7749 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7755 gChatSounds
[i
].Sound
.Play();
7761 g_Sound_PlayEx('SOUND_GAME_RADIO');
7764 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7773 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7777 if goodsnd
[a
].IsPlaying() then
7780 goodsnd
[Random(4)].Play();
7783 procedure g_Game_Announce_KillCombo(Param
: Integer);
7790 UID
:= Param
and $FFFF;
7795 Pl
:= g_Player_Get(UID
);
7804 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7808 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7812 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7816 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7824 if not g_Game_IsWatchedPlayer(UID
) then
7827 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7831 if killsnd
[n
].IsPlaying() then
7836 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7844 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7848 if hahasnd
[a
].IsPlaying() then
7851 hahasnd
[Random(3)].Play();
7854 procedure g_Game_StartVote(Command
, Initiator
: string);
7858 if not gVotesEnabled
then Exit
;
7859 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7860 if gVoteInProgress
or gVotePassed
then
7862 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7863 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7866 gVoteInProgress
:= True;
7867 gVotePassed
:= False;
7868 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7871 gVoteCommand
:= Command
;
7873 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7874 Need
:= Floor((NetClientCount
+1)/2.0)+1
7876 Need
:= Floor(NetClientCount
/2.0)+1;
7877 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7878 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7881 procedure g_Game_CheckVote
;
7885 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7886 if not gVoteInProgress
then Exit
;
7888 if (gTime
>= gVoteTimer
) then
7890 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7891 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7893 Need
:= Floor(NetClientCount
/2.0) + 1;
7894 if gVoteCount
>= Need
then
7896 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7897 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7898 gVotePassed
:= True;
7899 gVoteCmdTimer
:= gTime
+ 5000;
7903 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7904 MH_SEND_VoteEvent(NET_VE_FAILED
);
7906 if NetClients
<> nil then
7907 for I
:= Low(NetClients
) to High(NetClients
) do
7908 if NetClients
[i
].Used
then
7909 NetClients
[i
].Voted
:= False;
7910 gVoteInProgress
:= False;
7916 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7917 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7919 Need
:= Floor(NetClientCount
/2.0) + 1;
7920 if gVoteCount
>= Need
then
7922 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7923 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7924 gVoteInProgress
:= False;
7925 gVotePassed
:= True;
7926 gVoteCmdTimer
:= gTime
+ 5000;
7929 if NetClients
<> nil then
7930 for I
:= Low(NetClients
) to High(NetClients
) do
7931 if NetClients
[i
].Used
then
7932 NetClients
[i
].Voted
:= False;
7937 procedure g_Game_LoadMapList(FileName
: string);
7945 if not FileExists(FileName
) then Exit
;
7947 AssignFile(ListFile
, FileName
);
7949 while not EOF(ListFile
) do
7951 ReadLn(ListFile
, s
);
7954 if s
= '' then Continue
;
7956 SetLength(MapList
, Length(MapList
)+1);
7957 MapList
[High(MapList
)] := s
;
7959 CloseFile(ListFile
);
7962 procedure g_Game_SetDebugMode();
7965 // ×èòû (äàæå â ñâîåé èãðå):
7969 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7973 if Length(LoadingStat
.Msgs
) = 0 then
7979 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7980 if NextMsg
= Length(Msgs
) then
7982 for i
:= 0 to High(Msgs
)-1 do
7983 Msgs
[i
] := Msgs
[i
+1];
7991 Msgs
[NextMsg
-1] := Text;
7995 PBarWasHere
:= false;
7998 g_ActiveWindow
:= nil;
8000 ProcessLoading(true);
8003 procedure g_Game_StepLoading(Value
: Integer = -1);
8014 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8022 procedure g_Game_ClearLoading();
8031 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8032 if len
< 1 then len
:= 1;
8033 SetLength(Msgs
, len
);
8034 for len
:= Low(Msgs
) to High(Msgs
) do
8037 PBarWasHere
:= false;
8041 procedure Parse_Params(var pars
: TParamStrValues
);
8048 while i
<= ParamCount
do
8051 if (s
[1] = '-') and (Length(s
) > 1) then
8053 if (s
[2] = '-') and (Length(s
) > 2) then
8054 begin // Îäèíî÷íûé ïàðàìåòð
8055 SetLength(pars
, Length(pars
) + 1);
8056 with pars
[High(pars
)] do
8058 Name
:= LowerCase(s
);
8063 if (i
< ParamCount
) then
8064 begin // Ïàðàìåòð ñî çíà÷åíèåì
8066 SetLength(pars
, Length(pars
) + 1);
8067 with pars
[High(pars
)] do
8069 Name
:= LowerCase(s
);
8070 Value
:= LowerCase(ParamStr(i
));
8079 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8084 for i
:= 0 to High(pars
) do
8085 if pars
[i
].Name
= aName
then
8087 Result
:= pars
[i
].Value
;
8092 procedure g_Game_Process_Params();
8094 pars
: TParamStrValues
;
8097 LimT
, LimS
: Integer;
8108 s
:= Find_Param_Value(pars
, '--debug');
8111 g_Game_SetDebugMode();
8112 s
:= Find_Param_Value(pars
, '--netdump');
8117 // Connect when game loads
8118 ip
:= Find_Param_Value(pars
, '-connect');
8122 s
:= Find_Param_Value(pars
, '-port');
8123 if (s
= '') or not TryStrToInt(s
, Port
) then
8126 s
:= Find_Param_Value(pars
, '-pw');
8128 g_Game_StartClient(ip
, Port
, s
);
8132 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8135 gDefaultMegawadStart
:= s
;
8138 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8139 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8141 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8144 // Start map when game loads:
8145 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8146 if isWadPath(map
) then
8149 s
:= Find_Param_Value(pars
, '-gm');
8150 GMode
:= g_Game_TextToMode(s
);
8151 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8152 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8155 s
:= Find_Param_Value(pars
, '-limt');
8156 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8162 s
:= Find_Param_Value(pars
, '-lims');
8163 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8169 s
:= Find_Param_Value(pars
, '-lives');
8170 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8176 s
:= Find_Param_Value(pars
, '-opt');
8180 Opt
:= StrToIntDef(s
, 0);
8183 s
:= Find_Param_Value(pars
, '--close');
8187 // Override map to test:
8188 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8191 if e_IsValidResourceName(s
) then
8192 e_FindResource(AllMapDirs
, s
);
8193 gTestMap
:= ExpandFileName(s
);
8196 // Delete test map after play:
8197 s
:= Find_Param_Value(pars
, '--testdelete');
8200 //gMapToDelete := MapsDir + map;
8201 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8205 // Delete temporary WAD after play:
8206 s
:= Find_Param_Value(pars
, '--tempdelete');
8207 if (s
<> '') and (gTestMap
<> '') then
8209 gMapToDelete
:= gTestMap
;
8210 gTempDelete
:= True;
8213 // Number of players:
8214 s
:= Find_Param_Value(pars
, '-pl');
8216 n
:= DEFAULT_PLAYERS
8218 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8221 s
:= Find_Param_Value(pars
, '-port');
8222 if (s
= '') or not TryStrToInt(s
, Port
) then
8223 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8225 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8228 // Execute script when game loads:
8229 s
:= Find_Param_Value(pars
, '-exec');
8232 // if not isWadPath(s) then
8233 // s := GameDir + '/' + s;
8238 if IOResult
<> 0 then
8240 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8241 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8245 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8246 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8251 if IOResult
<> 0 then
8253 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8254 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8258 if Pos('#', s
) <> 1 then // script comment
8259 g_Console_Process(s
, True);
8270 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8271 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8272 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8273 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8275 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8276 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8277 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8278 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8280 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8281 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8283 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8284 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8286 {$IFDEF ENABLE_HOLMES}
8287 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8290 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8292 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8293 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8295 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8296 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8298 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8299 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8301 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8302 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8303 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8304 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8305 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8306 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8307 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8308 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8309 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');