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
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
;
1074 if gSaveStats
then SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1077 StatShotDone
:= False;
1080 g_Game_ExecuteEvent('onmapend');
1081 if not g_Game_IsClient
then g_Player_ResetReady
;
1082 gInterReadyCount
:= 0;
1084 // Çàòóõàþùèé ýêðàí:
1085 EndingGameCounter
:= 255;
1086 gState
:= STATE_FOLD
;
1088 if gDefInterTime
< 0 then
1089 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1091 gInterEndTime
:= gDefInterTime
* 1000;
1094 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1096 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1097 SingleStat
.GameTime
:= gTime
;
1098 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1099 SingleStat
.TotalSecrets
:= gSecretsCount
;
1100 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1101 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1102 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1103 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1104 if SingleStat
.TwoPlayers
then
1106 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1107 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1110 g_Game_ExecuteEvent('onmapend');
1113 if gNextMap
<> '' then
1115 gMusic
.SetByName('MUSIC_INTERMUS');
1117 gState
:= STATE_INTERSINGLE
;
1120 g_Game_ExecuteEvent('oninter');
1122 else // Áîëüøå íåò êàðò
1124 // Çàòóõàþùèé ýêðàí:
1125 EndingGameCounter
:= 255;
1126 gState
:= STATE_FOLD
;
1131 // Îêîí÷àíèå îáðàáîòàíî:
1132 if gExit
<> EXIT_QUIT
then
1136 procedure drawTime(X
, Y
: Integer); inline;
1138 e_TextureFontPrint(x
, y
,
1139 Format('%d:%.2d:%.2d', [
1140 gTime
div 1000 div 3600,
1141 (gTime
div 1000 div 60) mod 60,
1142 gTime
div 1000 mod 60
1147 procedure DrawStat();
1149 pc
, x
, y
, w
, h
: Integer;
1150 w1
, w2
, w3
, w4
: Integer;
1152 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1155 stat
: TPlayerStatArray
;
1162 pc
:= g_Player_GetCount
;
1163 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1165 w
:= gScreenWidth
-(gScreenWidth
div 5);
1166 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1169 h
:= 40+ch
*5+(ch
+8)*pc
;
1170 x
:= (gScreenWidth
div 2)-(w
div 2);
1171 y
:= (gScreenHeight
div 2)-(h
div 2);
1173 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1174 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1176 drawTime(x
+w
-78, y
+8);
1178 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1179 map
:= g_ExtractFileName(gMapInfo
.Map
);
1180 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1182 case gGameSettings
.GameMode
of
1185 if gGameSettings
.MaxLives
= 0 then
1186 s1
:= _lc
[I_GAME_DM
]
1188 s1
:= _lc
[I_GAME_LMS
];
1189 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1190 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1195 if gGameSettings
.MaxLives
= 0 then
1196 s1
:= _lc
[I_GAME_TDM
]
1198 s1
:= _lc
[I_GAME_TLMS
];
1199 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1200 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1205 s1
:= _lc
[I_GAME_CTF
];
1206 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1207 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1212 if gGameSettings
.MaxLives
= 0 then
1213 s1
:= _lc
[I_GAME_COOP
]
1215 s1
:= _lc
[I_GAME_SURV
];
1216 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1217 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1228 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1230 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1232 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1234 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1235 gStdFont
, 200, 200, 200, 1);
1237 if NetMode
= NET_SERVER
then
1238 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1240 if NetMode
= NET_CLIENT
then
1241 e_TextureFontPrintEx(x
+8, y
+ 8,
1242 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1246 stat
:= g_Player_GetStats();
1249 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1250 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1252 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1254 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1258 for a
:= TEAM_RED
to TEAM_BLUE
do
1260 if a
= TEAM_RED
then
1262 s1
:= _lc
[I_GAME_TEAM_RED
];
1269 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1275 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1276 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1277 gStdFont
, r
, g
, b
, 1);
1279 _y
:= _y
+ch
+(ch
div 4);
1280 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1281 _y
:= _y
+(ch
div 4);
1283 for aa
:= 0 to High(stat
) do
1284 if stat
[aa
].Team
= a
then
1300 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1302 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1304 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1306 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1313 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1316 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1317 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1318 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1319 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1322 for aa
:= 0 to High(stat
) do
1336 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1337 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1339 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1341 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1343 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1345 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1351 procedure g_Game_Init();
1354 knownFiles
: array of AnsiString = nil;
1356 wext
, s
: AnsiString;
1361 gTempDelete
:= False;
1363 sfsGCDisable(); // temporary disable removing of temporary volumes
1366 TEXTUREFILTER
:= GL_LINEAR
;
1367 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1368 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1369 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1370 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1371 TEXTUREFILTER
:= GL_NEAREST
;
1373 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1374 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1375 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1377 g_Game_ClearLoading();
1378 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1379 g_Game_SetLoadingText('', 0, False);
1381 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1384 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1385 g_PlayerModel_LoadData();
1387 // load models from all possible wad types, in all known directories
1388 // this does a loosy job (linear search, ooph!), but meh
1389 for wext
in wadExtensions
do
1391 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1393 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1397 for s
in knownFiles
do
1399 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1407 SetLength(knownFiles
, length(knownFiles
)+1);
1408 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1410 until (FindNext(SR
) <> 0);
1416 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1418 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
);
1419 for s
in knownFiles
do
1421 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1425 gPauseMain
:= false;
1426 gPauseHolmes
:= false;
1429 {e_MouseInfo.Accel := 1.0;}
1431 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1434 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1435 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1436 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1437 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1438 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1441 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1445 gMusic
:= TMusic
.Create();
1446 gMusic
.SetByName('MUSIC_MENU');
1449 gGameSettings
.WarmupTime
:= 30;
1451 gState
:= STATE_MENU
;
1453 SetLength(gEvents
, 6);
1454 gEvents
[0].Name
:= 'ongamestart';
1455 gEvents
[1].Name
:= 'ongameend';
1456 gEvents
[2].Name
:= 'onmapstart';
1457 gEvents
[3].Name
:= 'onmapend';
1458 gEvents
[4].Name
:= 'oninter';
1459 gEvents
[5].Name
:= 'onwadend';
1461 sfsGCEnable(); // enable releasing unused volumes
1465 procedure g_Game_Free(freeTextures
: Boolean=true);
1467 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1468 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1470 g_Map_Free(freeTextures
);
1472 g_Player_RemoveAllCorpses();
1474 gGameSettings
.GameType
:= GT_NONE
;
1475 if gGameSettings
.GameMode
= GM_SINGLE
then
1476 gGameSettings
.GameMode
:= GM_DM
;
1477 gSwitchGameMode
:= gGameSettings
.GameMode
;
1480 gExitByTrigger
:= False;
1483 function IsActivePlayer(p
: TPlayer
): Boolean;
1488 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1491 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1498 if gPlayers
= nil then
1500 for a
:= Low(gPlayers
) to High(gPlayers
) do
1501 if IsActivePlayer(gPlayers
[a
]) then
1503 if gPlayers
[a
].UID
<> ID
then
1505 Result
:= gPlayers
[a
];
1510 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1516 if gPlayers
= nil then
1520 for a
:= Low(gPlayers
) to High(gPlayers
) do
1521 if IsActivePlayer(gPlayers
[a
]) then
1523 SetLength(ids
, Length(ids
) + 1);
1524 ids
[High(ids
)] := gPlayers
[a
].UID
;
1525 if gPlayers
[a
].UID
= Skip
then
1528 if Length(ids
) = 0 then
1533 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1536 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1542 if gPlayers
= nil then
1546 for a
:= Low(gPlayers
) to High(gPlayers
) do
1547 if IsActivePlayer(gPlayers
[a
]) then
1549 SetLength(ids
, Length(ids
) + 1);
1550 ids
[High(ids
)] := gPlayers
[a
].UID
;
1551 if gPlayers
[a
].UID
= Skip
then
1554 if Length(ids
) = 0 then
1557 Result
:= ids
[Length(ids
) - 1]
1559 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1562 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1568 if gPlayers
= nil then
1572 for a
:= Low(gPlayers
) to High(gPlayers
) do
1573 if IsActivePlayer(gPlayers
[a
]) then
1575 SetLength(ids
, Length(ids
) + 1);
1576 ids
[High(ids
)] := gPlayers
[a
].UID
;
1577 if gPlayers
[a
].UID
= Skip
then
1580 if Length(ids
) = 0 then
1582 if Length(ids
) = 1 then
1587 Result
:= ids
[Random(Length(ids
))];
1589 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1591 Result
:= ids
[Random(Length(ids
))];
1596 function GetRandomSpectMode(Current
: Byte): Byte;
1603 0: Result
:= SPECT_STATS
;
1604 1: Result
:= SPECT_MAPVIEW
;
1605 2: Result
:= SPECT_MAPVIEW
;
1606 3: Result
:= SPECT_PLAYERS
;
1607 4: Result
:= SPECT_PLAYERS
;
1608 5: Result
:= SPECT_PLAYERS
;
1609 6: Result
:= SPECT_PLAYERS
;
1611 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1615 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1621 if (plr
= nil) then exit
;
1622 if (p
= 2) then time
:= 1000 else time
:= 1;
1623 strafeDir
:= MoveButton
shr 4;
1624 MoveButton
:= MoveButton
and $0F;
1626 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1627 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1628 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1629 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1630 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1631 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1633 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1634 if MoveButton
= 1 then
1635 plr
.PressKey(KEY_LEFT
, time
)
1636 else if MoveButton
= 2 then
1637 plr
.PressKey(KEY_RIGHT
, time
);
1639 // if we have "strafe" key, turn off old strafe mechanics
1640 if gPlayerAction
[p
, ACTION_STRAFE
] then
1642 // new strafe mechanics
1643 if (strafeDir
= 0) then
1644 strafeDir
:= MoveButton
; // start strafing
1645 // now set direction according to strafe (reversed)
1646 if (strafeDir
= 2) then
1647 plr
.SetDirection(TDirection
.D_LEFT
)
1648 else if (strafeDir
= 1) then
1649 plr
.SetDirection(TDirection
.D_RIGHT
)
1653 strafeDir
:= 0; // not strafing anymore
1654 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1655 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1656 plr
.SetDirection(TDirection
.D_LEFT
)
1657 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1658 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1659 plr
.SetDirection(TDirection
.D_RIGHT
)
1660 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1661 else if MoveButton
<> 0 then
1662 plr
.SetDirection(TDirection(MoveButton
-1))
1665 // fix movebutton state
1666 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1668 // Îñòàëüíûå êëàâèøè:
1669 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1670 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1671 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1672 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1673 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1674 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1675 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1677 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1678 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1680 for i
:= WP_FIRST
to WP_LAST
do
1682 if gSelectWeapon
[p
, i
] then
1684 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1685 gSelectWeapon
[p
, i
] := False
1689 // HACK: add dynlight here
1690 if gwin_k8_enable_light_experiments
then
1692 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1694 g_playerLight
:= true;
1696 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1698 g_playerLight
:= false;
1702 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1705 // HACK: don't have a "key was pressed" function
1706 procedure InterReady();
1708 if InterReadyTime
> gTime
then Exit
;
1709 InterReadyTime
:= gTime
+ 3000;
1710 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1713 procedure g_Game_Update();
1715 Msg
: g_gui
.TMessage
;
1721 function sendMonsPos (mon
: TMonster
): Boolean;
1723 result
:= false; // don't stop
1724 // this will also reset "need-send" flag
1725 if mon
.gncNeedSend
then
1727 MH_SEND_MonsterPos(mon
.UID
);
1729 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1731 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1733 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1735 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1739 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1741 result
:= false; // don't stop
1742 // this will also reset "need-send" flag
1743 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1747 reliableUpdate
: Boolean;
1752 // Ïîðà âûêëþ÷àòü èãðó:
1753 if gExit
= EXIT_QUIT
then
1755 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1759 if gExit
= EXIT_QUIT
then
1763 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1764 // no need to, as we'll do it in event handler
1766 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1769 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1771 gExit
:= EXIT_SIMPLE
;
1776 // process master server communications
1777 g_Net_Slist_Pulse();
1780 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1781 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1782 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1783 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1785 if g_Game_IsNet
and g_Game_IsServer
then
1787 gInterTime
:= gInterTime
+ GAME_TICK
;
1788 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1789 if a
<> gServInterTime
then
1791 gServInterTime
:= a
;
1792 MH_SEND_TimeSync(gServInterTime
);
1796 if (not g_Game_IsClient
) and
1800 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1801 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1802 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1803 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1805 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1806 and (g_ActiveWindow
= nil)
1808 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1811 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1812 g_Game_StopAllSounds(True);
1814 if gMapOnce
then // Ýòî áûë òåñò
1815 gExit
:= EXIT_SIMPLE
1817 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1818 g_Game_ChangeMap(gNextMap
)
1819 else // Ñëåäóþùåé êàðòû íåò
1821 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1823 // Âûõîä â ãëàâíîå ìåíþ:
1825 g_GUI_ShowWindow('MainMenu');
1826 gMusic
.SetByName('MUSIC_MENU');
1828 gState
:= STATE_MENU
;
1831 // Ôèíàëüíàÿ êàðòèíêà:
1832 g_Game_ExecuteEvent('onwadend');
1834 if not gMusic
.SetByName('MUSIC_endmus') then
1835 gMusic
.SetByName('MUSIC_STDENDMUS');
1837 gState
:= STATE_ENDPIC
;
1839 g_Game_ExecuteEvent('ongameend');
1844 else if g_Game_IsClient
and
1847 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1848 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1849 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1850 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1852 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1853 and (g_ActiveWindow
= nil)
1861 if gState
= STATE_INTERTEXT
then
1862 if InterText
.counter
> 0 then
1863 InterText
.counter
:= InterText
.counter
- 1;
1866 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1868 if EndingGameCounter
= 0 then
1870 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1871 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1873 InterReadyTime
:= -1;
1874 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1876 g_Game_ExecuteEvent('onwadend');
1877 if not gMusic
.SetByName('MUSIC_endmus') then
1878 gMusic
.SetByName('MUSIC_STDENDMUS');
1881 gMusic
.SetByName('MUSIC_ROUNDMUS');
1884 gState
:= STATE_INTERCUSTOM
;
1887 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1889 gMusic
.SetByName('MUSIC_INTERMUS');
1891 gState
:= STATE_INTERSINGLE
;
1894 g_Game_ExecuteEvent('oninter');
1897 DecMin(EndingGameCounter
, 6, 0);
1900 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1902 if gMapOnce
then // Ýòî áûë òåñò
1904 gExit
:= EXIT_SIMPLE
;
1910 g_Serverlist_Control(slCurrent
, slTable
);
1913 // Ñòàòèñòèêà ïî Tab:
1915 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1918 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1920 // Âðåìÿ += 28 ìèëëèñåêóíä:
1921 gTime
:= gTime
+ GAME_TICK
;
1923 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1924 if MessageTime
= 0 then
1926 if MessageTime
> 0 then
1927 MessageTime
:= MessageTime
- 1;
1929 if (g_Game_IsServer
) then
1931 // Áûë çàäàí ëèìèò âðåìåíè:
1932 if (gGameSettings
.TimeLimit
> 0) then
1933 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1934 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1939 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1940 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1941 g_Game_RestartRound(gLMSSoftSpawn
);
1943 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1944 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1946 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1948 g_Console_Process(gVoteCommand
);
1950 gVotePassed
:= False;
1953 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1954 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1955 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1956 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1957 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1959 // Áûë çàäàí ëèìèò ïîáåä:
1960 if (gGameSettings
.GoalLimit
> 0) then
1964 if gGameSettings
.GameMode
= GM_DM
then
1965 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1966 for i
:= 0 to High(gPlayers
) do
1967 if gPlayers
[i
] <> nil then
1968 if gPlayers
[i
].Frags
> b
then
1969 b
:= gPlayers
[i
].Frags
;
1972 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1973 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1974 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1977 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1978 if b
>= gGameSettings
.GoalLimit
then
1985 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1986 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1987 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1988 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1990 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1991 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1992 end // if not console
1995 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1997 // process weapon switch queue
2001 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2002 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2004 if not gSpectKeyPress
then
2006 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2008 // switch spect mode
2010 SPECT_NONE
: ; // not spectator
2012 SPECT_MAPVIEW
: Inc(gSpectMode
);
2013 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2015 gSpectKeyPress
:= True;
2017 if (gSpectMode
= SPECT_MAPVIEW
)
2018 and (not gSpectAuto
) then
2020 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2021 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2022 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2023 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2024 if gPlayerAction
[0, ACTION_LOOKUP
] then
2025 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2026 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2027 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2028 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2031 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2032 gSpectKeyPress
:= True;
2034 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2037 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2038 gSpectKeyPress
:= True;
2041 if (gSpectMode
= SPECT_PLAYERS
)
2042 and (not gSpectAuto
) then
2044 if gPlayerAction
[0, ACTION_LOOKUP
] then
2047 gSpectViewTwo
:= True;
2048 gSpectKeyPress
:= True;
2050 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2052 // remove second view
2053 gSpectViewTwo
:= False;
2054 gSpectKeyPress
:= True;
2056 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2058 // prev player (view 1)
2059 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2060 gSpectKeyPress
:= True;
2062 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2064 // next player (view 1)
2065 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2066 gSpectKeyPress
:= True;
2068 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2070 // prev player (view 2)
2071 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2072 gSpectKeyPress
:= True;
2074 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2076 // next player (view 2)
2077 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2078 gSpectKeyPress
:= True;
2081 if gPlayerAction
[0, ACTION_ATTACK
] then
2083 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2086 gSpectAutoNext
:= 0;
2087 gSpectViewTwo
:= False;
2088 gSpectKeyPress
:= True;
2093 gSpectMode
:= SPECT_STATS
;
2094 gSpectAuto
:= False;
2095 gSpectKeyPress
:= True;
2100 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2101 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2102 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2103 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2104 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2105 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2106 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2107 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2108 gSpectKeyPress
:= False;
2112 if gSpectMode
= SPECT_MAPVIEW
then
2114 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2116 gSpectAutoNext
:= gTime
2119 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2121 gSpectAutoNext
:= gTime
2125 if gSpectAutoNext
<= gTime
then
2127 if gSpectAutoNext
> 0 then
2129 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2133 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2134 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2135 gSpectAutoStepX
:= Random(9) - 4;
2136 gSpectAutoStepY
:= Random(9) - 4;
2137 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2138 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2139 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2140 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2141 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2142 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2146 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2151 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2152 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2153 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2159 // Îáíîâëÿåì âñå îñòàëüíîå:
2162 g_Triggers_Update();
2164 g_Monsters_Update();
2166 g_Player_UpdateAll();
2167 g_Player_UpdatePhysicalObjects();
2169 // server: send newly spawned monsters unconditionally
2170 if (gGameSettings
.GameType
= GT_SERVER
) then
2172 if (Length(gMonstersSpawned
) > 0) then
2174 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2175 SetLength(gMonstersSpawned
, 0);
2179 if (gSoundTriggerTime
> 8) then
2181 g_Game_UpdateTriggerSounds();
2182 gSoundTriggerTime
:= 0;
2186 Inc(gSoundTriggerTime
);
2189 if (NetMode
= NET_SERVER
) then
2191 Inc(NetTimeToUpdate
);
2192 Inc(NetTimeToReliable
);
2194 // send monster updates
2195 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2197 // send all monsters (periodic sync)
2198 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2200 for I
:= 0 to High(gPlayers
) do
2202 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2205 g_Mons_ForEach(sendMonsPos
);
2207 if reliableUpdate
then
2209 NetTimeToReliable
:= 0;
2210 NetTimeToUpdate
:= NetUpdateRate
;
2214 NetTimeToUpdate
:= 0;
2219 // send only mosters with some unexpected changes
2220 g_Mons_ForEach(sendMonsPosUnexpected
);
2223 // send unexpected platform changes
2224 g_Map_NetSendInterestingPanels();
2226 g_Net_Slist_ServerUpdate();
2228 if NetUseMaster then
2230 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2232 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2234 NetTimeToMaster := gTime + NetMasterRate;
2239 else if (NetMode
= NET_CLIENT
) then
2241 MC_SEND_PlayerPos();
2243 end; // if gameOn ...
2245 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2246 if g_ActiveWindow
<> nil then
2248 w
:= e_GetFirstKeyPressed();
2250 if (w
<> IK_INVALID
) then
2252 Msg
.Msg
:= MESSAGE_DIKEY
;
2254 g_ActiveWindow
.OnMessage(Msg
);
2257 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2258 if g_ActiveWindow
<> nil then
2259 g_ActiveWindow
.Update();
2261 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2262 if gResolutionChange
then
2264 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2265 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2266 gResolutionChange
:= False;
2267 g_ActiveWindow
:= nil;
2270 // Íóæíî ñìåíèòü ÿçûê:
2271 if gLanguageChange
then
2273 //e_WriteLog('Read language file', MSG_NOTIFY);
2274 //g_Language_Load(DataDir + gLanguage + '.txt');
2275 g_Language_Set(gLanguage
);
2279 gLanguageChange
:= False;
2283 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2284 if e_KeyPressed(IK_F10
) and
2286 (not gConsoleShow
) and
2287 (g_ActiveWindow
= nil) then
2292 Time
:= sys_GetTicks() {div 1000};
2294 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2295 if gDelayedEvents
<> nil then
2296 for a
:= 0 to High(gDelayedEvents
) do
2297 if gDelayedEvents
[a
].Pending
and
2299 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2300 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2303 case gDelayedEvents
[a
].DEType
of
2305 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2308 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2312 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2313 if g_Game_IsNet
and g_Game_IsServer
then
2314 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2318 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2320 gDelayedEvents
[a
].Pending
:= False;
2323 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2324 UPSCounter
:= UPSCounter
+ 1;
2325 if Time
- UPSTime
>= 1000 then
2334 g_Weapon_AddDynLights();
2335 g_Items_AddDynLights();
2339 procedure g_Game_LoadChatSounds(Resource
: string);
2342 FileName
, Snd
: string;
2344 len
, cnt
, tags
, i
, j
: Integer;
2347 FileName
:= g_ExtractWadName(Resource
);
2349 WAD
:= TWADFile
.Create();
2350 WAD
.ReadFile(FileName
);
2352 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2359 cfg
:= TConfig
.CreateMem(p
, len
);
2360 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2362 SetLength(gChatSounds
, cnt
);
2363 for i
:= 0 to Length(gChatSounds
) - 1 do
2365 gChatSounds
[i
].Sound
:= nil;
2366 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2367 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2368 if (Snd
= '') or (Tags
<= 0) then
2370 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2371 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2372 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2373 SetLength(gChatSounds
[i
].Tags
, tags
);
2374 for j
:= 0 to tags
- 1 do
2375 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2376 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2383 procedure g_Game_FreeChatSounds();
2387 for i
:= 0 to Length(gChatSounds
) - 1 do
2389 gChatSounds
[i
].Sound
.Free();
2390 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2392 SetLength(gChatSounds
, 0);
2396 procedure g_Game_LoadData();
2403 if DataLoaded
then Exit
;
2405 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2407 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2408 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2409 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2410 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2411 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2412 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2413 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2414 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2415 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2416 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2417 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2418 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2419 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2420 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2421 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2424 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2425 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2426 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2427 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2431 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2432 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2433 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2434 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2435 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
2441 hasPBarGfx
:= false;
2445 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2446 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2447 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2448 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2449 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2450 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2451 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2452 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2453 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2454 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2455 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2456 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2457 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2458 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2459 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2460 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2461 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2462 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2463 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2464 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2465 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2466 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2467 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2472 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2473 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2474 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2475 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2476 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2477 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2478 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2479 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2480 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2481 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2482 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2483 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2485 goodsnd
[0] := TPlayableSound
.Create();
2486 goodsnd
[1] := TPlayableSound
.Create();
2487 goodsnd
[2] := TPlayableSound
.Create();
2488 goodsnd
[3] := TPlayableSound
.Create();
2490 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2491 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2492 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2493 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2495 killsnd
[0] := TPlayableSound
.Create();
2496 killsnd
[1] := TPlayableSound
.Create();
2497 killsnd
[2] := TPlayableSound
.Create();
2498 killsnd
[3] := TPlayableSound
.Create();
2500 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2501 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2502 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2503 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2505 hahasnd
[0] := TPlayableSound
.Create();
2506 hahasnd
[1] := TPlayableSound
.Create();
2507 hahasnd
[2] := TPlayableSound
.Create();
2509 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2510 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2511 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2513 sound_get_flag
[0] := TPlayableSound
.Create();
2514 sound_get_flag
[1] := TPlayableSound
.Create();
2515 sound_lost_flag
[0] := TPlayableSound
.Create();
2516 sound_lost_flag
[1] := TPlayableSound
.Create();
2517 sound_ret_flag
[0] := TPlayableSound
.Create();
2518 sound_ret_flag
[1] := TPlayableSound
.Create();
2519 sound_cap_flag
[0] := TPlayableSound
.Create();
2520 sound_cap_flag
[1] := TPlayableSound
.Create();
2522 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2523 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2524 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2525 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2526 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2527 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2528 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2529 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2531 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2533 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2536 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2537 g_Weapon_LoadData();
2539 g_Monsters_LoadData();
2544 procedure g_Game_FreeData();
2546 if not DataLoaded
then Exit
;
2549 g_Weapon_FreeData();
2550 g_Monsters_FreeData();
2552 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2554 g_Texture_Delete('NOTEXTURE');
2555 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2556 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2557 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2558 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2559 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2560 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2561 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2562 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2563 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2564 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2565 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2566 g_Frames_DeleteByName('FRAMES_TELEPORT');
2567 g_Frames_DeleteByName('FRAMES_PUNCH');
2568 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2569 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2570 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2571 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2572 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2573 g_Sound_Delete('SOUND_GAME_TELEPORT');
2574 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2575 g_Sound_Delete('SOUND_GAME_SECRET');
2576 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2577 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2578 g_Sound_Delete('SOUND_GAME_BULK1');
2579 g_Sound_Delete('SOUND_GAME_BULK2');
2580 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2581 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2582 g_Sound_Delete('SOUND_GAME_BURNING');
2583 g_Sound_Delete('SOUND_GAME_SWITCH1');
2584 g_Sound_Delete('SOUND_GAME_SWITCH0');
2591 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2592 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2593 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2594 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2601 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2602 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2603 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2604 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2610 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2611 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2612 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2614 sound_get_flag
[0].Free();
2615 sound_get_flag
[1].Free();
2616 sound_lost_flag
[0].Free();
2617 sound_lost_flag
[1].Free();
2618 sound_ret_flag
[0].Free();
2619 sound_ret_flag
[1].Free();
2620 sound_cap_flag
[0].Free();
2621 sound_cap_flag
[1].Free();
2623 g_Sound_Delete('SOUND_CTF_GET1');
2624 g_Sound_Delete('SOUND_CTF_GET2');
2625 g_Sound_Delete('SOUND_CTF_LOST1');
2626 g_Sound_Delete('SOUND_CTF_LOST2');
2627 g_Sound_Delete('SOUND_CTF_RETURN1');
2628 g_Sound_Delete('SOUND_CTF_RETURN2');
2629 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2630 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2632 g_Game_FreeChatSounds();
2634 DataLoaded
:= False;
2637 procedure DrawCustomStat();
2643 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2644 s1
, s2
, topstr
: String;
2646 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2650 if g_Console_Action(ACTION_SCORES
) then
2652 if not gStatsPressed
then
2654 gStatsOff
:= not gStatsOff
;
2655 gStatsPressed
:= True;
2659 gStatsPressed
:= False;
2663 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2664 w
:= (Length(s1
) * ww2
) div 2;
2665 x
:= gScreenWidth
div 2 - w
;
2667 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2671 if (gGameSettings
.GameMode
= GM_COOP
) then
2673 if gMissionFailed
then
2674 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2676 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2679 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2681 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2682 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2684 if g_Game_IsNet
then
2686 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2687 if not gChatShow
then
2688 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2689 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2692 if g_Game_IsClient
then
2693 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2695 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2696 if not gChatShow
then
2697 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2698 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2703 w
:= gScreenWidth
-x
*2;
2709 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2710 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2712 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2714 case CustomStat
.GameMode
of
2717 if gGameSettings
.MaxLives
= 0 then
2718 s1
:= _lc
[I_GAME_DM
]
2720 s1
:= _lc
[I_GAME_LMS
];
2724 if gGameSettings
.MaxLives
= 0 then
2725 s1
:= _lc
[I_GAME_TDM
]
2727 s1
:= _lc
[I_GAME_TLMS
];
2729 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2732 if gGameSettings
.MaxLives
= 0 then
2733 s1
:= _lc
[I_GAME_COOP
]
2735 s1
:= _lc
[I_GAME_SURV
];
2741 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2745 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2746 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2749 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2750 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2751 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2752 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2754 pc
:= Length(CustomStat
.PlayerStat
);
2755 if pc
= 0 then Exit
;
2757 if CustomStat
.GameMode
= GM_COOP
then
2759 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2761 s2
:= _lc
[I_GAME_MONSTERS
];
2762 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2763 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2765 s2
:= _lc
[I_GAME_SECRETS
];
2766 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2767 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2770 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2772 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2773 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2774 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2776 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2777 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2778 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2782 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2787 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2788 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2789 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2791 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2794 for t
:= TEAM_RED
to TEAM_BLUE
do
2796 if t
= TEAM_RED
then
2798 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2799 gStdFont
, 255, 0, 0, 1);
2800 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2801 gStdFont
, 255, 0, 0, 1);
2808 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2809 gStdFont
, 0, 0, 255, 1);
2810 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2811 gStdFont
, 0, 0, 255, 1);
2817 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2820 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2821 if CustomStat
.PlayerStat
[p
].Team
= t
then
2822 with CustomStat
.PlayerStat
[p
] do
2836 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2837 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2839 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2840 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2841 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2848 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2851 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2852 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2853 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2856 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2857 with CustomStat
.PlayerStat
[p
] do
2859 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2866 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2867 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2869 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2870 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2871 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2876 // HACK: take stats screenshot immediately after the first frame of the stats showing
2877 if gScreenshotStats
and not StatShotDone
then
2879 g_TakeScreenShot('stats/' + StatFilename
);
2880 StatShotDone
:= True;
2884 procedure DrawSingleStat();
2886 tm
, key_x
, val_x
, y
: Integer;
2890 procedure player_stat(n
: Integer);
2896 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2897 s2
:= Format(' %d', [gTotalMonsters
]);
2899 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2900 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2901 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2902 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2904 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2905 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2907 // "Kills-per-minute: ##.#":
2908 s1
:= _lc
[I_MENU_INTER_KPM
];
2910 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2912 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2913 s2
:= Format(' %.1f', [kpm
]);
2915 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2916 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2918 // "Secrets found: # / #":
2919 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2920 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2922 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2923 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2924 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2925 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2927 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2928 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2932 // "Level Complete":
2933 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2934 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2936 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2937 s1
:= _lc
[I_MENU_INTER_KPM
];
2938 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2941 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2943 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2944 val_x
:= key_x
+ w1
;
2947 tm
:= SingleStat
.GameTime
div 1000;
2948 s1
:= _lc
[I_MENU_INTER_TIME
];
2949 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2951 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2952 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2954 if SingleStat
.TwoPlayers
then
2957 s1
:= _lc
[I_MENU_PLAYER_1
];
2958 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2959 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2961 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2966 s1
:= _lc
[I_MENU_PLAYER_2
];
2967 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2968 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2970 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2976 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2982 procedure DrawLoadingStat();
2983 procedure drawRect (x
, y
, w
, h
: Integer);
2985 if (w
< 1) or (h
< 1) then exit
;
2987 glVertex2f(x
+0.375, y
+0.375);
2988 glVertex2f(x
+w
+0.375, y
+0.375);
2989 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2990 glVertex2f(x
+0.375, y
+h
+0.375);
2994 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2996 rectW
, rectH
: Integer;
3003 idl
, idr
, idb
, idm
: LongWord;
3007 if (total
< 1) then exit
;
3008 if (cur
< 1) then exit
; // don't blink
3009 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3010 //if (cur < 0) then cur := 0;
3011 //if (cur > total) then cur := total;
3014 if (hasPBarGfx
) then
3016 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3017 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3018 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3019 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3020 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3021 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3022 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3023 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3025 //rectW := gScreenWidth-360;
3026 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3029 x0
:= (gScreenWidth
-rectW
) div 2;
3030 y0
:= gScreenHeight
-rectH
-64;
3031 if (y0
< 2) then y0
:= 2;
3033 glEnable(GL_SCISSOR_TEST
);
3036 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3037 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3038 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3041 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3043 while (f
< x0
+rectW
) do
3045 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3050 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3051 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3054 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3055 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3059 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3065 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3069 rectW
:= gScreenWidth
-64;
3072 x0
:= (gScreenWidth
-rectW
) div 2;
3073 y0
:= gScreenHeight
-rectH
-64;
3074 if (y0
< 2) then y0
:= 2;
3076 glDisable(GL_BLEND
);
3077 glDisable(GL_TEXTURE_2D
);
3079 //glClearColor(0, 0, 0, 0);
3080 //glClear(GL_COLOR_BUFFER_BIT);
3082 glColor4ub(127, 127, 127, 255);
3083 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3085 glColor4ub(0, 0, 0, 255);
3086 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3088 glColor4ub(127, 127, 127, 255);
3089 wdt
:= rectW
*cur
div total
;
3090 if (wdt
> rectW
) then wdt
:= rectW
;
3091 drawRect(x0
, y0
, wdt
, rectH
);
3100 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3102 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3103 yy
:= (gScreenHeight
div 3);
3104 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3105 xx
:= (gScreenWidth
div 3);
3109 for i
:= 0 to NextMsg
-1 do
3111 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3112 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3116 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3117 yy
:= yy
+ LOADING_INTERLINE
;
3118 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3123 procedure DrawMenuBackground(tex
: AnsiString);
3129 if g_Texture_Get(tex
, ID
) then
3131 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3132 e_GetTextureSize(ID
, @w
, @h
);
3134 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3136 w
:= trunc(w
* (gScreenHeight
/ h
));
3137 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3139 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3142 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3144 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3146 function monDraw (mon
: TMonster
): Boolean;
3148 result
:= false; // don't stop
3153 // Ëåâûé âåðõíèé óãîë
3154 aX
:= Obj
.X
div ScaleSz
+ 1;
3155 aY
:= Obj
.Y
div ScaleSz
+ 1;
3157 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3158 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3159 // Ïðàâûé íèæíèé óãîë
3160 aX2
:= aX
+ aX2
- 1;
3161 aY2
:= aY
+ aY2
- 1;
3162 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3168 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3169 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3172 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3173 ScaleSz
:= 16 div Scale
;
3174 // Ðàçìåðû ìèíè-êàðòû:
3175 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3176 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3178 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3180 if gWalls
<> nil then
3183 for a
:= 0 to High(gWalls
) do
3185 if PanelType
<> 0 then
3187 // Ëåâûé âåðõíèé óãîë:
3188 aX
:= X
div ScaleSz
;
3189 aY
:= Y
div ScaleSz
;
3191 aX2
:= max(Width
div ScaleSz
, 1);
3192 aY2
:= max(Height
div ScaleSz
, 1);
3193 // Ïðàâûé íèæíèé óãîë:
3194 aX2
:= aX
+ aX2
- 1;
3195 aY2
:= aY
+ aY2
- 1;
3198 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3199 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3200 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3204 if gSteps
<> nil then
3207 for a
:= 0 to High(gSteps
) do
3209 if PanelType
<> 0 then
3211 // Ëåâûé âåðõíèé óãîë:
3212 aX
:= X
div ScaleSz
;
3213 aY
:= Y
div ScaleSz
;
3215 aX2
:= max(Width
div ScaleSz
, 1);
3216 aY2
:= max(Height
div ScaleSz
, 1);
3217 // Ïðàâûé íèæíèé óãîë:
3218 aX2
:= aX
+ aX2
- 1;
3219 aY2
:= aY
+ aY2
- 1;
3221 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3224 if gLifts
<> nil then
3227 for a
:= 0 to High(gLifts
) do
3229 if PanelType
<> 0 then
3231 // Ëåâûé âåðõíèé óãîë:
3232 aX
:= X
div ScaleSz
;
3233 aY
:= Y
div ScaleSz
;
3235 aX2
:= max(Width
div ScaleSz
, 1);
3236 aY2
:= max(Height
div ScaleSz
, 1);
3237 // Ïðàâûé íèæíèé óãîë:
3238 aX2
:= aX
+ aX2
- 1;
3239 aY2
:= aY
+ aY2
- 1;
3242 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3243 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3244 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3245 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3249 if gWater
<> nil then
3252 for a
:= 0 to High(gWater
) do
3254 if PanelType
<> 0 then
3256 // Ëåâûé âåðõíèé óãîë:
3257 aX
:= X
div ScaleSz
;
3258 aY
:= Y
div ScaleSz
;
3260 aX2
:= max(Width
div ScaleSz
, 1);
3261 aY2
:= max(Height
div ScaleSz
, 1);
3262 // Ïðàâûé íèæíèé óãîë:
3263 aX2
:= aX
+ aX2
- 1;
3264 aY2
:= aY
+ aY2
- 1;
3266 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3269 if gAcid1
<> nil then
3271 // Ðèñóåì êèñëîòó 1:
3272 for a
:= 0 to High(gAcid1
) do
3274 if PanelType
<> 0 then
3276 // Ëåâûé âåðõíèé óãîë:
3277 aX
:= X
div ScaleSz
;
3278 aY
:= Y
div ScaleSz
;
3280 aX2
:= max(Width
div ScaleSz
, 1);
3281 aY2
:= max(Height
div ScaleSz
, 1);
3282 // Ïðàâûé íèæíèé óãîë:
3283 aX2
:= aX
+ aX2
- 1;
3284 aY2
:= aY
+ aY2
- 1;
3286 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3289 if gAcid2
<> nil then
3291 // Ðèñóåì êèñëîòó 2:
3292 for a
:= 0 to High(gAcid2
) do
3294 if PanelType
<> 0 then
3296 // Ëåâûé âåðõíèé óãîë:
3297 aX
:= X
div ScaleSz
;
3298 aY
:= Y
div ScaleSz
;
3300 aX2
:= max(Width
div ScaleSz
, 1);
3301 aY2
:= max(Height
div ScaleSz
, 1);
3302 // Ïðàâûé íèæíèé óãîë:
3303 aX2
:= aX
+ aX2
- 1;
3304 aY2
:= aY
+ aY2
- 1;
3306 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3309 if gPlayers
<> nil then
3312 for a
:= 0 to High(gPlayers
) do
3313 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3315 // Ëåâûé âåðõíèé óãîë:
3316 aX
:= Obj
.X
div ScaleSz
+ 1;
3317 aY
:= Obj
.Y
div ScaleSz
+ 1;
3319 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3320 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3321 // Ïðàâûé íèæíèé óãîë:
3322 aX2
:= aX
+ aX2
- 1;
3323 aY2
:= aY
+ aY2
- 1;
3325 if gPlayers
[a
] = p
then
3326 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3329 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3330 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3331 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3336 g_Mons_ForEach(monDraw
);
3341 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3343 if not hasAmbient
then exit
;
3344 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3348 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3349 //FIXME: broken for splitscreen mode
3350 procedure renderDynLightsInternal ();
3352 //hasAmbient: Boolean;
3353 //ambColor: TDFColor;
3355 lx
, ly
, lrad
: Integer;
3356 scxywh
: array[0..3] of GLint
;
3359 if e_NoGraphics
then exit
;
3361 //TODO: lights should be in separate grid, i think
3362 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3363 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3366 //ambColor := gCurrentMap['light_ambient'].rgba;
3367 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3369 { // this will multiply incoming color to alpha from framebuffer
3371 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3375 * light rendering: (INVALID!)
3376 * glStencilFunc(GL_EQUAL, 0, $ff);
3378 * glClear(GL_STENCIL_BUFFER_BIT);
3379 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3380 * draw shadow volume into stencil buffer
3381 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3382 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3384 * draw color-less quad with light alpha (WARNING! don't touch color!)
3385 * glEnable(GL_BLEND);
3386 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3387 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3389 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3390 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3392 // setup OpenGL parameters
3393 glStencilMask($FFFFFFFF);
3394 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3395 glEnable(GL_STENCIL_TEST
);
3396 glEnable(GL_SCISSOR_TEST
);
3397 glClear(GL_STENCIL_BUFFER_BIT
);
3398 glStencilFunc(GL_EQUAL
, 0, $ff);
3400 for lln
:= 0 to g_dynLightCount
-1 do
3402 lx
:= g_dynLights
[lln
].x
;
3403 ly
:= g_dynLights
[lln
].y
;
3404 lrad
:= g_dynLights
[lln
].radius
;
3405 if (lrad
< 3) then continue
;
3407 if (lx
-sX
+lrad
< 0) then continue
;
3408 if (ly
-sY
+lrad
< 0) then continue
;
3409 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3410 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3412 // set scissor to optimize drawing
3413 if (g_dbg_scale
= 1.0) then
3415 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3419 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3421 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3422 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3423 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3424 // draw extruded panels
3425 glDisable(GL_TEXTURE_2D
);
3426 glDisable(GL_BLEND
);
3427 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3428 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3429 // render light texture
3430 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3431 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3434 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3435 glEnable(GL_TEXTURE_2D
);
3436 // color and opacity
3437 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3438 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3440 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3441 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3442 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3443 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3448 glDisable(GL_STENCIL_TEST
);
3449 glDisable(GL_BLEND
);
3450 glDisable(GL_SCISSOR_TEST
);
3451 //glScissor(0, 0, sWidth, sHeight);
3453 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3454 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3458 function fixViewportForScale (): Boolean;
3460 nx0
, ny0
, nw
, nh
: Integer;
3463 if (g_dbg_scale
<> 1.0) then
3466 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3467 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3468 nw
:= round(sWidth
/g_dbg_scale
);
3469 nh
:= round(sHeight
/g_dbg_scale
);
3478 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3479 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3480 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3482 TDrawCB
= procedure ();
3485 hasAmbient
: Boolean;
3487 doAmbient
: Boolean = false;
3489 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3494 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3495 if gdbg_map_use_accel_render
then
3497 tagmask
:= panelTypeToTag(panType
);
3498 while (gDrawPanelList
.count
> 0) do
3500 pan
:= TPanel(gDrawPanelList
.front());
3501 if ((pan
.tag
and tagmask
) = 0) then break
;
3502 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3503 gDrawPanelList
.popFront();
3508 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3510 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3513 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3515 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3516 if assigned(cb
) then cb();
3517 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3521 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3523 // our accelerated renderer will collect all panels to gDrawPanelList
3524 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3525 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3526 if gdbg_map_use_accel_render
then
3528 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3530 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3532 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3533 g_Map_DrawBack(backXOfs
, backYOfs
);
3534 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3536 if setTransMatrix
then
3538 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3539 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3540 glTranslatef(-sX
, -sY
, 0);
3544 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3545 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3550 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3551 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3552 glClear(GL_COLOR_BUFFER_BIT);
3555 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3558 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3559 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3560 drawOther('items', @g_Items_Draw
);
3561 drawOther('weapons', @g_Weapon_Draw
);
3562 drawOther('shells', @g_Player_DrawShells
);
3563 drawOther('drawall', @g_Player_DrawAll
);
3564 drawOther('corpses', @g_Player_DrawCorpses
);
3565 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3566 drawOther('monsters', @g_Monsters_Draw
);
3567 drawOther('itemdrop', @g_Items_DrawDrop
);
3568 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3569 drawOther('gfx', @g_GFX_Draw
);
3570 drawOther('flags', @g_Map_DrawFlags
);
3571 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3572 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3573 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3574 drawOther('dynlights', @renderDynLightsInternal
);
3576 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3578 renderAmbientQuad(hasAmbient
, ambColor
);
3582 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3585 if g_debug_HealthBar
then
3587 g_Monsters_DrawHealth();
3588 g_Player_DrawHealth();
3591 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3595 procedure DrawMapView(x
, y
, w
, h
: Integer);
3602 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3603 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3610 fixViewportForScale();
3611 renderMapInternal(-bx
, -by
, true);
3617 procedure DrawPlayer(p
: TPlayer
);
3619 px
, py
, a
, b
, c
, d
, i
: Integer;
3622 if (p
= nil) or (p
.FDummy
) then
3625 g_Map_DrawBack(0, 0);
3630 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3631 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3637 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3638 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3640 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3642 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3643 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3645 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3646 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3648 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3649 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3652 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3655 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3656 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3659 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3664 // scaled, ignore level bounds
3665 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3666 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3669 if p
.IncCam
<> 0 then
3671 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3673 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3675 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3679 if py
< gPlayerScreenSize
.Y
div 2 then
3681 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3683 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3687 if p
.IncCam
< 0 then
3689 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3692 if p
.IncCam
> 0 then
3694 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3698 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3699 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3700 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3702 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3703 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3704 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3707 sY
:= -(b
+p
.IncCam
);
3708 sWidth
:= gPlayerScreenSize
.X
;
3709 sHeight
:= gPlayerScreenSize
.Y
;
3711 //glTranslatef(a, b+p.IncCam, 0);
3713 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3715 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3716 fixViewportForScale();
3717 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3719 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3721 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3722 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3723 if (sX
< 0) then sX
:= 0;
3724 if (sY
< 0) then sY
:= 0;
3726 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3727 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3730 //r_smallmap_h: 0: left; 1: center; 2: right
3731 //r_smallmap_v: 0: top; 1: center; 2: bottom
3733 if (gMapInfo
.Width
= sWidth
) then
3737 else if (gMapInfo
.Width
< sWidth
) then
3739 case r_smallmap_h
of
3740 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3741 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3742 else sX
:= 0; // left
3746 if (gMapInfo
.Height
= sHeight
) then
3750 else if (gMapInfo
.Height
< sHeight
) then
3752 case r_smallmap_v
of
3753 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3754 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3755 else sY
:= 0; // top
3761 p
.viewPortW
:= sWidth
;
3762 p
.viewPortH
:= sHeight
;
3764 {$IFDEF ENABLE_HOLMES}
3765 if (p
= gPlayer1
) then
3767 g_Holmes_plrViewPos(sX
, sY
);
3768 g_Holmes_plrViewSize(sWidth
, sHeight
);
3772 renderMapInternal(-c
, -d
, true);
3774 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3775 case gPlayerIndicator
of
3777 p
.DrawIndicator(_RGB(255, 255, 255));
3780 for i
:= 0 to High(gPlayers
) do
3781 if gPlayers
[i
] <> nil then
3782 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3783 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3784 if gPlayerIndicatorStyle
= 1 then
3785 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3786 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3789 if p
.FSpectator
then
3790 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3791 p
.GameY
+ PLAYER_RECT_CY
- 4,
3792 'X', gStdFont
, 255, 255, 255, 1, True);
3794 for a := 0 to High(gCollideMap) do
3795 for b := 0 to High(gCollideMap[a]) do
3798 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3800 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3804 1: e_DrawPoint(1, b, a, 200, 200, 200);
3805 2: e_DrawPoint(1, b, a, 64, 64, 255);
3806 3: e_DrawPoint(1, b, a, 255, 0, 255);
3816 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3817 if g_Debug_Player
then
3818 g_Player_DrawDebug(p
);
3822 procedure drawProfilers ();
3827 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3828 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3829 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3832 procedure g_Game_Draw();
3839 plView1
, plView2
: TPlayer
;
3842 if gExit
= EXIT_QUIT
then Exit
;
3844 Time
:= sys_GetTicks() {div 1000};
3845 FPSCounter
:= FPSCounter
+1;
3846 if Time
- FPSTime
>= 1000 then
3853 if gGameOn
or (gState
= STATE_FOLD
) then
3855 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3857 gSpectMode
:= SPECT_NONE
;
3858 if not gRevertPlayers
then
3860 plView1
:= gPlayer1
;
3861 plView2
:= gPlayer2
;
3865 plView1
:= gPlayer2
;
3866 plView2
:= gPlayer1
;
3870 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3872 gSpectMode
:= SPECT_NONE
;
3873 if gPlayer2
= nil then
3876 plView1
:= gPlayer2
;
3885 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3886 gSpectMode
:= SPECT_STATS
;
3888 if gSpectMode
= SPECT_PLAYERS
then
3889 if gPlayers
<> nil then
3891 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3892 if plView1
= nil then
3894 gSpectPID1
:= GetActivePlayerID_Next();
3895 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3897 if gSpectViewTwo
then
3899 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3900 if plView2
= nil then
3902 gSpectPID2
:= GetActivePlayerID_Next();
3903 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3908 if gSpectMode
= SPECT_MAPVIEW
then
3910 // Ðåæèì ïðîñìîòðà êàðòû
3912 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3913 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3914 gHearPoint1
.Active
:= True;
3915 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3916 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3917 gHearPoint2
.Active
:= False;
3921 Split
:= (plView1
<> nil) and (plView2
<> nil);
3923 // Òî÷êè ñëóõà èãðîêîâ
3924 if plView1
<> nil then
3926 gHearPoint1
.Active
:= True;
3927 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3928 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3930 gHearPoint1
.Active
:= False;
3931 if plView2
<> nil then
3933 gHearPoint2
.Active
:= True;
3934 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3935 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3937 gHearPoint2
.Active
:= False;
3939 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3940 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3943 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3944 if gScreenHeight
mod 2 = 0 then
3945 Dec(gPlayerScreenSize
.Y
);
3948 gPlayerScreenSize
.Y
:= gScreenHeight
;
3951 if gScreenHeight
mod 2 = 0 then
3952 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3954 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3956 DrawPlayer(plView1
);
3957 gPlayer1ScreenCoord
.X
:= sX
;
3958 gPlayer1ScreenCoord
.Y
:= sY
;
3962 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3964 DrawPlayer(plView2
);
3965 gPlayer2ScreenCoord
.X
:= sX
;
3966 gPlayer2ScreenCoord
.Y
:= sY
;
3969 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3972 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3975 {$IFDEF ENABLE_HOLMES}
3977 if (g_holmes_enabled
) then g_Holmes_Draw();
3980 if MessageText
<> '' then
3984 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3986 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3987 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3989 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3990 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3993 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3995 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3997 // Draw spectator GUI
4000 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4003 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4005 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4007 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4009 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4010 if gSpectMode
= SPECT_STATS
then
4012 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4013 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4015 if gSpectMode
= SPECT_MAPVIEW
then
4017 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4018 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4019 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4020 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4023 if gSpectMode
= SPECT_PLAYERS
then
4025 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4026 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4027 if gSpectViewTwo
then
4029 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4030 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4031 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4032 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4036 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4037 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4043 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4045 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4046 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4048 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4049 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4050 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4055 if (gState
= STATE_MENU
) then
4057 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4058 // F3 at menu will show game loading dialog
4059 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4060 if (g_ActiveWindow
<> nil) then
4062 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4063 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4067 // F3 at titlepic will show game loading dialog
4068 if e_KeyPressed(IK_F3
) then
4070 g_Menu_Show_LoadMenu(true);
4071 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4076 if gState
= STATE_FOLD
then
4078 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4081 if gState
= STATE_INTERCUSTOM
then
4083 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4085 back
:= 'TEXTURE_endpic';
4086 if not g_Texture_Get(back
, ID
) then
4087 back
:= _lc
[I_TEXTURE_ENDPIC
];
4092 DrawMenuBackground(back
);
4096 if g_ActiveWindow
<> nil then
4098 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4099 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4103 if gState
= STATE_INTERSINGLE
then
4105 if EndingGameCounter
> 0 then
4107 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4113 DrawMenuBackground(back
);
4117 if g_ActiveWindow
<> nil then
4119 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4120 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4125 if gState
= STATE_ENDPIC
then
4128 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4129 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4131 if g_ActiveWindow
<> nil then
4133 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4134 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4138 if gState
= STATE_SLIST
then
4140 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4142 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4143 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4145 DrawMenuBackground('MENU_BACKGROUND');
4146 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4147 g_Serverlist_Draw(slCurrent
, slTable
);
4151 if g_ActiveWindow
<> nil then
4155 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4156 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4158 g_ActiveWindow
.Draw();
4165 if g_debug_Sounds
and gGameOn
then
4167 for w
:= 0 to High(e_SoundsArray
) do
4168 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4169 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4174 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4175 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4178 if gGameOn
and gShowTime
then
4179 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4181 if gGameOn
then drawProfilers();
4183 {$IFDEF ENABLE_HOLMES}
4190 procedure g_Game_Quit();
4192 g_Game_StopAllSounds(True);
4195 g_PlayerModel_FreeData();
4196 g_Texture_DeleteAll();
4197 g_Frames_DeleteAll();
4199 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4202 if NetInitDone
then g_Net_Free
;
4204 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4205 if gMapToDelete
<> '' then
4206 g_Game_DeleteTestMap();
4212 procedure g_FatalError(Text: String);
4214 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4215 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4217 gExit
:= EXIT_SIMPLE
;
4220 procedure g_SimpleError(Text: String);
4222 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4223 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4226 procedure g_Game_SetupScreenSize();
4228 RES_FACTOR
= 4.0 / 3.0;
4234 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4235 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4236 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4237 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4239 gPlayerScreenSize
.Y
:= gScreenHeight
;
4241 // Ðàçìåð çàäíåãî ïëàíà:
4242 if BackID
<> DWORD(-1) then
4245 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4246 (gScreenHeight
*s
> gMapInfo
.Height
) then
4248 gBackSize
.X
:= gScreenWidth
;
4249 gBackSize
.Y
:= gScreenHeight
;
4253 e_GetTextureSize(BackID
, @bw
, @bh
);
4254 rf
:= Single(bw
) / Single(bh
);
4255 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4256 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4257 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4258 if (s
< 1.0) then s
:= 1.0;
4259 gBackSize
.X
:= Round(bw
*s
);
4260 gBackSize
.Y
:= Round(bh
*s
);
4265 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4267 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4270 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4272 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4273 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4275 if gPlayer1
= nil then
4277 if g_Game_IsClient
then
4279 if NetPlrUID1
> -1 then
4281 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4282 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4287 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4288 Team
:= gPlayer1Settings
.Team
;
4290 // Ñîçäàíèå ïåðâîãî èãðîêà:
4291 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4292 gPlayer1Settings
.Color
,
4294 if gPlayer1
= nil then
4295 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4298 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4299 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4300 if g_Game_IsServer
and g_Game_IsNet
then
4301 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4302 gPlayer1
.Respawn(False, True);
4303 g_Net_Slist_ServerPlayerComes();
4308 if gPlayer2
= nil then
4310 if g_Game_IsClient
then
4312 if NetPlrUID2
> -1 then
4313 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4317 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4318 Team
:= gPlayer2Settings
.Team
;
4320 // Ñîçäàíèå âòîðîãî èãðîêà:
4321 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4322 gPlayer2Settings
.Color
,
4324 if gPlayer2
= nil then
4325 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4328 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4329 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4330 if g_Game_IsServer
and g_Game_IsNet
then
4331 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4332 gPlayer2
.Respawn(False, True);
4333 g_Net_Slist_ServerPlayerComes();
4340 procedure g_Game_RemovePlayer();
4344 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4345 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4350 if g_Game_IsServer
then
4353 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4354 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4355 g_Player_Remove(Pl
.UID
);
4356 g_Net_Slist_ServerPlayerLeaves();
4364 if g_Game_IsServer
then
4367 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4368 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4369 g_Player_Remove(Pl
.UID
);
4370 g_Net_Slist_ServerPlayerLeaves();
4374 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4378 g_Net_Slist_ServerPlayerLeaves();
4381 procedure g_Game_Spectate();
4383 g_Game_RemovePlayer();
4384 if gPlayer1
<> nil then
4385 g_Game_RemovePlayer();
4388 procedure g_Game_SpectateCenterView();
4390 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4391 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4394 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4401 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4403 g_Game_ClearLoading();
4406 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4409 gGameSettings
.GameType
:= GT_SINGLE
;
4410 gGameSettings
.MaxLives
:= 0;
4411 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4412 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4413 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4414 gSwitchGameMode
:= GM_SINGLE
;
4416 g_Game_ExecuteEvent('ongamestart');
4418 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4419 g_Game_SetupScreenSize();
4421 // Ñîçäàíèå ïåðâîãî èãðîêà:
4422 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4423 gPlayer1Settings
.Color
,
4424 gPlayer1Settings
.Team
, False));
4425 if gPlayer1
= nil then
4427 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4431 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4434 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4437 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4438 gPlayer2Settings
.Color
,
4439 gPlayer2Settings
.Team
, False));
4440 if gPlayer2
= nil then
4442 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4446 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4450 // Çàãðóçêà è çàïóñê êàðòû:
4451 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4453 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4454 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4458 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4462 for i
:= nPl
+1 to nPlayers
do
4463 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4466 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4467 TimeLimit
, GoalLimit
: Word;
4469 Options
: LongWord; nPlayers
: Byte);
4475 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4477 g_Game_ClearLoading();
4480 gGameSettings
.GameType
:= GT_CUSTOM
;
4481 gGameSettings
.GameMode
:= GameMode
;
4482 gSwitchGameMode
:= GameMode
;
4483 gGameSettings
.TimeLimit
:= TimeLimit
;
4484 gGameSettings
.GoalLimit
:= GoalLimit
;
4485 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4486 gGameSettings
.Options
:= Options
;
4488 gCoopTotalMonstersKilled
:= 0;
4489 gCoopTotalSecretsFound
:= 0;
4490 gCoopTotalMonsters
:= 0;
4491 gCoopTotalSecrets
:= 0;
4495 g_Game_ExecuteEvent('ongamestart');
4497 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4498 g_Game_SetupScreenSize();
4500 // Ðåæèì íàáëþäàòåëÿ:
4501 if nPlayers
= 0 then
4508 if nPlayers
>= 1 then
4510 // Ñîçäàíèå ïåðâîãî èãðîêà:
4511 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4512 gPlayer1Settings
.Color
,
4513 gPlayer1Settings
.Team
, False));
4514 if gPlayer1
= nil then
4516 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4520 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4524 if nPlayers
>= 2 then
4526 // Ñîçäàíèå âòîðîãî èãðîêà:
4527 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4528 gPlayer2Settings
.Color
,
4529 gPlayer2Settings
.Team
, False));
4530 if gPlayer2
= nil then
4532 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4536 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4540 // Çàãðóçêà è çàïóñê êàðòû:
4541 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4543 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4547 // Íåò òî÷åê ïîÿâëåíèÿ:
4548 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4549 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4550 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4551 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4552 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4554 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4558 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4562 for i
:= nPl
+1 to nPlayers
do
4563 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4566 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4567 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4568 Options
: LongWord; nPlayers
: Byte;
4569 IPAddr
: LongWord; Port
: Word);
4572 g_Net_Slist_ServerClosed();
4574 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4576 g_Game_ClearLoading();
4579 gGameSettings
.GameType
:= GT_SERVER
;
4580 gGameSettings
.GameMode
:= GameMode
;
4581 gSwitchGameMode
:= GameMode
;
4582 gGameSettings
.TimeLimit
:= TimeLimit
;
4583 gGameSettings
.GoalLimit
:= GoalLimit
;
4584 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4585 gGameSettings
.Options
:= Options
;
4587 gCoopTotalMonstersKilled
:= 0;
4588 gCoopTotalSecretsFound
:= 0;
4589 gCoopTotalMonsters
:= 0;
4590 gCoopTotalSecrets
:= 0;
4594 g_Game_ExecuteEvent('ongamestart');
4596 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4597 g_Game_SetupScreenSize();
4599 // Ðåæèì íàáëþäàòåëÿ:
4600 if nPlayers
= 0 then
4606 if nPlayers
>= 1 then
4608 // Ñîçäàíèå ïåðâîãî èãðîêà:
4609 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4610 gPlayer1Settings
.Color
,
4611 gPlayer1Settings
.Team
, False));
4612 if gPlayer1
= nil then
4614 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4618 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4621 if nPlayers
>= 2 then
4623 // Ñîçäàíèå âòîðîãî èãðîêà:
4624 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4625 gPlayer2Settings
.Color
,
4626 gPlayer2Settings
.Team
, False));
4627 if gPlayer2
= nil then
4629 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4633 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4636 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4637 if NetForwardPorts
then
4638 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4641 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4643 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4647 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4649 g_Net_Slist_ServerStarted();
4651 // Çàãðóçêà è çàïóñê êàðòû:
4652 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4654 g_Net_Slist_ServerClosed();
4655 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4659 // Íåò òî÷åê ïîÿâëåíèÿ:
4660 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4661 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4662 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4663 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4664 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4666 g_Net_Slist_ServerClosed();
4667 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4671 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4674 g_Net_Slist_ServerMapStarted();
4675 NetState
:= NET_STATE_GAME
;
4678 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4693 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4694 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4696 g_Game_ClearLoading();
4699 gGameSettings
.GameType
:= GT_CLIENT
;
4701 gCoopTotalMonstersKilled
:= 0;
4702 gCoopTotalSecretsFound
:= 0;
4703 gCoopTotalMonsters
:= 0;
4704 gCoopTotalSecrets
:= 0;
4708 g_Game_ExecuteEvent('ongamestart');
4710 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4711 g_Game_SetupScreenSize();
4713 NetState
:= NET_STATE_AUTH
;
4715 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4717 // create (or update) map/resource databases
4718 g_Res_CreateDatabases(true);
4721 if not g_Net_Connect(Addr
, Port
) then
4723 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4724 NetState
:= NET_STATE_NONE
;
4728 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4730 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4735 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4736 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4737 // thank you, enet. let's ignore failures altogether then.
4738 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4740 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4742 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4744 // ignore all download packets, they're processed by separate code
4745 enet_packet_destroy(NetEvent
.packet
);
4748 Ptr
:= NetEvent
.packet
^.data
;
4749 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4751 enet_packet_destroy(NetEvent
.packet
);
4755 InMsg
.ReadLongWord(); // skip size
4756 MID
:= InMsg
.ReadByte();
4758 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4760 NetMyID
:= InMsg
.ReadByte();
4761 NetPlrUID1
:= InMsg
.ReadWord();
4763 WadName
:= InMsg
.ReadString();
4764 Map
:= InMsg
.ReadString();
4766 gWADHash
:= InMsg
.ReadMD5();
4768 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4769 gSwitchGameMode
:= gGameSettings
.GameMode
;
4770 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4771 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4772 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4773 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4774 T
:= InMsg
.ReadLongWord();
4776 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4777 //if newResPath = '' then
4779 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4780 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4781 if newResPath
= '' then
4783 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4784 enet_packet_destroy(NetEvent
.packet
);
4785 NetState
:= NET_STATE_NONE
;
4788 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4790 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4793 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4794 gPlayer1Settings
.Color
,
4795 gPlayer1Settings
.Team
, False));
4797 if gPlayer1
= nil then
4799 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4801 enet_packet_destroy(NetEvent
.packet
);
4802 NetState
:= NET_STATE_NONE
;
4806 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4807 gPlayer1
.UID
:= NetPlrUID1
;
4808 gPlayer1
.Reset(True);
4810 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4812 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4814 enet_packet_destroy(NetEvent
.packet
);
4815 NetState
:= NET_STATE_NONE
;
4823 enet_packet_destroy(NetEvent
.packet
);
4827 enet_packet_destroy(NetEvent
.packet
);
4831 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4834 if (NetEvent
.data
<= NET_DISC_MAX
) then
4835 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4836 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4843 ProcessLoading(true);
4845 if g_Net_UserRequestExit() then
4854 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4855 NetState
:= NET_STATE_NONE
;
4859 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4860 gLMSRespawnTime
:= 0;
4863 NetState
:= NET_STATE_GAME
;
4864 MC_SEND_FullStateRequest
;
4865 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4869 lastAsMegaWad
: Boolean = false;
4871 procedure g_Game_ChangeMap(const MapPath
: String);
4875 g_Game_ClearLoading();
4877 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4878 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4879 if gExitByTrigger
then
4882 gExitByTrigger
:= False;
4884 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4885 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4888 procedure g_Game_Restart();
4892 if g_Game_IsClient
then
4894 map
:= g_ExtractFileName(gMapInfo
.Map
);
4895 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4899 g_Game_ClearLoading();
4900 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4903 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4905 NewWAD
, ResName
: String;
4909 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4910 g_Player_RemoveAllCorpses();
4912 if (not g_Game_IsClient
) and
4913 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4914 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4916 if gSwitchGameMode
= GM_CTF
then
4917 gGameSettings
.MaxLives
:= 0;
4918 gGameSettings
.GameMode
:= gSwitchGameMode
;
4921 gSwitchGameMode
:= gGameSettings
.GameMode
;
4923 g_Player_ResetTeams();
4925 lastAsMegaWad
:= asMegawad
;
4926 if isWadPath(Map
) then
4928 NewWAD
:= g_ExtractWadName(Map
);
4929 ResName
:= g_ExtractFileName(Map
);
4930 if g_Game_IsServer
then
4932 nws
:= findDiskWad(NewWAD
);
4933 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4936 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4937 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4941 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4942 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4944 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4945 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4947 if (length(nws
) = 0) then
4949 ResName
:= ''; // failed
4954 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4955 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4956 g_Game_LoadWAD(NewWAD
);
4961 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4962 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
4967 NewWAD
:= gGameSettings
.WAD
;
4971 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4973 if (ResName
<> '') and (NewWAD
<> '') then
4975 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4976 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
4980 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4982 gState
:= STATE_NONE
;
4983 g_ActiveWindow
:= nil;
4989 if gGameSettings
.GameMode
= GM_CTF
then
4991 g_Map_ResetFlag(FLAG_RED
);
4992 g_Map_ResetFlag(FLAG_BLUE
);
4993 // CTF, à ôëàãîâ íåò:
4994 if not g_Map_HaveFlagPoints() then
4995 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5000 gState
:= STATE_MENU
;
5005 gPauseMain
:= false;
5006 gPauseHolmes
:= false;
5008 NetTimeToUpdate
:= 1;
5009 NetTimeToReliable
:= 0;
5010 NetTimeToMaster
:= NetMasterRate
;
5011 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5012 gLMSRespawnTime
:= 0;
5013 gMissionFailed
:= False;
5016 gCoopMonstersKilled
:= 0;
5017 gCoopSecretsFound
:= 0;
5019 gVoteInProgress
:= False;
5020 gVotePassed
:= False;
5026 if not gGameOn
then Exit
;
5028 g_Game_SpectateCenterView();
5030 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5032 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5033 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5034 gLMSSoftSpawn
:= True;
5035 if NetMode
= NET_SERVER
then
5036 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
5038 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
5041 if NetMode
= NET_SERVER
then
5043 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5046 g_Net_Slist_ServerMapStarted();
5048 if NetClients
<> nil then
5049 for I
:= 0 to High(NetClients
) do
5050 if NetClients
[I
].Used
then
5052 NetClients
[I
].Voted
:= False;
5053 if NetClients
[I
].RequestedFullUpdate
then
5055 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5056 NetClients
[I
].RequestedFullUpdate
:= False;
5060 g_Net_UnbanNonPermHosts();
5065 gCoopTotalMonstersKilled
:= 0;
5066 gCoopTotalSecretsFound
:= 0;
5067 gCoopTotalMonsters
:= 0;
5068 gCoopTotalSecrets
:= 0;
5072 g_Game_ExecuteEvent('onmapstart');
5075 procedure SetFirstLevel
;
5079 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5080 if MapList
= nil then
5083 SortSArray(MapList
);
5084 gNextMap
:= MapList
[Low(MapList
)];
5089 procedure g_Game_ExitLevel(const Map
: AnsiString);
5093 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5094 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5095 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5096 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5098 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5099 if gGameSettings
.GameType
= GT_SINGLE
then
5100 gExit
:= EXIT_ENDLEVELSINGLE
5101 else // Âûøëè â âûõîä â Ñâîåé èãðå
5103 gExit
:= EXIT_ENDLEVELCUSTOM
;
5104 if gGameSettings
.GameMode
= GM_COOP
then
5105 g_Player_RememberAll
;
5107 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5110 if gGameSettings
.GameMode
= GM_COOP
then
5113 gStatsPressed
:= True;
5114 gNextMap
:= 'MAP01';
5116 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5119 if g_Game_IsNet
then
5121 MH_SEND_GameStats();
5122 MH_SEND_CoopStats();
5128 procedure g_Game_RestartLevel();
5132 if gGameSettings
.GameMode
= GM_SINGLE
then
5137 gExit
:= EXIT_ENDLEVELCUSTOM
;
5138 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5142 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5144 gWAD
{, xwad}: String;
5147 if not g_Game_IsClient
then Exit
;
5148 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5150 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5155 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5159 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5162 g_Game_LoadWAD(NewWAD
);
5166 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5167 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5170 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5171 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5175 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5179 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5180 g_Game_LoadWAD(NewWAD);
5184 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5186 i
, n
, nb
, nr
: Integer;
5188 function monRespawn (mon
: TMonster
): Boolean;
5190 result
:= false; // don't stop
5191 if not mon
.FNoRespawn
then mon
.Respawn();
5195 if not g_Game_IsServer
then Exit
;
5196 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5197 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5198 gLMSRespawnTime
:= 0;
5201 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5203 gMissionFailed
:= True;
5204 g_Game_RestartLevel
;
5208 n
:= 0; nb
:= 0; nr
:= 0;
5209 for i
:= Low(gPlayers
) to High(gPlayers
) do
5210 if (gPlayers
[i
] <> nil) and
5211 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5212 (gPlayers
[i
] is TBot
)) then
5215 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5216 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5219 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5221 // wait a second until the fuckers finally decide to join
5222 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5223 gLMSRespawnTime
:= gTime
+ 1000;
5224 gLMSSoftSpawn
:= NoMapRestart
;
5228 g_Player_RemoveAllCorpses
;
5229 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5230 if g_Game_IsNet
then
5231 MH_SEND_GameEvent(NET_EV_LMS_START
);
5233 for i
:= Low(gPlayers
) to High(gPlayers
) do
5235 if gPlayers
[i
] = nil then continue
;
5236 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5237 // don't touch normal spectators
5238 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5240 gPlayers
[i
].FNoRespawn
:= True;
5241 gPlayers
[i
].Lives
:= 0;
5242 if g_Game_IsNet
then
5243 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5246 gPlayers
[i
].FNoRespawn
:= False;
5247 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5248 gPlayers
[i
].Respawn(False, True);
5249 if gGameSettings
.GameMode
= GM_COOP
then
5251 gPlayers
[i
].Frags
:= 0;
5252 gPlayers
[i
].RecallState
;
5254 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5255 gPlayer1
:= g_Player_Get(gLMSPID1
);
5256 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5257 gPlayer2
:= g_Player_Get(gLMSPID2
);
5260 g_Items_RestartRound();
5263 g_Mons_ForEach(monRespawn
);
5265 gLMSSoftSpawn
:= False;
5268 function g_Game_GetFirstMap(WAD
: String): String;
5272 MapList
:= g_Map_GetMapsList(WAD
);
5273 if MapList
= nil then
5276 SortSArray(MapList
);
5277 Result
:= MapList
[Low(MapList
)];
5279 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5285 function g_Game_GetNextMap(): String;
5292 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5293 if MapList
= nil then
5296 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5298 SortSArray(MapList
);
5300 for I
:= Low(MapList
) to High(MapList
) do
5301 if Map
= MapList
[I
] then
5307 if MapIndex
<> -255 then
5309 if MapIndex
= High(MapList
) then
5310 Result
:= MapList
[Low(MapList
)]
5312 Result
:= MapList
[MapIndex
+ 1];
5314 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5320 procedure g_Game_NextLevel();
5322 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5323 gExit
:= EXIT_ENDLEVELCUSTOM
5326 gExit
:= EXIT_ENDLEVELSINGLE
;
5330 if gNextMap
<> '' then Exit
;
5331 gNextMap
:= g_Game_GetNextMap();
5334 function g_Game_IsTestMap(): Boolean;
5336 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5339 procedure g_Game_DeleteTestMap();
5342 //MapName: AnsiString;
5350 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5351 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5352 if (a
= 0) then exit
;
5354 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5355 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5356 Delete(gMapToDelete
, 1, a
+5);
5357 gMapToDelete
:= UpperCase(gMapToDelete
);
5359 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5362 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5363 if MapName <> TEST_MAP_NAME then
5366 if not gTempDelete then
5368 time := g_GetFileTime(WadName);
5369 WAD := TWADFile.Create();
5372 if not WAD.ReadFile(WadName) then
5373 begin // Íåò òàêîãî WAD-ôàéëà
5378 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5380 MapList := WAD.GetResourcesList('');
5382 if MapList <> nil then
5383 for a := 0 to High(MapList) do
5384 if MapList[a] = MapName then
5386 // Óäàëÿåì è ñîõðàíÿåì:
5387 WAD.RemoveResource('', MapName);
5388 WAD.SaveTo(WadName);
5393 g_SetFileTime(WadName, time);
5396 if gTempDelete
then DeleteFile(WadName
);
5399 procedure GameCVars(P
: SSArray
);
5402 stat
: TPlayerStatArray
;
5407 cmd
:= LowerCase(P
[0]);
5408 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5410 with gGameSettings
do
5412 if (Length(P
) > 1) and
5413 ((P
[1] = '1') or (P
[1] = '0')) then
5415 if (P
[1][1] = '1') then
5416 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5418 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5421 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5422 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5424 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5426 if g_Game_IsNet
then MH_SEND_GameSettings
;
5429 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5431 with gGameSettings
do
5433 if (Length(P
) > 1) and
5434 ((P
[1] = '1') or (P
[1] = '0')) then
5436 if (P
[1][1] = '1') then
5437 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5439 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5442 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5443 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5445 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5447 if g_Game_IsNet
then MH_SEND_GameSettings
;
5450 else if cmd
= 'g_gamemode' then
5452 a
:= g_Game_TextToMode(P
[1]);
5453 if a
= GM_SINGLE
then a
:= GM_COOP
;
5454 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5456 gSwitchGameMode
:= a
;
5457 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5458 (gState
= STATE_INTERSINGLE
) then
5459 gSwitchGameMode
:= GM_SINGLE
;
5461 gGameSettings
.GameMode
:= gSwitchGameMode
;
5463 if gSwitchGameMode
= gGameSettings
.GameMode
then
5464 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5465 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5467 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5468 [g_Game_ModeToText(gGameSettings
.GameMode
),
5469 g_Game_ModeToText(gSwitchGameMode
)]));
5471 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5473 with gGameSettings
do
5475 if (Length(P
) > 1) and
5476 ((P
[1] = '1') or (P
[1] = '0')) then
5478 if (P
[1][1] = '1') then
5479 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5481 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5484 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5485 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5487 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5488 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5490 if g_Game_IsNet
then MH_SEND_GameSettings
;
5493 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5495 with gGameSettings
do
5497 if (Length(P
) > 1) and
5498 ((P
[1] = '1') or (P
[1] = '0')) then
5500 if (P
[1][1] = '1') then
5501 Options
:= Options
or GAME_OPTION_MONSTERS
5503 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5506 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5507 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5509 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5510 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5512 if g_Game_IsNet
then MH_SEND_GameSettings
;
5515 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5517 with gGameSettings
do
5519 if (Length(P
) > 1) and
5520 ((P
[1] = '1') or (P
[1] = '0')) then
5522 if (P
[1][1] = '1') then
5523 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5525 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5528 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5529 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5531 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5533 if g_Game_IsNet
then MH_SEND_GameSettings
;
5536 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5538 with gGameSettings
do
5540 if (Length(P
) > 1) and
5541 ((P
[1] = '1') or (P
[1] = '0')) then
5543 if (P
[1][1] = '1') then
5544 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5546 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5549 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5550 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5552 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5554 if g_Game_IsNet
then MH_SEND_GameSettings
;
5557 else if (cmd
= 'g_dm_keys') and not g_Game_IsClient
then
5559 with gGameSettings
do
5561 if (Length(P
) > 1) and
5562 ((P
[1] = '1') or (P
[1] = '0')) then
5564 if (P
[1][1] = '1') then
5565 Options
:= Options
or GAME_OPTION_DMKEYS
5567 Options
:= Options
and (not GAME_OPTION_DMKEYS
);
5570 if (LongBool(Options
and GAME_OPTION_DMKEYS
)) then
5571 g_Console_Add(_lc
[I_MSG_DMKEYS_ON
])
5573 g_Console_Add(_lc
[I_MSG_DMKEYS_OFF
]);
5574 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5576 if g_Game_IsNet
then MH_SEND_GameSettings
;
5579 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5581 if Length(P
) > 1 then
5583 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5584 gGameSettings
.WarmupTime
:= 30
5586 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5589 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5590 [gGameSettings
.WarmupTime
]));
5591 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5593 else if (cmd
= 'g_spawn_invul') and not g_Game_IsClient
then
5595 if Length(P
) > 1 then
5597 if StrToIntDef(P
[1], gGameSettings
.SpawnInvul
) = 0 then
5598 gGameSettings
.SpawnInvul
:= 0
5600 gGameSettings
.SpawnInvul
:= StrToIntDef(P
[1], gGameSettings
.SpawnInvul
);
5603 g_Console_Add(Format(_lc
[I_MSG_SPAWNINVUL
],
5604 [gGameSettings
.SpawnInvul
]));
5605 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5607 else if cmd
= 'net_interp' then
5609 if (Length(P
) > 1) then
5610 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5611 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5612 s
:= e_GetWriteableDir(ConfigDirs
);
5615 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5616 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5617 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5621 else if cmd
= 'net_forceplayerupdate' then
5623 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5624 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5626 if NetForcePlayerUpdate
then
5627 g_Console_Add('net_forceplayerupdate = 1')
5629 g_Console_Add('net_forceplayerupdate = 0');
5631 s
:= e_GetWriteableDir(ConfigDirs
);
5634 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5635 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5636 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5640 else if cmd
= 'net_predictself' then
5642 if (Length(P
) > 1) and
5643 ((P
[1] = '1') or (P
[1] = '0')) then
5644 NetPredictSelf
:= (P
[1][1] = '1');
5646 if NetPredictSelf
then
5647 g_Console_Add('net_predictself = 1')
5649 g_Console_Add('net_predictself = 0');
5651 s
:= e_GetWriteableDir(ConfigDirs
);
5654 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5655 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5656 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5660 else if cmd
= 'sv_name' then
5662 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5664 NetServerName
:= P
[1];
5665 if Length(NetServerName
) > 64 then
5666 SetLength(NetServerName
, 64);
5667 g_Net_Slist_ServerRenamed();
5670 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5672 else if cmd
= 'sv_passwd' then
5674 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5676 NetPassword
:= P
[1];
5677 if Length(NetPassword
) > 24 then
5678 SetLength(NetPassword
, 24);
5679 g_Net_Slist_ServerRenamed();
5682 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5684 else if cmd
= 'sv_maxplrs' then
5686 if (Length(P
) > 1) then
5688 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5689 if g_Game_IsServer
and g_Game_IsNet
then
5692 for a
:= 0 to High(NetClients
) do
5694 if NetClients
[a
].Used
then
5697 if b
> NetMaxClients
then
5699 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5700 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5701 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5702 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5706 g_Net_Slist_ServerRenamed();
5710 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5712 else if cmd
= 'sv_public' then
5714 if (Length(P
) > 1) then
5716 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5717 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5720 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5722 else if cmd
= 'sv_intertime' then
5724 if (Length(P
) > 1) then
5725 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5727 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5729 else if cmd
= 'p1_name' then
5731 if (Length(P
) > 1) and gGameOn
then
5733 if g_Game_IsClient
then
5735 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5736 MC_SEND_PlayerSettings
;
5739 if gPlayer1
<> nil then
5741 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5742 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5745 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5748 else if cmd
= 'p2_name' then
5750 if (Length(P
) > 1) and gGameOn
then
5752 if g_Game_IsClient
then
5754 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5755 MC_SEND_PlayerSettings
;
5758 if gPlayer2
<> nil then
5760 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5761 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5764 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5767 else if cmd
= 'p1_color' then
5769 if Length(P
) > 3 then
5770 if g_Game_IsClient
then
5772 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5773 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5774 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5775 MC_SEND_PlayerSettings
;
5778 if gPlayer1
<> nil then
5780 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5781 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5782 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5783 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5786 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5787 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5788 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5790 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5792 if Length(P
) > 3 then
5793 if g_Game_IsClient
then
5795 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5796 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5797 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5798 MC_SEND_PlayerSettings
;
5801 if gPlayer2
<> nil then
5803 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5804 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5805 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5806 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5809 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5810 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5811 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5813 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5815 if cmd
= 'r_showscore' then
5817 if (Length(P
) > 1) and
5818 ((P
[1] = '1') or (P
[1] = '0')) then
5819 gShowGoals
:= (P
[1][1] = '1');
5822 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5824 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5826 else if cmd
= 'r_showstat' then
5828 if (Length(P
) > 1) and
5829 ((P
[1] = '1') or (P
[1] = '0')) then
5830 gShowStat
:= (P
[1][1] = '1');
5833 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5835 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5837 else if cmd
= 'r_showkillmsg' then
5839 if (Length(P
) > 1) and
5840 ((P
[1] = '1') or (P
[1] = '0')) then
5841 gShowKillMsg
:= (P
[1][1] = '1');
5843 if gShowKillMsg
then
5844 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5846 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5848 else if cmd
= 'r_showlives' then
5850 if (Length(P
) > 1) and
5851 ((P
[1] = '1') or (P
[1] = '0')) then
5852 gShowLives
:= (P
[1][1] = '1');
5855 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5857 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5859 else if cmd
= 'r_showspect' then
5861 if (Length(P
) > 1) and
5862 ((P
[1] = '1') or (P
[1] = '0')) then
5863 gSpectHUD
:= (P
[1][1] = '1');
5866 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5868 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5870 else if cmd
= 'r_showping' then
5872 if (Length(P
) > 1) and
5873 ((P
[1] = '1') or (P
[1] = '0')) then
5874 gShowPing
:= (P
[1][1] = '1');
5877 g_Console_Add(_lc
[I_MSG_PING_ON
])
5879 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5881 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5883 if Length(P
) > 1 then
5885 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5886 gGameSettings
.GoalLimit
:= 0
5891 if gGameSettings
.GameMode
= GM_DM
then
5893 stat
:= g_Player_GetStats();
5895 for a
:= 0 to High(stat
) do
5896 if stat
[a
].Frags
> b
then
5900 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5902 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5905 if g_Game_IsNet
then MH_SEND_GameSettings
;
5908 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5910 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5912 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5913 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5915 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5916 [gGameSettings
.TimeLimit
div 3600,
5917 (gGameSettings
.TimeLimit
div 60) mod 60,
5918 gGameSettings
.TimeLimit
mod 60]));
5919 if g_Game_IsNet
then MH_SEND_GameSettings
;
5921 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5923 if Length(P
) > 1 then
5925 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5926 gGameSettings
.MaxLives
:= 0
5930 stat
:= g_Player_GetStats();
5932 for a
:= 0 to High(stat
) do
5933 if stat
[a
].Lives
> b
then
5935 gGameSettings
.MaxLives
:=
5936 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5940 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5941 [gGameSettings
.MaxLives
]));
5942 if g_Game_IsNet
then MH_SEND_GameSettings
;
5947 procedure PrintHeapStats();
5951 hs
:= GetFPCHeapStatus();
5952 e_LogWriteLn ('v===== heap status =====v');
5953 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5954 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5955 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5956 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5957 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5958 e_LogWriteLn ('^=======================^');
5961 procedure DebugCommands(P
: SSArray
);
5968 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5969 if {gDebugMode}conIsCheatsEnabled
then
5971 cmd
:= LowerCase(P
[0]);
5972 if cmd
= 'd_window' then
5974 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5975 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5977 else if cmd
= 'd_sounds' then
5979 if (Length(P
) > 1) and
5980 ((P
[1] = '1') or (P
[1] = '0')) then
5981 g_Debug_Sounds
:= (P
[1][1] = '1');
5983 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5985 else if cmd
= 'd_frames' then
5987 if (Length(P
) > 1) and
5988 ((P
[1] = '1') or (P
[1] = '0')) then
5989 g_Debug_Frames
:= (P
[1][1] = '1');
5991 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5993 else if cmd
= 'd_winmsg' then
5995 if (Length(P
) > 1) and
5996 ((P
[1] = '1') or (P
[1] = '0')) then
5997 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5999 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6001 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6003 if (Length(P
) > 1) and
6004 ((P
[1] = '1') or (P
[1] = '0')) then
6005 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6007 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6009 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6011 if Length(P
) > 1 then
6013 '0': g_debug_BotAIOff
:= 0;
6014 '1': g_debug_BotAIOff
:= 1;
6015 '2': g_debug_BotAIOff
:= 2;
6016 '3': g_debug_BotAIOff
:= 3;
6019 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6021 else if cmd
= 'd_monster' then
6023 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6024 if Length(P
) < 2 then
6026 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6027 g_Console_Add('ID | Name');
6028 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6029 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6030 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6033 a
:= StrToIntDef(P
[1], 0);
6034 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6035 a
:= g_Mons_TypeIdByName(P
[1]);
6037 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6038 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6041 with gPlayer1
.Obj
do
6043 mon
:= g_Monsters_Create(a
,
6044 X
+ Rect
.X
+ (Rect
.Width
div 2),
6045 Y
+ Rect
.Y
+ Rect
.Height
,
6046 gPlayer1
.Direction
, True);
6048 if (Length(P
) > 2) and (mon
<> nil) then
6050 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6051 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6052 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6053 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6054 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6055 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6056 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6057 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6058 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6063 else if (cmd
= 'd_health') then
6065 if (Length(P
) > 1) and
6066 ((P
[1] = '1') or (P
[1] = '0')) then
6067 g_debug_HealthBar
:= (P
[1][1] = '1');
6069 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6071 else if (cmd
= 'd_player') then
6073 if (Length(P
) > 1) and
6074 ((P
[1] = '1') or (P
[1] = '0')) then
6075 g_debug_Player
:= (P
[1][1] = '1');
6077 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6079 else if (cmd
= 'd_mem') then
6085 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6089 procedure GameCheats(P
: SSArray
);
6095 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6097 g_Console_Add('not available');
6103 g_Console_Add('where is the player?!');
6106 cmd
:= LowerCase(P
[0]);
6110 plr
.GodMode
:= not plr
.GodMode
;
6111 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6114 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6115 if cmd
= 'give' then
6117 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6118 for f
:= 1 to High(P
) do
6120 cmd
:= LowerCase(P
[f
]);
6121 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6122 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6123 if cmd
= 'exit' then
6125 if gTriggers
<> nil then
6127 for a
:= 0 to High(gTriggers
) do
6129 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6131 g_Console_Add('player left the map');
6132 gExitByTrigger
:= True;
6133 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6134 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6142 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6143 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6144 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6145 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6146 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6148 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6149 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6151 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6152 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;
6154 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6155 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6157 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6158 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6160 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6161 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6163 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6164 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6165 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6167 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6168 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6169 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6170 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;
6171 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6172 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6174 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;
6175 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;
6176 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;
6177 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;
6178 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;
6179 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;
6181 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6182 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;
6184 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;
6185 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;
6187 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6189 if cmd
= 'ammo' then
6191 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6192 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6193 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6194 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6195 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6196 g_Console_Add('player got some ammo');
6200 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6201 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6203 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6204 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6206 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6207 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6209 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6210 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6212 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6214 if cmd
= 'weapons' then
6216 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6217 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6218 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6219 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6220 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6221 plr
.GiveItem(ITEM_WEAPON_BFG
);
6222 g_Console_Add('player got weapons');
6226 if cmd
= 'keys' then
6228 plr
.GiveItem(ITEM_KEY_RED
);
6229 plr
.GiveItem(ITEM_KEY_GREEN
);
6230 plr
.GiveItem(ITEM_KEY_BLUE
);
6231 g_Console_Add('player got all keys');
6235 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6240 if cmd
= 'open' then
6242 g_Console_Add('player activated sesame');
6243 g_Triggers_OpenAll();
6250 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6254 if cmd
= 'noclip' then
6257 g_Console_Add('wall hardeness adjusted');
6261 if cmd
= 'notarget' then
6263 plr
.NoTarget
:= not plr
.NoTarget
;
6264 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6268 if cmd
= 'noreload' then
6270 plr
.NoReload
:= not plr
.NoReload
;
6271 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6275 if cmd
= 'speedy' then
6277 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6278 g_Console_Add('speed adjusted');
6282 if cmd
= 'jumpy' then
6284 VEL_JUMP
:= 30-VEL_JUMP
;
6285 g_Console_Add('jump height adjusted');
6289 if cmd
= 'automap' then
6291 gShowMap
:= not gShowMap
;
6292 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6296 if cmd
= 'aimline' then
6298 gAimLine
:= not gAimLine
;
6299 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6304 procedure GameCommands(P
: SSArray
);
6310 pl
: pTNetClient
= nil;
6318 cmd
:= LowerCase(P
[0]);
6320 if (cmd
= 'quit') or
6327 else if cmd
= 'pause' then
6329 if (g_ActiveWindow
= nil) then
6330 g_Game_Pause(not gPauseMain
);
6332 else if cmd
= 'endgame' then
6333 gExit
:= EXIT_SIMPLE
6334 else if cmd
= 'restart' then
6336 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6338 if g_Game_IsClient
then
6340 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6345 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6347 else if cmd
= 'kick' then
6349 if g_Game_IsServer
then
6351 if Length(P
) < 2 then
6353 g_Console_Add('kick <name>');
6358 g_Console_Add('kick <name>');
6362 if g_Game_IsNet
then
6363 pl
:= g_Net_Client_ByName(P
[1]);
6366 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6367 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6368 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6369 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6370 g_Net_Slist_ServerPlayerLeaves();
6371 end else if gPlayers
<> nil then
6372 for a
:= Low(gPlayers
) to High(gPlayers
) do
6373 if gPlayers
[a
] <> nil then
6374 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6376 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6377 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6379 gPlayers
[a
].Lives
:= 0;
6380 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6381 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6382 g_Player_Remove(gPlayers
[a
].UID
);
6383 g_Net_Slist_ServerPlayerLeaves();
6384 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6388 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6390 else if cmd
= 'kick_id' then
6392 if g_Game_IsServer
and g_Game_IsNet
then
6394 if Length(P
) < 2 then
6396 g_Console_Add('kick_id <client ID>');
6401 g_Console_Add('kick_id <client ID>');
6405 a
:= StrToIntDef(P
[1], 0);
6406 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6408 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6410 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6411 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6412 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6413 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6414 g_Net_Slist_ServerPlayerLeaves();
6418 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6420 else if cmd
= 'ban' then
6422 if g_Game_IsServer
and g_Game_IsNet
then
6424 if Length(P
) < 2 then
6426 g_Console_Add('ban <name>');
6431 g_Console_Add('ban <name>');
6435 pl
:= g_Net_Client_ByName(P
[1]);
6438 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6439 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6440 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6441 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6442 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6443 g_Net_Slist_ServerPlayerLeaves();
6445 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6447 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6449 else if cmd
= 'ban_id' then
6451 if g_Game_IsServer
and g_Game_IsNet
then
6453 if Length(P
) < 2 then
6455 g_Console_Add('ban_id <client ID>');
6460 g_Console_Add('ban_id <client ID>');
6464 a
:= StrToIntDef(P
[1], 0);
6465 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6466 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6468 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6469 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6470 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6471 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6472 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6473 g_Net_Slist_ServerPlayerLeaves();
6476 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6478 else if cmd
= 'permban' then
6480 if g_Game_IsServer
and g_Game_IsNet
then
6482 if Length(P
) < 2 then
6484 g_Console_Add('permban <name>');
6489 g_Console_Add('permban <name>');
6493 pl
:= g_Net_Client_ByName(P
[1]);
6496 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6497 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6498 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6499 g_Net_SaveBanList();
6500 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6501 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6502 g_Net_Slist_ServerPlayerLeaves();
6504 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6506 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6508 else if cmd
= 'permban_id' then
6510 if g_Game_IsServer
and g_Game_IsNet
then
6512 if Length(P
) < 2 then
6514 g_Console_Add('permban_id <client ID>');
6519 g_Console_Add('permban_id <client ID>');
6523 a
:= StrToIntDef(P
[1], 0);
6524 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6525 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6527 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6528 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6529 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6530 g_Net_SaveBanList();
6531 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6532 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6533 g_Net_Slist_ServerPlayerLeaves();
6536 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6538 else if cmd
= 'unban' then
6540 if g_Game_IsServer
and g_Game_IsNet
then
6542 if Length(P
) < 2 then
6544 g_Console_Add('unban <IP Address>');
6549 g_Console_Add('unban <IP Address>');
6553 if g_Net_UnbanHost(P
[1]) then
6555 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6556 g_Net_SaveBanList();
6558 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6560 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6562 else if cmd
= 'clientlist' then
6564 if g_Game_IsServer
and g_Game_IsNet
then
6567 if NetClients
<> nil then
6568 for a
:= Low(NetClients
) to High(NetClients
) do
6569 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6571 plr
:= g_Player_Get(NetClients
[a
].Player
);
6572 if plr
= nil then continue
;
6574 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6575 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6578 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6580 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6582 else if cmd
= 'connect' then
6584 if (NetMode
= NET_NONE
) then
6586 if Length(P
) < 2 then
6588 g_Console_Add('connect <IP> [port] [password]');
6593 g_Console_Add('connect <IP> [port] [password]');
6597 if Length(P
) > 2 then
6598 prt
:= StrToIntDef(P
[2], 25666)
6602 if Length(P
) > 3 then
6607 g_Game_StartClient(P
[1], prt
, pw
);
6610 else if cmd
= 'disconnect' then
6612 if (NetMode
= NET_CLIENT
) then
6615 else if cmd
= 'reconnect' then
6617 if (NetMode
= NET_SERVER
) then
6620 if (NetMode
= NET_CLIENT
) then
6623 gExit
:= EXIT_SIMPLE
;
6627 //TODO: Use last successful password to reconnect, instead of ''
6628 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6630 else if (cmd
= 'addbot') or
6631 (cmd
= 'bot_add') then
6633 if Length(P
) > 2 then
6634 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6635 else if Length(P
) > 1 then
6636 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6638 g_Bot_Add(TEAM_NONE
, 2);
6640 else if cmd
= 'bot_addlist' then
6642 if Length(P
) > 1 then
6644 if Length(P
) = 2 then
6645 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6646 else if Length(P
) = 3 then
6647 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6649 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6652 else if cmd
= 'bot_removeall' then
6654 else if cmd
= 'chat' then
6656 if g_Game_IsNet
then
6658 if Length(P
) > 1 then
6660 for a
:= 1 to High(P
) do
6661 chstr
:= chstr
+ P
[a
] + ' ';
6663 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6665 if Length(chstr
) < 1 then
6667 g_Console_Add('chat <text>');
6671 chstr
:= b_Text_Format(chstr
);
6672 if g_Game_IsClient
then
6673 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6675 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6678 g_Console_Add('chat <text>');
6680 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6682 else if cmd
= 'teamchat' then
6684 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6686 if Length(P
) > 1 then
6688 for a
:= 1 to High(P
) do
6689 chstr
:= chstr
+ P
[a
] + ' ';
6691 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6693 if Length(chstr
) < 1 then
6695 g_Console_Add('teamchat <text>');
6699 chstr
:= b_Text_Format(chstr
);
6700 if g_Game_IsClient
then
6701 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6703 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6704 gPlayer1Settings
.Team
);
6707 g_Console_Add('teamchat <text>');
6709 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6711 else if cmd
= 'game' then
6713 if gGameSettings
.GameType
<> GT_NONE
then
6715 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6718 if Length(P
) = 1 then
6720 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6723 // game not started yet, load fist map from some wad
6725 s
:= addWadExtension(P
[1]);
6726 found
:= e_FindResource(AllMapDirs
, s
);
6730 P
[1] := ExpandFileName(P
[1]);
6731 // if map not choosed then set first map
6732 if Length(P
) < 3 then
6735 P
[2] := g_Game_GetFirstMap(P
[1]);
6738 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6740 if g_Map_Exist(s
) then
6744 with gGameSettings
do
6746 GameMode
:= g_Game_TextToMode(gcGameMode
);
6747 if gSwitchGameMode
<> GM_NONE
then
6748 GameMode
:= gSwitchGameMode
;
6749 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6750 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6752 if Length(P
) >= 4 then
6753 b
:= StrToIntDef(P
[3], 1);
6754 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6755 GoalLimit
, MaxLives
, Options
, b
);
6760 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6762 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6764 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6766 else if cmd
= 'host' then
6768 if gGameSettings
.GameType
<> GT_NONE
then
6770 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6773 if Length(P
) < 4 then
6775 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6778 if not StrToIp(P
[1], listen
) then
6780 prt
:= StrToIntDef(P
[2], 25666);
6782 s
:= addWadExtension(P
[3]);
6783 found
:= e_FindResource(AllMapDirs
, s
);
6787 // get first map in wad, if not specified
6788 if Length(P
) < 5 then
6791 P
[4] := g_Game_GetFirstMap(P
[1]);
6793 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6794 if g_Map_Exist(s
) then
6798 with gGameSettings
do
6800 GameMode
:= g_Game_TextToMode(gcGameMode
);
6801 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6802 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6803 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6805 if Length(P
) >= 6 then
6806 b
:= StrToIntDef(P
[5], 0);
6807 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6813 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6815 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6820 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6823 else if cmd
= 'map' then
6825 if Length(P
) = 1 then
6827 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6829 g_Console_Add(cmd
+ ' <MAP>');
6830 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6834 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6839 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6841 if Length(P
) < 3 then
6843 // first param is map or wad
6844 s
:= UpperCase(P
[1]);
6845 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6847 gExitByTrigger
:= False;
6850 // already in game, finish current map
6852 gExit
:= EXIT_ENDLEVELCUSTOM
;
6856 // intermission, so change map immediately
6863 found
:= e_FindResource(AllMapDirs
, s
);
6865 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6868 // no such map, found wad
6871 P
[1] := ExpandFileName(pw
);
6872 P
[2] := g_Game_GetFirstMap(P
[1]);
6873 s
:= P
[1] + ':\' + P
[2];
6874 if g_Map_Exist(s
) then
6876 gExitByTrigger
:= False;
6879 // already in game, finish current map
6881 gExit
:= EXIT_ENDLEVELCUSTOM
6885 // intermission, so change map immediately
6892 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6894 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6899 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6905 s
:= addWadExtension(P
[1]);
6906 found
:= e_FindResource(AllMapDirs
, s
);
6910 P
[2] := UpperCase(P
[2]);
6911 s
:= P
[1] + ':\' + P
[2];
6912 if g_Map_Exist(s
) then
6914 gExitByTrigger
:= False;
6918 gExit
:= EXIT_ENDLEVELCUSTOM
6927 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6932 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6938 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6942 else if cmd
= 'nextmap' then
6944 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6946 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6951 if Length(P
) = 1 then
6953 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6955 g_Console_Add(cmd
+ ' <MAP>');
6956 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6961 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6967 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6969 if Length(P
) < 3 then
6971 // first param is map or wad
6972 s
:= UpperCase(P
[1]);
6973 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6976 gExitByTrigger
:= False;
6982 // no such map, found wad
6983 pw
:= addWadExtension(P
[1]);
6984 found
:= e_FindResource(MapDirs
, pw
);
6986 found
:= e_FindResource(WadDirs
, pw
);
6988 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6991 // map not specified, select first map
6993 P
[2] := g_Game_GetFirstMap(P
[1]);
6994 s
:= P
[1] + ':\' + P
[2];
6995 if g_Map_Exist(s
) then
6997 gExitByTrigger
:= False;
7004 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7006 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7011 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7017 // specified two params wad + map
7018 pw
:= addWadExtension(P
[1]);
7019 found
:= e_FindResource(MapDirs
, pw
);
7021 found
:= e_FindResource(MapDirs
, pw
);
7025 P
[2] := UpperCase(P
[2]);
7026 s
:= P
[1] + ':\' + P
[2];
7027 if g_Map_Exist(s
) then
7029 gExitByTrigger
:= False;
7035 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7040 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7046 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7051 if gNextMap
= '' then
7052 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7054 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7058 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7062 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7066 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7068 gExitByTrigger
:= False;
7069 // next map not specified, try to find trigger EXIT
7070 if (gNextMap
= '') and (gTriggers
<> nil) then
7072 for a
:= 0 to High(gTriggers
) do
7074 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7076 gExitByTrigger
:= True;
7077 //gNextMap := gTriggers[a].Data.MapName;
7078 gNextMap
:= gTriggers
[a
].tgcMap
;
7083 if gNextMap
= '' then
7084 gNextMap
:= g_Game_GetNextMap();
7085 if not isWadPath(gNextMap
) then
7086 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7089 if g_Map_Exist(s
) then
7090 gExit
:= EXIT_ENDLEVELCUSTOM
7092 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7096 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7100 else if (cmd
= 'event') then
7102 if (Length(P
) <= 1) then
7104 for a
:= 0 to High(gEvents
) do
7105 if gEvents
[a
].Command
= '' then
7106 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7108 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7111 if (Length(P
) = 2) then
7113 for a
:= 0 to High(gEvents
) do
7114 if gEvents
[a
].Name
= P
[1] then
7115 if gEvents
[a
].Command
= '' then
7116 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7118 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7121 for a
:= 0 to High(gEvents
) do
7122 if gEvents
[a
].Name
= P
[1] then
7124 gEvents
[a
].Command
:= '';
7125 for b
:= 2 to High(P
) do
7126 if Pos(' ', P
[b
]) = 0 then
7127 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7129 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7130 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7134 else if cmd
= 'suicide' then
7138 if g_Game_IsClient
then
7139 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7142 if gPlayer1
<> nil then
7143 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7144 if gPlayer2
<> nil then
7145 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7149 else if cmd
= 'screenshot' then
7153 else if cmd
= 'weapon' then
7155 if Length(p
) = 2 then
7157 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7158 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7159 gSelectWeapon
[0, a
] := True
7162 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7164 if Length(p
) = 2 then
7166 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7167 b
:= ord(cmd
[2]) - ord('1');
7168 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7169 gSelectWeapon
[b
, a
] := True
7172 // Êîìàíäû Ñâîåé èãðû:
7173 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7175 if cmd
= 'bot_addred' then
7177 if Length(P
) > 1 then
7178 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7180 g_Bot_Add(TEAM_RED
, 2);
7182 else if cmd
= 'bot_addblue' then
7184 if Length(P
) > 1 then
7185 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7187 g_Bot_Add(TEAM_BLUE
, 2);
7189 else if cmd
= 'spectate' then
7195 else if cmd
= 'say' then
7197 if g_Game_IsServer
and g_Game_IsNet
then
7199 if Length(P
) > 1 then
7202 for a
:= 1 to High(P
) do
7203 chstr
:= chstr
+ P
[a
] + ' ';
7205 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7207 if Length(chstr
) < 1 then
7209 g_Console_Add('say <text>');
7213 chstr
:= b_Text_Format(chstr
);
7214 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7216 else g_Console_Add('say <text>');
7218 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7220 else if cmd
= 'tell' then
7222 if g_Game_IsServer
and g_Game_IsNet
then
7224 if (Length(P
) > 2) and (P
[1] <> '') then
7227 for a
:= 2 to High(P
) do
7228 chstr
:= chstr
+ P
[a
] + ' ';
7230 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7232 if Length(chstr
) < 1 then
7234 g_Console_Add('tell <playername> <text>');
7238 pl
:= g_Net_Client_ByName(P
[1]);
7240 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7242 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7244 else g_Console_Add('tell <playername> <text>');
7246 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7248 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7250 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7252 // Äîïîëíèòåëüíîå âðåìÿ:
7253 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7255 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7256 [gGameSettings
.TimeLimit
div 3600,
7257 (gGameSettings
.TimeLimit
div 60) mod 60,
7258 gGameSettings
.TimeLimit
mod 60]));
7259 if g_Game_IsNet
then MH_SEND_GameSettings
;
7261 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7263 if (Length(P
) <= 1) then
7264 g_Console_Add('rcon_password <password>')
7266 MC_SEND_RCONPassword(P
[1]);
7268 else if cmd
= 'rcon' then
7270 if g_Game_IsClient
then
7272 if Length(P
) > 1 then
7275 for a
:= 1 to High(P
) do
7276 chstr
:= chstr
+ P
[a
] + ' ';
7278 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7280 if Length(chstr
) < 1 then
7282 g_Console_Add('rcon <command>');
7286 MC_SEND_RCONCommand(chstr
);
7288 else g_Console_Add('rcon <command>');
7291 else if cmd
= 'ready' then
7293 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7294 gLMSRespawnTime
:= gTime
+ 100;
7296 else if (cmd
= 'callvote') and g_Game_IsNet
then
7298 if Length(P
) > 1 then
7301 for a
:= 1 to High(P
) do begin
7302 if a
> 1 then chstr
:= chstr
+ ' ';
7303 chstr
:= chstr
+ P
[a
];
7306 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7308 if Length(chstr
) < 1 then
7310 g_Console_Add('callvote <command>');
7314 if g_Game_IsClient
then
7315 MC_SEND_Vote(True, chstr
)
7317 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7318 g_Console_Process('vote', True);
7321 g_Console_Add('callvote <command>');
7323 else if (cmd
= 'vote') and g_Game_IsNet
then
7325 if g_Game_IsClient
then
7327 else if gVoteInProgress
then
7329 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7330 a
:= Floor((NetClientCount
+1)/2.0) + 1
7332 a
:= Floor(NetClientCount
/2.0) + 1;
7337 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7338 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7344 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7345 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7353 procedure g_TakeScreenShot(Filename
: string = '');
7354 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7356 if e_NoGraphics
then Exit
;
7358 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7360 if Filename
= '' then
7363 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7364 Filename
:= 'screenshot-' + date
;
7367 name
:= e_CatPath(dir
, Filename
+ '.png');
7368 s
:= createDiskFile(name
);
7370 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7372 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7374 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7379 g_Console_Add('oh shit, i can''t create screenshot!')
7383 procedure g_Game_InGameMenu(Show
: Boolean);
7385 if (g_ActiveWindow
= nil) and Show
then
7387 if gGameSettings
.GameType
= GT_SINGLE
then
7388 g_GUI_ShowWindow('GameSingleMenu')
7391 if g_Game_IsClient
then
7392 g_GUI_ShowWindow('GameClientMenu')
7394 if g_Game_IsNet
then
7395 g_GUI_ShowWindow('GameServerMenu')
7397 g_GUI_ShowWindow('GameCustomMenu');
7399 g_Sound_PlayEx('MENU_OPEN');
7401 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7402 if (not g_Game_IsNet
) then
7406 if (g_ActiveWindow
<> nil) and (not Show
) then
7408 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7409 if (not g_Game_IsNet
) then
7410 g_Game_Pause(False);
7414 procedure g_Game_Pause (Enable
: Boolean);
7418 if not gGameOn
then exit
;
7420 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7423 gPauseMain
:= Enable
;
7425 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7428 procedure g_Game_HolmesPause (Enable
: Boolean);
7432 if not gGameOn
then exit
;
7433 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7436 gPauseHolmes
:= Enable
;
7438 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7441 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7446 if gTriggers
<> nil then
7447 for i
:= 0 to High(gTriggers
) do
7448 with gTriggers
[i
] do
7449 if (TriggerType
= TRIGGER_SOUND
) and
7451 Sound
.IsPlaying() then
7453 Sound
.Pause(Enable
);
7457 if gPlayers
<> nil then
7458 for i
:= 0 to High(gPlayers
) do
7459 if gPlayers
[i
] <> nil then
7460 gPlayers
[i
].PauseSounds(Enable
);
7463 if gMusic
<> nil then
7464 gMusic
.Pause(Enable
);
7467 procedure g_Game_StopAllSounds(all
: Boolean);
7471 if gTriggers
<> nil then
7472 for i
:= 0 to High(gTriggers
) do
7473 with gTriggers
[i
] do
7474 if (TriggerType
= TRIGGER_SOUND
) and
7478 if gMusic
<> nil then
7485 procedure g_Game_UpdateTriggerSounds
;
7488 if gTriggers
<> nil then
7489 for i
:= 0 to High(gTriggers
) do
7490 with gTriggers
[i
] do
7491 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7492 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7495 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7498 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7503 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7508 if gSpectMode
<> SPECT_PLAYERS
then
7510 if gSpectPID1
= UID
then
7515 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7522 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7527 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7532 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7537 if gSpectMode
<> SPECT_PLAYERS
then
7539 Pl
:= g_Player_Get(gSpectPID1
);
7540 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7545 if gSpectViewTwo
then
7547 Pl
:= g_Player_Get(gSpectPID2
);
7548 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7556 procedure g_Game_Message(Msg
: string; Time
: Word);
7558 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7559 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7560 MessageTime
:= Time
;
7563 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7565 punct
: Array[0..13] of String =
7566 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7572 function IsPunctuation(S
: String): Boolean;
7577 if Length(S
) <> 1 then
7579 for i
:= Low(punct
) to High(punct
) do
7580 if S
= punct
[i
] then
7586 function FilterPunctuation(S
: String): String;
7590 for i
:= Low(punct
) to High(punct
) do
7591 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7597 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7599 // remove player name
7600 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7601 // for FullWord check
7602 Text := toLowerCase1251(' ' + Text + ' ');
7603 fpText
:= FilterPunctuation(Text);
7605 for i
:= 0 to Length(gChatSounds
) - 1 do
7608 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7610 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7611 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7613 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7619 gChatSounds
[i
].Sound
.Play();
7625 g_Sound_PlayEx('SOUND_GAME_RADIO');
7628 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7637 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7641 if goodsnd
[a
].IsPlaying() then
7644 goodsnd
[Random(4)].Play();
7647 procedure g_Game_Announce_KillCombo(Param
: Integer);
7654 UID
:= Param
and $FFFF;
7659 Pl
:= g_Player_Get(UID
);
7668 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7672 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7676 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7680 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7688 if not g_Game_IsWatchedPlayer(UID
) then
7691 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7695 if killsnd
[n
].IsPlaying() then
7700 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7709 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7713 if hahasnd
[a
].IsPlaying() then
7716 hahasnd
[Random(3)].Play();
7719 procedure g_Game_StartVote(Command
, Initiator
: string);
7723 if not gVotesEnabled
then Exit
;
7724 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7725 if gVoteInProgress
or gVotePassed
then
7727 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7728 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7731 gVoteInProgress
:= True;
7732 gVotePassed
:= False;
7733 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7736 gVoteCommand
:= Command
;
7738 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7739 Need
:= Floor((NetClientCount
+1)/2.0)+1
7741 Need
:= Floor(NetClientCount
/2.0)+1;
7742 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7743 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7746 procedure g_Game_CheckVote
;
7750 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7751 if not gVoteInProgress
then Exit
;
7753 if (gTime
>= gVoteTimer
) then
7755 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7756 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7758 Need
:= Floor(NetClientCount
/2.0) + 1;
7759 if gVoteCount
>= Need
then
7761 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7762 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7763 gVotePassed
:= True;
7764 gVoteCmdTimer
:= gTime
+ 5000;
7768 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7769 MH_SEND_VoteEvent(NET_VE_FAILED
);
7771 if NetClients
<> nil then
7772 for I
:= Low(NetClients
) to High(NetClients
) do
7773 if NetClients
[i
].Used
then
7774 NetClients
[i
].Voted
:= False;
7775 gVoteInProgress
:= False;
7781 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7782 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7784 Need
:= Floor(NetClientCount
/2.0) + 1;
7785 if gVoteCount
>= Need
then
7787 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7788 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7789 gVoteInProgress
:= False;
7790 gVotePassed
:= True;
7791 gVoteCmdTimer
:= gTime
+ 5000;
7794 if NetClients
<> nil then
7795 for I
:= Low(NetClients
) to High(NetClients
) do
7796 if NetClients
[i
].Used
then
7797 NetClients
[i
].Voted
:= False;
7802 procedure g_Game_LoadMapList(FileName
: string);
7810 if not FileExists(FileName
) then Exit
;
7812 AssignFile(ListFile
, FileName
);
7814 while not EOF(ListFile
) do
7816 ReadLn(ListFile
, s
);
7819 if s
= '' then Continue
;
7821 SetLength(MapList
, Length(MapList
)+1);
7822 MapList
[High(MapList
)] := s
;
7824 CloseFile(ListFile
);
7827 procedure g_Game_SetDebugMode();
7830 // ×èòû (äàæå â ñâîåé èãðå):
7834 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7838 if Length(LoadingStat
.Msgs
) = 0 then
7844 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7845 if NextMsg
= Length(Msgs
) then
7847 for i
:= 0 to High(Msgs
)-1 do
7848 Msgs
[i
] := Msgs
[i
+1];
7856 Msgs
[NextMsg
-1] := Text;
7860 PBarWasHere
:= false;
7863 g_ActiveWindow
:= nil;
7865 ProcessLoading(true);
7868 procedure g_Game_StepLoading(Value
: Integer = -1);
7879 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7887 procedure g_Game_ClearLoading();
7896 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7897 if len
< 1 then len
:= 1;
7898 SetLength(Msgs
, len
);
7899 for len
:= Low(Msgs
) to High(Msgs
) do
7902 PBarWasHere
:= false;
7906 procedure Parse_Params(var pars
: TParamStrValues
);
7913 while i
<= ParamCount
do
7916 if (s
[1] = '-') and (Length(s
) > 1) then
7918 if (s
[2] = '-') and (Length(s
) > 2) then
7919 begin // Îäèíî÷íûé ïàðàìåòð
7920 SetLength(pars
, Length(pars
) + 1);
7921 with pars
[High(pars
)] do
7923 Name
:= LowerCase(s
);
7928 if (i
< ParamCount
) then
7929 begin // Ïàðàìåòð ñî çíà÷åíèåì
7931 SetLength(pars
, Length(pars
) + 1);
7932 with pars
[High(pars
)] do
7934 Name
:= LowerCase(s
);
7935 Value
:= LowerCase(ParamStr(i
));
7944 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7949 for i
:= 0 to High(pars
) do
7950 if pars
[i
].Name
= aName
then
7952 Result
:= pars
[i
].Value
;
7957 procedure g_Game_Process_Params();
7959 pars
: TParamStrValues
;
7962 LimT
, LimS
: Integer;
7973 s
:= Find_Param_Value(pars
, '--debug');
7976 g_Game_SetDebugMode();
7977 s
:= Find_Param_Value(pars
, '--netdump');
7982 // Connect when game loads
7983 ip
:= Find_Param_Value(pars
, '-connect');
7987 s
:= Find_Param_Value(pars
, '-port');
7988 if (s
= '') or not TryStrToInt(s
, Port
) then
7991 s
:= Find_Param_Value(pars
, '-pw');
7993 g_Game_StartClient(ip
, Port
, s
);
7997 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8000 gDefaultMegawadStart
:= s
;
8003 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8004 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8006 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8009 // Start map when game loads:
8010 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8011 if isWadPath(map
) then
8014 s
:= Find_Param_Value(pars
, '-gm');
8015 GMode
:= g_Game_TextToMode(s
);
8016 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8017 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8020 s
:= Find_Param_Value(pars
, '-limt');
8021 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8027 s
:= Find_Param_Value(pars
, '-lims');
8028 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8034 s
:= Find_Param_Value(pars
, '-lives');
8035 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8041 s
:= Find_Param_Value(pars
, '-opt');
8043 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
8045 Opt
:= StrToIntDef(s
, 0);
8047 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
8050 s
:= Find_Param_Value(pars
, '--close');
8054 // Override map to test:
8055 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8058 if e_IsValidResourceName(s
) then
8059 e_FindResource(AllMapDirs
, s
);
8060 gTestMap
:= ExpandFileName(s
);
8063 // Delete test map after play:
8064 s
:= Find_Param_Value(pars
, '--testdelete');
8067 //gMapToDelete := MapsDir + map;
8068 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8072 // Delete temporary WAD after play:
8073 s
:= Find_Param_Value(pars
, '--tempdelete');
8074 if (s
<> '') and (gTestMap
<> '') then
8076 gMapToDelete
:= gTestMap
;
8077 gTempDelete
:= True;
8080 // Number of players:
8081 s
:= Find_Param_Value(pars
, '-pl');
8083 n
:= DEFAULT_PLAYERS
8085 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8088 s
:= Find_Param_Value(pars
, '-port');
8089 if (s
= '') or not TryStrToInt(s
, Port
) then
8090 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8092 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8095 // Execute script when game loads:
8096 s
:= Find_Param_Value(pars
, '-exec');
8099 // if not isWadPath(s) then
8100 // s := GameDir + '/' + s;
8105 if IOResult
<> 0 then
8107 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8108 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8112 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8113 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8118 if IOResult
<> 0 then
8120 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8121 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8125 if Pos('#', s
) <> 1 then // script comment
8126 g_Console_Process(s
, True);
8137 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8138 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8139 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8140 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8142 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8143 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8144 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8145 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8147 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8148 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8150 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8151 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8153 {$IFDEF ENABLE_HOLMES}
8154 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8157 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8159 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8161 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8162 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8164 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8165 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8167 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8168 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');