1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_basic
, g_player
, e_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
45 TDelayedEvent
= record
54 Sound
: TPlayableSound
;
55 Tags
: Array of String;
59 TPlayerSettings
= record
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures
: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
90 function g_Game_ModeToText(Mode
: Byte): string;
91 function g_Game_TextToMode(Mode
: string): Byte;
92 procedure g_Game_ExecuteEvent(Name
: String);
93 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
99 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
100 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
105 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
106 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
107 procedure g_Game_ChangeMap(const MapPath
: String);
108 procedure g_Game_ExitLevel(const Map
: AnsiString);
109 function g_Game_GetFirstMap(WAD
: String): String;
110 function g_Game_GetNextMap(): String;
111 procedure g_Game_NextLevel();
112 procedure g_Game_Pause(Enable
: Boolean);
113 procedure g_Game_HolmesPause(Enable
: Boolean);
114 procedure g_Game_InGameMenu(Show
: Boolean);
115 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
116 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
117 procedure g_Game_Message(Msg
: String; Time
: Word);
118 procedure g_Game_LoadMapList(FileName
: String);
119 procedure g_Game_PauseAllSounds(Enable
: Boolean);
120 procedure g_Game_StopAllSounds(all
: Boolean);
121 procedure g_Game_UpdateTriggerSounds();
122 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
123 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
124 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
125 procedure g_Game_Announce_KillCombo(Param
: Integer);
126 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
127 procedure g_Game_StartVote(Command
, Initiator
: string);
128 procedure g_Game_CheckVote
;
129 procedure g_TakeScreenShot(Filename
: string = '');
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P
: SSArray
);
135 procedure GameCommands(P
: SSArray
);
136 procedure GameCheats(P
: SSArray
);
137 procedure DebugCommands(P
: SSArray
);
138 procedure g_Game_Process_Params
;
139 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
140 procedure g_Game_StepLoading(Value
: Integer = -1);
141 procedure g_Game_ClearLoading();
142 procedure g_Game_SetDebugMode();
143 procedure DrawLoadingStat();
144 procedure DrawMenuBackground(tex
: AnsiString);
146 { procedure SetWinPause(Enable: Boolean); }
151 LOADING_SHOW_STEP
= 100;
152 LOADING_INTERLINE
= 20;
167 MESSAGE_DIKEY
= WM_USER
+ 1;
172 EXIT_ENDLEVELSINGLE
= 4;
173 EXIT_ENDLEVELCUSTOM
= 5;
175 GAME_OPTION_RESERVED
= 1;
176 GAME_OPTION_TEAMDAMAGE
= 2;
177 GAME_OPTION_ALLOWEXIT
= 4;
178 GAME_OPTION_WEAPONSTAY
= 8;
179 GAME_OPTION_MONSTERS
= 16;
180 GAME_OPTION_BOTVSPLAYER
= 32;
181 GAME_OPTION_BOTVSMONSTER
= 64;
182 GAME_OPTION_DMKEYS
= 128;
187 STATE_INTERCUSTOM
= 3;
188 STATE_INTERSINGLE
= 4;
194 LMS_RESPAWN_NONE
= 0;
195 LMS_RESPAWN_WARMUP
= 1;
196 LMS_RESPAWN_FINAL
= 2;
213 CONFIG_FILENAME
= 'Doom2DF.cfg';
215 TEST_MAP_NAME
= '$$$_TEST_$$$';
217 STD_PLAYER_MODEL
= 'Doomer';
225 STATFILE_VERSION
= $03;
229 gGameSettings
: TGameSettings
;
230 gPlayer1Settings
: TPlayerSettings
;
231 gPlayer2Settings
: TPlayerSettings
;
233 gPlayerScreenSize
: TDFPoint
;
234 gPlayer1ScreenCoord
: TDFPoint
;
235 gPlayer2ScreenCoord
: TDFPoint
;
236 gPlayer1
: TPlayer
= nil;
237 gPlayer2
: TPlayer
= nil;
238 gPlayerDrawn
: TPlayer
= nil;
240 gSwitchGameMode
: Byte = GM_DM
;
241 gHearPoint1
, gHearPoint2
: THearPoint
;
242 gSoundEffectsDF
: Boolean = False;
243 gSoundTriggerTime
: Word = 0;
244 gAnnouncer
: Integer = ANNOUNCE_NONE
;
245 goodsnd
: array[0..3] of TPlayableSound
;
246 killsnd
: array[0..3] of TPlayableSound
;
247 hahasnd
: array[0..2] of TPlayableSound
;
248 sound_get_flag
: array[0..1] of TPlayableSound
;
249 sound_lost_flag
: array[0..1] of TPlayableSound
;
250 sound_ret_flag
: array[0..1] of TPlayableSound
;
251 sound_cap_flag
: array[0..1] of TPlayableSound
;
252 gBodyKillEvent
: Integer = -1;
253 gDefInterTime
: ShortInt = -1;
254 gInterEndTime
: LongWord = 0;
255 gInterTime
: LongWord = 0;
256 gServInterTime
: Byte = 0;
257 gGameStartTime
: LongWord = 0;
258 gTotalMonsters
: Integer = 0;
259 gPauseMain
: Boolean = false;
260 gPauseHolmes
: Boolean = false;
261 gShowTime
: Boolean = False;
262 gShowFPS
: Boolean = False;
263 gShowGoals
: Boolean = True;
264 gShowStat
: Boolean = True;
265 gShowKillMsg
: Boolean = True;
266 gShowLives
: Boolean = True;
267 gShowPing
: Boolean = False;
268 gShowMap
: Boolean = False;
270 gState
: Byte = STATE_NONE
;
272 sWidth
, sHeight
: Word;
273 gSpectMode
: Byte = SPECT_NONE
;
274 gSpectHUD
: Boolean = True;
275 gSpectKeyPress
: Boolean = False;
276 gSpectX
: Integer = 0;
277 gSpectY
: Integer = 0;
278 gSpectStep
: Byte = 8;
279 gSpectViewTwo
: Boolean = False;
280 gSpectPID1
: Integer = -1;
281 gSpectPID2
: Integer = -1;
282 gSpectAuto
: Boolean = False;
283 gSpectAutoNext
: LongWord;
284 gSpectAutoStepX
: Integer;
285 gSpectAutoStepY
: Integer;
286 gMusic
: TMusic
= nil;
287 gLoadGameMode
: Boolean;
288 gCheats
: Boolean = False;
289 gMapOnce
: Boolean = False;
290 gMapToDelete
: String;
291 gTempDelete
: Boolean = False;
292 gLastMap
: Boolean = False;
293 gWinSizeX
, gWinSizeY
: Integer;
294 gResolutionChange
: Boolean = False;
295 gRC_Width
, gRC_Height
: Integer;
296 gRC_FullScreen
, gRC_Maximized
: Boolean;
297 gLanguageChange
: Boolean = False;
298 gDebugMode
: Boolean = False;
299 g_debug_Sounds
: Boolean = False;
300 g_debug_Frames
: Boolean = False;
301 g_debug_WinMsgs
: Boolean = False;
302 g_debug_MonsterOff
: Boolean = False;
303 g_debug_BotAIOff
: Byte = 0;
304 g_debug_HealthBar
: Boolean = False;
305 g_Debug_Player
: Boolean = False;
306 gCoopMonstersKilled
: Word = 0;
307 gCoopSecretsFound
: Word = 0;
308 gCoopTotalMonstersKilled
: Word = 0;
309 gCoopTotalSecretsFound
: Word = 0;
310 gCoopTotalMonsters
: Word = 0;
311 gCoopTotalSecrets
: Word = 0;
312 gStatsOff
: Boolean = False;
313 gStatsPressed
: Boolean = False;
314 gExitByTrigger
: Boolean = False;
315 gNextMap
: String = '';
316 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
317 gLMSRespawnTime
: Cardinal = 0;
318 gLMSSoftSpawn
: Boolean = False;
319 gMissionFailed
: Boolean = False;
320 gVoteInProgress
: Boolean = False;
321 gVotePassed
: Boolean = False;
322 gVoteCommand
: string = '';
323 gVoteTimer
: Cardinal = 0;
324 gVoteCmdTimer
: Cardinal = 0;
325 gVoteCount
: Integer = 0;
326 gVoteTimeout
: Cardinal = 30;
327 gVoted
: Boolean = False;
328 gVotesEnabled
: Boolean = True;
329 gEvents
: Array of TGameEvent
;
330 gDelayedEvents
: Array of TDelayedEvent
;
331 gUseChatSounds
: Boolean = True;
332 gChatSounds
: Array of TChatSound
;
333 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
334 gInterReadyCount
: Integer = 0;
336 g_dbg_ignore_bounds
: Boolean = false;
337 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
338 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
340 // move button values:
341 // bits 0-1: l/r state:
342 // 0: neither left, nor right pressed
345 // bits 4-5: l/r state when strafe was pressed
346 P1MoveButton
: Byte = 0;
347 P2MoveButton
: Byte = 0;
349 g_profile_frame_update
: Boolean = false;
350 g_profile_frame_draw
: Boolean = false;
351 g_profile_collision
: Boolean = false;
352 g_profile_los
: Boolean = false;
353 g_profile_history_size
: Integer = 1000;
355 g_rlayer_back
: Boolean = true;
356 g_rlayer_step
: Boolean = true;
357 g_rlayer_wall
: Boolean = true;
358 g_rlayer_door
: Boolean = true;
359 g_rlayer_acid1
: Boolean = true;
360 g_rlayer_acid2
: Boolean = true;
361 g_rlayer_water
: Boolean = true;
362 g_rlayer_fore
: Boolean = true;
365 procedure g_ResetDynlights ();
366 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
367 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
369 function conIsCheatsEnabled (): Boolean; inline;
370 function gPause (): Boolean; inline;
376 {$INCLUDE ../nogl/noGLuses.inc}
377 {$IFDEF ENABLE_HOLMES}
380 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
381 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
382 g_playermodel
, g_gfx
, g_options
, Math
,
383 g_triggers
, g_monsters
, e_sound
, CONFIG
,
384 g_language
, g_net
, g_main
,
385 ENet
, e_msg
, g_netmsg
, g_netmaster
,
386 sfs
, wadreader
, g_system
;
390 hasPBarGfx
: Boolean = false;
393 // ////////////////////////////////////////////////////////////////////////// //
394 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
397 // ////////////////////////////////////////////////////////////////////////// //
398 function conIsCheatsEnabled (): Boolean; inline;
401 if g_Game_IsNet
then exit
;
402 if not gDebugMode
then
404 //if not gCheats then exit;
405 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
406 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
412 // ////////////////////////////////////////////////////////////////////////// //
414 profileFrameDraw
: TProfiler
= nil;
417 // ////////////////////////////////////////////////////////////////////////// //
420 x
, y
, radius
: Integer;
423 exploRadius
: Integer;
427 g_dynLights
: array of TDynLight
= nil;
428 g_dynLightCount
: Integer = 0;
429 g_playerLight
: Boolean = false;
431 procedure g_ResetDynlights ();
435 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
437 for idx
:= 0 to g_dynLightCount
-1 do
439 if g_dynLights
[idx
].exploCount
= -666 then
446 Inc(g_dynLights
[idx
].exploCount
);
447 if (g_dynLights
[idx
].exploCount
< 10) then
449 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
450 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
451 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
452 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
457 g_dynLightCount
:= lnum
;
460 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
462 if not gwin_has_stencil
then exit
;
463 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
464 g_dynLights
[g_dynLightCount
].x
:= x
;
465 g_dynLights
[g_dynLightCount
].y
:= y
;
466 g_dynLights
[g_dynLightCount
].radius
:= radius
;
467 g_dynLights
[g_dynLightCount
].r
:= r
;
468 g_dynLights
[g_dynLightCount
].g
:= g
;
469 g_dynLights
[g_dynLightCount
].b
:= b
;
470 g_dynLights
[g_dynLightCount
].a
:= a
;
471 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
472 Inc(g_dynLightCount
);
475 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
477 if not gwin_has_stencil
then exit
;
478 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
479 g_dynLights
[g_dynLightCount
].x
:= x
;
480 g_dynLights
[g_dynLightCount
].y
:= y
;
481 g_dynLights
[g_dynLightCount
].radius
:= 0;
482 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
483 g_dynLights
[g_dynLightCount
].r
:= r
;
484 g_dynLights
[g_dynLightCount
].g
:= g
;
485 g_dynLights
[g_dynLightCount
].b
:= b
;
486 g_dynLights
[g_dynLightCount
].a
:= 0;
487 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
488 Inc(g_dynLightCount
);
492 // ////////////////////////////////////////////////////////////////////////// //
493 function calcProfilesHeight (prof
: TProfiler
): Integer;
496 if (prof
= nil) then exit
;
497 if (length(prof
.bars
) = 0) then exit
;
498 result
:= length(prof
.bars
)*(16+2);
502 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
509 if (prof
= nil) then exit
;
511 if (length(prof
.bars
) = 0) then exit
;
513 hgt
:= calcProfilesHeight(prof
);
514 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
515 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
517 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
518 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
519 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
522 for ii
:= 0 to High(prof
.bars
) do
524 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);
531 // ////////////////////////////////////////////////////////////////////////// //
533 TEndCustomGameStat
= record
534 PlayerStat
: TPlayerStatArray
;
538 Map
, MapName
: String;
541 TEndSingleGameStat
= record
542 PlayerStat
: Array [0..1] of record
548 TotalSecrets
: Integer;
551 TLoadingStat
= record
555 Msgs
: Array of String;
557 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
560 TParamStrValue
= record
565 TParamStrValues
= Array of TParamStrValue
;
568 INTER_ACTION_TEXT
= 1;
569 INTER_ACTION_PIC
= 2;
570 INTER_ACTION_MUSIC
= 3;
574 FPSCounter
, UPSCounter
: Word;
575 FPSTime
, UPSTime
: LongWord;
576 DataLoaded
: Boolean = False;
577 IsDrawStat
: Boolean = False;
578 CustomStat
: TEndCustomGameStat
;
579 SingleStat
: TEndSingleGameStat
;
580 LoadingStat
: TLoadingStat
;
581 EndingGameCounter
: Byte = 0;
584 MessageLineLength
: Integer = 80;
585 MapList
: SSArray
= nil;
586 MapIndex
: Integer = -1;
587 InterReadyTime
: Integer = -1;
588 StatShotDone
: Boolean = False;
589 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
590 StatDate
: string = '';
596 text: Array of ShortString;
597 anim
: Array of ShortString;
598 pic
: Array of ShortString;
599 mus
: Array of ShortString;
601 triggers
: Array of record
603 actions
: Array of record
604 action
, p1
, p2
: Integer;
607 cur_trigger
: Integer;
620 function Compare(a
, b
: TPlayerStat
): Integer;
622 if a
.Spectator
then Result
:= 1
623 else if b
.Spectator
then Result
:= -1
624 else if a
.Frags
< b
.Frags
then Result
:= 1
625 else if a
.Frags
> b
.Frags
then Result
:= -1
626 else if a
.Deaths
< b
.Deaths
then Result
:= -1
627 else if a
.Deaths
> b
.Deaths
then Result
:= 1
628 else if a
.Kills
< b
.Kills
then Result
:= -1
632 procedure SortGameStat(var stat
: TPlayerStatArray
);
637 if stat
= nil then Exit
;
639 for I
:= High(stat
) downto Low(stat
) do
640 for J
:= Low(stat
) to High(stat
) - 1 do
641 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
644 stat
[J
] := stat
[J
+ 1];
649 // saves a shitty CSV containing the game stats passed to it
650 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
653 dir
, fname
, map
, mode
, etime
: String;
657 dir
:= e_GetWriteableDir(StatsDirs
);
658 // stats are placed in stats/yy/mm/dd/*.csv
659 fname
:= e_CatPath(dir
, Path
);
660 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
661 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
662 AssignFile(s
, fname
);
665 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
666 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
667 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
668 mode
:= g_Game_ModeToText(Stat
.GameMode
);
669 etime
:= Format('%d:%.2d:%.2d', [
670 Stat
.GameTime
div 1000 div 3600,
671 (Stat
.GameTime
div 1000 div 60) mod 60,
672 Stat
.GameTime
div 1000 mod 60
674 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
675 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
681 gGameSettings
.TimeLimit
,
682 gGameSettings
.GoalLimit
,
683 gGameSettings
.Options
,
685 Length(Stat
.PlayerStat
)
687 // line 2: game specific shit
688 // if it's a team game: red score, blue score
689 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
691 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
693 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
694 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
696 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
697 // lines 3-...: team, player name, frags, deaths
698 WriteLn(s
, 'team,name,frags,deaths');
699 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
700 with Stat
.PlayerStat
[I
] do
701 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
703 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
706 g_Console_Add('could not create gamestats file "' + fname
+ '"');
711 function g_Game_ModeToText(Mode
: Byte): string;
715 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
716 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
717 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
718 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
719 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
723 function g_Game_TextToMode(Mode
: string): Byte;
726 Mode
:= UpperCase(Mode
);
727 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
732 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
737 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
742 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
747 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
754 function g_Game_IsNet(): Boolean;
756 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
759 function g_Game_IsServer(): Boolean;
761 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
764 function g_Game_IsClient(): Boolean;
766 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
769 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
776 Result
.name
:= ExtractFileName(WAD
);
777 Result
.description
:= '';
780 w
:= TWADFile
.Create();
783 if not w
.GetResource('INTERSCRIPT', p
, len
) then
789 cfg
:= TConfig
.CreateMem(p
, len
);
790 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
791 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
792 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
793 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
799 procedure g_Game_FreeWAD();
803 for a
:= 0 to High(MegaWAD
.res
.pic
) do
804 if MegaWAD
.res
.pic
[a
] <> '' then
805 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
807 for a
:= 0 to High(MegaWAD
.res
.mus
) do
808 if MegaWAD
.res
.mus
[a
] <> '' then
809 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
811 MegaWAD
.res
.pic
:= nil;
812 MegaWAD
.res
.text := nil;
813 MegaWAD
.res
.anim
:= nil;
814 MegaWAD
.res
.mus
:= nil;
815 MegaWAD
.triggers
:= nil;
817 g_Texture_Delete('TEXTURE_endpic');
818 g_Sound_Delete('MUSIC_endmus');
820 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
821 gGameSettings
.WAD
:= '';
824 procedure g_Game_LoadWAD(WAD
: string);
833 gGameSettings
.WAD
:= WAD
;
834 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
837 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
839 w
:= TWADFile
.Create();
842 if not w
.GetResource('INTERSCRIPT', p
, len
) then
848 cfg
:= TConfig
.CreateMem(p
, len
);
853 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
854 if s = '' then Break;
857 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
858 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
860 g_Texture_CreateWADEx(s, s);
866 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
867 if s = '' then Break;
870 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
871 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
873 g_Music_CreateWADEx(s, s);
876 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
877 if MegaWAD
.endpic
<> '' then
879 TEXTUREFILTER
:= GL_LINEAR
;
880 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
881 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
882 TEXTUREFILTER
:= GL_NEAREST
;
884 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
885 if MegaWAD
.endmus
<> '' then
887 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
888 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
896 {procedure start_trigger(t: string);
900 function next_trigger(): Boolean;
904 procedure DisableCheats();
910 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
911 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
912 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
913 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
915 {$IF DEFINED(D2F_DEBUG)}
916 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
917 gAimLine
:= g_dbg_aimline_on
;
921 procedure g_Game_ExecuteEvent(Name
: String);
927 if gEvents
= nil then
929 for a
:= 0 to High(gEvents
) do
930 if gEvents
[a
].Name
= Name
then
932 if gEvents
[a
].Command
<> '' then
933 g_Console_Process(gEvents
[a
].Command
, True);
938 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
943 if gDelayedEvents
<> nil then
944 for a
:= 0 to High(gDelayedEvents
) do
945 if not gDelayedEvents
[a
].Pending
then
952 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
953 n
:= High(gDelayedEvents
);
955 gDelayedEvents
[n
].Pending
:= True;
956 gDelayedEvents
[n
].DEType
:= DEType
;
957 gDelayedEvents
[n
].DENum
:= Num
;
958 gDelayedEvents
[n
].DEStr
:= Str
;
959 if DEType
= DE_GLOBEVENT
then
960 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
962 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
972 if g_Game_IsNet
and g_Game_IsServer
then
973 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
977 gPauseHolmes
:= false;
980 g_Game_StopAllSounds(False);
985 EndingGameCounter
:= 0;
986 g_ActiveWindow
:= nil;
988 gLMSRespawn
:= LMS_RESPAWN_NONE
;
989 gLMSRespawnTime
:= 0;
992 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
997 begin // Ýòî áûë òåñò
1001 begin // Âûõîä â ãëàâíîå ìåíþ
1002 gMusic
.SetByName('MUSIC_MENU');
1004 if gState
<> STATE_SLIST
then
1006 g_GUI_ShowWindow('MainMenu');
1007 gState
:= STATE_MENU
;
1010 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1011 slReturnPressed
:= True;
1012 if g_Net_Slist_Fetch(slCurrent
) then
1014 if slCurrent
= nil then
1015 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1018 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1019 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1022 g_Game_ExecuteEvent('ongameend');
1026 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1028 if not g_Game_IsClient
then g_Game_Restart();
1031 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1033 // Ñòàòèñòèêà Ñâîåé èãðû:
1034 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1036 CustomStat
.GameTime
:= gTime
;
1037 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1038 CustomStat
.MapName
:= gMapInfo
.Name
;
1039 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1040 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1041 CustomStat
.TeamStat
:= gTeamStat
;
1043 CustomStat
.PlayerStat
:= nil;
1045 // Ñòàòèñòèêà èãðîêîâ:
1046 if gPlayers
<> nil then
1048 for a
:= 0 to High(gPlayers
) do
1049 if gPlayers
[a
] <> nil then
1051 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1052 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1055 Name
:= gPlayers
[a
].Name
;
1056 Frags
:= gPlayers
[a
].Frags
;
1057 Deaths
:= gPlayers
[a
].Death
;
1058 Kills
:= gPlayers
[a
].Kills
;
1059 Team
:= gPlayers
[a
].Team
;
1060 Color
:= gPlayers
[a
].Model
.Color
;
1061 Spectator
:= gPlayers
[a
].FSpectator
;
1065 SortGameStat(CustomStat
.PlayerStat
);
1067 if (gSaveStats
or gScreenshotStats
) and (Length(gPlayers
) > 1) then
1070 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1071 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1072 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1073 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1075 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1078 StatShotDone
:= False;
1081 g_Game_ExecuteEvent('onmapend');
1082 if not g_Game_IsClient
then g_Player_ResetReady
;
1083 gInterReadyCount
:= 0;
1085 // Çàòóõàþùèé ýêðàí:
1086 EndingGameCounter
:= 255;
1087 gState
:= STATE_FOLD
;
1089 if gDefInterTime
< 0 then
1090 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1092 gInterEndTime
:= gDefInterTime
* 1000;
1095 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1097 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1098 SingleStat
.GameTime
:= gTime
;
1099 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1100 SingleStat
.TotalSecrets
:= gSecretsCount
;
1101 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1102 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1103 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1104 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1105 if SingleStat
.TwoPlayers
then
1107 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1108 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1111 g_Game_ExecuteEvent('onmapend');
1114 if gNextMap
<> '' then
1116 gMusic
.SetByName('MUSIC_INTERMUS');
1118 gState
:= STATE_INTERSINGLE
;
1121 g_Game_ExecuteEvent('oninter');
1123 else // Áîëüøå íåò êàðò
1125 // Çàòóõàþùèé ýêðàí:
1126 EndingGameCounter
:= 255;
1127 gState
:= STATE_FOLD
;
1132 // Îêîí÷àíèå îáðàáîòàíî:
1133 if gExit
<> EXIT_QUIT
then
1137 procedure drawTime(X
, Y
: Integer); inline;
1139 e_TextureFontPrint(x
, y
,
1140 Format('%d:%.2d:%.2d', [
1141 gTime
div 1000 div 3600,
1142 (gTime
div 1000 div 60) mod 60,
1143 gTime
div 1000 mod 60
1148 procedure DrawStat();
1150 pc
, x
, y
, w
, h
: Integer;
1151 w1
, w2
, w3
, w4
: Integer;
1153 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1156 stat
: TPlayerStatArray
;
1163 pc
:= g_Player_GetCount
;
1164 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1166 w
:= gScreenWidth
-(gScreenWidth
div 5);
1167 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1170 h
:= 40+ch
*5+(ch
+8)*pc
;
1171 x
:= (gScreenWidth
div 2)-(w
div 2);
1172 y
:= (gScreenHeight
div 2)-(h
div 2);
1174 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1175 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1177 drawTime(x
+w
-78, y
+8);
1179 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1180 map
:= g_ExtractFileName(gMapInfo
.Map
);
1181 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1183 case gGameSettings
.GameMode
of
1186 if gGameSettings
.MaxLives
= 0 then
1187 s1
:= _lc
[I_GAME_DM
]
1189 s1
:= _lc
[I_GAME_LMS
];
1190 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1191 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1196 if gGameSettings
.MaxLives
= 0 then
1197 s1
:= _lc
[I_GAME_TDM
]
1199 s1
:= _lc
[I_GAME_TLMS
];
1200 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1201 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1206 s1
:= _lc
[I_GAME_CTF
];
1207 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1208 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1213 if gGameSettings
.MaxLives
= 0 then
1214 s1
:= _lc
[I_GAME_COOP
]
1216 s1
:= _lc
[I_GAME_SURV
];
1217 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1218 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1229 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1231 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1233 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1235 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1236 gStdFont
, 200, 200, 200, 1);
1238 if NetMode
= NET_SERVER
then
1239 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1241 if NetMode
= NET_CLIENT
then
1242 e_TextureFontPrintEx(x
+8, y
+ 8,
1243 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1247 stat
:= g_Player_GetStats();
1250 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1251 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1253 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1255 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1259 for a
:= TEAM_RED
to TEAM_BLUE
do
1261 if a
= TEAM_RED
then
1263 s1
:= _lc
[I_GAME_TEAM_RED
];
1270 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1276 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1277 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1278 gStdFont
, r
, g
, b
, 1);
1280 _y
:= _y
+ch
+(ch
div 4);
1281 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1282 _y
:= _y
+(ch
div 4);
1284 for aa
:= 0 to High(stat
) do
1285 if stat
[aa
].Team
= a
then
1301 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1303 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1305 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1307 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1314 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1317 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1318 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1319 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1320 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1323 for aa
:= 0 to High(stat
) do
1337 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1338 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1340 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1342 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1344 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1346 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1352 procedure g_Game_Init();
1355 knownFiles
: array of AnsiString = nil;
1357 wext
, s
: AnsiString;
1362 gTempDelete
:= False;
1364 sfsGCDisable(); // temporary disable removing of temporary volumes
1367 TEXTUREFILTER
:= GL_LINEAR
;
1368 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1369 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1370 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1371 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1372 TEXTUREFILTER
:= GL_NEAREST
;
1374 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1375 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1376 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1378 g_Game_ClearLoading();
1379 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1380 g_Game_SetLoadingText('', 0, False);
1382 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1385 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1386 g_PlayerModel_LoadData();
1388 // load models from all possible wad types, in all known directories
1389 // this does a loosy job (linear search, ooph!), but meh
1390 for wext
in wadExtensions
do
1392 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1394 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1398 for s
in knownFiles
do
1400 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1408 SetLength(knownFiles
, length(knownFiles
)+1);
1409 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1411 until (FindNext(SR
) <> 0);
1417 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1419 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
);
1420 for s
in knownFiles
do
1422 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1426 gPauseMain
:= false;
1427 gPauseHolmes
:= false;
1430 {e_MouseInfo.Accel := 1.0;}
1432 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1435 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1436 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1437 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1438 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1439 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1442 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1446 gMusic
:= TMusic
.Create();
1447 gMusic
.SetByName('MUSIC_MENU');
1450 gGameSettings
.WarmupTime
:= 30;
1452 gState
:= STATE_MENU
;
1454 SetLength(gEvents
, 6);
1455 gEvents
[0].Name
:= 'ongamestart';
1456 gEvents
[1].Name
:= 'ongameend';
1457 gEvents
[2].Name
:= 'onmapstart';
1458 gEvents
[3].Name
:= 'onmapend';
1459 gEvents
[4].Name
:= 'oninter';
1460 gEvents
[5].Name
:= 'onwadend';
1462 sfsGCEnable(); // enable releasing unused volumes
1466 procedure g_Game_Free(freeTextures
: Boolean=true);
1468 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1469 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1471 g_Map_Free(freeTextures
);
1473 g_Player_RemoveAllCorpses();
1475 gGameSettings
.GameType
:= GT_NONE
;
1476 if gGameSettings
.GameMode
= GM_SINGLE
then
1477 gGameSettings
.GameMode
:= GM_DM
;
1478 gSwitchGameMode
:= gGameSettings
.GameMode
;
1481 gExitByTrigger
:= False;
1484 function IsActivePlayer(p
: TPlayer
): Boolean;
1489 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1492 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1499 if gPlayers
= nil then
1501 for a
:= Low(gPlayers
) to High(gPlayers
) do
1502 if IsActivePlayer(gPlayers
[a
]) then
1504 if gPlayers
[a
].UID
<> ID
then
1506 Result
:= gPlayers
[a
];
1511 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1517 if gPlayers
= nil then
1521 for a
:= Low(gPlayers
) to High(gPlayers
) do
1522 if IsActivePlayer(gPlayers
[a
]) then
1524 SetLength(ids
, Length(ids
) + 1);
1525 ids
[High(ids
)] := gPlayers
[a
].UID
;
1526 if gPlayers
[a
].UID
= Skip
then
1529 if Length(ids
) = 0 then
1534 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1537 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1543 if gPlayers
= nil then
1547 for a
:= Low(gPlayers
) to High(gPlayers
) do
1548 if IsActivePlayer(gPlayers
[a
]) then
1550 SetLength(ids
, Length(ids
) + 1);
1551 ids
[High(ids
)] := gPlayers
[a
].UID
;
1552 if gPlayers
[a
].UID
= Skip
then
1555 if Length(ids
) = 0 then
1558 Result
:= ids
[Length(ids
) - 1]
1560 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1563 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1569 if gPlayers
= nil then
1573 for a
:= Low(gPlayers
) to High(gPlayers
) do
1574 if IsActivePlayer(gPlayers
[a
]) then
1576 SetLength(ids
, Length(ids
) + 1);
1577 ids
[High(ids
)] := gPlayers
[a
].UID
;
1578 if gPlayers
[a
].UID
= Skip
then
1581 if Length(ids
) = 0 then
1583 if Length(ids
) = 1 then
1588 Result
:= ids
[Random(Length(ids
))];
1590 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1592 Result
:= ids
[Random(Length(ids
))];
1597 function GetRandomSpectMode(Current
: Byte): Byte;
1604 0: Result
:= SPECT_STATS
;
1605 1: Result
:= SPECT_MAPVIEW
;
1606 2: Result
:= SPECT_MAPVIEW
;
1607 3: Result
:= SPECT_PLAYERS
;
1608 4: Result
:= SPECT_PLAYERS
;
1609 5: Result
:= SPECT_PLAYERS
;
1610 6: Result
:= SPECT_PLAYERS
;
1612 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1616 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1622 if (plr
= nil) then exit
;
1623 if (p
= 2) then time
:= 1000 else time
:= 1;
1624 strafeDir
:= MoveButton
shr 4;
1625 MoveButton
:= MoveButton
and $0F;
1627 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1628 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1629 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1630 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1631 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1632 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1634 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1635 if MoveButton
= 1 then
1636 plr
.PressKey(KEY_LEFT
, time
)
1637 else if MoveButton
= 2 then
1638 plr
.PressKey(KEY_RIGHT
, time
);
1640 // if we have "strafe" key, turn off old strafe mechanics
1641 if gPlayerAction
[p
, ACTION_STRAFE
] then
1643 // new strafe mechanics
1644 if (strafeDir
= 0) then
1645 strafeDir
:= MoveButton
; // start strafing
1646 // now set direction according to strafe (reversed)
1647 if (strafeDir
= 2) then
1648 plr
.SetDirection(TDirection
.D_LEFT
)
1649 else if (strafeDir
= 1) then
1650 plr
.SetDirection(TDirection
.D_RIGHT
)
1654 strafeDir
:= 0; // not strafing anymore
1655 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1656 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1657 plr
.SetDirection(TDirection
.D_LEFT
)
1658 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1659 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1660 plr
.SetDirection(TDirection
.D_RIGHT
)
1661 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1662 else if MoveButton
<> 0 then
1663 plr
.SetDirection(TDirection(MoveButton
-1))
1666 // fix movebutton state
1667 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1669 // Îñòàëüíûå êëàâèøè:
1670 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1671 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1672 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1673 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1674 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1675 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1676 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1678 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1679 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1681 for i
:= WP_FIRST
to WP_LAST
do
1683 if gSelectWeapon
[p
, i
] then
1685 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1686 gSelectWeapon
[p
, i
] := False
1690 // HACK: add dynlight here
1691 if gwin_k8_enable_light_experiments
then
1693 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1695 g_playerLight
:= true;
1697 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1699 g_playerLight
:= false;
1703 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1706 // HACK: don't have a "key was pressed" function
1707 procedure InterReady();
1709 if InterReadyTime
> gTime
then Exit
;
1710 InterReadyTime
:= gTime
+ 3000;
1711 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1714 procedure g_Game_Update();
1716 Msg
: g_gui
.TMessage
;
1722 function sendMonsPos (mon
: TMonster
): Boolean;
1724 result
:= false; // don't stop
1725 // this will also reset "need-send" flag
1726 if mon
.gncNeedSend
then
1728 MH_SEND_MonsterPos(mon
.UID
);
1730 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1732 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1734 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1736 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1740 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1742 result
:= false; // don't stop
1743 // this will also reset "need-send" flag
1744 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1748 reliableUpdate
: Boolean;
1753 // Ïîðà âûêëþ÷àòü èãðó:
1754 if gExit
= EXIT_QUIT
then
1756 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1760 if gExit
= EXIT_QUIT
then
1764 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1765 // no need to, as we'll do it in event handler
1767 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1770 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1772 gExit
:= EXIT_SIMPLE
;
1777 // process master server communications
1778 g_Net_Slist_Pulse();
1781 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1782 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1783 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1784 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1786 if g_Game_IsNet
and g_Game_IsServer
then
1788 gInterTime
:= gInterTime
+ GAME_TICK
;
1789 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1790 if a
<> gServInterTime
then
1792 gServInterTime
:= a
;
1793 MH_SEND_TimeSync(gServInterTime
);
1797 if (not g_Game_IsClient
) and
1801 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1802 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1803 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1804 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1806 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1807 and (g_ActiveWindow
= nil)
1809 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1812 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1813 g_Game_StopAllSounds(True);
1815 if gMapOnce
then // Ýòî áûë òåñò
1816 gExit
:= EXIT_SIMPLE
1818 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1819 g_Game_ChangeMap(gNextMap
)
1820 else // Ñëåäóþùåé êàðòû íåò
1822 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1824 // Âûõîä â ãëàâíîå ìåíþ:
1826 g_GUI_ShowWindow('MainMenu');
1827 gMusic
.SetByName('MUSIC_MENU');
1829 gState
:= STATE_MENU
;
1832 // Ôèíàëüíàÿ êàðòèíêà:
1833 g_Game_ExecuteEvent('onwadend');
1835 if not gMusic
.SetByName('MUSIC_endmus') then
1836 gMusic
.SetByName('MUSIC_STDENDMUS');
1838 gState
:= STATE_ENDPIC
;
1840 g_Game_ExecuteEvent('ongameend');
1845 else if g_Game_IsClient
and
1848 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1849 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1850 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1851 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1853 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1854 and (g_ActiveWindow
= nil)
1862 if gState
= STATE_INTERTEXT
then
1863 if InterText
.counter
> 0 then
1864 InterText
.counter
:= InterText
.counter
- 1;
1867 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1869 if EndingGameCounter
= 0 then
1871 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1872 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1874 InterReadyTime
:= -1;
1875 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1877 g_Game_ExecuteEvent('onwadend');
1878 if not gMusic
.SetByName('MUSIC_endmus') then
1879 gMusic
.SetByName('MUSIC_STDENDMUS');
1882 gMusic
.SetByName('MUSIC_ROUNDMUS');
1885 gState
:= STATE_INTERCUSTOM
;
1888 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1890 gMusic
.SetByName('MUSIC_INTERMUS');
1892 gState
:= STATE_INTERSINGLE
;
1895 g_Game_ExecuteEvent('oninter');
1898 DecMin(EndingGameCounter
, 6, 0);
1901 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1903 if gMapOnce
then // Ýòî áûë òåñò
1905 gExit
:= EXIT_SIMPLE
;
1911 g_Serverlist_Control(slCurrent
, slTable
);
1914 // Ñòàòèñòèêà ïî Tab:
1916 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1919 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1921 // Âðåìÿ += 28 ìèëëèñåêóíä:
1922 gTime
:= gTime
+ GAME_TICK
;
1924 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1925 if MessageTime
= 0 then
1927 if MessageTime
> 0 then
1928 MessageTime
:= MessageTime
- 1;
1930 if (g_Game_IsServer
) then
1932 // Áûë çàäàí ëèìèò âðåìåíè:
1933 if (gGameSettings
.TimeLimit
> 0) then
1934 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1935 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1940 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1941 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1942 g_Game_RestartRound(gLMSSoftSpawn
);
1944 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1945 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1947 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1949 g_Console_Process(gVoteCommand
);
1951 gVotePassed
:= False;
1954 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1955 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1956 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1957 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1958 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1960 // Áûë çàäàí ëèìèò ïîáåä:
1961 if (gGameSettings
.GoalLimit
> 0) then
1965 if gGameSettings
.GameMode
= GM_DM
then
1966 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1967 for i
:= 0 to High(gPlayers
) do
1968 if gPlayers
[i
] <> nil then
1969 if gPlayers
[i
].Frags
> b
then
1970 b
:= gPlayers
[i
].Frags
;
1973 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1974 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1975 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1978 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1979 if b
>= gGameSettings
.GoalLimit
then
1986 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1987 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1988 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1989 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1991 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1992 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1993 end // if not console
1996 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1998 // process weapon switch queue
2002 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2003 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2005 if not gSpectKeyPress
then
2007 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2009 // switch spect mode
2011 SPECT_NONE
: ; // not spectator
2013 SPECT_MAPVIEW
: Inc(gSpectMode
);
2014 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2016 gSpectKeyPress
:= True;
2018 if (gSpectMode
= SPECT_MAPVIEW
)
2019 and (not gSpectAuto
) then
2021 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2022 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2023 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2024 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2025 if gPlayerAction
[0, ACTION_LOOKUP
] then
2026 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2027 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2028 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2029 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2032 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2033 gSpectKeyPress
:= True;
2035 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2038 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2039 gSpectKeyPress
:= True;
2042 if (gSpectMode
= SPECT_PLAYERS
)
2043 and (not gSpectAuto
) then
2045 if gPlayerAction
[0, ACTION_LOOKUP
] then
2048 gSpectViewTwo
:= True;
2049 gSpectKeyPress
:= True;
2051 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2053 // remove second view
2054 gSpectViewTwo
:= False;
2055 gSpectKeyPress
:= True;
2057 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2059 // prev player (view 1)
2060 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2061 gSpectKeyPress
:= True;
2063 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2065 // next player (view 1)
2066 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2067 gSpectKeyPress
:= True;
2069 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2071 // prev player (view 2)
2072 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2073 gSpectKeyPress
:= True;
2075 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2077 // next player (view 2)
2078 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2079 gSpectKeyPress
:= True;
2082 if gPlayerAction
[0, ACTION_ATTACK
] then
2084 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2087 gSpectAutoNext
:= 0;
2088 gSpectViewTwo
:= False;
2089 gSpectKeyPress
:= True;
2094 gSpectMode
:= SPECT_STATS
;
2095 gSpectAuto
:= False;
2096 gSpectKeyPress
:= True;
2101 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2102 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2103 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2104 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2105 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2106 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2107 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2108 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2109 gSpectKeyPress
:= False;
2113 if gSpectMode
= SPECT_MAPVIEW
then
2115 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2117 gSpectAutoNext
:= gTime
2120 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2122 gSpectAutoNext
:= gTime
2126 if gSpectAutoNext
<= gTime
then
2128 if gSpectAutoNext
> 0 then
2130 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2134 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2135 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2136 gSpectAutoStepX
:= Random(9) - 4;
2137 gSpectAutoStepY
:= Random(9) - 4;
2138 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2139 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2140 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2141 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2142 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2143 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2147 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2152 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2153 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2154 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2160 // Îáíîâëÿåì âñå îñòàëüíîå:
2163 g_Triggers_Update();
2165 g_Monsters_Update();
2167 g_Player_UpdateAll();
2168 g_Player_UpdatePhysicalObjects();
2170 // server: send newly spawned monsters unconditionally
2171 if (gGameSettings
.GameType
= GT_SERVER
) then
2173 if (Length(gMonstersSpawned
) > 0) then
2175 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2176 SetLength(gMonstersSpawned
, 0);
2180 if (gSoundTriggerTime
> 8) then
2182 g_Game_UpdateTriggerSounds();
2183 gSoundTriggerTime
:= 0;
2187 Inc(gSoundTriggerTime
);
2190 if (NetMode
= NET_SERVER
) then
2192 Inc(NetTimeToUpdate
);
2193 Inc(NetTimeToReliable
);
2195 // send monster updates
2196 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2198 // send all monsters (periodic sync)
2199 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2201 for I
:= 0 to High(gPlayers
) do
2203 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2206 g_Mons_ForEach(sendMonsPos
);
2208 if reliableUpdate
then
2210 NetTimeToReliable
:= 0;
2211 NetTimeToUpdate
:= NetUpdateRate
;
2215 NetTimeToUpdate
:= 0;
2220 // send only mosters with some unexpected changes
2221 g_Mons_ForEach(sendMonsPosUnexpected
);
2224 // send unexpected platform changes
2225 g_Map_NetSendInterestingPanels();
2227 g_Net_Slist_ServerUpdate();
2229 if NetUseMaster then
2231 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2233 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2235 NetTimeToMaster := gTime + NetMasterRate;
2240 else if (NetMode
= NET_CLIENT
) then
2242 MC_SEND_PlayerPos();
2244 end; // if gameOn ...
2246 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2247 if g_ActiveWindow
<> nil then
2249 w
:= e_GetFirstKeyPressed();
2251 if (w
<> IK_INVALID
) then
2253 Msg
.Msg
:= MESSAGE_DIKEY
;
2255 g_ActiveWindow
.OnMessage(Msg
);
2258 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2259 if g_ActiveWindow
<> nil then
2260 g_ActiveWindow
.Update();
2262 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2263 if gResolutionChange
then
2265 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2266 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2267 gResolutionChange
:= False;
2268 g_ActiveWindow
:= nil;
2271 // Íóæíî ñìåíèòü ÿçûê:
2272 if gLanguageChange
then
2274 //e_WriteLog('Read language file', MSG_NOTIFY);
2275 //g_Language_Load(DataDir + gLanguage + '.txt');
2276 g_Language_Set(gLanguage
);
2280 gLanguageChange
:= False;
2284 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2285 if e_KeyPressed(IK_F10
) and
2287 (not gConsoleShow
) and
2288 (g_ActiveWindow
= nil) then
2293 Time
:= sys_GetTicks() {div 1000};
2295 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2296 if gDelayedEvents
<> nil then
2297 for a
:= 0 to High(gDelayedEvents
) do
2298 if gDelayedEvents
[a
].Pending
and
2300 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2301 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2304 case gDelayedEvents
[a
].DEType
of
2306 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2309 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2313 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2314 if g_Game_IsNet
and g_Game_IsServer
then
2315 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2319 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2321 gDelayedEvents
[a
].Pending
:= False;
2324 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2325 UPSCounter
:= UPSCounter
+ 1;
2326 if Time
- UPSTime
>= 1000 then
2335 g_Weapon_AddDynLights();
2336 g_Items_AddDynLights();
2340 procedure g_Game_LoadChatSounds(Resource
: string);
2343 FileName
, Snd
: string;
2345 len
, cnt
, tags
, i
, j
: Integer;
2348 FileName
:= g_ExtractWadName(Resource
);
2350 WAD
:= TWADFile
.Create();
2351 WAD
.ReadFile(FileName
);
2353 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2360 cfg
:= TConfig
.CreateMem(p
, len
);
2361 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2363 SetLength(gChatSounds
, cnt
);
2364 for i
:= 0 to Length(gChatSounds
) - 1 do
2366 gChatSounds
[i
].Sound
:= nil;
2367 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2368 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2369 if (Snd
= '') or (Tags
<= 0) then
2371 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2372 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2373 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2374 SetLength(gChatSounds
[i
].Tags
, tags
);
2375 for j
:= 0 to tags
- 1 do
2376 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2377 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2384 procedure g_Game_FreeChatSounds();
2388 for i
:= 0 to Length(gChatSounds
) - 1 do
2390 gChatSounds
[i
].Sound
.Free();
2391 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2393 SetLength(gChatSounds
, 0);
2397 procedure g_Game_LoadData();
2404 if DataLoaded
then Exit
;
2406 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2408 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2409 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2410 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2411 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2412 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2413 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2414 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2415 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2416 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2417 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2418 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2419 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2420 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2421 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2422 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2425 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2426 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2427 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2428 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2432 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2433 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2434 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2435 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2436 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
2442 hasPBarGfx
:= false;
2446 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2447 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2448 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2449 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2450 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2451 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2452 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2453 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2454 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2455 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2456 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2457 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2458 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2459 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2460 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2461 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2462 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2463 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2464 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2465 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2466 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2467 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2472 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2473 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2474 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2475 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2476 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2477 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2478 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2479 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2480 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2481 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2482 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2483 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2484 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2486 goodsnd
[0] := TPlayableSound
.Create();
2487 goodsnd
[1] := TPlayableSound
.Create();
2488 goodsnd
[2] := TPlayableSound
.Create();
2489 goodsnd
[3] := TPlayableSound
.Create();
2491 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2492 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2493 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2494 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2496 killsnd
[0] := TPlayableSound
.Create();
2497 killsnd
[1] := TPlayableSound
.Create();
2498 killsnd
[2] := TPlayableSound
.Create();
2499 killsnd
[3] := TPlayableSound
.Create();
2501 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2502 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2503 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2504 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2506 hahasnd
[0] := TPlayableSound
.Create();
2507 hahasnd
[1] := TPlayableSound
.Create();
2508 hahasnd
[2] := TPlayableSound
.Create();
2510 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2511 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2512 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2514 sound_get_flag
[0] := TPlayableSound
.Create();
2515 sound_get_flag
[1] := TPlayableSound
.Create();
2516 sound_lost_flag
[0] := TPlayableSound
.Create();
2517 sound_lost_flag
[1] := TPlayableSound
.Create();
2518 sound_ret_flag
[0] := TPlayableSound
.Create();
2519 sound_ret_flag
[1] := TPlayableSound
.Create();
2520 sound_cap_flag
[0] := TPlayableSound
.Create();
2521 sound_cap_flag
[1] := TPlayableSound
.Create();
2523 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2524 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2525 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2526 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2527 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2528 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2529 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2530 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2532 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2534 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2537 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2538 g_Weapon_LoadData();
2540 g_Monsters_LoadData();
2545 procedure g_Game_FreeData();
2547 if not DataLoaded
then Exit
;
2550 g_Weapon_FreeData();
2551 g_Monsters_FreeData();
2553 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2555 g_Texture_Delete('NOTEXTURE');
2556 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2557 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2558 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2559 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2560 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2561 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2562 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2563 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2564 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2565 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2566 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2567 g_Frames_DeleteByName('FRAMES_TELEPORT');
2568 g_Frames_DeleteByName('FRAMES_PUNCH');
2569 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2570 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2571 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2572 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2573 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2574 g_Sound_Delete('SOUND_GAME_TELEPORT');
2575 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2576 g_Sound_Delete('SOUND_GAME_SECRET');
2577 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2578 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2579 g_Sound_Delete('SOUND_GAME_BULK1');
2580 g_Sound_Delete('SOUND_GAME_BULK2');
2581 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2582 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2583 g_Sound_Delete('SOUND_GAME_BURNING');
2584 g_Sound_Delete('SOUND_GAME_SWITCH1');
2585 g_Sound_Delete('SOUND_GAME_SWITCH0');
2592 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2593 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2594 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2595 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2602 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2603 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2604 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2605 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2611 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2612 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2613 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2615 sound_get_flag
[0].Free();
2616 sound_get_flag
[1].Free();
2617 sound_lost_flag
[0].Free();
2618 sound_lost_flag
[1].Free();
2619 sound_ret_flag
[0].Free();
2620 sound_ret_flag
[1].Free();
2621 sound_cap_flag
[0].Free();
2622 sound_cap_flag
[1].Free();
2624 g_Sound_Delete('SOUND_CTF_GET1');
2625 g_Sound_Delete('SOUND_CTF_GET2');
2626 g_Sound_Delete('SOUND_CTF_LOST1');
2627 g_Sound_Delete('SOUND_CTF_LOST2');
2628 g_Sound_Delete('SOUND_CTF_RETURN1');
2629 g_Sound_Delete('SOUND_CTF_RETURN2');
2630 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2631 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2633 g_Game_FreeChatSounds();
2635 DataLoaded
:= False;
2638 procedure DrawCustomStat();
2644 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2645 s1
, s2
, topstr
: String;
2647 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2651 if g_Console_Action(ACTION_SCORES
) then
2653 if not gStatsPressed
then
2655 gStatsOff
:= not gStatsOff
;
2656 gStatsPressed
:= True;
2660 gStatsPressed
:= False;
2664 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2665 w
:= (Length(s1
) * ww2
) div 2;
2666 x
:= gScreenWidth
div 2 - w
;
2668 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2672 if (gGameSettings
.GameMode
= GM_COOP
) then
2674 if gMissionFailed
then
2675 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2677 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2680 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2682 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2683 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2685 if g_Game_IsNet
then
2687 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2688 if not gChatShow
then
2689 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2690 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2693 if g_Game_IsClient
then
2694 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2696 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2697 if not gChatShow
then
2698 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2699 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2704 w
:= gScreenWidth
-x
*2;
2710 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2711 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2713 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2715 case CustomStat
.GameMode
of
2718 if gGameSettings
.MaxLives
= 0 then
2719 s1
:= _lc
[I_GAME_DM
]
2721 s1
:= _lc
[I_GAME_LMS
];
2725 if gGameSettings
.MaxLives
= 0 then
2726 s1
:= _lc
[I_GAME_TDM
]
2728 s1
:= _lc
[I_GAME_TLMS
];
2730 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2733 if gGameSettings
.MaxLives
= 0 then
2734 s1
:= _lc
[I_GAME_COOP
]
2736 s1
:= _lc
[I_GAME_SURV
];
2742 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2746 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2747 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2750 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2751 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2752 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2753 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2755 pc
:= Length(CustomStat
.PlayerStat
);
2756 if pc
= 0 then Exit
;
2758 if CustomStat
.GameMode
= GM_COOP
then
2760 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2762 s2
:= _lc
[I_GAME_MONSTERS
];
2763 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2764 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2766 s2
:= _lc
[I_GAME_SECRETS
];
2767 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2768 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2771 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2773 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2774 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2775 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2777 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2778 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2779 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2783 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2788 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2789 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2790 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2792 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2795 for t
:= TEAM_RED
to TEAM_BLUE
do
2797 if t
= TEAM_RED
then
2799 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2800 gStdFont
, 255, 0, 0, 1);
2801 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2802 gStdFont
, 255, 0, 0, 1);
2809 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2810 gStdFont
, 0, 0, 255, 1);
2811 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2812 gStdFont
, 0, 0, 255, 1);
2818 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2821 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2822 if CustomStat
.PlayerStat
[p
].Team
= t
then
2823 with CustomStat
.PlayerStat
[p
] do
2837 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2838 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2840 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2841 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2842 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2849 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2852 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2853 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2854 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2857 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2858 with CustomStat
.PlayerStat
[p
] do
2860 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2867 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2868 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2870 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2871 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2872 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2877 // HACK: take stats screenshot immediately after the first frame of the stats showing
2878 if gScreenshotStats
and not StatShotDone
then
2880 g_TakeScreenShot('stats/' + StatFilename
);
2881 StatShotDone
:= True;
2885 procedure DrawSingleStat();
2887 tm
, key_x
, val_x
, y
: Integer;
2891 procedure player_stat(n
: Integer);
2897 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2898 s2
:= Format(' %d', [gTotalMonsters
]);
2900 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2901 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2902 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2903 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2905 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2906 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2908 // "Kills-per-minute: ##.#":
2909 s1
:= _lc
[I_MENU_INTER_KPM
];
2911 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2913 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2914 s2
:= Format(' %.1f', [kpm
]);
2916 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2917 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2919 // "Secrets found: # / #":
2920 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2921 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2923 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2924 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2925 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2926 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2928 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2929 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2933 // "Level Complete":
2934 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2935 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2937 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2938 s1
:= _lc
[I_MENU_INTER_KPM
];
2939 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2942 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2944 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2945 val_x
:= key_x
+ w1
;
2948 tm
:= SingleStat
.GameTime
div 1000;
2949 s1
:= _lc
[I_MENU_INTER_TIME
];
2950 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2952 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2953 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2955 if SingleStat
.TwoPlayers
then
2958 s1
:= _lc
[I_MENU_PLAYER_1
];
2959 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2960 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2962 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2967 s1
:= _lc
[I_MENU_PLAYER_2
];
2968 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2969 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2971 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2977 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2983 procedure DrawLoadingStat();
2984 procedure drawRect (x
, y
, w
, h
: Integer);
2986 if (w
< 1) or (h
< 1) then exit
;
2988 glVertex2f(x
+0.375, y
+0.375);
2989 glVertex2f(x
+w
+0.375, y
+0.375);
2990 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2991 glVertex2f(x
+0.375, y
+h
+0.375);
2995 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2997 rectW
, rectH
: Integer;
3004 idl
, idr
, idb
, idm
: LongWord;
3008 if (total
< 1) then exit
;
3009 if (cur
< 1) then exit
; // don't blink
3010 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3011 //if (cur < 0) then cur := 0;
3012 //if (cur > total) then cur := total;
3015 if (hasPBarGfx
) then
3017 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3018 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3019 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3020 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3021 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3022 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3023 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3024 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3026 //rectW := gScreenWidth-360;
3027 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3030 x0
:= (gScreenWidth
-rectW
) div 2;
3031 y0
:= gScreenHeight
-rectH
-64;
3032 if (y0
< 2) then y0
:= 2;
3034 glEnable(GL_SCISSOR_TEST
);
3037 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3038 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3039 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3042 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3044 while (f
< x0
+rectW
) do
3046 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3051 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3052 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3055 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3056 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3060 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3066 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3070 rectW
:= gScreenWidth
-64;
3073 x0
:= (gScreenWidth
-rectW
) div 2;
3074 y0
:= gScreenHeight
-rectH
-64;
3075 if (y0
< 2) then y0
:= 2;
3077 glDisable(GL_BLEND
);
3078 glDisable(GL_TEXTURE_2D
);
3080 //glClearColor(0, 0, 0, 0);
3081 //glClear(GL_COLOR_BUFFER_BIT);
3083 glColor4ub(127, 127, 127, 255);
3084 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3086 glColor4ub(0, 0, 0, 255);
3087 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3089 glColor4ub(127, 127, 127, 255);
3090 wdt
:= rectW
*cur
div total
;
3091 if (wdt
> rectW
) then wdt
:= rectW
;
3092 drawRect(x0
, y0
, wdt
, rectH
);
3101 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3103 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3104 yy
:= (gScreenHeight
div 3);
3105 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3106 xx
:= (gScreenWidth
div 3);
3110 for i
:= 0 to NextMsg
-1 do
3112 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3113 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3117 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3118 yy
:= yy
+ LOADING_INTERLINE
;
3119 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3124 procedure DrawMenuBackground(tex
: AnsiString);
3130 if g_Texture_Get(tex
, ID
) then
3132 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3133 e_GetTextureSize(ID
, @w
, @h
);
3135 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3137 w
:= trunc(w
* (gScreenHeight
/ h
));
3138 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3140 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3143 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3145 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3147 function monDraw (mon
: TMonster
): Boolean;
3149 result
:= false; // don't stop
3154 // Ëåâûé âåðõíèé óãîë
3155 aX
:= Obj
.X
div ScaleSz
+ 1;
3156 aY
:= Obj
.Y
div ScaleSz
+ 1;
3158 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3159 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3160 // Ïðàâûé íèæíèé óãîë
3161 aX2
:= aX
+ aX2
- 1;
3162 aY2
:= aY
+ aY2
- 1;
3163 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3169 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3170 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3173 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3174 ScaleSz
:= 16 div Scale
;
3175 // Ðàçìåðû ìèíè-êàðòû:
3176 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3177 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3179 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3181 if gWalls
<> nil then
3184 for a
:= 0 to High(gWalls
) do
3186 if PanelType
<> 0 then
3188 // Ëåâûé âåðõíèé óãîë:
3189 aX
:= X
div ScaleSz
;
3190 aY
:= Y
div ScaleSz
;
3192 aX2
:= max(Width
div ScaleSz
, 1);
3193 aY2
:= max(Height
div ScaleSz
, 1);
3194 // Ïðàâûé íèæíèé óãîë:
3195 aX2
:= aX
+ aX2
- 1;
3196 aY2
:= aY
+ aY2
- 1;
3199 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3200 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3201 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3205 if gSteps
<> nil then
3208 for a
:= 0 to High(gSteps
) do
3210 if PanelType
<> 0 then
3212 // Ëåâûé âåðõíèé óãîë:
3213 aX
:= X
div ScaleSz
;
3214 aY
:= Y
div ScaleSz
;
3216 aX2
:= max(Width
div ScaleSz
, 1);
3217 aY2
:= max(Height
div ScaleSz
, 1);
3218 // Ïðàâûé íèæíèé óãîë:
3219 aX2
:= aX
+ aX2
- 1;
3220 aY2
:= aY
+ aY2
- 1;
3222 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3225 if gLifts
<> nil then
3228 for a
:= 0 to High(gLifts
) do
3230 if PanelType
<> 0 then
3232 // Ëåâûé âåðõíèé óãîë:
3233 aX
:= X
div ScaleSz
;
3234 aY
:= Y
div ScaleSz
;
3236 aX2
:= max(Width
div ScaleSz
, 1);
3237 aY2
:= max(Height
div ScaleSz
, 1);
3238 // Ïðàâûé íèæíèé óãîë:
3239 aX2
:= aX
+ aX2
- 1;
3240 aY2
:= aY
+ aY2
- 1;
3243 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3244 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3245 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3246 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3250 if gWater
<> nil then
3253 for a
:= 0 to High(gWater
) do
3255 if PanelType
<> 0 then
3257 // Ëåâûé âåðõíèé óãîë:
3258 aX
:= X
div ScaleSz
;
3259 aY
:= Y
div ScaleSz
;
3261 aX2
:= max(Width
div ScaleSz
, 1);
3262 aY2
:= max(Height
div ScaleSz
, 1);
3263 // Ïðàâûé íèæíèé óãîë:
3264 aX2
:= aX
+ aX2
- 1;
3265 aY2
:= aY
+ aY2
- 1;
3267 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3270 if gAcid1
<> nil then
3272 // Ðèñóåì êèñëîòó 1:
3273 for a
:= 0 to High(gAcid1
) do
3275 if PanelType
<> 0 then
3277 // Ëåâûé âåðõíèé óãîë:
3278 aX
:= X
div ScaleSz
;
3279 aY
:= Y
div ScaleSz
;
3281 aX2
:= max(Width
div ScaleSz
, 1);
3282 aY2
:= max(Height
div ScaleSz
, 1);
3283 // Ïðàâûé íèæíèé óãîë:
3284 aX2
:= aX
+ aX2
- 1;
3285 aY2
:= aY
+ aY2
- 1;
3287 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3290 if gAcid2
<> nil then
3292 // Ðèñóåì êèñëîòó 2:
3293 for a
:= 0 to High(gAcid2
) do
3295 if PanelType
<> 0 then
3297 // Ëåâûé âåðõíèé óãîë:
3298 aX
:= X
div ScaleSz
;
3299 aY
:= Y
div ScaleSz
;
3301 aX2
:= max(Width
div ScaleSz
, 1);
3302 aY2
:= max(Height
div ScaleSz
, 1);
3303 // Ïðàâûé íèæíèé óãîë:
3304 aX2
:= aX
+ aX2
- 1;
3305 aY2
:= aY
+ aY2
- 1;
3307 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3310 if gPlayers
<> nil then
3313 for a
:= 0 to High(gPlayers
) do
3314 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3316 // Ëåâûé âåðõíèé óãîë:
3317 aX
:= Obj
.X
div ScaleSz
+ 1;
3318 aY
:= Obj
.Y
div ScaleSz
+ 1;
3320 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3321 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3322 // Ïðàâûé íèæíèé óãîë:
3323 aX2
:= aX
+ aX2
- 1;
3324 aY2
:= aY
+ aY2
- 1;
3326 if gPlayers
[a
] = p
then
3327 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3330 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3331 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3332 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3337 g_Mons_ForEach(monDraw
);
3342 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3344 if not hasAmbient
then exit
;
3345 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3349 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3350 //FIXME: broken for splitscreen mode
3351 procedure renderDynLightsInternal ();
3353 //hasAmbient: Boolean;
3354 //ambColor: TDFColor;
3356 lx
, ly
, lrad
: Integer;
3357 scxywh
: array[0..3] of GLint
;
3360 if e_NoGraphics
then exit
;
3362 //TODO: lights should be in separate grid, i think
3363 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3364 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3367 //ambColor := gCurrentMap['light_ambient'].rgba;
3368 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3370 { // this will multiply incoming color to alpha from framebuffer
3372 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3376 * light rendering: (INVALID!)
3377 * glStencilFunc(GL_EQUAL, 0, $ff);
3379 * glClear(GL_STENCIL_BUFFER_BIT);
3380 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3381 * draw shadow volume into stencil buffer
3382 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3383 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3385 * draw color-less quad with light alpha (WARNING! don't touch color!)
3386 * glEnable(GL_BLEND);
3387 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3388 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3390 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3391 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3393 // setup OpenGL parameters
3394 glStencilMask($FFFFFFFF);
3395 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3396 glEnable(GL_STENCIL_TEST
);
3397 glEnable(GL_SCISSOR_TEST
);
3398 glClear(GL_STENCIL_BUFFER_BIT
);
3399 glStencilFunc(GL_EQUAL
, 0, $ff);
3401 for lln
:= 0 to g_dynLightCount
-1 do
3403 lx
:= g_dynLights
[lln
].x
;
3404 ly
:= g_dynLights
[lln
].y
;
3405 lrad
:= g_dynLights
[lln
].radius
;
3406 if (lrad
< 3) then continue
;
3408 if (lx
-sX
+lrad
< 0) then continue
;
3409 if (ly
-sY
+lrad
< 0) then continue
;
3410 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3411 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3413 // set scissor to optimize drawing
3414 if (g_dbg_scale
= 1.0) then
3416 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3420 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3422 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3423 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3424 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3425 // draw extruded panels
3426 glDisable(GL_TEXTURE_2D
);
3427 glDisable(GL_BLEND
);
3428 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3429 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3430 // render light texture
3431 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3432 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3435 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3436 glEnable(GL_TEXTURE_2D
);
3437 // color and opacity
3438 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3439 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3441 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3442 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3443 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3444 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3449 glDisable(GL_STENCIL_TEST
);
3450 glDisable(GL_BLEND
);
3451 glDisable(GL_SCISSOR_TEST
);
3452 //glScissor(0, 0, sWidth, sHeight);
3454 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3455 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3459 function fixViewportForScale (): Boolean;
3461 nx0
, ny0
, nw
, nh
: Integer;
3464 if (g_dbg_scale
<> 1.0) then
3467 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3468 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3469 nw
:= round(sWidth
/g_dbg_scale
);
3470 nh
:= round(sHeight
/g_dbg_scale
);
3479 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3480 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3481 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3483 TDrawCB
= procedure ();
3486 hasAmbient
: Boolean;
3488 doAmbient
: Boolean = false;
3490 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3495 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3496 if gdbg_map_use_accel_render
then
3498 tagmask
:= panelTypeToTag(panType
);
3499 while (gDrawPanelList
.count
> 0) do
3501 pan
:= TPanel(gDrawPanelList
.front());
3502 if ((pan
.tag
and tagmask
) = 0) then break
;
3503 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3504 gDrawPanelList
.popFront();
3509 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3511 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3514 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3516 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3517 if assigned(cb
) then cb();
3518 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3522 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3524 // our accelerated renderer will collect all panels to gDrawPanelList
3525 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3526 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3527 if gdbg_map_use_accel_render
then
3529 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3531 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3533 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3534 g_Map_DrawBack(backXOfs
, backYOfs
);
3535 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3537 if setTransMatrix
then
3539 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3540 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3541 glTranslatef(-sX
, -sY
, 0);
3545 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3546 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3551 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3552 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3553 glClear(GL_COLOR_BUFFER_BIT);
3556 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3559 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3560 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3561 drawOther('items', @g_Items_Draw
);
3562 drawOther('weapons', @g_Weapon_Draw
);
3563 drawOther('shells', @g_Player_DrawShells
);
3564 drawOther('drawall', @g_Player_DrawAll
);
3565 drawOther('corpses', @g_Player_DrawCorpses
);
3566 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3567 drawOther('monsters', @g_Monsters_Draw
);
3568 drawOther('itemdrop', @g_Items_DrawDrop
);
3569 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3570 drawOther('gfx', @g_GFX_Draw
);
3571 drawOther('flags', @g_Map_DrawFlags
);
3572 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3573 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3574 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3575 drawOther('dynlights', @renderDynLightsInternal
);
3577 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3579 renderAmbientQuad(hasAmbient
, ambColor
);
3583 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3586 if g_debug_HealthBar
then
3588 g_Monsters_DrawHealth();
3589 g_Player_DrawHealth();
3592 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3596 procedure DrawMapView(x
, y
, w
, h
: Integer);
3603 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3604 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3611 fixViewportForScale();
3612 renderMapInternal(-bx
, -by
, true);
3618 procedure DrawPlayer(p
: TPlayer
);
3620 px
, py
, a
, b
, c
, d
, i
: Integer;
3623 if (p
= nil) or (p
.FDummy
) then
3626 g_Map_DrawBack(0, 0);
3631 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3632 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3638 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3639 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3641 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3643 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3644 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3646 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3647 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3649 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3650 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3653 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3656 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3657 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3660 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3665 // scaled, ignore level bounds
3666 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3667 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3670 if p
.IncCam
<> 0 then
3672 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3674 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3676 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3680 if py
< gPlayerScreenSize
.Y
div 2 then
3682 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3684 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3688 if p
.IncCam
< 0 then
3690 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3693 if p
.IncCam
> 0 then
3695 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3699 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3700 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3701 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3703 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3704 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3705 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3708 sY
:= -(b
+p
.IncCam
);
3709 sWidth
:= gPlayerScreenSize
.X
;
3710 sHeight
:= gPlayerScreenSize
.Y
;
3712 //glTranslatef(a, b+p.IncCam, 0);
3714 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3716 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3717 fixViewportForScale();
3718 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3720 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3722 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3723 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3724 if (sX
< 0) then sX
:= 0;
3725 if (sY
< 0) then sY
:= 0;
3727 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3728 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3731 //r_smallmap_h: 0: left; 1: center; 2: right
3732 //r_smallmap_v: 0: top; 1: center; 2: bottom
3734 if (gMapInfo
.Width
= sWidth
) then
3738 else if (gMapInfo
.Width
< sWidth
) then
3740 case r_smallmap_h
of
3741 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3742 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3743 else sX
:= 0; // left
3747 if (gMapInfo
.Height
= sHeight
) then
3751 else if (gMapInfo
.Height
< sHeight
) then
3753 case r_smallmap_v
of
3754 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3755 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3756 else sY
:= 0; // top
3762 p
.viewPortW
:= sWidth
;
3763 p
.viewPortH
:= sHeight
;
3765 {$IFDEF ENABLE_HOLMES}
3766 if (p
= gPlayer1
) then
3768 g_Holmes_plrViewPos(sX
, sY
);
3769 g_Holmes_plrViewSize(sWidth
, sHeight
);
3773 renderMapInternal(-c
, -d
, true);
3775 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3776 case gPlayerIndicator
of
3778 p
.DrawIndicator(_RGB(255, 255, 255));
3781 for i
:= 0 to High(gPlayers
) do
3782 if gPlayers
[i
] <> nil then
3783 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3784 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3785 if gPlayerIndicatorStyle
= 1 then
3786 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3787 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3790 if p
.FSpectator
then
3791 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3792 p
.GameY
+ PLAYER_RECT_CY
- 4,
3793 'X', gStdFont
, 255, 255, 255, 1, True);
3795 for a := 0 to High(gCollideMap) do
3796 for b := 0 to High(gCollideMap[a]) do
3799 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3801 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3805 1: e_DrawPoint(1, b, a, 200, 200, 200);
3806 2: e_DrawPoint(1, b, a, 64, 64, 255);
3807 3: e_DrawPoint(1, b, a, 255, 0, 255);
3817 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3818 if g_Debug_Player
then
3819 g_Player_DrawDebug(p
);
3823 procedure drawProfilers ();
3828 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3829 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3830 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3833 procedure g_Game_Draw();
3840 plView1
, plView2
: TPlayer
;
3843 if gExit
= EXIT_QUIT
then Exit
;
3845 Time
:= sys_GetTicks() {div 1000};
3846 FPSCounter
:= FPSCounter
+1;
3847 if Time
- FPSTime
>= 1000 then
3854 if gGameOn
or (gState
= STATE_FOLD
) then
3856 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3858 gSpectMode
:= SPECT_NONE
;
3859 if not gRevertPlayers
then
3861 plView1
:= gPlayer1
;
3862 plView2
:= gPlayer2
;
3866 plView1
:= gPlayer2
;
3867 plView2
:= gPlayer1
;
3871 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3873 gSpectMode
:= SPECT_NONE
;
3874 if gPlayer2
= nil then
3877 plView1
:= gPlayer2
;
3886 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3887 gSpectMode
:= SPECT_STATS
;
3889 if gSpectMode
= SPECT_PLAYERS
then
3890 if gPlayers
<> nil then
3892 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3893 if plView1
= nil then
3895 gSpectPID1
:= GetActivePlayerID_Next();
3896 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3898 if gSpectViewTwo
then
3900 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3901 if plView2
= nil then
3903 gSpectPID2
:= GetActivePlayerID_Next();
3904 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3909 if gSpectMode
= SPECT_MAPVIEW
then
3911 // Ðåæèì ïðîñìîòðà êàðòû
3913 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3914 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3915 gHearPoint1
.Active
:= True;
3916 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3917 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3918 gHearPoint2
.Active
:= False;
3922 Split
:= (plView1
<> nil) and (plView2
<> nil);
3924 // Òî÷êè ñëóõà èãðîêîâ
3925 if plView1
<> nil then
3927 gHearPoint1
.Active
:= True;
3928 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3929 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3931 gHearPoint1
.Active
:= False;
3932 if plView2
<> nil then
3934 gHearPoint2
.Active
:= True;
3935 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3936 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3938 gHearPoint2
.Active
:= False;
3940 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3941 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3944 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3945 if gScreenHeight
mod 2 = 0 then
3946 Dec(gPlayerScreenSize
.Y
);
3949 gPlayerScreenSize
.Y
:= gScreenHeight
;
3952 if gScreenHeight
mod 2 = 0 then
3953 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3955 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3957 DrawPlayer(plView1
);
3958 gPlayer1ScreenCoord
.X
:= sX
;
3959 gPlayer1ScreenCoord
.Y
:= sY
;
3963 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3965 DrawPlayer(plView2
);
3966 gPlayer2ScreenCoord
.X
:= sX
;
3967 gPlayer2ScreenCoord
.Y
:= sY
;
3970 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3973 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3976 {$IFDEF ENABLE_HOLMES}
3978 if (g_holmes_enabled
) then g_Holmes_Draw();
3981 if MessageText
<> '' then
3985 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3987 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3988 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3990 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3991 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3994 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3996 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3998 // Draw spectator GUI
4001 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4004 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4006 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4008 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4010 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4011 if gSpectMode
= SPECT_STATS
then
4013 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4014 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4016 if gSpectMode
= SPECT_MAPVIEW
then
4018 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4019 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4020 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4022 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4024 if gSpectMode
= SPECT_PLAYERS
then
4026 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4027 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4028 if gSpectViewTwo
then
4030 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4031 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4032 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4033 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4037 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4038 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4044 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4046 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4047 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4049 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4050 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4051 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4056 if (gState
= STATE_MENU
) then
4058 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4059 // F3 at menu will show game loading dialog
4060 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4061 if (g_ActiveWindow
<> nil) then
4063 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4064 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4068 // F3 at titlepic will show game loading dialog
4069 if e_KeyPressed(IK_F3
) then
4071 g_Menu_Show_LoadMenu(true);
4072 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4077 if gState
= STATE_FOLD
then
4079 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4082 if gState
= STATE_INTERCUSTOM
then
4084 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4086 back
:= 'TEXTURE_endpic';
4087 if not g_Texture_Get(back
, ID
) then
4088 back
:= _lc
[I_TEXTURE_ENDPIC
];
4093 DrawMenuBackground(back
);
4097 if g_ActiveWindow
<> nil then
4099 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4100 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4104 if gState
= STATE_INTERSINGLE
then
4106 if EndingGameCounter
> 0 then
4108 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4114 DrawMenuBackground(back
);
4118 if g_ActiveWindow
<> nil then
4120 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4121 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4126 if gState
= STATE_ENDPIC
then
4129 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4130 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4132 if g_ActiveWindow
<> nil then
4134 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4135 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4139 if gState
= STATE_SLIST
then
4141 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4143 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4144 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4146 DrawMenuBackground('MENU_BACKGROUND');
4147 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4148 g_Serverlist_Draw(slCurrent
, slTable
);
4152 if g_ActiveWindow
<> nil then
4156 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4157 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4159 g_ActiveWindow
.Draw();
4166 if g_debug_Sounds
and gGameOn
then
4168 for w
:= 0 to High(e_SoundsArray
) do
4169 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4170 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4175 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4176 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4179 if gGameOn
and gShowTime
then
4180 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4182 if gGameOn
then drawProfilers();
4184 {$IFDEF ENABLE_HOLMES}
4191 procedure g_Game_Quit();
4193 g_Game_StopAllSounds(True);
4196 g_PlayerModel_FreeData();
4197 g_Texture_DeleteAll();
4198 g_Frames_DeleteAll();
4200 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4203 if NetInitDone
then g_Net_Free
;
4205 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4206 if gMapToDelete
<> '' then
4207 g_Game_DeleteTestMap();
4213 procedure g_FatalError(Text: String);
4215 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4216 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4218 gExit
:= EXIT_SIMPLE
;
4221 procedure g_SimpleError(Text: String);
4223 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4224 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4227 procedure g_Game_SetupScreenSize();
4229 RES_FACTOR
= 4.0 / 3.0;
4235 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4236 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4237 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4238 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4240 gPlayerScreenSize
.Y
:= gScreenHeight
;
4242 // Ðàçìåð çàäíåãî ïëàíà:
4243 if BackID
<> DWORD(-1) then
4246 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4247 (gScreenHeight
*s
> gMapInfo
.Height
) then
4249 gBackSize
.X
:= gScreenWidth
;
4250 gBackSize
.Y
:= gScreenHeight
;
4254 e_GetTextureSize(BackID
, @bw
, @bh
);
4255 rf
:= Single(bw
) / Single(bh
);
4256 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4257 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4258 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4259 if (s
< 1.0) then s
:= 1.0;
4260 gBackSize
.X
:= Round(bw
*s
);
4261 gBackSize
.Y
:= Round(bh
*s
);
4266 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4268 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4271 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4273 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4274 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4276 if gPlayer1
= nil then
4278 if g_Game_IsClient
then
4280 if NetPlrUID1
> -1 then
4282 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4283 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4288 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4289 Team
:= gPlayer1Settings
.Team
;
4291 // Ñîçäàíèå ïåðâîãî èãðîêà:
4292 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4293 gPlayer1Settings
.Color
,
4295 if gPlayer1
= nil then
4296 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4299 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4300 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4301 if g_Game_IsServer
and g_Game_IsNet
then
4302 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4303 gPlayer1
.Respawn(False, True);
4304 g_Net_Slist_ServerPlayerComes();
4309 if gPlayer2
= nil then
4311 if g_Game_IsClient
then
4313 if NetPlrUID2
> -1 then
4314 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4318 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4319 Team
:= gPlayer2Settings
.Team
;
4321 // Ñîçäàíèå âòîðîãî èãðîêà:
4322 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4323 gPlayer2Settings
.Color
,
4325 if gPlayer2
= nil then
4326 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4329 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4330 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4331 if g_Game_IsServer
and g_Game_IsNet
then
4332 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4333 gPlayer2
.Respawn(False, True);
4334 g_Net_Slist_ServerPlayerComes();
4341 procedure g_Game_RemovePlayer();
4345 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4346 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4351 if g_Game_IsServer
then
4354 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4355 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4356 g_Player_Remove(Pl
.UID
);
4357 g_Net_Slist_ServerPlayerLeaves();
4365 if g_Game_IsServer
then
4368 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4369 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4370 g_Player_Remove(Pl
.UID
);
4371 g_Net_Slist_ServerPlayerLeaves();
4375 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4379 g_Net_Slist_ServerPlayerLeaves();
4382 procedure g_Game_Spectate();
4384 g_Game_RemovePlayer();
4385 if gPlayer1
<> nil then
4386 g_Game_RemovePlayer();
4389 procedure g_Game_SpectateCenterView();
4391 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4392 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4395 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4402 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4404 g_Game_ClearLoading();
4407 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4410 gGameSettings
.GameType
:= GT_SINGLE
;
4411 gGameSettings
.MaxLives
:= 0;
4412 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4413 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4414 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4415 gSwitchGameMode
:= GM_SINGLE
;
4417 g_Game_ExecuteEvent('ongamestart');
4419 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4420 g_Game_SetupScreenSize();
4422 // Ñîçäàíèå ïåðâîãî èãðîêà:
4423 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4424 gPlayer1Settings
.Color
,
4425 gPlayer1Settings
.Team
, False));
4426 if gPlayer1
= nil then
4428 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4432 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4435 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4438 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4439 gPlayer2Settings
.Color
,
4440 gPlayer2Settings
.Team
, False));
4441 if gPlayer2
= nil then
4443 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4447 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4451 // Çàãðóçêà è çàïóñê êàðòû:
4452 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4454 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4455 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4459 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4463 for i
:= nPl
+1 to nPlayers
do
4464 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4467 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4468 TimeLimit
, GoalLimit
: Word;
4470 Options
: LongWord; nPlayers
: Byte);
4476 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4478 g_Game_ClearLoading();
4481 gGameSettings
.GameType
:= GT_CUSTOM
;
4482 gGameSettings
.GameMode
:= GameMode
;
4483 gSwitchGameMode
:= GameMode
;
4484 gGameSettings
.TimeLimit
:= TimeLimit
;
4485 gGameSettings
.GoalLimit
:= GoalLimit
;
4486 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4487 gGameSettings
.Options
:= Options
;
4489 gCoopTotalMonstersKilled
:= 0;
4490 gCoopTotalSecretsFound
:= 0;
4491 gCoopTotalMonsters
:= 0;
4492 gCoopTotalSecrets
:= 0;
4496 g_Game_ExecuteEvent('ongamestart');
4498 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4499 g_Game_SetupScreenSize();
4501 // Ðåæèì íàáëþäàòåëÿ:
4502 if nPlayers
= 0 then
4509 if nPlayers
>= 1 then
4511 // Ñîçäàíèå ïåðâîãî èãðîêà:
4512 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4513 gPlayer1Settings
.Color
,
4514 gPlayer1Settings
.Team
, False));
4515 if gPlayer1
= nil then
4517 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4521 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4525 if nPlayers
>= 2 then
4527 // Ñîçäàíèå âòîðîãî èãðîêà:
4528 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4529 gPlayer2Settings
.Color
,
4530 gPlayer2Settings
.Team
, False));
4531 if gPlayer2
= nil then
4533 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4537 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4541 // Çàãðóçêà è çàïóñê êàðòû:
4542 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4544 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4548 // Íåò òî÷åê ïîÿâëåíèÿ:
4549 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4550 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4551 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4552 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4553 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4555 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4559 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4563 for i
:= nPl
+1 to nPlayers
do
4564 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4567 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4568 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4569 Options
: LongWord; nPlayers
: Byte;
4570 IPAddr
: LongWord; Port
: Word);
4573 g_Net_Slist_ServerClosed();
4575 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4577 g_Game_ClearLoading();
4580 gGameSettings
.GameType
:= GT_SERVER
;
4581 gGameSettings
.GameMode
:= GameMode
;
4582 gSwitchGameMode
:= GameMode
;
4583 gGameSettings
.TimeLimit
:= TimeLimit
;
4584 gGameSettings
.GoalLimit
:= GoalLimit
;
4585 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4586 gGameSettings
.Options
:= Options
;
4588 gCoopTotalMonstersKilled
:= 0;
4589 gCoopTotalSecretsFound
:= 0;
4590 gCoopTotalMonsters
:= 0;
4591 gCoopTotalSecrets
:= 0;
4595 g_Game_ExecuteEvent('ongamestart');
4597 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4598 g_Game_SetupScreenSize();
4600 // Ðåæèì íàáëþäàòåëÿ:
4601 if nPlayers
= 0 then
4607 if nPlayers
>= 1 then
4609 // Ñîçäàíèå ïåðâîãî èãðîêà:
4610 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4611 gPlayer1Settings
.Color
,
4612 gPlayer1Settings
.Team
, False));
4613 if gPlayer1
= nil then
4615 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4619 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4622 if nPlayers
>= 2 then
4624 // Ñîçäàíèå âòîðîãî èãðîêà:
4625 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4626 gPlayer2Settings
.Color
,
4627 gPlayer2Settings
.Team
, False));
4628 if gPlayer2
= nil then
4630 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4634 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4637 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4638 if NetForwardPorts
then
4639 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4642 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4644 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4648 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4650 g_Net_Slist_ServerStarted();
4652 // Çàãðóçêà è çàïóñê êàðòû:
4653 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4655 g_Net_Slist_ServerClosed();
4656 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4660 // Íåò òî÷åê ïîÿâëåíèÿ:
4661 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4662 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4663 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4664 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4665 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4667 g_Net_Slist_ServerClosed();
4668 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4672 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4675 g_Net_Slist_ServerMapStarted();
4676 NetState
:= NET_STATE_GAME
;
4679 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4694 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4695 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4697 g_Game_ClearLoading();
4700 gGameSettings
.GameType
:= GT_CLIENT
;
4702 gCoopTotalMonstersKilled
:= 0;
4703 gCoopTotalSecretsFound
:= 0;
4704 gCoopTotalMonsters
:= 0;
4705 gCoopTotalSecrets
:= 0;
4709 g_Game_ExecuteEvent('ongamestart');
4711 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4712 g_Game_SetupScreenSize();
4714 NetState
:= NET_STATE_AUTH
;
4716 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4718 // create (or update) map/resource databases
4719 g_Res_CreateDatabases(true);
4722 if not g_Net_Connect(Addr
, Port
) then
4724 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4725 NetState
:= NET_STATE_NONE
;
4729 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4731 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4736 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4737 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4738 // thank you, enet. let's ignore failures altogether then.
4739 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4741 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4743 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4745 // ignore all download packets, they're processed by separate code
4746 enet_packet_destroy(NetEvent
.packet
);
4749 Ptr
:= NetEvent
.packet
^.data
;
4750 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4752 enet_packet_destroy(NetEvent
.packet
);
4756 InMsg
.ReadLongWord(); // skip size
4757 MID
:= InMsg
.ReadByte();
4759 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4761 NetMyID
:= InMsg
.ReadByte();
4762 NetPlrUID1
:= InMsg
.ReadWord();
4764 WadName
:= InMsg
.ReadString();
4765 Map
:= InMsg
.ReadString();
4767 gWADHash
:= InMsg
.ReadMD5();
4769 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4770 gSwitchGameMode
:= gGameSettings
.GameMode
;
4771 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4772 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4773 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4774 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4775 T
:= InMsg
.ReadLongWord();
4777 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4778 //if newResPath = '' then
4780 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4781 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4782 if newResPath
= '' then
4784 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4785 enet_packet_destroy(NetEvent
.packet
);
4786 NetState
:= NET_STATE_NONE
;
4789 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4791 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4794 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4795 gPlayer1Settings
.Color
,
4796 gPlayer1Settings
.Team
, False));
4798 if gPlayer1
= nil then
4800 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4802 enet_packet_destroy(NetEvent
.packet
);
4803 NetState
:= NET_STATE_NONE
;
4807 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4808 gPlayer1
.UID
:= NetPlrUID1
;
4809 gPlayer1
.Reset(True);
4811 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4813 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4815 enet_packet_destroy(NetEvent
.packet
);
4816 NetState
:= NET_STATE_NONE
;
4824 enet_packet_destroy(NetEvent
.packet
);
4828 enet_packet_destroy(NetEvent
.packet
);
4832 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4835 if (NetEvent
.data
<= NET_DISC_MAX
) then
4836 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4837 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4844 ProcessLoading(true);
4846 if g_Net_UserRequestExit() then
4855 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4856 NetState
:= NET_STATE_NONE
;
4860 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4861 gLMSRespawnTime
:= 0;
4864 NetState
:= NET_STATE_GAME
;
4865 MC_SEND_FullStateRequest
;
4866 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4870 lastAsMegaWad
: Boolean = false;
4872 procedure g_Game_ChangeMap(const MapPath
: String);
4876 g_Game_ClearLoading();
4878 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4879 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4880 if gExitByTrigger
then
4883 gExitByTrigger
:= False;
4885 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4886 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4889 procedure g_Game_Restart();
4893 if g_Game_IsClient
then
4895 map
:= g_ExtractFileName(gMapInfo
.Map
);
4896 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4900 g_Game_ClearLoading();
4901 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4904 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4906 NewWAD
, ResName
: String;
4910 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4911 g_Player_RemoveAllCorpses();
4913 if (not g_Game_IsClient
) and
4914 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4915 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4917 if gSwitchGameMode
= GM_CTF
then
4918 gGameSettings
.MaxLives
:= 0;
4919 gGameSettings
.GameMode
:= gSwitchGameMode
;
4922 gSwitchGameMode
:= gGameSettings
.GameMode
;
4924 g_Player_ResetTeams();
4926 lastAsMegaWad
:= asMegawad
;
4927 if isWadPath(Map
) then
4929 NewWAD
:= g_ExtractWadName(Map
);
4930 ResName
:= g_ExtractFileName(Map
);
4931 if g_Game_IsServer
then
4933 nws
:= findDiskWad(NewWAD
);
4934 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4937 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4938 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4942 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4943 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4945 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4946 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4948 if (length(nws
) = 0) then
4950 ResName
:= ''; // failed
4955 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4956 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4957 g_Game_LoadWAD(NewWAD
);
4962 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4963 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
4968 NewWAD
:= gGameSettings
.WAD
;
4972 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4974 if (ResName
<> '') and (NewWAD
<> '') then
4976 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4977 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
4981 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4983 gState
:= STATE_NONE
;
4984 g_ActiveWindow
:= nil;
4990 if gGameSettings
.GameMode
= GM_CTF
then
4992 g_Map_ResetFlag(FLAG_RED
);
4993 g_Map_ResetFlag(FLAG_BLUE
);
4994 // CTF, à ôëàãîâ íåò:
4995 if not g_Map_HaveFlagPoints() then
4996 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5001 gState
:= STATE_MENU
;
5006 gPauseMain
:= false;
5007 gPauseHolmes
:= false;
5009 NetTimeToUpdate
:= 1;
5010 NetTimeToReliable
:= 0;
5011 NetTimeToMaster
:= NetMasterRate
;
5012 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5013 gLMSRespawnTime
:= 0;
5014 gMissionFailed
:= False;
5017 gCoopMonstersKilled
:= 0;
5018 gCoopSecretsFound
:= 0;
5020 gVoteInProgress
:= False;
5021 gVotePassed
:= False;
5027 if not gGameOn
then Exit
;
5029 g_Game_SpectateCenterView();
5031 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5033 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5034 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5035 gLMSSoftSpawn
:= True;
5036 if NetMode
= NET_SERVER
then
5037 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
5039 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
5042 if NetMode
= NET_SERVER
then
5044 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5047 g_Net_Slist_ServerMapStarted();
5049 if NetClients
<> nil then
5050 for I
:= 0 to High(NetClients
) do
5051 if NetClients
[I
].Used
then
5053 NetClients
[I
].Voted
:= False;
5054 if NetClients
[I
].RequestedFullUpdate
then
5056 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5057 NetClients
[I
].RequestedFullUpdate
:= False;
5061 g_Net_UnbanNonPermHosts();
5066 gCoopTotalMonstersKilled
:= 0;
5067 gCoopTotalSecretsFound
:= 0;
5068 gCoopTotalMonsters
:= 0;
5069 gCoopTotalSecrets
:= 0;
5073 g_Game_ExecuteEvent('onmapstart');
5076 procedure SetFirstLevel
;
5080 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5081 if MapList
= nil then
5084 SortSArray(MapList
);
5085 gNextMap
:= MapList
[Low(MapList
)];
5090 procedure g_Game_ExitLevel(const Map
: AnsiString);
5094 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5095 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5096 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5097 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5099 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5100 if gGameSettings
.GameType
= GT_SINGLE
then
5101 gExit
:= EXIT_ENDLEVELSINGLE
5102 else // Âûøëè â âûõîä â Ñâîåé èãðå
5104 gExit
:= EXIT_ENDLEVELCUSTOM
;
5105 if gGameSettings
.GameMode
= GM_COOP
then
5106 g_Player_RememberAll
;
5108 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5111 if gGameSettings
.GameMode
= GM_COOP
then
5114 gStatsPressed
:= True;
5115 gNextMap
:= 'MAP01';
5117 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5120 if g_Game_IsNet
then
5122 MH_SEND_GameStats();
5123 MH_SEND_CoopStats();
5129 procedure g_Game_RestartLevel();
5133 if gGameSettings
.GameMode
= GM_SINGLE
then
5138 gExit
:= EXIT_ENDLEVELCUSTOM
;
5139 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5143 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5145 gWAD
{, xwad}: String;
5148 if not g_Game_IsClient
then Exit
;
5149 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5151 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5156 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5160 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5163 g_Game_LoadWAD(NewWAD
);
5167 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5168 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5171 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5172 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5176 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5180 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5181 g_Game_LoadWAD(NewWAD);
5185 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5187 i
, n
, nb
, nr
: Integer;
5189 function monRespawn (mon
: TMonster
): Boolean;
5191 result
:= false; // don't stop
5192 if not mon
.FNoRespawn
then mon
.Respawn();
5196 if not g_Game_IsServer
then Exit
;
5197 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5198 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5199 gLMSRespawnTime
:= 0;
5202 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5204 gMissionFailed
:= True;
5205 g_Game_RestartLevel
;
5209 n
:= 0; nb
:= 0; nr
:= 0;
5210 for i
:= Low(gPlayers
) to High(gPlayers
) do
5211 if (gPlayers
[i
] <> nil) and
5212 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5213 (gPlayers
[i
] is TBot
)) then
5216 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5217 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5220 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5222 // wait a second until the fuckers finally decide to join
5223 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5224 gLMSRespawnTime
:= gTime
+ 1000;
5225 gLMSSoftSpawn
:= NoMapRestart
;
5229 g_Player_RemoveAllCorpses
;
5230 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5231 if g_Game_IsNet
then
5232 MH_SEND_GameEvent(NET_EV_LMS_START
);
5234 for i
:= Low(gPlayers
) to High(gPlayers
) do
5236 if gPlayers
[i
] = nil then continue
;
5237 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5238 // don't touch normal spectators
5239 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5241 gPlayers
[i
].FNoRespawn
:= True;
5242 gPlayers
[i
].Lives
:= 0;
5243 if g_Game_IsNet
then
5244 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5247 gPlayers
[i
].FNoRespawn
:= False;
5248 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5249 gPlayers
[i
].Respawn(False, True);
5250 if gGameSettings
.GameMode
= GM_COOP
then
5252 gPlayers
[i
].Frags
:= 0;
5253 gPlayers
[i
].RecallState
;
5255 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5256 gPlayer1
:= g_Player_Get(gLMSPID1
);
5257 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5258 gPlayer2
:= g_Player_Get(gLMSPID2
);
5261 g_Items_RestartRound();
5264 g_Mons_ForEach(monRespawn
);
5266 gLMSSoftSpawn
:= False;
5269 function g_Game_GetFirstMap(WAD
: String): String;
5273 MapList
:= g_Map_GetMapsList(WAD
);
5274 if MapList
= nil then
5277 SortSArray(MapList
);
5278 Result
:= MapList
[Low(MapList
)];
5280 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5286 function g_Game_GetNextMap(): String;
5293 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5294 if MapList
= nil then
5297 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5299 SortSArray(MapList
);
5301 for I
:= Low(MapList
) to High(MapList
) do
5302 if Map
= MapList
[I
] then
5308 if MapIndex
<> -255 then
5310 if MapIndex
= High(MapList
) then
5311 Result
:= MapList
[Low(MapList
)]
5313 Result
:= MapList
[MapIndex
+ 1];
5315 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5321 procedure g_Game_NextLevel();
5323 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5324 gExit
:= EXIT_ENDLEVELCUSTOM
5327 gExit
:= EXIT_ENDLEVELSINGLE
;
5331 if gNextMap
<> '' then Exit
;
5332 gNextMap
:= g_Game_GetNextMap();
5335 function g_Game_IsTestMap(): Boolean;
5337 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5340 procedure g_Game_DeleteTestMap();
5343 //MapName: AnsiString;
5351 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5352 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5353 if (a
= 0) then exit
;
5355 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5356 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5357 Delete(gMapToDelete
, 1, a
+5);
5358 gMapToDelete
:= UpperCase(gMapToDelete
);
5360 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5363 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5364 if MapName <> TEST_MAP_NAME then
5367 if not gTempDelete then
5369 time := g_GetFileTime(WadName);
5370 WAD := TWADFile.Create();
5373 if not WAD.ReadFile(WadName) then
5374 begin // Íåò òàêîãî WAD-ôàéëà
5379 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5381 MapList := WAD.GetResourcesList('');
5383 if MapList <> nil then
5384 for a := 0 to High(MapList) do
5385 if MapList[a] = MapName then
5387 // Óäàëÿåì è ñîõðàíÿåì:
5388 WAD.RemoveResource('', MapName);
5389 WAD.SaveTo(WadName);
5394 g_SetFileTime(WadName, time);
5397 if gTempDelete
then DeleteFile(WadName
);
5400 procedure GameCVars(P
: SSArray
);
5403 stat
: TPlayerStatArray
;
5408 cmd
:= LowerCase(P
[0]);
5409 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5411 with gGameSettings
do
5413 if (Length(P
) > 1) and
5414 ((P
[1] = '1') or (P
[1] = '0')) then
5416 if (P
[1][1] = '1') then
5417 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5419 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5422 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5423 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5425 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5427 if g_Game_IsNet
then MH_SEND_GameSettings
;
5430 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5432 with gGameSettings
do
5434 if (Length(P
) > 1) and
5435 ((P
[1] = '1') or (P
[1] = '0')) then
5437 if (P
[1][1] = '1') then
5438 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5440 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5443 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5444 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5446 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5448 if g_Game_IsNet
then MH_SEND_GameSettings
;
5451 else if cmd
= 'g_gamemode' then
5453 a
:= g_Game_TextToMode(P
[1]);
5454 if a
= GM_SINGLE
then a
:= GM_COOP
;
5455 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5457 gSwitchGameMode
:= a
;
5458 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5459 (gState
= STATE_INTERSINGLE
) then
5460 gSwitchGameMode
:= GM_SINGLE
;
5462 gGameSettings
.GameMode
:= gSwitchGameMode
;
5464 if gSwitchGameMode
= gGameSettings
.GameMode
then
5465 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5466 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5468 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5469 [g_Game_ModeToText(gGameSettings
.GameMode
),
5470 g_Game_ModeToText(gSwitchGameMode
)]));
5472 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5474 with gGameSettings
do
5476 if (Length(P
) > 1) and
5477 ((P
[1] = '1') or (P
[1] = '0')) then
5479 if (P
[1][1] = '1') then
5480 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5482 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5485 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5486 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5488 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5489 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5491 if g_Game_IsNet
then MH_SEND_GameSettings
;
5494 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5496 with gGameSettings
do
5498 if (Length(P
) > 1) and
5499 ((P
[1] = '1') or (P
[1] = '0')) then
5501 if (P
[1][1] = '1') then
5502 Options
:= Options
or GAME_OPTION_MONSTERS
5504 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5507 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5508 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5510 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5511 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5513 if g_Game_IsNet
then MH_SEND_GameSettings
;
5516 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5518 with gGameSettings
do
5520 if (Length(P
) > 1) and
5521 ((P
[1] = '1') or (P
[1] = '0')) then
5523 if (P
[1][1] = '1') then
5524 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5526 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5529 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5530 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5532 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5534 if g_Game_IsNet
then MH_SEND_GameSettings
;
5537 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5539 with gGameSettings
do
5541 if (Length(P
) > 1) and
5542 ((P
[1] = '1') or (P
[1] = '0')) then
5544 if (P
[1][1] = '1') then
5545 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5547 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5550 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5551 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5553 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5555 if g_Game_IsNet
then MH_SEND_GameSettings
;
5558 else if (cmd
= 'g_dm_keys') and not g_Game_IsClient
then
5560 with gGameSettings
do
5562 if (Length(P
) > 1) and
5563 ((P
[1] = '1') or (P
[1] = '0')) then
5565 if (P
[1][1] = '1') then
5566 Options
:= Options
or GAME_OPTION_DMKEYS
5568 Options
:= Options
and (not GAME_OPTION_DMKEYS
);
5571 if (LongBool(Options
and GAME_OPTION_DMKEYS
)) then
5572 g_Console_Add(_lc
[I_MSG_DMKEYS_ON
])
5574 g_Console_Add(_lc
[I_MSG_DMKEYS_OFF
]);
5575 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5577 if g_Game_IsNet
then MH_SEND_GameSettings
;
5580 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5582 if Length(P
) > 1 then
5584 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5585 gGameSettings
.WarmupTime
:= 30
5587 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5590 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5591 [gGameSettings
.WarmupTime
]));
5592 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5594 else if (cmd
= 'g_spawn_invul') and not g_Game_IsClient
then
5596 if Length(P
) > 1 then
5598 if StrToIntDef(P
[1], gGameSettings
.SpawnInvul
) = 0 then
5599 gGameSettings
.SpawnInvul
:= 0
5601 gGameSettings
.SpawnInvul
:= StrToIntDef(P
[1], gGameSettings
.SpawnInvul
);
5604 g_Console_Add(Format(_lc
[I_MSG_SPAWNINVUL
],
5605 [gGameSettings
.SpawnInvul
]));
5606 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5608 else if cmd
= 'net_interp' then
5610 if (Length(P
) > 1) then
5611 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5612 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5613 s
:= e_GetWriteableDir(ConfigDirs
);
5616 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5617 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5618 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5622 else if cmd
= 'net_forceplayerupdate' then
5624 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5625 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5627 if NetForcePlayerUpdate
then
5628 g_Console_Add('net_forceplayerupdate = 1')
5630 g_Console_Add('net_forceplayerupdate = 0');
5632 s
:= e_GetWriteableDir(ConfigDirs
);
5635 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5636 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5637 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5641 else if cmd
= 'net_predictself' then
5643 if (Length(P
) > 1) and
5644 ((P
[1] = '1') or (P
[1] = '0')) then
5645 NetPredictSelf
:= (P
[1][1] = '1');
5647 if NetPredictSelf
then
5648 g_Console_Add('net_predictself = 1')
5650 g_Console_Add('net_predictself = 0');
5652 s
:= e_GetWriteableDir(ConfigDirs
);
5655 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5656 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5657 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5661 else if cmd
= 'sv_name' then
5663 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5665 NetServerName
:= P
[1];
5666 if Length(NetServerName
) > 64 then
5667 SetLength(NetServerName
, 64);
5668 g_Net_Slist_ServerRenamed();
5671 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5673 else if cmd
= 'sv_passwd' then
5675 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5677 NetPassword
:= P
[1];
5678 if Length(NetPassword
) > 24 then
5679 SetLength(NetPassword
, 24);
5680 g_Net_Slist_ServerRenamed();
5683 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5685 else if cmd
= 'sv_maxplrs' then
5687 if (Length(P
) > 1) then
5689 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5690 if g_Game_IsServer
and g_Game_IsNet
then
5693 for a
:= 0 to High(NetClients
) do
5695 if NetClients
[a
].Used
then
5698 if b
> NetMaxClients
then
5700 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5701 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5702 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5703 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5707 g_Net_Slist_ServerRenamed();
5711 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5713 else if cmd
= 'sv_public' then
5715 if (Length(P
) > 1) then
5717 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5718 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5721 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5723 else if cmd
= 'sv_intertime' then
5725 if (Length(P
) > 1) then
5726 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5728 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5730 else if cmd
= 'p1_name' then
5732 if (Length(P
) > 1) and gGameOn
then
5734 if g_Game_IsClient
then
5736 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5737 MC_SEND_PlayerSettings
;
5740 if gPlayer1
<> nil then
5742 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5743 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5746 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5749 else if cmd
= 'p2_name' then
5751 if (Length(P
) > 1) and gGameOn
then
5753 if g_Game_IsClient
then
5755 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5756 MC_SEND_PlayerSettings
;
5759 if gPlayer2
<> nil then
5761 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5762 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5765 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5768 else if cmd
= 'p1_color' then
5770 if Length(P
) > 3 then
5771 if g_Game_IsClient
then
5773 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5774 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5775 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5776 MC_SEND_PlayerSettings
;
5779 if gPlayer1
<> nil then
5781 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5782 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5783 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5784 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5787 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5788 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5789 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5791 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5793 if Length(P
) > 3 then
5794 if g_Game_IsClient
then
5796 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5797 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5798 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5799 MC_SEND_PlayerSettings
;
5802 if gPlayer2
<> nil then
5804 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5805 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5806 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5807 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5810 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5811 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5812 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5814 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5816 if cmd
= 'r_showscore' then
5818 if (Length(P
) > 1) and
5819 ((P
[1] = '1') or (P
[1] = '0')) then
5820 gShowGoals
:= (P
[1][1] = '1');
5823 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5825 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5827 else if cmd
= 'r_showstat' then
5829 if (Length(P
) > 1) and
5830 ((P
[1] = '1') or (P
[1] = '0')) then
5831 gShowStat
:= (P
[1][1] = '1');
5834 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5836 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5838 else if cmd
= 'r_showkillmsg' then
5840 if (Length(P
) > 1) and
5841 ((P
[1] = '1') or (P
[1] = '0')) then
5842 gShowKillMsg
:= (P
[1][1] = '1');
5844 if gShowKillMsg
then
5845 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5847 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5849 else if cmd
= 'r_showlives' then
5851 if (Length(P
) > 1) and
5852 ((P
[1] = '1') or (P
[1] = '0')) then
5853 gShowLives
:= (P
[1][1] = '1');
5856 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5858 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5860 else if cmd
= 'r_showspect' then
5862 if (Length(P
) > 1) and
5863 ((P
[1] = '1') or (P
[1] = '0')) then
5864 gSpectHUD
:= (P
[1][1] = '1');
5867 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5869 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5871 else if cmd
= 'r_showping' then
5873 if (Length(P
) > 1) and
5874 ((P
[1] = '1') or (P
[1] = '0')) then
5875 gShowPing
:= (P
[1][1] = '1');
5878 g_Console_Add(_lc
[I_MSG_PING_ON
])
5880 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5882 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5884 if Length(P
) > 1 then
5886 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5887 gGameSettings
.GoalLimit
:= 0
5892 if gGameSettings
.GameMode
= GM_DM
then
5894 stat
:= g_Player_GetStats();
5896 for a
:= 0 to High(stat
) do
5897 if stat
[a
].Frags
> b
then
5901 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5903 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5906 if g_Game_IsNet
then MH_SEND_GameSettings
;
5909 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5911 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5913 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5914 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5916 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5917 [gGameSettings
.TimeLimit
div 3600,
5918 (gGameSettings
.TimeLimit
div 60) mod 60,
5919 gGameSettings
.TimeLimit
mod 60]));
5920 if g_Game_IsNet
then MH_SEND_GameSettings
;
5922 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5924 if Length(P
) > 1 then
5926 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5927 gGameSettings
.MaxLives
:= 0
5931 stat
:= g_Player_GetStats();
5933 for a
:= 0 to High(stat
) do
5934 if stat
[a
].Lives
> b
then
5936 gGameSettings
.MaxLives
:=
5937 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5941 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5942 [gGameSettings
.MaxLives
]));
5943 if g_Game_IsNet
then MH_SEND_GameSettings
;
5948 procedure PrintHeapStats();
5952 hs
:= GetFPCHeapStatus();
5953 e_LogWriteLn ('v===== heap status =====v');
5954 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5955 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5956 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5957 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5958 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5959 e_LogWriteLn ('^=======================^');
5962 procedure DebugCommands(P
: SSArray
);
5969 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5970 if {gDebugMode}conIsCheatsEnabled
then
5972 cmd
:= LowerCase(P
[0]);
5973 if cmd
= 'd_window' then
5975 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5976 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5978 else if cmd
= 'd_sounds' then
5980 if (Length(P
) > 1) and
5981 ((P
[1] = '1') or (P
[1] = '0')) then
5982 g_Debug_Sounds
:= (P
[1][1] = '1');
5984 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5986 else if cmd
= 'd_frames' then
5988 if (Length(P
) > 1) and
5989 ((P
[1] = '1') or (P
[1] = '0')) then
5990 g_Debug_Frames
:= (P
[1][1] = '1');
5992 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5994 else if cmd
= 'd_winmsg' then
5996 if (Length(P
) > 1) and
5997 ((P
[1] = '1') or (P
[1] = '0')) then
5998 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6000 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6002 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6004 if (Length(P
) > 1) and
6005 ((P
[1] = '1') or (P
[1] = '0')) then
6006 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6008 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6010 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6012 if Length(P
) > 1 then
6014 '0': g_debug_BotAIOff
:= 0;
6015 '1': g_debug_BotAIOff
:= 1;
6016 '2': g_debug_BotAIOff
:= 2;
6017 '3': g_debug_BotAIOff
:= 3;
6020 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6022 else if cmd
= 'd_monster' then
6024 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6025 if Length(P
) < 2 then
6027 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6028 g_Console_Add('ID | Name');
6029 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6030 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6031 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6034 a
:= StrToIntDef(P
[1], 0);
6035 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6036 a
:= g_Mons_TypeIdByName(P
[1]);
6038 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6039 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6042 with gPlayer1
.Obj
do
6044 mon
:= g_Monsters_Create(a
,
6045 X
+ Rect
.X
+ (Rect
.Width
div 2),
6046 Y
+ Rect
.Y
+ Rect
.Height
,
6047 gPlayer1
.Direction
, True);
6049 if (Length(P
) > 2) and (mon
<> nil) then
6051 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6052 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6053 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6054 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6055 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6056 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6057 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6058 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6059 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6064 else if (cmd
= 'd_health') then
6066 if (Length(P
) > 1) and
6067 ((P
[1] = '1') or (P
[1] = '0')) then
6068 g_debug_HealthBar
:= (P
[1][1] = '1');
6070 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6072 else if (cmd
= 'd_player') then
6074 if (Length(P
) > 1) and
6075 ((P
[1] = '1') or (P
[1] = '0')) then
6076 g_debug_Player
:= (P
[1][1] = '1');
6078 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6080 else if (cmd
= 'd_mem') then
6086 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6090 procedure GameCheats(P
: SSArray
);
6096 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6098 g_Console_Add('not available');
6104 g_Console_Add('where is the player?!');
6107 cmd
:= LowerCase(P
[0]);
6111 plr
.GodMode
:= not plr
.GodMode
;
6112 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6115 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6116 if cmd
= 'give' then
6118 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6119 for f
:= 1 to High(P
) do
6121 cmd
:= LowerCase(P
[f
]);
6122 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6123 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6124 if cmd
= 'exit' then
6126 if gTriggers
<> nil then
6128 for a
:= 0 to High(gTriggers
) do
6130 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6132 g_Console_Add('player left the map');
6133 gExitByTrigger
:= True;
6134 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6135 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6143 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6144 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6145 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6146 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6147 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6149 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6150 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6152 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6153 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;
6155 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6156 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6158 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6159 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6161 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6162 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6164 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6165 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6166 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6168 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6169 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6170 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6171 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;
6172 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6173 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6175 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;
6176 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;
6177 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;
6178 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;
6179 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;
6180 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;
6182 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6183 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;
6185 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;
6186 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;
6188 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6190 if cmd
= 'ammo' then
6192 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6193 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6194 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6195 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6196 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6197 g_Console_Add('player got some ammo');
6201 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6202 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6204 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6205 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6207 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6208 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6210 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6211 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6213 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6215 if cmd
= 'weapons' then
6217 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6218 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6219 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6220 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6221 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6222 plr
.GiveItem(ITEM_WEAPON_BFG
);
6223 g_Console_Add('player got weapons');
6227 if cmd
= 'keys' then
6229 plr
.GiveItem(ITEM_KEY_RED
);
6230 plr
.GiveItem(ITEM_KEY_GREEN
);
6231 plr
.GiveItem(ITEM_KEY_BLUE
);
6232 g_Console_Add('player got all keys');
6236 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6241 if cmd
= 'open' then
6243 g_Console_Add('player activated sesame');
6244 g_Triggers_OpenAll();
6251 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6255 if cmd
= 'noclip' then
6258 g_Console_Add('wall hardeness adjusted');
6262 if cmd
= 'notarget' then
6264 plr
.NoTarget
:= not plr
.NoTarget
;
6265 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6269 if cmd
= 'noreload' then
6271 plr
.NoReload
:= not plr
.NoReload
;
6272 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6276 if cmd
= 'speedy' then
6278 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6279 g_Console_Add('speed adjusted');
6283 if cmd
= 'jumpy' then
6285 VEL_JUMP
:= 30-VEL_JUMP
;
6286 g_Console_Add('jump height adjusted');
6290 if cmd
= 'automap' then
6292 gShowMap
:= not gShowMap
;
6293 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6297 if cmd
= 'aimline' then
6299 gAimLine
:= not gAimLine
;
6300 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6305 procedure GameCommands(P
: SSArray
);
6311 pl
: pTNetClient
= nil;
6319 cmd
:= LowerCase(P
[0]);
6321 if (cmd
= 'quit') or
6328 else if cmd
= 'pause' then
6330 if (g_ActiveWindow
= nil) then
6331 g_Game_Pause(not gPauseMain
);
6333 else if cmd
= 'endgame' then
6334 gExit
:= EXIT_SIMPLE
6335 else if cmd
= 'restart' then
6337 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6339 if g_Game_IsClient
then
6341 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6346 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6348 else if cmd
= 'kick' then
6350 if g_Game_IsServer
then
6352 if Length(P
) < 2 then
6354 g_Console_Add('kick <name>');
6359 g_Console_Add('kick <name>');
6363 if g_Game_IsNet
then
6364 pl
:= g_Net_Client_ByName(P
[1]);
6367 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6368 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6369 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6370 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6371 g_Net_Slist_ServerPlayerLeaves();
6372 end else if gPlayers
<> nil then
6373 for a
:= Low(gPlayers
) to High(gPlayers
) do
6374 if gPlayers
[a
] <> nil then
6375 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6377 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6378 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6380 gPlayers
[a
].Lives
:= 0;
6381 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6382 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6383 g_Player_Remove(gPlayers
[a
].UID
);
6384 g_Net_Slist_ServerPlayerLeaves();
6385 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6389 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6391 else if cmd
= 'kick_id' then
6393 if g_Game_IsServer
and g_Game_IsNet
then
6395 if Length(P
) < 2 then
6397 g_Console_Add('kick_id <client ID>');
6402 g_Console_Add('kick_id <client ID>');
6406 a
:= StrToIntDef(P
[1], 0);
6407 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6409 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6411 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6412 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6413 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6414 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6415 g_Net_Slist_ServerPlayerLeaves();
6419 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6421 else if cmd
= 'ban' then
6423 if g_Game_IsServer
and g_Game_IsNet
then
6425 if Length(P
) < 2 then
6427 g_Console_Add('ban <name>');
6432 g_Console_Add('ban <name>');
6436 pl
:= g_Net_Client_ByName(P
[1]);
6439 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6440 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6441 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6442 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6443 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6444 g_Net_Slist_ServerPlayerLeaves();
6446 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6448 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6450 else if cmd
= 'ban_id' then
6452 if g_Game_IsServer
and g_Game_IsNet
then
6454 if Length(P
) < 2 then
6456 g_Console_Add('ban_id <client ID>');
6461 g_Console_Add('ban_id <client ID>');
6465 a
:= StrToIntDef(P
[1], 0);
6466 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6467 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6469 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6470 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6471 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6472 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6473 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6474 g_Net_Slist_ServerPlayerLeaves();
6477 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6479 else if cmd
= 'permban' then
6481 if g_Game_IsServer
and g_Game_IsNet
then
6483 if Length(P
) < 2 then
6485 g_Console_Add('permban <name>');
6490 g_Console_Add('permban <name>');
6494 pl
:= g_Net_Client_ByName(P
[1]);
6497 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6498 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6499 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6500 g_Net_SaveBanList();
6501 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6502 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6503 g_Net_Slist_ServerPlayerLeaves();
6505 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6507 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6509 else if cmd
= 'permban_id' then
6511 if g_Game_IsServer
and g_Game_IsNet
then
6513 if Length(P
) < 2 then
6515 g_Console_Add('permban_id <client ID>');
6520 g_Console_Add('permban_id <client ID>');
6524 a
:= StrToIntDef(P
[1], 0);
6525 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6526 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6528 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6529 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6530 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6531 g_Net_SaveBanList();
6532 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6533 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6534 g_Net_Slist_ServerPlayerLeaves();
6537 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6539 else if cmd
= 'unban' then
6541 if g_Game_IsServer
and g_Game_IsNet
then
6543 if Length(P
) < 2 then
6545 g_Console_Add('unban <IP Address>');
6550 g_Console_Add('unban <IP Address>');
6554 if g_Net_UnbanHost(P
[1]) then
6556 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6557 g_Net_SaveBanList();
6559 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6561 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6563 else if cmd
= 'clientlist' then
6565 if g_Game_IsServer
and g_Game_IsNet
then
6568 if NetClients
<> nil then
6569 for a
:= Low(NetClients
) to High(NetClients
) do
6570 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6572 plr
:= g_Player_Get(NetClients
[a
].Player
);
6573 if plr
= nil then continue
;
6575 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6576 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6579 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6581 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6583 else if cmd
= 'connect' then
6585 if (NetMode
= NET_NONE
) then
6587 if Length(P
) < 2 then
6589 g_Console_Add('connect <IP> [port] [password]');
6594 g_Console_Add('connect <IP> [port] [password]');
6598 if Length(P
) > 2 then
6599 prt
:= StrToIntDef(P
[2], 25666)
6603 if Length(P
) > 3 then
6608 g_Game_StartClient(P
[1], prt
, pw
);
6611 else if cmd
= 'disconnect' then
6613 if (NetMode
= NET_CLIENT
) then
6616 else if cmd
= 'reconnect' then
6618 if (NetMode
= NET_SERVER
) then
6621 if (NetMode
= NET_CLIENT
) then
6624 gExit
:= EXIT_SIMPLE
;
6628 //TODO: Use last successful password to reconnect, instead of ''
6629 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6631 else if (cmd
= 'addbot') or
6632 (cmd
= 'bot_add') then
6634 if Length(P
) > 2 then
6635 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6636 else if Length(P
) > 1 then
6637 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6639 g_Bot_Add(TEAM_NONE
, 2);
6641 else if cmd
= 'bot_addlist' then
6643 if Length(P
) > 1 then
6645 if Length(P
) = 2 then
6646 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6647 else if Length(P
) = 3 then
6648 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6650 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6653 else if cmd
= 'bot_removeall' then
6655 else if cmd
= 'chat' then
6657 if g_Game_IsNet
then
6659 if Length(P
) > 1 then
6661 for a
:= 1 to High(P
) do
6662 chstr
:= chstr
+ P
[a
] + ' ';
6664 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6666 if Length(chstr
) < 1 then
6668 g_Console_Add('chat <text>');
6672 chstr
:= b_Text_Format(chstr
);
6673 if g_Game_IsClient
then
6674 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6676 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6679 g_Console_Add('chat <text>');
6681 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6683 else if cmd
= 'teamchat' then
6685 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6687 if Length(P
) > 1 then
6689 for a
:= 1 to High(P
) do
6690 chstr
:= chstr
+ P
[a
] + ' ';
6692 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6694 if Length(chstr
) < 1 then
6696 g_Console_Add('teamchat <text>');
6700 chstr
:= b_Text_Format(chstr
);
6701 if g_Game_IsClient
then
6702 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6704 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6705 gPlayer1Settings
.Team
);
6708 g_Console_Add('teamchat <text>');
6710 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6712 else if cmd
= 'game' then
6714 if gGameSettings
.GameType
<> GT_NONE
then
6716 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6719 if Length(P
) = 1 then
6721 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6724 // game not started yet, load fist map from some wad
6726 s
:= addWadExtension(P
[1]);
6727 found
:= e_FindResource(AllMapDirs
, s
);
6731 P
[1] := ExpandFileName(P
[1]);
6732 // if map not choosed then set first map
6733 if Length(P
) < 3 then
6736 P
[2] := g_Game_GetFirstMap(P
[1]);
6739 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6741 if g_Map_Exist(s
) then
6745 with gGameSettings
do
6747 GameMode
:= g_Game_TextToMode(gcGameMode
);
6748 if gSwitchGameMode
<> GM_NONE
then
6749 GameMode
:= gSwitchGameMode
;
6750 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6751 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6753 if Length(P
) >= 4 then
6754 b
:= StrToIntDef(P
[3], 1);
6755 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6756 GoalLimit
, MaxLives
, Options
, b
);
6761 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6763 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6765 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6767 else if cmd
= 'host' then
6769 if gGameSettings
.GameType
<> GT_NONE
then
6771 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6774 if Length(P
) < 4 then
6776 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6779 if not StrToIp(P
[1], listen
) then
6781 prt
:= StrToIntDef(P
[2], 25666);
6783 s
:= addWadExtension(P
[3]);
6784 found
:= e_FindResource(AllMapDirs
, s
);
6788 // get first map in wad, if not specified
6789 if Length(P
) < 5 then
6792 P
[4] := g_Game_GetFirstMap(P
[1]);
6794 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6795 if g_Map_Exist(s
) then
6799 with gGameSettings
do
6801 GameMode
:= g_Game_TextToMode(gcGameMode
);
6802 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6803 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6804 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6806 if Length(P
) >= 6 then
6807 b
:= StrToIntDef(P
[5], 0);
6808 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6814 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6816 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6821 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6824 else if cmd
= 'map' then
6826 if Length(P
) = 1 then
6828 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6830 g_Console_Add(cmd
+ ' <MAP>');
6831 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6835 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6840 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6842 if Length(P
) < 3 then
6844 // first param is map or wad
6845 s
:= UpperCase(P
[1]);
6846 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6848 gExitByTrigger
:= False;
6851 // already in game, finish current map
6853 gExit
:= EXIT_ENDLEVELCUSTOM
;
6857 // intermission, so change map immediately
6864 found
:= e_FindResource(AllMapDirs
, s
);
6866 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6869 // no such map, found wad
6872 P
[1] := ExpandFileName(pw
);
6873 P
[2] := g_Game_GetFirstMap(P
[1]);
6874 s
:= P
[1] + ':\' + P
[2];
6875 if g_Map_Exist(s
) then
6877 gExitByTrigger
:= False;
6880 // already in game, finish current map
6882 gExit
:= EXIT_ENDLEVELCUSTOM
6886 // intermission, so change map immediately
6893 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6895 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6900 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6906 s
:= addWadExtension(P
[1]);
6907 found
:= e_FindResource(AllMapDirs
, s
);
6911 P
[2] := UpperCase(P
[2]);
6912 s
:= P
[1] + ':\' + P
[2];
6913 if g_Map_Exist(s
) then
6915 gExitByTrigger
:= False;
6919 gExit
:= EXIT_ENDLEVELCUSTOM
6928 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6933 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6939 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6943 else if cmd
= 'nextmap' then
6945 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6947 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6952 if Length(P
) = 1 then
6954 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6956 g_Console_Add(cmd
+ ' <MAP>');
6957 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6962 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6968 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6970 if Length(P
) < 3 then
6972 // first param is map or wad
6973 s
:= UpperCase(P
[1]);
6974 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6977 gExitByTrigger
:= False;
6983 // no such map, found wad
6984 pw
:= addWadExtension(P
[1]);
6985 found
:= e_FindResource(MapDirs
, pw
);
6987 found
:= e_FindResource(WadDirs
, pw
);
6989 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6992 // map not specified, select first map
6994 P
[2] := g_Game_GetFirstMap(P
[1]);
6995 s
:= P
[1] + ':\' + P
[2];
6996 if g_Map_Exist(s
) then
6998 gExitByTrigger
:= False;
7005 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7007 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7012 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7018 // specified two params wad + map
7019 pw
:= addWadExtension(P
[1]);
7020 found
:= e_FindResource(MapDirs
, pw
);
7022 found
:= e_FindResource(MapDirs
, pw
);
7026 P
[2] := UpperCase(P
[2]);
7027 s
:= P
[1] + ':\' + P
[2];
7028 if g_Map_Exist(s
) then
7030 gExitByTrigger
:= False;
7036 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7041 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7047 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7052 if gNextMap
= '' then
7053 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7055 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7059 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7063 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7067 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7069 gExitByTrigger
:= False;
7070 // next map not specified, try to find trigger EXIT
7071 if (gNextMap
= '') and (gTriggers
<> nil) then
7073 for a
:= 0 to High(gTriggers
) do
7075 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7077 gExitByTrigger
:= True;
7078 //gNextMap := gTriggers[a].Data.MapName;
7079 gNextMap
:= gTriggers
[a
].tgcMap
;
7084 if gNextMap
= '' then
7085 gNextMap
:= g_Game_GetNextMap();
7086 if not isWadPath(gNextMap
) then
7087 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7090 if g_Map_Exist(s
) then
7091 gExit
:= EXIT_ENDLEVELCUSTOM
7093 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7097 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7101 else if (cmd
= 'event') then
7103 if (Length(P
) <= 1) then
7105 for a
:= 0 to High(gEvents
) do
7106 if gEvents
[a
].Command
= '' then
7107 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7109 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7112 if (Length(P
) = 2) then
7114 for a
:= 0 to High(gEvents
) do
7115 if gEvents
[a
].Name
= P
[1] then
7116 if gEvents
[a
].Command
= '' then
7117 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7119 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7122 for a
:= 0 to High(gEvents
) do
7123 if gEvents
[a
].Name
= P
[1] then
7125 gEvents
[a
].Command
:= '';
7126 for b
:= 2 to High(P
) do
7127 if Pos(' ', P
[b
]) = 0 then
7128 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7130 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7131 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7135 else if cmd
= 'suicide' then
7139 if g_Game_IsClient
then
7140 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7143 if gPlayer1
<> nil then
7144 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7145 if gPlayer2
<> nil then
7146 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7150 else if cmd
= 'screenshot' then
7154 else if cmd
= 'weapon' then
7156 if Length(p
) = 2 then
7158 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7159 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7160 gSelectWeapon
[0, a
] := True
7163 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7165 if Length(p
) = 2 then
7167 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7168 b
:= ord(cmd
[2]) - ord('1');
7169 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7170 gSelectWeapon
[b
, a
] := True
7173 // Êîìàíäû Ñâîåé èãðû:
7174 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7176 if cmd
= 'bot_addred' then
7178 if Length(P
) > 1 then
7179 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7181 g_Bot_Add(TEAM_RED
, 2);
7183 else if cmd
= 'bot_addblue' then
7185 if Length(P
) > 1 then
7186 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7188 g_Bot_Add(TEAM_BLUE
, 2);
7190 else if cmd
= 'spectate' then
7196 else if cmd
= 'say' then
7198 if g_Game_IsServer
and g_Game_IsNet
then
7200 if Length(P
) > 1 then
7203 for a
:= 1 to High(P
) do
7204 chstr
:= chstr
+ P
[a
] + ' ';
7206 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7208 if Length(chstr
) < 1 then
7210 g_Console_Add('say <text>');
7214 chstr
:= b_Text_Format(chstr
);
7215 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7217 else g_Console_Add('say <text>');
7219 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7221 else if cmd
= 'tell' then
7223 if g_Game_IsServer
and g_Game_IsNet
then
7225 if (Length(P
) > 2) and (P
[1] <> '') then
7228 for a
:= 2 to High(P
) do
7229 chstr
:= chstr
+ P
[a
] + ' ';
7231 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7233 if Length(chstr
) < 1 then
7235 g_Console_Add('tell <playername> <text>');
7239 pl
:= g_Net_Client_ByName(P
[1]);
7241 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7243 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7245 else g_Console_Add('tell <playername> <text>');
7247 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7249 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7251 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7253 // Äîïîëíèòåëüíîå âðåìÿ:
7254 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7256 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7257 [gGameSettings
.TimeLimit
div 3600,
7258 (gGameSettings
.TimeLimit
div 60) mod 60,
7259 gGameSettings
.TimeLimit
mod 60]));
7260 if g_Game_IsNet
then MH_SEND_GameSettings
;
7262 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7264 if (Length(P
) <= 1) then
7265 g_Console_Add('rcon_password <password>')
7267 MC_SEND_RCONPassword(P
[1]);
7269 else if cmd
= 'rcon' then
7271 if g_Game_IsClient
then
7273 if Length(P
) > 1 then
7276 for a
:= 1 to High(P
) do
7277 chstr
:= chstr
+ P
[a
] + ' ';
7279 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7281 if Length(chstr
) < 1 then
7283 g_Console_Add('rcon <command>');
7287 MC_SEND_RCONCommand(chstr
);
7289 else g_Console_Add('rcon <command>');
7292 else if cmd
= 'ready' then
7294 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7295 gLMSRespawnTime
:= gTime
+ 100;
7297 else if (cmd
= 'callvote') and g_Game_IsNet
then
7299 if Length(P
) > 1 then
7302 for a
:= 1 to High(P
) do begin
7303 if a
> 1 then chstr
:= chstr
+ ' ';
7304 chstr
:= chstr
+ P
[a
];
7307 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7309 if Length(chstr
) < 1 then
7311 g_Console_Add('callvote <command>');
7315 if g_Game_IsClient
then
7316 MC_SEND_Vote(True, chstr
)
7318 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7319 g_Console_Process('vote', True);
7322 g_Console_Add('callvote <command>');
7324 else if (cmd
= 'vote') and g_Game_IsNet
then
7326 if g_Game_IsClient
then
7328 else if gVoteInProgress
then
7330 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7331 a
:= Floor((NetClientCount
+1)/2.0) + 1
7333 a
:= Floor(NetClientCount
/2.0) + 1;
7338 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7339 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7345 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7346 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7354 procedure g_TakeScreenShot(Filename
: string = '');
7355 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7357 if e_NoGraphics
then Exit
;
7359 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7361 if Filename
= '' then
7364 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7365 Filename
:= 'screenshot-' + date
;
7368 name
:= e_CatPath(dir
, Filename
+ '.png');
7369 s
:= createDiskFile(name
);
7371 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7373 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7375 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7380 g_Console_Add('oh shit, i can''t create screenshot!')
7384 procedure g_Game_InGameMenu(Show
: Boolean);
7386 if (g_ActiveWindow
= nil) and Show
then
7388 if gGameSettings
.GameType
= GT_SINGLE
then
7389 g_GUI_ShowWindow('GameSingleMenu')
7392 if g_Game_IsClient
then
7393 g_GUI_ShowWindow('GameClientMenu')
7395 if g_Game_IsNet
then
7396 g_GUI_ShowWindow('GameServerMenu')
7398 g_GUI_ShowWindow('GameCustomMenu');
7400 g_Sound_PlayEx('MENU_OPEN');
7402 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7403 if (not g_Game_IsNet
) then
7407 if (g_ActiveWindow
<> nil) and (not Show
) then
7409 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7410 if (not g_Game_IsNet
) then
7411 g_Game_Pause(False);
7415 procedure g_Game_Pause (Enable
: Boolean);
7419 if not gGameOn
then exit
;
7421 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7424 gPauseMain
:= Enable
;
7426 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7429 procedure g_Game_HolmesPause (Enable
: Boolean);
7433 if not gGameOn
then exit
;
7434 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7437 gPauseHolmes
:= Enable
;
7439 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7442 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7447 if gTriggers
<> nil then
7448 for i
:= 0 to High(gTriggers
) do
7449 with gTriggers
[i
] do
7450 if (TriggerType
= TRIGGER_SOUND
) and
7452 Sound
.IsPlaying() then
7454 Sound
.Pause(Enable
);
7458 if gPlayers
<> nil then
7459 for i
:= 0 to High(gPlayers
) do
7460 if gPlayers
[i
] <> nil then
7461 gPlayers
[i
].PauseSounds(Enable
);
7464 if gMusic
<> nil then
7465 gMusic
.Pause(Enable
);
7468 procedure g_Game_StopAllSounds(all
: Boolean);
7472 if gTriggers
<> nil then
7473 for i
:= 0 to High(gTriggers
) do
7474 with gTriggers
[i
] do
7475 if (TriggerType
= TRIGGER_SOUND
) and
7479 if gMusic
<> nil then
7486 procedure g_Game_UpdateTriggerSounds
;
7489 if gTriggers
<> nil then
7490 for i
:= 0 to High(gTriggers
) do
7491 with gTriggers
[i
] do
7492 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7493 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7496 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7499 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7504 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7509 if gSpectMode
<> SPECT_PLAYERS
then
7511 if gSpectPID1
= UID
then
7516 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7523 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7528 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7533 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7538 if gSpectMode
<> SPECT_PLAYERS
then
7540 Pl
:= g_Player_Get(gSpectPID1
);
7541 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7546 if gSpectViewTwo
then
7548 Pl
:= g_Player_Get(gSpectPID2
);
7549 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7557 procedure g_Game_Message(Msg
: string; Time
: Word);
7559 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7560 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7561 MessageTime
:= Time
;
7564 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7566 punct
: Array[0..13] of String =
7567 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7573 function IsPunctuation(S
: String): Boolean;
7578 if Length(S
) <> 1 then
7580 for i
:= Low(punct
) to High(punct
) do
7581 if S
= punct
[i
] then
7587 function FilterPunctuation(S
: String): String;
7591 for i
:= Low(punct
) to High(punct
) do
7592 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7598 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7600 // remove player name
7601 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7602 // for FullWord check
7603 Text := toLowerCase1251(' ' + Text + ' ');
7604 fpText
:= FilterPunctuation(Text);
7606 for i
:= 0 to Length(gChatSounds
) - 1 do
7609 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7611 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7612 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7614 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7620 gChatSounds
[i
].Sound
.Play();
7626 g_Sound_PlayEx('SOUND_GAME_RADIO');
7629 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7638 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7642 if goodsnd
[a
].IsPlaying() then
7645 goodsnd
[Random(4)].Play();
7648 procedure g_Game_Announce_KillCombo(Param
: Integer);
7655 UID
:= Param
and $FFFF;
7660 Pl
:= g_Player_Get(UID
);
7669 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7673 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7677 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7681 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7689 if not g_Game_IsWatchedPlayer(UID
) then
7692 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7696 if killsnd
[n
].IsPlaying() then
7701 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7710 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7714 if hahasnd
[a
].IsPlaying() then
7717 hahasnd
[Random(3)].Play();
7720 procedure g_Game_StartVote(Command
, Initiator
: string);
7724 if not gVotesEnabled
then Exit
;
7725 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7726 if gVoteInProgress
or gVotePassed
then
7728 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7729 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7732 gVoteInProgress
:= True;
7733 gVotePassed
:= False;
7734 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7737 gVoteCommand
:= Command
;
7739 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7740 Need
:= Floor((NetClientCount
+1)/2.0)+1
7742 Need
:= Floor(NetClientCount
/2.0)+1;
7743 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7744 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7747 procedure g_Game_CheckVote
;
7751 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7752 if not gVoteInProgress
then Exit
;
7754 if (gTime
>= gVoteTimer
) then
7756 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7757 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7759 Need
:= Floor(NetClientCount
/2.0) + 1;
7760 if gVoteCount
>= Need
then
7762 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7763 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7764 gVotePassed
:= True;
7765 gVoteCmdTimer
:= gTime
+ 5000;
7769 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7770 MH_SEND_VoteEvent(NET_VE_FAILED
);
7772 if NetClients
<> nil then
7773 for I
:= Low(NetClients
) to High(NetClients
) do
7774 if NetClients
[i
].Used
then
7775 NetClients
[i
].Voted
:= False;
7776 gVoteInProgress
:= False;
7782 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7783 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7785 Need
:= Floor(NetClientCount
/2.0) + 1;
7786 if gVoteCount
>= Need
then
7788 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7789 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7790 gVoteInProgress
:= False;
7791 gVotePassed
:= True;
7792 gVoteCmdTimer
:= gTime
+ 5000;
7795 if NetClients
<> nil then
7796 for I
:= Low(NetClients
) to High(NetClients
) do
7797 if NetClients
[i
].Used
then
7798 NetClients
[i
].Voted
:= False;
7803 procedure g_Game_LoadMapList(FileName
: string);
7811 if not FileExists(FileName
) then Exit
;
7813 AssignFile(ListFile
, FileName
);
7815 while not EOF(ListFile
) do
7817 ReadLn(ListFile
, s
);
7820 if s
= '' then Continue
;
7822 SetLength(MapList
, Length(MapList
)+1);
7823 MapList
[High(MapList
)] := s
;
7825 CloseFile(ListFile
);
7828 procedure g_Game_SetDebugMode();
7831 // ×èòû (äàæå â ñâîåé èãðå):
7835 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7839 if Length(LoadingStat
.Msgs
) = 0 then
7845 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7846 if NextMsg
= Length(Msgs
) then
7848 for i
:= 0 to High(Msgs
)-1 do
7849 Msgs
[i
] := Msgs
[i
+1];
7857 Msgs
[NextMsg
-1] := Text;
7861 PBarWasHere
:= false;
7864 g_ActiveWindow
:= nil;
7866 ProcessLoading(true);
7869 procedure g_Game_StepLoading(Value
: Integer = -1);
7880 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7888 procedure g_Game_ClearLoading();
7897 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7898 if len
< 1 then len
:= 1;
7899 SetLength(Msgs
, len
);
7900 for len
:= Low(Msgs
) to High(Msgs
) do
7903 PBarWasHere
:= false;
7907 procedure Parse_Params(var pars
: TParamStrValues
);
7914 while i
<= ParamCount
do
7917 if (s
[1] = '-') and (Length(s
) > 1) then
7919 if (s
[2] = '-') and (Length(s
) > 2) then
7920 begin // Îäèíî÷íûé ïàðàìåòð
7921 SetLength(pars
, Length(pars
) + 1);
7922 with pars
[High(pars
)] do
7924 Name
:= LowerCase(s
);
7929 if (i
< ParamCount
) then
7930 begin // Ïàðàìåòð ñî çíà÷åíèåì
7932 SetLength(pars
, Length(pars
) + 1);
7933 with pars
[High(pars
)] do
7935 Name
:= LowerCase(s
);
7936 Value
:= LowerCase(ParamStr(i
));
7945 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7950 for i
:= 0 to High(pars
) do
7951 if pars
[i
].Name
= aName
then
7953 Result
:= pars
[i
].Value
;
7958 procedure g_Game_Process_Params();
7960 pars
: TParamStrValues
;
7963 LimT
, LimS
: Integer;
7974 s
:= Find_Param_Value(pars
, '--debug');
7977 g_Game_SetDebugMode();
7978 s
:= Find_Param_Value(pars
, '--netdump');
7983 // Connect when game loads
7984 ip
:= Find_Param_Value(pars
, '-connect');
7988 s
:= Find_Param_Value(pars
, '-port');
7989 if (s
= '') or not TryStrToInt(s
, Port
) then
7992 s
:= Find_Param_Value(pars
, '-pw');
7994 g_Game_StartClient(ip
, Port
, s
);
7998 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8001 gDefaultMegawadStart
:= s
;
8004 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8005 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8007 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8010 // Start map when game loads:
8011 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8012 if isWadPath(map
) then
8015 s
:= Find_Param_Value(pars
, '-gm');
8016 GMode
:= g_Game_TextToMode(s
);
8017 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8018 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8021 s
:= Find_Param_Value(pars
, '-limt');
8022 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8028 s
:= Find_Param_Value(pars
, '-lims');
8029 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8035 s
:= Find_Param_Value(pars
, '-lives');
8036 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8042 s
:= Find_Param_Value(pars
, '-opt');
8044 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
8046 Opt
:= StrToIntDef(s
, 0);
8048 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
8051 s
:= Find_Param_Value(pars
, '--close');
8055 // Override map to test:
8056 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8059 if e_IsValidResourceName(s
) then
8060 e_FindResource(AllMapDirs
, s
);
8061 gTestMap
:= ExpandFileName(s
);
8064 // Delete test map after play:
8065 s
:= Find_Param_Value(pars
, '--testdelete');
8068 //gMapToDelete := MapsDir + map;
8069 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8073 // Delete temporary WAD after play:
8074 s
:= Find_Param_Value(pars
, '--tempdelete');
8075 if (s
<> '') and (gTestMap
<> '') then
8077 gMapToDelete
:= gTestMap
;
8078 gTempDelete
:= True;
8081 // Number of players:
8082 s
:= Find_Param_Value(pars
, '-pl');
8084 n
:= DEFAULT_PLAYERS
8086 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8089 s
:= Find_Param_Value(pars
, '-port');
8090 if (s
= '') or not TryStrToInt(s
, Port
) then
8091 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8093 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8096 // Execute script when game loads:
8097 s
:= Find_Param_Value(pars
, '-exec');
8100 // if not isWadPath(s) then
8101 // s := GameDir + '/' + s;
8106 if IOResult
<> 0 then
8108 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8109 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8113 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8114 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8119 if IOResult
<> 0 then
8121 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8122 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8126 if Pos('#', s
) <> 1 then // script comment
8127 g_Console_Process(s
, True);
8138 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8139 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8140 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8141 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8143 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8144 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8145 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8146 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8148 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8149 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8151 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8152 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8154 {$IFDEF ENABLE_HOLMES}
8155 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8158 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8160 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8162 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8163 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8165 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8166 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8168 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8169 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');