1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_basic
, g_player
, e_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
44 TDelayedEvent
= record
53 Sound
: TPlayableSound
;
54 Tags
: Array of String;
58 TPlayerSettings
= record
77 function g_Game_IsNet(): Boolean;
78 function g_Game_IsServer(): Boolean;
79 function g_Game_IsClient(): Boolean;
80 procedure g_Game_Init();
81 procedure g_Game_Free (freeTextures
: Boolean=true);
82 procedure g_Game_LoadData();
83 procedure g_Game_FreeData();
84 procedure g_Game_Update();
85 procedure g_Game_Draw();
86 procedure g_Game_Quit();
87 procedure g_Game_SetupScreenSize();
88 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
89 function g_Game_ModeToText(Mode
: Byte): string;
90 function g_Game_TextToMode(Mode
: string): Byte;
91 procedure g_Game_ExecuteEvent(Name
: String);
92 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
93 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
94 procedure g_Game_RemovePlayer();
95 procedure g_Game_Spectate();
96 procedure g_Game_SpectateCenterView();
97 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
98 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
99 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
100 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
101 procedure g_Game_Restart();
102 procedure g_Game_RestartLevel();
103 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
104 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
105 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
106 procedure g_Game_ChangeMap(const MapPath
: String);
107 procedure g_Game_ExitLevel(const Map
: AnsiString);
108 function g_Game_GetFirstMap(WAD
: String): String;
109 function g_Game_GetNextMap(): String;
110 procedure g_Game_NextLevel();
111 procedure g_Game_Pause(Enable
: Boolean);
112 procedure g_Game_HolmesPause(Enable
: Boolean);
113 procedure g_Game_InGameMenu(Show
: Boolean);
114 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
115 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
116 procedure g_Game_Message(Msg
: String; Time
: Word);
117 procedure g_Game_LoadMapList(FileName
: String);
118 procedure g_Game_PauseAllSounds(Enable
: Boolean);
119 procedure g_Game_StopAllSounds(all
: Boolean);
120 procedure g_Game_UpdateTriggerSounds();
121 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
122 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
123 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
124 procedure g_Game_Announce_KillCombo(Param
: Integer);
125 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
126 procedure g_Game_StartVote(Command
, Initiator
: string);
127 procedure g_Game_CheckVote
;
128 procedure g_TakeScreenShot(Filename
: string = '');
129 procedure g_FatalError(Text: String);
130 procedure g_SimpleError(Text: String);
131 function g_Game_IsTestMap(): Boolean;
132 procedure g_Game_DeleteTestMap();
133 procedure GameCVars(P
: SSArray
);
134 procedure GameCommands(P
: SSArray
);
135 procedure GameCheats(P
: SSArray
);
136 procedure DebugCommands(P
: SSArray
);
137 procedure g_Game_Process_Params
;
138 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
139 procedure g_Game_StepLoading(Value
: Integer = -1);
140 procedure g_Game_ClearLoading();
141 procedure g_Game_SetDebugMode();
142 procedure DrawLoadingStat();
143 procedure DrawMenuBackground(tex
: AnsiString);
145 { procedure SetWinPause(Enable: Boolean); }
150 LOADING_SHOW_STEP
= 100;
151 LOADING_INTERLINE
= 20;
166 MESSAGE_DIKEY
= WM_USER
+ 1;
171 EXIT_ENDLEVELSINGLE
= 4;
172 EXIT_ENDLEVELCUSTOM
= 5;
174 GAME_OPTION_RESERVED
= 1;
175 GAME_OPTION_TEAMDAMAGE
= 2;
176 GAME_OPTION_ALLOWEXIT
= 4;
177 GAME_OPTION_WEAPONSTAY
= 8;
178 GAME_OPTION_MONSTERS
= 16;
179 GAME_OPTION_BOTVSPLAYER
= 32;
180 GAME_OPTION_BOTVSMONSTER
= 64;
185 STATE_INTERCUSTOM
= 3;
186 STATE_INTERSINGLE
= 4;
192 LMS_RESPAWN_NONE
= 0;
193 LMS_RESPAWN_WARMUP
= 1;
194 LMS_RESPAWN_FINAL
= 2;
211 CONFIG_FILENAME
= 'Doom2DF.cfg';
213 TEST_MAP_NAME
= '$$$_TEST_$$$';
215 STD_PLAYER_MODEL
= 'Doomer';
223 STATFILE_VERSION
= $03;
227 gGameSettings
: TGameSettings
;
228 gPlayer1Settings
: TPlayerSettings
;
229 gPlayer2Settings
: TPlayerSettings
;
231 gPlayerScreenSize
: TDFPoint
;
232 gPlayer1ScreenCoord
: TDFPoint
;
233 gPlayer2ScreenCoord
: TDFPoint
;
234 gPlayer1
: TPlayer
= nil;
235 gPlayer2
: TPlayer
= nil;
236 gPlayerDrawn
: TPlayer
= nil;
238 gSwitchGameMode
: Byte = GM_DM
;
239 gHearPoint1
, gHearPoint2
: THearPoint
;
240 gSoundEffectsDF
: Boolean = False;
241 gSoundTriggerTime
: Word = 0;
242 gAnnouncer
: Integer = ANNOUNCE_NONE
;
243 goodsnd
: array[0..3] of TPlayableSound
;
244 killsnd
: array[0..3] of TPlayableSound
;
245 hahasnd
: array[0..2] of TPlayableSound
;
246 sound_get_flag
: array[0..1] of TPlayableSound
;
247 sound_lost_flag
: array[0..1] of TPlayableSound
;
248 sound_ret_flag
: array[0..1] of TPlayableSound
;
249 sound_cap_flag
: array[0..1] of TPlayableSound
;
250 gBodyKillEvent
: Integer = -1;
251 gDefInterTime
: ShortInt = -1;
252 gInterEndTime
: LongWord = 0;
253 gInterTime
: LongWord = 0;
254 gServInterTime
: Byte = 0;
255 gGameStartTime
: LongWord = 0;
256 gTotalMonsters
: Integer = 0;
257 gPauseMain
: Boolean = false;
258 gPauseHolmes
: Boolean = false;
259 gShowTime
: Boolean = False;
260 gShowFPS
: Boolean = False;
261 gShowGoals
: Boolean = True;
262 gShowStat
: Boolean = True;
263 gShowKillMsg
: Boolean = True;
264 gShowLives
: Boolean = True;
265 gShowPing
: Boolean = False;
266 gShowMap
: Boolean = False;
268 gState
: Byte = STATE_NONE
;
270 sWidth
, sHeight
: Word;
271 gSpectMode
: Byte = SPECT_NONE
;
272 gSpectHUD
: Boolean = True;
273 gSpectKeyPress
: Boolean = False;
274 gSpectX
: Integer = 0;
275 gSpectY
: Integer = 0;
276 gSpectStep
: Byte = 8;
277 gSpectViewTwo
: Boolean = False;
278 gSpectPID1
: Integer = -1;
279 gSpectPID2
: Integer = -1;
280 gSpectAuto
: Boolean = False;
281 gSpectAutoNext
: LongWord;
282 gSpectAutoStepX
: Integer;
283 gSpectAutoStepY
: Integer;
284 gMusic
: TMusic
= nil;
285 gLoadGameMode
: Boolean;
286 gCheats
: Boolean = False;
287 gMapOnce
: Boolean = False;
288 gMapToDelete
: String;
289 gTempDelete
: Boolean = False;
290 gLastMap
: Boolean = False;
291 gWinSizeX
, gWinSizeY
: Integer;
292 gResolutionChange
: Boolean = False;
293 gRC_Width
, gRC_Height
: Integer;
294 gRC_FullScreen
, gRC_Maximized
: Boolean;
295 gLanguageChange
: Boolean = False;
296 gDebugMode
: Boolean = False;
297 g_debug_Sounds
: Boolean = False;
298 g_debug_Frames
: Boolean = False;
299 g_debug_WinMsgs
: Boolean = False;
300 g_debug_MonsterOff
: Boolean = False;
301 g_debug_BotAIOff
: Byte = 0;
302 g_debug_HealthBar
: Boolean = False;
303 g_Debug_Player
: Boolean = False;
304 gCoopMonstersKilled
: Word = 0;
305 gCoopSecretsFound
: Word = 0;
306 gCoopTotalMonstersKilled
: Word = 0;
307 gCoopTotalSecretsFound
: Word = 0;
308 gCoopTotalMonsters
: Word = 0;
309 gCoopTotalSecrets
: Word = 0;
310 gStatsOff
: Boolean = False;
311 gStatsPressed
: Boolean = False;
312 gExitByTrigger
: Boolean = False;
313 gNextMap
: String = '';
314 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
315 gLMSRespawnTime
: Cardinal = 0;
316 gLMSSoftSpawn
: Boolean = False;
317 gMissionFailed
: Boolean = False;
318 gVoteInProgress
: Boolean = False;
319 gVotePassed
: Boolean = False;
320 gVoteCommand
: string = '';
321 gVoteTimer
: Cardinal = 0;
322 gVoteCmdTimer
: Cardinal = 0;
323 gVoteCount
: Integer = 0;
324 gVoteTimeout
: Cardinal = 30;
325 gVoted
: Boolean = False;
326 gVotesEnabled
: Boolean = True;
327 gEvents
: Array of TGameEvent
;
328 gDelayedEvents
: Array of TDelayedEvent
;
329 gUseChatSounds
: Boolean = True;
330 gChatSounds
: Array of TChatSound
;
331 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
332 gInterReadyCount
: Integer = 0;
334 g_dbg_ignore_bounds
: Boolean = false;
335 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
336 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
338 // move button values:
339 // bits 0-1: l/r state:
340 // 0: neither left, nor right pressed
343 // bits 4-5: l/r state when strafe was pressed
344 P1MoveButton
: Byte = 0;
345 P2MoveButton
: Byte = 0;
347 g_profile_frame_update
: Boolean = false;
348 g_profile_frame_draw
: Boolean = false;
349 g_profile_collision
: Boolean = false;
350 g_profile_los
: Boolean = false;
351 g_profile_history_size
: Integer = 1000;
353 g_rlayer_back
: Boolean = true;
354 g_rlayer_step
: Boolean = true;
355 g_rlayer_wall
: Boolean = true;
356 g_rlayer_door
: Boolean = true;
357 g_rlayer_acid1
: Boolean = true;
358 g_rlayer_acid2
: Boolean = true;
359 g_rlayer_water
: Boolean = true;
360 g_rlayer_fore
: Boolean = true;
363 procedure g_ResetDynlights ();
364 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
365 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
367 function conIsCheatsEnabled (): Boolean; inline;
368 function gPause (): Boolean; inline;
374 {$INCLUDE ../nogl/noGLuses.inc}
375 {$IFDEF ENABLE_HOLMES}
378 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
379 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
380 g_playermodel
, g_gfx
, g_options
, Math
,
381 g_triggers
, g_monsters
, e_sound
, CONFIG
,
382 g_language
, g_net
, g_main
,
383 ENet
, e_msg
, g_netmsg
, g_netmaster
,
384 sfs
, wadreader
, g_system
;
388 hasPBarGfx
: Boolean = false;
391 // ////////////////////////////////////////////////////////////////////////// //
392 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
395 // ////////////////////////////////////////////////////////////////////////// //
396 function conIsCheatsEnabled (): Boolean; inline;
399 if g_Game_IsNet
then exit
;
400 if not gDebugMode
then
402 //if not gCheats then exit;
403 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
404 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
410 // ////////////////////////////////////////////////////////////////////////// //
412 profileFrameDraw
: TProfiler
= nil;
415 // ////////////////////////////////////////////////////////////////////////// //
418 x
, y
, radius
: Integer;
421 exploRadius
: Integer;
425 g_dynLights
: array of TDynLight
= nil;
426 g_dynLightCount
: Integer = 0;
427 g_playerLight
: Boolean = false;
429 procedure g_ResetDynlights ();
433 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
435 for idx
:= 0 to g_dynLightCount
-1 do
437 if g_dynLights
[idx
].exploCount
= -666 then
444 Inc(g_dynLights
[idx
].exploCount
);
445 if (g_dynLights
[idx
].exploCount
< 10) then
447 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
448 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
449 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
450 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
455 g_dynLightCount
:= lnum
;
458 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
460 if not gwin_has_stencil
then exit
;
461 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
462 g_dynLights
[g_dynLightCount
].x
:= x
;
463 g_dynLights
[g_dynLightCount
].y
:= y
;
464 g_dynLights
[g_dynLightCount
].radius
:= radius
;
465 g_dynLights
[g_dynLightCount
].r
:= r
;
466 g_dynLights
[g_dynLightCount
].g
:= g
;
467 g_dynLights
[g_dynLightCount
].b
:= b
;
468 g_dynLights
[g_dynLightCount
].a
:= a
;
469 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
470 Inc(g_dynLightCount
);
473 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
475 if not gwin_has_stencil
then exit
;
476 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
477 g_dynLights
[g_dynLightCount
].x
:= x
;
478 g_dynLights
[g_dynLightCount
].y
:= y
;
479 g_dynLights
[g_dynLightCount
].radius
:= 0;
480 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
481 g_dynLights
[g_dynLightCount
].r
:= r
;
482 g_dynLights
[g_dynLightCount
].g
:= g
;
483 g_dynLights
[g_dynLightCount
].b
:= b
;
484 g_dynLights
[g_dynLightCount
].a
:= 0;
485 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
486 Inc(g_dynLightCount
);
490 // ////////////////////////////////////////////////////////////////////////// //
491 function calcProfilesHeight (prof
: TProfiler
): Integer;
494 if (prof
= nil) then exit
;
495 if (length(prof
.bars
) = 0) then exit
;
496 result
:= length(prof
.bars
)*(16+2);
500 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
507 if (prof
= nil) then exit
;
509 if (length(prof
.bars
) = 0) then exit
;
511 hgt
:= calcProfilesHeight(prof
);
512 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
513 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
515 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
516 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
517 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
520 for ii
:= 0 to High(prof
.bars
) do
522 e_TextureFontPrintEx(x
+2+4*prof
.bars
[ii
].level
, yy
, Format('%s: %d', [prof
.bars
[ii
].name
, prof
.bars
[ii
].value
]), gStdFont
, 255, 255, 0, 1, false);
529 // ////////////////////////////////////////////////////////////////////////// //
531 TEndCustomGameStat
= record
532 PlayerStat
: TPlayerStatArray
;
536 Map
, MapName
: String;
539 TEndSingleGameStat
= record
540 PlayerStat
: Array [0..1] of record
546 TotalSecrets
: Integer;
549 TLoadingStat
= record
553 Msgs
: Array of String;
555 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
558 TParamStrValue
= record
563 TParamStrValues
= Array of TParamStrValue
;
566 INTER_ACTION_TEXT
= 1;
567 INTER_ACTION_PIC
= 2;
568 INTER_ACTION_MUSIC
= 3;
572 FPSCounter
, UPSCounter
: Word;
573 FPSTime
, UPSTime
: LongWord;
574 DataLoaded
: Boolean = False;
575 IsDrawStat
: Boolean = False;
576 CustomStat
: TEndCustomGameStat
;
577 SingleStat
: TEndSingleGameStat
;
578 LoadingStat
: TLoadingStat
;
579 EndingGameCounter
: Byte = 0;
582 MessageLineLength
: Integer = 80;
583 MapList
: SSArray
= nil;
584 MapIndex
: Integer = -1;
585 InterReadyTime
: Integer = -1;
586 StatShotDone
: Boolean = False;
587 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
588 StatDate
: string = '';
594 text: Array of ShortString;
595 anim
: Array of ShortString;
596 pic
: Array of ShortString;
597 mus
: Array of ShortString;
599 triggers
: Array of record
601 actions
: Array of record
602 action
, p1
, p2
: Integer;
605 cur_trigger
: Integer;
618 function Compare(a
, b
: TPlayerStat
): Integer;
620 if a
.Spectator
then Result
:= 1
621 else if b
.Spectator
then Result
:= -1
622 else if a
.Frags
< b
.Frags
then Result
:= 1
623 else if a
.Frags
> b
.Frags
then Result
:= -1
624 else if a
.Deaths
< b
.Deaths
then Result
:= -1
625 else if a
.Deaths
> b
.Deaths
then Result
:= 1
626 else if a
.Kills
< b
.Kills
then Result
:= -1
630 procedure SortGameStat(var stat
: TPlayerStatArray
);
635 if stat
= nil then Exit
;
637 for I
:= High(stat
) downto Low(stat
) do
638 for J
:= Low(stat
) to High(stat
) - 1 do
639 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
642 stat
[J
] := stat
[J
+ 1];
647 // saves a shitty CSV containing the game stats passed to it
648 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
651 dir
, fname
, map
, mode
, etime
: String;
655 dir
:= e_GetWriteableDir(StatsDirs
);
656 // stats are placed in stats/yy/mm/dd/*.csv
657 fname
:= e_CatPath(dir
, Path
);
658 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
659 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
660 AssignFile(s
, fname
);
663 // line 1: stats version, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, number of players
664 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
665 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
666 mode
:= g_Game_ModeToText(Stat
.GameMode
);
667 etime
:= Format('%d:%.2d:%.2d', [Stat
.GameTime
div 1000 div 3600,
668 (Stat
.GameTime
div 1000 div 60) mod 60,
669 Stat
.GameTime
div 1000 mod 60]);
670 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
672 Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d',
673 [STATFILE_VERSION
, StatDate
, fname
, map
, mode
, gGameSettings
.TimeLimit
, gGameSettings
.GoalLimit
, gGameSettings
.Options
, etime
, Length(Stat
.PlayerStat
)]));
674 // line 2: game specific shit
675 // if it's a team game: red score, blue score
676 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
678 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
679 WriteLn(s
, Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
680 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
681 WriteLn(s
, Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d', [gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
682 // lines 3-...: team, player name, frags, deaths
683 WriteLn(s
, 'team,name,frags,deaths');
684 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
685 with Stat
.PlayerStat
[I
] do
686 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, Name
, Frags
, Deaths
]));
688 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
691 g_Console_Add('could not create gamestats file "' + fname
+ '"');
696 function g_Game_ModeToText(Mode
: Byte): string;
700 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
701 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
702 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
703 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
704 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
708 function g_Game_TextToMode(Mode
: string): Byte;
711 Mode
:= UpperCase(Mode
);
712 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
717 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
722 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
727 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
732 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
739 function g_Game_IsNet(): Boolean;
741 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
744 function g_Game_IsServer(): Boolean;
746 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
749 function g_Game_IsClient(): Boolean;
751 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
754 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
761 Result
.name
:= ExtractFileName(WAD
);
762 Result
.description
:= '';
765 w
:= TWADFile
.Create();
768 if not w
.GetResource('INTERSCRIPT', p
, len
) then
774 cfg
:= TConfig
.CreateMem(p
, len
);
775 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
776 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
777 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
778 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
784 procedure g_Game_FreeWAD();
788 for a
:= 0 to High(MegaWAD
.res
.pic
) do
789 if MegaWAD
.res
.pic
[a
] <> '' then
790 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
792 for a
:= 0 to High(MegaWAD
.res
.mus
) do
793 if MegaWAD
.res
.mus
[a
] <> '' then
794 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
796 MegaWAD
.res
.pic
:= nil;
797 MegaWAD
.res
.text := nil;
798 MegaWAD
.res
.anim
:= nil;
799 MegaWAD
.res
.mus
:= nil;
800 MegaWAD
.triggers
:= nil;
802 g_Texture_Delete('TEXTURE_endpic');
803 g_Sound_Delete('MUSIC_endmus');
805 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
806 gGameSettings
.WAD
:= '';
809 procedure g_Game_LoadWAD(WAD
: string);
818 gGameSettings
.WAD
:= WAD
;
819 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
822 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
824 w
:= TWADFile
.Create();
827 if not w
.GetResource('INTERSCRIPT', p
, len
) then
833 cfg
:= TConfig
.CreateMem(p
, len
);
838 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
839 if s = '' then Break;
842 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
843 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
845 g_Texture_CreateWADEx(s, s);
851 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
852 if s = '' then Break;
855 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
856 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
858 g_Music_CreateWADEx(s, s);
861 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
862 if MegaWAD
.endpic
<> '' then
864 TEXTUREFILTER
:= GL_LINEAR
;
865 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
866 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
867 TEXTUREFILTER
:= GL_NEAREST
;
869 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
870 if MegaWAD
.endmus
<> '' then
872 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
873 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
881 {procedure start_trigger(t: string);
885 function next_trigger(): Boolean;
889 procedure DisableCheats();
895 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
896 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
897 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
898 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
900 {$IF DEFINED(D2F_DEBUG)}
901 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
902 gAimLine
:= g_dbg_aimline_on
;
906 procedure g_Game_ExecuteEvent(Name
: String);
912 if gEvents
= nil then
914 for a
:= 0 to High(gEvents
) do
915 if gEvents
[a
].Name
= Name
then
917 if gEvents
[a
].Command
<> '' then
918 g_Console_Process(gEvents
[a
].Command
, True);
923 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
928 if gDelayedEvents
<> nil then
929 for a
:= 0 to High(gDelayedEvents
) do
930 if not gDelayedEvents
[a
].Pending
then
937 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
938 n
:= High(gDelayedEvents
);
940 gDelayedEvents
[n
].Pending
:= True;
941 gDelayedEvents
[n
].DEType
:= DEType
;
942 gDelayedEvents
[n
].DENum
:= Num
;
943 gDelayedEvents
[n
].DEStr
:= Str
;
944 if DEType
= DE_GLOBEVENT
then
945 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
947 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
957 if g_Game_IsNet
and g_Game_IsServer
then
958 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
962 gPauseHolmes
:= false;
965 g_Game_StopAllSounds(False);
970 EndingGameCounter
:= 0;
971 g_ActiveWindow
:= nil;
973 gLMSRespawn
:= LMS_RESPAWN_NONE
;
974 gLMSRespawnTime
:= 0;
977 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
982 begin // Ýòî áûë òåñò
986 begin // Âûõîä â ãëàâíîå ìåíþ
987 gMusic
.SetByName('MUSIC_MENU');
989 if gState
<> STATE_SLIST
then
991 g_GUI_ShowWindow('MainMenu');
992 gState
:= STATE_MENU
;
995 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
996 slReturnPressed
:= True;
997 if g_Net_Slist_Fetch(slCurrent
) then
999 if slCurrent
= nil then
1000 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1003 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1004 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1007 g_Game_ExecuteEvent('ongameend');
1011 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1013 if not g_Game_IsClient
then g_Game_Restart();
1016 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1018 // Ñòàòèñòèêà Ñâîåé èãðû:
1019 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1021 CustomStat
.GameTime
:= gTime
;
1022 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1023 CustomStat
.MapName
:= gMapInfo
.Name
;
1024 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1025 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1026 CustomStat
.TeamStat
:= gTeamStat
;
1028 CustomStat
.PlayerStat
:= nil;
1030 // Ñòàòèñòèêà èãðîêîâ:
1031 if gPlayers
<> nil then
1033 for a
:= 0 to High(gPlayers
) do
1034 if gPlayers
[a
] <> nil then
1036 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1037 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1040 Name
:= gPlayers
[a
].Name
;
1041 Frags
:= gPlayers
[a
].Frags
;
1042 Deaths
:= gPlayers
[a
].Death
;
1043 Kills
:= gPlayers
[a
].Kills
;
1044 Team
:= gPlayers
[a
].Team
;
1045 Color
:= gPlayers
[a
].Model
.Color
;
1046 Spectator
:= gPlayers
[a
].FSpectator
;
1050 SortGameStat(CustomStat
.PlayerStat
);
1052 if gSaveStats
or gScreenshotStats
then
1055 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1056 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1057 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1058 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1059 if gSaveStats
then SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1062 StatShotDone
:= False;
1065 g_Game_ExecuteEvent('onmapend');
1066 if not g_Game_IsClient
then g_Player_ResetReady
;
1067 gInterReadyCount
:= 0;
1069 // Çàòóõàþùèé ýêðàí:
1070 EndingGameCounter
:= 255;
1071 gState
:= STATE_FOLD
;
1073 if gDefInterTime
< 0 then
1074 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1076 gInterEndTime
:= gDefInterTime
* 1000;
1079 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1081 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1082 SingleStat
.GameTime
:= gTime
;
1083 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1084 SingleStat
.TotalSecrets
:= gSecretsCount
;
1085 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1086 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1087 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1088 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1089 if SingleStat
.TwoPlayers
then
1091 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1092 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1095 g_Game_ExecuteEvent('onmapend');
1098 if gNextMap
<> '' then
1100 gMusic
.SetByName('MUSIC_INTERMUS');
1102 gState
:= STATE_INTERSINGLE
;
1105 g_Game_ExecuteEvent('oninter');
1107 else // Áîëüøå íåò êàðò
1109 // Çàòóõàþùèé ýêðàí:
1110 EndingGameCounter
:= 255;
1111 gState
:= STATE_FOLD
;
1116 // Îêîí÷àíèå îáðàáîòàíî:
1117 if gExit
<> EXIT_QUIT
then
1121 procedure drawTime(X
, Y
: Integer); inline;
1123 e_TextureFontPrint(x
, y
,
1124 Format('%d:%.2d:%.2d', [
1125 gTime
div 1000 div 3600,
1126 (gTime
div 1000 div 60) mod 60,
1127 gTime
div 1000 mod 60
1132 procedure DrawStat();
1134 pc
, x
, y
, w
, h
: Integer;
1135 w1
, w2
, w3
, w4
: Integer;
1137 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1140 stat
: TPlayerStatArray
;
1147 pc
:= g_Player_GetCount
;
1148 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1150 w
:= gScreenWidth
-(gScreenWidth
div 5);
1151 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1154 h
:= 40+ch
*5+(ch
+8)*pc
;
1155 x
:= (gScreenWidth
div 2)-(w
div 2);
1156 y
:= (gScreenHeight
div 2)-(h
div 2);
1158 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1159 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1161 drawTime(x
+w
-78, y
+8);
1163 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1164 map
:= g_ExtractFileName(gMapInfo
.Map
);
1165 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1167 case gGameSettings
.GameMode
of
1170 if gGameSettings
.MaxLives
= 0 then
1171 s1
:= _lc
[I_GAME_DM
]
1173 s1
:= _lc
[I_GAME_LMS
];
1174 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1175 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1180 if gGameSettings
.MaxLives
= 0 then
1181 s1
:= _lc
[I_GAME_TDM
]
1183 s1
:= _lc
[I_GAME_TLMS
];
1184 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1185 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1190 s1
:= _lc
[I_GAME_CTF
];
1191 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1192 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1197 if gGameSettings
.MaxLives
= 0 then
1198 s1
:= _lc
[I_GAME_COOP
]
1200 s1
:= _lc
[I_GAME_SURV
];
1201 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1202 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1213 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1215 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1217 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1219 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1220 gStdFont
, 200, 200, 200, 1);
1222 if NetMode
= NET_SERVER
then
1223 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1225 if NetMode
= NET_CLIENT
then
1226 e_TextureFontPrintEx(x
+8, y
+ 8,
1227 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1231 stat
:= g_Player_GetStats();
1234 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1235 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1237 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1239 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1243 for a
:= TEAM_RED
to TEAM_BLUE
do
1245 if a
= TEAM_RED
then
1247 s1
:= _lc
[I_GAME_TEAM_RED
];
1254 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1260 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1261 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1262 gStdFont
, r
, g
, b
, 1);
1264 _y
:= _y
+ch
+(ch
div 4);
1265 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1266 _y
:= _y
+(ch
div 4);
1268 for aa
:= 0 to High(stat
) do
1269 if stat
[aa
].Team
= a
then
1285 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1287 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1289 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1291 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1298 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1301 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1302 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1303 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1304 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1307 for aa
:= 0 to High(stat
) do
1321 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1322 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1324 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1326 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1328 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1330 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1336 procedure g_Game_Init();
1339 knownFiles
: array of AnsiString = nil;
1341 wext
, s
: AnsiString;
1346 gTempDelete
:= False;
1348 sfsGCDisable(); // temporary disable removing of temporary volumes
1351 TEXTUREFILTER
:= GL_LINEAR
;
1352 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1353 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1354 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1355 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1356 TEXTUREFILTER
:= GL_NEAREST
;
1358 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1359 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1360 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1362 g_Game_ClearLoading();
1363 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1364 g_Game_SetLoadingText('', 0, False);
1366 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1369 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1370 g_PlayerModel_LoadData();
1372 // load models from all possible wad types, in all known directories
1373 // this does a loosy job (linear search, ooph!), but meh
1374 for wext
in wadExtensions
do
1376 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1378 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1382 for s
in knownFiles
do
1384 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1392 SetLength(knownFiles
, length(knownFiles
)+1);
1393 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1395 until (FindNext(SR
) <> 0);
1401 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1403 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
);
1404 for s
in knownFiles
do
1406 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1410 gPauseMain
:= false;
1411 gPauseHolmes
:= false;
1414 {e_MouseInfo.Accel := 1.0;}
1416 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1419 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1420 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1421 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1422 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1423 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1426 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1430 gMusic
:= TMusic
.Create();
1431 gMusic
.SetByName('MUSIC_MENU');
1434 gGameSettings
.WarmupTime
:= 30;
1436 gState
:= STATE_MENU
;
1438 SetLength(gEvents
, 6);
1439 gEvents
[0].Name
:= 'ongamestart';
1440 gEvents
[1].Name
:= 'ongameend';
1441 gEvents
[2].Name
:= 'onmapstart';
1442 gEvents
[3].Name
:= 'onmapend';
1443 gEvents
[4].Name
:= 'oninter';
1444 gEvents
[5].Name
:= 'onwadend';
1446 sfsGCEnable(); // enable releasing unused volumes
1450 procedure g_Game_Free(freeTextures
: Boolean=true);
1452 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1453 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1455 g_Map_Free(freeTextures
);
1457 g_Player_RemoveAllCorpses();
1459 gGameSettings
.GameType
:= GT_NONE
;
1460 if gGameSettings
.GameMode
= GM_SINGLE
then
1461 gGameSettings
.GameMode
:= GM_DM
;
1462 gSwitchGameMode
:= gGameSettings
.GameMode
;
1465 gExitByTrigger
:= False;
1468 function IsActivePlayer(p
: TPlayer
): Boolean;
1473 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1476 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1483 if gPlayers
= nil then
1485 for a
:= Low(gPlayers
) to High(gPlayers
) do
1486 if IsActivePlayer(gPlayers
[a
]) then
1488 if gPlayers
[a
].UID
<> ID
then
1490 Result
:= gPlayers
[a
];
1495 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1501 if gPlayers
= nil then
1505 for a
:= Low(gPlayers
) to High(gPlayers
) do
1506 if IsActivePlayer(gPlayers
[a
]) then
1508 SetLength(ids
, Length(ids
) + 1);
1509 ids
[High(ids
)] := gPlayers
[a
].UID
;
1510 if gPlayers
[a
].UID
= Skip
then
1513 if Length(ids
) = 0 then
1518 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1521 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1527 if gPlayers
= nil then
1531 for a
:= Low(gPlayers
) to High(gPlayers
) do
1532 if IsActivePlayer(gPlayers
[a
]) then
1534 SetLength(ids
, Length(ids
) + 1);
1535 ids
[High(ids
)] := gPlayers
[a
].UID
;
1536 if gPlayers
[a
].UID
= Skip
then
1539 if Length(ids
) = 0 then
1542 Result
:= ids
[Length(ids
) - 1]
1544 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1547 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1553 if gPlayers
= nil then
1557 for a
:= Low(gPlayers
) to High(gPlayers
) do
1558 if IsActivePlayer(gPlayers
[a
]) then
1560 SetLength(ids
, Length(ids
) + 1);
1561 ids
[High(ids
)] := gPlayers
[a
].UID
;
1562 if gPlayers
[a
].UID
= Skip
then
1565 if Length(ids
) = 0 then
1567 if Length(ids
) = 1 then
1572 Result
:= ids
[Random(Length(ids
))];
1574 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1576 Result
:= ids
[Random(Length(ids
))];
1581 function GetRandomSpectMode(Current
: Byte): Byte;
1588 0: Result
:= SPECT_STATS
;
1589 1: Result
:= SPECT_MAPVIEW
;
1590 2: Result
:= SPECT_MAPVIEW
;
1591 3: Result
:= SPECT_PLAYERS
;
1592 4: Result
:= SPECT_PLAYERS
;
1593 5: Result
:= SPECT_PLAYERS
;
1594 6: Result
:= SPECT_PLAYERS
;
1596 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1600 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1606 if (plr
= nil) then exit
;
1607 if (p
= 2) then time
:= 1000 else time
:= 1;
1608 strafeDir
:= MoveButton
shr 4;
1609 MoveButton
:= MoveButton
and $0F;
1611 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1612 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1613 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1614 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1615 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1616 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1618 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1619 if MoveButton
= 1 then
1620 plr
.PressKey(KEY_LEFT
, time
)
1621 else if MoveButton
= 2 then
1622 plr
.PressKey(KEY_RIGHT
, time
);
1624 // if we have "strafe" key, turn off old strafe mechanics
1625 if gPlayerAction
[p
, ACTION_STRAFE
] then
1627 // new strafe mechanics
1628 if (strafeDir
= 0) then
1629 strafeDir
:= MoveButton
; // start strafing
1630 // now set direction according to strafe (reversed)
1631 if (strafeDir
= 2) then
1632 plr
.SetDirection(TDirection
.D_LEFT
)
1633 else if (strafeDir
= 1) then
1634 plr
.SetDirection(TDirection
.D_RIGHT
)
1638 strafeDir
:= 0; // not strafing anymore
1639 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1640 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1641 plr
.SetDirection(TDirection
.D_LEFT
)
1642 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1643 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1644 plr
.SetDirection(TDirection
.D_RIGHT
)
1645 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1646 else if MoveButton
<> 0 then
1647 plr
.SetDirection(TDirection(MoveButton
-1))
1650 // fix movebutton state
1651 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1653 // Îñòàëüíûå êëàâèøè:
1654 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1655 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1656 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1657 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1658 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1659 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1660 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1662 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1663 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1665 for i
:= WP_FIRST
to WP_LAST
do
1667 if gSelectWeapon
[p
, i
] then
1669 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1670 gSelectWeapon
[p
, i
] := False
1674 // HACK: add dynlight here
1675 if gwin_k8_enable_light_experiments
then
1677 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1679 g_playerLight
:= true;
1681 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1683 g_playerLight
:= false;
1687 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1690 // HACK: don't have a "key was pressed" function
1691 procedure InterReady();
1693 if InterReadyTime
> gTime
then Exit
;
1694 InterReadyTime
:= gTime
+ 3000;
1695 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1698 procedure g_Game_Update();
1700 Msg
: g_gui
.TMessage
;
1706 function sendMonsPos (mon
: TMonster
): Boolean;
1708 result
:= false; // don't stop
1709 // this will also reset "need-send" flag
1710 if mon
.gncNeedSend
then
1712 MH_SEND_MonsterPos(mon
.UID
);
1714 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1716 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1718 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1720 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1724 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1726 result
:= false; // don't stop
1727 // this will also reset "need-send" flag
1728 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1732 reliableUpdate
: Boolean;
1737 // Ïîðà âûêëþ÷àòü èãðó:
1738 if gExit
= EXIT_QUIT
then
1740 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1744 if gExit
= EXIT_QUIT
then
1748 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1749 // no need to, as we'll do it in event handler
1751 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1754 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1756 gExit
:= EXIT_SIMPLE
;
1761 // process master server communications
1762 g_Net_Slist_Pulse();
1765 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1766 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1767 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1768 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1770 if g_Game_IsNet
and g_Game_IsServer
then
1772 gInterTime
:= gInterTime
+ GAME_TICK
;
1773 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1774 if a
<> gServInterTime
then
1776 gServInterTime
:= a
;
1777 MH_SEND_TimeSync(gServInterTime
);
1781 if (not g_Game_IsClient
) and
1785 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1786 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1787 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1788 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1790 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1791 and (g_ActiveWindow
= nil)
1793 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1796 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1797 g_Game_StopAllSounds(True);
1799 if gMapOnce
then // Ýòî áûë òåñò
1800 gExit
:= EXIT_SIMPLE
1802 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1803 g_Game_ChangeMap(gNextMap
)
1804 else // Ñëåäóþùåé êàðòû íåò
1806 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1808 // Âûõîä â ãëàâíîå ìåíþ:
1810 g_GUI_ShowWindow('MainMenu');
1811 gMusic
.SetByName('MUSIC_MENU');
1813 gState
:= STATE_MENU
;
1816 // Ôèíàëüíàÿ êàðòèíêà:
1817 g_Game_ExecuteEvent('onwadend');
1819 if not gMusic
.SetByName('MUSIC_endmus') then
1820 gMusic
.SetByName('MUSIC_STDENDMUS');
1822 gState
:= STATE_ENDPIC
;
1824 g_Game_ExecuteEvent('ongameend');
1829 else if g_Game_IsClient
and
1832 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1833 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1834 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1835 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1837 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1838 and (g_ActiveWindow
= nil)
1846 if gState
= STATE_INTERTEXT
then
1847 if InterText
.counter
> 0 then
1848 InterText
.counter
:= InterText
.counter
- 1;
1851 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1853 if EndingGameCounter
= 0 then
1855 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1856 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1858 InterReadyTime
:= -1;
1859 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1861 g_Game_ExecuteEvent('onwadend');
1862 if not gMusic
.SetByName('MUSIC_endmus') then
1863 gMusic
.SetByName('MUSIC_STDENDMUS');
1866 gMusic
.SetByName('MUSIC_ROUNDMUS');
1869 gState
:= STATE_INTERCUSTOM
;
1872 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1874 gMusic
.SetByName('MUSIC_INTERMUS');
1876 gState
:= STATE_INTERSINGLE
;
1879 g_Game_ExecuteEvent('oninter');
1882 DecMin(EndingGameCounter
, 6, 0);
1885 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1887 if gMapOnce
then // Ýòî áûë òåñò
1889 gExit
:= EXIT_SIMPLE
;
1895 g_Serverlist_Control(slCurrent
, slTable
);
1898 // Ñòàòèñòèêà ïî Tab:
1900 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1903 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1905 // Âðåìÿ += 28 ìèëëèñåêóíä:
1906 gTime
:= gTime
+ GAME_TICK
;
1908 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1909 if MessageTime
= 0 then
1911 if MessageTime
> 0 then
1912 MessageTime
:= MessageTime
- 1;
1914 if (g_Game_IsServer
) then
1916 // Áûë çàäàí ëèìèò âðåìåíè:
1917 if (gGameSettings
.TimeLimit
> 0) then
1918 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1919 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1924 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1925 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1926 g_Game_RestartRound(gLMSSoftSpawn
);
1928 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1929 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1931 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1933 g_Console_Process(gVoteCommand
);
1935 gVotePassed
:= False;
1938 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1939 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1940 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1941 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1942 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1944 // Áûë çàäàí ëèìèò ïîáåä:
1945 if (gGameSettings
.GoalLimit
> 0) then
1949 if gGameSettings
.GameMode
= GM_DM
then
1950 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1951 for i
:= 0 to High(gPlayers
) do
1952 if gPlayers
[i
] <> nil then
1953 if gPlayers
[i
].Frags
> b
then
1954 b
:= gPlayers
[i
].Frags
;
1957 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1958 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1959 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1962 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1963 if b
>= gGameSettings
.GoalLimit
then
1970 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1971 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1972 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1973 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1975 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1976 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1977 end // if not console
1980 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1982 // process weapon switch queue
1986 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1987 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1989 if not gSpectKeyPress
then
1991 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1993 // switch spect mode
1995 SPECT_NONE
: ; // not spectator
1997 SPECT_MAPVIEW
: Inc(gSpectMode
);
1998 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2000 gSpectKeyPress
:= True;
2002 if (gSpectMode
= SPECT_MAPVIEW
)
2003 and (not gSpectAuto
) then
2005 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2006 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2007 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2008 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2009 if gPlayerAction
[0, ACTION_LOOKUP
] then
2010 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2011 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2012 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2013 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2016 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2017 gSpectKeyPress
:= True;
2019 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2022 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2023 gSpectKeyPress
:= True;
2026 if (gSpectMode
= SPECT_PLAYERS
)
2027 and (not gSpectAuto
) then
2029 if gPlayerAction
[0, ACTION_LOOKUP
] then
2032 gSpectViewTwo
:= True;
2033 gSpectKeyPress
:= True;
2035 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2037 // remove second view
2038 gSpectViewTwo
:= False;
2039 gSpectKeyPress
:= True;
2041 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2043 // prev player (view 1)
2044 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2045 gSpectKeyPress
:= True;
2047 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2049 // next player (view 1)
2050 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2051 gSpectKeyPress
:= True;
2053 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2055 // prev player (view 2)
2056 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2057 gSpectKeyPress
:= True;
2059 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2061 // next player (view 2)
2062 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2063 gSpectKeyPress
:= True;
2066 if gPlayerAction
[0, ACTION_ATTACK
] then
2068 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2071 gSpectAutoNext
:= 0;
2072 gSpectViewTwo
:= False;
2073 gSpectKeyPress
:= True;
2078 gSpectMode
:= SPECT_STATS
;
2079 gSpectAuto
:= False;
2080 gSpectKeyPress
:= True;
2085 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2086 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2087 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2088 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2089 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2090 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2091 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2092 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2093 gSpectKeyPress
:= False;
2097 if gSpectMode
= SPECT_MAPVIEW
then
2099 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2101 gSpectAutoNext
:= gTime
2104 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2106 gSpectAutoNext
:= gTime
2110 if gSpectAutoNext
<= gTime
then
2112 if gSpectAutoNext
> 0 then
2114 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2118 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2119 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2120 gSpectAutoStepX
:= Random(9) - 4;
2121 gSpectAutoStepY
:= Random(9) - 4;
2122 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2123 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2124 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2125 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2126 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2127 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2131 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2136 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2137 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2138 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2144 // Îáíîâëÿåì âñå îñòàëüíîå:
2147 g_Triggers_Update();
2149 g_Monsters_Update();
2151 g_Player_UpdateAll();
2152 g_Player_UpdatePhysicalObjects();
2154 // server: send newly spawned monsters unconditionally
2155 if (gGameSettings
.GameType
= GT_SERVER
) then
2157 if (Length(gMonstersSpawned
) > 0) then
2159 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2160 SetLength(gMonstersSpawned
, 0);
2164 if (gSoundTriggerTime
> 8) then
2166 g_Game_UpdateTriggerSounds();
2167 gSoundTriggerTime
:= 0;
2171 Inc(gSoundTriggerTime
);
2174 if (NetMode
= NET_SERVER
) then
2176 Inc(NetTimeToUpdate
);
2177 Inc(NetTimeToReliable
);
2179 // send monster updates
2180 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2182 // send all monsters (periodic sync)
2183 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2185 for I
:= 0 to High(gPlayers
) do
2187 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2190 g_Mons_ForEach(sendMonsPos
);
2192 if reliableUpdate
then
2194 NetTimeToReliable
:= 0;
2195 NetTimeToUpdate
:= NetUpdateRate
;
2199 NetTimeToUpdate
:= 0;
2204 // send only mosters with some unexpected changes
2205 g_Mons_ForEach(sendMonsPosUnexpected
);
2208 // send unexpected platform changes
2209 g_Map_NetSendInterestingPanels();
2211 g_Net_Slist_ServerUpdate();
2213 if NetUseMaster then
2215 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2217 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2219 NetTimeToMaster := gTime + NetMasterRate;
2224 else if (NetMode
= NET_CLIENT
) then
2226 MC_SEND_PlayerPos();
2228 end; // if gameOn ...
2230 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2231 if g_ActiveWindow
<> nil then
2233 w
:= e_GetFirstKeyPressed();
2235 if (w
<> IK_INVALID
) then
2237 Msg
.Msg
:= MESSAGE_DIKEY
;
2239 g_ActiveWindow
.OnMessage(Msg
);
2242 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2243 if g_ActiveWindow
<> nil then
2244 g_ActiveWindow
.Update();
2246 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2247 if gResolutionChange
then
2249 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2250 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2251 gResolutionChange
:= False;
2252 g_ActiveWindow
:= nil;
2255 // Íóæíî ñìåíèòü ÿçûê:
2256 if gLanguageChange
then
2258 //e_WriteLog('Read language file', MSG_NOTIFY);
2259 //g_Language_Load(DataDir + gLanguage + '.txt');
2260 g_Language_Set(gLanguage
);
2264 gLanguageChange
:= False;
2268 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2269 if e_KeyPressed(IK_F10
) and
2271 (not gConsoleShow
) and
2272 (g_ActiveWindow
= nil) then
2277 Time
:= sys_GetTicks() {div 1000};
2279 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2280 if gDelayedEvents
<> nil then
2281 for a
:= 0 to High(gDelayedEvents
) do
2282 if gDelayedEvents
[a
].Pending
and
2284 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2285 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2288 case gDelayedEvents
[a
].DEType
of
2290 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2293 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2297 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2298 if g_Game_IsNet
and g_Game_IsServer
then
2299 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2303 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2305 gDelayedEvents
[a
].Pending
:= False;
2308 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2309 UPSCounter
:= UPSCounter
+ 1;
2310 if Time
- UPSTime
>= 1000 then
2319 g_Weapon_AddDynLights();
2320 g_Items_AddDynLights();
2324 procedure g_Game_LoadChatSounds(Resource
: string);
2327 FileName
, Snd
: string;
2329 len
, cnt
, tags
, i
, j
: Integer;
2332 FileName
:= g_ExtractWadName(Resource
);
2334 WAD
:= TWADFile
.Create();
2335 WAD
.ReadFile(FileName
);
2337 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2344 cfg
:= TConfig
.CreateMem(p
, len
);
2345 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2347 SetLength(gChatSounds
, cnt
);
2348 for i
:= 0 to Length(gChatSounds
) - 1 do
2350 gChatSounds
[i
].Sound
:= nil;
2351 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2352 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2353 if (Snd
= '') or (Tags
<= 0) then
2355 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2356 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2357 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2358 SetLength(gChatSounds
[i
].Tags
, tags
);
2359 for j
:= 0 to tags
- 1 do
2360 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2361 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2368 procedure g_Game_FreeChatSounds();
2372 for i
:= 0 to Length(gChatSounds
) - 1 do
2374 gChatSounds
[i
].Sound
.Free();
2375 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2377 SetLength(gChatSounds
, 0);
2381 procedure g_Game_LoadData();
2388 if DataLoaded
then Exit
;
2390 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2392 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2393 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2394 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2395 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2396 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2397 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2398 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2399 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2400 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2401 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2402 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2403 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2404 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2405 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2406 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2409 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2410 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2411 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2412 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2416 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2417 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2418 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2419 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2420 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
2426 hasPBarGfx
:= false;
2430 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2431 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2432 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2433 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2434 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2435 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2436 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2437 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2438 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2439 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2440 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2441 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2442 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2443 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2444 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2445 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2446 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2447 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2448 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2449 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2450 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2451 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2452 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2453 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2454 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2455 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2456 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2457 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2458 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2459 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2460 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2461 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2462 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2463 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2464 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2465 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2466 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2467 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2468 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2470 goodsnd
[0] := TPlayableSound
.Create();
2471 goodsnd
[1] := TPlayableSound
.Create();
2472 goodsnd
[2] := TPlayableSound
.Create();
2473 goodsnd
[3] := TPlayableSound
.Create();
2475 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2476 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2477 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2478 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2480 killsnd
[0] := TPlayableSound
.Create();
2481 killsnd
[1] := TPlayableSound
.Create();
2482 killsnd
[2] := TPlayableSound
.Create();
2483 killsnd
[3] := TPlayableSound
.Create();
2485 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2486 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2487 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2488 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2490 hahasnd
[0] := TPlayableSound
.Create();
2491 hahasnd
[1] := TPlayableSound
.Create();
2492 hahasnd
[2] := TPlayableSound
.Create();
2494 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2495 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2496 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2498 sound_get_flag
[0] := TPlayableSound
.Create();
2499 sound_get_flag
[1] := TPlayableSound
.Create();
2500 sound_lost_flag
[0] := TPlayableSound
.Create();
2501 sound_lost_flag
[1] := TPlayableSound
.Create();
2502 sound_ret_flag
[0] := TPlayableSound
.Create();
2503 sound_ret_flag
[1] := TPlayableSound
.Create();
2504 sound_cap_flag
[0] := TPlayableSound
.Create();
2505 sound_cap_flag
[1] := TPlayableSound
.Create();
2507 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2508 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2509 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2510 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2511 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2512 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2513 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2514 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2516 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2518 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2521 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2522 g_Weapon_LoadData();
2524 g_Monsters_LoadData();
2529 procedure g_Game_FreeData();
2531 if not DataLoaded
then Exit
;
2534 g_Weapon_FreeData();
2535 g_Monsters_FreeData();
2537 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2539 g_Texture_Delete('NOTEXTURE');
2540 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2541 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2542 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2543 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2544 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2545 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2546 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2547 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2548 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2549 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2550 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2551 g_Frames_DeleteByName('FRAMES_TELEPORT');
2552 g_Frames_DeleteByName('FRAMES_PUNCH');
2553 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2554 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2555 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2556 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2557 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2558 g_Sound_Delete('SOUND_GAME_TELEPORT');
2559 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2560 g_Sound_Delete('SOUND_GAME_SECRET');
2561 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2562 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2563 g_Sound_Delete('SOUND_GAME_BULK1');
2564 g_Sound_Delete('SOUND_GAME_BULK2');
2565 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2566 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2567 g_Sound_Delete('SOUND_GAME_BURNING');
2568 g_Sound_Delete('SOUND_GAME_SWITCH1');
2569 g_Sound_Delete('SOUND_GAME_SWITCH0');
2576 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2577 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2578 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2579 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2586 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2587 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2588 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2589 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2595 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2596 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2597 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2599 sound_get_flag
[0].Free();
2600 sound_get_flag
[1].Free();
2601 sound_lost_flag
[0].Free();
2602 sound_lost_flag
[1].Free();
2603 sound_ret_flag
[0].Free();
2604 sound_ret_flag
[1].Free();
2605 sound_cap_flag
[0].Free();
2606 sound_cap_flag
[1].Free();
2608 g_Sound_Delete('SOUND_CTF_GET1');
2609 g_Sound_Delete('SOUND_CTF_GET2');
2610 g_Sound_Delete('SOUND_CTF_LOST1');
2611 g_Sound_Delete('SOUND_CTF_LOST2');
2612 g_Sound_Delete('SOUND_CTF_RETURN1');
2613 g_Sound_Delete('SOUND_CTF_RETURN2');
2614 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2615 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2617 g_Game_FreeChatSounds();
2619 DataLoaded
:= False;
2622 procedure DrawCustomStat();
2628 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2629 s1
, s2
, topstr
: String;
2631 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2635 if g_Console_Action(ACTION_SCORES
) then
2637 if not gStatsPressed
then
2639 gStatsOff
:= not gStatsOff
;
2640 gStatsPressed
:= True;
2644 gStatsPressed
:= False;
2648 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2649 w
:= (Length(s1
) * ww2
) div 2;
2650 x
:= gScreenWidth
div 2 - w
;
2652 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2656 if (gGameSettings
.GameMode
= GM_COOP
) then
2658 if gMissionFailed
then
2659 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2661 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2664 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2666 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2667 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2669 if g_Game_IsNet
then
2671 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2672 if not gChatShow
then
2673 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2674 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2677 if g_Game_IsClient
then
2678 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2680 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2681 if not gChatShow
then
2682 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2683 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2688 w
:= gScreenWidth
-x
*2;
2694 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2695 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2697 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2699 case CustomStat
.GameMode
of
2702 if gGameSettings
.MaxLives
= 0 then
2703 s1
:= _lc
[I_GAME_DM
]
2705 s1
:= _lc
[I_GAME_LMS
];
2709 if gGameSettings
.MaxLives
= 0 then
2710 s1
:= _lc
[I_GAME_TDM
]
2712 s1
:= _lc
[I_GAME_TLMS
];
2714 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2717 if gGameSettings
.MaxLives
= 0 then
2718 s1
:= _lc
[I_GAME_COOP
]
2720 s1
:= _lc
[I_GAME_SURV
];
2726 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2730 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2731 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2734 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2735 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2736 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2737 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2739 pc
:= Length(CustomStat
.PlayerStat
);
2740 if pc
= 0 then Exit
;
2742 if CustomStat
.GameMode
= GM_COOP
then
2744 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2746 s2
:= _lc
[I_GAME_MONSTERS
];
2747 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2748 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2750 s2
:= _lc
[I_GAME_SECRETS
];
2751 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2752 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2755 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2757 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2758 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2759 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2761 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2762 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2763 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2767 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2772 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2773 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2774 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2776 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2779 for t
:= TEAM_RED
to TEAM_BLUE
do
2781 if t
= TEAM_RED
then
2783 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2784 gStdFont
, 255, 0, 0, 1);
2785 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2786 gStdFont
, 255, 0, 0, 1);
2793 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2794 gStdFont
, 0, 0, 255, 1);
2795 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2796 gStdFont
, 0, 0, 255, 1);
2802 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2805 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2806 if CustomStat
.PlayerStat
[p
].Team
= t
then
2807 with CustomStat
.PlayerStat
[p
] do
2821 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2822 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2824 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2825 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2826 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2833 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2836 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2837 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2838 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2841 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2842 with CustomStat
.PlayerStat
[p
] do
2844 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2851 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2852 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2854 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2855 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2856 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2861 // HACK: take stats screenshot immediately after the first frame of the stats showing
2862 if gScreenshotStats
and not StatShotDone
then
2864 g_TakeScreenShot('stats/' + StatFilename
);
2865 StatShotDone
:= True;
2869 procedure DrawSingleStat();
2871 tm
, key_x
, val_x
, y
: Integer;
2875 procedure player_stat(n
: Integer);
2881 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2882 s2
:= Format(' %d', [gTotalMonsters
]);
2884 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2885 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2886 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2887 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2889 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2890 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2892 // "Kills-per-minute: ##.#":
2893 s1
:= _lc
[I_MENU_INTER_KPM
];
2895 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2897 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2898 s2
:= Format(' %.1f', [kpm
]);
2900 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2901 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2903 // "Secrets found: # / #":
2904 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2905 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2907 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2908 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2909 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2910 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2912 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2913 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2917 // "Level Complete":
2918 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2919 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2921 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2922 s1
:= _lc
[I_MENU_INTER_KPM
];
2923 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2926 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2928 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2929 val_x
:= key_x
+ w1
;
2932 tm
:= SingleStat
.GameTime
div 1000;
2933 s1
:= _lc
[I_MENU_INTER_TIME
];
2934 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2936 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2937 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2939 if SingleStat
.TwoPlayers
then
2942 s1
:= _lc
[I_MENU_PLAYER_1
];
2943 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2944 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2946 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2951 s1
:= _lc
[I_MENU_PLAYER_2
];
2952 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2953 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2955 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2961 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2967 procedure DrawLoadingStat();
2968 procedure drawRect (x
, y
, w
, h
: Integer);
2970 if (w
< 1) or (h
< 1) then exit
;
2972 glVertex2f(x
+0.375, y
+0.375);
2973 glVertex2f(x
+w
+0.375, y
+0.375);
2974 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2975 glVertex2f(x
+0.375, y
+h
+0.375);
2979 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2981 rectW
, rectH
: Integer;
2988 idl
, idr
, idb
, idm
: LongWord;
2992 if (total
< 1) then exit
;
2993 if (cur
< 1) then exit
; // don't blink
2994 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2995 //if (cur < 0) then cur := 0;
2996 //if (cur > total) then cur := total;
2999 if (hasPBarGfx
) then
3001 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3002 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3003 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3004 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3005 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3006 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3007 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3008 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3010 //rectW := gScreenWidth-360;
3011 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3014 x0
:= (gScreenWidth
-rectW
) div 2;
3015 y0
:= gScreenHeight
-rectH
-64;
3016 if (y0
< 2) then y0
:= 2;
3018 glEnable(GL_SCISSOR_TEST
);
3021 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3022 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3023 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3026 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3028 while (f
< x0
+rectW
) do
3030 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3035 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3036 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3039 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3040 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3044 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3050 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3054 rectW
:= gScreenWidth
-64;
3057 x0
:= (gScreenWidth
-rectW
) div 2;
3058 y0
:= gScreenHeight
-rectH
-64;
3059 if (y0
< 2) then y0
:= 2;
3061 glDisable(GL_BLEND
);
3062 glDisable(GL_TEXTURE_2D
);
3064 //glClearColor(0, 0, 0, 0);
3065 //glClear(GL_COLOR_BUFFER_BIT);
3067 glColor4ub(127, 127, 127, 255);
3068 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3070 glColor4ub(0, 0, 0, 255);
3071 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3073 glColor4ub(127, 127, 127, 255);
3074 wdt
:= rectW
*cur
div total
;
3075 if (wdt
> rectW
) then wdt
:= rectW
;
3076 drawRect(x0
, y0
, wdt
, rectH
);
3085 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3087 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3088 yy
:= (gScreenHeight
div 3);
3089 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3090 xx
:= (gScreenWidth
div 3);
3094 for i
:= 0 to NextMsg
-1 do
3096 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3097 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3101 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3102 yy
:= yy
+ LOADING_INTERLINE
;
3103 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3108 procedure DrawMenuBackground(tex
: AnsiString);
3114 if g_Texture_Get(tex
, ID
) then
3116 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3117 e_GetTextureSize(ID
, @w
, @h
);
3119 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3121 w
:= trunc(w
* (gScreenHeight
/ h
));
3122 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3124 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3127 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3129 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3131 function monDraw (mon
: TMonster
): Boolean;
3133 result
:= false; // don't stop
3138 // Ëåâûé âåðõíèé óãîë
3139 aX
:= Obj
.X
div ScaleSz
+ 1;
3140 aY
:= Obj
.Y
div ScaleSz
+ 1;
3142 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3143 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3144 // Ïðàâûé íèæíèé óãîë
3145 aX2
:= aX
+ aX2
- 1;
3146 aY2
:= aY
+ aY2
- 1;
3147 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3153 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3154 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3157 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3158 ScaleSz
:= 16 div Scale
;
3159 // Ðàçìåðû ìèíè-êàðòû:
3160 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3161 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3163 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3165 if gWalls
<> nil then
3168 for a
:= 0 to High(gWalls
) do
3170 if PanelType
<> 0 then
3172 // Ëåâûé âåðõíèé óãîë:
3173 aX
:= X
div ScaleSz
;
3174 aY
:= Y
div ScaleSz
;
3176 aX2
:= max(Width
div ScaleSz
, 1);
3177 aY2
:= max(Height
div ScaleSz
, 1);
3178 // Ïðàâûé íèæíèé óãîë:
3179 aX2
:= aX
+ aX2
- 1;
3180 aY2
:= aY
+ aY2
- 1;
3183 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3184 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3185 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3189 if gSteps
<> nil then
3192 for a
:= 0 to High(gSteps
) do
3194 if PanelType
<> 0 then
3196 // Ëåâûé âåðõíèé óãîë:
3197 aX
:= X
div ScaleSz
;
3198 aY
:= Y
div ScaleSz
;
3200 aX2
:= max(Width
div ScaleSz
, 1);
3201 aY2
:= max(Height
div ScaleSz
, 1);
3202 // Ïðàâûé íèæíèé óãîë:
3203 aX2
:= aX
+ aX2
- 1;
3204 aY2
:= aY
+ aY2
- 1;
3206 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3209 if gLifts
<> nil then
3212 for a
:= 0 to High(gLifts
) do
3214 if PanelType
<> 0 then
3216 // Ëåâûé âåðõíèé óãîë:
3217 aX
:= X
div ScaleSz
;
3218 aY
:= Y
div ScaleSz
;
3220 aX2
:= max(Width
div ScaleSz
, 1);
3221 aY2
:= max(Height
div ScaleSz
, 1);
3222 // Ïðàâûé íèæíèé óãîë:
3223 aX2
:= aX
+ aX2
- 1;
3224 aY2
:= aY
+ aY2
- 1;
3227 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3228 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3229 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3230 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3234 if gWater
<> nil then
3237 for a
:= 0 to High(gWater
) do
3239 if PanelType
<> 0 then
3241 // Ëåâûé âåðõíèé óãîë:
3242 aX
:= X
div ScaleSz
;
3243 aY
:= Y
div ScaleSz
;
3245 aX2
:= max(Width
div ScaleSz
, 1);
3246 aY2
:= max(Height
div ScaleSz
, 1);
3247 // Ïðàâûé íèæíèé óãîë:
3248 aX2
:= aX
+ aX2
- 1;
3249 aY2
:= aY
+ aY2
- 1;
3251 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3254 if gAcid1
<> nil then
3256 // Ðèñóåì êèñëîòó 1:
3257 for a
:= 0 to High(gAcid1
) do
3259 if PanelType
<> 0 then
3261 // Ëåâûé âåðõíèé óãîë:
3262 aX
:= X
div ScaleSz
;
3263 aY
:= Y
div ScaleSz
;
3265 aX2
:= max(Width
div ScaleSz
, 1);
3266 aY2
:= max(Height
div ScaleSz
, 1);
3267 // Ïðàâûé íèæíèé óãîë:
3268 aX2
:= aX
+ aX2
- 1;
3269 aY2
:= aY
+ aY2
- 1;
3271 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3274 if gAcid2
<> nil then
3276 // Ðèñóåì êèñëîòó 2:
3277 for a
:= 0 to High(gAcid2
) do
3279 if PanelType
<> 0 then
3281 // Ëåâûé âåðõíèé óãîë:
3282 aX
:= X
div ScaleSz
;
3283 aY
:= Y
div ScaleSz
;
3285 aX2
:= max(Width
div ScaleSz
, 1);
3286 aY2
:= max(Height
div ScaleSz
, 1);
3287 // Ïðàâûé íèæíèé óãîë:
3288 aX2
:= aX
+ aX2
- 1;
3289 aY2
:= aY
+ aY2
- 1;
3291 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3294 if gPlayers
<> nil then
3297 for a
:= 0 to High(gPlayers
) do
3298 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3300 // Ëåâûé âåðõíèé óãîë:
3301 aX
:= Obj
.X
div ScaleSz
+ 1;
3302 aY
:= Obj
.Y
div ScaleSz
+ 1;
3304 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3305 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3306 // Ïðàâûé íèæíèé óãîë:
3307 aX2
:= aX
+ aX2
- 1;
3308 aY2
:= aY
+ aY2
- 1;
3310 if gPlayers
[a
] = p
then
3311 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3314 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3315 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3316 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3321 g_Mons_ForEach(monDraw
);
3326 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3328 if not hasAmbient
then exit
;
3329 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3333 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3334 //FIXME: broken for splitscreen mode
3335 procedure renderDynLightsInternal ();
3337 //hasAmbient: Boolean;
3338 //ambColor: TDFColor;
3340 lx
, ly
, lrad
: Integer;
3341 scxywh
: array[0..3] of GLint
;
3344 if e_NoGraphics
then exit
;
3346 //TODO: lights should be in separate grid, i think
3347 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3348 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3351 //ambColor := gCurrentMap['light_ambient'].rgba;
3352 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3354 { // this will multiply incoming color to alpha from framebuffer
3356 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3360 * light rendering: (INVALID!)
3361 * glStencilFunc(GL_EQUAL, 0, $ff);
3363 * glClear(GL_STENCIL_BUFFER_BIT);
3364 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3365 * draw shadow volume into stencil buffer
3366 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3367 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3369 * draw color-less quad with light alpha (WARNING! don't touch color!)
3370 * glEnable(GL_BLEND);
3371 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3372 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3374 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3375 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3377 // setup OpenGL parameters
3378 glStencilMask($FFFFFFFF);
3379 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3380 glEnable(GL_STENCIL_TEST
);
3381 glEnable(GL_SCISSOR_TEST
);
3382 glClear(GL_STENCIL_BUFFER_BIT
);
3383 glStencilFunc(GL_EQUAL
, 0, $ff);
3385 for lln
:= 0 to g_dynLightCount
-1 do
3387 lx
:= g_dynLights
[lln
].x
;
3388 ly
:= g_dynLights
[lln
].y
;
3389 lrad
:= g_dynLights
[lln
].radius
;
3390 if (lrad
< 3) then continue
;
3392 if (lx
-sX
+lrad
< 0) then continue
;
3393 if (ly
-sY
+lrad
< 0) then continue
;
3394 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3395 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3397 // set scissor to optimize drawing
3398 if (g_dbg_scale
= 1.0) then
3400 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3404 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3406 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3407 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3408 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3409 // draw extruded panels
3410 glDisable(GL_TEXTURE_2D
);
3411 glDisable(GL_BLEND
);
3412 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3413 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3414 // render light texture
3415 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3416 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3419 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3420 glEnable(GL_TEXTURE_2D
);
3421 // color and opacity
3422 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3423 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3425 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3426 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3427 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3428 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3433 glDisable(GL_STENCIL_TEST
);
3434 glDisable(GL_BLEND
);
3435 glDisable(GL_SCISSOR_TEST
);
3436 //glScissor(0, 0, sWidth, sHeight);
3438 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3439 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3443 function fixViewportForScale (): Boolean;
3445 nx0
, ny0
, nw
, nh
: Integer;
3448 if (g_dbg_scale
<> 1.0) then
3451 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3452 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3453 nw
:= round(sWidth
/g_dbg_scale
);
3454 nh
:= round(sHeight
/g_dbg_scale
);
3463 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3464 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3465 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3467 TDrawCB
= procedure ();
3470 hasAmbient
: Boolean;
3472 doAmbient
: Boolean = false;
3474 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3479 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3480 if gdbg_map_use_accel_render
then
3482 tagmask
:= panelTypeToTag(panType
);
3483 while (gDrawPanelList
.count
> 0) do
3485 pan
:= TPanel(gDrawPanelList
.front());
3486 if ((pan
.tag
and tagmask
) = 0) then break
;
3487 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3488 gDrawPanelList
.popFront();
3493 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3495 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3498 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3500 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3501 if assigned(cb
) then cb();
3502 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3506 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3508 // our accelerated renderer will collect all panels to gDrawPanelList
3509 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3510 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3511 if gdbg_map_use_accel_render
then
3513 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3515 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3517 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3518 g_Map_DrawBack(backXOfs
, backYOfs
);
3519 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3521 if setTransMatrix
then
3523 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3524 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3525 glTranslatef(-sX
, -sY
, 0);
3529 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3530 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3535 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3536 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3537 glClear(GL_COLOR_BUFFER_BIT);
3540 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3543 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3544 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3545 drawOther('items', @g_Items_Draw
);
3546 drawOther('weapons', @g_Weapon_Draw
);
3547 drawOther('shells', @g_Player_DrawShells
);
3548 drawOther('drawall', @g_Player_DrawAll
);
3549 drawOther('corpses', @g_Player_DrawCorpses
);
3550 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3551 drawOther('monsters', @g_Monsters_Draw
);
3552 drawOther('itemdrop', @g_Items_DrawDrop
);
3553 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3554 drawOther('gfx', @g_GFX_Draw
);
3555 drawOther('flags', @g_Map_DrawFlags
);
3556 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3557 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3558 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3559 drawOther('dynlights', @renderDynLightsInternal
);
3561 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3563 renderAmbientQuad(hasAmbient
, ambColor
);
3567 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3570 if g_debug_HealthBar
then
3572 g_Monsters_DrawHealth();
3573 g_Player_DrawHealth();
3576 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3580 procedure DrawMapView(x
, y
, w
, h
: Integer);
3587 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3588 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3595 fixViewportForScale();
3596 renderMapInternal(-bx
, -by
, true);
3602 procedure DrawPlayer(p
: TPlayer
);
3604 px
, py
, a
, b
, c
, d
, i
: Integer;
3607 if (p
= nil) or (p
.FDummy
) then
3610 g_Map_DrawBack(0, 0);
3615 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3616 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3622 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3623 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3625 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3627 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3628 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3630 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3631 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3633 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3634 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3637 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3640 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3641 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3644 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3649 // scaled, ignore level bounds
3650 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3651 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3654 if p
.IncCam
<> 0 then
3656 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3658 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3660 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3664 if py
< gPlayerScreenSize
.Y
div 2 then
3666 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3668 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3672 if p
.IncCam
< 0 then
3674 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3677 if p
.IncCam
> 0 then
3679 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3683 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3684 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3685 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3687 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3688 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3689 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3692 sY
:= -(b
+p
.IncCam
);
3693 sWidth
:= gPlayerScreenSize
.X
;
3694 sHeight
:= gPlayerScreenSize
.Y
;
3696 //glTranslatef(a, b+p.IncCam, 0);
3698 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3700 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3701 fixViewportForScale();
3702 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3704 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3706 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3707 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3708 if (sX
< 0) then sX
:= 0;
3709 if (sY
< 0) then sY
:= 0;
3711 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3712 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3715 //r_smallmap_h: 0: left; 1: center; 2: right
3716 //r_smallmap_v: 0: top; 1: center; 2: bottom
3718 if (gMapInfo
.Width
= sWidth
) then
3722 else if (gMapInfo
.Width
< sWidth
) then
3724 case r_smallmap_h
of
3725 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3726 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3727 else sX
:= 0; // left
3731 if (gMapInfo
.Height
= sHeight
) then
3735 else if (gMapInfo
.Height
< sHeight
) then
3737 case r_smallmap_v
of
3738 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3739 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3740 else sY
:= 0; // top
3746 p
.viewPortW
:= sWidth
;
3747 p
.viewPortH
:= sHeight
;
3749 {$IFDEF ENABLE_HOLMES}
3750 if (p
= gPlayer1
) then
3752 g_Holmes_plrViewPos(sX
, sY
);
3753 g_Holmes_plrViewSize(sWidth
, sHeight
);
3757 renderMapInternal(-c
, -d
, true);
3759 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3760 case gPlayerIndicator
of
3762 p
.DrawIndicator(_RGB(255, 255, 255));
3765 for i
:= 0 to High(gPlayers
) do
3766 if gPlayers
[i
] <> nil then
3767 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3768 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3769 if gPlayerIndicatorStyle
= 1 then
3770 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3771 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3774 if p
.FSpectator
then
3775 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3776 p
.GameY
+ PLAYER_RECT_CY
- 4,
3777 'X', gStdFont
, 255, 255, 255, 1, True);
3779 for a := 0 to High(gCollideMap) do
3780 for b := 0 to High(gCollideMap[a]) do
3783 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3785 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3789 1: e_DrawPoint(1, b, a, 200, 200, 200);
3790 2: e_DrawPoint(1, b, a, 64, 64, 255);
3791 3: e_DrawPoint(1, b, a, 255, 0, 255);
3801 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3802 if g_Debug_Player
then
3803 g_Player_DrawDebug(p
);
3807 procedure drawProfilers ();
3812 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3813 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3814 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3817 procedure g_Game_Draw();
3824 plView1
, plView2
: TPlayer
;
3827 if gExit
= EXIT_QUIT
then Exit
;
3829 Time
:= sys_GetTicks() {div 1000};
3830 FPSCounter
:= FPSCounter
+1;
3831 if Time
- FPSTime
>= 1000 then
3838 if gGameOn
or (gState
= STATE_FOLD
) then
3840 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3842 gSpectMode
:= SPECT_NONE
;
3843 if not gRevertPlayers
then
3845 plView1
:= gPlayer1
;
3846 plView2
:= gPlayer2
;
3850 plView1
:= gPlayer2
;
3851 plView2
:= gPlayer1
;
3855 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3857 gSpectMode
:= SPECT_NONE
;
3858 if gPlayer2
= nil then
3861 plView1
:= gPlayer2
;
3870 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3871 gSpectMode
:= SPECT_STATS
;
3873 if gSpectMode
= SPECT_PLAYERS
then
3874 if gPlayers
<> nil then
3876 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3877 if plView1
= nil then
3879 gSpectPID1
:= GetActivePlayerID_Next();
3880 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3882 if gSpectViewTwo
then
3884 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3885 if plView2
= nil then
3887 gSpectPID2
:= GetActivePlayerID_Next();
3888 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3893 if gSpectMode
= SPECT_MAPVIEW
then
3895 // Ðåæèì ïðîñìîòðà êàðòû
3897 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3898 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3899 gHearPoint1
.Active
:= True;
3900 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3901 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3902 gHearPoint2
.Active
:= False;
3906 Split
:= (plView1
<> nil) and (plView2
<> nil);
3908 // Òî÷êè ñëóõà èãðîêîâ
3909 if plView1
<> nil then
3911 gHearPoint1
.Active
:= True;
3912 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3913 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3915 gHearPoint1
.Active
:= False;
3916 if plView2
<> nil then
3918 gHearPoint2
.Active
:= True;
3919 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3920 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3922 gHearPoint2
.Active
:= False;
3924 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3925 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3928 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3929 if gScreenHeight
mod 2 = 0 then
3930 Dec(gPlayerScreenSize
.Y
);
3933 gPlayerScreenSize
.Y
:= gScreenHeight
;
3936 if gScreenHeight
mod 2 = 0 then
3937 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3939 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3941 DrawPlayer(plView1
);
3942 gPlayer1ScreenCoord
.X
:= sX
;
3943 gPlayer1ScreenCoord
.Y
:= sY
;
3947 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3949 DrawPlayer(plView2
);
3950 gPlayer2ScreenCoord
.X
:= sX
;
3951 gPlayer2ScreenCoord
.Y
:= sY
;
3954 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3957 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3960 {$IFDEF ENABLE_HOLMES}
3962 if (g_holmes_enabled
) then g_Holmes_Draw();
3965 if MessageText
<> '' then
3969 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3971 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3972 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3974 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3975 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3978 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3980 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3982 // Draw spectator GUI
3985 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3988 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3990 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3992 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3994 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3995 if gSpectMode
= SPECT_STATS
then
3997 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3998 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4000 if gSpectMode
= SPECT_MAPVIEW
then
4002 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4003 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4004 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4005 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4006 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4008 if gSpectMode
= SPECT_PLAYERS
then
4010 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4011 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4012 if gSpectViewTwo
then
4014 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4015 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4016 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4017 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4022 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4028 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4030 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4031 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4033 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4034 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4035 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4040 if (gState
= STATE_MENU
) then
4042 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4043 // F3 at menu will show game loading dialog
4044 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4045 if (g_ActiveWindow
<> nil) then
4047 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4048 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4052 // F3 at titlepic will show game loading dialog
4053 if e_KeyPressed(IK_F3
) then
4055 g_Menu_Show_LoadMenu(true);
4056 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4061 if gState
= STATE_FOLD
then
4063 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4066 if gState
= STATE_INTERCUSTOM
then
4068 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4070 back
:= 'TEXTURE_endpic';
4071 if not g_Texture_Get(back
, ID
) then
4072 back
:= _lc
[I_TEXTURE_ENDPIC
];
4077 DrawMenuBackground(back
);
4081 if g_ActiveWindow
<> nil then
4083 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4084 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4088 if gState
= STATE_INTERSINGLE
then
4090 if EndingGameCounter
> 0 then
4092 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4098 DrawMenuBackground(back
);
4102 if g_ActiveWindow
<> nil then
4104 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4105 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4110 if gState
= STATE_ENDPIC
then
4113 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4114 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4116 if g_ActiveWindow
<> nil then
4118 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4119 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4123 if gState
= STATE_SLIST
then
4125 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4127 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4128 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4130 DrawMenuBackground('MENU_BACKGROUND');
4131 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4132 g_Serverlist_Draw(slCurrent
, slTable
);
4136 if g_ActiveWindow
<> nil then
4140 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4141 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4143 g_ActiveWindow
.Draw();
4150 if g_debug_Sounds
and gGameOn
then
4152 for w
:= 0 to High(e_SoundsArray
) do
4153 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4154 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4159 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4160 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4163 if gGameOn
and gShowTime
then
4164 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4166 if gGameOn
then drawProfilers();
4168 {$IFDEF ENABLE_HOLMES}
4175 procedure g_Game_Quit();
4177 g_Game_StopAllSounds(True);
4180 g_PlayerModel_FreeData();
4181 g_Texture_DeleteAll();
4182 g_Frames_DeleteAll();
4184 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4187 if NetInitDone
then g_Net_Free
;
4189 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4190 if gMapToDelete
<> '' then
4191 g_Game_DeleteTestMap();
4197 procedure g_FatalError(Text: String);
4199 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4200 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4202 gExit
:= EXIT_SIMPLE
;
4205 procedure g_SimpleError(Text: String);
4207 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4208 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4211 procedure g_Game_SetupScreenSize();
4213 RES_FACTOR
= 4.0 / 3.0;
4219 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4220 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4221 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4222 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4224 gPlayerScreenSize
.Y
:= gScreenHeight
;
4226 // Ðàçìåð çàäíåãî ïëàíà:
4227 if BackID
<> DWORD(-1) then
4230 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4231 (gScreenHeight
*s
> gMapInfo
.Height
) then
4233 gBackSize
.X
:= gScreenWidth
;
4234 gBackSize
.Y
:= gScreenHeight
;
4238 e_GetTextureSize(BackID
, @bw
, @bh
);
4239 rf
:= Single(bw
) / Single(bh
);
4240 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4241 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4242 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4243 if (s
< 1.0) then s
:= 1.0;
4244 gBackSize
.X
:= Round(bw
*s
);
4245 gBackSize
.Y
:= Round(bh
*s
);
4250 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4252 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4255 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4257 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4258 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4260 if gPlayer1
= nil then
4262 if g_Game_IsClient
then
4264 if NetPlrUID1
> -1 then
4266 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4267 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4272 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4273 Team
:= gPlayer1Settings
.Team
;
4275 // Ñîçäàíèå ïåðâîãî èãðîêà:
4276 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4277 gPlayer1Settings
.Color
,
4279 if gPlayer1
= nil then
4280 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4283 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4284 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4285 if g_Game_IsServer
and g_Game_IsNet
then
4286 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4287 gPlayer1
.Respawn(False, True);
4288 g_Net_Slist_ServerPlayerComes();
4293 if gPlayer2
= nil then
4295 if g_Game_IsClient
then
4297 if NetPlrUID2
> -1 then
4298 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4302 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4303 Team
:= gPlayer2Settings
.Team
;
4305 // Ñîçäàíèå âòîðîãî èãðîêà:
4306 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4307 gPlayer2Settings
.Color
,
4309 if gPlayer2
= nil then
4310 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4313 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4314 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4315 if g_Game_IsServer
and g_Game_IsNet
then
4316 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4317 gPlayer2
.Respawn(False, True);
4318 g_Net_Slist_ServerPlayerComes();
4325 procedure g_Game_RemovePlayer();
4329 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4330 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4335 if g_Game_IsServer
then
4338 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4339 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4340 g_Player_Remove(Pl
.UID
);
4341 g_Net_Slist_ServerPlayerLeaves();
4349 if g_Game_IsServer
then
4352 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4353 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4354 g_Player_Remove(Pl
.UID
);
4355 g_Net_Slist_ServerPlayerLeaves();
4359 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4363 g_Net_Slist_ServerPlayerLeaves();
4366 procedure g_Game_Spectate();
4368 g_Game_RemovePlayer();
4369 if gPlayer1
<> nil then
4370 g_Game_RemovePlayer();
4373 procedure g_Game_SpectateCenterView();
4375 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4376 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4379 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4386 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4388 g_Game_ClearLoading();
4391 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4394 gGameSettings
.GameType
:= GT_SINGLE
;
4395 gGameSettings
.MaxLives
:= 0;
4396 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4397 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4398 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4399 gSwitchGameMode
:= GM_SINGLE
;
4401 g_Game_ExecuteEvent('ongamestart');
4403 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4404 g_Game_SetupScreenSize();
4406 // Ñîçäàíèå ïåðâîãî èãðîêà:
4407 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4408 gPlayer1Settings
.Color
,
4409 gPlayer1Settings
.Team
, False));
4410 if gPlayer1
= nil then
4412 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4416 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4419 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4422 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4423 gPlayer2Settings
.Color
,
4424 gPlayer2Settings
.Team
, False));
4425 if gPlayer2
= nil then
4427 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4431 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4435 // Çàãðóçêà è çàïóñê êàðòû:
4436 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4438 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4439 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4443 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4447 for i
:= nPl
+1 to nPlayers
do
4448 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4451 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4452 TimeLimit
, GoalLimit
: Word;
4454 Options
: LongWord; nPlayers
: Byte);
4460 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4462 g_Game_ClearLoading();
4465 gGameSettings
.GameType
:= GT_CUSTOM
;
4466 gGameSettings
.GameMode
:= GameMode
;
4467 gSwitchGameMode
:= GameMode
;
4468 gGameSettings
.TimeLimit
:= TimeLimit
;
4469 gGameSettings
.GoalLimit
:= GoalLimit
;
4470 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4471 gGameSettings
.Options
:= Options
;
4473 gCoopTotalMonstersKilled
:= 0;
4474 gCoopTotalSecretsFound
:= 0;
4475 gCoopTotalMonsters
:= 0;
4476 gCoopTotalSecrets
:= 0;
4480 g_Game_ExecuteEvent('ongamestart');
4482 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4483 g_Game_SetupScreenSize();
4485 // Ðåæèì íàáëþäàòåëÿ:
4486 if nPlayers
= 0 then
4493 if nPlayers
>= 1 then
4495 // Ñîçäàíèå ïåðâîãî èãðîêà:
4496 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4497 gPlayer1Settings
.Color
,
4498 gPlayer1Settings
.Team
, False));
4499 if gPlayer1
= nil then
4501 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4505 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4509 if nPlayers
>= 2 then
4511 // Ñîçäàíèå âòîðîãî èãðîêà:
4512 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4513 gPlayer2Settings
.Color
,
4514 gPlayer2Settings
.Team
, False));
4515 if gPlayer2
= nil then
4517 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4521 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4525 // Çàãðóçêà è çàïóñê êàðòû:
4526 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4528 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4532 // Íåò òî÷åê ïîÿâëåíèÿ:
4533 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4534 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4535 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4536 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4537 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4539 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4543 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4547 for i
:= nPl
+1 to nPlayers
do
4548 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4551 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4552 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4553 Options
: LongWord; nPlayers
: Byte;
4554 IPAddr
: LongWord; Port
: Word);
4557 g_Net_Slist_ServerClosed();
4559 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4561 g_Game_ClearLoading();
4564 gGameSettings
.GameType
:= GT_SERVER
;
4565 gGameSettings
.GameMode
:= GameMode
;
4566 gSwitchGameMode
:= GameMode
;
4567 gGameSettings
.TimeLimit
:= TimeLimit
;
4568 gGameSettings
.GoalLimit
:= GoalLimit
;
4569 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4570 gGameSettings
.Options
:= Options
;
4572 gCoopTotalMonstersKilled
:= 0;
4573 gCoopTotalSecretsFound
:= 0;
4574 gCoopTotalMonsters
:= 0;
4575 gCoopTotalSecrets
:= 0;
4579 g_Game_ExecuteEvent('ongamestart');
4581 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4582 g_Game_SetupScreenSize();
4584 // Ðåæèì íàáëþäàòåëÿ:
4585 if nPlayers
= 0 then
4591 if nPlayers
>= 1 then
4593 // Ñîçäàíèå ïåðâîãî èãðîêà:
4594 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4595 gPlayer1Settings
.Color
,
4596 gPlayer1Settings
.Team
, False));
4597 if gPlayer1
= nil then
4599 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4603 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4606 if nPlayers
>= 2 then
4608 // Ñîçäàíèå âòîðîãî èãðîêà:
4609 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4610 gPlayer2Settings
.Color
,
4611 gPlayer2Settings
.Team
, False));
4612 if gPlayer2
= nil then
4614 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4618 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4621 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4622 if NetForwardPorts
then
4623 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4626 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4628 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4632 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4634 g_Net_Slist_ServerStarted();
4636 // Çàãðóçêà è çàïóñê êàðòû:
4637 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4639 g_Net_Slist_ServerClosed();
4640 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4644 // Íåò òî÷åê ïîÿâëåíèÿ:
4645 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4646 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4647 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4648 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4649 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4651 g_Net_Slist_ServerClosed();
4652 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4656 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4659 g_Net_Slist_ServerMapStarted();
4660 NetState
:= NET_STATE_GAME
;
4663 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4678 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4679 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4681 g_Game_ClearLoading();
4684 gGameSettings
.GameType
:= GT_CLIENT
;
4686 gCoopTotalMonstersKilled
:= 0;
4687 gCoopTotalSecretsFound
:= 0;
4688 gCoopTotalMonsters
:= 0;
4689 gCoopTotalSecrets
:= 0;
4693 g_Game_ExecuteEvent('ongamestart');
4695 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4696 g_Game_SetupScreenSize();
4698 NetState
:= NET_STATE_AUTH
;
4700 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4702 // create (or update) map/resource databases
4703 g_Res_CreateDatabases(true);
4706 if not g_Net_Connect(Addr
, Port
) then
4708 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4709 NetState
:= NET_STATE_NONE
;
4713 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4715 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4720 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4721 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4722 // thank you, enet. let's ignore failures altogether then.
4723 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4725 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4727 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4729 // ignore all download packets, they're processed by separate code
4730 enet_packet_destroy(NetEvent
.packet
);
4733 Ptr
:= NetEvent
.packet
^.data
;
4734 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4736 enet_packet_destroy(NetEvent
.packet
);
4740 InMsg
.ReadLongWord(); // skip size
4741 MID
:= InMsg
.ReadByte();
4743 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4745 NetMyID
:= InMsg
.ReadByte();
4746 NetPlrUID1
:= InMsg
.ReadWord();
4748 WadName
:= InMsg
.ReadString();
4749 Map
:= InMsg
.ReadString();
4751 gWADHash
:= InMsg
.ReadMD5();
4753 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4754 gSwitchGameMode
:= gGameSettings
.GameMode
;
4755 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4756 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4757 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4758 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4759 T
:= InMsg
.ReadLongWord();
4761 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4762 //if newResPath = '' then
4764 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4765 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4766 if newResPath
= '' then
4768 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4769 enet_packet_destroy(NetEvent
.packet
);
4770 NetState
:= NET_STATE_NONE
;
4773 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4775 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4778 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4779 gPlayer1Settings
.Color
,
4780 gPlayer1Settings
.Team
, False));
4782 if gPlayer1
= nil then
4784 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4786 enet_packet_destroy(NetEvent
.packet
);
4787 NetState
:= NET_STATE_NONE
;
4791 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4792 gPlayer1
.UID
:= NetPlrUID1
;
4793 gPlayer1
.Reset(True);
4795 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4797 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4799 enet_packet_destroy(NetEvent
.packet
);
4800 NetState
:= NET_STATE_NONE
;
4808 enet_packet_destroy(NetEvent
.packet
);
4812 enet_packet_destroy(NetEvent
.packet
);
4816 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4819 if (NetEvent
.data
<= NET_DISC_MAX
) then
4820 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4821 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4828 ProcessLoading(true);
4830 if g_Net_UserRequestExit() then
4839 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4840 NetState
:= NET_STATE_NONE
;
4844 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4845 gLMSRespawnTime
:= 0;
4848 NetState
:= NET_STATE_GAME
;
4849 MC_SEND_FullStateRequest
;
4850 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4854 lastAsMegaWad
: Boolean = false;
4856 procedure g_Game_ChangeMap(const MapPath
: String);
4860 g_Game_ClearLoading();
4862 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4863 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4864 if gExitByTrigger
then
4867 gExitByTrigger
:= False;
4869 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4870 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4873 procedure g_Game_Restart();
4877 if g_Game_IsClient
then
4879 map
:= g_ExtractFileName(gMapInfo
.Map
);
4880 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4884 g_Game_ClearLoading();
4885 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
4888 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4890 NewWAD
, ResName
: String;
4894 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4895 g_Player_RemoveAllCorpses();
4897 if (not g_Game_IsClient
) and
4898 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4899 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4901 if gSwitchGameMode
= GM_CTF
then
4902 gGameSettings
.MaxLives
:= 0;
4903 gGameSettings
.GameMode
:= gSwitchGameMode
;
4906 gSwitchGameMode
:= gGameSettings
.GameMode
;
4908 g_Player_ResetTeams();
4910 lastAsMegaWad
:= asMegawad
;
4911 if isWadPath(Map
) then
4913 NewWAD
:= g_ExtractWadName(Map
);
4914 ResName
:= g_ExtractFileName(Map
);
4915 if g_Game_IsServer
then
4917 nws
:= findDiskWad(NewWAD
);
4918 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4921 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4922 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4926 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
4927 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
4929 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4930 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4932 if (length(nws
) = 0) then
4934 ResName
:= ''; // failed
4939 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4940 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4941 g_Game_LoadWAD(NewWAD
);
4946 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4947 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
4952 NewWAD
:= gGameSettings
.WAD
;
4956 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4958 if (ResName
<> '') and (NewWAD
<> '') then
4960 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4961 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
4965 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4967 gState
:= STATE_NONE
;
4968 g_ActiveWindow
:= nil;
4974 if gGameSettings
.GameMode
= GM_CTF
then
4976 g_Map_ResetFlag(FLAG_RED
);
4977 g_Map_ResetFlag(FLAG_BLUE
);
4978 // CTF, à ôëàãîâ íåò:
4979 if not g_Map_HaveFlagPoints() then
4980 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4985 gState
:= STATE_MENU
;
4990 gPauseMain
:= false;
4991 gPauseHolmes
:= false;
4993 NetTimeToUpdate
:= 1;
4994 NetTimeToReliable
:= 0;
4995 NetTimeToMaster
:= NetMasterRate
;
4996 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4997 gLMSRespawnTime
:= 0;
4998 gMissionFailed
:= False;
5001 gCoopMonstersKilled
:= 0;
5002 gCoopSecretsFound
:= 0;
5004 gVoteInProgress
:= False;
5005 gVotePassed
:= False;
5011 if not gGameOn
then Exit
;
5013 g_Game_SpectateCenterView();
5015 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5017 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5018 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5019 gLMSSoftSpawn
:= True;
5020 if NetMode
= NET_SERVER
then
5021 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
5023 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
5026 if NetMode
= NET_SERVER
then
5028 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5031 g_Net_Slist_ServerMapStarted();
5033 if NetClients
<> nil then
5034 for I
:= 0 to High(NetClients
) do
5035 if NetClients
[I
].Used
then
5037 NetClients
[I
].Voted
:= False;
5038 if NetClients
[I
].RequestedFullUpdate
then
5040 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5041 NetClients
[I
].RequestedFullUpdate
:= False;
5045 g_Net_UnbanNonPermHosts();
5050 gCoopTotalMonstersKilled
:= 0;
5051 gCoopTotalSecretsFound
:= 0;
5052 gCoopTotalMonsters
:= 0;
5053 gCoopTotalSecrets
:= 0;
5057 g_Game_ExecuteEvent('onmapstart');
5060 procedure SetFirstLevel
;
5064 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5065 if MapList
= nil then
5068 SortSArray(MapList
);
5069 gNextMap
:= MapList
[Low(MapList
)];
5074 procedure g_Game_ExitLevel(const Map
: AnsiString);
5078 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5079 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5080 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5081 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5083 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5084 if gGameSettings
.GameType
= GT_SINGLE
then
5085 gExit
:= EXIT_ENDLEVELSINGLE
5086 else // Âûøëè â âûõîä â Ñâîåé èãðå
5088 gExit
:= EXIT_ENDLEVELCUSTOM
;
5089 if gGameSettings
.GameMode
= GM_COOP
then
5090 g_Player_RememberAll
;
5092 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5095 if gGameSettings
.GameMode
= GM_COOP
then
5098 gStatsPressed
:= True;
5099 gNextMap
:= 'MAP01';
5101 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5104 if g_Game_IsNet
then
5106 MH_SEND_GameStats();
5107 MH_SEND_CoopStats();
5113 procedure g_Game_RestartLevel();
5117 if gGameSettings
.GameMode
= GM_SINGLE
then
5122 gExit
:= EXIT_ENDLEVELCUSTOM
;
5123 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5127 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5129 gWAD
{, xwad}: String;
5132 if not g_Game_IsClient
then Exit
;
5133 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5135 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5140 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5144 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5147 g_Game_LoadWAD(NewWAD
);
5151 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5152 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5155 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5156 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5160 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5164 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5165 g_Game_LoadWAD(NewWAD);
5169 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5171 i
, n
, nb
, nr
: Integer;
5173 function monRespawn (mon
: TMonster
): Boolean;
5175 result
:= false; // don't stop
5176 if not mon
.FNoRespawn
then mon
.Respawn();
5180 if not g_Game_IsServer
then Exit
;
5181 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5182 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5183 gLMSRespawnTime
:= 0;
5186 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5188 gMissionFailed
:= True;
5189 g_Game_RestartLevel
;
5193 n
:= 0; nb
:= 0; nr
:= 0;
5194 for i
:= Low(gPlayers
) to High(gPlayers
) do
5195 if (gPlayers
[i
] <> nil) and
5196 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5197 (gPlayers
[i
] is TBot
)) then
5200 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5201 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5204 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5206 // wait a second until the fuckers finally decide to join
5207 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5208 gLMSRespawnTime
:= gTime
+ 1000;
5209 gLMSSoftSpawn
:= NoMapRestart
;
5213 g_Player_RemoveAllCorpses
;
5214 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5215 if g_Game_IsNet
then
5216 MH_SEND_GameEvent(NET_EV_LMS_START
);
5218 for i
:= Low(gPlayers
) to High(gPlayers
) do
5220 if gPlayers
[i
] = nil then continue
;
5221 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5222 // don't touch normal spectators
5223 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5225 gPlayers
[i
].FNoRespawn
:= True;
5226 gPlayers
[i
].Lives
:= 0;
5227 if g_Game_IsNet
then
5228 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5231 gPlayers
[i
].FNoRespawn
:= False;
5232 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5233 gPlayers
[i
].Respawn(False, True);
5234 if gGameSettings
.GameMode
= GM_COOP
then
5236 gPlayers
[i
].Frags
:= 0;
5237 gPlayers
[i
].RecallState
;
5239 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5240 gPlayer1
:= g_Player_Get(gLMSPID1
);
5241 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5242 gPlayer2
:= g_Player_Get(gLMSPID2
);
5245 g_Items_RestartRound();
5248 g_Mons_ForEach(monRespawn
);
5250 gLMSSoftSpawn
:= False;
5253 function g_Game_GetFirstMap(WAD
: String): String;
5257 MapList
:= g_Map_GetMapsList(WAD
);
5258 if MapList
= nil then
5261 SortSArray(MapList
);
5262 Result
:= MapList
[Low(MapList
)];
5264 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5270 function g_Game_GetNextMap(): String;
5277 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5278 if MapList
= nil then
5281 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5283 SortSArray(MapList
);
5285 for I
:= Low(MapList
) to High(MapList
) do
5286 if Map
= MapList
[I
] then
5292 if MapIndex
<> -255 then
5294 if MapIndex
= High(MapList
) then
5295 Result
:= MapList
[Low(MapList
)]
5297 Result
:= MapList
[MapIndex
+ 1];
5299 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5305 procedure g_Game_NextLevel();
5307 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5308 gExit
:= EXIT_ENDLEVELCUSTOM
5311 gExit
:= EXIT_ENDLEVELSINGLE
;
5315 if gNextMap
<> '' then Exit
;
5316 gNextMap
:= g_Game_GetNextMap();
5319 function g_Game_IsTestMap(): Boolean;
5321 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5324 procedure g_Game_DeleteTestMap();
5327 //MapName: AnsiString;
5335 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5336 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5337 if (a
= 0) then exit
;
5339 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5340 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5341 Delete(gMapToDelete
, 1, a
+5);
5342 gMapToDelete
:= UpperCase(gMapToDelete
);
5344 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5347 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5348 if MapName <> TEST_MAP_NAME then
5351 if not gTempDelete then
5353 time := g_GetFileTime(WadName);
5354 WAD := TWADFile.Create();
5357 if not WAD.ReadFile(WadName) then
5358 begin // Íåò òàêîãî WAD-ôàéëà
5363 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5365 MapList := WAD.GetResourcesList('');
5367 if MapList <> nil then
5368 for a := 0 to High(MapList) do
5369 if MapList[a] = MapName then
5371 // Óäàëÿåì è ñîõðàíÿåì:
5372 WAD.RemoveResource('', MapName);
5373 WAD.SaveTo(WadName);
5378 g_SetFileTime(WadName, time);
5381 if gTempDelete
then DeleteFile(WadName
);
5384 procedure GameCVars(P
: SSArray
);
5387 stat
: TPlayerStatArray
;
5392 cmd
:= LowerCase(P
[0]);
5393 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5395 with gGameSettings
do
5397 if (Length(P
) > 1) and
5398 ((P
[1] = '1') or (P
[1] = '0')) then
5400 if (P
[1][1] = '1') then
5401 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5403 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5406 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5407 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5409 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5411 if g_Game_IsNet
then MH_SEND_GameSettings
;
5414 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5416 with gGameSettings
do
5418 if (Length(P
) > 1) and
5419 ((P
[1] = '1') or (P
[1] = '0')) then
5421 if (P
[1][1] = '1') then
5422 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5424 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5427 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5428 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5430 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5432 if g_Game_IsNet
then MH_SEND_GameSettings
;
5435 else if cmd
= 'g_gamemode' then
5437 a
:= g_Game_TextToMode(P
[1]);
5438 if a
= GM_SINGLE
then a
:= GM_COOP
;
5439 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5441 gSwitchGameMode
:= a
;
5442 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5443 (gState
= STATE_INTERSINGLE
) then
5444 gSwitchGameMode
:= GM_SINGLE
;
5446 gGameSettings
.GameMode
:= gSwitchGameMode
;
5448 if gSwitchGameMode
= gGameSettings
.GameMode
then
5449 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5450 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5452 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5453 [g_Game_ModeToText(gGameSettings
.GameMode
),
5454 g_Game_ModeToText(gSwitchGameMode
)]));
5456 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5458 with gGameSettings
do
5460 if (Length(P
) > 1) and
5461 ((P
[1] = '1') or (P
[1] = '0')) then
5463 if (P
[1][1] = '1') then
5464 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5466 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5469 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5470 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5472 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5473 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5475 if g_Game_IsNet
then MH_SEND_GameSettings
;
5478 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5480 with gGameSettings
do
5482 if (Length(P
) > 1) and
5483 ((P
[1] = '1') or (P
[1] = '0')) then
5485 if (P
[1][1] = '1') then
5486 Options
:= Options
or GAME_OPTION_MONSTERS
5488 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5491 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5492 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5494 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5495 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5497 if g_Game_IsNet
then MH_SEND_GameSettings
;
5500 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5502 with gGameSettings
do
5504 if (Length(P
) > 1) and
5505 ((P
[1] = '1') or (P
[1] = '0')) then
5507 if (P
[1][1] = '1') then
5508 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5510 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5513 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5514 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5516 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5518 if g_Game_IsNet
then MH_SEND_GameSettings
;
5521 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5523 with gGameSettings
do
5525 if (Length(P
) > 1) and
5526 ((P
[1] = '1') or (P
[1] = '0')) then
5528 if (P
[1][1] = '1') then
5529 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5531 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5534 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5535 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5537 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5539 if g_Game_IsNet
then MH_SEND_GameSettings
;
5542 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5544 if Length(P
) > 1 then
5546 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5547 gGameSettings
.WarmupTime
:= 30
5549 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5552 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5553 [gGameSettings
.WarmupTime
]));
5554 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5556 else if cmd
= 'net_interp' then
5558 if (Length(P
) > 1) then
5559 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5560 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5561 s
:= e_GetWriteableDir(ConfigDirs
);
5564 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5565 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5566 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5570 else if cmd
= 'net_forceplayerupdate' then
5572 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5573 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5575 if NetForcePlayerUpdate
then
5576 g_Console_Add('net_forceplayerupdate = 1')
5578 g_Console_Add('net_forceplayerupdate = 0');
5580 s
:= e_GetWriteableDir(ConfigDirs
);
5583 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5584 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5585 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5589 else if cmd
= 'net_predictself' then
5591 if (Length(P
) > 1) and
5592 ((P
[1] = '1') or (P
[1] = '0')) then
5593 NetPredictSelf
:= (P
[1][1] = '1');
5595 if NetPredictSelf
then
5596 g_Console_Add('net_predictself = 1')
5598 g_Console_Add('net_predictself = 0');
5600 s
:= e_GetWriteableDir(ConfigDirs
);
5603 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5604 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5605 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5609 else if cmd
= 'sv_name' then
5611 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5613 NetServerName
:= P
[1];
5614 if Length(NetServerName
) > 64 then
5615 SetLength(NetServerName
, 64);
5616 g_Net_Slist_ServerRenamed();
5619 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5621 else if cmd
= 'sv_passwd' then
5623 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5625 NetPassword
:= P
[1];
5626 if Length(NetPassword
) > 24 then
5627 SetLength(NetPassword
, 24);
5628 g_Net_Slist_ServerRenamed();
5631 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5633 else if cmd
= 'sv_maxplrs' then
5635 if (Length(P
) > 1) then
5637 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5638 if g_Game_IsServer
and g_Game_IsNet
then
5641 for a
:= 0 to High(NetClients
) do
5643 if NetClients
[a
].Used
then
5646 if b
> NetMaxClients
then
5648 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5649 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5650 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5651 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5655 g_Net_Slist_ServerRenamed();
5659 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5661 else if cmd
= 'sv_public' then
5663 if (Length(P
) > 1) then
5665 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5666 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5669 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5671 else if cmd
= 'sv_intertime' then
5673 if (Length(P
) > 1) then
5674 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5676 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5678 else if cmd
= 'p1_name' then
5680 if (Length(P
) > 1) and gGameOn
then
5682 if g_Game_IsClient
then
5684 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5685 MC_SEND_PlayerSettings
;
5688 if gPlayer1
<> nil then
5690 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5691 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5694 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5697 else if cmd
= 'p2_name' then
5699 if (Length(P
) > 1) and gGameOn
then
5701 if g_Game_IsClient
then
5703 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5704 MC_SEND_PlayerSettings
;
5707 if gPlayer2
<> nil then
5709 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5710 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5713 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5716 else if cmd
= 'p1_color' then
5718 if Length(P
) > 3 then
5719 if g_Game_IsClient
then
5721 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5722 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5723 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5724 MC_SEND_PlayerSettings
;
5727 if gPlayer1
<> nil then
5729 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5730 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5731 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5732 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5735 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5736 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5737 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5739 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5741 if Length(P
) > 3 then
5742 if g_Game_IsClient
then
5744 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5745 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5746 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5747 MC_SEND_PlayerSettings
;
5750 if gPlayer2
<> nil then
5752 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5753 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5754 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5755 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5758 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5759 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5760 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5762 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5764 if cmd
= 'r_showscore' then
5766 if (Length(P
) > 1) and
5767 ((P
[1] = '1') or (P
[1] = '0')) then
5768 gShowGoals
:= (P
[1][1] = '1');
5771 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5773 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5775 else if cmd
= 'r_showstat' then
5777 if (Length(P
) > 1) and
5778 ((P
[1] = '1') or (P
[1] = '0')) then
5779 gShowStat
:= (P
[1][1] = '1');
5782 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5784 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5786 else if cmd
= 'r_showkillmsg' then
5788 if (Length(P
) > 1) and
5789 ((P
[1] = '1') or (P
[1] = '0')) then
5790 gShowKillMsg
:= (P
[1][1] = '1');
5792 if gShowKillMsg
then
5793 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5795 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5797 else if cmd
= 'r_showlives' then
5799 if (Length(P
) > 1) and
5800 ((P
[1] = '1') or (P
[1] = '0')) then
5801 gShowLives
:= (P
[1][1] = '1');
5804 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5806 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5808 else if cmd
= 'r_showspect' then
5810 if (Length(P
) > 1) and
5811 ((P
[1] = '1') or (P
[1] = '0')) then
5812 gSpectHUD
:= (P
[1][1] = '1');
5815 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5817 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5819 else if cmd
= 'r_showping' then
5821 if (Length(P
) > 1) and
5822 ((P
[1] = '1') or (P
[1] = '0')) then
5823 gShowPing
:= (P
[1][1] = '1');
5826 g_Console_Add(_lc
[I_MSG_PING_ON
])
5828 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5830 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5832 if Length(P
) > 1 then
5834 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5835 gGameSettings
.GoalLimit
:= 0
5840 if gGameSettings
.GameMode
= GM_DM
then
5842 stat
:= g_Player_GetStats();
5844 for a
:= 0 to High(stat
) do
5845 if stat
[a
].Frags
> b
then
5849 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5851 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5854 if g_Game_IsNet
then MH_SEND_GameSettings
;
5857 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5859 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5861 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5862 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5864 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5865 [gGameSettings
.TimeLimit
div 3600,
5866 (gGameSettings
.TimeLimit
div 60) mod 60,
5867 gGameSettings
.TimeLimit
mod 60]));
5868 if g_Game_IsNet
then MH_SEND_GameSettings
;
5870 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5872 if Length(P
) > 1 then
5874 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5875 gGameSettings
.MaxLives
:= 0
5879 stat
:= g_Player_GetStats();
5881 for a
:= 0 to High(stat
) do
5882 if stat
[a
].Lives
> b
then
5884 gGameSettings
.MaxLives
:=
5885 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5889 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5890 [gGameSettings
.MaxLives
]));
5891 if g_Game_IsNet
then MH_SEND_GameSettings
;
5896 procedure PrintHeapStats();
5900 hs
:= GetFPCHeapStatus();
5901 e_LogWriteLn ('v===== heap status =====v');
5902 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5903 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5904 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5905 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5906 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5907 e_LogWriteLn ('^=======================^');
5910 procedure DebugCommands(P
: SSArray
);
5917 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5918 if {gDebugMode}conIsCheatsEnabled
then
5920 cmd
:= LowerCase(P
[0]);
5921 if cmd
= 'd_window' then
5923 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5924 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5926 else if cmd
= 'd_sounds' then
5928 if (Length(P
) > 1) and
5929 ((P
[1] = '1') or (P
[1] = '0')) then
5930 g_Debug_Sounds
:= (P
[1][1] = '1');
5932 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5934 else if cmd
= 'd_frames' then
5936 if (Length(P
) > 1) and
5937 ((P
[1] = '1') or (P
[1] = '0')) then
5938 g_Debug_Frames
:= (P
[1][1] = '1');
5940 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5942 else if cmd
= 'd_winmsg' then
5944 if (Length(P
) > 1) and
5945 ((P
[1] = '1') or (P
[1] = '0')) then
5946 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5948 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5950 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5952 if (Length(P
) > 1) and
5953 ((P
[1] = '1') or (P
[1] = '0')) then
5954 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5956 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5958 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5960 if Length(P
) > 1 then
5962 '0': g_debug_BotAIOff
:= 0;
5963 '1': g_debug_BotAIOff
:= 1;
5964 '2': g_debug_BotAIOff
:= 2;
5965 '3': g_debug_BotAIOff
:= 3;
5968 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5970 else if cmd
= 'd_monster' then
5972 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5973 if Length(P
) < 2 then
5975 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5976 g_Console_Add('ID | Name');
5977 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5978 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5979 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5982 a
:= StrToIntDef(P
[1], 0);
5983 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5984 a
:= g_Mons_TypeIdByName(P
[1]);
5986 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5987 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5990 with gPlayer1
.Obj
do
5992 mon
:= g_Monsters_Create(a
,
5993 X
+ Rect
.X
+ (Rect
.Width
div 2),
5994 Y
+ Rect
.Y
+ Rect
.Height
,
5995 gPlayer1
.Direction
, True);
5997 if (Length(P
) > 2) and (mon
<> nil) then
5999 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6000 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6001 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6002 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6003 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6004 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6005 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6006 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6007 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6012 else if (cmd
= 'd_health') then
6014 if (Length(P
) > 1) and
6015 ((P
[1] = '1') or (P
[1] = '0')) then
6016 g_debug_HealthBar
:= (P
[1][1] = '1');
6018 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6020 else if (cmd
= 'd_player') then
6022 if (Length(P
) > 1) and
6023 ((P
[1] = '1') or (P
[1] = '0')) then
6024 g_debug_Player
:= (P
[1][1] = '1');
6026 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6028 else if (cmd
= 'd_mem') then
6034 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6038 procedure GameCheats(P
: SSArray
);
6044 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6046 g_Console_Add('not available');
6052 g_Console_Add('where is the player?!');
6055 cmd
:= LowerCase(P
[0]);
6059 plr
.GodMode
:= not plr
.GodMode
;
6060 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6063 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6064 if cmd
= 'give' then
6066 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6067 for f
:= 1 to High(P
) do
6069 cmd
:= LowerCase(P
[f
]);
6070 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6071 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6072 if cmd
= 'exit' then
6074 if gTriggers
<> nil then
6076 for a
:= 0 to High(gTriggers
) do
6078 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6080 g_Console_Add('player left the map');
6081 gExitByTrigger
:= True;
6082 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6083 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6091 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6092 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6093 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6094 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6095 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6097 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6098 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6100 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6101 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;
6103 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6104 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6106 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6107 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6109 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6110 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6112 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6113 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6114 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6116 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6117 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6118 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6119 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;
6120 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6121 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6123 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;
6124 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;
6125 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;
6126 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;
6127 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;
6128 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;
6130 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6131 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;
6133 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;
6134 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;
6136 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6138 if cmd
= 'ammo' then
6140 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6141 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6142 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6143 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6144 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6145 g_Console_Add('player got some ammo');
6149 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6150 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6152 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6153 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6155 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6156 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6158 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6159 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6161 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6163 if cmd
= 'weapons' then
6165 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6166 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6167 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6168 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6169 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6170 plr
.GiveItem(ITEM_WEAPON_BFG
);
6171 g_Console_Add('player got weapons');
6175 if cmd
= 'keys' then
6177 plr
.GiveItem(ITEM_KEY_RED
);
6178 plr
.GiveItem(ITEM_KEY_GREEN
);
6179 plr
.GiveItem(ITEM_KEY_BLUE
);
6180 g_Console_Add('player got all keys');
6184 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6189 if cmd
= 'open' then
6191 g_Console_Add('player activated sesame');
6192 g_Triggers_OpenAll();
6199 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6203 if cmd
= 'noclip' then
6206 g_Console_Add('wall hardeness adjusted');
6210 if cmd
= 'notarget' then
6212 plr
.NoTarget
:= not plr
.NoTarget
;
6213 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6217 if cmd
= 'noreload' then
6219 plr
.NoReload
:= not plr
.NoReload
;
6220 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6224 if cmd
= 'speedy' then
6226 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6227 g_Console_Add('speed adjusted');
6231 if cmd
= 'jumpy' then
6233 VEL_JUMP
:= 30-VEL_JUMP
;
6234 g_Console_Add('jump height adjusted');
6238 if cmd
= 'automap' then
6240 gShowMap
:= not gShowMap
;
6241 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6245 if cmd
= 'aimline' then
6247 gAimLine
:= not gAimLine
;
6248 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6253 procedure GameCommands(P
: SSArray
);
6259 pl
: pTNetClient
= nil;
6267 cmd
:= LowerCase(P
[0]);
6269 if (cmd
= 'quit') or
6276 else if cmd
= 'pause' then
6278 if (g_ActiveWindow
= nil) then
6279 g_Game_Pause(not gPauseMain
);
6281 else if cmd
= 'endgame' then
6282 gExit
:= EXIT_SIMPLE
6283 else if cmd
= 'restart' then
6285 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6287 if g_Game_IsClient
then
6289 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6294 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6296 else if cmd
= 'kick' then
6298 if g_Game_IsServer
then
6300 if Length(P
) < 2 then
6302 g_Console_Add('kick <name>');
6307 g_Console_Add('kick <name>');
6311 if g_Game_IsNet
then
6312 pl
:= g_Net_Client_ByName(P
[1]);
6315 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6316 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6317 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6318 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6319 g_Net_Slist_ServerPlayerLeaves();
6320 end else if gPlayers
<> nil then
6321 for a
:= Low(gPlayers
) to High(gPlayers
) do
6322 if gPlayers
[a
] <> nil then
6323 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6325 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6326 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6328 gPlayers
[a
].Lives
:= 0;
6329 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6330 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6331 g_Player_Remove(gPlayers
[a
].UID
);
6332 g_Net_Slist_ServerPlayerLeaves();
6333 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6337 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6339 else if cmd
= 'kick_id' then
6341 if g_Game_IsServer
and g_Game_IsNet
then
6343 if Length(P
) < 2 then
6345 g_Console_Add('kick_id <client ID>');
6350 g_Console_Add('kick_id <client ID>');
6354 a
:= StrToIntDef(P
[1], 0);
6355 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6357 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6359 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6360 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6361 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6362 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6363 g_Net_Slist_ServerPlayerLeaves();
6367 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6369 else if cmd
= 'ban' then
6371 if g_Game_IsServer
and g_Game_IsNet
then
6373 if Length(P
) < 2 then
6375 g_Console_Add('ban <name>');
6380 g_Console_Add('ban <name>');
6384 pl
:= g_Net_Client_ByName(P
[1]);
6387 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6388 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6389 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6390 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6391 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6392 g_Net_Slist_ServerPlayerLeaves();
6394 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6396 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6398 else if cmd
= 'ban_id' then
6400 if g_Game_IsServer
and g_Game_IsNet
then
6402 if Length(P
) < 2 then
6404 g_Console_Add('ban_id <client ID>');
6409 g_Console_Add('ban_id <client ID>');
6413 a
:= StrToIntDef(P
[1], 0);
6414 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6415 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6417 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6418 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6419 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6420 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6421 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6422 g_Net_Slist_ServerPlayerLeaves();
6425 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6427 else if cmd
= 'permban' then
6429 if g_Game_IsServer
and g_Game_IsNet
then
6431 if Length(P
) < 2 then
6433 g_Console_Add('permban <name>');
6438 g_Console_Add('permban <name>');
6442 pl
:= g_Net_Client_ByName(P
[1]);
6445 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6446 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6447 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6448 g_Net_SaveBanList();
6449 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6450 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6451 g_Net_Slist_ServerPlayerLeaves();
6453 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6455 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6457 else if cmd
= 'permban_id' then
6459 if g_Game_IsServer
and g_Game_IsNet
then
6461 if Length(P
) < 2 then
6463 g_Console_Add('permban_id <client ID>');
6468 g_Console_Add('permban_id <client ID>');
6472 a
:= StrToIntDef(P
[1], 0);
6473 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6474 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6476 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6477 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6478 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6479 g_Net_SaveBanList();
6480 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6481 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6482 g_Net_Slist_ServerPlayerLeaves();
6485 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6487 else if cmd
= 'unban' then
6489 if g_Game_IsServer
and g_Game_IsNet
then
6491 if Length(P
) < 2 then
6493 g_Console_Add('unban <IP Address>');
6498 g_Console_Add('unban <IP Address>');
6502 if g_Net_UnbanHost(P
[1]) then
6504 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6505 g_Net_SaveBanList();
6507 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6509 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6511 else if cmd
= 'clientlist' then
6513 if g_Game_IsServer
and g_Game_IsNet
then
6516 if NetClients
<> nil then
6517 for a
:= Low(NetClients
) to High(NetClients
) do
6518 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6520 plr
:= g_Player_Get(NetClients
[a
].Player
);
6521 if plr
= nil then continue
;
6523 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6524 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6527 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6529 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6531 else if cmd
= 'connect' then
6533 if (NetMode
= NET_NONE
) then
6535 if Length(P
) < 2 then
6537 g_Console_Add('connect <IP> [port] [password]');
6542 g_Console_Add('connect <IP> [port] [password]');
6546 if Length(P
) > 2 then
6547 prt
:= StrToIntDef(P
[2], 25666)
6551 if Length(P
) > 3 then
6556 g_Game_StartClient(P
[1], prt
, pw
);
6559 else if cmd
= 'disconnect' then
6561 if (NetMode
= NET_CLIENT
) then
6564 else if cmd
= 'reconnect' then
6566 if (NetMode
= NET_SERVER
) then
6569 if (NetMode
= NET_CLIENT
) then
6572 gExit
:= EXIT_SIMPLE
;
6576 //TODO: Use last successful password to reconnect, instead of ''
6577 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6579 else if (cmd
= 'addbot') or
6580 (cmd
= 'bot_add') then
6582 if Length(P
) > 2 then
6583 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6584 else if Length(P
) > 1 then
6585 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6587 g_Bot_Add(TEAM_NONE
, 2);
6589 else if cmd
= 'bot_addlist' then
6591 if Length(P
) > 1 then
6593 if Length(P
) = 2 then
6594 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6595 else if Length(P
) = 3 then
6596 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6598 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6601 else if cmd
= 'bot_removeall' then
6603 else if cmd
= 'chat' then
6605 if g_Game_IsNet
then
6607 if Length(P
) > 1 then
6609 for a
:= 1 to High(P
) do
6610 chstr
:= chstr
+ P
[a
] + ' ';
6612 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6614 if Length(chstr
) < 1 then
6616 g_Console_Add('chat <text>');
6620 chstr
:= b_Text_Format(chstr
);
6621 if g_Game_IsClient
then
6622 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6624 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6627 g_Console_Add('chat <text>');
6629 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6631 else if cmd
= 'teamchat' then
6633 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6635 if Length(P
) > 1 then
6637 for a
:= 1 to High(P
) do
6638 chstr
:= chstr
+ P
[a
] + ' ';
6640 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6642 if Length(chstr
) < 1 then
6644 g_Console_Add('teamchat <text>');
6648 chstr
:= b_Text_Format(chstr
);
6649 if g_Game_IsClient
then
6650 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6652 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6653 gPlayer1Settings
.Team
);
6656 g_Console_Add('teamchat <text>');
6658 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6660 else if cmd
= 'game' then
6662 if gGameSettings
.GameType
<> GT_NONE
then
6664 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6667 if Length(P
) = 1 then
6669 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6672 // game not started yet, load fist map from some wad
6674 s
:= addWadExtension(P
[1]);
6675 found
:= e_FindResource(AllMapDirs
, s
);
6679 P
[1] := ExpandFileName(P
[1]);
6680 // if map not choosed then set first map
6681 if Length(P
) < 3 then
6684 P
[2] := g_Game_GetFirstMap(P
[1]);
6687 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6689 if g_Map_Exist(s
) then
6693 with gGameSettings
do
6695 GameMode
:= g_Game_TextToMode(gcGameMode
);
6696 if gSwitchGameMode
<> GM_NONE
then
6697 GameMode
:= gSwitchGameMode
;
6698 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6699 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6701 if Length(P
) >= 4 then
6702 b
:= StrToIntDef(P
[3], 1);
6703 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6704 GoalLimit
, MaxLives
, Options
, b
);
6709 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6711 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6713 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6715 else if cmd
= 'host' then
6717 if gGameSettings
.GameType
<> GT_NONE
then
6719 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6722 if Length(P
) < 4 then
6724 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6727 if not StrToIp(P
[1], listen
) then
6729 prt
:= StrToIntDef(P
[2], 25666);
6731 s
:= addWadExtension(P
[3]);
6732 found
:= e_FindResource(AllMapDirs
, s
);
6736 // get first map in wad, if not specified
6737 if Length(P
) < 5 then
6740 P
[4] := g_Game_GetFirstMap(P
[1]);
6742 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6743 if g_Map_Exist(s
) then
6747 with gGameSettings
do
6749 GameMode
:= g_Game_TextToMode(gcGameMode
);
6750 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6751 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6752 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6754 if Length(P
) >= 6 then
6755 b
:= StrToIntDef(P
[5], 0);
6756 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6762 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6764 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6769 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6772 else if cmd
= 'map' then
6774 if Length(P
) = 1 then
6776 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6778 g_Console_Add(cmd
+ ' <MAP>');
6779 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6783 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6788 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6790 if Length(P
) < 3 then
6792 // first param is map or wad
6793 s
:= UpperCase(P
[1]);
6794 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6796 gExitByTrigger
:= False;
6799 // already in game, finish current map
6801 gExit
:= EXIT_ENDLEVELCUSTOM
;
6805 // intermission, so change map immediately
6812 found
:= e_FindResource(AllMapDirs
, s
);
6814 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6817 // no such map, found wad
6820 P
[1] := ExpandFileName(pw
);
6821 P
[2] := g_Game_GetFirstMap(P
[1]);
6822 s
:= P
[1] + ':\' + P
[2];
6823 if g_Map_Exist(s
) then
6825 gExitByTrigger
:= False;
6828 // already in game, finish current map
6830 gExit
:= EXIT_ENDLEVELCUSTOM
6834 // intermission, so change map immediately
6841 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6843 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6848 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6854 s
:= addWadExtension(P
[1]);
6855 found
:= e_FindResource(AllMapDirs
, s
);
6859 P
[2] := UpperCase(P
[2]);
6860 s
:= P
[1] + ':\' + P
[2];
6861 if g_Map_Exist(s
) then
6863 gExitByTrigger
:= False;
6867 gExit
:= EXIT_ENDLEVELCUSTOM
6876 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6881 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6887 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6891 else if cmd
= 'nextmap' then
6893 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6895 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6900 if Length(P
) = 1 then
6902 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6904 g_Console_Add(cmd
+ ' <MAP>');
6905 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6910 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6916 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6918 if Length(P
) < 3 then
6920 // first param is map or wad
6921 s
:= UpperCase(P
[1]);
6922 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6925 gExitByTrigger
:= False;
6931 // no such map, found wad
6932 pw
:= addWadExtension(P
[1]);
6933 found
:= e_FindResource(MapDirs
, pw
);
6935 found
:= e_FindResource(WadDirs
, pw
);
6937 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6940 // map not specified, select first map
6942 P
[2] := g_Game_GetFirstMap(P
[1]);
6943 s
:= P
[1] + ':\' + P
[2];
6944 if g_Map_Exist(s
) then
6946 gExitByTrigger
:= False;
6953 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6955 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6960 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6966 // specified two params wad + map
6967 pw
:= addWadExtension(P
[1]);
6968 found
:= e_FindResource(MapDirs
, pw
);
6970 found
:= e_FindResource(MapDirs
, pw
);
6974 P
[2] := UpperCase(P
[2]);
6975 s
:= P
[1] + ':\' + P
[2];
6976 if g_Map_Exist(s
) then
6978 gExitByTrigger
:= False;
6984 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6989 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6995 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7000 if gNextMap
= '' then
7001 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7003 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7007 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7011 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7015 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7017 gExitByTrigger
:= False;
7018 // next map not specified, try to find trigger EXIT
7019 if (gNextMap
= '') and (gTriggers
<> nil) then
7021 for a
:= 0 to High(gTriggers
) do
7023 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7025 gExitByTrigger
:= True;
7026 //gNextMap := gTriggers[a].Data.MapName;
7027 gNextMap
:= gTriggers
[a
].tgcMap
;
7032 if gNextMap
= '' then
7033 gNextMap
:= g_Game_GetNextMap();
7034 if not isWadPath(gNextMap
) then
7035 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7038 if g_Map_Exist(s
) then
7039 gExit
:= EXIT_ENDLEVELCUSTOM
7041 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7045 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7049 else if (cmd
= 'event') then
7051 if (Length(P
) <= 1) then
7053 for a
:= 0 to High(gEvents
) do
7054 if gEvents
[a
].Command
= '' then
7055 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7057 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7060 if (Length(P
) = 2) then
7062 for a
:= 0 to High(gEvents
) do
7063 if gEvents
[a
].Name
= P
[1] then
7064 if gEvents
[a
].Command
= '' then
7065 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7067 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7070 for a
:= 0 to High(gEvents
) do
7071 if gEvents
[a
].Name
= P
[1] then
7073 gEvents
[a
].Command
:= '';
7074 for b
:= 2 to High(P
) do
7075 if Pos(' ', P
[b
]) = 0 then
7076 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7078 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7079 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7083 else if cmd
= 'suicide' then
7087 if g_Game_IsClient
then
7088 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7091 if gPlayer1
<> nil then
7092 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7093 if gPlayer2
<> nil then
7094 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7098 else if cmd
= 'screenshot' then
7102 else if cmd
= 'weapon' then
7104 if Length(p
) = 2 then
7106 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7107 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7108 gSelectWeapon
[0, a
] := True
7111 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7113 if Length(p
) = 2 then
7115 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7116 b
:= ord(cmd
[2]) - ord('1');
7117 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7118 gSelectWeapon
[b
, a
] := True
7121 // Êîìàíäû Ñâîåé èãðû:
7122 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7124 if cmd
= 'bot_addred' then
7126 if Length(P
) > 1 then
7127 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7129 g_Bot_Add(TEAM_RED
, 2);
7131 else if cmd
= 'bot_addblue' then
7133 if Length(P
) > 1 then
7134 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7136 g_Bot_Add(TEAM_BLUE
, 2);
7138 else if cmd
= 'spectate' then
7144 else if cmd
= 'say' then
7146 if g_Game_IsServer
and g_Game_IsNet
then
7148 if Length(P
) > 1 then
7151 for a
:= 1 to High(P
) do
7152 chstr
:= chstr
+ P
[a
] + ' ';
7154 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7156 if Length(chstr
) < 1 then
7158 g_Console_Add('say <text>');
7162 chstr
:= b_Text_Format(chstr
);
7163 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7165 else g_Console_Add('say <text>');
7167 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7169 else if cmd
= 'tell' then
7171 if g_Game_IsServer
and g_Game_IsNet
then
7173 if (Length(P
) > 2) and (P
[1] <> '') then
7176 for a
:= 2 to High(P
) do
7177 chstr
:= chstr
+ P
[a
] + ' ';
7179 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7181 if Length(chstr
) < 1 then
7183 g_Console_Add('tell <playername> <text>');
7187 pl
:= g_Net_Client_ByName(P
[1]);
7189 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7191 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7193 else g_Console_Add('tell <playername> <text>');
7195 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7197 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7199 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7201 // Äîïîëíèòåëüíîå âðåìÿ:
7202 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7204 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7205 [gGameSettings
.TimeLimit
div 3600,
7206 (gGameSettings
.TimeLimit
div 60) mod 60,
7207 gGameSettings
.TimeLimit
mod 60]));
7208 if g_Game_IsNet
then MH_SEND_GameSettings
;
7210 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7212 if (Length(P
) <= 1) then
7213 g_Console_Add('rcon_password <password>')
7215 MC_SEND_RCONPassword(P
[1]);
7217 else if cmd
= 'rcon' then
7219 if g_Game_IsClient
then
7221 if Length(P
) > 1 then
7224 for a
:= 1 to High(P
) do
7225 chstr
:= chstr
+ P
[a
] + ' ';
7227 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7229 if Length(chstr
) < 1 then
7231 g_Console_Add('rcon <command>');
7235 MC_SEND_RCONCommand(chstr
);
7237 else g_Console_Add('rcon <command>');
7240 else if cmd
= 'ready' then
7242 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7243 gLMSRespawnTime
:= gTime
+ 100;
7245 else if (cmd
= 'callvote') and g_Game_IsNet
then
7247 if Length(P
) > 1 then
7250 for a
:= 1 to High(P
) do begin
7251 if a
> 1 then chstr
:= chstr
+ ' ';
7252 chstr
:= chstr
+ P
[a
];
7255 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7257 if Length(chstr
) < 1 then
7259 g_Console_Add('callvote <command>');
7263 if g_Game_IsClient
then
7264 MC_SEND_Vote(True, chstr
)
7266 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7267 g_Console_Process('vote', True);
7270 g_Console_Add('callvote <command>');
7272 else if (cmd
= 'vote') and g_Game_IsNet
then
7274 if g_Game_IsClient
then
7276 else if gVoteInProgress
then
7278 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7279 a
:= Floor((NetClientCount
+1)/2.0) + 1
7281 a
:= Floor(NetClientCount
/2.0) + 1;
7286 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7287 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7293 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7294 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7302 procedure g_TakeScreenShot(Filename
: string = '');
7303 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7305 if e_NoGraphics
then Exit
;
7307 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7309 if Filename
= '' then
7312 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7313 Filename
:= 'screenshot-' + date
;
7316 name
:= e_CatPath(dir
, Filename
+ '.png');
7317 s
:= createDiskFile(name
);
7319 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7321 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7323 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7328 g_Console_Add('oh shit, i can''t create screenshot!')
7332 procedure g_Game_InGameMenu(Show
: Boolean);
7334 if (g_ActiveWindow
= nil) and Show
then
7336 if gGameSettings
.GameType
= GT_SINGLE
then
7337 g_GUI_ShowWindow('GameSingleMenu')
7340 if g_Game_IsClient
then
7341 g_GUI_ShowWindow('GameClientMenu')
7343 if g_Game_IsNet
then
7344 g_GUI_ShowWindow('GameServerMenu')
7346 g_GUI_ShowWindow('GameCustomMenu');
7348 g_Sound_PlayEx('MENU_OPEN');
7350 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7351 if (not g_Game_IsNet
) then
7355 if (g_ActiveWindow
<> nil) and (not Show
) then
7357 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7358 if (not g_Game_IsNet
) then
7359 g_Game_Pause(False);
7363 procedure g_Game_Pause (Enable
: Boolean);
7367 if not gGameOn
then exit
;
7369 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7372 gPauseMain
:= Enable
;
7374 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7377 procedure g_Game_HolmesPause (Enable
: Boolean);
7381 if not gGameOn
then exit
;
7382 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7385 gPauseHolmes
:= Enable
;
7387 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7390 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7395 if gTriggers
<> nil then
7396 for i
:= 0 to High(gTriggers
) do
7397 with gTriggers
[i
] do
7398 if (TriggerType
= TRIGGER_SOUND
) and
7400 Sound
.IsPlaying() then
7402 Sound
.Pause(Enable
);
7406 if gPlayers
<> nil then
7407 for i
:= 0 to High(gPlayers
) do
7408 if gPlayers
[i
] <> nil then
7409 gPlayers
[i
].PauseSounds(Enable
);
7412 if gMusic
<> nil then
7413 gMusic
.Pause(Enable
);
7416 procedure g_Game_StopAllSounds(all
: Boolean);
7420 if gTriggers
<> nil then
7421 for i
:= 0 to High(gTriggers
) do
7422 with gTriggers
[i
] do
7423 if (TriggerType
= TRIGGER_SOUND
) and
7427 if gMusic
<> nil then
7434 procedure g_Game_UpdateTriggerSounds
;
7437 if gTriggers
<> nil then
7438 for i
:= 0 to High(gTriggers
) do
7439 with gTriggers
[i
] do
7440 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7441 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7444 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7447 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7452 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7457 if gSpectMode
<> SPECT_PLAYERS
then
7459 if gSpectPID1
= UID
then
7464 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7471 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7476 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7481 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7486 if gSpectMode
<> SPECT_PLAYERS
then
7488 Pl
:= g_Player_Get(gSpectPID1
);
7489 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7494 if gSpectViewTwo
then
7496 Pl
:= g_Player_Get(gSpectPID2
);
7497 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7505 procedure g_Game_Message(Msg
: string; Time
: Word);
7507 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7508 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7509 MessageTime
:= Time
;
7512 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7514 punct
: Array[0..13] of String =
7515 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7521 function IsPunctuation(S
: String): Boolean;
7526 if Length(S
) <> 1 then
7528 for i
:= Low(punct
) to High(punct
) do
7529 if S
= punct
[i
] then
7535 function FilterPunctuation(S
: String): String;
7539 for i
:= Low(punct
) to High(punct
) do
7540 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7546 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7548 // remove player name
7549 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7550 // for FullWord check
7551 Text := toLowerCase1251(' ' + Text + ' ');
7552 fpText
:= FilterPunctuation(Text);
7554 for i
:= 0 to Length(gChatSounds
) - 1 do
7557 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7559 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7560 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7562 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7568 gChatSounds
[i
].Sound
.Play();
7574 g_Sound_PlayEx('SOUND_GAME_RADIO');
7577 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7586 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7590 if goodsnd
[a
].IsPlaying() then
7593 goodsnd
[Random(4)].Play();
7596 procedure g_Game_Announce_KillCombo(Param
: Integer);
7603 UID
:= Param
and $FFFF;
7608 Pl
:= g_Player_Get(UID
);
7617 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7621 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7625 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7629 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7637 if not g_Game_IsWatchedPlayer(UID
) then
7640 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7644 if killsnd
[n
].IsPlaying() then
7649 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7658 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7662 if hahasnd
[a
].IsPlaying() then
7665 hahasnd
[Random(3)].Play();
7668 procedure g_Game_StartVote(Command
, Initiator
: string);
7672 if not gVotesEnabled
then Exit
;
7673 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7674 if gVoteInProgress
or gVotePassed
then
7676 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7677 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7680 gVoteInProgress
:= True;
7681 gVotePassed
:= False;
7682 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7685 gVoteCommand
:= Command
;
7687 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7688 Need
:= Floor((NetClientCount
+1)/2.0)+1
7690 Need
:= Floor(NetClientCount
/2.0)+1;
7691 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7692 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7695 procedure g_Game_CheckVote
;
7699 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7700 if not gVoteInProgress
then Exit
;
7702 if (gTime
>= gVoteTimer
) then
7704 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7705 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7707 Need
:= Floor(NetClientCount
/2.0) + 1;
7708 if gVoteCount
>= Need
then
7710 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7711 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7712 gVotePassed
:= True;
7713 gVoteCmdTimer
:= gTime
+ 5000;
7717 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7718 MH_SEND_VoteEvent(NET_VE_FAILED
);
7720 if NetClients
<> nil then
7721 for I
:= Low(NetClients
) to High(NetClients
) do
7722 if NetClients
[i
].Used
then
7723 NetClients
[i
].Voted
:= False;
7724 gVoteInProgress
:= False;
7730 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7731 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7733 Need
:= Floor(NetClientCount
/2.0) + 1;
7734 if gVoteCount
>= Need
then
7736 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7737 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7738 gVoteInProgress
:= False;
7739 gVotePassed
:= True;
7740 gVoteCmdTimer
:= gTime
+ 5000;
7743 if NetClients
<> nil then
7744 for I
:= Low(NetClients
) to High(NetClients
) do
7745 if NetClients
[i
].Used
then
7746 NetClients
[i
].Voted
:= False;
7751 procedure g_Game_LoadMapList(FileName
: string);
7759 if not FileExists(FileName
) then Exit
;
7761 AssignFile(ListFile
, FileName
);
7763 while not EOF(ListFile
) do
7765 ReadLn(ListFile
, s
);
7768 if s
= '' then Continue
;
7770 SetLength(MapList
, Length(MapList
)+1);
7771 MapList
[High(MapList
)] := s
;
7773 CloseFile(ListFile
);
7776 procedure g_Game_SetDebugMode();
7779 // ×èòû (äàæå â ñâîåé èãðå):
7783 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7787 if Length(LoadingStat
.Msgs
) = 0 then
7793 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7794 if NextMsg
= Length(Msgs
) then
7796 for i
:= 0 to High(Msgs
)-1 do
7797 Msgs
[i
] := Msgs
[i
+1];
7805 Msgs
[NextMsg
-1] := Text;
7809 PBarWasHere
:= false;
7812 g_ActiveWindow
:= nil;
7814 ProcessLoading(true);
7817 procedure g_Game_StepLoading(Value
: Integer = -1);
7828 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7836 procedure g_Game_ClearLoading();
7845 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7846 if len
< 1 then len
:= 1;
7847 SetLength(Msgs
, len
);
7848 for len
:= Low(Msgs
) to High(Msgs
) do
7851 PBarWasHere
:= false;
7855 procedure Parse_Params(var pars
: TParamStrValues
);
7862 while i
<= ParamCount
do
7865 if (s
[1] = '-') and (Length(s
) > 1) then
7867 if (s
[2] = '-') and (Length(s
) > 2) then
7868 begin // Îäèíî÷íûé ïàðàìåòð
7869 SetLength(pars
, Length(pars
) + 1);
7870 with pars
[High(pars
)] do
7872 Name
:= LowerCase(s
);
7877 if (i
< ParamCount
) then
7878 begin // Ïàðàìåòð ñî çíà÷åíèåì
7880 SetLength(pars
, Length(pars
) + 1);
7881 with pars
[High(pars
)] do
7883 Name
:= LowerCase(s
);
7884 Value
:= LowerCase(ParamStr(i
));
7893 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7898 for i
:= 0 to High(pars
) do
7899 if pars
[i
].Name
= aName
then
7901 Result
:= pars
[i
].Value
;
7906 procedure g_Game_Process_Params();
7908 pars
: TParamStrValues
;
7911 LimT
, LimS
: Integer;
7922 s
:= Find_Param_Value(pars
, '--debug');
7925 g_Game_SetDebugMode();
7926 s
:= Find_Param_Value(pars
, '--netdump');
7931 // Connect when game loads
7932 ip
:= Find_Param_Value(pars
, '-connect');
7936 s
:= Find_Param_Value(pars
, '-port');
7937 if (s
= '') or not TryStrToInt(s
, Port
) then
7940 s
:= Find_Param_Value(pars
, '-pw');
7942 g_Game_StartClient(ip
, Port
, s
);
7946 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7949 gDefaultMegawadStart
:= s
;
7952 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7953 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7955 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7958 // Start map when game loads:
7959 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7960 if isWadPath(map
) then
7963 s
:= Find_Param_Value(pars
, '-gm');
7964 GMode
:= g_Game_TextToMode(s
);
7965 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7966 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7969 s
:= Find_Param_Value(pars
, '-limt');
7970 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7976 s
:= Find_Param_Value(pars
, '-lims');
7977 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7983 s
:= Find_Param_Value(pars
, '-lives');
7984 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7990 s
:= Find_Param_Value(pars
, '-opt');
7992 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7994 Opt
:= StrToIntDef(s
, 0);
7996 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7999 s
:= Find_Param_Value(pars
, '--close');
8003 // Override map to test:
8004 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8007 if e_IsValidResourceName(s
) then
8008 e_FindResource(AllMapDirs
, s
);
8009 gTestMap
:= ExpandFileName(s
);
8012 // Delete test map after play:
8013 s
:= Find_Param_Value(pars
, '--testdelete');
8016 //gMapToDelete := MapsDir + map;
8017 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8021 // Delete temporary WAD after play:
8022 s
:= Find_Param_Value(pars
, '--tempdelete');
8023 if (s
<> '') and (gTestMap
<> '') then
8025 gMapToDelete
:= gTestMap
;
8026 gTempDelete
:= True;
8029 // Number of players:
8030 s
:= Find_Param_Value(pars
, '-pl');
8032 n
:= DEFAULT_PLAYERS
8034 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8037 s
:= Find_Param_Value(pars
, '-port');
8038 if (s
= '') or not TryStrToInt(s
, Port
) then
8039 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8041 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8044 // Execute script when game loads:
8045 s
:= Find_Param_Value(pars
, '-exec');
8048 // if not isWadPath(s) then
8049 // s := GameDir + '/' + s;
8054 if IOResult
<> 0 then
8056 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8057 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8061 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8062 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8067 if IOResult
<> 0 then
8069 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8070 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8074 if Pos('#', s
) <> 1 then // script comment
8075 g_Console_Process(s
, True);
8086 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8087 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8088 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8089 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8091 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8092 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8093 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8094 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8096 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8097 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8099 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8100 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8102 {$IFDEF ENABLE_HOLMES}
8103 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8106 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8108 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8110 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8111 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8113 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8114 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8116 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8117 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');