1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_basic
, g_player
, e_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures
: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Draw();
89 procedure g_Game_Quit();
90 procedure g_Game_SetupScreenSize();
91 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
92 function g_Game_ModeToText(Mode
: Byte): string;
93 function g_Game_TextToMode(Mode
: string): Byte;
94 procedure g_Game_ExecuteEvent(Name
: String);
95 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
96 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
97 procedure g_Game_RemovePlayer();
98 procedure g_Game_Spectate();
99 procedure g_Game_SpectateCenterView();
100 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
101 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
102 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
103 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
104 procedure g_Game_Restart();
105 procedure g_Game_RestartLevel();
106 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
107 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
108 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
109 procedure g_Game_ChangeMap(const MapPath
: String);
110 procedure g_Game_ExitLevel(const Map
: AnsiString);
111 function g_Game_GetFirstMap(WAD
: String): String;
112 function g_Game_GetNextMap(): String;
113 procedure g_Game_NextLevel();
114 procedure g_Game_Pause(Enable
: Boolean);
115 procedure g_Game_HolmesPause(Enable
: Boolean);
116 procedure g_Game_InGameMenu(Show
: Boolean);
117 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
118 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
119 procedure g_Game_Message(Msg
: String; Time
: Word);
120 procedure g_Game_LoadMapList(FileName
: String);
121 procedure g_Game_PauseAllSounds(Enable
: Boolean);
122 procedure g_Game_StopAllSounds(all
: Boolean);
123 procedure g_Game_UpdateTriggerSounds();
124 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
125 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
126 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
127 procedure g_Game_Announce_KillCombo(Param
: Integer);
128 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
129 procedure g_Game_StartVote(Command
, Initiator
: string);
130 procedure g_Game_CheckVote
;
131 procedure g_TakeScreenShot(Filename
: string = '');
132 procedure g_FatalError(Text: String);
133 procedure g_SimpleError(Text: String);
134 function g_Game_IsTestMap(): Boolean;
135 procedure g_Game_DeleteTestMap();
136 procedure GameCVars(P
: SSArray
);
137 procedure PlayerSettingsCVars(P
: SSArray
);
138 procedure SystemCommands(P
: SSArray
);
139 procedure GameCommands(P
: SSArray
);
140 procedure GameCheats(P
: SSArray
);
141 procedure DebugCommands(P
: SSArray
);
142 procedure g_Game_Process_Params
;
143 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
144 procedure g_Game_StepLoading(Value
: Integer = -1);
145 procedure g_Game_ClearLoading();
146 procedure g_Game_SetDebugMode();
147 procedure DrawLoadingStat();
148 procedure DrawMenuBackground(tex
: AnsiString);
150 { procedure SetWinPause(Enable: Boolean); }
155 LOADING_SHOW_STEP
= 100;
156 LOADING_INTERLINE
= 20;
171 MESSAGE_DIKEY
= WM_USER
+ 1;
176 EXIT_ENDLEVELSINGLE
= 4;
177 EXIT_ENDLEVELCUSTOM
= 5;
179 GAME_OPTION_RESERVED
= 1;
180 GAME_OPTION_TEAMDAMAGE
= 2;
181 GAME_OPTION_ALLOWEXIT
= 4;
182 GAME_OPTION_WEAPONSTAY
= 8;
183 GAME_OPTION_MONSTERS
= 16;
184 GAME_OPTION_BOTVSPLAYER
= 32;
185 GAME_OPTION_BOTVSMONSTER
= 64;
186 GAME_OPTION_DMKEYS
= 128;
187 GAME_OPTION_TEAMHITTRACE
= 256;
188 GAME_OPTION_TEAMHITPROJECTILE
= 512;
189 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
190 GAME_OPTION_ALLOWDROPFLAG
= 2048;
191 GAME_OPTION_THROWFLAG
= 4096;
196 STATE_INTERCUSTOM
= 3;
197 STATE_INTERSINGLE
= 4;
203 LMS_RESPAWN_NONE
= 0;
204 LMS_RESPAWN_WARMUP
= 1;
205 LMS_RESPAWN_FINAL
= 2;
222 CONFIG_FILENAME
= 'Doom2DF.cfg';
224 TEST_MAP_NAME
= '$$$_TEST_$$$';
226 STD_PLAYER_MODEL
= 'Doomer';
234 STATFILE_VERSION
= $03;
238 gGameSettings
: TGameSettings
;
239 gPlayer1Settings
: TPlayerSettings
;
240 gPlayer2Settings
: TPlayerSettings
;
242 gPlayerScreenSize
: TDFPoint
;
243 gPlayer1ScreenCoord
: TDFPoint
;
244 gPlayer2ScreenCoord
: TDFPoint
;
245 gPlayer1
: TPlayer
= nil;
246 gPlayer2
: TPlayer
= nil;
247 gPlayerDrawn
: TPlayer
= nil;
249 gLerpFactor
: Single = 1.0;
250 gSwitchGameMode
: Byte = GM_DM
;
251 gHearPoint1
, gHearPoint2
: THearPoint
;
252 gSoundEffectsDF
: Boolean = False;
253 gSoundTriggerTime
: Word = 0;
254 gAnnouncer
: Integer = ANNOUNCE_NONE
;
255 goodsnd
: array[0..3] of TPlayableSound
;
256 killsnd
: array[0..3] of TPlayableSound
;
257 hahasnd
: array[0..2] of TPlayableSound
;
258 sound_get_flag
: array[0..1] of TPlayableSound
;
259 sound_lost_flag
: array[0..1] of TPlayableSound
;
260 sound_ret_flag
: array[0..1] of TPlayableSound
;
261 sound_cap_flag
: array[0..1] of TPlayableSound
;
262 gBodyKillEvent
: Integer = -1;
263 gDefInterTime
: ShortInt = -1;
264 gInterEndTime
: LongWord = 0;
265 gInterTime
: LongWord = 0;
266 gServInterTime
: Byte = 0;
267 gGameStartTime
: LongWord = 0;
268 gTotalMonsters
: Integer = 0;
269 gPauseMain
: Boolean = false;
270 gPauseHolmes
: Boolean = false;
271 gShowTime
: Boolean = False;
272 gShowFPS
: Boolean = False;
273 gShowGoals
: Boolean = True;
274 gShowStat
: Boolean = True;
275 gShowPIDs
: Boolean = False;
276 gShowKillMsg
: Boolean = True;
277 gShowLives
: Boolean = True;
278 gShowPing
: Boolean = False;
279 gShowMap
: Boolean = False;
281 gState
: Byte = STATE_NONE
;
283 sWidth
, sHeight
: Word;
284 gSpectMode
: Byte = SPECT_NONE
;
285 gSpectHUD
: Boolean = True;
286 gSpectKeyPress
: Boolean = False;
287 gSpectX
: Integer = 0;
288 gSpectY
: Integer = 0;
289 gSpectStep
: Byte = 8;
290 gSpectViewTwo
: Boolean = False;
291 gSpectPID1
: Integer = -1;
292 gSpectPID2
: Integer = -1;
293 gSpectAuto
: Boolean = False;
294 gSpectAutoNext
: LongWord;
295 gSpectAutoStepX
: Integer;
296 gSpectAutoStepY
: Integer;
297 gMusic
: TMusic
= nil;
298 gLoadGameMode
: Boolean;
299 gCheats
: Boolean = False;
300 gMapOnce
: Boolean = False;
301 gMapToDelete
: String;
302 gTempDelete
: Boolean = False;
303 gLastMap
: Boolean = False;
306 gResolutionChange
: Boolean = False;
307 gRC_Width
, gRC_Height
: Integer;
308 gRC_FullScreen
, gRC_Maximized
: Boolean;
309 gLanguageChange
: Boolean = False;
310 gDebugMode
: Boolean = False;
311 g_debug_Sounds
: Boolean = False;
312 g_debug_Frames
: Boolean = False;
313 g_debug_WinMsgs
: Boolean = False;
314 g_debug_MonsterOff
: Boolean = False;
315 g_debug_BotAIOff
: Byte = 0;
316 g_debug_HealthBar
: Boolean = False;
317 g_Debug_Player
: Boolean = False;
318 gCoopMonstersKilled
: Word = 0;
319 gCoopSecretsFound
: Word = 0;
320 gCoopTotalMonstersKilled
: Word = 0;
321 gCoopTotalSecretsFound
: Word = 0;
322 gCoopTotalMonsters
: Word = 0;
323 gCoopTotalSecrets
: Word = 0;
324 gStatsOff
: Boolean = False;
325 gStatsPressed
: Boolean = False;
326 gExitByTrigger
: Boolean = False;
327 gNextMap
: String = '';
328 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
329 gLMSRespawnTime
: Cardinal = 0;
330 gLMSSoftSpawn
: Boolean = False;
331 gMissionFailed
: Boolean = False;
332 gVoteInProgress
: Boolean = False;
333 gVotePassed
: Boolean = False;
334 gVoteCommand
: string = '';
335 gVoteTimer
: Cardinal = 0;
336 gVoteCmdTimer
: Cardinal = 0;
337 gVoteCount
: Integer = 0;
338 gVoteTimeout
: Cardinal = 30;
339 gVoted
: Boolean = False;
340 gVotesEnabled
: Boolean = True;
341 gEvents
: Array of TGameEvent
;
342 gDelayedEvents
: Array of TDelayedEvent
;
343 gUseChatSounds
: Boolean = True;
344 gChatSounds
: Array of TChatSound
;
345 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
346 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
347 gInterReadyCount
: Integer = 0;
349 g_dbg_ignore_bounds
: Boolean = false;
350 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
351 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
353 // move button values:
354 // bits 0-1: l/r state:
355 // 0: neither left, nor right pressed
358 // bits 4-5: l/r state when strafe was pressed
359 P1MoveButton
: Byte = 0;
360 P2MoveButton
: Byte = 0;
362 g_profile_frame_update
: Boolean = false;
363 g_profile_frame_draw
: Boolean = false;
364 g_profile_collision
: Boolean = false;
365 g_profile_los
: Boolean = false;
366 g_profile_history_size
: Integer = 1000;
368 g_rlayer_back
: Boolean = true;
369 g_rlayer_step
: Boolean = true;
370 g_rlayer_wall
: Boolean = true;
371 g_rlayer_door
: Boolean = true;
372 g_rlayer_acid1
: Boolean = true;
373 g_rlayer_acid2
: Boolean = true;
374 g_rlayer_water
: Boolean = true;
375 g_rlayer_fore
: Boolean = true;
378 procedure g_ResetDynlights ();
379 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
380 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
382 function conIsCheatsEnabled (): Boolean; inline;
383 function gPause (): Boolean; inline;
389 {$INCLUDE ../nogl/noGLuses.inc}
390 {$IFDEF ENABLE_HOLMES}
393 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
394 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
395 g_playermodel
, g_gfx
, g_options
, Math
,
396 g_triggers
, g_monsters
, e_sound
, CONFIG
,
397 g_language
, g_net
, g_main
, g_phys
,
398 ENet
, e_msg
, g_netmsg
, g_netmaster
,
399 sfs
, wadreader
, g_system
;
403 hasPBarGfx
: Boolean = false;
406 // ////////////////////////////////////////////////////////////////////////// //
407 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
410 // ////////////////////////////////////////////////////////////////////////// //
411 function conIsCheatsEnabled (): Boolean; inline;
414 if g_Game_IsNet
then exit
;
415 if not gDebugMode
then
417 //if not gCheats then exit;
418 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
419 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
425 // ////////////////////////////////////////////////////////////////////////// //
427 profileFrameDraw
: TProfiler
= nil;
430 // ////////////////////////////////////////////////////////////////////////// //
433 x
, y
, radius
: Integer;
436 exploRadius
: Integer;
440 g_dynLights
: array of TDynLight
= nil;
441 g_dynLightCount
: Integer = 0;
442 g_playerLight
: Boolean = false;
444 procedure g_ResetDynlights ();
448 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
450 for idx
:= 0 to g_dynLightCount
-1 do
452 if g_dynLights
[idx
].exploCount
= -666 then
459 Inc(g_dynLights
[idx
].exploCount
);
460 if (g_dynLights
[idx
].exploCount
< 10) then
462 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
463 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
464 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
465 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
470 g_dynLightCount
:= lnum
;
473 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
475 if not gwin_has_stencil
then exit
;
476 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
477 g_dynLights
[g_dynLightCount
].x
:= x
;
478 g_dynLights
[g_dynLightCount
].y
:= y
;
479 g_dynLights
[g_dynLightCount
].radius
:= radius
;
480 g_dynLights
[g_dynLightCount
].r
:= r
;
481 g_dynLights
[g_dynLightCount
].g
:= g
;
482 g_dynLights
[g_dynLightCount
].b
:= b
;
483 g_dynLights
[g_dynLightCount
].a
:= a
;
484 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
485 Inc(g_dynLightCount
);
488 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
490 if not gwin_has_stencil
then exit
;
491 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
492 g_dynLights
[g_dynLightCount
].x
:= x
;
493 g_dynLights
[g_dynLightCount
].y
:= y
;
494 g_dynLights
[g_dynLightCount
].radius
:= 0;
495 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
496 g_dynLights
[g_dynLightCount
].r
:= r
;
497 g_dynLights
[g_dynLightCount
].g
:= g
;
498 g_dynLights
[g_dynLightCount
].b
:= b
;
499 g_dynLights
[g_dynLightCount
].a
:= 0;
500 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
501 Inc(g_dynLightCount
);
505 // ////////////////////////////////////////////////////////////////////////// //
506 function calcProfilesHeight (prof
: TProfiler
): Integer;
509 if (prof
= nil) then exit
;
510 if (length(prof
.bars
) = 0) then exit
;
511 result
:= length(prof
.bars
)*(16+2);
515 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
522 if (prof
= nil) then exit
;
524 if (length(prof
.bars
) = 0) then exit
;
526 hgt
:= calcProfilesHeight(prof
);
527 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
528 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
530 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
531 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
532 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
535 for ii
:= 0 to High(prof
.bars
) do
537 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);
544 // ////////////////////////////////////////////////////////////////////////// //
546 TEndCustomGameStat
= record
547 PlayerStat
: TPlayerStatArray
;
551 Map
, MapName
: String;
554 TEndSingleGameStat
= record
555 PlayerStat
: Array [0..1] of record
561 TotalSecrets
: Integer;
564 TLoadingStat
= record
568 Msgs
: Array of String;
570 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
573 TParamStrValue
= record
578 TParamStrValues
= Array of TParamStrValue
;
581 INTER_ACTION_TEXT
= 1;
582 INTER_ACTION_PIC
= 2;
583 INTER_ACTION_MUSIC
= 3;
587 FPSCounter
, UPSCounter
: Word;
588 FPSTime
, UPSTime
: LongWord;
589 DataLoaded
: Boolean = False;
590 IsDrawStat
: Boolean = False;
591 CustomStat
: TEndCustomGameStat
;
592 SingleStat
: TEndSingleGameStat
;
593 LoadingStat
: TLoadingStat
;
594 EndingGameCounter
: Byte = 0;
597 MessageLineLength
: Integer = 80;
598 MapList
: SSArray
= nil;
599 MapIndex
: Integer = -1;
600 InterReadyTime
: Integer = -1;
601 StatShotDone
: Boolean = False;
602 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
603 StatDate
: string = '';
609 text: Array of ShortString;
610 anim
: Array of ShortString;
611 pic
: Array of ShortString;
612 mus
: Array of ShortString;
614 triggers
: Array of record
616 actions
: Array of record
617 action
, p1
, p2
: Integer;
620 cur_trigger
: Integer;
633 function Compare(a
, b
: TPlayerStat
): Integer;
635 if a
.Spectator
then Result
:= 1
636 else if b
.Spectator
then Result
:= -1
637 else if a
.Frags
< b
.Frags
then Result
:= 1
638 else if a
.Frags
> b
.Frags
then Result
:= -1
639 else if a
.Deaths
< b
.Deaths
then Result
:= -1
640 else if a
.Deaths
> b
.Deaths
then Result
:= 1
641 else if a
.Kills
< b
.Kills
then Result
:= -1
645 procedure SortGameStat(var stat
: TPlayerStatArray
);
650 if stat
= nil then Exit
;
652 for I
:= High(stat
) downto Low(stat
) do
653 for J
:= Low(stat
) to High(stat
) - 1 do
654 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
657 stat
[J
] := stat
[J
+ 1];
662 // saves a shitty CSV containing the game stats passed to it
663 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
666 dir
, fname
, map
, mode
, etime
: String;
670 dir
:= e_GetWriteableDir(StatsDirs
);
671 // stats are placed in stats/yy/mm/dd/*.csv
672 fname
:= e_CatPath(dir
, Path
);
673 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
674 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
675 AssignFile(s
, fname
);
678 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
679 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
680 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
681 mode
:= g_Game_ModeToText(Stat
.GameMode
);
682 etime
:= Format('%d:%.2d:%.2d', [
683 Stat
.GameTime
div 1000 div 3600,
684 (Stat
.GameTime
div 1000 div 60) mod 60,
685 Stat
.GameTime
div 1000 mod 60
687 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
688 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
694 gGameSettings
.TimeLimit
,
695 gGameSettings
.GoalLimit
,
696 gGameSettings
.Options
,
698 Length(Stat
.PlayerStat
)
700 // line 2: game specific shit
701 // if it's a team game: red score, blue score
702 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
704 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
706 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
707 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
709 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
710 // lines 3-...: team, player name, frags, deaths
711 WriteLn(s
, 'team,name,frags,deaths');
712 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
713 with Stat
.PlayerStat
[I
] do
714 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
716 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
719 g_Console_Add('could not create gamestats file "' + fname
+ '"');
724 function g_Game_ModeToText(Mode
: Byte): string;
728 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
729 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
730 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
731 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
732 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
736 function g_Game_TextToMode(Mode
: string): Byte;
739 Mode
:= UpperCase(Mode
);
740 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
745 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
750 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
755 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
760 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
767 function g_Game_IsNet(): Boolean;
769 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
772 function g_Game_IsServer(): Boolean;
774 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
777 function g_Game_IsClient(): Boolean;
779 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
782 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
789 Result
.name
:= ExtractFileName(WAD
);
790 Result
.description
:= '';
793 w
:= TWADFile
.Create();
796 if not w
.GetResource('INTERSCRIPT', p
, len
) then
802 cfg
:= TConfig
.CreateMem(p
, len
);
803 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
804 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
805 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
806 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
812 procedure g_Game_FreeWAD();
816 for a
:= 0 to High(MegaWAD
.res
.pic
) do
817 if MegaWAD
.res
.pic
[a
] <> '' then
818 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
820 for a
:= 0 to High(MegaWAD
.res
.mus
) do
821 if MegaWAD
.res
.mus
[a
] <> '' then
822 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
824 MegaWAD
.res
.pic
:= nil;
825 MegaWAD
.res
.text := nil;
826 MegaWAD
.res
.anim
:= nil;
827 MegaWAD
.res
.mus
:= nil;
828 MegaWAD
.triggers
:= nil;
830 g_Texture_Delete('TEXTURE_endpic');
831 g_Sound_Delete('MUSIC_endmus');
833 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
834 gGameSettings
.WAD
:= '';
837 procedure g_Game_LoadWAD(WAD
: string);
846 gGameSettings
.WAD
:= WAD
;
847 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
850 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
852 w
:= TWADFile
.Create();
855 if not w
.GetResource('INTERSCRIPT', p
, len
) then
861 cfg
:= TConfig
.CreateMem(p
, len
);
866 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
867 if s = '' then Break;
870 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
871 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
873 g_Texture_CreateWADEx(s, s);
879 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
880 if s = '' then Break;
883 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
884 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
886 g_Music_CreateWADEx(s, s);
889 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
890 if MegaWAD
.endpic
<> '' then
892 TEXTUREFILTER
:= GL_LINEAR
;
893 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
894 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
895 TEXTUREFILTER
:= GL_NEAREST
;
897 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
898 if MegaWAD
.endmus
<> '' then
900 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
901 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
909 {procedure start_trigger(t: string);
913 function next_trigger(): Boolean;
917 procedure DisableCheats();
923 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
924 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
925 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
926 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
928 {$IF DEFINED(D2F_DEBUG)}
929 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
930 gAimLine
:= g_dbg_aimline_on
;
934 procedure g_Game_ExecuteEvent(Name
: String);
940 if gEvents
= nil then
942 for a
:= 0 to High(gEvents
) do
943 if gEvents
[a
].Name
= Name
then
945 if gEvents
[a
].Command
<> '' then
946 g_Console_Process(gEvents
[a
].Command
, True);
951 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
956 if gDelayedEvents
<> nil then
957 for a
:= 0 to High(gDelayedEvents
) do
958 if not gDelayedEvents
[a
].Pending
then
965 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
966 n
:= High(gDelayedEvents
);
968 gDelayedEvents
[n
].Pending
:= True;
969 gDelayedEvents
[n
].DEType
:= DEType
;
970 gDelayedEvents
[n
].DENum
:= Num
;
971 gDelayedEvents
[n
].DEStr
:= Str
;
972 if DEType
= DE_GLOBEVENT
then
973 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
975 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
985 if g_Game_IsNet
and g_Game_IsServer
then
986 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
990 gPauseHolmes
:= false;
993 g_Game_StopAllSounds(False);
998 EndingGameCounter
:= 0;
999 g_ActiveWindow
:= nil;
1001 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1002 gLMSRespawnTime
:= 0;
1005 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1010 begin // Ýòî áûë òåñò
1014 begin // Âûõîä â ãëàâíîå ìåíþ
1015 gMusic
.SetByName('MUSIC_MENU');
1017 if gState
<> STATE_SLIST
then
1019 g_GUI_ShowWindow('MainMenu');
1020 gState
:= STATE_MENU
;
1023 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1024 slReturnPressed
:= True;
1025 if g_Net_Slist_Fetch(slCurrent
) then
1027 if slCurrent
= nil then
1028 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1031 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1032 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1035 g_Game_ExecuteEvent('ongameend');
1039 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1041 if not g_Game_IsClient
then g_Game_Restart();
1044 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1046 // Ñòàòèñòèêà Ñâîåé èãðû:
1047 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1049 CustomStat
.GameTime
:= gTime
;
1050 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1051 CustomStat
.MapName
:= gMapInfo
.Name
;
1052 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1053 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1054 CustomStat
.TeamStat
:= gTeamStat
;
1056 CustomStat
.PlayerStat
:= nil;
1058 // Ñòàòèñòèêà èãðîêîâ:
1059 if gPlayers
<> nil then
1061 for a
:= 0 to High(gPlayers
) do
1062 if gPlayers
[a
] <> nil then
1064 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1065 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1068 Name
:= gPlayers
[a
].Name
;
1069 Frags
:= gPlayers
[a
].Frags
;
1070 Deaths
:= gPlayers
[a
].Death
;
1071 Kills
:= gPlayers
[a
].Kills
;
1072 Team
:= gPlayers
[a
].Team
;
1073 Color
:= gPlayers
[a
].Model
.Color
;
1074 Spectator
:= gPlayers
[a
].FSpectator
;
1078 SortGameStat(CustomStat
.PlayerStat
);
1080 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1083 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1084 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1085 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1086 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1088 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1091 StatShotDone
:= False;
1094 g_Game_ExecuteEvent('onmapend');
1095 if not g_Game_IsClient
then g_Player_ResetReady
;
1096 gInterReadyCount
:= 0;
1098 // Çàòóõàþùèé ýêðàí:
1099 EndingGameCounter
:= 255;
1100 gState
:= STATE_FOLD
;
1102 if gDefInterTime
< 0 then
1103 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1105 gInterEndTime
:= gDefInterTime
* 1000;
1108 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1110 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1111 SingleStat
.GameTime
:= gTime
;
1112 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1113 SingleStat
.TotalSecrets
:= gSecretsCount
;
1114 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1115 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1116 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1117 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1118 if SingleStat
.TwoPlayers
then
1120 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1121 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1124 g_Game_ExecuteEvent('onmapend');
1127 if gNextMap
<> '' then
1129 gMusic
.SetByName('MUSIC_INTERMUS');
1131 gState
:= STATE_INTERSINGLE
;
1134 g_Game_ExecuteEvent('oninter');
1136 else // Áîëüøå íåò êàðò
1138 // Çàòóõàþùèé ýêðàí:
1139 EndingGameCounter
:= 255;
1140 gState
:= STATE_FOLD
;
1145 // Îêîí÷àíèå îáðàáîòàíî:
1146 if gExit
<> EXIT_QUIT
then
1150 procedure drawTime(X
, Y
: Integer); inline;
1152 e_TextureFontPrint(x
, y
,
1153 Format('%d:%.2d:%.2d', [
1154 gTime
div 1000 div 3600,
1155 (gTime
div 1000 div 60) mod 60,
1156 gTime
div 1000 mod 60
1161 procedure DrawStat();
1163 pc
, x
, y
, w
, h
: Integer;
1164 w1
, w2
, w3
, w4
: Integer;
1166 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1169 stat
: TPlayerStatArray
;
1177 pc
:= g_Player_GetCount
;
1178 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1180 w
:= gScreenWidth
-(gScreenWidth
div 5);
1181 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1184 h
:= 40+ch
*5+(ch
+8)*pc
;
1185 x
:= (gScreenWidth
div 2)-(w
div 2);
1186 y
:= (gScreenHeight
div 2)-(h
div 2);
1188 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1189 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1191 drawTime(x
+w
-78, y
+8);
1193 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1194 map
:= g_ExtractFileName(gMapInfo
.Map
);
1195 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1197 case gGameSettings
.GameMode
of
1200 if gGameSettings
.MaxLives
= 0 then
1201 s1
:= _lc
[I_GAME_DM
]
1203 s1
:= _lc
[I_GAME_LMS
];
1204 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1205 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1210 if gGameSettings
.MaxLives
= 0 then
1211 s1
:= _lc
[I_GAME_TDM
]
1213 s1
:= _lc
[I_GAME_TLMS
];
1214 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1215 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1220 s1
:= _lc
[I_GAME_CTF
];
1221 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1222 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1227 if gGameSettings
.MaxLives
= 0 then
1228 s1
:= _lc
[I_GAME_COOP
]
1230 s1
:= _lc
[I_GAME_SURV
];
1231 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1232 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1243 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1245 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1247 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1249 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1250 gStdFont
, 200, 200, 200, 1);
1252 if NetMode
= NET_SERVER
then
1253 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1255 if NetMode
= NET_CLIENT
then
1256 e_TextureFontPrintEx(x
+8, y
+ 8,
1257 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1261 stat
:= g_Player_GetStats();
1264 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1265 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1267 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1269 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1273 for a
:= TEAM_RED
to TEAM_BLUE
do
1275 if a
= TEAM_RED
then
1277 s1
:= _lc
[I_GAME_TEAM_RED
];
1284 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1290 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1291 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1292 gStdFont
, r
, g
, b
, 1);
1294 _y
:= _y
+ch
+(ch
div 4);
1295 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1296 _y
:= _y
+(ch
div 4);
1298 for aa
:= 0 to High(stat
) do
1299 if stat
[aa
].Team
= a
then
1315 namestr
:= Format('[%5d] %s', [UID
, Name
])
1319 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1321 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1323 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1325 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1332 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1335 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1336 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1337 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1338 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1341 for aa
:= 0 to High(stat
) do
1355 namestr
:= Format('[%5d] %s', [UID
, Name
])
1359 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1360 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1362 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1364 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1366 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1368 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1374 procedure g_Game_Init();
1377 knownFiles
: array of AnsiString = nil;
1379 wext
, s
: AnsiString;
1384 gTempDelete
:= False;
1386 sfsGCDisable(); // temporary disable removing of temporary volumes
1389 TEXTUREFILTER
:= GL_LINEAR
;
1390 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1391 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1392 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1393 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1394 TEXTUREFILTER
:= GL_NEAREST
;
1396 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1397 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1398 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1400 g_Game_ClearLoading();
1401 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1402 g_Game_SetLoadingText('', 0, False);
1404 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1407 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1408 g_PlayerModel_LoadData();
1410 // load models from all possible wad types, in all known directories
1411 // this does a loosy job (linear search, ooph!), but meh
1412 for wext
in wadExtensions
do
1414 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1416 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1420 for s
in knownFiles
do
1422 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1430 SetLength(knownFiles
, length(knownFiles
)+1);
1431 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1433 until (FindNext(SR
) <> 0);
1439 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1441 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
);
1442 for s
in knownFiles
do
1444 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1448 gPauseMain
:= false;
1449 gPauseHolmes
:= false;
1452 {e_MouseInfo.Accel := 1.0;}
1454 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1457 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1458 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1459 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1460 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1461 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1464 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1468 gMusic
:= TMusic
.Create();
1469 gMusic
.SetByName('MUSIC_MENU');
1472 gGameSettings
.WarmupTime
:= 30;
1474 gState
:= STATE_MENU
;
1476 SetLength(gEvents
, 6);
1477 gEvents
[0].Name
:= 'ongamestart';
1478 gEvents
[1].Name
:= 'ongameend';
1479 gEvents
[2].Name
:= 'onmapstart';
1480 gEvents
[3].Name
:= 'onmapend';
1481 gEvents
[4].Name
:= 'oninter';
1482 gEvents
[5].Name
:= 'onwadend';
1484 sfsGCEnable(); // enable releasing unused volumes
1488 procedure g_Game_Free(freeTextures
: Boolean=true);
1490 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1491 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1493 g_Map_Free(freeTextures
);
1495 g_Player_RemoveAllCorpses();
1497 gGameSettings
.GameType
:= GT_NONE
;
1498 if gGameSettings
.GameMode
= GM_SINGLE
then
1499 gGameSettings
.GameMode
:= GM_DM
;
1500 gSwitchGameMode
:= gGameSettings
.GameMode
;
1503 gExitByTrigger
:= False;
1506 function IsActivePlayer(p
: TPlayer
): Boolean;
1511 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1514 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1521 if gPlayers
= nil then
1523 for a
:= Low(gPlayers
) to High(gPlayers
) do
1524 if IsActivePlayer(gPlayers
[a
]) then
1526 if gPlayers
[a
].UID
<> ID
then
1528 Result
:= gPlayers
[a
];
1533 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1539 if gPlayers
= nil then
1543 for a
:= Low(gPlayers
) to High(gPlayers
) do
1544 if IsActivePlayer(gPlayers
[a
]) then
1546 SetLength(ids
, Length(ids
) + 1);
1547 ids
[High(ids
)] := gPlayers
[a
].UID
;
1548 if gPlayers
[a
].UID
= Skip
then
1551 if Length(ids
) = 0 then
1556 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1559 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1565 if gPlayers
= nil then
1569 for a
:= Low(gPlayers
) to High(gPlayers
) do
1570 if IsActivePlayer(gPlayers
[a
]) then
1572 SetLength(ids
, Length(ids
) + 1);
1573 ids
[High(ids
)] := gPlayers
[a
].UID
;
1574 if gPlayers
[a
].UID
= Skip
then
1577 if Length(ids
) = 0 then
1580 Result
:= ids
[Length(ids
) - 1]
1582 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1585 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1591 if gPlayers
= nil then
1595 for a
:= Low(gPlayers
) to High(gPlayers
) do
1596 if IsActivePlayer(gPlayers
[a
]) then
1598 SetLength(ids
, Length(ids
) + 1);
1599 ids
[High(ids
)] := gPlayers
[a
].UID
;
1600 if gPlayers
[a
].UID
= Skip
then
1603 if Length(ids
) = 0 then
1605 if Length(ids
) = 1 then
1610 Result
:= ids
[Random(Length(ids
))];
1612 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1614 Result
:= ids
[Random(Length(ids
))];
1619 function GetRandomSpectMode(Current
: Byte): Byte;
1626 0: Result
:= SPECT_STATS
;
1627 1: Result
:= SPECT_MAPVIEW
;
1628 2: Result
:= SPECT_MAPVIEW
;
1629 3: Result
:= SPECT_PLAYERS
;
1630 4: Result
:= SPECT_PLAYERS
;
1631 5: Result
:= SPECT_PLAYERS
;
1632 6: Result
:= SPECT_PLAYERS
;
1634 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1638 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1644 if (plr
= nil) then exit
;
1645 if (p
= 2) then time
:= 1000 else time
:= 1;
1646 strafeDir
:= MoveButton
shr 4;
1647 MoveButton
:= MoveButton
and $0F;
1649 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1650 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1651 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1652 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1653 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1654 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1656 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1657 if MoveButton
= 1 then
1658 plr
.PressKey(KEY_LEFT
, time
)
1659 else if MoveButton
= 2 then
1660 plr
.PressKey(KEY_RIGHT
, time
);
1662 // if we have "strafe" key, turn off old strafe mechanics
1663 if gPlayerAction
[p
, ACTION_STRAFE
] then
1665 // new strafe mechanics
1666 if (strafeDir
= 0) then
1667 strafeDir
:= MoveButton
; // start strafing
1668 // now set direction according to strafe (reversed)
1669 if (strafeDir
= 2) then
1670 plr
.SetDirection(TDirection
.D_LEFT
)
1671 else if (strafeDir
= 1) then
1672 plr
.SetDirection(TDirection
.D_RIGHT
)
1676 strafeDir
:= 0; // not strafing anymore
1677 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1678 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1679 plr
.SetDirection(TDirection
.D_LEFT
)
1680 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1681 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1682 plr
.SetDirection(TDirection
.D_RIGHT
)
1683 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1684 else if MoveButton
<> 0 then
1685 plr
.SetDirection(TDirection(MoveButton
-1))
1688 // fix movebutton state
1689 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1691 // Îñòàëüíûå êëàâèøè:
1692 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1693 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1694 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1695 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1696 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1698 for i
:= WP_FACT
to WP_LACT
do
1700 if gWeaponAction
[p
, i
] then
1702 plr
.ProcessWeaponAction(i
);
1703 gWeaponAction
[p
, i
] := False
1707 for i
:= WP_FIRST
to WP_LAST
do
1709 if gSelectWeapon
[p
, i
] then
1711 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1712 gSelectWeapon
[p
, i
] := False
1716 // HACK: add dynlight here
1717 if gwin_k8_enable_light_experiments
then
1719 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1721 g_playerLight
:= true;
1723 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1725 g_playerLight
:= false;
1729 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1732 // HACK: don't have a "key was pressed" function
1733 procedure InterReady();
1735 if InterReadyTime
> gTime
then Exit
;
1736 InterReadyTime
:= gTime
+ 3000;
1737 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1740 procedure g_Game_PreUpdate();
1742 // these are in separate PreUpdate functions because they can interact during Update()
1743 // and are synced over the net
1744 // we don't care that much about corpses and gibs
1745 g_Player_PreUpdate();
1746 g_Monsters_PreUpdate();
1747 g_Items_PreUpdate();
1748 g_Weapon_PreUpdate();
1751 procedure g_Game_Update();
1753 Msg
: g_gui
.TMessage
;
1759 function sendMonsPos (mon
: TMonster
): Boolean;
1761 result
:= false; // don't stop
1762 // this will also reset "need-send" flag
1763 if mon
.gncNeedSend
then
1765 MH_SEND_MonsterPos(mon
.UID
);
1767 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1769 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1771 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1773 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1777 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1779 result
:= false; // don't stop
1780 // this will also reset "need-send" flag
1781 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1785 reliableUpdate
: Boolean;
1790 // Ïîðà âûêëþ÷àòü èãðó:
1791 if gExit
= EXIT_QUIT
then
1793 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1797 if gExit
= EXIT_QUIT
then
1801 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1802 // no need to, as we'll do it in event handler
1804 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1807 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1809 gExit
:= EXIT_SIMPLE
;
1814 // process master server communications
1815 g_Net_Slist_Pulse();
1818 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1819 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1820 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1821 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1823 if g_Game_IsNet
and g_Game_IsServer
then
1825 gInterTime
:= gInterTime
+ GAME_TICK
;
1826 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1827 if a
<> gServInterTime
then
1829 gServInterTime
:= a
;
1830 MH_SEND_TimeSync(gServInterTime
);
1834 if (not g_Game_IsClient
) and
1838 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1839 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1840 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1841 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1843 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1844 and (g_ActiveWindow
= nil)
1846 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1849 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1850 g_Game_StopAllSounds(True);
1852 if gMapOnce
then // Ýòî áûë òåñò
1853 gExit
:= EXIT_SIMPLE
1855 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1856 g_Game_ChangeMap(gNextMap
)
1857 else // Ñëåäóþùåé êàðòû íåò
1859 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1861 // Âûõîä â ãëàâíîå ìåíþ:
1863 g_GUI_ShowWindow('MainMenu');
1864 gMusic
.SetByName('MUSIC_MENU');
1866 gState
:= STATE_MENU
;
1869 // Ôèíàëüíàÿ êàðòèíêà:
1870 g_Game_ExecuteEvent('onwadend');
1872 if not gMusic
.SetByName('MUSIC_endmus') then
1873 gMusic
.SetByName('MUSIC_STDENDMUS');
1875 gState
:= STATE_ENDPIC
;
1877 g_Game_ExecuteEvent('ongameend');
1882 else if g_Game_IsClient
and
1885 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1886 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1887 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1888 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1890 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1891 and (g_ActiveWindow
= nil)
1899 if gState
= STATE_INTERTEXT
then
1900 if InterText
.counter
> 0 then
1901 InterText
.counter
:= InterText
.counter
- 1;
1904 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1906 if EndingGameCounter
= 0 then
1908 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1909 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1911 gState
:= STATE_INTERCUSTOM
;
1912 InterReadyTime
:= -1;
1913 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1915 g_Game_ExecuteEvent('onwadend');
1916 if not gMusic
.SetByName('MUSIC_endmus') then
1917 gMusic
.SetByName('MUSIC_STDENDMUS');
1920 gMusic
.SetByName('MUSIC_ROUNDMUS');
1924 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1926 gMusic
.SetByName('MUSIC_INTERMUS');
1928 gState
:= STATE_INTERSINGLE
;
1931 g_Game_ExecuteEvent('oninter');
1934 DecMin(EndingGameCounter
, 6, 0);
1937 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1939 if gMapOnce
then // Ýòî áûë òåñò
1941 gExit
:= EXIT_SIMPLE
;
1947 g_Serverlist_Control(slCurrent
, slTable
);
1950 // Ñòàòèñòèêà ïî Tab:
1952 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1955 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1957 // Âðåìÿ += 28 ìèëëèñåêóíä:
1958 gTime
:= gTime
+ GAME_TICK
;
1960 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1961 if MessageTime
= 0 then
1963 if MessageTime
> 0 then
1964 MessageTime
:= MessageTime
- 1;
1966 if (g_Game_IsServer
) then
1968 // Áûë çàäàí ëèìèò âðåìåíè:
1969 if (gGameSettings
.TimeLimit
> 0) then
1970 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1971 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1976 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1977 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1978 g_Game_RestartRound(gLMSSoftSpawn
);
1980 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1981 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1983 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1985 g_Console_Process(gVoteCommand
);
1987 gVotePassed
:= False;
1990 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1991 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1992 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1993 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1994 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1996 // Áûë çàäàí ëèìèò ïîáåä:
1997 if (gGameSettings
.GoalLimit
> 0) then
2001 if gGameSettings
.GameMode
= GM_DM
then
2002 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2003 for i
:= 0 to High(gPlayers
) do
2004 if gPlayers
[i
] <> nil then
2005 if gPlayers
[i
].Frags
> b
then
2006 b
:= gPlayers
[i
].Frags
;
2009 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2010 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2011 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2014 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2015 if b
>= gGameSettings
.GoalLimit
then
2022 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2023 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2024 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2025 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2027 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2028 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2029 end // if not console
2032 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2034 // process weapon switch queue
2038 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2039 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2041 if not gSpectKeyPress
then
2043 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2045 // switch spect mode
2047 SPECT_NONE
: ; // not spectator
2049 SPECT_MAPVIEW
: Inc(gSpectMode
);
2050 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2052 gSpectKeyPress
:= True;
2054 if (gSpectMode
= SPECT_MAPVIEW
)
2055 and (not gSpectAuto
) then
2057 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2058 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2059 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2060 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2061 if gPlayerAction
[0, ACTION_LOOKUP
] then
2062 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2063 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2064 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2065 if gWeaponAction
[0, WP_PREV
] then
2068 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2069 gWeaponAction
[0, WP_PREV
] := False;
2071 if gWeaponAction
[0, WP_NEXT
] then
2074 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2075 gWeaponAction
[0, WP_NEXT
] := False;
2078 if (gSpectMode
= SPECT_PLAYERS
)
2079 and (not gSpectAuto
) then
2081 if gPlayerAction
[0, ACTION_LOOKUP
] then
2084 gSpectViewTwo
:= True;
2085 gSpectKeyPress
:= True;
2087 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2089 // remove second view
2090 gSpectViewTwo
:= False;
2091 gSpectKeyPress
:= True;
2093 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2095 // prev player (view 1)
2096 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2097 gSpectKeyPress
:= True;
2099 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2101 // next player (view 1)
2102 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2103 gSpectKeyPress
:= True;
2105 if gWeaponAction
[0, WP_PREV
] then
2107 // prev player (view 2)
2108 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2109 gWeaponAction
[0, WP_PREV
] := False;
2111 if gWeaponAction
[0, WP_NEXT
] then
2113 // next player (view 2)
2114 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2115 gWeaponAction
[0, WP_NEXT
] := False;
2118 if gPlayerAction
[0, ACTION_ATTACK
] then
2120 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2123 gSpectAutoNext
:= 0;
2124 gSpectViewTwo
:= False;
2125 gSpectKeyPress
:= True;
2130 gSpectMode
:= SPECT_STATS
;
2131 gSpectAuto
:= False;
2132 gSpectKeyPress
:= True;
2137 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2138 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2139 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2140 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2141 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2142 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2143 gSpectKeyPress
:= False;
2147 if gSpectMode
= SPECT_MAPVIEW
then
2149 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2151 gSpectAutoNext
:= gTime
2154 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2156 gSpectAutoNext
:= gTime
2160 if gSpectAutoNext
<= gTime
then
2162 if gSpectAutoNext
> 0 then
2164 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2168 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2169 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2170 gSpectAutoStepX
:= Random(9) - 4;
2171 gSpectAutoStepY
:= Random(9) - 4;
2172 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2173 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2174 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2175 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2176 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2177 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2181 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2186 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2187 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2188 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2194 // Îáíîâëÿåì âñå îñòàëüíîå:
2197 g_Triggers_Update();
2199 g_Monsters_Update();
2201 g_Player_UpdateAll();
2202 g_Player_UpdatePhysicalObjects();
2204 // server: send newly spawned monsters unconditionally
2205 if (gGameSettings
.GameType
= GT_SERVER
) then
2207 if (Length(gMonstersSpawned
) > 0) then
2209 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2210 SetLength(gMonstersSpawned
, 0);
2214 if (gSoundTriggerTime
> 8) then
2216 g_Game_UpdateTriggerSounds();
2217 gSoundTriggerTime
:= 0;
2221 Inc(gSoundTriggerTime
);
2224 if (NetMode
= NET_SERVER
) then
2226 Inc(NetTimeToUpdate
);
2227 Inc(NetTimeToReliable
);
2229 // send monster updates
2230 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2232 // send all monsters (periodic sync)
2233 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2235 for I
:= 0 to High(gPlayers
) do
2237 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2240 g_Mons_ForEach(sendMonsPos
);
2242 if reliableUpdate
then
2244 NetTimeToReliable
:= 0;
2245 NetTimeToUpdate
:= NetUpdateRate
;
2249 NetTimeToUpdate
:= 0;
2254 // send only mosters with some unexpected changes
2255 g_Mons_ForEach(sendMonsPosUnexpected
);
2258 // send unexpected platform changes
2259 g_Map_NetSendInterestingPanels();
2261 g_Net_Slist_ServerUpdate();
2263 if NetUseMaster then
2265 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2267 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2269 NetTimeToMaster := gTime + NetMasterRate;
2274 else if (NetMode
= NET_CLIENT
) then
2276 MC_SEND_PlayerPos();
2278 end; // if gameOn ...
2280 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2281 if g_ActiveWindow
<> nil then
2283 w
:= e_GetFirstKeyPressed();
2285 if (w
<> IK_INVALID
) then
2287 Msg
.Msg
:= MESSAGE_DIKEY
;
2289 g_ActiveWindow
.OnMessage(Msg
);
2292 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2293 if g_ActiveWindow
<> nil then
2294 g_ActiveWindow
.Update();
2296 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2297 if gResolutionChange
then
2299 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2300 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2301 gResolutionChange
:= False;
2302 g_ActiveWindow
:= nil;
2305 // Íóæíî ñìåíèòü ÿçûê:
2306 if gLanguageChange
then
2308 //e_WriteLog('Read language file', MSG_NOTIFY);
2309 //g_Language_Load(DataDir + gLanguage + '.txt');
2310 g_Language_Set(gLanguage
);
2314 gLanguageChange
:= False;
2318 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2319 if e_KeyPressed(IK_F10
) and
2321 (not gConsoleShow
) and
2322 (g_ActiveWindow
= nil) then
2327 Time
:= sys_GetTicks() {div 1000};
2329 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2330 if gDelayedEvents
<> nil then
2331 for a
:= 0 to High(gDelayedEvents
) do
2332 if gDelayedEvents
[a
].Pending
and
2334 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2335 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2338 case gDelayedEvents
[a
].DEType
of
2340 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2343 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2347 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2348 if g_Game_IsNet
and g_Game_IsServer
then
2349 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2353 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2355 gDelayedEvents
[a
].Pending
:= False;
2358 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2359 UPSCounter
:= UPSCounter
+ 1;
2360 if Time
- UPSTime
>= 1000 then
2369 g_Weapon_AddDynLights();
2370 g_Items_AddDynLights();
2374 procedure g_Game_LoadChatSounds(Resource
: string);
2377 FileName
, Snd
: string;
2379 len
, cnt
, tags
, i
, j
: Integer;
2382 FileName
:= g_ExtractWadName(Resource
);
2384 WAD
:= TWADFile
.Create();
2385 WAD
.ReadFile(FileName
);
2387 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2394 cfg
:= TConfig
.CreateMem(p
, len
);
2395 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2397 SetLength(gChatSounds
, cnt
);
2398 for i
:= 0 to Length(gChatSounds
) - 1 do
2400 gChatSounds
[i
].Sound
:= nil;
2401 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2402 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2403 if (Snd
= '') or (Tags
<= 0) then
2405 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2406 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2407 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2408 SetLength(gChatSounds
[i
].Tags
, tags
);
2409 for j
:= 0 to tags
- 1 do
2410 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2411 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2418 procedure g_Game_FreeChatSounds();
2422 for i
:= 0 to Length(gChatSounds
) - 1 do
2424 gChatSounds
[i
].Sound
.Free();
2425 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2427 SetLength(gChatSounds
, 0);
2431 procedure g_Game_LoadData();
2438 if DataLoaded
then Exit
;
2440 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2442 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2443 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2444 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2445 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2446 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2447 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2448 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2449 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2450 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2451 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2452 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2453 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2454 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2455 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2456 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2459 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2460 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2461 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2462 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2466 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2467 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2468 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2469 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2470 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
2476 hasPBarGfx
:= false;
2480 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2481 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2482 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2483 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2484 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2485 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2486 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2487 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2488 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2489 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2490 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2491 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2492 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2493 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2494 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2495 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2496 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2497 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2498 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2499 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2500 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2507 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2508 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2509 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2510 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2511 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2512 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2513 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2514 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2515 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2516 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2517 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2518 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2520 goodsnd
[0] := TPlayableSound
.Create();
2521 goodsnd
[1] := TPlayableSound
.Create();
2522 goodsnd
[2] := TPlayableSound
.Create();
2523 goodsnd
[3] := TPlayableSound
.Create();
2525 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2526 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2527 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2528 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2530 killsnd
[0] := TPlayableSound
.Create();
2531 killsnd
[1] := TPlayableSound
.Create();
2532 killsnd
[2] := TPlayableSound
.Create();
2533 killsnd
[3] := TPlayableSound
.Create();
2535 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2536 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2537 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2538 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2540 hahasnd
[0] := TPlayableSound
.Create();
2541 hahasnd
[1] := TPlayableSound
.Create();
2542 hahasnd
[2] := TPlayableSound
.Create();
2544 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2545 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2546 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2548 sound_get_flag
[0] := TPlayableSound
.Create();
2549 sound_get_flag
[1] := TPlayableSound
.Create();
2550 sound_lost_flag
[0] := TPlayableSound
.Create();
2551 sound_lost_flag
[1] := TPlayableSound
.Create();
2552 sound_ret_flag
[0] := TPlayableSound
.Create();
2553 sound_ret_flag
[1] := TPlayableSound
.Create();
2554 sound_cap_flag
[0] := TPlayableSound
.Create();
2555 sound_cap_flag
[1] := TPlayableSound
.Create();
2557 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2558 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2559 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2560 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2561 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2562 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2563 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2564 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2566 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2568 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2571 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2572 g_Weapon_LoadData();
2574 g_Monsters_LoadData();
2579 procedure g_Game_FreeData();
2581 if not DataLoaded
then Exit
;
2584 g_Weapon_FreeData();
2585 g_Monsters_FreeData();
2587 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2589 g_Texture_Delete('NOTEXTURE');
2590 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2591 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2592 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2593 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2594 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2595 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2596 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2597 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2598 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2599 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2600 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2601 g_Frames_DeleteByName('FRAMES_TELEPORT');
2602 g_Frames_DeleteByName('FRAMES_PUNCH');
2603 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2604 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2605 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2606 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2607 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2608 g_Sound_Delete('SOUND_GAME_TELEPORT');
2609 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2610 g_Sound_Delete('SOUND_GAME_SECRET');
2611 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2612 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2613 g_Sound_Delete('SOUND_GAME_BULK1');
2614 g_Sound_Delete('SOUND_GAME_BULK2');
2615 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2616 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2617 g_Sound_Delete('SOUND_GAME_BURNING');
2618 g_Sound_Delete('SOUND_GAME_SWITCH1');
2619 g_Sound_Delete('SOUND_GAME_SWITCH0');
2626 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2627 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2628 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2629 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2636 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2637 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2638 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2639 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2645 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2646 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2647 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2649 sound_get_flag
[0].Free();
2650 sound_get_flag
[1].Free();
2651 sound_lost_flag
[0].Free();
2652 sound_lost_flag
[1].Free();
2653 sound_ret_flag
[0].Free();
2654 sound_ret_flag
[1].Free();
2655 sound_cap_flag
[0].Free();
2656 sound_cap_flag
[1].Free();
2658 g_Sound_Delete('SOUND_CTF_GET1');
2659 g_Sound_Delete('SOUND_CTF_GET2');
2660 g_Sound_Delete('SOUND_CTF_LOST1');
2661 g_Sound_Delete('SOUND_CTF_LOST2');
2662 g_Sound_Delete('SOUND_CTF_RETURN1');
2663 g_Sound_Delete('SOUND_CTF_RETURN2');
2664 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2665 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2667 g_Game_FreeChatSounds();
2669 DataLoaded
:= False;
2672 procedure DrawCustomStat();
2678 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2679 s1
, s2
, topstr
: String;
2681 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2685 if g_Console_Action(ACTION_SCORES
) then
2687 if not gStatsPressed
then
2689 gStatsOff
:= not gStatsOff
;
2690 gStatsPressed
:= True;
2694 gStatsPressed
:= False;
2698 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2699 w
:= (Length(s1
) * ww2
) div 2;
2700 x
:= gScreenWidth
div 2 - w
;
2702 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2706 if (gGameSettings
.GameMode
= GM_COOP
) then
2708 if gMissionFailed
then
2709 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2711 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2714 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2716 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2717 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2719 if g_Game_IsNet
then
2721 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2722 if not gChatShow
then
2723 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2724 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2727 if g_Game_IsClient
then
2728 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2730 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2731 if not gChatShow
then
2732 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2733 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2738 w
:= gScreenWidth
-x
*2;
2744 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2745 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2747 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2749 case CustomStat
.GameMode
of
2752 if gGameSettings
.MaxLives
= 0 then
2753 s1
:= _lc
[I_GAME_DM
]
2755 s1
:= _lc
[I_GAME_LMS
];
2759 if gGameSettings
.MaxLives
= 0 then
2760 s1
:= _lc
[I_GAME_TDM
]
2762 s1
:= _lc
[I_GAME_TLMS
];
2764 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2767 if gGameSettings
.MaxLives
= 0 then
2768 s1
:= _lc
[I_GAME_COOP
]
2770 s1
:= _lc
[I_GAME_SURV
];
2776 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2780 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2781 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2784 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2785 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2786 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2787 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2789 pc
:= Length(CustomStat
.PlayerStat
);
2790 if pc
= 0 then Exit
;
2792 if CustomStat
.GameMode
= GM_COOP
then
2794 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2796 s2
:= _lc
[I_GAME_MONSTERS
];
2797 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2798 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2800 s2
:= _lc
[I_GAME_SECRETS
];
2801 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2802 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2805 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2807 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2808 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2809 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2811 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2812 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2813 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2817 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2822 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2823 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2824 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2826 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2829 for t
:= TEAM_RED
to TEAM_BLUE
do
2831 if t
= TEAM_RED
then
2833 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2834 gStdFont
, 255, 0, 0, 1);
2835 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2836 gStdFont
, 255, 0, 0, 1);
2843 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2844 gStdFont
, 0, 0, 255, 1);
2845 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2846 gStdFont
, 0, 0, 255, 1);
2852 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2855 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2856 if CustomStat
.PlayerStat
[p
].Team
= t
then
2857 with CustomStat
.PlayerStat
[p
] do
2871 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2872 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2874 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2875 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2876 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2883 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2886 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2887 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2888 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2891 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2892 with CustomStat
.PlayerStat
[p
] do
2894 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2901 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2902 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2904 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2905 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2906 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2911 // HACK: take stats screenshot immediately after the first frame of the stats showing
2912 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2914 g_TakeScreenShot('stats/' + StatFilename
);
2915 StatShotDone
:= True;
2919 procedure DrawSingleStat();
2921 tm
, key_x
, val_x
, y
: Integer;
2925 procedure player_stat(n
: Integer);
2931 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2932 s2
:= Format(' %d', [gTotalMonsters
]);
2934 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2935 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2936 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2937 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2939 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2940 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2942 // "Kills-per-minute: ##.#":
2943 s1
:= _lc
[I_MENU_INTER_KPM
];
2945 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2947 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2948 s2
:= Format(' %.1f', [kpm
]);
2950 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2951 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2953 // "Secrets found: # / #":
2954 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2955 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2957 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2958 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2959 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2960 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2962 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2963 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2967 // "Level Complete":
2968 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2969 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2971 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2972 s1
:= _lc
[I_MENU_INTER_KPM
];
2973 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2976 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2978 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2979 val_x
:= key_x
+ w1
;
2982 tm
:= SingleStat
.GameTime
div 1000;
2983 s1
:= _lc
[I_MENU_INTER_TIME
];
2984 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2986 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2987 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2989 if SingleStat
.TwoPlayers
then
2992 s1
:= _lc
[I_MENU_PLAYER_1
];
2993 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2994 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2996 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3001 s1
:= _lc
[I_MENU_PLAYER_2
];
3002 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3003 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3005 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3011 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3017 procedure DrawLoadingStat();
3018 procedure drawRect (x
, y
, w
, h
: Integer);
3020 if (w
< 1) or (h
< 1) then exit
;
3022 glVertex2f(x
+0.375, y
+0.375);
3023 glVertex2f(x
+w
+0.375, y
+0.375);
3024 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3025 glVertex2f(x
+0.375, y
+h
+0.375);
3029 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3031 rectW
, rectH
: Integer;
3038 idl
, idr
, idb
, idm
: LongWord;
3042 if (total
< 1) then exit
;
3043 if (cur
< 1) then exit
; // don't blink
3044 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3045 //if (cur < 0) then cur := 0;
3046 //if (cur > total) then cur := total;
3049 if (hasPBarGfx
) then
3051 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3052 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3053 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3054 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3055 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3056 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3057 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3058 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3060 //rectW := gScreenWidth-360;
3061 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3064 x0
:= (gScreenWidth
-rectW
) div 2;
3065 y0
:= gScreenHeight
-rectH
-64;
3066 if (y0
< 2) then y0
:= 2;
3068 glEnable(GL_SCISSOR_TEST
);
3071 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3072 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3073 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3076 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3078 while (f
< x0
+rectW
) do
3080 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3085 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3086 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3089 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3090 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3094 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3100 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3104 rectW
:= gScreenWidth
-64;
3107 x0
:= (gScreenWidth
-rectW
) div 2;
3108 y0
:= gScreenHeight
-rectH
-64;
3109 if (y0
< 2) then y0
:= 2;
3111 glDisable(GL_BLEND
);
3112 glDisable(GL_TEXTURE_2D
);
3114 //glClearColor(0, 0, 0, 0);
3115 //glClear(GL_COLOR_BUFFER_BIT);
3117 glColor4ub(127, 127, 127, 255);
3118 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3120 glColor4ub(0, 0, 0, 255);
3121 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3123 glColor4ub(127, 127, 127, 255);
3124 wdt
:= rectW
*cur
div total
;
3125 if (wdt
> rectW
) then wdt
:= rectW
;
3126 drawRect(x0
, y0
, wdt
, rectH
);
3135 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3137 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3138 yy
:= (gScreenHeight
div 3);
3139 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3140 xx
:= (gScreenWidth
div 3);
3144 for i
:= 0 to NextMsg
-1 do
3146 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3147 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3151 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3152 yy
:= yy
+ LOADING_INTERLINE
;
3153 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3158 procedure DrawMenuBackground(tex
: AnsiString);
3164 if g_Texture_Get(tex
, ID
) then
3166 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3167 e_GetTextureSize(ID
, @w
, @h
);
3169 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3171 w
:= trunc(w
* (gScreenHeight
/ h
));
3172 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3174 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3177 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3179 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3181 function monDraw (mon
: TMonster
): Boolean;
3183 result
:= false; // don't stop
3188 // Ëåâûé âåðõíèé óãîë
3189 aX
:= Obj
.X
div ScaleSz
+ 1;
3190 aY
:= Obj
.Y
div ScaleSz
+ 1;
3192 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3193 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3194 // Ïðàâûé íèæíèé óãîë
3195 aX2
:= aX
+ aX2
- 1;
3196 aY2
:= aY
+ aY2
- 1;
3197 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3203 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3204 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3207 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3208 ScaleSz
:= 16 div Scale
;
3209 // Ðàçìåðû ìèíè-êàðòû:
3210 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3211 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3213 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3215 if gWalls
<> nil then
3218 for a
:= 0 to High(gWalls
) do
3220 if PanelType
<> 0 then
3222 // Ëåâûé âåðõíèé óãîë:
3223 aX
:= X
div ScaleSz
;
3224 aY
:= Y
div ScaleSz
;
3226 aX2
:= max(Width
div ScaleSz
, 1);
3227 aY2
:= max(Height
div ScaleSz
, 1);
3228 // Ïðàâûé íèæíèé óãîë:
3229 aX2
:= aX
+ aX2
- 1;
3230 aY2
:= aY
+ aY2
- 1;
3233 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3234 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3235 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3239 if gSteps
<> nil then
3242 for a
:= 0 to High(gSteps
) do
3244 if PanelType
<> 0 then
3246 // Ëåâûé âåðõíèé óãîë:
3247 aX
:= X
div ScaleSz
;
3248 aY
:= Y
div ScaleSz
;
3250 aX2
:= max(Width
div ScaleSz
, 1);
3251 aY2
:= max(Height
div ScaleSz
, 1);
3252 // Ïðàâûé íèæíèé óãîë:
3253 aX2
:= aX
+ aX2
- 1;
3254 aY2
:= aY
+ aY2
- 1;
3256 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3259 if gLifts
<> nil then
3262 for a
:= 0 to High(gLifts
) do
3264 if PanelType
<> 0 then
3266 // Ëåâûé âåðõíèé óãîë:
3267 aX
:= X
div ScaleSz
;
3268 aY
:= Y
div ScaleSz
;
3270 aX2
:= max(Width
div ScaleSz
, 1);
3271 aY2
:= max(Height
div ScaleSz
, 1);
3272 // Ïðàâûé íèæíèé óãîë:
3273 aX2
:= aX
+ aX2
- 1;
3274 aY2
:= aY
+ aY2
- 1;
3277 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3278 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3279 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3280 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3284 if gWater
<> nil then
3287 for a
:= 0 to High(gWater
) do
3289 if PanelType
<> 0 then
3291 // Ëåâûé âåðõíèé óãîë:
3292 aX
:= X
div ScaleSz
;
3293 aY
:= Y
div ScaleSz
;
3295 aX2
:= max(Width
div ScaleSz
, 1);
3296 aY2
:= max(Height
div ScaleSz
, 1);
3297 // Ïðàâûé íèæíèé óãîë:
3298 aX2
:= aX
+ aX2
- 1;
3299 aY2
:= aY
+ aY2
- 1;
3301 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3304 if gAcid1
<> nil then
3306 // Ðèñóåì êèñëîòó 1:
3307 for a
:= 0 to High(gAcid1
) do
3309 if PanelType
<> 0 then
3311 // Ëåâûé âåðõíèé óãîë:
3312 aX
:= X
div ScaleSz
;
3313 aY
:= Y
div ScaleSz
;
3315 aX2
:= max(Width
div ScaleSz
, 1);
3316 aY2
:= max(Height
div ScaleSz
, 1);
3317 // Ïðàâûé íèæíèé óãîë:
3318 aX2
:= aX
+ aX2
- 1;
3319 aY2
:= aY
+ aY2
- 1;
3321 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3324 if gAcid2
<> nil then
3326 // Ðèñóåì êèñëîòó 2:
3327 for a
:= 0 to High(gAcid2
) do
3329 if PanelType
<> 0 then
3331 // Ëåâûé âåðõíèé óãîë:
3332 aX
:= X
div ScaleSz
;
3333 aY
:= Y
div ScaleSz
;
3335 aX2
:= max(Width
div ScaleSz
, 1);
3336 aY2
:= max(Height
div ScaleSz
, 1);
3337 // Ïðàâûé íèæíèé óãîë:
3338 aX2
:= aX
+ aX2
- 1;
3339 aY2
:= aY
+ aY2
- 1;
3341 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3344 if gPlayers
<> nil then
3347 for a
:= 0 to High(gPlayers
) do
3348 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3350 // Ëåâûé âåðõíèé óãîë:
3351 aX
:= Obj
.X
div ScaleSz
+ 1;
3352 aY
:= Obj
.Y
div ScaleSz
+ 1;
3354 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3355 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3356 // Ïðàâûé íèæíèé óãîë:
3357 aX2
:= aX
+ aX2
- 1;
3358 aY2
:= aY
+ aY2
- 1;
3360 if gPlayers
[a
] = p
then
3361 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3364 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3365 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3366 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3371 g_Mons_ForEach(monDraw
);
3376 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3378 if not hasAmbient
then exit
;
3379 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3383 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3384 //FIXME: broken for splitscreen mode
3385 procedure renderDynLightsInternal ();
3387 //hasAmbient: Boolean;
3388 //ambColor: TDFColor;
3390 lx
, ly
, lrad
: Integer;
3391 scxywh
: array[0..3] of GLint
;
3394 if e_NoGraphics
then exit
;
3396 //TODO: lights should be in separate grid, i think
3397 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3398 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3401 //ambColor := gCurrentMap['light_ambient'].rgba;
3402 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3404 { // this will multiply incoming color to alpha from framebuffer
3406 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3410 * light rendering: (INVALID!)
3411 * glStencilFunc(GL_EQUAL, 0, $ff);
3413 * glClear(GL_STENCIL_BUFFER_BIT);
3414 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3415 * draw shadow volume into stencil buffer
3416 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3417 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3419 * draw color-less quad with light alpha (WARNING! don't touch color!)
3420 * glEnable(GL_BLEND);
3421 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3422 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3424 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3425 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3427 // setup OpenGL parameters
3428 glStencilMask($FFFFFFFF);
3429 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3430 glEnable(GL_STENCIL_TEST
);
3431 glEnable(GL_SCISSOR_TEST
);
3432 glClear(GL_STENCIL_BUFFER_BIT
);
3433 glStencilFunc(GL_EQUAL
, 0, $ff);
3435 for lln
:= 0 to g_dynLightCount
-1 do
3437 lx
:= g_dynLights
[lln
].x
;
3438 ly
:= g_dynLights
[lln
].y
;
3439 lrad
:= g_dynLights
[lln
].radius
;
3440 if (lrad
< 3) then continue
;
3442 if (lx
-sX
+lrad
< 0) then continue
;
3443 if (ly
-sY
+lrad
< 0) then continue
;
3444 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3445 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3447 // set scissor to optimize drawing
3448 if (g_dbg_scale
= 1.0) then
3450 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3454 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3456 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3457 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3458 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3459 // draw extruded panels
3460 glDisable(GL_TEXTURE_2D
);
3461 glDisable(GL_BLEND
);
3462 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3463 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3464 // render light texture
3465 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3466 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3469 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3470 glEnable(GL_TEXTURE_2D
);
3471 // color and opacity
3472 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3473 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3475 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3476 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3477 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3478 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3483 glDisable(GL_STENCIL_TEST
);
3484 glDisable(GL_BLEND
);
3485 glDisable(GL_SCISSOR_TEST
);
3486 //glScissor(0, 0, sWidth, sHeight);
3488 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3489 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3493 function fixViewportForScale (): Boolean;
3495 nx0
, ny0
, nw
, nh
: Integer;
3498 if (g_dbg_scale
<> 1.0) then
3501 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3502 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3503 nw
:= round(sWidth
/g_dbg_scale
);
3504 nh
:= round(sHeight
/g_dbg_scale
);
3513 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3514 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3515 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3517 TDrawCB
= procedure ();
3520 hasAmbient
: Boolean;
3522 doAmbient
: Boolean = false;
3524 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3529 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3530 if gdbg_map_use_accel_render
then
3532 tagmask
:= panelTypeToTag(panType
);
3533 while (gDrawPanelList
.count
> 0) do
3535 pan
:= TPanel(gDrawPanelList
.front());
3536 if ((pan
.tag
and tagmask
) = 0) then break
;
3537 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3538 gDrawPanelList
.popFront();
3543 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3545 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3548 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3550 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3551 if assigned(cb
) then cb();
3552 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3556 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3558 // our accelerated renderer will collect all panels to gDrawPanelList
3559 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3560 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3561 if gdbg_map_use_accel_render
then
3563 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3565 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3567 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3568 g_Map_DrawBack(backXOfs
, backYOfs
);
3569 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3571 if setTransMatrix
then
3573 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3574 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3575 glTranslatef(-sX
, -sY
, 0);
3579 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3580 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3585 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3586 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3587 glClear(GL_COLOR_BUFFER_BIT);
3590 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3593 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3594 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3595 drawOther('items', @g_Items_Draw
);
3596 drawOther('weapons', @g_Weapon_Draw
);
3597 drawOther('shells', @g_Player_DrawShells
);
3598 drawOther('drawall', @g_Player_DrawAll
);
3599 drawOther('corpses', @g_Player_DrawCorpses
);
3600 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3601 drawOther('monsters', @g_Monsters_Draw
);
3602 drawOther('itemdrop', @g_Items_DrawDrop
);
3603 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3604 drawOther('gfx', @g_GFX_Draw
);
3605 drawOther('flags', @g_Map_DrawFlags
);
3606 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3607 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3608 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3609 drawOther('dynlights', @renderDynLightsInternal
);
3611 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3613 renderAmbientQuad(hasAmbient
, ambColor
);
3617 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3620 if g_debug_HealthBar
then
3622 g_Monsters_DrawHealth();
3623 g_Player_DrawHealth();
3626 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3630 procedure DrawMapView(x
, y
, w
, h
: Integer);
3637 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3638 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3645 fixViewportForScale();
3646 renderMapInternal(-bx
, -by
, true);
3652 procedure DrawPlayer(p
: TPlayer
);
3654 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3658 if (p
= nil) or (p
.FDummy
) then
3661 g_Map_DrawBack(0, 0);
3666 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3667 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3673 camObj
:= p
.getCameraObj();
3674 camObj
.lerp(gLerpFactor
, fX
, fY
);
3675 px
:= fX
+ PLAYER_RECT_CX
;
3676 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3678 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3680 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3681 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3683 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3684 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3686 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3687 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3690 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3693 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3694 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3697 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3702 // scaled, ignore level bounds
3703 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3704 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3709 sWidth
:= gPlayerScreenSize
.X
;
3710 sHeight
:= gPlayerScreenSize
.Y
;
3711 fixViewportForScale();
3713 i
:= py
- (sY
+ sHeight
div 2);
3714 if (p
.IncCam
> 0) then
3716 // clamp to level bounds
3717 if (sY
- p
.IncCam
< 0) then
3718 p
.IncCam
:= nclamp(sY
, 0, 120);
3719 // clamp around player position
3721 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3723 else if (p
.IncCam
< 0) then
3725 // clamp to level bounds
3726 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3727 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3728 // clamp around player position
3730 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3733 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3735 if (not g_dbg_ignore_bounds
) then
3737 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3738 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3739 if (sX
< 0) then sX
:= 0;
3740 if (sY
< 0) then sY
:= 0;
3743 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3744 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3746 //r_smallmap_h: 0: left; 1: center; 2: right
3747 //r_smallmap_v: 0: top; 1: center; 2: bottom
3749 if (gMapInfo
.Width
= sWidth
) then
3753 else if (gMapInfo
.Width
< sWidth
) then
3755 case r_smallmap_h
of
3756 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3757 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3758 else sX
:= 0; // left
3762 if (gMapInfo
.Height
= sHeight
) then
3766 else if (gMapInfo
.Height
< sHeight
) then
3768 case r_smallmap_v
of
3769 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3770 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3771 else sY
:= 0; // top
3777 p
.viewPortW
:= sWidth
;
3778 p
.viewPortH
:= sHeight
;
3780 {$IFDEF ENABLE_HOLMES}
3781 if (p
= gPlayer1
) then
3783 g_Holmes_plrViewPos(sX
, sY
);
3784 g_Holmes_plrViewSize(sWidth
, sHeight
);
3788 renderMapInternal(-c
, -d
, true);
3790 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3791 case gPlayerIndicator
of
3793 p
.DrawIndicator(_RGB(255, 255, 255));
3796 for i
:= 0 to High(gPlayers
) do
3797 if gPlayers
[i
] <> nil then
3798 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3799 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3800 if gPlayerIndicatorStyle
= 1 then
3801 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3802 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3806 for a := 0 to High(gCollideMap) do
3807 for b := 0 to High(gCollideMap[a]) do
3810 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3812 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3816 1: e_DrawPoint(1, b, a, 200, 200, 200);
3817 2: e_DrawPoint(1, b, a, 64, 64, 255);
3818 3: e_DrawPoint(1, b, a, 255, 0, 255);
3828 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3829 if g_Debug_Player
then
3830 g_Player_DrawDebug(p
);
3834 procedure drawProfilers ();
3839 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3840 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3841 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3844 procedure g_Game_Draw();
3851 plView1
, plView2
: TPlayer
;
3854 if gExit
= EXIT_QUIT
then Exit
;
3856 Time
:= sys_GetTicks() {div 1000};
3857 FPSCounter
:= FPSCounter
+1;
3858 if Time
- FPSTime
>= 1000 then
3865 e_SetRendertarget(True);
3866 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3868 if gGameOn
or (gState
= STATE_FOLD
) then
3870 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3872 gSpectMode
:= SPECT_NONE
;
3873 if not gRevertPlayers
then
3875 plView1
:= gPlayer1
;
3876 plView2
:= gPlayer2
;
3880 plView1
:= gPlayer2
;
3881 plView2
:= gPlayer1
;
3885 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3887 gSpectMode
:= SPECT_NONE
;
3888 if gPlayer2
= nil then
3891 plView1
:= gPlayer2
;
3900 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3901 gSpectMode
:= SPECT_STATS
;
3903 if gSpectMode
= SPECT_PLAYERS
then
3904 if gPlayers
<> nil then
3906 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3907 if plView1
= nil then
3909 gSpectPID1
:= GetActivePlayerID_Next();
3910 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3912 if gSpectViewTwo
then
3914 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3915 if plView2
= nil then
3917 gSpectPID2
:= GetActivePlayerID_Next();
3918 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3923 if gSpectMode
= SPECT_MAPVIEW
then
3925 // Ðåæèì ïðîñìîòðà êàðòû
3927 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3928 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3929 gHearPoint1
.Active
:= True;
3930 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3931 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3932 gHearPoint2
.Active
:= False;
3936 Split
:= (plView1
<> nil) and (plView2
<> nil);
3938 // Òî÷êè ñëóõà èãðîêîâ
3939 if plView1
<> nil then
3941 gHearPoint1
.Active
:= True;
3942 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3943 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3945 gHearPoint1
.Active
:= False;
3946 if plView2
<> nil then
3948 gHearPoint2
.Active
:= True;
3949 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3950 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3952 gHearPoint2
.Active
:= False;
3954 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3955 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3958 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3959 if gScreenHeight
mod 2 = 0 then
3960 Dec(gPlayerScreenSize
.Y
);
3963 gPlayerScreenSize
.Y
:= gScreenHeight
;
3966 if gScreenHeight
mod 2 = 0 then
3967 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3969 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3971 DrawPlayer(plView1
);
3972 gPlayer1ScreenCoord
.X
:= sX
;
3973 gPlayer1ScreenCoord
.Y
:= sY
;
3977 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3979 DrawPlayer(plView2
);
3980 gPlayer2ScreenCoord
.X
:= sX
;
3981 gPlayer2ScreenCoord
.Y
:= sY
;
3984 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3987 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3990 {$IFDEF ENABLE_HOLMES}
3992 if (g_holmes_enabled
) then g_Holmes_Draw();
3995 if MessageText
<> '' then
3999 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
4001 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4002 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4004 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4005 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4008 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4011 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4013 // Draw spectator GUI
4016 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4019 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4023 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4025 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4026 if gSpectMode
= SPECT_STATS
then
4028 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4029 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4031 if gSpectMode
= SPECT_MAPVIEW
then
4033 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4034 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4035 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4036 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4037 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4039 if gSpectMode
= SPECT_PLAYERS
then
4041 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4042 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4043 if gSpectViewTwo
then
4045 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4046 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4047 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4048 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4052 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4053 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4059 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4061 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4062 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4064 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4065 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4066 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4071 if (gState
= STATE_MENU
) then
4073 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4074 // F3 at menu will show game loading dialog
4075 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4076 if (g_ActiveWindow
<> nil) then
4078 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4079 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4083 // F3 at titlepic will show game loading dialog
4084 if e_KeyPressed(IK_F3
) then
4086 g_Menu_Show_LoadMenu(true);
4087 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4092 if gState
= STATE_FOLD
then
4094 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4097 if gState
= STATE_INTERCUSTOM
then
4099 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4101 back
:= 'TEXTURE_endpic';
4102 if not g_Texture_Get(back
, ID
) then
4103 back
:= _lc
[I_TEXTURE_ENDPIC
];
4108 DrawMenuBackground(back
);
4112 if g_ActiveWindow
<> nil then
4114 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4115 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4119 if gState
= STATE_INTERSINGLE
then
4121 if EndingGameCounter
> 0 then
4123 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4129 DrawMenuBackground(back
);
4133 if g_ActiveWindow
<> nil then
4135 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4136 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4141 if gState
= STATE_ENDPIC
then
4144 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4145 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4147 if g_ActiveWindow
<> nil then
4149 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4150 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4154 if gState
= STATE_SLIST
then
4156 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4158 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4159 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4161 DrawMenuBackground('MENU_BACKGROUND');
4162 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4163 g_Serverlist_Draw(slCurrent
, slTable
);
4167 if g_ActiveWindow
<> nil then
4171 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4172 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4174 g_ActiveWindow
.Draw();
4181 if g_debug_Sounds
and gGameOn
then
4183 for w
:= 0 to High(e_SoundsArray
) do
4184 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4185 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4190 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4191 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4194 if gGameOn
and gShowTime
then
4195 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4197 if gGameOn
then drawProfilers();
4199 // TODO: draw this after the FBO and remap mouse click coordinates
4201 {$IFDEF ENABLE_HOLMES}
4205 // blit framebuffer to screen
4207 e_SetRendertarget(False);
4208 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4209 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4211 // draw the overlay stuff on top of it
4216 procedure g_Game_Quit();
4218 g_Game_StopAllSounds(True);
4221 g_PlayerModel_FreeData();
4222 g_Texture_DeleteAll();
4223 g_Frames_DeleteAll();
4225 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4228 if NetInitDone
then g_Net_Free
;
4230 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4231 if gMapToDelete
<> '' then
4232 g_Game_DeleteTestMap();
4238 procedure g_FatalError(Text: String);
4240 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4241 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4243 gExit
:= EXIT_SIMPLE
;
4244 if gGameOn
then EndGame
;
4247 procedure g_SimpleError(Text: String);
4249 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4250 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4253 procedure g_Game_SetupScreenSize();
4255 RES_FACTOR
= 4.0 / 3.0;
4261 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4262 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4263 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4264 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4266 gPlayerScreenSize
.Y
:= gScreenHeight
;
4268 // Ðàçìåð çàäíåãî ïëàíà:
4269 if BackID
<> DWORD(-1) then
4272 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4273 (gScreenHeight
*s
> gMapInfo
.Height
) then
4275 gBackSize
.X
:= gScreenWidth
;
4276 gBackSize
.Y
:= gScreenHeight
;
4280 e_GetTextureSize(BackID
, @bw
, @bh
);
4281 rf
:= Single(bw
) / Single(bh
);
4282 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4283 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4284 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4285 if (s
< 1.0) then s
:= 1.0;
4286 gBackSize
.X
:= Round(bw
*s
);
4287 gBackSize
.Y
:= Round(bh
*s
);
4292 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4294 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4297 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4299 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4300 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4303 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4306 if gPlayer1
= nil then
4308 if g_Game_IsClient
then
4310 if NetPlrUID1
> -1 then
4311 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4315 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4316 Team
:= gPlayer1Settings
.Team
;
4318 // Ñîçäàíèå ïåðâîãî èãðîêà:
4319 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4320 gPlayer1Settings
.Color
,
4322 if gPlayer1
= nil then
4323 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4326 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4327 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4328 if g_Game_IsServer
and g_Game_IsNet
then
4329 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4330 gPlayer1
.Respawn(False, True);
4331 g_Net_Slist_ServerPlayerComes();
4336 if gPlayer2
= nil then
4338 if g_Game_IsClient
then
4340 if NetPlrUID2
> -1 then
4341 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4345 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4346 Team
:= gPlayer2Settings
.Team
;
4348 // Ñîçäàíèå âòîðîãî èãðîêà:
4349 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4350 gPlayer2Settings
.Color
,
4352 if gPlayer2
= nil then
4353 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4356 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4357 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4358 if g_Game_IsServer
and g_Game_IsNet
then
4359 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4360 gPlayer2
.Respawn(False, True);
4361 g_Net_Slist_ServerPlayerComes();
4368 procedure g_Game_RemovePlayer();
4372 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4373 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4378 if g_Game_IsServer
then
4381 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4382 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4383 g_Player_Remove(Pl
.UID
);
4384 g_Net_Slist_ServerPlayerLeaves();
4388 gSpectLatchPID2
:= Pl
.UID
;
4396 if g_Game_IsServer
then
4399 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4400 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4401 g_Player_Remove(Pl
.UID
);
4402 g_Net_Slist_ServerPlayerLeaves();
4405 gSpectLatchPID1
:= Pl
.UID
;
4407 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4411 g_Net_Slist_ServerPlayerLeaves();
4414 procedure g_Game_Spectate();
4416 g_Game_RemovePlayer();
4417 if gPlayer1
<> nil then
4418 g_Game_RemovePlayer();
4421 procedure g_Game_SpectateCenterView();
4423 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4424 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4427 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4434 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4436 g_Game_ClearLoading();
4439 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4442 gGameSettings
.GameType
:= GT_SINGLE
;
4443 gGameSettings
.MaxLives
:= 0;
4444 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4445 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4446 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4447 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4448 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4449 gSwitchGameMode
:= GM_SINGLE
;
4451 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4452 gLMSRespawnTime
:= 0;
4453 gSpectLatchPID1
:= 0;
4454 gSpectLatchPID2
:= 0;
4456 g_Game_ExecuteEvent('ongamestart');
4458 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4459 g_Game_SetupScreenSize();
4461 // Ñîçäàíèå ïåðâîãî èãðîêà:
4462 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4463 gPlayer1Settings
.Color
,
4464 gPlayer1Settings
.Team
, False));
4465 if gPlayer1
= nil then
4467 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4471 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4474 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4477 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4478 gPlayer2Settings
.Color
,
4479 gPlayer2Settings
.Team
, False));
4480 if gPlayer2
= nil then
4482 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4486 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4490 // Çàãðóçêà è çàïóñê êàðòû:
4491 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4493 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4494 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4498 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4502 for i
:= nPl
+1 to nPlayers
do
4503 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4506 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4507 TimeLimit
, GoalLimit
: Word;
4509 Options
: LongWord; nPlayers
: Byte);
4515 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4517 g_Game_ClearLoading();
4520 gGameSettings
.GameType
:= GT_CUSTOM
;
4521 gGameSettings
.GameMode
:= GameMode
;
4522 gSwitchGameMode
:= GameMode
;
4523 gGameSettings
.TimeLimit
:= TimeLimit
;
4524 gGameSettings
.GoalLimit
:= GoalLimit
;
4525 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4526 gGameSettings
.Options
:= Options
;
4528 gCoopTotalMonstersKilled
:= 0;
4529 gCoopTotalSecretsFound
:= 0;
4530 gCoopTotalMonsters
:= 0;
4531 gCoopTotalSecrets
:= 0;
4535 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4536 gLMSRespawnTime
:= 0;
4537 gSpectLatchPID1
:= 0;
4538 gSpectLatchPID2
:= 0;
4540 g_Game_ExecuteEvent('ongamestart');
4542 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4543 g_Game_SetupScreenSize();
4545 // Ðåæèì íàáëþäàòåëÿ:
4546 if nPlayers
= 0 then
4553 if nPlayers
>= 1 then
4555 // Ñîçäàíèå ïåðâîãî èãðîêà:
4556 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4557 gPlayer1Settings
.Color
,
4558 gPlayer1Settings
.Team
, False));
4559 if gPlayer1
= nil then
4561 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4565 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4569 if nPlayers
>= 2 then
4571 // Ñîçäàíèå âòîðîãî èãðîêà:
4572 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4573 gPlayer2Settings
.Color
,
4574 gPlayer2Settings
.Team
, False));
4575 if gPlayer2
= nil then
4577 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4581 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4585 // Çàãðóçêà è çàïóñê êàðòû:
4586 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4588 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4592 // Íåò òî÷åê ïîÿâëåíèÿ:
4593 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4594 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4595 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4596 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4597 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4599 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4603 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4607 for i
:= nPl
+1 to nPlayers
do
4608 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4611 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4612 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4613 Options
: LongWord; nPlayers
: Byte;
4614 IPAddr
: LongWord; Port
: Word);
4617 g_Net_Slist_ServerClosed();
4619 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4621 g_Game_ClearLoading();
4624 gGameSettings
.GameType
:= GT_SERVER
;
4625 gGameSettings
.GameMode
:= GameMode
;
4626 gSwitchGameMode
:= GameMode
;
4627 gGameSettings
.TimeLimit
:= TimeLimit
;
4628 gGameSettings
.GoalLimit
:= GoalLimit
;
4629 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4630 gGameSettings
.Options
:= Options
;
4632 gCoopTotalMonstersKilled
:= 0;
4633 gCoopTotalSecretsFound
:= 0;
4634 gCoopTotalMonsters
:= 0;
4635 gCoopTotalSecrets
:= 0;
4639 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4640 gLMSRespawnTime
:= 0;
4641 gSpectLatchPID1
:= 0;
4642 gSpectLatchPID2
:= 0;
4644 g_Game_ExecuteEvent('ongamestart');
4646 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4647 g_Game_SetupScreenSize();
4649 // Ðåæèì íàáëþäàòåëÿ:
4650 if nPlayers
= 0 then
4656 if nPlayers
>= 1 then
4658 // Ñîçäàíèå ïåðâîãî èãðîêà:
4659 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4660 gPlayer1Settings
.Color
,
4661 gPlayer1Settings
.Team
, False));
4662 if gPlayer1
= nil then
4664 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4668 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4671 if nPlayers
>= 2 then
4673 // Ñîçäàíèå âòîðîãî èãðîêà:
4674 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4675 gPlayer2Settings
.Color
,
4676 gPlayer2Settings
.Team
, False));
4677 if gPlayer2
= nil then
4679 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4683 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4686 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4687 if NetForwardPorts
then
4688 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4691 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4693 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4697 g_Net_Slist_Set(NetMasterList
);
4699 g_Net_Slist_ServerStarted();
4701 // Çàãðóçêà è çàïóñê êàðòû:
4702 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4704 g_Net_Slist_ServerClosed();
4705 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4709 // Íåò òî÷åê ïîÿâëåíèÿ:
4710 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4711 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4712 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4713 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4714 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4716 g_Net_Slist_ServerClosed();
4717 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4721 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4724 g_Net_Slist_ServerMapStarted();
4725 NetState
:= NET_STATE_GAME
;
4728 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4743 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4744 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4746 g_Game_ClearLoading();
4749 gGameSettings
.GameType
:= GT_CLIENT
;
4751 gCoopTotalMonstersKilled
:= 0;
4752 gCoopTotalSecretsFound
:= 0;
4753 gCoopTotalMonsters
:= 0;
4754 gCoopTotalSecrets
:= 0;
4758 g_Game_ExecuteEvent('ongamestart');
4760 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4761 g_Game_SetupScreenSize();
4763 NetState
:= NET_STATE_AUTH
;
4765 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4767 // create (or update) map/resource databases
4768 g_Res_CreateDatabases(true);
4770 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4771 gLMSRespawnTime
:= 0;
4772 gSpectLatchPID1
:= 0;
4773 gSpectLatchPID2
:= 0;
4776 if not g_Net_Connect(Addr
, Port
) then
4778 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4779 NetState
:= NET_STATE_NONE
;
4783 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4785 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4790 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4791 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4792 // thank you, enet. let's ignore failures altogether then.
4793 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4795 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4797 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4799 // ignore all download packets, they're processed by separate code
4800 enet_packet_destroy(NetEvent
.packet
);
4803 Ptr
:= NetEvent
.packet
^.data
;
4804 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4806 enet_packet_destroy(NetEvent
.packet
);
4810 InMsg
.ReadLongWord(); // skip size
4811 MID
:= InMsg
.ReadByte();
4813 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4815 NetMyID
:= InMsg
.ReadByte();
4816 NetPlrUID1
:= InMsg
.ReadWord();
4818 WadName
:= InMsg
.ReadString();
4819 Map
:= InMsg
.ReadString();
4821 gWADHash
:= InMsg
.ReadMD5();
4823 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4824 gSwitchGameMode
:= gGameSettings
.GameMode
;
4825 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4826 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4827 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4828 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4829 T
:= InMsg
.ReadLongWord();
4831 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4832 //if newResPath = '' then
4834 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4835 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4836 if newResPath
= '' then
4838 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4839 enet_packet_destroy(NetEvent
.packet
);
4840 NetState
:= NET_STATE_NONE
;
4843 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4845 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4848 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4849 gPlayer1Settings
.Color
,
4850 gPlayer1Settings
.Team
, False));
4852 if gPlayer1
= nil then
4854 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4856 enet_packet_destroy(NetEvent
.packet
);
4857 NetState
:= NET_STATE_NONE
;
4861 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4862 gPlayer1
.UID
:= NetPlrUID1
;
4863 gPlayer1
.Reset(True);
4865 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4867 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4869 enet_packet_destroy(NetEvent
.packet
);
4870 NetState
:= NET_STATE_NONE
;
4878 enet_packet_destroy(NetEvent
.packet
);
4882 enet_packet_destroy(NetEvent
.packet
);
4886 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4889 if (NetEvent
.data
<= NET_DISC_MAX
) then
4890 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4891 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4898 ProcessLoading(true);
4900 if g_Net_UserRequestExit() then
4909 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4910 NetState
:= NET_STATE_NONE
;
4915 NetState
:= NET_STATE_GAME
;
4916 MC_SEND_FullStateRequest
;
4917 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4921 lastAsMegaWad
: Boolean = false;
4923 procedure g_Game_ChangeMap(const MapPath
: String);
4927 g_Game_ClearLoading();
4929 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4930 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4931 if gExitByTrigger
then
4934 gExitByTrigger
:= False;
4936 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4937 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4940 procedure g_Game_Restart();
4944 if g_Game_IsClient
then
4946 map
:= g_ExtractFileName(gMapInfo
.Map
);
4947 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4951 g_Game_ClearLoading();
4952 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4955 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4957 NewWAD
, ResName
: String;
4961 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4962 g_Player_RemoveAllCorpses();
4964 if (not g_Game_IsClient
) and
4965 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4966 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4968 if gSwitchGameMode
= GM_CTF
then
4969 gGameSettings
.MaxLives
:= 0;
4970 gGameSettings
.GameMode
:= gSwitchGameMode
;
4973 gSwitchGameMode
:= gGameSettings
.GameMode
;
4975 g_Player_ResetTeams();
4977 lastAsMegaWad
:= asMegawad
;
4978 if isWadPath(Map
) then
4980 NewWAD
:= g_ExtractWadName(Map
);
4981 ResName
:= g_ExtractFileName(Map
);
4982 if g_Game_IsServer
then
4984 nws
:= findDiskWad(NewWAD
);
4985 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4988 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4989 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4993 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4994 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4996 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4997 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4999 if (length(nws
) = 0) then
5001 ResName
:= ''; // failed
5006 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5007 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5008 g_Game_LoadWAD(NewWAD
);
5013 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5014 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5019 NewWAD
:= gGameSettings
.WAD
;
5025 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5027 if (ResName
<> '') and (NewWAD
<> '') then
5029 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5030 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5034 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5036 gState
:= STATE_NONE
;
5037 g_ActiveWindow
:= nil;
5043 if gGameSettings
.GameMode
= GM_CTF
then
5045 g_Map_ResetFlag(FLAG_RED
);
5046 g_Map_ResetFlag(FLAG_BLUE
);
5047 // CTF, à ôëàãîâ íåò:
5048 if not g_Map_HaveFlagPoints() then
5049 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5054 gState
:= STATE_MENU
;
5059 gPauseMain
:= false;
5060 gPauseHolmes
:= false;
5061 NetTimeToUpdate
:= 1;
5062 NetTimeToReliable
:= 0;
5063 NetTimeToMaster
:= NetMasterRate
;
5064 gSpectLatchPID1
:= 0;
5065 gSpectLatchPID2
:= 0;
5066 gMissionFailed
:= False;
5069 gCoopMonstersKilled
:= 0;
5070 gCoopSecretsFound
:= 0;
5072 gVoteInProgress
:= False;
5073 gVotePassed
:= False;
5079 if not gGameOn
then Exit
;
5081 g_Game_SpectateCenterView();
5083 if g_Game_IsServer
then
5085 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5087 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5088 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5089 gLMSSoftSpawn
:= True;
5090 if g_Game_IsNet
then
5091 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5095 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5096 gLMSRespawnTime
:= 0;
5100 if NetMode
= NET_SERVER
then
5102 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5105 g_Net_Slist_ServerMapStarted();
5107 if NetClients
<> nil then
5108 for I
:= 0 to High(NetClients
) do
5109 if NetClients
[I
].Used
then
5111 NetClients
[I
].Voted
:= False;
5112 if NetClients
[I
].RequestedFullUpdate
then
5114 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5115 NetClients
[I
].RequestedFullUpdate
:= False;
5119 g_Net_UnbanNonPermHosts();
5124 gCoopTotalMonstersKilled
:= 0;
5125 gCoopTotalSecretsFound
:= 0;
5126 gCoopTotalMonsters
:= 0;
5127 gCoopTotalSecrets
:= 0;
5131 g_Game_ExecuteEvent('onmapstart');
5134 procedure SetFirstLevel
;
5138 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5139 if MapList
= nil then
5142 SortSArray(MapList
);
5143 gNextMap
:= MapList
[Low(MapList
)];
5148 procedure g_Game_ExitLevel(const Map
: AnsiString);
5152 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5153 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5154 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5155 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5157 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5158 if gGameSettings
.GameType
= GT_SINGLE
then
5159 gExit
:= EXIT_ENDLEVELSINGLE
5160 else // Âûøëè â âûõîä â Ñâîåé èãðå
5162 gExit
:= EXIT_ENDLEVELCUSTOM
;
5163 if gGameSettings
.GameMode
= GM_COOP
then
5164 g_Player_RememberAll
;
5166 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5169 if gGameSettings
.GameMode
= GM_COOP
then
5172 gStatsPressed
:= True;
5173 gNextMap
:= 'MAP01';
5175 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5178 if g_Game_IsNet
then
5180 MH_SEND_GameStats();
5181 MH_SEND_CoopStats();
5187 procedure g_Game_RestartLevel();
5191 if gGameSettings
.GameMode
= GM_SINGLE
then
5196 gExit
:= EXIT_ENDLEVELCUSTOM
;
5197 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5201 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5203 gWAD
{, xwad}: String;
5206 if not g_Game_IsClient
then Exit
;
5207 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5209 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5214 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5218 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5221 g_Game_LoadWAD(NewWAD
);
5225 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5226 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5229 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5230 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5234 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5238 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5239 g_Game_LoadWAD(NewWAD);
5243 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5245 i
, n
, nb
, nr
: Integer;
5247 if not g_Game_IsServer
then Exit
;
5248 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5249 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5250 gLMSRespawnTime
:= 0;
5253 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5255 gMissionFailed
:= True;
5256 g_Game_RestartLevel
;
5260 n
:= 0; nb
:= 0; nr
:= 0;
5261 for i
:= Low(gPlayers
) to High(gPlayers
) do
5262 if (gPlayers
[i
] <> nil) and
5263 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5264 (gPlayers
[i
] is TBot
)) then
5267 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5268 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5271 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5273 // wait a second until the fuckers finally decide to join
5274 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5275 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5276 gLMSSoftSpawn
:= NoMapRestart
;
5277 if g_Game_IsNet
then
5278 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5282 g_Player_RemoveAllCorpses
;
5283 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5284 if g_Game_IsNet
then
5285 MH_SEND_GameEvent(NET_EV_LMS_START
);
5287 for i
:= Low(gPlayers
) to High(gPlayers
) do
5289 if gPlayers
[i
] = nil then continue
;
5290 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5291 // don't touch normal spectators
5292 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5294 gPlayers
[i
].FNoRespawn
:= True;
5295 gPlayers
[i
].Lives
:= 0;
5296 if g_Game_IsNet
then
5297 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5300 gPlayers
[i
].FNoRespawn
:= False;
5301 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5302 gPlayers
[i
].Respawn(False, True);
5303 if gGameSettings
.GameMode
= GM_COOP
then
5305 gPlayers
[i
].Frags
:= 0;
5306 gPlayers
[i
].RecallState
;
5308 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5309 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5310 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5311 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5314 g_Items_RestartRound();
5316 gLMSSoftSpawn
:= False;
5319 function g_Game_GetFirstMap(WAD
: String): String;
5323 MapList
:= g_Map_GetMapsList(WAD
);
5324 if MapList
= nil then
5327 SortSArray(MapList
);
5328 Result
:= MapList
[Low(MapList
)];
5330 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5336 function g_Game_GetNextMap(): String;
5343 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5344 if MapList
= nil then
5347 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5349 SortSArray(MapList
);
5351 for I
:= Low(MapList
) to High(MapList
) do
5352 if Map
= MapList
[I
] then
5358 if MapIndex
<> -255 then
5360 if MapIndex
= High(MapList
) then
5361 Result
:= MapList
[Low(MapList
)]
5363 Result
:= MapList
[MapIndex
+ 1];
5365 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5371 procedure g_Game_NextLevel();
5373 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5374 gExit
:= EXIT_ENDLEVELCUSTOM
5377 gExit
:= EXIT_ENDLEVELSINGLE
;
5381 if gNextMap
<> '' then Exit
;
5382 gNextMap
:= g_Game_GetNextMap();
5385 function g_Game_IsTestMap(): Boolean;
5387 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5390 procedure g_Game_DeleteTestMap();
5393 //MapName: AnsiString;
5401 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5402 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5403 if (a
= 0) then exit
;
5405 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5406 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5407 Delete(gMapToDelete
, 1, a
+5);
5408 gMapToDelete
:= UpperCase(gMapToDelete
);
5410 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5413 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5414 if MapName <> TEST_MAP_NAME then
5417 if not gTempDelete then
5419 time := g_GetFileTime(WadName);
5420 WAD := TWADFile.Create();
5423 if not WAD.ReadFile(WadName) then
5424 begin // Íåò òàêîãî WAD-ôàéëà
5429 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5431 MapList := WAD.GetResourcesList('');
5433 if MapList <> nil then
5434 for a := 0 to High(MapList) do
5435 if MapList[a] = MapName then
5437 // Óäàëÿåì è ñîõðàíÿåì:
5438 WAD.RemoveResource('', MapName);
5439 WAD.SaveTo(WadName);
5444 g_SetFileTime(WadName, time);
5447 if gTempDelete
then DeleteFile(WadName
);
5450 procedure GameCVars(P
: SSArray
);
5453 stat
: TPlayerStatArray
;
5456 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5460 if Length(P
) > 1 then
5465 gsGameFlags
:= gsGameFlags
or Flag
5467 gsGameFlags
:= gsGameFlags
and (not Flag
);
5469 if g_Game_IsServer
then
5472 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5474 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5475 if g_Game_IsNet
then MH_SEND_GameSettings
;
5479 if LongBool(gsGameFlags
and Flag
) then
5480 g_Console_Add(_lc
[OnMsg
])
5482 g_Console_Add(_lc
[OffMsg
]);
5484 if OnMapChange
and g_Game_IsServer
then
5485 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5490 cmd
:= LowerCase(P
[0]);
5492 if cmd
= 'g_gamemode' then
5494 if (Length(P
) > 1) then
5496 a
:= g_Game_TextToMode(P
[1]);
5497 if a
= GM_SINGLE
then a
:= GM_COOP
;
5498 gsGameMode
:= g_Game_ModeToText(a
);
5499 if g_Game_IsServer
then
5501 gSwitchGameMode
:= a
;
5502 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5503 (gState
= STATE_INTERSINGLE
) then
5504 gSwitchGameMode
:= GM_SINGLE
;
5506 gGameSettings
.GameMode
:= gSwitchGameMode
;
5510 if gSwitchGameMode
= gGameSettings
.GameMode
then
5511 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5512 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5514 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5515 [g_Game_ModeToText(gGameSettings
.GameMode
),
5516 g_Game_ModeToText(gSwitchGameMode
)]));
5518 else if cmd
= 'g_friendlyfire' then
5520 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5522 else if cmd
= 'g_friendly_absorb_damage' then
5524 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5526 else if cmd
= 'g_friendly_hit_trace' then
5528 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5530 else if cmd
= 'g_friendly_hit_projectile' then
5532 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5534 else if cmd
= 'g_weaponstay' then
5536 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5538 else if cmd
= 'g_allow_exit' then
5540 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5542 else if cmd
= 'g_allow_monsters' then
5544 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5546 else if cmd
= 'g_allow_dropflag' then
5548 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5550 else if cmd
= 'g_throw_flag' then
5552 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5554 else if cmd
= 'g_bot_vsplayers' then
5556 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5558 else if cmd
= 'g_bot_vsmonsters' then
5560 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5562 else if cmd
= 'g_dm_keys' then
5564 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5566 else if cmd
= 'g_gameflags' then
5568 if Length(P
) > 1 then
5570 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5571 if g_Game_IsServer
then
5573 gGameSettings
.Options
:= gsGameFlags
;
5574 if g_Game_IsNet
then MH_SEND_GameSettings
;
5578 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5580 else if cmd
= 'g_warmup_time' then
5582 if Length(P
) > 1 then
5584 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5585 if g_Game_IsServer
then
5587 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5588 // extend warmup if it's already going
5589 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5591 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5592 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5594 if g_Game_IsNet
then MH_SEND_GameSettings
;
5598 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5599 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5601 else if cmd
= 'g_spawn_invul' then
5603 if Length(P
) > 1 then
5605 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5606 if g_Game_IsServer
then
5608 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5609 if g_Game_IsNet
then MH_SEND_GameSettings
;
5613 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5615 else if cmd
= 'g_item_respawn_time' then
5617 if Length(P
) > 1 then
5619 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5620 if g_Game_IsServer
then
5622 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5623 if g_Game_IsNet
then MH_SEND_GameSettings
;
5627 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5628 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5630 else if cmd
= 'sv_intertime' then
5632 if (Length(P
) > 1) then
5633 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5635 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5637 else if cmd
= 'g_max_particles' then
5639 if Length(p
) = 2 then
5641 a
:= Max(0, StrToInt(p
[1]));
5644 else if Length(p
) = 1 then
5646 e_LogWritefln('%s', [g_GFX_GetMax()])
5650 e_LogWritefln('usage: %s <n>', [cmd
])
5653 else if cmd
= 'g_max_shells' then
5655 if Length(p
) = 2 then
5657 a
:= Max(0, StrToInt(p
[1]));
5660 else if Length(p
) = 1 then
5662 e_LogWritefln('%s', [g_Shells_GetMax()])
5666 e_LogWritefln('usage: %s <n>', [cmd
])
5669 else if cmd
= 'g_max_gibs' then
5671 if Length(p
) = 2 then
5673 a
:= Max(0, StrToInt(p
[1]));
5676 else if Length(p
) = 1 then
5678 e_LogWritefln('%s', [g_Gibs_GetMax()])
5682 e_LogWritefln('usage: %s <n>', [cmd
])
5685 else if cmd
= 'g_max_corpses' then
5687 if Length(p
) = 2 then
5689 a
:= Max(0, StrToInt(p
[1]));
5692 else if Length(p
) = 1 then
5694 e_LogWritefln('%s', [g_Corpses_GetMax()])
5698 e_LogWritefln('usage: %s <n>', [cmd
])
5701 else if cmd
= 'g_scorelimit' then
5703 if Length(P
) > 1 then
5705 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5707 if g_Game_IsServer
then
5710 if gGameSettings
.GameMode
= GM_DM
then
5712 stat
:= g_Player_GetStats();
5714 for a
:= 0 to High(stat
) do
5715 if stat
[a
].Frags
> b
then
5719 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5721 // if someone has a higher score, set it to that instead
5722 gsGoalLimit
:= max(gsGoalLimit
, b
);
5723 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5725 if g_Game_IsNet
then MH_SEND_GameSettings
;
5729 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5731 else if cmd
= 'g_timelimit' then
5733 if Length(P
) > 1 then
5735 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5736 if g_Game_IsServer
then
5738 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5739 if g_Game_IsNet
then MH_SEND_GameSettings
;
5742 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5743 [gsTimeLimit
div 3600,
5744 (gsTimeLimit
div 60) mod 60,
5745 gsTimeLimit
mod 60]));
5747 else if cmd
= 'g_maxlives' then
5749 if Length(P
) > 1 then
5751 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5752 if g_Game_IsServer
then
5754 gGameSettings
.MaxLives
:= gsMaxLives
;
5755 if g_Game_IsNet
then MH_SEND_GameSettings
;
5759 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5763 procedure PlayerSettingsCVars(P
: SSArray
);
5768 function ParseTeam(s
: string): Byte;
5772 'red', '1': result
:= TEAM_RED
;
5773 'blue', '2': result
:= TEAM_BLUE
;
5774 else result
:= TEAM_NONE
;
5778 cmd
:= LowerCase(P
[0]);
5782 if (Length(P
) > 1) then
5784 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5785 if g_Game_IsClient
then
5786 MC_SEND_PlayerSettings
5787 else if gGameOn
and (gPlayer1
<> nil) then
5789 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5790 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5796 if (Length(P
) > 1) then
5798 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5799 if g_Game_IsClient
then
5800 MC_SEND_PlayerSettings
5801 else if gGameOn
and (gPlayer2
<> nil) then
5803 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5804 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5810 if Length(P
) > 3 then
5812 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5813 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5814 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5815 if g_Game_IsClient
then
5816 MC_SEND_PlayerSettings
5817 else if gGameOn
and (gPlayer1
<> nil) then
5819 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5820 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5826 if Length(P
) > 3 then
5828 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5829 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5830 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5831 if g_Game_IsClient
then
5832 MC_SEND_PlayerSettings
5833 else if gGameOn
and (gPlayer2
<> nil) then
5835 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5836 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5842 if (Length(P
) > 1) then
5844 gPlayer1Settings
.Model
:= P
[1];
5845 if g_Game_IsClient
then
5846 MC_SEND_PlayerSettings
5847 else if gGameOn
and (gPlayer1
<> nil) then
5849 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5850 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5851 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5857 if (Length(P
) > 1) then
5859 gPlayer2Settings
.Model
:= P
[1];
5860 if g_Game_IsClient
then
5861 MC_SEND_PlayerSettings
5862 else if gGameOn
and (gPlayer2
<> nil) then
5864 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5865 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5866 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5872 // TODO: switch teams if in game or store this separately
5873 if (Length(P
) > 1) then
5875 team
:= ParseTeam(P
[1]);
5876 if team
= TEAM_NONE
then
5877 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5878 else if not gGameOn
and not g_Game_IsNet
then
5879 gPlayer1Settings
.Team
:= team
5881 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5886 // TODO: switch teams if in game or store this separately
5887 if (Length(P
) > 1) then
5889 team
:= ParseTeam(P
[1]);
5890 if team
= TEAM_NONE
then
5891 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5892 else if not gGameOn
and not g_Game_IsNet
then
5893 gPlayer2Settings
.Team
:= team
5895 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5901 procedure PrintHeapStats();
5905 hs
:= GetFPCHeapStatus();
5906 e_LogWriteLn ('v===== heap status =====v');
5907 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5908 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5909 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5910 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5911 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5912 e_LogWriteLn ('^=======================^');
5915 procedure DebugCommands(P
: SSArray
);
5922 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5923 if {gDebugMode}conIsCheatsEnabled
then
5925 cmd
:= LowerCase(P
[0]);
5926 if cmd
= 'd_window' then
5928 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5929 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5931 else if cmd
= 'd_sounds' then
5933 if (Length(P
) > 1) and
5934 ((P
[1] = '1') or (P
[1] = '0')) then
5935 g_Debug_Sounds
:= (P
[1][1] = '1');
5937 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5939 else if cmd
= 'd_frames' then
5941 if (Length(P
) > 1) and
5942 ((P
[1] = '1') or (P
[1] = '0')) then
5943 g_Debug_Frames
:= (P
[1][1] = '1');
5945 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5947 else if cmd
= 'd_winmsg' then
5949 if (Length(P
) > 1) and
5950 ((P
[1] = '1') or (P
[1] = '0')) then
5951 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5953 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5955 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5957 if (Length(P
) > 1) and
5958 ((P
[1] = '1') or (P
[1] = '0')) then
5959 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5961 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5963 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5965 if Length(P
) > 1 then
5967 '0': g_debug_BotAIOff
:= 0;
5968 '1': g_debug_BotAIOff
:= 1;
5969 '2': g_debug_BotAIOff
:= 2;
5970 '3': g_debug_BotAIOff
:= 3;
5973 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5975 else if cmd
= 'd_monster' then
5977 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5978 if Length(P
) < 2 then
5980 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5981 g_Console_Add('ID | Name');
5982 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5983 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5984 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5987 a
:= StrToIntDef(P
[1], 0);
5988 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5989 a
:= g_Mons_TypeIdByName(P
[1]);
5991 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5992 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5995 with gPlayer1
.Obj
do
5997 mon
:= g_Monsters_Create(a
,
5998 X
+ Rect
.X
+ (Rect
.Width
div 2),
5999 Y
+ Rect
.Y
+ Rect
.Height
,
6000 gPlayer1
.Direction
, True);
6002 if (Length(P
) > 2) and (mon
<> nil) then
6004 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6005 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6006 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6007 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6008 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6009 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6010 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6011 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6012 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6017 else if (cmd
= 'd_health') then
6019 if (Length(P
) > 1) and
6020 ((P
[1] = '1') or (P
[1] = '0')) then
6021 g_debug_HealthBar
:= (P
[1][1] = '1');
6023 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6025 else if (cmd
= 'd_player') then
6027 if (Length(P
) > 1) and
6028 ((P
[1] = '1') or (P
[1] = '0')) then
6029 g_debug_Player
:= (P
[1][1] = '1');
6031 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6033 else if (cmd
= 'd_mem') then
6039 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6043 procedure GameCheats(P
: SSArray
);
6049 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6051 g_Console_Add('not available');
6057 g_Console_Add('where is the player?!');
6060 cmd
:= LowerCase(P
[0]);
6064 plr
.GodMode
:= not plr
.GodMode
;
6065 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6068 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6069 if cmd
= 'give' then
6071 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6072 for f
:= 1 to High(P
) do
6074 cmd
:= LowerCase(P
[f
]);
6075 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6076 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6077 if cmd
= 'exit' then
6079 if gTriggers
<> nil then
6081 for a
:= 0 to High(gTriggers
) do
6083 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6085 g_Console_Add('player left the map');
6086 gExitByTrigger
:= True;
6087 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6088 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6096 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6097 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6098 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6099 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6100 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6102 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6103 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6105 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6106 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;
6108 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6109 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6111 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6112 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6114 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6115 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6117 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6118 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6119 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6121 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6122 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6123 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6124 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;
6125 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6126 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6128 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;
6129 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;
6130 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;
6131 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;
6132 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;
6133 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;
6135 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6136 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;
6138 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;
6139 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;
6141 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6143 if cmd
= 'ammo' then
6145 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6146 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6147 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6148 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6149 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6150 g_Console_Add('player got some ammo');
6154 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6155 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6157 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6158 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6160 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6161 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6163 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6164 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6166 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6168 if cmd
= 'weapons' then
6170 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6171 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6172 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6173 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6174 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6175 plr
.GiveItem(ITEM_WEAPON_BFG
);
6176 g_Console_Add('player got weapons');
6180 if cmd
= 'keys' then
6182 plr
.GiveItem(ITEM_KEY_RED
);
6183 plr
.GiveItem(ITEM_KEY_GREEN
);
6184 plr
.GiveItem(ITEM_KEY_BLUE
);
6185 g_Console_Add('player got all keys');
6189 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6194 if cmd
= 'open' then
6196 g_Console_Add('player activated sesame');
6197 g_Triggers_OpenAll();
6204 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6208 if cmd
= 'noclip' then
6211 g_Console_Add('wall hardeness adjusted');
6215 if cmd
= 'notarget' then
6217 plr
.NoTarget
:= not plr
.NoTarget
;
6218 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6222 if cmd
= 'noreload' then
6224 plr
.NoReload
:= not plr
.NoReload
;
6225 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6229 if cmd
= 'speedy' then
6231 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6232 g_Console_Add('speed adjusted');
6236 if cmd
= 'jumpy' then
6238 VEL_JUMP
:= 30-VEL_JUMP
;
6239 g_Console_Add('jump height adjusted');
6243 if cmd
= 'automap' then
6245 gShowMap
:= not gShowMap
;
6246 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6250 if cmd
= 'aimline' then
6252 gAimLine
:= not gAimLine
;
6253 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6258 procedure GameCommands(P
: SSArray
);
6264 pl
: pTNetClient
= nil;
6272 cmd
:= LowerCase(P
[0]);
6274 if cmd
= 'pause' then
6276 if (g_ActiveWindow
= nil) then
6277 g_Game_Pause(not gPauseMain
);
6279 else if cmd
= 'endgame' then
6280 gExit
:= EXIT_SIMPLE
6281 else if cmd
= 'restart' then
6283 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6285 if g_Game_IsClient
then
6287 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6292 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6294 else if cmd
= 'kick' then
6296 if g_Game_IsServer
then
6298 if Length(P
) < 2 then
6300 g_Console_Add('kick <name>');
6305 g_Console_Add('kick <name>');
6309 if g_Game_IsNet
then
6310 pl
:= g_Net_Client_ByName(P
[1]);
6313 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6314 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6315 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6316 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6317 g_Net_Slist_ServerPlayerLeaves();
6318 end else if gPlayers
<> nil then
6319 for a
:= Low(gPlayers
) to High(gPlayers
) do
6320 if gPlayers
[a
] <> nil then
6321 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6323 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6324 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6326 gPlayers
[a
].Lives
:= 0;
6327 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6328 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6329 g_Player_Remove(gPlayers
[a
].UID
);
6330 g_Net_Slist_ServerPlayerLeaves();
6331 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6335 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6337 else if cmd
= 'kick_id' then
6339 if g_Game_IsServer
and g_Game_IsNet
then
6341 if Length(P
) < 2 then
6343 g_Console_Add('kick_id <client ID>');
6348 g_Console_Add('kick_id <client ID>');
6352 a
:= StrToIntDef(P
[1], 0);
6353 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6355 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6357 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6358 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6359 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6360 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6361 g_Net_Slist_ServerPlayerLeaves();
6365 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6367 else if cmd
= 'kick_pid' then
6369 if g_Game_IsServer
and g_Game_IsNet
then
6371 if Length(P
) < 2 then
6373 g_Console_Add('kick_pid <player ID>');
6378 g_Console_Add('kick_pid <player ID>');
6382 a
:= StrToIntDef(P
[1], 0);
6383 pl
:= g_Net_Client_ByPlayer(a
);
6384 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6386 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6387 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6388 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6389 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6390 g_Net_Slist_ServerPlayerLeaves();
6393 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6395 else if cmd
= 'ban' then
6397 if g_Game_IsServer
and g_Game_IsNet
then
6399 if Length(P
) < 2 then
6401 g_Console_Add('ban <name>');
6406 g_Console_Add('ban <name>');
6410 pl
:= g_Net_Client_ByName(P
[1]);
6413 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6414 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6415 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6416 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6417 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6418 g_Net_Slist_ServerPlayerLeaves();
6420 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6422 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6424 else if cmd
= 'ban_id' then
6426 if g_Game_IsServer
and g_Game_IsNet
then
6428 if Length(P
) < 2 then
6430 g_Console_Add('ban_id <client ID>');
6435 g_Console_Add('ban_id <client ID>');
6439 a
:= StrToIntDef(P
[1], 0);
6440 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6441 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6443 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6444 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6445 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6446 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6447 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6448 g_Net_Slist_ServerPlayerLeaves();
6451 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6453 else if cmd
= 'ban_pid' then
6455 if g_Game_IsServer
and g_Game_IsNet
then
6457 if Length(P
) < 2 then
6459 g_Console_Add('ban_pid <player ID>');
6464 g_Console_Add('ban_pid <player ID>');
6468 a
:= StrToIntDef(P
[1], 0);
6469 pl
:= g_Net_Client_ByPlayer(a
);
6470 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6472 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6473 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6474 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6475 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6476 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6477 g_Net_Slist_ServerPlayerLeaves();
6480 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6482 else if cmd
= 'permban' then
6484 if g_Game_IsServer
and g_Game_IsNet
then
6486 if Length(P
) < 2 then
6488 g_Console_Add('permban <name>');
6493 g_Console_Add('permban <name>');
6497 pl
:= g_Net_Client_ByName(P
[1]);
6500 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6501 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6502 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6503 g_Net_SaveBanList();
6504 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6505 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6506 g_Net_Slist_ServerPlayerLeaves();
6508 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6510 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6512 else if cmd
= 'permban_id' then
6514 if g_Game_IsServer
and g_Game_IsNet
then
6516 if Length(P
) < 2 then
6518 g_Console_Add('permban_id <client ID>');
6523 g_Console_Add('permban_id <client ID>');
6527 a
:= StrToIntDef(P
[1], 0);
6528 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6529 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6531 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6532 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6533 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6534 g_Net_SaveBanList();
6535 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6536 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6537 g_Net_Slist_ServerPlayerLeaves();
6540 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6542 else if cmd
= 'permban_pid' then
6544 if g_Game_IsServer
and g_Game_IsNet
then
6546 if Length(P
) < 2 then
6548 g_Console_Add('permban_pid <player ID>');
6553 g_Console_Add('permban_pid <player ID>');
6557 a
:= StrToIntDef(P
[1], 0);
6558 pl
:= g_Net_Client_ByPlayer(a
);
6559 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6561 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6562 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6563 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6564 g_Net_SaveBanList();
6565 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6566 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6567 g_Net_Slist_ServerPlayerLeaves();
6570 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6572 else if cmd
= 'permban_ip' then
6574 if g_Game_IsServer
and g_Game_IsNet
then
6576 if Length(P
) < 2 then
6578 g_Console_Add('permban_ip <IP address>');
6583 g_Console_Add('permban_ip <IP address>');
6587 g_Net_BanHost(P
[1]);
6588 g_Net_SaveBanList();
6589 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6591 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6593 else if cmd
= 'unban' then
6595 if g_Game_IsServer
and g_Game_IsNet
then
6597 if Length(P
) < 2 then
6599 g_Console_Add('unban <IP Address>');
6604 g_Console_Add('unban <IP Address>');
6608 if g_Net_UnbanHost(P
[1]) then
6610 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6611 g_Net_SaveBanList();
6613 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6615 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6617 else if cmd
= 'clientlist' then
6619 if g_Game_IsServer
and g_Game_IsNet
then
6622 if NetClients
<> nil then
6623 for a
:= Low(NetClients
) to High(NetClients
) do
6624 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6626 plr
:= g_Player_Get(NetClients
[a
].Player
);
6627 if plr
= nil then continue
;
6629 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6630 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6633 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6635 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6637 else if cmd
= 'connect' then
6639 if (NetMode
= NET_NONE
) then
6641 if Length(P
) < 2 then
6643 g_Console_Add('connect <IP> [port] [password]');
6648 g_Console_Add('connect <IP> [port] [password]');
6652 if Length(P
) > 2 then
6653 prt
:= StrToIntDef(P
[2], 25666)
6657 if Length(P
) > 3 then
6662 g_Game_StartClient(P
[1], prt
, pw
);
6665 else if cmd
= 'disconnect' then
6667 if (NetMode
= NET_CLIENT
) then
6670 else if cmd
= 'reconnect' then
6672 if (NetMode
= NET_SERVER
) then
6675 if (NetMode
= NET_CLIENT
) then
6678 gExit
:= EXIT_SIMPLE
;
6682 //TODO: Use last successful password to reconnect, instead of ''
6683 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6685 else if (cmd
= 'addbot') or
6686 (cmd
= 'bot_add') then
6688 if Length(P
) > 2 then
6689 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6690 else if Length(P
) > 1 then
6691 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6693 g_Bot_Add(TEAM_NONE
, 2);
6695 else if cmd
= 'bot_addlist' then
6697 if Length(P
) > 1 then
6699 if Length(P
) = 2 then
6700 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6701 else if Length(P
) = 3 then
6702 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6704 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6707 else if cmd
= 'bot_removeall' then
6709 else if cmd
= 'chat' then
6711 if g_Game_IsNet
then
6713 if Length(P
) > 1 then
6715 for a
:= 1 to High(P
) do
6716 chstr
:= chstr
+ P
[a
] + ' ';
6718 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6720 if Length(chstr
) < 1 then
6722 g_Console_Add('chat <text>');
6726 chstr
:= b_Text_Format(chstr
);
6727 if g_Game_IsClient
then
6728 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6730 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6733 g_Console_Add('chat <text>');
6735 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6737 else if cmd
= 'teamchat' then
6739 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6741 if Length(P
) > 1 then
6743 for a
:= 1 to High(P
) do
6744 chstr
:= chstr
+ P
[a
] + ' ';
6746 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6748 if Length(chstr
) < 1 then
6750 g_Console_Add('teamchat <text>');
6754 chstr
:= b_Text_Format(chstr
);
6755 if g_Game_IsClient
then
6756 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6758 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6759 gPlayer1Settings
.Team
);
6762 g_Console_Add('teamchat <text>');
6764 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6766 else if cmd
= 'game' then
6768 if gGameSettings
.GameType
<> GT_NONE
then
6770 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6773 if Length(P
) = 1 then
6775 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6778 // game not started yet, load fist map from some wad
6780 s
:= addWadExtension(P
[1]);
6781 found
:= e_FindResource(AllMapDirs
, s
);
6785 P
[1] := ExpandFileName(P
[1]);
6786 // if map not choosed then set first map
6787 if Length(P
) < 3 then
6790 P
[2] := g_Game_GetFirstMap(P
[1]);
6793 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6795 if g_Map_Exist(s
) then
6799 with gGameSettings
do
6801 Options
:= gsGameFlags
;
6802 GameMode
:= g_Game_TextToMode(gsGameMode
);
6803 if gSwitchGameMode
<> GM_NONE
then
6804 GameMode
:= gSwitchGameMode
;
6805 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6806 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6808 if Length(P
) >= 4 then
6809 b
:= StrToIntDef(P
[3], 1);
6810 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6811 GoalLimit
, MaxLives
, Options
, b
);
6816 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6818 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6820 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6822 else if cmd
= 'host' then
6824 if gGameSettings
.GameType
<> GT_NONE
then
6826 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6829 if Length(P
) < 4 then
6831 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6834 if not StrToIp(P
[1], listen
) then
6836 prt
:= StrToIntDef(P
[2], 25666);
6838 s
:= addWadExtension(P
[3]);
6839 found
:= e_FindResource(AllMapDirs
, s
);
6843 // get first map in wad, if not specified
6844 if Length(P
) < 5 then
6847 P
[4] := g_Game_GetFirstMap(P
[1]);
6849 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6850 if g_Map_Exist(s
) then
6854 with gGameSettings
do
6856 Options
:= gsGameFlags
;
6857 GameMode
:= g_Game_TextToMode(gsGameMode
);
6858 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6859 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6860 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6862 if Length(P
) >= 6 then
6863 b
:= StrToIntDef(P
[5], 0);
6864 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6870 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6872 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6877 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6880 else if cmd
= 'map' then
6882 if Length(P
) = 1 then
6884 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6886 g_Console_Add(cmd
+ ' <MAP>');
6887 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6891 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6896 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6898 if Length(P
) < 3 then
6900 // first param is map or wad
6901 s
:= UpperCase(P
[1]);
6902 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6904 gExitByTrigger
:= False;
6907 // already in game, finish current map
6909 gExit
:= EXIT_ENDLEVELCUSTOM
;
6913 // intermission, so change map immediately
6920 found
:= e_FindResource(AllMapDirs
, s
);
6922 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6925 // no such map, found wad
6928 P
[1] := ExpandFileName(pw
);
6929 P
[2] := g_Game_GetFirstMap(P
[1]);
6930 s
:= P
[1] + ':\' + P
[2];
6931 if g_Map_Exist(s
) then
6933 gExitByTrigger
:= False;
6936 // already in game, finish current map
6938 gExit
:= EXIT_ENDLEVELCUSTOM
6942 // intermission, so change map immediately
6949 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6951 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6956 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6962 s
:= addWadExtension(P
[1]);
6963 found
:= e_FindResource(AllMapDirs
, s
);
6967 P
[2] := UpperCase(P
[2]);
6968 s
:= P
[1] + ':\' + P
[2];
6969 if g_Map_Exist(s
) then
6971 gExitByTrigger
:= False;
6975 gExit
:= EXIT_ENDLEVELCUSTOM
6984 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6989 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6995 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6999 else if cmd
= 'nextmap' then
7001 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7003 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7008 if Length(P
) = 1 then
7010 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7012 g_Console_Add(cmd
+ ' <MAP>');
7013 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7018 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7024 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7026 if Length(P
) < 3 then
7028 // first param is map or wad
7029 s
:= UpperCase(P
[1]);
7030 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7033 gExitByTrigger
:= False;
7039 // no such map, found wad
7040 pw
:= addWadExtension(P
[1]);
7041 found
:= e_FindResource(MapDirs
, pw
);
7043 found
:= e_FindResource(WadDirs
, pw
);
7045 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7048 // map not specified, select first map
7050 P
[2] := g_Game_GetFirstMap(P
[1]);
7051 s
:= P
[1] + ':\' + P
[2];
7052 if g_Map_Exist(s
) then
7054 gExitByTrigger
:= False;
7061 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7063 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7068 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7074 // specified two params wad + map
7075 pw
:= addWadExtension(P
[1]);
7076 found
:= e_FindResource(MapDirs
, pw
);
7078 found
:= e_FindResource(MapDirs
, pw
);
7082 P
[2] := UpperCase(P
[2]);
7083 s
:= P
[1] + ':\' + P
[2];
7084 if g_Map_Exist(s
) then
7086 gExitByTrigger
:= False;
7092 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7097 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7103 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7108 if gNextMap
= '' then
7109 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7111 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7115 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7119 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7123 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7125 gExitByTrigger
:= False;
7126 // next map not specified, try to find trigger EXIT
7127 if (gNextMap
= '') and (gTriggers
<> nil) then
7129 for a
:= 0 to High(gTriggers
) do
7131 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7133 gExitByTrigger
:= True;
7134 //gNextMap := gTriggers[a].Data.MapName;
7135 gNextMap
:= gTriggers
[a
].tgcMap
;
7140 if gNextMap
= '' then
7141 gNextMap
:= g_Game_GetNextMap();
7142 if not isWadPath(gNextMap
) then
7143 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7146 if g_Map_Exist(s
) then
7147 gExit
:= EXIT_ENDLEVELCUSTOM
7149 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7153 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7157 else if (cmd
= 'event') then
7159 if (Length(P
) <= 1) then
7161 for a
:= 0 to High(gEvents
) do
7162 if gEvents
[a
].Command
= '' then
7163 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7165 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7168 if (Length(P
) = 2) then
7170 for a
:= 0 to High(gEvents
) do
7171 if gEvents
[a
].Name
= P
[1] then
7172 if gEvents
[a
].Command
= '' then
7173 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7175 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7178 for a
:= 0 to High(gEvents
) do
7179 if gEvents
[a
].Name
= P
[1] then
7181 gEvents
[a
].Command
:= '';
7182 for b
:= 2 to High(P
) do
7183 if Pos(' ', P
[b
]) = 0 then
7184 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7186 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7187 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7191 else if cmd
= 'suicide' then
7195 if g_Game_IsClient
then
7196 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7199 if gPlayer1
<> nil then
7200 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7201 if gPlayer2
<> nil then
7202 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7206 else if cmd
= 'screenshot' then
7210 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7212 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7214 gWeaponAction
[0, WP_PREV
] := True;
7216 gWeaponAction
[0, WP_NEXT
] := True;
7218 else if cmd
= 'weapon' then
7220 if Length(p
) = 2 then
7222 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7223 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7224 gSelectWeapon
[0, a
] := True
7227 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7228 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7230 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7231 b
:= ord(cmd
[2]) - ord('1');
7233 gWeaponAction
[b
, WP_PREV
] := True;
7235 gWeaponAction
[b
, WP_NEXT
] := True;
7237 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7239 if Length(p
) = 2 then
7241 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7242 b
:= ord(cmd
[2]) - ord('1');
7243 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7244 gSelectWeapon
[b
, a
] := True
7247 else if (cmd
= 'dropflag') then
7249 if g_Game_IsServer
then
7251 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7252 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7255 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7257 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7259 b
:= ord(cmd
[2]) - ord('1');
7260 if g_Game_IsServer
then
7262 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7263 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7266 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7268 // Êîìàíäû Ñâîåé èãðû:
7269 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7271 if cmd
= 'bot_addred' then
7273 if Length(P
) > 1 then
7274 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7276 g_Bot_Add(TEAM_RED
, 2);
7278 else if cmd
= 'bot_addblue' then
7280 if Length(P
) > 1 then
7281 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7283 g_Bot_Add(TEAM_BLUE
, 2);
7285 else if cmd
= 'spectate' then
7291 else if cmd
= 'say' then
7293 if g_Game_IsServer
and g_Game_IsNet
then
7295 if Length(P
) > 1 then
7298 for a
:= 1 to High(P
) do
7299 chstr
:= chstr
+ P
[a
] + ' ';
7301 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7303 if Length(chstr
) < 1 then
7305 g_Console_Add('say <text>');
7309 chstr
:= b_Text_Format(chstr
);
7310 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7312 else g_Console_Add('say <text>');
7314 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7316 else if cmd
= 'tell' then
7318 if g_Game_IsServer
and g_Game_IsNet
then
7320 if (Length(P
) > 2) and (P
[1] <> '') then
7323 for a
:= 2 to High(P
) do
7324 chstr
:= chstr
+ P
[a
] + ' ';
7326 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7328 if Length(chstr
) < 1 then
7330 g_Console_Add('tell <playername> <text>');
7334 pl
:= g_Net_Client_ByName(P
[1]);
7336 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7338 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7340 else g_Console_Add('tell <playername> <text>');
7342 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7344 else if cmd
= 'centerprint' then
7346 if (Length(P
) > 2) and (P
[1] <> '') then
7349 for a
:= 2 to High(P
) do
7350 chstr
:= chstr
+ P
[a
] + ' ';
7352 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7354 if Length(chstr
) < 1 then
7356 g_Console_Add('centerprint <timeout> <text>');
7360 a
:= StrToIntDef(P
[1], 100);
7361 chstr
:= b_Text_Format(chstr
);
7362 g_Game_Message(chstr
, a
);
7363 if g_Game_IsNet
and g_Game_IsServer
then
7364 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7366 else g_Console_Add('centerprint <timeout> <text>');
7368 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7370 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7372 // Äîïîëíèòåëüíîå âðåìÿ:
7373 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7375 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7376 [gGameSettings
.TimeLimit
div 3600,
7377 (gGameSettings
.TimeLimit
div 60) mod 60,
7378 gGameSettings
.TimeLimit
mod 60]));
7379 if g_Game_IsNet
then MH_SEND_GameSettings
;
7381 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7383 if (Length(P
) <= 1) then
7384 g_Console_Add('rcon_password <password>')
7386 MC_SEND_RCONPassword(P
[1]);
7388 else if cmd
= 'rcon' then
7390 if g_Game_IsClient
then
7392 if Length(P
) > 1 then
7395 for a
:= 1 to High(P
) do
7396 chstr
:= chstr
+ P
[a
] + ' ';
7398 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7400 if Length(chstr
) < 1 then
7402 g_Console_Add('rcon <command>');
7406 MC_SEND_RCONCommand(chstr
);
7408 else g_Console_Add('rcon <command>');
7411 else if cmd
= 'ready' then
7413 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7414 gLMSRespawnTime
:= gTime
+ 100;
7416 else if (cmd
= 'callvote') and g_Game_IsNet
then
7418 if Length(P
) > 1 then
7421 for a
:= 1 to High(P
) do begin
7422 if a
> 1 then chstr
:= chstr
+ ' ';
7423 chstr
:= chstr
+ P
[a
];
7426 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7428 if Length(chstr
) < 1 then
7430 g_Console_Add('callvote <command>');
7434 if g_Game_IsClient
then
7435 MC_SEND_Vote(True, chstr
)
7437 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7438 g_Console_Process('vote', True);
7441 g_Console_Add('callvote <command>');
7443 else if (cmd
= 'vote') and g_Game_IsNet
then
7445 if g_Game_IsClient
then
7447 else if gVoteInProgress
then
7449 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7450 a
:= Floor((NetClientCount
+1)/2.0) + 1
7452 a
:= Floor(NetClientCount
/2.0) + 1;
7457 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7458 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7464 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7465 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7473 procedure SystemCommands(P
: SSArray
);
7477 cmd
:= LowerCase(P
[0]);
7486 gRC_Width
:= Max(1, gRC_Width
);
7487 gRC_Height
:= Max(1, gRC_Height
);
7488 gBPP
:= Max(1, gBPP
);
7489 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7490 e_LogWriteln('resolution changed')
7492 e_LogWriteln('resolution not changed');
7493 sys_EnableVSync(gVSync
);
7497 if Length(p
) = 2 then
7499 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7501 gFrameTime
:= 1000 div gMaxFPS
7505 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7509 if Length(p
) = 2 then
7511 gAskLanguage
:= true;
7512 gLanguage
:= LANGUAGE_ENGLISH
;
7513 case LowerCase(p
[1]) of
7516 gAskLanguage
:= false;
7517 gLanguage
:= LANGUAGE_ENGLISH
;
7521 gAskLanguage
:= false;
7522 gLanguage
:= LANGUAGE_RUSSIAN
;
7526 gAskLanguage
:= true;
7527 gLanguage
:= LANGUAGE_ENGLISH
;
7530 g_Language_Set(gLanguage
);
7534 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7540 procedure g_TakeScreenShot(Filename
: string = '');
7541 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7543 if e_NoGraphics
then Exit
;
7545 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7547 if Filename
= '' then
7550 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7551 Filename
:= 'screenshot-' + date
;
7554 name
:= e_CatPath(dir
, Filename
+ '.png');
7555 s
:= createDiskFile(name
);
7557 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7559 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7561 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7566 g_Console_Add('oh shit, i can''t create screenshot!')
7570 procedure g_Game_InGameMenu(Show
: Boolean);
7572 if (g_ActiveWindow
= nil) and Show
then
7574 if gGameSettings
.GameType
= GT_SINGLE
then
7575 g_GUI_ShowWindow('GameSingleMenu')
7578 if g_Game_IsClient
then
7579 g_GUI_ShowWindow('GameClientMenu')
7581 if g_Game_IsNet
then
7582 g_GUI_ShowWindow('GameServerMenu')
7584 g_GUI_ShowWindow('GameCustomMenu');
7586 g_Sound_PlayEx('MENU_OPEN');
7588 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7589 if (not g_Game_IsNet
) then
7593 if (g_ActiveWindow
<> nil) and (not Show
) then
7595 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7596 if (not g_Game_IsNet
) then
7597 g_Game_Pause(False);
7601 procedure g_Game_Pause (Enable
: Boolean);
7605 if not gGameOn
then exit
;
7607 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7610 gPauseMain
:= Enable
;
7612 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7615 procedure g_Game_HolmesPause (Enable
: Boolean);
7619 if not gGameOn
then exit
;
7620 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7623 gPauseHolmes
:= Enable
;
7625 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7628 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7633 if gTriggers
<> nil then
7634 for i
:= 0 to High(gTriggers
) do
7635 with gTriggers
[i
] do
7636 if (TriggerType
= TRIGGER_SOUND
) and
7638 Sound
.IsPlaying() then
7640 Sound
.Pause(Enable
);
7644 if gPlayers
<> nil then
7645 for i
:= 0 to High(gPlayers
) do
7646 if gPlayers
[i
] <> nil then
7647 gPlayers
[i
].PauseSounds(Enable
);
7650 if gMusic
<> nil then
7651 gMusic
.Pause(Enable
);
7654 procedure g_Game_StopAllSounds(all
: Boolean);
7658 if gTriggers
<> nil then
7659 for i
:= 0 to High(gTriggers
) do
7660 with gTriggers
[i
] do
7661 if (TriggerType
= TRIGGER_SOUND
) and
7665 if gMusic
<> nil then
7672 procedure g_Game_UpdateTriggerSounds
;
7675 if gTriggers
<> nil then
7676 for i
:= 0 to High(gTriggers
) do
7677 with gTriggers
[i
] do
7678 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7679 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7682 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7685 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7690 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7695 if gSpectMode
<> SPECT_PLAYERS
then
7697 if gSpectPID1
= UID
then
7702 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7709 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7714 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7719 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7724 if gSpectMode
<> SPECT_PLAYERS
then
7726 Pl
:= g_Player_Get(gSpectPID1
);
7727 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7732 if gSpectViewTwo
then
7734 Pl
:= g_Player_Get(gSpectPID2
);
7735 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7743 procedure g_Game_Message(Msg
: string; Time
: Word);
7745 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7746 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7747 MessageTime
:= Time
;
7750 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7752 punct
: Array[0..13] of String =
7753 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7759 function IsPunctuation(S
: String): Boolean;
7764 if Length(S
) <> 1 then
7766 for i
:= Low(punct
) to High(punct
) do
7767 if S
= punct
[i
] then
7773 function FilterPunctuation(S
: String): String;
7777 for i
:= Low(punct
) to High(punct
) do
7778 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7784 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7786 // remove player name
7787 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7788 // for FullWord check
7789 Text := toLowerCase1251(' ' + Text + ' ');
7790 fpText
:= FilterPunctuation(Text);
7792 for i
:= 0 to Length(gChatSounds
) - 1 do
7795 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7797 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7798 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7800 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7806 gChatSounds
[i
].Sound
.Play();
7812 g_Sound_PlayEx('SOUND_GAME_RADIO');
7815 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7824 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7828 if goodsnd
[a
].IsPlaying() then
7831 goodsnd
[Random(4)].Play();
7834 procedure g_Game_Announce_KillCombo(Param
: Integer);
7841 UID
:= Param
and $FFFF;
7846 Pl
:= g_Player_Get(UID
);
7855 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7859 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7863 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7867 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7875 if not g_Game_IsWatchedPlayer(UID
) then
7878 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7882 if killsnd
[n
].IsPlaying() then
7887 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7895 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7899 if hahasnd
[a
].IsPlaying() then
7902 hahasnd
[Random(3)].Play();
7905 procedure g_Game_StartVote(Command
, Initiator
: string);
7909 if not gVotesEnabled
then Exit
;
7910 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7911 if gVoteInProgress
or gVotePassed
then
7913 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7914 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7917 gVoteInProgress
:= True;
7918 gVotePassed
:= False;
7919 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7922 gVoteCommand
:= Command
;
7924 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7925 Need
:= Floor((NetClientCount
+1)/2.0)+1
7927 Need
:= Floor(NetClientCount
/2.0)+1;
7928 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7929 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7932 procedure g_Game_CheckVote
;
7936 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7937 if not gVoteInProgress
then Exit
;
7939 if (gTime
>= gVoteTimer
) then
7941 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7942 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7944 Need
:= Floor(NetClientCount
/2.0) + 1;
7945 if gVoteCount
>= Need
then
7947 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7948 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7949 gVotePassed
:= True;
7950 gVoteCmdTimer
:= gTime
+ 5000;
7954 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7955 MH_SEND_VoteEvent(NET_VE_FAILED
);
7957 if NetClients
<> nil then
7958 for I
:= Low(NetClients
) to High(NetClients
) do
7959 if NetClients
[i
].Used
then
7960 NetClients
[i
].Voted
:= False;
7961 gVoteInProgress
:= False;
7967 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7968 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7970 Need
:= Floor(NetClientCount
/2.0) + 1;
7971 if gVoteCount
>= Need
then
7973 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7974 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7975 gVoteInProgress
:= False;
7976 gVotePassed
:= True;
7977 gVoteCmdTimer
:= gTime
+ 5000;
7980 if NetClients
<> nil then
7981 for I
:= Low(NetClients
) to High(NetClients
) do
7982 if NetClients
[i
].Used
then
7983 NetClients
[i
].Voted
:= False;
7988 procedure g_Game_LoadMapList(FileName
: string);
7996 if not FileExists(FileName
) then Exit
;
7998 AssignFile(ListFile
, FileName
);
8000 while not EOF(ListFile
) do
8002 ReadLn(ListFile
, s
);
8005 if s
= '' then Continue
;
8007 SetLength(MapList
, Length(MapList
)+1);
8008 MapList
[High(MapList
)] := s
;
8010 CloseFile(ListFile
);
8013 procedure g_Game_SetDebugMode();
8016 // ×èòû (äàæå â ñâîåé èãðå):
8020 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8024 if Length(LoadingStat
.Msgs
) = 0 then
8030 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8031 if NextMsg
= Length(Msgs
) then
8033 for i
:= 0 to High(Msgs
)-1 do
8034 Msgs
[i
] := Msgs
[i
+1];
8042 Msgs
[NextMsg
-1] := Text;
8046 PBarWasHere
:= false;
8049 g_ActiveWindow
:= nil;
8051 ProcessLoading(true);
8054 procedure g_Game_StepLoading(Value
: Integer = -1);
8065 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8073 procedure g_Game_ClearLoading();
8082 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8083 if len
< 1 then len
:= 1;
8084 SetLength(Msgs
, len
);
8085 for len
:= Low(Msgs
) to High(Msgs
) do
8088 PBarWasHere
:= false;
8092 procedure Parse_Params(var pars
: TParamStrValues
);
8099 while i
<= ParamCount
do
8102 if (Length(s
) > 1) and (s
[1] = '-') then
8104 if (Length(s
) > 2) and (s
[2] = '-') then
8105 begin // Îäèíî÷íûé ïàðàìåòð
8106 SetLength(pars
, Length(pars
) + 1);
8107 with pars
[High(pars
)] do
8109 Name
:= LowerCase(s
);
8114 if (i
< ParamCount
) then
8115 begin // Ïàðàìåòð ñî çíà÷åíèåì
8117 SetLength(pars
, Length(pars
) + 1);
8118 with pars
[High(pars
)] do
8120 Name
:= LowerCase(s
);
8121 Value
:= LowerCase(ParamStr(i
));
8130 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8135 for i
:= 0 to High(pars
) do
8136 if pars
[i
].Name
= aName
then
8138 Result
:= pars
[i
].Value
;
8143 procedure g_Game_Process_Params();
8145 pars
: TParamStrValues
;
8148 LimT
, LimS
: Integer;
8159 s
:= Find_Param_Value(pars
, '--debug');
8162 g_Game_SetDebugMode();
8163 s
:= Find_Param_Value(pars
, '--netdump');
8168 // Connect when game loads
8169 ip
:= Find_Param_Value(pars
, '-connect');
8173 s
:= Find_Param_Value(pars
, '-port');
8174 if (s
= '') or not TryStrToInt(s
, Port
) then
8177 s
:= Find_Param_Value(pars
, '-pw');
8179 g_Game_StartClient(ip
, Port
, s
);
8183 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8186 gDefaultMegawadStart
:= s
;
8189 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8190 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8192 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8195 // Start map when game loads:
8196 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8197 if isWadPath(map
) then
8200 s
:= Find_Param_Value(pars
, '-gm');
8201 GMode
:= g_Game_TextToMode(s
);
8202 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8203 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8206 s
:= Find_Param_Value(pars
, '-limt');
8207 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8213 s
:= Find_Param_Value(pars
, '-lims');
8214 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8220 s
:= Find_Param_Value(pars
, '-lives');
8221 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8227 s
:= Find_Param_Value(pars
, '-opt');
8231 Opt
:= StrToIntDef(s
, 0);
8234 s
:= Find_Param_Value(pars
, '--close');
8238 // Override map to test:
8239 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8242 if e_IsValidResourceName(s
) then
8243 e_FindResource(AllMapDirs
, s
);
8244 gTestMap
:= ExpandFileName(s
);
8247 // Delete test map after play:
8248 s
:= Find_Param_Value(pars
, '--testdelete');
8251 //gMapToDelete := MapsDir + map;
8252 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8256 // Delete temporary WAD after play:
8257 s
:= Find_Param_Value(pars
, '--tempdelete');
8258 if (s
<> '') and (gTestMap
<> '') then
8260 gMapToDelete
:= gTestMap
;
8261 gTempDelete
:= True;
8264 // Number of players:
8265 s
:= Find_Param_Value(pars
, '-pl');
8267 n
:= DEFAULT_PLAYERS
8269 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8272 s
:= Find_Param_Value(pars
, '-port');
8273 if (s
= '') or not TryStrToInt(s
, Port
) then
8274 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8276 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8279 // Execute script when game loads:
8280 s
:= Find_Param_Value(pars
, '-exec');
8283 // if not isWadPath(s) then
8284 // s := GameDir + '/' + s;
8289 if IOResult
<> 0 then
8291 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8292 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8296 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8297 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8302 if IOResult
<> 0 then
8304 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8305 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8309 if Pos('#', s
) <> 1 then // script comment
8310 g_Console_Process(s
, True);
8321 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8322 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8323 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8324 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8326 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8327 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8328 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8329 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8331 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8332 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8334 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8335 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8337 {$IFDEF ENABLE_HOLMES}
8338 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8341 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8343 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8344 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8346 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8347 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8349 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8350 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8352 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8353 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8354 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8355 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8356 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8357 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8358 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8359 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8360 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');