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
);
1784 function sendItemPos (it
: PItem
): Boolean;
1786 result
:= false; // don't stop
1789 MH_SEND_ItemPos(it
.myId
);
1790 it
.needSend
:= False;
1795 reliableUpdate
: Boolean;
1800 // Ïîðà âûêëþ÷àòü èãðó:
1801 if gExit
= EXIT_QUIT
then
1803 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1807 if gExit
= EXIT_QUIT
then
1811 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1812 // no need to, as we'll do it in event handler
1814 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1817 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1819 gExit
:= EXIT_SIMPLE
;
1824 // process master server communications
1825 g_Net_Slist_Pulse();
1828 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1829 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1830 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1831 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1833 if g_Game_IsNet
and g_Game_IsServer
then
1835 gInterTime
:= gInterTime
+ GAME_TICK
;
1836 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1837 if a
<> gServInterTime
then
1839 gServInterTime
:= a
;
1840 MH_SEND_TimeSync(gServInterTime
);
1844 if (not g_Game_IsClient
) and
1848 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1849 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1850 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1851 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1853 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1854 and (g_ActiveWindow
= nil)
1856 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1859 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1860 g_Game_StopAllSounds(True);
1862 if gMapOnce
then // Ýòî áûë òåñò
1863 gExit
:= EXIT_SIMPLE
1865 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1866 g_Game_ChangeMap(gNextMap
)
1867 else // Ñëåäóþùåé êàðòû íåò
1869 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1871 // Âûõîä â ãëàâíîå ìåíþ:
1873 g_GUI_ShowWindow('MainMenu');
1874 gMusic
.SetByName('MUSIC_MENU');
1876 gState
:= STATE_MENU
;
1879 // Ôèíàëüíàÿ êàðòèíêà:
1880 g_Game_ExecuteEvent('onwadend');
1882 if not gMusic
.SetByName('MUSIC_endmus') then
1883 gMusic
.SetByName('MUSIC_STDENDMUS');
1885 gState
:= STATE_ENDPIC
;
1887 g_Game_ExecuteEvent('ongameend');
1892 else if g_Game_IsClient
and
1895 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1896 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1897 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1898 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1900 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1901 and (g_ActiveWindow
= nil)
1909 if gState
= STATE_INTERTEXT
then
1910 if InterText
.counter
> 0 then
1911 InterText
.counter
:= InterText
.counter
- 1;
1914 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1916 if EndingGameCounter
= 0 then
1918 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1919 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1921 gState
:= STATE_INTERCUSTOM
;
1922 InterReadyTime
:= -1;
1923 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1925 g_Game_ExecuteEvent('onwadend');
1926 if not gMusic
.SetByName('MUSIC_endmus') then
1927 gMusic
.SetByName('MUSIC_STDENDMUS');
1930 gMusic
.SetByName('MUSIC_ROUNDMUS');
1934 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1936 gMusic
.SetByName('MUSIC_INTERMUS');
1938 gState
:= STATE_INTERSINGLE
;
1941 g_Game_ExecuteEvent('oninter');
1944 DecMin(EndingGameCounter
, 6, 0);
1947 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1949 if gMapOnce
then // Ýòî áûë òåñò
1951 gExit
:= EXIT_SIMPLE
;
1957 g_Serverlist_Control(slCurrent
, slTable
);
1960 // Ñòàòèñòèêà ïî Tab:
1962 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1965 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1967 // Âðåìÿ += 28 ìèëëèñåêóíä:
1968 gTime
:= gTime
+ GAME_TICK
;
1970 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1971 if MessageTime
= 0 then
1973 if MessageTime
> 0 then
1974 MessageTime
:= MessageTime
- 1;
1976 if (g_Game_IsServer
) then
1978 // Áûë çàäàí ëèìèò âðåìåíè:
1979 if (gGameSettings
.TimeLimit
> 0) then
1980 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1981 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1986 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1987 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1988 g_Game_RestartRound(gLMSSoftSpawn
);
1990 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1991 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1993 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1995 g_Console_Process(gVoteCommand
);
1997 gVotePassed
:= False;
2000 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2001 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2002 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2003 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2004 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2006 // Áûë çàäàí ëèìèò ïîáåä:
2007 if (gGameSettings
.GoalLimit
> 0) then
2011 if gGameSettings
.GameMode
= GM_DM
then
2012 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2013 for i
:= 0 to High(gPlayers
) do
2014 if gPlayers
[i
] <> nil then
2015 if gPlayers
[i
].Frags
> b
then
2016 b
:= gPlayers
[i
].Frags
;
2019 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2020 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2021 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2024 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2025 if b
>= gGameSettings
.GoalLimit
then
2032 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2033 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2034 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2035 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2037 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2038 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2039 end // if not console
2042 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2044 // process weapon switch queue
2048 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2049 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2051 if not gSpectKeyPress
then
2053 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2055 // switch spect mode
2057 SPECT_NONE
: ; // not spectator
2059 SPECT_MAPVIEW
: Inc(gSpectMode
);
2060 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2062 gSpectKeyPress
:= True;
2064 if (gSpectMode
= SPECT_MAPVIEW
)
2065 and (not gSpectAuto
) then
2067 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2068 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2069 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2070 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2071 if gPlayerAction
[0, ACTION_LOOKUP
] then
2072 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2073 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2074 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2075 if gWeaponAction
[0, WP_PREV
] then
2078 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2079 gWeaponAction
[0, WP_PREV
] := False;
2081 if gWeaponAction
[0, WP_NEXT
] then
2084 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2085 gWeaponAction
[0, WP_NEXT
] := False;
2088 if (gSpectMode
= SPECT_PLAYERS
)
2089 and (not gSpectAuto
) then
2091 if gPlayerAction
[0, ACTION_LOOKUP
] then
2094 gSpectViewTwo
:= True;
2095 gSpectKeyPress
:= True;
2097 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2099 // remove second view
2100 gSpectViewTwo
:= False;
2101 gSpectKeyPress
:= True;
2103 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2105 // prev player (view 1)
2106 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2107 gSpectKeyPress
:= True;
2109 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2111 // next player (view 1)
2112 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2113 gSpectKeyPress
:= True;
2115 if gWeaponAction
[0, WP_PREV
] then
2117 // prev player (view 2)
2118 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2119 gWeaponAction
[0, WP_PREV
] := False;
2121 if gWeaponAction
[0, WP_NEXT
] then
2123 // next player (view 2)
2124 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2125 gWeaponAction
[0, WP_NEXT
] := False;
2128 if gPlayerAction
[0, ACTION_ATTACK
] then
2130 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2133 gSpectAutoNext
:= 0;
2134 gSpectViewTwo
:= False;
2135 gSpectKeyPress
:= True;
2140 gSpectMode
:= SPECT_STATS
;
2141 gSpectAuto
:= False;
2142 gSpectKeyPress
:= True;
2147 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2148 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2149 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2150 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2151 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2152 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2153 gSpectKeyPress
:= False;
2157 if gSpectMode
= SPECT_MAPVIEW
then
2159 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2161 gSpectAutoNext
:= gTime
2164 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2166 gSpectAutoNext
:= gTime
2170 if gSpectAutoNext
<= gTime
then
2172 if gSpectAutoNext
> 0 then
2174 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2178 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2179 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2180 gSpectAutoStepX
:= Random(9) - 4;
2181 gSpectAutoStepY
:= Random(9) - 4;
2182 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2183 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2184 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2185 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2186 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2187 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2191 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2196 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2197 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2198 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2204 // Îáíîâëÿåì âñå îñòàëüíîå:
2207 g_Triggers_Update();
2209 g_Monsters_Update();
2211 g_Player_UpdateAll();
2212 g_Player_UpdatePhysicalObjects();
2214 // server: send newly spawned monsters unconditionally
2215 if (gGameSettings
.GameType
= GT_SERVER
) then
2217 if (Length(gMonstersSpawned
) > 0) then
2219 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2220 SetLength(gMonstersSpawned
, 0);
2224 if (gSoundTriggerTime
> 8) then
2226 g_Game_UpdateTriggerSounds();
2227 gSoundTriggerTime
:= 0;
2231 Inc(gSoundTriggerTime
);
2234 if (NetMode
= NET_SERVER
) then
2236 Inc(NetTimeToUpdate
);
2237 Inc(NetTimeToReliable
);
2239 // send monster updates
2240 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2242 // send all monsters (periodic sync)
2243 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2245 for I
:= 0 to High(gPlayers
) do
2247 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2250 g_Mons_ForEach(sendMonsPos
);
2252 // update flags that aren't stationary
2253 if gGameSettings
.GameMode
= GM_CTF
then
2254 for I
:= FLAG_RED
to FLAG_BLUE
do
2255 if gFlags
[I
].NeedSend
then
2257 gFlags
[I
].NeedSend
:= False;
2261 // update items that aren't stationary
2262 g_Items_ForEachAlive(sendItemPos
);
2264 if reliableUpdate
then
2266 NetTimeToReliable
:= 0;
2267 NetTimeToUpdate
:= NetUpdateRate
;
2271 NetTimeToUpdate
:= 0;
2276 // send only mosters with some unexpected changes
2277 g_Mons_ForEach(sendMonsPosUnexpected
);
2280 // send unexpected platform changes
2281 g_Map_NetSendInterestingPanels();
2283 g_Net_Slist_ServerUpdate();
2285 if NetUseMaster then
2287 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2289 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2291 NetTimeToMaster := gTime + NetMasterRate;
2296 else if (NetMode
= NET_CLIENT
) then
2298 MC_SEND_PlayerPos();
2300 end; // if gameOn ...
2302 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2303 if g_ActiveWindow
<> nil then
2305 w
:= e_GetFirstKeyPressed();
2307 if (w
<> IK_INVALID
) then
2309 Msg
.Msg
:= MESSAGE_DIKEY
;
2311 g_ActiveWindow
.OnMessage(Msg
);
2314 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2315 if g_ActiveWindow
<> nil then
2316 g_ActiveWindow
.Update();
2318 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2319 if gResolutionChange
then
2321 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2322 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2323 gResolutionChange
:= False;
2324 g_ActiveWindow
:= nil;
2327 // Íóæíî ñìåíèòü ÿçûê:
2328 if gLanguageChange
then
2330 //e_WriteLog('Read language file', MSG_NOTIFY);
2331 //g_Language_Load(DataDir + gLanguage + '.txt');
2332 g_Language_Set(gLanguage
);
2336 gLanguageChange
:= False;
2340 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2341 if e_KeyPressed(IK_F10
) and
2343 (not gConsoleShow
) and
2344 (g_ActiveWindow
= nil) then
2349 Time
:= sys_GetTicks() {div 1000};
2351 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2352 if gDelayedEvents
<> nil then
2353 for a
:= 0 to High(gDelayedEvents
) do
2354 if gDelayedEvents
[a
].Pending
and
2356 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2357 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2360 case gDelayedEvents
[a
].DEType
of
2362 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2365 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2369 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2370 if g_Game_IsNet
and g_Game_IsServer
then
2371 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2375 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2377 gDelayedEvents
[a
].Pending
:= False;
2380 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2381 UPSCounter
:= UPSCounter
+ 1;
2382 if Time
- UPSTime
>= 1000 then
2391 g_Weapon_AddDynLights();
2392 g_Items_AddDynLights();
2396 procedure g_Game_LoadChatSounds(Resource
: string);
2399 FileName
, Snd
: string;
2401 len
, cnt
, tags
, i
, j
: Integer;
2404 FileName
:= g_ExtractWadName(Resource
);
2406 WAD
:= TWADFile
.Create();
2407 WAD
.ReadFile(FileName
);
2409 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2416 cfg
:= TConfig
.CreateMem(p
, len
);
2417 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2419 SetLength(gChatSounds
, cnt
);
2420 for i
:= 0 to Length(gChatSounds
) - 1 do
2422 gChatSounds
[i
].Sound
:= nil;
2423 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2424 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2425 if (Snd
= '') or (Tags
<= 0) then
2427 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2428 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2429 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2430 SetLength(gChatSounds
[i
].Tags
, tags
);
2431 for j
:= 0 to tags
- 1 do
2432 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2433 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2440 procedure g_Game_FreeChatSounds();
2444 for i
:= 0 to Length(gChatSounds
) - 1 do
2446 gChatSounds
[i
].Sound
.Free();
2447 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2449 SetLength(gChatSounds
, 0);
2453 procedure g_Game_LoadData();
2460 if DataLoaded
then Exit
;
2462 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2464 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2465 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2466 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2467 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2468 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2469 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2470 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2471 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2472 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2473 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2474 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2475 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2476 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2477 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2478 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2481 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2482 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2483 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2484 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2488 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2489 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2490 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2491 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2492 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
2498 hasPBarGfx
:= false;
2502 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2503 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2504 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2505 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2506 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2507 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2508 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2509 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2510 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2511 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2512 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2513 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2514 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2515 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2516 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2517 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2518 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2519 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2520 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2521 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2522 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2523 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2524 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2525 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2526 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2527 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2528 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2529 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2530 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2531 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2532 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2533 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2534 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2535 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2536 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2537 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2538 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2539 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2540 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2542 goodsnd
[0] := TPlayableSound
.Create();
2543 goodsnd
[1] := TPlayableSound
.Create();
2544 goodsnd
[2] := TPlayableSound
.Create();
2545 goodsnd
[3] := TPlayableSound
.Create();
2547 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2548 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2549 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2550 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2552 killsnd
[0] := TPlayableSound
.Create();
2553 killsnd
[1] := TPlayableSound
.Create();
2554 killsnd
[2] := TPlayableSound
.Create();
2555 killsnd
[3] := TPlayableSound
.Create();
2557 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2558 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2559 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2560 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2562 hahasnd
[0] := TPlayableSound
.Create();
2563 hahasnd
[1] := TPlayableSound
.Create();
2564 hahasnd
[2] := TPlayableSound
.Create();
2566 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2567 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2568 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2570 sound_get_flag
[0] := TPlayableSound
.Create();
2571 sound_get_flag
[1] := TPlayableSound
.Create();
2572 sound_lost_flag
[0] := TPlayableSound
.Create();
2573 sound_lost_flag
[1] := TPlayableSound
.Create();
2574 sound_ret_flag
[0] := TPlayableSound
.Create();
2575 sound_ret_flag
[1] := TPlayableSound
.Create();
2576 sound_cap_flag
[0] := TPlayableSound
.Create();
2577 sound_cap_flag
[1] := TPlayableSound
.Create();
2579 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2580 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2581 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2582 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2583 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2584 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2585 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2586 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2588 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2590 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2593 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2594 g_Weapon_LoadData();
2596 g_Monsters_LoadData();
2601 procedure g_Game_FreeData();
2603 if not DataLoaded
then Exit
;
2606 g_Weapon_FreeData();
2607 g_Monsters_FreeData();
2609 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2611 g_Texture_Delete('NOTEXTURE');
2612 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2613 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2614 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2615 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2616 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2617 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2618 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2619 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2620 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2621 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2622 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2623 g_Frames_DeleteByName('FRAMES_TELEPORT');
2624 g_Frames_DeleteByName('FRAMES_PUNCH');
2625 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2626 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2627 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2628 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2629 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2630 g_Sound_Delete('SOUND_GAME_TELEPORT');
2631 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2632 g_Sound_Delete('SOUND_GAME_SECRET');
2633 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2634 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2635 g_Sound_Delete('SOUND_GAME_BULK1');
2636 g_Sound_Delete('SOUND_GAME_BULK2');
2637 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2638 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2639 g_Sound_Delete('SOUND_GAME_BURNING');
2640 g_Sound_Delete('SOUND_GAME_SWITCH1');
2641 g_Sound_Delete('SOUND_GAME_SWITCH0');
2648 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2649 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2650 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2651 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2658 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2659 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2660 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2661 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2667 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2668 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2669 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2671 sound_get_flag
[0].Free();
2672 sound_get_flag
[1].Free();
2673 sound_lost_flag
[0].Free();
2674 sound_lost_flag
[1].Free();
2675 sound_ret_flag
[0].Free();
2676 sound_ret_flag
[1].Free();
2677 sound_cap_flag
[0].Free();
2678 sound_cap_flag
[1].Free();
2680 g_Sound_Delete('SOUND_CTF_GET1');
2681 g_Sound_Delete('SOUND_CTF_GET2');
2682 g_Sound_Delete('SOUND_CTF_LOST1');
2683 g_Sound_Delete('SOUND_CTF_LOST2');
2684 g_Sound_Delete('SOUND_CTF_RETURN1');
2685 g_Sound_Delete('SOUND_CTF_RETURN2');
2686 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2687 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2689 g_Game_FreeChatSounds();
2691 DataLoaded
:= False;
2694 procedure DrawCustomStat();
2700 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2701 s1
, s2
, topstr
: String;
2703 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2707 if g_Console_Action(ACTION_SCORES
) then
2709 if not gStatsPressed
then
2711 gStatsOff
:= not gStatsOff
;
2712 gStatsPressed
:= True;
2716 gStatsPressed
:= False;
2720 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2721 w
:= (Length(s1
) * ww2
) div 2;
2722 x
:= gScreenWidth
div 2 - w
;
2724 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2728 if (gGameSettings
.GameMode
= GM_COOP
) then
2730 if gMissionFailed
then
2731 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2733 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2736 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2738 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2739 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2741 if g_Game_IsNet
then
2743 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2744 if not gChatShow
then
2745 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2746 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2749 if g_Game_IsClient
then
2750 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2752 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2753 if not gChatShow
then
2754 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2755 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2760 w
:= gScreenWidth
-x
*2;
2766 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2767 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2769 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2771 case CustomStat
.GameMode
of
2774 if gGameSettings
.MaxLives
= 0 then
2775 s1
:= _lc
[I_GAME_DM
]
2777 s1
:= _lc
[I_GAME_LMS
];
2781 if gGameSettings
.MaxLives
= 0 then
2782 s1
:= _lc
[I_GAME_TDM
]
2784 s1
:= _lc
[I_GAME_TLMS
];
2786 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2789 if gGameSettings
.MaxLives
= 0 then
2790 s1
:= _lc
[I_GAME_COOP
]
2792 s1
:= _lc
[I_GAME_SURV
];
2798 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2802 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2803 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2806 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2807 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2808 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2809 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2811 pc
:= Length(CustomStat
.PlayerStat
);
2812 if pc
= 0 then Exit
;
2814 if CustomStat
.GameMode
= GM_COOP
then
2816 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2818 s2
:= _lc
[I_GAME_MONSTERS
];
2819 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2820 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2822 s2
:= _lc
[I_GAME_SECRETS
];
2823 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2824 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2827 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2829 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2830 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2831 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2833 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2834 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2835 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2839 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2844 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2845 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2846 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2848 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2851 for t
:= TEAM_RED
to TEAM_BLUE
do
2853 if t
= TEAM_RED
then
2855 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2856 gStdFont
, 255, 0, 0, 1);
2857 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2858 gStdFont
, 255, 0, 0, 1);
2865 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2866 gStdFont
, 0, 0, 255, 1);
2867 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2868 gStdFont
, 0, 0, 255, 1);
2874 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2877 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2878 if CustomStat
.PlayerStat
[p
].Team
= t
then
2879 with CustomStat
.PlayerStat
[p
] do
2893 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2894 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2896 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2897 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2898 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2905 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2908 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2909 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2910 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2913 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2914 with CustomStat
.PlayerStat
[p
] do
2916 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2923 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2924 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2926 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2927 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2928 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2933 // HACK: take stats screenshot immediately after the first frame of the stats showing
2934 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2936 g_TakeScreenShot('stats/' + StatFilename
);
2937 StatShotDone
:= True;
2941 procedure DrawSingleStat();
2943 tm
, key_x
, val_x
, y
: Integer;
2947 procedure player_stat(n
: Integer);
2953 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2954 s2
:= Format(' %d', [gTotalMonsters
]);
2956 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2957 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2958 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2959 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2961 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2962 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2964 // "Kills-per-minute: ##.#":
2965 s1
:= _lc
[I_MENU_INTER_KPM
];
2967 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2969 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2970 s2
:= Format(' %.1f', [kpm
]);
2972 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2973 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2975 // "Secrets found: # / #":
2976 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2977 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2979 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2980 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2981 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2982 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2984 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2985 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2989 // "Level Complete":
2990 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2991 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2993 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2994 s1
:= _lc
[I_MENU_INTER_KPM
];
2995 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2998 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
3000 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
3001 val_x
:= key_x
+ w1
;
3004 tm
:= SingleStat
.GameTime
div 1000;
3005 s1
:= _lc
[I_MENU_INTER_TIME
];
3006 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
3008 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
3009 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
3011 if SingleStat
.TwoPlayers
then
3014 s1
:= _lc
[I_MENU_PLAYER_1
];
3015 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3016 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
3018 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3023 s1
:= _lc
[I_MENU_PLAYER_2
];
3024 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3025 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3027 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3033 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3039 procedure DrawLoadingStat();
3040 procedure drawRect (x
, y
, w
, h
: Integer);
3042 if (w
< 1) or (h
< 1) then exit
;
3044 glVertex2f(x
+0.375, y
+0.375);
3045 glVertex2f(x
+w
+0.375, y
+0.375);
3046 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3047 glVertex2f(x
+0.375, y
+h
+0.375);
3051 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3053 rectW
, rectH
: Integer;
3060 idl
, idr
, idb
, idm
: LongWord;
3064 if (total
< 1) then exit
;
3065 if (cur
< 1) then exit
; // don't blink
3066 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3067 //if (cur < 0) then cur := 0;
3068 //if (cur > total) then cur := total;
3071 if (hasPBarGfx
) then
3073 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3074 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3075 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3076 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3077 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3078 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3079 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3080 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3082 //rectW := gScreenWidth-360;
3083 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3086 x0
:= (gScreenWidth
-rectW
) div 2;
3087 y0
:= gScreenHeight
-rectH
-64;
3088 if (y0
< 2) then y0
:= 2;
3090 glEnable(GL_SCISSOR_TEST
);
3093 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3094 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3095 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3098 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3100 while (f
< x0
+rectW
) do
3102 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3107 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3108 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3111 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3112 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3116 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3122 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3126 rectW
:= gScreenWidth
-64;
3129 x0
:= (gScreenWidth
-rectW
) div 2;
3130 y0
:= gScreenHeight
-rectH
-64;
3131 if (y0
< 2) then y0
:= 2;
3133 glDisable(GL_BLEND
);
3134 glDisable(GL_TEXTURE_2D
);
3136 //glClearColor(0, 0, 0, 0);
3137 //glClear(GL_COLOR_BUFFER_BIT);
3139 glColor4ub(127, 127, 127, 255);
3140 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3142 glColor4ub(0, 0, 0, 255);
3143 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3145 glColor4ub(127, 127, 127, 255);
3146 wdt
:= rectW
*cur
div total
;
3147 if (wdt
> rectW
) then wdt
:= rectW
;
3148 drawRect(x0
, y0
, wdt
, rectH
);
3157 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3159 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3160 yy
:= (gScreenHeight
div 3);
3161 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3162 xx
:= (gScreenWidth
div 3);
3166 for i
:= 0 to NextMsg
-1 do
3168 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3169 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3173 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3174 yy
:= yy
+ LOADING_INTERLINE
;
3175 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3180 procedure DrawMenuBackground(tex
: AnsiString);
3186 if g_Texture_Get(tex
, ID
) then
3188 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3189 e_GetTextureSize(ID
, @w
, @h
);
3191 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3193 w
:= trunc(w
* (gScreenHeight
/ h
));
3194 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3196 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3199 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3201 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3203 function monDraw (mon
: TMonster
): Boolean;
3205 result
:= false; // don't stop
3210 // Ëåâûé âåðõíèé óãîë
3211 aX
:= Obj
.X
div ScaleSz
+ 1;
3212 aY
:= Obj
.Y
div ScaleSz
+ 1;
3214 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3215 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3216 // Ïðàâûé íèæíèé óãîë
3217 aX2
:= aX
+ aX2
- 1;
3218 aY2
:= aY
+ aY2
- 1;
3219 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3225 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3226 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3229 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3230 ScaleSz
:= 16 div Scale
;
3231 // Ðàçìåðû ìèíè-êàðòû:
3232 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3233 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3235 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3237 if gWalls
<> nil then
3240 for a
:= 0 to High(gWalls
) do
3242 if PanelType
<> 0 then
3244 // Ëåâûé âåðõíèé óãîë:
3245 aX
:= X
div ScaleSz
;
3246 aY
:= Y
div ScaleSz
;
3248 aX2
:= max(Width
div ScaleSz
, 1);
3249 aY2
:= max(Height
div ScaleSz
, 1);
3250 // Ïðàâûé íèæíèé óãîë:
3251 aX2
:= aX
+ aX2
- 1;
3252 aY2
:= aY
+ aY2
- 1;
3255 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3256 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3257 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3261 if gSteps
<> nil then
3264 for a
:= 0 to High(gSteps
) do
3266 if PanelType
<> 0 then
3268 // Ëåâûé âåðõíèé óãîë:
3269 aX
:= X
div ScaleSz
;
3270 aY
:= Y
div ScaleSz
;
3272 aX2
:= max(Width
div ScaleSz
, 1);
3273 aY2
:= max(Height
div ScaleSz
, 1);
3274 // Ïðàâûé íèæíèé óãîë:
3275 aX2
:= aX
+ aX2
- 1;
3276 aY2
:= aY
+ aY2
- 1;
3278 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3281 if gLifts
<> nil then
3284 for a
:= 0 to High(gLifts
) do
3286 if PanelType
<> 0 then
3288 // Ëåâûé âåðõíèé óãîë:
3289 aX
:= X
div ScaleSz
;
3290 aY
:= Y
div ScaleSz
;
3292 aX2
:= max(Width
div ScaleSz
, 1);
3293 aY2
:= max(Height
div ScaleSz
, 1);
3294 // Ïðàâûé íèæíèé óãîë:
3295 aX2
:= aX
+ aX2
- 1;
3296 aY2
:= aY
+ aY2
- 1;
3299 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3300 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3301 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3302 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3306 if gWater
<> nil then
3309 for a
:= 0 to High(gWater
) do
3311 if PanelType
<> 0 then
3313 // Ëåâûé âåðõíèé óãîë:
3314 aX
:= X
div ScaleSz
;
3315 aY
:= Y
div ScaleSz
;
3317 aX2
:= max(Width
div ScaleSz
, 1);
3318 aY2
:= max(Height
div ScaleSz
, 1);
3319 // Ïðàâûé íèæíèé óãîë:
3320 aX2
:= aX
+ aX2
- 1;
3321 aY2
:= aY
+ aY2
- 1;
3323 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3326 if gAcid1
<> nil then
3328 // Ðèñóåì êèñëîòó 1:
3329 for a
:= 0 to High(gAcid1
) do
3331 if PanelType
<> 0 then
3333 // Ëåâûé âåðõíèé óãîë:
3334 aX
:= X
div ScaleSz
;
3335 aY
:= Y
div ScaleSz
;
3337 aX2
:= max(Width
div ScaleSz
, 1);
3338 aY2
:= max(Height
div ScaleSz
, 1);
3339 // Ïðàâûé íèæíèé óãîë:
3340 aX2
:= aX
+ aX2
- 1;
3341 aY2
:= aY
+ aY2
- 1;
3343 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3346 if gAcid2
<> nil then
3348 // Ðèñóåì êèñëîòó 2:
3349 for a
:= 0 to High(gAcid2
) do
3351 if PanelType
<> 0 then
3353 // Ëåâûé âåðõíèé óãîë:
3354 aX
:= X
div ScaleSz
;
3355 aY
:= Y
div ScaleSz
;
3357 aX2
:= max(Width
div ScaleSz
, 1);
3358 aY2
:= max(Height
div ScaleSz
, 1);
3359 // Ïðàâûé íèæíèé óãîë:
3360 aX2
:= aX
+ aX2
- 1;
3361 aY2
:= aY
+ aY2
- 1;
3363 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3366 if gPlayers
<> nil then
3369 for a
:= 0 to High(gPlayers
) do
3370 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3372 // Ëåâûé âåðõíèé óãîë:
3373 aX
:= Obj
.X
div ScaleSz
+ 1;
3374 aY
:= Obj
.Y
div ScaleSz
+ 1;
3376 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3377 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3378 // Ïðàâûé íèæíèé óãîë:
3379 aX2
:= aX
+ aX2
- 1;
3380 aY2
:= aY
+ aY2
- 1;
3382 if gPlayers
[a
] = p
then
3383 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3386 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3387 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3388 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3393 g_Mons_ForEach(monDraw
);
3398 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3400 if not hasAmbient
then exit
;
3401 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3405 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3406 //FIXME: broken for splitscreen mode
3407 procedure renderDynLightsInternal ();
3409 //hasAmbient: Boolean;
3410 //ambColor: TDFColor;
3412 lx
, ly
, lrad
: Integer;
3413 scxywh
: array[0..3] of GLint
;
3416 if e_NoGraphics
then exit
;
3418 //TODO: lights should be in separate grid, i think
3419 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3420 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3423 //ambColor := gCurrentMap['light_ambient'].rgba;
3424 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3426 { // this will multiply incoming color to alpha from framebuffer
3428 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3432 * light rendering: (INVALID!)
3433 * glStencilFunc(GL_EQUAL, 0, $ff);
3435 * glClear(GL_STENCIL_BUFFER_BIT);
3436 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3437 * draw shadow volume into stencil buffer
3438 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3439 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3441 * draw color-less quad with light alpha (WARNING! don't touch color!)
3442 * glEnable(GL_BLEND);
3443 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3444 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3446 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3447 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3449 // setup OpenGL parameters
3450 glStencilMask($FFFFFFFF);
3451 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3452 glEnable(GL_STENCIL_TEST
);
3453 glEnable(GL_SCISSOR_TEST
);
3454 glClear(GL_STENCIL_BUFFER_BIT
);
3455 glStencilFunc(GL_EQUAL
, 0, $ff);
3457 for lln
:= 0 to g_dynLightCount
-1 do
3459 lx
:= g_dynLights
[lln
].x
;
3460 ly
:= g_dynLights
[lln
].y
;
3461 lrad
:= g_dynLights
[lln
].radius
;
3462 if (lrad
< 3) then continue
;
3464 if (lx
-sX
+lrad
< 0) then continue
;
3465 if (ly
-sY
+lrad
< 0) then continue
;
3466 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3467 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3469 // set scissor to optimize drawing
3470 if (g_dbg_scale
= 1.0) then
3472 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3476 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3478 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3479 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3480 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3481 // draw extruded panels
3482 glDisable(GL_TEXTURE_2D
);
3483 glDisable(GL_BLEND
);
3484 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3485 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3486 // render light texture
3487 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3488 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3491 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3492 glEnable(GL_TEXTURE_2D
);
3493 // color and opacity
3494 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3495 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3497 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3498 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3499 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3500 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3505 glDisable(GL_STENCIL_TEST
);
3506 glDisable(GL_BLEND
);
3507 glDisable(GL_SCISSOR_TEST
);
3508 //glScissor(0, 0, sWidth, sHeight);
3510 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3511 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3515 function fixViewportForScale (): Boolean;
3517 nx0
, ny0
, nw
, nh
: Integer;
3520 if (g_dbg_scale
<> 1.0) then
3523 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3524 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3525 nw
:= round(sWidth
/g_dbg_scale
);
3526 nh
:= round(sHeight
/g_dbg_scale
);
3535 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3536 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3537 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3539 TDrawCB
= procedure ();
3542 hasAmbient
: Boolean;
3544 doAmbient
: Boolean = false;
3546 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3551 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3552 if gdbg_map_use_accel_render
then
3554 tagmask
:= panelTypeToTag(panType
);
3555 while (gDrawPanelList
.count
> 0) do
3557 pan
:= TPanel(gDrawPanelList
.front());
3558 if ((pan
.tag
and tagmask
) = 0) then break
;
3559 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3560 gDrawPanelList
.popFront();
3565 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3567 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3570 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3572 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3573 if assigned(cb
) then cb();
3574 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3578 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3580 // our accelerated renderer will collect all panels to gDrawPanelList
3581 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3582 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3583 if gdbg_map_use_accel_render
then
3585 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3587 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3589 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3590 g_Map_DrawBack(backXOfs
, backYOfs
);
3591 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3593 if setTransMatrix
then
3595 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3596 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3597 glTranslatef(-sX
, -sY
, 0);
3601 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3602 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3607 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3608 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3609 glClear(GL_COLOR_BUFFER_BIT);
3612 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3615 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3616 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3617 drawOther('items', @g_Items_Draw
);
3618 drawOther('weapons', @g_Weapon_Draw
);
3619 drawOther('shells', @g_Player_DrawShells
);
3620 drawOther('drawall', @g_Player_DrawAll
);
3621 drawOther('corpses', @g_Player_DrawCorpses
);
3622 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3623 drawOther('monsters', @g_Monsters_Draw
);
3624 drawOther('itemdrop', @g_Items_DrawDrop
);
3625 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3626 drawOther('gfx', @g_GFX_Draw
);
3627 drawOther('flags', @g_Map_DrawFlags
);
3628 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3629 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3630 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3631 drawOther('dynlights', @renderDynLightsInternal
);
3633 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3635 renderAmbientQuad(hasAmbient
, ambColor
);
3639 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3642 if g_debug_HealthBar
then
3644 g_Monsters_DrawHealth();
3645 g_Player_DrawHealth();
3648 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3652 procedure DrawMapView(x
, y
, w
, h
: Integer);
3659 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3660 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3667 fixViewportForScale();
3668 renderMapInternal(-bx
, -by
, true);
3674 procedure DrawPlayer(p
: TPlayer
);
3676 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3680 if (p
= nil) or (p
.FDummy
) then
3683 g_Map_DrawBack(0, 0);
3688 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3689 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3695 camObj
:= p
.getCameraObj();
3696 camObj
.lerp(gLerpFactor
, fX
, fY
);
3697 px
:= fX
+ PLAYER_RECT_CX
;
3698 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3700 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3702 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3703 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3705 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3706 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3708 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3709 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3712 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3715 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3716 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3719 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3724 // scaled, ignore level bounds
3725 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3726 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3731 sWidth
:= gPlayerScreenSize
.X
;
3732 sHeight
:= gPlayerScreenSize
.Y
;
3733 fixViewportForScale();
3735 i
:= py
- (sY
+ sHeight
div 2);
3736 if (p
.IncCam
> 0) then
3738 // clamp to level bounds
3739 if (sY
- p
.IncCam
< 0) then
3740 p
.IncCam
:= nclamp(sY
, 0, 120);
3741 // clamp around player position
3743 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3745 else if (p
.IncCam
< 0) then
3747 // clamp to level bounds
3748 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3749 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3750 // clamp around player position
3752 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3755 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3757 if (not g_dbg_ignore_bounds
) then
3759 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3760 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3761 if (sX
< 0) then sX
:= 0;
3762 if (sY
< 0) then sY
:= 0;
3765 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3766 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3768 //r_smallmap_h: 0: left; 1: center; 2: right
3769 //r_smallmap_v: 0: top; 1: center; 2: bottom
3771 if (gMapInfo
.Width
= sWidth
) then
3775 else if (gMapInfo
.Width
< sWidth
) then
3777 case r_smallmap_h
of
3778 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3779 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3780 else sX
:= 0; // left
3784 if (gMapInfo
.Height
= sHeight
) then
3788 else if (gMapInfo
.Height
< sHeight
) then
3790 case r_smallmap_v
of
3791 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3792 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3793 else sY
:= 0; // top
3799 p
.viewPortW
:= sWidth
;
3800 p
.viewPortH
:= sHeight
;
3802 {$IFDEF ENABLE_HOLMES}
3803 if (p
= gPlayer1
) then
3805 g_Holmes_plrViewPos(sX
, sY
);
3806 g_Holmes_plrViewSize(sWidth
, sHeight
);
3810 renderMapInternal(-c
, -d
, true);
3812 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3813 case gPlayerIndicator
of
3815 p
.DrawIndicator(_RGB(255, 255, 255));
3818 for i
:= 0 to High(gPlayers
) do
3819 if gPlayers
[i
] <> nil then
3820 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3821 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3822 if gPlayerIndicatorStyle
= 1 then
3823 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3824 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3828 for a := 0 to High(gCollideMap) do
3829 for b := 0 to High(gCollideMap[a]) do
3832 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3834 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3838 1: e_DrawPoint(1, b, a, 200, 200, 200);
3839 2: e_DrawPoint(1, b, a, 64, 64, 255);
3840 3: e_DrawPoint(1, b, a, 255, 0, 255);
3850 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3851 if g_Debug_Player
then
3852 g_Player_DrawDebug(p
);
3856 procedure drawProfilers ();
3861 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3862 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3863 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3866 procedure g_Game_Draw();
3873 plView1
, plView2
: TPlayer
;
3876 if gExit
= EXIT_QUIT
then Exit
;
3878 Time
:= sys_GetTicks() {div 1000};
3879 FPSCounter
:= FPSCounter
+1;
3880 if Time
- FPSTime
>= 1000 then
3887 e_SetRendertarget(True);
3888 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3890 if gGameOn
or (gState
= STATE_FOLD
) then
3892 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3894 gSpectMode
:= SPECT_NONE
;
3895 if not gRevertPlayers
then
3897 plView1
:= gPlayer1
;
3898 plView2
:= gPlayer2
;
3902 plView1
:= gPlayer2
;
3903 plView2
:= gPlayer1
;
3907 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3909 gSpectMode
:= SPECT_NONE
;
3910 if gPlayer2
= nil then
3913 plView1
:= gPlayer2
;
3922 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3923 gSpectMode
:= SPECT_STATS
;
3925 if gSpectMode
= SPECT_PLAYERS
then
3926 if gPlayers
<> nil then
3928 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3929 if plView1
= nil then
3931 gSpectPID1
:= GetActivePlayerID_Next();
3932 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3934 if gSpectViewTwo
then
3936 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3937 if plView2
= nil then
3939 gSpectPID2
:= GetActivePlayerID_Next();
3940 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3945 if gSpectMode
= SPECT_MAPVIEW
then
3947 // Ðåæèì ïðîñìîòðà êàðòû
3949 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3950 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3951 gHearPoint1
.Active
:= True;
3952 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3953 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3954 gHearPoint2
.Active
:= False;
3958 Split
:= (plView1
<> nil) and (plView2
<> nil);
3960 // Òî÷êè ñëóõà èãðîêîâ
3961 if plView1
<> nil then
3963 gHearPoint1
.Active
:= True;
3964 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3965 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3967 gHearPoint1
.Active
:= False;
3968 if plView2
<> nil then
3970 gHearPoint2
.Active
:= True;
3971 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3972 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3974 gHearPoint2
.Active
:= False;
3976 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3977 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3980 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3981 if gScreenHeight
mod 2 = 0 then
3982 Dec(gPlayerScreenSize
.Y
);
3985 gPlayerScreenSize
.Y
:= gScreenHeight
;
3988 if gScreenHeight
mod 2 = 0 then
3989 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3991 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3993 DrawPlayer(plView1
);
3994 gPlayer1ScreenCoord
.X
:= sX
;
3995 gPlayer1ScreenCoord
.Y
:= sY
;
3999 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4001 DrawPlayer(plView2
);
4002 gPlayer2ScreenCoord
.X
:= sX
;
4003 gPlayer2ScreenCoord
.Y
:= sY
;
4006 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
4009 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
4012 {$IFDEF ENABLE_HOLMES}
4014 if (g_holmes_enabled
) then g_Holmes_Draw();
4017 if MessageText
<> '' then
4021 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
4023 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4024 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4026 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4027 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4030 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4033 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4035 // Draw spectator GUI
4038 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4041 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4043 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4045 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4047 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4048 if gSpectMode
= SPECT_STATS
then
4050 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4051 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4053 if gSpectMode
= SPECT_MAPVIEW
then
4055 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4056 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4057 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4058 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4059 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4061 if gSpectMode
= SPECT_PLAYERS
then
4063 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4064 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4065 if gSpectViewTwo
then
4067 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4068 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4069 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4070 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4074 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4075 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4081 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4083 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4084 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4086 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4087 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4088 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4093 if (gState
= STATE_MENU
) then
4095 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4096 // F3 at menu will show game loading dialog
4097 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4098 if (g_ActiveWindow
<> nil) then
4100 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4101 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4105 // F3 at titlepic will show game loading dialog
4106 if e_KeyPressed(IK_F3
) then
4108 g_Menu_Show_LoadMenu(true);
4109 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4114 if gState
= STATE_FOLD
then
4116 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4119 if gState
= STATE_INTERCUSTOM
then
4121 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4123 back
:= 'TEXTURE_endpic';
4124 if not g_Texture_Get(back
, ID
) then
4125 back
:= _lc
[I_TEXTURE_ENDPIC
];
4130 DrawMenuBackground(back
);
4134 if g_ActiveWindow
<> nil then
4136 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4137 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4141 if gState
= STATE_INTERSINGLE
then
4143 if EndingGameCounter
> 0 then
4145 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4151 DrawMenuBackground(back
);
4155 if g_ActiveWindow
<> nil then
4157 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4158 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4163 if gState
= STATE_ENDPIC
then
4166 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4167 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4169 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);
4176 if gState
= STATE_SLIST
then
4178 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4180 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4181 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4183 DrawMenuBackground('MENU_BACKGROUND');
4184 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4185 g_Serverlist_Draw(slCurrent
, slTable
);
4189 if g_ActiveWindow
<> nil then
4193 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4194 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4196 g_ActiveWindow
.Draw();
4203 if g_debug_Sounds
and gGameOn
then
4205 for w
:= 0 to High(e_SoundsArray
) do
4206 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4207 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4212 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4213 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4216 if gGameOn
and gShowTime
then
4217 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4219 if gGameOn
then drawProfilers();
4221 // TODO: draw this after the FBO and remap mouse click coordinates
4223 {$IFDEF ENABLE_HOLMES}
4227 // blit framebuffer to screen
4229 e_SetRendertarget(False);
4230 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4231 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4233 // draw the overlay stuff on top of it
4238 procedure g_Game_Quit();
4240 g_Game_StopAllSounds(True);
4243 g_PlayerModel_FreeData();
4244 g_Texture_DeleteAll();
4245 g_Frames_DeleteAll();
4247 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4250 if NetInitDone
then g_Net_Free
;
4252 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4253 if gMapToDelete
<> '' then
4254 g_Game_DeleteTestMap();
4260 procedure g_FatalError(Text: String);
4262 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4263 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4265 gExit
:= EXIT_SIMPLE
;
4266 if gGameOn
then EndGame
;
4269 procedure g_SimpleError(Text: String);
4271 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4272 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4275 procedure g_Game_SetupScreenSize();
4277 RES_FACTOR
= 4.0 / 3.0;
4283 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4284 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4285 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4286 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4288 gPlayerScreenSize
.Y
:= gScreenHeight
;
4290 // Ðàçìåð çàäíåãî ïëàíà:
4291 if BackID
<> DWORD(-1) then
4294 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4295 (gScreenHeight
*s
> gMapInfo
.Height
) then
4297 gBackSize
.X
:= gScreenWidth
;
4298 gBackSize
.Y
:= gScreenHeight
;
4302 e_GetTextureSize(BackID
, @bw
, @bh
);
4303 rf
:= Single(bw
) / Single(bh
);
4304 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4305 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4306 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4307 if (s
< 1.0) then s
:= 1.0;
4308 gBackSize
.X
:= Round(bw
*s
);
4309 gBackSize
.Y
:= Round(bh
*s
);
4314 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4316 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4319 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4321 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4322 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4325 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4328 if gPlayer1
= nil then
4330 if g_Game_IsClient
then
4332 if NetPlrUID1
> -1 then
4333 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4337 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4338 Team
:= gPlayer1Settings
.Team
;
4340 // Ñîçäàíèå ïåðâîãî èãðîêà:
4341 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4342 gPlayer1Settings
.Color
,
4344 if gPlayer1
= nil then
4345 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4348 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4349 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4350 if g_Game_IsServer
and g_Game_IsNet
then
4351 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4352 gPlayer1
.Respawn(False, True);
4353 g_Net_Slist_ServerPlayerComes();
4358 if gPlayer2
= nil then
4360 if g_Game_IsClient
then
4362 if NetPlrUID2
> -1 then
4363 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4367 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4368 Team
:= gPlayer2Settings
.Team
;
4370 // Ñîçäàíèå âòîðîãî èãðîêà:
4371 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4372 gPlayer2Settings
.Color
,
4374 if gPlayer2
= nil then
4375 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4378 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4379 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4380 if g_Game_IsServer
and g_Game_IsNet
then
4381 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4382 gPlayer2
.Respawn(False, True);
4383 g_Net_Slist_ServerPlayerComes();
4390 procedure g_Game_RemovePlayer();
4394 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4395 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4400 if g_Game_IsServer
then
4403 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4404 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4405 g_Player_Remove(Pl
.UID
);
4406 g_Net_Slist_ServerPlayerLeaves();
4410 gSpectLatchPID2
:= Pl
.UID
;
4418 if g_Game_IsServer
then
4421 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4422 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4423 g_Player_Remove(Pl
.UID
);
4424 g_Net_Slist_ServerPlayerLeaves();
4427 gSpectLatchPID1
:= Pl
.UID
;
4429 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4433 g_Net_Slist_ServerPlayerLeaves();
4436 procedure g_Game_Spectate();
4438 g_Game_RemovePlayer();
4439 if gPlayer1
<> nil then
4440 g_Game_RemovePlayer();
4443 procedure g_Game_SpectateCenterView();
4445 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4446 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4449 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4456 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4458 g_Game_ClearLoading();
4461 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4464 gGameSettings
.GameType
:= GT_SINGLE
;
4465 gGameSettings
.MaxLives
:= 0;
4466 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4467 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4468 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4469 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4470 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4471 gSwitchGameMode
:= GM_SINGLE
;
4473 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4474 gLMSRespawnTime
:= 0;
4475 gSpectLatchPID1
:= 0;
4476 gSpectLatchPID2
:= 0;
4478 g_Game_ExecuteEvent('ongamestart');
4480 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4481 g_Game_SetupScreenSize();
4483 // Ñîçäàíèå ïåðâîãî èãðîêà:
4484 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4485 gPlayer1Settings
.Color
,
4486 gPlayer1Settings
.Team
, False));
4487 if gPlayer1
= nil then
4489 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4493 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4496 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4499 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4500 gPlayer2Settings
.Color
,
4501 gPlayer2Settings
.Team
, False));
4502 if gPlayer2
= nil then
4504 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4508 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4512 // Çàãðóçêà è çàïóñê êàðòû:
4513 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4515 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4516 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4520 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4524 for i
:= nPl
+1 to nPlayers
do
4525 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4528 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4529 TimeLimit
, GoalLimit
: Word;
4531 Options
: LongWord; nPlayers
: Byte);
4537 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4539 g_Game_ClearLoading();
4542 gGameSettings
.GameType
:= GT_CUSTOM
;
4543 gGameSettings
.GameMode
:= GameMode
;
4544 gSwitchGameMode
:= GameMode
;
4545 gGameSettings
.TimeLimit
:= TimeLimit
;
4546 gGameSettings
.GoalLimit
:= GoalLimit
;
4547 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4548 gGameSettings
.Options
:= Options
;
4550 gCoopTotalMonstersKilled
:= 0;
4551 gCoopTotalSecretsFound
:= 0;
4552 gCoopTotalMonsters
:= 0;
4553 gCoopTotalSecrets
:= 0;
4557 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4558 gLMSRespawnTime
:= 0;
4559 gSpectLatchPID1
:= 0;
4560 gSpectLatchPID2
:= 0;
4562 g_Game_ExecuteEvent('ongamestart');
4564 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4565 g_Game_SetupScreenSize();
4567 // Ðåæèì íàáëþäàòåëÿ:
4568 if nPlayers
= 0 then
4575 if nPlayers
>= 1 then
4577 // Ñîçäàíèå ïåðâîãî èãðîêà:
4578 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4579 gPlayer1Settings
.Color
,
4580 gPlayer1Settings
.Team
, False));
4581 if gPlayer1
= nil then
4583 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4587 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4591 if nPlayers
>= 2 then
4593 // Ñîçäàíèå âòîðîãî èãðîêà:
4594 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4595 gPlayer2Settings
.Color
,
4596 gPlayer2Settings
.Team
, False));
4597 if gPlayer2
= nil then
4599 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4603 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4607 // Çàãðóçêà è çàïóñê êàðòû:
4608 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4610 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4614 // Íåò òî÷åê ïîÿâëåíèÿ:
4615 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4616 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4617 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4618 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4619 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4621 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4625 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4629 for i
:= nPl
+1 to nPlayers
do
4630 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4633 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4634 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4635 Options
: LongWord; nPlayers
: Byte;
4636 IPAddr
: LongWord; Port
: Word);
4639 g_Net_Slist_ServerClosed();
4641 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4643 g_Game_ClearLoading();
4646 gGameSettings
.GameType
:= GT_SERVER
;
4647 gGameSettings
.GameMode
:= GameMode
;
4648 gSwitchGameMode
:= GameMode
;
4649 gGameSettings
.TimeLimit
:= TimeLimit
;
4650 gGameSettings
.GoalLimit
:= GoalLimit
;
4651 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4652 gGameSettings
.Options
:= Options
;
4654 gCoopTotalMonstersKilled
:= 0;
4655 gCoopTotalSecretsFound
:= 0;
4656 gCoopTotalMonsters
:= 0;
4657 gCoopTotalSecrets
:= 0;
4661 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4662 gLMSRespawnTime
:= 0;
4663 gSpectLatchPID1
:= 0;
4664 gSpectLatchPID2
:= 0;
4666 g_Game_ExecuteEvent('ongamestart');
4668 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4669 g_Game_SetupScreenSize();
4671 // Ðåæèì íàáëþäàòåëÿ:
4672 if nPlayers
= 0 then
4678 if nPlayers
>= 1 then
4680 // Ñîçäàíèå ïåðâîãî èãðîêà:
4681 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4682 gPlayer1Settings
.Color
,
4683 gPlayer1Settings
.Team
, False));
4684 if gPlayer1
= nil then
4686 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4690 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4693 if nPlayers
>= 2 then
4695 // Ñîçäàíèå âòîðîãî èãðîêà:
4696 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4697 gPlayer2Settings
.Color
,
4698 gPlayer2Settings
.Team
, False));
4699 if gPlayer2
= nil then
4701 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4705 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4708 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4709 if NetForwardPorts
then
4710 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4713 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4715 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4719 g_Net_Slist_Set(NetMasterList
);
4721 g_Net_Slist_ServerStarted();
4723 // Çàãðóçêà è çàïóñê êàðòû:
4724 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4726 g_Net_Slist_ServerClosed();
4727 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4731 // Íåò òî÷åê ïîÿâëåíèÿ:
4732 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4733 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4734 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4735 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4736 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4738 g_Net_Slist_ServerClosed();
4739 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4743 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4746 g_Net_Slist_ServerMapStarted();
4747 NetState
:= NET_STATE_GAME
;
4750 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4765 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4766 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4768 g_Game_ClearLoading();
4771 gGameSettings
.GameType
:= GT_CLIENT
;
4773 gCoopTotalMonstersKilled
:= 0;
4774 gCoopTotalSecretsFound
:= 0;
4775 gCoopTotalMonsters
:= 0;
4776 gCoopTotalSecrets
:= 0;
4780 g_Game_ExecuteEvent('ongamestart');
4782 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4783 g_Game_SetupScreenSize();
4785 NetState
:= NET_STATE_AUTH
;
4787 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4789 // create (or update) map/resource databases
4790 g_Res_CreateDatabases(true);
4792 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4793 gLMSRespawnTime
:= 0;
4794 gSpectLatchPID1
:= 0;
4795 gSpectLatchPID2
:= 0;
4798 if not g_Net_Connect(Addr
, Port
) then
4800 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4801 NetState
:= NET_STATE_NONE
;
4805 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4807 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4812 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4813 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4814 // thank you, enet. let's ignore failures altogether then.
4815 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4817 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4819 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4821 // ignore all download packets, they're processed by separate code
4822 enet_packet_destroy(NetEvent
.packet
);
4825 Ptr
:= NetEvent
.packet
^.data
;
4826 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4828 enet_packet_destroy(NetEvent
.packet
);
4832 InMsg
.ReadLongWord(); // skip size
4833 MID
:= InMsg
.ReadByte();
4835 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4837 NetMyID
:= InMsg
.ReadByte();
4838 NetPlrUID1
:= InMsg
.ReadWord();
4840 WadName
:= InMsg
.ReadString();
4841 Map
:= InMsg
.ReadString();
4843 gWADHash
:= InMsg
.ReadMD5();
4845 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4846 gSwitchGameMode
:= gGameSettings
.GameMode
;
4847 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4848 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4849 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4850 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4851 T
:= InMsg
.ReadLongWord();
4853 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4854 //if newResPath = '' then
4856 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4857 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4858 if newResPath
= '' then
4860 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4861 enet_packet_destroy(NetEvent
.packet
);
4862 NetState
:= NET_STATE_NONE
;
4865 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4867 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4870 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4871 gPlayer1Settings
.Color
,
4872 gPlayer1Settings
.Team
, False));
4874 if gPlayer1
= nil then
4876 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4878 enet_packet_destroy(NetEvent
.packet
);
4879 NetState
:= NET_STATE_NONE
;
4883 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4884 gPlayer1
.UID
:= NetPlrUID1
;
4885 gPlayer1
.Reset(True);
4887 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4889 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4891 enet_packet_destroy(NetEvent
.packet
);
4892 NetState
:= NET_STATE_NONE
;
4900 enet_packet_destroy(NetEvent
.packet
);
4904 enet_packet_destroy(NetEvent
.packet
);
4908 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4911 if (NetEvent
.data
<= NET_DISC_MAX
) then
4912 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4913 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4920 ProcessLoading(true);
4922 if g_Net_UserRequestExit() then
4931 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4932 NetState
:= NET_STATE_NONE
;
4937 NetState
:= NET_STATE_GAME
;
4938 MC_SEND_FullStateRequest
;
4939 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4943 lastAsMegaWad
: Boolean = false;
4945 procedure g_Game_ChangeMap(const MapPath
: String);
4949 g_Game_ClearLoading();
4951 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4952 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4953 if gExitByTrigger
then
4956 gExitByTrigger
:= False;
4958 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4959 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4962 procedure g_Game_Restart();
4966 if g_Game_IsClient
then
4968 map
:= g_ExtractFileName(gMapInfo
.Map
);
4969 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4973 g_Game_ClearLoading();
4974 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4977 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4979 NewWAD
, ResName
: String;
4983 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4984 g_Player_RemoveAllCorpses();
4986 if (not g_Game_IsClient
) and
4987 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4988 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4990 if gSwitchGameMode
= GM_CTF
then
4991 gGameSettings
.MaxLives
:= 0;
4992 gGameSettings
.GameMode
:= gSwitchGameMode
;
4995 gSwitchGameMode
:= gGameSettings
.GameMode
;
4997 g_Player_ResetTeams();
4999 lastAsMegaWad
:= asMegawad
;
5000 if isWadPath(Map
) then
5002 NewWAD
:= g_ExtractWadName(Map
);
5003 ResName
:= g_ExtractFileName(Map
);
5004 if g_Game_IsServer
then
5006 nws
:= findDiskWad(NewWAD
);
5007 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5010 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5011 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5015 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5016 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5018 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5019 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5021 if (length(nws
) = 0) then
5023 ResName
:= ''; // failed
5028 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5029 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5030 g_Game_LoadWAD(NewWAD
);
5035 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5036 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5041 NewWAD
:= gGameSettings
.WAD
;
5047 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5049 if (ResName
<> '') and (NewWAD
<> '') then
5051 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5052 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5056 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5058 gState
:= STATE_NONE
;
5059 g_ActiveWindow
:= nil;
5065 if gGameSettings
.GameMode
= GM_CTF
then
5067 g_Map_ResetFlag(FLAG_RED
);
5068 g_Map_ResetFlag(FLAG_BLUE
);
5069 // CTF, à ôëàãîâ íåò:
5070 if not g_Map_HaveFlagPoints() then
5071 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5076 gState
:= STATE_MENU
;
5081 gPauseMain
:= false;
5082 gPauseHolmes
:= false;
5083 NetTimeToUpdate
:= 1;
5084 NetTimeToReliable
:= 0;
5085 NetTimeToMaster
:= NetMasterRate
;
5086 gSpectLatchPID1
:= 0;
5087 gSpectLatchPID2
:= 0;
5088 gMissionFailed
:= False;
5091 gCoopMonstersKilled
:= 0;
5092 gCoopSecretsFound
:= 0;
5094 gVoteInProgress
:= False;
5095 gVotePassed
:= False;
5101 if not gGameOn
then Exit
;
5103 g_Game_SpectateCenterView();
5105 if g_Game_IsServer
then
5107 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5109 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5110 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5111 gLMSSoftSpawn
:= True;
5112 if g_Game_IsNet
then
5113 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5117 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5118 gLMSRespawnTime
:= 0;
5122 if NetMode
= NET_SERVER
then
5124 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5127 g_Net_Slist_ServerMapStarted();
5129 if NetClients
<> nil then
5130 for I
:= 0 to High(NetClients
) do
5131 if NetClients
[I
].Used
then
5133 NetClients
[I
].Voted
:= False;
5134 if NetClients
[I
].RequestedFullUpdate
then
5136 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5137 NetClients
[I
].RequestedFullUpdate
:= False;
5141 g_Net_UnbanNonPermHosts();
5146 gCoopTotalMonstersKilled
:= 0;
5147 gCoopTotalSecretsFound
:= 0;
5148 gCoopTotalMonsters
:= 0;
5149 gCoopTotalSecrets
:= 0;
5153 g_Game_ExecuteEvent('onmapstart');
5156 procedure SetFirstLevel
;
5160 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5161 if MapList
= nil then
5164 SortSArray(MapList
);
5165 gNextMap
:= MapList
[Low(MapList
)];
5170 procedure g_Game_ExitLevel(const Map
: AnsiString);
5174 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5175 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5176 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5177 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5179 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5180 if gGameSettings
.GameType
= GT_SINGLE
then
5181 gExit
:= EXIT_ENDLEVELSINGLE
5182 else // Âûøëè â âûõîä â Ñâîåé èãðå
5184 gExit
:= EXIT_ENDLEVELCUSTOM
;
5185 if gGameSettings
.GameMode
= GM_COOP
then
5186 g_Player_RememberAll
;
5188 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5191 if gGameSettings
.GameMode
= GM_COOP
then
5194 gStatsPressed
:= True;
5195 gNextMap
:= 'MAP01';
5197 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5200 if g_Game_IsNet
then
5202 MH_SEND_GameStats();
5203 MH_SEND_CoopStats();
5209 procedure g_Game_RestartLevel();
5213 if gGameSettings
.GameMode
= GM_SINGLE
then
5218 gExit
:= EXIT_ENDLEVELCUSTOM
;
5219 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5223 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5225 gWAD
{, xwad}: String;
5228 if not g_Game_IsClient
then Exit
;
5229 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5231 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5236 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5240 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5243 g_Game_LoadWAD(NewWAD
);
5247 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5248 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5251 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5252 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5256 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5260 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5261 g_Game_LoadWAD(NewWAD);
5265 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5267 i
, n
, nb
, nr
: Integer;
5269 if not g_Game_IsServer
then Exit
;
5270 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5271 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5272 gLMSRespawnTime
:= 0;
5275 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5277 gMissionFailed
:= True;
5278 g_Game_RestartLevel
;
5282 n
:= 0; nb
:= 0; nr
:= 0;
5283 for i
:= Low(gPlayers
) to High(gPlayers
) do
5284 if (gPlayers
[i
] <> nil) and
5285 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5286 (gPlayers
[i
] is TBot
)) then
5289 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5290 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5293 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5295 // wait a second until the fuckers finally decide to join
5296 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5297 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5298 gLMSSoftSpawn
:= NoMapRestart
;
5299 if g_Game_IsNet
then
5300 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5304 g_Player_RemoveAllCorpses
;
5305 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5306 if g_Game_IsNet
then
5307 MH_SEND_GameEvent(NET_EV_LMS_START
);
5309 for i
:= Low(gPlayers
) to High(gPlayers
) do
5311 if gPlayers
[i
] = nil then continue
;
5312 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5313 // don't touch normal spectators
5314 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5316 gPlayers
[i
].FNoRespawn
:= True;
5317 gPlayers
[i
].Lives
:= 0;
5318 if g_Game_IsNet
then
5319 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5322 gPlayers
[i
].FNoRespawn
:= False;
5323 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5324 gPlayers
[i
].Respawn(False, True);
5325 if gGameSettings
.GameMode
= GM_COOP
then
5327 gPlayers
[i
].Frags
:= 0;
5328 gPlayers
[i
].RecallState
;
5330 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5331 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5332 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5333 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5336 g_Items_RestartRound();
5338 gLMSSoftSpawn
:= False;
5341 function g_Game_GetFirstMap(WAD
: String): String;
5345 MapList
:= g_Map_GetMapsList(WAD
);
5346 if MapList
= nil then
5349 SortSArray(MapList
);
5350 Result
:= MapList
[Low(MapList
)];
5352 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5358 function g_Game_GetNextMap(): String;
5365 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5366 if MapList
= nil then
5369 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5371 SortSArray(MapList
);
5373 for I
:= Low(MapList
) to High(MapList
) do
5374 if Map
= MapList
[I
] then
5380 if MapIndex
<> -255 then
5382 if MapIndex
= High(MapList
) then
5383 Result
:= MapList
[Low(MapList
)]
5385 Result
:= MapList
[MapIndex
+ 1];
5387 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5393 procedure g_Game_NextLevel();
5395 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5396 gExit
:= EXIT_ENDLEVELCUSTOM
5399 gExit
:= EXIT_ENDLEVELSINGLE
;
5403 if gNextMap
<> '' then Exit
;
5404 gNextMap
:= g_Game_GetNextMap();
5407 function g_Game_IsTestMap(): Boolean;
5409 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5412 procedure g_Game_DeleteTestMap();
5415 //MapName: AnsiString;
5423 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5424 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5425 if (a
= 0) then exit
;
5427 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5428 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5429 Delete(gMapToDelete
, 1, a
+5);
5430 gMapToDelete
:= UpperCase(gMapToDelete
);
5432 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5435 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5436 if MapName <> TEST_MAP_NAME then
5439 if not gTempDelete then
5441 time := g_GetFileTime(WadName);
5442 WAD := TWADFile.Create();
5445 if not WAD.ReadFile(WadName) then
5446 begin // Íåò òàêîãî WAD-ôàéëà
5451 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5453 MapList := WAD.GetResourcesList('');
5455 if MapList <> nil then
5456 for a := 0 to High(MapList) do
5457 if MapList[a] = MapName then
5459 // Óäàëÿåì è ñîõðàíÿåì:
5460 WAD.RemoveResource('', MapName);
5461 WAD.SaveTo(WadName);
5466 g_SetFileTime(WadName, time);
5469 if gTempDelete
then DeleteFile(WadName
);
5472 procedure GameCVars(P
: SSArray
);
5475 stat
: TPlayerStatArray
;
5478 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5482 if Length(P
) > 1 then
5487 gsGameFlags
:= gsGameFlags
or Flag
5489 gsGameFlags
:= gsGameFlags
and (not Flag
);
5491 if g_Game_IsServer
then
5494 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5496 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5497 if g_Game_IsNet
then MH_SEND_GameSettings
;
5501 if LongBool(gsGameFlags
and Flag
) then
5502 g_Console_Add(_lc
[OnMsg
])
5504 g_Console_Add(_lc
[OffMsg
]);
5506 if OnMapChange
and g_Game_IsServer
then
5507 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5512 cmd
:= LowerCase(P
[0]);
5514 if cmd
= 'g_gamemode' then
5516 if (Length(P
) > 1) then
5518 a
:= g_Game_TextToMode(P
[1]);
5519 if a
= GM_SINGLE
then a
:= GM_COOP
;
5520 gsGameMode
:= g_Game_ModeToText(a
);
5521 if g_Game_IsServer
then
5523 gSwitchGameMode
:= a
;
5524 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5525 (gState
= STATE_INTERSINGLE
) then
5526 gSwitchGameMode
:= GM_SINGLE
;
5528 gGameSettings
.GameMode
:= gSwitchGameMode
;
5532 if gSwitchGameMode
= gGameSettings
.GameMode
then
5533 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5534 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5536 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5537 [g_Game_ModeToText(gGameSettings
.GameMode
),
5538 g_Game_ModeToText(gSwitchGameMode
)]));
5540 else if cmd
= 'g_friendlyfire' then
5542 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5544 else if cmd
= 'g_friendly_absorb_damage' then
5546 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5548 else if cmd
= 'g_friendly_hit_trace' then
5550 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5552 else if cmd
= 'g_friendly_hit_projectile' then
5554 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5556 else if cmd
= 'g_weaponstay' then
5558 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5560 else if cmd
= 'g_allow_exit' then
5562 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5564 else if cmd
= 'g_allow_monsters' then
5566 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5568 else if cmd
= 'g_allow_dropflag' then
5570 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5572 else if cmd
= 'g_throw_flag' then
5574 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5576 else if cmd
= 'g_bot_vsplayers' then
5578 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5580 else if cmd
= 'g_bot_vsmonsters' then
5582 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5584 else if cmd
= 'g_dm_keys' then
5586 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5588 else if cmd
= 'g_gameflags' then
5590 if Length(P
) > 1 then
5592 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5593 if g_Game_IsServer
then
5595 gGameSettings
.Options
:= gsGameFlags
;
5596 if g_Game_IsNet
then MH_SEND_GameSettings
;
5600 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5602 else if cmd
= 'g_warmup_time' then
5604 if Length(P
) > 1 then
5606 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5607 if g_Game_IsServer
then
5609 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5610 // extend warmup if it's already going
5611 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5613 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5614 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5616 if g_Game_IsNet
then MH_SEND_GameSettings
;
5620 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5621 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5623 else if cmd
= 'g_spawn_invul' then
5625 if Length(P
) > 1 then
5627 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5628 if g_Game_IsServer
then
5630 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5631 if g_Game_IsNet
then MH_SEND_GameSettings
;
5635 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5637 else if cmd
= 'g_item_respawn_time' then
5639 if Length(P
) > 1 then
5641 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5642 if g_Game_IsServer
then
5644 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5645 if g_Game_IsNet
then MH_SEND_GameSettings
;
5649 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5650 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5652 else if cmd
= 'sv_intertime' then
5654 if (Length(P
) > 1) then
5655 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5657 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5659 else if cmd
= 'g_max_particles' then
5661 if Length(p
) = 2 then
5663 a
:= Max(0, StrToInt(p
[1]));
5666 else if Length(p
) = 1 then
5668 e_LogWritefln('%s', [g_GFX_GetMax()])
5672 e_LogWritefln('usage: %s <n>', [cmd
])
5675 else if cmd
= 'g_max_shells' then
5677 if Length(p
) = 2 then
5679 a
:= Max(0, StrToInt(p
[1]));
5682 else if Length(p
) = 1 then
5684 e_LogWritefln('%s', [g_Shells_GetMax()])
5688 e_LogWritefln('usage: %s <n>', [cmd
])
5691 else if cmd
= 'g_max_gibs' then
5693 if Length(p
) = 2 then
5695 a
:= Max(0, StrToInt(p
[1]));
5698 else if Length(p
) = 1 then
5700 e_LogWritefln('%s', [g_Gibs_GetMax()])
5704 e_LogWritefln('usage: %s <n>', [cmd
])
5707 else if cmd
= 'g_max_corpses' then
5709 if Length(p
) = 2 then
5711 a
:= Max(0, StrToInt(p
[1]));
5714 else if Length(p
) = 1 then
5716 e_LogWritefln('%s', [g_Corpses_GetMax()])
5720 e_LogWritefln('usage: %s <n>', [cmd
])
5723 else if cmd
= 'g_scorelimit' then
5725 if Length(P
) > 1 then
5727 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5729 if g_Game_IsServer
then
5732 if gGameSettings
.GameMode
= GM_DM
then
5734 stat
:= g_Player_GetStats();
5736 for a
:= 0 to High(stat
) do
5737 if stat
[a
].Frags
> b
then
5741 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5743 // if someone has a higher score, set it to that instead
5744 gsGoalLimit
:= max(gsGoalLimit
, b
);
5745 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5747 if g_Game_IsNet
then MH_SEND_GameSettings
;
5751 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5753 else if cmd
= 'g_timelimit' then
5755 if Length(P
) > 1 then
5757 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5758 if g_Game_IsServer
then
5760 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5761 if g_Game_IsNet
then MH_SEND_GameSettings
;
5764 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5765 [gsTimeLimit
div 3600,
5766 (gsTimeLimit
div 60) mod 60,
5767 gsTimeLimit
mod 60]));
5769 else if cmd
= 'g_maxlives' then
5771 if Length(P
) > 1 then
5773 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5774 if g_Game_IsServer
then
5776 gGameSettings
.MaxLives
:= gsMaxLives
;
5777 if g_Game_IsNet
then MH_SEND_GameSettings
;
5781 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5785 procedure PlayerSettingsCVars(P
: SSArray
);
5790 function ParseTeam(s
: string): Byte;
5794 'red', '1': result
:= TEAM_RED
;
5795 'blue', '2': result
:= TEAM_BLUE
;
5796 else result
:= TEAM_NONE
;
5800 cmd
:= LowerCase(P
[0]);
5804 if (Length(P
) > 1) then
5806 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5807 if g_Game_IsClient
then
5808 MC_SEND_PlayerSettings
5809 else if gGameOn
and (gPlayer1
<> nil) then
5811 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5812 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5818 if (Length(P
) > 1) then
5820 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5821 if g_Game_IsClient
then
5822 MC_SEND_PlayerSettings
5823 else if gGameOn
and (gPlayer2
<> nil) then
5825 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5826 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5832 if Length(P
) > 3 then
5834 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5835 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5836 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5837 if g_Game_IsClient
then
5838 MC_SEND_PlayerSettings
5839 else if gGameOn
and (gPlayer1
<> nil) then
5841 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5842 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5848 if Length(P
) > 3 then
5850 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5851 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5852 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5853 if g_Game_IsClient
then
5854 MC_SEND_PlayerSettings
5855 else if gGameOn
and (gPlayer2
<> nil) then
5857 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5858 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5864 if (Length(P
) > 1) then
5866 gPlayer1Settings
.Model
:= P
[1];
5867 if g_Game_IsClient
then
5868 MC_SEND_PlayerSettings
5869 else if gGameOn
and (gPlayer1
<> nil) then
5871 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5872 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5873 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5879 if (Length(P
) > 1) then
5881 gPlayer2Settings
.Model
:= P
[1];
5882 if g_Game_IsClient
then
5883 MC_SEND_PlayerSettings
5884 else if gGameOn
and (gPlayer2
<> nil) then
5886 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5887 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5888 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5894 // TODO: switch teams if in game or store this separately
5895 if (Length(P
) > 1) then
5897 team
:= ParseTeam(P
[1]);
5898 if team
= TEAM_NONE
then
5899 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5900 else if not gGameOn
and not g_Game_IsNet
then
5901 gPlayer1Settings
.Team
:= team
5903 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5908 // TODO: switch teams if in game or store this separately
5909 if (Length(P
) > 1) then
5911 team
:= ParseTeam(P
[1]);
5912 if team
= TEAM_NONE
then
5913 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5914 else if not gGameOn
and not g_Game_IsNet
then
5915 gPlayer2Settings
.Team
:= team
5917 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5923 procedure PrintHeapStats();
5927 hs
:= GetFPCHeapStatus();
5928 e_LogWriteLn ('v===== heap status =====v');
5929 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5930 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5931 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5932 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5933 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5934 e_LogWriteLn ('^=======================^');
5937 procedure DebugCommands(P
: SSArray
);
5944 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5945 if {gDebugMode}conIsCheatsEnabled
then
5947 cmd
:= LowerCase(P
[0]);
5948 if cmd
= 'd_window' then
5950 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5951 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5953 else if cmd
= 'd_sounds' then
5955 if (Length(P
) > 1) and
5956 ((P
[1] = '1') or (P
[1] = '0')) then
5957 g_Debug_Sounds
:= (P
[1][1] = '1');
5959 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5961 else if cmd
= 'd_frames' then
5963 if (Length(P
) > 1) and
5964 ((P
[1] = '1') or (P
[1] = '0')) then
5965 g_Debug_Frames
:= (P
[1][1] = '1');
5967 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5969 else if cmd
= 'd_winmsg' then
5971 if (Length(P
) > 1) and
5972 ((P
[1] = '1') or (P
[1] = '0')) then
5973 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5975 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5977 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5979 if (Length(P
) > 1) and
5980 ((P
[1] = '1') or (P
[1] = '0')) then
5981 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5983 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5985 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5987 if Length(P
) > 1 then
5989 '0': g_debug_BotAIOff
:= 0;
5990 '1': g_debug_BotAIOff
:= 1;
5991 '2': g_debug_BotAIOff
:= 2;
5992 '3': g_debug_BotAIOff
:= 3;
5995 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5997 else if cmd
= 'd_monster' then
5999 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6000 if Length(P
) < 2 then
6002 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6003 g_Console_Add('ID | Name');
6004 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6005 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6006 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6009 a
:= StrToIntDef(P
[1], 0);
6010 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6011 a
:= g_Mons_TypeIdByName(P
[1]);
6013 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6014 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6017 with gPlayer1
.Obj
do
6019 mon
:= g_Monsters_Create(a
,
6020 X
+ Rect
.X
+ (Rect
.Width
div 2),
6021 Y
+ Rect
.Y
+ Rect
.Height
,
6022 gPlayer1
.Direction
, True);
6024 if (Length(P
) > 2) and (mon
<> nil) then
6026 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6027 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6028 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6029 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6030 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6031 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6032 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6033 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6034 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6039 else if (cmd
= 'd_health') then
6041 if (Length(P
) > 1) and
6042 ((P
[1] = '1') or (P
[1] = '0')) then
6043 g_debug_HealthBar
:= (P
[1][1] = '1');
6045 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6047 else if (cmd
= 'd_player') then
6049 if (Length(P
) > 1) and
6050 ((P
[1] = '1') or (P
[1] = '0')) then
6051 g_debug_Player
:= (P
[1][1] = '1');
6053 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6055 else if (cmd
= 'd_mem') then
6061 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6065 procedure GameCheats(P
: SSArray
);
6071 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6073 g_Console_Add('not available');
6079 g_Console_Add('where is the player?!');
6082 cmd
:= LowerCase(P
[0]);
6086 plr
.GodMode
:= not plr
.GodMode
;
6087 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6090 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6091 if cmd
= 'give' then
6093 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6094 for f
:= 1 to High(P
) do
6096 cmd
:= LowerCase(P
[f
]);
6097 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6098 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6099 if cmd
= 'exit' then
6101 if gTriggers
<> nil then
6103 for a
:= 0 to High(gTriggers
) do
6105 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6107 g_Console_Add('player left the map');
6108 gExitByTrigger
:= True;
6109 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6110 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6118 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6119 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6120 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6121 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6122 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6124 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6125 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6127 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6128 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;
6130 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6131 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6133 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6134 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6136 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6137 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6139 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6140 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6141 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6143 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6144 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6145 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6146 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;
6147 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6148 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6150 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;
6151 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;
6152 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;
6153 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;
6154 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;
6155 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;
6157 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6158 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;
6160 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;
6161 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;
6163 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6165 if cmd
= 'ammo' then
6167 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6168 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6169 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6170 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6171 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6172 g_Console_Add('player got some ammo');
6176 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6177 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6179 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6180 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6182 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6183 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6185 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6186 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6188 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6190 if cmd
= 'weapons' then
6192 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6193 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6194 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6195 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6196 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6197 plr
.GiveItem(ITEM_WEAPON_BFG
);
6198 g_Console_Add('player got weapons');
6202 if cmd
= 'keys' then
6204 plr
.GiveItem(ITEM_KEY_RED
);
6205 plr
.GiveItem(ITEM_KEY_GREEN
);
6206 plr
.GiveItem(ITEM_KEY_BLUE
);
6207 g_Console_Add('player got all keys');
6211 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6216 if cmd
= 'open' then
6218 g_Console_Add('player activated sesame');
6219 g_Triggers_OpenAll();
6226 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6230 if cmd
= 'noclip' then
6233 g_Console_Add('wall hardeness adjusted');
6237 if cmd
= 'notarget' then
6239 plr
.NoTarget
:= not plr
.NoTarget
;
6240 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6244 if cmd
= 'noreload' then
6246 plr
.NoReload
:= not plr
.NoReload
;
6247 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6251 if cmd
= 'speedy' then
6253 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6254 g_Console_Add('speed adjusted');
6258 if cmd
= 'jumpy' then
6260 VEL_JUMP
:= 30-VEL_JUMP
;
6261 g_Console_Add('jump height adjusted');
6265 if cmd
= 'automap' then
6267 gShowMap
:= not gShowMap
;
6268 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6272 if cmd
= 'aimline' then
6274 gAimLine
:= not gAimLine
;
6275 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6280 procedure GameCommands(P
: SSArray
);
6286 pl
: pTNetClient
= nil;
6294 cmd
:= LowerCase(P
[0]);
6296 if cmd
= 'pause' then
6298 if (g_ActiveWindow
= nil) then
6299 g_Game_Pause(not gPauseMain
);
6301 else if cmd
= 'endgame' then
6302 gExit
:= EXIT_SIMPLE
6303 else if cmd
= 'restart' then
6305 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6307 if g_Game_IsClient
then
6309 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6314 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6316 else if cmd
= 'kick' then
6318 if g_Game_IsServer
then
6320 if Length(P
) < 2 then
6322 g_Console_Add('kick <name>');
6327 g_Console_Add('kick <name>');
6331 if g_Game_IsNet
then
6332 pl
:= g_Net_Client_ByName(P
[1]);
6335 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6336 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6337 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6338 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6339 g_Net_Slist_ServerPlayerLeaves();
6340 end else if gPlayers
<> nil then
6341 for a
:= Low(gPlayers
) to High(gPlayers
) do
6342 if gPlayers
[a
] <> nil then
6343 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6345 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6346 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6348 gPlayers
[a
].Lives
:= 0;
6349 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6350 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6351 g_Player_Remove(gPlayers
[a
].UID
);
6352 g_Net_Slist_ServerPlayerLeaves();
6353 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6357 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6359 else if cmd
= 'kick_id' then
6361 if g_Game_IsServer
and g_Game_IsNet
then
6363 if Length(P
) < 2 then
6365 g_Console_Add('kick_id <client ID>');
6370 g_Console_Add('kick_id <client ID>');
6374 a
:= StrToIntDef(P
[1], 0);
6375 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6377 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6379 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6380 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6381 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6382 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6383 g_Net_Slist_ServerPlayerLeaves();
6387 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6389 else if cmd
= 'kick_pid' then
6391 if g_Game_IsServer
and g_Game_IsNet
then
6393 if Length(P
) < 2 then
6395 g_Console_Add('kick_pid <player ID>');
6400 g_Console_Add('kick_pid <player ID>');
6404 a
:= StrToIntDef(P
[1], 0);
6405 pl
:= g_Net_Client_ByPlayer(a
);
6406 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6408 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6409 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6410 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6411 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6412 g_Net_Slist_ServerPlayerLeaves();
6415 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6417 else if cmd
= 'ban' then
6419 if g_Game_IsServer
and g_Game_IsNet
then
6421 if Length(P
) < 2 then
6423 g_Console_Add('ban <name>');
6428 g_Console_Add('ban <name>');
6432 pl
:= g_Net_Client_ByName(P
[1]);
6435 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6436 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6437 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6438 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6439 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6440 g_Net_Slist_ServerPlayerLeaves();
6442 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6444 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6446 else if cmd
= 'ban_id' then
6448 if g_Game_IsServer
and g_Game_IsNet
then
6450 if Length(P
) < 2 then
6452 g_Console_Add('ban_id <client ID>');
6457 g_Console_Add('ban_id <client ID>');
6461 a
:= StrToIntDef(P
[1], 0);
6462 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6463 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6465 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6466 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6467 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6468 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6469 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6470 g_Net_Slist_ServerPlayerLeaves();
6473 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6475 else if cmd
= 'ban_pid' then
6477 if g_Game_IsServer
and g_Game_IsNet
then
6479 if Length(P
) < 2 then
6481 g_Console_Add('ban_pid <player ID>');
6486 g_Console_Add('ban_pid <player ID>');
6490 a
:= StrToIntDef(P
[1], 0);
6491 pl
:= g_Net_Client_ByPlayer(a
);
6492 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6494 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6495 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6496 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6497 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6498 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6499 g_Net_Slist_ServerPlayerLeaves();
6502 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6504 else if cmd
= 'permban' then
6506 if g_Game_IsServer
and g_Game_IsNet
then
6508 if Length(P
) < 2 then
6510 g_Console_Add('permban <name>');
6515 g_Console_Add('permban <name>');
6519 pl
:= g_Net_Client_ByName(P
[1]);
6522 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6523 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6524 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6525 g_Net_SaveBanList();
6526 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6527 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6528 g_Net_Slist_ServerPlayerLeaves();
6530 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6532 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6534 else if cmd
= 'permban_id' then
6536 if g_Game_IsServer
and g_Game_IsNet
then
6538 if Length(P
) < 2 then
6540 g_Console_Add('permban_id <client ID>');
6545 g_Console_Add('permban_id <client ID>');
6549 a
:= StrToIntDef(P
[1], 0);
6550 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6551 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6553 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6554 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6555 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6556 g_Net_SaveBanList();
6557 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6558 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6559 g_Net_Slist_ServerPlayerLeaves();
6562 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6564 else if cmd
= 'permban_pid' then
6566 if g_Game_IsServer
and g_Game_IsNet
then
6568 if Length(P
) < 2 then
6570 g_Console_Add('permban_pid <player ID>');
6575 g_Console_Add('permban_pid <player ID>');
6579 a
:= StrToIntDef(P
[1], 0);
6580 pl
:= g_Net_Client_ByPlayer(a
);
6581 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6583 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6584 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6585 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6586 g_Net_SaveBanList();
6587 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6588 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6589 g_Net_Slist_ServerPlayerLeaves();
6592 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6594 else if cmd
= 'permban_ip' then
6596 if g_Game_IsServer
and g_Game_IsNet
then
6598 if Length(P
) < 2 then
6600 g_Console_Add('permban_ip <IP address>');
6605 g_Console_Add('permban_ip <IP address>');
6609 g_Net_BanHost(P
[1]);
6610 g_Net_SaveBanList();
6611 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6613 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6615 else if cmd
= 'unban' then
6617 if g_Game_IsServer
and g_Game_IsNet
then
6619 if Length(P
) < 2 then
6621 g_Console_Add('unban <IP Address>');
6626 g_Console_Add('unban <IP Address>');
6630 if g_Net_UnbanHost(P
[1]) then
6632 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6633 g_Net_SaveBanList();
6635 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6637 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6639 else if cmd
= 'clientlist' then
6641 if g_Game_IsServer
and g_Game_IsNet
then
6644 if NetClients
<> nil then
6645 for a
:= Low(NetClients
) to High(NetClients
) do
6646 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6648 plr
:= g_Player_Get(NetClients
[a
].Player
);
6649 if plr
= nil then continue
;
6651 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6652 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6655 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6657 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6659 else if cmd
= 'connect' then
6661 if (NetMode
= NET_NONE
) then
6663 if Length(P
) < 2 then
6665 g_Console_Add('connect <IP> [port] [password]');
6670 g_Console_Add('connect <IP> [port] [password]');
6674 if Length(P
) > 2 then
6675 prt
:= StrToIntDef(P
[2], 25666)
6679 if Length(P
) > 3 then
6684 g_Game_StartClient(P
[1], prt
, pw
);
6687 else if cmd
= 'disconnect' then
6689 if (NetMode
= NET_CLIENT
) then
6692 else if cmd
= 'reconnect' then
6694 if (NetMode
= NET_SERVER
) then
6697 if (NetMode
= NET_CLIENT
) then
6700 gExit
:= EXIT_SIMPLE
;
6704 //TODO: Use last successful password to reconnect, instead of ''
6705 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6707 else if (cmd
= 'addbot') or
6708 (cmd
= 'bot_add') then
6710 if Length(P
) > 2 then
6711 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6712 else if Length(P
) > 1 then
6713 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6715 g_Bot_Add(TEAM_NONE
, 2);
6717 else if cmd
= 'bot_addlist' then
6719 if Length(P
) > 1 then
6721 if Length(P
) = 2 then
6722 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6723 else if Length(P
) = 3 then
6724 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6726 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6729 else if cmd
= 'bot_removeall' then
6731 else if cmd
= 'chat' then
6733 if g_Game_IsNet
then
6735 if Length(P
) > 1 then
6737 for a
:= 1 to High(P
) do
6738 chstr
:= chstr
+ P
[a
] + ' ';
6740 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6742 if Length(chstr
) < 1 then
6744 g_Console_Add('chat <text>');
6748 chstr
:= b_Text_Format(chstr
);
6749 if g_Game_IsClient
then
6750 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6752 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6755 g_Console_Add('chat <text>');
6757 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6759 else if cmd
= 'teamchat' then
6761 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6763 if Length(P
) > 1 then
6765 for a
:= 1 to High(P
) do
6766 chstr
:= chstr
+ P
[a
] + ' ';
6768 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6770 if Length(chstr
) < 1 then
6772 g_Console_Add('teamchat <text>');
6776 chstr
:= b_Text_Format(chstr
);
6777 if g_Game_IsClient
then
6778 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6780 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6781 gPlayer1Settings
.Team
);
6784 g_Console_Add('teamchat <text>');
6786 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6788 else if cmd
= 'game' then
6790 if gGameSettings
.GameType
<> GT_NONE
then
6792 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6795 if Length(P
) = 1 then
6797 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6800 // game not started yet, load fist map from some wad
6802 s
:= addWadExtension(P
[1]);
6803 found
:= e_FindResource(AllMapDirs
, s
);
6807 P
[1] := ExpandFileName(P
[1]);
6808 // if map not choosed then set first map
6809 if Length(P
) < 3 then
6812 P
[2] := g_Game_GetFirstMap(P
[1]);
6815 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6817 if g_Map_Exist(s
) then
6821 with gGameSettings
do
6823 Options
:= gsGameFlags
;
6824 GameMode
:= g_Game_TextToMode(gsGameMode
);
6825 if gSwitchGameMode
<> GM_NONE
then
6826 GameMode
:= gSwitchGameMode
;
6827 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6828 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6830 if Length(P
) >= 4 then
6831 b
:= StrToIntDef(P
[3], 1);
6832 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6833 GoalLimit
, MaxLives
, Options
, b
);
6838 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6840 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6842 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6844 else if cmd
= 'host' then
6846 if gGameSettings
.GameType
<> GT_NONE
then
6848 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6851 if Length(P
) < 4 then
6853 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6856 if not StrToIp(P
[1], listen
) then
6858 prt
:= StrToIntDef(P
[2], 25666);
6860 s
:= addWadExtension(P
[3]);
6861 found
:= e_FindResource(AllMapDirs
, s
);
6865 // get first map in wad, if not specified
6866 if Length(P
) < 5 then
6869 P
[4] := g_Game_GetFirstMap(P
[1]);
6871 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6872 if g_Map_Exist(s
) then
6876 with gGameSettings
do
6878 Options
:= gsGameFlags
;
6879 GameMode
:= g_Game_TextToMode(gsGameMode
);
6880 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6881 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6882 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6884 if Length(P
) >= 6 then
6885 b
:= StrToIntDef(P
[5], 0);
6886 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6892 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6894 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6899 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6902 else if cmd
= 'map' then
6904 if Length(P
) = 1 then
6906 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6908 g_Console_Add(cmd
+ ' <MAP>');
6909 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6913 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6918 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6920 if Length(P
) < 3 then
6922 // first param is map or wad
6923 s
:= UpperCase(P
[1]);
6924 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6926 gExitByTrigger
:= False;
6929 // already in game, finish current map
6931 gExit
:= EXIT_ENDLEVELCUSTOM
;
6935 // intermission, so change map immediately
6942 found
:= e_FindResource(AllMapDirs
, s
);
6944 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6947 // no such map, found wad
6950 P
[1] := ExpandFileName(pw
);
6951 P
[2] := g_Game_GetFirstMap(P
[1]);
6952 s
:= P
[1] + ':\' + P
[2];
6953 if g_Map_Exist(s
) then
6955 gExitByTrigger
:= False;
6958 // already in game, finish current map
6960 gExit
:= EXIT_ENDLEVELCUSTOM
6964 // intermission, so change map immediately
6971 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6973 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6978 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6984 s
:= addWadExtension(P
[1]);
6985 found
:= e_FindResource(AllMapDirs
, s
);
6989 P
[2] := UpperCase(P
[2]);
6990 s
:= P
[1] + ':\' + P
[2];
6991 if g_Map_Exist(s
) then
6993 gExitByTrigger
:= False;
6997 gExit
:= EXIT_ENDLEVELCUSTOM
7006 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7011 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7017 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7021 else if cmd
= 'nextmap' then
7023 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7025 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7030 if Length(P
) = 1 then
7032 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7034 g_Console_Add(cmd
+ ' <MAP>');
7035 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7040 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7046 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7048 if Length(P
) < 3 then
7050 // first param is map or wad
7051 s
:= UpperCase(P
[1]);
7052 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7055 gExitByTrigger
:= False;
7061 // no such map, found wad
7062 pw
:= addWadExtension(P
[1]);
7063 found
:= e_FindResource(MapDirs
, pw
);
7065 found
:= e_FindResource(WadDirs
, pw
);
7067 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7070 // map not specified, select first map
7072 P
[2] := g_Game_GetFirstMap(P
[1]);
7073 s
:= P
[1] + ':\' + P
[2];
7074 if g_Map_Exist(s
) then
7076 gExitByTrigger
:= False;
7083 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7085 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7090 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7096 // specified two params wad + map
7097 pw
:= addWadExtension(P
[1]);
7098 found
:= e_FindResource(MapDirs
, pw
);
7100 found
:= e_FindResource(MapDirs
, pw
);
7104 P
[2] := UpperCase(P
[2]);
7105 s
:= P
[1] + ':\' + P
[2];
7106 if g_Map_Exist(s
) then
7108 gExitByTrigger
:= False;
7114 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7119 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7125 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7130 if gNextMap
= '' then
7131 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7133 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7137 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7141 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7145 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7147 gExitByTrigger
:= False;
7148 // next map not specified, try to find trigger EXIT
7149 if (gNextMap
= '') and (gTriggers
<> nil) then
7151 for a
:= 0 to High(gTriggers
) do
7153 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7155 gExitByTrigger
:= True;
7156 //gNextMap := gTriggers[a].Data.MapName;
7157 gNextMap
:= gTriggers
[a
].tgcMap
;
7162 if gNextMap
= '' then
7163 gNextMap
:= g_Game_GetNextMap();
7164 if not isWadPath(gNextMap
) then
7165 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7168 if g_Map_Exist(s
) then
7169 gExit
:= EXIT_ENDLEVELCUSTOM
7171 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7175 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7179 else if (cmd
= 'event') then
7181 if (Length(P
) <= 1) then
7183 for a
:= 0 to High(gEvents
) do
7184 if gEvents
[a
].Command
= '' then
7185 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7187 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7190 if (Length(P
) = 2) then
7192 for a
:= 0 to High(gEvents
) do
7193 if gEvents
[a
].Name
= P
[1] then
7194 if gEvents
[a
].Command
= '' then
7195 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7197 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7200 for a
:= 0 to High(gEvents
) do
7201 if gEvents
[a
].Name
= P
[1] then
7203 gEvents
[a
].Command
:= '';
7204 for b
:= 2 to High(P
) do
7205 if Pos(' ', P
[b
]) = 0 then
7206 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7208 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7209 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7213 else if cmd
= 'suicide' then
7217 if g_Game_IsClient
then
7218 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7221 if gPlayer1
<> nil then
7222 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7223 if gPlayer2
<> nil then
7224 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7228 else if cmd
= 'screenshot' then
7232 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7234 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7236 gWeaponAction
[0, WP_PREV
] := True;
7238 gWeaponAction
[0, WP_NEXT
] := True;
7240 else if cmd
= 'weapon' then
7242 if Length(p
) = 2 then
7244 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7245 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7246 gSelectWeapon
[0, a
] := True
7249 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7250 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7252 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7253 b
:= ord(cmd
[2]) - ord('1');
7255 gWeaponAction
[b
, WP_PREV
] := True;
7257 gWeaponAction
[b
, WP_NEXT
] := True;
7259 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7261 if Length(p
) = 2 then
7263 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7264 b
:= ord(cmd
[2]) - ord('1');
7265 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7266 gSelectWeapon
[b
, a
] := True
7269 else if (cmd
= 'dropflag') then
7271 if g_Game_IsServer
then
7273 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7274 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7277 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7279 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7281 b
:= ord(cmd
[2]) - ord('1');
7282 if g_Game_IsServer
then
7284 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7285 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7288 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7290 // Êîìàíäû Ñâîåé èãðû:
7291 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7293 if cmd
= 'bot_addred' then
7295 if Length(P
) > 1 then
7296 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7298 g_Bot_Add(TEAM_RED
, 2);
7300 else if cmd
= 'bot_addblue' then
7302 if Length(P
) > 1 then
7303 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7305 g_Bot_Add(TEAM_BLUE
, 2);
7307 else if cmd
= 'spectate' then
7313 else if cmd
= 'say' then
7315 if g_Game_IsServer
and g_Game_IsNet
then
7317 if Length(P
) > 1 then
7320 for a
:= 1 to High(P
) do
7321 chstr
:= chstr
+ P
[a
] + ' ';
7323 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7325 if Length(chstr
) < 1 then
7327 g_Console_Add('say <text>');
7331 chstr
:= b_Text_Format(chstr
);
7332 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7334 else g_Console_Add('say <text>');
7336 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7338 else if cmd
= 'tell' then
7340 if g_Game_IsServer
and g_Game_IsNet
then
7342 if (Length(P
) > 2) and (P
[1] <> '') then
7345 for a
:= 2 to High(P
) do
7346 chstr
:= chstr
+ P
[a
] + ' ';
7348 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7350 if Length(chstr
) < 1 then
7352 g_Console_Add('tell <playername> <text>');
7356 pl
:= g_Net_Client_ByName(P
[1]);
7358 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7360 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7362 else g_Console_Add('tell <playername> <text>');
7364 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7366 else if cmd
= 'centerprint' then
7368 if (Length(P
) > 2) and (P
[1] <> '') then
7371 for a
:= 2 to High(P
) do
7372 chstr
:= chstr
+ P
[a
] + ' ';
7374 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7376 if Length(chstr
) < 1 then
7378 g_Console_Add('centerprint <timeout> <text>');
7382 a
:= StrToIntDef(P
[1], 100);
7383 chstr
:= b_Text_Format(chstr
);
7384 g_Game_Message(chstr
, a
);
7385 if g_Game_IsNet
and g_Game_IsServer
then
7386 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7388 else g_Console_Add('centerprint <timeout> <text>');
7390 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7392 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7394 // Äîïîëíèòåëüíîå âðåìÿ:
7395 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7397 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7398 [gGameSettings
.TimeLimit
div 3600,
7399 (gGameSettings
.TimeLimit
div 60) mod 60,
7400 gGameSettings
.TimeLimit
mod 60]));
7401 if g_Game_IsNet
then MH_SEND_GameSettings
;
7403 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7405 if (Length(P
) <= 1) then
7406 g_Console_Add('rcon_password <password>')
7408 MC_SEND_RCONPassword(P
[1]);
7410 else if cmd
= 'rcon' then
7412 if g_Game_IsClient
then
7414 if Length(P
) > 1 then
7417 for a
:= 1 to High(P
) do
7418 chstr
:= chstr
+ P
[a
] + ' ';
7420 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7422 if Length(chstr
) < 1 then
7424 g_Console_Add('rcon <command>');
7428 MC_SEND_RCONCommand(chstr
);
7430 else g_Console_Add('rcon <command>');
7433 else if cmd
= 'ready' then
7435 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7436 gLMSRespawnTime
:= gTime
+ 100;
7438 else if (cmd
= 'callvote') and g_Game_IsNet
then
7440 if Length(P
) > 1 then
7443 for a
:= 1 to High(P
) do begin
7444 if a
> 1 then chstr
:= chstr
+ ' ';
7445 chstr
:= chstr
+ P
[a
];
7448 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7450 if Length(chstr
) < 1 then
7452 g_Console_Add('callvote <command>');
7456 if g_Game_IsClient
then
7457 MC_SEND_Vote(True, chstr
)
7459 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7460 g_Console_Process('vote', True);
7463 g_Console_Add('callvote <command>');
7465 else if (cmd
= 'vote') and g_Game_IsNet
then
7467 if g_Game_IsClient
then
7469 else if gVoteInProgress
then
7471 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7472 a
:= Floor((NetClientCount
+1)/2.0) + 1
7474 a
:= Floor(NetClientCount
/2.0) + 1;
7479 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7480 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7486 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7487 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7495 procedure SystemCommands(P
: SSArray
);
7499 cmd
:= LowerCase(P
[0]);
7508 gRC_Width
:= Max(1, gRC_Width
);
7509 gRC_Height
:= Max(1, gRC_Height
);
7510 gBPP
:= Max(1, gBPP
);
7511 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7512 e_LogWriteln('resolution changed')
7514 e_LogWriteln('resolution not changed');
7515 sys_EnableVSync(gVSync
);
7519 if Length(p
) = 2 then
7521 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7523 gFrameTime
:= 1000 div gMaxFPS
7527 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7531 if Length(p
) = 2 then
7533 gAskLanguage
:= true;
7534 gLanguage
:= LANGUAGE_ENGLISH
;
7535 case LowerCase(p
[1]) of
7538 gAskLanguage
:= false;
7539 gLanguage
:= LANGUAGE_ENGLISH
;
7543 gAskLanguage
:= false;
7544 gLanguage
:= LANGUAGE_RUSSIAN
;
7548 gAskLanguage
:= true;
7549 gLanguage
:= LANGUAGE_ENGLISH
;
7552 g_Language_Set(gLanguage
);
7556 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7562 procedure g_TakeScreenShot(Filename
: string = '');
7563 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7565 if e_NoGraphics
then Exit
;
7567 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7569 if Filename
= '' then
7572 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7573 Filename
:= 'screenshot-' + date
;
7576 name
:= e_CatPath(dir
, Filename
+ '.png');
7577 s
:= createDiskFile(name
);
7579 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7581 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7583 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7588 g_Console_Add('oh shit, i can''t create screenshot!')
7592 procedure g_Game_InGameMenu(Show
: Boolean);
7594 if (g_ActiveWindow
= nil) and Show
then
7596 if gGameSettings
.GameType
= GT_SINGLE
then
7597 g_GUI_ShowWindow('GameSingleMenu')
7600 if g_Game_IsClient
then
7601 g_GUI_ShowWindow('GameClientMenu')
7603 if g_Game_IsNet
then
7604 g_GUI_ShowWindow('GameServerMenu')
7606 g_GUI_ShowWindow('GameCustomMenu');
7608 g_Sound_PlayEx('MENU_OPEN');
7610 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7611 if (not g_Game_IsNet
) then
7615 if (g_ActiveWindow
<> nil) and (not Show
) then
7617 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7618 if (not g_Game_IsNet
) then
7619 g_Game_Pause(False);
7623 procedure g_Game_Pause (Enable
: Boolean);
7627 if not gGameOn
then exit
;
7629 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7632 gPauseMain
:= Enable
;
7634 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7637 procedure g_Game_HolmesPause (Enable
: Boolean);
7641 if not gGameOn
then exit
;
7642 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7645 gPauseHolmes
:= Enable
;
7647 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7650 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7655 if gTriggers
<> nil then
7656 for i
:= 0 to High(gTriggers
) do
7657 with gTriggers
[i
] do
7658 if (TriggerType
= TRIGGER_SOUND
) and
7660 Sound
.IsPlaying() then
7662 Sound
.Pause(Enable
);
7666 if gPlayers
<> nil then
7667 for i
:= 0 to High(gPlayers
) do
7668 if gPlayers
[i
] <> nil then
7669 gPlayers
[i
].PauseSounds(Enable
);
7672 if gMusic
<> nil then
7673 gMusic
.Pause(Enable
);
7676 procedure g_Game_StopAllSounds(all
: Boolean);
7680 if gTriggers
<> nil then
7681 for i
:= 0 to High(gTriggers
) do
7682 with gTriggers
[i
] do
7683 if (TriggerType
= TRIGGER_SOUND
) and
7687 if gMusic
<> nil then
7694 procedure g_Game_UpdateTriggerSounds
;
7697 if gTriggers
<> nil then
7698 for i
:= 0 to High(gTriggers
) do
7699 with gTriggers
[i
] do
7700 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7701 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7704 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7707 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7712 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7717 if gSpectMode
<> SPECT_PLAYERS
then
7719 if gSpectPID1
= UID
then
7724 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7731 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7736 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7741 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7746 if gSpectMode
<> SPECT_PLAYERS
then
7748 Pl
:= g_Player_Get(gSpectPID1
);
7749 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7754 if gSpectViewTwo
then
7756 Pl
:= g_Player_Get(gSpectPID2
);
7757 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7765 procedure g_Game_Message(Msg
: string; Time
: Word);
7767 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7768 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7769 MessageTime
:= Time
;
7772 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7774 punct
: Array[0..13] of String =
7775 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7781 function IsPunctuation(S
: String): Boolean;
7786 if Length(S
) <> 1 then
7788 for i
:= Low(punct
) to High(punct
) do
7789 if S
= punct
[i
] then
7795 function FilterPunctuation(S
: String): String;
7799 for i
:= Low(punct
) to High(punct
) do
7800 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7806 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7808 // remove player name
7809 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7810 // for FullWord check
7811 Text := toLowerCase1251(' ' + Text + ' ');
7812 fpText
:= FilterPunctuation(Text);
7814 for i
:= 0 to Length(gChatSounds
) - 1 do
7817 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7819 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7820 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7822 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7828 gChatSounds
[i
].Sound
.Play();
7834 g_Sound_PlayEx('SOUND_GAME_RADIO');
7837 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7846 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7850 if goodsnd
[a
].IsPlaying() then
7853 goodsnd
[Random(4)].Play();
7856 procedure g_Game_Announce_KillCombo(Param
: Integer);
7863 UID
:= Param
and $FFFF;
7868 Pl
:= g_Player_Get(UID
);
7877 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7881 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7885 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7889 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7897 if not g_Game_IsWatchedPlayer(UID
) then
7900 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7904 if killsnd
[n
].IsPlaying() then
7909 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7917 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7921 if hahasnd
[a
].IsPlaying() then
7924 hahasnd
[Random(3)].Play();
7927 procedure g_Game_StartVote(Command
, Initiator
: string);
7931 if not gVotesEnabled
then Exit
;
7932 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7933 if gVoteInProgress
or gVotePassed
then
7935 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7936 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7939 gVoteInProgress
:= True;
7940 gVotePassed
:= False;
7941 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7944 gVoteCommand
:= Command
;
7946 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7947 Need
:= Floor((NetClientCount
+1)/2.0)+1
7949 Need
:= Floor(NetClientCount
/2.0)+1;
7950 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7951 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7954 procedure g_Game_CheckVote
;
7958 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7959 if not gVoteInProgress
then Exit
;
7961 if (gTime
>= gVoteTimer
) then
7963 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7964 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7966 Need
:= Floor(NetClientCount
/2.0) + 1;
7967 if gVoteCount
>= Need
then
7969 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7970 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7971 gVotePassed
:= True;
7972 gVoteCmdTimer
:= gTime
+ 5000;
7976 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7977 MH_SEND_VoteEvent(NET_VE_FAILED
);
7979 if NetClients
<> nil then
7980 for I
:= Low(NetClients
) to High(NetClients
) do
7981 if NetClients
[i
].Used
then
7982 NetClients
[i
].Voted
:= False;
7983 gVoteInProgress
:= False;
7989 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7990 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7992 Need
:= Floor(NetClientCount
/2.0) + 1;
7993 if gVoteCount
>= Need
then
7995 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7996 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7997 gVoteInProgress
:= False;
7998 gVotePassed
:= True;
7999 gVoteCmdTimer
:= gTime
+ 5000;
8002 if NetClients
<> nil then
8003 for I
:= Low(NetClients
) to High(NetClients
) do
8004 if NetClients
[i
].Used
then
8005 NetClients
[i
].Voted
:= False;
8010 procedure g_Game_LoadMapList(FileName
: string);
8018 if not FileExists(FileName
) then Exit
;
8020 AssignFile(ListFile
, FileName
);
8022 while not EOF(ListFile
) do
8024 ReadLn(ListFile
, s
);
8027 if s
= '' then Continue
;
8029 SetLength(MapList
, Length(MapList
)+1);
8030 MapList
[High(MapList
)] := s
;
8032 CloseFile(ListFile
);
8035 procedure g_Game_SetDebugMode();
8038 // ×èòû (äàæå â ñâîåé èãðå):
8042 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8046 if Length(LoadingStat
.Msgs
) = 0 then
8052 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8053 if NextMsg
= Length(Msgs
) then
8055 for i
:= 0 to High(Msgs
)-1 do
8056 Msgs
[i
] := Msgs
[i
+1];
8064 Msgs
[NextMsg
-1] := Text;
8068 PBarWasHere
:= false;
8071 g_ActiveWindow
:= nil;
8073 ProcessLoading(true);
8076 procedure g_Game_StepLoading(Value
: Integer = -1);
8087 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8095 procedure g_Game_ClearLoading();
8104 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8105 if len
< 1 then len
:= 1;
8106 SetLength(Msgs
, len
);
8107 for len
:= Low(Msgs
) to High(Msgs
) do
8110 PBarWasHere
:= false;
8114 procedure Parse_Params(var pars
: TParamStrValues
);
8121 while i
<= ParamCount
do
8124 if (Length(s
) > 1) and (s
[1] = '-') then
8126 if (Length(s
) > 2) and (s
[2] = '-') then
8127 begin // Îäèíî÷íûé ïàðàìåòð
8128 SetLength(pars
, Length(pars
) + 1);
8129 with pars
[High(pars
)] do
8131 Name
:= LowerCase(s
);
8136 if (i
< ParamCount
) then
8137 begin // Ïàðàìåòð ñî çíà÷åíèåì
8139 SetLength(pars
, Length(pars
) + 1);
8140 with pars
[High(pars
)] do
8142 Name
:= LowerCase(s
);
8143 Value
:= LowerCase(ParamStr(i
));
8152 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8157 for i
:= 0 to High(pars
) do
8158 if pars
[i
].Name
= aName
then
8160 Result
:= pars
[i
].Value
;
8165 procedure g_Game_Process_Params();
8167 pars
: TParamStrValues
;
8170 LimT
, LimS
: Integer;
8181 s
:= Find_Param_Value(pars
, '--debug');
8184 g_Game_SetDebugMode();
8185 s
:= Find_Param_Value(pars
, '--netdump');
8190 // Connect when game loads
8191 ip
:= Find_Param_Value(pars
, '-connect');
8195 s
:= Find_Param_Value(pars
, '-port');
8196 if (s
= '') or not TryStrToInt(s
, Port
) then
8199 s
:= Find_Param_Value(pars
, '-pw');
8201 g_Game_StartClient(ip
, Port
, s
);
8205 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8208 gDefaultMegawadStart
:= s
;
8211 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8212 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8214 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8217 // Start map when game loads:
8218 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8219 if isWadPath(map
) then
8222 s
:= Find_Param_Value(pars
, '-gm');
8223 GMode
:= g_Game_TextToMode(s
);
8224 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8225 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8228 s
:= Find_Param_Value(pars
, '-limt');
8229 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8235 s
:= Find_Param_Value(pars
, '-lims');
8236 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8242 s
:= Find_Param_Value(pars
, '-lives');
8243 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8249 s
:= Find_Param_Value(pars
, '-opt');
8253 Opt
:= StrToIntDef(s
, 0);
8256 s
:= Find_Param_Value(pars
, '--close');
8260 // Override map to test:
8261 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8264 if e_IsValidResourceName(s
) then
8265 e_FindResource(AllMapDirs
, s
);
8266 gTestMap
:= ExpandFileName(s
);
8269 // Delete test map after play:
8270 s
:= Find_Param_Value(pars
, '--testdelete');
8273 //gMapToDelete := MapsDir + map;
8274 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8278 // Delete temporary WAD after play:
8279 s
:= Find_Param_Value(pars
, '--tempdelete');
8280 if (s
<> '') and (gTestMap
<> '') then
8282 gMapToDelete
:= gTestMap
;
8283 gTempDelete
:= True;
8286 // Number of players:
8287 s
:= Find_Param_Value(pars
, '-pl');
8289 n
:= DEFAULT_PLAYERS
8291 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8294 s
:= Find_Param_Value(pars
, '-port');
8295 if (s
= '') or not TryStrToInt(s
, Port
) then
8296 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8298 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8301 // Execute script when game loads:
8302 s
:= Find_Param_Value(pars
, '-exec');
8305 // if not isWadPath(s) then
8306 // s := GameDir + '/' + s;
8311 if IOResult
<> 0 then
8313 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8314 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8318 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8319 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8324 if IOResult
<> 0 then
8326 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8327 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8331 if Pos('#', s
) <> 1 then // script comment
8332 g_Console_Process(s
, True);
8343 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8344 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8345 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8346 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8348 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8349 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8350 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8351 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8353 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8354 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8356 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8357 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8359 {$IFDEF ENABLE_HOLMES}
8360 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8363 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8365 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8366 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8368 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8369 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8371 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8372 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8374 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8375 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8376 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8377 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8378 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8379 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8380 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8381 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8382 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');