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
45 TDelayedEvent
= record
54 Sound
: TPlayableSound
;
55 Tags
: Array of String;
59 TPlayerSettings
= record
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures
: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
90 function g_Game_ModeToText(Mode
: Byte): string;
91 function g_Game_TextToMode(Mode
: string): Byte;
92 procedure g_Game_ExecuteEvent(Name
: String);
93 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
99 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
100 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
105 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
106 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
107 procedure g_Game_ChangeMap(const MapPath
: String);
108 procedure g_Game_ExitLevel(const Map
: AnsiString);
109 function g_Game_GetFirstMap(WAD
: String): String;
110 function g_Game_GetNextMap(): String;
111 procedure g_Game_NextLevel();
112 procedure g_Game_Pause(Enable
: Boolean);
113 procedure g_Game_HolmesPause(Enable
: Boolean);
114 procedure g_Game_InGameMenu(Show
: Boolean);
115 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
116 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
117 procedure g_Game_Message(Msg
: String; Time
: Word);
118 procedure g_Game_LoadMapList(FileName
: String);
119 procedure g_Game_PauseAllSounds(Enable
: Boolean);
120 procedure g_Game_StopAllSounds(all
: Boolean);
121 procedure g_Game_UpdateTriggerSounds();
122 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
123 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
124 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
125 procedure g_Game_Announce_KillCombo(Param
: Integer);
126 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
127 procedure g_Game_StartVote(Command
, Initiator
: string);
128 procedure g_Game_CheckVote
;
129 procedure g_TakeScreenShot(Filename
: string = '');
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P
: SSArray
);
135 procedure GameCommands(P
: SSArray
);
136 procedure GameCheats(P
: SSArray
);
137 procedure DebugCommands(P
: SSArray
);
138 procedure g_Game_Process_Params
;
139 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
140 procedure g_Game_StepLoading(Value
: Integer = -1);
141 procedure g_Game_ClearLoading();
142 procedure g_Game_SetDebugMode();
143 procedure DrawLoadingStat();
144 procedure DrawMenuBackground(tex
: AnsiString);
146 { procedure SetWinPause(Enable: Boolean); }
151 LOADING_SHOW_STEP
= 100;
152 LOADING_INTERLINE
= 20;
167 MESSAGE_DIKEY
= WM_USER
+ 1;
172 EXIT_ENDLEVELSINGLE
= 4;
173 EXIT_ENDLEVELCUSTOM
= 5;
175 GAME_OPTION_RESERVED
= 1;
176 GAME_OPTION_TEAMDAMAGE
= 2;
177 GAME_OPTION_ALLOWEXIT
= 4;
178 GAME_OPTION_WEAPONSTAY
= 8;
179 GAME_OPTION_MONSTERS
= 16;
180 GAME_OPTION_BOTVSPLAYER
= 32;
181 GAME_OPTION_BOTVSMONSTER
= 64;
182 GAME_OPTION_DMKEYS
= 128;
183 GAME_OPTION_RESPAWNITEMS
= 256;
188 STATE_INTERCUSTOM
= 3;
189 STATE_INTERSINGLE
= 4;
195 LMS_RESPAWN_NONE
= 0;
196 LMS_RESPAWN_WARMUP
= 1;
197 LMS_RESPAWN_FINAL
= 2;
214 CONFIG_FILENAME
= 'Doom2DF.cfg';
216 TEST_MAP_NAME
= '$$$_TEST_$$$';
218 STD_PLAYER_MODEL
= 'Doomer';
226 STATFILE_VERSION
= $03;
230 gGameSettings
: TGameSettings
;
231 gPlayer1Settings
: TPlayerSettings
;
232 gPlayer2Settings
: TPlayerSettings
;
234 gPlayerScreenSize
: TDFPoint
;
235 gPlayer1ScreenCoord
: TDFPoint
;
236 gPlayer2ScreenCoord
: TDFPoint
;
237 gPlayer1
: TPlayer
= nil;
238 gPlayer2
: TPlayer
= nil;
239 gPlayerDrawn
: TPlayer
= nil;
241 gSwitchGameMode
: Byte = GM_DM
;
242 gHearPoint1
, gHearPoint2
: THearPoint
;
243 gSoundEffectsDF
: Boolean = False;
244 gSoundTriggerTime
: Word = 0;
245 gAnnouncer
: Integer = ANNOUNCE_NONE
;
246 goodsnd
: array[0..3] of TPlayableSound
;
247 killsnd
: array[0..3] of TPlayableSound
;
248 hahasnd
: array[0..2] of TPlayableSound
;
249 sound_get_flag
: array[0..1] of TPlayableSound
;
250 sound_lost_flag
: array[0..1] of TPlayableSound
;
251 sound_ret_flag
: array[0..1] of TPlayableSound
;
252 sound_cap_flag
: array[0..1] of TPlayableSound
;
253 gBodyKillEvent
: Integer = -1;
254 gDefInterTime
: ShortInt = -1;
255 gInterEndTime
: LongWord = 0;
256 gInterTime
: LongWord = 0;
257 gServInterTime
: Byte = 0;
258 gGameStartTime
: LongWord = 0;
259 gTotalMonsters
: Integer = 0;
260 gPauseMain
: Boolean = false;
261 gPauseHolmes
: Boolean = false;
262 gShowTime
: Boolean = False;
263 gShowFPS
: Boolean = False;
264 gShowGoals
: Boolean = True;
265 gShowStat
: Boolean = True;
266 gShowKillMsg
: Boolean = True;
267 gShowLives
: Boolean = True;
268 gShowPing
: Boolean = False;
269 gShowMap
: Boolean = False;
271 gState
: Byte = STATE_NONE
;
273 sWidth
, sHeight
: Word;
274 gSpectMode
: Byte = SPECT_NONE
;
275 gSpectHUD
: Boolean = True;
276 gSpectKeyPress
: Boolean = False;
277 gSpectX
: Integer = 0;
278 gSpectY
: Integer = 0;
279 gSpectStep
: Byte = 8;
280 gSpectViewTwo
: Boolean = False;
281 gSpectPID1
: Integer = -1;
282 gSpectPID2
: Integer = -1;
283 gSpectAuto
: Boolean = False;
284 gSpectAutoNext
: LongWord;
285 gSpectAutoStepX
: Integer;
286 gSpectAutoStepY
: Integer;
287 gMusic
: TMusic
= nil;
288 gLoadGameMode
: Boolean;
289 gCheats
: Boolean = False;
290 gMapOnce
: Boolean = False;
291 gMapToDelete
: String;
292 gTempDelete
: Boolean = False;
293 gLastMap
: Boolean = False;
294 gWinSizeX
, gWinSizeY
: Integer;
295 gResolutionChange
: Boolean = False;
296 gRC_Width
, gRC_Height
: Integer;
297 gRC_FullScreen
, gRC_Maximized
: Boolean;
298 gLanguageChange
: Boolean = False;
299 gDebugMode
: Boolean = False;
300 g_debug_Sounds
: Boolean = False;
301 g_debug_Frames
: Boolean = False;
302 g_debug_WinMsgs
: Boolean = False;
303 g_debug_MonsterOff
: Boolean = False;
304 g_debug_BotAIOff
: Byte = 0;
305 g_debug_HealthBar
: Boolean = False;
306 g_Debug_Player
: Boolean = False;
307 gCoopMonstersKilled
: Word = 0;
308 gCoopSecretsFound
: Word = 0;
309 gCoopTotalMonstersKilled
: Word = 0;
310 gCoopTotalSecretsFound
: Word = 0;
311 gCoopTotalMonsters
: Word = 0;
312 gCoopTotalSecrets
: Word = 0;
313 gStatsOff
: Boolean = False;
314 gStatsPressed
: Boolean = False;
315 gExitByTrigger
: Boolean = False;
316 gNextMap
: String = '';
317 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
318 gLMSRespawnTime
: Cardinal = 0;
319 gLMSSoftSpawn
: Boolean = False;
320 gMissionFailed
: Boolean = False;
321 gVoteInProgress
: Boolean = False;
322 gVotePassed
: Boolean = False;
323 gVoteCommand
: string = '';
324 gVoteTimer
: Cardinal = 0;
325 gVoteCmdTimer
: Cardinal = 0;
326 gVoteCount
: Integer = 0;
327 gVoteTimeout
: Cardinal = 30;
328 gVoted
: Boolean = False;
329 gVotesEnabled
: Boolean = True;
330 gEvents
: Array of TGameEvent
;
331 gDelayedEvents
: Array of TDelayedEvent
;
332 gUseChatSounds
: Boolean = True;
333 gChatSounds
: Array of TChatSound
;
334 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
335 gInterReadyCount
: Integer = 0;
337 g_dbg_ignore_bounds
: Boolean = false;
338 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
339 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
341 // move button values:
342 // bits 0-1: l/r state:
343 // 0: neither left, nor right pressed
346 // bits 4-5: l/r state when strafe was pressed
347 P1MoveButton
: Byte = 0;
348 P2MoveButton
: Byte = 0;
350 g_profile_frame_update
: Boolean = false;
351 g_profile_frame_draw
: Boolean = false;
352 g_profile_collision
: Boolean = false;
353 g_profile_los
: Boolean = false;
354 g_profile_history_size
: Integer = 1000;
356 g_rlayer_back
: Boolean = true;
357 g_rlayer_step
: Boolean = true;
358 g_rlayer_wall
: Boolean = true;
359 g_rlayer_door
: Boolean = true;
360 g_rlayer_acid1
: Boolean = true;
361 g_rlayer_acid2
: Boolean = true;
362 g_rlayer_water
: Boolean = true;
363 g_rlayer_fore
: Boolean = true;
366 procedure g_ResetDynlights ();
367 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
368 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
370 function conIsCheatsEnabled (): Boolean; inline;
371 function gPause (): Boolean; inline;
377 {$INCLUDE ../nogl/noGLuses.inc}
378 {$IFDEF ENABLE_HOLMES}
381 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
382 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
383 g_playermodel
, g_gfx
, g_options
, Math
,
384 g_triggers
, g_monsters
, e_sound
, CONFIG
,
385 g_language
, g_net
, g_main
,
386 ENet
, e_msg
, g_netmsg
, g_netmaster
,
387 sfs
, wadreader
, g_system
;
391 hasPBarGfx
: Boolean = false;
394 // ////////////////////////////////////////////////////////////////////////// //
395 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
398 // ////////////////////////////////////////////////////////////////////////// //
399 function conIsCheatsEnabled (): Boolean; inline;
402 if g_Game_IsNet
then exit
;
403 if not gDebugMode
then
405 //if not gCheats then exit;
406 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
407 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
413 // ////////////////////////////////////////////////////////////////////////// //
415 profileFrameDraw
: TProfiler
= nil;
418 // ////////////////////////////////////////////////////////////////////////// //
421 x
, y
, radius
: Integer;
424 exploRadius
: Integer;
428 g_dynLights
: array of TDynLight
= nil;
429 g_dynLightCount
: Integer = 0;
430 g_playerLight
: Boolean = false;
432 procedure g_ResetDynlights ();
436 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
438 for idx
:= 0 to g_dynLightCount
-1 do
440 if g_dynLights
[idx
].exploCount
= -666 then
447 Inc(g_dynLights
[idx
].exploCount
);
448 if (g_dynLights
[idx
].exploCount
< 10) then
450 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
451 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
452 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
453 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
458 g_dynLightCount
:= lnum
;
461 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
463 if not gwin_has_stencil
then exit
;
464 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
465 g_dynLights
[g_dynLightCount
].x
:= x
;
466 g_dynLights
[g_dynLightCount
].y
:= y
;
467 g_dynLights
[g_dynLightCount
].radius
:= radius
;
468 g_dynLights
[g_dynLightCount
].r
:= r
;
469 g_dynLights
[g_dynLightCount
].g
:= g
;
470 g_dynLights
[g_dynLightCount
].b
:= b
;
471 g_dynLights
[g_dynLightCount
].a
:= a
;
472 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
473 Inc(g_dynLightCount
);
476 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
478 if not gwin_has_stencil
then exit
;
479 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
480 g_dynLights
[g_dynLightCount
].x
:= x
;
481 g_dynLights
[g_dynLightCount
].y
:= y
;
482 g_dynLights
[g_dynLightCount
].radius
:= 0;
483 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
484 g_dynLights
[g_dynLightCount
].r
:= r
;
485 g_dynLights
[g_dynLightCount
].g
:= g
;
486 g_dynLights
[g_dynLightCount
].b
:= b
;
487 g_dynLights
[g_dynLightCount
].a
:= 0;
488 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
489 Inc(g_dynLightCount
);
493 // ////////////////////////////////////////////////////////////////////////// //
494 function calcProfilesHeight (prof
: TProfiler
): Integer;
497 if (prof
= nil) then exit
;
498 if (length(prof
.bars
) = 0) then exit
;
499 result
:= length(prof
.bars
)*(16+2);
503 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
510 if (prof
= nil) then exit
;
512 if (length(prof
.bars
) = 0) then exit
;
514 hgt
:= calcProfilesHeight(prof
);
515 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
516 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
518 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
519 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
520 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
523 for ii
:= 0 to High(prof
.bars
) do
525 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);
532 // ////////////////////////////////////////////////////////////////////////// //
534 TEndCustomGameStat
= record
535 PlayerStat
: TPlayerStatArray
;
539 Map
, MapName
: String;
542 TEndSingleGameStat
= record
543 PlayerStat
: Array [0..1] of record
549 TotalSecrets
: Integer;
552 TLoadingStat
= record
556 Msgs
: Array of String;
558 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
561 TParamStrValue
= record
566 TParamStrValues
= Array of TParamStrValue
;
569 INTER_ACTION_TEXT
= 1;
570 INTER_ACTION_PIC
= 2;
571 INTER_ACTION_MUSIC
= 3;
575 FPSCounter
, UPSCounter
: Word;
576 FPSTime
, UPSTime
: LongWord;
577 DataLoaded
: Boolean = False;
578 IsDrawStat
: Boolean = False;
579 CustomStat
: TEndCustomGameStat
;
580 SingleStat
: TEndSingleGameStat
;
581 LoadingStat
: TLoadingStat
;
582 EndingGameCounter
: Byte = 0;
585 MessageLineLength
: Integer = 80;
586 MapList
: SSArray
= nil;
587 MapIndex
: Integer = -1;
588 InterReadyTime
: Integer = -1;
589 StatShotDone
: Boolean = False;
590 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
591 StatDate
: string = '';
597 text: Array of ShortString;
598 anim
: Array of ShortString;
599 pic
: Array of ShortString;
600 mus
: Array of ShortString;
602 triggers
: Array of record
604 actions
: Array of record
605 action
, p1
, p2
: Integer;
608 cur_trigger
: Integer;
621 function Compare(a
, b
: TPlayerStat
): Integer;
623 if a
.Spectator
then Result
:= 1
624 else if b
.Spectator
then Result
:= -1
625 else if a
.Frags
< b
.Frags
then Result
:= 1
626 else if a
.Frags
> b
.Frags
then Result
:= -1
627 else if a
.Deaths
< b
.Deaths
then Result
:= -1
628 else if a
.Deaths
> b
.Deaths
then Result
:= 1
629 else if a
.Kills
< b
.Kills
then Result
:= -1
633 procedure SortGameStat(var stat
: TPlayerStatArray
);
638 if stat
= nil then Exit
;
640 for I
:= High(stat
) downto Low(stat
) do
641 for J
:= Low(stat
) to High(stat
) - 1 do
642 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
645 stat
[J
] := stat
[J
+ 1];
650 // saves a shitty CSV containing the game stats passed to it
651 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
654 dir
, fname
, map
, mode
, etime
: String;
658 dir
:= e_GetWriteableDir(StatsDirs
);
659 // stats are placed in stats/yy/mm/dd/*.csv
660 fname
:= e_CatPath(dir
, Path
);
661 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
662 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
663 AssignFile(s
, fname
);
666 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
667 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
668 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
669 mode
:= g_Game_ModeToText(Stat
.GameMode
);
670 etime
:= Format('%d:%.2d:%.2d', [
671 Stat
.GameTime
div 1000 div 3600,
672 (Stat
.GameTime
div 1000 div 60) mod 60,
673 Stat
.GameTime
div 1000 mod 60
675 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
676 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
682 gGameSettings
.TimeLimit
,
683 gGameSettings
.GoalLimit
,
684 gGameSettings
.Options
,
686 Length(Stat
.PlayerStat
)
688 // line 2: game specific shit
689 // if it's a team game: red score, blue score
690 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
692 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
694 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
695 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
697 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
698 // lines 3-...: team, player name, frags, deaths
699 WriteLn(s
, 'team,name,frags,deaths');
700 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
701 with Stat
.PlayerStat
[I
] do
702 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
704 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
707 g_Console_Add('could not create gamestats file "' + fname
+ '"');
712 function g_Game_ModeToText(Mode
: Byte): string;
716 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
717 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
718 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
719 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
720 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
724 function g_Game_TextToMode(Mode
: string): Byte;
727 Mode
:= UpperCase(Mode
);
728 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
733 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
738 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
743 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
748 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
755 function g_Game_IsNet(): Boolean;
757 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
760 function g_Game_IsServer(): Boolean;
762 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
765 function g_Game_IsClient(): Boolean;
767 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
770 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
777 Result
.name
:= ExtractFileName(WAD
);
778 Result
.description
:= '';
781 w
:= TWADFile
.Create();
784 if not w
.GetResource('INTERSCRIPT', p
, len
) then
790 cfg
:= TConfig
.CreateMem(p
, len
);
791 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
792 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
793 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
794 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
800 procedure g_Game_FreeWAD();
804 for a
:= 0 to High(MegaWAD
.res
.pic
) do
805 if MegaWAD
.res
.pic
[a
] <> '' then
806 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
808 for a
:= 0 to High(MegaWAD
.res
.mus
) do
809 if MegaWAD
.res
.mus
[a
] <> '' then
810 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
812 MegaWAD
.res
.pic
:= nil;
813 MegaWAD
.res
.text := nil;
814 MegaWAD
.res
.anim
:= nil;
815 MegaWAD
.res
.mus
:= nil;
816 MegaWAD
.triggers
:= nil;
818 g_Texture_Delete('TEXTURE_endpic');
819 g_Sound_Delete('MUSIC_endmus');
821 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
822 gGameSettings
.WAD
:= '';
825 procedure g_Game_LoadWAD(WAD
: string);
834 gGameSettings
.WAD
:= WAD
;
835 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
838 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
840 w
:= TWADFile
.Create();
843 if not w
.GetResource('INTERSCRIPT', p
, len
) then
849 cfg
:= TConfig
.CreateMem(p
, len
);
854 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
855 if s = '' then Break;
858 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
859 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
861 g_Texture_CreateWADEx(s, s);
867 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
868 if s = '' then Break;
871 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
872 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
874 g_Music_CreateWADEx(s, s);
877 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
878 if MegaWAD
.endpic
<> '' then
880 TEXTUREFILTER
:= GL_LINEAR
;
881 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
882 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
883 TEXTUREFILTER
:= GL_NEAREST
;
885 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
886 if MegaWAD
.endmus
<> '' then
888 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
889 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
897 {procedure start_trigger(t: string);
901 function next_trigger(): Boolean;
905 procedure DisableCheats();
911 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
912 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
913 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
914 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
916 {$IF DEFINED(D2F_DEBUG)}
917 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
918 gAimLine
:= g_dbg_aimline_on
;
922 procedure g_Game_ExecuteEvent(Name
: String);
928 if gEvents
= nil then
930 for a
:= 0 to High(gEvents
) do
931 if gEvents
[a
].Name
= Name
then
933 if gEvents
[a
].Command
<> '' then
934 g_Console_Process(gEvents
[a
].Command
, True);
939 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
944 if gDelayedEvents
<> nil then
945 for a
:= 0 to High(gDelayedEvents
) do
946 if not gDelayedEvents
[a
].Pending
then
953 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
954 n
:= High(gDelayedEvents
);
956 gDelayedEvents
[n
].Pending
:= True;
957 gDelayedEvents
[n
].DEType
:= DEType
;
958 gDelayedEvents
[n
].DENum
:= Num
;
959 gDelayedEvents
[n
].DEStr
:= Str
;
960 if DEType
= DE_GLOBEVENT
then
961 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
963 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
973 if g_Game_IsNet
and g_Game_IsServer
then
974 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
978 gPauseHolmes
:= false;
981 g_Game_StopAllSounds(False);
986 EndingGameCounter
:= 0;
987 g_ActiveWindow
:= nil;
989 gLMSRespawn
:= LMS_RESPAWN_NONE
;
990 gLMSRespawnTime
:= 0;
993 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
998 begin // Ýòî áûë òåñò
1002 begin // Âûõîä â ãëàâíîå ìåíþ
1003 gMusic
.SetByName('MUSIC_MENU');
1005 if gState
<> STATE_SLIST
then
1007 g_GUI_ShowWindow('MainMenu');
1008 gState
:= STATE_MENU
;
1011 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1012 slReturnPressed
:= True;
1013 if g_Net_Slist_Fetch(slCurrent
) then
1015 if slCurrent
= nil then
1016 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1019 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1020 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1023 g_Game_ExecuteEvent('ongameend');
1027 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1029 if not g_Game_IsClient
then g_Game_Restart();
1032 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1034 // Ñòàòèñòèêà Ñâîåé èãðû:
1035 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1037 CustomStat
.GameTime
:= gTime
;
1038 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1039 CustomStat
.MapName
:= gMapInfo
.Name
;
1040 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1041 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1042 CustomStat
.TeamStat
:= gTeamStat
;
1044 CustomStat
.PlayerStat
:= nil;
1046 // Ñòàòèñòèêà èãðîêîâ:
1047 if gPlayers
<> nil then
1049 for a
:= 0 to High(gPlayers
) do
1050 if gPlayers
[a
] <> nil then
1052 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1053 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1056 Name
:= gPlayers
[a
].Name
;
1057 Frags
:= gPlayers
[a
].Frags
;
1058 Deaths
:= gPlayers
[a
].Death
;
1059 Kills
:= gPlayers
[a
].Kills
;
1060 Team
:= gPlayers
[a
].Team
;
1061 Color
:= gPlayers
[a
].Model
.Color
;
1062 Spectator
:= gPlayers
[a
].FSpectator
;
1066 SortGameStat(CustomStat
.PlayerStat
);
1068 if (gSaveStats
or gScreenshotStats
) and (Length(gPlayers
) > 1) then
1071 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1072 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1073 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1074 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1076 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1079 StatShotDone
:= False;
1082 g_Game_ExecuteEvent('onmapend');
1083 if not g_Game_IsClient
then g_Player_ResetReady
;
1084 gInterReadyCount
:= 0;
1086 // Çàòóõàþùèé ýêðàí:
1087 EndingGameCounter
:= 255;
1088 gState
:= STATE_FOLD
;
1090 if gDefInterTime
< 0 then
1091 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1093 gInterEndTime
:= gDefInterTime
* 1000;
1096 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1098 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1099 SingleStat
.GameTime
:= gTime
;
1100 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1101 SingleStat
.TotalSecrets
:= gSecretsCount
;
1102 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1103 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1104 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1105 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1106 if SingleStat
.TwoPlayers
then
1108 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1109 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1112 g_Game_ExecuteEvent('onmapend');
1115 if gNextMap
<> '' then
1117 gMusic
.SetByName('MUSIC_INTERMUS');
1119 gState
:= STATE_INTERSINGLE
;
1122 g_Game_ExecuteEvent('oninter');
1124 else // Áîëüøå íåò êàðò
1126 // Çàòóõàþùèé ýêðàí:
1127 EndingGameCounter
:= 255;
1128 gState
:= STATE_FOLD
;
1133 // Îêîí÷àíèå îáðàáîòàíî:
1134 if gExit
<> EXIT_QUIT
then
1138 procedure drawTime(X
, Y
: Integer); inline;
1140 e_TextureFontPrint(x
, y
,
1141 Format('%d:%.2d:%.2d', [
1142 gTime
div 1000 div 3600,
1143 (gTime
div 1000 div 60) mod 60,
1144 gTime
div 1000 mod 60
1149 procedure DrawStat();
1151 pc
, x
, y
, w
, h
: Integer;
1152 w1
, w2
, w3
, w4
: Integer;
1154 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1157 stat
: TPlayerStatArray
;
1164 pc
:= g_Player_GetCount
;
1165 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1167 w
:= gScreenWidth
-(gScreenWidth
div 5);
1168 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1171 h
:= 40+ch
*5+(ch
+8)*pc
;
1172 x
:= (gScreenWidth
div 2)-(w
div 2);
1173 y
:= (gScreenHeight
div 2)-(h
div 2);
1175 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1176 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1178 drawTime(x
+w
-78, y
+8);
1180 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1181 map
:= g_ExtractFileName(gMapInfo
.Map
);
1182 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1184 case gGameSettings
.GameMode
of
1187 if gGameSettings
.MaxLives
= 0 then
1188 s1
:= _lc
[I_GAME_DM
]
1190 s1
:= _lc
[I_GAME_LMS
];
1191 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1192 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1197 if gGameSettings
.MaxLives
= 0 then
1198 s1
:= _lc
[I_GAME_TDM
]
1200 s1
:= _lc
[I_GAME_TLMS
];
1201 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1202 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1207 s1
:= _lc
[I_GAME_CTF
];
1208 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1209 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1214 if gGameSettings
.MaxLives
= 0 then
1215 s1
:= _lc
[I_GAME_COOP
]
1217 s1
:= _lc
[I_GAME_SURV
];
1218 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1219 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1230 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1232 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1234 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1236 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1237 gStdFont
, 200, 200, 200, 1);
1239 if NetMode
= NET_SERVER
then
1240 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1242 if NetMode
= NET_CLIENT
then
1243 e_TextureFontPrintEx(x
+8, y
+ 8,
1244 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1248 stat
:= g_Player_GetStats();
1251 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1252 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1254 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1256 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1260 for a
:= TEAM_RED
to TEAM_BLUE
do
1262 if a
= TEAM_RED
then
1264 s1
:= _lc
[I_GAME_TEAM_RED
];
1271 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1277 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1278 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1279 gStdFont
, r
, g
, b
, 1);
1281 _y
:= _y
+ch
+(ch
div 4);
1282 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1283 _y
:= _y
+(ch
div 4);
1285 for aa
:= 0 to High(stat
) do
1286 if stat
[aa
].Team
= a
then
1302 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1304 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1306 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1308 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1315 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1318 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1319 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1320 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1321 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1324 for aa
:= 0 to High(stat
) do
1338 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1339 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1341 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1343 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1345 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1347 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1353 procedure g_Game_Init();
1356 knownFiles
: array of AnsiString = nil;
1358 wext
, s
: AnsiString;
1363 gTempDelete
:= False;
1365 sfsGCDisable(); // temporary disable removing of temporary volumes
1368 TEXTUREFILTER
:= GL_LINEAR
;
1369 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1370 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1371 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1372 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1373 TEXTUREFILTER
:= GL_NEAREST
;
1375 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1376 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1377 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1379 g_Game_ClearLoading();
1380 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1381 g_Game_SetLoadingText('', 0, False);
1383 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1386 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1387 g_PlayerModel_LoadData();
1389 // load models from all possible wad types, in all known directories
1390 // this does a loosy job (linear search, ooph!), but meh
1391 for wext
in wadExtensions
do
1393 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1395 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1399 for s
in knownFiles
do
1401 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1409 SetLength(knownFiles
, length(knownFiles
)+1);
1410 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1412 until (FindNext(SR
) <> 0);
1418 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1420 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
);
1421 for s
in knownFiles
do
1423 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1427 gPauseMain
:= false;
1428 gPauseHolmes
:= false;
1431 {e_MouseInfo.Accel := 1.0;}
1433 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1436 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1437 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1438 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1439 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1440 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1443 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1447 gMusic
:= TMusic
.Create();
1448 gMusic
.SetByName('MUSIC_MENU');
1451 gGameSettings
.WarmupTime
:= 30;
1453 gState
:= STATE_MENU
;
1455 SetLength(gEvents
, 6);
1456 gEvents
[0].Name
:= 'ongamestart';
1457 gEvents
[1].Name
:= 'ongameend';
1458 gEvents
[2].Name
:= 'onmapstart';
1459 gEvents
[3].Name
:= 'onmapend';
1460 gEvents
[4].Name
:= 'oninter';
1461 gEvents
[5].Name
:= 'onwadend';
1463 sfsGCEnable(); // enable releasing unused volumes
1467 procedure g_Game_Free(freeTextures
: Boolean=true);
1469 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1470 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1472 g_Map_Free(freeTextures
);
1474 g_Player_RemoveAllCorpses();
1476 gGameSettings
.GameType
:= GT_NONE
;
1477 if gGameSettings
.GameMode
= GM_SINGLE
then
1478 gGameSettings
.GameMode
:= GM_DM
;
1479 gSwitchGameMode
:= gGameSettings
.GameMode
;
1482 gExitByTrigger
:= False;
1485 function IsActivePlayer(p
: TPlayer
): Boolean;
1490 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1493 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1500 if gPlayers
= nil then
1502 for a
:= Low(gPlayers
) to High(gPlayers
) do
1503 if IsActivePlayer(gPlayers
[a
]) then
1505 if gPlayers
[a
].UID
<> ID
then
1507 Result
:= gPlayers
[a
];
1512 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1518 if gPlayers
= nil then
1522 for a
:= Low(gPlayers
) to High(gPlayers
) do
1523 if IsActivePlayer(gPlayers
[a
]) then
1525 SetLength(ids
, Length(ids
) + 1);
1526 ids
[High(ids
)] := gPlayers
[a
].UID
;
1527 if gPlayers
[a
].UID
= Skip
then
1530 if Length(ids
) = 0 then
1535 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1538 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1544 if gPlayers
= nil then
1548 for a
:= Low(gPlayers
) to High(gPlayers
) do
1549 if IsActivePlayer(gPlayers
[a
]) then
1551 SetLength(ids
, Length(ids
) + 1);
1552 ids
[High(ids
)] := gPlayers
[a
].UID
;
1553 if gPlayers
[a
].UID
= Skip
then
1556 if Length(ids
) = 0 then
1559 Result
:= ids
[Length(ids
) - 1]
1561 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1564 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1570 if gPlayers
= nil then
1574 for a
:= Low(gPlayers
) to High(gPlayers
) do
1575 if IsActivePlayer(gPlayers
[a
]) then
1577 SetLength(ids
, Length(ids
) + 1);
1578 ids
[High(ids
)] := gPlayers
[a
].UID
;
1579 if gPlayers
[a
].UID
= Skip
then
1582 if Length(ids
) = 0 then
1584 if Length(ids
) = 1 then
1589 Result
:= ids
[Random(Length(ids
))];
1591 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1593 Result
:= ids
[Random(Length(ids
))];
1598 function GetRandomSpectMode(Current
: Byte): Byte;
1605 0: Result
:= SPECT_STATS
;
1606 1: Result
:= SPECT_MAPVIEW
;
1607 2: Result
:= SPECT_MAPVIEW
;
1608 3: Result
:= SPECT_PLAYERS
;
1609 4: Result
:= SPECT_PLAYERS
;
1610 5: Result
:= SPECT_PLAYERS
;
1611 6: Result
:= SPECT_PLAYERS
;
1613 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1617 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1623 if (plr
= nil) then exit
;
1624 if (p
= 2) then time
:= 1000 else time
:= 1;
1625 strafeDir
:= MoveButton
shr 4;
1626 MoveButton
:= MoveButton
and $0F;
1628 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1629 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1630 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1631 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1632 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1633 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1635 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1636 if MoveButton
= 1 then
1637 plr
.PressKey(KEY_LEFT
, time
)
1638 else if MoveButton
= 2 then
1639 plr
.PressKey(KEY_RIGHT
, time
);
1641 // if we have "strafe" key, turn off old strafe mechanics
1642 if gPlayerAction
[p
, ACTION_STRAFE
] then
1644 // new strafe mechanics
1645 if (strafeDir
= 0) then
1646 strafeDir
:= MoveButton
; // start strafing
1647 // now set direction according to strafe (reversed)
1648 if (strafeDir
= 2) then
1649 plr
.SetDirection(TDirection
.D_LEFT
)
1650 else if (strafeDir
= 1) then
1651 plr
.SetDirection(TDirection
.D_RIGHT
)
1655 strafeDir
:= 0; // not strafing anymore
1656 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1657 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1658 plr
.SetDirection(TDirection
.D_LEFT
)
1659 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1660 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1661 plr
.SetDirection(TDirection
.D_RIGHT
)
1662 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1663 else if MoveButton
<> 0 then
1664 plr
.SetDirection(TDirection(MoveButton
-1))
1667 // fix movebutton state
1668 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1670 // Îñòàëüíûå êëàâèøè:
1671 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1672 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1673 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1674 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1675 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1676 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1677 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1679 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1680 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1682 for i
:= WP_FIRST
to WP_LAST
do
1684 if gSelectWeapon
[p
, i
] then
1686 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1687 gSelectWeapon
[p
, i
] := False
1691 // HACK: add dynlight here
1692 if gwin_k8_enable_light_experiments
then
1694 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1696 g_playerLight
:= true;
1698 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1700 g_playerLight
:= false;
1704 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1707 // HACK: don't have a "key was pressed" function
1708 procedure InterReady();
1710 if InterReadyTime
> gTime
then Exit
;
1711 InterReadyTime
:= gTime
+ 3000;
1712 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1715 procedure g_Game_Update();
1717 Msg
: g_gui
.TMessage
;
1723 function sendMonsPos (mon
: TMonster
): Boolean;
1725 result
:= false; // don't stop
1726 // this will also reset "need-send" flag
1727 if mon
.gncNeedSend
then
1729 MH_SEND_MonsterPos(mon
.UID
);
1731 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1733 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1735 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1737 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1741 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1743 result
:= false; // don't stop
1744 // this will also reset "need-send" flag
1745 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1749 reliableUpdate
: Boolean;
1754 // Ïîðà âûêëþ÷àòü èãðó:
1755 if gExit
= EXIT_QUIT
then
1757 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1761 if gExit
= EXIT_QUIT
then
1765 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1766 // no need to, as we'll do it in event handler
1768 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1771 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1773 gExit
:= EXIT_SIMPLE
;
1778 // process master server communications
1779 g_Net_Slist_Pulse();
1782 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1783 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1784 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1785 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1787 if g_Game_IsNet
and g_Game_IsServer
then
1789 gInterTime
:= gInterTime
+ GAME_TICK
;
1790 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1791 if a
<> gServInterTime
then
1793 gServInterTime
:= a
;
1794 MH_SEND_TimeSync(gServInterTime
);
1798 if (not g_Game_IsClient
) and
1802 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1803 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1804 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1805 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1807 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1808 and (g_ActiveWindow
= nil)
1810 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1813 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1814 g_Game_StopAllSounds(True);
1816 if gMapOnce
then // Ýòî áûë òåñò
1817 gExit
:= EXIT_SIMPLE
1819 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1820 g_Game_ChangeMap(gNextMap
)
1821 else // Ñëåäóþùåé êàðòû íåò
1823 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1825 // Âûõîä â ãëàâíîå ìåíþ:
1827 g_GUI_ShowWindow('MainMenu');
1828 gMusic
.SetByName('MUSIC_MENU');
1830 gState
:= STATE_MENU
;
1833 // Ôèíàëüíàÿ êàðòèíêà:
1834 g_Game_ExecuteEvent('onwadend');
1836 if not gMusic
.SetByName('MUSIC_endmus') then
1837 gMusic
.SetByName('MUSIC_STDENDMUS');
1839 gState
:= STATE_ENDPIC
;
1841 g_Game_ExecuteEvent('ongameend');
1846 else if g_Game_IsClient
and
1849 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1850 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1851 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1852 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1854 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1855 and (g_ActiveWindow
= nil)
1863 if gState
= STATE_INTERTEXT
then
1864 if InterText
.counter
> 0 then
1865 InterText
.counter
:= InterText
.counter
- 1;
1868 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1870 if EndingGameCounter
= 0 then
1872 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1873 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1875 InterReadyTime
:= -1;
1876 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1878 g_Game_ExecuteEvent('onwadend');
1879 if not gMusic
.SetByName('MUSIC_endmus') then
1880 gMusic
.SetByName('MUSIC_STDENDMUS');
1883 gMusic
.SetByName('MUSIC_ROUNDMUS');
1886 gState
:= STATE_INTERCUSTOM
;
1889 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1891 gMusic
.SetByName('MUSIC_INTERMUS');
1893 gState
:= STATE_INTERSINGLE
;
1896 g_Game_ExecuteEvent('oninter');
1899 DecMin(EndingGameCounter
, 6, 0);
1902 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1904 if gMapOnce
then // Ýòî áûë òåñò
1906 gExit
:= EXIT_SIMPLE
;
1912 g_Serverlist_Control(slCurrent
, slTable
);
1915 // Ñòàòèñòèêà ïî Tab:
1917 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1920 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1922 // Âðåìÿ += 28 ìèëëèñåêóíä:
1923 gTime
:= gTime
+ GAME_TICK
;
1925 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1926 if MessageTime
= 0 then
1928 if MessageTime
> 0 then
1929 MessageTime
:= MessageTime
- 1;
1931 if (g_Game_IsServer
) then
1933 // Áûë çàäàí ëèìèò âðåìåíè:
1934 if (gGameSettings
.TimeLimit
> 0) then
1935 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1936 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1941 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1942 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1943 g_Game_RestartRound(gLMSSoftSpawn
);
1945 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1946 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1948 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1950 g_Console_Process(gVoteCommand
);
1952 gVotePassed
:= False;
1955 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1956 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1957 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1958 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1959 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1961 // Áûë çàäàí ëèìèò ïîáåä:
1962 if (gGameSettings
.GoalLimit
> 0) then
1966 if gGameSettings
.GameMode
= GM_DM
then
1967 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1968 for i
:= 0 to High(gPlayers
) do
1969 if gPlayers
[i
] <> nil then
1970 if gPlayers
[i
].Frags
> b
then
1971 b
:= gPlayers
[i
].Frags
;
1974 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1975 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1976 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1979 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1980 if b
>= gGameSettings
.GoalLimit
then
1987 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1988 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1989 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1990 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1992 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1993 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1994 end // if not console
1997 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1999 // process weapon switch queue
2003 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2004 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2006 if not gSpectKeyPress
then
2008 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2010 // switch spect mode
2012 SPECT_NONE
: ; // not spectator
2014 SPECT_MAPVIEW
: Inc(gSpectMode
);
2015 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2017 gSpectKeyPress
:= True;
2019 if (gSpectMode
= SPECT_MAPVIEW
)
2020 and (not gSpectAuto
) then
2022 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2023 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2024 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2025 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2026 if gPlayerAction
[0, ACTION_LOOKUP
] then
2027 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2028 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2029 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2030 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2033 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2034 gSpectKeyPress
:= True;
2036 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2039 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2040 gSpectKeyPress
:= True;
2043 if (gSpectMode
= SPECT_PLAYERS
)
2044 and (not gSpectAuto
) then
2046 if gPlayerAction
[0, ACTION_LOOKUP
] then
2049 gSpectViewTwo
:= True;
2050 gSpectKeyPress
:= True;
2052 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2054 // remove second view
2055 gSpectViewTwo
:= False;
2056 gSpectKeyPress
:= True;
2058 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2060 // prev player (view 1)
2061 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2062 gSpectKeyPress
:= True;
2064 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2066 // next player (view 1)
2067 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2068 gSpectKeyPress
:= True;
2070 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2072 // prev player (view 2)
2073 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2074 gSpectKeyPress
:= True;
2076 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2078 // next player (view 2)
2079 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2080 gSpectKeyPress
:= True;
2083 if gPlayerAction
[0, ACTION_ATTACK
] then
2085 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2088 gSpectAutoNext
:= 0;
2089 gSpectViewTwo
:= False;
2090 gSpectKeyPress
:= True;
2095 gSpectMode
:= SPECT_STATS
;
2096 gSpectAuto
:= False;
2097 gSpectKeyPress
:= True;
2102 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2103 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2104 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2105 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2106 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2107 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2108 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2109 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2110 gSpectKeyPress
:= False;
2114 if gSpectMode
= SPECT_MAPVIEW
then
2116 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2118 gSpectAutoNext
:= gTime
2121 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2123 gSpectAutoNext
:= gTime
2127 if gSpectAutoNext
<= gTime
then
2129 if gSpectAutoNext
> 0 then
2131 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2135 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2136 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2137 gSpectAutoStepX
:= Random(9) - 4;
2138 gSpectAutoStepY
:= Random(9) - 4;
2139 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2140 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2141 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2142 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2143 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2144 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2148 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2153 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2154 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2155 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2161 // Îáíîâëÿåì âñå îñòàëüíîå:
2164 g_Triggers_Update();
2166 g_Monsters_Update();
2168 g_Player_UpdateAll();
2169 g_Player_UpdatePhysicalObjects();
2171 // server: send newly spawned monsters unconditionally
2172 if (gGameSettings
.GameType
= GT_SERVER
) then
2174 if (Length(gMonstersSpawned
) > 0) then
2176 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2177 SetLength(gMonstersSpawned
, 0);
2181 if (gSoundTriggerTime
> 8) then
2183 g_Game_UpdateTriggerSounds();
2184 gSoundTriggerTime
:= 0;
2188 Inc(gSoundTriggerTime
);
2191 if (NetMode
= NET_SERVER
) then
2193 Inc(NetTimeToUpdate
);
2194 Inc(NetTimeToReliable
);
2196 // send monster updates
2197 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2199 // send all monsters (periodic sync)
2200 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2202 for I
:= 0 to High(gPlayers
) do
2204 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2207 g_Mons_ForEach(sendMonsPos
);
2209 if reliableUpdate
then
2211 NetTimeToReliable
:= 0;
2212 NetTimeToUpdate
:= NetUpdateRate
;
2216 NetTimeToUpdate
:= 0;
2221 // send only mosters with some unexpected changes
2222 g_Mons_ForEach(sendMonsPosUnexpected
);
2225 // send unexpected platform changes
2226 g_Map_NetSendInterestingPanels();
2228 g_Net_Slist_ServerUpdate();
2230 if NetUseMaster then
2232 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2234 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2236 NetTimeToMaster := gTime + NetMasterRate;
2241 else if (NetMode
= NET_CLIENT
) then
2243 MC_SEND_PlayerPos();
2245 end; // if gameOn ...
2247 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2248 if g_ActiveWindow
<> nil then
2250 w
:= e_GetFirstKeyPressed();
2252 if (w
<> IK_INVALID
) then
2254 Msg
.Msg
:= MESSAGE_DIKEY
;
2256 g_ActiveWindow
.OnMessage(Msg
);
2259 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2260 if g_ActiveWindow
<> nil then
2261 g_ActiveWindow
.Update();
2263 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2264 if gResolutionChange
then
2266 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2267 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2268 gResolutionChange
:= False;
2269 g_ActiveWindow
:= nil;
2272 // Íóæíî ñìåíèòü ÿçûê:
2273 if gLanguageChange
then
2275 //e_WriteLog('Read language file', MSG_NOTIFY);
2276 //g_Language_Load(DataDir + gLanguage + '.txt');
2277 g_Language_Set(gLanguage
);
2281 gLanguageChange
:= False;
2285 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2286 if e_KeyPressed(IK_F10
) and
2288 (not gConsoleShow
) and
2289 (g_ActiveWindow
= nil) then
2294 Time
:= sys_GetTicks() {div 1000};
2296 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2297 if gDelayedEvents
<> nil then
2298 for a
:= 0 to High(gDelayedEvents
) do
2299 if gDelayedEvents
[a
].Pending
and
2301 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2302 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2305 case gDelayedEvents
[a
].DEType
of
2307 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2310 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2314 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2315 if g_Game_IsNet
and g_Game_IsServer
then
2316 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2320 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2322 gDelayedEvents
[a
].Pending
:= False;
2325 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2326 UPSCounter
:= UPSCounter
+ 1;
2327 if Time
- UPSTime
>= 1000 then
2336 g_Weapon_AddDynLights();
2337 g_Items_AddDynLights();
2341 procedure g_Game_LoadChatSounds(Resource
: string);
2344 FileName
, Snd
: string;
2346 len
, cnt
, tags
, i
, j
: Integer;
2349 FileName
:= g_ExtractWadName(Resource
);
2351 WAD
:= TWADFile
.Create();
2352 WAD
.ReadFile(FileName
);
2354 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2361 cfg
:= TConfig
.CreateMem(p
, len
);
2362 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2364 SetLength(gChatSounds
, cnt
);
2365 for i
:= 0 to Length(gChatSounds
) - 1 do
2367 gChatSounds
[i
].Sound
:= nil;
2368 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2369 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2370 if (Snd
= '') or (Tags
<= 0) then
2372 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2373 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2374 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2375 SetLength(gChatSounds
[i
].Tags
, tags
);
2376 for j
:= 0 to tags
- 1 do
2377 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2378 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2385 procedure g_Game_FreeChatSounds();
2389 for i
:= 0 to Length(gChatSounds
) - 1 do
2391 gChatSounds
[i
].Sound
.Free();
2392 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2394 SetLength(gChatSounds
, 0);
2398 procedure g_Game_LoadData();
2405 if DataLoaded
then Exit
;
2407 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2409 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2410 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2411 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2412 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2413 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2414 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2415 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2416 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2417 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2418 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2419 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2420 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2421 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2422 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2423 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2426 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2427 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2428 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2429 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2433 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2434 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2435 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2436 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2437 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
2443 hasPBarGfx
:= false;
2447 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2448 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2449 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2450 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2451 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2452 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2453 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2454 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2455 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2456 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2457 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2458 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2459 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2460 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2461 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2462 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2463 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2464 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2465 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2466 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2467 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2472 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2473 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2474 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2475 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2476 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2477 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2478 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2479 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2480 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2481 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2482 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2483 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2484 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2485 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2487 goodsnd
[0] := TPlayableSound
.Create();
2488 goodsnd
[1] := TPlayableSound
.Create();
2489 goodsnd
[2] := TPlayableSound
.Create();
2490 goodsnd
[3] := TPlayableSound
.Create();
2492 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2493 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2494 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2495 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2497 killsnd
[0] := TPlayableSound
.Create();
2498 killsnd
[1] := TPlayableSound
.Create();
2499 killsnd
[2] := TPlayableSound
.Create();
2500 killsnd
[3] := TPlayableSound
.Create();
2502 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2503 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2504 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2505 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2507 hahasnd
[0] := TPlayableSound
.Create();
2508 hahasnd
[1] := TPlayableSound
.Create();
2509 hahasnd
[2] := TPlayableSound
.Create();
2511 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2512 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2513 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2515 sound_get_flag
[0] := TPlayableSound
.Create();
2516 sound_get_flag
[1] := TPlayableSound
.Create();
2517 sound_lost_flag
[0] := TPlayableSound
.Create();
2518 sound_lost_flag
[1] := TPlayableSound
.Create();
2519 sound_ret_flag
[0] := TPlayableSound
.Create();
2520 sound_ret_flag
[1] := TPlayableSound
.Create();
2521 sound_cap_flag
[0] := TPlayableSound
.Create();
2522 sound_cap_flag
[1] := TPlayableSound
.Create();
2524 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2525 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2526 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2527 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2528 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2529 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2530 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2531 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2533 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2535 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2538 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2539 g_Weapon_LoadData();
2541 g_Monsters_LoadData();
2546 procedure g_Game_FreeData();
2548 if not DataLoaded
then Exit
;
2551 g_Weapon_FreeData();
2552 g_Monsters_FreeData();
2554 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2556 g_Texture_Delete('NOTEXTURE');
2557 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2558 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2559 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2560 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2561 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2562 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2563 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2564 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2565 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2566 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2567 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2568 g_Frames_DeleteByName('FRAMES_TELEPORT');
2569 g_Frames_DeleteByName('FRAMES_PUNCH');
2570 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2571 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2572 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2573 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2574 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2575 g_Sound_Delete('SOUND_GAME_TELEPORT');
2576 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2577 g_Sound_Delete('SOUND_GAME_SECRET');
2578 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2579 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2580 g_Sound_Delete('SOUND_GAME_BULK1');
2581 g_Sound_Delete('SOUND_GAME_BULK2');
2582 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2583 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2584 g_Sound_Delete('SOUND_GAME_BURNING');
2585 g_Sound_Delete('SOUND_GAME_SWITCH1');
2586 g_Sound_Delete('SOUND_GAME_SWITCH0');
2593 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2594 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2595 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2596 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2603 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2604 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2605 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2606 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2612 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2613 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2614 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2616 sound_get_flag
[0].Free();
2617 sound_get_flag
[1].Free();
2618 sound_lost_flag
[0].Free();
2619 sound_lost_flag
[1].Free();
2620 sound_ret_flag
[0].Free();
2621 sound_ret_flag
[1].Free();
2622 sound_cap_flag
[0].Free();
2623 sound_cap_flag
[1].Free();
2625 g_Sound_Delete('SOUND_CTF_GET1');
2626 g_Sound_Delete('SOUND_CTF_GET2');
2627 g_Sound_Delete('SOUND_CTF_LOST1');
2628 g_Sound_Delete('SOUND_CTF_LOST2');
2629 g_Sound_Delete('SOUND_CTF_RETURN1');
2630 g_Sound_Delete('SOUND_CTF_RETURN2');
2631 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2632 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2634 g_Game_FreeChatSounds();
2636 DataLoaded
:= False;
2639 procedure DrawCustomStat();
2645 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2646 s1
, s2
, topstr
: String;
2648 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2652 if g_Console_Action(ACTION_SCORES
) then
2654 if not gStatsPressed
then
2656 gStatsOff
:= not gStatsOff
;
2657 gStatsPressed
:= True;
2661 gStatsPressed
:= False;
2665 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2666 w
:= (Length(s1
) * ww2
) div 2;
2667 x
:= gScreenWidth
div 2 - w
;
2669 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2673 if (gGameSettings
.GameMode
= GM_COOP
) then
2675 if gMissionFailed
then
2676 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2678 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2681 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2683 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2684 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2686 if g_Game_IsNet
then
2688 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2689 if not gChatShow
then
2690 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2691 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2694 if g_Game_IsClient
then
2695 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2697 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2698 if not gChatShow
then
2699 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2700 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2705 w
:= gScreenWidth
-x
*2;
2711 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2712 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2714 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2716 case CustomStat
.GameMode
of
2719 if gGameSettings
.MaxLives
= 0 then
2720 s1
:= _lc
[I_GAME_DM
]
2722 s1
:= _lc
[I_GAME_LMS
];
2726 if gGameSettings
.MaxLives
= 0 then
2727 s1
:= _lc
[I_GAME_TDM
]
2729 s1
:= _lc
[I_GAME_TLMS
];
2731 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2734 if gGameSettings
.MaxLives
= 0 then
2735 s1
:= _lc
[I_GAME_COOP
]
2737 s1
:= _lc
[I_GAME_SURV
];
2743 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2747 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2748 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2751 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2752 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2753 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2754 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2756 pc
:= Length(CustomStat
.PlayerStat
);
2757 if pc
= 0 then Exit
;
2759 if CustomStat
.GameMode
= GM_COOP
then
2761 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2763 s2
:= _lc
[I_GAME_MONSTERS
];
2764 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2765 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2767 s2
:= _lc
[I_GAME_SECRETS
];
2768 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2769 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2772 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2774 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2775 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2776 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2778 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2779 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2780 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2784 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2789 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2790 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2791 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2793 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2796 for t
:= TEAM_RED
to TEAM_BLUE
do
2798 if t
= TEAM_RED
then
2800 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2801 gStdFont
, 255, 0, 0, 1);
2802 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2803 gStdFont
, 255, 0, 0, 1);
2810 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2811 gStdFont
, 0, 0, 255, 1);
2812 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2813 gStdFont
, 0, 0, 255, 1);
2819 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2822 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2823 if CustomStat
.PlayerStat
[p
].Team
= t
then
2824 with CustomStat
.PlayerStat
[p
] do
2838 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2839 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2841 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2842 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2843 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2850 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2853 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2854 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2855 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2858 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2859 with CustomStat
.PlayerStat
[p
] do
2861 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2868 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2869 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2871 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2872 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2873 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2878 // HACK: take stats screenshot immediately after the first frame of the stats showing
2879 if gScreenshotStats
and not StatShotDone
then
2881 g_TakeScreenShot('stats/' + StatFilename
);
2882 StatShotDone
:= True;
2886 procedure DrawSingleStat();
2888 tm
, key_x
, val_x
, y
: Integer;
2892 procedure player_stat(n
: Integer);
2898 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2899 s2
:= Format(' %d', [gTotalMonsters
]);
2901 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2902 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2903 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2904 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2906 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2907 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2909 // "Kills-per-minute: ##.#":
2910 s1
:= _lc
[I_MENU_INTER_KPM
];
2912 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2914 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2915 s2
:= Format(' %.1f', [kpm
]);
2917 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2918 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2920 // "Secrets found: # / #":
2921 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2922 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2924 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2925 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2926 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2927 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2929 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2930 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2934 // "Level Complete":
2935 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2936 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2938 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2939 s1
:= _lc
[I_MENU_INTER_KPM
];
2940 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2943 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2945 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2946 val_x
:= key_x
+ w1
;
2949 tm
:= SingleStat
.GameTime
div 1000;
2950 s1
:= _lc
[I_MENU_INTER_TIME
];
2951 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2953 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2954 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2956 if SingleStat
.TwoPlayers
then
2959 s1
:= _lc
[I_MENU_PLAYER_1
];
2960 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2961 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2963 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2968 s1
:= _lc
[I_MENU_PLAYER_2
];
2969 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2970 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2972 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2978 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2984 procedure DrawLoadingStat();
2985 procedure drawRect (x
, y
, w
, h
: Integer);
2987 if (w
< 1) or (h
< 1) then exit
;
2989 glVertex2f(x
+0.375, y
+0.375);
2990 glVertex2f(x
+w
+0.375, y
+0.375);
2991 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2992 glVertex2f(x
+0.375, y
+h
+0.375);
2996 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2998 rectW
, rectH
: Integer;
3005 idl
, idr
, idb
, idm
: LongWord;
3009 if (total
< 1) then exit
;
3010 if (cur
< 1) then exit
; // don't blink
3011 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3012 //if (cur < 0) then cur := 0;
3013 //if (cur > total) then cur := total;
3016 if (hasPBarGfx
) then
3018 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3019 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3020 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3021 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3022 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3023 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3024 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3025 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3027 //rectW := gScreenWidth-360;
3028 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3031 x0
:= (gScreenWidth
-rectW
) div 2;
3032 y0
:= gScreenHeight
-rectH
-64;
3033 if (y0
< 2) then y0
:= 2;
3035 glEnable(GL_SCISSOR_TEST
);
3038 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3039 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3040 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3043 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3045 while (f
< x0
+rectW
) do
3047 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3052 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3053 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3056 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3057 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3061 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3067 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3071 rectW
:= gScreenWidth
-64;
3074 x0
:= (gScreenWidth
-rectW
) div 2;
3075 y0
:= gScreenHeight
-rectH
-64;
3076 if (y0
< 2) then y0
:= 2;
3078 glDisable(GL_BLEND
);
3079 glDisable(GL_TEXTURE_2D
);
3081 //glClearColor(0, 0, 0, 0);
3082 //glClear(GL_COLOR_BUFFER_BIT);
3084 glColor4ub(127, 127, 127, 255);
3085 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3087 glColor4ub(0, 0, 0, 255);
3088 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3090 glColor4ub(127, 127, 127, 255);
3091 wdt
:= rectW
*cur
div total
;
3092 if (wdt
> rectW
) then wdt
:= rectW
;
3093 drawRect(x0
, y0
, wdt
, rectH
);
3102 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3104 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3105 yy
:= (gScreenHeight
div 3);
3106 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3107 xx
:= (gScreenWidth
div 3);
3111 for i
:= 0 to NextMsg
-1 do
3113 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3114 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3118 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3119 yy
:= yy
+ LOADING_INTERLINE
;
3120 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3125 procedure DrawMenuBackground(tex
: AnsiString);
3131 if g_Texture_Get(tex
, ID
) then
3133 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3134 e_GetTextureSize(ID
, @w
, @h
);
3136 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3138 w
:= trunc(w
* (gScreenHeight
/ h
));
3139 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3141 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3144 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3146 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3148 function monDraw (mon
: TMonster
): Boolean;
3150 result
:= false; // don't stop
3155 // Ëåâûé âåðõíèé óãîë
3156 aX
:= Obj
.X
div ScaleSz
+ 1;
3157 aY
:= Obj
.Y
div ScaleSz
+ 1;
3159 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3160 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3161 // Ïðàâûé íèæíèé óãîë
3162 aX2
:= aX
+ aX2
- 1;
3163 aY2
:= aY
+ aY2
- 1;
3164 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3170 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3171 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3174 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3175 ScaleSz
:= 16 div Scale
;
3176 // Ðàçìåðû ìèíè-êàðòû:
3177 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3178 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3180 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3182 if gWalls
<> nil then
3185 for a
:= 0 to High(gWalls
) do
3187 if PanelType
<> 0 then
3189 // Ëåâûé âåðõíèé óãîë:
3190 aX
:= X
div ScaleSz
;
3191 aY
:= Y
div ScaleSz
;
3193 aX2
:= max(Width
div ScaleSz
, 1);
3194 aY2
:= max(Height
div ScaleSz
, 1);
3195 // Ïðàâûé íèæíèé óãîë:
3196 aX2
:= aX
+ aX2
- 1;
3197 aY2
:= aY
+ aY2
- 1;
3200 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3201 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3202 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3206 if gSteps
<> nil then
3209 for a
:= 0 to High(gSteps
) do
3211 if PanelType
<> 0 then
3213 // Ëåâûé âåðõíèé óãîë:
3214 aX
:= X
div ScaleSz
;
3215 aY
:= Y
div ScaleSz
;
3217 aX2
:= max(Width
div ScaleSz
, 1);
3218 aY2
:= max(Height
div ScaleSz
, 1);
3219 // Ïðàâûé íèæíèé óãîë:
3220 aX2
:= aX
+ aX2
- 1;
3221 aY2
:= aY
+ aY2
- 1;
3223 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3226 if gLifts
<> nil then
3229 for a
:= 0 to High(gLifts
) do
3231 if PanelType
<> 0 then
3233 // Ëåâûé âåðõíèé óãîë:
3234 aX
:= X
div ScaleSz
;
3235 aY
:= Y
div ScaleSz
;
3237 aX2
:= max(Width
div ScaleSz
, 1);
3238 aY2
:= max(Height
div ScaleSz
, 1);
3239 // Ïðàâûé íèæíèé óãîë:
3240 aX2
:= aX
+ aX2
- 1;
3241 aY2
:= aY
+ aY2
- 1;
3244 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3245 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3246 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3247 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3251 if gWater
<> nil then
3254 for a
:= 0 to High(gWater
) do
3256 if PanelType
<> 0 then
3258 // Ëåâûé âåðõíèé óãîë:
3259 aX
:= X
div ScaleSz
;
3260 aY
:= Y
div ScaleSz
;
3262 aX2
:= max(Width
div ScaleSz
, 1);
3263 aY2
:= max(Height
div ScaleSz
, 1);
3264 // Ïðàâûé íèæíèé óãîë:
3265 aX2
:= aX
+ aX2
- 1;
3266 aY2
:= aY
+ aY2
- 1;
3268 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3271 if gAcid1
<> nil then
3273 // Ðèñóåì êèñëîòó 1:
3274 for a
:= 0 to High(gAcid1
) do
3276 if PanelType
<> 0 then
3278 // Ëåâûé âåðõíèé óãîë:
3279 aX
:= X
div ScaleSz
;
3280 aY
:= Y
div ScaleSz
;
3282 aX2
:= max(Width
div ScaleSz
, 1);
3283 aY2
:= max(Height
div ScaleSz
, 1);
3284 // Ïðàâûé íèæíèé óãîë:
3285 aX2
:= aX
+ aX2
- 1;
3286 aY2
:= aY
+ aY2
- 1;
3288 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3291 if gAcid2
<> nil then
3293 // Ðèñóåì êèñëîòó 2:
3294 for a
:= 0 to High(gAcid2
) do
3296 if PanelType
<> 0 then
3298 // Ëåâûé âåðõíèé óãîë:
3299 aX
:= X
div ScaleSz
;
3300 aY
:= Y
div ScaleSz
;
3302 aX2
:= max(Width
div ScaleSz
, 1);
3303 aY2
:= max(Height
div ScaleSz
, 1);
3304 // Ïðàâûé íèæíèé óãîë:
3305 aX2
:= aX
+ aX2
- 1;
3306 aY2
:= aY
+ aY2
- 1;
3308 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3311 if gPlayers
<> nil then
3314 for a
:= 0 to High(gPlayers
) do
3315 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3317 // Ëåâûé âåðõíèé óãîë:
3318 aX
:= Obj
.X
div ScaleSz
+ 1;
3319 aY
:= Obj
.Y
div ScaleSz
+ 1;
3321 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3322 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3323 // Ïðàâûé íèæíèé óãîë:
3324 aX2
:= aX
+ aX2
- 1;
3325 aY2
:= aY
+ aY2
- 1;
3327 if gPlayers
[a
] = p
then
3328 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3331 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3332 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3333 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3338 g_Mons_ForEach(monDraw
);
3343 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3345 if not hasAmbient
then exit
;
3346 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3350 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3351 //FIXME: broken for splitscreen mode
3352 procedure renderDynLightsInternal ();
3354 //hasAmbient: Boolean;
3355 //ambColor: TDFColor;
3357 lx
, ly
, lrad
: Integer;
3358 scxywh
: array[0..3] of GLint
;
3361 if e_NoGraphics
then exit
;
3363 //TODO: lights should be in separate grid, i think
3364 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3365 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3368 //ambColor := gCurrentMap['light_ambient'].rgba;
3369 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3371 { // this will multiply incoming color to alpha from framebuffer
3373 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3377 * light rendering: (INVALID!)
3378 * glStencilFunc(GL_EQUAL, 0, $ff);
3380 * glClear(GL_STENCIL_BUFFER_BIT);
3381 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3382 * draw shadow volume into stencil buffer
3383 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3384 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3386 * draw color-less quad with light alpha (WARNING! don't touch color!)
3387 * glEnable(GL_BLEND);
3388 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3389 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3391 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3392 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3394 // setup OpenGL parameters
3395 glStencilMask($FFFFFFFF);
3396 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3397 glEnable(GL_STENCIL_TEST
);
3398 glEnable(GL_SCISSOR_TEST
);
3399 glClear(GL_STENCIL_BUFFER_BIT
);
3400 glStencilFunc(GL_EQUAL
, 0, $ff);
3402 for lln
:= 0 to g_dynLightCount
-1 do
3404 lx
:= g_dynLights
[lln
].x
;
3405 ly
:= g_dynLights
[lln
].y
;
3406 lrad
:= g_dynLights
[lln
].radius
;
3407 if (lrad
< 3) then continue
;
3409 if (lx
-sX
+lrad
< 0) then continue
;
3410 if (ly
-sY
+lrad
< 0) then continue
;
3411 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3412 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3414 // set scissor to optimize drawing
3415 if (g_dbg_scale
= 1.0) then
3417 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3421 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3423 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3424 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3425 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3426 // draw extruded panels
3427 glDisable(GL_TEXTURE_2D
);
3428 glDisable(GL_BLEND
);
3429 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3430 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3431 // render light texture
3432 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3433 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3436 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3437 glEnable(GL_TEXTURE_2D
);
3438 // color and opacity
3439 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3440 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3442 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3443 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3444 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3445 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3450 glDisable(GL_STENCIL_TEST
);
3451 glDisable(GL_BLEND
);
3452 glDisable(GL_SCISSOR_TEST
);
3453 //glScissor(0, 0, sWidth, sHeight);
3455 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3456 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3460 function fixViewportForScale (): Boolean;
3462 nx0
, ny0
, nw
, nh
: Integer;
3465 if (g_dbg_scale
<> 1.0) then
3468 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3469 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3470 nw
:= round(sWidth
/g_dbg_scale
);
3471 nh
:= round(sHeight
/g_dbg_scale
);
3480 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3481 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3482 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3484 TDrawCB
= procedure ();
3487 hasAmbient
: Boolean;
3489 doAmbient
: Boolean = false;
3491 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3496 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3497 if gdbg_map_use_accel_render
then
3499 tagmask
:= panelTypeToTag(panType
);
3500 while (gDrawPanelList
.count
> 0) do
3502 pan
:= TPanel(gDrawPanelList
.front());
3503 if ((pan
.tag
and tagmask
) = 0) then break
;
3504 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3505 gDrawPanelList
.popFront();
3510 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3512 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3515 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3517 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3518 if assigned(cb
) then cb();
3519 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3523 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3525 // our accelerated renderer will collect all panels to gDrawPanelList
3526 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3527 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3528 if gdbg_map_use_accel_render
then
3530 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3532 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3534 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3535 g_Map_DrawBack(backXOfs
, backYOfs
);
3536 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3538 if setTransMatrix
then
3540 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3541 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3542 glTranslatef(-sX
, -sY
, 0);
3546 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3547 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3552 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3553 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3554 glClear(GL_COLOR_BUFFER_BIT);
3557 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3560 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3561 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3562 drawOther('items', @g_Items_Draw
);
3563 drawOther('weapons', @g_Weapon_Draw
);
3564 drawOther('shells', @g_Player_DrawShells
);
3565 drawOther('drawall', @g_Player_DrawAll
);
3566 drawOther('corpses', @g_Player_DrawCorpses
);
3567 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3568 drawOther('monsters', @g_Monsters_Draw
);
3569 drawOther('itemdrop', @g_Items_DrawDrop
);
3570 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3571 drawOther('gfx', @g_GFX_Draw
);
3572 drawOther('flags', @g_Map_DrawFlags
);
3573 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3574 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3575 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3576 drawOther('dynlights', @renderDynLightsInternal
);
3578 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3580 renderAmbientQuad(hasAmbient
, ambColor
);
3584 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3587 if g_debug_HealthBar
then
3589 g_Monsters_DrawHealth();
3590 g_Player_DrawHealth();
3593 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3597 procedure DrawMapView(x
, y
, w
, h
: Integer);
3604 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3605 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3612 fixViewportForScale();
3613 renderMapInternal(-bx
, -by
, true);
3619 procedure DrawPlayer(p
: TPlayer
);
3621 px
, py
, a
, b
, c
, d
, i
: Integer;
3624 if (p
= nil) or (p
.FDummy
) then
3627 g_Map_DrawBack(0, 0);
3632 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3633 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3639 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3640 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3642 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3644 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3645 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3647 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3648 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3650 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3651 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3654 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3657 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3658 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3661 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3666 // scaled, ignore level bounds
3667 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3668 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3671 if p
.IncCam
<> 0 then
3673 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3675 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3677 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3681 if py
< gPlayerScreenSize
.Y
div 2 then
3683 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3685 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3689 if p
.IncCam
< 0 then
3691 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3694 if p
.IncCam
> 0 then
3696 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3700 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3701 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3702 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3704 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3705 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3706 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3709 sY
:= -(b
+p
.IncCam
);
3710 sWidth
:= gPlayerScreenSize
.X
;
3711 sHeight
:= gPlayerScreenSize
.Y
;
3713 //glTranslatef(a, b+p.IncCam, 0);
3715 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3717 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3718 fixViewportForScale();
3719 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3721 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3723 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3724 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3725 if (sX
< 0) then sX
:= 0;
3726 if (sY
< 0) then sY
:= 0;
3728 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3729 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3732 //r_smallmap_h: 0: left; 1: center; 2: right
3733 //r_smallmap_v: 0: top; 1: center; 2: bottom
3735 if (gMapInfo
.Width
= sWidth
) then
3739 else if (gMapInfo
.Width
< sWidth
) then
3741 case r_smallmap_h
of
3742 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3743 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3744 else sX
:= 0; // left
3748 if (gMapInfo
.Height
= sHeight
) then
3752 else if (gMapInfo
.Height
< sHeight
) then
3754 case r_smallmap_v
of
3755 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3756 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3757 else sY
:= 0; // top
3763 p
.viewPortW
:= sWidth
;
3764 p
.viewPortH
:= sHeight
;
3766 {$IFDEF ENABLE_HOLMES}
3767 if (p
= gPlayer1
) then
3769 g_Holmes_plrViewPos(sX
, sY
);
3770 g_Holmes_plrViewSize(sWidth
, sHeight
);
3774 renderMapInternal(-c
, -d
, true);
3776 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3777 case gPlayerIndicator
of
3779 p
.DrawIndicator(_RGB(255, 255, 255));
3782 for i
:= 0 to High(gPlayers
) do
3783 if gPlayers
[i
] <> nil then
3784 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3785 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3786 if gPlayerIndicatorStyle
= 1 then
3787 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3788 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3791 if p
.FSpectator
then
3792 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3793 p
.GameY
+ PLAYER_RECT_CY
- 4,
3794 'X', gStdFont
, 255, 255, 255, 1, True);
3796 for a := 0 to High(gCollideMap) do
3797 for b := 0 to High(gCollideMap[a]) do
3800 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3802 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3806 1: e_DrawPoint(1, b, a, 200, 200, 200);
3807 2: e_DrawPoint(1, b, a, 64, 64, 255);
3808 3: e_DrawPoint(1, b, a, 255, 0, 255);
3818 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3819 if g_Debug_Player
then
3820 g_Player_DrawDebug(p
);
3824 procedure drawProfilers ();
3829 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3830 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3831 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3834 procedure g_Game_Draw();
3841 plView1
, plView2
: TPlayer
;
3844 if gExit
= EXIT_QUIT
then Exit
;
3846 Time
:= sys_GetTicks() {div 1000};
3847 FPSCounter
:= FPSCounter
+1;
3848 if Time
- FPSTime
>= 1000 then
3855 if gGameOn
or (gState
= STATE_FOLD
) then
3857 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3859 gSpectMode
:= SPECT_NONE
;
3860 if not gRevertPlayers
then
3862 plView1
:= gPlayer1
;
3863 plView2
:= gPlayer2
;
3867 plView1
:= gPlayer2
;
3868 plView2
:= gPlayer1
;
3872 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3874 gSpectMode
:= SPECT_NONE
;
3875 if gPlayer2
= nil then
3878 plView1
:= gPlayer2
;
3887 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3888 gSpectMode
:= SPECT_STATS
;
3890 if gSpectMode
= SPECT_PLAYERS
then
3891 if gPlayers
<> nil then
3893 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3894 if plView1
= nil then
3896 gSpectPID1
:= GetActivePlayerID_Next();
3897 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3899 if gSpectViewTwo
then
3901 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3902 if plView2
= nil then
3904 gSpectPID2
:= GetActivePlayerID_Next();
3905 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3910 if gSpectMode
= SPECT_MAPVIEW
then
3912 // Ðåæèì ïðîñìîòðà êàðòû
3914 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3915 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3916 gHearPoint1
.Active
:= True;
3917 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3918 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3919 gHearPoint2
.Active
:= False;
3923 Split
:= (plView1
<> nil) and (plView2
<> nil);
3925 // Òî÷êè ñëóõà èãðîêîâ
3926 if plView1
<> nil then
3928 gHearPoint1
.Active
:= True;
3929 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3930 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3932 gHearPoint1
.Active
:= False;
3933 if plView2
<> nil then
3935 gHearPoint2
.Active
:= True;
3936 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3937 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3939 gHearPoint2
.Active
:= False;
3941 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3942 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3945 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3946 if gScreenHeight
mod 2 = 0 then
3947 Dec(gPlayerScreenSize
.Y
);
3950 gPlayerScreenSize
.Y
:= gScreenHeight
;
3953 if gScreenHeight
mod 2 = 0 then
3954 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3956 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3958 DrawPlayer(plView1
);
3959 gPlayer1ScreenCoord
.X
:= sX
;
3960 gPlayer1ScreenCoord
.Y
:= sY
;
3964 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3966 DrawPlayer(plView2
);
3967 gPlayer2ScreenCoord
.X
:= sX
;
3968 gPlayer2ScreenCoord
.Y
:= sY
;
3971 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3974 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3977 {$IFDEF ENABLE_HOLMES}
3979 if (g_holmes_enabled
) then g_Holmes_Draw();
3982 if MessageText
<> '' then
3986 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3988 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3989 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3991 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3992 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3995 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3997 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3999 // Draw spectator GUI
4002 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4005 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4007 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4009 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4011 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4012 if gSpectMode
= SPECT_STATS
then
4014 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4015 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4017 if gSpectMode
= SPECT_MAPVIEW
then
4019 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4020 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4022 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4023 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4025 if gSpectMode
= SPECT_PLAYERS
then
4027 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4028 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4029 if gSpectViewTwo
then
4031 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4032 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4033 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4034 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4038 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4039 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4045 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4047 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4048 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4050 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4051 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4052 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4057 if (gState
= STATE_MENU
) then
4059 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4060 // F3 at menu will show game loading dialog
4061 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4062 if (g_ActiveWindow
<> nil) then
4064 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4065 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4069 // F3 at titlepic will show game loading dialog
4070 if e_KeyPressed(IK_F3
) then
4072 g_Menu_Show_LoadMenu(true);
4073 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4078 if gState
= STATE_FOLD
then
4080 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4083 if gState
= STATE_INTERCUSTOM
then
4085 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4087 back
:= 'TEXTURE_endpic';
4088 if not g_Texture_Get(back
, ID
) then
4089 back
:= _lc
[I_TEXTURE_ENDPIC
];
4094 DrawMenuBackground(back
);
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 if gState
= STATE_INTERSINGLE
then
4107 if EndingGameCounter
> 0 then
4109 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4115 DrawMenuBackground(back
);
4119 if g_ActiveWindow
<> nil then
4121 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4122 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4127 if gState
= STATE_ENDPIC
then
4130 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4131 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4133 if g_ActiveWindow
<> nil then
4135 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4136 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4140 if gState
= STATE_SLIST
then
4142 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4144 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4145 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4147 DrawMenuBackground('MENU_BACKGROUND');
4148 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4149 g_Serverlist_Draw(slCurrent
, slTable
);
4153 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);
4160 g_ActiveWindow
.Draw();
4167 if g_debug_Sounds
and gGameOn
then
4169 for w
:= 0 to High(e_SoundsArray
) do
4170 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4171 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4176 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4177 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4180 if gGameOn
and gShowTime
then
4181 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4183 if gGameOn
then drawProfilers();
4185 {$IFDEF ENABLE_HOLMES}
4192 procedure g_Game_Quit();
4194 g_Game_StopAllSounds(True);
4197 g_PlayerModel_FreeData();
4198 g_Texture_DeleteAll();
4199 g_Frames_DeleteAll();
4201 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4204 if NetInitDone
then g_Net_Free
;
4206 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4207 if gMapToDelete
<> '' then
4208 g_Game_DeleteTestMap();
4214 procedure g_FatalError(Text: String);
4216 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4217 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4219 gExit
:= EXIT_SIMPLE
;
4222 procedure g_SimpleError(Text: String);
4224 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4225 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4228 procedure g_Game_SetupScreenSize();
4230 RES_FACTOR
= 4.0 / 3.0;
4236 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4237 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4238 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4239 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4241 gPlayerScreenSize
.Y
:= gScreenHeight
;
4243 // Ðàçìåð çàäíåãî ïëàíà:
4244 if BackID
<> DWORD(-1) then
4247 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4248 (gScreenHeight
*s
> gMapInfo
.Height
) then
4250 gBackSize
.X
:= gScreenWidth
;
4251 gBackSize
.Y
:= gScreenHeight
;
4255 e_GetTextureSize(BackID
, @bw
, @bh
);
4256 rf
:= Single(bw
) / Single(bh
);
4257 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4258 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4259 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4260 if (s
< 1.0) then s
:= 1.0;
4261 gBackSize
.X
:= Round(bw
*s
);
4262 gBackSize
.Y
:= Round(bh
*s
);
4267 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4269 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4272 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4274 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4275 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4277 if gPlayer1
= nil then
4279 if g_Game_IsClient
then
4281 if NetPlrUID1
> -1 then
4283 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4284 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4289 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4290 Team
:= gPlayer1Settings
.Team
;
4292 // Ñîçäàíèå ïåðâîãî èãðîêà:
4293 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4294 gPlayer1Settings
.Color
,
4296 if gPlayer1
= nil then
4297 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4300 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4301 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4302 if g_Game_IsServer
and g_Game_IsNet
then
4303 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4304 gPlayer1
.Respawn(False, True);
4305 g_Net_Slist_ServerPlayerComes();
4310 if gPlayer2
= nil then
4312 if g_Game_IsClient
then
4314 if NetPlrUID2
> -1 then
4315 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4319 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4320 Team
:= gPlayer2Settings
.Team
;
4322 // Ñîçäàíèå âòîðîãî èãðîêà:
4323 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4324 gPlayer2Settings
.Color
,
4326 if gPlayer2
= nil then
4327 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4330 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4331 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4332 if g_Game_IsServer
and g_Game_IsNet
then
4333 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4334 gPlayer2
.Respawn(False, True);
4335 g_Net_Slist_ServerPlayerComes();
4342 procedure g_Game_RemovePlayer();
4346 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4347 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4352 if g_Game_IsServer
then
4355 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4356 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4357 g_Player_Remove(Pl
.UID
);
4358 g_Net_Slist_ServerPlayerLeaves();
4366 if g_Game_IsServer
then
4369 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4370 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4371 g_Player_Remove(Pl
.UID
);
4372 g_Net_Slist_ServerPlayerLeaves();
4376 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4380 g_Net_Slist_ServerPlayerLeaves();
4383 procedure g_Game_Spectate();
4385 g_Game_RemovePlayer();
4386 if gPlayer1
<> nil then
4387 g_Game_RemovePlayer();
4390 procedure g_Game_SpectateCenterView();
4392 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4393 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4396 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4403 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4405 g_Game_ClearLoading();
4408 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4411 gGameSettings
.GameType
:= GT_SINGLE
;
4412 gGameSettings
.MaxLives
:= 0;
4413 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4414 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4415 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4416 gSwitchGameMode
:= GM_SINGLE
;
4418 g_Game_ExecuteEvent('ongamestart');
4420 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4421 g_Game_SetupScreenSize();
4423 // Ñîçäàíèå ïåðâîãî èãðîêà:
4424 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4425 gPlayer1Settings
.Color
,
4426 gPlayer1Settings
.Team
, False));
4427 if gPlayer1
= nil then
4429 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4433 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4436 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4439 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4440 gPlayer2Settings
.Color
,
4441 gPlayer2Settings
.Team
, False));
4442 if gPlayer2
= nil then
4444 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4448 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4452 // Çàãðóçêà è çàïóñê êàðòû:
4453 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4455 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4456 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4460 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4464 for i
:= nPl
+1 to nPlayers
do
4465 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4468 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4469 TimeLimit
, GoalLimit
: Word;
4471 Options
: LongWord; nPlayers
: Byte);
4477 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4479 g_Game_ClearLoading();
4482 gGameSettings
.GameType
:= GT_CUSTOM
;
4483 gGameSettings
.GameMode
:= GameMode
;
4484 gSwitchGameMode
:= GameMode
;
4485 gGameSettings
.TimeLimit
:= TimeLimit
;
4486 gGameSettings
.GoalLimit
:= GoalLimit
;
4487 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4488 gGameSettings
.Options
:= Options
;
4490 gCoopTotalMonstersKilled
:= 0;
4491 gCoopTotalSecretsFound
:= 0;
4492 gCoopTotalMonsters
:= 0;
4493 gCoopTotalSecrets
:= 0;
4497 g_Game_ExecuteEvent('ongamestart');
4499 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4500 g_Game_SetupScreenSize();
4502 // Ðåæèì íàáëþäàòåëÿ:
4503 if nPlayers
= 0 then
4510 if nPlayers
>= 1 then
4512 // Ñîçäàíèå ïåðâîãî èãðîêà:
4513 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4514 gPlayer1Settings
.Color
,
4515 gPlayer1Settings
.Team
, False));
4516 if gPlayer1
= nil then
4518 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4522 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4526 if nPlayers
>= 2 then
4528 // Ñîçäàíèå âòîðîãî èãðîêà:
4529 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4530 gPlayer2Settings
.Color
,
4531 gPlayer2Settings
.Team
, False));
4532 if gPlayer2
= nil then
4534 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4538 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4542 // Çàãðóçêà è çàïóñê êàðòû:
4543 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4545 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4549 // Íåò òî÷åê ïîÿâëåíèÿ:
4550 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4551 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4552 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4553 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4554 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4556 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4560 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4564 for i
:= nPl
+1 to nPlayers
do
4565 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4568 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4569 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4570 Options
: LongWord; nPlayers
: Byte;
4571 IPAddr
: LongWord; Port
: Word);
4574 g_Net_Slist_ServerClosed();
4576 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4578 g_Game_ClearLoading();
4581 gGameSettings
.GameType
:= GT_SERVER
;
4582 gGameSettings
.GameMode
:= GameMode
;
4583 gSwitchGameMode
:= GameMode
;
4584 gGameSettings
.TimeLimit
:= TimeLimit
;
4585 gGameSettings
.GoalLimit
:= GoalLimit
;
4586 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4587 gGameSettings
.Options
:= Options
;
4589 gCoopTotalMonstersKilled
:= 0;
4590 gCoopTotalSecretsFound
:= 0;
4591 gCoopTotalMonsters
:= 0;
4592 gCoopTotalSecrets
:= 0;
4596 g_Game_ExecuteEvent('ongamestart');
4598 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4599 g_Game_SetupScreenSize();
4601 // Ðåæèì íàáëþäàòåëÿ:
4602 if nPlayers
= 0 then
4608 if nPlayers
>= 1 then
4610 // Ñîçäàíèå ïåðâîãî èãðîêà:
4611 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4612 gPlayer1Settings
.Color
,
4613 gPlayer1Settings
.Team
, False));
4614 if gPlayer1
= nil then
4616 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4620 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4623 if nPlayers
>= 2 then
4625 // Ñîçäàíèå âòîðîãî èãðîêà:
4626 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4627 gPlayer2Settings
.Color
,
4628 gPlayer2Settings
.Team
, False));
4629 if gPlayer2
= nil then
4631 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4635 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4638 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4639 if NetForwardPorts
then
4640 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4643 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4645 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4649 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4651 g_Net_Slist_ServerStarted();
4653 // Çàãðóçêà è çàïóñê êàðòû:
4654 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4656 g_Net_Slist_ServerClosed();
4657 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4661 // Íåò òî÷åê ïîÿâëåíèÿ:
4662 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4663 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4664 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4665 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4666 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4668 g_Net_Slist_ServerClosed();
4669 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4673 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4676 g_Net_Slist_ServerMapStarted();
4677 NetState
:= NET_STATE_GAME
;
4680 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4695 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4696 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4698 g_Game_ClearLoading();
4701 gGameSettings
.GameType
:= GT_CLIENT
;
4703 gCoopTotalMonstersKilled
:= 0;
4704 gCoopTotalSecretsFound
:= 0;
4705 gCoopTotalMonsters
:= 0;
4706 gCoopTotalSecrets
:= 0;
4710 g_Game_ExecuteEvent('ongamestart');
4712 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4713 g_Game_SetupScreenSize();
4715 NetState
:= NET_STATE_AUTH
;
4717 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4719 // create (or update) map/resource databases
4720 g_Res_CreateDatabases(true);
4723 if not g_Net_Connect(Addr
, Port
) then
4725 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4726 NetState
:= NET_STATE_NONE
;
4730 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4732 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4737 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4738 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4739 // thank you, enet. let's ignore failures altogether then.
4740 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4742 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4744 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4746 // ignore all download packets, they're processed by separate code
4747 enet_packet_destroy(NetEvent
.packet
);
4750 Ptr
:= NetEvent
.packet
^.data
;
4751 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4753 enet_packet_destroy(NetEvent
.packet
);
4757 InMsg
.ReadLongWord(); // skip size
4758 MID
:= InMsg
.ReadByte();
4760 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4762 NetMyID
:= InMsg
.ReadByte();
4763 NetPlrUID1
:= InMsg
.ReadWord();
4765 WadName
:= InMsg
.ReadString();
4766 Map
:= InMsg
.ReadString();
4768 gWADHash
:= InMsg
.ReadMD5();
4770 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4771 gSwitchGameMode
:= gGameSettings
.GameMode
;
4772 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4773 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4774 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4775 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4776 T
:= InMsg
.ReadLongWord();
4778 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4779 //if newResPath = '' then
4781 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4782 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4783 if newResPath
= '' then
4785 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4786 enet_packet_destroy(NetEvent
.packet
);
4787 NetState
:= NET_STATE_NONE
;
4790 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4792 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4795 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4796 gPlayer1Settings
.Color
,
4797 gPlayer1Settings
.Team
, False));
4799 if gPlayer1
= nil then
4801 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4803 enet_packet_destroy(NetEvent
.packet
);
4804 NetState
:= NET_STATE_NONE
;
4808 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4809 gPlayer1
.UID
:= NetPlrUID1
;
4810 gPlayer1
.Reset(True);
4812 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4814 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4816 enet_packet_destroy(NetEvent
.packet
);
4817 NetState
:= NET_STATE_NONE
;
4825 enet_packet_destroy(NetEvent
.packet
);
4829 enet_packet_destroy(NetEvent
.packet
);
4833 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4836 if (NetEvent
.data
<= NET_DISC_MAX
) then
4837 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4838 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4845 ProcessLoading(true);
4847 if g_Net_UserRequestExit() then
4856 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4857 NetState
:= NET_STATE_NONE
;
4861 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4862 gLMSRespawnTime
:= 0;
4865 NetState
:= NET_STATE_GAME
;
4866 MC_SEND_FullStateRequest
;
4867 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4871 lastAsMegaWad
: Boolean = false;
4873 procedure g_Game_ChangeMap(const MapPath
: String);
4877 g_Game_ClearLoading();
4879 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4880 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4881 if gExitByTrigger
then
4884 gExitByTrigger
:= False;
4886 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4887 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4890 procedure g_Game_Restart();
4894 if g_Game_IsClient
then
4896 map
:= g_ExtractFileName(gMapInfo
.Map
);
4897 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4901 g_Game_ClearLoading();
4902 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4905 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4907 NewWAD
, ResName
: String;
4911 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4912 g_Player_RemoveAllCorpses();
4914 if (not g_Game_IsClient
) and
4915 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4916 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4918 if gSwitchGameMode
= GM_CTF
then
4919 gGameSettings
.MaxLives
:= 0;
4920 gGameSettings
.GameMode
:= gSwitchGameMode
;
4923 gSwitchGameMode
:= gGameSettings
.GameMode
;
4925 g_Player_ResetTeams();
4927 lastAsMegaWad
:= asMegawad
;
4928 if isWadPath(Map
) then
4930 NewWAD
:= g_ExtractWadName(Map
);
4931 ResName
:= g_ExtractFileName(Map
);
4932 if g_Game_IsServer
then
4934 nws
:= findDiskWad(NewWAD
);
4935 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4938 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4939 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4943 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4944 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4946 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4947 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4949 if (length(nws
) = 0) then
4951 ResName
:= ''; // failed
4956 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4957 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4958 g_Game_LoadWAD(NewWAD
);
4963 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4964 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
4969 NewWAD
:= gGameSettings
.WAD
;
4973 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4975 if (ResName
<> '') and (NewWAD
<> '') then
4977 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4978 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
4982 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4984 gState
:= STATE_NONE
;
4985 g_ActiveWindow
:= nil;
4991 if gGameSettings
.GameMode
= GM_CTF
then
4993 g_Map_ResetFlag(FLAG_RED
);
4994 g_Map_ResetFlag(FLAG_BLUE
);
4995 // CTF, à ôëàãîâ íåò:
4996 if not g_Map_HaveFlagPoints() then
4997 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5002 gState
:= STATE_MENU
;
5007 gPauseMain
:= false;
5008 gPauseHolmes
:= false;
5010 NetTimeToUpdate
:= 1;
5011 NetTimeToReliable
:= 0;
5012 NetTimeToMaster
:= NetMasterRate
;
5013 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5014 gLMSRespawnTime
:= 0;
5015 gMissionFailed
:= False;
5018 gCoopMonstersKilled
:= 0;
5019 gCoopSecretsFound
:= 0;
5021 gVoteInProgress
:= False;
5022 gVotePassed
:= False;
5028 if not gGameOn
then Exit
;
5030 g_Game_SpectateCenterView();
5032 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5034 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5035 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5036 gLMSSoftSpawn
:= True;
5037 if NetMode
= NET_SERVER
then
5038 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
5040 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
5043 if NetMode
= NET_SERVER
then
5045 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5048 g_Net_Slist_ServerMapStarted();
5050 if NetClients
<> nil then
5051 for I
:= 0 to High(NetClients
) do
5052 if NetClients
[I
].Used
then
5054 NetClients
[I
].Voted
:= False;
5055 if NetClients
[I
].RequestedFullUpdate
then
5057 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5058 NetClients
[I
].RequestedFullUpdate
:= False;
5062 g_Net_UnbanNonPermHosts();
5067 gCoopTotalMonstersKilled
:= 0;
5068 gCoopTotalSecretsFound
:= 0;
5069 gCoopTotalMonsters
:= 0;
5070 gCoopTotalSecrets
:= 0;
5074 g_Game_ExecuteEvent('onmapstart');
5077 procedure SetFirstLevel
;
5081 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5082 if MapList
= nil then
5085 SortSArray(MapList
);
5086 gNextMap
:= MapList
[Low(MapList
)];
5091 procedure g_Game_ExitLevel(const Map
: AnsiString);
5095 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5096 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5097 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5098 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5100 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5101 if gGameSettings
.GameType
= GT_SINGLE
then
5102 gExit
:= EXIT_ENDLEVELSINGLE
5103 else // Âûøëè â âûõîä â Ñâîåé èãðå
5105 gExit
:= EXIT_ENDLEVELCUSTOM
;
5106 if gGameSettings
.GameMode
= GM_COOP
then
5107 g_Player_RememberAll
;
5109 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5112 if gGameSettings
.GameMode
= GM_COOP
then
5115 gStatsPressed
:= True;
5116 gNextMap
:= 'MAP01';
5118 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5121 if g_Game_IsNet
then
5123 MH_SEND_GameStats();
5124 MH_SEND_CoopStats();
5130 procedure g_Game_RestartLevel();
5134 if gGameSettings
.GameMode
= GM_SINGLE
then
5139 gExit
:= EXIT_ENDLEVELCUSTOM
;
5140 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5144 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5146 gWAD
{, xwad}: String;
5149 if not g_Game_IsClient
then Exit
;
5150 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5152 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5157 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5161 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5164 g_Game_LoadWAD(NewWAD
);
5168 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5169 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5172 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5173 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5177 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5181 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5182 g_Game_LoadWAD(NewWAD);
5186 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5188 i
, n
, nb
, nr
: Integer;
5190 function monRespawn (mon
: TMonster
): Boolean;
5192 result
:= false; // don't stop
5193 if not mon
.FNoRespawn
then mon
.Respawn();
5197 if not g_Game_IsServer
then Exit
;
5198 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5199 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5200 gLMSRespawnTime
:= 0;
5203 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5205 gMissionFailed
:= True;
5206 g_Game_RestartLevel
;
5210 n
:= 0; nb
:= 0; nr
:= 0;
5211 for i
:= Low(gPlayers
) to High(gPlayers
) do
5212 if (gPlayers
[i
] <> nil) and
5213 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5214 (gPlayers
[i
] is TBot
)) then
5217 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5218 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5221 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5223 // wait a second until the fuckers finally decide to join
5224 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5225 gLMSRespawnTime
:= gTime
+ 1000;
5226 gLMSSoftSpawn
:= NoMapRestart
;
5230 g_Player_RemoveAllCorpses
;
5231 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5232 if g_Game_IsNet
then
5233 MH_SEND_GameEvent(NET_EV_LMS_START
);
5235 for i
:= Low(gPlayers
) to High(gPlayers
) do
5237 if gPlayers
[i
] = nil then continue
;
5238 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5239 // don't touch normal spectators
5240 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5242 gPlayers
[i
].FNoRespawn
:= True;
5243 gPlayers
[i
].Lives
:= 0;
5244 if g_Game_IsNet
then
5245 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5248 gPlayers
[i
].FNoRespawn
:= False;
5249 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5250 gPlayers
[i
].Respawn(False, True);
5251 if gGameSettings
.GameMode
= GM_COOP
then
5253 gPlayers
[i
].Frags
:= 0;
5254 gPlayers
[i
].RecallState
;
5256 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5257 gPlayer1
:= g_Player_Get(gLMSPID1
);
5258 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5259 gPlayer2
:= g_Player_Get(gLMSPID2
);
5262 g_Items_RestartRound();
5265 g_Mons_ForEach(monRespawn
);
5267 gLMSSoftSpawn
:= False;
5270 function g_Game_GetFirstMap(WAD
: String): String;
5274 MapList
:= g_Map_GetMapsList(WAD
);
5275 if MapList
= nil then
5278 SortSArray(MapList
);
5279 Result
:= MapList
[Low(MapList
)];
5281 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5287 function g_Game_GetNextMap(): String;
5294 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5295 if MapList
= nil then
5298 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5300 SortSArray(MapList
);
5302 for I
:= Low(MapList
) to High(MapList
) do
5303 if Map
= MapList
[I
] then
5309 if MapIndex
<> -255 then
5311 if MapIndex
= High(MapList
) then
5312 Result
:= MapList
[Low(MapList
)]
5314 Result
:= MapList
[MapIndex
+ 1];
5316 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5322 procedure g_Game_NextLevel();
5324 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5325 gExit
:= EXIT_ENDLEVELCUSTOM
5328 gExit
:= EXIT_ENDLEVELSINGLE
;
5332 if gNextMap
<> '' then Exit
;
5333 gNextMap
:= g_Game_GetNextMap();
5336 function g_Game_IsTestMap(): Boolean;
5338 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5341 procedure g_Game_DeleteTestMap();
5344 //MapName: AnsiString;
5352 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5353 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5354 if (a
= 0) then exit
;
5356 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5357 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5358 Delete(gMapToDelete
, 1, a
+5);
5359 gMapToDelete
:= UpperCase(gMapToDelete
);
5361 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5364 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5365 if MapName <> TEST_MAP_NAME then
5368 if not gTempDelete then
5370 time := g_GetFileTime(WadName);
5371 WAD := TWADFile.Create();
5374 if not WAD.ReadFile(WadName) then
5375 begin // Íåò òàêîãî WAD-ôàéëà
5380 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5382 MapList := WAD.GetResourcesList('');
5384 if MapList <> nil then
5385 for a := 0 to High(MapList) do
5386 if MapList[a] = MapName then
5388 // Óäàëÿåì è ñîõðàíÿåì:
5389 WAD.RemoveResource('', MapName);
5390 WAD.SaveTo(WadName);
5395 g_SetFileTime(WadName, time);
5398 if gTempDelete
then DeleteFile(WadName
);
5401 procedure GameCVars(P
: SSArray
);
5404 stat
: TPlayerStatArray
;
5409 cmd
:= LowerCase(P
[0]);
5410 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5412 with gGameSettings
do
5414 if (Length(P
) > 1) and
5415 ((P
[1] = '1') or (P
[1] = '0')) then
5417 if (P
[1][1] = '1') then
5418 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5420 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5423 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5424 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5426 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5428 if g_Game_IsNet
then MH_SEND_GameSettings
;
5431 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5433 with gGameSettings
do
5435 if (Length(P
) > 1) and
5436 ((P
[1] = '1') or (P
[1] = '0')) then
5438 if (P
[1][1] = '1') then
5439 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5441 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5444 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5445 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5447 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5449 if g_Game_IsNet
then MH_SEND_GameSettings
;
5452 else if cmd
= 'g_gamemode' then
5454 a
:= g_Game_TextToMode(P
[1]);
5455 if a
= GM_SINGLE
then a
:= GM_COOP
;
5456 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5458 gSwitchGameMode
:= a
;
5459 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5460 (gState
= STATE_INTERSINGLE
) then
5461 gSwitchGameMode
:= GM_SINGLE
;
5463 gGameSettings
.GameMode
:= gSwitchGameMode
;
5465 if gSwitchGameMode
= gGameSettings
.GameMode
then
5466 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5467 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5469 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5470 [g_Game_ModeToText(gGameSettings
.GameMode
),
5471 g_Game_ModeToText(gSwitchGameMode
)]));
5473 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5475 with gGameSettings
do
5477 if (Length(P
) > 1) and
5478 ((P
[1] = '1') or (P
[1] = '0')) then
5480 if (P
[1][1] = '1') then
5481 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5483 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5486 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5487 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5489 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5490 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5492 if g_Game_IsNet
then MH_SEND_GameSettings
;
5495 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5497 with gGameSettings
do
5499 if (Length(P
) > 1) and
5500 ((P
[1] = '1') or (P
[1] = '0')) then
5502 if (P
[1][1] = '1') then
5503 Options
:= Options
or GAME_OPTION_MONSTERS
5505 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5508 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5509 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5511 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5512 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5514 if g_Game_IsNet
then MH_SEND_GameSettings
;
5517 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5519 with gGameSettings
do
5521 if (Length(P
) > 1) and
5522 ((P
[1] = '1') or (P
[1] = '0')) then
5524 if (P
[1][1] = '1') then
5525 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5527 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5530 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5531 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5533 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5535 if g_Game_IsNet
then MH_SEND_GameSettings
;
5538 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5540 with gGameSettings
do
5542 if (Length(P
) > 1) and
5543 ((P
[1] = '1') or (P
[1] = '0')) then
5545 if (P
[1][1] = '1') then
5546 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5548 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5551 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5552 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5554 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5556 if g_Game_IsNet
then MH_SEND_GameSettings
;
5559 else if (cmd
= 'g_dm_keys') and not g_Game_IsClient
then
5561 with gGameSettings
do
5563 if (Length(P
) > 1) and
5564 ((P
[1] = '1') or (P
[1] = '0')) then
5566 if (P
[1][1] = '1') then
5567 Options
:= Options
or GAME_OPTION_DMKEYS
5569 Options
:= Options
and (not GAME_OPTION_DMKEYS
);
5572 if (LongBool(Options
and GAME_OPTION_DMKEYS
)) then
5573 g_Console_Add(_lc
[I_MSG_DMKEYS_ON
])
5575 g_Console_Add(_lc
[I_MSG_DMKEYS_OFF
]);
5577 if g_Game_IsNet
then MH_SEND_GameSettings
;
5580 else if (cmd
= 'g_respawn_items') and not g_Game_IsClient
then
5582 with gGameSettings
do
5584 if (Length(P
) > 1) and
5585 ((P
[1] = '1') or (P
[1] = '0')) then
5587 if (P
[1][1] = '1') then
5588 Options
:= Options
or GAME_OPTION_RESPAWNITEMS
5590 Options
:= Options
and (not GAME_OPTION_RESPAWNITEMS
);
5593 if (LongBool(Options
and GAME_OPTION_RESPAWNITEMS
)) then
5594 g_Console_Add(_lc
[I_MSG_RESPAWNITEMS_ON
])
5596 g_Console_Add(_lc
[I_MSG_RESPAWNITEMS_OFF
]);
5598 if g_Game_IsNet
then MH_SEND_GameSettings
;
5601 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5603 if Length(P
) > 1 then
5605 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5606 gGameSettings
.WarmupTime
:= 30
5608 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5611 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5612 [gGameSettings
.WarmupTime
]));
5613 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5615 else if (cmd
= 'g_spawn_invul') and not g_Game_IsClient
then
5617 if Length(P
) > 1 then
5619 if StrToIntDef(P
[1], gGameSettings
.SpawnInvul
) = 0 then
5620 gGameSettings
.SpawnInvul
:= 0
5622 gGameSettings
.SpawnInvul
:= StrToIntDef(P
[1], gGameSettings
.SpawnInvul
);
5625 g_Console_Add(Format(_lc
[I_MSG_SPAWNINVUL
],
5626 [gGameSettings
.SpawnInvul
]));
5627 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5629 else if cmd
= 'net_interp' then
5631 if (Length(P
) > 1) then
5632 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5633 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5634 s
:= e_GetWriteableDir(ConfigDirs
);
5637 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5638 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5639 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5643 else if cmd
= 'net_forceplayerupdate' then
5645 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5646 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5648 if NetForcePlayerUpdate
then
5649 g_Console_Add('net_forceplayerupdate = 1')
5651 g_Console_Add('net_forceplayerupdate = 0');
5653 s
:= e_GetWriteableDir(ConfigDirs
);
5656 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5657 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5658 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5662 else if cmd
= 'net_predictself' then
5664 if (Length(P
) > 1) and
5665 ((P
[1] = '1') or (P
[1] = '0')) then
5666 NetPredictSelf
:= (P
[1][1] = '1');
5668 if NetPredictSelf
then
5669 g_Console_Add('net_predictself = 1')
5671 g_Console_Add('net_predictself = 0');
5673 s
:= e_GetWriteableDir(ConfigDirs
);
5676 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5677 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5678 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5682 else if cmd
= 'sv_name' then
5684 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5686 NetServerName
:= P
[1];
5687 if Length(NetServerName
) > 64 then
5688 SetLength(NetServerName
, 64);
5689 g_Net_Slist_ServerRenamed();
5692 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5694 else if cmd
= 'sv_passwd' then
5696 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5698 NetPassword
:= P
[1];
5699 if Length(NetPassword
) > 24 then
5700 SetLength(NetPassword
, 24);
5701 g_Net_Slist_ServerRenamed();
5704 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5706 else if cmd
= 'sv_maxplrs' then
5708 if (Length(P
) > 1) then
5710 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5711 if g_Game_IsServer
and g_Game_IsNet
then
5714 for a
:= 0 to High(NetClients
) do
5716 if NetClients
[a
].Used
then
5719 if b
> NetMaxClients
then
5721 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5722 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5723 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5724 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5728 g_Net_Slist_ServerRenamed();
5732 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5734 else if cmd
= 'sv_public' then
5736 if (Length(P
) > 1) then
5738 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5739 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5742 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5744 else if cmd
= 'sv_intertime' then
5746 if (Length(P
) > 1) then
5747 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5749 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5751 else if cmd
= 'p1_name' then
5753 if (Length(P
) > 1) and gGameOn
then
5755 if g_Game_IsClient
then
5757 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5758 MC_SEND_PlayerSettings
;
5761 if gPlayer1
<> nil then
5763 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5764 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5767 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5770 else if cmd
= 'p2_name' then
5772 if (Length(P
) > 1) and gGameOn
then
5774 if g_Game_IsClient
then
5776 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5777 MC_SEND_PlayerSettings
;
5780 if gPlayer2
<> nil then
5782 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5783 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5786 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5789 else if cmd
= 'p1_color' then
5791 if Length(P
) > 3 then
5792 if g_Game_IsClient
then
5794 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5795 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5796 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5797 MC_SEND_PlayerSettings
;
5800 if gPlayer1
<> nil then
5802 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5803 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5804 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5805 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5808 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5809 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5810 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5812 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5814 if Length(P
) > 3 then
5815 if g_Game_IsClient
then
5817 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5818 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5819 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5820 MC_SEND_PlayerSettings
;
5823 if gPlayer2
<> nil then
5825 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5826 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5827 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5828 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5831 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5832 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5833 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5835 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5837 if cmd
= 'r_showscore' then
5839 if (Length(P
) > 1) and
5840 ((P
[1] = '1') or (P
[1] = '0')) then
5841 gShowGoals
:= (P
[1][1] = '1');
5844 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5846 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5848 else if cmd
= 'r_showstat' then
5850 if (Length(P
) > 1) and
5851 ((P
[1] = '1') or (P
[1] = '0')) then
5852 gShowStat
:= (P
[1][1] = '1');
5855 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5857 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5859 else if cmd
= 'r_showkillmsg' then
5861 if (Length(P
) > 1) and
5862 ((P
[1] = '1') or (P
[1] = '0')) then
5863 gShowKillMsg
:= (P
[1][1] = '1');
5865 if gShowKillMsg
then
5866 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5868 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5870 else if cmd
= 'r_showlives' then
5872 if (Length(P
) > 1) and
5873 ((P
[1] = '1') or (P
[1] = '0')) then
5874 gShowLives
:= (P
[1][1] = '1');
5877 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5879 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5881 else if cmd
= 'r_showspect' then
5883 if (Length(P
) > 1) and
5884 ((P
[1] = '1') or (P
[1] = '0')) then
5885 gSpectHUD
:= (P
[1][1] = '1');
5888 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5890 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5892 else if cmd
= 'r_showping' then
5894 if (Length(P
) > 1) and
5895 ((P
[1] = '1') or (P
[1] = '0')) then
5896 gShowPing
:= (P
[1][1] = '1');
5899 g_Console_Add(_lc
[I_MSG_PING_ON
])
5901 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5903 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5905 if Length(P
) > 1 then
5907 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5908 gGameSettings
.GoalLimit
:= 0
5913 if gGameSettings
.GameMode
= GM_DM
then
5915 stat
:= g_Player_GetStats();
5917 for a
:= 0 to High(stat
) do
5918 if stat
[a
].Frags
> b
then
5922 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5924 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5927 if g_Game_IsNet
then MH_SEND_GameSettings
;
5930 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5932 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5934 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5935 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5937 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5938 [gGameSettings
.TimeLimit
div 3600,
5939 (gGameSettings
.TimeLimit
div 60) mod 60,
5940 gGameSettings
.TimeLimit
mod 60]));
5941 if g_Game_IsNet
then MH_SEND_GameSettings
;
5943 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5945 if Length(P
) > 1 then
5947 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5948 gGameSettings
.MaxLives
:= 0
5952 stat
:= g_Player_GetStats();
5954 for a
:= 0 to High(stat
) do
5955 if stat
[a
].Lives
> b
then
5957 gGameSettings
.MaxLives
:=
5958 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5962 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5963 [gGameSettings
.MaxLives
]));
5964 if g_Game_IsNet
then MH_SEND_GameSettings
;
5969 procedure PrintHeapStats();
5973 hs
:= GetFPCHeapStatus();
5974 e_LogWriteLn ('v===== heap status =====v');
5975 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5976 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5977 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5978 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5979 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5980 e_LogWriteLn ('^=======================^');
5983 procedure DebugCommands(P
: SSArray
);
5990 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5991 if {gDebugMode}conIsCheatsEnabled
then
5993 cmd
:= LowerCase(P
[0]);
5994 if cmd
= 'd_window' then
5996 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5997 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5999 else if cmd
= 'd_sounds' then
6001 if (Length(P
) > 1) and
6002 ((P
[1] = '1') or (P
[1] = '0')) then
6003 g_Debug_Sounds
:= (P
[1][1] = '1');
6005 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
6007 else if cmd
= 'd_frames' then
6009 if (Length(P
) > 1) and
6010 ((P
[1] = '1') or (P
[1] = '0')) then
6011 g_Debug_Frames
:= (P
[1][1] = '1');
6013 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
6015 else if cmd
= 'd_winmsg' then
6017 if (Length(P
) > 1) and
6018 ((P
[1] = '1') or (P
[1] = '0')) then
6019 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6021 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6023 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6025 if (Length(P
) > 1) and
6026 ((P
[1] = '1') or (P
[1] = '0')) then
6027 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6029 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6031 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6033 if Length(P
) > 1 then
6035 '0': g_debug_BotAIOff
:= 0;
6036 '1': g_debug_BotAIOff
:= 1;
6037 '2': g_debug_BotAIOff
:= 2;
6038 '3': g_debug_BotAIOff
:= 3;
6041 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6043 else if cmd
= 'd_monster' then
6045 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6046 if Length(P
) < 2 then
6048 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6049 g_Console_Add('ID | Name');
6050 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6051 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6052 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6055 a
:= StrToIntDef(P
[1], 0);
6056 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6057 a
:= g_Mons_TypeIdByName(P
[1]);
6059 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6060 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6063 with gPlayer1
.Obj
do
6065 mon
:= g_Monsters_Create(a
,
6066 X
+ Rect
.X
+ (Rect
.Width
div 2),
6067 Y
+ Rect
.Y
+ Rect
.Height
,
6068 gPlayer1
.Direction
, True);
6070 if (Length(P
) > 2) and (mon
<> nil) then
6072 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6073 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6074 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6075 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6076 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6077 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6078 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6079 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6080 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6085 else if (cmd
= 'd_health') then
6087 if (Length(P
) > 1) and
6088 ((P
[1] = '1') or (P
[1] = '0')) then
6089 g_debug_HealthBar
:= (P
[1][1] = '1');
6091 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6093 else if (cmd
= 'd_player') then
6095 if (Length(P
) > 1) and
6096 ((P
[1] = '1') or (P
[1] = '0')) then
6097 g_debug_Player
:= (P
[1][1] = '1');
6099 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6101 else if (cmd
= 'd_mem') then
6107 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6111 procedure GameCheats(P
: SSArray
);
6117 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6119 g_Console_Add('not available');
6125 g_Console_Add('where is the player?!');
6128 cmd
:= LowerCase(P
[0]);
6132 plr
.GodMode
:= not plr
.GodMode
;
6133 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6136 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6137 if cmd
= 'give' then
6139 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6140 for f
:= 1 to High(P
) do
6142 cmd
:= LowerCase(P
[f
]);
6143 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6144 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6145 if cmd
= 'exit' then
6147 if gTriggers
<> nil then
6149 for a
:= 0 to High(gTriggers
) do
6151 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6153 g_Console_Add('player left the map');
6154 gExitByTrigger
:= True;
6155 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6156 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6164 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6165 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6166 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6167 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6168 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6170 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6171 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6173 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6174 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;
6176 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6177 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6179 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6180 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6182 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6183 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6185 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6186 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6187 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6189 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6190 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6191 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6192 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;
6193 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6194 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6196 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;
6197 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;
6198 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;
6199 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;
6200 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;
6201 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;
6203 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6204 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;
6206 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;
6207 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;
6209 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6211 if cmd
= 'ammo' then
6213 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6214 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6215 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6216 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6217 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6218 g_Console_Add('player got some ammo');
6222 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6223 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6225 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6226 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6228 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6229 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6231 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6232 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6234 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6236 if cmd
= 'weapons' then
6238 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6239 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6240 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6241 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6242 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6243 plr
.GiveItem(ITEM_WEAPON_BFG
);
6244 g_Console_Add('player got weapons');
6248 if cmd
= 'keys' then
6250 plr
.GiveItem(ITEM_KEY_RED
);
6251 plr
.GiveItem(ITEM_KEY_GREEN
);
6252 plr
.GiveItem(ITEM_KEY_BLUE
);
6253 g_Console_Add('player got all keys');
6257 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6262 if cmd
= 'open' then
6264 g_Console_Add('player activated sesame');
6265 g_Triggers_OpenAll();
6272 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6276 if cmd
= 'noclip' then
6279 g_Console_Add('wall hardeness adjusted');
6283 if cmd
= 'notarget' then
6285 plr
.NoTarget
:= not plr
.NoTarget
;
6286 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6290 if cmd
= 'noreload' then
6292 plr
.NoReload
:= not plr
.NoReload
;
6293 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6297 if cmd
= 'speedy' then
6299 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6300 g_Console_Add('speed adjusted');
6304 if cmd
= 'jumpy' then
6306 VEL_JUMP
:= 30-VEL_JUMP
;
6307 g_Console_Add('jump height adjusted');
6311 if cmd
= 'automap' then
6313 gShowMap
:= not gShowMap
;
6314 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6318 if cmd
= 'aimline' then
6320 gAimLine
:= not gAimLine
;
6321 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6326 procedure GameCommands(P
: SSArray
);
6332 pl
: pTNetClient
= nil;
6340 cmd
:= LowerCase(P
[0]);
6342 if (cmd
= 'quit') or
6349 else if cmd
= 'pause' then
6351 if (g_ActiveWindow
= nil) then
6352 g_Game_Pause(not gPauseMain
);
6354 else if cmd
= 'endgame' then
6355 gExit
:= EXIT_SIMPLE
6356 else if cmd
= 'restart' then
6358 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6360 if g_Game_IsClient
then
6362 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6367 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6369 else if cmd
= 'kick' then
6371 if g_Game_IsServer
then
6373 if Length(P
) < 2 then
6375 g_Console_Add('kick <name>');
6380 g_Console_Add('kick <name>');
6384 if g_Game_IsNet
then
6385 pl
:= g_Net_Client_ByName(P
[1]);
6388 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6389 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6390 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6391 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6392 g_Net_Slist_ServerPlayerLeaves();
6393 end else if gPlayers
<> nil then
6394 for a
:= Low(gPlayers
) to High(gPlayers
) do
6395 if gPlayers
[a
] <> nil then
6396 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6398 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6399 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6401 gPlayers
[a
].Lives
:= 0;
6402 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6403 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6404 g_Player_Remove(gPlayers
[a
].UID
);
6405 g_Net_Slist_ServerPlayerLeaves();
6406 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6410 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6412 else if cmd
= 'kick_id' then
6414 if g_Game_IsServer
and g_Game_IsNet
then
6416 if Length(P
) < 2 then
6418 g_Console_Add('kick_id <client ID>');
6423 g_Console_Add('kick_id <client ID>');
6427 a
:= StrToIntDef(P
[1], 0);
6428 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6430 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6432 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6433 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6434 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6435 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6436 g_Net_Slist_ServerPlayerLeaves();
6440 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6442 else if cmd
= 'ban' then
6444 if g_Game_IsServer
and g_Game_IsNet
then
6446 if Length(P
) < 2 then
6448 g_Console_Add('ban <name>');
6453 g_Console_Add('ban <name>');
6457 pl
:= g_Net_Client_ByName(P
[1]);
6460 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6461 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6462 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6463 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6464 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6465 g_Net_Slist_ServerPlayerLeaves();
6467 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6469 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6471 else if cmd
= 'ban_id' then
6473 if g_Game_IsServer
and g_Game_IsNet
then
6475 if Length(P
) < 2 then
6477 g_Console_Add('ban_id <client ID>');
6482 g_Console_Add('ban_id <client ID>');
6486 a
:= StrToIntDef(P
[1], 0);
6487 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6488 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6490 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6491 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6492 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6493 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6494 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6495 g_Net_Slist_ServerPlayerLeaves();
6498 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6500 else if cmd
= 'permban' then
6502 if g_Game_IsServer
and g_Game_IsNet
then
6504 if Length(P
) < 2 then
6506 g_Console_Add('permban <name>');
6511 g_Console_Add('permban <name>');
6515 pl
:= g_Net_Client_ByName(P
[1]);
6518 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6519 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6520 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6521 g_Net_SaveBanList();
6522 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6523 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6524 g_Net_Slist_ServerPlayerLeaves();
6526 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6528 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6530 else if cmd
= 'permban_id' then
6532 if g_Game_IsServer
and g_Game_IsNet
then
6534 if Length(P
) < 2 then
6536 g_Console_Add('permban_id <client ID>');
6541 g_Console_Add('permban_id <client ID>');
6545 a
:= StrToIntDef(P
[1], 0);
6546 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6547 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6549 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6550 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6551 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6552 g_Net_SaveBanList();
6553 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6554 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6555 g_Net_Slist_ServerPlayerLeaves();
6558 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6560 else if cmd
= 'unban' then
6562 if g_Game_IsServer
and g_Game_IsNet
then
6564 if Length(P
) < 2 then
6566 g_Console_Add('unban <IP Address>');
6571 g_Console_Add('unban <IP Address>');
6575 if g_Net_UnbanHost(P
[1]) then
6577 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6578 g_Net_SaveBanList();
6580 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6582 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6584 else if cmd
= 'clientlist' then
6586 if g_Game_IsServer
and g_Game_IsNet
then
6589 if NetClients
<> nil then
6590 for a
:= Low(NetClients
) to High(NetClients
) do
6591 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6593 plr
:= g_Player_Get(NetClients
[a
].Player
);
6594 if plr
= nil then continue
;
6596 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6597 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6600 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6602 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6604 else if cmd
= 'connect' then
6606 if (NetMode
= NET_NONE
) then
6608 if Length(P
) < 2 then
6610 g_Console_Add('connect <IP> [port] [password]');
6615 g_Console_Add('connect <IP> [port] [password]');
6619 if Length(P
) > 2 then
6620 prt
:= StrToIntDef(P
[2], 25666)
6624 if Length(P
) > 3 then
6629 g_Game_StartClient(P
[1], prt
, pw
);
6632 else if cmd
= 'disconnect' then
6634 if (NetMode
= NET_CLIENT
) then
6637 else if cmd
= 'reconnect' then
6639 if (NetMode
= NET_SERVER
) then
6642 if (NetMode
= NET_CLIENT
) then
6645 gExit
:= EXIT_SIMPLE
;
6649 //TODO: Use last successful password to reconnect, instead of ''
6650 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6652 else if (cmd
= 'addbot') or
6653 (cmd
= 'bot_add') then
6655 if Length(P
) > 2 then
6656 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6657 else if Length(P
) > 1 then
6658 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6660 g_Bot_Add(TEAM_NONE
, 2);
6662 else if cmd
= 'bot_addlist' then
6664 if Length(P
) > 1 then
6666 if Length(P
) = 2 then
6667 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6668 else if Length(P
) = 3 then
6669 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6671 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6674 else if cmd
= 'bot_removeall' then
6676 else if cmd
= 'chat' then
6678 if g_Game_IsNet
then
6680 if Length(P
) > 1 then
6682 for a
:= 1 to High(P
) do
6683 chstr
:= chstr
+ P
[a
] + ' ';
6685 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6687 if Length(chstr
) < 1 then
6689 g_Console_Add('chat <text>');
6693 chstr
:= b_Text_Format(chstr
);
6694 if g_Game_IsClient
then
6695 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6697 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6700 g_Console_Add('chat <text>');
6702 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6704 else if cmd
= 'teamchat' then
6706 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6708 if Length(P
) > 1 then
6710 for a
:= 1 to High(P
) do
6711 chstr
:= chstr
+ P
[a
] + ' ';
6713 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6715 if Length(chstr
) < 1 then
6717 g_Console_Add('teamchat <text>');
6721 chstr
:= b_Text_Format(chstr
);
6722 if g_Game_IsClient
then
6723 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6725 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6726 gPlayer1Settings
.Team
);
6729 g_Console_Add('teamchat <text>');
6731 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6733 else if cmd
= 'game' then
6735 if gGameSettings
.GameType
<> GT_NONE
then
6737 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6740 if Length(P
) = 1 then
6742 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6745 // game not started yet, load fist map from some wad
6747 s
:= addWadExtension(P
[1]);
6748 found
:= e_FindResource(AllMapDirs
, s
);
6752 P
[1] := ExpandFileName(P
[1]);
6753 // if map not choosed then set first map
6754 if Length(P
) < 3 then
6757 P
[2] := g_Game_GetFirstMap(P
[1]);
6760 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6762 if g_Map_Exist(s
) then
6766 with gGameSettings
do
6768 GameMode
:= g_Game_TextToMode(gcGameMode
);
6769 if gSwitchGameMode
<> GM_NONE
then
6770 GameMode
:= gSwitchGameMode
;
6771 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6772 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6774 if Length(P
) >= 4 then
6775 b
:= StrToIntDef(P
[3], 1);
6776 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6777 GoalLimit
, MaxLives
, Options
, b
);
6782 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6784 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6786 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6788 else if cmd
= 'host' then
6790 if gGameSettings
.GameType
<> GT_NONE
then
6792 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6795 if Length(P
) < 4 then
6797 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6800 if not StrToIp(P
[1], listen
) then
6802 prt
:= StrToIntDef(P
[2], 25666);
6804 s
:= addWadExtension(P
[3]);
6805 found
:= e_FindResource(AllMapDirs
, s
);
6809 // get first map in wad, if not specified
6810 if Length(P
) < 5 then
6813 P
[4] := g_Game_GetFirstMap(P
[1]);
6815 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6816 if g_Map_Exist(s
) then
6820 with gGameSettings
do
6822 GameMode
:= g_Game_TextToMode(gcGameMode
);
6823 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6824 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6825 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6827 if Length(P
) >= 6 then
6828 b
:= StrToIntDef(P
[5], 0);
6829 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6835 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6837 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6842 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6845 else if cmd
= 'map' then
6847 if Length(P
) = 1 then
6849 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6851 g_Console_Add(cmd
+ ' <MAP>');
6852 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6856 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6861 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6863 if Length(P
) < 3 then
6865 // first param is map or wad
6866 s
:= UpperCase(P
[1]);
6867 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6869 gExitByTrigger
:= False;
6872 // already in game, finish current map
6874 gExit
:= EXIT_ENDLEVELCUSTOM
;
6878 // intermission, so change map immediately
6885 found
:= e_FindResource(AllMapDirs
, s
);
6887 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6890 // no such map, found wad
6893 P
[1] := ExpandFileName(pw
);
6894 P
[2] := g_Game_GetFirstMap(P
[1]);
6895 s
:= P
[1] + ':\' + P
[2];
6896 if g_Map_Exist(s
) then
6898 gExitByTrigger
:= False;
6901 // already in game, finish current map
6903 gExit
:= EXIT_ENDLEVELCUSTOM
6907 // intermission, so change map immediately
6914 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6916 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6921 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6927 s
:= addWadExtension(P
[1]);
6928 found
:= e_FindResource(AllMapDirs
, s
);
6932 P
[2] := UpperCase(P
[2]);
6933 s
:= P
[1] + ':\' + P
[2];
6934 if g_Map_Exist(s
) then
6936 gExitByTrigger
:= False;
6940 gExit
:= EXIT_ENDLEVELCUSTOM
6949 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6954 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6960 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6964 else if cmd
= 'nextmap' then
6966 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6968 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6973 if Length(P
) = 1 then
6975 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6977 g_Console_Add(cmd
+ ' <MAP>');
6978 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6983 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6989 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6991 if Length(P
) < 3 then
6993 // first param is map or wad
6994 s
:= UpperCase(P
[1]);
6995 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6998 gExitByTrigger
:= False;
7004 // no such map, found wad
7005 pw
:= addWadExtension(P
[1]);
7006 found
:= e_FindResource(MapDirs
, pw
);
7008 found
:= e_FindResource(WadDirs
, pw
);
7010 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7013 // map not specified, select first map
7015 P
[2] := g_Game_GetFirstMap(P
[1]);
7016 s
:= P
[1] + ':\' + P
[2];
7017 if g_Map_Exist(s
) then
7019 gExitByTrigger
:= False;
7026 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7028 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7033 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7039 // specified two params wad + map
7040 pw
:= addWadExtension(P
[1]);
7041 found
:= e_FindResource(MapDirs
, pw
);
7043 found
:= e_FindResource(MapDirs
, pw
);
7047 P
[2] := UpperCase(P
[2]);
7048 s
:= P
[1] + ':\' + P
[2];
7049 if g_Map_Exist(s
) then
7051 gExitByTrigger
:= False;
7057 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7062 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7068 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7073 if gNextMap
= '' then
7074 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7076 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7080 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7084 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7088 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7090 gExitByTrigger
:= False;
7091 // next map not specified, try to find trigger EXIT
7092 if (gNextMap
= '') and (gTriggers
<> nil) then
7094 for a
:= 0 to High(gTriggers
) do
7096 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7098 gExitByTrigger
:= True;
7099 //gNextMap := gTriggers[a].Data.MapName;
7100 gNextMap
:= gTriggers
[a
].tgcMap
;
7105 if gNextMap
= '' then
7106 gNextMap
:= g_Game_GetNextMap();
7107 if not isWadPath(gNextMap
) then
7108 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7111 if g_Map_Exist(s
) then
7112 gExit
:= EXIT_ENDLEVELCUSTOM
7114 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7118 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7122 else if (cmd
= 'event') then
7124 if (Length(P
) <= 1) then
7126 for a
:= 0 to High(gEvents
) do
7127 if gEvents
[a
].Command
= '' then
7128 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7130 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7133 if (Length(P
) = 2) then
7135 for a
:= 0 to High(gEvents
) do
7136 if gEvents
[a
].Name
= P
[1] then
7137 if gEvents
[a
].Command
= '' then
7138 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7140 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7143 for a
:= 0 to High(gEvents
) do
7144 if gEvents
[a
].Name
= P
[1] then
7146 gEvents
[a
].Command
:= '';
7147 for b
:= 2 to High(P
) do
7148 if Pos(' ', P
[b
]) = 0 then
7149 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7151 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7152 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7156 else if cmd
= 'suicide' then
7160 if g_Game_IsClient
then
7161 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7164 if gPlayer1
<> nil then
7165 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7166 if gPlayer2
<> nil then
7167 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7171 else if cmd
= 'screenshot' then
7175 else if cmd
= 'weapon' then
7177 if Length(p
) = 2 then
7179 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7180 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7181 gSelectWeapon
[0, a
] := True
7184 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7186 if Length(p
) = 2 then
7188 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7189 b
:= ord(cmd
[2]) - ord('1');
7190 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7191 gSelectWeapon
[b
, a
] := True
7194 // Êîìàíäû Ñâîåé èãðû:
7195 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7197 if cmd
= 'bot_addred' then
7199 if Length(P
) > 1 then
7200 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7202 g_Bot_Add(TEAM_RED
, 2);
7204 else if cmd
= 'bot_addblue' then
7206 if Length(P
) > 1 then
7207 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7209 g_Bot_Add(TEAM_BLUE
, 2);
7211 else if cmd
= 'spectate' then
7217 else if cmd
= 'say' then
7219 if g_Game_IsServer
and g_Game_IsNet
then
7221 if Length(P
) > 1 then
7224 for a
:= 1 to High(P
) do
7225 chstr
:= chstr
+ P
[a
] + ' ';
7227 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7229 if Length(chstr
) < 1 then
7231 g_Console_Add('say <text>');
7235 chstr
:= b_Text_Format(chstr
);
7236 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7238 else g_Console_Add('say <text>');
7240 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7242 else if cmd
= 'tell' then
7244 if g_Game_IsServer
and g_Game_IsNet
then
7246 if (Length(P
) > 2) and (P
[1] <> '') then
7249 for a
:= 2 to High(P
) do
7250 chstr
:= chstr
+ P
[a
] + ' ';
7252 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7254 if Length(chstr
) < 1 then
7256 g_Console_Add('tell <playername> <text>');
7260 pl
:= g_Net_Client_ByName(P
[1]);
7262 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7264 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7266 else g_Console_Add('tell <playername> <text>');
7268 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7270 else if cmd
= 'centerprint' then
7272 if (Length(P
) > 2) and (P
[1] <> '') then
7275 for a
:= 2 to High(P
) do
7276 chstr
:= chstr
+ P
[a
] + ' ';
7278 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7280 if Length(chstr
) < 1 then
7282 g_Console_Add('centerprint <timeout> <text>');
7286 a
:= StrToIntDef(P
[1], 100);
7287 chstr
:= b_Text_Format(chstr
);
7288 g_Game_Message(chstr
, a
);
7289 if g_Game_IsNet
and g_Game_IsServer
then
7290 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7292 else g_Console_Add('centerprint <timeout> <text>');
7294 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7296 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7298 // Äîïîëíèòåëüíîå âðåìÿ:
7299 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7301 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7302 [gGameSettings
.TimeLimit
div 3600,
7303 (gGameSettings
.TimeLimit
div 60) mod 60,
7304 gGameSettings
.TimeLimit
mod 60]));
7305 if g_Game_IsNet
then MH_SEND_GameSettings
;
7307 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7309 if (Length(P
) <= 1) then
7310 g_Console_Add('rcon_password <password>')
7312 MC_SEND_RCONPassword(P
[1]);
7314 else if cmd
= 'rcon' then
7316 if g_Game_IsClient
then
7318 if Length(P
) > 1 then
7321 for a
:= 1 to High(P
) do
7322 chstr
:= chstr
+ P
[a
] + ' ';
7324 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7326 if Length(chstr
) < 1 then
7328 g_Console_Add('rcon <command>');
7332 MC_SEND_RCONCommand(chstr
);
7334 else g_Console_Add('rcon <command>');
7337 else if cmd
= 'ready' then
7339 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7340 gLMSRespawnTime
:= gTime
+ 100;
7342 else if (cmd
= 'callvote') and g_Game_IsNet
then
7344 if Length(P
) > 1 then
7347 for a
:= 1 to High(P
) do begin
7348 if a
> 1 then chstr
:= chstr
+ ' ';
7349 chstr
:= chstr
+ P
[a
];
7352 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7354 if Length(chstr
) < 1 then
7356 g_Console_Add('callvote <command>');
7360 if g_Game_IsClient
then
7361 MC_SEND_Vote(True, chstr
)
7363 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7364 g_Console_Process('vote', True);
7367 g_Console_Add('callvote <command>');
7369 else if (cmd
= 'vote') and g_Game_IsNet
then
7371 if g_Game_IsClient
then
7373 else if gVoteInProgress
then
7375 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7376 a
:= Floor((NetClientCount
+1)/2.0) + 1
7378 a
:= Floor(NetClientCount
/2.0) + 1;
7383 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7384 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7390 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7391 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7399 procedure g_TakeScreenShot(Filename
: string = '');
7400 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7402 if e_NoGraphics
then Exit
;
7404 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7406 if Filename
= '' then
7409 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7410 Filename
:= 'screenshot-' + date
;
7413 name
:= e_CatPath(dir
, Filename
+ '.png');
7414 s
:= createDiskFile(name
);
7416 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7418 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7420 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7425 g_Console_Add('oh shit, i can''t create screenshot!')
7429 procedure g_Game_InGameMenu(Show
: Boolean);
7431 if (g_ActiveWindow
= nil) and Show
then
7433 if gGameSettings
.GameType
= GT_SINGLE
then
7434 g_GUI_ShowWindow('GameSingleMenu')
7437 if g_Game_IsClient
then
7438 g_GUI_ShowWindow('GameClientMenu')
7440 if g_Game_IsNet
then
7441 g_GUI_ShowWindow('GameServerMenu')
7443 g_GUI_ShowWindow('GameCustomMenu');
7445 g_Sound_PlayEx('MENU_OPEN');
7447 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7448 if (not g_Game_IsNet
) then
7452 if (g_ActiveWindow
<> nil) and (not Show
) then
7454 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7455 if (not g_Game_IsNet
) then
7456 g_Game_Pause(False);
7460 procedure g_Game_Pause (Enable
: Boolean);
7464 if not gGameOn
then exit
;
7466 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7469 gPauseMain
:= Enable
;
7471 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7474 procedure g_Game_HolmesPause (Enable
: Boolean);
7478 if not gGameOn
then exit
;
7479 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7482 gPauseHolmes
:= Enable
;
7484 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7487 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7492 if gTriggers
<> nil then
7493 for i
:= 0 to High(gTriggers
) do
7494 with gTriggers
[i
] do
7495 if (TriggerType
= TRIGGER_SOUND
) and
7497 Sound
.IsPlaying() then
7499 Sound
.Pause(Enable
);
7503 if gPlayers
<> nil then
7504 for i
:= 0 to High(gPlayers
) do
7505 if gPlayers
[i
] <> nil then
7506 gPlayers
[i
].PauseSounds(Enable
);
7509 if gMusic
<> nil then
7510 gMusic
.Pause(Enable
);
7513 procedure g_Game_StopAllSounds(all
: Boolean);
7517 if gTriggers
<> nil then
7518 for i
:= 0 to High(gTriggers
) do
7519 with gTriggers
[i
] do
7520 if (TriggerType
= TRIGGER_SOUND
) and
7524 if gMusic
<> nil then
7531 procedure g_Game_UpdateTriggerSounds
;
7534 if gTriggers
<> nil then
7535 for i
:= 0 to High(gTriggers
) do
7536 with gTriggers
[i
] do
7537 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7538 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7541 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7544 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7549 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7554 if gSpectMode
<> SPECT_PLAYERS
then
7556 if gSpectPID1
= UID
then
7561 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7568 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7573 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7578 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7583 if gSpectMode
<> SPECT_PLAYERS
then
7585 Pl
:= g_Player_Get(gSpectPID1
);
7586 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7591 if gSpectViewTwo
then
7593 Pl
:= g_Player_Get(gSpectPID2
);
7594 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7602 procedure g_Game_Message(Msg
: string; Time
: Word);
7604 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7605 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7606 MessageTime
:= Time
;
7609 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7611 punct
: Array[0..13] of String =
7612 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7618 function IsPunctuation(S
: String): Boolean;
7623 if Length(S
) <> 1 then
7625 for i
:= Low(punct
) to High(punct
) do
7626 if S
= punct
[i
] then
7632 function FilterPunctuation(S
: String): String;
7636 for i
:= Low(punct
) to High(punct
) do
7637 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7643 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7645 // remove player name
7646 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7647 // for FullWord check
7648 Text := toLowerCase1251(' ' + Text + ' ');
7649 fpText
:= FilterPunctuation(Text);
7651 for i
:= 0 to Length(gChatSounds
) - 1 do
7654 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7656 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7657 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7659 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7665 gChatSounds
[i
].Sound
.Play();
7671 g_Sound_PlayEx('SOUND_GAME_RADIO');
7674 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7683 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7687 if goodsnd
[a
].IsPlaying() then
7690 goodsnd
[Random(4)].Play();
7693 procedure g_Game_Announce_KillCombo(Param
: Integer);
7700 UID
:= Param
and $FFFF;
7705 Pl
:= g_Player_Get(UID
);
7714 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7718 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7722 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7726 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7734 if not g_Game_IsWatchedPlayer(UID
) then
7737 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7741 if killsnd
[n
].IsPlaying() then
7746 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7755 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7759 if hahasnd
[a
].IsPlaying() then
7762 hahasnd
[Random(3)].Play();
7765 procedure g_Game_StartVote(Command
, Initiator
: string);
7769 if not gVotesEnabled
then Exit
;
7770 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7771 if gVoteInProgress
or gVotePassed
then
7773 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7774 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7777 gVoteInProgress
:= True;
7778 gVotePassed
:= False;
7779 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7782 gVoteCommand
:= Command
;
7784 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7785 Need
:= Floor((NetClientCount
+1)/2.0)+1
7787 Need
:= Floor(NetClientCount
/2.0)+1;
7788 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7789 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7792 procedure g_Game_CheckVote
;
7796 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7797 if not gVoteInProgress
then Exit
;
7799 if (gTime
>= gVoteTimer
) then
7801 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7802 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7804 Need
:= Floor(NetClientCount
/2.0) + 1;
7805 if gVoteCount
>= Need
then
7807 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7808 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7809 gVotePassed
:= True;
7810 gVoteCmdTimer
:= gTime
+ 5000;
7814 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7815 MH_SEND_VoteEvent(NET_VE_FAILED
);
7817 if NetClients
<> nil then
7818 for I
:= Low(NetClients
) to High(NetClients
) do
7819 if NetClients
[i
].Used
then
7820 NetClients
[i
].Voted
:= False;
7821 gVoteInProgress
:= False;
7827 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7828 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7830 Need
:= Floor(NetClientCount
/2.0) + 1;
7831 if gVoteCount
>= Need
then
7833 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7834 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7835 gVoteInProgress
:= False;
7836 gVotePassed
:= True;
7837 gVoteCmdTimer
:= gTime
+ 5000;
7840 if NetClients
<> nil then
7841 for I
:= Low(NetClients
) to High(NetClients
) do
7842 if NetClients
[i
].Used
then
7843 NetClients
[i
].Voted
:= False;
7848 procedure g_Game_LoadMapList(FileName
: string);
7856 if not FileExists(FileName
) then Exit
;
7858 AssignFile(ListFile
, FileName
);
7860 while not EOF(ListFile
) do
7862 ReadLn(ListFile
, s
);
7865 if s
= '' then Continue
;
7867 SetLength(MapList
, Length(MapList
)+1);
7868 MapList
[High(MapList
)] := s
;
7870 CloseFile(ListFile
);
7873 procedure g_Game_SetDebugMode();
7876 // ×èòû (äàæå â ñâîåé èãðå):
7880 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7884 if Length(LoadingStat
.Msgs
) = 0 then
7890 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7891 if NextMsg
= Length(Msgs
) then
7893 for i
:= 0 to High(Msgs
)-1 do
7894 Msgs
[i
] := Msgs
[i
+1];
7902 Msgs
[NextMsg
-1] := Text;
7906 PBarWasHere
:= false;
7909 g_ActiveWindow
:= nil;
7911 ProcessLoading(true);
7914 procedure g_Game_StepLoading(Value
: Integer = -1);
7925 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7933 procedure g_Game_ClearLoading();
7942 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7943 if len
< 1 then len
:= 1;
7944 SetLength(Msgs
, len
);
7945 for len
:= Low(Msgs
) to High(Msgs
) do
7948 PBarWasHere
:= false;
7952 procedure Parse_Params(var pars
: TParamStrValues
);
7959 while i
<= ParamCount
do
7962 if (s
[1] = '-') and (Length(s
) > 1) then
7964 if (s
[2] = '-') and (Length(s
) > 2) then
7965 begin // Îäèíî÷íûé ïàðàìåòð
7966 SetLength(pars
, Length(pars
) + 1);
7967 with pars
[High(pars
)] do
7969 Name
:= LowerCase(s
);
7974 if (i
< ParamCount
) then
7975 begin // Ïàðàìåòð ñî çíà÷åíèåì
7977 SetLength(pars
, Length(pars
) + 1);
7978 with pars
[High(pars
)] do
7980 Name
:= LowerCase(s
);
7981 Value
:= LowerCase(ParamStr(i
));
7990 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7995 for i
:= 0 to High(pars
) do
7996 if pars
[i
].Name
= aName
then
7998 Result
:= pars
[i
].Value
;
8003 procedure g_Game_Process_Params();
8005 pars
: TParamStrValues
;
8008 LimT
, LimS
: Integer;
8019 s
:= Find_Param_Value(pars
, '--debug');
8022 g_Game_SetDebugMode();
8023 s
:= Find_Param_Value(pars
, '--netdump');
8028 // Connect when game loads
8029 ip
:= Find_Param_Value(pars
, '-connect');
8033 s
:= Find_Param_Value(pars
, '-port');
8034 if (s
= '') or not TryStrToInt(s
, Port
) then
8037 s
:= Find_Param_Value(pars
, '-pw');
8039 g_Game_StartClient(ip
, Port
, s
);
8043 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8046 gDefaultMegawadStart
:= s
;
8049 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8050 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8052 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8055 // Start map when game loads:
8056 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8057 if isWadPath(map
) then
8060 s
:= Find_Param_Value(pars
, '-gm');
8061 GMode
:= g_Game_TextToMode(s
);
8062 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8063 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8066 s
:= Find_Param_Value(pars
, '-limt');
8067 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8073 s
:= Find_Param_Value(pars
, '-lims');
8074 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8080 s
:= Find_Param_Value(pars
, '-lives');
8081 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8087 s
:= Find_Param_Value(pars
, '-opt');
8089 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
8091 Opt
:= StrToIntDef(s
, 0);
8093 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
8096 s
:= Find_Param_Value(pars
, '--close');
8100 // Override map to test:
8101 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8104 if e_IsValidResourceName(s
) then
8105 e_FindResource(AllMapDirs
, s
);
8106 gTestMap
:= ExpandFileName(s
);
8109 // Delete test map after play:
8110 s
:= Find_Param_Value(pars
, '--testdelete');
8113 //gMapToDelete := MapsDir + map;
8114 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8118 // Delete temporary WAD after play:
8119 s
:= Find_Param_Value(pars
, '--tempdelete');
8120 if (s
<> '') and (gTestMap
<> '') then
8122 gMapToDelete
:= gTestMap
;
8123 gTempDelete
:= True;
8126 // Number of players:
8127 s
:= Find_Param_Value(pars
, '-pl');
8129 n
:= DEFAULT_PLAYERS
8131 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8134 s
:= Find_Param_Value(pars
, '-port');
8135 if (s
= '') or not TryStrToInt(s
, Port
) then
8136 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8138 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8141 // Execute script when game loads:
8142 s
:= Find_Param_Value(pars
, '-exec');
8145 // if not isWadPath(s) then
8146 // s := GameDir + '/' + s;
8151 if IOResult
<> 0 then
8153 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8154 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8158 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8159 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8164 if IOResult
<> 0 then
8166 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8167 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8171 if Pos('#', s
) <> 1 then // script comment
8172 g_Console_Process(s
, True);
8183 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8184 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8185 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8186 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8188 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8189 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8190 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8191 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8193 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8194 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8196 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8197 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8199 {$IFDEF ENABLE_HOLMES}
8200 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8203 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8205 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8207 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8208 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8210 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8211 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8213 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8214 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');