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
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
65 // ones below are sent only to the server
67 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
84 function g_Game_IsNet(): Boolean;
85 function g_Game_IsServer(): Boolean;
86 function g_Game_IsClient(): Boolean;
87 procedure g_Game_Init();
88 procedure g_Game_Free (freeTextures
: Boolean=true);
89 procedure g_Game_LoadData();
90 procedure g_Game_FreeData();
91 procedure g_Game_Update();
92 procedure g_Game_PreUpdate();
93 procedure g_Game_Draw();
94 procedure g_Game_Quit();
95 procedure g_Game_SetupScreenSize();
96 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 procedure g_Game_InGameMenu(Show
: Boolean);
122 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
123 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
124 procedure g_Game_Message(Msg
: String; Time
: Word);
125 procedure g_Game_LoadMapList(FileName
: String);
126 procedure g_Game_PauseAllSounds(Enable
: Boolean);
127 procedure g_Game_StopAllSounds(all
: Boolean);
128 procedure g_Game_UpdateTriggerSounds();
129 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
130 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
131 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
132 procedure g_Game_Announce_KillCombo(Param
: Integer);
133 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
134 procedure g_Game_StartVote(Command
, Initiator
: string);
135 procedure g_Game_CheckVote
;
136 procedure g_TakeScreenShot(Filename
: string = '');
137 procedure g_FatalError(Text: String);
138 procedure g_SimpleError(Text: String);
139 function g_Game_IsTestMap(): Boolean;
140 procedure g_Game_DeleteTestMap();
141 procedure GameCVars(P
: SSArray
);
142 procedure PlayerSettingsCVars(P
: SSArray
);
143 procedure SystemCommands(P
: SSArray
);
144 procedure GameCommands(P
: SSArray
);
145 procedure GameCheats(P
: SSArray
);
146 procedure DebugCommands(P
: SSArray
);
147 procedure g_Game_Process_Params
;
148 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
149 procedure g_Game_StepLoading(Value
: Integer = -1);
150 procedure g_Game_ClearLoading();
151 procedure g_Game_SetDebugMode();
152 procedure DrawLoadingStat();
153 procedure DrawMenuBackground(tex
: AnsiString);
155 { procedure SetWinPause(Enable: Boolean); }
160 LOADING_SHOW_STEP
= 100;
161 LOADING_INTERLINE
= 20;
176 MESSAGE_DIKEY
= WM_USER
+ 1;
181 EXIT_ENDLEVELSINGLE
= 4;
182 EXIT_ENDLEVELCUSTOM
= 5;
184 GAME_OPTION_RESERVED
= 1;
185 GAME_OPTION_TEAMDAMAGE
= 2;
186 GAME_OPTION_ALLOWEXIT
= 4;
187 GAME_OPTION_WEAPONSTAY
= 8;
188 GAME_OPTION_MONSTERS
= 16;
189 GAME_OPTION_BOTVSPLAYER
= 32;
190 GAME_OPTION_BOTVSMONSTER
= 64;
191 GAME_OPTION_DMKEYS
= 128;
192 GAME_OPTION_TEAMHITTRACE
= 256;
193 GAME_OPTION_TEAMHITPROJECTILE
= 512;
194 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
195 GAME_OPTION_ALLOWDROPFLAG
= 2048;
196 GAME_OPTION_THROWFLAG
= 4096;
201 STATE_INTERCUSTOM
= 3;
202 STATE_INTERSINGLE
= 4;
208 LMS_RESPAWN_NONE
= 0;
209 LMS_RESPAWN_WARMUP
= 1;
210 LMS_RESPAWN_FINAL
= 2;
227 CONFIG_FILENAME
= 'Doom2DF.cfg';
229 TEST_MAP_NAME
= '$$$_TEST_$$$';
231 STD_PLAYER_MODEL
= 'Doomer';
239 STATFILE_VERSION
= $03;
243 gGameSettings
: TGameSettings
;
244 gPlayer1Settings
: TPlayerSettings
;
245 gPlayer2Settings
: TPlayerSettings
;
247 gPlayerScreenSize
: TDFPoint
;
248 gPlayer1ScreenCoord
: TDFPoint
;
249 gPlayer2ScreenCoord
: TDFPoint
;
250 gPlayer1
: TPlayer
= nil;
251 gPlayer2
: TPlayer
= nil;
252 gPlayerDrawn
: TPlayer
= nil;
254 gLerpFactor
: Single = 1.0;
255 gSwitchGameMode
: Byte = GM_DM
;
256 gHearPoint1
, gHearPoint2
: THearPoint
;
257 gSoundEffectsDF
: Boolean = False;
258 gSoundTriggerTime
: Word = 0;
259 gAnnouncer
: Integer = ANNOUNCE_NONE
;
260 goodsnd
: array[0..3] of TPlayableSound
;
261 killsnd
: array[0..3] of TPlayableSound
;
262 hahasnd
: array[0..2] of TPlayableSound
;
263 sound_get_flag
: array[0..1] of TPlayableSound
;
264 sound_lost_flag
: array[0..1] of TPlayableSound
;
265 sound_ret_flag
: array[0..1] of TPlayableSound
;
266 sound_cap_flag
: array[0..1] of TPlayableSound
;
267 gBodyKillEvent
: Integer = -1;
268 gDefInterTime
: ShortInt = -1;
269 gInterEndTime
: LongWord = 0;
270 gInterTime
: LongWord = 0;
271 gServInterTime
: Byte = 0;
272 gGameStartTime
: LongWord = 0;
273 gTotalMonsters
: Integer = 0;
274 gPauseMain
: Boolean = false;
275 gPauseHolmes
: Boolean = false;
276 gShowTime
: Boolean = False;
277 gShowFPS
: Boolean = False;
278 gShowGoals
: Boolean = True;
279 gShowStat
: Boolean = True;
280 gShowPIDs
: Boolean = False;
281 gShowKillMsg
: Boolean = True;
282 gShowLives
: Boolean = True;
283 gShowPing
: Boolean = False;
284 gShowMap
: Boolean = False;
286 gState
: Byte = STATE_NONE
;
288 sWidth
, sHeight
: Word;
289 gSpectMode
: Byte = SPECT_NONE
;
290 gSpectHUD
: Boolean = True;
291 gSpectKeyPress
: Boolean = False;
292 gSpectX
: Integer = 0;
293 gSpectY
: Integer = 0;
294 gSpectStep
: Byte = 8;
295 gSpectViewTwo
: Boolean = False;
296 gSpectPID1
: Integer = -1;
297 gSpectPID2
: Integer = -1;
298 gSpectAuto
: Boolean = False;
299 gSpectAutoNext
: LongWord;
300 gSpectAutoStepX
: Integer;
301 gSpectAutoStepY
: Integer;
302 gMusic
: TMusic
= nil;
303 gLoadGameMode
: Boolean;
304 gCheats
: Boolean = False;
305 gMapOnce
: Boolean = False;
306 gMapToDelete
: String;
307 gTempDelete
: Boolean = False;
308 gLastMap
: Boolean = False;
311 gResolutionChange
: Boolean = False;
312 gRC_Width
, gRC_Height
: Integer;
313 gRC_FullScreen
, gRC_Maximized
: Boolean;
314 gLanguageChange
: Boolean = False;
315 gDebugMode
: Boolean = False;
316 g_debug_Sounds
: Boolean = False;
317 g_debug_Frames
: Boolean = False;
318 g_debug_WinMsgs
: Boolean = False;
319 g_debug_MonsterOff
: Boolean = False;
320 g_debug_BotAIOff
: Byte = 0;
321 g_debug_HealthBar
: Boolean = False;
322 g_Debug_Player
: Boolean = False;
323 gCoopMonstersKilled
: Word = 0;
324 gCoopSecretsFound
: Word = 0;
325 gCoopTotalMonstersKilled
: Word = 0;
326 gCoopTotalSecretsFound
: Word = 0;
327 gCoopTotalMonsters
: Word = 0;
328 gCoopTotalSecrets
: Word = 0;
329 gStatsOff
: Boolean = False;
330 gStatsPressed
: Boolean = False;
331 gExitByTrigger
: Boolean = False;
332 gNextMap
: String = '';
333 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
334 gLMSRespawnTime
: Cardinal = 0;
335 gLMSSoftSpawn
: Boolean = False;
336 gMissionFailed
: Boolean = False;
337 gVoteInProgress
: Boolean = False;
338 gVotePassed
: Boolean = False;
339 gVoteCommand
: string = '';
340 gVoteTimer
: Cardinal = 0;
341 gVoteCmdTimer
: Cardinal = 0;
342 gVoteCount
: Integer = 0;
343 gVoteTimeout
: Cardinal = 30;
344 gVoted
: Boolean = False;
345 gVotesEnabled
: Boolean = True;
346 gEvents
: Array of TGameEvent
;
347 gDelayedEvents
: Array of TDelayedEvent
;
348 gUseChatSounds
: Boolean = True;
349 gChatSounds
: Array of TChatSound
;
350 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
351 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
352 gInterReadyCount
: Integer = 0;
353 gMaxBots
: Integer = 127;
355 g_dbg_ignore_bounds
: Boolean = false;
356 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
357 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
359 // move button values:
360 // bits 0-1: l/r state:
361 // 0: neither left, nor right pressed
364 // bits 4-5: l/r state when strafe was pressed
365 P1MoveButton
: Byte = 0;
366 P2MoveButton
: Byte = 0;
368 g_profile_frame_update
: Boolean = false;
369 g_profile_frame_draw
: Boolean = false;
370 g_profile_collision
: Boolean = false;
371 g_profile_los
: Boolean = false;
372 g_profile_history_size
: Integer = 1000;
374 g_rlayer_back
: Boolean = true;
375 g_rlayer_step
: Boolean = true;
376 g_rlayer_wall
: Boolean = true;
377 g_rlayer_door
: Boolean = true;
378 g_rlayer_acid1
: Boolean = true;
379 g_rlayer_acid2
: Boolean = true;
380 g_rlayer_water
: Boolean = true;
381 g_rlayer_fore
: Boolean = true;
384 procedure g_ResetDynlights ();
385 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
386 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
388 function conIsCheatsEnabled (): Boolean; inline;
389 function gPause (): Boolean; inline;
395 {$INCLUDE ../nogl/noGLuses.inc}
396 {$IFDEF ENABLE_HOLMES}
399 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
400 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
401 g_playermodel
, g_gfx
, g_options
, Math
,
402 g_triggers
, g_monsters
, e_sound
, CONFIG
,
403 g_language
, g_net
, g_main
, g_phys
,
404 ENet
, e_msg
, g_netmsg
, g_netmaster
,
405 sfs
, wadreader
, g_system
;
409 hasPBarGfx
: Boolean = false;
412 // ////////////////////////////////////////////////////////////////////////// //
413 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
416 // ////////////////////////////////////////////////////////////////////////// //
417 function conIsCheatsEnabled (): Boolean; inline;
420 if g_Game_IsNet
then exit
;
421 if not gDebugMode
then
423 //if not gCheats then exit;
424 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
425 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
431 // ////////////////////////////////////////////////////////////////////////// //
433 profileFrameDraw
: TProfiler
= nil;
436 // ////////////////////////////////////////////////////////////////////////// //
439 x
, y
, radius
: Integer;
442 exploRadius
: Integer;
446 g_dynLights
: array of TDynLight
= nil;
447 g_dynLightCount
: Integer = 0;
448 g_playerLight
: Boolean = false;
450 procedure g_ResetDynlights ();
454 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
456 for idx
:= 0 to g_dynLightCount
-1 do
458 if g_dynLights
[idx
].exploCount
= -666 then
465 Inc(g_dynLights
[idx
].exploCount
);
466 if (g_dynLights
[idx
].exploCount
< 10) then
468 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
469 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
470 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
471 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
476 g_dynLightCount
:= lnum
;
479 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
481 if not gwin_has_stencil
then exit
;
482 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
483 g_dynLights
[g_dynLightCount
].x
:= x
;
484 g_dynLights
[g_dynLightCount
].y
:= y
;
485 g_dynLights
[g_dynLightCount
].radius
:= radius
;
486 g_dynLights
[g_dynLightCount
].r
:= r
;
487 g_dynLights
[g_dynLightCount
].g
:= g
;
488 g_dynLights
[g_dynLightCount
].b
:= b
;
489 g_dynLights
[g_dynLightCount
].a
:= a
;
490 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
491 Inc(g_dynLightCount
);
494 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
496 if not gwin_has_stencil
then exit
;
497 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
498 g_dynLights
[g_dynLightCount
].x
:= x
;
499 g_dynLights
[g_dynLightCount
].y
:= y
;
500 g_dynLights
[g_dynLightCount
].radius
:= 0;
501 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
502 g_dynLights
[g_dynLightCount
].r
:= r
;
503 g_dynLights
[g_dynLightCount
].g
:= g
;
504 g_dynLights
[g_dynLightCount
].b
:= b
;
505 g_dynLights
[g_dynLightCount
].a
:= 0;
506 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
507 Inc(g_dynLightCount
);
511 // ////////////////////////////////////////////////////////////////////////// //
512 function calcProfilesHeight (prof
: TProfiler
): Integer;
515 if (prof
= nil) then exit
;
516 if (length(prof
.bars
) = 0) then exit
;
517 result
:= length(prof
.bars
)*(16+2);
521 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
528 if (prof
= nil) then exit
;
530 if (length(prof
.bars
) = 0) then exit
;
532 hgt
:= calcProfilesHeight(prof
);
533 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
534 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
536 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
537 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
538 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
541 for ii
:= 0 to High(prof
.bars
) do
543 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);
550 // ////////////////////////////////////////////////////////////////////////// //
552 TEndCustomGameStat
= record
553 PlayerStat
: TPlayerStatArray
;
557 Map
, MapName
: String;
560 TEndSingleGameStat
= record
561 PlayerStat
: Array [0..1] of record
567 TotalSecrets
: Integer;
570 TLoadingStat
= record
574 Msgs
: Array of String;
576 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
579 TParamStrValue
= record
584 TParamStrValues
= Array of TParamStrValue
;
587 INTER_ACTION_TEXT
= 1;
588 INTER_ACTION_PIC
= 2;
589 INTER_ACTION_MUSIC
= 3;
593 FPSCounter
, UPSCounter
: Word;
594 FPSTime
, UPSTime
: LongWord;
595 DataLoaded
: Boolean = False;
596 IsDrawStat
: Boolean = False;
597 CustomStat
: TEndCustomGameStat
;
598 SingleStat
: TEndSingleGameStat
;
599 LoadingStat
: TLoadingStat
;
600 EndingGameCounter
: Byte = 0;
603 MessageLineLength
: Integer = 80;
604 MapList
: SSArray
= nil;
605 MapIndex
: Integer = -1;
606 InterReadyTime
: Integer = -1;
607 StatShotDone
: Boolean = False;
608 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
609 StatDate
: string = '';
615 text: Array of ShortString;
616 anim
: Array of ShortString;
617 pic
: Array of ShortString;
618 mus
: Array of ShortString;
620 triggers
: Array of record
622 actions
: Array of record
623 action
, p1
, p2
: Integer;
626 cur_trigger
: Integer;
639 function Compare(a
, b
: TPlayerStat
): Integer;
641 if a
.Spectator
then Result
:= 1
642 else if b
.Spectator
then Result
:= -1
643 else if a
.Frags
< b
.Frags
then Result
:= 1
644 else if a
.Frags
> b
.Frags
then Result
:= -1
645 else if a
.Deaths
< b
.Deaths
then Result
:= -1
646 else if a
.Deaths
> b
.Deaths
then Result
:= 1
647 else if a
.Kills
< b
.Kills
then Result
:= -1
651 procedure SortGameStat(var stat
: TPlayerStatArray
);
656 if stat
= nil then Exit
;
658 for I
:= High(stat
) downto Low(stat
) do
659 for J
:= Low(stat
) to High(stat
) - 1 do
660 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
663 stat
[J
] := stat
[J
+ 1];
668 // saves a shitty CSV containing the game stats passed to it
669 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
672 dir
, fname
, map
, mode
, etime
: String;
676 dir
:= e_GetWriteableDir(StatsDirs
);
677 // stats are placed in stats/yy/mm/dd/*.csv
678 fname
:= e_CatPath(dir
, Path
);
679 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
680 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
681 AssignFile(s
, fname
);
684 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
685 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
686 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
687 mode
:= g_Game_ModeToText(Stat
.GameMode
);
688 etime
:= Format('%d:%.2d:%.2d', [
689 Stat
.GameTime
div 1000 div 3600,
690 (Stat
.GameTime
div 1000 div 60) mod 60,
691 Stat
.GameTime
div 1000 mod 60
693 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
694 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
700 gGameSettings
.TimeLimit
,
701 gGameSettings
.GoalLimit
,
702 gGameSettings
.Options
,
704 Length(Stat
.PlayerStat
)
706 // line 2: game specific shit
707 // if it's a team game: red score, blue score
708 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
710 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
712 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
713 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
715 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
716 // lines 3-...: team, player name, frags, deaths
717 WriteLn(s
, 'team,name,frags,deaths');
718 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
719 with Stat
.PlayerStat
[I
] do
720 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
722 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
725 g_Console_Add('could not create gamestats file "' + fname
+ '"');
730 function g_Game_ModeToText(Mode
: Byte): string;
734 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
735 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
736 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
737 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
738 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
742 function g_Game_TextToMode(Mode
: string): Byte;
745 Mode
:= UpperCase(Mode
);
746 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
751 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
756 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
761 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
766 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
773 function g_Game_IsNet(): Boolean;
775 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
778 function g_Game_IsServer(): Boolean;
780 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
783 function g_Game_IsClient(): Boolean;
785 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
788 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
795 Result
.name
:= ExtractFileName(WAD
);
796 Result
.description
:= '';
799 w
:= TWADFile
.Create();
802 if not w
.GetResource('INTERSCRIPT', p
, len
) then
808 cfg
:= TConfig
.CreateMem(p
, len
);
809 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
810 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
811 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
812 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
818 procedure g_Game_FreeWAD();
822 for a
:= 0 to High(MegaWAD
.res
.pic
) do
823 if MegaWAD
.res
.pic
[a
] <> '' then
824 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
826 for a
:= 0 to High(MegaWAD
.res
.mus
) do
827 if MegaWAD
.res
.mus
[a
] <> '' then
828 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
830 MegaWAD
.res
.pic
:= nil;
831 MegaWAD
.res
.text := nil;
832 MegaWAD
.res
.anim
:= nil;
833 MegaWAD
.res
.mus
:= nil;
834 MegaWAD
.triggers
:= nil;
836 g_Texture_Delete('TEXTURE_endpic');
837 g_Sound_Delete('MUSIC_endmus');
839 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
840 gGameSettings
.WAD
:= '';
843 procedure g_Game_LoadWAD(WAD
: string);
852 gGameSettings
.WAD
:= WAD
;
853 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
856 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
858 w
:= TWADFile
.Create();
861 if not w
.GetResource('INTERSCRIPT', p
, len
) then
867 cfg
:= TConfig
.CreateMem(p
, len
);
872 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
873 if s = '' then Break;
876 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
877 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
879 g_Texture_CreateWADEx(s, s);
885 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
886 if s = '' then Break;
889 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
890 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
892 g_Music_CreateWADEx(s, s);
895 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
896 if MegaWAD
.endpic
<> '' then
898 TEXTUREFILTER
:= GL_LINEAR
;
899 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
900 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
901 TEXTUREFILTER
:= GL_NEAREST
;
903 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
904 if MegaWAD
.endmus
<> '' then
906 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
907 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
915 {procedure start_trigger(t: string);
919 function next_trigger(): Boolean;
923 procedure DisableCheats();
929 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
930 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
931 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
932 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
934 {$IF DEFINED(D2F_DEBUG)}
935 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
936 gAimLine
:= g_dbg_aimline_on
;
940 procedure g_Game_ExecuteEvent(Name
: String);
946 if gEvents
= nil then
948 for a
:= 0 to High(gEvents
) do
949 if gEvents
[a
].Name
= Name
then
951 if gEvents
[a
].Command
<> '' then
952 g_Console_Process(gEvents
[a
].Command
, True);
957 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
962 if gDelayedEvents
<> nil then
963 for a
:= 0 to High(gDelayedEvents
) do
964 if not gDelayedEvents
[a
].Pending
then
971 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
972 n
:= High(gDelayedEvents
);
974 gDelayedEvents
[n
].Pending
:= True;
975 gDelayedEvents
[n
].DEType
:= DEType
;
976 gDelayedEvents
[n
].DENum
:= Num
;
977 gDelayedEvents
[n
].DEStr
:= Str
;
978 if DEType
= DE_GLOBEVENT
then
979 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
981 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
991 if g_Game_IsNet
and g_Game_IsServer
then
992 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
996 gPauseHolmes
:= false;
999 g_Game_StopAllSounds(False);
1004 EndingGameCounter
:= 0;
1005 g_ActiveWindow
:= nil;
1007 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1008 gLMSRespawnTime
:= 0;
1011 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1016 begin // Ýòî áûë òåñò
1020 begin // Âûõîä â ãëàâíîå ìåíþ
1021 gMusic
.SetByName('MUSIC_MENU');
1023 if gState
<> STATE_SLIST
then
1025 g_GUI_ShowWindow('MainMenu');
1026 gState
:= STATE_MENU
;
1029 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1030 slReturnPressed
:= True;
1031 if g_Net_Slist_Fetch(slCurrent
) then
1033 if slCurrent
= nil then
1034 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1037 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1038 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1041 g_Game_ExecuteEvent('ongameend');
1045 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1047 if not g_Game_IsClient
then g_Game_Restart();
1050 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1052 // Ñòàòèñòèêà Ñâîåé èãðû:
1053 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1055 CustomStat
.GameTime
:= gTime
;
1056 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1057 CustomStat
.MapName
:= gMapInfo
.Name
;
1058 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1059 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1060 CustomStat
.TeamStat
:= gTeamStat
;
1062 CustomStat
.PlayerStat
:= nil;
1064 // Ñòàòèñòèêà èãðîêîâ:
1065 if gPlayers
<> nil then
1067 for a
:= 0 to High(gPlayers
) do
1068 if gPlayers
[a
] <> nil then
1070 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1071 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1074 Name
:= gPlayers
[a
].Name
;
1075 Frags
:= gPlayers
[a
].Frags
;
1076 Deaths
:= gPlayers
[a
].Death
;
1077 Kills
:= gPlayers
[a
].Kills
;
1078 Team
:= gPlayers
[a
].Team
;
1079 Color
:= gPlayers
[a
].Model
.Color
;
1080 Spectator
:= gPlayers
[a
].FSpectator
;
1084 SortGameStat(CustomStat
.PlayerStat
);
1086 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1089 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1090 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1091 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1092 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1094 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1097 StatShotDone
:= False;
1100 g_Game_ExecuteEvent('onmapend');
1101 if not g_Game_IsClient
then g_Player_ResetReady
;
1102 gInterReadyCount
:= 0;
1104 // Çàòóõàþùèé ýêðàí:
1105 EndingGameCounter
:= 255;
1106 gState
:= STATE_FOLD
;
1108 if gDefInterTime
< 0 then
1109 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1111 gInterEndTime
:= gDefInterTime
* 1000;
1114 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1116 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1117 SingleStat
.GameTime
:= gTime
;
1118 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1119 SingleStat
.TotalSecrets
:= gSecretsCount
;
1120 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1121 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1122 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1123 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1124 if SingleStat
.TwoPlayers
then
1126 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1127 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1130 g_Game_ExecuteEvent('onmapend');
1133 if gNextMap
<> '' then
1135 gMusic
.SetByName('MUSIC_INTERMUS');
1137 gState
:= STATE_INTERSINGLE
;
1140 g_Game_ExecuteEvent('oninter');
1142 else // Áîëüøå íåò êàðò
1144 // Çàòóõàþùèé ýêðàí:
1145 EndingGameCounter
:= 255;
1146 gState
:= STATE_FOLD
;
1151 // Îêîí÷àíèå îáðàáîòàíî:
1152 if gExit
<> EXIT_QUIT
then
1156 procedure drawTime(X
, Y
: Integer); inline;
1158 e_TextureFontPrint(x
, y
,
1159 Format('%d:%.2d:%.2d', [
1160 gTime
div 1000 div 3600,
1161 (gTime
div 1000 div 60) mod 60,
1162 gTime
div 1000 mod 60
1167 procedure DrawStat();
1169 pc
, x
, y
, w
, h
: Integer;
1170 w1
, w2
, w3
, w4
: Integer;
1172 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1175 stat
: TPlayerStatArray
;
1183 pc
:= g_Player_GetCount
;
1184 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1186 w
:= gScreenWidth
-(gScreenWidth
div 5);
1187 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1190 h
:= 40+ch
*5+(ch
+8)*pc
;
1191 x
:= (gScreenWidth
div 2)-(w
div 2);
1192 y
:= (gScreenHeight
div 2)-(h
div 2);
1194 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1195 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1197 drawTime(x
+w
-78, y
+8);
1199 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1200 map
:= g_ExtractFileName(gMapInfo
.Map
);
1201 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1203 case gGameSettings
.GameMode
of
1206 if gGameSettings
.MaxLives
= 0 then
1207 s1
:= _lc
[I_GAME_DM
]
1209 s1
:= _lc
[I_GAME_LMS
];
1210 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1211 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1216 if gGameSettings
.MaxLives
= 0 then
1217 s1
:= _lc
[I_GAME_TDM
]
1219 s1
:= _lc
[I_GAME_TLMS
];
1220 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1221 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1226 s1
:= _lc
[I_GAME_CTF
];
1227 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1228 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1233 if gGameSettings
.MaxLives
= 0 then
1234 s1
:= _lc
[I_GAME_COOP
]
1236 s1
:= _lc
[I_GAME_SURV
];
1237 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1238 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1249 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1251 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1253 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1255 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1256 gStdFont
, 200, 200, 200, 1);
1258 if NetMode
= NET_SERVER
then
1259 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1261 if NetMode
= NET_CLIENT
then
1262 e_TextureFontPrintEx(x
+8, y
+ 8,
1263 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1267 stat
:= g_Player_GetStats();
1270 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1271 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1273 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1275 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1279 for a
:= TEAM_RED
to TEAM_BLUE
do
1281 if a
= TEAM_RED
then
1283 s1
:= _lc
[I_GAME_TEAM_RED
];
1290 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1296 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1297 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1298 gStdFont
, r
, g
, b
, 1);
1300 _y
:= _y
+ch
+(ch
div 4);
1301 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1302 _y
:= _y
+(ch
div 4);
1304 for aa
:= 0 to High(stat
) do
1305 if stat
[aa
].Team
= a
then
1321 namestr
:= Format('[%5d] %s', [UID
, Name
])
1325 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1327 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1329 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1331 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1338 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1341 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1342 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1343 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1344 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1347 for aa
:= 0 to High(stat
) do
1361 namestr
:= Format('[%5d] %s', [UID
, Name
])
1365 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1366 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1368 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1370 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1372 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1374 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1380 procedure g_Game_Init();
1383 knownFiles
: array of AnsiString = nil;
1385 wext
, s
: AnsiString;
1390 gTempDelete
:= False;
1392 sfsGCDisable(); // temporary disable removing of temporary volumes
1395 TEXTUREFILTER
:= GL_LINEAR
;
1396 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1397 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1398 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1399 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1400 TEXTUREFILTER
:= GL_NEAREST
;
1402 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1403 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1404 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1406 g_Game_ClearLoading();
1407 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1408 g_Game_SetLoadingText('', 0, False);
1410 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1413 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1414 g_PlayerModel_LoadData();
1416 // load models from all possible wad types, in all known directories
1417 // this does a loosy job (linear search, ooph!), but meh
1418 for wext
in wadExtensions
do
1420 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1422 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1426 for s
in knownFiles
do
1428 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1436 SetLength(knownFiles
, length(knownFiles
)+1);
1437 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1439 until (FindNext(SR
) <> 0);
1445 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1447 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
);
1448 for s
in knownFiles
do
1450 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1454 gPauseMain
:= false;
1455 gPauseHolmes
:= false;
1458 {e_MouseInfo.Accel := 1.0;}
1460 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1463 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1464 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1465 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1466 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1467 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1470 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1474 gMusic
:= TMusic
.Create();
1475 gMusic
.SetByName('MUSIC_MENU');
1478 gGameSettings
.WarmupTime
:= 30;
1480 gState
:= STATE_MENU
;
1482 SetLength(gEvents
, 6);
1483 gEvents
[0].Name
:= 'ongamestart';
1484 gEvents
[1].Name
:= 'ongameend';
1485 gEvents
[2].Name
:= 'onmapstart';
1486 gEvents
[3].Name
:= 'onmapend';
1487 gEvents
[4].Name
:= 'oninter';
1488 gEvents
[5].Name
:= 'onwadend';
1490 sfsGCEnable(); // enable releasing unused volumes
1494 procedure g_Game_Free(freeTextures
: Boolean=true);
1496 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1497 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1499 g_Map_Free(freeTextures
);
1501 g_Player_RemoveAllCorpses();
1503 gGameSettings
.GameType
:= GT_NONE
;
1504 if gGameSettings
.GameMode
= GM_SINGLE
then
1505 gGameSettings
.GameMode
:= GM_DM
;
1506 gSwitchGameMode
:= gGameSettings
.GameMode
;
1509 gExitByTrigger
:= False;
1512 function IsActivePlayer(p
: TPlayer
): Boolean;
1517 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1520 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1527 if gPlayers
= nil then
1529 for a
:= Low(gPlayers
) to High(gPlayers
) do
1530 if IsActivePlayer(gPlayers
[a
]) then
1532 if gPlayers
[a
].UID
<> ID
then
1534 Result
:= gPlayers
[a
];
1539 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1545 if gPlayers
= nil then
1549 for a
:= Low(gPlayers
) to High(gPlayers
) do
1550 if IsActivePlayer(gPlayers
[a
]) then
1552 SetLength(ids
, Length(ids
) + 1);
1553 ids
[High(ids
)] := gPlayers
[a
].UID
;
1554 if gPlayers
[a
].UID
= Skip
then
1557 if Length(ids
) = 0 then
1562 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1565 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1571 if gPlayers
= nil then
1575 for a
:= Low(gPlayers
) to High(gPlayers
) do
1576 if IsActivePlayer(gPlayers
[a
]) then
1578 SetLength(ids
, Length(ids
) + 1);
1579 ids
[High(ids
)] := gPlayers
[a
].UID
;
1580 if gPlayers
[a
].UID
= Skip
then
1583 if Length(ids
) = 0 then
1586 Result
:= ids
[Length(ids
) - 1]
1588 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1591 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1597 if gPlayers
= nil then
1601 for a
:= Low(gPlayers
) to High(gPlayers
) do
1602 if IsActivePlayer(gPlayers
[a
]) then
1604 SetLength(ids
, Length(ids
) + 1);
1605 ids
[High(ids
)] := gPlayers
[a
].UID
;
1606 if gPlayers
[a
].UID
= Skip
then
1609 if Length(ids
) = 0 then
1611 if Length(ids
) = 1 then
1616 Result
:= ids
[Random(Length(ids
))];
1618 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1620 Result
:= ids
[Random(Length(ids
))];
1625 function GetRandomSpectMode(Current
: Byte): Byte;
1632 0: Result
:= SPECT_STATS
;
1633 1: Result
:= SPECT_MAPVIEW
;
1634 2: Result
:= SPECT_MAPVIEW
;
1635 3: Result
:= SPECT_PLAYERS
;
1636 4: Result
:= SPECT_PLAYERS
;
1637 5: Result
:= SPECT_PLAYERS
;
1638 6: Result
:= SPECT_PLAYERS
;
1640 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1644 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1650 if (plr
= nil) then exit
;
1651 if (p
= 2) then time
:= 1000 else time
:= 1;
1652 strafeDir
:= MoveButton
shr 4;
1653 MoveButton
:= MoveButton
and $0F;
1655 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1656 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1657 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1658 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1659 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1660 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1662 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1663 if MoveButton
= 1 then
1664 plr
.PressKey(KEY_LEFT
, time
)
1665 else if MoveButton
= 2 then
1666 plr
.PressKey(KEY_RIGHT
, time
);
1668 // if we have "strafe" key, turn off old strafe mechanics
1669 if gPlayerAction
[p
, ACTION_STRAFE
] then
1671 // new strafe mechanics
1672 if (strafeDir
= 0) then
1673 strafeDir
:= MoveButton
; // start strafing
1674 // now set direction according to strafe (reversed)
1675 if (strafeDir
= 2) then
1676 plr
.SetDirection(TDirection
.D_LEFT
)
1677 else if (strafeDir
= 1) then
1678 plr
.SetDirection(TDirection
.D_RIGHT
)
1682 strafeDir
:= 0; // not strafing anymore
1683 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1684 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1685 plr
.SetDirection(TDirection
.D_LEFT
)
1686 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1687 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1688 plr
.SetDirection(TDirection
.D_RIGHT
)
1689 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1690 else if MoveButton
<> 0 then
1691 plr
.SetDirection(TDirection(MoveButton
-1))
1694 // fix movebutton state
1695 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1697 // Îñòàëüíûå êëàâèøè:
1698 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1699 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1700 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1701 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1702 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1704 for i
:= WP_FACT
to WP_LACT
do
1706 if gWeaponAction
[p
, i
] then
1708 plr
.ProcessWeaponAction(i
);
1709 gWeaponAction
[p
, i
] := False
1713 for i
:= WP_FIRST
to WP_LAST
do
1715 if gSelectWeapon
[p
, i
] then
1717 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1718 gSelectWeapon
[p
, i
] := False
1722 // HACK: add dynlight here
1723 if gwin_k8_enable_light_experiments
then
1725 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1727 g_playerLight
:= true;
1729 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1731 g_playerLight
:= false;
1735 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1738 // HACK: don't have a "key was pressed" function
1739 procedure InterReady();
1741 if InterReadyTime
> gTime
then Exit
;
1742 InterReadyTime
:= gTime
+ 3000;
1743 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1746 procedure g_Game_PreUpdate();
1748 // these are in separate PreUpdate functions because they can interact during Update()
1749 // and are synced over the net
1750 // we don't care that much about corpses and gibs
1751 g_Player_PreUpdate();
1752 g_Monsters_PreUpdate();
1753 g_Items_PreUpdate();
1754 g_Weapon_PreUpdate();
1757 procedure g_Game_Update();
1759 Msg
: g_gui
.TMessage
;
1765 function sendMonsPos (mon
: TMonster
): Boolean;
1767 result
:= false; // don't stop
1768 // this will also reset "need-send" flag
1769 if mon
.gncNeedSend
then
1771 MH_SEND_MonsterPos(mon
.UID
);
1773 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1775 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1777 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1779 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1783 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1785 result
:= false; // don't stop
1786 // this will also reset "need-send" flag
1787 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1790 function sendItemPos (it
: PItem
): Boolean;
1792 result
:= false; // don't stop
1795 MH_SEND_ItemPos(it
.myId
);
1796 it
.needSend
:= False;
1801 reliableUpdate
: Boolean;
1806 // Ïîðà âûêëþ÷àòü èãðó:
1807 if gExit
= EXIT_QUIT
then
1809 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1813 if gExit
= EXIT_QUIT
then
1817 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1818 // no need to, as we'll do it in event handler
1820 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1823 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1825 gExit
:= EXIT_SIMPLE
;
1830 // process master server communications
1831 g_Net_Slist_Pulse();
1834 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1835 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1836 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1837 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1839 if g_Game_IsNet
and g_Game_IsServer
then
1841 gInterTime
:= gInterTime
+ GAME_TICK
;
1842 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1843 if a
<> gServInterTime
then
1845 gServInterTime
:= a
;
1846 MH_SEND_TimeSync(gServInterTime
);
1850 if (not g_Game_IsClient
) and
1854 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1855 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1856 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1857 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1859 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1860 and (g_ActiveWindow
= nil)
1862 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1865 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1866 g_Game_StopAllSounds(True);
1868 if gMapOnce
then // Ýòî áûë òåñò
1869 gExit
:= EXIT_SIMPLE
1871 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1872 g_Game_ChangeMap(gNextMap
)
1873 else // Ñëåäóþùåé êàðòû íåò
1875 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1877 // Âûõîä â ãëàâíîå ìåíþ:
1879 g_GUI_ShowWindow('MainMenu');
1880 gMusic
.SetByName('MUSIC_MENU');
1882 gState
:= STATE_MENU
;
1885 // Ôèíàëüíàÿ êàðòèíêà:
1886 g_Game_ExecuteEvent('onwadend');
1888 if not gMusic
.SetByName('MUSIC_endmus') then
1889 gMusic
.SetByName('MUSIC_STDENDMUS');
1891 gState
:= STATE_ENDPIC
;
1893 g_Game_ExecuteEvent('ongameend');
1898 else if g_Game_IsClient
and
1901 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1902 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1903 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1904 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1906 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1907 and (g_ActiveWindow
= nil)
1915 if gState
= STATE_INTERTEXT
then
1916 if InterText
.counter
> 0 then
1917 InterText
.counter
:= InterText
.counter
- 1;
1920 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1922 if EndingGameCounter
= 0 then
1924 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1925 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1927 gState
:= STATE_INTERCUSTOM
;
1928 InterReadyTime
:= -1;
1929 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1931 g_Game_ExecuteEvent('onwadend');
1932 if not gMusic
.SetByName('MUSIC_endmus') then
1933 gMusic
.SetByName('MUSIC_STDENDMUS');
1936 gMusic
.SetByName('MUSIC_ROUNDMUS');
1940 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1942 gMusic
.SetByName('MUSIC_INTERMUS');
1944 gState
:= STATE_INTERSINGLE
;
1947 g_Game_ExecuteEvent('oninter');
1950 DecMin(EndingGameCounter
, 6, 0);
1953 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1955 if gMapOnce
then // Ýòî áûë òåñò
1957 gExit
:= EXIT_SIMPLE
;
1963 g_Serverlist_Control(slCurrent
, slTable
);
1966 // Ñòàòèñòèêà ïî Tab:
1968 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1971 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1973 // Âðåìÿ += 28 ìèëëèñåêóíä:
1974 gTime
:= gTime
+ GAME_TICK
;
1976 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1977 if MessageTime
= 0 then
1979 if MessageTime
> 0 then
1980 MessageTime
:= MessageTime
- 1;
1982 if (g_Game_IsServer
) then
1984 // Áûë çàäàí ëèìèò âðåìåíè:
1985 if (gGameSettings
.TimeLimit
> 0) then
1986 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1987 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1992 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1993 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1994 g_Game_RestartRound(gLMSSoftSpawn
);
1996 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1997 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1999 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2001 g_Console_Process(gVoteCommand
);
2003 gVotePassed
:= False;
2006 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2007 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2008 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2009 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2010 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2012 // Áûë çàäàí ëèìèò ïîáåä:
2013 if (gGameSettings
.GoalLimit
> 0) then
2017 if gGameSettings
.GameMode
= GM_DM
then
2018 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2019 for i
:= 0 to High(gPlayers
) do
2020 if gPlayers
[i
] <> nil then
2021 if gPlayers
[i
].Frags
> b
then
2022 b
:= gPlayers
[i
].Frags
;
2025 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2026 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2027 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2030 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2031 if b
>= gGameSettings
.GoalLimit
then
2038 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2039 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2040 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2041 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2043 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2044 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2045 end // if not console
2048 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2050 // process weapon switch queue
2054 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2055 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2057 if not gSpectKeyPress
then
2059 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2061 // switch spect mode
2063 SPECT_NONE
: ; // not spectator
2065 SPECT_MAPVIEW
: Inc(gSpectMode
);
2066 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2068 gSpectKeyPress
:= True;
2070 if (gSpectMode
= SPECT_MAPVIEW
)
2071 and (not gSpectAuto
) then
2073 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2074 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2075 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2076 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2077 if gPlayerAction
[0, ACTION_LOOKUP
] then
2078 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2079 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2080 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2081 if gWeaponAction
[0, WP_PREV
] then
2084 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2085 gWeaponAction
[0, WP_PREV
] := False;
2087 if gWeaponAction
[0, WP_NEXT
] then
2090 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2091 gWeaponAction
[0, WP_NEXT
] := False;
2094 if (gSpectMode
= SPECT_PLAYERS
)
2095 and (not gSpectAuto
) then
2097 if gPlayerAction
[0, ACTION_LOOKUP
] then
2100 gSpectViewTwo
:= True;
2101 gSpectKeyPress
:= True;
2103 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2105 // remove second view
2106 gSpectViewTwo
:= False;
2107 gSpectKeyPress
:= True;
2109 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2111 // prev player (view 1)
2112 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2113 gSpectKeyPress
:= True;
2115 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2117 // next player (view 1)
2118 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2119 gSpectKeyPress
:= True;
2121 if gWeaponAction
[0, WP_PREV
] then
2123 // prev player (view 2)
2124 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2125 gWeaponAction
[0, WP_PREV
] := False;
2127 if gWeaponAction
[0, WP_NEXT
] then
2129 // next player (view 2)
2130 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2131 gWeaponAction
[0, WP_NEXT
] := False;
2134 if gPlayerAction
[0, ACTION_ATTACK
] then
2136 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2139 gSpectAutoNext
:= 0;
2140 gSpectViewTwo
:= False;
2141 gSpectKeyPress
:= True;
2146 gSpectMode
:= SPECT_STATS
;
2147 gSpectAuto
:= False;
2148 gSpectKeyPress
:= True;
2153 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2154 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2155 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2156 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2157 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2158 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2159 gSpectKeyPress
:= False;
2163 if gSpectMode
= SPECT_MAPVIEW
then
2165 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2167 gSpectAutoNext
:= gTime
2170 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2172 gSpectAutoNext
:= gTime
2176 if gSpectAutoNext
<= gTime
then
2178 if gSpectAutoNext
> 0 then
2180 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2184 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2185 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2186 gSpectAutoStepX
:= Random(9) - 4;
2187 gSpectAutoStepY
:= Random(9) - 4;
2188 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2189 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2190 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2191 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2192 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2193 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2197 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2202 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2203 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2204 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2210 // Îáíîâëÿåì âñå îñòàëüíîå:
2213 g_Triggers_Update();
2215 g_Monsters_Update();
2217 g_Player_UpdateAll();
2218 g_Player_UpdatePhysicalObjects();
2220 // server: send newly spawned monsters unconditionally
2221 if (gGameSettings
.GameType
= GT_SERVER
) then
2223 if (Length(gMonstersSpawned
) > 0) then
2225 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2226 SetLength(gMonstersSpawned
, 0);
2230 if (gSoundTriggerTime
> 8) then
2232 g_Game_UpdateTriggerSounds();
2233 gSoundTriggerTime
:= 0;
2237 Inc(gSoundTriggerTime
);
2240 if (NetMode
= NET_SERVER
) then
2242 Inc(NetTimeToUpdate
);
2243 Inc(NetTimeToReliable
);
2245 // send monster updates
2246 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2248 // send all monsters (periodic sync)
2249 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2251 for I
:= 0 to High(gPlayers
) do
2253 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2256 g_Mons_ForEach(sendMonsPos
);
2258 // update flags that aren't stationary
2259 if gGameSettings
.GameMode
= GM_CTF
then
2260 for I
:= FLAG_RED
to FLAG_BLUE
do
2261 if gFlags
[I
].NeedSend
then
2263 gFlags
[I
].NeedSend
:= False;
2267 // update items that aren't stationary
2268 g_Items_ForEachAlive(sendItemPos
);
2270 if reliableUpdate
then
2272 NetTimeToReliable
:= 0;
2273 NetTimeToUpdate
:= NetUpdateRate
;
2277 NetTimeToUpdate
:= 0;
2282 // send only mosters with some unexpected changes
2283 g_Mons_ForEach(sendMonsPosUnexpected
);
2286 // send unexpected platform changes
2287 g_Map_NetSendInterestingPanels();
2289 g_Net_Slist_ServerUpdate();
2291 if NetUseMaster then
2293 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2295 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2297 NetTimeToMaster := gTime + NetMasterRate;
2302 else if (NetMode
= NET_CLIENT
) then
2304 MC_SEND_PlayerPos();
2306 end; // if gameOn ...
2308 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2309 if g_ActiveWindow
<> nil then
2311 w
:= e_GetFirstKeyPressed();
2313 if (w
<> IK_INVALID
) then
2315 Msg
.Msg
:= MESSAGE_DIKEY
;
2317 g_ActiveWindow
.OnMessage(Msg
);
2320 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2321 if g_ActiveWindow
<> nil then
2322 g_ActiveWindow
.Update();
2324 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2325 if gResolutionChange
then
2327 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2328 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2329 gResolutionChange
:= False;
2330 g_ActiveWindow
:= nil;
2333 // Íóæíî ñìåíèòü ÿçûê:
2334 if gLanguageChange
then
2336 //e_WriteLog('Read language file', MSG_NOTIFY);
2337 //g_Language_Load(DataDir + gLanguage + '.txt');
2338 g_Language_Set(gLanguage
);
2342 gLanguageChange
:= False;
2346 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2347 if e_KeyPressed(IK_F10
) and
2349 (not gConsoleShow
) and
2350 (g_ActiveWindow
= nil) then
2355 Time
:= sys_GetTicks() {div 1000};
2357 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2358 if gDelayedEvents
<> nil then
2359 for a
:= 0 to High(gDelayedEvents
) do
2360 if gDelayedEvents
[a
].Pending
and
2362 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2363 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2366 case gDelayedEvents
[a
].DEType
of
2368 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2371 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2375 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2376 if g_Game_IsNet
and g_Game_IsServer
then
2377 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2381 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2383 gDelayedEvents
[a
].Pending
:= False;
2386 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2387 UPSCounter
:= UPSCounter
+ 1;
2388 if Time
- UPSTime
>= 1000 then
2397 g_Weapon_AddDynLights();
2398 g_Items_AddDynLights();
2402 procedure g_Game_LoadChatSounds(Resource
: string);
2405 FileName
, Snd
: string;
2407 len
, cnt
, tags
, i
, j
: Integer;
2410 FileName
:= g_ExtractWadName(Resource
);
2412 WAD
:= TWADFile
.Create();
2413 WAD
.ReadFile(FileName
);
2415 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2422 cfg
:= TConfig
.CreateMem(p
, len
);
2423 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2425 SetLength(gChatSounds
, cnt
);
2426 for i
:= 0 to Length(gChatSounds
) - 1 do
2428 gChatSounds
[i
].Sound
:= nil;
2429 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2430 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2431 if (Snd
= '') or (Tags
<= 0) then
2433 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2434 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2435 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2436 SetLength(gChatSounds
[i
].Tags
, tags
);
2437 for j
:= 0 to tags
- 1 do
2438 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2439 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2446 procedure g_Game_FreeChatSounds();
2450 for i
:= 0 to Length(gChatSounds
) - 1 do
2452 gChatSounds
[i
].Sound
.Free();
2453 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2455 SetLength(gChatSounds
, 0);
2459 procedure g_Game_LoadData();
2466 if DataLoaded
then Exit
;
2468 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2470 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2471 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2472 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2473 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2474 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2475 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2476 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2477 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2478 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2479 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2480 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2481 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2482 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2483 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2484 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2487 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2488 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2489 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2490 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2494 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2495 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2496 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2497 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2498 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
2504 hasPBarGfx
:= false;
2508 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2509 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2510 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2511 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2512 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2513 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2514 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2515 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2516 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2517 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2518 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2519 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2520 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2521 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2522 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2523 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2524 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2525 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2526 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2527 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2528 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2529 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2530 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2531 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2532 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2533 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2534 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2535 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2536 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2537 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2538 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2539 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2540 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2541 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2542 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2543 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2544 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2545 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2546 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2548 goodsnd
[0] := TPlayableSound
.Create();
2549 goodsnd
[1] := TPlayableSound
.Create();
2550 goodsnd
[2] := TPlayableSound
.Create();
2551 goodsnd
[3] := TPlayableSound
.Create();
2553 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2554 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2555 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2556 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2558 killsnd
[0] := TPlayableSound
.Create();
2559 killsnd
[1] := TPlayableSound
.Create();
2560 killsnd
[2] := TPlayableSound
.Create();
2561 killsnd
[3] := TPlayableSound
.Create();
2563 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2564 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2565 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2566 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2568 hahasnd
[0] := TPlayableSound
.Create();
2569 hahasnd
[1] := TPlayableSound
.Create();
2570 hahasnd
[2] := TPlayableSound
.Create();
2572 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2573 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2574 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2576 sound_get_flag
[0] := TPlayableSound
.Create();
2577 sound_get_flag
[1] := TPlayableSound
.Create();
2578 sound_lost_flag
[0] := TPlayableSound
.Create();
2579 sound_lost_flag
[1] := TPlayableSound
.Create();
2580 sound_ret_flag
[0] := TPlayableSound
.Create();
2581 sound_ret_flag
[1] := TPlayableSound
.Create();
2582 sound_cap_flag
[0] := TPlayableSound
.Create();
2583 sound_cap_flag
[1] := TPlayableSound
.Create();
2585 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2586 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2587 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2588 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2589 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2590 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2591 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2592 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2594 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2596 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2599 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2600 g_Weapon_LoadData();
2602 g_Monsters_LoadData();
2607 procedure g_Game_FreeData();
2609 if not DataLoaded
then Exit
;
2612 g_Weapon_FreeData();
2613 g_Monsters_FreeData();
2615 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2617 g_Texture_Delete('NOTEXTURE');
2618 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2619 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2620 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2621 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2622 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2623 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2624 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2625 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2626 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2627 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2628 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2629 g_Frames_DeleteByName('FRAMES_TELEPORT');
2630 g_Frames_DeleteByName('FRAMES_PUNCH');
2631 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2632 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2633 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2634 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2635 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2636 g_Sound_Delete('SOUND_GAME_TELEPORT');
2637 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2638 g_Sound_Delete('SOUND_GAME_SECRET');
2639 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2640 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2641 g_Sound_Delete('SOUND_GAME_BULK1');
2642 g_Sound_Delete('SOUND_GAME_BULK2');
2643 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2644 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2645 g_Sound_Delete('SOUND_GAME_BURNING');
2646 g_Sound_Delete('SOUND_GAME_SWITCH1');
2647 g_Sound_Delete('SOUND_GAME_SWITCH0');
2654 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2655 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2656 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2657 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2664 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2665 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2666 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2667 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2673 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2674 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2675 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2677 sound_get_flag
[0].Free();
2678 sound_get_flag
[1].Free();
2679 sound_lost_flag
[0].Free();
2680 sound_lost_flag
[1].Free();
2681 sound_ret_flag
[0].Free();
2682 sound_ret_flag
[1].Free();
2683 sound_cap_flag
[0].Free();
2684 sound_cap_flag
[1].Free();
2686 g_Sound_Delete('SOUND_CTF_GET1');
2687 g_Sound_Delete('SOUND_CTF_GET2');
2688 g_Sound_Delete('SOUND_CTF_LOST1');
2689 g_Sound_Delete('SOUND_CTF_LOST2');
2690 g_Sound_Delete('SOUND_CTF_RETURN1');
2691 g_Sound_Delete('SOUND_CTF_RETURN2');
2692 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2693 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2695 g_Game_FreeChatSounds();
2697 DataLoaded
:= False;
2700 procedure DrawCustomStat();
2706 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2707 s1
, s2
, topstr
: String;
2709 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2713 if g_Console_Action(ACTION_SCORES
) then
2715 if not gStatsPressed
then
2717 gStatsOff
:= not gStatsOff
;
2718 gStatsPressed
:= True;
2722 gStatsPressed
:= False;
2726 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2727 w
:= (Length(s1
) * ww2
) div 2;
2728 x
:= gScreenWidth
div 2 - w
;
2730 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2734 if (gGameSettings
.GameMode
= GM_COOP
) then
2736 if gMissionFailed
then
2737 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2739 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2742 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2744 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2745 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2747 if g_Game_IsNet
then
2749 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2750 if not gChatShow
then
2751 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2752 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2755 if g_Game_IsClient
then
2756 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2758 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2759 if not gChatShow
then
2760 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2761 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2766 w
:= gScreenWidth
-x
*2;
2772 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2773 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2775 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2777 case CustomStat
.GameMode
of
2780 if gGameSettings
.MaxLives
= 0 then
2781 s1
:= _lc
[I_GAME_DM
]
2783 s1
:= _lc
[I_GAME_LMS
];
2787 if gGameSettings
.MaxLives
= 0 then
2788 s1
:= _lc
[I_GAME_TDM
]
2790 s1
:= _lc
[I_GAME_TLMS
];
2792 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2795 if gGameSettings
.MaxLives
= 0 then
2796 s1
:= _lc
[I_GAME_COOP
]
2798 s1
:= _lc
[I_GAME_SURV
];
2804 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2808 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2809 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2812 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2813 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2814 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2815 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2817 pc
:= Length(CustomStat
.PlayerStat
);
2818 if pc
= 0 then Exit
;
2820 if CustomStat
.GameMode
= GM_COOP
then
2822 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2824 s2
:= _lc
[I_GAME_MONSTERS
];
2825 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2826 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2828 s2
:= _lc
[I_GAME_SECRETS
];
2829 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2830 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2833 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2835 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2836 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2837 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2839 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2840 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2841 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2845 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2850 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2851 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2852 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2854 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2857 for t
:= TEAM_RED
to TEAM_BLUE
do
2859 if t
= TEAM_RED
then
2861 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2862 gStdFont
, 255, 0, 0, 1);
2863 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2864 gStdFont
, 255, 0, 0, 1);
2871 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2872 gStdFont
, 0, 0, 255, 1);
2873 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2874 gStdFont
, 0, 0, 255, 1);
2880 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2883 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2884 if CustomStat
.PlayerStat
[p
].Team
= t
then
2885 with CustomStat
.PlayerStat
[p
] do
2899 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2900 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2902 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2903 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2904 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2911 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2914 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2915 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2916 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2919 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2920 with CustomStat
.PlayerStat
[p
] do
2922 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2929 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2930 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2932 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2933 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2934 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2939 // HACK: take stats screenshot immediately after the first frame of the stats showing
2940 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2942 g_TakeScreenShot('stats/' + StatFilename
);
2943 StatShotDone
:= True;
2947 procedure DrawSingleStat();
2949 tm
, key_x
, val_x
, y
: Integer;
2953 procedure player_stat(n
: Integer);
2959 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2960 s2
:= Format(' %d', [gTotalMonsters
]);
2962 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2963 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2964 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2965 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2967 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2968 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2970 // "Kills-per-minute: ##.#":
2971 s1
:= _lc
[I_MENU_INTER_KPM
];
2973 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2975 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2976 s2
:= Format(' %.1f', [kpm
]);
2978 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2979 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2981 // "Secrets found: # / #":
2982 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2983 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2985 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2986 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2987 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2988 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2990 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2991 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2995 // "Level Complete":
2996 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2997 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2999 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3000 s1
:= _lc
[I_MENU_INTER_KPM
];
3001 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3004 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
3006 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
3007 val_x
:= key_x
+ w1
;
3010 tm
:= SingleStat
.GameTime
div 1000;
3011 s1
:= _lc
[I_MENU_INTER_TIME
];
3012 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
3014 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
3015 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
3017 if SingleStat
.TwoPlayers
then
3020 s1
:= _lc
[I_MENU_PLAYER_1
];
3021 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3022 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
3024 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3029 s1
:= _lc
[I_MENU_PLAYER_2
];
3030 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3031 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3033 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3039 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3045 procedure DrawLoadingStat();
3046 procedure drawRect (x
, y
, w
, h
: Integer);
3048 if (w
< 1) or (h
< 1) then exit
;
3050 glVertex2f(x
+0.375, y
+0.375);
3051 glVertex2f(x
+w
+0.375, y
+0.375);
3052 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3053 glVertex2f(x
+0.375, y
+h
+0.375);
3057 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3059 rectW
, rectH
: Integer;
3066 idl
, idr
, idb
, idm
: LongWord;
3070 if (total
< 1) then exit
;
3071 if (cur
< 1) then exit
; // don't blink
3072 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3073 //if (cur < 0) then cur := 0;
3074 //if (cur > total) then cur := total;
3077 if (hasPBarGfx
) then
3079 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3080 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3081 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3082 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3083 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3084 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3085 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3086 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3088 //rectW := gScreenWidth-360;
3089 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3092 x0
:= (gScreenWidth
-rectW
) div 2;
3093 y0
:= gScreenHeight
-rectH
-64;
3094 if (y0
< 2) then y0
:= 2;
3096 glEnable(GL_SCISSOR_TEST
);
3099 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3100 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3101 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3104 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3106 while (f
< x0
+rectW
) do
3108 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3113 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3114 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3117 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3118 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3122 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3128 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3132 rectW
:= gScreenWidth
-64;
3135 x0
:= (gScreenWidth
-rectW
) div 2;
3136 y0
:= gScreenHeight
-rectH
-64;
3137 if (y0
< 2) then y0
:= 2;
3139 glDisable(GL_BLEND
);
3140 glDisable(GL_TEXTURE_2D
);
3142 //glClearColor(0, 0, 0, 0);
3143 //glClear(GL_COLOR_BUFFER_BIT);
3145 glColor4ub(127, 127, 127, 255);
3146 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3148 glColor4ub(0, 0, 0, 255);
3149 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3151 glColor4ub(127, 127, 127, 255);
3152 wdt
:= rectW
*cur
div total
;
3153 if (wdt
> rectW
) then wdt
:= rectW
;
3154 drawRect(x0
, y0
, wdt
, rectH
);
3163 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3165 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3166 yy
:= (gScreenHeight
div 3);
3167 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3168 xx
:= (gScreenWidth
div 3);
3172 for i
:= 0 to NextMsg
-1 do
3174 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3175 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3179 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3180 yy
:= yy
+ LOADING_INTERLINE
;
3181 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3186 procedure DrawMenuBackground(tex
: AnsiString);
3192 if g_Texture_Get(tex
, ID
) then
3194 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3195 e_GetTextureSize(ID
, @w
, @h
);
3197 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3199 w
:= trunc(w
* (gScreenHeight
/ h
));
3200 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3202 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3205 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3207 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3209 function monDraw (mon
: TMonster
): Boolean;
3211 result
:= false; // don't stop
3216 // Ëåâûé âåðõíèé óãîë
3217 aX
:= Obj
.X
div ScaleSz
+ 1;
3218 aY
:= Obj
.Y
div ScaleSz
+ 1;
3220 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3221 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3222 // Ïðàâûé íèæíèé óãîë
3223 aX2
:= aX
+ aX2
- 1;
3224 aY2
:= aY
+ aY2
- 1;
3225 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3231 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3232 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3235 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3236 ScaleSz
:= 16 div Scale
;
3237 // Ðàçìåðû ìèíè-êàðòû:
3238 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3239 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3241 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3243 if gWalls
<> nil then
3246 for a
:= 0 to High(gWalls
) do
3248 if PanelType
<> 0 then
3250 // Ëåâûé âåðõíèé óãîë:
3251 aX
:= X
div ScaleSz
;
3252 aY
:= Y
div ScaleSz
;
3254 aX2
:= max(Width
div ScaleSz
, 1);
3255 aY2
:= max(Height
div ScaleSz
, 1);
3256 // Ïðàâûé íèæíèé óãîë:
3257 aX2
:= aX
+ aX2
- 1;
3258 aY2
:= aY
+ aY2
- 1;
3261 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3262 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3263 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3267 if gSteps
<> nil then
3270 for a
:= 0 to High(gSteps
) do
3272 if PanelType
<> 0 then
3274 // Ëåâûé âåðõíèé óãîë:
3275 aX
:= X
div ScaleSz
;
3276 aY
:= Y
div ScaleSz
;
3278 aX2
:= max(Width
div ScaleSz
, 1);
3279 aY2
:= max(Height
div ScaleSz
, 1);
3280 // Ïðàâûé íèæíèé óãîë:
3281 aX2
:= aX
+ aX2
- 1;
3282 aY2
:= aY
+ aY2
- 1;
3284 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3287 if gLifts
<> nil then
3290 for a
:= 0 to High(gLifts
) do
3292 if PanelType
<> 0 then
3294 // Ëåâûé âåðõíèé óãîë:
3295 aX
:= X
div ScaleSz
;
3296 aY
:= Y
div ScaleSz
;
3298 aX2
:= max(Width
div ScaleSz
, 1);
3299 aY2
:= max(Height
div ScaleSz
, 1);
3300 // Ïðàâûé íèæíèé óãîë:
3301 aX2
:= aX
+ aX2
- 1;
3302 aY2
:= aY
+ aY2
- 1;
3305 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3306 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3307 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3308 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3312 if gWater
<> nil then
3315 for a
:= 0 to High(gWater
) do
3317 if PanelType
<> 0 then
3319 // Ëåâûé âåðõíèé óãîë:
3320 aX
:= X
div ScaleSz
;
3321 aY
:= Y
div ScaleSz
;
3323 aX2
:= max(Width
div ScaleSz
, 1);
3324 aY2
:= max(Height
div ScaleSz
, 1);
3325 // Ïðàâûé íèæíèé óãîë:
3326 aX2
:= aX
+ aX2
- 1;
3327 aY2
:= aY
+ aY2
- 1;
3329 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3332 if gAcid1
<> nil then
3334 // Ðèñóåì êèñëîòó 1:
3335 for a
:= 0 to High(gAcid1
) do
3337 if PanelType
<> 0 then
3339 // Ëåâûé âåðõíèé óãîë:
3340 aX
:= X
div ScaleSz
;
3341 aY
:= Y
div ScaleSz
;
3343 aX2
:= max(Width
div ScaleSz
, 1);
3344 aY2
:= max(Height
div ScaleSz
, 1);
3345 // Ïðàâûé íèæíèé óãîë:
3346 aX2
:= aX
+ aX2
- 1;
3347 aY2
:= aY
+ aY2
- 1;
3349 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3352 if gAcid2
<> nil then
3354 // Ðèñóåì êèñëîòó 2:
3355 for a
:= 0 to High(gAcid2
) do
3357 if PanelType
<> 0 then
3359 // Ëåâûé âåðõíèé óãîë:
3360 aX
:= X
div ScaleSz
;
3361 aY
:= Y
div ScaleSz
;
3363 aX2
:= max(Width
div ScaleSz
, 1);
3364 aY2
:= max(Height
div ScaleSz
, 1);
3365 // Ïðàâûé íèæíèé óãîë:
3366 aX2
:= aX
+ aX2
- 1;
3367 aY2
:= aY
+ aY2
- 1;
3369 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3372 if gPlayers
<> nil then
3375 for a
:= 0 to High(gPlayers
) do
3376 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3378 // Ëåâûé âåðõíèé óãîë:
3379 aX
:= Obj
.X
div ScaleSz
+ 1;
3380 aY
:= Obj
.Y
div ScaleSz
+ 1;
3382 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3383 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3384 // Ïðàâûé íèæíèé óãîë:
3385 aX2
:= aX
+ aX2
- 1;
3386 aY2
:= aY
+ aY2
- 1;
3388 if gPlayers
[a
] = p
then
3389 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3392 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3393 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3394 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3399 g_Mons_ForEach(monDraw
);
3404 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3406 if not hasAmbient
then exit
;
3407 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3411 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3412 //FIXME: broken for splitscreen mode
3413 procedure renderDynLightsInternal ();
3415 //hasAmbient: Boolean;
3416 //ambColor: TDFColor;
3418 lx
, ly
, lrad
: Integer;
3419 scxywh
: array[0..3] of GLint
;
3422 if e_NoGraphics
then exit
;
3424 //TODO: lights should be in separate grid, i think
3425 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3426 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3429 //ambColor := gCurrentMap['light_ambient'].rgba;
3430 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3432 { // this will multiply incoming color to alpha from framebuffer
3434 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3438 * light rendering: (INVALID!)
3439 * glStencilFunc(GL_EQUAL, 0, $ff);
3441 * glClear(GL_STENCIL_BUFFER_BIT);
3442 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3443 * draw shadow volume into stencil buffer
3444 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3445 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3447 * draw color-less quad with light alpha (WARNING! don't touch color!)
3448 * glEnable(GL_BLEND);
3449 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3450 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3452 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3453 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3455 // setup OpenGL parameters
3456 glStencilMask($FFFFFFFF);
3457 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3458 glEnable(GL_STENCIL_TEST
);
3459 glEnable(GL_SCISSOR_TEST
);
3460 glClear(GL_STENCIL_BUFFER_BIT
);
3461 glStencilFunc(GL_EQUAL
, 0, $ff);
3463 for lln
:= 0 to g_dynLightCount
-1 do
3465 lx
:= g_dynLights
[lln
].x
;
3466 ly
:= g_dynLights
[lln
].y
;
3467 lrad
:= g_dynLights
[lln
].radius
;
3468 if (lrad
< 3) then continue
;
3470 if (lx
-sX
+lrad
< 0) then continue
;
3471 if (ly
-sY
+lrad
< 0) then continue
;
3472 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3473 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3475 // set scissor to optimize drawing
3476 if (g_dbg_scale
= 1.0) then
3478 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3482 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3484 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3485 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3486 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3487 // draw extruded panels
3488 glDisable(GL_TEXTURE_2D
);
3489 glDisable(GL_BLEND
);
3490 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3491 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3492 // render light texture
3493 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3494 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3497 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3498 glEnable(GL_TEXTURE_2D
);
3499 // color and opacity
3500 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3501 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3503 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3504 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3505 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3506 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3511 glDisable(GL_STENCIL_TEST
);
3512 glDisable(GL_BLEND
);
3513 glDisable(GL_SCISSOR_TEST
);
3514 //glScissor(0, 0, sWidth, sHeight);
3516 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3517 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3521 function fixViewportForScale (): Boolean;
3523 nx0
, ny0
, nw
, nh
: Integer;
3526 if (g_dbg_scale
<> 1.0) then
3529 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3530 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3531 nw
:= round(sWidth
/g_dbg_scale
);
3532 nh
:= round(sHeight
/g_dbg_scale
);
3541 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3542 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3543 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3545 TDrawCB
= procedure ();
3548 hasAmbient
: Boolean;
3550 doAmbient
: Boolean = false;
3552 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3557 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3558 if gdbg_map_use_accel_render
then
3560 tagmask
:= panelTypeToTag(panType
);
3561 while (gDrawPanelList
.count
> 0) do
3563 pan
:= TPanel(gDrawPanelList
.front());
3564 if ((pan
.tag
and tagmask
) = 0) then break
;
3565 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3566 gDrawPanelList
.popFront();
3571 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3573 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3576 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3578 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3579 if assigned(cb
) then cb();
3580 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3584 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3586 // our accelerated renderer will collect all panels to gDrawPanelList
3587 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3588 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3589 if gdbg_map_use_accel_render
then
3591 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3593 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3595 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3596 g_Map_DrawBack(backXOfs
, backYOfs
);
3597 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3599 if setTransMatrix
then
3601 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3602 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3603 glTranslatef(-sX
, -sY
, 0);
3607 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3608 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3613 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3614 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3615 glClear(GL_COLOR_BUFFER_BIT);
3618 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3621 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3622 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3623 drawOther('items', @g_Items_Draw
);
3624 drawOther('weapons', @g_Weapon_Draw
);
3625 drawOther('shells', @g_Player_DrawShells
);
3626 drawOther('drawall', @g_Player_DrawAll
);
3627 drawOther('corpses', @g_Player_DrawCorpses
);
3628 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3629 drawOther('monsters', @g_Monsters_Draw
);
3630 drawOther('itemdrop', @g_Items_DrawDrop
);
3631 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3632 drawOther('gfx', @g_GFX_Draw
);
3633 drawOther('flags', @g_Map_DrawFlags
);
3634 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3635 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3636 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3637 drawOther('dynlights', @renderDynLightsInternal
);
3639 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3641 renderAmbientQuad(hasAmbient
, ambColor
);
3645 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3648 if g_debug_HealthBar
then
3650 g_Monsters_DrawHealth();
3651 g_Player_DrawHealth();
3654 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3658 procedure DrawMapView(x
, y
, w
, h
: Integer);
3665 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3666 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3673 fixViewportForScale();
3674 renderMapInternal(-bx
, -by
, true);
3680 procedure DrawPlayer(p
: TPlayer
);
3682 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3686 if (p
= nil) or (p
.FDummy
) then
3689 g_Map_DrawBack(0, 0);
3694 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3695 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3701 camObj
:= p
.getCameraObj();
3702 camObj
.lerp(gLerpFactor
, fX
, fY
);
3703 px
:= fX
+ PLAYER_RECT_CX
;
3704 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3706 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3708 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3709 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3711 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3712 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3714 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3715 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3718 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3721 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3722 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3725 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3730 // scaled, ignore level bounds
3731 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3732 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3737 sWidth
:= gPlayerScreenSize
.X
;
3738 sHeight
:= gPlayerScreenSize
.Y
;
3739 fixViewportForScale();
3741 i
:= py
- (sY
+ sHeight
div 2);
3742 if (p
.IncCam
> 0) then
3744 // clamp to level bounds
3745 if (sY
- p
.IncCam
< 0) then
3746 p
.IncCam
:= nclamp(sY
, 0, 120);
3747 // clamp around player position
3749 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3751 else if (p
.IncCam
< 0) then
3753 // clamp to level bounds
3754 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3755 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3756 // clamp around player position
3758 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3761 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3763 if (not g_dbg_ignore_bounds
) then
3765 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3766 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3767 if (sX
< 0) then sX
:= 0;
3768 if (sY
< 0) then sY
:= 0;
3771 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3772 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3774 //r_smallmap_h: 0: left; 1: center; 2: right
3775 //r_smallmap_v: 0: top; 1: center; 2: bottom
3777 if (gMapInfo
.Width
= sWidth
) then
3781 else if (gMapInfo
.Width
< sWidth
) then
3783 case r_smallmap_h
of
3784 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3785 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3786 else sX
:= 0; // left
3790 if (gMapInfo
.Height
= sHeight
) then
3794 else if (gMapInfo
.Height
< sHeight
) then
3796 case r_smallmap_v
of
3797 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3798 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3799 else sY
:= 0; // top
3805 p
.viewPortW
:= sWidth
;
3806 p
.viewPortH
:= sHeight
;
3808 {$IFDEF ENABLE_HOLMES}
3809 if (p
= gPlayer1
) then
3811 g_Holmes_plrViewPos(sX
, sY
);
3812 g_Holmes_plrViewSize(sWidth
, sHeight
);
3816 renderMapInternal(-c
, -d
, true);
3818 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3819 case gPlayerIndicator
of
3821 p
.DrawIndicator(_RGB(255, 255, 255));
3824 for i
:= 0 to High(gPlayers
) do
3825 if gPlayers
[i
] <> nil then
3826 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3827 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3828 if gPlayerIndicatorStyle
= 1 then
3829 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3830 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3834 for a := 0 to High(gCollideMap) do
3835 for b := 0 to High(gCollideMap[a]) do
3838 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3840 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3844 1: e_DrawPoint(1, b, a, 200, 200, 200);
3845 2: e_DrawPoint(1, b, a, 64, 64, 255);
3846 3: e_DrawPoint(1, b, a, 255, 0, 255);
3856 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3857 if g_Debug_Player
then
3858 g_Player_DrawDebug(p
);
3862 procedure drawProfilers ();
3867 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3868 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3869 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3872 procedure g_Game_Draw();
3879 plView1
, plView2
: TPlayer
;
3882 if gExit
= EXIT_QUIT
then Exit
;
3884 Time
:= sys_GetTicks() {div 1000};
3885 FPSCounter
:= FPSCounter
+1;
3886 if Time
- FPSTime
>= 1000 then
3893 e_SetRendertarget(True);
3894 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3896 if gGameOn
or (gState
= STATE_FOLD
) then
3898 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3900 gSpectMode
:= SPECT_NONE
;
3901 if not gRevertPlayers
then
3903 plView1
:= gPlayer1
;
3904 plView2
:= gPlayer2
;
3908 plView1
:= gPlayer2
;
3909 plView2
:= gPlayer1
;
3913 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3915 gSpectMode
:= SPECT_NONE
;
3916 if gPlayer2
= nil then
3919 plView1
:= gPlayer2
;
3928 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3929 gSpectMode
:= SPECT_STATS
;
3931 if gSpectMode
= SPECT_PLAYERS
then
3932 if gPlayers
<> nil then
3934 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3935 if plView1
= nil then
3937 gSpectPID1
:= GetActivePlayerID_Next();
3938 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3940 if gSpectViewTwo
then
3942 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3943 if plView2
= nil then
3945 gSpectPID2
:= GetActivePlayerID_Next();
3946 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3951 if gSpectMode
= SPECT_MAPVIEW
then
3953 // Ðåæèì ïðîñìîòðà êàðòû
3955 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3956 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3957 gHearPoint1
.Active
:= True;
3958 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3959 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3960 gHearPoint2
.Active
:= False;
3964 Split
:= (plView1
<> nil) and (plView2
<> nil);
3966 // Òî÷êè ñëóõà èãðîêîâ
3967 if plView1
<> nil then
3969 gHearPoint1
.Active
:= True;
3970 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3971 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3973 gHearPoint1
.Active
:= False;
3974 if plView2
<> nil then
3976 gHearPoint2
.Active
:= True;
3977 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3978 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3980 gHearPoint2
.Active
:= False;
3982 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3983 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3986 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3987 if gScreenHeight
mod 2 = 0 then
3988 Dec(gPlayerScreenSize
.Y
);
3991 gPlayerScreenSize
.Y
:= gScreenHeight
;
3994 if gScreenHeight
mod 2 = 0 then
3995 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3997 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3999 DrawPlayer(plView1
);
4000 gPlayer1ScreenCoord
.X
:= sX
;
4001 gPlayer1ScreenCoord
.Y
:= sY
;
4005 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4007 DrawPlayer(plView2
);
4008 gPlayer2ScreenCoord
.X
:= sX
;
4009 gPlayer2ScreenCoord
.Y
:= sY
;
4012 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
4015 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
4018 {$IFDEF ENABLE_HOLMES}
4020 if (g_holmes_enabled
) then g_Holmes_Draw();
4023 if MessageText
<> '' then
4027 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
4029 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4030 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4032 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4033 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4036 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4039 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4041 // Draw spectator GUI
4044 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4047 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4049 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4051 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4053 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4054 if gSpectMode
= SPECT_STATS
then
4056 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4057 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4059 if gSpectMode
= SPECT_MAPVIEW
then
4061 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4062 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4063 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4064 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4065 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4067 if gSpectMode
= SPECT_PLAYERS
then
4069 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4070 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4071 if gSpectViewTwo
then
4073 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4074 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4075 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4076 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4080 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4081 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4087 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4089 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4090 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4092 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4093 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4094 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4099 if (gState
= STATE_MENU
) then
4101 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4102 // F3 at menu will show game loading dialog
4103 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4104 if (g_ActiveWindow
<> nil) then
4106 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4107 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4111 // F3 at titlepic will show game loading dialog
4112 if e_KeyPressed(IK_F3
) then
4114 g_Menu_Show_LoadMenu(true);
4115 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4120 if gState
= STATE_FOLD
then
4122 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4125 if gState
= STATE_INTERCUSTOM
then
4127 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4129 back
:= 'TEXTURE_endpic';
4130 if not g_Texture_Get(back
, ID
) then
4131 back
:= _lc
[I_TEXTURE_ENDPIC
];
4136 DrawMenuBackground(back
);
4140 if g_ActiveWindow
<> nil then
4142 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4143 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4147 if gState
= STATE_INTERSINGLE
then
4149 if EndingGameCounter
> 0 then
4151 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4157 DrawMenuBackground(back
);
4161 if g_ActiveWindow
<> nil then
4163 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4164 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4169 if gState
= STATE_ENDPIC
then
4172 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4173 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4175 if g_ActiveWindow
<> nil then
4177 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4178 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4182 if gState
= STATE_SLIST
then
4184 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4186 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4187 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4189 DrawMenuBackground('MENU_BACKGROUND');
4190 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4191 g_Serverlist_Draw(slCurrent
, slTable
);
4195 if g_ActiveWindow
<> nil then
4199 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4200 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4202 g_ActiveWindow
.Draw();
4209 if g_debug_Sounds
and gGameOn
then
4211 for w
:= 0 to High(e_SoundsArray
) do
4212 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4213 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4218 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4219 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4222 if gGameOn
and gShowTime
then
4223 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4225 if gGameOn
then drawProfilers();
4227 // TODO: draw this after the FBO and remap mouse click coordinates
4229 {$IFDEF ENABLE_HOLMES}
4233 // blit framebuffer to screen
4235 e_SetRendertarget(False);
4236 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4237 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4239 // draw the overlay stuff on top of it
4244 procedure g_Game_Quit();
4246 g_Game_StopAllSounds(True);
4249 g_PlayerModel_FreeData();
4250 g_Texture_DeleteAll();
4251 g_Frames_DeleteAll();
4253 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4256 if NetInitDone
then g_Net_Free
;
4258 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4259 if gMapToDelete
<> '' then
4260 g_Game_DeleteTestMap();
4266 procedure g_FatalError(Text: String);
4268 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4269 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4271 gExit
:= EXIT_SIMPLE
;
4272 if gGameOn
then EndGame
;
4275 procedure g_SimpleError(Text: String);
4277 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4278 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4281 procedure g_Game_SetupScreenSize();
4283 RES_FACTOR
= 4.0 / 3.0;
4289 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4290 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4291 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4292 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4294 gPlayerScreenSize
.Y
:= gScreenHeight
;
4296 // Ðàçìåð çàäíåãî ïëàíà:
4297 if BackID
<> DWORD(-1) then
4300 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4301 (gScreenHeight
*s
> gMapInfo
.Height
) then
4303 gBackSize
.X
:= gScreenWidth
;
4304 gBackSize
.Y
:= gScreenHeight
;
4308 e_GetTextureSize(BackID
, @bw
, @bh
);
4309 rf
:= Single(bw
) / Single(bh
);
4310 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4311 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4312 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4313 if (s
< 1.0) then s
:= 1.0;
4314 gBackSize
.X
:= Round(bw
*s
);
4315 gBackSize
.Y
:= Round(bh
*s
);
4320 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4322 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4325 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4327 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4328 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4331 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4334 if gPlayer1
= nil then
4336 if g_Game_IsClient
then
4338 if NetPlrUID1
> -1 then
4339 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4343 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4344 Team
:= gPlayer1Settings
.Team
;
4346 // Ñîçäàíèå ïåðâîãî èãðîêà:
4347 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4348 gPlayer1Settings
.Color
,
4350 if gPlayer1
= nil then
4351 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4354 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4355 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4356 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4357 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4358 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4359 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4360 if g_Game_IsServer
and g_Game_IsNet
then
4361 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4362 gPlayer1
.Respawn(False, True);
4363 g_Net_Slist_ServerPlayerComes();
4368 if gPlayer2
= nil then
4370 if g_Game_IsClient
then
4372 if NetPlrUID2
> -1 then
4373 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4377 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4378 Team
:= gPlayer2Settings
.Team
;
4380 // Ñîçäàíèå âòîðîãî èãðîêà:
4381 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4382 gPlayer2Settings
.Color
,
4384 if gPlayer2
= nil then
4385 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4388 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4389 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4390 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4391 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4392 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4393 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4394 if g_Game_IsServer
and g_Game_IsNet
then
4395 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4396 gPlayer2
.Respawn(False, True);
4397 g_Net_Slist_ServerPlayerComes();
4404 procedure g_Game_RemovePlayer();
4408 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4409 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4414 if g_Game_IsServer
then
4417 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4418 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4419 g_Player_Remove(Pl
.UID
);
4420 g_Net_Slist_ServerPlayerLeaves();
4424 gSpectLatchPID2
:= Pl
.UID
;
4432 if g_Game_IsServer
then
4435 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4436 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4437 g_Player_Remove(Pl
.UID
);
4438 g_Net_Slist_ServerPlayerLeaves();
4441 gSpectLatchPID1
:= Pl
.UID
;
4443 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4447 g_Net_Slist_ServerPlayerLeaves();
4450 procedure g_Game_Spectate();
4452 g_Game_RemovePlayer();
4453 if gPlayer1
<> nil then
4454 g_Game_RemovePlayer();
4457 procedure g_Game_SpectateCenterView();
4459 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4460 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4463 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4470 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4472 g_Game_ClearLoading();
4475 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4478 gGameSettings
.GameType
:= GT_SINGLE
;
4479 gGameSettings
.MaxLives
:= 0;
4480 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4481 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4482 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4483 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4484 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4485 gSwitchGameMode
:= GM_SINGLE
;
4487 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4488 gLMSRespawnTime
:= 0;
4489 gSpectLatchPID1
:= 0;
4490 gSpectLatchPID2
:= 0;
4492 g_Game_ExecuteEvent('ongamestart');
4494 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4495 g_Game_SetupScreenSize();
4497 // Ñîçäàíèå ïåðâîãî èãðîêà:
4498 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4499 gPlayer1Settings
.Color
,
4500 gPlayer1Settings
.Team
, False));
4501 if gPlayer1
= nil then
4503 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4507 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4508 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4509 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4510 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4511 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4514 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4517 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4518 gPlayer2Settings
.Color
,
4519 gPlayer2Settings
.Team
, False));
4520 if gPlayer2
= nil then
4522 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4526 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4527 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4528 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4529 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4530 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4534 // Çàãðóçêà è çàïóñê êàðòû:
4535 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4537 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4538 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4542 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4546 for i
:= nPl
+1 to nPlayers
do
4547 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4550 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4551 TimeLimit
, GoalLimit
: Word;
4553 Options
: LongWord; nPlayers
: Byte);
4559 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4561 g_Game_ClearLoading();
4564 gGameSettings
.GameType
:= GT_CUSTOM
;
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 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4580 gLMSRespawnTime
:= 0;
4581 gSpectLatchPID1
:= 0;
4582 gSpectLatchPID2
:= 0;
4584 g_Game_ExecuteEvent('ongamestart');
4586 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4587 g_Game_SetupScreenSize();
4589 // Ðåæèì íàáëþäàòåëÿ:
4590 if nPlayers
= 0 then
4597 if nPlayers
>= 1 then
4599 // Ñîçäàíèå ïåðâîãî èãðîêà:
4600 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4601 gPlayer1Settings
.Color
,
4602 gPlayer1Settings
.Team
, False));
4603 if gPlayer1
= nil then
4605 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4609 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4610 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4611 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4612 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4613 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4617 if nPlayers
>= 2 then
4619 // Ñîçäàíèå âòîðîãî èãðîêà:
4620 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4621 gPlayer2Settings
.Color
,
4622 gPlayer2Settings
.Team
, False));
4623 if gPlayer2
= nil then
4625 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4629 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4630 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4631 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4632 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4633 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4637 // Çàãðóçêà è çàïóñê êàðòû:
4638 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
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_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4655 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4659 for i
:= nPl
+1 to nPlayers
do
4660 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4663 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4664 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4665 Options
: LongWord; nPlayers
: Byte;
4666 IPAddr
: LongWord; Port
: Word);
4669 g_Net_Slist_ServerClosed();
4671 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4673 g_Game_ClearLoading();
4676 gGameSettings
.GameType
:= GT_SERVER
;
4677 gGameSettings
.GameMode
:= GameMode
;
4678 gSwitchGameMode
:= GameMode
;
4679 gGameSettings
.TimeLimit
:= TimeLimit
;
4680 gGameSettings
.GoalLimit
:= GoalLimit
;
4681 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4682 gGameSettings
.Options
:= Options
;
4684 gCoopTotalMonstersKilled
:= 0;
4685 gCoopTotalSecretsFound
:= 0;
4686 gCoopTotalMonsters
:= 0;
4687 gCoopTotalSecrets
:= 0;
4691 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4692 gLMSRespawnTime
:= 0;
4693 gSpectLatchPID1
:= 0;
4694 gSpectLatchPID2
:= 0;
4696 g_Game_ExecuteEvent('ongamestart');
4698 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4699 g_Game_SetupScreenSize();
4701 // Ðåæèì íàáëþäàòåëÿ:
4702 if nPlayers
= 0 then
4708 if nPlayers
>= 1 then
4710 // Ñîçäàíèå ïåðâîãî èãðîêà:
4711 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4712 gPlayer1Settings
.Color
,
4713 gPlayer1Settings
.Team
, False));
4714 if gPlayer1
= nil then
4716 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4720 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4721 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4722 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4723 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4724 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4727 if nPlayers
>= 2 then
4729 // Ñîçäàíèå âòîðîãî èãðîêà:
4730 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4731 gPlayer2Settings
.Color
,
4732 gPlayer2Settings
.Team
, False));
4733 if gPlayer2
= nil then
4735 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4739 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4740 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4741 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4742 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4743 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4746 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4747 if NetForwardPorts
then
4748 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4751 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4753 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4757 g_Net_Slist_Set(NetMasterList
);
4759 g_Net_Slist_ServerStarted();
4761 // Çàãðóçêà è çàïóñê êàðòû:
4762 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4764 g_Net_Slist_ServerClosed();
4765 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4769 // Íåò òî÷åê ïîÿâëåíèÿ:
4770 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4771 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4772 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4773 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4774 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4776 g_Net_Slist_ServerClosed();
4777 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4781 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4784 g_Net_Slist_ServerMapStarted();
4785 NetState
:= NET_STATE_GAME
;
4788 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4803 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4804 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4806 g_Game_ClearLoading();
4809 gGameSettings
.GameType
:= GT_CLIENT
;
4811 gCoopTotalMonstersKilled
:= 0;
4812 gCoopTotalSecretsFound
:= 0;
4813 gCoopTotalMonsters
:= 0;
4814 gCoopTotalSecrets
:= 0;
4818 g_Game_ExecuteEvent('ongamestart');
4820 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4821 g_Game_SetupScreenSize();
4823 NetState
:= NET_STATE_AUTH
;
4825 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4827 // create (or update) map/resource databases
4828 g_Res_CreateDatabases(true);
4830 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4831 gLMSRespawnTime
:= 0;
4832 gSpectLatchPID1
:= 0;
4833 gSpectLatchPID2
:= 0;
4836 if not g_Net_Connect(Addr
, Port
) then
4838 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4839 NetState
:= NET_STATE_NONE
;
4843 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4845 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4850 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4851 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4852 // thank you, enet. let's ignore failures altogether then.
4853 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4855 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4857 Ptr
:= NetEvent
.packet
^.data
;
4858 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4860 enet_packet_destroy(NetEvent
.packet
);
4864 InMsg
.ReadLongWord(); // skip size
4865 MID
:= InMsg
.ReadByte();
4867 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4869 NetMyID
:= InMsg
.ReadByte();
4870 NetPlrUID1
:= InMsg
.ReadWord();
4872 WadName
:= InMsg
.ReadString();
4873 Map
:= InMsg
.ReadString();
4875 gWADHash
:= InMsg
.ReadMD5();
4877 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4878 gSwitchGameMode
:= gGameSettings
.GameMode
;
4879 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4880 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4881 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4882 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4883 T
:= InMsg
.ReadLongWord();
4885 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4886 //if newResPath = '' then
4888 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4889 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4890 if newResPath
= '' then
4892 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4893 enet_packet_destroy(NetEvent
.packet
);
4894 NetState
:= NET_STATE_NONE
;
4897 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4899 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4902 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4903 gPlayer1Settings
.Color
,
4904 gPlayer1Settings
.Team
, False));
4906 if gPlayer1
= nil then
4908 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4910 enet_packet_destroy(NetEvent
.packet
);
4911 NetState
:= NET_STATE_NONE
;
4915 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4916 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4917 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4918 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4919 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4920 gPlayer1
.UID
:= NetPlrUID1
;
4921 gPlayer1
.Reset(True);
4923 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4925 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4927 enet_packet_destroy(NetEvent
.packet
);
4928 NetState
:= NET_STATE_NONE
;
4936 enet_packet_destroy(NetEvent
.packet
);
4940 enet_packet_destroy(NetEvent
.packet
);
4944 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4947 if (NetEvent
.data
<= NET_DISC_MAX
) then
4948 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4949 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4956 ProcessLoading(True);
4957 if g_Net_UserRequestExit() then
4966 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4967 NetState
:= NET_STATE_NONE
;
4972 NetState
:= NET_STATE_GAME
;
4973 MC_SEND_FullStateRequest
;
4974 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4978 lastAsMegaWad
: Boolean = false;
4980 procedure g_Game_ChangeMap(const MapPath
: String);
4984 g_Game_ClearLoading();
4986 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4987 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4988 if gExitByTrigger
then
4991 gExitByTrigger
:= False;
4993 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4994 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4997 procedure g_Game_Restart();
5001 if g_Game_IsClient
then
5003 map
:= g_ExtractFileName(gMapInfo
.Map
);
5004 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
5008 g_Game_ClearLoading();
5009 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
5012 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
5014 NewWAD
, ResName
: String;
5018 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
5019 g_Player_RemoveAllCorpses();
5021 if (not g_Game_IsClient
) and
5022 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
5023 (gGameSettings
.GameMode
<> GM_SINGLE
) then
5025 if gSwitchGameMode
= GM_CTF
then
5026 gGameSettings
.MaxLives
:= 0;
5027 gGameSettings
.GameMode
:= gSwitchGameMode
;
5030 gSwitchGameMode
:= gGameSettings
.GameMode
;
5032 g_Player_ResetTeams();
5034 lastAsMegaWad
:= asMegawad
;
5035 if isWadPath(Map
) then
5037 NewWAD
:= g_ExtractWadName(Map
);
5038 ResName
:= g_ExtractFileName(Map
);
5039 if g_Game_IsServer
then
5041 nws
:= findDiskWad(NewWAD
);
5042 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5045 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5046 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5050 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5051 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5053 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5054 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5056 if (length(nws
) = 0) then
5058 ResName
:= ''; // failed
5063 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5064 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5065 g_Game_LoadWAD(NewWAD
);
5070 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5071 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5076 NewWAD
:= gGameSettings
.WAD
;
5082 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5084 if (ResName
<> '') and (NewWAD
<> '') then
5086 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5087 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5091 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5093 gState
:= STATE_NONE
;
5094 g_ActiveWindow
:= nil;
5100 if gGameSettings
.GameMode
= GM_CTF
then
5102 g_Map_ResetFlag(FLAG_RED
);
5103 g_Map_ResetFlag(FLAG_BLUE
);
5104 // CTF, à ôëàãîâ íåò:
5105 if not g_Map_HaveFlagPoints() then
5106 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5111 gState
:= STATE_MENU
;
5116 gPauseMain
:= false;
5117 gPauseHolmes
:= false;
5118 NetTimeToUpdate
:= 1;
5119 NetTimeToReliable
:= 0;
5120 NetTimeToMaster
:= NetMasterRate
;
5121 gSpectLatchPID1
:= 0;
5122 gSpectLatchPID2
:= 0;
5123 gMissionFailed
:= False;
5126 gCoopMonstersKilled
:= 0;
5127 gCoopSecretsFound
:= 0;
5129 gVoteInProgress
:= False;
5130 gVotePassed
:= False;
5136 if not gGameOn
then Exit
;
5138 g_Game_SpectateCenterView();
5140 if g_Game_IsServer
then
5142 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5144 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5145 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5146 gLMSSoftSpawn
:= True;
5147 if g_Game_IsNet
then
5148 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5152 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5153 gLMSRespawnTime
:= 0;
5157 if NetMode
= NET_SERVER
then
5159 // reset full state flags
5160 if NetClients
<> nil then
5161 for I
:= 0 to High(NetClients
) do
5162 NetClients
[I
].FullUpdateSent
:= False;
5164 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5167 g_Net_Slist_ServerMapStarted();
5169 if NetClients
<> nil then
5170 for I
:= 0 to High(NetClients
) do
5171 if NetClients
[I
].Used
then
5173 NetClients
[I
].Voted
:= False;
5174 if NetClients
[I
].RequestedFullUpdate
then
5176 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5177 NetClients
[I
].RequestedFullUpdate
:= False;
5181 g_Net_UnbanNonPermHosts();
5186 gCoopTotalMonstersKilled
:= 0;
5187 gCoopTotalSecretsFound
:= 0;
5188 gCoopTotalMonsters
:= 0;
5189 gCoopTotalSecrets
:= 0;
5193 g_Game_ExecuteEvent('onmapstart');
5196 procedure SetFirstLevel
;
5200 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5201 if MapList
= nil then
5204 SortSArray(MapList
);
5205 gNextMap
:= MapList
[Low(MapList
)];
5210 procedure g_Game_ExitLevel(const Map
: AnsiString);
5214 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5215 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5216 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5217 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5219 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5220 if gGameSettings
.GameType
= GT_SINGLE
then
5221 gExit
:= EXIT_ENDLEVELSINGLE
5222 else // Âûøëè â âûõîä â Ñâîåé èãðå
5224 gExit
:= EXIT_ENDLEVELCUSTOM
;
5225 if gGameSettings
.GameMode
= GM_COOP
then
5226 g_Player_RememberAll
;
5228 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5231 if gGameSettings
.GameMode
= GM_COOP
then
5234 gStatsPressed
:= True;
5235 gNextMap
:= 'MAP01';
5237 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5240 if g_Game_IsNet
then
5242 MH_SEND_GameStats();
5243 MH_SEND_CoopStats();
5249 procedure g_Game_RestartLevel();
5253 if gGameSettings
.GameMode
= GM_SINGLE
then
5258 gExit
:= EXIT_ENDLEVELCUSTOM
;
5259 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5263 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5265 gWAD
{, xwad}: String;
5268 if not g_Game_IsClient
then Exit
;
5269 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5271 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5276 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5280 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5283 g_Game_LoadWAD(NewWAD
);
5287 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5288 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5291 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5292 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5296 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5300 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5301 g_Game_LoadWAD(NewWAD);
5305 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5307 i
, n
, nb
, nr
: Integer;
5309 if not g_Game_IsServer
then Exit
;
5310 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5311 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5312 gLMSRespawnTime
:= 0;
5315 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5317 gMissionFailed
:= True;
5318 g_Game_RestartLevel
;
5322 n
:= 0; nb
:= 0; nr
:= 0;
5323 for i
:= Low(gPlayers
) to High(gPlayers
) do
5324 if (gPlayers
[i
] <> nil) and
5325 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5326 (gPlayers
[i
] is TBot
)) then
5329 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5330 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5333 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5335 // wait a second until the fuckers finally decide to join
5336 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5337 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5338 gLMSSoftSpawn
:= NoMapRestart
;
5339 if g_Game_IsNet
then
5340 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5344 g_Player_RemoveAllCorpses
;
5345 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5346 if g_Game_IsNet
then
5347 MH_SEND_GameEvent(NET_EV_LMS_START
);
5349 for i
:= Low(gPlayers
) to High(gPlayers
) do
5351 if gPlayers
[i
] = nil then continue
;
5352 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5353 // don't touch normal spectators
5354 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5356 gPlayers
[i
].FNoRespawn
:= True;
5357 gPlayers
[i
].Lives
:= 0;
5358 if g_Game_IsNet
then
5359 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5362 gPlayers
[i
].FNoRespawn
:= False;
5363 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5364 gPlayers
[i
].Respawn(False, True);
5365 if gGameSettings
.GameMode
= GM_COOP
then
5367 gPlayers
[i
].Frags
:= 0;
5368 gPlayers
[i
].RecallState
;
5370 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5371 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5372 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5373 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5376 g_Items_RestartRound();
5378 gLMSSoftSpawn
:= False;
5381 function g_Game_GetFirstMap(WAD
: String): String;
5385 MapList
:= g_Map_GetMapsList(WAD
);
5386 if MapList
= nil then
5389 SortSArray(MapList
);
5390 Result
:= MapList
[Low(MapList
)];
5392 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5398 function g_Game_GetNextMap(): String;
5405 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5406 if MapList
= nil then
5409 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5411 SortSArray(MapList
);
5413 for I
:= Low(MapList
) to High(MapList
) do
5414 if Map
= MapList
[I
] then
5420 if MapIndex
<> -255 then
5422 if MapIndex
= High(MapList
) then
5423 Result
:= MapList
[Low(MapList
)]
5425 Result
:= MapList
[MapIndex
+ 1];
5427 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5433 procedure g_Game_NextLevel();
5435 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5436 gExit
:= EXIT_ENDLEVELCUSTOM
5439 gExit
:= EXIT_ENDLEVELSINGLE
;
5443 if gNextMap
<> '' then Exit
;
5444 gNextMap
:= g_Game_GetNextMap();
5447 function g_Game_IsTestMap(): Boolean;
5449 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5452 procedure g_Game_DeleteTestMap();
5455 //MapName: AnsiString;
5463 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5464 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5465 if (a
= 0) then exit
;
5467 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5468 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5469 Delete(gMapToDelete
, 1, a
+5);
5470 gMapToDelete
:= UpperCase(gMapToDelete
);
5472 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5475 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5476 if MapName <> TEST_MAP_NAME then
5479 if not gTempDelete then
5481 time := g_GetFileTime(WadName);
5482 WAD := TWADFile.Create();
5485 if not WAD.ReadFile(WadName) then
5486 begin // Íåò òàêîãî WAD-ôàéëà
5491 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5493 MapList := WAD.GetResourcesList('');
5495 if MapList <> nil then
5496 for a := 0 to High(MapList) do
5497 if MapList[a] = MapName then
5499 // Óäàëÿåì è ñîõðàíÿåì:
5500 WAD.RemoveResource('', MapName);
5501 WAD.SaveTo(WadName);
5506 g_SetFileTime(WadName, time);
5509 if gTempDelete
then DeleteFile(WadName
);
5512 procedure GameCVars(P
: SSArray
);
5515 stat
: TPlayerStatArray
;
5518 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5522 if Length(P
) > 1 then
5527 gsGameFlags
:= gsGameFlags
or Flag
5529 gsGameFlags
:= gsGameFlags
and (not Flag
);
5531 if g_Game_IsServer
then
5534 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5536 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5537 if g_Game_IsNet
then MH_SEND_GameSettings
;
5541 if LongBool(gsGameFlags
and Flag
) then
5542 g_Console_Add(_lc
[OnMsg
])
5544 g_Console_Add(_lc
[OffMsg
]);
5546 if OnMapChange
and g_Game_IsServer
then
5547 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5552 cmd
:= LowerCase(P
[0]);
5554 if cmd
= 'g_gamemode' then
5556 if (Length(P
) > 1) then
5558 a
:= g_Game_TextToMode(P
[1]);
5559 if a
= GM_SINGLE
then a
:= GM_COOP
;
5560 gsGameMode
:= g_Game_ModeToText(a
);
5561 if g_Game_IsServer
then
5563 gSwitchGameMode
:= a
;
5564 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5565 (gState
= STATE_INTERSINGLE
) then
5566 gSwitchGameMode
:= GM_SINGLE
;
5568 gGameSettings
.GameMode
:= gSwitchGameMode
;
5572 if gSwitchGameMode
= gGameSettings
.GameMode
then
5573 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5574 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5576 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5577 [g_Game_ModeToText(gGameSettings
.GameMode
),
5578 g_Game_ModeToText(gSwitchGameMode
)]));
5580 else if cmd
= 'g_friendlyfire' then
5582 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5584 else if cmd
= 'g_friendly_absorb_damage' then
5586 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5588 else if cmd
= 'g_friendly_hit_trace' then
5590 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5592 else if cmd
= 'g_friendly_hit_projectile' then
5594 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5596 else if cmd
= 'g_weaponstay' then
5598 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5600 else if cmd
= 'g_allow_exit' then
5602 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5604 else if cmd
= 'g_allow_monsters' then
5606 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5608 else if cmd
= 'g_allow_dropflag' then
5610 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5612 else if cmd
= 'g_throw_flag' then
5614 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5616 else if cmd
= 'g_bot_vsplayers' then
5618 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5620 else if cmd
= 'g_bot_vsmonsters' then
5622 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5624 else if cmd
= 'g_dm_keys' then
5626 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5628 else if cmd
= 'g_gameflags' then
5630 if Length(P
) > 1 then
5632 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5633 if g_Game_IsServer
then
5635 gGameSettings
.Options
:= gsGameFlags
;
5636 if g_Game_IsNet
then MH_SEND_GameSettings
;
5640 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5642 else if cmd
= 'g_warmup_time' then
5644 if Length(P
) > 1 then
5646 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5647 if g_Game_IsServer
then
5649 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5650 // extend warmup if it's already going
5651 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5653 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5654 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5656 if g_Game_IsNet
then MH_SEND_GameSettings
;
5660 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5661 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5663 else if cmd
= 'g_spawn_invul' then
5665 if Length(P
) > 1 then
5667 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5668 if g_Game_IsServer
then
5670 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5671 if g_Game_IsNet
then MH_SEND_GameSettings
;
5675 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5677 else if cmd
= 'g_item_respawn_time' then
5679 if Length(P
) > 1 then
5681 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5682 if g_Game_IsServer
then
5684 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5685 if g_Game_IsNet
then MH_SEND_GameSettings
;
5689 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5690 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5692 else if cmd
= 'sv_intertime' then
5694 if (Length(P
) > 1) then
5695 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5697 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5699 else if cmd
= 'g_max_particles' then
5701 if Length(p
) = 2 then
5703 a
:= Max(0, StrToIntDef(p
[1], 0));
5706 else if Length(p
) = 1 then
5708 e_LogWritefln('%s', [g_GFX_GetMax()])
5712 e_LogWritefln('usage: %s <n>', [cmd
])
5715 else if cmd
= 'g_max_shells' then
5717 if Length(p
) = 2 then
5719 a
:= Max(0, StrToIntDef(p
[1], 0));
5722 else if Length(p
) = 1 then
5724 e_LogWritefln('%s', [g_Shells_GetMax()])
5728 e_LogWritefln('usage: %s <n>', [cmd
])
5731 else if cmd
= 'g_max_gibs' then
5733 if Length(p
) = 2 then
5735 a
:= Max(0, StrToIntDef(p
[1], 0));
5738 else if Length(p
) = 1 then
5740 e_LogWritefln('%s', [g_Gibs_GetMax()])
5744 e_LogWritefln('usage: %s <n>', [cmd
])
5747 else if cmd
= 'g_max_corpses' then
5749 if Length(p
) = 2 then
5751 a
:= Max(0, StrToIntDef(p
[1], 0));
5754 else if Length(p
) = 1 then
5756 e_LogWritefln('%s', [g_Corpses_GetMax()])
5760 e_LogWritefln('usage: %s <n>', [cmd
])
5763 else if cmd
= 'g_scorelimit' then
5765 if Length(P
) > 1 then
5767 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5769 if g_Game_IsServer
then
5772 if gGameSettings
.GameMode
= GM_DM
then
5774 stat
:= g_Player_GetStats();
5776 for a
:= 0 to High(stat
) do
5777 if stat
[a
].Frags
> b
then
5781 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5783 // if someone has a higher score, set it to that instead
5784 gsGoalLimit
:= max(gsGoalLimit
, b
);
5785 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5787 if g_Game_IsNet
then MH_SEND_GameSettings
;
5791 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5793 else if cmd
= 'g_timelimit' then
5795 if Length(P
) > 1 then
5797 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5798 if g_Game_IsServer
then
5800 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5801 if g_Game_IsNet
then MH_SEND_GameSettings
;
5804 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5805 [gsTimeLimit
div 3600,
5806 (gsTimeLimit
div 60) mod 60,
5807 gsTimeLimit
mod 60]));
5809 else if cmd
= 'g_max_bots' then
5811 if Length(P
) > 1 then
5812 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
5813 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
5815 else if cmd
= 'g_maxlives' then
5817 if Length(P
) > 1 then
5819 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5820 if g_Game_IsServer
then
5822 gGameSettings
.MaxLives
:= gsMaxLives
;
5823 if g_Game_IsNet
then MH_SEND_GameSettings
;
5827 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5831 procedure PlayerSettingsCVars(P
: SSArray
);
5836 function ParseTeam(s
: string): Byte;
5840 'red', '1': result
:= TEAM_RED
;
5841 'blue', '2': result
:= TEAM_BLUE
;
5842 else result
:= TEAM_NONE
;
5846 cmd
:= LowerCase(P
[0]);
5850 if (Length(P
) > 1) then
5852 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5853 if g_Game_IsClient
then
5854 MC_SEND_PlayerSettings
5855 else if gGameOn
and (gPlayer1
<> nil) then
5857 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5858 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5864 if (Length(P
) > 1) then
5866 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5867 if g_Game_IsClient
then
5868 MC_SEND_PlayerSettings
5869 else if gGameOn
and (gPlayer2
<> nil) then
5871 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5872 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5878 if Length(P
) > 3 then
5880 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5881 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5882 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5883 if g_Game_IsClient
then
5884 MC_SEND_PlayerSettings
5885 else if gGameOn
and (gPlayer1
<> nil) then
5887 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5888 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5894 if Length(P
) > 3 then
5896 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5897 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5898 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5899 if g_Game_IsClient
then
5900 MC_SEND_PlayerSettings
5901 else if gGameOn
and (gPlayer2
<> nil) then
5903 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5904 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5910 if (Length(P
) > 1) then
5912 gPlayer1Settings
.Model
:= P
[1];
5913 if g_Game_IsClient
then
5914 MC_SEND_PlayerSettings
5915 else if gGameOn
and (gPlayer1
<> nil) then
5917 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5918 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5919 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5925 if (Length(P
) > 1) then
5927 gPlayer2Settings
.Model
:= P
[1];
5928 if g_Game_IsClient
then
5929 MC_SEND_PlayerSettings
5930 else if gGameOn
and (gPlayer2
<> nil) then
5932 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5933 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5934 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5940 // TODO: switch teams if in game or store this separately
5941 if (Length(P
) > 1) then
5943 team
:= ParseTeam(P
[1]);
5944 if team
= TEAM_NONE
then
5945 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5946 else if not gGameOn
and not g_Game_IsNet
then
5947 gPlayer1Settings
.Team
:= team
5949 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5954 // TODO: switch teams if in game or store this separately
5955 if (Length(P
) > 1) then
5957 team
:= ParseTeam(P
[1]);
5958 if team
= TEAM_NONE
then
5959 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5960 else if not gGameOn
and not g_Game_IsNet
then
5961 gPlayer2Settings
.Team
:= team
5963 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5968 if (Length(P
) = 2) then
5969 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
5973 if (Length(P
) = 2) then
5974 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
5978 if (Length(P
) = 2) then
5979 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5983 if (Length(P
) = 2) then
5984 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5988 if (Length(P
) = 2) then
5989 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5993 if (Length(P
) = 2) then
5994 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5996 'p1_priority_kastet':
5998 if (Length(P
) = 2) then
5999 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6001 'p2_priority_kastet':
6003 if (Length(P
) = 2) then
6004 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6008 if (Length(P
) = 2) then
6009 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6013 if (Length(P
) = 2) then
6014 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6016 'p1_priority_pistol':
6018 if (Length(P
) = 2) then
6019 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6021 'p2_priority_pistol':
6023 if (Length(P
) = 2) then
6024 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6026 'p1_priority_shotgun1':
6028 if (Length(P
) = 2) then
6029 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6031 'p2_priority_shotgun1':
6033 if (Length(P
) = 2) then
6034 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6036 'p1_priority_shotgun2':
6038 if (Length(P
) = 2) then
6039 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6041 'p2_priority_shotgun2':
6043 if (Length(P
) = 2) then
6044 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6046 'p1_priority_chaingun':
6048 if (Length(P
) = 2) then
6049 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6051 'p2_priority_chaingun':
6053 if (Length(P
) = 2) then
6054 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6056 'p1_priority_rocketlauncher':
6058 if (Length(P
) = 2) then
6059 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6061 'p2_priority_rocketlauncher':
6063 if (Length(P
) = 2) then
6064 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6066 'p1_priority_plasma':
6068 if (Length(P
) = 2) then
6069 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6071 'p2_priority_plasma':
6073 if (Length(P
) = 2) then
6074 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6078 if (Length(P
) = 2) then
6079 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6083 if (Length(P
) = 2) then
6084 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6086 'p1_priority_super':
6088 if (Length(P
) = 2) then
6089 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6091 'p2_priority_super':
6093 if (Length(P
) = 2) then
6094 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6096 'p1_priority_flamethrower':
6098 if (Length(P
) = 2) then
6099 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6101 'p2_priority_flamethrower':
6103 if (Length(P
) = 2) then
6104 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6106 'p1_priority_berserk':
6108 if (Length(P
) = 2) then
6109 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6111 'p2_priority_berserk':
6113 if (Length(P
) = 2) then
6114 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6119 procedure PrintHeapStats();
6123 hs
:= GetFPCHeapStatus();
6124 e_LogWriteLn ('v===== heap status =====v');
6125 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
6126 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
6127 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
6128 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
6129 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
6130 e_LogWriteLn ('^=======================^');
6133 procedure DebugCommands(P
: SSArray
);
6140 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6141 if {gDebugMode}conIsCheatsEnabled
then
6143 cmd
:= LowerCase(P
[0]);
6144 if cmd
= 'd_window' then
6146 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6147 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6149 else if cmd
= 'd_sounds' then
6151 if (Length(P
) > 1) and
6152 ((P
[1] = '1') or (P
[1] = '0')) then
6153 g_Debug_Sounds
:= (P
[1][1] = '1');
6155 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
6157 else if cmd
= 'd_frames' then
6159 if (Length(P
) > 1) and
6160 ((P
[1] = '1') or (P
[1] = '0')) then
6161 g_Debug_Frames
:= (P
[1][1] = '1');
6163 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
6165 else if cmd
= 'd_winmsg' then
6167 if (Length(P
) > 1) and
6168 ((P
[1] = '1') or (P
[1] = '0')) then
6169 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6171 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6173 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6175 if (Length(P
) > 1) and
6176 ((P
[1] = '1') or (P
[1] = '0')) then
6177 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6179 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6181 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6183 if Length(P
) > 1 then
6185 '0': g_debug_BotAIOff
:= 0;
6186 '1': g_debug_BotAIOff
:= 1;
6187 '2': g_debug_BotAIOff
:= 2;
6188 '3': g_debug_BotAIOff
:= 3;
6191 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6193 else if cmd
= 'd_monster' then
6195 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6196 if Length(P
) < 2 then
6198 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6199 g_Console_Add('ID | Name');
6200 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6201 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6202 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6205 a
:= StrToIntDef(P
[1], 0);
6206 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6207 a
:= g_Mons_TypeIdByName(P
[1]);
6209 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6210 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6213 with gPlayer1
.Obj
do
6215 mon
:= g_Monsters_Create(a
,
6216 X
+ Rect
.X
+ (Rect
.Width
div 2),
6217 Y
+ Rect
.Y
+ Rect
.Height
,
6218 gPlayer1
.Direction
, True);
6220 if (Length(P
) > 2) and (mon
<> nil) then
6222 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6223 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6224 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6225 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6226 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6227 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6228 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6229 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6230 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6235 else if (cmd
= 'd_health') then
6237 if (Length(P
) > 1) and
6238 ((P
[1] = '1') or (P
[1] = '0')) then
6239 g_debug_HealthBar
:= (P
[1][1] = '1');
6241 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6243 else if (cmd
= 'd_player') then
6245 if (Length(P
) > 1) and
6246 ((P
[1] = '1') or (P
[1] = '0')) then
6247 g_debug_Player
:= (P
[1][1] = '1');
6249 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6251 else if (cmd
= 'd_mem') then
6257 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6261 procedure GameCheats(P
: SSArray
);
6267 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6269 g_Console_Add('not available');
6275 g_Console_Add('where is the player?!');
6278 cmd
:= LowerCase(P
[0]);
6282 plr
.GodMode
:= not plr
.GodMode
;
6283 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6286 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6287 if cmd
= 'give' then
6289 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6290 for f
:= 1 to High(P
) do
6292 cmd
:= LowerCase(P
[f
]);
6293 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6294 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6295 if cmd
= 'exit' then
6297 if gTriggers
<> nil then
6299 for a
:= 0 to High(gTriggers
) do
6301 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6303 g_Console_Add('player left the map');
6304 gExitByTrigger
:= True;
6305 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6306 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6314 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6315 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6316 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6317 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6318 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6320 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6321 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6323 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6324 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;
6326 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6327 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6329 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6330 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6332 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6333 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6335 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6336 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6337 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6339 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6340 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6341 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6342 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;
6343 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6344 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6346 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;
6347 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;
6348 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;
6349 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;
6350 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;
6351 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;
6353 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6354 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;
6356 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;
6357 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;
6359 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6361 if cmd
= 'ammo' then
6363 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6364 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6365 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6366 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6367 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6368 g_Console_Add('player got some ammo');
6372 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6373 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6375 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6376 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6378 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6379 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6381 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6382 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6384 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6386 if cmd
= 'weapons' then
6388 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6389 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6390 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6391 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6392 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6393 plr
.GiveItem(ITEM_WEAPON_BFG
);
6394 g_Console_Add('player got weapons');
6398 if cmd
= 'keys' then
6400 plr
.GiveItem(ITEM_KEY_RED
);
6401 plr
.GiveItem(ITEM_KEY_GREEN
);
6402 plr
.GiveItem(ITEM_KEY_BLUE
);
6403 g_Console_Add('player got all keys');
6407 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6412 if cmd
= 'open' then
6414 g_Console_Add('player activated sesame');
6415 g_Triggers_OpenAll();
6422 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6426 if cmd
= 'noclip' then
6429 g_Console_Add('wall hardeness adjusted');
6433 if cmd
= 'notarget' then
6435 plr
.NoTarget
:= not plr
.NoTarget
;
6436 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6440 if cmd
= 'noreload' then
6442 plr
.NoReload
:= not plr
.NoReload
;
6443 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6447 if cmd
= 'speedy' then
6449 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6450 g_Console_Add('speed adjusted');
6454 if cmd
= 'jumpy' then
6456 VEL_JUMP
:= 30-VEL_JUMP
;
6457 g_Console_Add('jump height adjusted');
6461 if cmd
= 'automap' then
6463 gShowMap
:= not gShowMap
;
6464 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6468 if cmd
= 'aimline' then
6470 gAimLine
:= not gAimLine
;
6471 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6476 procedure GameCommands(P
: SSArray
);
6482 pl
: pTNetClient
= nil;
6490 cmd
:= LowerCase(P
[0]);
6492 if cmd
= 'pause' then
6494 if (g_ActiveWindow
= nil) then
6495 g_Game_Pause(not gPauseMain
);
6497 else if cmd
= 'endgame' then
6498 gExit
:= EXIT_SIMPLE
6499 else if cmd
= 'restart' then
6501 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6503 if g_Game_IsClient
then
6505 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6510 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6512 else if cmd
= 'kick' then
6514 if g_Game_IsServer
then
6516 if Length(P
) < 2 then
6518 g_Console_Add('kick <name>');
6523 g_Console_Add('kick <name>');
6527 if g_Game_IsNet
then
6528 pl
:= g_Net_Client_ByName(P
[1]);
6531 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6532 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6533 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6534 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6535 g_Net_Slist_ServerPlayerLeaves();
6536 end else if gPlayers
<> nil then
6537 for a
:= Low(gPlayers
) to High(gPlayers
) do
6538 if gPlayers
[a
] <> nil then
6539 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6541 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6542 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6544 gPlayers
[a
].Lives
:= 0;
6545 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6546 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6547 g_Player_Remove(gPlayers
[a
].UID
);
6548 g_Net_Slist_ServerPlayerLeaves();
6549 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6553 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6555 else if cmd
= 'kick_id' then
6557 if g_Game_IsServer
and g_Game_IsNet
then
6559 if Length(P
) < 2 then
6561 g_Console_Add('kick_id <client ID>');
6566 g_Console_Add('kick_id <client ID>');
6570 a
:= StrToIntDef(P
[1], 0);
6571 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6573 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6575 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6576 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6577 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6578 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6579 g_Net_Slist_ServerPlayerLeaves();
6583 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6585 else if cmd
= 'kick_pid' then
6587 if g_Game_IsServer
and g_Game_IsNet
then
6589 if Length(P
) < 2 then
6591 g_Console_Add('kick_pid <player ID>');
6596 g_Console_Add('kick_pid <player ID>');
6600 a
:= StrToIntDef(P
[1], 0);
6601 pl
:= g_Net_Client_ByPlayer(a
);
6602 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6604 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6605 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6606 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6607 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6608 g_Net_Slist_ServerPlayerLeaves();
6611 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6613 else if cmd
= 'ban' then
6615 if g_Game_IsServer
and g_Game_IsNet
then
6617 if Length(P
) < 2 then
6619 g_Console_Add('ban <name>');
6624 g_Console_Add('ban <name>');
6628 pl
:= g_Net_Client_ByName(P
[1]);
6631 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6632 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6633 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6634 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6635 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6636 g_Net_Slist_ServerPlayerLeaves();
6638 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6640 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6642 else if cmd
= 'ban_id' then
6644 if g_Game_IsServer
and g_Game_IsNet
then
6646 if Length(P
) < 2 then
6648 g_Console_Add('ban_id <client ID>');
6653 g_Console_Add('ban_id <client ID>');
6657 a
:= StrToIntDef(P
[1], 0);
6658 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6659 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6661 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6662 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6663 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6664 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6665 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6666 g_Net_Slist_ServerPlayerLeaves();
6669 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6671 else if cmd
= 'ban_pid' then
6673 if g_Game_IsServer
and g_Game_IsNet
then
6675 if Length(P
) < 2 then
6677 g_Console_Add('ban_pid <player ID>');
6682 g_Console_Add('ban_pid <player ID>');
6686 a
:= StrToIntDef(P
[1], 0);
6687 pl
:= g_Net_Client_ByPlayer(a
);
6688 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6690 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6691 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6692 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6693 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6694 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6695 g_Net_Slist_ServerPlayerLeaves();
6698 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6700 else if cmd
= 'permban' then
6702 if g_Game_IsServer
and g_Game_IsNet
then
6704 if Length(P
) < 2 then
6706 g_Console_Add('permban <name>');
6711 g_Console_Add('permban <name>');
6715 pl
:= g_Net_Client_ByName(P
[1]);
6718 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6719 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6720 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6721 g_Net_SaveBanList();
6722 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6723 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6724 g_Net_Slist_ServerPlayerLeaves();
6726 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6728 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6730 else if cmd
= 'permban_id' then
6732 if g_Game_IsServer
and g_Game_IsNet
then
6734 if Length(P
) < 2 then
6736 g_Console_Add('permban_id <client ID>');
6741 g_Console_Add('permban_id <client ID>');
6745 a
:= StrToIntDef(P
[1], 0);
6746 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6747 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6749 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6750 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6751 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6752 g_Net_SaveBanList();
6753 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6754 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6755 g_Net_Slist_ServerPlayerLeaves();
6758 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6760 else if cmd
= 'permban_pid' then
6762 if g_Game_IsServer
and g_Game_IsNet
then
6764 if Length(P
) < 2 then
6766 g_Console_Add('permban_pid <player ID>');
6771 g_Console_Add('permban_pid <player ID>');
6775 a
:= StrToIntDef(P
[1], 0);
6776 pl
:= g_Net_Client_ByPlayer(a
);
6777 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6779 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6780 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6781 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6782 g_Net_SaveBanList();
6783 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6784 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6785 g_Net_Slist_ServerPlayerLeaves();
6788 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6790 else if cmd
= 'permban_ip' then
6792 if g_Game_IsServer
and g_Game_IsNet
then
6794 if Length(P
) < 2 then
6796 g_Console_Add('permban_ip <IP address>');
6801 g_Console_Add('permban_ip <IP address>');
6805 g_Net_BanHost(P
[1]);
6806 g_Net_SaveBanList();
6807 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6809 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6811 else if cmd
= 'unban' then
6813 if g_Game_IsServer
and g_Game_IsNet
then
6815 if Length(P
) < 2 then
6817 g_Console_Add('unban <IP Address>');
6822 g_Console_Add('unban <IP Address>');
6826 if g_Net_UnbanHost(P
[1]) then
6828 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6829 g_Net_SaveBanList();
6831 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6833 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6835 else if cmd
= 'clientlist' then
6837 if g_Game_IsServer
and g_Game_IsNet
then
6840 if NetClients
<> nil then
6841 for a
:= Low(NetClients
) to High(NetClients
) do
6842 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6844 plr
:= g_Player_Get(NetClients
[a
].Player
);
6845 if plr
= nil then continue
;
6847 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6848 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6851 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6853 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6855 else if cmd
= 'connect' then
6857 if (NetMode
= NET_NONE
) then
6859 if Length(P
) < 2 then
6861 g_Console_Add('connect <IP> [port] [password]');
6866 g_Console_Add('connect <IP> [port] [password]');
6870 if Length(P
) > 2 then
6871 prt
:= StrToIntDef(P
[2], 25666)
6875 if Length(P
) > 3 then
6880 g_Game_StartClient(P
[1], prt
, pw
);
6883 else if cmd
= 'disconnect' then
6885 if (NetMode
= NET_CLIENT
) then
6888 else if cmd
= 'reconnect' then
6890 if (NetMode
= NET_SERVER
) then
6893 if (NetMode
= NET_CLIENT
) then
6896 gExit
:= EXIT_SIMPLE
;
6900 //TODO: Use last successful password to reconnect, instead of ''
6901 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6903 else if (cmd
= 'addbot') or
6904 (cmd
= 'bot_add') then
6906 if Length(P
) > 2 then
6907 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6908 else if Length(P
) > 1 then
6909 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6911 g_Bot_Add(TEAM_NONE
, 2);
6913 else if cmd
= 'bot_addlist' then
6915 if Length(P
) > 1 then
6917 if Length(P
) = 2 then
6918 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6919 else if Length(P
) = 3 then
6920 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6922 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6925 else if cmd
= 'bot_removeall' then
6927 else if cmd
= 'chat' then
6929 if g_Game_IsNet
then
6931 if Length(P
) > 1 then
6933 for a
:= 1 to High(P
) do
6934 chstr
:= chstr
+ P
[a
] + ' ';
6936 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6938 if Length(chstr
) < 1 then
6940 g_Console_Add('chat <text>');
6944 chstr
:= b_Text_Format(chstr
);
6945 if g_Game_IsClient
then
6946 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6948 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6951 g_Console_Add('chat <text>');
6953 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6955 else if cmd
= 'teamchat' then
6957 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6959 if Length(P
) > 1 then
6961 for a
:= 1 to High(P
) do
6962 chstr
:= chstr
+ P
[a
] + ' ';
6964 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6966 if Length(chstr
) < 1 then
6968 g_Console_Add('teamchat <text>');
6972 chstr
:= b_Text_Format(chstr
);
6973 if g_Game_IsClient
then
6974 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6976 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6977 gPlayer1Settings
.Team
);
6980 g_Console_Add('teamchat <text>');
6982 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6984 else if (cmd
= 'an') or (cmd
= 'announce') then
6986 if g_Game_IsNet
then
6988 if Length(P
) > 1 then
6990 for a
:= 1 to High(P
) do
6991 chstr
:= chstr
+ P
[a
] + ' ';
6993 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6995 if Length(chstr
) < 1 then
6997 g_Console_Add('announce <text>');
7001 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
7002 if g_Game_IsClient
then
7003 MC_SEND_RCONCommand(chstr
)
7005 g_Console_Process(chstr
, True);
7008 g_Console_Add('announce <text>');
7010 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7012 else if cmd
= 'game' then
7014 if gGameSettings
.GameType
<> GT_NONE
then
7016 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7019 if Length(P
) = 1 then
7021 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
7024 // game not started yet, load fist map from some wad
7026 s
:= addWadExtension(P
[1]);
7027 found
:= e_FindResource(AllMapDirs
, s
);
7031 P
[1] := ExpandFileName(P
[1]);
7032 // if map not choosed then set first map
7033 if Length(P
) < 3 then
7036 P
[2] := g_Game_GetFirstMap(P
[1]);
7039 s
:= P
[1] + ':\' + UpperCase(P
[2]);
7041 if g_Map_Exist(s
) then
7045 with gGameSettings
do
7047 Options
:= gsGameFlags
;
7048 GameMode
:= g_Game_TextToMode(gsGameMode
);
7049 if gSwitchGameMode
<> GM_NONE
then
7050 GameMode
:= gSwitchGameMode
;
7051 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7052 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7054 if Length(P
) >= 4 then
7055 b
:= StrToIntDef(P
[3], 1);
7056 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
7057 GoalLimit
, MaxLives
, Options
, b
);
7062 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7064 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
7066 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
7068 else if cmd
= 'host' then
7070 if gGameSettings
.GameType
<> GT_NONE
then
7072 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7075 if Length(P
) < 4 then
7077 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
7080 if not StrToIp(P
[1], listen
) then
7082 prt
:= StrToIntDef(P
[2], 25666);
7084 s
:= addWadExtension(P
[3]);
7085 found
:= e_FindResource(AllMapDirs
, s
);
7089 // get first map in wad, if not specified
7090 if Length(P
) < 5 then
7093 P
[4] := g_Game_GetFirstMap(P
[1]);
7095 s
:= P
[3] + ':\' + UpperCase(P
[4]);
7096 if g_Map_Exist(s
) then
7100 with gGameSettings
do
7102 Options
:= gsGameFlags
;
7103 GameMode
:= g_Game_TextToMode(gsGameMode
);
7104 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
7105 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7106 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7108 if Length(P
) >= 6 then
7109 b
:= StrToIntDef(P
[5], 0);
7110 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
7116 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
7118 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
7123 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
7126 else if cmd
= 'map' then
7128 if Length(P
) = 1 then
7130 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7132 g_Console_Add(cmd
+ ' <MAP>');
7133 g_Console_Add(cmd
+ ' <WAD> [MAP]')
7137 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7142 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7144 if Length(P
) < 3 then
7146 // first param is map or wad
7147 s
:= UpperCase(P
[1]);
7148 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7150 gExitByTrigger
:= False;
7153 // already in game, finish current map
7155 gExit
:= EXIT_ENDLEVELCUSTOM
;
7159 // intermission, so change map immediately
7166 found
:= e_FindResource(AllMapDirs
, s
);
7168 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
7171 // no such map, found wad
7174 P
[1] := ExpandFileName(pw
);
7175 P
[2] := g_Game_GetFirstMap(P
[1]);
7176 s
:= P
[1] + ':\' + P
[2];
7177 if g_Map_Exist(s
) then
7179 gExitByTrigger
:= False;
7182 // already in game, finish current map
7184 gExit
:= EXIT_ENDLEVELCUSTOM
7188 // intermission, so change map immediately
7195 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7197 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7202 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7208 s
:= addWadExtension(P
[1]);
7209 found
:= e_FindResource(AllMapDirs
, s
);
7213 P
[2] := UpperCase(P
[2]);
7214 s
:= P
[1] + ':\' + P
[2];
7215 if g_Map_Exist(s
) then
7217 gExitByTrigger
:= False;
7221 gExit
:= EXIT_ENDLEVELCUSTOM
7230 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7235 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7241 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7245 else if cmd
= 'nextmap' then
7247 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7249 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7254 if Length(P
) = 1 then
7256 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7258 g_Console_Add(cmd
+ ' <MAP>');
7259 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7264 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7270 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7272 if Length(P
) < 3 then
7274 // first param is map or wad
7275 s
:= UpperCase(P
[1]);
7276 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7279 gExitByTrigger
:= False;
7285 // no such map, found wad
7286 pw
:= addWadExtension(P
[1]);
7287 found
:= e_FindResource(MapDirs
, pw
);
7289 found
:= e_FindResource(WadDirs
, pw
);
7291 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7294 // map not specified, select first map
7296 P
[2] := g_Game_GetFirstMap(P
[1]);
7297 s
:= P
[1] + ':\' + P
[2];
7298 if g_Map_Exist(s
) then
7300 gExitByTrigger
:= False;
7307 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7309 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7314 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7320 // specified two params wad + map
7321 pw
:= addWadExtension(P
[1]);
7322 found
:= e_FindResource(MapDirs
, pw
);
7324 found
:= e_FindResource(MapDirs
, pw
);
7328 P
[2] := UpperCase(P
[2]);
7329 s
:= P
[1] + ':\' + P
[2];
7330 if g_Map_Exist(s
) then
7332 gExitByTrigger
:= False;
7338 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7343 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7349 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7354 if gNextMap
= '' then
7355 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7357 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7361 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7365 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7369 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7371 gExitByTrigger
:= False;
7372 // next map not specified, try to find trigger EXIT
7373 if (gNextMap
= '') and (gTriggers
<> nil) then
7375 for a
:= 0 to High(gTriggers
) do
7377 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7379 gExitByTrigger
:= True;
7380 //gNextMap := gTriggers[a].Data.MapName;
7381 gNextMap
:= gTriggers
[a
].tgcMap
;
7386 if gNextMap
= '' then
7387 gNextMap
:= g_Game_GetNextMap();
7388 if not isWadPath(gNextMap
) then
7389 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7392 if g_Map_Exist(s
) then
7393 gExit
:= EXIT_ENDLEVELCUSTOM
7395 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7399 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7403 else if (cmd
= 'event') then
7405 if (Length(P
) <= 1) then
7407 for a
:= 0 to High(gEvents
) do
7408 if gEvents
[a
].Command
= '' then
7409 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7411 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7414 if (Length(P
) = 2) then
7416 for a
:= 0 to High(gEvents
) do
7417 if gEvents
[a
].Name
= P
[1] then
7418 if gEvents
[a
].Command
= '' then
7419 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7421 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7424 for a
:= 0 to High(gEvents
) do
7425 if gEvents
[a
].Name
= P
[1] then
7427 gEvents
[a
].Command
:= '';
7428 for b
:= 2 to High(P
) do
7429 if Pos(' ', P
[b
]) = 0 then
7430 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7432 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7433 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7437 else if cmd
= 'suicide' then
7441 if g_Game_IsClient
then
7442 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7445 if gPlayer1
<> nil then
7446 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7447 if gPlayer2
<> nil then
7448 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7452 else if cmd
= 'screenshot' then
7456 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7458 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7460 gWeaponAction
[0, WP_PREV
] := True;
7462 gWeaponAction
[0, WP_NEXT
] := True;
7464 else if cmd
= 'weapon' then
7466 if Length(p
) = 2 then
7468 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7469 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7470 gSelectWeapon
[0, a
] := True
7473 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7474 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7476 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7477 b
:= ord(cmd
[2]) - ord('1');
7479 gWeaponAction
[b
, WP_PREV
] := True;
7481 gWeaponAction
[b
, WP_NEXT
] := True;
7483 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7485 if Length(p
) = 2 then
7487 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7488 b
:= ord(cmd
[2]) - ord('1');
7489 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7490 gSelectWeapon
[b
, a
] := True
7493 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
7495 b
:= ord(cmd
[2]) - ord('1');
7497 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
7499 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
7501 else if (cmd
= 'dropflag') then
7503 if g_Game_IsServer
then
7505 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7506 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7509 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7511 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7513 b
:= ord(cmd
[2]) - ord('1');
7514 if g_Game_IsServer
then
7516 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7517 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7520 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7522 // Êîìàíäû Ñâîåé èãðû:
7523 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7525 if cmd
= 'bot_addred' then
7527 if Length(P
) > 1 then
7528 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7530 g_Bot_Add(TEAM_RED
, 2);
7532 else if cmd
= 'bot_addblue' then
7534 if Length(P
) > 1 then
7535 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7537 g_Bot_Add(TEAM_BLUE
, 2);
7539 else if cmd
= 'spectate' then
7545 else if cmd
= 'say' then
7547 if g_Game_IsServer
and g_Game_IsNet
then
7549 if Length(P
) > 1 then
7552 for a
:= 1 to High(P
) do
7553 chstr
:= chstr
+ P
[a
] + ' ';
7555 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7557 if Length(chstr
) < 1 then
7559 g_Console_Add('say <text>');
7563 chstr
:= b_Text_Format(chstr
);
7564 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7566 else g_Console_Add('say <text>');
7568 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7570 else if cmd
= 'tell' then
7572 if g_Game_IsServer
and g_Game_IsNet
then
7574 if (Length(P
) > 2) and (P
[1] <> '') then
7577 for a
:= 2 to High(P
) do
7578 chstr
:= chstr
+ P
[a
] + ' ';
7580 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7582 if Length(chstr
) < 1 then
7584 g_Console_Add('tell <playername> <text>');
7588 pl
:= g_Net_Client_ByName(P
[1]);
7590 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7592 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7594 else g_Console_Add('tell <playername> <text>');
7596 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7598 else if cmd
= 'centerprint' then
7600 if (Length(P
) > 2) and (P
[1] <> '') then
7603 for a
:= 2 to High(P
) do
7604 chstr
:= chstr
+ P
[a
] + ' ';
7606 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7608 if Length(chstr
) < 1 then
7610 g_Console_Add('centerprint <timeout> <text>');
7614 a
:= StrToIntDef(P
[1], 100);
7615 chstr
:= b_Text_Format(chstr
);
7616 g_Game_Message(chstr
, a
);
7617 if g_Game_IsNet
and g_Game_IsServer
then
7618 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7620 else g_Console_Add('centerprint <timeout> <text>');
7622 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7624 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7626 // Äîïîëíèòåëüíîå âðåìÿ:
7627 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7629 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7630 [gGameSettings
.TimeLimit
div 3600,
7631 (gGameSettings
.TimeLimit
div 60) mod 60,
7632 gGameSettings
.TimeLimit
mod 60]));
7633 if g_Game_IsNet
then MH_SEND_GameSettings
;
7635 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7637 if (Length(P
) <= 1) then
7638 g_Console_Add('rcon_password <password>')
7640 MC_SEND_RCONPassword(P
[1]);
7642 else if cmd
= 'rcon' then
7644 if g_Game_IsClient
then
7646 if Length(P
) > 1 then
7649 for a
:= 1 to High(P
) do
7650 chstr
:= chstr
+ P
[a
] + ' ';
7652 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7654 if Length(chstr
) < 1 then
7656 g_Console_Add('rcon <command>');
7660 MC_SEND_RCONCommand(chstr
);
7662 else g_Console_Add('rcon <command>');
7665 else if cmd
= 'ready' then
7667 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7668 gLMSRespawnTime
:= gTime
+ 100;
7670 else if (cmd
= 'callvote') and g_Game_IsNet
then
7672 if Length(P
) > 1 then
7675 for a
:= 1 to High(P
) do begin
7676 if a
> 1 then chstr
:= chstr
+ ' ';
7677 chstr
:= chstr
+ P
[a
];
7680 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7682 if Length(chstr
) < 1 then
7684 g_Console_Add('callvote <command>');
7688 if g_Game_IsClient
then
7689 MC_SEND_Vote(True, chstr
)
7691 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7692 g_Console_Process('vote', True);
7695 g_Console_Add('callvote <command>');
7697 else if (cmd
= 'vote') and g_Game_IsNet
then
7699 if g_Game_IsClient
then
7701 else if gVoteInProgress
then
7703 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7704 a
:= Floor((NetClientCount
+1)/2.0) + 1
7706 a
:= Floor(NetClientCount
/2.0) + 1;
7711 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7712 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7718 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7719 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7727 procedure SystemCommands(P
: SSArray
);
7731 cmd
:= LowerCase(P
[0]);
7740 gRC_Width
:= Max(1, gRC_Width
);
7741 gRC_Height
:= Max(1, gRC_Height
);
7742 gBPP
:= Max(1, gBPP
);
7743 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7744 e_LogWriteln('resolution changed')
7746 e_LogWriteln('resolution not changed');
7747 sys_EnableVSync(gVSync
);
7751 if Length(p
) = 2 then
7753 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7755 gFrameTime
:= 1000 div gMaxFPS
7759 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7763 if Length(p
) = 2 then
7765 gAskLanguage
:= true;
7766 gLanguage
:= LANGUAGE_ENGLISH
;
7767 case LowerCase(p
[1]) of
7770 gAskLanguage
:= false;
7771 gLanguage
:= LANGUAGE_ENGLISH
;
7775 gAskLanguage
:= false;
7776 gLanguage
:= LANGUAGE_RUSSIAN
;
7780 gAskLanguage
:= true;
7781 gLanguage
:= LANGUAGE_ENGLISH
;
7784 g_Language_Set(gLanguage
);
7788 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7794 procedure g_TakeScreenShot(Filename
: string = '');
7795 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7797 if e_NoGraphics
then Exit
;
7799 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7801 if Filename
= '' then
7804 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7805 Filename
:= 'screenshot-' + date
;
7808 name
:= e_CatPath(dir
, Filename
+ '.png');
7809 s
:= createDiskFile(name
);
7811 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
7813 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7815 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7820 g_Console_Add('oh shit, i can''t create screenshot!')
7824 procedure g_Game_InGameMenu(Show
: Boolean);
7826 if (g_ActiveWindow
= nil) and Show
then
7828 if gGameSettings
.GameType
= GT_SINGLE
then
7829 g_GUI_ShowWindow('GameSingleMenu')
7832 if g_Game_IsClient
then
7833 g_GUI_ShowWindow('GameClientMenu')
7835 if g_Game_IsNet
then
7836 g_GUI_ShowWindow('GameServerMenu')
7838 g_GUI_ShowWindow('GameCustomMenu');
7840 g_Sound_PlayEx('MENU_OPEN');
7842 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7843 if (not g_Game_IsNet
) then
7847 if (g_ActiveWindow
<> nil) and (not Show
) then
7849 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7850 if (not g_Game_IsNet
) then
7851 g_Game_Pause(False);
7855 procedure g_Game_Pause (Enable
: Boolean);
7859 if not gGameOn
then exit
;
7861 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7864 gPauseMain
:= Enable
;
7866 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7869 procedure g_Game_HolmesPause (Enable
: Boolean);
7873 if not gGameOn
then exit
;
7874 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7877 gPauseHolmes
:= Enable
;
7879 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7882 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7887 if gTriggers
<> nil then
7888 for i
:= 0 to High(gTriggers
) do
7889 with gTriggers
[i
] do
7890 if (TriggerType
= TRIGGER_SOUND
) and
7892 Sound
.IsPlaying() then
7894 Sound
.Pause(Enable
);
7898 if gPlayers
<> nil then
7899 for i
:= 0 to High(gPlayers
) do
7900 if gPlayers
[i
] <> nil then
7901 gPlayers
[i
].PauseSounds(Enable
);
7904 if gMusic
<> nil then
7905 gMusic
.Pause(Enable
);
7908 procedure g_Game_StopAllSounds(all
: Boolean);
7912 if gTriggers
<> nil then
7913 for i
:= 0 to High(gTriggers
) do
7914 with gTriggers
[i
] do
7915 if (TriggerType
= TRIGGER_SOUND
) and
7919 if gMusic
<> nil then
7926 procedure g_Game_UpdateTriggerSounds
;
7929 if gTriggers
<> nil then
7930 for i
:= 0 to High(gTriggers
) do
7931 with gTriggers
[i
] do
7932 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7933 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7936 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7939 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7944 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7949 if gSpectMode
<> SPECT_PLAYERS
then
7951 if gSpectPID1
= UID
then
7956 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7963 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7968 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7973 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7978 if gSpectMode
<> SPECT_PLAYERS
then
7980 Pl
:= g_Player_Get(gSpectPID1
);
7981 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7986 if gSpectViewTwo
then
7988 Pl
:= g_Player_Get(gSpectPID2
);
7989 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7997 procedure g_Game_Message(Msg
: string; Time
: Word);
7999 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
8000 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
8001 MessageTime
:= Time
;
8004 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
8006 punct
: Array[0..13] of String =
8007 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8013 function IsPunctuation(S
: String): Boolean;
8018 if Length(S
) <> 1 then
8020 for i
:= Low(punct
) to High(punct
) do
8021 if S
= punct
[i
] then
8027 function FilterPunctuation(S
: String): String;
8031 for i
:= Low(punct
) to High(punct
) do
8032 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
8038 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
8040 // remove player name
8041 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8042 // for FullWord check
8043 Text := toLowerCase1251(' ' + Text + ' ');
8044 fpText
:= FilterPunctuation(Text);
8046 for i
:= 0 to Length(gChatSounds
) - 1 do
8049 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
8051 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
8052 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
8054 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
8060 gChatSounds
[i
].Sound
.Play();
8066 g_Sound_PlayEx('SOUND_GAME_RADIO');
8069 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
8078 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8082 if goodsnd
[a
].IsPlaying() then
8085 goodsnd
[Random(4)].Play();
8088 procedure g_Game_Announce_KillCombo(Param
: Integer);
8095 UID
:= Param
and $FFFF;
8100 Pl
:= g_Player_Get(UID
);
8109 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
8113 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
8117 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
8121 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
8129 if not g_Game_IsWatchedPlayer(UID
) then
8132 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
8136 if killsnd
[n
].IsPlaying() then
8141 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
8149 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8153 if hahasnd
[a
].IsPlaying() then
8156 hahasnd
[Random(3)].Play();
8159 procedure g_Game_StartVote(Command
, Initiator
: string);
8163 if not gVotesEnabled
then Exit
;
8164 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8165 if gVoteInProgress
or gVotePassed
then
8167 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
8168 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
8171 gVoteInProgress
:= True;
8172 gVotePassed
:= False;
8173 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
8176 gVoteCommand
:= Command
;
8178 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8179 Need
:= Floor((NetClientCount
+1)/2.0)+1
8181 Need
:= Floor(NetClientCount
/2.0)+1;
8182 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
8183 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
8186 procedure g_Game_CheckVote
;
8190 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8191 if not gVoteInProgress
then Exit
;
8193 if (gTime
>= gVoteTimer
) then
8195 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8196 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8198 Need
:= Floor(NetClientCount
/2.0) + 1;
8199 if gVoteCount
>= Need
then
8201 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8202 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8203 gVotePassed
:= True;
8204 gVoteCmdTimer
:= gTime
+ 5000;
8208 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
8209 MH_SEND_VoteEvent(NET_VE_FAILED
);
8211 if NetClients
<> nil then
8212 for I
:= Low(NetClients
) to High(NetClients
) do
8213 if NetClients
[i
].Used
then
8214 NetClients
[i
].Voted
:= False;
8215 gVoteInProgress
:= False;
8221 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8222 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8224 Need
:= Floor(NetClientCount
/2.0) + 1;
8225 if gVoteCount
>= Need
then
8227 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8228 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8229 gVoteInProgress
:= False;
8230 gVotePassed
:= True;
8231 gVoteCmdTimer
:= gTime
+ 5000;
8234 if NetClients
<> nil then
8235 for I
:= Low(NetClients
) to High(NetClients
) do
8236 if NetClients
[i
].Used
then
8237 NetClients
[i
].Voted
:= False;
8242 procedure g_Game_LoadMapList(FileName
: string);
8250 if not FileExists(FileName
) then Exit
;
8252 AssignFile(ListFile
, FileName
);
8254 while not EOF(ListFile
) do
8256 ReadLn(ListFile
, s
);
8259 if s
= '' then Continue
;
8261 SetLength(MapList
, Length(MapList
)+1);
8262 MapList
[High(MapList
)] := s
;
8264 CloseFile(ListFile
);
8267 procedure g_Game_SetDebugMode();
8270 // ×èòû (äàæå â ñâîåé èãðå):
8274 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8278 if Length(LoadingStat
.Msgs
) = 0 then
8284 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8285 if NextMsg
= Length(Msgs
) then
8287 for i
:= 0 to High(Msgs
)-1 do
8288 Msgs
[i
] := Msgs
[i
+1];
8296 Msgs
[NextMsg
-1] := Text;
8300 PBarWasHere
:= false;
8303 g_ActiveWindow
:= nil;
8304 ProcessLoading(True);
8307 procedure g_Game_StepLoading(Value
: Integer = -1);
8319 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8322 ProcessLoading(False);
8327 procedure g_Game_ClearLoading();
8336 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8337 if len
< 1 then len
:= 1;
8338 SetLength(Msgs
, len
);
8339 for len
:= Low(Msgs
) to High(Msgs
) do
8342 PBarWasHere
:= false;
8346 procedure Parse_Params(var pars
: TParamStrValues
);
8353 while i
<= ParamCount
do
8356 if (Length(s
) > 1) and (s
[1] = '-') then
8358 if (Length(s
) > 2) and (s
[2] = '-') then
8359 begin // Îäèíî÷íûé ïàðàìåòð
8360 SetLength(pars
, Length(pars
) + 1);
8361 with pars
[High(pars
)] do
8363 Name
:= LowerCase(s
);
8368 if (i
< ParamCount
) then
8369 begin // Ïàðàìåòð ñî çíà÷åíèåì
8371 SetLength(pars
, Length(pars
) + 1);
8372 with pars
[High(pars
)] do
8374 Name
:= LowerCase(s
);
8375 Value
:= LowerCase(ParamStr(i
));
8384 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8389 for i
:= 0 to High(pars
) do
8390 if pars
[i
].Name
= aName
then
8392 Result
:= pars
[i
].Value
;
8397 procedure g_Game_Process_Params();
8399 pars
: TParamStrValues
;
8402 LimT
, LimS
: Integer;
8413 s
:= Find_Param_Value(pars
, '--debug');
8416 g_Game_SetDebugMode();
8417 s
:= Find_Param_Value(pars
, '--netdump');
8422 // Connect when game loads
8423 ip
:= Find_Param_Value(pars
, '-connect');
8427 s
:= Find_Param_Value(pars
, '-port');
8428 if (s
= '') or not TryStrToInt(s
, Port
) then
8431 s
:= Find_Param_Value(pars
, '-pw');
8433 g_Game_StartClient(ip
, Port
, s
);
8437 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8440 gDefaultMegawadStart
:= s
;
8443 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8444 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8446 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8449 // Start map when game loads:
8450 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8451 if isWadPath(map
) then
8454 s
:= Find_Param_Value(pars
, '-gm');
8455 GMode
:= g_Game_TextToMode(s
);
8456 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8457 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8460 s
:= Find_Param_Value(pars
, '-limt');
8461 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8467 s
:= Find_Param_Value(pars
, '-lims');
8468 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8474 s
:= Find_Param_Value(pars
, '-lives');
8475 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8481 s
:= Find_Param_Value(pars
, '-opt');
8485 Opt
:= StrToIntDef(s
, 0);
8488 s
:= Find_Param_Value(pars
, '--close');
8492 // Override map to test:
8493 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8496 if e_IsValidResourceName(s
) then
8497 e_FindResource(AllMapDirs
, s
);
8498 gTestMap
:= ExpandFileName(s
);
8501 // Delete test map after play:
8502 s
:= Find_Param_Value(pars
, '--testdelete');
8505 //gMapToDelete := MapsDir + map;
8506 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8510 // Delete temporary WAD after play:
8511 s
:= Find_Param_Value(pars
, '--tempdelete');
8512 if (s
<> '') and (gTestMap
<> '') then
8514 gMapToDelete
:= gTestMap
;
8515 gTempDelete
:= True;
8518 // Number of players:
8519 s
:= Find_Param_Value(pars
, '-pl');
8521 n
:= DEFAULT_PLAYERS
8523 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8526 s
:= Find_Param_Value(pars
, '-port');
8527 if (s
= '') or not TryStrToInt(s
, Port
) then
8528 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8530 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8533 // Execute script when game loads:
8534 s
:= Find_Param_Value(pars
, '-exec');
8537 // if not isWadPath(s) then
8538 // s := GameDir + '/' + s;
8543 if IOResult
<> 0 then
8545 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8546 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8550 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8551 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8556 if IOResult
<> 0 then
8558 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8559 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8563 if Pos('#', s
) <> 1 then // script comment
8564 g_Console_Process(s
, True);
8575 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8576 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8577 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8578 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8580 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8581 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8582 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8583 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8585 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8586 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8588 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8589 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8591 {$IFDEF ENABLE_HOLMES}
8592 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8595 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8597 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8598 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8600 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8601 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8603 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8604 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8606 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8607 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8608 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8609 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8610 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8611 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8612 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8613 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8614 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');