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
65 // ones below are sent only to the server
67 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
84 function g_Game_IsNet(): Boolean;
85 function g_Game_IsServer(): Boolean;
86 function g_Game_IsClient(): Boolean;
87 procedure g_Game_Init();
88 procedure g_Game_Free (freeTextures
: Boolean=true);
89 procedure g_Game_LoadData();
90 procedure g_Game_FreeData();
91 procedure g_Game_Update();
92 procedure g_Game_PreUpdate();
93 procedure g_Game_Draw();
94 procedure g_Game_Quit();
95 procedure g_Game_SetupScreenSize();
96 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 procedure g_Game_InGameMenu(Show
: Boolean);
122 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
123 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
124 procedure g_Game_Message(Msg
: String; Time
: Word);
125 procedure g_Game_LoadMapList(FileName
: String);
126 procedure g_Game_PauseAllSounds(Enable
: Boolean);
127 procedure g_Game_StopAllSounds(all
: Boolean);
128 procedure g_Game_UpdateTriggerSounds();
129 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
130 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
131 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
132 procedure g_Game_Announce_KillCombo(Param
: Integer);
133 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
134 procedure g_Game_Effect_Bubbles(fX
, fY
: Integer; count
: Word; devX
, devY
: Byte; Silent
: Boolean = False);
135 procedure g_Game_StartVote(Command
, Initiator
: string);
136 procedure g_Game_CheckVote
;
137 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
150 procedure g_Game_StepLoading(Value
: Integer = -1);
151 procedure g_Game_ClearLoading();
152 procedure g_Game_SetDebugMode();
153 procedure DrawLoadingStat();
154 procedure DrawMenuBackground(tex
: AnsiString);
156 { procedure SetWinPause(Enable: Boolean); }
161 LOADING_SHOW_STEP
= 100;
162 LOADING_INTERLINE
= 20;
177 MESSAGE_DIKEY
= WM_USER
+ 1;
182 EXIT_ENDLEVELSINGLE
= 4;
183 EXIT_ENDLEVELCUSTOM
= 5;
185 GAME_OPTION_RESERVED
= 1;
186 GAME_OPTION_TEAMDAMAGE
= 2;
187 GAME_OPTION_ALLOWEXIT
= 4;
188 GAME_OPTION_WEAPONSTAY
= 8;
189 GAME_OPTION_MONSTERS
= 16;
190 GAME_OPTION_BOTVSPLAYER
= 32;
191 GAME_OPTION_BOTVSMONSTER
= 64;
192 GAME_OPTION_DMKEYS
= 128;
193 GAME_OPTION_TEAMHITTRACE
= 256;
194 GAME_OPTION_TEAMHITPROJECTILE
= 512;
195 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
196 GAME_OPTION_ALLOWDROPFLAG
= 2048;
197 GAME_OPTION_THROWFLAG
= 4096;
202 STATE_INTERCUSTOM
= 3;
203 STATE_INTERSINGLE
= 4;
209 LMS_RESPAWN_NONE
= 0;
210 LMS_RESPAWN_WARMUP
= 1;
211 LMS_RESPAWN_FINAL
= 2;
228 CONFIG_FILENAME
= 'Doom2DF.cfg';
230 TEST_MAP_NAME
= '$$$_TEST_$$$';
232 STD_PLAYER_MODEL
= 'Doomer';
240 STATFILE_VERSION
= $03;
244 gGameSettings
: TGameSettings
;
245 gPlayer1Settings
: TPlayerSettings
;
246 gPlayer2Settings
: TPlayerSettings
;
248 gPlayerScreenSize
: TDFPoint
;
249 gPlayer1ScreenCoord
: TDFPoint
;
250 gPlayer2ScreenCoord
: TDFPoint
;
251 gPlayer1
: TPlayer
= nil;
252 gPlayer2
: TPlayer
= nil;
253 gPlayerDrawn
: TPlayer
= nil;
255 gLerpFactor
: Single = 1.0;
256 gSwitchGameMode
: Byte = GM_DM
;
257 gHearPoint1
, gHearPoint2
: THearPoint
;
258 gSoundEffectsDF
: Boolean = False;
259 gSoundTriggerTime
: Word = 0;
260 gAnnouncer
: Integer = ANNOUNCE_NONE
;
261 goodsnd
: array[0..3] of TPlayableSound
;
262 killsnd
: array[0..3] of TPlayableSound
;
263 hahasnd
: array[0..2] of TPlayableSound
;
264 sound_get_flag
: array[0..1] of TPlayableSound
;
265 sound_lost_flag
: array[0..1] of TPlayableSound
;
266 sound_ret_flag
: array[0..1] of TPlayableSound
;
267 sound_cap_flag
: array[0..1] of TPlayableSound
;
268 gBodyKillEvent
: Integer = -1;
269 gDefInterTime
: ShortInt = -1;
270 gInterEndTime
: LongWord = 0;
271 gInterTime
: LongWord = 0;
272 gServInterTime
: Byte = 0;
273 gGameStartTime
: LongWord = 0;
274 gTotalMonsters
: Integer = 0;
275 gPauseMain
: Boolean = false;
276 gPauseHolmes
: Boolean = false;
277 gShowTime
: Boolean = False;
278 gShowFPS
: Boolean = False;
279 gShowScore
: Boolean = True;
280 gShowStat
: Boolean = True;
281 gShowPIDs
: Boolean = False;
282 gShowKillMsg
: Boolean = True;
283 gShowLives
: Boolean = True;
284 gShowPing
: Boolean = False;
285 gShowMap
: Boolean = False;
287 gState
: Byte = STATE_NONE
;
289 sWidth
, sHeight
: Word;
290 gSpectMode
: Byte = SPECT_NONE
;
291 gSpectHUD
: Boolean = True;
292 gSpectKeyPress
: Boolean = False;
293 gSpectX
: Integer = 0;
294 gSpectY
: Integer = 0;
295 gSpectStep
: Byte = 8;
296 gSpectViewTwo
: Boolean = False;
297 gSpectPID1
: Integer = -1;
298 gSpectPID2
: Integer = -1;
299 gSpectAuto
: Boolean = False;
300 gSpectAutoNext
: LongWord;
301 gSpectAutoStepX
: Integer;
302 gSpectAutoStepY
: Integer;
303 gMusic
: TMusic
= nil;
304 gLoadGameMode
: Boolean;
305 gCheats
: Boolean = False;
306 gMapOnce
: Boolean = False;
307 gMapToDelete
: String;
308 gTempDelete
: Boolean = False;
309 gLastMap
: Boolean = False;
312 gResolutionChange
: Boolean = False;
313 gRC_Width
, gRC_Height
: Integer;
314 gRC_FullScreen
, gRC_Maximized
: Boolean;
315 gLanguageChange
: Boolean = False;
316 gDebugMode
: Boolean = False;
317 g_debug_Sounds
: Boolean = False;
318 g_debug_Frames
: Boolean = False;
319 g_debug_WinMsgs
: Boolean = False;
320 g_debug_MonsterOff
: Boolean = False;
321 g_debug_BotAIOff
: Byte = 0;
322 g_debug_HealthBar
: Boolean = False;
323 g_Debug_Player
: Boolean = False;
324 gCoopMonstersKilled
: Word = 0;
325 gCoopSecretsFound
: Word = 0;
326 gCoopTotalMonstersKilled
: Word = 0;
327 gCoopTotalSecretsFound
: Word = 0;
328 gCoopTotalMonsters
: Word = 0;
329 gCoopTotalSecrets
: Word = 0;
330 gStatsOff
: Boolean = False;
331 gStatsPressed
: Boolean = False;
332 gExitByTrigger
: Boolean = False;
333 gNextMap
: String = '';
334 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
335 gLMSRespawnTime
: Cardinal = 0;
336 gLMSSoftSpawn
: Boolean = False;
337 gMissionFailed
: Boolean = False;
338 gVoteInProgress
: Boolean = False;
339 gVotePassed
: Boolean = False;
340 gVoteCommand
: string = '';
341 gVoteTimer
: Cardinal = 0;
342 gVoteCmdTimer
: Cardinal = 0;
343 gVoteCount
: Integer = 0;
344 gVoteTimeout
: Cardinal = 30;
345 gVoted
: Boolean = False;
346 gVotesEnabled
: Boolean = True;
347 gEvents
: Array of TGameEvent
;
348 gDelayedEvents
: Array of TDelayedEvent
;
349 gUseChatSounds
: Boolean = True;
350 gChatSounds
: Array of TChatSound
;
351 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
352 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
353 gInterReadyCount
: Integer = 0;
354 gMaxBots
: Integer = 127;
356 g_dbg_ignore_bounds
: Boolean = false;
357 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
358 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
360 // move button values:
361 // bits 0-1: l/r state:
362 // 0: neither left, nor right pressed
365 // bits 4-5: l/r state when strafe was pressed
366 P1MoveButton
: Byte = 0;
367 P2MoveButton
: Byte = 0;
369 g_profile_frame_update
: Boolean = false;
370 g_profile_frame_draw
: Boolean = false;
371 g_profile_collision
: Boolean = false;
372 g_profile_los
: Boolean = false;
373 g_profile_history_size
: Integer = 1000;
375 g_rlayer_back
: Boolean = true;
376 g_rlayer_step
: Boolean = true;
377 g_rlayer_wall
: Boolean = true;
378 g_rlayer_door
: Boolean = true;
379 g_rlayer_acid1
: Boolean = true;
380 g_rlayer_acid2
: Boolean = true;
381 g_rlayer_water
: Boolean = true;
382 g_rlayer_fore
: Boolean = true;
385 procedure g_ResetDynlights ();
386 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
387 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
389 function conIsCheatsEnabled (): Boolean; inline;
390 function gPause (): Boolean; inline;
396 {$INCLUDE ../nogl/noGLuses.inc}
397 {$IFDEF ENABLE_HOLMES}
400 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
401 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
402 g_playermodel
, g_gfx
, g_options
, Math
,
403 g_triggers
, g_monsters
, e_sound
, CONFIG
,
404 g_language
, g_net
, g_main
, g_phys
,
405 ENet
, e_msg
, g_netmsg
, g_netmaster
,
406 sfs
, wadreader
, g_system
;
410 hasPBarGfx
: Boolean = false;
413 // ////////////////////////////////////////////////////////////////////////// //
414 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
417 // ////////////////////////////////////////////////////////////////////////// //
418 function conIsCheatsEnabled (): Boolean; inline;
421 if g_Game_IsNet
then exit
;
422 if not gDebugMode
then
424 //if not gCheats then exit;
425 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
426 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
432 // ////////////////////////////////////////////////////////////////////////// //
434 profileFrameDraw
: TProfiler
= nil;
437 // ////////////////////////////////////////////////////////////////////////// //
440 x
, y
, radius
: Integer;
443 exploRadius
: Integer;
447 g_dynLights
: array of TDynLight
= nil;
448 g_dynLightCount
: Integer = 0;
449 g_playerLight
: Boolean = false;
451 procedure g_ResetDynlights ();
455 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
457 for idx
:= 0 to g_dynLightCount
-1 do
459 if g_dynLights
[idx
].exploCount
= -666 then
466 Inc(g_dynLights
[idx
].exploCount
);
467 if (g_dynLights
[idx
].exploCount
< 10) then
469 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
470 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
471 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
472 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
477 g_dynLightCount
:= lnum
;
480 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
482 if not gwin_has_stencil
then exit
;
483 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
484 g_dynLights
[g_dynLightCount
].x
:= x
;
485 g_dynLights
[g_dynLightCount
].y
:= y
;
486 g_dynLights
[g_dynLightCount
].radius
:= radius
;
487 g_dynLights
[g_dynLightCount
].r
:= r
;
488 g_dynLights
[g_dynLightCount
].g
:= g
;
489 g_dynLights
[g_dynLightCount
].b
:= b
;
490 g_dynLights
[g_dynLightCount
].a
:= a
;
491 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
492 Inc(g_dynLightCount
);
495 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
497 if not gwin_has_stencil
then exit
;
498 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
499 g_dynLights
[g_dynLightCount
].x
:= x
;
500 g_dynLights
[g_dynLightCount
].y
:= y
;
501 g_dynLights
[g_dynLightCount
].radius
:= 0;
502 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
503 g_dynLights
[g_dynLightCount
].r
:= r
;
504 g_dynLights
[g_dynLightCount
].g
:= g
;
505 g_dynLights
[g_dynLightCount
].b
:= b
;
506 g_dynLights
[g_dynLightCount
].a
:= 0;
507 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
508 Inc(g_dynLightCount
);
512 // ////////////////////////////////////////////////////////////////////////// //
513 function calcProfilesHeight (prof
: TProfiler
): Integer;
516 if (prof
= nil) then exit
;
517 if (length(prof
.bars
) = 0) then exit
;
518 result
:= length(prof
.bars
)*(16+2);
522 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
529 if (prof
= nil) then exit
;
531 if (length(prof
.bars
) = 0) then exit
;
533 hgt
:= calcProfilesHeight(prof
);
534 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
535 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
537 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
538 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
539 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
542 for ii
:= 0 to High(prof
.bars
) do
544 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);
551 // ////////////////////////////////////////////////////////////////////////// //
553 TEndCustomGameStat
= record
554 PlayerStat
: TPlayerStatArray
;
558 Map
, MapName
: String;
561 TEndSingleGameStat
= record
562 PlayerStat
: Array [0..1] of record
568 TotalSecrets
: Integer;
571 TLoadingStat
= record
575 Msgs
: Array of String;
577 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
580 TParamStrValue
= record
585 TParamStrValues
= Array of TParamStrValue
;
588 INTER_ACTION_TEXT
= 1;
589 INTER_ACTION_PIC
= 2;
590 INTER_ACTION_MUSIC
= 3;
594 FPSCounter
, UPSCounter
: Word;
595 FPSTime
, UPSTime
: LongWord;
596 DataLoaded
: Boolean = False;
597 IsDrawStat
: Boolean = False;
598 CustomStat
: TEndCustomGameStat
;
599 SingleStat
: TEndSingleGameStat
;
600 LoadingStat
: TLoadingStat
;
601 EndingGameCounter
: Byte = 0;
604 MessageLineLength
: Integer = 80;
605 MapList
: SSArray
= nil;
606 MapIndex
: Integer = -1;
607 InterReadyTime
: Integer = -1;
608 StatShotDone
: Boolean = False;
609 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
610 StatDate
: string = '';
616 text: Array of ShortString;
617 anim
: Array of ShortString;
618 pic
: Array of ShortString;
619 mus
: Array of ShortString;
621 triggers
: Array of record
623 actions
: Array of record
624 action
, p1
, p2
: Integer;
627 cur_trigger
: Integer;
640 function Compare(a
, b
: TPlayerStat
): Integer;
642 if a
.Spectator
then Result
:= 1
643 else if b
.Spectator
then Result
:= -1
644 else if a
.Frags
< b
.Frags
then Result
:= 1
645 else if a
.Frags
> b
.Frags
then Result
:= -1
646 else if a
.Deaths
< b
.Deaths
then Result
:= -1
647 else if a
.Deaths
> b
.Deaths
then Result
:= 1
648 else if a
.Kills
< b
.Kills
then Result
:= -1
652 procedure SortGameStat(var stat
: TPlayerStatArray
);
657 if stat
= nil then Exit
;
659 for I
:= High(stat
) downto Low(stat
) do
660 for J
:= Low(stat
) to High(stat
) - 1 do
661 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
664 stat
[J
] := stat
[J
+ 1];
669 // saves a shitty CSV containing the game stats passed to it
670 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
673 dir
, fname
, map
, mode
, etime
: String;
677 dir
:= e_GetWriteableDir(StatsDirs
);
678 // stats are placed in stats/yy/mm/dd/*.csv
679 fname
:= e_CatPath(dir
, Path
);
680 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
681 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
682 AssignFile(s
, fname
);
684 SetTextCodePage(s
, CP_UTF8
);
686 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
687 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
688 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
689 mode
:= g_Game_ModeToText(Stat
.GameMode
);
690 etime
:= Format('%d:%.2d:%.2d', [
691 Stat
.GameTime
div 1000 div 3600,
692 (Stat
.GameTime
div 1000 div 60) mod 60,
693 Stat
.GameTime
div 1000 mod 60
695 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
696 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
702 gGameSettings
.TimeLimit
,
703 gGameSettings
.ScoreLimit
,
704 gGameSettings
.Options
,
706 Length(Stat
.PlayerStat
)
708 // line 2: game specific shit
709 // if it's a team game: red score, blue score
710 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
712 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
714 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
715 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
717 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
718 // lines 3-...: team, player name, frags, deaths
719 WriteLn(s
, 'team,name,frags,deaths');
720 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
721 with Stat
.PlayerStat
[I
] do
722 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
724 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
727 g_Console_Add('could not create gamestats file "' + fname
+ '"');
732 procedure ClearDebugCvars();
734 g_debug_Sounds
:= False;
735 g_debug_Frames
:= False;
736 g_debug_WinMsgs
:= False;
737 g_debug_MonsterOff
:= False;
738 g_debug_BotAIOff
:= 0;
739 g_debug_HealthBar
:= False;
740 g_Debug_Player
:= False;
743 function g_Game_ModeToText(Mode
: Byte): string;
747 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
748 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
749 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
750 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
751 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
755 function g_Game_TextToMode(Mode
: string): Byte;
758 Mode
:= UpperCase(Mode
);
759 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
764 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
769 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
774 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
779 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
786 function g_Game_IsNet(): Boolean;
788 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
791 function g_Game_IsServer(): Boolean;
793 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
796 function g_Game_IsClient(): Boolean;
798 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
801 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
808 Result
.name
:= ExtractFileName(WAD
);
809 Result
.description
:= '';
812 w
:= TWADFile
.Create();
815 if not w
.GetResource('INTERSCRIPT', p
, len
) then
821 cfg
:= TConfig
.CreateMem(p
, len
);
822 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
823 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
824 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
825 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
831 procedure g_Game_FreeWAD();
835 for a
:= 0 to High(MegaWAD
.res
.pic
) do
836 if MegaWAD
.res
.pic
[a
] <> '' then
837 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
839 for a
:= 0 to High(MegaWAD
.res
.mus
) do
840 if MegaWAD
.res
.mus
[a
] <> '' then
841 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
843 MegaWAD
.res
.pic
:= nil;
844 MegaWAD
.res
.text := nil;
845 MegaWAD
.res
.anim
:= nil;
846 MegaWAD
.res
.mus
:= nil;
847 MegaWAD
.triggers
:= nil;
849 g_Texture_Delete('TEXTURE_endpic');
850 g_Sound_Delete('MUSIC_endmus');
852 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
853 gGameSettings
.WAD
:= '';
856 procedure g_Game_LoadWAD(WAD
: string);
865 gGameSettings
.WAD
:= WAD
;
866 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
869 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
871 w
:= TWADFile
.Create();
874 if not w
.GetResource('INTERSCRIPT', p
, len
) then
880 cfg
:= TConfig
.CreateMem(p
, len
);
885 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
886 if s = '' then Break;
889 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
890 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
892 g_Texture_CreateWADEx(s, s);
898 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
899 if s = '' then Break;
902 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
903 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
905 g_Music_CreateWADEx(s, s);
908 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
909 if MegaWAD
.endpic
<> '' then
911 TEXTUREFILTER
:= GL_LINEAR
;
912 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
913 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
914 TEXTUREFILTER
:= GL_NEAREST
;
916 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
917 if MegaWAD
.endmus
<> '' then
919 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
920 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
928 {procedure start_trigger(t: string);
932 function next_trigger(): Boolean;
936 procedure DisableCheats();
942 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
943 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
944 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
945 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
947 {$IF DEFINED(D2F_DEBUG)}
948 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
949 gAimLine
:= g_dbg_aimline_on
;
953 procedure g_Game_ExecuteEvent(Name
: String);
959 if gEvents
= nil then
961 for a
:= 0 to High(gEvents
) do
962 if gEvents
[a
].Name
= Name
then
964 if gEvents
[a
].Command
<> '' then
965 g_Console_Process(gEvents
[a
].Command
, True);
970 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
975 if gDelayedEvents
<> nil then
976 for a
:= 0 to High(gDelayedEvents
) do
977 if not gDelayedEvents
[a
].Pending
then
984 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
985 n
:= High(gDelayedEvents
);
987 gDelayedEvents
[n
].Pending
:= True;
988 gDelayedEvents
[n
].DEType
:= DEType
;
989 gDelayedEvents
[n
].DENum
:= Num
;
990 gDelayedEvents
[n
].DEStr
:= Str
;
991 if DEType
= DE_GLOBEVENT
then
992 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
994 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1004 if g_Game_IsNet
and g_Game_IsServer
then
1005 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1008 gPauseMain
:= false;
1009 gPauseHolmes
:= false;
1012 g_Game_StopAllSounds(False);
1017 EndingGameCounter
:= 0;
1018 g_ActiveWindow
:= nil;
1020 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1021 gLMSRespawnTime
:= 0;
1024 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1029 begin // Ýòî áûë òåñò
1033 begin // Âûõîä â ãëàâíîå ìåíþ
1034 gMusic
.SetByName('MUSIC_MENU');
1036 if gState
<> STATE_SLIST
then
1038 g_GUI_ShowWindow('MainMenu');
1039 gState
:= STATE_MENU
;
1042 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1043 slReturnPressed
:= True;
1044 if g_Net_Slist_Fetch(slCurrent
) then
1046 if slCurrent
= nil then
1047 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1050 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1051 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1054 g_Game_ExecuteEvent('ongameend');
1058 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1060 if not g_Game_IsClient
then g_Game_Restart();
1063 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1065 // Ñòàòèñòèêà Ñâîåé èãðû:
1066 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1068 CustomStat
.GameTime
:= gTime
;
1069 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1070 CustomStat
.MapName
:= gMapInfo
.Name
;
1071 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1072 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1073 CustomStat
.TeamStat
:= gTeamStat
;
1075 CustomStat
.PlayerStat
:= nil;
1077 // Ñòàòèñòèêà èãðîêîâ:
1078 if gPlayers
<> nil then
1080 for a
:= 0 to High(gPlayers
) do
1081 if gPlayers
[a
] <> nil then
1083 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1084 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1087 Name
:= gPlayers
[a
].Name
;
1088 Frags
:= gPlayers
[a
].Frags
;
1089 Deaths
:= gPlayers
[a
].Death
;
1090 Kills
:= gPlayers
[a
].Kills
;
1091 Team
:= gPlayers
[a
].Team
;
1092 Color
:= gPlayers
[a
].Model
.Color
;
1093 Spectator
:= gPlayers
[a
].FSpectator
;
1097 SortGameStat(CustomStat
.PlayerStat
);
1099 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1102 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1103 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1104 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1105 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1107 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1110 StatShotDone
:= False;
1113 g_Game_ExecuteEvent('onmapend');
1114 if not g_Game_IsClient
then g_Player_ResetReady
;
1115 gInterReadyCount
:= 0;
1117 // Çàòóõàþùèé ýêðàí:
1118 EndingGameCounter
:= 255;
1119 gState
:= STATE_FOLD
;
1121 if gDefInterTime
< 0 then
1122 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1124 gInterEndTime
:= gDefInterTime
* 1000;
1127 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1129 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1130 SingleStat
.GameTime
:= gTime
;
1131 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1132 SingleStat
.TotalSecrets
:= gSecretsCount
;
1133 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1134 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1135 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1136 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1137 if SingleStat
.TwoPlayers
then
1139 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1140 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1143 g_Game_ExecuteEvent('onmapend');
1146 if gNextMap
<> '' then
1148 gMusic
.SetByName('MUSIC_INTERMUS');
1150 gState
:= STATE_INTERSINGLE
;
1153 g_Game_ExecuteEvent('oninter');
1155 else // Áîëüøå íåò êàðò
1157 // Çàòóõàþùèé ýêðàí:
1158 EndingGameCounter
:= 255;
1159 gState
:= STATE_FOLD
;
1164 // Îêîí÷àíèå îáðàáîòàíî:
1165 if gExit
<> EXIT_QUIT
then
1169 procedure drawTime(X
, Y
: Integer); inline;
1171 e_TextureFontPrint(x
, y
,
1172 Format('%d:%.2d:%.2d', [
1173 gTime
div 1000 div 3600,
1174 (gTime
div 1000 div 60) mod 60,
1175 gTime
div 1000 mod 60
1180 procedure DrawStat();
1182 pc
, x
, y
, w
, h
: Integer;
1183 w1
, w2
, w3
, w4
: Integer;
1185 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1188 stat
: TPlayerStatArray
;
1196 pc
:= g_Player_GetCount
;
1197 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1199 w
:= gScreenWidth
-(gScreenWidth
div 5);
1200 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1203 h
:= 40+ch
*5+(ch
+8)*pc
;
1204 x
:= (gScreenWidth
div 2)-(w
div 2);
1205 y
:= (gScreenHeight
div 2)-(h
div 2);
1207 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1208 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1210 drawTime(x
+w
-78, y
+8);
1212 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1213 map
:= g_ExtractFileName(gMapInfo
.Map
);
1214 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1216 case gGameSettings
.GameMode
of
1219 if gGameSettings
.MaxLives
= 0 then
1220 s1
:= _lc
[I_GAME_DM
]
1222 s1
:= _lc
[I_GAME_LMS
];
1223 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.ScoreLimit
]);
1224 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1229 if gGameSettings
.MaxLives
= 0 then
1230 s1
:= _lc
[I_GAME_TDM
]
1232 s1
:= _lc
[I_GAME_TLMS
];
1233 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.ScoreLimit
]);
1234 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1239 s1
:= _lc
[I_GAME_CTF
];
1240 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.ScoreLimit
]);
1241 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1246 if gGameSettings
.MaxLives
= 0 then
1247 s1
:= _lc
[I_GAME_COOP
]
1249 s1
:= _lc
[I_GAME_SURV
];
1250 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1251 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1262 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1264 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1266 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1268 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1269 gStdFont
, 200, 200, 200, 1);
1271 if NetMode
= NET_SERVER
then
1272 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1274 if NetMode
= NET_CLIENT
then
1275 e_TextureFontPrintEx(x
+8, y
+ 8,
1276 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1280 stat
:= g_Player_GetStats();
1283 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1284 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1286 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1288 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1292 for a
:= TEAM_RED
to TEAM_BLUE
do
1294 if a
= TEAM_RED
then
1296 s1
:= _lc
[I_GAME_TEAM_RED
];
1303 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1309 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1310 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Score
),
1311 gStdFont
, r
, g
, b
, 1);
1313 _y
:= _y
+ch
+(ch
div 4);
1314 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1315 _y
:= _y
+(ch
div 4);
1317 for aa
:= 0 to High(stat
) do
1318 if stat
[aa
].Team
= a
then
1334 namestr
:= Format('[%5d] %s', [UID
, Name
])
1338 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1340 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1342 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1344 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1351 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1354 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1355 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1356 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1357 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1360 for aa
:= 0 to High(stat
) do
1374 namestr
:= Format('[%5d] %s', [UID
, Name
])
1378 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1379 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1381 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1383 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1385 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1387 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1393 procedure g_Game_Init();
1396 knownFiles
: array of AnsiString = nil;
1398 wext
, s
: AnsiString;
1403 gTempDelete
:= False;
1405 sfsGCDisable(); // temporary disable removing of temporary volumes
1408 TEXTUREFILTER
:= GL_LINEAR
;
1409 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1410 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1411 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1412 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1413 TEXTUREFILTER
:= GL_NEAREST
;
1415 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1416 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1417 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1419 g_Game_ClearLoading();
1420 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1421 g_Game_SetLoadingText('', 0, False);
1423 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1426 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1427 g_PlayerModel_LoadData();
1429 // load models from all possible wad types, in all known directories
1430 // this does a loosy job (linear search, ooph!), but meh
1431 for wext
in wadExtensions
do
1433 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1435 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1439 for s
in knownFiles
do
1441 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1449 SetLength(knownFiles
, length(knownFiles
)+1);
1450 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1452 until (FindNext(SR
) <> 0);
1458 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1460 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
);
1461 for s
in knownFiles
do
1463 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1467 gPauseMain
:= false;
1468 gPauseHolmes
:= false;
1471 {e_MouseInfo.Accel := 1.0;}
1473 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1476 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1477 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1478 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1479 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1480 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1483 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1487 gMusic
:= TMusic
.Create();
1488 gMusic
.SetByName('MUSIC_MENU');
1491 gGameSettings
.WarmupTime
:= 30;
1493 gState
:= STATE_MENU
;
1495 SetLength(gEvents
, 6);
1496 gEvents
[0].Name
:= 'ongamestart';
1497 gEvents
[1].Name
:= 'ongameend';
1498 gEvents
[2].Name
:= 'onmapstart';
1499 gEvents
[3].Name
:= 'onmapend';
1500 gEvents
[4].Name
:= 'oninter';
1501 gEvents
[5].Name
:= 'onwadend';
1503 sfsGCEnable(); // enable releasing unused volumes
1507 procedure g_Game_Free(freeTextures
: Boolean=true);
1509 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1510 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1512 g_Map_Free(freeTextures
);
1514 g_Player_RemoveAllCorpses();
1516 gGameSettings
.GameType
:= GT_NONE
;
1517 if gGameSettings
.GameMode
= GM_SINGLE
then
1518 gGameSettings
.GameMode
:= GM_DM
;
1519 gSwitchGameMode
:= gGameSettings
.GameMode
;
1522 gExitByTrigger
:= False;
1525 function IsActivePlayer(p
: TPlayer
): Boolean;
1530 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1533 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1540 if gPlayers
= nil then
1542 for a
:= Low(gPlayers
) to High(gPlayers
) do
1543 if IsActivePlayer(gPlayers
[a
]) then
1545 if gPlayers
[a
].UID
<> ID
then
1547 Result
:= gPlayers
[a
];
1552 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1558 if gPlayers
= nil then
1562 for a
:= Low(gPlayers
) to High(gPlayers
) do
1563 if IsActivePlayer(gPlayers
[a
]) then
1565 SetLength(ids
, Length(ids
) + 1);
1566 ids
[High(ids
)] := gPlayers
[a
].UID
;
1567 if gPlayers
[a
].UID
= Skip
then
1570 if Length(ids
) = 0 then
1575 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1578 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1584 if gPlayers
= nil then
1588 for a
:= Low(gPlayers
) to High(gPlayers
) do
1589 if IsActivePlayer(gPlayers
[a
]) then
1591 SetLength(ids
, Length(ids
) + 1);
1592 ids
[High(ids
)] := gPlayers
[a
].UID
;
1593 if gPlayers
[a
].UID
= Skip
then
1596 if Length(ids
) = 0 then
1599 Result
:= ids
[Length(ids
) - 1]
1601 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1604 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1610 if gPlayers
= nil then
1614 for a
:= Low(gPlayers
) to High(gPlayers
) do
1615 if IsActivePlayer(gPlayers
[a
]) then
1617 SetLength(ids
, Length(ids
) + 1);
1618 ids
[High(ids
)] := gPlayers
[a
].UID
;
1619 if gPlayers
[a
].UID
= Skip
then
1622 if Length(ids
) = 0 then
1624 if Length(ids
) = 1 then
1629 Result
:= ids
[Random(Length(ids
))];
1631 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1633 Result
:= ids
[Random(Length(ids
))];
1638 function GetRandomSpectMode(Current
: Byte): Byte;
1645 0: Result
:= SPECT_STATS
;
1646 1: Result
:= SPECT_MAPVIEW
;
1647 2: Result
:= SPECT_MAPVIEW
;
1648 3: Result
:= SPECT_PLAYERS
;
1649 4: Result
:= SPECT_PLAYERS
;
1650 5: Result
:= SPECT_PLAYERS
;
1651 6: Result
:= SPECT_PLAYERS
;
1653 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1657 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1663 if (plr
= nil) then exit
;
1664 if (p
= 2) then time
:= 1000 else time
:= 1;
1665 strafeDir
:= MoveButton
shr 4;
1666 MoveButton
:= MoveButton
and $0F;
1668 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1669 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1670 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1671 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1672 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1673 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1675 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1676 if MoveButton
= 1 then
1677 plr
.PressKey(KEY_LEFT
, time
)
1678 else if MoveButton
= 2 then
1679 plr
.PressKey(KEY_RIGHT
, time
);
1681 // if we have "strafe" key, turn off old strafe mechanics
1682 if gPlayerAction
[p
, ACTION_STRAFE
] then
1684 // new strafe mechanics
1685 if (strafeDir
= 0) then
1686 strafeDir
:= MoveButton
; // start strafing
1687 // now set direction according to strafe (reversed)
1688 if (strafeDir
= 2) then
1689 plr
.SetDirection(TDirection
.D_LEFT
)
1690 else if (strafeDir
= 1) then
1691 plr
.SetDirection(TDirection
.D_RIGHT
)
1695 strafeDir
:= 0; // not strafing anymore
1696 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1697 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1698 plr
.SetDirection(TDirection
.D_LEFT
)
1699 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1700 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1701 plr
.SetDirection(TDirection
.D_RIGHT
)
1702 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1703 else if MoveButton
<> 0 then
1704 plr
.SetDirection(TDirection(MoveButton
-1))
1707 // fix movebutton state
1708 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1710 // Îñòàëüíûå êëàâèøè:
1711 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1712 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1713 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1714 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1715 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1717 for i
:= WP_FACT
to WP_LACT
do
1719 if gWeaponAction
[p
, i
] then
1721 plr
.ProcessWeaponAction(i
);
1722 gWeaponAction
[p
, i
] := False
1726 for i
:= WP_FIRST
to WP_LAST
do
1728 if gSelectWeapon
[p
, i
] then
1730 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1731 gSelectWeapon
[p
, i
] := False
1735 // HACK: add dynlight here
1736 if gwin_k8_enable_light_experiments
then
1738 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1740 g_playerLight
:= true;
1742 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1744 g_playerLight
:= false;
1748 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1751 // HACK: don't have a "key was pressed" function
1752 procedure InterReady();
1754 if InterReadyTime
> gTime
then Exit
;
1755 InterReadyTime
:= gTime
+ 3000;
1756 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1759 procedure g_Game_PreUpdate();
1761 // these are in separate PreUpdate functions because they can interact during Update()
1762 // and are synced over the net
1763 // we don't care that much about corpses and gibs
1764 g_Player_PreUpdate();
1765 g_Monsters_PreUpdate();
1766 g_Items_PreUpdate();
1767 g_Weapon_PreUpdate();
1770 procedure g_Game_Update();
1772 Msg
: g_gui
.TMessage
;
1778 function sendMonsPos (mon
: TMonster
): Boolean;
1780 result
:= false; // don't stop
1781 // this will also reset "need-send" flag
1782 if mon
.gncNeedSend
then
1784 MH_SEND_MonsterPos(mon
.UID
);
1786 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1788 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1790 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1792 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1796 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1798 result
:= false; // don't stop
1799 // this will also reset "need-send" flag
1800 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1803 function sendItemPos (it
: PItem
): Boolean;
1805 result
:= false; // don't stop
1808 MH_SEND_ItemPos(it
.myId
);
1809 it
.needSend
:= False;
1814 reliableUpdate
: Boolean;
1819 // Ïîðà âûêëþ÷àòü èãðó:
1820 if gExit
= EXIT_QUIT
then
1822 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1826 if gExit
= EXIT_QUIT
then
1830 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1831 // no need to, as we'll do it in event handler
1833 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1836 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1838 gExit
:= EXIT_SIMPLE
;
1843 // process master server communications
1844 g_Net_Slist_Pulse();
1847 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1848 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1849 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1850 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1852 if g_Game_IsNet
and g_Game_IsServer
then
1854 gInterTime
:= gInterTime
+ GAME_TICK
;
1855 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1856 if a
<> gServInterTime
then
1858 gServInterTime
:= a
;
1859 MH_SEND_TimeSync(gServInterTime
);
1863 if (not g_Game_IsClient
) and
1867 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1868 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1869 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1870 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1872 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1873 and (g_ActiveWindow
= nil)
1875 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1878 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1879 g_Game_StopAllSounds(True);
1881 if gMapOnce
then // Ýòî áûë òåñò
1882 gExit
:= EXIT_SIMPLE
1884 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1885 g_Game_ChangeMap(gNextMap
)
1886 else // Ñëåäóþùåé êàðòû íåò
1888 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1890 // Âûõîä â ãëàâíîå ìåíþ:
1892 g_GUI_ShowWindow('MainMenu');
1893 gMusic
.SetByName('MUSIC_MENU');
1895 gState
:= STATE_MENU
;
1898 // Ôèíàëüíàÿ êàðòèíêà:
1899 g_Game_ExecuteEvent('onwadend');
1901 if not gMusic
.SetByName('MUSIC_endmus') then
1902 gMusic
.SetByName('MUSIC_STDENDMUS');
1904 gState
:= STATE_ENDPIC
;
1906 g_Game_ExecuteEvent('ongameend');
1911 else if g_Game_IsClient
and
1914 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1915 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1916 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1917 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1919 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1920 and (g_ActiveWindow
= nil)
1928 if gState
= STATE_INTERTEXT
then
1929 if InterText
.counter
> 0 then
1930 InterText
.counter
:= InterText
.counter
- 1;
1933 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1935 if EndingGameCounter
= 0 then
1937 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1938 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1940 gState
:= STATE_INTERCUSTOM
;
1941 InterReadyTime
:= -1;
1942 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1944 g_Game_ExecuteEvent('onwadend');
1945 if not gMusic
.SetByName('MUSIC_endmus') then
1946 gMusic
.SetByName('MUSIC_STDENDMUS');
1949 gMusic
.SetByName('MUSIC_ROUNDMUS');
1953 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1955 gMusic
.SetByName('MUSIC_INTERMUS');
1957 gState
:= STATE_INTERSINGLE
;
1960 g_Game_ExecuteEvent('oninter');
1963 DecMin(EndingGameCounter
, 6, 0);
1966 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1968 if gMapOnce
then // Ýòî áûë òåñò
1970 gExit
:= EXIT_SIMPLE
;
1976 g_Serverlist_Control(slCurrent
, slTable
);
1979 // Ñòàòèñòèêà ïî Tab:
1981 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1984 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1986 // Âðåìÿ += 28 ìèëëèñåêóíä:
1987 gTime
:= gTime
+ GAME_TICK
;
1989 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1990 if MessageTime
= 0 then
1992 if MessageTime
> 0 then
1993 MessageTime
:= MessageTime
- 1;
1995 if (g_Game_IsServer
) then
1997 // Áûë çàäàí ëèìèò âðåìåíè:
1998 if (gGameSettings
.TimeLimit
> 0) then
1999 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2000 begin // Îí ïðîøåë => êîíåö óðîâíÿ
2005 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
2006 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2007 g_Game_RestartRound(gLMSSoftSpawn
);
2009 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
2010 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2012 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2014 g_Console_Process(gVoteCommand
);
2016 gVotePassed
:= False;
2019 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2020 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2021 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2022 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2023 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2025 // Áûë çàäàí ëèìèò ïîáåä:
2026 if (gGameSettings
.ScoreLimit
> 0) then
2030 if gGameSettings
.GameMode
= GM_DM
then
2031 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2032 for i
:= 0 to High(gPlayers
) do
2033 if gPlayers
[i
] <> nil then
2034 if gPlayers
[i
].Frags
> b
then
2035 b
:= gPlayers
[i
].Frags
;
2038 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2039 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2040 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2043 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2044 if b
>= gGameSettings
.ScoreLimit
then
2051 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2052 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2053 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2054 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2056 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2057 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2058 end // if not console
2061 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2063 // process weapon switch queue
2067 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2068 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2070 if not gSpectKeyPress
then
2072 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2074 // switch spect mode
2076 SPECT_NONE
: ; // not spectator
2078 SPECT_MAPVIEW
: Inc(gSpectMode
);
2079 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2081 gSpectKeyPress
:= True;
2083 if (gSpectMode
= SPECT_MAPVIEW
)
2084 and (not gSpectAuto
) then
2086 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2087 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2088 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2089 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2090 if gPlayerAction
[0, ACTION_LOOKUP
] then
2091 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2092 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2093 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2094 if gWeaponAction
[0, WP_PREV
] then
2097 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2098 gWeaponAction
[0, WP_PREV
] := False;
2100 if gWeaponAction
[0, WP_NEXT
] then
2103 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2104 gWeaponAction
[0, WP_NEXT
] := False;
2107 if (gSpectMode
= SPECT_PLAYERS
)
2108 and (not gSpectAuto
) then
2110 if gPlayerAction
[0, ACTION_LOOKUP
] then
2113 gSpectViewTwo
:= True;
2114 gSpectKeyPress
:= True;
2116 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2118 // remove second view
2119 gSpectViewTwo
:= False;
2120 gSpectKeyPress
:= True;
2122 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2124 // prev player (view 1)
2125 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2126 gSpectKeyPress
:= True;
2128 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2130 // next player (view 1)
2131 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2132 gSpectKeyPress
:= True;
2134 if gWeaponAction
[0, WP_PREV
] then
2136 // prev player (view 2)
2137 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2138 gWeaponAction
[0, WP_PREV
] := False;
2140 if gWeaponAction
[0, WP_NEXT
] then
2142 // next player (view 2)
2143 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2144 gWeaponAction
[0, WP_NEXT
] := False;
2147 if gPlayerAction
[0, ACTION_ATTACK
] then
2149 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2152 gSpectAutoNext
:= 0;
2153 gSpectViewTwo
:= False;
2154 gSpectKeyPress
:= True;
2159 gSpectMode
:= SPECT_STATS
;
2160 gSpectAuto
:= False;
2161 gSpectKeyPress
:= True;
2166 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2167 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2168 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2169 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2170 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2171 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2172 gSpectKeyPress
:= False;
2176 if gSpectMode
= SPECT_MAPVIEW
then
2178 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2180 gSpectAutoNext
:= gTime
2183 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2185 gSpectAutoNext
:= gTime
2189 if gSpectAutoNext
<= gTime
then
2191 if gSpectAutoNext
> 0 then
2193 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2197 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2198 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2199 gSpectAutoStepX
:= Random(9) - 4;
2200 gSpectAutoStepY
:= Random(9) - 4;
2201 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2202 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2203 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2204 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2205 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2206 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2210 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2215 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2216 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2217 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2223 // Îáíîâëÿåì âñå îñòàëüíîå:
2226 g_Triggers_Update();
2228 g_Monsters_Update();
2230 g_Player_UpdateAll();
2231 g_Player_UpdatePhysicalObjects();
2233 // server: send newly spawned monsters unconditionally
2234 if (gGameSettings
.GameType
= GT_SERVER
) then
2236 if (Length(gMonstersSpawned
) > 0) then
2238 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2239 SetLength(gMonstersSpawned
, 0);
2243 if (gSoundTriggerTime
> 8) then
2245 g_Game_UpdateTriggerSounds();
2246 gSoundTriggerTime
:= 0;
2250 Inc(gSoundTriggerTime
);
2253 if (NetMode
= NET_SERVER
) then
2255 Inc(NetTimeToUpdate
);
2256 Inc(NetTimeToReliable
);
2258 // send monster updates
2259 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2261 // send all monsters (periodic sync)
2262 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2264 for I
:= 0 to High(gPlayers
) do
2266 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2269 g_Mons_ForEach(sendMonsPos
);
2271 // update flags that aren't stationary
2272 if gGameSettings
.GameMode
= GM_CTF
then
2273 for I
:= FLAG_RED
to FLAG_BLUE
do
2274 if gFlags
[I
].NeedSend
then
2276 gFlags
[I
].NeedSend
:= False;
2280 // update items that aren't stationary
2281 g_Items_ForEachAlive(sendItemPos
);
2283 if reliableUpdate
then
2285 NetTimeToReliable
:= 0;
2286 NetTimeToUpdate
:= NetUpdateRate
;
2290 NetTimeToUpdate
:= 0;
2295 // send only mosters with some unexpected changes
2296 g_Mons_ForEach(sendMonsPosUnexpected
);
2299 // send unexpected platform changes
2300 g_Map_NetSendInterestingPanels();
2302 g_Net_Slist_ServerUpdate();
2304 if NetUseMaster then
2306 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2308 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2310 NetTimeToMaster := gTime + NetMasterRate;
2315 else if (NetMode
= NET_CLIENT
) then
2317 MC_SEND_PlayerPos();
2319 end; // if gameOn ...
2321 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2322 if g_ActiveWindow
<> nil then
2324 w
:= e_GetFirstKeyPressed();
2326 if (w
<> IK_INVALID
) then
2328 Msg
.Msg
:= MESSAGE_DIKEY
;
2330 g_ActiveWindow
.OnMessage(Msg
);
2333 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2334 if g_ActiveWindow
<> nil then
2335 g_ActiveWindow
.Update();
2337 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2338 if gResolutionChange
then
2340 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2341 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2342 gResolutionChange
:= False;
2343 g_ActiveWindow
:= nil;
2346 // Íóæíî ñìåíèòü ÿçûê:
2347 if gLanguageChange
then
2349 //e_WriteLog('Read language file', MSG_NOTIFY);
2350 //g_Language_Load(DataDir + gLanguage + '.txt');
2351 g_Language_Set(gLanguage
);
2355 gLanguageChange
:= False;
2359 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2360 if e_KeyPressed(IK_F10
) and
2362 (not gConsoleShow
) and
2363 (g_ActiveWindow
= nil) then
2368 Time
:= sys_GetTicks() {div 1000};
2370 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2371 if gDelayedEvents
<> nil then
2372 for a
:= 0 to High(gDelayedEvents
) do
2373 if gDelayedEvents
[a
].Pending
and
2375 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2376 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2379 case gDelayedEvents
[a
].DEType
of
2381 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2384 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2388 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2389 if g_Game_IsNet
and g_Game_IsServer
then
2390 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2394 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2396 gDelayedEvents
[a
].Pending
:= False;
2399 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2400 UPSCounter
:= UPSCounter
+ 1;
2401 if Time
- UPSTime
>= 1000 then
2410 g_Weapon_AddDynLights();
2411 g_Items_AddDynLights();
2415 procedure g_Game_LoadChatSounds(Resource
: string);
2418 FileName
, Snd
: string;
2420 len
, cnt
, tags
, i
, j
: Integer;
2423 FileName
:= g_ExtractWadName(Resource
);
2425 WAD
:= TWADFile
.Create();
2426 WAD
.ReadFile(FileName
);
2428 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2435 cfg
:= TConfig
.CreateMem(p
, len
);
2436 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2438 SetLength(gChatSounds
, cnt
);
2439 for i
:= 0 to Length(gChatSounds
) - 1 do
2441 gChatSounds
[i
].Sound
:= nil;
2442 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2443 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2444 if (Snd
= '') or (Tags
<= 0) then
2446 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2447 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2448 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2449 SetLength(gChatSounds
[i
].Tags
, tags
);
2450 for j
:= 0 to tags
- 1 do
2451 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2452 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2459 procedure g_Game_FreeChatSounds();
2463 for i
:= 0 to Length(gChatSounds
) - 1 do
2465 gChatSounds
[i
].Sound
.Free();
2466 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2468 SetLength(gChatSounds
, 0);
2472 procedure g_Game_LoadData();
2479 if DataLoaded
then Exit
;
2481 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2483 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2484 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2485 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2486 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2487 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2488 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2489 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2494 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2495 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2496 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2497 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2500 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2501 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2502 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2503 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2507 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2508 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2509 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2510 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2511 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
2517 hasPBarGfx
:= false;
2521 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2522 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2523 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2524 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2525 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2526 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2527 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2528 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2529 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2530 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2531 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2532 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2533 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2534 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2535 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2536 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2537 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2538 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2539 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2540 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2541 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2542 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2543 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2544 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2545 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2546 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2547 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2548 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2549 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2550 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2551 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2552 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2553 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2554 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2555 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2556 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2557 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2558 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2559 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2561 goodsnd
[0] := TPlayableSound
.Create();
2562 goodsnd
[1] := TPlayableSound
.Create();
2563 goodsnd
[2] := TPlayableSound
.Create();
2564 goodsnd
[3] := TPlayableSound
.Create();
2566 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2567 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2568 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2569 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2571 killsnd
[0] := TPlayableSound
.Create();
2572 killsnd
[1] := TPlayableSound
.Create();
2573 killsnd
[2] := TPlayableSound
.Create();
2574 killsnd
[3] := TPlayableSound
.Create();
2576 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2577 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2578 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2579 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2581 hahasnd
[0] := TPlayableSound
.Create();
2582 hahasnd
[1] := TPlayableSound
.Create();
2583 hahasnd
[2] := TPlayableSound
.Create();
2585 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2586 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2587 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2589 sound_get_flag
[0] := TPlayableSound
.Create();
2590 sound_get_flag
[1] := TPlayableSound
.Create();
2591 sound_lost_flag
[0] := TPlayableSound
.Create();
2592 sound_lost_flag
[1] := TPlayableSound
.Create();
2593 sound_ret_flag
[0] := TPlayableSound
.Create();
2594 sound_ret_flag
[1] := TPlayableSound
.Create();
2595 sound_cap_flag
[0] := TPlayableSound
.Create();
2596 sound_cap_flag
[1] := TPlayableSound
.Create();
2598 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2599 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2600 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2601 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2602 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2603 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2604 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2605 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2607 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2609 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2612 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2613 g_Weapon_LoadData();
2615 g_Monsters_LoadData();
2620 procedure g_Game_FreeData();
2622 if not DataLoaded
then Exit
;
2625 g_Weapon_FreeData();
2626 g_Monsters_FreeData();
2628 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2630 g_Texture_Delete('NOTEXTURE');
2631 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2632 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2633 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2634 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2635 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2636 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2637 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2638 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2639 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2640 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2641 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2642 g_Frames_DeleteByName('FRAMES_TELEPORT');
2643 g_Frames_DeleteByName('FRAMES_PUNCH');
2644 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2645 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2646 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2647 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2648 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2649 g_Sound_Delete('SOUND_GAME_TELEPORT');
2650 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2651 g_Sound_Delete('SOUND_GAME_SECRET');
2652 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2653 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2654 g_Sound_Delete('SOUND_GAME_BULK1');
2655 g_Sound_Delete('SOUND_GAME_BULK2');
2656 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2657 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2658 g_Sound_Delete('SOUND_GAME_BURNING');
2659 g_Sound_Delete('SOUND_GAME_SWITCH1');
2660 g_Sound_Delete('SOUND_GAME_SWITCH0');
2667 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2668 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2669 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2670 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2677 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2678 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2679 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2680 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2686 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2687 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2688 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2690 sound_get_flag
[0].Free();
2691 sound_get_flag
[1].Free();
2692 sound_lost_flag
[0].Free();
2693 sound_lost_flag
[1].Free();
2694 sound_ret_flag
[0].Free();
2695 sound_ret_flag
[1].Free();
2696 sound_cap_flag
[0].Free();
2697 sound_cap_flag
[1].Free();
2699 g_Sound_Delete('SOUND_CTF_GET1');
2700 g_Sound_Delete('SOUND_CTF_GET2');
2701 g_Sound_Delete('SOUND_CTF_LOST1');
2702 g_Sound_Delete('SOUND_CTF_LOST2');
2703 g_Sound_Delete('SOUND_CTF_RETURN1');
2704 g_Sound_Delete('SOUND_CTF_RETURN2');
2705 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2706 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2708 g_Game_FreeChatSounds();
2710 DataLoaded
:= False;
2713 procedure DrawCustomStat();
2719 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2720 s1
, s2
, topstr
: String;
2722 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2726 if g_Console_Action(ACTION_SCORES
) then
2728 if not gStatsPressed
then
2730 gStatsOff
:= not gStatsOff
;
2731 gStatsPressed
:= True;
2735 gStatsPressed
:= False;
2739 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2740 w
:= (Length(s1
) * ww2
) div 2;
2741 x
:= gScreenWidth
div 2 - w
;
2743 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2747 if (gGameSettings
.GameMode
= GM_COOP
) then
2749 if gMissionFailed
then
2750 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2752 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2755 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2757 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2758 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2760 if g_Game_IsNet
then
2762 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2763 if not gChatShow
then
2764 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2765 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2768 if g_Game_IsClient
then
2769 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2771 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2772 if not gChatShow
then
2773 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2774 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2779 w
:= gScreenWidth
-x
*2;
2785 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2786 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2788 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2790 case CustomStat
.GameMode
of
2793 if gGameSettings
.MaxLives
= 0 then
2794 s1
:= _lc
[I_GAME_DM
]
2796 s1
:= _lc
[I_GAME_LMS
];
2800 if gGameSettings
.MaxLives
= 0 then
2801 s1
:= _lc
[I_GAME_TDM
]
2803 s1
:= _lc
[I_GAME_TLMS
];
2805 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2808 if gGameSettings
.MaxLives
= 0 then
2809 s1
:= _lc
[I_GAME_COOP
]
2811 s1
:= _lc
[I_GAME_SURV
];
2817 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2821 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2822 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2825 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2826 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2827 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2828 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2830 pc
:= Length(CustomStat
.PlayerStat
);
2831 if pc
= 0 then Exit
;
2833 if CustomStat
.GameMode
= GM_COOP
then
2835 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2837 s2
:= _lc
[I_GAME_MONSTERS
];
2838 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2839 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2841 s2
:= _lc
[I_GAME_SECRETS
];
2842 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2843 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2846 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2848 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2849 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2850 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2852 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2853 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2854 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2858 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2863 if TeamStat
[TEAM_RED
].Score
> TeamStat
[TEAM_BLUE
].Score
then s1
:= _lc
[I_GAME_WIN_RED
]
2864 else if TeamStat
[TEAM_BLUE
].Score
> TeamStat
[TEAM_RED
].Score
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2865 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2867 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2870 for t
:= TEAM_RED
to TEAM_BLUE
do
2872 if t
= TEAM_RED
then
2874 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2875 gStdFont
, 255, 0, 0, 1);
2876 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Score
),
2877 gStdFont
, 255, 0, 0, 1);
2884 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2885 gStdFont
, 0, 0, 255, 1);
2886 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Score
),
2887 gStdFont
, 0, 0, 255, 1);
2893 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2896 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2897 if CustomStat
.PlayerStat
[p
].Team
= t
then
2898 with CustomStat
.PlayerStat
[p
] do
2912 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2913 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2915 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2916 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2917 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2924 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2927 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2928 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2929 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2932 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2933 with CustomStat
.PlayerStat
[p
] do
2935 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2942 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2943 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2945 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2946 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2947 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2952 // HACK: take stats screenshot immediately after the first frame of the stats showing
2953 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2955 g_TakeScreenShot('stats/' + StatFilename
);
2956 StatShotDone
:= True;
2960 procedure DrawSingleStat();
2962 tm
, key_x
, val_x
, y
: Integer;
2966 procedure player_stat(n
: Integer);
2972 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2973 s2
:= Format(' %d', [gTotalMonsters
]);
2975 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2976 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2977 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2978 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2980 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2981 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2983 // "Kills-per-minute: ##.#":
2984 s1
:= _lc
[I_MENU_INTER_KPM
];
2986 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2988 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2989 s2
:= Format(' %.1f', [kpm
]);
2991 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2992 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2994 // "Secrets found: # / #":
2995 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2996 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2998 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2999 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
3000 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3001 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
3003 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3004 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
3008 // "Level Complete":
3009 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
3010 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
3012 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3013 s1
:= _lc
[I_MENU_INTER_KPM
];
3014 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3017 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
3019 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
3020 val_x
:= key_x
+ w1
;
3023 tm
:= SingleStat
.GameTime
div 1000;
3024 s1
:= _lc
[I_MENU_INTER_TIME
];
3025 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
3027 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
3028 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
3030 if SingleStat
.TwoPlayers
then
3033 s1
:= _lc
[I_MENU_PLAYER_1
];
3034 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3035 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
3037 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3042 s1
:= _lc
[I_MENU_PLAYER_2
];
3043 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3044 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3046 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3052 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3058 procedure DrawLoadingStat();
3059 procedure drawRect (x
, y
, w
, h
: Integer);
3061 if (w
< 1) or (h
< 1) then exit
;
3063 glVertex2f(x
+0.375, y
+0.375);
3064 glVertex2f(x
+w
+0.375, y
+0.375);
3065 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3066 glVertex2f(x
+0.375, y
+h
+0.375);
3070 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3072 rectW
, rectH
: Integer;
3079 idl
, idr
, idb
, idm
: LongWord;
3083 if (total
< 1) then exit
;
3084 if (cur
< 1) then exit
; // don't blink
3085 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3086 //if (cur < 0) then cur := 0;
3087 //if (cur > total) then cur := total;
3090 if (hasPBarGfx
) then
3092 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3093 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3094 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3095 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3096 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3097 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3098 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3099 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3101 //rectW := gScreenWidth-360;
3102 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3105 x0
:= (gScreenWidth
-rectW
) div 2;
3106 y0
:= gScreenHeight
-rectH
-64;
3107 if (y0
< 2) then y0
:= 2;
3109 glEnable(GL_SCISSOR_TEST
);
3112 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3113 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3114 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3117 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3119 while (f
< x0
+rectW
) do
3121 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3126 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3127 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3130 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3131 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3135 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3141 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3145 rectW
:= gScreenWidth
-64;
3148 x0
:= (gScreenWidth
-rectW
) div 2;
3149 y0
:= gScreenHeight
-rectH
-64;
3150 if (y0
< 2) then y0
:= 2;
3152 glDisable(GL_BLEND
);
3153 glDisable(GL_TEXTURE_2D
);
3155 //glClearColor(0, 0, 0, 0);
3156 //glClear(GL_COLOR_BUFFER_BIT);
3158 glColor4ub(127, 127, 127, 255);
3159 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3161 glColor4ub(0, 0, 0, 255);
3162 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3164 glColor4ub(127, 127, 127, 255);
3165 wdt
:= rectW
*cur
div total
;
3166 if (wdt
> rectW
) then wdt
:= rectW
;
3167 drawRect(x0
, y0
, wdt
, rectH
);
3176 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3178 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3179 yy
:= (gScreenHeight
div 3);
3180 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3181 xx
:= (gScreenWidth
div 3);
3185 for i
:= 0 to NextMsg
-1 do
3187 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3188 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3192 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3193 yy
:= yy
+ LOADING_INTERLINE
;
3194 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3199 procedure DrawMenuBackground(tex
: AnsiString);
3205 if g_Texture_Get(tex
, ID
) then
3207 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3208 e_GetTextureSize(ID
, @w
, @h
);
3210 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3212 w
:= trunc(w
* (gScreenHeight
/ h
));
3213 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3215 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3218 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3220 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3222 function monDraw (mon
: TMonster
): Boolean;
3224 result
:= false; // don't stop
3229 // Ëåâûé âåðõíèé óãîë
3230 aX
:= Obj
.X
div ScaleSz
+ 1;
3231 aY
:= Obj
.Y
div ScaleSz
+ 1;
3233 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3234 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3235 // Ïðàâûé íèæíèé óãîë
3236 aX2
:= aX
+ aX2
- 1;
3237 aY2
:= aY
+ aY2
- 1;
3238 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3244 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3245 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3248 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3249 ScaleSz
:= 16 div Scale
;
3250 // Ðàçìåðû ìèíè-êàðòû:
3251 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3252 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3254 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3256 if gWalls
<> nil then
3259 for a
:= 0 to High(gWalls
) do
3261 if PanelType
<> 0 then
3263 // Ëåâûé âåðõíèé óãîë:
3264 aX
:= X
div ScaleSz
;
3265 aY
:= Y
div ScaleSz
;
3267 aX2
:= max(Width
div ScaleSz
, 1);
3268 aY2
:= max(Height
div ScaleSz
, 1);
3269 // Ïðàâûé íèæíèé óãîë:
3270 aX2
:= aX
+ aX2
- 1;
3271 aY2
:= aY
+ aY2
- 1;
3274 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3275 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3276 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3280 if gSteps
<> nil then
3283 for a
:= 0 to High(gSteps
) 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
, 128, 128, 128, 0);
3300 if gLifts
<> nil then
3303 for a
:= 0 to High(gLifts
) 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;
3318 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3319 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3320 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3321 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3325 if gWater
<> nil then
3328 for a
:= 0 to High(gWater
) do
3330 if PanelType
<> 0 then
3332 // Ëåâûé âåðõíèé óãîë:
3333 aX
:= X
div ScaleSz
;
3334 aY
:= Y
div ScaleSz
;
3336 aX2
:= max(Width
div ScaleSz
, 1);
3337 aY2
:= max(Height
div ScaleSz
, 1);
3338 // Ïðàâûé íèæíèé óãîë:
3339 aX2
:= aX
+ aX2
- 1;
3340 aY2
:= aY
+ aY2
- 1;
3342 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3345 if gAcid1
<> nil then
3347 // Ðèñóåì êèñëîòó 1:
3348 for a
:= 0 to High(gAcid1
) do
3350 if PanelType
<> 0 then
3352 // Ëåâûé âåðõíèé óãîë:
3353 aX
:= X
div ScaleSz
;
3354 aY
:= Y
div ScaleSz
;
3356 aX2
:= max(Width
div ScaleSz
, 1);
3357 aY2
:= max(Height
div ScaleSz
, 1);
3358 // Ïðàâûé íèæíèé óãîë:
3359 aX2
:= aX
+ aX2
- 1;
3360 aY2
:= aY
+ aY2
- 1;
3362 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3365 if gAcid2
<> nil then
3367 // Ðèñóåì êèñëîòó 2:
3368 for a
:= 0 to High(gAcid2
) do
3370 if PanelType
<> 0 then
3372 // Ëåâûé âåðõíèé óãîë:
3373 aX
:= X
div ScaleSz
;
3374 aY
:= Y
div ScaleSz
;
3376 aX2
:= max(Width
div ScaleSz
, 1);
3377 aY2
:= max(Height
div ScaleSz
, 1);
3378 // Ïðàâûé íèæíèé óãîë:
3379 aX2
:= aX
+ aX2
- 1;
3380 aY2
:= aY
+ aY2
- 1;
3382 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3385 if gPlayers
<> nil then
3388 for a
:= 0 to High(gPlayers
) do
3389 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3391 // Ëåâûé âåðõíèé óãîë:
3392 aX
:= Obj
.X
div ScaleSz
+ 1;
3393 aY
:= Obj
.Y
div ScaleSz
+ 1;
3395 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3396 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3397 // Ïðàâûé íèæíèé óãîë:
3398 aX2
:= aX
+ aX2
- 1;
3399 aY2
:= aY
+ aY2
- 1;
3401 if gPlayers
[a
] = p
then
3402 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3405 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3406 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3407 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3412 g_Mons_ForEach(monDraw
);
3417 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3419 if not hasAmbient
then exit
;
3420 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3424 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3425 //FIXME: broken for splitscreen mode
3426 procedure renderDynLightsInternal ();
3428 //hasAmbient: Boolean;
3429 //ambColor: TDFColor;
3431 lx
, ly
, lrad
: Integer;
3432 scxywh
: array[0..3] of GLint
;
3435 if e_NoGraphics
then exit
;
3437 //TODO: lights should be in separate grid, i think
3438 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3439 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3442 //ambColor := gCurrentMap['light_ambient'].rgba;
3443 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3445 { // this will multiply incoming color to alpha from framebuffer
3447 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3451 * light rendering: (INVALID!)
3452 * glStencilFunc(GL_EQUAL, 0, $ff);
3454 * glClear(GL_STENCIL_BUFFER_BIT);
3455 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3456 * draw shadow volume into stencil buffer
3457 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3458 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3460 * draw color-less quad with light alpha (WARNING! don't touch color!)
3461 * glEnable(GL_BLEND);
3462 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3463 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3465 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3466 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3468 // setup OpenGL parameters
3469 glStencilMask($FFFFFFFF);
3470 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3471 glEnable(GL_STENCIL_TEST
);
3472 glEnable(GL_SCISSOR_TEST
);
3473 glClear(GL_STENCIL_BUFFER_BIT
);
3474 glStencilFunc(GL_EQUAL
, 0, $ff);
3476 for lln
:= 0 to g_dynLightCount
-1 do
3478 lx
:= g_dynLights
[lln
].x
;
3479 ly
:= g_dynLights
[lln
].y
;
3480 lrad
:= g_dynLights
[lln
].radius
;
3481 if (lrad
< 3) then continue
;
3483 if (lx
-sX
+lrad
< 0) then continue
;
3484 if (ly
-sY
+lrad
< 0) then continue
;
3485 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3486 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3488 // set scissor to optimize drawing
3489 if (g_dbg_scale
= 1.0) then
3491 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3495 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3497 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3498 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3499 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3500 // draw extruded panels
3501 glDisable(GL_TEXTURE_2D
);
3502 glDisable(GL_BLEND
);
3503 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3504 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3505 // render light texture
3506 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3507 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3510 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3511 glEnable(GL_TEXTURE_2D
);
3512 // color and opacity
3513 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3514 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3516 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3517 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3518 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3519 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3524 glDisable(GL_STENCIL_TEST
);
3525 glDisable(GL_BLEND
);
3526 glDisable(GL_SCISSOR_TEST
);
3527 //glScissor(0, 0, sWidth, sHeight);
3529 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3530 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3534 function fixViewportForScale (): Boolean;
3536 nx0
, ny0
, nw
, nh
: Integer;
3539 if (g_dbg_scale
<> 1.0) then
3542 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3543 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3544 nw
:= round(sWidth
/g_dbg_scale
);
3545 nh
:= round(sHeight
/g_dbg_scale
);
3554 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3555 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3556 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3558 TDrawCB
= procedure ();
3561 hasAmbient
: Boolean;
3563 doAmbient
: Boolean = false;
3565 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3570 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3571 if gdbg_map_use_accel_render
then
3573 tagmask
:= panelTypeToTag(panType
);
3574 while (gDrawPanelList
.count
> 0) do
3576 pan
:= TPanel(gDrawPanelList
.front());
3577 if ((pan
.tag
and tagmask
) = 0) then break
;
3578 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3579 gDrawPanelList
.popFront();
3584 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3586 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3589 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3591 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3592 if assigned(cb
) then cb();
3593 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3597 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3599 // our accelerated renderer will collect all panels to gDrawPanelList
3600 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3601 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3602 if gdbg_map_use_accel_render
then
3604 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3606 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3608 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3609 g_Map_DrawBack(backXOfs
, backYOfs
);
3610 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3612 if setTransMatrix
then
3614 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3615 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3616 glTranslatef(-sX
, -sY
, 0);
3620 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3621 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3626 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3627 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3628 glClear(GL_COLOR_BUFFER_BIT);
3631 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3634 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3635 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3636 drawOther('items', @g_Items_Draw
);
3637 drawOther('weapons', @g_Weapon_Draw
);
3638 drawOther('shells', @g_Player_DrawShells
);
3639 drawOther('drawall', @g_Player_DrawAll
);
3640 drawOther('corpses', @g_Player_DrawCorpses
);
3641 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3642 drawOther('monsters', @g_Monsters_Draw
);
3643 drawOther('itemdrop', @g_Items_DrawDrop
);
3644 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3645 drawOther('gfx', @g_GFX_Draw
);
3646 drawOther('flags', @g_Map_DrawFlags
);
3647 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3648 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3649 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3650 drawOther('dynlights', @renderDynLightsInternal
);
3652 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3654 renderAmbientQuad(hasAmbient
, ambColor
);
3658 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3661 if g_debug_HealthBar
then
3663 g_Monsters_DrawHealth();
3664 g_Player_DrawHealth();
3667 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3671 procedure DrawMapView(x
, y
, w
, h
: Integer);
3678 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3679 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3686 fixViewportForScale();
3687 renderMapInternal(-bx
, -by
, true);
3693 procedure DrawPlayer(p
: TPlayer
);
3695 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3699 if (p
= nil) or (p
.FDummy
) then
3702 g_Map_DrawBack(0, 0);
3707 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3708 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3714 camObj
:= p
.getCameraObj();
3715 camObj
.lerp(gLerpFactor
, fX
, fY
);
3716 px
:= fX
+ PLAYER_RECT_CX
;
3717 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3719 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3721 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3722 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3724 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3725 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3727 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3728 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3731 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3734 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3735 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3738 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3743 // scaled, ignore level bounds
3744 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3745 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3750 sWidth
:= gPlayerScreenSize
.X
;
3751 sHeight
:= gPlayerScreenSize
.Y
;
3752 fixViewportForScale();
3754 i
:= py
- (sY
+ sHeight
div 2);
3755 if (p
.IncCam
> 0) then
3757 // clamp to level bounds
3758 if (sY
- p
.IncCam
< 0) then
3759 p
.IncCam
:= nclamp(sY
, 0, 120);
3760 // clamp around player position
3762 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3764 else if (p
.IncCam
< 0) then
3766 // clamp to level bounds
3767 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3768 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3769 // clamp around player position
3771 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3774 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3776 if (not g_dbg_ignore_bounds
) then
3778 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3779 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3780 if (sX
< 0) then sX
:= 0;
3781 if (sY
< 0) then sY
:= 0;
3784 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3785 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3787 //r_smallmap_h: 0: left; 1: center; 2: right
3788 //r_smallmap_v: 0: top; 1: center; 2: bottom
3790 if (gMapInfo
.Width
= sWidth
) then
3794 else if (gMapInfo
.Width
< sWidth
) then
3796 case r_smallmap_h
of
3797 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3798 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3799 else sX
:= 0; // left
3803 if (gMapInfo
.Height
= sHeight
) then
3807 else if (gMapInfo
.Height
< sHeight
) then
3809 case r_smallmap_v
of
3810 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3811 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3812 else sY
:= 0; // top
3818 p
.viewPortW
:= sWidth
;
3819 p
.viewPortH
:= sHeight
;
3821 {$IFDEF ENABLE_HOLMES}
3822 if (p
= gPlayer1
) then
3824 g_Holmes_plrViewPos(sX
, sY
);
3825 g_Holmes_plrViewSize(sWidth
, sHeight
);
3829 renderMapInternal(-c
, -d
, true);
3831 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3832 case gPlayerIndicator
of
3834 p
.DrawIndicator(_RGB(255, 255, 255));
3837 for i
:= 0 to High(gPlayers
) do
3838 if gPlayers
[i
] <> nil then
3839 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3840 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3841 if gPlayerIndicatorStyle
= 1 then
3842 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3843 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3847 for a := 0 to High(gCollideMap) do
3848 for b := 0 to High(gCollideMap[a]) do
3851 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3853 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3857 1: e_DrawPoint(1, b, a, 200, 200, 200);
3858 2: e_DrawPoint(1, b, a, 64, 64, 255);
3859 3: e_DrawPoint(1, b, a, 255, 0, 255);
3869 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3870 if g_Debug_Player
then
3871 g_Player_DrawDebug(p
);
3875 procedure drawProfilers ();
3880 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3881 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3882 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3885 procedure g_Game_Draw();
3892 plView1
, plView2
: TPlayer
;
3895 if gExit
= EXIT_QUIT
then Exit
;
3897 Time
:= sys_GetTicks() {div 1000};
3898 FPSCounter
:= FPSCounter
+1;
3899 if Time
- FPSTime
>= 1000 then
3906 e_SetRendertarget(True);
3907 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3909 if gGameOn
or (gState
= STATE_FOLD
) then
3911 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3913 gSpectMode
:= SPECT_NONE
;
3914 if not gRevertPlayers
then
3916 plView1
:= gPlayer1
;
3917 plView2
:= gPlayer2
;
3921 plView1
:= gPlayer2
;
3922 plView2
:= gPlayer1
;
3926 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3928 gSpectMode
:= SPECT_NONE
;
3929 if gPlayer2
= nil then
3932 plView1
:= gPlayer2
;
3941 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3942 gSpectMode
:= SPECT_STATS
;
3944 if gSpectMode
= SPECT_PLAYERS
then
3945 if gPlayers
<> nil then
3947 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3948 if plView1
= nil then
3950 gSpectPID1
:= GetActivePlayerID_Next();
3951 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3953 if gSpectViewTwo
then
3955 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3956 if plView2
= nil then
3958 gSpectPID2
:= GetActivePlayerID_Next();
3959 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3964 if gSpectMode
= SPECT_MAPVIEW
then
3966 // Ðåæèì ïðîñìîòðà êàðòû
3968 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3969 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3970 gHearPoint1
.Active
:= True;
3971 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3972 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3973 gHearPoint2
.Active
:= False;
3977 Split
:= (plView1
<> nil) and (plView2
<> nil);
3979 // Òî÷êè ñëóõà èãðîêîâ
3980 if plView1
<> nil then
3982 gHearPoint1
.Active
:= True;
3983 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3984 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3986 gHearPoint1
.Active
:= False;
3987 if plView2
<> nil then
3989 gHearPoint2
.Active
:= True;
3990 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3991 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3993 gHearPoint2
.Active
:= False;
3995 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3996 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3999 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
4000 if gScreenHeight
mod 2 = 0 then
4001 Dec(gPlayerScreenSize
.Y
);
4004 gPlayerScreenSize
.Y
:= gScreenHeight
;
4007 if gScreenHeight
mod 2 = 0 then
4008 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
4010 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4012 DrawPlayer(plView1
);
4013 gPlayer1ScreenCoord
.X
:= sX
;
4014 gPlayer1ScreenCoord
.Y
:= sY
;
4018 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4020 DrawPlayer(plView2
);
4021 gPlayer2ScreenCoord
.X
:= sX
;
4022 gPlayer2ScreenCoord
.Y
:= sY
;
4025 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
4028 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
4031 {$IFDEF ENABLE_HOLMES}
4033 if (g_holmes_enabled
) then g_Holmes_Draw();
4036 if MessageText
<> '' then
4040 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
4042 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4043 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4045 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4046 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4049 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4052 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4054 // Draw spectator GUI
4057 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4060 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4062 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4064 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4066 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4067 if gSpectMode
= SPECT_STATS
then
4069 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4070 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4072 if gSpectMode
= SPECT_MAPVIEW
then
4074 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4075 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4076 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4077 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4078 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4080 if gSpectMode
= SPECT_PLAYERS
then
4082 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4083 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4084 if gSpectViewTwo
then
4086 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4087 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4088 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4089 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4093 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4094 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4100 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4102 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4103 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4105 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4106 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4107 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4112 if (gState
= STATE_MENU
) then
4114 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4115 // F3 at menu will show game loading dialog
4116 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4117 if (g_ActiveWindow
<> nil) then
4119 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4120 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4124 // F3 at titlepic will show game loading dialog
4125 if e_KeyPressed(IK_F3
) then
4127 g_Menu_Show_LoadMenu(true);
4128 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4133 if gState
= STATE_FOLD
then
4135 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4138 if gState
= STATE_INTERCUSTOM
then
4140 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4142 back
:= 'TEXTURE_endpic';
4143 if not g_Texture_Get(back
, ID
) then
4144 back
:= _lc
[I_TEXTURE_ENDPIC
];
4149 DrawMenuBackground(back
);
4153 if g_ActiveWindow
<> nil then
4155 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4156 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4160 if gState
= STATE_INTERSINGLE
then
4162 if EndingGameCounter
> 0 then
4164 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4170 DrawMenuBackground(back
);
4174 if g_ActiveWindow
<> nil then
4176 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4177 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4182 if gState
= STATE_ENDPIC
then
4185 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4186 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4188 if g_ActiveWindow
<> nil then
4190 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4191 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4195 if gState
= STATE_SLIST
then
4197 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4199 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4200 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4202 DrawMenuBackground('MENU_BACKGROUND');
4203 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4204 g_Serverlist_Draw(slCurrent
, slTable
);
4208 if g_ActiveWindow
<> nil then
4212 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4213 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4215 g_ActiveWindow
.Draw();
4222 if g_debug_Sounds
and gGameOn
then
4224 for w
:= 0 to High(e_SoundsArray
) do
4225 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4226 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4231 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4232 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4235 if gGameOn
and gShowTime
then
4236 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4238 if gGameOn
then drawProfilers();
4240 // TODO: draw this after the FBO and remap mouse click coordinates
4242 {$IFDEF ENABLE_HOLMES}
4246 // blit framebuffer to screen
4248 e_SetRendertarget(False);
4249 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4250 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4252 // draw the overlay stuff on top of it
4257 procedure g_Game_Quit();
4259 g_Game_StopAllSounds(True);
4262 g_PlayerModel_FreeData();
4263 g_Texture_DeleteAll();
4264 g_Frames_DeleteAll();
4266 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4269 if NetInitDone
then g_Net_Free
;
4271 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4272 if gMapToDelete
<> '' then
4273 g_Game_DeleteTestMap();
4279 procedure g_FatalError(Text: String);
4281 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4282 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4284 gExit
:= EXIT_SIMPLE
;
4285 if gGameOn
then EndGame
;
4288 procedure g_SimpleError(Text: String);
4290 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4291 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4294 procedure g_Game_SetupScreenSize();
4296 RES_FACTOR
= 4.0 / 3.0;
4302 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4303 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4304 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4305 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4307 gPlayerScreenSize
.Y
:= gScreenHeight
;
4309 // Ðàçìåð çàäíåãî ïëàíà:
4310 if BackID
<> DWORD(-1) then
4313 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4314 (gScreenHeight
*s
> gMapInfo
.Height
) then
4316 gBackSize
.X
:= gScreenWidth
;
4317 gBackSize
.Y
:= gScreenHeight
;
4321 e_GetTextureSize(BackID
, @bw
, @bh
);
4322 rf
:= Single(bw
) / Single(bh
);
4323 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4324 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4325 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4326 if (s
< 1.0) then s
:= 1.0;
4327 gBackSize
.X
:= Round(bw
*s
);
4328 gBackSize
.Y
:= Round(bh
*s
);
4333 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4335 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4338 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4340 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4341 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4344 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4347 if gPlayer1
= nil then
4349 if g_Game_IsClient
then
4351 if NetPlrUID1
> -1 then
4352 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4356 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4357 Team
:= gPlayer1Settings
.Team
;
4359 // Ñîçäàíèå ïåðâîãî èãðîêà:
4360 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4361 gPlayer1Settings
.Color
,
4363 if gPlayer1
= nil then
4364 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4367 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4368 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4369 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4370 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4371 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4372 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4373 if g_Game_IsServer
and g_Game_IsNet
then
4374 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4375 gPlayer1
.Respawn(False, True);
4376 g_Net_Slist_ServerPlayerComes();
4381 if gPlayer2
= nil then
4383 if g_Game_IsClient
then
4385 if NetPlrUID2
> -1 then
4386 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4390 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4391 Team
:= gPlayer2Settings
.Team
;
4393 // Ñîçäàíèå âòîðîãî èãðîêà:
4394 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4395 gPlayer2Settings
.Color
,
4397 if gPlayer2
= nil then
4398 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4401 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4402 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4403 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4404 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4405 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4406 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4407 if g_Game_IsServer
and g_Game_IsNet
then
4408 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4409 gPlayer2
.Respawn(False, True);
4410 g_Net_Slist_ServerPlayerComes();
4417 procedure g_Game_RemovePlayer();
4421 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4422 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4427 if g_Game_IsServer
then
4430 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4431 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4432 g_Player_Remove(Pl
.UID
);
4433 g_Net_Slist_ServerPlayerLeaves();
4437 gSpectLatchPID2
:= Pl
.UID
;
4445 if g_Game_IsServer
then
4448 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4449 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4450 g_Player_Remove(Pl
.UID
);
4451 g_Net_Slist_ServerPlayerLeaves();
4454 gSpectLatchPID1
:= Pl
.UID
;
4456 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4460 g_Net_Slist_ServerPlayerLeaves();
4463 procedure g_Game_Spectate();
4465 g_Game_RemovePlayer();
4466 if gPlayer1
<> nil then
4467 g_Game_RemovePlayer();
4470 procedure g_Game_SpectateCenterView();
4472 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4473 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4476 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4483 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4485 g_Game_ClearLoading();
4488 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4491 gGameSettings
.GameType
:= GT_SINGLE
;
4492 gGameSettings
.MaxLives
:= 0;
4493 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4494 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4495 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4496 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4497 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4498 gSwitchGameMode
:= GM_SINGLE
;
4500 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4501 gLMSRespawnTime
:= 0;
4502 gSpectLatchPID1
:= 0;
4503 gSpectLatchPID2
:= 0;
4505 g_Game_ExecuteEvent('ongamestart');
4507 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4508 g_Game_SetupScreenSize();
4510 // Ñîçäàíèå ïåðâîãî èãðîêà:
4511 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4512 gPlayer1Settings
.Color
,
4513 gPlayer1Settings
.Team
, False));
4514 if gPlayer1
= nil then
4516 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4520 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4521 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4522 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4523 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4524 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4527 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4530 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4531 gPlayer2Settings
.Color
,
4532 gPlayer2Settings
.Team
, False));
4533 if gPlayer2
= nil then
4535 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4539 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4540 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4541 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4542 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4543 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4547 // Çàãðóçêà è çàïóñê êàðòû:
4548 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4550 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4551 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4555 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4559 for i
:= nPl
+1 to nPlayers
do
4560 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4563 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4564 TimeLimit
, ScoreLimit
: Word;
4566 Options
: LongWord; nPlayers
: Byte);
4572 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4574 g_Game_ClearLoading();
4577 gGameSettings
.GameType
:= GT_CUSTOM
;
4578 gGameSettings
.GameMode
:= GameMode
;
4579 gSwitchGameMode
:= GameMode
;
4580 gGameSettings
.TimeLimit
:= TimeLimit
;
4581 gGameSettings
.ScoreLimit
:= ScoreLimit
;
4582 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4583 gGameSettings
.Options
:= Options
;
4585 gCoopTotalMonstersKilled
:= 0;
4586 gCoopTotalSecretsFound
:= 0;
4587 gCoopTotalMonsters
:= 0;
4588 gCoopTotalSecrets
:= 0;
4592 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4593 gLMSRespawnTime
:= 0;
4594 gSpectLatchPID1
:= 0;
4595 gSpectLatchPID2
:= 0;
4597 g_Game_ExecuteEvent('ongamestart');
4599 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4600 g_Game_SetupScreenSize();
4602 // Ðåæèì íàáëþäàòåëÿ:
4603 if nPlayers
= 0 then
4610 if nPlayers
>= 1 then
4612 // Ñîçäàíèå ïåðâîãî èãðîêà:
4613 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4614 gPlayer1Settings
.Color
,
4615 gPlayer1Settings
.Team
, False));
4616 if gPlayer1
= nil then
4618 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4622 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4623 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4624 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4625 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4626 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4630 if nPlayers
>= 2 then
4632 // Ñîçäàíèå âòîðîãî èãðîêà:
4633 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4634 gPlayer2Settings
.Color
,
4635 gPlayer2Settings
.Team
, False));
4636 if gPlayer2
= nil then
4638 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4642 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4643 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4644 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4645 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4646 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4650 // Çàãðóçêà è çàïóñê êàðòû:
4651 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4653 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4657 // Íåò òî÷åê ïîÿâëåíèÿ:
4658 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4659 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4660 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4661 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4662 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4664 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4668 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4672 for i
:= nPl
+1 to nPlayers
do
4673 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4676 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4677 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
4678 Options
: LongWord; nPlayers
: Byte;
4679 IPAddr
: LongWord; Port
: Word);
4682 g_Net_Slist_ServerClosed();
4684 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4686 g_Game_ClearLoading();
4691 gGameSettings
.GameType
:= GT_SERVER
;
4692 gGameSettings
.GameMode
:= GameMode
;
4693 gSwitchGameMode
:= GameMode
;
4694 gGameSettings
.TimeLimit
:= TimeLimit
;
4695 gGameSettings
.ScoreLimit
:= ScoreLimit
;
4696 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4697 gGameSettings
.Options
:= Options
;
4699 gCoopTotalMonstersKilled
:= 0;
4700 gCoopTotalSecretsFound
:= 0;
4701 gCoopTotalMonsters
:= 0;
4702 gCoopTotalSecrets
:= 0;
4706 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4707 gLMSRespawnTime
:= 0;
4708 gSpectLatchPID1
:= 0;
4709 gSpectLatchPID2
:= 0;
4711 g_Game_ExecuteEvent('ongamestart');
4713 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4714 g_Game_SetupScreenSize();
4716 // Ðåæèì íàáëþäàòåëÿ:
4717 if nPlayers
= 0 then
4723 if nPlayers
>= 1 then
4725 // Ñîçäàíèå ïåðâîãî èãðîêà:
4726 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4727 gPlayer1Settings
.Color
,
4728 gPlayer1Settings
.Team
, False));
4729 if gPlayer1
= nil then
4731 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4735 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4736 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4737 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4738 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4739 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4742 if nPlayers
>= 2 then
4744 // Ñîçäàíèå âòîðîãî èãðîêà:
4745 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4746 gPlayer2Settings
.Color
,
4747 gPlayer2Settings
.Team
, False));
4748 if gPlayer2
= nil then
4750 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4754 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4755 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4756 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4757 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4758 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4761 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4762 if NetForwardPorts
then
4763 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4766 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4768 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4772 g_Net_Slist_Set(NetMasterList
);
4774 g_Net_Slist_ServerStarted();
4776 // Çàãðóçêà è çàïóñê êàðòû:
4777 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4779 g_Net_Slist_ServerClosed();
4780 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4784 // Íåò òî÷åê ïîÿâëåíèÿ:
4785 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4786 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4787 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4788 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4789 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4791 g_Net_Slist_ServerClosed();
4792 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4796 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4799 g_Net_Slist_ServerMapStarted();
4800 NetState
:= NET_STATE_GAME
;
4803 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4818 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4819 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4821 g_Game_ClearLoading();
4826 gGameSettings
.GameType
:= GT_CLIENT
;
4828 gCoopTotalMonstersKilled
:= 0;
4829 gCoopTotalSecretsFound
:= 0;
4830 gCoopTotalMonsters
:= 0;
4831 gCoopTotalSecrets
:= 0;
4835 g_Game_ExecuteEvent('ongamestart');
4837 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4838 g_Game_SetupScreenSize();
4840 NetState
:= NET_STATE_AUTH
;
4842 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4844 // create (or update) map/resource databases
4845 g_Res_CreateDatabases(true);
4847 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4848 gLMSRespawnTime
:= 0;
4849 gSpectLatchPID1
:= 0;
4850 gSpectLatchPID2
:= 0;
4853 if not g_Net_Connect(Addr
, Port
) then
4855 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4856 NetState
:= NET_STATE_NONE
;
4860 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4862 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4867 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4868 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4869 // thank you, enet. let's ignore failures altogether then.
4870 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4872 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4874 Ptr
:= NetEvent
.packet
^.data
;
4875 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4877 enet_packet_destroy(NetEvent
.packet
);
4881 InMsg
.ReadLongWord(); // skip size
4882 MID
:= InMsg
.ReadByte();
4884 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4886 NetMyID
:= InMsg
.ReadByte();
4887 NetPlrUID1
:= InMsg
.ReadWord();
4889 WadName
:= InMsg
.ReadString();
4890 Map
:= InMsg
.ReadString();
4892 gWADHash
:= InMsg
.ReadMD5();
4894 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4895 gSwitchGameMode
:= gGameSettings
.GameMode
;
4896 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
4897 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4898 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4899 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4900 T
:= InMsg
.ReadLongWord();
4902 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4903 //if newResPath = '' then
4905 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4906 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4907 if newResPath
= '' then
4909 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4910 enet_packet_destroy(NetEvent
.packet
);
4911 NetState
:= NET_STATE_NONE
;
4914 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4916 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4919 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4920 gPlayer1Settings
.Color
,
4921 gPlayer1Settings
.Team
, False));
4923 if gPlayer1
= nil then
4925 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4927 enet_packet_destroy(NetEvent
.packet
);
4928 NetState
:= NET_STATE_NONE
;
4932 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4933 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4934 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4935 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4936 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4937 gPlayer1
.UID
:= NetPlrUID1
;
4938 gPlayer1
.Reset(True);
4940 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4942 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4944 enet_packet_destroy(NetEvent
.packet
);
4945 NetState
:= NET_STATE_NONE
;
4953 enet_packet_destroy(NetEvent
.packet
);
4957 enet_packet_destroy(NetEvent
.packet
);
4961 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4964 if (NetEvent
.data
<= NET_DISC_MAX
) then
4965 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4966 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4973 ProcessLoading(True);
4974 if g_Net_UserRequestExit() then
4983 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4984 NetState
:= NET_STATE_NONE
;
4989 NetState
:= NET_STATE_GAME
;
4990 MC_SEND_FullStateRequest
;
4991 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4995 lastAsMegaWad
: Boolean = false;
4997 procedure g_Game_ChangeMap(const MapPath
: String);
5001 g_Game_ClearLoading();
5003 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
5004 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5005 if gExitByTrigger
then
5008 gExitByTrigger
:= False;
5010 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
5011 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
5014 procedure g_Game_Restart();
5018 if g_Game_IsClient
then
5020 map
:= g_ExtractFileName(gMapInfo
.Map
);
5021 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
5025 g_Game_ClearLoading();
5026 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
5029 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
5031 NewWAD
, ResName
: String;
5035 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
5036 g_Player_RemoveAllCorpses();
5038 if (not g_Game_IsClient
) and
5039 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
5040 (gGameSettings
.GameMode
<> GM_SINGLE
) then
5042 if gSwitchGameMode
= GM_CTF
then
5043 gGameSettings
.MaxLives
:= 0;
5044 gGameSettings
.GameMode
:= gSwitchGameMode
;
5047 gSwitchGameMode
:= gGameSettings
.GameMode
;
5049 g_Player_ResetTeams();
5051 lastAsMegaWad
:= asMegawad
;
5052 if isWadPath(Map
) then
5054 NewWAD
:= g_ExtractWadName(Map
);
5055 ResName
:= g_ExtractFileName(Map
);
5056 if g_Game_IsServer
then
5058 nws
:= findDiskWad(NewWAD
);
5059 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5062 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5063 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5067 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5068 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5070 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5071 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5073 if (length(nws
) = 0) then
5075 ResName
:= ''; // failed
5080 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5081 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5082 g_Game_LoadWAD(NewWAD
);
5087 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5088 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5093 NewWAD
:= gGameSettings
.WAD
;
5099 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5101 if (ResName
<> '') and (NewWAD
<> '') then
5103 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5104 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5108 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5110 gState
:= STATE_NONE
;
5111 g_ActiveWindow
:= nil;
5117 if gGameSettings
.GameMode
= GM_CTF
then
5119 g_Map_ResetFlag(FLAG_RED
);
5120 g_Map_ResetFlag(FLAG_BLUE
);
5121 // CTF, à ôëàãîâ íåò:
5122 if not g_Map_HaveFlagPoints() then
5123 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5128 gState
:= STATE_MENU
;
5133 gPauseMain
:= false;
5134 gPauseHolmes
:= false;
5135 NetTimeToUpdate
:= 1;
5136 NetTimeToReliable
:= 0;
5137 NetTimeToMaster
:= NetMasterRate
;
5138 gSpectLatchPID1
:= 0;
5139 gSpectLatchPID2
:= 0;
5140 gMissionFailed
:= False;
5143 gCoopMonstersKilled
:= 0;
5144 gCoopSecretsFound
:= 0;
5146 gVoteInProgress
:= False;
5147 gVotePassed
:= False;
5153 if not gGameOn
then Exit
;
5155 g_Game_SpectateCenterView();
5157 if g_Game_IsServer
then
5159 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5161 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5162 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5163 gLMSSoftSpawn
:= True;
5164 if g_Game_IsNet
then
5165 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5169 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5170 gLMSRespawnTime
:= 0;
5174 if NetMode
= NET_SERVER
then
5176 // reset full state flags
5177 if NetClients
<> nil then
5178 for I
:= 0 to High(NetClients
) do
5179 NetClients
[I
].FullUpdateSent
:= False;
5181 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5184 g_Net_Slist_ServerMapStarted();
5186 if NetClients
<> nil then
5187 for I
:= 0 to High(NetClients
) do
5188 if NetClients
[I
].Used
then
5190 NetClients
[I
].Voted
:= False;
5191 if NetClients
[I
].RequestedFullUpdate
then
5193 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5194 NetClients
[I
].RequestedFullUpdate
:= False;
5198 g_Net_UnbanNonPerm();
5203 gCoopTotalMonstersKilled
:= 0;
5204 gCoopTotalSecretsFound
:= 0;
5205 gCoopTotalMonsters
:= 0;
5206 gCoopTotalSecrets
:= 0;
5210 g_Game_ExecuteEvent('onmapstart');
5213 procedure SetFirstLevel
;
5217 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5218 if MapList
= nil then
5221 SortSArray(MapList
);
5222 gNextMap
:= MapList
[Low(MapList
)];
5227 procedure g_Game_ExitLevel(const Map
: AnsiString);
5231 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5232 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5233 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5234 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5236 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5237 if gGameSettings
.GameType
= GT_SINGLE
then
5238 gExit
:= EXIT_ENDLEVELSINGLE
5239 else // Âûøëè â âûõîä â Ñâîåé èãðå
5241 gExit
:= EXIT_ENDLEVELCUSTOM
;
5242 if gGameSettings
.GameMode
= GM_COOP
then
5243 g_Player_RememberAll
;
5245 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5248 if gGameSettings
.GameMode
= GM_COOP
then
5251 gStatsPressed
:= True;
5252 gNextMap
:= 'MAP01';
5254 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5257 if g_Game_IsNet
then
5259 MH_SEND_GameStats();
5260 MH_SEND_CoopStats();
5266 procedure g_Game_RestartLevel();
5270 if gGameSettings
.GameMode
= GM_SINGLE
then
5275 gExit
:= EXIT_ENDLEVELCUSTOM
;
5276 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5280 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5282 gWAD
{, xwad}: String;
5285 if not g_Game_IsClient
then Exit
;
5286 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5288 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5293 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5297 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5300 g_Game_LoadWAD(NewWAD
);
5304 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5305 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5308 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5309 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5313 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5317 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5318 g_Game_LoadWAD(NewWAD);
5322 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5324 i
, n
, nb
, nr
: Integer;
5326 if not g_Game_IsServer
then Exit
;
5327 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5328 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5329 gLMSRespawnTime
:= 0;
5332 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5334 gMissionFailed
:= True;
5335 g_Game_RestartLevel
;
5339 n
:= 0; nb
:= 0; nr
:= 0;
5340 for i
:= Low(gPlayers
) to High(gPlayers
) do
5341 if (gPlayers
[i
] <> nil) and
5342 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5343 (gPlayers
[i
] is TBot
)) then
5346 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5347 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5350 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5352 // wait a second until the fuckers finally decide to join
5353 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5354 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5355 gLMSSoftSpawn
:= NoMapRestart
;
5356 if g_Game_IsNet
then
5357 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5361 g_Player_RemoveAllCorpses
;
5362 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5363 if g_Game_IsNet
then
5364 MH_SEND_GameEvent(NET_EV_LMS_START
);
5366 for i
:= Low(gPlayers
) to High(gPlayers
) do
5368 if gPlayers
[i
] = nil then continue
;
5369 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5370 // don't touch normal spectators
5371 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5373 gPlayers
[i
].FNoRespawn
:= True;
5374 gPlayers
[i
].Lives
:= 0;
5375 if g_Game_IsNet
then
5376 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5379 gPlayers
[i
].FNoRespawn
:= False;
5380 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5381 gPlayers
[i
].Respawn(False, True);
5382 if gGameSettings
.GameMode
= GM_COOP
then
5384 gPlayers
[i
].Frags
:= 0;
5385 gPlayers
[i
].RecallState
;
5387 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5388 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5389 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5390 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5393 g_Items_RestartRound();
5395 gLMSSoftSpawn
:= False;
5398 function g_Game_GetFirstMap(WAD
: String): String;
5402 MapList
:= g_Map_GetMapsList(WAD
);
5403 if MapList
= nil then
5406 SortSArray(MapList
);
5407 Result
:= MapList
[Low(MapList
)];
5409 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5415 function g_Game_GetNextMap(): String;
5422 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5423 if MapList
= nil then
5426 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5428 SortSArray(MapList
);
5430 for I
:= Low(MapList
) to High(MapList
) do
5431 if Map
= MapList
[I
] then
5437 if MapIndex
<> -255 then
5439 if MapIndex
= High(MapList
) then
5440 Result
:= MapList
[Low(MapList
)]
5442 Result
:= MapList
[MapIndex
+ 1];
5444 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5450 procedure g_Game_NextLevel();
5452 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5453 gExit
:= EXIT_ENDLEVELCUSTOM
5456 gExit
:= EXIT_ENDLEVELSINGLE
;
5460 if gNextMap
<> '' then Exit
;
5461 gNextMap
:= g_Game_GetNextMap();
5464 function g_Game_IsTestMap(): Boolean;
5466 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5469 procedure g_Game_DeleteTestMap();
5472 //MapName: AnsiString;
5480 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5481 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5482 if (a
= 0) then exit
;
5484 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5485 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5486 Delete(gMapToDelete
, 1, a
+5);
5487 gMapToDelete
:= UpperCase(gMapToDelete
);
5489 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5492 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5493 if MapName <> TEST_MAP_NAME then
5496 if not gTempDelete then
5498 time := g_GetFileTime(WadName);
5499 WAD := TWADFile.Create();
5502 if not WAD.ReadFile(WadName) then
5503 begin // Íåò òàêîãî WAD-ôàéëà
5508 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5510 MapList := WAD.GetResourcesList('');
5512 if MapList <> nil then
5513 for a := 0 to High(MapList) do
5514 if MapList[a] = MapName then
5516 // Óäàëÿåì è ñîõðàíÿåì:
5517 WAD.RemoveResource('', MapName);
5518 WAD.SaveTo(WadName);
5523 g_SetFileTime(WadName, time);
5526 if gTempDelete
then DeleteFile(WadName
);
5529 procedure GameCVars(P
: SSArray
);
5532 stat
: TPlayerStatArray
;
5535 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5539 if Length(P
) > 1 then
5544 gsGameFlags
:= gsGameFlags
or Flag
5546 gsGameFlags
:= gsGameFlags
and (not Flag
);
5548 if g_Game_IsServer
then
5551 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5553 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5554 if g_Game_IsNet
then MH_SEND_GameSettings
;
5558 if LongBool(gsGameFlags
and Flag
) then
5559 g_Console_Add(_lc
[OnMsg
])
5561 g_Console_Add(_lc
[OffMsg
]);
5563 if OnMapChange
and g_Game_IsServer
then
5564 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5569 cmd
:= LowerCase(P
[0]);
5571 if cmd
= 'g_gamemode' then
5573 if (Length(P
) > 1) then
5575 a
:= g_Game_TextToMode(P
[1]);
5576 if a
= GM_SINGLE
then a
:= GM_COOP
;
5577 gsGameMode
:= g_Game_ModeToText(a
);
5578 if g_Game_IsServer
then
5580 gSwitchGameMode
:= a
;
5581 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5582 (gState
= STATE_INTERSINGLE
) then
5583 gSwitchGameMode
:= GM_SINGLE
;
5585 gGameSettings
.GameMode
:= gSwitchGameMode
;
5589 if gSwitchGameMode
= gGameSettings
.GameMode
then
5590 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5591 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5593 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5594 [g_Game_ModeToText(gGameSettings
.GameMode
),
5595 g_Game_ModeToText(gSwitchGameMode
)]));
5597 else if cmd
= 'g_friendlyfire' then
5599 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5601 else if cmd
= 'g_friendly_absorb_damage' then
5603 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5605 else if cmd
= 'g_friendly_hit_trace' then
5607 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5609 else if cmd
= 'g_friendly_hit_projectile' then
5611 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5613 else if cmd
= 'g_weaponstay' then
5615 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5617 else if cmd
= 'g_allow_exit' then
5619 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5621 else if cmd
= 'g_allow_monsters' then
5623 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5625 else if cmd
= 'g_allow_dropflag' then
5627 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5629 else if cmd
= 'g_throw_flag' then
5631 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5633 else if cmd
= 'g_bot_vsplayers' then
5635 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5637 else if cmd
= 'g_bot_vsmonsters' then
5639 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5641 else if cmd
= 'g_dm_keys' then
5643 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5645 else if cmd
= 'g_gameflags' then
5647 if Length(P
) > 1 then
5649 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5650 if g_Game_IsServer
then
5652 gGameSettings
.Options
:= gsGameFlags
;
5653 if g_Game_IsNet
then MH_SEND_GameSettings
;
5657 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5659 else if cmd
= 'g_warmup_time' then
5661 if Length(P
) > 1 then
5663 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5664 if g_Game_IsServer
then
5666 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5667 // extend warmup if it's already going
5668 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5670 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5671 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5673 if g_Game_IsNet
then MH_SEND_GameSettings
;
5677 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5678 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5680 else if cmd
= 'g_spawn_invul' then
5682 if Length(P
) > 1 then
5684 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5685 if g_Game_IsServer
then
5687 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5688 if g_Game_IsNet
then MH_SEND_GameSettings
;
5692 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5694 else if cmd
= 'g_item_respawn_time' then
5696 if Length(P
) > 1 then
5698 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5699 if g_Game_IsServer
then
5701 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5702 if g_Game_IsNet
then MH_SEND_GameSettings
;
5706 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5707 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5709 else if cmd
= 'sv_intertime' then
5711 if (Length(P
) > 1) then
5712 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5714 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5716 else if cmd
= 'g_max_particles' then
5718 if Length(p
) = 2 then
5720 a
:= Max(0, StrToIntDef(p
[1], 0));
5723 else if Length(p
) = 1 then
5725 e_LogWritefln('%s', [g_GFX_GetMax()])
5729 e_LogWritefln('usage: %s <n>', [cmd
])
5732 else if cmd
= 'g_max_shells' then
5734 if Length(p
) = 2 then
5736 a
:= Max(0, StrToIntDef(p
[1], 0));
5739 else if Length(p
) = 1 then
5741 e_LogWritefln('%s', [g_Shells_GetMax()])
5745 e_LogWritefln('usage: %s <n>', [cmd
])
5748 else if cmd
= 'g_max_gibs' then
5750 if Length(p
) = 2 then
5752 a
:= Max(0, StrToIntDef(p
[1], 0));
5755 else if Length(p
) = 1 then
5757 e_LogWritefln('%s', [g_Gibs_GetMax()])
5761 e_LogWritefln('usage: %s <n>', [cmd
])
5764 else if cmd
= 'g_max_corpses' then
5766 if Length(p
) = 2 then
5768 a
:= Max(0, StrToIntDef(p
[1], 0));
5771 else if Length(p
) = 1 then
5773 e_LogWritefln('%s', [g_Corpses_GetMax()])
5777 e_LogWritefln('usage: %s <n>', [cmd
])
5780 else if cmd
= 'g_force_model' then
5782 if Length(p
) = 2 then
5784 a
:= StrToIntDef(p
[1], 0);
5785 g_Force_Model_Set(a
);
5786 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
5788 for a
:= Low(gPlayers
) to High(gPlayers
) do
5790 if (gPlayers
[a
] <> nil) then
5792 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
5794 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
5796 gPlayers
[a
].setModel(g_Forced_Model_GetName());
5800 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
5802 for a
:= Low(gPlayers
) to High(gPlayers
) do
5804 if (gPlayers
[a
] <> nil) then
5806 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
5808 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
5810 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
5816 else if cmd
= 'g_force_model_name' then
5818 if (Length(P
) > 1) then
5820 cmd
:= b_Text_Unformat(P
[1]);
5821 g_Forced_Model_SetName(cmd
);
5822 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
5824 for a
:= Low(gPlayers
) to High(gPlayers
) do
5826 if (gPlayers
[a
] <> nil) then
5828 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
5830 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
5832 gPlayers
[a
].setModel(g_Forced_Model_GetName());
5838 else if cmd
= 'g_scorelimit' then
5840 if Length(P
) > 1 then
5842 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
5844 if g_Game_IsServer
then
5847 if gGameSettings
.GameMode
= GM_DM
then
5849 stat
:= g_Player_GetStats();
5851 for a
:= 0 to High(stat
) do
5852 if stat
[a
].Frags
> b
then
5856 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
5858 // if someone has a higher score, set it to that instead
5859 gsScoreLimit
:= max(gsScoreLimit
, b
);
5860 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
5862 if g_Game_IsNet
then MH_SEND_GameSettings
;
5866 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
5868 else if cmd
= 'g_timelimit' then
5870 if Length(P
) > 1 then
5872 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5873 if g_Game_IsServer
then
5875 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5876 if g_Game_IsNet
then MH_SEND_GameSettings
;
5879 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5880 [gsTimeLimit
div 3600,
5881 (gsTimeLimit
div 60) mod 60,
5882 gsTimeLimit
mod 60]));
5884 else if cmd
= 'g_max_bots' then
5886 if Length(P
) > 1 then
5887 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
5888 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
5890 else if cmd
= 'g_maxlives' then
5892 if Length(P
) > 1 then
5894 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5895 if g_Game_IsServer
then
5897 gGameSettings
.MaxLives
:= gsMaxLives
;
5898 if g_Game_IsNet
then MH_SEND_GameSettings
;
5902 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5906 procedure PlayerSettingsCVars(P
: SSArray
);
5911 function ParseTeam(s
: string): Byte;
5915 'red', '1': result
:= TEAM_RED
;
5916 'blue', '2': result
:= TEAM_BLUE
;
5917 else result
:= TEAM_NONE
;
5921 cmd
:= LowerCase(P
[0]);
5925 if (Length(P
) > 1) then
5927 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5928 if g_Game_IsClient
then
5929 MC_SEND_PlayerSettings
5930 else if gGameOn
and (gPlayer1
<> nil) then
5932 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5933 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5939 if (Length(P
) > 1) then
5941 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5942 if g_Game_IsClient
then
5943 MC_SEND_PlayerSettings
5944 else if gGameOn
and (gPlayer2
<> nil) then
5946 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5947 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5953 if Length(P
) > 3 then
5955 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5956 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5957 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5958 if g_Game_IsClient
then
5959 MC_SEND_PlayerSettings
5960 else if gGameOn
and (gPlayer1
<> nil) then
5962 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5963 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5969 if Length(P
) > 3 then
5971 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5972 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5973 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5974 if g_Game_IsClient
then
5975 MC_SEND_PlayerSettings
5976 else if gGameOn
and (gPlayer2
<> nil) then
5978 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5979 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5985 if (Length(P
) > 1) then
5987 gPlayer1Settings
.Model
:= P
[1];
5988 if g_Game_IsClient
then
5989 MC_SEND_PlayerSettings
5990 else if gGameOn
and (gPlayer1
<> nil) then
5992 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5993 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5994 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
6000 if (Length(P
) > 1) then
6002 gPlayer2Settings
.Model
:= P
[1];
6003 if g_Game_IsClient
then
6004 MC_SEND_PlayerSettings
6005 else if gGameOn
and (gPlayer2
<> nil) then
6007 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
6008 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
6009 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
6015 // TODO: switch teams if in game or store this separately
6016 if (Length(P
) > 1) then
6018 team
:= ParseTeam(P
[1]);
6019 if team
= TEAM_NONE
then
6020 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6021 else if not gGameOn
and not g_Game_IsNet
then
6022 gPlayer1Settings
.Team
:= team
6024 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
6029 // TODO: switch teams if in game or store this separately
6030 if (Length(P
) > 1) then
6032 team
:= ParseTeam(P
[1]);
6033 if team
= TEAM_NONE
then
6034 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6035 else if not gGameOn
and not g_Game_IsNet
then
6036 gPlayer2Settings
.Team
:= team
6038 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
6043 if (Length(P
) = 2) then
6044 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
6048 if (Length(P
) = 2) then
6049 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
6053 if (Length(P
) = 2) then
6054 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6058 if (Length(P
) = 2) then
6059 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6063 if (Length(P
) = 2) then
6064 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6068 if (Length(P
) = 2) then
6069 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6071 'p1_priority_kastet':
6073 if (Length(P
) = 2) then
6074 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6076 'p2_priority_kastet':
6078 if (Length(P
) = 2) then
6079 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6083 if (Length(P
) = 2) then
6084 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6088 if (Length(P
) = 2) then
6089 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6091 'p1_priority_pistol':
6093 if (Length(P
) = 2) then
6094 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6096 'p2_priority_pistol':
6098 if (Length(P
) = 2) then
6099 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6101 'p1_priority_shotgun1':
6103 if (Length(P
) = 2) then
6104 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6106 'p2_priority_shotgun1':
6108 if (Length(P
) = 2) then
6109 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6111 'p1_priority_shotgun2':
6113 if (Length(P
) = 2) then
6114 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6116 'p2_priority_shotgun2':
6118 if (Length(P
) = 2) then
6119 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6121 'p1_priority_chaingun':
6123 if (Length(P
) = 2) then
6124 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6126 'p2_priority_chaingun':
6128 if (Length(P
) = 2) then
6129 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6131 'p1_priority_rocketlauncher':
6133 if (Length(P
) = 2) then
6134 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6136 'p2_priority_rocketlauncher':
6138 if (Length(P
) = 2) then
6139 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6141 'p1_priority_plasma':
6143 if (Length(P
) = 2) then
6144 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6146 'p2_priority_plasma':
6148 if (Length(P
) = 2) then
6149 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6153 if (Length(P
) = 2) then
6154 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6158 if (Length(P
) = 2) then
6159 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6161 'p1_priority_super':
6163 if (Length(P
) = 2) then
6164 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6166 'p2_priority_super':
6168 if (Length(P
) = 2) then
6169 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6171 'p1_priority_flamethrower':
6173 if (Length(P
) = 2) then
6174 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6176 'p2_priority_flamethrower':
6178 if (Length(P
) = 2) then
6179 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6181 'p1_priority_berserk':
6183 if (Length(P
) = 2) then
6184 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6186 'p2_priority_berserk':
6188 if (Length(P
) = 2) then
6189 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6194 procedure PrintHeapStats();
6198 hs
:= GetFPCHeapStatus();
6199 e_LogWriteLn ('v===== heap status =====v');
6200 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
6201 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
6202 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
6203 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
6204 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
6205 e_LogWriteLn ('^=======================^');
6208 procedure DebugCommands(P
: SSArray
);
6215 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6216 if {gDebugMode}conIsCheatsEnabled
then
6218 cmd
:= LowerCase(P
[0]);
6219 if cmd
= 'd_window' then
6221 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6222 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6224 else if cmd
= 'd_sounds' then
6226 if (Length(P
) > 1) and
6227 ((P
[1] = '1') or (P
[1] = '0')) then
6228 g_Debug_Sounds
:= (P
[1][1] = '1');
6230 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
6232 else if cmd
= 'd_frames' then
6234 if (Length(P
) > 1) and
6235 ((P
[1] = '1') or (P
[1] = '0')) then
6236 g_Debug_Frames
:= (P
[1][1] = '1');
6238 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
6240 else if cmd
= 'd_winmsg' then
6242 if (Length(P
) > 1) and
6243 ((P
[1] = '1') or (P
[1] = '0')) then
6244 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6246 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6248 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6250 if (Length(P
) > 1) and
6251 ((P
[1] = '1') or (P
[1] = '0')) then
6252 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6254 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6256 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6258 if Length(P
) > 1 then
6260 '0': g_debug_BotAIOff
:= 0;
6261 '1': g_debug_BotAIOff
:= 1;
6262 '2': g_debug_BotAIOff
:= 2;
6263 '3': g_debug_BotAIOff
:= 3;
6266 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6268 else if cmd
= 'd_monster' then
6270 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6271 if Length(P
) < 2 then
6273 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6274 g_Console_Add('ID | Name');
6275 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6276 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6277 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6280 a
:= StrToIntDef(P
[1], 0);
6281 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6282 a
:= g_Mons_TypeIdByName(P
[1]);
6284 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6285 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6288 with gPlayer1
.Obj
do
6290 mon
:= g_Monsters_Create(a
,
6291 X
+ Rect
.X
+ (Rect
.Width
div 2),
6292 Y
+ Rect
.Y
+ Rect
.Height
,
6293 gPlayer1
.Direction
, True);
6295 if (Length(P
) > 2) and (mon
<> nil) then
6297 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6298 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6299 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6300 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6301 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6302 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6303 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6304 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6305 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6310 else if (cmd
= 'd_health') then
6312 if (Length(P
) > 1) and
6313 ((P
[1] = '1') or (P
[1] = '0')) then
6314 g_debug_HealthBar
:= (P
[1][1] = '1');
6316 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6318 else if (cmd
= 'd_player') then
6320 if (Length(P
) > 1) and
6321 ((P
[1] = '1') or (P
[1] = '0')) then
6322 g_debug_Player
:= (P
[1][1] = '1');
6324 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6326 else if (cmd
= 'd_mem') then
6332 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6336 procedure GameCheats(P
: SSArray
);
6342 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6344 g_Console_Add('not available');
6350 g_Console_Add('where is the player?!');
6353 cmd
:= LowerCase(P
[0]);
6357 plr
.GodMode
:= not plr
.GodMode
;
6358 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6361 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6362 if cmd
= 'give' then
6364 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6365 for f
:= 1 to High(P
) do
6367 cmd
:= LowerCase(P
[f
]);
6368 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6369 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6370 if cmd
= 'exit' then
6372 if gTriggers
<> nil then
6374 for a
:= 0 to High(gTriggers
) do
6376 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6378 g_Console_Add('player left the map');
6379 gExitByTrigger
:= True;
6380 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6381 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6389 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6390 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6391 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6392 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6393 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6395 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6396 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6398 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6399 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;
6401 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6402 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6404 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6405 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6407 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6408 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6410 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6411 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6412 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6414 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6415 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6416 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6417 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;
6418 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6419 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6421 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;
6422 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;
6423 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;
6424 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;
6425 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;
6426 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;
6428 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6429 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;
6431 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;
6432 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;
6434 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6436 if cmd
= 'ammo' then
6438 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6439 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6440 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6441 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6442 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6443 g_Console_Add('player got some ammo');
6447 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6448 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6450 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6451 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6453 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6454 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6456 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6457 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6459 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6461 if cmd
= 'weapons' then
6463 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6464 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6465 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6466 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6467 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6468 plr
.GiveItem(ITEM_WEAPON_BFG
);
6469 g_Console_Add('player got weapons');
6473 if cmd
= 'keys' then
6475 plr
.GiveItem(ITEM_KEY_RED
);
6476 plr
.GiveItem(ITEM_KEY_GREEN
);
6477 plr
.GiveItem(ITEM_KEY_BLUE
);
6478 g_Console_Add('player got all keys');
6482 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6487 if cmd
= 'open' then
6489 g_Console_Add('player activated sesame');
6490 g_Triggers_OpenAll();
6497 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6501 if cmd
= 'noclip' then
6504 g_Console_Add('wall hardeness adjusted');
6508 if cmd
= 'notarget' then
6510 plr
.NoTarget
:= not plr
.NoTarget
;
6511 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6515 if cmd
= 'noreload' then
6517 plr
.NoReload
:= not plr
.NoReload
;
6518 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6522 if cmd
= 'speedy' then
6524 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6525 g_Console_Add('speed adjusted');
6529 if cmd
= 'jumpy' then
6531 VEL_JUMP
:= 30-VEL_JUMP
;
6532 g_Console_Add('jump height adjusted');
6536 if cmd
= 'automap' then
6538 gShowMap
:= not gShowMap
;
6539 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6543 if cmd
= 'aimline' then
6545 gAimLine
:= not gAimLine
;
6546 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6551 procedure GameCommands(P
: SSArray
);
6557 pl
: pTNetClient
= nil;
6566 cmd
:= LowerCase(P
[0]);
6568 if cmd
= 'pause' then
6570 if (g_ActiveWindow
= nil) then
6571 g_Game_Pause(not gPauseMain
);
6573 else if cmd
= 'endgame' then
6574 gExit
:= EXIT_SIMPLE
6575 else if cmd
= 'restart' then
6577 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6579 if g_Game_IsClient
then
6581 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6586 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6588 else if cmd
= 'kick' then
6590 if g_Game_IsServer
then
6592 if Length(P
) < 2 then
6594 g_Console_Add('kick <name>');
6599 g_Console_Add('kick <name>');
6603 if g_Game_IsNet
then
6604 pl
:= g_Net_Client_ByName(P
[1]);
6607 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6608 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
6609 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6610 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6611 g_Net_Slist_ServerPlayerLeaves();
6612 end else if gPlayers
<> nil then
6613 for a
:= Low(gPlayers
) to High(gPlayers
) do
6614 if gPlayers
[a
] <> nil then
6615 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6617 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6618 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6620 gPlayers
[a
].Lives
:= 0;
6621 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6622 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6623 g_Player_Remove(gPlayers
[a
].UID
);
6624 g_Net_Slist_ServerPlayerLeaves();
6625 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6629 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6631 else if cmd
= 'kick_id' then
6633 if g_Game_IsServer
and g_Game_IsNet
then
6635 if Length(P
) < 2 then
6637 g_Console_Add('kick_id <client ID>');
6642 g_Console_Add('kick_id <client ID>');
6646 a
:= StrToIntDef(P
[1], 0);
6647 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6649 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6651 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6652 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
6653 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6654 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6655 g_Net_Slist_ServerPlayerLeaves();
6659 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6661 else if cmd
= 'kick_pid' then
6663 if g_Game_IsServer
and g_Game_IsNet
then
6665 if Length(P
) < 2 then
6667 g_Console_Add('kick_pid <player ID>');
6672 g_Console_Add('kick_pid <player ID>');
6676 a
:= StrToIntDef(P
[1], 0);
6677 pl
:= g_Net_Client_ByPlayer(a
);
6678 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6680 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6681 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
6682 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6683 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6684 g_Net_Slist_ServerPlayerLeaves();
6687 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6689 else if cmd
= 'ban' then
6691 if g_Game_IsServer
and g_Game_IsNet
then
6693 if Length(P
) < 2 then
6695 g_Console_Add('ban <name>');
6700 g_Console_Add('ban <name>');
6704 pl
:= g_Net_Client_ByName(P
[1]);
6706 g_Net_Host_Ban(pl
, False)
6708 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6710 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6712 else if cmd
= 'ban_id' then
6714 if g_Game_IsServer
and g_Game_IsNet
then
6716 if Length(P
) < 2 then
6718 g_Console_Add('ban_id <client ID>');
6723 g_Console_Add('ban_id <client ID>');
6727 a
:= StrToIntDef(P
[1], 0);
6728 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6729 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6730 g_Net_Host_Ban(pl
, False);
6732 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6734 else if cmd
= 'ban_pid' then
6736 if g_Game_IsServer
and g_Game_IsNet
then
6738 if Length(P
) < 2 then
6740 g_Console_Add('ban_pid <player ID>');
6745 g_Console_Add('ban_pid <player ID>');
6749 a
:= StrToIntDef(P
[1], 0);
6750 pl
:= g_Net_Client_ByPlayer(a
);
6751 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6752 g_Net_Host_Ban(pl
, False);
6754 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6756 else if cmd
= 'permban' then
6758 if g_Game_IsServer
and g_Game_IsNet
then
6760 if Length(P
) < 2 then
6762 g_Console_Add('permban <name>');
6767 g_Console_Add('permban <name>');
6771 pl
:= g_Net_Client_ByName(P
[1]);
6773 g_Net_Host_Ban(pl
, True)
6775 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6777 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6779 else if cmd
= 'permban_id' then
6781 if g_Game_IsServer
and g_Game_IsNet
then
6783 if Length(P
) < 2 then
6785 g_Console_Add('permban_id <client ID>');
6790 g_Console_Add('permban_id <client ID>');
6794 a
:= StrToIntDef(P
[1], 0);
6795 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6796 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6797 g_Net_Host_Ban(@NetClients
[a
], True);
6799 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6801 else if cmd
= 'permban_pid' then
6803 if g_Game_IsServer
and g_Game_IsNet
then
6805 if Length(P
) < 2 then
6807 g_Console_Add('permban_pid <player ID>');
6812 g_Console_Add('permban_pid <player ID>');
6816 a
:= StrToIntDef(P
[1], 0);
6817 pl
:= g_Net_Client_ByPlayer(a
);
6818 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6819 g_Net_Host_Ban(pl
, True);
6821 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6823 else if cmd
= 'permban_ip' then
6825 if g_Game_IsServer
and g_Game_IsNet
then
6827 if Length(P
) < 2 then
6829 g_Console_Add('permban_ip <IP address>');
6834 g_Console_Add('permban_ip <IP address>');
6838 g_Net_BanAddress(P
[1]);
6839 g_Net_SaveBanList();
6840 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6842 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6844 else if cmd
= 'unban' then
6846 if g_Game_IsServer
and g_Game_IsNet
then
6848 if Length(P
) < 2 then
6850 g_Console_Add('unban <IP Address>');
6855 g_Console_Add('unban <IP Address>');
6859 if g_Net_UnbanAddress(P
[1]) then
6861 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6862 g_Net_SaveBanList();
6864 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6866 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6868 else if cmd
= 'clientlist' then
6870 if g_Game_IsServer
and g_Game_IsNet
then
6873 if NetClients
<> nil then
6874 for a
:= Low(NetClients
) to High(NetClients
) do
6875 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6877 plr
:= g_Player_Get(NetClients
[a
].Player
);
6878 if plr
= nil then continue
;
6880 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6881 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6884 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6886 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6888 else if cmd
= 'connect' then
6890 if (NetMode
= NET_NONE
) then
6892 if Length(P
) < 2 then
6894 g_Console_Add('connect <IP> [port] [password]');
6899 g_Console_Add('connect <IP> [port] [password]');
6903 if Length(P
) > 2 then
6904 prt
:= StrToIntDef(P
[2], 25666)
6908 if Length(P
) > 3 then
6913 g_Game_StartClient(P
[1], prt
, pw
);
6916 else if cmd
= 'disconnect' then
6918 if (NetMode
= NET_CLIENT
) then
6921 else if cmd
= 'reconnect' then
6923 if (NetMode
= NET_SERVER
) then
6926 if (NetMode
= NET_CLIENT
) then
6929 gExit
:= EXIT_SIMPLE
;
6933 //TODO: Use last successful password to reconnect, instead of ''
6934 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6936 else if (cmd
= 'addbot') or
6937 (cmd
= 'bot_add') then
6940 1: g_Bot_Add(TEAM_NONE
, 2);
6941 2: g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2));
6943 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100));
6946 else if cmd
= 'bot_addlist' then
6949 1: g_Bot_AddList(TEAM_NONE
, '');
6950 2: g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1));
6952 if P
[2] = 'red' then
6954 else if P
[2] = 'blue' then
6960 then g_Bot_AddList(t
, P
[1], StrToIntDef(P
[1], -1))
6961 else g_Bot_AddList(t
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[3], 100));
6964 else if cmd
= 'bot_removeall' then
6966 else if cmd
= 'chat' then
6968 if g_Game_IsNet
then
6970 if Length(P
) > 1 then
6972 for a
:= 1 to High(P
) do
6973 chstr
:= chstr
+ P
[a
] + ' ';
6975 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6977 if Length(chstr
) < 1 then
6979 g_Console_Add('chat <text>');
6983 chstr
:= b_Text_Format(chstr
);
6984 if g_Game_IsClient
then
6985 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6987 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6990 g_Console_Add('chat <text>');
6992 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6994 else if cmd
= 'teamchat' then
6996 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6998 if Length(P
) > 1 then
7000 for a
:= 1 to High(P
) do
7001 chstr
:= chstr
+ P
[a
] + ' ';
7003 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7005 if Length(chstr
) < 1 then
7007 g_Console_Add('teamchat <text>');
7011 chstr
:= b_Text_Format(chstr
);
7012 if g_Game_IsClient
then
7013 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
7015 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
7016 gPlayer1Settings
.Team
);
7019 g_Console_Add('teamchat <text>');
7021 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7023 else if (cmd
= 'an') or (cmd
= 'announce') then
7025 if g_Game_IsNet
then
7027 if Length(P
) > 1 then
7029 for a
:= 1 to High(P
) do
7030 chstr
:= chstr
+ P
[a
] + ' ';
7032 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7034 if Length(chstr
) < 1 then
7036 g_Console_Add('announce <text>');
7040 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
7041 if g_Game_IsClient
then
7042 MC_SEND_RCONCommand(chstr
)
7044 g_Console_Process(chstr
, True);
7047 g_Console_Add('announce <text>');
7049 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7051 else if cmd
= 'game' then
7053 if gGameSettings
.GameType
<> GT_NONE
then
7055 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7058 if Length(P
) = 1 then
7060 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
7063 // game not started yet, load fist map from some wad
7065 s
:= addWadExtension(P
[1]);
7066 found
:= e_FindResource(AllMapDirs
, s
);
7070 P
[1] := ExpandFileName(P
[1]);
7071 // if map not choosed then set first map
7072 if Length(P
) < 3 then
7075 P
[2] := g_Game_GetFirstMap(P
[1]);
7078 s
:= P
[1] + ':\' + UpperCase(P
[2]);
7080 if g_Map_Exist(s
) then
7084 with gGameSettings
do
7086 Options
:= gsGameFlags
;
7087 GameMode
:= g_Game_TextToMode(gsGameMode
);
7088 if gSwitchGameMode
<> GM_NONE
then
7089 GameMode
:= gSwitchGameMode
;
7090 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7091 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7093 if Length(P
) >= 4 then
7094 b
:= StrToIntDef(P
[3], 1);
7095 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
7096 ScoreLimit
, MaxLives
, Options
, b
);
7101 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7103 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
7105 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
7107 else if cmd
= 'host' then
7109 if gGameSettings
.GameType
<> GT_NONE
then
7111 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7114 if Length(P
) < 4 then
7116 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
7119 if not StrToIp(P
[1], listen
) then
7121 prt
:= StrToIntDef(P
[2], 25666);
7123 s
:= addWadExtension(P
[3]);
7124 found
:= e_FindResource(AllMapDirs
, s
);
7128 // get first map in wad, if not specified
7129 if Length(P
) < 5 then
7132 P
[4] := g_Game_GetFirstMap(P
[1]);
7134 s
:= P
[3] + ':\' + UpperCase(P
[4]);
7135 if g_Map_Exist(s
) then
7139 with gGameSettings
do
7141 Options
:= gsGameFlags
;
7142 GameMode
:= g_Game_TextToMode(gsGameMode
);
7143 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
7144 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7145 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7147 if Length(P
) >= 6 then
7148 b
:= StrToIntDef(P
[5], 0);
7149 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
7155 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
7157 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
7162 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
7165 else if cmd
= 'map' then
7167 if Length(P
) = 1 then
7169 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7171 g_Console_Add(cmd
+ ' <MAP>');
7172 g_Console_Add(cmd
+ ' <WAD> [MAP]')
7176 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7179 else if not e_IsValidResourceName(P
[1]) then
7181 g_Console_Add('wad name must not be absolute or relative');
7185 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7187 if Length(P
) < 3 then
7189 // first param is map or wad
7190 s
:= UpperCase(P
[1]);
7191 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7193 gExitByTrigger
:= False;
7196 // already in game, finish current map
7198 gExit
:= EXIT_ENDLEVELCUSTOM
;
7202 // intermission, so change map immediately
7209 found
:= e_FindResource(AllMapDirs
, s
);
7211 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
7214 // no such map, found wad
7217 P
[1] := ExpandFileName(pw
);
7218 P
[2] := g_Game_GetFirstMap(P
[1]);
7219 s
:= P
[1] + ':\' + P
[2];
7220 if g_Map_Exist(s
) then
7222 gExitByTrigger
:= False;
7225 // already in game, finish current map
7227 gExit
:= EXIT_ENDLEVELCUSTOM
7231 // intermission, so change map immediately
7238 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7240 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7245 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7251 s
:= addWadExtension(P
[1]);
7252 found
:= e_FindResource(AllMapDirs
, s
);
7256 P
[2] := UpperCase(P
[2]);
7257 s
:= P
[1] + ':\' + P
[2];
7258 if g_Map_Exist(s
) then
7260 gExitByTrigger
:= False;
7264 gExit
:= EXIT_ENDLEVELCUSTOM
7273 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7278 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7284 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7288 else if cmd
= 'nextmap' then
7290 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7292 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7297 if Length(P
) = 1 then
7299 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7301 g_Console_Add(cmd
+ ' <MAP>');
7302 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7307 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7310 else if not e_IsValidResourceName(P
[1]) then
7312 g_Console_Add('wad name must not be absolute or relative');
7317 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7319 if Length(P
) < 3 then
7321 // first param is map or wad
7322 s
:= UpperCase(P
[1]);
7323 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7326 gExitByTrigger
:= False;
7332 // no such map, found wad
7333 pw
:= addWadExtension(P
[1]);
7334 found
:= e_FindResource(MapDirs
, pw
);
7336 found
:= e_FindResource(WadDirs
, pw
);
7338 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7341 // map not specified, select first map
7343 P
[2] := g_Game_GetFirstMap(P
[1]);
7344 s
:= P
[1] + ':\' + P
[2];
7345 if g_Map_Exist(s
) then
7347 gExitByTrigger
:= False;
7354 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7356 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7361 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7367 // specified two params wad + map
7368 pw
:= addWadExtension(P
[1]);
7369 found
:= e_FindResource(MapDirs
, pw
);
7371 found
:= e_FindResource(MapDirs
, pw
);
7375 P
[2] := UpperCase(P
[2]);
7376 s
:= P
[1] + ':\' + P
[2];
7377 if g_Map_Exist(s
) then
7379 gExitByTrigger
:= False;
7385 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7390 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7396 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7401 if gNextMap
= '' then
7402 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7404 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7408 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7412 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7416 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7418 gExitByTrigger
:= False;
7419 // next map not specified, try to find trigger EXIT
7420 if (gNextMap
= '') and (gTriggers
<> nil) then
7422 for a
:= 0 to High(gTriggers
) do
7424 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7426 gExitByTrigger
:= True;
7427 //gNextMap := gTriggers[a].Data.MapName;
7428 gNextMap
:= gTriggers
[a
].tgcMap
;
7433 if gNextMap
= '' then
7434 gNextMap
:= g_Game_GetNextMap();
7435 if not isWadPath(gNextMap
) then
7436 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7439 if g_Map_Exist(s
) then
7440 gExit
:= EXIT_ENDLEVELCUSTOM
7442 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7446 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7450 else if (cmd
= 'event') then
7452 if (Length(P
) <= 1) then
7454 for a
:= 0 to High(gEvents
) do
7455 if gEvents
[a
].Command
= '' then
7456 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7458 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7461 if (Length(P
) = 2) then
7463 for a
:= 0 to High(gEvents
) do
7464 if gEvents
[a
].Name
= P
[1] then
7465 if gEvents
[a
].Command
= '' then
7466 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7468 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7471 for a
:= 0 to High(gEvents
) do
7472 if gEvents
[a
].Name
= P
[1] then
7474 gEvents
[a
].Command
:= '';
7475 for b
:= 2 to High(P
) do
7476 if Pos(' ', P
[b
]) = 0 then
7477 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7479 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7480 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7484 else if cmd
= 'suicide' then
7488 if g_Game_IsClient
then
7489 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7492 if gPlayer1
<> nil then
7493 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7494 if gPlayer2
<> nil then
7495 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7499 else if cmd
= 'screenshot' then
7503 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7505 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7507 gWeaponAction
[0, WP_PREV
] := True;
7509 gWeaponAction
[0, WP_NEXT
] := True;
7511 else if cmd
= 'weapon' then
7513 if Length(p
) = 2 then
7515 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7516 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7517 gSelectWeapon
[0, a
] := True
7520 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7521 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7523 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7524 b
:= ord(cmd
[2]) - ord('1');
7526 gWeaponAction
[b
, WP_PREV
] := True;
7528 gWeaponAction
[b
, WP_NEXT
] := True;
7530 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7532 if Length(p
) = 2 then
7534 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7535 b
:= ord(cmd
[2]) - ord('1');
7536 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7537 gSelectWeapon
[b
, a
] := True
7540 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
7542 b
:= ord(cmd
[2]) - ord('1');
7544 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
7546 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
7548 else if (cmd
= 'dropflag') then
7550 if g_Game_IsServer
then
7552 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7553 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7556 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7558 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7560 b
:= ord(cmd
[2]) - ord('1');
7561 if g_Game_IsServer
then
7563 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7564 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7567 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7569 // Êîìàíäû Ñâîåé èãðû:
7570 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7572 if cmd
= 'bot_addred' then
7574 if Length(P
) > 1 then
7575 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7577 g_Bot_Add(TEAM_RED
, 2);
7579 else if cmd
= 'bot_addblue' then
7581 if Length(P
) > 1 then
7582 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7584 g_Bot_Add(TEAM_BLUE
, 2);
7586 else if cmd
= 'spectate' then
7592 else if cmd
= 'say' then
7594 if g_Game_IsServer
and g_Game_IsNet
then
7596 if Length(P
) > 1 then
7599 for a
:= 1 to High(P
) do
7600 chstr
:= chstr
+ P
[a
] + ' ';
7602 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7604 if Length(chstr
) < 1 then
7606 g_Console_Add('say <text>');
7610 chstr
:= b_Text_Format(chstr
);
7611 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7613 else g_Console_Add('say <text>');
7615 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7617 else if cmd
= 'tell' then
7619 if g_Game_IsServer
and g_Game_IsNet
then
7621 if (Length(P
) > 2) and (P
[1] <> '') then
7624 for a
:= 2 to High(P
) do
7625 chstr
:= chstr
+ P
[a
] + ' ';
7627 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7629 if Length(chstr
) < 1 then
7631 g_Console_Add('tell <playername> <text>');
7635 pl
:= g_Net_Client_ByName(P
[1]);
7637 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7639 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7641 else g_Console_Add('tell <playername> <text>');
7643 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7645 else if cmd
= 'centerprint' then
7647 if (Length(P
) > 2) and (P
[1] <> '') then
7650 for a
:= 2 to High(P
) do
7651 chstr
:= chstr
+ P
[a
] + ' ';
7653 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7655 if Length(chstr
) < 1 then
7657 g_Console_Add('centerprint <timeout> <text>');
7661 a
:= StrToIntDef(P
[1], 100);
7662 chstr
:= b_Text_Format(chstr
);
7663 g_Game_Message(chstr
, a
);
7664 if g_Game_IsNet
and g_Game_IsServer
then
7665 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7667 else g_Console_Add('centerprint <timeout> <text>');
7669 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7671 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7673 // Äîïîëíèòåëüíîå âðåìÿ:
7674 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7676 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7677 [gGameSettings
.TimeLimit
div 3600,
7678 (gGameSettings
.TimeLimit
div 60) mod 60,
7679 gGameSettings
.TimeLimit
mod 60]));
7680 if g_Game_IsNet
then MH_SEND_GameSettings
;
7682 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7684 if (Length(P
) <= 1) then
7685 g_Console_Add('rcon_password <password>')
7687 MC_SEND_RCONPassword(P
[1]);
7689 else if cmd
= 'rcon' then
7691 if g_Game_IsClient
then
7693 if Length(P
) > 1 then
7696 for a
:= 1 to High(P
) do
7697 chstr
:= chstr
+ P
[a
] + ' ';
7699 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7701 if Length(chstr
) < 1 then
7703 g_Console_Add('rcon <command>');
7707 MC_SEND_RCONCommand(chstr
);
7709 else g_Console_Add('rcon <command>');
7712 else if cmd
= 'ready' then
7714 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7715 gLMSRespawnTime
:= gTime
+ 100;
7717 else if (cmd
= 'callvote') and g_Game_IsNet
then
7719 if Length(P
) > 1 then
7722 for a
:= 1 to High(P
) do begin
7723 if a
> 1 then chstr
:= chstr
+ ' ';
7724 chstr
:= chstr
+ P
[a
];
7727 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7729 if Length(chstr
) < 1 then
7731 g_Console_Add('callvote <command>');
7735 if g_Game_IsClient
then
7736 MC_SEND_Vote(True, chstr
)
7738 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7739 g_Console_Process('vote', True);
7742 g_Console_Add('callvote <command>');
7744 else if (cmd
= 'vote') and g_Game_IsNet
then
7746 if g_Game_IsClient
then
7748 else if gVoteInProgress
then
7750 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7751 a
:= Floor((NetClientCount
+1)/2.0) + 1
7753 a
:= Floor(NetClientCount
/2.0) + 1;
7758 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7759 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7765 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7766 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7774 procedure SystemCommands(P
: SSArray
);
7778 cmd
:= LowerCase(P
[0]);
7787 gRC_Width
:= Max(1, gRC_Width
);
7788 gRC_Height
:= Max(1, gRC_Height
);
7789 gBPP
:= Max(1, gBPP
);
7790 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7791 e_LogWriteln('resolution changed')
7793 e_LogWriteln('resolution not changed');
7794 sys_EnableVSync(gVSync
);
7798 if Length(p
) = 2 then
7800 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7802 gFrameTime
:= 1000 div gMaxFPS
7806 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7810 if Length(p
) = 2 then
7812 gAskLanguage
:= true;
7813 gLanguage
:= LANGUAGE_ENGLISH
;
7814 case LowerCase(p
[1]) of
7817 gAskLanguage
:= false;
7818 gLanguage
:= LANGUAGE_ENGLISH
;
7822 gAskLanguage
:= false;
7823 gLanguage
:= LANGUAGE_RUSSIAN
;
7827 gAskLanguage
:= true;
7828 gLanguage
:= LANGUAGE_ENGLISH
;
7831 g_Language_Set(gLanguage
);
7835 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7841 procedure g_TakeScreenShot(Filename
: string = '');
7842 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7844 if e_NoGraphics
then Exit
;
7846 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7848 if Filename
= '' then
7851 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7852 Filename
:= 'screenshot-' + date
;
7855 name
:= e_CatPath(dir
, Filename
+ '.png');
7856 s
:= createDiskFile(name
);
7858 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
7860 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7862 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7867 g_Console_Add('oh shit, i can''t create screenshot!')
7871 procedure g_Game_InGameMenu(Show
: Boolean);
7873 if (g_ActiveWindow
= nil) and Show
then
7875 if gGameSettings
.GameType
= GT_SINGLE
then
7876 g_GUI_ShowWindow('GameSingleMenu')
7879 if g_Game_IsClient
then
7880 g_GUI_ShowWindow('GameClientMenu')
7882 if g_Game_IsNet
then
7883 g_GUI_ShowWindow('GameServerMenu')
7885 g_GUI_ShowWindow('GameCustomMenu');
7887 g_Sound_PlayEx('MENU_OPEN');
7889 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7890 if (not g_Game_IsNet
) then
7894 if (g_ActiveWindow
<> nil) and (not Show
) then
7896 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7897 if (not g_Game_IsNet
) then
7898 g_Game_Pause(False);
7902 procedure g_Game_Pause (Enable
: Boolean);
7906 if not gGameOn
then exit
;
7908 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7911 gPauseMain
:= Enable
;
7913 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7916 procedure g_Game_HolmesPause (Enable
: Boolean);
7920 if not gGameOn
then exit
;
7921 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7924 gPauseHolmes
:= Enable
;
7926 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7929 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7934 if gTriggers
<> nil then
7935 for i
:= 0 to High(gTriggers
) do
7936 with gTriggers
[i
] do
7937 if (TriggerType
= TRIGGER_SOUND
) and
7939 Sound
.IsPlaying() then
7941 Sound
.Pause(Enable
);
7945 if gPlayers
<> nil then
7946 for i
:= 0 to High(gPlayers
) do
7947 if gPlayers
[i
] <> nil then
7948 gPlayers
[i
].PauseSounds(Enable
);
7951 if gMusic
<> nil then
7952 gMusic
.Pause(Enable
);
7955 procedure g_Game_StopAllSounds(all
: Boolean);
7959 if gTriggers
<> nil then
7960 for i
:= 0 to High(gTriggers
) do
7961 with gTriggers
[i
] do
7962 if (TriggerType
= TRIGGER_SOUND
) and
7966 if gMusic
<> nil then
7973 procedure g_Game_UpdateTriggerSounds
;
7976 if gTriggers
<> nil then
7977 for i
:= 0 to High(gTriggers
) do
7978 with gTriggers
[i
] do
7979 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7980 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7983 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7986 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7991 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7996 if gSpectMode
<> SPECT_PLAYERS
then
7998 if gSpectPID1
= UID
then
8003 if gSpectViewTwo
and (gSpectPID2
= UID
) then
8010 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
8015 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
8020 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
8025 if gSpectMode
<> SPECT_PLAYERS
then
8027 Pl
:= g_Player_Get(gSpectPID1
);
8028 if (Pl
<> nil) and (Pl
.Team
= Team
) then
8033 if gSpectViewTwo
then
8035 Pl
:= g_Player_Get(gSpectPID2
);
8036 if (Pl
<> nil) and (Pl
.Team
= Team
) then
8044 procedure g_Game_Message(Msg
: string; Time
: Word);
8046 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
8047 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
8048 MessageTime
:= Time
;
8051 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
8053 punct
: Array[0..13] of String =
8054 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8060 function IsPunctuation(S
: String): Boolean;
8065 if Length(S
) <> 1 then
8067 for i
:= Low(punct
) to High(punct
) do
8068 if S
= punct
[i
] then
8074 function FilterPunctuation(S
: String): String;
8078 for i
:= Low(punct
) to High(punct
) do
8079 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
8085 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
8087 // remove player name
8088 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8089 // for FullWord check
8090 Text := toLowerCase1251(' ' + Text + ' ');
8091 fpText
:= FilterPunctuation(Text);
8093 for i
:= 0 to Length(gChatSounds
) - 1 do
8096 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
8098 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
8099 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
8101 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
8107 gChatSounds
[i
].Sound
.Play();
8113 g_Sound_PlayEx('SOUND_GAME_RADIO');
8116 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
8125 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8129 if goodsnd
[a
].IsPlaying() then
8132 goodsnd
[Random(4)].Play();
8135 procedure g_Game_Announce_KillCombo(Param
: Integer);
8142 UID
:= Param
and $FFFF;
8147 Pl
:= g_Player_Get(UID
);
8156 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
8160 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
8164 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
8168 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
8176 if not g_Game_IsWatchedPlayer(UID
) then
8179 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
8183 if killsnd
[n
].IsPlaying() then
8188 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
8196 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8200 if hahasnd
[a
].IsPlaying() then
8203 hahasnd
[Random(3)].Play();
8206 procedure g_Game_Effect_Bubbles (fX
, fY
: Integer; count
: Word; devX
, devY
: Byte; Silent
: Boolean);
8208 g_GFX_Bubbles(fX
, fY
, count
, devX
, devY
);
8209 if not Silent
then if Random(2) = 0
8210 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX
, fY
)
8211 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX
, fY
);
8214 procedure g_Game_StartVote(Command
, Initiator
: string);
8218 if not gVotesEnabled
then Exit
;
8219 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8220 if gVoteInProgress
or gVotePassed
then
8222 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
8223 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
8226 gVoteInProgress
:= True;
8227 gVotePassed
:= False;
8228 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
8231 gVoteCommand
:= Command
;
8233 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8234 Need
:= Floor((NetClientCount
+1)/2.0)+1
8236 Need
:= Floor(NetClientCount
/2.0)+1;
8237 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
8238 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
8241 procedure g_Game_CheckVote
;
8245 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8246 if not gVoteInProgress
then Exit
;
8248 if (gTime
>= gVoteTimer
) then
8250 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8251 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8253 Need
:= Floor(NetClientCount
/2.0) + 1;
8254 if gVoteCount
>= Need
then
8256 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8257 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8258 gVotePassed
:= True;
8259 gVoteCmdTimer
:= gTime
+ 5000;
8263 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
8264 MH_SEND_VoteEvent(NET_VE_FAILED
);
8266 if NetClients
<> nil then
8267 for I
:= Low(NetClients
) to High(NetClients
) do
8268 if NetClients
[i
].Used
then
8269 NetClients
[i
].Voted
:= False;
8270 gVoteInProgress
:= False;
8276 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8277 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8279 Need
:= Floor(NetClientCount
/2.0) + 1;
8280 if gVoteCount
>= Need
then
8282 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8283 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8284 gVoteInProgress
:= False;
8285 gVotePassed
:= True;
8286 gVoteCmdTimer
:= gTime
+ 5000;
8289 if NetClients
<> nil then
8290 for I
:= Low(NetClients
) to High(NetClients
) do
8291 if NetClients
[i
].Used
then
8292 NetClients
[i
].Voted
:= False;
8297 procedure g_Game_LoadMapList(FileName
: string);
8305 if not FileExists(FileName
) then Exit
;
8307 AssignFile(ListFile
, FileName
);
8309 while not EOF(ListFile
) do
8311 ReadLn(ListFile
, s
);
8314 if s
= '' then Continue
;
8316 SetLength(MapList
, Length(MapList
)+1);
8317 MapList
[High(MapList
)] := s
;
8319 CloseFile(ListFile
);
8322 procedure g_Game_SetDebugMode();
8325 // ×èòû (äàæå â ñâîåé èãðå):
8329 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8333 if Length(LoadingStat
.Msgs
) = 0 then
8339 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8340 if NextMsg
= Length(Msgs
) then
8342 for i
:= 0 to High(Msgs
)-1 do
8343 Msgs
[i
] := Msgs
[i
+1];
8351 Msgs
[NextMsg
-1] := Text;
8355 PBarWasHere
:= false;
8358 g_ActiveWindow
:= nil;
8359 ProcessLoading(True);
8362 procedure g_Game_StepLoading(Value
: Integer = -1);
8374 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8377 ProcessLoading(False);
8382 procedure g_Game_ClearLoading();
8391 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8392 if len
< 1 then len
:= 1;
8393 SetLength(Msgs
, len
);
8394 for len
:= Low(Msgs
) to High(Msgs
) do
8397 PBarWasHere
:= false;
8401 procedure Parse_Params(var pars
: TParamStrValues
);
8408 while i
<= ParamCount
do
8411 if (Length(s
) > 1) and (s
[1] = '-') then
8413 if (Length(s
) > 2) and (s
[2] = '-') then
8414 begin // Îäèíî÷íûé ïàðàìåòð
8415 SetLength(pars
, Length(pars
) + 1);
8416 with pars
[High(pars
)] do
8418 Name
:= LowerCase(s
);
8423 if (i
< ParamCount
) then
8424 begin // Ïàðàìåòð ñî çíà÷åíèåì
8426 SetLength(pars
, Length(pars
) + 1);
8427 with pars
[High(pars
)] do
8429 Name
:= LowerCase(s
);
8430 Value
:= LowerCase(ParamStr(i
));
8439 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8444 for i
:= 0 to High(pars
) do
8445 if pars
[i
].Name
= aName
then
8447 Result
:= pars
[i
].Value
;
8452 procedure g_Game_Process_Params();
8454 pars
: TParamStrValues
;
8457 LimT
, LimS
: Integer;
8468 s
:= Find_Param_Value(pars
, '--debug');
8471 g_Game_SetDebugMode();
8472 s
:= Find_Param_Value(pars
, '--netdump');
8477 // Connect when game loads
8478 ip
:= Find_Param_Value(pars
, '-connect');
8482 s
:= Find_Param_Value(pars
, '-port');
8483 if (s
= '') or not TryStrToInt(s
, Port
) then
8486 s
:= Find_Param_Value(pars
, '-pw');
8488 g_Game_StartClient(ip
, Port
, s
);
8492 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8495 gDefaultMegawadStart
:= s
;
8498 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8499 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8501 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8504 // Start map when game loads:
8505 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8506 if isWadPath(map
) then
8509 s
:= Find_Param_Value(pars
, '-gm');
8510 GMode
:= g_Game_TextToMode(s
);
8511 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8512 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8515 s
:= Find_Param_Value(pars
, '-limt');
8516 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8522 s
:= Find_Param_Value(pars
, '-lims');
8523 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8529 s
:= Find_Param_Value(pars
, '-lives');
8530 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8536 s
:= Find_Param_Value(pars
, '-opt');
8540 Opt
:= StrToIntDef(s
, 0);
8543 s
:= Find_Param_Value(pars
, '--close');
8547 // Override map to test:
8548 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8551 if e_IsValidResourceName(s
) then
8552 e_FindResource(AllMapDirs
, s
);
8553 gTestMap
:= ExpandFileName(s
);
8556 // Delete test map after play:
8557 s
:= Find_Param_Value(pars
, '--testdelete');
8560 //gMapToDelete := MapsDir + map;
8561 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8565 // Delete temporary WAD after play:
8566 s
:= Find_Param_Value(pars
, '--tempdelete');
8567 if (s
<> '') and (gTestMap
<> '') then
8569 gMapToDelete
:= gTestMap
;
8570 gTempDelete
:= True;
8573 // Number of players:
8574 s
:= Find_Param_Value(pars
, '-pl');
8576 n
:= DEFAULT_PLAYERS
8578 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8581 s
:= Find_Param_Value(pars
, '-port');
8582 if (s
= '') or not TryStrToInt(s
, Port
) then
8583 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8585 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8588 // Execute script when game loads:
8589 s
:= Find_Param_Value(pars
, '-exec');
8592 // if not isWadPath(s) then
8593 // s := GameDir + '/' + s;
8598 if IOResult
<> 0 then
8600 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8601 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8605 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8606 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8611 if IOResult
<> 0 then
8613 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8614 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8618 if Pos('#', s
) <> 1 then // script comment
8619 g_Console_Process(s
, True);
8630 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8631 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8632 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8633 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8635 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8636 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8637 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8638 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8640 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8641 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8643 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8644 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8646 {$IFDEF ENABLE_HOLMES}
8647 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8650 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8652 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8653 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8655 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8656 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8658 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8659 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8661 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8662 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8663 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8664 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
8665 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8666 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8667 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8668 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8669 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');