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
.Assists
< b
.Assists
then Result
:= 1
645 else if a
.Assists
> b
.Assists
then Result
:= -1
646 else if a
.Frags
< b
.Frags
then Result
:= 1
647 else if a
.Frags
> b
.Frags
then Result
:= -1
648 else if a
.Deaths
< b
.Deaths
then Result
:= -1
649 else if a
.Deaths
> b
.Deaths
then Result
:= 1
650 else if a
.Kills
< b
.Kills
then Result
:= -1
654 procedure SortGameStat(var stat
: TPlayerStatArray
);
659 if stat
= nil then Exit
;
661 for I
:= High(stat
) downto Low(stat
) do
662 for J
:= Low(stat
) to High(stat
) - 1 do
663 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
666 stat
[J
] := stat
[J
+ 1];
671 // saves a shitty CSV containing the game stats passed to it
672 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
675 dir
, fname
, map
, mode
, etime
: String;
679 dir
:= e_GetWriteableDir(StatsDirs
);
680 // stats are placed in stats/yy/mm/dd/*.csv
681 fname
:= e_CatPath(dir
, Path
);
682 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
683 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
684 AssignFile(s
, fname
);
686 SetTextCodePage(s
, CP_UTF8
);
688 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
689 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
690 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
691 mode
:= g_Game_ModeToText(Stat
.GameMode
);
692 etime
:= Format('%d:%.2d:%.2d', [
693 Stat
.GameTime
div 1000 div 3600,
694 (Stat
.GameTime
div 1000 div 60) mod 60,
695 Stat
.GameTime
div 1000 mod 60
697 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
698 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
704 gGameSettings
.TimeLimit
,
705 gGameSettings
.ScoreLimit
,
706 gGameSettings
.Options
,
708 Length(Stat
.PlayerStat
)
710 // line 2: game specific shit
711 // if it's a team game: red score, blue score
712 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
714 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
716 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
717 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
719 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
720 // lines 3-...: team, player name, frags, deaths
721 WriteLn(s
, 'team,name,frags,assists,deaths');
722 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
723 with Stat
.PlayerStat
[I
] do
724 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Assists
, Deaths
]));
726 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
729 g_Console_Add('could not create gamestats file "' + fname
+ '"');
734 procedure ClearDebugCvars();
736 g_debug_Sounds
:= False;
737 g_debug_Frames
:= False;
738 g_debug_WinMsgs
:= False;
739 g_debug_MonsterOff
:= False;
740 g_debug_BotAIOff
:= 0;
741 g_debug_HealthBar
:= False;
742 g_Debug_Player
:= False;
745 function g_Game_ModeToText(Mode
: Byte): string;
749 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
750 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
751 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
752 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
753 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
757 function g_Game_TextToMode(Mode
: string): Byte;
760 Mode
:= UpperCase(Mode
);
761 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
766 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
771 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
776 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
781 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
788 function g_Game_IsNet(): Boolean;
790 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
793 function g_Game_IsServer(): Boolean;
795 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
798 function g_Game_IsClient(): Boolean;
800 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
803 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
810 Result
.name
:= ExtractFileName(WAD
);
811 Result
.description
:= '';
814 w
:= TWADFile
.Create();
817 if not w
.GetResource('INTERSCRIPT', p
, len
) then
823 cfg
:= TConfig
.CreateMem(p
, len
);
824 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
825 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
826 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
827 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
833 procedure g_Game_FreeWAD();
837 for a
:= 0 to High(MegaWAD
.res
.pic
) do
838 if MegaWAD
.res
.pic
[a
] <> '' then
839 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
841 for a
:= 0 to High(MegaWAD
.res
.mus
) do
842 if MegaWAD
.res
.mus
[a
] <> '' then
843 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
845 MegaWAD
.res
.pic
:= nil;
846 MegaWAD
.res
.text := nil;
847 MegaWAD
.res
.anim
:= nil;
848 MegaWAD
.res
.mus
:= nil;
849 MegaWAD
.triggers
:= nil;
851 g_Texture_Delete('TEXTURE_endpic');
852 g_Sound_Delete('MUSIC_endmus');
854 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
855 gGameSettings
.WAD
:= '';
858 procedure g_Game_LoadWAD(WAD
: string);
867 gGameSettings
.WAD
:= WAD
;
868 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
871 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
873 w
:= TWADFile
.Create();
876 if not w
.GetResource('INTERSCRIPT', p
, len
) then
882 cfg
:= TConfig
.CreateMem(p
, len
);
887 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
888 if s = '' then Break;
891 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
892 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
894 g_Texture_CreateWADEx(s, s);
900 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
901 if s = '' then Break;
904 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
905 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
907 g_Music_CreateWADEx(s, s);
910 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
911 if MegaWAD
.endpic
<> '' then
913 TEXTUREFILTER
:= GL_LINEAR
;
914 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
915 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
916 TEXTUREFILTER
:= GL_NEAREST
;
918 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
919 if MegaWAD
.endmus
<> '' then
921 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
922 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
930 {procedure start_trigger(t: string);
934 function next_trigger(): Boolean;
938 procedure DisableCheats();
944 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
945 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
946 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
947 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
949 {$IF DEFINED(D2F_DEBUG)}
950 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
951 gAimLine
:= g_dbg_aimline_on
;
955 procedure g_Game_ExecuteEvent(Name
: String);
961 if gEvents
= nil then
963 for a
:= 0 to High(gEvents
) do
964 if gEvents
[a
].Name
= Name
then
966 if gEvents
[a
].Command
<> '' then
967 g_Console_Process(gEvents
[a
].Command
, True);
972 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
977 if gDelayedEvents
<> nil then
978 for a
:= 0 to High(gDelayedEvents
) do
979 if not gDelayedEvents
[a
].Pending
then
986 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
987 n
:= High(gDelayedEvents
);
989 gDelayedEvents
[n
].Pending
:= True;
990 gDelayedEvents
[n
].DEType
:= DEType
;
991 gDelayedEvents
[n
].DENum
:= Num
;
992 gDelayedEvents
[n
].DEStr
:= Str
;
993 if DEType
= DE_GLOBEVENT
then
994 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
996 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1000 procedure EndGame();
1006 if g_Game_IsNet
and g_Game_IsServer
then
1007 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1010 gPauseMain
:= false;
1011 gPauseHolmes
:= false;
1014 g_Game_StopAllSounds(False);
1019 EndingGameCounter
:= 0;
1020 g_ActiveWindow
:= nil;
1022 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1023 gLMSRespawnTime
:= 0;
1026 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1031 begin // Ýòî áûë òåñò
1035 begin // Âûõîä â ãëàâíîå ìåíþ
1036 gMusic
.SetByName('MUSIC_MENU');
1038 if gState
<> STATE_SLIST
then
1040 g_GUI_ShowWindow('MainMenu');
1041 gState
:= STATE_MENU
;
1044 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1045 slReturnPressed
:= True;
1046 if g_Net_Slist_Fetch(slCurrent
) then
1048 if slCurrent
= nil then
1049 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1052 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1053 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1056 g_Game_ExecuteEvent('ongameend');
1060 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1062 if not g_Game_IsClient
then g_Game_Restart();
1065 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1067 // Ñòàòèñòèêà Ñâîåé èãðû:
1068 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1070 CustomStat
.GameTime
:= gTime
;
1071 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1072 CustomStat
.MapName
:= gMapInfo
.Name
;
1073 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1074 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1075 CustomStat
.TeamStat
:= gTeamStat
;
1077 CustomStat
.PlayerStat
:= nil;
1079 // Ñòàòèñòèêà èãðîêîâ:
1080 if gPlayers
<> nil then
1082 for a
:= 0 to High(gPlayers
) do
1083 if gPlayers
[a
] <> nil then
1085 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1086 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1089 Name
:= gPlayers
[a
].Name
;
1090 Frags
:= gPlayers
[a
].Frags
;
1091 Assists
:= gPlayers
[a
].Assists
;
1092 Deaths
:= gPlayers
[a
].Death
;
1093 Kills
:= gPlayers
[a
].Kills
;
1094 Team
:= gPlayers
[a
].Team
;
1095 Color
:= gPlayers
[a
].Model
.Color
;
1096 Spectator
:= gPlayers
[a
].FSpectator
;
1100 SortGameStat(CustomStat
.PlayerStat
);
1102 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1105 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1106 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1107 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1108 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1110 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1113 StatShotDone
:= False;
1116 g_Game_ExecuteEvent('onmapend');
1117 if not g_Game_IsClient
then g_Player_ResetReady
;
1118 gInterReadyCount
:= 0;
1120 // Çàòóõàþùèé ýêðàí:
1121 EndingGameCounter
:= 255;
1122 gState
:= STATE_FOLD
;
1124 if gDefInterTime
< 0 then
1125 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1127 gInterEndTime
:= gDefInterTime
* 1000;
1130 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1132 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1133 SingleStat
.GameTime
:= gTime
;
1134 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1135 SingleStat
.TotalSecrets
:= gSecretsCount
;
1136 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1137 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1138 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1139 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1140 if SingleStat
.TwoPlayers
then
1142 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1143 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1146 g_Game_ExecuteEvent('onmapend');
1149 if gNextMap
<> '' then
1151 gMusic
.SetByName('MUSIC_INTERMUS');
1153 gState
:= STATE_INTERSINGLE
;
1156 g_Game_ExecuteEvent('oninter');
1158 else // Áîëüøå íåò êàðò
1160 // Çàòóõàþùèé ýêðàí:
1161 EndingGameCounter
:= 255;
1162 gState
:= STATE_FOLD
;
1167 // Îêîí÷àíèå îáðàáîòàíî:
1168 if gExit
<> EXIT_QUIT
then
1172 procedure drawTime(X
, Y
: Integer); inline;
1174 e_TextureFontPrint(x
, y
,
1175 Format('%d:%.2d:%.2d', [
1176 gTime
div 1000 div 3600,
1177 (gTime
div 1000 div 60) mod 60,
1178 gTime
div 1000 mod 60
1183 procedure DrawStat();
1185 pc
, x
, y
, w
, h
: Integer;
1186 w1
, w2
, w3
, w4
: Integer;
1188 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1191 stat
: TPlayerStatArray
;
1199 pc
:= g_Player_GetCount
;
1200 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1202 w
:= gScreenWidth
-(gScreenWidth
div 5);
1203 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1206 h
:= 40+ch
*5+(ch
+8)*pc
;
1207 x
:= (gScreenWidth
div 2)-(w
div 2);
1208 y
:= (gScreenHeight
div 2)-(h
div 2);
1210 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1211 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1213 drawTime(x
+w
-78, y
+8);
1215 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1216 map
:= g_ExtractFileName(gMapInfo
.Map
);
1217 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1219 case gGameSettings
.GameMode
of
1222 if gGameSettings
.MaxLives
= 0 then
1223 s1
:= _lc
[I_GAME_DM
]
1225 s1
:= _lc
[I_GAME_LMS
];
1226 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.ScoreLimit
]);
1227 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1232 if gGameSettings
.MaxLives
= 0 then
1233 s1
:= _lc
[I_GAME_TDM
]
1235 s1
:= _lc
[I_GAME_TLMS
];
1236 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.ScoreLimit
]);
1237 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1242 s1
:= _lc
[I_GAME_CTF
];
1243 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.ScoreLimit
]);
1244 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1249 if gGameSettings
.MaxLives
= 0 then
1250 s1
:= _lc
[I_GAME_COOP
]
1252 s1
:= _lc
[I_GAME_SURV
];
1253 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1254 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1265 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1267 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1269 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1271 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1272 gStdFont
, 200, 200, 200, 1);
1274 if NetMode
= NET_SERVER
then
1275 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1277 if NetMode
= NET_CLIENT
then
1278 e_TextureFontPrintEx(x
+8, y
+ 8,
1279 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1283 stat
:= g_Player_GetStats();
1286 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1287 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1289 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1291 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1295 for a
:= TEAM_RED
to TEAM_BLUE
do
1297 if a
= TEAM_RED
then
1299 s1
:= _lc
[I_GAME_TEAM_RED
];
1306 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1312 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1313 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Score
),
1314 gStdFont
, r
, g
, b
, 1);
1316 _y
:= _y
+ch
+(ch
div 4);
1317 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1318 _y
:= _y
+(ch
div 4);
1320 for aa
:= 0 to High(stat
) do
1321 if stat
[aa
].Team
= a
then
1337 namestr
:= Format('[%5d] %s', [UID
, Name
])
1341 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1343 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1345 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1347 e_TextureFontPrintEx(x
+w1
+w2
+48, _y
, IntToStr(Assists
), gStdFont
, rr
, gg
, bb
, 1);
1349 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1356 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1359 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1360 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1361 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1362 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1365 for aa
:= 0 to High(stat
) do
1379 namestr
:= Format('[%5d] %s', [UID
, Name
])
1383 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1384 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1386 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1388 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1390 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1392 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1398 procedure g_Game_Init();
1401 knownFiles
: array of AnsiString = nil;
1403 wext
, s
: AnsiString;
1408 gTempDelete
:= False;
1410 sfsGCDisable(); // temporary disable removing of temporary volumes
1413 TEXTUREFILTER
:= GL_LINEAR
;
1414 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1415 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1416 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1417 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1418 TEXTUREFILTER
:= GL_NEAREST
;
1420 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1421 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1422 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1424 g_Game_ClearLoading();
1425 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1426 g_Game_SetLoadingText('', 0, False);
1428 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1431 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1432 g_PlayerModel_LoadData();
1434 // load models from all possible wad types, in all known directories
1435 // this does a loosy job (linear search, ooph!), but meh
1436 for wext
in wadExtensions
do
1438 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1440 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1444 for s
in knownFiles
do
1446 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1454 SetLength(knownFiles
, length(knownFiles
)+1);
1455 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1457 until (FindNext(SR
) <> 0);
1463 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1465 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
);
1466 for s
in knownFiles
do
1468 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1472 gPauseMain
:= false;
1473 gPauseHolmes
:= false;
1476 {e_MouseInfo.Accel := 1.0;}
1478 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1481 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1482 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1483 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1484 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1485 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1488 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1492 gMusic
:= TMusic
.Create();
1493 gMusic
.SetByName('MUSIC_MENU');
1496 gGameSettings
.WarmupTime
:= 30;
1498 gState
:= STATE_MENU
;
1500 SetLength(gEvents
, 6);
1501 gEvents
[0].Name
:= 'ongamestart';
1502 gEvents
[1].Name
:= 'ongameend';
1503 gEvents
[2].Name
:= 'onmapstart';
1504 gEvents
[3].Name
:= 'onmapend';
1505 gEvents
[4].Name
:= 'oninter';
1506 gEvents
[5].Name
:= 'onwadend';
1508 sfsGCEnable(); // enable releasing unused volumes
1512 procedure g_Game_Free(freeTextures
: Boolean=true);
1514 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1515 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1517 g_Map_Free(freeTextures
);
1519 g_Player_RemoveAllCorpses();
1521 gGameSettings
.GameType
:= GT_NONE
;
1522 if gGameSettings
.GameMode
= GM_SINGLE
then
1523 gGameSettings
.GameMode
:= GM_DM
;
1524 gSwitchGameMode
:= gGameSettings
.GameMode
;
1527 gExitByTrigger
:= False;
1530 function IsActivePlayer(p
: TPlayer
): Boolean;
1535 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1538 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1545 if gPlayers
= nil then
1547 for a
:= Low(gPlayers
) to High(gPlayers
) do
1548 if IsActivePlayer(gPlayers
[a
]) then
1550 if gPlayers
[a
].UID
<> ID
then
1552 Result
:= gPlayers
[a
];
1557 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1563 if gPlayers
= nil then
1567 for a
:= Low(gPlayers
) to High(gPlayers
) do
1568 if IsActivePlayer(gPlayers
[a
]) then
1570 SetLength(ids
, Length(ids
) + 1);
1571 ids
[High(ids
)] := gPlayers
[a
].UID
;
1572 if gPlayers
[a
].UID
= Skip
then
1575 if Length(ids
) = 0 then
1580 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1583 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1589 if gPlayers
= nil then
1593 for a
:= Low(gPlayers
) to High(gPlayers
) do
1594 if IsActivePlayer(gPlayers
[a
]) then
1596 SetLength(ids
, Length(ids
) + 1);
1597 ids
[High(ids
)] := gPlayers
[a
].UID
;
1598 if gPlayers
[a
].UID
= Skip
then
1601 if Length(ids
) = 0 then
1604 Result
:= ids
[Length(ids
) - 1]
1606 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1609 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1615 if gPlayers
= nil then
1619 for a
:= Low(gPlayers
) to High(gPlayers
) do
1620 if IsActivePlayer(gPlayers
[a
]) then
1622 SetLength(ids
, Length(ids
) + 1);
1623 ids
[High(ids
)] := gPlayers
[a
].UID
;
1624 if gPlayers
[a
].UID
= Skip
then
1627 if Length(ids
) = 0 then
1629 if Length(ids
) = 1 then
1634 Result
:= ids
[Random(Length(ids
))];
1636 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1638 Result
:= ids
[Random(Length(ids
))];
1643 function GetRandomSpectMode(Current
: Byte): Byte;
1650 0: Result
:= SPECT_STATS
;
1651 1: Result
:= SPECT_MAPVIEW
;
1652 2: Result
:= SPECT_MAPVIEW
;
1653 3: Result
:= SPECT_PLAYERS
;
1654 4: Result
:= SPECT_PLAYERS
;
1655 5: Result
:= SPECT_PLAYERS
;
1656 6: Result
:= SPECT_PLAYERS
;
1658 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1662 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1668 if (plr
= nil) then exit
;
1669 if (p
= 2) then time
:= 1000 else time
:= 1;
1670 strafeDir
:= MoveButton
shr 4;
1671 MoveButton
:= MoveButton
and $0F;
1673 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1674 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1675 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1676 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1677 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1678 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1680 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1681 if MoveButton
= 1 then
1682 plr
.PressKey(KEY_LEFT
, time
)
1683 else if MoveButton
= 2 then
1684 plr
.PressKey(KEY_RIGHT
, time
);
1686 // if we have "strafe" key, turn off old strafe mechanics
1687 if gPlayerAction
[p
, ACTION_STRAFE
] then
1689 // new strafe mechanics
1690 if (strafeDir
= 0) then
1691 strafeDir
:= MoveButton
; // start strafing
1692 // now set direction according to strafe (reversed)
1693 if (strafeDir
= 2) then
1694 plr
.SetDirection(TDirection
.D_LEFT
)
1695 else if (strafeDir
= 1) then
1696 plr
.SetDirection(TDirection
.D_RIGHT
)
1700 strafeDir
:= 0; // not strafing anymore
1701 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1702 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1703 plr
.SetDirection(TDirection
.D_LEFT
)
1704 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1705 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1706 plr
.SetDirection(TDirection
.D_RIGHT
)
1707 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1708 else if MoveButton
<> 0 then
1709 plr
.SetDirection(TDirection(MoveButton
-1))
1712 // fix movebutton state
1713 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1715 // Îñòàëüíûå êëàâèøè:
1716 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1717 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1718 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1719 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1720 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1722 for i
:= WP_FACT
to WP_LACT
do
1724 if gWeaponAction
[p
, i
] then
1726 plr
.ProcessWeaponAction(i
);
1727 gWeaponAction
[p
, i
] := False
1731 for i
:= WP_FIRST
to WP_LAST
do
1733 if gSelectWeapon
[p
, i
] then
1735 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1736 gSelectWeapon
[p
, i
] := False
1740 // HACK: add dynlight here
1741 if gwin_k8_enable_light_experiments
then
1743 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1745 g_playerLight
:= true;
1747 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1749 g_playerLight
:= false;
1753 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1756 // HACK: don't have a "key was pressed" function
1757 procedure InterReady();
1759 if InterReadyTime
> gTime
then Exit
;
1760 InterReadyTime
:= gTime
+ 3000;
1761 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1764 procedure g_Game_PreUpdate();
1766 // these are in separate PreUpdate functions because they can interact during Update()
1767 // and are synced over the net
1768 // we don't care that much about corpses and gibs
1769 g_Player_PreUpdate();
1770 g_Monsters_PreUpdate();
1771 g_Items_PreUpdate();
1772 g_Weapon_PreUpdate();
1775 procedure g_Game_Update();
1777 Msg
: g_gui
.TMessage
;
1783 function sendMonsPos (mon
: TMonster
): Boolean;
1785 result
:= false; // don't stop
1786 // this will also reset "need-send" flag
1787 if mon
.gncNeedSend
then
1789 MH_SEND_MonsterPos(mon
.UID
);
1791 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1793 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1795 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1797 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1801 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1803 result
:= false; // don't stop
1804 // this will also reset "need-send" flag
1805 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1808 function sendItemPos (it
: PItem
): Boolean;
1810 result
:= false; // don't stop
1813 MH_SEND_ItemPos(it
.myId
);
1814 it
.needSend
:= False;
1819 reliableUpdate
: Boolean;
1824 // Ïîðà âûêëþ÷àòü èãðó:
1825 if gExit
= EXIT_QUIT
then
1827 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1831 if gExit
= EXIT_QUIT
then
1835 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1836 // no need to, as we'll do it in event handler
1838 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1841 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1843 gExit
:= EXIT_SIMPLE
;
1848 // process master server communications
1849 g_Net_Slist_Pulse();
1852 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1853 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1854 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1855 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1857 if g_Game_IsNet
and g_Game_IsServer
then
1859 gInterTime
:= gInterTime
+ GAME_TICK
;
1860 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1861 if a
<> gServInterTime
then
1863 gServInterTime
:= a
;
1864 MH_SEND_TimeSync(gServInterTime
);
1868 if (not g_Game_IsClient
) and
1872 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1873 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1874 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1875 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1877 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1878 and (g_ActiveWindow
= nil)
1880 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1883 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1884 g_Game_StopAllSounds(True);
1886 if gMapOnce
then // Ýòî áûë òåñò
1887 gExit
:= EXIT_SIMPLE
1889 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1890 g_Game_ChangeMap(gNextMap
)
1891 else // Ñëåäóþùåé êàðòû íåò
1893 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1895 // Âûõîä â ãëàâíîå ìåíþ:
1897 g_GUI_ShowWindow('MainMenu');
1898 gMusic
.SetByName('MUSIC_MENU');
1900 gState
:= STATE_MENU
;
1903 // Ôèíàëüíàÿ êàðòèíêà:
1904 g_Game_ExecuteEvent('onwadend');
1906 if not gMusic
.SetByName('MUSIC_endmus') then
1907 gMusic
.SetByName('MUSIC_STDENDMUS');
1909 gState
:= STATE_ENDPIC
;
1911 g_Game_ExecuteEvent('ongameend');
1916 else if g_Game_IsClient
and
1919 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1920 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1921 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1922 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1924 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1925 and (g_ActiveWindow
= nil)
1933 if gState
= STATE_INTERTEXT
then
1934 if InterText
.counter
> 0 then
1935 InterText
.counter
:= InterText
.counter
- 1;
1938 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1940 if EndingGameCounter
= 0 then
1942 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1943 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1945 gState
:= STATE_INTERCUSTOM
;
1946 InterReadyTime
:= -1;
1947 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1949 g_Game_ExecuteEvent('onwadend');
1950 if not gMusic
.SetByName('MUSIC_endmus') then
1951 gMusic
.SetByName('MUSIC_STDENDMUS');
1954 gMusic
.SetByName('MUSIC_ROUNDMUS');
1958 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1960 gMusic
.SetByName('MUSIC_INTERMUS');
1962 gState
:= STATE_INTERSINGLE
;
1965 g_Game_ExecuteEvent('oninter');
1968 DecMin(EndingGameCounter
, 6, 0);
1971 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1973 if gMapOnce
then // Ýòî áûë òåñò
1975 gExit
:= EXIT_SIMPLE
;
1981 g_Serverlist_Control(slCurrent
, slTable
);
1984 // Ñòàòèñòèêà ïî Tab:
1986 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1989 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1991 // Âðåìÿ += 28 ìèëëèñåêóíä:
1992 gTime
:= gTime
+ GAME_TICK
;
1994 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1995 if MessageTime
= 0 then
1997 if MessageTime
> 0 then
1998 MessageTime
:= MessageTime
- 1;
2000 if (g_Game_IsServer
) then
2002 // Áûë çàäàí ëèìèò âðåìåíè:
2003 if (gGameSettings
.TimeLimit
> 0) then
2004 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2005 begin // Îí ïðîøåë => êîíåö óðîâíÿ
2010 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
2011 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2012 g_Game_RestartRound(gLMSSoftSpawn
);
2014 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
2015 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2017 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2019 g_Console_Process(gVoteCommand
);
2021 gVotePassed
:= False;
2024 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2025 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2026 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2027 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2028 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2030 // Áûë çàäàí ëèìèò ïîáåä:
2031 if (gGameSettings
.ScoreLimit
> 0) then
2035 if gGameSettings
.GameMode
= GM_DM
then
2036 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2037 for i
:= 0 to High(gPlayers
) do
2038 if gPlayers
[i
] <> nil then
2039 if gPlayers
[i
].Frags
> b
then
2040 b
:= gPlayers
[i
].Frags
;
2043 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2044 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2045 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2048 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2049 if b
>= gGameSettings
.ScoreLimit
then
2056 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2057 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2058 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2059 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2061 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2062 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2063 end // if not console
2066 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2068 // process weapon switch queue
2072 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2073 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2075 if not gSpectKeyPress
then
2077 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2079 // switch spect mode
2081 SPECT_NONE
: ; // not spectator
2083 SPECT_MAPVIEW
: Inc(gSpectMode
);
2084 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2086 gSpectKeyPress
:= True;
2088 if (gSpectMode
= SPECT_MAPVIEW
)
2089 and (not gSpectAuto
) then
2091 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2092 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2093 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2094 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2095 if gPlayerAction
[0, ACTION_LOOKUP
] then
2096 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2097 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2098 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2099 if gWeaponAction
[0, WP_PREV
] then
2102 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2103 gWeaponAction
[0, WP_PREV
] := False;
2105 if gWeaponAction
[0, WP_NEXT
] then
2108 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2109 gWeaponAction
[0, WP_NEXT
] := False;
2112 if (gSpectMode
= SPECT_PLAYERS
)
2113 and (not gSpectAuto
) then
2115 if gPlayerAction
[0, ACTION_LOOKUP
] then
2118 gSpectViewTwo
:= True;
2119 gSpectKeyPress
:= True;
2121 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2123 // remove second view
2124 gSpectViewTwo
:= False;
2125 gSpectKeyPress
:= True;
2127 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2129 // prev player (view 1)
2130 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2131 gSpectKeyPress
:= True;
2133 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2135 // next player (view 1)
2136 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2137 gSpectKeyPress
:= True;
2139 if gWeaponAction
[0, WP_PREV
] then
2141 // prev player (view 2)
2142 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2143 gWeaponAction
[0, WP_PREV
] := False;
2145 if gWeaponAction
[0, WP_NEXT
] then
2147 // next player (view 2)
2148 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2149 gWeaponAction
[0, WP_NEXT
] := False;
2152 if gPlayerAction
[0, ACTION_ATTACK
] then
2154 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2157 gSpectAutoNext
:= 0;
2158 gSpectViewTwo
:= False;
2159 gSpectKeyPress
:= True;
2164 gSpectMode
:= SPECT_STATS
;
2165 gSpectAuto
:= False;
2166 gSpectKeyPress
:= True;
2171 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2172 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2173 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2174 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2175 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2176 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2177 gSpectKeyPress
:= False;
2181 if gSpectMode
= SPECT_MAPVIEW
then
2183 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2185 gSpectAutoNext
:= gTime
2188 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2190 gSpectAutoNext
:= gTime
2194 if gSpectAutoNext
<= gTime
then
2196 if gSpectAutoNext
> 0 then
2198 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2202 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2203 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2204 gSpectAutoStepX
:= Random(9) - 4;
2205 gSpectAutoStepY
:= Random(9) - 4;
2206 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2207 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2208 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2209 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2210 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2211 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2215 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2220 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2221 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2222 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2228 // Îáíîâëÿåì âñå îñòàëüíîå:
2231 g_Triggers_Update();
2233 g_Monsters_Update();
2235 g_Player_UpdateAll();
2236 g_Player_UpdatePhysicalObjects();
2238 // server: send newly spawned monsters unconditionally
2239 if (gGameSettings
.GameType
= GT_SERVER
) then
2241 if (Length(gMonstersSpawned
) > 0) then
2243 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2244 SetLength(gMonstersSpawned
, 0);
2248 if (gSoundTriggerTime
> 8) then
2250 g_Game_UpdateTriggerSounds();
2251 gSoundTriggerTime
:= 0;
2255 Inc(gSoundTriggerTime
);
2258 if (NetMode
= NET_SERVER
) then
2260 Inc(NetTimeToUpdate
);
2261 Inc(NetTimeToReliable
);
2263 // send monster updates
2264 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2266 // send all monsters (periodic sync)
2267 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2269 for I
:= 0 to High(gPlayers
) do
2271 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2274 g_Mons_ForEach(sendMonsPos
);
2276 // update flags that aren't stationary
2277 if gGameSettings
.GameMode
= GM_CTF
then
2278 for I
:= FLAG_RED
to FLAG_BLUE
do
2279 if gFlags
[I
].NeedSend
then
2281 gFlags
[I
].NeedSend
:= False;
2285 // update items that aren't stationary
2286 g_Items_ForEachAlive(sendItemPos
);
2288 if reliableUpdate
then
2290 NetTimeToReliable
:= 0;
2291 NetTimeToUpdate
:= NetUpdateRate
;
2295 NetTimeToUpdate
:= 0;
2300 // send only mosters with some unexpected changes
2301 g_Mons_ForEach(sendMonsPosUnexpected
);
2304 // send unexpected platform changes
2305 g_Map_NetSendInterestingPanels();
2307 g_Net_Slist_ServerUpdate();
2309 if NetUseMaster then
2311 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2313 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2315 NetTimeToMaster := gTime + NetMasterRate;
2320 else if (NetMode
= NET_CLIENT
) then
2322 MC_SEND_PlayerPos();
2324 end; // if gameOn ...
2326 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2327 if g_ActiveWindow
<> nil then
2329 w
:= e_GetFirstKeyPressed();
2331 if (w
<> IK_INVALID
) then
2333 Msg
.Msg
:= MESSAGE_DIKEY
;
2335 g_ActiveWindow
.OnMessage(Msg
);
2338 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2339 if g_ActiveWindow
<> nil then
2340 g_ActiveWindow
.Update();
2342 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2343 if gResolutionChange
then
2345 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2346 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2347 gResolutionChange
:= False;
2348 g_ActiveWindow
:= nil;
2351 // Íóæíî ñìåíèòü ÿçûê:
2352 if gLanguageChange
then
2354 //e_WriteLog('Read language file', MSG_NOTIFY);
2355 //g_Language_Load(DataDir + gLanguage + '.txt');
2356 g_Language_Set(gLanguage
);
2360 gLanguageChange
:= False;
2364 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2365 if e_KeyPressed(IK_F10
) and
2367 (not gConsoleShow
) and
2368 (g_ActiveWindow
= nil) then
2373 Time
:= sys_GetTicks() {div 1000};
2375 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2376 if gDelayedEvents
<> nil then
2377 for a
:= 0 to High(gDelayedEvents
) do
2378 if gDelayedEvents
[a
].Pending
and
2380 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2381 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2384 case gDelayedEvents
[a
].DEType
of
2386 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2389 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2393 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2394 if g_Game_IsNet
and g_Game_IsServer
then
2395 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2399 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2401 gDelayedEvents
[a
].Pending
:= False;
2404 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2405 UPSCounter
:= UPSCounter
+ 1;
2406 if Time
- UPSTime
>= 1000 then
2415 g_Weapon_AddDynLights();
2416 g_Items_AddDynLights();
2420 procedure g_Game_LoadChatSounds(Resource
: string);
2423 FileName
, Snd
: string;
2425 len
, cnt
, tags
, i
, j
: Integer;
2428 FileName
:= g_ExtractWadName(Resource
);
2430 WAD
:= TWADFile
.Create();
2431 WAD
.ReadFile(FileName
);
2433 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2440 cfg
:= TConfig
.CreateMem(p
, len
);
2441 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2443 SetLength(gChatSounds
, cnt
);
2444 for i
:= 0 to Length(gChatSounds
) - 1 do
2446 gChatSounds
[i
].Sound
:= nil;
2447 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2448 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2449 if (Snd
= '') or (Tags
<= 0) then
2451 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2452 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2453 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2454 SetLength(gChatSounds
[i
].Tags
, tags
);
2455 for j
:= 0 to tags
- 1 do
2456 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2457 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2464 procedure g_Game_FreeChatSounds();
2468 for i
:= 0 to Length(gChatSounds
) - 1 do
2470 gChatSounds
[i
].Sound
.Free();
2471 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2473 SetLength(gChatSounds
, 0);
2477 procedure g_Game_LoadData();
2484 if DataLoaded
then Exit
;
2486 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2488 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2489 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2494 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2495 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2496 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2497 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2498 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2499 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2500 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2501 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2502 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2505 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2506 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2507 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2508 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2512 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2513 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2514 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2515 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2516 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
2522 hasPBarGfx
:= false;
2526 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2527 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2528 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2529 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2530 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2531 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2532 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2533 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2534 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2535 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2536 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2537 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2538 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2539 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2540 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2541 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2542 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2543 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2544 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2545 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2546 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2547 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2548 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2549 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2550 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2551 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2552 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2553 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2554 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2555 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2556 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2557 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2558 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2559 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2560 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2561 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2562 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2563 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2564 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2566 goodsnd
[0] := TPlayableSound
.Create();
2567 goodsnd
[1] := TPlayableSound
.Create();
2568 goodsnd
[2] := TPlayableSound
.Create();
2569 goodsnd
[3] := TPlayableSound
.Create();
2571 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2572 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2573 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2574 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2576 killsnd
[0] := TPlayableSound
.Create();
2577 killsnd
[1] := TPlayableSound
.Create();
2578 killsnd
[2] := TPlayableSound
.Create();
2579 killsnd
[3] := TPlayableSound
.Create();
2581 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2582 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2583 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2584 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2586 hahasnd
[0] := TPlayableSound
.Create();
2587 hahasnd
[1] := TPlayableSound
.Create();
2588 hahasnd
[2] := TPlayableSound
.Create();
2590 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2591 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2592 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2594 sound_get_flag
[0] := TPlayableSound
.Create();
2595 sound_get_flag
[1] := TPlayableSound
.Create();
2596 sound_lost_flag
[0] := TPlayableSound
.Create();
2597 sound_lost_flag
[1] := TPlayableSound
.Create();
2598 sound_ret_flag
[0] := TPlayableSound
.Create();
2599 sound_ret_flag
[1] := TPlayableSound
.Create();
2600 sound_cap_flag
[0] := TPlayableSound
.Create();
2601 sound_cap_flag
[1] := TPlayableSound
.Create();
2603 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2604 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2605 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2606 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2607 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2608 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2609 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2610 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2612 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2614 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2617 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2618 g_Weapon_LoadData();
2620 g_Monsters_LoadData();
2625 procedure g_Game_FreeData();
2627 if not DataLoaded
then Exit
;
2630 g_Weapon_FreeData();
2631 g_Monsters_FreeData();
2633 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2635 g_Texture_Delete('NOTEXTURE');
2636 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2637 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2638 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2639 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2640 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2641 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2642 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2643 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2644 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2645 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2646 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2647 g_Frames_DeleteByName('FRAMES_TELEPORT');
2648 g_Frames_DeleteByName('FRAMES_PUNCH');
2649 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2650 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2651 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2652 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2653 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2654 g_Sound_Delete('SOUND_GAME_TELEPORT');
2655 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2656 g_Sound_Delete('SOUND_GAME_SECRET');
2657 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2658 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2659 g_Sound_Delete('SOUND_GAME_BULK1');
2660 g_Sound_Delete('SOUND_GAME_BULK2');
2661 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2662 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2663 g_Sound_Delete('SOUND_GAME_BURNING');
2664 g_Sound_Delete('SOUND_GAME_SWITCH1');
2665 g_Sound_Delete('SOUND_GAME_SWITCH0');
2672 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2673 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2674 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2675 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2682 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2683 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2684 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2685 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2691 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2692 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2693 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2695 sound_get_flag
[0].Free();
2696 sound_get_flag
[1].Free();
2697 sound_lost_flag
[0].Free();
2698 sound_lost_flag
[1].Free();
2699 sound_ret_flag
[0].Free();
2700 sound_ret_flag
[1].Free();
2701 sound_cap_flag
[0].Free();
2702 sound_cap_flag
[1].Free();
2704 g_Sound_Delete('SOUND_CTF_GET1');
2705 g_Sound_Delete('SOUND_CTF_GET2');
2706 g_Sound_Delete('SOUND_CTF_LOST1');
2707 g_Sound_Delete('SOUND_CTF_LOST2');
2708 g_Sound_Delete('SOUND_CTF_RETURN1');
2709 g_Sound_Delete('SOUND_CTF_RETURN2');
2710 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2711 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2713 g_Game_FreeChatSounds();
2715 DataLoaded
:= False;
2718 procedure DrawCustomStat();
2724 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2725 s1
, s2
, topstr
: String;
2727 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2731 if g_Console_Action(ACTION_SCORES
) then
2733 if not gStatsPressed
then
2735 gStatsOff
:= not gStatsOff
;
2736 gStatsPressed
:= True;
2740 gStatsPressed
:= False;
2744 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2745 w
:= (Length(s1
) * ww2
) div 2;
2746 x
:= gScreenWidth
div 2 - w
;
2748 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2752 if (gGameSettings
.GameMode
= GM_COOP
) then
2754 if gMissionFailed
then
2755 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2757 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2760 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2762 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2763 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2765 if g_Game_IsNet
then
2767 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2768 if not gChatShow
then
2769 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2770 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2773 if g_Game_IsClient
then
2774 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2776 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2777 if not gChatShow
then
2778 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2779 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2784 w
:= gScreenWidth
-x
*2;
2790 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2791 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2793 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2795 case CustomStat
.GameMode
of
2798 if gGameSettings
.MaxLives
= 0 then
2799 s1
:= _lc
[I_GAME_DM
]
2801 s1
:= _lc
[I_GAME_LMS
];
2805 if gGameSettings
.MaxLives
= 0 then
2806 s1
:= _lc
[I_GAME_TDM
]
2808 s1
:= _lc
[I_GAME_TLMS
];
2810 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2813 if gGameSettings
.MaxLives
= 0 then
2814 s1
:= _lc
[I_GAME_COOP
]
2816 s1
:= _lc
[I_GAME_SURV
];
2822 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2826 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2827 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2830 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2831 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2832 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2833 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2835 pc
:= Length(CustomStat
.PlayerStat
);
2836 if pc
= 0 then Exit
;
2838 if CustomStat
.GameMode
= GM_COOP
then
2840 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2842 s2
:= _lc
[I_GAME_MONSTERS
];
2843 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2844 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2846 s2
:= _lc
[I_GAME_SECRETS
];
2847 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2848 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2851 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2853 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2854 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2855 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2857 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2858 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2859 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2863 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2868 if TeamStat
[TEAM_RED
].Score
> TeamStat
[TEAM_BLUE
].Score
then s1
:= _lc
[I_GAME_WIN_RED
]
2869 else if TeamStat
[TEAM_BLUE
].Score
> TeamStat
[TEAM_RED
].Score
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2870 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2872 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2875 for t
:= TEAM_RED
to TEAM_BLUE
do
2877 if t
= TEAM_RED
then
2879 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2880 gStdFont
, 255, 0, 0, 1);
2881 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Score
),
2882 gStdFont
, 255, 0, 0, 1);
2889 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2890 gStdFont
, 0, 0, 255, 1);
2891 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Score
),
2892 gStdFont
, 0, 0, 255, 1);
2898 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2901 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2902 if CustomStat
.PlayerStat
[p
].Team
= t
then
2903 with CustomStat
.PlayerStat
[p
] do
2917 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2918 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2920 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2921 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2922 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Assists
), gStdFont
, rr
, gg
, bb
, 1);
2923 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2930 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2933 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2934 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2935 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2938 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2939 with CustomStat
.PlayerStat
[p
] do
2941 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2948 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2949 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2951 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2952 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2953 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2958 // HACK: take stats screenshot immediately after the first frame of the stats showing
2959 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2961 g_TakeScreenShot('stats/' + StatFilename
);
2962 StatShotDone
:= True;
2966 procedure DrawSingleStat();
2968 tm
, key_x
, val_x
, y
: Integer;
2972 procedure player_stat(n
: Integer);
2978 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2979 s2
:= Format(' %d', [gTotalMonsters
]);
2981 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2982 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2983 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2984 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2986 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2987 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2989 // "Kills-per-minute: ##.#":
2990 s1
:= _lc
[I_MENU_INTER_KPM
];
2992 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2994 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2995 s2
:= Format(' %.1f', [kpm
]);
2997 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2998 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
3000 // "Secrets found: # / #":
3001 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
3002 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
3004 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
3005 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
3006 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3007 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
3009 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3010 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
3014 // "Level Complete":
3015 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
3016 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
3018 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3019 s1
:= _lc
[I_MENU_INTER_KPM
];
3020 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3023 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
3025 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
3026 val_x
:= key_x
+ w1
;
3029 tm
:= SingleStat
.GameTime
div 1000;
3030 s1
:= _lc
[I_MENU_INTER_TIME
];
3031 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
3033 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
3034 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
3036 if SingleStat
.TwoPlayers
then
3039 s1
:= _lc
[I_MENU_PLAYER_1
];
3040 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3041 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
3043 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3048 s1
:= _lc
[I_MENU_PLAYER_2
];
3049 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3050 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3052 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3058 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3064 procedure DrawLoadingStat();
3065 procedure drawRect (x
, y
, w
, h
: Integer);
3067 if (w
< 1) or (h
< 1) then exit
;
3069 glVertex2f(x
+0.375, y
+0.375);
3070 glVertex2f(x
+w
+0.375, y
+0.375);
3071 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3072 glVertex2f(x
+0.375, y
+h
+0.375);
3076 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3078 rectW
, rectH
: Integer;
3085 idl
, idr
, idb
, idm
: LongWord;
3089 if (total
< 1) then exit
;
3090 if (cur
< 1) then exit
; // don't blink
3091 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3092 //if (cur < 0) then cur := 0;
3093 //if (cur > total) then cur := total;
3096 if (hasPBarGfx
) then
3098 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3099 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3100 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3101 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3102 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3103 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3104 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3105 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3107 //rectW := gScreenWidth-360;
3108 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3111 x0
:= (gScreenWidth
-rectW
) div 2;
3112 y0
:= gScreenHeight
-rectH
-64;
3113 if (y0
< 2) then y0
:= 2;
3115 glEnable(GL_SCISSOR_TEST
);
3118 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3119 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3120 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3123 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3125 while (f
< x0
+rectW
) do
3127 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3132 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3133 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3136 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3137 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3141 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3147 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3151 rectW
:= gScreenWidth
-64;
3154 x0
:= (gScreenWidth
-rectW
) div 2;
3155 y0
:= gScreenHeight
-rectH
-64;
3156 if (y0
< 2) then y0
:= 2;
3158 glDisable(GL_BLEND
);
3159 glDisable(GL_TEXTURE_2D
);
3161 //glClearColor(0, 0, 0, 0);
3162 //glClear(GL_COLOR_BUFFER_BIT);
3164 glColor4ub(127, 127, 127, 255);
3165 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3167 glColor4ub(0, 0, 0, 255);
3168 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3170 glColor4ub(127, 127, 127, 255);
3171 wdt
:= rectW
*cur
div total
;
3172 if (wdt
> rectW
) then wdt
:= rectW
;
3173 drawRect(x0
, y0
, wdt
, rectH
);
3182 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3184 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3185 yy
:= (gScreenHeight
div 3);
3186 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3187 xx
:= (gScreenWidth
div 3);
3191 for i
:= 0 to NextMsg
-1 do
3193 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3194 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3198 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3199 yy
:= yy
+ LOADING_INTERLINE
;
3200 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3205 procedure DrawMenuBackground(tex
: AnsiString);
3211 if g_Texture_Get(tex
, ID
) then
3213 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3214 e_GetTextureSize(ID
, @w
, @h
);
3216 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3218 w
:= trunc(w
* (gScreenHeight
/ h
));
3219 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3221 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3224 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3226 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3228 function monDraw (mon
: TMonster
): Boolean;
3230 result
:= false; // don't stop
3235 // Ëåâûé âåðõíèé óãîë
3236 aX
:= Obj
.X
div ScaleSz
+ 1;
3237 aY
:= Obj
.Y
div ScaleSz
+ 1;
3239 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3240 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3241 // Ïðàâûé íèæíèé óãîë
3242 aX2
:= aX
+ aX2
- 1;
3243 aY2
:= aY
+ aY2
- 1;
3244 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3250 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3251 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3254 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3255 ScaleSz
:= 16 div Scale
;
3256 // Ðàçìåðû ìèíè-êàðòû:
3257 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3258 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3260 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3262 if gWalls
<> nil then
3265 for a
:= 0 to High(gWalls
) do
3267 if PanelType
<> 0 then
3269 // Ëåâûé âåðõíèé óãîë:
3270 aX
:= X
div ScaleSz
;
3271 aY
:= Y
div ScaleSz
;
3273 aX2
:= max(Width
div ScaleSz
, 1);
3274 aY2
:= max(Height
div ScaleSz
, 1);
3275 // Ïðàâûé íèæíèé óãîë:
3276 aX2
:= aX
+ aX2
- 1;
3277 aY2
:= aY
+ aY2
- 1;
3280 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3281 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3282 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3286 if gSteps
<> nil then
3289 for a
:= 0 to High(gSteps
) do
3291 if PanelType
<> 0 then
3293 // Ëåâûé âåðõíèé óãîë:
3294 aX
:= X
div ScaleSz
;
3295 aY
:= Y
div ScaleSz
;
3297 aX2
:= max(Width
div ScaleSz
, 1);
3298 aY2
:= max(Height
div ScaleSz
, 1);
3299 // Ïðàâûé íèæíèé óãîë:
3300 aX2
:= aX
+ aX2
- 1;
3301 aY2
:= aY
+ aY2
- 1;
3303 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3306 if gLifts
<> nil then
3309 for a
:= 0 to High(gLifts
) do
3311 if PanelType
<> 0 then
3313 // Ëåâûé âåðõíèé óãîë:
3314 aX
:= X
div ScaleSz
;
3315 aY
:= Y
div ScaleSz
;
3317 aX2
:= max(Width
div ScaleSz
, 1);
3318 aY2
:= max(Height
div ScaleSz
, 1);
3319 // Ïðàâûé íèæíèé óãîë:
3320 aX2
:= aX
+ aX2
- 1;
3321 aY2
:= aY
+ aY2
- 1;
3324 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3325 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3326 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3327 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3331 if gWater
<> nil then
3334 for a
:= 0 to High(gWater
) do
3336 if PanelType
<> 0 then
3338 // Ëåâûé âåðõíèé óãîë:
3339 aX
:= X
div ScaleSz
;
3340 aY
:= Y
div ScaleSz
;
3342 aX2
:= max(Width
div ScaleSz
, 1);
3343 aY2
:= max(Height
div ScaleSz
, 1);
3344 // Ïðàâûé íèæíèé óãîë:
3345 aX2
:= aX
+ aX2
- 1;
3346 aY2
:= aY
+ aY2
- 1;
3348 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3351 if gAcid1
<> nil then
3353 // Ðèñóåì êèñëîòó 1:
3354 for a
:= 0 to High(gAcid1
) do
3356 if PanelType
<> 0 then
3358 // Ëåâûé âåðõíèé óãîë:
3359 aX
:= X
div ScaleSz
;
3360 aY
:= Y
div ScaleSz
;
3362 aX2
:= max(Width
div ScaleSz
, 1);
3363 aY2
:= max(Height
div ScaleSz
, 1);
3364 // Ïðàâûé íèæíèé óãîë:
3365 aX2
:= aX
+ aX2
- 1;
3366 aY2
:= aY
+ aY2
- 1;
3368 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3371 if gAcid2
<> nil then
3373 // Ðèñóåì êèñëîòó 2:
3374 for a
:= 0 to High(gAcid2
) do
3376 if PanelType
<> 0 then
3378 // Ëåâûé âåðõíèé óãîë:
3379 aX
:= X
div ScaleSz
;
3380 aY
:= Y
div ScaleSz
;
3382 aX2
:= max(Width
div ScaleSz
, 1);
3383 aY2
:= max(Height
div ScaleSz
, 1);
3384 // Ïðàâûé íèæíèé óãîë:
3385 aX2
:= aX
+ aX2
- 1;
3386 aY2
:= aY
+ aY2
- 1;
3388 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3391 if gPlayers
<> nil then
3394 for a
:= 0 to High(gPlayers
) do
3395 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3397 // Ëåâûé âåðõíèé óãîë:
3398 aX
:= Obj
.X
div ScaleSz
+ 1;
3399 aY
:= Obj
.Y
div ScaleSz
+ 1;
3401 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3402 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3403 // Ïðàâûé íèæíèé óãîë:
3404 aX2
:= aX
+ aX2
- 1;
3405 aY2
:= aY
+ aY2
- 1;
3407 if gPlayers
[a
] = p
then
3408 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3411 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3412 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3413 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3418 g_Mons_ForEach(monDraw
);
3423 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3425 if not hasAmbient
then exit
;
3426 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3430 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3431 //FIXME: broken for splitscreen mode
3432 procedure renderDynLightsInternal ();
3434 //hasAmbient: Boolean;
3435 //ambColor: TDFColor;
3437 lx
, ly
, lrad
: Integer;
3438 scxywh
: array[0..3] of GLint
;
3441 if e_NoGraphics
then exit
;
3443 //TODO: lights should be in separate grid, i think
3444 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3445 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3448 //ambColor := gCurrentMap['light_ambient'].rgba;
3449 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3451 { // this will multiply incoming color to alpha from framebuffer
3453 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3457 * light rendering: (INVALID!)
3458 * glStencilFunc(GL_EQUAL, 0, $ff);
3460 * glClear(GL_STENCIL_BUFFER_BIT);
3461 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3462 * draw shadow volume into stencil buffer
3463 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3464 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3466 * draw color-less quad with light alpha (WARNING! don't touch color!)
3467 * glEnable(GL_BLEND);
3468 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3469 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3471 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3472 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3474 // setup OpenGL parameters
3475 glStencilMask($FFFFFFFF);
3476 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3477 glEnable(GL_STENCIL_TEST
);
3478 glEnable(GL_SCISSOR_TEST
);
3479 glClear(GL_STENCIL_BUFFER_BIT
);
3480 glStencilFunc(GL_EQUAL
, 0, $ff);
3482 for lln
:= 0 to g_dynLightCount
-1 do
3484 lx
:= g_dynLights
[lln
].x
;
3485 ly
:= g_dynLights
[lln
].y
;
3486 lrad
:= g_dynLights
[lln
].radius
;
3487 if (lrad
< 3) then continue
;
3489 if (lx
-sX
+lrad
< 0) then continue
;
3490 if (ly
-sY
+lrad
< 0) then continue
;
3491 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3492 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3494 // set scissor to optimize drawing
3495 if (g_dbg_scale
= 1.0) then
3497 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3501 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3503 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3504 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3505 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3506 // draw extruded panels
3507 glDisable(GL_TEXTURE_2D
);
3508 glDisable(GL_BLEND
);
3509 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3510 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3511 // render light texture
3512 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3513 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3516 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3517 glEnable(GL_TEXTURE_2D
);
3518 // color and opacity
3519 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3520 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3522 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3523 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3524 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3525 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3530 glDisable(GL_STENCIL_TEST
);
3531 glDisable(GL_BLEND
);
3532 glDisable(GL_SCISSOR_TEST
);
3533 //glScissor(0, 0, sWidth, sHeight);
3535 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3536 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3540 function fixViewportForScale (): Boolean;
3542 nx0
, ny0
, nw
, nh
: Integer;
3545 if (g_dbg_scale
<> 1.0) then
3548 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3549 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3550 nw
:= round(sWidth
/g_dbg_scale
);
3551 nh
:= round(sHeight
/g_dbg_scale
);
3560 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3561 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3562 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3564 TDrawCB
= procedure ();
3567 hasAmbient
: Boolean;
3569 doAmbient
: Boolean = false;
3571 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3576 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3577 if gdbg_map_use_accel_render
then
3579 tagmask
:= panelTypeToTag(panType
);
3580 while (gDrawPanelList
.count
> 0) do
3582 pan
:= TPanel(gDrawPanelList
.front());
3583 if ((pan
.tag
and tagmask
) = 0) then break
;
3584 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3585 gDrawPanelList
.popFront();
3590 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3592 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3595 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3597 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3598 if assigned(cb
) then cb();
3599 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3603 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3605 // our accelerated renderer will collect all panels to gDrawPanelList
3606 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3607 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3608 if gdbg_map_use_accel_render
then
3610 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3612 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3614 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3615 g_Map_DrawBack(backXOfs
, backYOfs
);
3616 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3618 if setTransMatrix
then
3620 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3621 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3622 glTranslatef(-sX
, -sY
, 0);
3626 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3627 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3632 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3633 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3634 glClear(GL_COLOR_BUFFER_BIT);
3637 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3640 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3641 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3642 drawOther('items', @g_Items_Draw
);
3643 drawOther('weapons', @g_Weapon_Draw
);
3644 drawOther('shells', @g_Player_DrawShells
);
3645 drawOther('drawall', @g_Player_DrawAll
);
3646 drawOther('corpses', @g_Player_DrawCorpses
);
3647 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3648 drawOther('monsters', @g_Monsters_Draw
);
3649 drawOther('itemdrop', @g_Items_DrawDrop
);
3650 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3651 drawOther('gfx', @g_GFX_Draw
);
3652 drawOther('flags', @g_Map_DrawFlags
);
3653 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3654 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3655 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3656 drawOther('dynlights', @renderDynLightsInternal
);
3658 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3660 renderAmbientQuad(hasAmbient
, ambColor
);
3664 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3667 if g_debug_HealthBar
then
3669 g_Monsters_DrawHealth();
3670 g_Player_DrawHealth();
3673 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3677 procedure DrawMapView(x
, y
, w
, h
: Integer);
3684 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3685 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3692 fixViewportForScale();
3693 renderMapInternal(-bx
, -by
, true);
3699 procedure DrawPlayer(p
: TPlayer
);
3701 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3705 if (p
= nil) or (p
.FDummy
) then
3708 g_Map_DrawBack(0, 0);
3713 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3714 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3720 camObj
:= p
.getCameraObj();
3721 camObj
.lerp(gLerpFactor
, fX
, fY
);
3722 px
:= fX
+ PLAYER_RECT_CX
;
3723 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3725 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3727 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3728 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3730 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3731 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3733 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3734 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3737 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3740 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3741 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3744 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3749 // scaled, ignore level bounds
3750 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3751 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3756 sWidth
:= gPlayerScreenSize
.X
;
3757 sHeight
:= gPlayerScreenSize
.Y
;
3758 fixViewportForScale();
3760 i
:= py
- (sY
+ sHeight
div 2);
3761 if (p
.IncCam
> 0) then
3763 // clamp to level bounds
3764 if (sY
- p
.IncCam
< 0) then
3765 p
.IncCam
:= nclamp(sY
, 0, 120);
3766 // clamp around player position
3768 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3770 else if (p
.IncCam
< 0) then
3772 // clamp to level bounds
3773 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3774 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3775 // clamp around player position
3777 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3780 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3782 if (not g_dbg_ignore_bounds
) then
3784 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3785 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3786 if (sX
< 0) then sX
:= 0;
3787 if (sY
< 0) then sY
:= 0;
3790 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3791 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3793 //r_smallmap_h: 0: left; 1: center; 2: right
3794 //r_smallmap_v: 0: top; 1: center; 2: bottom
3796 if (gMapInfo
.Width
= sWidth
) then
3800 else if (gMapInfo
.Width
< sWidth
) then
3802 case r_smallmap_h
of
3803 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3804 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3805 else sX
:= 0; // left
3809 if (gMapInfo
.Height
= sHeight
) then
3813 else if (gMapInfo
.Height
< sHeight
) then
3815 case r_smallmap_v
of
3816 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3817 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3818 else sY
:= 0; // top
3824 p
.viewPortW
:= sWidth
;
3825 p
.viewPortH
:= sHeight
;
3827 {$IFDEF ENABLE_HOLMES}
3828 if (p
= gPlayer1
) then
3830 g_Holmes_plrViewPos(sX
, sY
);
3831 g_Holmes_plrViewSize(sWidth
, sHeight
);
3835 renderMapInternal(-c
, -d
, true);
3837 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3838 case gPlayerIndicator
of
3840 p
.DrawIndicator(_RGB(255, 255, 255));
3843 for i
:= 0 to High(gPlayers
) do
3844 if gPlayers
[i
] <> nil then
3845 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3846 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3847 if gPlayerIndicatorStyle
= 1 then
3848 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3849 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3853 for a := 0 to High(gCollideMap) do
3854 for b := 0 to High(gCollideMap[a]) do
3857 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3859 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3863 1: e_DrawPoint(1, b, a, 200, 200, 200);
3864 2: e_DrawPoint(1, b, a, 64, 64, 255);
3865 3: e_DrawPoint(1, b, a, 255, 0, 255);
3875 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3876 if g_Debug_Player
then
3877 g_Player_DrawDebug(p
);
3881 procedure drawProfilers ();
3886 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3887 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3888 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3891 procedure g_Game_Draw();
3898 plView1
, plView2
: TPlayer
;
3901 if gExit
= EXIT_QUIT
then Exit
;
3903 Time
:= sys_GetTicks() {div 1000};
3904 FPSCounter
:= FPSCounter
+1;
3905 if Time
- FPSTime
>= 1000 then
3912 e_SetRendertarget(True);
3913 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3915 if gGameOn
or (gState
= STATE_FOLD
) then
3917 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3919 gSpectMode
:= SPECT_NONE
;
3920 if not gRevertPlayers
then
3922 plView1
:= gPlayer1
;
3923 plView2
:= gPlayer2
;
3927 plView1
:= gPlayer2
;
3928 plView2
:= gPlayer1
;
3932 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3934 gSpectMode
:= SPECT_NONE
;
3935 if gPlayer2
= nil then
3938 plView1
:= gPlayer2
;
3947 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3948 gSpectMode
:= SPECT_STATS
;
3950 if gSpectMode
= SPECT_PLAYERS
then
3951 if gPlayers
<> nil then
3953 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3954 if plView1
= nil then
3956 gSpectPID1
:= GetActivePlayerID_Next();
3957 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3959 if gSpectViewTwo
then
3961 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3962 if plView2
= nil then
3964 gSpectPID2
:= GetActivePlayerID_Next();
3965 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3970 if gSpectMode
= SPECT_MAPVIEW
then
3972 // Ðåæèì ïðîñìîòðà êàðòû
3974 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3975 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3976 gHearPoint1
.Active
:= True;
3977 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3978 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3979 gHearPoint2
.Active
:= False;
3983 Split
:= (plView1
<> nil) and (plView2
<> nil);
3985 // Òî÷êè ñëóõà èãðîêîâ
3986 if plView1
<> nil then
3988 gHearPoint1
.Active
:= True;
3989 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3990 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3992 gHearPoint1
.Active
:= False;
3993 if plView2
<> nil then
3995 gHearPoint2
.Active
:= True;
3996 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3997 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3999 gHearPoint2
.Active
:= False;
4001 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4002 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4005 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
4006 if gScreenHeight
mod 2 = 0 then
4007 Dec(gPlayerScreenSize
.Y
);
4010 gPlayerScreenSize
.Y
:= gScreenHeight
;
4013 if gScreenHeight
mod 2 = 0 then
4014 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
4016 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4018 DrawPlayer(plView1
);
4019 gPlayer1ScreenCoord
.X
:= sX
;
4020 gPlayer1ScreenCoord
.Y
:= sY
;
4024 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4026 DrawPlayer(plView2
);
4027 gPlayer2ScreenCoord
.X
:= sX
;
4028 gPlayer2ScreenCoord
.Y
:= sY
;
4031 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
4034 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
4037 {$IFDEF ENABLE_HOLMES}
4039 if (g_holmes_enabled
) then g_Holmes_Draw();
4042 if MessageText
<> '' then
4046 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
4048 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4049 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4051 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4052 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4055 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4058 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4060 // Draw spectator GUI
4063 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4066 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4068 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4070 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4072 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4073 if gSpectMode
= SPECT_STATS
then
4075 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4076 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4078 if gSpectMode
= SPECT_MAPVIEW
then
4080 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4081 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4082 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4083 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4084 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4086 if gSpectMode
= SPECT_PLAYERS
then
4088 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4089 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4090 if gSpectViewTwo
then
4092 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4093 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4094 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4095 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4099 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4100 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4106 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4108 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4109 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4111 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4112 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4113 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4118 if (gState
= STATE_MENU
) then
4120 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4121 // F3 at menu will show game loading dialog
4122 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4123 if (g_ActiveWindow
<> nil) then
4125 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4126 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4130 // F3 at titlepic will show game loading dialog
4131 if e_KeyPressed(IK_F3
) then
4133 g_Menu_Show_LoadMenu(true);
4134 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4139 if gState
= STATE_FOLD
then
4141 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4144 if gState
= STATE_INTERCUSTOM
then
4146 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4148 back
:= 'TEXTURE_endpic';
4149 if not g_Texture_Get(back
, ID
) then
4150 back
:= _lc
[I_TEXTURE_ENDPIC
];
4155 DrawMenuBackground(back
);
4159 if g_ActiveWindow
<> nil then
4161 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4162 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4166 if gState
= STATE_INTERSINGLE
then
4168 if EndingGameCounter
> 0 then
4170 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4176 DrawMenuBackground(back
);
4180 if g_ActiveWindow
<> nil then
4182 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4183 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4188 if gState
= STATE_ENDPIC
then
4191 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4192 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4194 if g_ActiveWindow
<> nil then
4196 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4197 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4201 if gState
= STATE_SLIST
then
4203 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4205 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4206 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4208 DrawMenuBackground('MENU_BACKGROUND');
4209 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4210 g_Serverlist_Draw(slCurrent
, slTable
);
4214 if g_ActiveWindow
<> nil then
4218 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4219 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4221 g_ActiveWindow
.Draw();
4228 if g_debug_Sounds
and gGameOn
then
4230 for w
:= 0 to High(e_SoundsArray
) do
4231 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4232 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4237 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4238 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4241 if gGameOn
and gShowTime
then
4242 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4244 if gGameOn
then drawProfilers();
4246 // TODO: draw this after the FBO and remap mouse click coordinates
4248 {$IFDEF ENABLE_HOLMES}
4252 // blit framebuffer to screen
4254 e_SetRendertarget(False);
4255 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4256 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4258 // draw the overlay stuff on top of it
4263 procedure g_Game_Quit();
4265 g_Game_StopAllSounds(True);
4268 g_PlayerModel_FreeData();
4269 g_Texture_DeleteAll();
4270 g_Frames_DeleteAll();
4272 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4275 if NetInitDone
then g_Net_Free
;
4277 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4278 if gMapToDelete
<> '' then
4279 g_Game_DeleteTestMap();
4285 procedure g_FatalError(Text: String);
4287 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4288 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4290 gExit
:= EXIT_SIMPLE
;
4291 if gGameOn
then EndGame
;
4294 procedure g_SimpleError(Text: String);
4296 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4297 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4300 procedure g_Game_SetupScreenSize();
4302 RES_FACTOR
= 4.0 / 3.0;
4308 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4309 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4310 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4311 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4313 gPlayerScreenSize
.Y
:= gScreenHeight
;
4315 // Ðàçìåð çàäíåãî ïëàíà:
4316 if BackID
<> DWORD(-1) then
4319 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4320 (gScreenHeight
*s
> gMapInfo
.Height
) then
4322 gBackSize
.X
:= gScreenWidth
;
4323 gBackSize
.Y
:= gScreenHeight
;
4327 e_GetTextureSize(BackID
, @bw
, @bh
);
4328 rf
:= Single(bw
) / Single(bh
);
4329 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4330 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4331 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4332 if (s
< 1.0) then s
:= 1.0;
4333 gBackSize
.X
:= Round(bw
*s
);
4334 gBackSize
.Y
:= Round(bh
*s
);
4339 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4341 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4344 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4346 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4347 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4350 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4353 if gPlayer1
= nil then
4355 if g_Game_IsClient
then
4357 if NetPlrUID1
> -1 then
4358 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4362 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4363 Team
:= gPlayer1Settings
.Team
;
4365 // Ñîçäàíèå ïåðâîãî èãðîêà:
4366 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4367 gPlayer1Settings
.Color
,
4369 if gPlayer1
= nil then
4370 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4373 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4374 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4375 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4376 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4377 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4378 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4379 if g_Game_IsServer
and g_Game_IsNet
then
4380 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4381 gPlayer1
.Respawn(False, True);
4382 g_Net_Slist_ServerPlayerComes();
4387 if gPlayer2
= nil then
4389 if g_Game_IsClient
then
4391 if NetPlrUID2
> -1 then
4392 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4396 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4397 Team
:= gPlayer2Settings
.Team
;
4399 // Ñîçäàíèå âòîðîãî èãðîêà:
4400 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4401 gPlayer2Settings
.Color
,
4403 if gPlayer2
= nil then
4404 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4407 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4408 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4409 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4410 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4411 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4412 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4413 if g_Game_IsServer
and g_Game_IsNet
then
4414 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4415 gPlayer2
.Respawn(False, True);
4416 g_Net_Slist_ServerPlayerComes();
4423 procedure g_Game_RemovePlayer();
4427 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4428 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4433 if g_Game_IsServer
then
4436 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4437 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4438 g_Player_Remove(Pl
.UID
);
4439 g_Net_Slist_ServerPlayerLeaves();
4443 gSpectLatchPID2
:= Pl
.UID
;
4451 if g_Game_IsServer
then
4454 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4455 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4456 g_Player_Remove(Pl
.UID
);
4457 g_Net_Slist_ServerPlayerLeaves();
4460 gSpectLatchPID1
:= Pl
.UID
;
4462 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4466 g_Net_Slist_ServerPlayerLeaves();
4469 procedure g_Game_Spectate();
4471 g_Game_RemovePlayer();
4472 if gPlayer1
<> nil then
4473 g_Game_RemovePlayer();
4476 procedure g_Game_SpectateCenterView();
4478 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4479 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4482 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4489 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4491 g_Game_ClearLoading();
4494 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4497 gGameSettings
.GameType
:= GT_SINGLE
;
4498 gGameSettings
.MaxLives
:= 0;
4499 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4500 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4501 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4502 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4503 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4504 gSwitchGameMode
:= GM_SINGLE
;
4506 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4507 gLMSRespawnTime
:= 0;
4508 gSpectLatchPID1
:= 0;
4509 gSpectLatchPID2
:= 0;
4511 g_Game_ExecuteEvent('ongamestart');
4513 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4514 g_Game_SetupScreenSize();
4516 // Ñîçäàíèå ïåðâîãî èãðîêà:
4517 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4518 gPlayer1Settings
.Color
,
4519 gPlayer1Settings
.Team
, False));
4520 if gPlayer1
= nil then
4522 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4526 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4527 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4528 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4529 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4530 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4533 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4536 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4537 gPlayer2Settings
.Color
,
4538 gPlayer2Settings
.Team
, False));
4539 if gPlayer2
= nil then
4541 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4545 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4546 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4547 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4548 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4549 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4553 // Çàãðóçêà è çàïóñê êàðòû:
4554 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4556 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4557 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4561 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4565 for i
:= nPl
+1 to nPlayers
do
4566 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4569 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4570 TimeLimit
, ScoreLimit
: Word;
4572 Options
: LongWord; nPlayers
: Byte);
4578 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4580 g_Game_ClearLoading();
4583 gGameSettings
.GameType
:= GT_CUSTOM
;
4584 gGameSettings
.GameMode
:= GameMode
;
4585 gSwitchGameMode
:= GameMode
;
4586 gGameSettings
.TimeLimit
:= TimeLimit
;
4587 gGameSettings
.ScoreLimit
:= ScoreLimit
;
4588 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4589 gGameSettings
.Options
:= Options
;
4591 gCoopTotalMonstersKilled
:= 0;
4592 gCoopTotalSecretsFound
:= 0;
4593 gCoopTotalMonsters
:= 0;
4594 gCoopTotalSecrets
:= 0;
4598 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4599 gLMSRespawnTime
:= 0;
4600 gSpectLatchPID1
:= 0;
4601 gSpectLatchPID2
:= 0;
4603 g_Game_ExecuteEvent('ongamestart');
4605 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4606 g_Game_SetupScreenSize();
4608 // Ðåæèì íàáëþäàòåëÿ:
4609 if nPlayers
= 0 then
4616 if nPlayers
>= 1 then
4618 // Ñîçäàíèå ïåðâîãî èãðîêà:
4619 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4620 gPlayer1Settings
.Color
,
4621 gPlayer1Settings
.Team
, False));
4622 if gPlayer1
= nil then
4624 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4628 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4629 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4630 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4631 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4632 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4636 if nPlayers
>= 2 then
4638 // Ñîçäàíèå âòîðîãî èãðîêà:
4639 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4640 gPlayer2Settings
.Color
,
4641 gPlayer2Settings
.Team
, False));
4642 if gPlayer2
= nil then
4644 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4648 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4649 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4650 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4651 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4652 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4656 // Çàãðóçêà è çàïóñê êàðòû:
4657 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4659 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4663 // Íåò òî÷åê ïîÿâëåíèÿ:
4664 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4665 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4666 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4667 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4668 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4670 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4674 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4678 for i
:= nPl
+1 to nPlayers
do
4679 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4682 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4683 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
4684 Options
: LongWord; nPlayers
: Byte;
4685 IPAddr
: LongWord; Port
: Word);
4688 g_Net_Slist_ServerClosed();
4690 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4692 g_Game_ClearLoading();
4697 gGameSettings
.GameType
:= GT_SERVER
;
4698 gGameSettings
.GameMode
:= GameMode
;
4699 gSwitchGameMode
:= GameMode
;
4700 gGameSettings
.TimeLimit
:= TimeLimit
;
4701 gGameSettings
.ScoreLimit
:= ScoreLimit
;
4702 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4703 gGameSettings
.Options
:= Options
;
4705 gCoopTotalMonstersKilled
:= 0;
4706 gCoopTotalSecretsFound
:= 0;
4707 gCoopTotalMonsters
:= 0;
4708 gCoopTotalSecrets
:= 0;
4712 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4713 gLMSRespawnTime
:= 0;
4714 gSpectLatchPID1
:= 0;
4715 gSpectLatchPID2
:= 0;
4717 g_Game_ExecuteEvent('ongamestart');
4719 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4720 g_Game_SetupScreenSize();
4722 // Ðåæèì íàáëþäàòåëÿ:
4723 if nPlayers
= 0 then
4729 if nPlayers
>= 1 then
4731 // Ñîçäàíèå ïåðâîãî èãðîêà:
4732 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4733 gPlayer1Settings
.Color
,
4734 gPlayer1Settings
.Team
, False));
4735 if gPlayer1
= nil then
4737 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4741 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4742 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4743 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4744 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4745 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4748 if nPlayers
>= 2 then
4750 // Ñîçäàíèå âòîðîãî èãðîêà:
4751 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4752 gPlayer2Settings
.Color
,
4753 gPlayer2Settings
.Team
, False));
4754 if gPlayer2
= nil then
4756 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4760 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4761 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4762 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4763 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4764 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4767 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4768 if NetForwardPorts
then
4769 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4772 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4774 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4778 g_Net_Slist_Set(NetMasterList
);
4780 g_Net_Slist_ServerStarted();
4782 // Çàãðóçêà è çàïóñê êàðòû:
4783 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4785 g_Net_Slist_ServerClosed();
4786 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4790 // Íåò òî÷åê ïîÿâëåíèÿ:
4791 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4792 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4793 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4794 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4795 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4797 g_Net_Slist_ServerClosed();
4798 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4802 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4805 g_Net_Slist_ServerMapStarted();
4806 NetState
:= NET_STATE_GAME
;
4809 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4824 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4825 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4827 g_Game_ClearLoading();
4832 gGameSettings
.GameType
:= GT_CLIENT
;
4834 gCoopTotalMonstersKilled
:= 0;
4835 gCoopTotalSecretsFound
:= 0;
4836 gCoopTotalMonsters
:= 0;
4837 gCoopTotalSecrets
:= 0;
4841 g_Game_ExecuteEvent('ongamestart');
4843 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4844 g_Game_SetupScreenSize();
4846 NetState
:= NET_STATE_AUTH
;
4848 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4850 // create (or update) map/resource databases
4851 g_Res_CreateDatabases(true);
4853 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4854 gLMSRespawnTime
:= 0;
4855 gSpectLatchPID1
:= 0;
4856 gSpectLatchPID2
:= 0;
4859 if not g_Net_Connect(Addr
, Port
) then
4861 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4862 NetState
:= NET_STATE_NONE
;
4866 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4868 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4873 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4874 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4875 // thank you, enet. let's ignore failures altogether then.
4876 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4878 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4880 Ptr
:= NetEvent
.packet
^.data
;
4881 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4883 enet_packet_destroy(NetEvent
.packet
);
4887 InMsg
.ReadLongWord(); // skip size
4888 MID
:= InMsg
.ReadByte();
4890 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4892 NetMyID
:= InMsg
.ReadByte();
4893 NetPlrUID1
:= InMsg
.ReadWord();
4895 WadName
:= InMsg
.ReadString();
4896 Map
:= InMsg
.ReadString();
4898 gWADHash
:= InMsg
.ReadMD5();
4900 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4901 gSwitchGameMode
:= gGameSettings
.GameMode
;
4902 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
4903 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4904 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4905 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4906 T
:= InMsg
.ReadLongWord();
4908 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4909 //if newResPath = '' then
4911 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4912 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4913 if newResPath
= '' then
4915 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4916 enet_packet_destroy(NetEvent
.packet
);
4917 NetState
:= NET_STATE_NONE
;
4920 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4922 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4925 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4926 gPlayer1Settings
.Color
,
4927 gPlayer1Settings
.Team
, False));
4929 if gPlayer1
= nil then
4931 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4933 enet_packet_destroy(NetEvent
.packet
);
4934 NetState
:= NET_STATE_NONE
;
4938 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4939 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4940 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4941 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4942 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4943 gPlayer1
.UID
:= NetPlrUID1
;
4944 gPlayer1
.Reset(True);
4946 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4948 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4950 enet_packet_destroy(NetEvent
.packet
);
4951 NetState
:= NET_STATE_NONE
;
4959 enet_packet_destroy(NetEvent
.packet
);
4963 enet_packet_destroy(NetEvent
.packet
);
4967 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4970 if (NetEvent
.data
<= NET_DISC_MAX
) then
4971 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4972 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4979 ProcessLoading(True);
4980 if g_Net_UserRequestExit() then
4989 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4990 NetState
:= NET_STATE_NONE
;
4995 NetState
:= NET_STATE_GAME
;
4996 MC_SEND_FullStateRequest
;
4997 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
5001 lastAsMegaWad
: Boolean = false;
5003 procedure g_Game_ChangeMap(const MapPath
: String);
5007 g_Game_ClearLoading();
5009 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
5010 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5011 if gExitByTrigger
then
5014 gExitByTrigger
:= False;
5016 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
5017 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
5020 procedure g_Game_Restart();
5024 if g_Game_IsClient
then
5026 map
:= g_ExtractFileName(gMapInfo
.Map
);
5027 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
5031 g_Game_ClearLoading();
5032 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
5035 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
5037 NewWAD
, ResName
: String;
5041 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
5042 g_Player_RemoveAllCorpses();
5044 if (not g_Game_IsClient
) and
5045 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
5046 (gGameSettings
.GameMode
<> GM_SINGLE
) then
5048 if gSwitchGameMode
= GM_CTF
then
5049 gGameSettings
.MaxLives
:= 0;
5050 gGameSettings
.GameMode
:= gSwitchGameMode
;
5053 gSwitchGameMode
:= gGameSettings
.GameMode
;
5055 g_Player_ResetTeams();
5057 lastAsMegaWad
:= asMegawad
;
5058 if isWadPath(Map
) then
5060 NewWAD
:= g_ExtractWadName(Map
);
5061 ResName
:= g_ExtractFileName(Map
);
5062 if g_Game_IsServer
then
5064 nws
:= findDiskWad(NewWAD
);
5065 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5068 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5069 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5073 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5074 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5076 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5077 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5079 if (length(nws
) = 0) then
5081 ResName
:= ''; // failed
5086 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5087 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5088 g_Game_LoadWAD(NewWAD
);
5093 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5094 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5099 NewWAD
:= gGameSettings
.WAD
;
5105 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5107 if (ResName
<> '') and (NewWAD
<> '') then
5109 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5110 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5114 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5116 gState
:= STATE_NONE
;
5117 g_ActiveWindow
:= nil;
5123 if gGameSettings
.GameMode
= GM_CTF
then
5125 g_Map_ResetFlag(FLAG_RED
);
5126 g_Map_ResetFlag(FLAG_BLUE
);
5127 // CTF, à ôëàãîâ íåò:
5128 if not g_Map_HaveFlagPoints() then
5129 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5134 gState
:= STATE_MENU
;
5139 gPauseMain
:= false;
5140 gPauseHolmes
:= false;
5141 NetTimeToUpdate
:= 1;
5142 NetTimeToReliable
:= 0;
5143 NetTimeToMaster
:= NetMasterRate
;
5144 gSpectLatchPID1
:= 0;
5145 gSpectLatchPID2
:= 0;
5146 gMissionFailed
:= False;
5149 gCoopMonstersKilled
:= 0;
5150 gCoopSecretsFound
:= 0;
5152 gVoteInProgress
:= False;
5153 gVotePassed
:= False;
5159 if not gGameOn
then Exit
;
5161 g_Game_SpectateCenterView();
5163 if g_Game_IsServer
then
5165 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5167 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5168 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5169 gLMSSoftSpawn
:= True;
5170 if g_Game_IsNet
then
5171 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5175 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5176 gLMSRespawnTime
:= 0;
5180 if NetMode
= NET_SERVER
then
5182 // reset full state flags
5183 if NetClients
<> nil then
5184 for I
:= 0 to High(NetClients
) do
5185 NetClients
[I
].FullUpdateSent
:= False;
5187 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5190 g_Net_Slist_ServerMapStarted();
5192 if NetClients
<> nil then
5193 for I
:= 0 to High(NetClients
) do
5194 if NetClients
[I
].Used
then
5196 NetClients
[I
].Voted
:= False;
5197 if NetClients
[I
].RequestedFullUpdate
then
5199 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5200 NetClients
[I
].RequestedFullUpdate
:= False;
5204 g_Net_UnbanNonPerm();
5209 gCoopTotalMonstersKilled
:= 0;
5210 gCoopTotalSecretsFound
:= 0;
5211 gCoopTotalMonsters
:= 0;
5212 gCoopTotalSecrets
:= 0;
5216 g_Game_ExecuteEvent('onmapstart');
5219 procedure SetFirstLevel
;
5223 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5224 if MapList
= nil then
5227 SortSArray(MapList
);
5228 gNextMap
:= MapList
[Low(MapList
)];
5233 procedure g_Game_ExitLevel(const Map
: AnsiString);
5237 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5238 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5239 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5240 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5242 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5243 if gGameSettings
.GameType
= GT_SINGLE
then
5244 gExit
:= EXIT_ENDLEVELSINGLE
5245 else // Âûøëè â âûõîä â Ñâîåé èãðå
5247 gExit
:= EXIT_ENDLEVELCUSTOM
;
5248 if gGameSettings
.GameMode
= GM_COOP
then
5249 g_Player_RememberAll
;
5251 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5254 if gGameSettings
.GameMode
= GM_COOP
then
5257 gStatsPressed
:= True;
5258 gNextMap
:= 'MAP01';
5260 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5263 if g_Game_IsNet
then
5265 MH_SEND_GameStats();
5266 MH_SEND_CoopStats();
5272 procedure g_Game_RestartLevel();
5276 if gGameSettings
.GameMode
= GM_SINGLE
then
5281 gExit
:= EXIT_ENDLEVELCUSTOM
;
5282 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5286 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5288 gWAD
{, xwad}: String;
5291 if not g_Game_IsClient
then Exit
;
5292 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5294 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5299 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5303 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5306 g_Game_LoadWAD(NewWAD
);
5310 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5311 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5314 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5315 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5319 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5323 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5324 g_Game_LoadWAD(NewWAD);
5328 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5330 i
, n
, nb
, nr
: Integer;
5332 if not g_Game_IsServer
then Exit
;
5333 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5334 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5335 gLMSRespawnTime
:= 0;
5338 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5340 gMissionFailed
:= True;
5341 g_Game_RestartLevel
;
5345 n
:= 0; nb
:= 0; nr
:= 0;
5346 for i
:= Low(gPlayers
) to High(gPlayers
) do
5347 if (gPlayers
[i
] <> nil) and
5348 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5349 (gPlayers
[i
] is TBot
)) then
5352 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5353 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5356 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5358 // wait a second until the fuckers finally decide to join
5359 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5360 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5361 gLMSSoftSpawn
:= NoMapRestart
;
5362 if g_Game_IsNet
then
5363 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5367 g_Player_RemoveAllCorpses
;
5368 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5369 if g_Game_IsNet
then
5370 MH_SEND_GameEvent(NET_EV_LMS_START
);
5372 for i
:= Low(gPlayers
) to High(gPlayers
) do
5374 if gPlayers
[i
] = nil then continue
;
5375 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5376 // don't touch normal spectators
5377 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5379 gPlayers
[i
].FNoRespawn
:= True;
5380 gPlayers
[i
].Lives
:= 0;
5381 if g_Game_IsNet
then
5382 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5385 gPlayers
[i
].FNoRespawn
:= False;
5386 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5387 gPlayers
[i
].Respawn(False, True);
5388 if gGameSettings
.GameMode
= GM_COOP
then
5390 gPlayers
[i
].Frags
:= 0;
5391 gPlayers
[i
].Assists
:= 0;
5392 gPlayers
[i
].RecallState
;
5394 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5395 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5396 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5397 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5400 g_Items_RestartRound();
5402 gLMSSoftSpawn
:= False;
5405 function g_Game_GetFirstMap(WAD
: String): String;
5409 MapList
:= g_Map_GetMapsList(WAD
);
5410 if MapList
= nil then
5413 SortSArray(MapList
);
5414 Result
:= MapList
[Low(MapList
)];
5416 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5422 function g_Game_GetNextMap(): String;
5429 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5430 if MapList
= nil then
5433 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5435 SortSArray(MapList
);
5437 for I
:= Low(MapList
) to High(MapList
) do
5438 if Map
= MapList
[I
] then
5444 if MapIndex
<> -255 then
5446 if MapIndex
= High(MapList
) then
5447 Result
:= MapList
[Low(MapList
)]
5449 Result
:= MapList
[MapIndex
+ 1];
5451 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5457 procedure g_Game_NextLevel();
5459 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5460 gExit
:= EXIT_ENDLEVELCUSTOM
5463 gExit
:= EXIT_ENDLEVELSINGLE
;
5467 if gNextMap
<> '' then Exit
;
5468 gNextMap
:= g_Game_GetNextMap();
5471 function g_Game_IsTestMap(): Boolean;
5473 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5476 procedure g_Game_DeleteTestMap();
5479 //MapName: AnsiString;
5487 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5488 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5489 if (a
= 0) then exit
;
5491 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5492 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5493 Delete(gMapToDelete
, 1, a
+5);
5494 gMapToDelete
:= UpperCase(gMapToDelete
);
5496 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5499 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5500 if MapName <> TEST_MAP_NAME then
5503 if not gTempDelete then
5505 time := g_GetFileTime(WadName);
5506 WAD := TWADFile.Create();
5509 if not WAD.ReadFile(WadName) then
5510 begin // Íåò òàêîãî WAD-ôàéëà
5515 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5517 MapList := WAD.GetResourcesList('');
5519 if MapList <> nil then
5520 for a := 0 to High(MapList) do
5521 if MapList[a] = MapName then
5523 // Óäàëÿåì è ñîõðàíÿåì:
5524 WAD.RemoveResource('', MapName);
5525 WAD.SaveTo(WadName);
5530 g_SetFileTime(WadName, time);
5533 if gTempDelete
then DeleteFile(WadName
);
5536 procedure GameCVars(P
: SSArray
);
5539 stat
: TPlayerStatArray
;
5542 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5546 if Length(P
) > 1 then
5551 gsGameFlags
:= gsGameFlags
or Flag
5553 gsGameFlags
:= gsGameFlags
and (not Flag
);
5555 if g_Game_IsServer
then
5558 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5560 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5561 if g_Game_IsNet
then MH_SEND_GameSettings
;
5565 if LongBool(gsGameFlags
and Flag
) then
5566 g_Console_Add(_lc
[OnMsg
])
5568 g_Console_Add(_lc
[OffMsg
]);
5570 if OnMapChange
and g_Game_IsServer
then
5571 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5576 cmd
:= LowerCase(P
[0]);
5578 if cmd
= 'g_gamemode' then
5580 if (Length(P
) > 1) then
5582 a
:= g_Game_TextToMode(P
[1]);
5583 if a
= GM_SINGLE
then a
:= GM_COOP
;
5584 gsGameMode
:= g_Game_ModeToText(a
);
5585 if g_Game_IsServer
then
5587 gSwitchGameMode
:= a
;
5588 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5589 (gState
= STATE_INTERSINGLE
) then
5590 gSwitchGameMode
:= GM_SINGLE
;
5592 gGameSettings
.GameMode
:= gSwitchGameMode
;
5596 if gSwitchGameMode
= gGameSettings
.GameMode
then
5597 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5598 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5600 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5601 [g_Game_ModeToText(gGameSettings
.GameMode
),
5602 g_Game_ModeToText(gSwitchGameMode
)]));
5604 else if cmd
= 'g_friendlyfire' then
5606 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5608 else if cmd
= 'g_friendly_absorb_damage' then
5610 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5612 else if cmd
= 'g_friendly_hit_trace' then
5614 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5616 else if cmd
= 'g_friendly_hit_projectile' then
5618 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5620 else if cmd
= 'g_weaponstay' then
5622 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5624 else if cmd
= 'g_allow_exit' then
5626 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5628 else if cmd
= 'g_allow_monsters' then
5630 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5632 else if cmd
= 'g_allow_dropflag' then
5634 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5636 else if cmd
= 'g_throw_flag' then
5638 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5640 else if cmd
= 'g_bot_vsplayers' then
5642 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5644 else if cmd
= 'g_bot_vsmonsters' then
5646 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5648 else if cmd
= 'g_dm_keys' then
5650 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5652 else if cmd
= 'g_gameflags' then
5654 if Length(P
) > 1 then
5656 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5657 if g_Game_IsServer
then
5659 gGameSettings
.Options
:= gsGameFlags
;
5660 if g_Game_IsNet
then MH_SEND_GameSettings
;
5664 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5666 else if cmd
= 'g_warmup_time' then
5668 if Length(P
) > 1 then
5670 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5671 if g_Game_IsServer
then
5673 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5674 // extend warmup if it's already going
5675 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5677 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5678 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5680 if g_Game_IsNet
then MH_SEND_GameSettings
;
5684 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5685 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5687 else if cmd
= 'g_spawn_invul' then
5689 if Length(P
) > 1 then
5691 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5692 if g_Game_IsServer
then
5694 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5695 if g_Game_IsNet
then MH_SEND_GameSettings
;
5699 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5701 else if cmd
= 'g_item_respawn_time' then
5703 if Length(P
) > 1 then
5705 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5706 if g_Game_IsServer
then
5708 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5709 if g_Game_IsNet
then MH_SEND_GameSettings
;
5713 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5714 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5716 else if cmd
= 'sv_intertime' then
5718 if (Length(P
) > 1) then
5719 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5721 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5723 else if cmd
= 'g_max_particles' then
5725 if Length(p
) = 2 then
5727 a
:= Max(0, StrToIntDef(p
[1], 0));
5730 else if Length(p
) = 1 then
5732 e_LogWritefln('%s', [g_GFX_GetMax()])
5736 e_LogWritefln('usage: %s <n>', [cmd
])
5739 else if cmd
= 'g_max_shells' then
5741 if Length(p
) = 2 then
5743 a
:= Max(0, StrToIntDef(p
[1], 0));
5746 else if Length(p
) = 1 then
5748 e_LogWritefln('%s', [g_Shells_GetMax()])
5752 e_LogWritefln('usage: %s <n>', [cmd
])
5755 else if cmd
= 'g_max_gibs' then
5757 if Length(p
) = 2 then
5759 a
:= Max(0, StrToIntDef(p
[1], 0));
5762 else if Length(p
) = 1 then
5764 e_LogWritefln('%s', [g_Gibs_GetMax()])
5768 e_LogWritefln('usage: %s <n>', [cmd
])
5771 else if cmd
= 'g_max_corpses' then
5773 if Length(p
) = 2 then
5775 a
:= Max(0, StrToIntDef(p
[1], 0));
5778 else if Length(p
) = 1 then
5780 e_LogWritefln('%s', [g_Corpses_GetMax()])
5784 e_LogWritefln('usage: %s <n>', [cmd
])
5787 else if cmd
= 'g_force_model' then
5789 if Length(p
) = 2 then
5791 a
:= StrToIntDef(p
[1], 0);
5792 g_Force_Model_Set(a
);
5793 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
5795 for a
:= Low(gPlayers
) to High(gPlayers
) do
5797 if (gPlayers
[a
] <> nil) then
5799 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
5801 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
5803 gPlayers
[a
].setModel(g_Forced_Model_GetName());
5807 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
5809 for a
:= Low(gPlayers
) to High(gPlayers
) do
5811 if (gPlayers
[a
] <> nil) then
5813 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
5815 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
5817 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
5823 else if cmd
= 'g_force_model_name' then
5825 if (Length(P
) > 1) then
5827 cmd
:= b_Text_Unformat(P
[1]);
5828 g_Forced_Model_SetName(cmd
);
5829 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
5831 for a
:= Low(gPlayers
) to High(gPlayers
) do
5833 if (gPlayers
[a
] <> nil) then
5835 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
5837 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
5839 gPlayers
[a
].setModel(g_Forced_Model_GetName());
5845 else if cmd
= 'g_scorelimit' then
5847 if Length(P
) > 1 then
5849 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
5851 if g_Game_IsServer
then
5854 if gGameSettings
.GameMode
= GM_DM
then
5856 stat
:= g_Player_GetStats();
5858 for a
:= 0 to High(stat
) do
5859 if stat
[a
].Frags
> b
then
5863 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
5865 // if someone has a higher score, set it to that instead
5866 gsScoreLimit
:= max(gsScoreLimit
, b
);
5867 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
5869 if g_Game_IsNet
then MH_SEND_GameSettings
;
5873 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
5875 else if cmd
= 'g_timelimit' then
5877 if Length(P
) > 1 then
5879 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5880 if g_Game_IsServer
then
5882 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5883 if g_Game_IsNet
then MH_SEND_GameSettings
;
5886 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5887 [gsTimeLimit
div 3600,
5888 (gsTimeLimit
div 60) mod 60,
5889 gsTimeLimit
mod 60]));
5891 else if cmd
= 'g_max_bots' then
5893 if Length(P
) > 1 then
5894 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
5895 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
5897 else if cmd
= 'g_maxlives' then
5899 if Length(P
) > 1 then
5901 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5902 if g_Game_IsServer
then
5904 gGameSettings
.MaxLives
:= gsMaxLives
;
5905 if g_Game_IsNet
then MH_SEND_GameSettings
;
5909 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5913 procedure PlayerSettingsCVars(P
: SSArray
);
5918 function ParseTeam(s
: string): Byte;
5922 'red', '1': result
:= TEAM_RED
;
5923 'blue', '2': result
:= TEAM_BLUE
;
5924 else result
:= TEAM_NONE
;
5928 cmd
:= LowerCase(P
[0]);
5932 if (Length(P
) > 1) then
5934 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5935 if g_Game_IsClient
then
5936 MC_SEND_PlayerSettings
5937 else if gGameOn
and (gPlayer1
<> nil) then
5939 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5940 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5946 if (Length(P
) > 1) then
5948 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5949 if g_Game_IsClient
then
5950 MC_SEND_PlayerSettings
5951 else if gGameOn
and (gPlayer2
<> nil) then
5953 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5954 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5960 if Length(P
) > 3 then
5962 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5963 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5964 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5965 if g_Game_IsClient
then
5966 MC_SEND_PlayerSettings
5967 else if gGameOn
and (gPlayer1
<> nil) then
5969 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5970 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5976 if Length(P
) > 3 then
5978 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5979 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5980 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5981 if g_Game_IsClient
then
5982 MC_SEND_PlayerSettings
5983 else if gGameOn
and (gPlayer2
<> nil) then
5985 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5986 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5992 if (Length(P
) > 1) then
5994 gPlayer1Settings
.Model
:= P
[1];
5995 if g_Game_IsClient
then
5996 MC_SEND_PlayerSettings
5997 else if gGameOn
and (gPlayer1
<> nil) then
5999 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
6000 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
6001 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
6007 if (Length(P
) > 1) then
6009 gPlayer2Settings
.Model
:= P
[1];
6010 if g_Game_IsClient
then
6011 MC_SEND_PlayerSettings
6012 else if gGameOn
and (gPlayer2
<> nil) then
6014 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
6015 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
6016 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
6022 // TODO: switch teams if in game or store this separately
6023 if (Length(P
) > 1) then
6025 team
:= ParseTeam(P
[1]);
6026 if team
= TEAM_NONE
then
6027 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6028 else if not gGameOn
and not g_Game_IsNet
then
6029 gPlayer1Settings
.Team
:= team
6031 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
6036 // TODO: switch teams if in game or store this separately
6037 if (Length(P
) > 1) then
6039 team
:= ParseTeam(P
[1]);
6040 if team
= TEAM_NONE
then
6041 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6042 else if not gGameOn
and not g_Game_IsNet
then
6043 gPlayer2Settings
.Team
:= team
6045 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
6050 if (Length(P
) = 2) then
6051 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
6055 if (Length(P
) = 2) then
6056 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
6060 if (Length(P
) = 2) then
6061 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6065 if (Length(P
) = 2) then
6066 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6070 if (Length(P
) = 2) then
6071 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6075 if (Length(P
) = 2) then
6076 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
6078 'p1_priority_kastet':
6080 if (Length(P
) = 2) then
6081 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6083 'p2_priority_kastet':
6085 if (Length(P
) = 2) then
6086 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6090 if (Length(P
) = 2) then
6091 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6095 if (Length(P
) = 2) then
6096 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6098 'p1_priority_pistol':
6100 if (Length(P
) = 2) then
6101 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6103 'p2_priority_pistol':
6105 if (Length(P
) = 2) then
6106 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6108 'p1_priority_shotgun1':
6110 if (Length(P
) = 2) then
6111 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6113 'p2_priority_shotgun1':
6115 if (Length(P
) = 2) then
6116 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6118 'p1_priority_shotgun2':
6120 if (Length(P
) = 2) then
6121 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6123 'p2_priority_shotgun2':
6125 if (Length(P
) = 2) then
6126 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6128 'p1_priority_chaingun':
6130 if (Length(P
) = 2) then
6131 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6133 'p2_priority_chaingun':
6135 if (Length(P
) = 2) then
6136 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6138 'p1_priority_rocketlauncher':
6140 if (Length(P
) = 2) then
6141 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6143 'p2_priority_rocketlauncher':
6145 if (Length(P
) = 2) then
6146 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6148 'p1_priority_plasma':
6150 if (Length(P
) = 2) then
6151 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6153 'p2_priority_plasma':
6155 if (Length(P
) = 2) then
6156 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6160 if (Length(P
) = 2) then
6161 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6165 if (Length(P
) = 2) then
6166 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6168 'p1_priority_super':
6170 if (Length(P
) = 2) then
6171 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6173 'p2_priority_super':
6175 if (Length(P
) = 2) then
6176 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6178 'p1_priority_flamethrower':
6180 if (Length(P
) = 2) then
6181 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6183 'p2_priority_flamethrower':
6185 if (Length(P
) = 2) then
6186 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6188 'p1_priority_berserk':
6190 if (Length(P
) = 2) then
6191 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6193 'p2_priority_berserk':
6195 if (Length(P
) = 2) then
6196 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6201 procedure PrintHeapStats();
6205 hs
:= GetFPCHeapStatus();
6206 e_LogWriteLn ('v===== heap status =====v');
6207 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
6208 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
6209 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
6210 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
6211 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
6212 e_LogWriteLn ('^=======================^');
6215 procedure DebugCommands(P
: SSArray
);
6222 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6223 if {gDebugMode}conIsCheatsEnabled
then
6225 cmd
:= LowerCase(P
[0]);
6226 if cmd
= 'd_window' then
6228 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6229 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6231 else if cmd
= 'd_sounds' then
6233 if (Length(P
) > 1) and
6234 ((P
[1] = '1') or (P
[1] = '0')) then
6235 g_Debug_Sounds
:= (P
[1][1] = '1');
6237 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
6239 else if cmd
= 'd_frames' then
6241 if (Length(P
) > 1) and
6242 ((P
[1] = '1') or (P
[1] = '0')) then
6243 g_Debug_Frames
:= (P
[1][1] = '1');
6245 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
6247 else if cmd
= 'd_winmsg' then
6249 if (Length(P
) > 1) and
6250 ((P
[1] = '1') or (P
[1] = '0')) then
6251 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6253 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6255 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6257 if (Length(P
) > 1) and
6258 ((P
[1] = '1') or (P
[1] = '0')) then
6259 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6261 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6263 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6265 if Length(P
) > 1 then
6267 '0': g_debug_BotAIOff
:= 0;
6268 '1': g_debug_BotAIOff
:= 1;
6269 '2': g_debug_BotAIOff
:= 2;
6270 '3': g_debug_BotAIOff
:= 3;
6273 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6275 else if cmd
= 'd_monster' then
6277 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6278 if Length(P
) < 2 then
6280 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6281 g_Console_Add('ID | Name');
6282 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6283 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6284 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6287 a
:= StrToIntDef(P
[1], 0);
6288 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6289 a
:= g_Mons_TypeIdByName(P
[1]);
6291 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6292 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6295 with gPlayer1
.Obj
do
6297 mon
:= g_Monsters_Create(a
,
6298 X
+ Rect
.X
+ (Rect
.Width
div 2),
6299 Y
+ Rect
.Y
+ Rect
.Height
,
6300 gPlayer1
.Direction
, True);
6302 if (Length(P
) > 2) and (mon
<> nil) then
6304 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6305 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6306 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6307 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6308 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6309 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6310 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6311 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6312 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6317 else if (cmd
= 'd_health') then
6319 if (Length(P
) > 1) and
6320 ((P
[1] = '1') or (P
[1] = '0')) then
6321 g_debug_HealthBar
:= (P
[1][1] = '1');
6323 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6325 else if (cmd
= 'd_player') then
6327 if (Length(P
) > 1) and
6328 ((P
[1] = '1') or (P
[1] = '0')) then
6329 g_debug_Player
:= (P
[1][1] = '1');
6331 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6333 else if (cmd
= 'd_mem') then
6339 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6343 procedure GameCheats(P
: SSArray
);
6349 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6351 g_Console_Add('not available');
6357 g_Console_Add('where is the player?!');
6360 cmd
:= LowerCase(P
[0]);
6364 plr
.GodMode
:= not plr
.GodMode
;
6365 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6368 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6369 if cmd
= 'give' then
6371 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6372 for f
:= 1 to High(P
) do
6374 cmd
:= LowerCase(P
[f
]);
6375 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6376 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6377 if cmd
= 'exit' then
6379 if gTriggers
<> nil then
6381 for a
:= 0 to High(gTriggers
) do
6383 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6385 g_Console_Add('player left the map');
6386 gExitByTrigger
:= True;
6387 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6388 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6396 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6397 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6398 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6399 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6400 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6402 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6403 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6405 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6406 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;
6408 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6409 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6411 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6412 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6414 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6415 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6417 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6418 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6419 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6421 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6422 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6423 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6424 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;
6425 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6426 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6428 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;
6429 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;
6430 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;
6431 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;
6432 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;
6433 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;
6435 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6436 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;
6438 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;
6439 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;
6441 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6443 if cmd
= 'ammo' then
6445 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6446 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6447 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6448 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6449 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6450 g_Console_Add('player got some ammo');
6454 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6455 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6457 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6458 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6460 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6461 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6463 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6464 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6466 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6468 if cmd
= 'weapons' then
6470 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6471 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6472 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6473 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6474 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6475 plr
.GiveItem(ITEM_WEAPON_BFG
);
6476 g_Console_Add('player got weapons');
6480 if cmd
= 'keys' then
6482 plr
.GiveItem(ITEM_KEY_RED
);
6483 plr
.GiveItem(ITEM_KEY_GREEN
);
6484 plr
.GiveItem(ITEM_KEY_BLUE
);
6485 g_Console_Add('player got all keys');
6489 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6494 if cmd
= 'open' then
6496 g_Console_Add('player activated sesame');
6497 g_Triggers_OpenAll();
6504 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6508 if cmd
= 'noclip' then
6511 g_Console_Add('wall hardeness adjusted');
6515 if cmd
= 'notarget' then
6517 plr
.NoTarget
:= not plr
.NoTarget
;
6518 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6522 if cmd
= 'noreload' then
6524 plr
.NoReload
:= not plr
.NoReload
;
6525 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6529 if cmd
= 'speedy' then
6531 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6532 g_Console_Add('speed adjusted');
6536 if cmd
= 'jumpy' then
6538 VEL_JUMP
:= 30-VEL_JUMP
;
6539 g_Console_Add('jump height adjusted');
6543 if cmd
= 'automap' then
6545 gShowMap
:= not gShowMap
;
6546 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6550 if cmd
= 'aimline' then
6552 gAimLine
:= not gAimLine
;
6553 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6558 procedure GameCommands(P
: SSArray
);
6564 pl
: pTNetClient
= nil;
6573 cmd
:= LowerCase(P
[0]);
6575 if cmd
= 'pause' then
6577 if (g_ActiveWindow
= nil) then
6578 g_Game_Pause(not gPauseMain
);
6580 else if cmd
= 'endgame' then
6581 gExit
:= EXIT_SIMPLE
6582 else if cmd
= 'restart' then
6584 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6586 if g_Game_IsClient
then
6588 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6593 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6595 else if cmd
= 'kick' then
6597 if g_Game_IsServer
then
6599 if Length(P
) < 2 then
6601 g_Console_Add('kick <name>');
6606 g_Console_Add('kick <name>');
6610 if g_Game_IsNet
then
6611 pl
:= g_Net_Client_ByName(P
[1]);
6614 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6615 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
6616 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6617 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6618 g_Net_Slist_ServerPlayerLeaves();
6619 end else if gPlayers
<> nil then
6620 for a
:= Low(gPlayers
) to High(gPlayers
) do
6621 if gPlayers
[a
] <> nil then
6622 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6624 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6625 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6627 gPlayers
[a
].Lives
:= 0;
6628 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6629 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6630 g_Player_Remove(gPlayers
[a
].UID
);
6631 g_Net_Slist_ServerPlayerLeaves();
6632 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6636 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6638 else if cmd
= 'kick_id' then
6640 if g_Game_IsServer
and g_Game_IsNet
then
6642 if Length(P
) < 2 then
6644 g_Console_Add('kick_id <client ID>');
6649 g_Console_Add('kick_id <client ID>');
6653 a
:= StrToIntDef(P
[1], 0);
6654 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6656 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6658 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6659 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
6660 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6661 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6662 g_Net_Slist_ServerPlayerLeaves();
6666 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6668 else if cmd
= 'kick_pid' then
6670 if g_Game_IsServer
and g_Game_IsNet
then
6672 if Length(P
) < 2 then
6674 g_Console_Add('kick_pid <player ID>');
6679 g_Console_Add('kick_pid <player ID>');
6683 a
:= StrToIntDef(P
[1], 0);
6684 pl
:= g_Net_Client_ByPlayer(a
);
6685 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6687 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6688 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
6689 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6690 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6691 g_Net_Slist_ServerPlayerLeaves();
6694 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6696 else if cmd
= 'ban' then
6698 if g_Game_IsServer
and g_Game_IsNet
then
6700 if Length(P
) < 2 then
6702 g_Console_Add('ban <name>');
6707 g_Console_Add('ban <name>');
6711 pl
:= g_Net_Client_ByName(P
[1]);
6713 g_Net_Host_Ban(pl
, False)
6715 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6717 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6719 else if cmd
= 'ban_id' then
6721 if g_Game_IsServer
and g_Game_IsNet
then
6723 if Length(P
) < 2 then
6725 g_Console_Add('ban_id <client ID>');
6730 g_Console_Add('ban_id <client ID>');
6734 a
:= StrToIntDef(P
[1], 0);
6735 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6736 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6737 g_Net_Host_Ban(pl
, False);
6739 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6741 else if cmd
= 'ban_pid' then
6743 if g_Game_IsServer
and g_Game_IsNet
then
6745 if Length(P
) < 2 then
6747 g_Console_Add('ban_pid <player ID>');
6752 g_Console_Add('ban_pid <player ID>');
6756 a
:= StrToIntDef(P
[1], 0);
6757 pl
:= g_Net_Client_ByPlayer(a
);
6758 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6759 g_Net_Host_Ban(pl
, False);
6761 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6763 else if cmd
= 'permban' then
6765 if g_Game_IsServer
and g_Game_IsNet
then
6767 if Length(P
) < 2 then
6769 g_Console_Add('permban <name>');
6774 g_Console_Add('permban <name>');
6778 pl
:= g_Net_Client_ByName(P
[1]);
6780 g_Net_Host_Ban(pl
, True)
6782 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6784 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6786 else if cmd
= 'permban_id' then
6788 if g_Game_IsServer
and g_Game_IsNet
then
6790 if Length(P
) < 2 then
6792 g_Console_Add('permban_id <client ID>');
6797 g_Console_Add('permban_id <client ID>');
6801 a
:= StrToIntDef(P
[1], 0);
6802 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6803 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6804 g_Net_Host_Ban(@NetClients
[a
], True);
6806 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6808 else if cmd
= 'permban_pid' then
6810 if g_Game_IsServer
and g_Game_IsNet
then
6812 if Length(P
) < 2 then
6814 g_Console_Add('permban_pid <player ID>');
6819 g_Console_Add('permban_pid <player ID>');
6823 a
:= StrToIntDef(P
[1], 0);
6824 pl
:= g_Net_Client_ByPlayer(a
);
6825 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6826 g_Net_Host_Ban(pl
, True);
6828 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6830 else if cmd
= 'permban_ip' then
6832 if g_Game_IsServer
and g_Game_IsNet
then
6834 if Length(P
) < 2 then
6836 g_Console_Add('permban_ip <IP address>');
6841 g_Console_Add('permban_ip <IP address>');
6845 g_Net_BanAddress(P
[1]);
6846 g_Net_SaveBanList();
6847 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6849 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6851 else if cmd
= 'unban' then
6853 if g_Game_IsServer
and g_Game_IsNet
then
6855 if Length(P
) < 2 then
6857 g_Console_Add('unban <IP Address>');
6862 g_Console_Add('unban <IP Address>');
6866 if g_Net_UnbanAddress(P
[1]) then
6868 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6869 g_Net_SaveBanList();
6871 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6873 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6875 else if cmd
= 'clientlist' then
6877 if g_Game_IsServer
and g_Game_IsNet
then
6880 if NetClients
<> nil then
6881 for a
:= Low(NetClients
) to High(NetClients
) do
6882 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6884 plr
:= g_Player_Get(NetClients
[a
].Player
);
6885 if plr
= nil then continue
;
6887 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6888 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6891 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6893 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6895 else if cmd
= 'connect' then
6897 if (NetMode
= NET_NONE
) then
6899 if Length(P
) < 2 then
6901 g_Console_Add('connect <IP> [port] [password]');
6906 g_Console_Add('connect <IP> [port] [password]');
6910 if Length(P
) > 2 then
6911 prt
:= StrToIntDef(P
[2], 25666)
6915 if Length(P
) > 3 then
6920 g_Game_StartClient(P
[1], prt
, pw
);
6923 else if cmd
= 'disconnect' then
6925 if (NetMode
= NET_CLIENT
) then
6928 else if cmd
= 'reconnect' then
6930 if (NetMode
= NET_SERVER
) then
6933 if (NetMode
= NET_CLIENT
) then
6936 gExit
:= EXIT_SIMPLE
;
6940 //TODO: Use last successful password to reconnect, instead of ''
6941 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6943 else if (cmd
= 'addbot') or
6944 (cmd
= 'bot_add') then
6947 1: g_Bot_Add(TEAM_NONE
, 2);
6948 2: g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2));
6950 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100));
6953 else if cmd
= 'bot_addlist' then
6956 1: g_Bot_AddList(TEAM_NONE
, '');
6957 2: g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1));
6959 if P
[2] = 'red' then
6961 else if P
[2] = 'blue' then
6967 then g_Bot_AddList(t
, P
[1], StrToIntDef(P
[1], -1))
6968 else g_Bot_AddList(t
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[3], 100));
6971 else if cmd
= 'bot_removeall' then
6973 else if cmd
= 'chat' then
6975 if g_Game_IsNet
then
6977 if Length(P
) > 1 then
6979 for a
:= 1 to High(P
) do
6980 chstr
:= chstr
+ P
[a
] + ' ';
6982 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6984 if Length(chstr
) < 1 then
6986 g_Console_Add('chat <text>');
6990 chstr
:= b_Text_Format(chstr
);
6991 if g_Game_IsClient
then
6992 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6994 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6997 g_Console_Add('chat <text>');
6999 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7001 else if cmd
= 'teamchat' then
7003 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
7005 if Length(P
) > 1 then
7007 for a
:= 1 to High(P
) do
7008 chstr
:= chstr
+ P
[a
] + ' ';
7010 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7012 if Length(chstr
) < 1 then
7014 g_Console_Add('teamchat <text>');
7018 chstr
:= b_Text_Format(chstr
);
7019 if g_Game_IsClient
then
7020 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
7022 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
7023 gPlayer1Settings
.Team
);
7026 g_Console_Add('teamchat <text>');
7028 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7030 else if (cmd
= 'an') or (cmd
= 'announce') then
7032 if g_Game_IsNet
then
7034 if Length(P
) > 1 then
7036 for a
:= 1 to High(P
) do
7037 chstr
:= chstr
+ P
[a
] + ' ';
7039 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7041 if Length(chstr
) < 1 then
7043 g_Console_Add('announce <text>');
7047 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
7048 if g_Game_IsClient
then
7049 MC_SEND_RCONCommand(chstr
)
7051 g_Console_Process(chstr
, True);
7054 g_Console_Add('announce <text>');
7056 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7058 else if cmd
= 'game' then
7060 if gGameSettings
.GameType
<> GT_NONE
then
7062 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7065 if Length(P
) = 1 then
7067 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
7070 // game not started yet, load fist map from some wad
7072 s
:= addWadExtension(P
[1]);
7073 found
:= e_FindResource(AllMapDirs
, s
);
7077 P
[1] := ExpandFileName(P
[1]);
7078 // if map not choosed then set first map
7079 if Length(P
) < 3 then
7082 P
[2] := g_Game_GetFirstMap(P
[1]);
7085 s
:= P
[1] + ':\' + UpperCase(P
[2]);
7087 if g_Map_Exist(s
) then
7091 with gGameSettings
do
7093 Options
:= gsGameFlags
;
7094 GameMode
:= g_Game_TextToMode(gsGameMode
);
7095 if gSwitchGameMode
<> GM_NONE
then
7096 GameMode
:= gSwitchGameMode
;
7097 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7098 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7100 if Length(P
) >= 4 then
7101 b
:= StrToIntDef(P
[3], 1);
7102 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
7103 ScoreLimit
, MaxLives
, Options
, b
);
7108 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7110 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
7112 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
7114 else if cmd
= 'host' then
7116 if gGameSettings
.GameType
<> GT_NONE
then
7118 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7121 if Length(P
) < 4 then
7123 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
7126 if not StrToIp(P
[1], listen
) then
7128 prt
:= StrToIntDef(P
[2], 25666);
7130 s
:= addWadExtension(P
[3]);
7131 found
:= e_FindResource(AllMapDirs
, s
);
7135 // get first map in wad, if not specified
7136 if Length(P
) < 5 then
7139 P
[4] := g_Game_GetFirstMap(P
[1]);
7141 s
:= P
[3] + ':\' + UpperCase(P
[4]);
7142 if g_Map_Exist(s
) then
7146 with gGameSettings
do
7148 Options
:= gsGameFlags
;
7149 GameMode
:= g_Game_TextToMode(gsGameMode
);
7150 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
7151 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7152 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7154 if Length(P
) >= 6 then
7155 b
:= StrToIntDef(P
[5], 0);
7156 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
7162 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
7164 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
7169 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
7172 else if cmd
= 'map' then
7174 if Length(P
) = 1 then
7176 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7178 g_Console_Add(cmd
+ ' <MAP>');
7179 g_Console_Add(cmd
+ ' <WAD> [MAP]')
7183 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7186 else if not e_IsValidResourceName(P
[1]) then
7188 g_Console_Add('wad name must not be absolute or relative');
7192 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7194 if Length(P
) < 3 then
7196 // first param is map or wad
7197 s
:= UpperCase(P
[1]);
7198 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7200 gExitByTrigger
:= False;
7203 // already in game, finish current map
7205 gExit
:= EXIT_ENDLEVELCUSTOM
;
7209 // intermission, so change map immediately
7216 found
:= e_FindResource(AllMapDirs
, s
);
7218 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
7221 // no such map, found wad
7224 P
[1] := ExpandFileName(pw
);
7225 P
[2] := g_Game_GetFirstMap(P
[1]);
7226 s
:= P
[1] + ':\' + P
[2];
7227 if g_Map_Exist(s
) then
7229 gExitByTrigger
:= False;
7232 // already in game, finish current map
7234 gExit
:= EXIT_ENDLEVELCUSTOM
7238 // intermission, so change map immediately
7245 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7247 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7252 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7258 s
:= addWadExtension(P
[1]);
7259 found
:= e_FindResource(AllMapDirs
, s
);
7263 P
[2] := UpperCase(P
[2]);
7264 s
:= P
[1] + ':\' + P
[2];
7265 if g_Map_Exist(s
) then
7267 gExitByTrigger
:= False;
7271 gExit
:= EXIT_ENDLEVELCUSTOM
7280 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7285 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7291 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7295 else if cmd
= 'nextmap' then
7297 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7299 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7304 if Length(P
) = 1 then
7306 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7308 g_Console_Add(cmd
+ ' <MAP>');
7309 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7314 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7317 else if not e_IsValidResourceName(P
[1]) then
7319 g_Console_Add('wad name must not be absolute or relative');
7324 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7326 if Length(P
) < 3 then
7328 // first param is map or wad
7329 s
:= UpperCase(P
[1]);
7330 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7333 gExitByTrigger
:= False;
7339 // no such map, found wad
7340 pw
:= addWadExtension(P
[1]);
7341 found
:= e_FindResource(MapDirs
, pw
);
7343 found
:= e_FindResource(WadDirs
, pw
);
7345 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7348 // map not specified, select first map
7350 P
[2] := g_Game_GetFirstMap(P
[1]);
7351 s
:= P
[1] + ':\' + P
[2];
7352 if g_Map_Exist(s
) then
7354 gExitByTrigger
:= False;
7361 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7363 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7368 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7374 // specified two params wad + map
7375 pw
:= addWadExtension(P
[1]);
7376 found
:= e_FindResource(MapDirs
, pw
);
7378 found
:= e_FindResource(MapDirs
, pw
);
7382 P
[2] := UpperCase(P
[2]);
7383 s
:= P
[1] + ':\' + P
[2];
7384 if g_Map_Exist(s
) then
7386 gExitByTrigger
:= False;
7392 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7397 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7403 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7408 if gNextMap
= '' then
7409 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7411 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7415 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7419 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7423 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7425 gExitByTrigger
:= False;
7426 // next map not specified, try to find trigger EXIT
7427 if (gNextMap
= '') and (gTriggers
<> nil) then
7429 for a
:= 0 to High(gTriggers
) do
7431 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7433 gExitByTrigger
:= True;
7434 //gNextMap := gTriggers[a].Data.MapName;
7435 gNextMap
:= gTriggers
[a
].tgcMap
;
7440 if gNextMap
= '' then
7441 gNextMap
:= g_Game_GetNextMap();
7442 if not isWadPath(gNextMap
) then
7443 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7446 if g_Map_Exist(s
) then
7447 gExit
:= EXIT_ENDLEVELCUSTOM
7449 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7453 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7457 else if (cmd
= 'event') then
7459 if (Length(P
) <= 1) then
7461 for a
:= 0 to High(gEvents
) do
7462 if gEvents
[a
].Command
= '' then
7463 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7465 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7468 if (Length(P
) = 2) then
7470 for a
:= 0 to High(gEvents
) do
7471 if gEvents
[a
].Name
= P
[1] then
7472 if gEvents
[a
].Command
= '' then
7473 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7475 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7478 for a
:= 0 to High(gEvents
) do
7479 if gEvents
[a
].Name
= P
[1] then
7481 gEvents
[a
].Command
:= '';
7482 for b
:= 2 to High(P
) do
7483 if Pos(' ', P
[b
]) = 0 then
7484 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7486 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7487 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7491 else if cmd
= 'suicide' then
7495 if g_Game_IsClient
then
7496 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7499 if gPlayer1
<> nil then
7500 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7501 if gPlayer2
<> nil then
7502 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7506 else if cmd
= 'screenshot' then
7510 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7512 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7514 gWeaponAction
[0, WP_PREV
] := True;
7516 gWeaponAction
[0, WP_NEXT
] := True;
7518 else if cmd
= 'weapon' then
7520 if Length(p
) = 2 then
7522 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7523 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7524 gSelectWeapon
[0, a
] := True
7527 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7528 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7530 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7531 b
:= ord(cmd
[2]) - ord('1');
7533 gWeaponAction
[b
, WP_PREV
] := True;
7535 gWeaponAction
[b
, WP_NEXT
] := True;
7537 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7539 if Length(p
) = 2 then
7541 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7542 b
:= ord(cmd
[2]) - ord('1');
7543 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7544 gSelectWeapon
[b
, a
] := True
7547 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
7549 b
:= ord(cmd
[2]) - ord('1');
7551 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
7553 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
7555 else if (cmd
= 'dropflag') then
7557 if g_Game_IsServer
then
7559 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7560 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7563 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7565 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7567 b
:= ord(cmd
[2]) - ord('1');
7568 if g_Game_IsServer
then
7570 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7571 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7574 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7576 // Êîìàíäû Ñâîåé èãðû:
7577 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7579 if cmd
= 'bot_addred' then
7581 if Length(P
) > 1 then
7582 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7584 g_Bot_Add(TEAM_RED
, 2);
7586 else if cmd
= 'bot_addblue' then
7588 if Length(P
) > 1 then
7589 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7591 g_Bot_Add(TEAM_BLUE
, 2);
7593 else if cmd
= 'spectate' then
7599 else if cmd
= 'say' then
7601 if g_Game_IsServer
and g_Game_IsNet
then
7603 if Length(P
) > 1 then
7606 for a
:= 1 to High(P
) do
7607 chstr
:= chstr
+ P
[a
] + ' ';
7609 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7611 if Length(chstr
) < 1 then
7613 g_Console_Add('say <text>');
7617 chstr
:= b_Text_Format(chstr
);
7618 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7620 else g_Console_Add('say <text>');
7622 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7624 else if cmd
= 'tell' then
7626 if g_Game_IsServer
and g_Game_IsNet
then
7628 if (Length(P
) > 2) and (P
[1] <> '') then
7631 for a
:= 2 to High(P
) do
7632 chstr
:= chstr
+ P
[a
] + ' ';
7634 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7636 if Length(chstr
) < 1 then
7638 g_Console_Add('tell <playername> <text>');
7642 pl
:= g_Net_Client_ByName(P
[1]);
7644 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7646 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7648 else g_Console_Add('tell <playername> <text>');
7650 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7652 else if cmd
= 'centerprint' then
7654 if (Length(P
) > 2) and (P
[1] <> '') then
7657 for a
:= 2 to High(P
) do
7658 chstr
:= chstr
+ P
[a
] + ' ';
7660 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7662 if Length(chstr
) < 1 then
7664 g_Console_Add('centerprint <timeout> <text>');
7668 a
:= StrToIntDef(P
[1], 100);
7669 chstr
:= b_Text_Format(chstr
);
7670 g_Game_Message(chstr
, a
);
7671 if g_Game_IsNet
and g_Game_IsServer
then
7672 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7674 else g_Console_Add('centerprint <timeout> <text>');
7676 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7678 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7680 // Äîïîëíèòåëüíîå âðåìÿ:
7681 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7683 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7684 [gGameSettings
.TimeLimit
div 3600,
7685 (gGameSettings
.TimeLimit
div 60) mod 60,
7686 gGameSettings
.TimeLimit
mod 60]));
7687 if g_Game_IsNet
then MH_SEND_GameSettings
;
7689 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7691 if (Length(P
) <= 1) then
7692 g_Console_Add('rcon_password <password>')
7694 MC_SEND_RCONPassword(P
[1]);
7696 else if cmd
= 'rcon' then
7698 if g_Game_IsClient
then
7700 if Length(P
) > 1 then
7703 for a
:= 1 to High(P
) do
7704 chstr
:= chstr
+ P
[a
] + ' ';
7706 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7708 if Length(chstr
) < 1 then
7710 g_Console_Add('rcon <command>');
7714 MC_SEND_RCONCommand(chstr
);
7716 else g_Console_Add('rcon <command>');
7719 else if cmd
= 'ready' then
7721 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7722 gLMSRespawnTime
:= gTime
+ 100;
7724 else if (cmd
= 'callvote') and g_Game_IsNet
then
7726 if Length(P
) > 1 then
7729 for a
:= 1 to High(P
) do begin
7730 if a
> 1 then chstr
:= chstr
+ ' ';
7731 chstr
:= chstr
+ P
[a
];
7734 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7736 if Length(chstr
) < 1 then
7738 g_Console_Add('callvote <command>');
7742 if g_Game_IsClient
then
7743 MC_SEND_Vote(True, chstr
)
7745 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7746 g_Console_Process('vote', True);
7749 g_Console_Add('callvote <command>');
7751 else if (cmd
= 'vote') and g_Game_IsNet
then
7753 if g_Game_IsClient
then
7755 else if gVoteInProgress
then
7757 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7758 a
:= Floor((NetClientCount
+1)/2.0) + 1
7760 a
:= Floor(NetClientCount
/2.0) + 1;
7765 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7766 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7772 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7773 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7781 procedure SystemCommands(P
: SSArray
);
7785 cmd
:= LowerCase(P
[0]);
7794 gRC_Width
:= Max(1, gRC_Width
);
7795 gRC_Height
:= Max(1, gRC_Height
);
7796 gBPP
:= Max(1, gBPP
);
7797 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7798 e_LogWriteln('resolution changed')
7800 e_LogWriteln('resolution not changed');
7801 sys_EnableVSync(gVSync
);
7805 if Length(p
) = 2 then
7807 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7809 gFrameTime
:= 1000 div gMaxFPS
7813 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7817 if Length(p
) = 2 then
7819 gAskLanguage
:= true;
7820 gLanguage
:= LANGUAGE_ENGLISH
;
7821 case LowerCase(p
[1]) of
7824 gAskLanguage
:= false;
7825 gLanguage
:= LANGUAGE_ENGLISH
;
7829 gAskLanguage
:= false;
7830 gLanguage
:= LANGUAGE_RUSSIAN
;
7834 gAskLanguage
:= true;
7835 gLanguage
:= LANGUAGE_ENGLISH
;
7838 g_Language_Set(gLanguage
);
7842 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7848 procedure g_TakeScreenShot(Filename
: string = '');
7849 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7851 if e_NoGraphics
then Exit
;
7853 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7855 if Filename
= '' then
7858 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7859 Filename
:= 'screenshot-' + date
;
7862 name
:= e_CatPath(dir
, Filename
+ '.png');
7863 s
:= createDiskFile(name
);
7865 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
7867 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7869 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7874 g_Console_Add('oh shit, i can''t create screenshot!')
7878 procedure g_Game_InGameMenu(Show
: Boolean);
7880 if (g_ActiveWindow
= nil) and Show
then
7882 if gGameSettings
.GameType
= GT_SINGLE
then
7883 g_GUI_ShowWindow('GameSingleMenu')
7886 if g_Game_IsClient
then
7887 g_GUI_ShowWindow('GameClientMenu')
7889 if g_Game_IsNet
then
7890 g_GUI_ShowWindow('GameServerMenu')
7892 g_GUI_ShowWindow('GameCustomMenu');
7894 g_Sound_PlayEx('MENU_OPEN');
7896 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7897 if (not g_Game_IsNet
) then
7901 if (g_ActiveWindow
<> nil) and (not Show
) then
7903 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7904 if (not g_Game_IsNet
) then
7905 g_Game_Pause(False);
7909 procedure g_Game_Pause (Enable
: Boolean);
7913 if not gGameOn
then exit
;
7915 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7918 gPauseMain
:= Enable
;
7920 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7923 procedure g_Game_HolmesPause (Enable
: Boolean);
7927 if not gGameOn
then exit
;
7928 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7931 gPauseHolmes
:= Enable
;
7933 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7936 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7941 if gTriggers
<> nil then
7942 for i
:= 0 to High(gTriggers
) do
7943 with gTriggers
[i
] do
7944 if (TriggerType
= TRIGGER_SOUND
) and
7946 Sound
.IsPlaying() then
7948 Sound
.Pause(Enable
);
7952 if gPlayers
<> nil then
7953 for i
:= 0 to High(gPlayers
) do
7954 if gPlayers
[i
] <> nil then
7955 gPlayers
[i
].PauseSounds(Enable
);
7958 if gMusic
<> nil then
7959 gMusic
.Pause(Enable
);
7962 procedure g_Game_StopAllSounds(all
: Boolean);
7966 if gTriggers
<> nil then
7967 for i
:= 0 to High(gTriggers
) do
7968 with gTriggers
[i
] do
7969 if (TriggerType
= TRIGGER_SOUND
) and
7973 if gMusic
<> nil then
7980 procedure g_Game_UpdateTriggerSounds
;
7983 if gTriggers
<> nil then
7984 for i
:= 0 to High(gTriggers
) do
7985 with gTriggers
[i
] do
7986 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7987 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7990 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7993 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7998 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
8003 if gSpectMode
<> SPECT_PLAYERS
then
8005 if gSpectPID1
= UID
then
8010 if gSpectViewTwo
and (gSpectPID2
= UID
) then
8017 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
8022 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
8027 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
8032 if gSpectMode
<> SPECT_PLAYERS
then
8034 Pl
:= g_Player_Get(gSpectPID1
);
8035 if (Pl
<> nil) and (Pl
.Team
= Team
) then
8040 if gSpectViewTwo
then
8042 Pl
:= g_Player_Get(gSpectPID2
);
8043 if (Pl
<> nil) and (Pl
.Team
= Team
) then
8051 procedure g_Game_Message(Msg
: string; Time
: Word);
8053 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
8054 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
8055 MessageTime
:= Time
;
8058 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
8060 punct
: Array[0..13] of String =
8061 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8067 function IsPunctuation(S
: String): Boolean;
8072 if Length(S
) <> 1 then
8074 for i
:= Low(punct
) to High(punct
) do
8075 if S
= punct
[i
] then
8081 function FilterPunctuation(S
: String): String;
8085 for i
:= Low(punct
) to High(punct
) do
8086 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
8092 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
8094 // remove player name
8095 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8096 // for FullWord check
8097 Text := toLowerCase1251(' ' + Text + ' ');
8098 fpText
:= FilterPunctuation(Text);
8100 for i
:= 0 to Length(gChatSounds
) - 1 do
8103 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
8105 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
8106 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
8108 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
8114 gChatSounds
[i
].Sound
.Play();
8120 g_Sound_PlayEx('SOUND_GAME_RADIO');
8123 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
8132 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8136 if goodsnd
[a
].IsPlaying() then
8139 goodsnd
[Random(4)].Play();
8142 procedure g_Game_Announce_KillCombo(Param
: Integer);
8149 UID
:= Param
and $FFFF;
8154 Pl
:= g_Player_Get(UID
);
8163 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
8167 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
8171 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
8175 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
8183 if not g_Game_IsWatchedPlayer(UID
) then
8186 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
8190 if killsnd
[n
].IsPlaying() then
8195 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
8203 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8207 if hahasnd
[a
].IsPlaying() then
8210 hahasnd
[Random(3)].Play();
8213 procedure g_Game_Effect_Bubbles (fX
, fY
: Integer; count
: Word; devX
, devY
: Byte; Silent
: Boolean);
8215 g_GFX_Bubbles(fX
, fY
, count
, devX
, devY
);
8216 if not Silent
then if Random(2) = 0
8217 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX
, fY
)
8218 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX
, fY
);
8221 procedure g_Game_StartVote(Command
, Initiator
: string);
8225 if not gVotesEnabled
then Exit
;
8226 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8227 if gVoteInProgress
or gVotePassed
then
8229 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
8230 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
8233 gVoteInProgress
:= True;
8234 gVotePassed
:= False;
8235 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
8238 gVoteCommand
:= Command
;
8240 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8241 Need
:= Floor((NetClientCount
+1)/2.0)+1
8243 Need
:= Floor(NetClientCount
/2.0)+1;
8244 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
8245 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
8248 procedure g_Game_CheckVote
;
8252 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8253 if not gVoteInProgress
then Exit
;
8255 if (gTime
>= gVoteTimer
) then
8257 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8258 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8260 Need
:= Floor(NetClientCount
/2.0) + 1;
8261 if gVoteCount
>= Need
then
8263 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8264 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8265 gVotePassed
:= True;
8266 gVoteCmdTimer
:= gTime
+ 5000;
8270 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
8271 MH_SEND_VoteEvent(NET_VE_FAILED
);
8273 if NetClients
<> nil then
8274 for I
:= Low(NetClients
) to High(NetClients
) do
8275 if NetClients
[i
].Used
then
8276 NetClients
[i
].Voted
:= False;
8277 gVoteInProgress
:= False;
8283 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8284 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8286 Need
:= Floor(NetClientCount
/2.0) + 1;
8287 if gVoteCount
>= Need
then
8289 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8290 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8291 gVoteInProgress
:= False;
8292 gVotePassed
:= True;
8293 gVoteCmdTimer
:= gTime
+ 5000;
8296 if NetClients
<> nil then
8297 for I
:= Low(NetClients
) to High(NetClients
) do
8298 if NetClients
[i
].Used
then
8299 NetClients
[i
].Voted
:= False;
8304 procedure g_Game_LoadMapList(FileName
: string);
8312 if not FileExists(FileName
) then Exit
;
8314 AssignFile(ListFile
, FileName
);
8316 while not EOF(ListFile
) do
8318 ReadLn(ListFile
, s
);
8321 if s
= '' then Continue
;
8323 SetLength(MapList
, Length(MapList
)+1);
8324 MapList
[High(MapList
)] := s
;
8326 CloseFile(ListFile
);
8329 procedure g_Game_SetDebugMode();
8332 // ×èòû (äàæå â ñâîåé èãðå):
8336 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8340 if Length(LoadingStat
.Msgs
) = 0 then
8346 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8347 if NextMsg
= Length(Msgs
) then
8349 for i
:= 0 to High(Msgs
)-1 do
8350 Msgs
[i
] := Msgs
[i
+1];
8358 Msgs
[NextMsg
-1] := Text;
8362 PBarWasHere
:= false;
8365 g_ActiveWindow
:= nil;
8366 ProcessLoading(True);
8369 procedure g_Game_StepLoading(Value
: Integer = -1);
8381 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8384 ProcessLoading(False);
8389 procedure g_Game_ClearLoading();
8398 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8399 if len
< 1 then len
:= 1;
8400 SetLength(Msgs
, len
);
8401 for len
:= Low(Msgs
) to High(Msgs
) do
8404 PBarWasHere
:= false;
8408 procedure Parse_Params(var pars
: TParamStrValues
);
8415 while i
<= ParamCount
do
8418 if (Length(s
) > 1) and (s
[1] = '-') then
8420 if (Length(s
) > 2) and (s
[2] = '-') then
8421 begin // Îäèíî÷íûé ïàðàìåòð
8422 SetLength(pars
, Length(pars
) + 1);
8423 with pars
[High(pars
)] do
8425 Name
:= LowerCase(s
);
8430 if (i
< ParamCount
) then
8431 begin // Ïàðàìåòð ñî çíà÷åíèåì
8433 SetLength(pars
, Length(pars
) + 1);
8434 with pars
[High(pars
)] do
8436 Name
:= LowerCase(s
);
8437 Value
:= LowerCase(ParamStr(i
));
8446 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8451 for i
:= 0 to High(pars
) do
8452 if pars
[i
].Name
= aName
then
8454 Result
:= pars
[i
].Value
;
8459 procedure g_Game_Process_Params();
8461 pars
: TParamStrValues
;
8464 LimT
, LimS
: Integer;
8475 s
:= Find_Param_Value(pars
, '--debug');
8478 g_Game_SetDebugMode();
8479 s
:= Find_Param_Value(pars
, '--netdump');
8484 // Connect when game loads
8485 ip
:= Find_Param_Value(pars
, '-connect');
8489 s
:= Find_Param_Value(pars
, '-port');
8490 if (s
= '') or not TryStrToInt(s
, Port
) then
8493 s
:= Find_Param_Value(pars
, '-pw');
8495 g_Game_StartClient(ip
, Port
, s
);
8499 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8502 gDefaultMegawadStart
:= s
;
8505 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8506 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8508 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8511 // Start map when game loads:
8512 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8513 if isWadPath(map
) then
8516 s
:= Find_Param_Value(pars
, '-gm');
8517 GMode
:= g_Game_TextToMode(s
);
8518 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8519 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8522 s
:= Find_Param_Value(pars
, '-limt');
8523 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8529 s
:= Find_Param_Value(pars
, '-lims');
8530 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8536 s
:= Find_Param_Value(pars
, '-lives');
8537 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8543 s
:= Find_Param_Value(pars
, '-opt');
8547 Opt
:= StrToIntDef(s
, 0);
8550 s
:= Find_Param_Value(pars
, '--close');
8554 // Override map to test:
8555 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8558 if e_IsValidResourceName(s
) then
8559 e_FindResource(AllMapDirs
, s
);
8560 gTestMap
:= ExpandFileName(s
);
8563 // Delete test map after play:
8564 s
:= Find_Param_Value(pars
, '--testdelete');
8567 //gMapToDelete := MapsDir + map;
8568 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8572 // Delete temporary WAD after play:
8573 s
:= Find_Param_Value(pars
, '--tempdelete');
8574 if (s
<> '') and (gTestMap
<> '') then
8576 gMapToDelete
:= gTestMap
;
8577 gTempDelete
:= True;
8580 // Number of players:
8581 s
:= Find_Param_Value(pars
, '-pl');
8583 n
:= DEFAULT_PLAYERS
8585 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8588 s
:= Find_Param_Value(pars
, '-port');
8589 if (s
= '') or not TryStrToInt(s
, Port
) then
8590 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8592 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8595 // Execute script when game loads:
8596 s
:= Find_Param_Value(pars
, '-exec');
8599 // if not isWadPath(s) then
8600 // s := GameDir + '/' + s;
8605 if IOResult
<> 0 then
8607 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8608 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8612 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8613 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8618 if IOResult
<> 0 then
8620 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8621 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8625 if Pos('#', s
) <> 1 then // script comment
8626 g_Console_Process(s
, True);
8637 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8638 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8639 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8640 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8642 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8643 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8644 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8645 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8647 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8648 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8650 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8651 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8653 {$IFDEF ENABLE_HOLMES}
8654 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8657 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8659 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8660 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8662 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8663 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8665 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8666 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8668 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8669 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8670 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8671 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
8672 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8673 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8674 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8675 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8676 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');