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
44 TDelayedEvent
= record
53 Sound
: TPlayableSound
;
54 Tags
: Array of String;
58 TPlayerSettings
= record
77 function g_Game_IsNet(): Boolean;
78 function g_Game_IsServer(): Boolean;
79 function g_Game_IsClient(): Boolean;
80 procedure g_Game_Init();
81 procedure g_Game_Free (freeTextures
: Boolean=true);
82 procedure g_Game_LoadData();
83 procedure g_Game_FreeData();
84 procedure g_Game_Update();
85 procedure g_Game_Draw();
86 procedure g_Game_Quit();
87 procedure g_Game_SetupScreenSize();
88 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
89 function g_Game_ModeToText(Mode
: Byte): string;
90 function g_Game_TextToMode(Mode
: string): Byte;
91 procedure g_Game_ExecuteEvent(Name
: String);
92 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
93 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
94 procedure g_Game_RemovePlayer();
95 procedure g_Game_Spectate();
96 procedure g_Game_SpectateCenterView();
97 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
98 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
99 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
100 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
101 procedure g_Game_Restart();
102 procedure g_Game_RestartLevel();
103 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
104 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
105 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
106 procedure g_Game_ChangeMap(const MapPath
: String);
107 procedure g_Game_ExitLevel(const Map
: AnsiString);
108 function g_Game_GetFirstMap(WAD
: String): String;
109 function g_Game_GetNextMap(): String;
110 procedure g_Game_NextLevel();
111 procedure g_Game_Pause(Enable
: Boolean);
112 procedure g_Game_HolmesPause(Enable
: Boolean);
113 procedure g_Game_InGameMenu(Show
: Boolean);
114 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
115 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
116 procedure g_Game_Message(Msg
: String; Time
: Word);
117 procedure g_Game_LoadMapList(FileName
: String);
118 procedure g_Game_PauseAllSounds(Enable
: Boolean);
119 procedure g_Game_StopAllSounds(all
: Boolean);
120 procedure g_Game_UpdateTriggerSounds();
121 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
122 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
123 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
124 procedure g_Game_Announce_KillCombo(Param
: Integer);
125 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
126 procedure g_Game_StartVote(Command
, Initiator
: string);
127 procedure g_Game_CheckVote
;
128 procedure g_TakeScreenShot(Filename
: string = '');
129 procedure g_FatalError(Text: String);
130 procedure g_SimpleError(Text: String);
131 function g_Game_IsTestMap(): Boolean;
132 procedure g_Game_DeleteTestMap();
133 procedure GameCVars(P
: SSArray
);
134 procedure GameCommands(P
: SSArray
);
135 procedure GameCheats(P
: SSArray
);
136 procedure DebugCommands(P
: SSArray
);
137 procedure g_Game_Process_Params
;
138 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
139 procedure g_Game_StepLoading(Value
: Integer = -1);
140 procedure g_Game_ClearLoading();
141 procedure g_Game_SetDebugMode();
142 procedure DrawLoadingStat();
143 procedure DrawMenuBackground(tex
: AnsiString);
145 { procedure SetWinPause(Enable: Boolean); }
150 LOADING_SHOW_STEP
= 100;
151 LOADING_INTERLINE
= 20;
166 MESSAGE_DIKEY
= WM_USER
+ 1;
171 EXIT_ENDLEVELSINGLE
= 4;
172 EXIT_ENDLEVELCUSTOM
= 5;
174 GAME_OPTION_RESERVED
= 1;
175 GAME_OPTION_TEAMDAMAGE
= 2;
176 GAME_OPTION_ALLOWEXIT
= 4;
177 GAME_OPTION_WEAPONSTAY
= 8;
178 GAME_OPTION_MONSTERS
= 16;
179 GAME_OPTION_BOTVSPLAYER
= 32;
180 GAME_OPTION_BOTVSMONSTER
= 64;
185 STATE_INTERCUSTOM
= 3;
186 STATE_INTERSINGLE
= 4;
192 LMS_RESPAWN_NONE
= 0;
193 LMS_RESPAWN_WARMUP
= 1;
194 LMS_RESPAWN_FINAL
= 2;
211 CONFIG_FILENAME
= 'Doom2DF.cfg';
213 TEST_MAP_NAME
= '$$$_TEST_$$$';
215 STD_PLAYER_MODEL
= 'Doomer';
223 STATFILE_VERSION
= $03;
227 gGameSettings
: TGameSettings
;
228 gPlayer1Settings
: TPlayerSettings
;
229 gPlayer2Settings
: TPlayerSettings
;
231 gPlayerScreenSize
: TDFPoint
;
232 gPlayer1ScreenCoord
: TDFPoint
;
233 gPlayer2ScreenCoord
: TDFPoint
;
234 gPlayer1
: TPlayer
= nil;
235 gPlayer2
: TPlayer
= nil;
236 gPlayerDrawn
: TPlayer
= nil;
238 gSwitchGameMode
: Byte = GM_DM
;
239 gHearPoint1
, gHearPoint2
: THearPoint
;
240 gSoundEffectsDF
: Boolean = False;
241 gSoundTriggerTime
: Word = 0;
242 gAnnouncer
: Integer = ANNOUNCE_NONE
;
243 goodsnd
: array[0..3] of TPlayableSound
;
244 killsnd
: array[0..3] of TPlayableSound
;
245 hahasnd
: array[0..2] of TPlayableSound
;
246 sound_get_flag
: array[0..1] of TPlayableSound
;
247 sound_lost_flag
: array[0..1] of TPlayableSound
;
248 sound_ret_flag
: array[0..1] of TPlayableSound
;
249 sound_cap_flag
: array[0..1] of TPlayableSound
;
250 gBodyKillEvent
: Integer = -1;
251 gDefInterTime
: ShortInt = -1;
252 gInterEndTime
: LongWord = 0;
253 gInterTime
: LongWord = 0;
254 gServInterTime
: Byte = 0;
255 gGameStartTime
: LongWord = 0;
256 gTotalMonsters
: Integer = 0;
257 gPauseMain
: Boolean = false;
258 gPauseHolmes
: Boolean = false;
259 gShowTime
: Boolean = False;
260 gShowFPS
: Boolean = False;
261 gShowGoals
: Boolean = True;
262 gShowStat
: Boolean = True;
263 gShowKillMsg
: Boolean = True;
264 gShowLives
: Boolean = True;
265 gShowPing
: Boolean = False;
266 gShowMap
: Boolean = False;
268 gState
: Byte = STATE_NONE
;
270 sWidth
, sHeight
: Word;
271 gSpectMode
: Byte = SPECT_NONE
;
272 gSpectHUD
: Boolean = True;
273 gSpectKeyPress
: Boolean = False;
274 gSpectX
: Integer = 0;
275 gSpectY
: Integer = 0;
276 gSpectStep
: Byte = 8;
277 gSpectViewTwo
: Boolean = False;
278 gSpectPID1
: Integer = -1;
279 gSpectPID2
: Integer = -1;
280 gSpectAuto
: Boolean = False;
281 gSpectAutoNext
: LongWord;
282 gSpectAutoStepX
: Integer;
283 gSpectAutoStepY
: Integer;
284 gMusic
: TMusic
= nil;
285 gLoadGameMode
: Boolean;
286 gCheats
: Boolean = False;
287 gMapOnce
: Boolean = False;
288 gMapToDelete
: String;
289 gTempDelete
: Boolean = False;
290 gLastMap
: Boolean = False;
291 gWinSizeX
, gWinSizeY
: Integer;
292 gResolutionChange
: Boolean = False;
293 gRC_Width
, gRC_Height
: Integer;
294 gRC_FullScreen
, gRC_Maximized
: Boolean;
295 gLanguageChange
: Boolean = False;
296 gDebugMode
: Boolean = False;
297 g_debug_Sounds
: Boolean = False;
298 g_debug_Frames
: Boolean = False;
299 g_debug_WinMsgs
: Boolean = False;
300 g_debug_MonsterOff
: Boolean = False;
301 g_debug_BotAIOff
: Byte = 0;
302 g_debug_HealthBar
: Boolean = False;
303 g_Debug_Player
: Boolean = False;
304 gCoopMonstersKilled
: Word = 0;
305 gCoopSecretsFound
: Word = 0;
306 gCoopTotalMonstersKilled
: Word = 0;
307 gCoopTotalSecretsFound
: Word = 0;
308 gCoopTotalMonsters
: Word = 0;
309 gCoopTotalSecrets
: Word = 0;
310 gStatsOff
: Boolean = False;
311 gStatsPressed
: Boolean = False;
312 gExitByTrigger
: Boolean = False;
313 gNextMap
: String = '';
314 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
315 gLMSRespawnTime
: Cardinal = 0;
316 gLMSSoftSpawn
: Boolean = False;
317 gMissionFailed
: Boolean = False;
318 gVoteInProgress
: Boolean = False;
319 gVotePassed
: Boolean = False;
320 gVoteCommand
: string = '';
321 gVoteTimer
: Cardinal = 0;
322 gVoteCmdTimer
: Cardinal = 0;
323 gVoteCount
: Integer = 0;
324 gVoteTimeout
: Cardinal = 30;
325 gVoted
: Boolean = False;
326 gVotesEnabled
: Boolean = True;
327 gEvents
: Array of TGameEvent
;
328 gDelayedEvents
: Array of TDelayedEvent
;
329 gUseChatSounds
: Boolean = True;
330 gChatSounds
: Array of TChatSound
;
331 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
332 gInterReadyCount
: Integer = 0;
334 g_dbg_ignore_bounds
: Boolean = false;
335 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
336 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
338 // move button values:
339 // bits 0-1: l/r state:
340 // 0: neither left, nor right pressed
343 // bits 4-5: l/r state when strafe was pressed
344 P1MoveButton
: Byte = 0;
345 P2MoveButton
: Byte = 0;
347 g_profile_frame_update
: Boolean = false;
348 g_profile_frame_draw
: Boolean = false;
349 g_profile_collision
: Boolean = false;
350 g_profile_los
: Boolean = false;
351 g_profile_history_size
: Integer = 1000;
353 g_rlayer_back
: Boolean = true;
354 g_rlayer_step
: Boolean = true;
355 g_rlayer_wall
: Boolean = true;
356 g_rlayer_door
: Boolean = true;
357 g_rlayer_acid1
: Boolean = true;
358 g_rlayer_acid2
: Boolean = true;
359 g_rlayer_water
: Boolean = true;
360 g_rlayer_fore
: Boolean = true;
363 procedure g_ResetDynlights ();
364 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
365 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
367 function conIsCheatsEnabled (): Boolean; inline;
368 function gPause (): Boolean; inline;
374 {$INCLUDE ../nogl/noGLuses.inc}
375 {$IFDEF ENABLE_HOLMES}
378 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
379 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
380 g_playermodel
, g_gfx
, g_options
, Math
,
381 g_triggers
, g_monsters
, e_sound
, CONFIG
,
382 g_language
, g_net
, g_main
,
383 ENet
, e_msg
, g_netmsg
, g_netmaster
,
384 sfs
, wadreader
, g_system
;
388 hasPBarGfx
: Boolean = false;
391 // ////////////////////////////////////////////////////////////////////////// //
392 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
395 // ////////////////////////////////////////////////////////////////////////// //
396 function conIsCheatsEnabled (): Boolean; inline;
399 if g_Game_IsNet
then exit
;
400 if not gDebugMode
then
402 //if not gCheats then exit;
403 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
404 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
410 // ////////////////////////////////////////////////////////////////////////// //
412 profileFrameDraw
: TProfiler
= nil;
415 // ////////////////////////////////////////////////////////////////////////// //
418 x
, y
, radius
: Integer;
421 exploRadius
: Integer;
425 g_dynLights
: array of TDynLight
= nil;
426 g_dynLightCount
: Integer = 0;
427 g_playerLight
: Boolean = false;
429 procedure g_ResetDynlights ();
433 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
435 for idx
:= 0 to g_dynLightCount
-1 do
437 if g_dynLights
[idx
].exploCount
= -666 then
444 Inc(g_dynLights
[idx
].exploCount
);
445 if (g_dynLights
[idx
].exploCount
< 10) then
447 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
448 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
449 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
450 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
455 g_dynLightCount
:= lnum
;
458 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
460 if not gwin_has_stencil
then exit
;
461 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
462 g_dynLights
[g_dynLightCount
].x
:= x
;
463 g_dynLights
[g_dynLightCount
].y
:= y
;
464 g_dynLights
[g_dynLightCount
].radius
:= radius
;
465 g_dynLights
[g_dynLightCount
].r
:= r
;
466 g_dynLights
[g_dynLightCount
].g
:= g
;
467 g_dynLights
[g_dynLightCount
].b
:= b
;
468 g_dynLights
[g_dynLightCount
].a
:= a
;
469 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
470 Inc(g_dynLightCount
);
473 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
475 if not gwin_has_stencil
then exit
;
476 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
477 g_dynLights
[g_dynLightCount
].x
:= x
;
478 g_dynLights
[g_dynLightCount
].y
:= y
;
479 g_dynLights
[g_dynLightCount
].radius
:= 0;
480 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
481 g_dynLights
[g_dynLightCount
].r
:= r
;
482 g_dynLights
[g_dynLightCount
].g
:= g
;
483 g_dynLights
[g_dynLightCount
].b
:= b
;
484 g_dynLights
[g_dynLightCount
].a
:= 0;
485 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
486 Inc(g_dynLightCount
);
490 // ////////////////////////////////////////////////////////////////////////// //
491 function calcProfilesHeight (prof
: TProfiler
): Integer;
494 if (prof
= nil) then exit
;
495 if (length(prof
.bars
) = 0) then exit
;
496 result
:= length(prof
.bars
)*(16+2);
500 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
507 if (prof
= nil) then exit
;
509 if (length(prof
.bars
) = 0) then exit
;
511 hgt
:= calcProfilesHeight(prof
);
512 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
513 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
515 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
516 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
517 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
520 for ii
:= 0 to High(prof
.bars
) do
522 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);
529 // ////////////////////////////////////////////////////////////////////////// //
531 TEndCustomGameStat
= record
532 PlayerStat
: TPlayerStatArray
;
536 Map
, MapName
: String;
539 TEndSingleGameStat
= record
540 PlayerStat
: Array [0..1] of record
546 TotalSecrets
: Integer;
549 TLoadingStat
= record
553 Msgs
: Array of String;
555 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
558 TParamStrValue
= record
563 TParamStrValues
= Array of TParamStrValue
;
566 INTER_ACTION_TEXT
= 1;
567 INTER_ACTION_PIC
= 2;
568 INTER_ACTION_MUSIC
= 3;
572 FPSCounter
, UPSCounter
: Word;
573 FPSTime
, UPSTime
: LongWord;
574 DataLoaded
: Boolean = False;
575 IsDrawStat
: Boolean = False;
576 CustomStat
: TEndCustomGameStat
;
577 SingleStat
: TEndSingleGameStat
;
578 LoadingStat
: TLoadingStat
;
579 EndingGameCounter
: Byte = 0;
582 MessageLineLength
: Integer = 80;
583 MapList
: SSArray
= nil;
584 MapIndex
: Integer = -1;
585 InterReadyTime
: Integer = -1;
586 StatShotDone
: Boolean = False;
587 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
588 StatDate
: string = '';
594 text: Array of ShortString;
595 anim
: Array of ShortString;
596 pic
: Array of ShortString;
597 mus
: Array of ShortString;
599 triggers
: Array of record
601 actions
: Array of record
602 action
, p1
, p2
: Integer;
605 cur_trigger
: Integer;
618 function Compare(a
, b
: TPlayerStat
): Integer;
620 if a
.Spectator
then Result
:= 1
621 else if b
.Spectator
then Result
:= -1
622 else if a
.Frags
< b
.Frags
then Result
:= 1
623 else if a
.Frags
> b
.Frags
then Result
:= -1
624 else if a
.Deaths
< b
.Deaths
then Result
:= -1
625 else if a
.Deaths
> b
.Deaths
then Result
:= 1
626 else if a
.Kills
< b
.Kills
then Result
:= -1
630 procedure SortGameStat(var stat
: TPlayerStatArray
);
635 if stat
= nil then Exit
;
637 for I
:= High(stat
) downto Low(stat
) do
638 for J
:= Low(stat
) to High(stat
) - 1 do
639 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
642 stat
[J
] := stat
[J
+ 1];
647 // saves a shitty CSV containing the game stats passed to it
648 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
651 dir
, fname
, map
, mode
, etime
: String;
655 dir
:= e_GetWriteableDir(StatsDirs
);
656 // stats are placed in stats/yy/mm/dd/*.csv
657 fname
:= e_CatPath(dir
, Path
);
658 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
659 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
660 AssignFile(s
, fname
);
663 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
664 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
665 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
666 mode
:= g_Game_ModeToText(Stat
.GameMode
);
667 etime
:= Format('%d:%.2d:%.2d', [
668 Stat
.GameTime
div 1000 div 3600,
669 (Stat
.GameTime
div 1000 div 60) mod 60,
670 Stat
.GameTime
div 1000 mod 60
672 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
673 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
679 gGameSettings
.TimeLimit
,
680 gGameSettings
.GoalLimit
,
681 gGameSettings
.Options
,
683 Length(Stat
.PlayerStat
)
685 // line 2: game specific shit
686 // if it's a team game: red score, blue score
687 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
689 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
691 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
692 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
694 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
695 // lines 3-...: team, player name, frags, deaths
696 WriteLn(s
, 'team,name,frags,deaths');
697 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
698 with Stat
.PlayerStat
[I
] do
699 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
701 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
704 g_Console_Add('could not create gamestats file "' + fname
+ '"');
709 function g_Game_ModeToText(Mode
: Byte): string;
713 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
714 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
715 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
716 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
717 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
721 function g_Game_TextToMode(Mode
: string): Byte;
724 Mode
:= UpperCase(Mode
);
725 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
730 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
735 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
740 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
745 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
752 function g_Game_IsNet(): Boolean;
754 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
757 function g_Game_IsServer(): Boolean;
759 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
762 function g_Game_IsClient(): Boolean;
764 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
767 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
774 Result
.name
:= ExtractFileName(WAD
);
775 Result
.description
:= '';
778 w
:= TWADFile
.Create();
781 if not w
.GetResource('INTERSCRIPT', p
, len
) then
787 cfg
:= TConfig
.CreateMem(p
, len
);
788 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
789 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
790 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
791 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
797 procedure g_Game_FreeWAD();
801 for a
:= 0 to High(MegaWAD
.res
.pic
) do
802 if MegaWAD
.res
.pic
[a
] <> '' then
803 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
805 for a
:= 0 to High(MegaWAD
.res
.mus
) do
806 if MegaWAD
.res
.mus
[a
] <> '' then
807 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
809 MegaWAD
.res
.pic
:= nil;
810 MegaWAD
.res
.text := nil;
811 MegaWAD
.res
.anim
:= nil;
812 MegaWAD
.res
.mus
:= nil;
813 MegaWAD
.triggers
:= nil;
815 g_Texture_Delete('TEXTURE_endpic');
816 g_Sound_Delete('MUSIC_endmus');
818 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
819 gGameSettings
.WAD
:= '';
822 procedure g_Game_LoadWAD(WAD
: string);
831 gGameSettings
.WAD
:= WAD
;
832 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
835 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
837 w
:= TWADFile
.Create();
840 if not w
.GetResource('INTERSCRIPT', p
, len
) then
846 cfg
:= TConfig
.CreateMem(p
, len
);
851 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
852 if s = '' then Break;
855 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
856 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
858 g_Texture_CreateWADEx(s, s);
864 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
865 if s = '' then Break;
868 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
869 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
871 g_Music_CreateWADEx(s, s);
874 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
875 if MegaWAD
.endpic
<> '' then
877 TEXTUREFILTER
:= GL_LINEAR
;
878 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
879 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
880 TEXTUREFILTER
:= GL_NEAREST
;
882 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
883 if MegaWAD
.endmus
<> '' then
885 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
886 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
894 {procedure start_trigger(t: string);
898 function next_trigger(): Boolean;
902 procedure DisableCheats();
908 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
909 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
910 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
911 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
913 {$IF DEFINED(D2F_DEBUG)}
914 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
915 gAimLine
:= g_dbg_aimline_on
;
919 procedure g_Game_ExecuteEvent(Name
: String);
925 if gEvents
= nil then
927 for a
:= 0 to High(gEvents
) do
928 if gEvents
[a
].Name
= Name
then
930 if gEvents
[a
].Command
<> '' then
931 g_Console_Process(gEvents
[a
].Command
, True);
936 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
941 if gDelayedEvents
<> nil then
942 for a
:= 0 to High(gDelayedEvents
) do
943 if not gDelayedEvents
[a
].Pending
then
950 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
951 n
:= High(gDelayedEvents
);
953 gDelayedEvents
[n
].Pending
:= True;
954 gDelayedEvents
[n
].DEType
:= DEType
;
955 gDelayedEvents
[n
].DENum
:= Num
;
956 gDelayedEvents
[n
].DEStr
:= Str
;
957 if DEType
= DE_GLOBEVENT
then
958 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
960 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
970 if g_Game_IsNet
and g_Game_IsServer
then
971 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
975 gPauseHolmes
:= false;
978 g_Game_StopAllSounds(False);
983 EndingGameCounter
:= 0;
984 g_ActiveWindow
:= nil;
986 gLMSRespawn
:= LMS_RESPAWN_NONE
;
987 gLMSRespawnTime
:= 0;
990 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
995 begin // Ýòî áûë òåñò
999 begin // Âûõîä â ãëàâíîå ìåíþ
1000 gMusic
.SetByName('MUSIC_MENU');
1002 if gState
<> STATE_SLIST
then
1004 g_GUI_ShowWindow('MainMenu');
1005 gState
:= STATE_MENU
;
1008 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1009 slReturnPressed
:= True;
1010 if g_Net_Slist_Fetch(slCurrent
) then
1012 if slCurrent
= nil then
1013 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1016 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1017 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1020 g_Game_ExecuteEvent('ongameend');
1024 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1026 if not g_Game_IsClient
then g_Game_Restart();
1029 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1031 // Ñòàòèñòèêà Ñâîåé èãðû:
1032 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1034 CustomStat
.GameTime
:= gTime
;
1035 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1036 CustomStat
.MapName
:= gMapInfo
.Name
;
1037 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1038 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1039 CustomStat
.TeamStat
:= gTeamStat
;
1041 CustomStat
.PlayerStat
:= nil;
1043 // Ñòàòèñòèêà èãðîêîâ:
1044 if gPlayers
<> nil then
1046 for a
:= 0 to High(gPlayers
) do
1047 if gPlayers
[a
] <> nil then
1049 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1050 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1053 Name
:= gPlayers
[a
].Name
;
1054 Frags
:= gPlayers
[a
].Frags
;
1055 Deaths
:= gPlayers
[a
].Death
;
1056 Kills
:= gPlayers
[a
].Kills
;
1057 Team
:= gPlayers
[a
].Team
;
1058 Color
:= gPlayers
[a
].Model
.Color
;
1059 Spectator
:= gPlayers
[a
].FSpectator
;
1063 SortGameStat(CustomStat
.PlayerStat
);
1065 if gSaveStats
or gScreenshotStats
then
1068 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1069 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1070 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1071 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1072 if gSaveStats
then SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1075 StatShotDone
:= False;
1078 g_Game_ExecuteEvent('onmapend');
1079 if not g_Game_IsClient
then g_Player_ResetReady
;
1080 gInterReadyCount
:= 0;
1082 // Çàòóõàþùèé ýêðàí:
1083 EndingGameCounter
:= 255;
1084 gState
:= STATE_FOLD
;
1086 if gDefInterTime
< 0 then
1087 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1089 gInterEndTime
:= gDefInterTime
* 1000;
1092 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1094 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1095 SingleStat
.GameTime
:= gTime
;
1096 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1097 SingleStat
.TotalSecrets
:= gSecretsCount
;
1098 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1099 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1100 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1101 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1102 if SingleStat
.TwoPlayers
then
1104 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1105 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1108 g_Game_ExecuteEvent('onmapend');
1111 if gNextMap
<> '' then
1113 gMusic
.SetByName('MUSIC_INTERMUS');
1115 gState
:= STATE_INTERSINGLE
;
1118 g_Game_ExecuteEvent('oninter');
1120 else // Áîëüøå íåò êàðò
1122 // Çàòóõàþùèé ýêðàí:
1123 EndingGameCounter
:= 255;
1124 gState
:= STATE_FOLD
;
1129 // Îêîí÷àíèå îáðàáîòàíî:
1130 if gExit
<> EXIT_QUIT
then
1134 procedure drawTime(X
, Y
: Integer); inline;
1136 e_TextureFontPrint(x
, y
,
1137 Format('%d:%.2d:%.2d', [
1138 gTime
div 1000 div 3600,
1139 (gTime
div 1000 div 60) mod 60,
1140 gTime
div 1000 mod 60
1145 procedure DrawStat();
1147 pc
, x
, y
, w
, h
: Integer;
1148 w1
, w2
, w3
, w4
: Integer;
1150 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1153 stat
: TPlayerStatArray
;
1160 pc
:= g_Player_GetCount
;
1161 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1163 w
:= gScreenWidth
-(gScreenWidth
div 5);
1164 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1167 h
:= 40+ch
*5+(ch
+8)*pc
;
1168 x
:= (gScreenWidth
div 2)-(w
div 2);
1169 y
:= (gScreenHeight
div 2)-(h
div 2);
1171 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1172 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1174 drawTime(x
+w
-78, y
+8);
1176 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1177 map
:= g_ExtractFileName(gMapInfo
.Map
);
1178 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1180 case gGameSettings
.GameMode
of
1183 if gGameSettings
.MaxLives
= 0 then
1184 s1
:= _lc
[I_GAME_DM
]
1186 s1
:= _lc
[I_GAME_LMS
];
1187 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1188 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1193 if gGameSettings
.MaxLives
= 0 then
1194 s1
:= _lc
[I_GAME_TDM
]
1196 s1
:= _lc
[I_GAME_TLMS
];
1197 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1198 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1203 s1
:= _lc
[I_GAME_CTF
];
1204 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1205 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1210 if gGameSettings
.MaxLives
= 0 then
1211 s1
:= _lc
[I_GAME_COOP
]
1213 s1
:= _lc
[I_GAME_SURV
];
1214 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1215 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1226 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1228 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1230 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1232 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1233 gStdFont
, 200, 200, 200, 1);
1235 if NetMode
= NET_SERVER
then
1236 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1238 if NetMode
= NET_CLIENT
then
1239 e_TextureFontPrintEx(x
+8, y
+ 8,
1240 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1244 stat
:= g_Player_GetStats();
1247 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1248 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1250 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1252 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1256 for a
:= TEAM_RED
to TEAM_BLUE
do
1258 if a
= TEAM_RED
then
1260 s1
:= _lc
[I_GAME_TEAM_RED
];
1267 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1273 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1274 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1275 gStdFont
, r
, g
, b
, 1);
1277 _y
:= _y
+ch
+(ch
div 4);
1278 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1279 _y
:= _y
+(ch
div 4);
1281 for aa
:= 0 to High(stat
) do
1282 if stat
[aa
].Team
= a
then
1298 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1300 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1302 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1304 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1311 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1314 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1315 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1316 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1317 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1320 for aa
:= 0 to High(stat
) do
1334 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1335 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1337 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1339 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1341 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1343 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1349 procedure g_Game_Init();
1352 knownFiles
: array of AnsiString = nil;
1354 wext
, s
: AnsiString;
1359 gTempDelete
:= False;
1361 sfsGCDisable(); // temporary disable removing of temporary volumes
1364 TEXTUREFILTER
:= GL_LINEAR
;
1365 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1366 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1367 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1368 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1369 TEXTUREFILTER
:= GL_NEAREST
;
1371 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1372 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1373 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1375 g_Game_ClearLoading();
1376 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1377 g_Game_SetLoadingText('', 0, False);
1379 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1382 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1383 g_PlayerModel_LoadData();
1385 // load models from all possible wad types, in all known directories
1386 // this does a loosy job (linear search, ooph!), but meh
1387 for wext
in wadExtensions
do
1389 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1391 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1395 for s
in knownFiles
do
1397 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1405 SetLength(knownFiles
, length(knownFiles
)+1);
1406 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1408 until (FindNext(SR
) <> 0);
1414 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1416 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
);
1417 for s
in knownFiles
do
1419 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1423 gPauseMain
:= false;
1424 gPauseHolmes
:= false;
1427 {e_MouseInfo.Accel := 1.0;}
1429 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1432 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1433 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1434 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1435 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1436 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1439 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1443 gMusic
:= TMusic
.Create();
1444 gMusic
.SetByName('MUSIC_MENU');
1447 gGameSettings
.WarmupTime
:= 30;
1449 gState
:= STATE_MENU
;
1451 SetLength(gEvents
, 6);
1452 gEvents
[0].Name
:= 'ongamestart';
1453 gEvents
[1].Name
:= 'ongameend';
1454 gEvents
[2].Name
:= 'onmapstart';
1455 gEvents
[3].Name
:= 'onmapend';
1456 gEvents
[4].Name
:= 'oninter';
1457 gEvents
[5].Name
:= 'onwadend';
1459 sfsGCEnable(); // enable releasing unused volumes
1463 procedure g_Game_Free(freeTextures
: Boolean=true);
1465 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1466 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1468 g_Map_Free(freeTextures
);
1470 g_Player_RemoveAllCorpses();
1472 gGameSettings
.GameType
:= GT_NONE
;
1473 if gGameSettings
.GameMode
= GM_SINGLE
then
1474 gGameSettings
.GameMode
:= GM_DM
;
1475 gSwitchGameMode
:= gGameSettings
.GameMode
;
1478 gExitByTrigger
:= False;
1481 function IsActivePlayer(p
: TPlayer
): Boolean;
1486 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1489 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1496 if gPlayers
= nil then
1498 for a
:= Low(gPlayers
) to High(gPlayers
) do
1499 if IsActivePlayer(gPlayers
[a
]) then
1501 if gPlayers
[a
].UID
<> ID
then
1503 Result
:= gPlayers
[a
];
1508 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1514 if gPlayers
= nil then
1518 for a
:= Low(gPlayers
) to High(gPlayers
) do
1519 if IsActivePlayer(gPlayers
[a
]) then
1521 SetLength(ids
, Length(ids
) + 1);
1522 ids
[High(ids
)] := gPlayers
[a
].UID
;
1523 if gPlayers
[a
].UID
= Skip
then
1526 if Length(ids
) = 0 then
1531 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1534 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1540 if gPlayers
= nil then
1544 for a
:= Low(gPlayers
) to High(gPlayers
) do
1545 if IsActivePlayer(gPlayers
[a
]) then
1547 SetLength(ids
, Length(ids
) + 1);
1548 ids
[High(ids
)] := gPlayers
[a
].UID
;
1549 if gPlayers
[a
].UID
= Skip
then
1552 if Length(ids
) = 0 then
1555 Result
:= ids
[Length(ids
) - 1]
1557 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1560 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1566 if gPlayers
= nil then
1570 for a
:= Low(gPlayers
) to High(gPlayers
) do
1571 if IsActivePlayer(gPlayers
[a
]) then
1573 SetLength(ids
, Length(ids
) + 1);
1574 ids
[High(ids
)] := gPlayers
[a
].UID
;
1575 if gPlayers
[a
].UID
= Skip
then
1578 if Length(ids
) = 0 then
1580 if Length(ids
) = 1 then
1585 Result
:= ids
[Random(Length(ids
))];
1587 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1589 Result
:= ids
[Random(Length(ids
))];
1594 function GetRandomSpectMode(Current
: Byte): Byte;
1601 0: Result
:= SPECT_STATS
;
1602 1: Result
:= SPECT_MAPVIEW
;
1603 2: Result
:= SPECT_MAPVIEW
;
1604 3: Result
:= SPECT_PLAYERS
;
1605 4: Result
:= SPECT_PLAYERS
;
1606 5: Result
:= SPECT_PLAYERS
;
1607 6: Result
:= SPECT_PLAYERS
;
1609 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1613 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1619 if (plr
= nil) then exit
;
1620 if (p
= 2) then time
:= 1000 else time
:= 1;
1621 strafeDir
:= MoveButton
shr 4;
1622 MoveButton
:= MoveButton
and $0F;
1624 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1625 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1626 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1627 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1628 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1629 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1631 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1632 if MoveButton
= 1 then
1633 plr
.PressKey(KEY_LEFT
, time
)
1634 else if MoveButton
= 2 then
1635 plr
.PressKey(KEY_RIGHT
, time
);
1637 // if we have "strafe" key, turn off old strafe mechanics
1638 if gPlayerAction
[p
, ACTION_STRAFE
] then
1640 // new strafe mechanics
1641 if (strafeDir
= 0) then
1642 strafeDir
:= MoveButton
; // start strafing
1643 // now set direction according to strafe (reversed)
1644 if (strafeDir
= 2) then
1645 plr
.SetDirection(TDirection
.D_LEFT
)
1646 else if (strafeDir
= 1) then
1647 plr
.SetDirection(TDirection
.D_RIGHT
)
1651 strafeDir
:= 0; // not strafing anymore
1652 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1653 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1654 plr
.SetDirection(TDirection
.D_LEFT
)
1655 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1656 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1657 plr
.SetDirection(TDirection
.D_RIGHT
)
1658 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1659 else if MoveButton
<> 0 then
1660 plr
.SetDirection(TDirection(MoveButton
-1))
1663 // fix movebutton state
1664 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1666 // Îñòàëüíûå êëàâèøè:
1667 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1668 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1669 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1670 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1671 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1672 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1673 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1675 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1676 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1678 for i
:= WP_FIRST
to WP_LAST
do
1680 if gSelectWeapon
[p
, i
] then
1682 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1683 gSelectWeapon
[p
, i
] := False
1687 // HACK: add dynlight here
1688 if gwin_k8_enable_light_experiments
then
1690 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1692 g_playerLight
:= true;
1694 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1696 g_playerLight
:= false;
1700 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1703 // HACK: don't have a "key was pressed" function
1704 procedure InterReady();
1706 if InterReadyTime
> gTime
then Exit
;
1707 InterReadyTime
:= gTime
+ 3000;
1708 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1711 procedure g_Game_Update();
1713 Msg
: g_gui
.TMessage
;
1719 function sendMonsPos (mon
: TMonster
): Boolean;
1721 result
:= false; // don't stop
1722 // this will also reset "need-send" flag
1723 if mon
.gncNeedSend
then
1725 MH_SEND_MonsterPos(mon
.UID
);
1727 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1729 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1731 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1733 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1737 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1739 result
:= false; // don't stop
1740 // this will also reset "need-send" flag
1741 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1745 reliableUpdate
: Boolean;
1750 // Ïîðà âûêëþ÷àòü èãðó:
1751 if gExit
= EXIT_QUIT
then
1753 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1757 if gExit
= EXIT_QUIT
then
1761 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1762 // no need to, as we'll do it in event handler
1764 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1767 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1769 gExit
:= EXIT_SIMPLE
;
1774 // process master server communications
1775 g_Net_Slist_Pulse();
1778 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1779 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1780 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1781 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1783 if g_Game_IsNet
and g_Game_IsServer
then
1785 gInterTime
:= gInterTime
+ GAME_TICK
;
1786 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1787 if a
<> gServInterTime
then
1789 gServInterTime
:= a
;
1790 MH_SEND_TimeSync(gServInterTime
);
1794 if (not g_Game_IsClient
) and
1798 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1799 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1800 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1801 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1803 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1804 and (g_ActiveWindow
= nil)
1806 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1809 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1810 g_Game_StopAllSounds(True);
1812 if gMapOnce
then // Ýòî áûë òåñò
1813 gExit
:= EXIT_SIMPLE
1815 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1816 g_Game_ChangeMap(gNextMap
)
1817 else // Ñëåäóþùåé êàðòû íåò
1819 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1821 // Âûõîä â ãëàâíîå ìåíþ:
1823 g_GUI_ShowWindow('MainMenu');
1824 gMusic
.SetByName('MUSIC_MENU');
1826 gState
:= STATE_MENU
;
1829 // Ôèíàëüíàÿ êàðòèíêà:
1830 g_Game_ExecuteEvent('onwadend');
1832 if not gMusic
.SetByName('MUSIC_endmus') then
1833 gMusic
.SetByName('MUSIC_STDENDMUS');
1835 gState
:= STATE_ENDPIC
;
1837 g_Game_ExecuteEvent('ongameend');
1842 else if g_Game_IsClient
and
1845 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1846 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1847 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1848 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1850 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1851 and (g_ActiveWindow
= nil)
1859 if gState
= STATE_INTERTEXT
then
1860 if InterText
.counter
> 0 then
1861 InterText
.counter
:= InterText
.counter
- 1;
1864 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1866 if EndingGameCounter
= 0 then
1868 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1869 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1871 InterReadyTime
:= -1;
1872 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1874 g_Game_ExecuteEvent('onwadend');
1875 if not gMusic
.SetByName('MUSIC_endmus') then
1876 gMusic
.SetByName('MUSIC_STDENDMUS');
1879 gMusic
.SetByName('MUSIC_ROUNDMUS');
1882 gState
:= STATE_INTERCUSTOM
;
1885 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1887 gMusic
.SetByName('MUSIC_INTERMUS');
1889 gState
:= STATE_INTERSINGLE
;
1892 g_Game_ExecuteEvent('oninter');
1895 DecMin(EndingGameCounter
, 6, 0);
1898 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1900 if gMapOnce
then // Ýòî áûë òåñò
1902 gExit
:= EXIT_SIMPLE
;
1908 g_Serverlist_Control(slCurrent
, slTable
);
1911 // Ñòàòèñòèêà ïî Tab:
1913 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1916 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1918 // Âðåìÿ += 28 ìèëëèñåêóíä:
1919 gTime
:= gTime
+ GAME_TICK
;
1921 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1922 if MessageTime
= 0 then
1924 if MessageTime
> 0 then
1925 MessageTime
:= MessageTime
- 1;
1927 if (g_Game_IsServer
) then
1929 // Áûë çàäàí ëèìèò âðåìåíè:
1930 if (gGameSettings
.TimeLimit
> 0) then
1931 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1932 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1937 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1938 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1939 g_Game_RestartRound(gLMSSoftSpawn
);
1941 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1942 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1944 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1946 g_Console_Process(gVoteCommand
);
1948 gVotePassed
:= False;
1951 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1952 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1953 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1954 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1955 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1957 // Áûë çàäàí ëèìèò ïîáåä:
1958 if (gGameSettings
.GoalLimit
> 0) then
1962 if gGameSettings
.GameMode
= GM_DM
then
1963 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1964 for i
:= 0 to High(gPlayers
) do
1965 if gPlayers
[i
] <> nil then
1966 if gPlayers
[i
].Frags
> b
then
1967 b
:= gPlayers
[i
].Frags
;
1970 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1971 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1972 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1975 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1976 if b
>= gGameSettings
.GoalLimit
then
1983 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1984 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1985 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1986 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1988 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1989 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1990 end // if not console
1993 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1995 // process weapon switch queue
1999 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2000 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2002 if not gSpectKeyPress
then
2004 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2006 // switch spect mode
2008 SPECT_NONE
: ; // not spectator
2010 SPECT_MAPVIEW
: Inc(gSpectMode
);
2011 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2013 gSpectKeyPress
:= True;
2015 if (gSpectMode
= SPECT_MAPVIEW
)
2016 and (not gSpectAuto
) then
2018 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2019 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2020 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2021 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2022 if gPlayerAction
[0, ACTION_LOOKUP
] then
2023 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2024 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2025 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2026 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2029 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2030 gSpectKeyPress
:= True;
2032 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2035 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2036 gSpectKeyPress
:= True;
2039 if (gSpectMode
= SPECT_PLAYERS
)
2040 and (not gSpectAuto
) then
2042 if gPlayerAction
[0, ACTION_LOOKUP
] then
2045 gSpectViewTwo
:= True;
2046 gSpectKeyPress
:= True;
2048 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2050 // remove second view
2051 gSpectViewTwo
:= False;
2052 gSpectKeyPress
:= True;
2054 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2056 // prev player (view 1)
2057 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2058 gSpectKeyPress
:= True;
2060 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2062 // next player (view 1)
2063 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2064 gSpectKeyPress
:= True;
2066 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2068 // prev player (view 2)
2069 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2070 gSpectKeyPress
:= True;
2072 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2074 // next player (view 2)
2075 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2076 gSpectKeyPress
:= True;
2079 if gPlayerAction
[0, ACTION_ATTACK
] then
2081 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2084 gSpectAutoNext
:= 0;
2085 gSpectViewTwo
:= False;
2086 gSpectKeyPress
:= True;
2091 gSpectMode
:= SPECT_STATS
;
2092 gSpectAuto
:= False;
2093 gSpectKeyPress
:= True;
2098 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2099 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2100 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2101 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2102 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2103 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2104 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2105 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2106 gSpectKeyPress
:= False;
2110 if gSpectMode
= SPECT_MAPVIEW
then
2112 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2114 gSpectAutoNext
:= gTime
2117 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2119 gSpectAutoNext
:= gTime
2123 if gSpectAutoNext
<= gTime
then
2125 if gSpectAutoNext
> 0 then
2127 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2131 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2132 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2133 gSpectAutoStepX
:= Random(9) - 4;
2134 gSpectAutoStepY
:= Random(9) - 4;
2135 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2136 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2137 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2138 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2139 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2140 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2144 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2149 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2150 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2151 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2157 // Îáíîâëÿåì âñå îñòàëüíîå:
2160 g_Triggers_Update();
2162 g_Monsters_Update();
2164 g_Player_UpdateAll();
2165 g_Player_UpdatePhysicalObjects();
2167 // server: send newly spawned monsters unconditionally
2168 if (gGameSettings
.GameType
= GT_SERVER
) then
2170 if (Length(gMonstersSpawned
) > 0) then
2172 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2173 SetLength(gMonstersSpawned
, 0);
2177 if (gSoundTriggerTime
> 8) then
2179 g_Game_UpdateTriggerSounds();
2180 gSoundTriggerTime
:= 0;
2184 Inc(gSoundTriggerTime
);
2187 if (NetMode
= NET_SERVER
) then
2189 Inc(NetTimeToUpdate
);
2190 Inc(NetTimeToReliable
);
2192 // send monster updates
2193 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2195 // send all monsters (periodic sync)
2196 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2198 for I
:= 0 to High(gPlayers
) do
2200 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2203 g_Mons_ForEach(sendMonsPos
);
2205 if reliableUpdate
then
2207 NetTimeToReliable
:= 0;
2208 NetTimeToUpdate
:= NetUpdateRate
;
2212 NetTimeToUpdate
:= 0;
2217 // send only mosters with some unexpected changes
2218 g_Mons_ForEach(sendMonsPosUnexpected
);
2221 // send unexpected platform changes
2222 g_Map_NetSendInterestingPanels();
2224 g_Net_Slist_ServerUpdate();
2226 if NetUseMaster then
2228 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2230 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2232 NetTimeToMaster := gTime + NetMasterRate;
2237 else if (NetMode
= NET_CLIENT
) then
2239 MC_SEND_PlayerPos();
2241 end; // if gameOn ...
2243 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2244 if g_ActiveWindow
<> nil then
2246 w
:= e_GetFirstKeyPressed();
2248 if (w
<> IK_INVALID
) then
2250 Msg
.Msg
:= MESSAGE_DIKEY
;
2252 g_ActiveWindow
.OnMessage(Msg
);
2255 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2256 if g_ActiveWindow
<> nil then
2257 g_ActiveWindow
.Update();
2259 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2260 if gResolutionChange
then
2262 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2263 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2264 gResolutionChange
:= False;
2265 g_ActiveWindow
:= nil;
2268 // Íóæíî ñìåíèòü ÿçûê:
2269 if gLanguageChange
then
2271 //e_WriteLog('Read language file', MSG_NOTIFY);
2272 //g_Language_Load(DataDir + gLanguage + '.txt');
2273 g_Language_Set(gLanguage
);
2277 gLanguageChange
:= False;
2281 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2282 if e_KeyPressed(IK_F10
) and
2284 (not gConsoleShow
) and
2285 (g_ActiveWindow
= nil) then
2290 Time
:= sys_GetTicks() {div 1000};
2292 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2293 if gDelayedEvents
<> nil then
2294 for a
:= 0 to High(gDelayedEvents
) do
2295 if gDelayedEvents
[a
].Pending
and
2297 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2298 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2301 case gDelayedEvents
[a
].DEType
of
2303 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2306 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2310 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2311 if g_Game_IsNet
and g_Game_IsServer
then
2312 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2316 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2318 gDelayedEvents
[a
].Pending
:= False;
2321 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2322 UPSCounter
:= UPSCounter
+ 1;
2323 if Time
- UPSTime
>= 1000 then
2332 g_Weapon_AddDynLights();
2333 g_Items_AddDynLights();
2337 procedure g_Game_LoadChatSounds(Resource
: string);
2340 FileName
, Snd
: string;
2342 len
, cnt
, tags
, i
, j
: Integer;
2345 FileName
:= g_ExtractWadName(Resource
);
2347 WAD
:= TWADFile
.Create();
2348 WAD
.ReadFile(FileName
);
2350 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2357 cfg
:= TConfig
.CreateMem(p
, len
);
2358 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2360 SetLength(gChatSounds
, cnt
);
2361 for i
:= 0 to Length(gChatSounds
) - 1 do
2363 gChatSounds
[i
].Sound
:= nil;
2364 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2365 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2366 if (Snd
= '') or (Tags
<= 0) then
2368 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2369 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2370 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2371 SetLength(gChatSounds
[i
].Tags
, tags
);
2372 for j
:= 0 to tags
- 1 do
2373 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2374 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2381 procedure g_Game_FreeChatSounds();
2385 for i
:= 0 to Length(gChatSounds
) - 1 do
2387 gChatSounds
[i
].Sound
.Free();
2388 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2390 SetLength(gChatSounds
, 0);
2394 procedure g_Game_LoadData();
2401 if DataLoaded
then Exit
;
2403 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2405 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2406 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2407 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2408 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2409 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2410 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2411 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2412 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2413 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2414 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2415 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2416 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2417 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2418 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2419 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2422 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2423 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2424 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2425 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2429 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2430 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2431 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2432 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2433 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
2439 hasPBarGfx
:= false;
2443 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2444 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2445 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2446 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2447 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2448 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2449 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2450 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2451 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2452 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2453 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2454 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2455 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2456 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2457 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2458 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2459 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2460 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2461 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2462 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2463 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2464 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2465 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2466 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2467 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2472 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2473 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2474 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2475 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2476 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2477 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2478 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2479 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2480 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2481 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2483 goodsnd
[0] := TPlayableSound
.Create();
2484 goodsnd
[1] := TPlayableSound
.Create();
2485 goodsnd
[2] := TPlayableSound
.Create();
2486 goodsnd
[3] := TPlayableSound
.Create();
2488 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2489 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2490 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2491 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2493 killsnd
[0] := TPlayableSound
.Create();
2494 killsnd
[1] := TPlayableSound
.Create();
2495 killsnd
[2] := TPlayableSound
.Create();
2496 killsnd
[3] := TPlayableSound
.Create();
2498 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2499 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2500 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2501 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2503 hahasnd
[0] := TPlayableSound
.Create();
2504 hahasnd
[1] := TPlayableSound
.Create();
2505 hahasnd
[2] := TPlayableSound
.Create();
2507 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2508 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2509 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2511 sound_get_flag
[0] := TPlayableSound
.Create();
2512 sound_get_flag
[1] := TPlayableSound
.Create();
2513 sound_lost_flag
[0] := TPlayableSound
.Create();
2514 sound_lost_flag
[1] := TPlayableSound
.Create();
2515 sound_ret_flag
[0] := TPlayableSound
.Create();
2516 sound_ret_flag
[1] := TPlayableSound
.Create();
2517 sound_cap_flag
[0] := TPlayableSound
.Create();
2518 sound_cap_flag
[1] := TPlayableSound
.Create();
2520 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2521 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2522 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2523 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2524 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2525 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2526 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2527 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2529 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2531 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2534 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2535 g_Weapon_LoadData();
2537 g_Monsters_LoadData();
2542 procedure g_Game_FreeData();
2544 if not DataLoaded
then Exit
;
2547 g_Weapon_FreeData();
2548 g_Monsters_FreeData();
2550 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2552 g_Texture_Delete('NOTEXTURE');
2553 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2554 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2555 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2556 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2557 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2558 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2559 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2560 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2561 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2562 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2563 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2564 g_Frames_DeleteByName('FRAMES_TELEPORT');
2565 g_Frames_DeleteByName('FRAMES_PUNCH');
2566 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2567 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2568 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2569 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2570 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2571 g_Sound_Delete('SOUND_GAME_TELEPORT');
2572 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2573 g_Sound_Delete('SOUND_GAME_SECRET');
2574 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2575 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2576 g_Sound_Delete('SOUND_GAME_BULK1');
2577 g_Sound_Delete('SOUND_GAME_BULK2');
2578 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2579 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2580 g_Sound_Delete('SOUND_GAME_BURNING');
2581 g_Sound_Delete('SOUND_GAME_SWITCH1');
2582 g_Sound_Delete('SOUND_GAME_SWITCH0');
2589 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2590 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2591 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2592 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2599 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2600 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2601 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2602 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2608 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2609 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2610 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2612 sound_get_flag
[0].Free();
2613 sound_get_flag
[1].Free();
2614 sound_lost_flag
[0].Free();
2615 sound_lost_flag
[1].Free();
2616 sound_ret_flag
[0].Free();
2617 sound_ret_flag
[1].Free();
2618 sound_cap_flag
[0].Free();
2619 sound_cap_flag
[1].Free();
2621 g_Sound_Delete('SOUND_CTF_GET1');
2622 g_Sound_Delete('SOUND_CTF_GET2');
2623 g_Sound_Delete('SOUND_CTF_LOST1');
2624 g_Sound_Delete('SOUND_CTF_LOST2');
2625 g_Sound_Delete('SOUND_CTF_RETURN1');
2626 g_Sound_Delete('SOUND_CTF_RETURN2');
2627 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2628 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2630 g_Game_FreeChatSounds();
2632 DataLoaded
:= False;
2635 procedure DrawCustomStat();
2641 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2642 s1
, s2
, topstr
: String;
2644 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2648 if g_Console_Action(ACTION_SCORES
) then
2650 if not gStatsPressed
then
2652 gStatsOff
:= not gStatsOff
;
2653 gStatsPressed
:= True;
2657 gStatsPressed
:= False;
2661 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2662 w
:= (Length(s1
) * ww2
) div 2;
2663 x
:= gScreenWidth
div 2 - w
;
2665 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2669 if (gGameSettings
.GameMode
= GM_COOP
) then
2671 if gMissionFailed
then
2672 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2674 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2677 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2679 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2680 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2682 if g_Game_IsNet
then
2684 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2685 if not gChatShow
then
2686 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2687 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2690 if g_Game_IsClient
then
2691 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2693 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2694 if not gChatShow
then
2695 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2696 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2701 w
:= gScreenWidth
-x
*2;
2707 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2708 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2710 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2712 case CustomStat
.GameMode
of
2715 if gGameSettings
.MaxLives
= 0 then
2716 s1
:= _lc
[I_GAME_DM
]
2718 s1
:= _lc
[I_GAME_LMS
];
2722 if gGameSettings
.MaxLives
= 0 then
2723 s1
:= _lc
[I_GAME_TDM
]
2725 s1
:= _lc
[I_GAME_TLMS
];
2727 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2730 if gGameSettings
.MaxLives
= 0 then
2731 s1
:= _lc
[I_GAME_COOP
]
2733 s1
:= _lc
[I_GAME_SURV
];
2739 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2743 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2744 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2747 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2748 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2749 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2750 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2752 pc
:= Length(CustomStat
.PlayerStat
);
2753 if pc
= 0 then Exit
;
2755 if CustomStat
.GameMode
= GM_COOP
then
2757 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2759 s2
:= _lc
[I_GAME_MONSTERS
];
2760 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2761 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2763 s2
:= _lc
[I_GAME_SECRETS
];
2764 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2765 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2768 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2770 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2771 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2772 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2774 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2775 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2776 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2780 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2785 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2786 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2787 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2789 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2792 for t
:= TEAM_RED
to TEAM_BLUE
do
2794 if t
= TEAM_RED
then
2796 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2797 gStdFont
, 255, 0, 0, 1);
2798 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2799 gStdFont
, 255, 0, 0, 1);
2806 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2807 gStdFont
, 0, 0, 255, 1);
2808 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2809 gStdFont
, 0, 0, 255, 1);
2815 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2818 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2819 if CustomStat
.PlayerStat
[p
].Team
= t
then
2820 with CustomStat
.PlayerStat
[p
] do
2834 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2835 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2837 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2838 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2839 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2846 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2849 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2850 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2851 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2854 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2855 with CustomStat
.PlayerStat
[p
] do
2857 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2864 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2865 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2867 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2868 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2869 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2874 // HACK: take stats screenshot immediately after the first frame of the stats showing
2875 if gScreenshotStats
and not StatShotDone
then
2877 g_TakeScreenShot('stats/' + StatFilename
);
2878 StatShotDone
:= True;
2882 procedure DrawSingleStat();
2884 tm
, key_x
, val_x
, y
: Integer;
2888 procedure player_stat(n
: Integer);
2894 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2895 s2
:= Format(' %d', [gTotalMonsters
]);
2897 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2898 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2899 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2900 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2902 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2903 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2905 // "Kills-per-minute: ##.#":
2906 s1
:= _lc
[I_MENU_INTER_KPM
];
2908 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2910 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2911 s2
:= Format(' %.1f', [kpm
]);
2913 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2914 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2916 // "Secrets found: # / #":
2917 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2918 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2920 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2921 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2922 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2923 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2925 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2926 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2930 // "Level Complete":
2931 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2932 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2934 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2935 s1
:= _lc
[I_MENU_INTER_KPM
];
2936 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2939 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2941 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2942 val_x
:= key_x
+ w1
;
2945 tm
:= SingleStat
.GameTime
div 1000;
2946 s1
:= _lc
[I_MENU_INTER_TIME
];
2947 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2949 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2950 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2952 if SingleStat
.TwoPlayers
then
2955 s1
:= _lc
[I_MENU_PLAYER_1
];
2956 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2957 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2959 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2964 s1
:= _lc
[I_MENU_PLAYER_2
];
2965 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2966 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2968 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2974 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2980 procedure DrawLoadingStat();
2981 procedure drawRect (x
, y
, w
, h
: Integer);
2983 if (w
< 1) or (h
< 1) then exit
;
2985 glVertex2f(x
+0.375, y
+0.375);
2986 glVertex2f(x
+w
+0.375, y
+0.375);
2987 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2988 glVertex2f(x
+0.375, y
+h
+0.375);
2992 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2994 rectW
, rectH
: Integer;
3001 idl
, idr
, idb
, idm
: LongWord;
3005 if (total
< 1) then exit
;
3006 if (cur
< 1) then exit
; // don't blink
3007 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3008 //if (cur < 0) then cur := 0;
3009 //if (cur > total) then cur := total;
3012 if (hasPBarGfx
) then
3014 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3015 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3016 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3017 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3018 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3019 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3020 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3021 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3023 //rectW := gScreenWidth-360;
3024 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3027 x0
:= (gScreenWidth
-rectW
) div 2;
3028 y0
:= gScreenHeight
-rectH
-64;
3029 if (y0
< 2) then y0
:= 2;
3031 glEnable(GL_SCISSOR_TEST
);
3034 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3035 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3036 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3039 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3041 while (f
< x0
+rectW
) do
3043 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3048 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3049 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3052 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3053 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3057 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3063 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3067 rectW
:= gScreenWidth
-64;
3070 x0
:= (gScreenWidth
-rectW
) div 2;
3071 y0
:= gScreenHeight
-rectH
-64;
3072 if (y0
< 2) then y0
:= 2;
3074 glDisable(GL_BLEND
);
3075 glDisable(GL_TEXTURE_2D
);
3077 //glClearColor(0, 0, 0, 0);
3078 //glClear(GL_COLOR_BUFFER_BIT);
3080 glColor4ub(127, 127, 127, 255);
3081 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3083 glColor4ub(0, 0, 0, 255);
3084 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3086 glColor4ub(127, 127, 127, 255);
3087 wdt
:= rectW
*cur
div total
;
3088 if (wdt
> rectW
) then wdt
:= rectW
;
3089 drawRect(x0
, y0
, wdt
, rectH
);
3098 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3100 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3101 yy
:= (gScreenHeight
div 3);
3102 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3103 xx
:= (gScreenWidth
div 3);
3107 for i
:= 0 to NextMsg
-1 do
3109 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3110 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3114 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3115 yy
:= yy
+ LOADING_INTERLINE
;
3116 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3121 procedure DrawMenuBackground(tex
: AnsiString);
3127 if g_Texture_Get(tex
, ID
) then
3129 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3130 e_GetTextureSize(ID
, @w
, @h
);
3132 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3134 w
:= trunc(w
* (gScreenHeight
/ h
));
3135 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3137 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3140 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3142 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3144 function monDraw (mon
: TMonster
): Boolean;
3146 result
:= false; // don't stop
3151 // Ëåâûé âåðõíèé óãîë
3152 aX
:= Obj
.X
div ScaleSz
+ 1;
3153 aY
:= Obj
.Y
div ScaleSz
+ 1;
3155 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3156 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3157 // Ïðàâûé íèæíèé óãîë
3158 aX2
:= aX
+ aX2
- 1;
3159 aY2
:= aY
+ aY2
- 1;
3160 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3166 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3167 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3170 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3171 ScaleSz
:= 16 div Scale
;
3172 // Ðàçìåðû ìèíè-êàðòû:
3173 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3174 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3176 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3178 if gWalls
<> nil then
3181 for a
:= 0 to High(gWalls
) do
3183 if PanelType
<> 0 then
3185 // Ëåâûé âåðõíèé óãîë:
3186 aX
:= X
div ScaleSz
;
3187 aY
:= Y
div ScaleSz
;
3189 aX2
:= max(Width
div ScaleSz
, 1);
3190 aY2
:= max(Height
div ScaleSz
, 1);
3191 // Ïðàâûé íèæíèé óãîë:
3192 aX2
:= aX
+ aX2
- 1;
3193 aY2
:= aY
+ aY2
- 1;
3196 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3197 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3198 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3202 if gSteps
<> nil then
3205 for a
:= 0 to High(gSteps
) do
3207 if PanelType
<> 0 then
3209 // Ëåâûé âåðõíèé óãîë:
3210 aX
:= X
div ScaleSz
;
3211 aY
:= Y
div ScaleSz
;
3213 aX2
:= max(Width
div ScaleSz
, 1);
3214 aY2
:= max(Height
div ScaleSz
, 1);
3215 // Ïðàâûé íèæíèé óãîë:
3216 aX2
:= aX
+ aX2
- 1;
3217 aY2
:= aY
+ aY2
- 1;
3219 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3222 if gLifts
<> nil then
3225 for a
:= 0 to High(gLifts
) do
3227 if PanelType
<> 0 then
3229 // Ëåâûé âåðõíèé óãîë:
3230 aX
:= X
div ScaleSz
;
3231 aY
:= Y
div ScaleSz
;
3233 aX2
:= max(Width
div ScaleSz
, 1);
3234 aY2
:= max(Height
div ScaleSz
, 1);
3235 // Ïðàâûé íèæíèé óãîë:
3236 aX2
:= aX
+ aX2
- 1;
3237 aY2
:= aY
+ aY2
- 1;
3240 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3241 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3242 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3243 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3247 if gWater
<> nil then
3250 for a
:= 0 to High(gWater
) do
3252 if PanelType
<> 0 then
3254 // Ëåâûé âåðõíèé óãîë:
3255 aX
:= X
div ScaleSz
;
3256 aY
:= Y
div ScaleSz
;
3258 aX2
:= max(Width
div ScaleSz
, 1);
3259 aY2
:= max(Height
div ScaleSz
, 1);
3260 // Ïðàâûé íèæíèé óãîë:
3261 aX2
:= aX
+ aX2
- 1;
3262 aY2
:= aY
+ aY2
- 1;
3264 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3267 if gAcid1
<> nil then
3269 // Ðèñóåì êèñëîòó 1:
3270 for a
:= 0 to High(gAcid1
) do
3272 if PanelType
<> 0 then
3274 // Ëåâûé âåðõíèé óãîë:
3275 aX
:= X
div ScaleSz
;
3276 aY
:= Y
div ScaleSz
;
3278 aX2
:= max(Width
div ScaleSz
, 1);
3279 aY2
:= max(Height
div ScaleSz
, 1);
3280 // Ïðàâûé íèæíèé óãîë:
3281 aX2
:= aX
+ aX2
- 1;
3282 aY2
:= aY
+ aY2
- 1;
3284 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3287 if gAcid2
<> nil then
3289 // Ðèñóåì êèñëîòó 2:
3290 for a
:= 0 to High(gAcid2
) do
3292 if PanelType
<> 0 then
3294 // Ëåâûé âåðõíèé óãîë:
3295 aX
:= X
div ScaleSz
;
3296 aY
:= Y
div ScaleSz
;
3298 aX2
:= max(Width
div ScaleSz
, 1);
3299 aY2
:= max(Height
div ScaleSz
, 1);
3300 // Ïðàâûé íèæíèé óãîë:
3301 aX2
:= aX
+ aX2
- 1;
3302 aY2
:= aY
+ aY2
- 1;
3304 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3307 if gPlayers
<> nil then
3310 for a
:= 0 to High(gPlayers
) do
3311 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3313 // Ëåâûé âåðõíèé óãîë:
3314 aX
:= Obj
.X
div ScaleSz
+ 1;
3315 aY
:= Obj
.Y
div ScaleSz
+ 1;
3317 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3318 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3319 // Ïðàâûé íèæíèé óãîë:
3320 aX2
:= aX
+ aX2
- 1;
3321 aY2
:= aY
+ aY2
- 1;
3323 if gPlayers
[a
] = p
then
3324 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3327 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3328 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3329 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3334 g_Mons_ForEach(monDraw
);
3339 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3341 if not hasAmbient
then exit
;
3342 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3346 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3347 //FIXME: broken for splitscreen mode
3348 procedure renderDynLightsInternal ();
3350 //hasAmbient: Boolean;
3351 //ambColor: TDFColor;
3353 lx
, ly
, lrad
: Integer;
3354 scxywh
: array[0..3] of GLint
;
3357 if e_NoGraphics
then exit
;
3359 //TODO: lights should be in separate grid, i think
3360 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3361 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3364 //ambColor := gCurrentMap['light_ambient'].rgba;
3365 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3367 { // this will multiply incoming color to alpha from framebuffer
3369 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3373 * light rendering: (INVALID!)
3374 * glStencilFunc(GL_EQUAL, 0, $ff);
3376 * glClear(GL_STENCIL_BUFFER_BIT);
3377 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3378 * draw shadow volume into stencil buffer
3379 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3380 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3382 * draw color-less quad with light alpha (WARNING! don't touch color!)
3383 * glEnable(GL_BLEND);
3384 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3385 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3387 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3388 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3390 // setup OpenGL parameters
3391 glStencilMask($FFFFFFFF);
3392 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3393 glEnable(GL_STENCIL_TEST
);
3394 glEnable(GL_SCISSOR_TEST
);
3395 glClear(GL_STENCIL_BUFFER_BIT
);
3396 glStencilFunc(GL_EQUAL
, 0, $ff);
3398 for lln
:= 0 to g_dynLightCount
-1 do
3400 lx
:= g_dynLights
[lln
].x
;
3401 ly
:= g_dynLights
[lln
].y
;
3402 lrad
:= g_dynLights
[lln
].radius
;
3403 if (lrad
< 3) then continue
;
3405 if (lx
-sX
+lrad
< 0) then continue
;
3406 if (ly
-sY
+lrad
< 0) then continue
;
3407 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3408 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3410 // set scissor to optimize drawing
3411 if (g_dbg_scale
= 1.0) then
3413 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3417 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3419 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3420 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3421 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3422 // draw extruded panels
3423 glDisable(GL_TEXTURE_2D
);
3424 glDisable(GL_BLEND
);
3425 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3426 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3427 // render light texture
3428 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3429 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3432 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3433 glEnable(GL_TEXTURE_2D
);
3434 // color and opacity
3435 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3436 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3438 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3439 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3440 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3441 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3446 glDisable(GL_STENCIL_TEST
);
3447 glDisable(GL_BLEND
);
3448 glDisable(GL_SCISSOR_TEST
);
3449 //glScissor(0, 0, sWidth, sHeight);
3451 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3452 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3456 function fixViewportForScale (): Boolean;
3458 nx0
, ny0
, nw
, nh
: Integer;
3461 if (g_dbg_scale
<> 1.0) then
3464 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3465 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3466 nw
:= round(sWidth
/g_dbg_scale
);
3467 nh
:= round(sHeight
/g_dbg_scale
);
3476 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3477 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3478 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3480 TDrawCB
= procedure ();
3483 hasAmbient
: Boolean;
3485 doAmbient
: Boolean = false;
3487 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3492 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3493 if gdbg_map_use_accel_render
then
3495 tagmask
:= panelTypeToTag(panType
);
3496 while (gDrawPanelList
.count
> 0) do
3498 pan
:= TPanel(gDrawPanelList
.front());
3499 if ((pan
.tag
and tagmask
) = 0) then break
;
3500 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3501 gDrawPanelList
.popFront();
3506 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3508 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3511 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3513 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3514 if assigned(cb
) then cb();
3515 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3519 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3521 // our accelerated renderer will collect all panels to gDrawPanelList
3522 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3523 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3524 if gdbg_map_use_accel_render
then
3526 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3528 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3530 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3531 g_Map_DrawBack(backXOfs
, backYOfs
);
3532 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3534 if setTransMatrix
then
3536 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3537 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3538 glTranslatef(-sX
, -sY
, 0);
3542 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3543 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3548 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3549 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3550 glClear(GL_COLOR_BUFFER_BIT);
3553 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3556 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3557 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3558 drawOther('items', @g_Items_Draw
);
3559 drawOther('weapons', @g_Weapon_Draw
);
3560 drawOther('shells', @g_Player_DrawShells
);
3561 drawOther('drawall', @g_Player_DrawAll
);
3562 drawOther('corpses', @g_Player_DrawCorpses
);
3563 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3564 drawOther('monsters', @g_Monsters_Draw
);
3565 drawOther('itemdrop', @g_Items_DrawDrop
);
3566 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3567 drawOther('gfx', @g_GFX_Draw
);
3568 drawOther('flags', @g_Map_DrawFlags
);
3569 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3570 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3571 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3572 drawOther('dynlights', @renderDynLightsInternal
);
3574 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3576 renderAmbientQuad(hasAmbient
, ambColor
);
3580 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3583 if g_debug_HealthBar
then
3585 g_Monsters_DrawHealth();
3586 g_Player_DrawHealth();
3589 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3593 procedure DrawMapView(x
, y
, w
, h
: Integer);
3600 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3601 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3608 fixViewportForScale();
3609 renderMapInternal(-bx
, -by
, true);
3615 procedure DrawPlayer(p
: TPlayer
);
3617 px
, py
, a
, b
, c
, d
, i
: Integer;
3620 if (p
= nil) or (p
.FDummy
) then
3623 g_Map_DrawBack(0, 0);
3628 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3629 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3635 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3636 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3638 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3640 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3641 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3643 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3644 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3646 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3647 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3650 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3653 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3654 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3657 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3662 // scaled, ignore level bounds
3663 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3664 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3667 if p
.IncCam
<> 0 then
3669 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3671 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3673 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3677 if py
< gPlayerScreenSize
.Y
div 2 then
3679 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3681 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3685 if p
.IncCam
< 0 then
3687 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3690 if p
.IncCam
> 0 then
3692 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3696 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3697 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3698 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3700 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3701 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3702 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3705 sY
:= -(b
+p
.IncCam
);
3706 sWidth
:= gPlayerScreenSize
.X
;
3707 sHeight
:= gPlayerScreenSize
.Y
;
3709 //glTranslatef(a, b+p.IncCam, 0);
3711 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3713 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3714 fixViewportForScale();
3715 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3717 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3719 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3720 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3721 if (sX
< 0) then sX
:= 0;
3722 if (sY
< 0) then sY
:= 0;
3724 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3725 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3728 //r_smallmap_h: 0: left; 1: center; 2: right
3729 //r_smallmap_v: 0: top; 1: center; 2: bottom
3731 if (gMapInfo
.Width
= sWidth
) then
3735 else if (gMapInfo
.Width
< sWidth
) then
3737 case r_smallmap_h
of
3738 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3739 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3740 else sX
:= 0; // left
3744 if (gMapInfo
.Height
= sHeight
) then
3748 else if (gMapInfo
.Height
< sHeight
) then
3750 case r_smallmap_v
of
3751 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3752 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3753 else sY
:= 0; // top
3759 p
.viewPortW
:= sWidth
;
3760 p
.viewPortH
:= sHeight
;
3762 {$IFDEF ENABLE_HOLMES}
3763 if (p
= gPlayer1
) then
3765 g_Holmes_plrViewPos(sX
, sY
);
3766 g_Holmes_plrViewSize(sWidth
, sHeight
);
3770 renderMapInternal(-c
, -d
, true);
3772 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3773 case gPlayerIndicator
of
3775 p
.DrawIndicator(_RGB(255, 255, 255));
3778 for i
:= 0 to High(gPlayers
) do
3779 if gPlayers
[i
] <> nil then
3780 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3781 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3782 if gPlayerIndicatorStyle
= 1 then
3783 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3784 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3787 if p
.FSpectator
then
3788 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3789 p
.GameY
+ PLAYER_RECT_CY
- 4,
3790 'X', gStdFont
, 255, 255, 255, 1, True);
3792 for a := 0 to High(gCollideMap) do
3793 for b := 0 to High(gCollideMap[a]) do
3796 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3798 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3802 1: e_DrawPoint(1, b, a, 200, 200, 200);
3803 2: e_DrawPoint(1, b, a, 64, 64, 255);
3804 3: e_DrawPoint(1, b, a, 255, 0, 255);
3814 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3815 if g_Debug_Player
then
3816 g_Player_DrawDebug(p
);
3820 procedure drawProfilers ();
3825 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3826 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3827 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3830 procedure g_Game_Draw();
3837 plView1
, plView2
: TPlayer
;
3840 if gExit
= EXIT_QUIT
then Exit
;
3842 Time
:= sys_GetTicks() {div 1000};
3843 FPSCounter
:= FPSCounter
+1;
3844 if Time
- FPSTime
>= 1000 then
3851 if gGameOn
or (gState
= STATE_FOLD
) then
3853 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3855 gSpectMode
:= SPECT_NONE
;
3856 if not gRevertPlayers
then
3858 plView1
:= gPlayer1
;
3859 plView2
:= gPlayer2
;
3863 plView1
:= gPlayer2
;
3864 plView2
:= gPlayer1
;
3868 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3870 gSpectMode
:= SPECT_NONE
;
3871 if gPlayer2
= nil then
3874 plView1
:= gPlayer2
;
3883 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3884 gSpectMode
:= SPECT_STATS
;
3886 if gSpectMode
= SPECT_PLAYERS
then
3887 if gPlayers
<> nil then
3889 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3890 if plView1
= nil then
3892 gSpectPID1
:= GetActivePlayerID_Next();
3893 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3895 if gSpectViewTwo
then
3897 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3898 if plView2
= nil then
3900 gSpectPID2
:= GetActivePlayerID_Next();
3901 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3906 if gSpectMode
= SPECT_MAPVIEW
then
3908 // Ðåæèì ïðîñìîòðà êàðòû
3910 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3911 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3912 gHearPoint1
.Active
:= True;
3913 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3914 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3915 gHearPoint2
.Active
:= False;
3919 Split
:= (plView1
<> nil) and (plView2
<> nil);
3921 // Òî÷êè ñëóõà èãðîêîâ
3922 if plView1
<> nil then
3924 gHearPoint1
.Active
:= True;
3925 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3926 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3928 gHearPoint1
.Active
:= False;
3929 if plView2
<> nil then
3931 gHearPoint2
.Active
:= True;
3932 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3933 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3935 gHearPoint2
.Active
:= False;
3937 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3938 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3941 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3942 if gScreenHeight
mod 2 = 0 then
3943 Dec(gPlayerScreenSize
.Y
);
3946 gPlayerScreenSize
.Y
:= gScreenHeight
;
3949 if gScreenHeight
mod 2 = 0 then
3950 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3952 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3954 DrawPlayer(plView1
);
3955 gPlayer1ScreenCoord
.X
:= sX
;
3956 gPlayer1ScreenCoord
.Y
:= sY
;
3960 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3962 DrawPlayer(plView2
);
3963 gPlayer2ScreenCoord
.X
:= sX
;
3964 gPlayer2ScreenCoord
.Y
:= sY
;
3967 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3970 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3973 {$IFDEF ENABLE_HOLMES}
3975 if (g_holmes_enabled
) then g_Holmes_Draw();
3978 if MessageText
<> '' then
3982 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3984 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3985 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3987 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3988 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3991 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3993 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3995 // Draw spectator GUI
3998 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4001 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4003 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4005 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4007 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4008 if gSpectMode
= SPECT_STATS
then
4010 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4011 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4013 if gSpectMode
= SPECT_MAPVIEW
then
4015 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4016 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4017 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4018 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4019 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4021 if gSpectMode
= SPECT_PLAYERS
then
4023 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4024 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4025 if gSpectViewTwo
then
4027 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4028 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4029 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4030 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4034 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4035 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4041 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4043 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4044 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4046 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4047 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4048 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4053 if (gState
= STATE_MENU
) then
4055 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4056 // F3 at menu will show game loading dialog
4057 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4058 if (g_ActiveWindow
<> nil) then
4060 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4061 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4065 // F3 at titlepic will show game loading dialog
4066 if e_KeyPressed(IK_F3
) then
4068 g_Menu_Show_LoadMenu(true);
4069 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4074 if gState
= STATE_FOLD
then
4076 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4079 if gState
= STATE_INTERCUSTOM
then
4081 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4083 back
:= 'TEXTURE_endpic';
4084 if not g_Texture_Get(back
, ID
) then
4085 back
:= _lc
[I_TEXTURE_ENDPIC
];
4090 DrawMenuBackground(back
);
4094 if g_ActiveWindow
<> nil then
4096 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4097 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4101 if gState
= STATE_INTERSINGLE
then
4103 if EndingGameCounter
> 0 then
4105 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4111 DrawMenuBackground(back
);
4115 if g_ActiveWindow
<> nil then
4117 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4118 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4123 if gState
= STATE_ENDPIC
then
4126 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4127 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4129 if g_ActiveWindow
<> nil then
4131 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4132 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4136 if gState
= STATE_SLIST
then
4138 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4140 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4141 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4143 DrawMenuBackground('MENU_BACKGROUND');
4144 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4145 g_Serverlist_Draw(slCurrent
, slTable
);
4149 if g_ActiveWindow
<> nil then
4153 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4154 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4156 g_ActiveWindow
.Draw();
4163 if g_debug_Sounds
and gGameOn
then
4165 for w
:= 0 to High(e_SoundsArray
) do
4166 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4167 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4172 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4173 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4176 if gGameOn
and gShowTime
then
4177 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4179 if gGameOn
then drawProfilers();
4181 {$IFDEF ENABLE_HOLMES}
4188 procedure g_Game_Quit();
4190 g_Game_StopAllSounds(True);
4193 g_PlayerModel_FreeData();
4194 g_Texture_DeleteAll();
4195 g_Frames_DeleteAll();
4197 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4200 if NetInitDone
then g_Net_Free
;
4202 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4203 if gMapToDelete
<> '' then
4204 g_Game_DeleteTestMap();
4210 procedure g_FatalError(Text: String);
4212 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4213 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4215 gExit
:= EXIT_SIMPLE
;
4218 procedure g_SimpleError(Text: String);
4220 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4221 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4224 procedure g_Game_SetupScreenSize();
4226 RES_FACTOR
= 4.0 / 3.0;
4232 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4233 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4234 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4235 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4237 gPlayerScreenSize
.Y
:= gScreenHeight
;
4239 // Ðàçìåð çàäíåãî ïëàíà:
4240 if BackID
<> DWORD(-1) then
4243 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4244 (gScreenHeight
*s
> gMapInfo
.Height
) then
4246 gBackSize
.X
:= gScreenWidth
;
4247 gBackSize
.Y
:= gScreenHeight
;
4251 e_GetTextureSize(BackID
, @bw
, @bh
);
4252 rf
:= Single(bw
) / Single(bh
);
4253 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4254 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4255 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4256 if (s
< 1.0) then s
:= 1.0;
4257 gBackSize
.X
:= Round(bw
*s
);
4258 gBackSize
.Y
:= Round(bh
*s
);
4263 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4265 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4268 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4270 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4271 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4273 if gPlayer1
= nil then
4275 if g_Game_IsClient
then
4277 if NetPlrUID1
> -1 then
4279 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4280 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4285 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4286 Team
:= gPlayer1Settings
.Team
;
4288 // Ñîçäàíèå ïåðâîãî èãðîêà:
4289 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4290 gPlayer1Settings
.Color
,
4292 if gPlayer1
= nil then
4293 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4296 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4297 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4298 if g_Game_IsServer
and g_Game_IsNet
then
4299 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4300 gPlayer1
.Respawn(False, True);
4301 g_Net_Slist_ServerPlayerComes();
4306 if gPlayer2
= nil then
4308 if g_Game_IsClient
then
4310 if NetPlrUID2
> -1 then
4311 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4315 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4316 Team
:= gPlayer2Settings
.Team
;
4318 // Ñîçäàíèå âòîðîãî èãðîêà:
4319 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4320 gPlayer2Settings
.Color
,
4322 if gPlayer2
= nil then
4323 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4326 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4327 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4328 if g_Game_IsServer
and g_Game_IsNet
then
4329 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4330 gPlayer2
.Respawn(False, True);
4331 g_Net_Slist_ServerPlayerComes();
4338 procedure g_Game_RemovePlayer();
4342 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4343 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4348 if g_Game_IsServer
then
4351 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4352 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4353 g_Player_Remove(Pl
.UID
);
4354 g_Net_Slist_ServerPlayerLeaves();
4362 if g_Game_IsServer
then
4365 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4366 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4367 g_Player_Remove(Pl
.UID
);
4368 g_Net_Slist_ServerPlayerLeaves();
4372 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4376 g_Net_Slist_ServerPlayerLeaves();
4379 procedure g_Game_Spectate();
4381 g_Game_RemovePlayer();
4382 if gPlayer1
<> nil then
4383 g_Game_RemovePlayer();
4386 procedure g_Game_SpectateCenterView();
4388 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4389 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4392 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4399 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4401 g_Game_ClearLoading();
4404 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4407 gGameSettings
.GameType
:= GT_SINGLE
;
4408 gGameSettings
.MaxLives
:= 0;
4409 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4410 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4411 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4412 gSwitchGameMode
:= GM_SINGLE
;
4414 g_Game_ExecuteEvent('ongamestart');
4416 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4417 g_Game_SetupScreenSize();
4419 // Ñîçäàíèå ïåðâîãî èãðîêà:
4420 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4421 gPlayer1Settings
.Color
,
4422 gPlayer1Settings
.Team
, False));
4423 if gPlayer1
= nil then
4425 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4429 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4432 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4435 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4436 gPlayer2Settings
.Color
,
4437 gPlayer2Settings
.Team
, False));
4438 if gPlayer2
= nil then
4440 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4444 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4448 // Çàãðóçêà è çàïóñê êàðòû:
4449 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4451 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4452 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4456 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4460 for i
:= nPl
+1 to nPlayers
do
4461 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4464 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4465 TimeLimit
, GoalLimit
: Word;
4467 Options
: LongWord; nPlayers
: Byte);
4473 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4475 g_Game_ClearLoading();
4478 gGameSettings
.GameType
:= GT_CUSTOM
;
4479 gGameSettings
.GameMode
:= GameMode
;
4480 gSwitchGameMode
:= GameMode
;
4481 gGameSettings
.TimeLimit
:= TimeLimit
;
4482 gGameSettings
.GoalLimit
:= GoalLimit
;
4483 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4484 gGameSettings
.Options
:= Options
;
4486 gCoopTotalMonstersKilled
:= 0;
4487 gCoopTotalSecretsFound
:= 0;
4488 gCoopTotalMonsters
:= 0;
4489 gCoopTotalSecrets
:= 0;
4493 g_Game_ExecuteEvent('ongamestart');
4495 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4496 g_Game_SetupScreenSize();
4498 // Ðåæèì íàáëþäàòåëÿ:
4499 if nPlayers
= 0 then
4506 if nPlayers
>= 1 then
4508 // Ñîçäàíèå ïåðâîãî èãðîêà:
4509 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4510 gPlayer1Settings
.Color
,
4511 gPlayer1Settings
.Team
, False));
4512 if gPlayer1
= nil then
4514 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4518 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4522 if nPlayers
>= 2 then
4524 // Ñîçäàíèå âòîðîãî èãðîêà:
4525 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4526 gPlayer2Settings
.Color
,
4527 gPlayer2Settings
.Team
, False));
4528 if gPlayer2
= nil then
4530 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4534 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4538 // Çàãðóçêà è çàïóñê êàðòû:
4539 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4541 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4545 // Íåò òî÷åê ïîÿâëåíèÿ:
4546 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4547 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4548 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4549 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4550 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4552 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4556 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4560 for i
:= nPl
+1 to nPlayers
do
4561 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4564 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4565 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4566 Options
: LongWord; nPlayers
: Byte;
4567 IPAddr
: LongWord; Port
: Word);
4570 g_Net_Slist_ServerClosed();
4572 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4574 g_Game_ClearLoading();
4577 gGameSettings
.GameType
:= GT_SERVER
;
4578 gGameSettings
.GameMode
:= GameMode
;
4579 gSwitchGameMode
:= GameMode
;
4580 gGameSettings
.TimeLimit
:= TimeLimit
;
4581 gGameSettings
.GoalLimit
:= GoalLimit
;
4582 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4583 gGameSettings
.Options
:= Options
;
4585 gCoopTotalMonstersKilled
:= 0;
4586 gCoopTotalSecretsFound
:= 0;
4587 gCoopTotalMonsters
:= 0;
4588 gCoopTotalSecrets
:= 0;
4592 g_Game_ExecuteEvent('ongamestart');
4594 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4595 g_Game_SetupScreenSize();
4597 // Ðåæèì íàáëþäàòåëÿ:
4598 if nPlayers
= 0 then
4604 if nPlayers
>= 1 then
4606 // Ñîçäàíèå ïåðâîãî èãðîêà:
4607 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4608 gPlayer1Settings
.Color
,
4609 gPlayer1Settings
.Team
, False));
4610 if gPlayer1
= nil then
4612 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4616 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4619 if nPlayers
>= 2 then
4621 // Ñîçäàíèå âòîðîãî èãðîêà:
4622 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4623 gPlayer2Settings
.Color
,
4624 gPlayer2Settings
.Team
, False));
4625 if gPlayer2
= nil then
4627 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4631 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4634 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4635 if NetForwardPorts
then
4636 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4639 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4641 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4645 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4647 g_Net_Slist_ServerStarted();
4649 // Çàãðóçêà è çàïóñê êàðòû:
4650 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4652 g_Net_Slist_ServerClosed();
4653 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4657 // Íåò òî÷åê ïîÿâëåíèÿ:
4658 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4659 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4660 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4661 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4662 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4664 g_Net_Slist_ServerClosed();
4665 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4669 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4672 g_Net_Slist_ServerMapStarted();
4673 NetState
:= NET_STATE_GAME
;
4676 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4691 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4692 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4694 g_Game_ClearLoading();
4697 gGameSettings
.GameType
:= GT_CLIENT
;
4699 gCoopTotalMonstersKilled
:= 0;
4700 gCoopTotalSecretsFound
:= 0;
4701 gCoopTotalMonsters
:= 0;
4702 gCoopTotalSecrets
:= 0;
4706 g_Game_ExecuteEvent('ongamestart');
4708 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4709 g_Game_SetupScreenSize();
4711 NetState
:= NET_STATE_AUTH
;
4713 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4715 // create (or update) map/resource databases
4716 g_Res_CreateDatabases(true);
4719 if not g_Net_Connect(Addr
, Port
) then
4721 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4722 NetState
:= NET_STATE_NONE
;
4726 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4728 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4733 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4734 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4735 // thank you, enet. let's ignore failures altogether then.
4736 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4738 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4740 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4742 // ignore all download packets, they're processed by separate code
4743 enet_packet_destroy(NetEvent
.packet
);
4746 Ptr
:= NetEvent
.packet
^.data
;
4747 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4749 enet_packet_destroy(NetEvent
.packet
);
4753 InMsg
.ReadLongWord(); // skip size
4754 MID
:= InMsg
.ReadByte();
4756 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4758 NetMyID
:= InMsg
.ReadByte();
4759 NetPlrUID1
:= InMsg
.ReadWord();
4761 WadName
:= InMsg
.ReadString();
4762 Map
:= InMsg
.ReadString();
4764 gWADHash
:= InMsg
.ReadMD5();
4766 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4767 gSwitchGameMode
:= gGameSettings
.GameMode
;
4768 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4769 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4770 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4771 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4772 T
:= InMsg
.ReadLongWord();
4774 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4775 //if newResPath = '' then
4777 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4778 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4779 if newResPath
= '' then
4781 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4782 enet_packet_destroy(NetEvent
.packet
);
4783 NetState
:= NET_STATE_NONE
;
4786 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4788 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4791 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4792 gPlayer1Settings
.Color
,
4793 gPlayer1Settings
.Team
, False));
4795 if gPlayer1
= nil then
4797 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4799 enet_packet_destroy(NetEvent
.packet
);
4800 NetState
:= NET_STATE_NONE
;
4804 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4805 gPlayer1
.UID
:= NetPlrUID1
;
4806 gPlayer1
.Reset(True);
4808 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4810 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4812 enet_packet_destroy(NetEvent
.packet
);
4813 NetState
:= NET_STATE_NONE
;
4821 enet_packet_destroy(NetEvent
.packet
);
4825 enet_packet_destroy(NetEvent
.packet
);
4829 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4832 if (NetEvent
.data
<= NET_DISC_MAX
) then
4833 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4834 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4841 ProcessLoading(true);
4843 if g_Net_UserRequestExit() then
4852 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4853 NetState
:= NET_STATE_NONE
;
4857 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4858 gLMSRespawnTime
:= 0;
4861 NetState
:= NET_STATE_GAME
;
4862 MC_SEND_FullStateRequest
;
4863 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4867 lastAsMegaWad
: Boolean = false;
4869 procedure g_Game_ChangeMap(const MapPath
: String);
4873 g_Game_ClearLoading();
4875 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4876 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4877 if gExitByTrigger
then
4880 gExitByTrigger
:= False;
4882 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4883 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4886 procedure g_Game_Restart();
4890 if g_Game_IsClient
then
4892 map
:= g_ExtractFileName(gMapInfo
.Map
);
4893 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4897 g_Game_ClearLoading();
4898 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4901 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4903 NewWAD
, ResName
: String;
4907 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4908 g_Player_RemoveAllCorpses();
4910 if (not g_Game_IsClient
) and
4911 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4912 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4914 if gSwitchGameMode
= GM_CTF
then
4915 gGameSettings
.MaxLives
:= 0;
4916 gGameSettings
.GameMode
:= gSwitchGameMode
;
4919 gSwitchGameMode
:= gGameSettings
.GameMode
;
4921 g_Player_ResetTeams();
4923 lastAsMegaWad
:= asMegawad
;
4924 if isWadPath(Map
) then
4926 NewWAD
:= g_ExtractWadName(Map
);
4927 ResName
:= g_ExtractFileName(Map
);
4928 if g_Game_IsServer
then
4930 nws
:= findDiskWad(NewWAD
);
4931 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4934 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4935 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4939 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4940 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4942 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4943 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4945 if (length(nws
) = 0) then
4947 ResName
:= ''; // failed
4952 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4953 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4954 g_Game_LoadWAD(NewWAD
);
4959 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4960 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
4965 NewWAD
:= gGameSettings
.WAD
;
4969 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4971 if (ResName
<> '') and (NewWAD
<> '') then
4973 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4974 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
4978 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4980 gState
:= STATE_NONE
;
4981 g_ActiveWindow
:= nil;
4987 if gGameSettings
.GameMode
= GM_CTF
then
4989 g_Map_ResetFlag(FLAG_RED
);
4990 g_Map_ResetFlag(FLAG_BLUE
);
4991 // CTF, à ôëàãîâ íåò:
4992 if not g_Map_HaveFlagPoints() then
4993 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4998 gState
:= STATE_MENU
;
5003 gPauseMain
:= false;
5004 gPauseHolmes
:= false;
5006 NetTimeToUpdate
:= 1;
5007 NetTimeToReliable
:= 0;
5008 NetTimeToMaster
:= NetMasterRate
;
5009 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5010 gLMSRespawnTime
:= 0;
5011 gMissionFailed
:= False;
5014 gCoopMonstersKilled
:= 0;
5015 gCoopSecretsFound
:= 0;
5017 gVoteInProgress
:= False;
5018 gVotePassed
:= False;
5024 if not gGameOn
then Exit
;
5026 g_Game_SpectateCenterView();
5028 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5030 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5031 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5032 gLMSSoftSpawn
:= True;
5033 if NetMode
= NET_SERVER
then
5034 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
5036 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
5039 if NetMode
= NET_SERVER
then
5041 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5044 g_Net_Slist_ServerMapStarted();
5046 if NetClients
<> nil then
5047 for I
:= 0 to High(NetClients
) do
5048 if NetClients
[I
].Used
then
5050 NetClients
[I
].Voted
:= False;
5051 if NetClients
[I
].RequestedFullUpdate
then
5053 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5054 NetClients
[I
].RequestedFullUpdate
:= False;
5058 g_Net_UnbanNonPermHosts();
5063 gCoopTotalMonstersKilled
:= 0;
5064 gCoopTotalSecretsFound
:= 0;
5065 gCoopTotalMonsters
:= 0;
5066 gCoopTotalSecrets
:= 0;
5070 g_Game_ExecuteEvent('onmapstart');
5073 procedure SetFirstLevel
;
5077 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5078 if MapList
= nil then
5081 SortSArray(MapList
);
5082 gNextMap
:= MapList
[Low(MapList
)];
5087 procedure g_Game_ExitLevel(const Map
: AnsiString);
5091 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5092 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5093 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5094 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5096 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5097 if gGameSettings
.GameType
= GT_SINGLE
then
5098 gExit
:= EXIT_ENDLEVELSINGLE
5099 else // Âûøëè â âûõîä â Ñâîåé èãðå
5101 gExit
:= EXIT_ENDLEVELCUSTOM
;
5102 if gGameSettings
.GameMode
= GM_COOP
then
5103 g_Player_RememberAll
;
5105 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5108 if gGameSettings
.GameMode
= GM_COOP
then
5111 gStatsPressed
:= True;
5112 gNextMap
:= 'MAP01';
5114 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5117 if g_Game_IsNet
then
5119 MH_SEND_GameStats();
5120 MH_SEND_CoopStats();
5126 procedure g_Game_RestartLevel();
5130 if gGameSettings
.GameMode
= GM_SINGLE
then
5135 gExit
:= EXIT_ENDLEVELCUSTOM
;
5136 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5140 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5142 gWAD
{, xwad}: String;
5145 if not g_Game_IsClient
then Exit
;
5146 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5148 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5153 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5157 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5160 g_Game_LoadWAD(NewWAD
);
5164 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5165 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5168 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5169 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5173 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5177 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5178 g_Game_LoadWAD(NewWAD);
5182 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5184 i
, n
, nb
, nr
: Integer;
5186 function monRespawn (mon
: TMonster
): Boolean;
5188 result
:= false; // don't stop
5189 if not mon
.FNoRespawn
then mon
.Respawn();
5193 if not g_Game_IsServer
then Exit
;
5194 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5195 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5196 gLMSRespawnTime
:= 0;
5199 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5201 gMissionFailed
:= True;
5202 g_Game_RestartLevel
;
5206 n
:= 0; nb
:= 0; nr
:= 0;
5207 for i
:= Low(gPlayers
) to High(gPlayers
) do
5208 if (gPlayers
[i
] <> nil) and
5209 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5210 (gPlayers
[i
] is TBot
)) then
5213 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5214 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5217 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5219 // wait a second until the fuckers finally decide to join
5220 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5221 gLMSRespawnTime
:= gTime
+ 1000;
5222 gLMSSoftSpawn
:= NoMapRestart
;
5226 g_Player_RemoveAllCorpses
;
5227 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5228 if g_Game_IsNet
then
5229 MH_SEND_GameEvent(NET_EV_LMS_START
);
5231 for i
:= Low(gPlayers
) to High(gPlayers
) do
5233 if gPlayers
[i
] = nil then continue
;
5234 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5235 // don't touch normal spectators
5236 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5238 gPlayers
[i
].FNoRespawn
:= True;
5239 gPlayers
[i
].Lives
:= 0;
5240 if g_Game_IsNet
then
5241 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5244 gPlayers
[i
].FNoRespawn
:= False;
5245 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5246 gPlayers
[i
].Respawn(False, True);
5247 if gGameSettings
.GameMode
= GM_COOP
then
5249 gPlayers
[i
].Frags
:= 0;
5250 gPlayers
[i
].RecallState
;
5252 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5253 gPlayer1
:= g_Player_Get(gLMSPID1
);
5254 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5255 gPlayer2
:= g_Player_Get(gLMSPID2
);
5258 g_Items_RestartRound();
5261 g_Mons_ForEach(monRespawn
);
5263 gLMSSoftSpawn
:= False;
5266 function g_Game_GetFirstMap(WAD
: String): String;
5270 MapList
:= g_Map_GetMapsList(WAD
);
5271 if MapList
= nil then
5274 SortSArray(MapList
);
5275 Result
:= MapList
[Low(MapList
)];
5277 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5283 function g_Game_GetNextMap(): String;
5290 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5291 if MapList
= nil then
5294 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5296 SortSArray(MapList
);
5298 for I
:= Low(MapList
) to High(MapList
) do
5299 if Map
= MapList
[I
] then
5305 if MapIndex
<> -255 then
5307 if MapIndex
= High(MapList
) then
5308 Result
:= MapList
[Low(MapList
)]
5310 Result
:= MapList
[MapIndex
+ 1];
5312 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5318 procedure g_Game_NextLevel();
5320 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5321 gExit
:= EXIT_ENDLEVELCUSTOM
5324 gExit
:= EXIT_ENDLEVELSINGLE
;
5328 if gNextMap
<> '' then Exit
;
5329 gNextMap
:= g_Game_GetNextMap();
5332 function g_Game_IsTestMap(): Boolean;
5334 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5337 procedure g_Game_DeleteTestMap();
5340 //MapName: AnsiString;
5348 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5349 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5350 if (a
= 0) then exit
;
5352 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5353 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5354 Delete(gMapToDelete
, 1, a
+5);
5355 gMapToDelete
:= UpperCase(gMapToDelete
);
5357 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5360 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5361 if MapName <> TEST_MAP_NAME then
5364 if not gTempDelete then
5366 time := g_GetFileTime(WadName);
5367 WAD := TWADFile.Create();
5370 if not WAD.ReadFile(WadName) then
5371 begin // Íåò òàêîãî WAD-ôàéëà
5376 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5378 MapList := WAD.GetResourcesList('');
5380 if MapList <> nil then
5381 for a := 0 to High(MapList) do
5382 if MapList[a] = MapName then
5384 // Óäàëÿåì è ñîõðàíÿåì:
5385 WAD.RemoveResource('', MapName);
5386 WAD.SaveTo(WadName);
5391 g_SetFileTime(WadName, time);
5394 if gTempDelete
then DeleteFile(WadName
);
5397 procedure GameCVars(P
: SSArray
);
5400 stat
: TPlayerStatArray
;
5405 cmd
:= LowerCase(P
[0]);
5406 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5408 with gGameSettings
do
5410 if (Length(P
) > 1) and
5411 ((P
[1] = '1') or (P
[1] = '0')) then
5413 if (P
[1][1] = '1') then
5414 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5416 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5419 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5420 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5422 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5424 if g_Game_IsNet
then MH_SEND_GameSettings
;
5427 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5429 with gGameSettings
do
5431 if (Length(P
) > 1) and
5432 ((P
[1] = '1') or (P
[1] = '0')) then
5434 if (P
[1][1] = '1') then
5435 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5437 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5440 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5441 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5443 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5445 if g_Game_IsNet
then MH_SEND_GameSettings
;
5448 else if cmd
= 'g_gamemode' then
5450 a
:= g_Game_TextToMode(P
[1]);
5451 if a
= GM_SINGLE
then a
:= GM_COOP
;
5452 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5454 gSwitchGameMode
:= a
;
5455 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5456 (gState
= STATE_INTERSINGLE
) then
5457 gSwitchGameMode
:= GM_SINGLE
;
5459 gGameSettings
.GameMode
:= gSwitchGameMode
;
5461 if gSwitchGameMode
= gGameSettings
.GameMode
then
5462 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5463 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5465 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5466 [g_Game_ModeToText(gGameSettings
.GameMode
),
5467 g_Game_ModeToText(gSwitchGameMode
)]));
5469 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5471 with gGameSettings
do
5473 if (Length(P
) > 1) and
5474 ((P
[1] = '1') or (P
[1] = '0')) then
5476 if (P
[1][1] = '1') then
5477 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5479 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5482 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5483 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5485 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5486 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5488 if g_Game_IsNet
then MH_SEND_GameSettings
;
5491 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5493 with gGameSettings
do
5495 if (Length(P
) > 1) and
5496 ((P
[1] = '1') or (P
[1] = '0')) then
5498 if (P
[1][1] = '1') then
5499 Options
:= Options
or GAME_OPTION_MONSTERS
5501 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5504 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5505 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5507 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5508 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5510 if g_Game_IsNet
then MH_SEND_GameSettings
;
5513 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5515 with gGameSettings
do
5517 if (Length(P
) > 1) and
5518 ((P
[1] = '1') or (P
[1] = '0')) then
5520 if (P
[1][1] = '1') then
5521 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5523 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5526 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5527 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5529 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5531 if g_Game_IsNet
then MH_SEND_GameSettings
;
5534 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5536 with gGameSettings
do
5538 if (Length(P
) > 1) and
5539 ((P
[1] = '1') or (P
[1] = '0')) then
5541 if (P
[1][1] = '1') then
5542 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5544 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5547 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5548 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5550 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5552 if g_Game_IsNet
then MH_SEND_GameSettings
;
5555 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5557 if Length(P
) > 1 then
5559 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5560 gGameSettings
.WarmupTime
:= 30
5562 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5565 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5566 [gGameSettings
.WarmupTime
]));
5567 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5569 else if cmd
= 'net_interp' then
5571 if (Length(P
) > 1) then
5572 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5573 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5574 s
:= e_GetWriteableDir(ConfigDirs
);
5577 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5578 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5579 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5583 else if cmd
= 'net_forceplayerupdate' then
5585 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5586 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5588 if NetForcePlayerUpdate
then
5589 g_Console_Add('net_forceplayerupdate = 1')
5591 g_Console_Add('net_forceplayerupdate = 0');
5593 s
:= e_GetWriteableDir(ConfigDirs
);
5596 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5597 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5598 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5602 else if cmd
= 'net_predictself' then
5604 if (Length(P
) > 1) and
5605 ((P
[1] = '1') or (P
[1] = '0')) then
5606 NetPredictSelf
:= (P
[1][1] = '1');
5608 if NetPredictSelf
then
5609 g_Console_Add('net_predictself = 1')
5611 g_Console_Add('net_predictself = 0');
5613 s
:= e_GetWriteableDir(ConfigDirs
);
5616 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5617 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5618 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5622 else if cmd
= 'sv_name' then
5624 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5626 NetServerName
:= P
[1];
5627 if Length(NetServerName
) > 64 then
5628 SetLength(NetServerName
, 64);
5629 g_Net_Slist_ServerRenamed();
5632 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5634 else if cmd
= 'sv_passwd' then
5636 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5638 NetPassword
:= P
[1];
5639 if Length(NetPassword
) > 24 then
5640 SetLength(NetPassword
, 24);
5641 g_Net_Slist_ServerRenamed();
5644 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5646 else if cmd
= 'sv_maxplrs' then
5648 if (Length(P
) > 1) then
5650 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5651 if g_Game_IsServer
and g_Game_IsNet
then
5654 for a
:= 0 to High(NetClients
) do
5656 if NetClients
[a
].Used
then
5659 if b
> NetMaxClients
then
5661 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5662 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5663 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5664 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5668 g_Net_Slist_ServerRenamed();
5672 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5674 else if cmd
= 'sv_public' then
5676 if (Length(P
) > 1) then
5678 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5679 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5682 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5684 else if cmd
= 'sv_intertime' then
5686 if (Length(P
) > 1) then
5687 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5689 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5691 else if cmd
= 'p1_name' then
5693 if (Length(P
) > 1) and gGameOn
then
5695 if g_Game_IsClient
then
5697 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5698 MC_SEND_PlayerSettings
;
5701 if gPlayer1
<> nil then
5703 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5704 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5707 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5710 else if cmd
= 'p2_name' then
5712 if (Length(P
) > 1) and gGameOn
then
5714 if g_Game_IsClient
then
5716 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5717 MC_SEND_PlayerSettings
;
5720 if gPlayer2
<> nil then
5722 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5723 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5726 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5729 else if cmd
= 'p1_color' then
5731 if Length(P
) > 3 then
5732 if g_Game_IsClient
then
5734 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5735 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5736 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5737 MC_SEND_PlayerSettings
;
5740 if gPlayer1
<> nil then
5742 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5743 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5744 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5745 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5748 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5749 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5750 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5752 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5754 if Length(P
) > 3 then
5755 if g_Game_IsClient
then
5757 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5758 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5759 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5760 MC_SEND_PlayerSettings
;
5763 if gPlayer2
<> nil then
5765 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5766 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5767 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5768 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5771 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5772 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5773 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5775 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5777 if cmd
= 'r_showscore' then
5779 if (Length(P
) > 1) and
5780 ((P
[1] = '1') or (P
[1] = '0')) then
5781 gShowGoals
:= (P
[1][1] = '1');
5784 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5786 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5788 else if cmd
= 'r_showstat' then
5790 if (Length(P
) > 1) and
5791 ((P
[1] = '1') or (P
[1] = '0')) then
5792 gShowStat
:= (P
[1][1] = '1');
5795 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5797 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5799 else if cmd
= 'r_showkillmsg' then
5801 if (Length(P
) > 1) and
5802 ((P
[1] = '1') or (P
[1] = '0')) then
5803 gShowKillMsg
:= (P
[1][1] = '1');
5805 if gShowKillMsg
then
5806 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5808 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5810 else if cmd
= 'r_showlives' then
5812 if (Length(P
) > 1) and
5813 ((P
[1] = '1') or (P
[1] = '0')) then
5814 gShowLives
:= (P
[1][1] = '1');
5817 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5819 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5821 else if cmd
= 'r_showspect' then
5823 if (Length(P
) > 1) and
5824 ((P
[1] = '1') or (P
[1] = '0')) then
5825 gSpectHUD
:= (P
[1][1] = '1');
5828 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5830 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5832 else if cmd
= 'r_showping' then
5834 if (Length(P
) > 1) and
5835 ((P
[1] = '1') or (P
[1] = '0')) then
5836 gShowPing
:= (P
[1][1] = '1');
5839 g_Console_Add(_lc
[I_MSG_PING_ON
])
5841 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5843 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5845 if Length(P
) > 1 then
5847 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5848 gGameSettings
.GoalLimit
:= 0
5853 if gGameSettings
.GameMode
= GM_DM
then
5855 stat
:= g_Player_GetStats();
5857 for a
:= 0 to High(stat
) do
5858 if stat
[a
].Frags
> b
then
5862 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5864 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5867 if g_Game_IsNet
then MH_SEND_GameSettings
;
5870 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5872 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5874 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5875 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5877 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5878 [gGameSettings
.TimeLimit
div 3600,
5879 (gGameSettings
.TimeLimit
div 60) mod 60,
5880 gGameSettings
.TimeLimit
mod 60]));
5881 if g_Game_IsNet
then MH_SEND_GameSettings
;
5883 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5885 if Length(P
) > 1 then
5887 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5888 gGameSettings
.MaxLives
:= 0
5892 stat
:= g_Player_GetStats();
5894 for a
:= 0 to High(stat
) do
5895 if stat
[a
].Lives
> b
then
5897 gGameSettings
.MaxLives
:=
5898 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5902 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5903 [gGameSettings
.MaxLives
]));
5904 if g_Game_IsNet
then MH_SEND_GameSettings
;
5909 procedure PrintHeapStats();
5913 hs
:= GetFPCHeapStatus();
5914 e_LogWriteLn ('v===== heap status =====v');
5915 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5916 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5917 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5918 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5919 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5920 e_LogWriteLn ('^=======================^');
5923 procedure DebugCommands(P
: SSArray
);
5930 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5931 if {gDebugMode}conIsCheatsEnabled
then
5933 cmd
:= LowerCase(P
[0]);
5934 if cmd
= 'd_window' then
5936 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5937 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5939 else if cmd
= 'd_sounds' then
5941 if (Length(P
) > 1) and
5942 ((P
[1] = '1') or (P
[1] = '0')) then
5943 g_Debug_Sounds
:= (P
[1][1] = '1');
5945 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5947 else if cmd
= 'd_frames' then
5949 if (Length(P
) > 1) and
5950 ((P
[1] = '1') or (P
[1] = '0')) then
5951 g_Debug_Frames
:= (P
[1][1] = '1');
5953 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5955 else if cmd
= 'd_winmsg' then
5957 if (Length(P
) > 1) and
5958 ((P
[1] = '1') or (P
[1] = '0')) then
5959 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5961 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5963 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5965 if (Length(P
) > 1) and
5966 ((P
[1] = '1') or (P
[1] = '0')) then
5967 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5969 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5971 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5973 if Length(P
) > 1 then
5975 '0': g_debug_BotAIOff
:= 0;
5976 '1': g_debug_BotAIOff
:= 1;
5977 '2': g_debug_BotAIOff
:= 2;
5978 '3': g_debug_BotAIOff
:= 3;
5981 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5983 else if cmd
= 'd_monster' then
5985 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5986 if Length(P
) < 2 then
5988 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5989 g_Console_Add('ID | Name');
5990 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5991 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5992 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5995 a
:= StrToIntDef(P
[1], 0);
5996 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5997 a
:= g_Mons_TypeIdByName(P
[1]);
5999 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6000 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6003 with gPlayer1
.Obj
do
6005 mon
:= g_Monsters_Create(a
,
6006 X
+ Rect
.X
+ (Rect
.Width
div 2),
6007 Y
+ Rect
.Y
+ Rect
.Height
,
6008 gPlayer1
.Direction
, True);
6010 if (Length(P
) > 2) and (mon
<> nil) then
6012 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6013 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6014 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6015 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6016 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6017 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6018 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6019 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6020 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6025 else if (cmd
= 'd_health') then
6027 if (Length(P
) > 1) and
6028 ((P
[1] = '1') or (P
[1] = '0')) then
6029 g_debug_HealthBar
:= (P
[1][1] = '1');
6031 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6033 else if (cmd
= 'd_player') then
6035 if (Length(P
) > 1) and
6036 ((P
[1] = '1') or (P
[1] = '0')) then
6037 g_debug_Player
:= (P
[1][1] = '1');
6039 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6041 else if (cmd
= 'd_mem') then
6047 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6051 procedure GameCheats(P
: SSArray
);
6057 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6059 g_Console_Add('not available');
6065 g_Console_Add('where is the player?!');
6068 cmd
:= LowerCase(P
[0]);
6072 plr
.GodMode
:= not plr
.GodMode
;
6073 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6076 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6077 if cmd
= 'give' then
6079 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6080 for f
:= 1 to High(P
) do
6082 cmd
:= LowerCase(P
[f
]);
6083 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6084 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6085 if cmd
= 'exit' then
6087 if gTriggers
<> nil then
6089 for a
:= 0 to High(gTriggers
) do
6091 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6093 g_Console_Add('player left the map');
6094 gExitByTrigger
:= True;
6095 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6096 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6104 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6105 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6106 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6107 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6108 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6110 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6111 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6113 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6114 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;
6116 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6117 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6119 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6120 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6122 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6123 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6125 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6126 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6127 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6129 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6130 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6131 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6132 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;
6133 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6134 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6136 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;
6137 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;
6138 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;
6139 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;
6140 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;
6141 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;
6143 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6144 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;
6146 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;
6147 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;
6149 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6151 if cmd
= 'ammo' then
6153 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6154 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6155 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6156 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6157 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6158 g_Console_Add('player got some ammo');
6162 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6163 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6165 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6166 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6168 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6169 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6171 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6172 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6174 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6176 if cmd
= 'weapons' then
6178 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6179 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6180 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6181 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6182 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6183 plr
.GiveItem(ITEM_WEAPON_BFG
);
6184 g_Console_Add('player got weapons');
6188 if cmd
= 'keys' then
6190 plr
.GiveItem(ITEM_KEY_RED
);
6191 plr
.GiveItem(ITEM_KEY_GREEN
);
6192 plr
.GiveItem(ITEM_KEY_BLUE
);
6193 g_Console_Add('player got all keys');
6197 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6202 if cmd
= 'open' then
6204 g_Console_Add('player activated sesame');
6205 g_Triggers_OpenAll();
6212 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6216 if cmd
= 'noclip' then
6219 g_Console_Add('wall hardeness adjusted');
6223 if cmd
= 'notarget' then
6225 plr
.NoTarget
:= not plr
.NoTarget
;
6226 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6230 if cmd
= 'noreload' then
6232 plr
.NoReload
:= not plr
.NoReload
;
6233 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6237 if cmd
= 'speedy' then
6239 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6240 g_Console_Add('speed adjusted');
6244 if cmd
= 'jumpy' then
6246 VEL_JUMP
:= 30-VEL_JUMP
;
6247 g_Console_Add('jump height adjusted');
6251 if cmd
= 'automap' then
6253 gShowMap
:= not gShowMap
;
6254 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6258 if cmd
= 'aimline' then
6260 gAimLine
:= not gAimLine
;
6261 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6266 procedure GameCommands(P
: SSArray
);
6272 pl
: pTNetClient
= nil;
6280 cmd
:= LowerCase(P
[0]);
6282 if (cmd
= 'quit') or
6289 else if cmd
= 'pause' then
6291 if (g_ActiveWindow
= nil) then
6292 g_Game_Pause(not gPauseMain
);
6294 else if cmd
= 'endgame' then
6295 gExit
:= EXIT_SIMPLE
6296 else if cmd
= 'restart' then
6298 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6300 if g_Game_IsClient
then
6302 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6307 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6309 else if cmd
= 'kick' then
6311 if g_Game_IsServer
then
6313 if Length(P
) < 2 then
6315 g_Console_Add('kick <name>');
6320 g_Console_Add('kick <name>');
6324 if g_Game_IsNet
then
6325 pl
:= g_Net_Client_ByName(P
[1]);
6328 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6329 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6330 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6331 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6332 g_Net_Slist_ServerPlayerLeaves();
6333 end else if gPlayers
<> nil then
6334 for a
:= Low(gPlayers
) to High(gPlayers
) do
6335 if gPlayers
[a
] <> nil then
6336 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6338 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6339 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6341 gPlayers
[a
].Lives
:= 0;
6342 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6343 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6344 g_Player_Remove(gPlayers
[a
].UID
);
6345 g_Net_Slist_ServerPlayerLeaves();
6346 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6350 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6352 else if cmd
= 'kick_id' then
6354 if g_Game_IsServer
and g_Game_IsNet
then
6356 if Length(P
) < 2 then
6358 g_Console_Add('kick_id <client ID>');
6363 g_Console_Add('kick_id <client ID>');
6367 a
:= StrToIntDef(P
[1], 0);
6368 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6370 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6372 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6373 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6374 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6375 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6376 g_Net_Slist_ServerPlayerLeaves();
6380 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6382 else if cmd
= 'ban' then
6384 if g_Game_IsServer
and g_Game_IsNet
then
6386 if Length(P
) < 2 then
6388 g_Console_Add('ban <name>');
6393 g_Console_Add('ban <name>');
6397 pl
:= g_Net_Client_ByName(P
[1]);
6400 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6401 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6402 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6403 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6404 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6405 g_Net_Slist_ServerPlayerLeaves();
6407 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6409 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6411 else if cmd
= 'ban_id' then
6413 if g_Game_IsServer
and g_Game_IsNet
then
6415 if Length(P
) < 2 then
6417 g_Console_Add('ban_id <client ID>');
6422 g_Console_Add('ban_id <client ID>');
6426 a
:= StrToIntDef(P
[1], 0);
6427 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6428 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6430 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6431 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6432 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6433 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6434 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6435 g_Net_Slist_ServerPlayerLeaves();
6438 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6440 else if cmd
= 'permban' then
6442 if g_Game_IsServer
and g_Game_IsNet
then
6444 if Length(P
) < 2 then
6446 g_Console_Add('permban <name>');
6451 g_Console_Add('permban <name>');
6455 pl
:= g_Net_Client_ByName(P
[1]);
6458 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6459 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6460 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6461 g_Net_SaveBanList();
6462 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6463 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6464 g_Net_Slist_ServerPlayerLeaves();
6466 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6468 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6470 else if cmd
= 'permban_id' then
6472 if g_Game_IsServer
and g_Game_IsNet
then
6474 if Length(P
) < 2 then
6476 g_Console_Add('permban_id <client ID>');
6481 g_Console_Add('permban_id <client ID>');
6485 a
:= StrToIntDef(P
[1], 0);
6486 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6487 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6489 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6490 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6491 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6492 g_Net_SaveBanList();
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
= 'unban' then
6502 if g_Game_IsServer
and g_Game_IsNet
then
6504 if Length(P
) < 2 then
6506 g_Console_Add('unban <IP Address>');
6511 g_Console_Add('unban <IP Address>');
6515 if g_Net_UnbanHost(P
[1]) then
6517 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6518 g_Net_SaveBanList();
6520 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6522 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6524 else if cmd
= 'clientlist' then
6526 if g_Game_IsServer
and g_Game_IsNet
then
6529 if NetClients
<> nil then
6530 for a
:= Low(NetClients
) to High(NetClients
) do
6531 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6533 plr
:= g_Player_Get(NetClients
[a
].Player
);
6534 if plr
= nil then continue
;
6536 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6537 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6540 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6542 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6544 else if cmd
= 'connect' then
6546 if (NetMode
= NET_NONE
) then
6548 if Length(P
) < 2 then
6550 g_Console_Add('connect <IP> [port] [password]');
6555 g_Console_Add('connect <IP> [port] [password]');
6559 if Length(P
) > 2 then
6560 prt
:= StrToIntDef(P
[2], 25666)
6564 if Length(P
) > 3 then
6569 g_Game_StartClient(P
[1], prt
, pw
);
6572 else if cmd
= 'disconnect' then
6574 if (NetMode
= NET_CLIENT
) then
6577 else if cmd
= 'reconnect' then
6579 if (NetMode
= NET_SERVER
) then
6582 if (NetMode
= NET_CLIENT
) then
6585 gExit
:= EXIT_SIMPLE
;
6589 //TODO: Use last successful password to reconnect, instead of ''
6590 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6592 else if (cmd
= 'addbot') or
6593 (cmd
= 'bot_add') then
6595 if Length(P
) > 2 then
6596 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6597 else if Length(P
) > 1 then
6598 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6600 g_Bot_Add(TEAM_NONE
, 2);
6602 else if cmd
= 'bot_addlist' then
6604 if Length(P
) > 1 then
6606 if Length(P
) = 2 then
6607 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6608 else if Length(P
) = 3 then
6609 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6611 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6614 else if cmd
= 'bot_removeall' then
6616 else if cmd
= 'chat' then
6618 if g_Game_IsNet
then
6620 if Length(P
) > 1 then
6622 for a
:= 1 to High(P
) do
6623 chstr
:= chstr
+ P
[a
] + ' ';
6625 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6627 if Length(chstr
) < 1 then
6629 g_Console_Add('chat <text>');
6633 chstr
:= b_Text_Format(chstr
);
6634 if g_Game_IsClient
then
6635 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6637 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6640 g_Console_Add('chat <text>');
6642 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6644 else if cmd
= 'teamchat' then
6646 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6648 if Length(P
) > 1 then
6650 for a
:= 1 to High(P
) do
6651 chstr
:= chstr
+ P
[a
] + ' ';
6653 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6655 if Length(chstr
) < 1 then
6657 g_Console_Add('teamchat <text>');
6661 chstr
:= b_Text_Format(chstr
);
6662 if g_Game_IsClient
then
6663 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6665 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6666 gPlayer1Settings
.Team
);
6669 g_Console_Add('teamchat <text>');
6671 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6673 else if cmd
= 'game' then
6675 if gGameSettings
.GameType
<> GT_NONE
then
6677 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6680 if Length(P
) = 1 then
6682 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6685 // game not started yet, load fist map from some wad
6687 s
:= addWadExtension(P
[1]);
6688 found
:= e_FindResource(AllMapDirs
, s
);
6692 P
[1] := ExpandFileName(P
[1]);
6693 // if map not choosed then set first map
6694 if Length(P
) < 3 then
6697 P
[2] := g_Game_GetFirstMap(P
[1]);
6700 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6702 if g_Map_Exist(s
) then
6706 with gGameSettings
do
6708 GameMode
:= g_Game_TextToMode(gcGameMode
);
6709 if gSwitchGameMode
<> GM_NONE
then
6710 GameMode
:= gSwitchGameMode
;
6711 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6712 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6714 if Length(P
) >= 4 then
6715 b
:= StrToIntDef(P
[3], 1);
6716 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6717 GoalLimit
, MaxLives
, Options
, b
);
6722 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6724 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6726 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6728 else if cmd
= 'host' then
6730 if gGameSettings
.GameType
<> GT_NONE
then
6732 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6735 if Length(P
) < 4 then
6737 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6740 if not StrToIp(P
[1], listen
) then
6742 prt
:= StrToIntDef(P
[2], 25666);
6744 s
:= addWadExtension(P
[3]);
6745 found
:= e_FindResource(AllMapDirs
, s
);
6749 // get first map in wad, if not specified
6750 if Length(P
) < 5 then
6753 P
[4] := g_Game_GetFirstMap(P
[1]);
6755 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6756 if g_Map_Exist(s
) then
6760 with gGameSettings
do
6762 GameMode
:= g_Game_TextToMode(gcGameMode
);
6763 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6764 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6765 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6767 if Length(P
) >= 6 then
6768 b
:= StrToIntDef(P
[5], 0);
6769 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6775 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6777 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6782 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6785 else if cmd
= 'map' then
6787 if Length(P
) = 1 then
6789 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6791 g_Console_Add(cmd
+ ' <MAP>');
6792 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6796 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6801 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6803 if Length(P
) < 3 then
6805 // first param is map or wad
6806 s
:= UpperCase(P
[1]);
6807 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6809 gExitByTrigger
:= False;
6812 // already in game, finish current map
6814 gExit
:= EXIT_ENDLEVELCUSTOM
;
6818 // intermission, so change map immediately
6825 found
:= e_FindResource(AllMapDirs
, s
);
6827 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6830 // no such map, found wad
6833 P
[1] := ExpandFileName(pw
);
6834 P
[2] := g_Game_GetFirstMap(P
[1]);
6835 s
:= P
[1] + ':\' + P
[2];
6836 if g_Map_Exist(s
) then
6838 gExitByTrigger
:= False;
6841 // already in game, finish current map
6843 gExit
:= EXIT_ENDLEVELCUSTOM
6847 // intermission, so change map immediately
6854 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6856 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6861 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6867 s
:= addWadExtension(P
[1]);
6868 found
:= e_FindResource(AllMapDirs
, s
);
6872 P
[2] := UpperCase(P
[2]);
6873 s
:= P
[1] + ':\' + P
[2];
6874 if g_Map_Exist(s
) then
6876 gExitByTrigger
:= False;
6880 gExit
:= EXIT_ENDLEVELCUSTOM
6889 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6894 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6900 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6904 else if cmd
= 'nextmap' then
6906 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6908 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6913 if Length(P
) = 1 then
6915 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6917 g_Console_Add(cmd
+ ' <MAP>');
6918 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6923 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6929 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6931 if Length(P
) < 3 then
6933 // first param is map or wad
6934 s
:= UpperCase(P
[1]);
6935 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6938 gExitByTrigger
:= False;
6944 // no such map, found wad
6945 pw
:= addWadExtension(P
[1]);
6946 found
:= e_FindResource(MapDirs
, pw
);
6948 found
:= e_FindResource(WadDirs
, pw
);
6950 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6953 // map not specified, select first map
6955 P
[2] := g_Game_GetFirstMap(P
[1]);
6956 s
:= P
[1] + ':\' + P
[2];
6957 if g_Map_Exist(s
) then
6959 gExitByTrigger
:= False;
6966 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6968 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6973 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6979 // specified two params wad + map
6980 pw
:= addWadExtension(P
[1]);
6981 found
:= e_FindResource(MapDirs
, pw
);
6983 found
:= e_FindResource(MapDirs
, pw
);
6987 P
[2] := UpperCase(P
[2]);
6988 s
:= P
[1] + ':\' + P
[2];
6989 if g_Map_Exist(s
) then
6991 gExitByTrigger
:= False;
6997 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7002 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7008 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7013 if gNextMap
= '' then
7014 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7016 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7020 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7024 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7028 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7030 gExitByTrigger
:= False;
7031 // next map not specified, try to find trigger EXIT
7032 if (gNextMap
= '') and (gTriggers
<> nil) then
7034 for a
:= 0 to High(gTriggers
) do
7036 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7038 gExitByTrigger
:= True;
7039 //gNextMap := gTriggers[a].Data.MapName;
7040 gNextMap
:= gTriggers
[a
].tgcMap
;
7045 if gNextMap
= '' then
7046 gNextMap
:= g_Game_GetNextMap();
7047 if not isWadPath(gNextMap
) then
7048 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7051 if g_Map_Exist(s
) then
7052 gExit
:= EXIT_ENDLEVELCUSTOM
7054 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7058 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7062 else if (cmd
= 'event') then
7064 if (Length(P
) <= 1) then
7066 for a
:= 0 to High(gEvents
) do
7067 if gEvents
[a
].Command
= '' then
7068 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7070 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7073 if (Length(P
) = 2) then
7075 for a
:= 0 to High(gEvents
) do
7076 if gEvents
[a
].Name
= P
[1] then
7077 if gEvents
[a
].Command
= '' then
7078 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7080 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7083 for a
:= 0 to High(gEvents
) do
7084 if gEvents
[a
].Name
= P
[1] then
7086 gEvents
[a
].Command
:= '';
7087 for b
:= 2 to High(P
) do
7088 if Pos(' ', P
[b
]) = 0 then
7089 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7091 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7092 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7096 else if cmd
= 'suicide' then
7100 if g_Game_IsClient
then
7101 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7104 if gPlayer1
<> nil then
7105 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7106 if gPlayer2
<> nil then
7107 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7111 else if cmd
= 'screenshot' then
7115 else if cmd
= 'weapon' then
7117 if Length(p
) = 2 then
7119 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7120 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7121 gSelectWeapon
[0, a
] := True
7124 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7126 if Length(p
) = 2 then
7128 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7129 b
:= ord(cmd
[2]) - ord('1');
7130 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7131 gSelectWeapon
[b
, a
] := True
7134 // Êîìàíäû Ñâîåé èãðû:
7135 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7137 if cmd
= 'bot_addred' then
7139 if Length(P
) > 1 then
7140 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7142 g_Bot_Add(TEAM_RED
, 2);
7144 else if cmd
= 'bot_addblue' then
7146 if Length(P
) > 1 then
7147 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7149 g_Bot_Add(TEAM_BLUE
, 2);
7151 else if cmd
= 'spectate' then
7157 else if cmd
= 'say' then
7159 if g_Game_IsServer
and g_Game_IsNet
then
7161 if Length(P
) > 1 then
7164 for a
:= 1 to High(P
) do
7165 chstr
:= chstr
+ P
[a
] + ' ';
7167 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7169 if Length(chstr
) < 1 then
7171 g_Console_Add('say <text>');
7175 chstr
:= b_Text_Format(chstr
);
7176 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7178 else g_Console_Add('say <text>');
7180 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7182 else if cmd
= 'tell' then
7184 if g_Game_IsServer
and g_Game_IsNet
then
7186 if (Length(P
) > 2) and (P
[1] <> '') then
7189 for a
:= 2 to High(P
) do
7190 chstr
:= chstr
+ P
[a
] + ' ';
7192 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7194 if Length(chstr
) < 1 then
7196 g_Console_Add('tell <playername> <text>');
7200 pl
:= g_Net_Client_ByName(P
[1]);
7202 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7204 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7206 else g_Console_Add('tell <playername> <text>');
7208 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7210 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7212 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7214 // Äîïîëíèòåëüíîå âðåìÿ:
7215 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7217 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7218 [gGameSettings
.TimeLimit
div 3600,
7219 (gGameSettings
.TimeLimit
div 60) mod 60,
7220 gGameSettings
.TimeLimit
mod 60]));
7221 if g_Game_IsNet
then MH_SEND_GameSettings
;
7223 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7225 if (Length(P
) <= 1) then
7226 g_Console_Add('rcon_password <password>')
7228 MC_SEND_RCONPassword(P
[1]);
7230 else if cmd
= 'rcon' then
7232 if g_Game_IsClient
then
7234 if Length(P
) > 1 then
7237 for a
:= 1 to High(P
) do
7238 chstr
:= chstr
+ P
[a
] + ' ';
7240 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7242 if Length(chstr
) < 1 then
7244 g_Console_Add('rcon <command>');
7248 MC_SEND_RCONCommand(chstr
);
7250 else g_Console_Add('rcon <command>');
7253 else if cmd
= 'ready' then
7255 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7256 gLMSRespawnTime
:= gTime
+ 100;
7258 else if (cmd
= 'callvote') and g_Game_IsNet
then
7260 if Length(P
) > 1 then
7263 for a
:= 1 to High(P
) do begin
7264 if a
> 1 then chstr
:= chstr
+ ' ';
7265 chstr
:= chstr
+ P
[a
];
7268 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7270 if Length(chstr
) < 1 then
7272 g_Console_Add('callvote <command>');
7276 if g_Game_IsClient
then
7277 MC_SEND_Vote(True, chstr
)
7279 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7280 g_Console_Process('vote', True);
7283 g_Console_Add('callvote <command>');
7285 else if (cmd
= 'vote') and g_Game_IsNet
then
7287 if g_Game_IsClient
then
7289 else if gVoteInProgress
then
7291 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7292 a
:= Floor((NetClientCount
+1)/2.0) + 1
7294 a
:= Floor(NetClientCount
/2.0) + 1;
7299 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7300 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7306 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7307 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7315 procedure g_TakeScreenShot(Filename
: string = '');
7316 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7318 if e_NoGraphics
then Exit
;
7320 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7322 if Filename
= '' then
7325 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7326 Filename
:= 'screenshot-' + date
;
7329 name
:= e_CatPath(dir
, Filename
+ '.png');
7330 s
:= createDiskFile(name
);
7332 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7334 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7336 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7341 g_Console_Add('oh shit, i can''t create screenshot!')
7345 procedure g_Game_InGameMenu(Show
: Boolean);
7347 if (g_ActiveWindow
= nil) and Show
then
7349 if gGameSettings
.GameType
= GT_SINGLE
then
7350 g_GUI_ShowWindow('GameSingleMenu')
7353 if g_Game_IsClient
then
7354 g_GUI_ShowWindow('GameClientMenu')
7356 if g_Game_IsNet
then
7357 g_GUI_ShowWindow('GameServerMenu')
7359 g_GUI_ShowWindow('GameCustomMenu');
7361 g_Sound_PlayEx('MENU_OPEN');
7363 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7364 if (not g_Game_IsNet
) then
7368 if (g_ActiveWindow
<> nil) and (not Show
) then
7370 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7371 if (not g_Game_IsNet
) then
7372 g_Game_Pause(False);
7376 procedure g_Game_Pause (Enable
: Boolean);
7380 if not gGameOn
then exit
;
7382 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7385 gPauseMain
:= Enable
;
7387 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7390 procedure g_Game_HolmesPause (Enable
: Boolean);
7394 if not gGameOn
then exit
;
7395 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7398 gPauseHolmes
:= Enable
;
7400 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7403 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7408 if gTriggers
<> nil then
7409 for i
:= 0 to High(gTriggers
) do
7410 with gTriggers
[i
] do
7411 if (TriggerType
= TRIGGER_SOUND
) and
7413 Sound
.IsPlaying() then
7415 Sound
.Pause(Enable
);
7419 if gPlayers
<> nil then
7420 for i
:= 0 to High(gPlayers
) do
7421 if gPlayers
[i
] <> nil then
7422 gPlayers
[i
].PauseSounds(Enable
);
7425 if gMusic
<> nil then
7426 gMusic
.Pause(Enable
);
7429 procedure g_Game_StopAllSounds(all
: Boolean);
7433 if gTriggers
<> nil then
7434 for i
:= 0 to High(gTriggers
) do
7435 with gTriggers
[i
] do
7436 if (TriggerType
= TRIGGER_SOUND
) and
7440 if gMusic
<> nil then
7447 procedure g_Game_UpdateTriggerSounds
;
7450 if gTriggers
<> nil then
7451 for i
:= 0 to High(gTriggers
) do
7452 with gTriggers
[i
] do
7453 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7454 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7457 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7460 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7465 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7470 if gSpectMode
<> SPECT_PLAYERS
then
7472 if gSpectPID1
= UID
then
7477 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7484 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7489 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7494 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7499 if gSpectMode
<> SPECT_PLAYERS
then
7501 Pl
:= g_Player_Get(gSpectPID1
);
7502 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7507 if gSpectViewTwo
then
7509 Pl
:= g_Player_Get(gSpectPID2
);
7510 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7518 procedure g_Game_Message(Msg
: string; Time
: Word);
7520 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7521 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7522 MessageTime
:= Time
;
7525 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7527 punct
: Array[0..13] of String =
7528 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7534 function IsPunctuation(S
: String): Boolean;
7539 if Length(S
) <> 1 then
7541 for i
:= Low(punct
) to High(punct
) do
7542 if S
= punct
[i
] then
7548 function FilterPunctuation(S
: String): String;
7552 for i
:= Low(punct
) to High(punct
) do
7553 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7559 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7561 // remove player name
7562 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7563 // for FullWord check
7564 Text := toLowerCase1251(' ' + Text + ' ');
7565 fpText
:= FilterPunctuation(Text);
7567 for i
:= 0 to Length(gChatSounds
) - 1 do
7570 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7572 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7573 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7575 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7581 gChatSounds
[i
].Sound
.Play();
7587 g_Sound_PlayEx('SOUND_GAME_RADIO');
7590 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7599 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7603 if goodsnd
[a
].IsPlaying() then
7606 goodsnd
[Random(4)].Play();
7609 procedure g_Game_Announce_KillCombo(Param
: Integer);
7616 UID
:= Param
and $FFFF;
7621 Pl
:= g_Player_Get(UID
);
7630 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7634 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7638 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7642 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7650 if not g_Game_IsWatchedPlayer(UID
) then
7653 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7657 if killsnd
[n
].IsPlaying() then
7662 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7671 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7675 if hahasnd
[a
].IsPlaying() then
7678 hahasnd
[Random(3)].Play();
7681 procedure g_Game_StartVote(Command
, Initiator
: string);
7685 if not gVotesEnabled
then Exit
;
7686 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7687 if gVoteInProgress
or gVotePassed
then
7689 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7690 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7693 gVoteInProgress
:= True;
7694 gVotePassed
:= False;
7695 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7698 gVoteCommand
:= Command
;
7700 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7701 Need
:= Floor((NetClientCount
+1)/2.0)+1
7703 Need
:= Floor(NetClientCount
/2.0)+1;
7704 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7705 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7708 procedure g_Game_CheckVote
;
7712 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7713 if not gVoteInProgress
then Exit
;
7715 if (gTime
>= gVoteTimer
) then
7717 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7718 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7720 Need
:= Floor(NetClientCount
/2.0) + 1;
7721 if gVoteCount
>= Need
then
7723 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7724 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7725 gVotePassed
:= True;
7726 gVoteCmdTimer
:= gTime
+ 5000;
7730 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7731 MH_SEND_VoteEvent(NET_VE_FAILED
);
7733 if NetClients
<> nil then
7734 for I
:= Low(NetClients
) to High(NetClients
) do
7735 if NetClients
[i
].Used
then
7736 NetClients
[i
].Voted
:= False;
7737 gVoteInProgress
:= False;
7743 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7744 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7746 Need
:= Floor(NetClientCount
/2.0) + 1;
7747 if gVoteCount
>= Need
then
7749 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7750 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7751 gVoteInProgress
:= False;
7752 gVotePassed
:= True;
7753 gVoteCmdTimer
:= gTime
+ 5000;
7756 if NetClients
<> nil then
7757 for I
:= Low(NetClients
) to High(NetClients
) do
7758 if NetClients
[i
].Used
then
7759 NetClients
[i
].Voted
:= False;
7764 procedure g_Game_LoadMapList(FileName
: string);
7772 if not FileExists(FileName
) then Exit
;
7774 AssignFile(ListFile
, FileName
);
7776 while not EOF(ListFile
) do
7778 ReadLn(ListFile
, s
);
7781 if s
= '' then Continue
;
7783 SetLength(MapList
, Length(MapList
)+1);
7784 MapList
[High(MapList
)] := s
;
7786 CloseFile(ListFile
);
7789 procedure g_Game_SetDebugMode();
7792 // ×èòû (äàæå â ñâîåé èãðå):
7796 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7800 if Length(LoadingStat
.Msgs
) = 0 then
7806 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7807 if NextMsg
= Length(Msgs
) then
7809 for i
:= 0 to High(Msgs
)-1 do
7810 Msgs
[i
] := Msgs
[i
+1];
7818 Msgs
[NextMsg
-1] := Text;
7822 PBarWasHere
:= false;
7825 g_ActiveWindow
:= nil;
7827 ProcessLoading(true);
7830 procedure g_Game_StepLoading(Value
: Integer = -1);
7841 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7849 procedure g_Game_ClearLoading();
7858 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7859 if len
< 1 then len
:= 1;
7860 SetLength(Msgs
, len
);
7861 for len
:= Low(Msgs
) to High(Msgs
) do
7864 PBarWasHere
:= false;
7868 procedure Parse_Params(var pars
: TParamStrValues
);
7875 while i
<= ParamCount
do
7878 if (s
[1] = '-') and (Length(s
) > 1) then
7880 if (s
[2] = '-') and (Length(s
) > 2) then
7881 begin // Îäèíî÷íûé ïàðàìåòð
7882 SetLength(pars
, Length(pars
) + 1);
7883 with pars
[High(pars
)] do
7885 Name
:= LowerCase(s
);
7890 if (i
< ParamCount
) then
7891 begin // Ïàðàìåòð ñî çíà÷åíèåì
7893 SetLength(pars
, Length(pars
) + 1);
7894 with pars
[High(pars
)] do
7896 Name
:= LowerCase(s
);
7897 Value
:= LowerCase(ParamStr(i
));
7906 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7911 for i
:= 0 to High(pars
) do
7912 if pars
[i
].Name
= aName
then
7914 Result
:= pars
[i
].Value
;
7919 procedure g_Game_Process_Params();
7921 pars
: TParamStrValues
;
7924 LimT
, LimS
: Integer;
7935 s
:= Find_Param_Value(pars
, '--debug');
7938 g_Game_SetDebugMode();
7939 s
:= Find_Param_Value(pars
, '--netdump');
7944 // Connect when game loads
7945 ip
:= Find_Param_Value(pars
, '-connect');
7949 s
:= Find_Param_Value(pars
, '-port');
7950 if (s
= '') or not TryStrToInt(s
, Port
) then
7953 s
:= Find_Param_Value(pars
, '-pw');
7955 g_Game_StartClient(ip
, Port
, s
);
7959 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7962 gDefaultMegawadStart
:= s
;
7965 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7966 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7968 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7971 // Start map when game loads:
7972 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7973 if isWadPath(map
) then
7976 s
:= Find_Param_Value(pars
, '-gm');
7977 GMode
:= g_Game_TextToMode(s
);
7978 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7979 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7982 s
:= Find_Param_Value(pars
, '-limt');
7983 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7989 s
:= Find_Param_Value(pars
, '-lims');
7990 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7996 s
:= Find_Param_Value(pars
, '-lives');
7997 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8003 s
:= Find_Param_Value(pars
, '-opt');
8005 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
8007 Opt
:= StrToIntDef(s
, 0);
8009 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
8012 s
:= Find_Param_Value(pars
, '--close');
8016 // Override map to test:
8017 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8020 if e_IsValidResourceName(s
) then
8021 e_FindResource(AllMapDirs
, s
);
8022 gTestMap
:= ExpandFileName(s
);
8025 // Delete test map after play:
8026 s
:= Find_Param_Value(pars
, '--testdelete');
8029 //gMapToDelete := MapsDir + map;
8030 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8034 // Delete temporary WAD after play:
8035 s
:= Find_Param_Value(pars
, '--tempdelete');
8036 if (s
<> '') and (gTestMap
<> '') then
8038 gMapToDelete
:= gTestMap
;
8039 gTempDelete
:= True;
8042 // Number of players:
8043 s
:= Find_Param_Value(pars
, '-pl');
8045 n
:= DEFAULT_PLAYERS
8047 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8050 s
:= Find_Param_Value(pars
, '-port');
8051 if (s
= '') or not TryStrToInt(s
, Port
) then
8052 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8054 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8057 // Execute script when game loads:
8058 s
:= Find_Param_Value(pars
, '-exec');
8061 // if not isWadPath(s) then
8062 // s := GameDir + '/' + s;
8067 if IOResult
<> 0 then
8069 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8070 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8074 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8075 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8080 if IOResult
<> 0 then
8082 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8083 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8087 if Pos('#', s
) <> 1 then // script comment
8088 g_Console_Process(s
, True);
8099 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8100 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8101 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8102 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8104 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8105 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8106 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8107 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8109 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8110 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8112 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8113 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8115 {$IFDEF ENABLE_HOLMES}
8116 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8119 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8121 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8123 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8124 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8126 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8127 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8129 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8130 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');