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;
354 g_dbg_ignore_bounds
: Boolean = false;
355 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
356 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
358 // move button values:
359 // bits 0-1: l/r state:
360 // 0: neither left, nor right pressed
363 // bits 4-5: l/r state when strafe was pressed
364 P1MoveButton
: Byte = 0;
365 P2MoveButton
: Byte = 0;
367 g_profile_frame_update
: Boolean = false;
368 g_profile_frame_draw
: Boolean = false;
369 g_profile_collision
: Boolean = false;
370 g_profile_los
: Boolean = false;
371 g_profile_history_size
: Integer = 1000;
373 g_rlayer_back
: Boolean = true;
374 g_rlayer_step
: Boolean = true;
375 g_rlayer_wall
: Boolean = true;
376 g_rlayer_door
: Boolean = true;
377 g_rlayer_acid1
: Boolean = true;
378 g_rlayer_acid2
: Boolean = true;
379 g_rlayer_water
: Boolean = true;
380 g_rlayer_fore
: Boolean = true;
383 procedure g_ResetDynlights ();
384 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
385 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
387 function conIsCheatsEnabled (): Boolean; inline;
388 function gPause (): Boolean; inline;
394 {$INCLUDE ../nogl/noGLuses.inc}
395 {$IFDEF ENABLE_HOLMES}
398 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
399 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
400 g_playermodel
, g_gfx
, g_options
, Math
,
401 g_triggers
, g_monsters
, e_sound
, CONFIG
,
402 g_language
, g_net
, g_main
, g_phys
,
403 ENet
, e_msg
, g_netmsg
, g_netmaster
,
404 sfs
, wadreader
, g_system
;
408 hasPBarGfx
: Boolean = false;
411 // ////////////////////////////////////////////////////////////////////////// //
412 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
415 // ////////////////////////////////////////////////////////////////////////// //
416 function conIsCheatsEnabled (): Boolean; inline;
419 if g_Game_IsNet
then exit
;
420 if not gDebugMode
then
422 //if not gCheats then exit;
423 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
424 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
430 // ////////////////////////////////////////////////////////////////////////// //
432 profileFrameDraw
: TProfiler
= nil;
435 // ////////////////////////////////////////////////////////////////////////// //
438 x
, y
, radius
: Integer;
441 exploRadius
: Integer;
445 g_dynLights
: array of TDynLight
= nil;
446 g_dynLightCount
: Integer = 0;
447 g_playerLight
: Boolean = false;
449 procedure g_ResetDynlights ();
453 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
455 for idx
:= 0 to g_dynLightCount
-1 do
457 if g_dynLights
[idx
].exploCount
= -666 then
464 Inc(g_dynLights
[idx
].exploCount
);
465 if (g_dynLights
[idx
].exploCount
< 10) then
467 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
468 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
469 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
470 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
475 g_dynLightCount
:= lnum
;
478 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
480 if not gwin_has_stencil
then exit
;
481 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
482 g_dynLights
[g_dynLightCount
].x
:= x
;
483 g_dynLights
[g_dynLightCount
].y
:= y
;
484 g_dynLights
[g_dynLightCount
].radius
:= radius
;
485 g_dynLights
[g_dynLightCount
].r
:= r
;
486 g_dynLights
[g_dynLightCount
].g
:= g
;
487 g_dynLights
[g_dynLightCount
].b
:= b
;
488 g_dynLights
[g_dynLightCount
].a
:= a
;
489 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
490 Inc(g_dynLightCount
);
493 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
495 if not gwin_has_stencil
then exit
;
496 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
497 g_dynLights
[g_dynLightCount
].x
:= x
;
498 g_dynLights
[g_dynLightCount
].y
:= y
;
499 g_dynLights
[g_dynLightCount
].radius
:= 0;
500 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
501 g_dynLights
[g_dynLightCount
].r
:= r
;
502 g_dynLights
[g_dynLightCount
].g
:= g
;
503 g_dynLights
[g_dynLightCount
].b
:= b
;
504 g_dynLights
[g_dynLightCount
].a
:= 0;
505 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
506 Inc(g_dynLightCount
);
510 // ////////////////////////////////////////////////////////////////////////// //
511 function calcProfilesHeight (prof
: TProfiler
): Integer;
514 if (prof
= nil) then exit
;
515 if (length(prof
.bars
) = 0) then exit
;
516 result
:= length(prof
.bars
)*(16+2);
520 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
527 if (prof
= nil) then exit
;
529 if (length(prof
.bars
) = 0) then exit
;
531 hgt
:= calcProfilesHeight(prof
);
532 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
533 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
535 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
536 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
537 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
540 for ii
:= 0 to High(prof
.bars
) do
542 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);
549 // ////////////////////////////////////////////////////////////////////////// //
551 TEndCustomGameStat
= record
552 PlayerStat
: TPlayerStatArray
;
556 Map
, MapName
: String;
559 TEndSingleGameStat
= record
560 PlayerStat
: Array [0..1] of record
566 TotalSecrets
: Integer;
569 TLoadingStat
= record
573 Msgs
: Array of String;
575 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
578 TParamStrValue
= record
583 TParamStrValues
= Array of TParamStrValue
;
586 INTER_ACTION_TEXT
= 1;
587 INTER_ACTION_PIC
= 2;
588 INTER_ACTION_MUSIC
= 3;
592 FPSCounter
, UPSCounter
: Word;
593 FPSTime
, UPSTime
: LongWord;
594 DataLoaded
: Boolean = False;
595 IsDrawStat
: Boolean = False;
596 CustomStat
: TEndCustomGameStat
;
597 SingleStat
: TEndSingleGameStat
;
598 LoadingStat
: TLoadingStat
;
599 EndingGameCounter
: Byte = 0;
602 MessageLineLength
: Integer = 80;
603 MapList
: SSArray
= nil;
604 MapIndex
: Integer = -1;
605 InterReadyTime
: Integer = -1;
606 StatShotDone
: Boolean = False;
607 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
608 StatDate
: string = '';
614 text: Array of ShortString;
615 anim
: Array of ShortString;
616 pic
: Array of ShortString;
617 mus
: Array of ShortString;
619 triggers
: Array of record
621 actions
: Array of record
622 action
, p1
, p2
: Integer;
625 cur_trigger
: Integer;
638 function Compare(a
, b
: TPlayerStat
): Integer;
640 if a
.Spectator
then Result
:= 1
641 else if b
.Spectator
then Result
:= -1
642 else if a
.Frags
< b
.Frags
then Result
:= 1
643 else if a
.Frags
> b
.Frags
then Result
:= -1
644 else if a
.Deaths
< b
.Deaths
then Result
:= -1
645 else if a
.Deaths
> b
.Deaths
then Result
:= 1
646 else if a
.Kills
< b
.Kills
then Result
:= -1
650 procedure SortGameStat(var stat
: TPlayerStatArray
);
655 if stat
= nil then Exit
;
657 for I
:= High(stat
) downto Low(stat
) do
658 for J
:= Low(stat
) to High(stat
) - 1 do
659 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
662 stat
[J
] := stat
[J
+ 1];
667 // saves a shitty CSV containing the game stats passed to it
668 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
671 dir
, fname
, map
, mode
, etime
: String;
675 dir
:= e_GetWriteableDir(StatsDirs
);
676 // stats are placed in stats/yy/mm/dd/*.csv
677 fname
:= e_CatPath(dir
, Path
);
678 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
679 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
680 AssignFile(s
, fname
);
683 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
684 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
685 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
686 mode
:= g_Game_ModeToText(Stat
.GameMode
);
687 etime
:= Format('%d:%.2d:%.2d', [
688 Stat
.GameTime
div 1000 div 3600,
689 (Stat
.GameTime
div 1000 div 60) mod 60,
690 Stat
.GameTime
div 1000 mod 60
692 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
693 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
699 gGameSettings
.TimeLimit
,
700 gGameSettings
.GoalLimit
,
701 gGameSettings
.Options
,
703 Length(Stat
.PlayerStat
)
705 // line 2: game specific shit
706 // if it's a team game: red score, blue score
707 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
709 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
711 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
712 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
714 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
715 // lines 3-...: team, player name, frags, deaths
716 WriteLn(s
, 'team,name,frags,deaths');
717 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
718 with Stat
.PlayerStat
[I
] do
719 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
721 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
724 g_Console_Add('could not create gamestats file "' + fname
+ '"');
729 function g_Game_ModeToText(Mode
: Byte): string;
733 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
734 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
735 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
736 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
737 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
741 function g_Game_TextToMode(Mode
: string): Byte;
744 Mode
:= UpperCase(Mode
);
745 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
750 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
755 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
760 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
765 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
772 function g_Game_IsNet(): Boolean;
774 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
777 function g_Game_IsServer(): Boolean;
779 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
782 function g_Game_IsClient(): Boolean;
784 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
787 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
794 Result
.name
:= ExtractFileName(WAD
);
795 Result
.description
:= '';
798 w
:= TWADFile
.Create();
801 if not w
.GetResource('INTERSCRIPT', p
, len
) then
807 cfg
:= TConfig
.CreateMem(p
, len
);
808 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
809 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
810 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
811 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
817 procedure g_Game_FreeWAD();
821 for a
:= 0 to High(MegaWAD
.res
.pic
) do
822 if MegaWAD
.res
.pic
[a
] <> '' then
823 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
825 for a
:= 0 to High(MegaWAD
.res
.mus
) do
826 if MegaWAD
.res
.mus
[a
] <> '' then
827 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
829 MegaWAD
.res
.pic
:= nil;
830 MegaWAD
.res
.text := nil;
831 MegaWAD
.res
.anim
:= nil;
832 MegaWAD
.res
.mus
:= nil;
833 MegaWAD
.triggers
:= nil;
835 g_Texture_Delete('TEXTURE_endpic');
836 g_Sound_Delete('MUSIC_endmus');
838 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
839 gGameSettings
.WAD
:= '';
842 procedure g_Game_LoadWAD(WAD
: string);
851 gGameSettings
.WAD
:= WAD
;
852 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
855 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
857 w
:= TWADFile
.Create();
860 if not w
.GetResource('INTERSCRIPT', p
, len
) then
866 cfg
:= TConfig
.CreateMem(p
, len
);
871 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
872 if s = '' then Break;
875 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
876 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
878 g_Texture_CreateWADEx(s, s);
884 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
885 if s = '' then Break;
888 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
889 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
891 g_Music_CreateWADEx(s, s);
894 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
895 if MegaWAD
.endpic
<> '' then
897 TEXTUREFILTER
:= GL_LINEAR
;
898 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
899 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
900 TEXTUREFILTER
:= GL_NEAREST
;
902 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
903 if MegaWAD
.endmus
<> '' then
905 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
906 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
914 {procedure start_trigger(t: string);
918 function next_trigger(): Boolean;
922 procedure DisableCheats();
928 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
929 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
930 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
931 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
933 {$IF DEFINED(D2F_DEBUG)}
934 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
935 gAimLine
:= g_dbg_aimline_on
;
939 procedure g_Game_ExecuteEvent(Name
: String);
945 if gEvents
= nil then
947 for a
:= 0 to High(gEvents
) do
948 if gEvents
[a
].Name
= Name
then
950 if gEvents
[a
].Command
<> '' then
951 g_Console_Process(gEvents
[a
].Command
, True);
956 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
961 if gDelayedEvents
<> nil then
962 for a
:= 0 to High(gDelayedEvents
) do
963 if not gDelayedEvents
[a
].Pending
then
970 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
971 n
:= High(gDelayedEvents
);
973 gDelayedEvents
[n
].Pending
:= True;
974 gDelayedEvents
[n
].DEType
:= DEType
;
975 gDelayedEvents
[n
].DENum
:= Num
;
976 gDelayedEvents
[n
].DEStr
:= Str
;
977 if DEType
= DE_GLOBEVENT
then
978 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
980 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
990 if g_Game_IsNet
and g_Game_IsServer
then
991 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
995 gPauseHolmes
:= false;
998 g_Game_StopAllSounds(False);
1003 EndingGameCounter
:= 0;
1004 g_ActiveWindow
:= nil;
1006 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1007 gLMSRespawnTime
:= 0;
1010 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1015 begin // Ýòî áûë òåñò
1019 begin // Âûõîä â ãëàâíîå ìåíþ
1020 gMusic
.SetByName('MUSIC_MENU');
1022 if gState
<> STATE_SLIST
then
1024 g_GUI_ShowWindow('MainMenu');
1025 gState
:= STATE_MENU
;
1028 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1029 slReturnPressed
:= True;
1030 if g_Net_Slist_Fetch(slCurrent
) then
1032 if slCurrent
= nil then
1033 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1036 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1037 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1040 g_Game_ExecuteEvent('ongameend');
1044 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
1046 if not g_Game_IsClient
then g_Game_Restart();
1049 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1051 // Ñòàòèñòèêà Ñâîåé èãðû:
1052 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1054 CustomStat
.GameTime
:= gTime
;
1055 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1056 CustomStat
.MapName
:= gMapInfo
.Name
;
1057 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1058 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1059 CustomStat
.TeamStat
:= gTeamStat
;
1061 CustomStat
.PlayerStat
:= nil;
1063 // Ñòàòèñòèêà èãðîêîâ:
1064 if gPlayers
<> nil then
1066 for a
:= 0 to High(gPlayers
) do
1067 if gPlayers
[a
] <> nil then
1069 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1070 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1073 Name
:= gPlayers
[a
].Name
;
1074 Frags
:= gPlayers
[a
].Frags
;
1075 Deaths
:= gPlayers
[a
].Death
;
1076 Kills
:= gPlayers
[a
].Kills
;
1077 Team
:= gPlayers
[a
].Team
;
1078 Color
:= gPlayers
[a
].Model
.Color
;
1079 Spectator
:= gPlayers
[a
].FSpectator
;
1083 SortGameStat(CustomStat
.PlayerStat
);
1085 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1088 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1089 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1090 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1091 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1093 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1096 StatShotDone
:= False;
1099 g_Game_ExecuteEvent('onmapend');
1100 if not g_Game_IsClient
then g_Player_ResetReady
;
1101 gInterReadyCount
:= 0;
1103 // Çàòóõàþùèé ýêðàí:
1104 EndingGameCounter
:= 255;
1105 gState
:= STATE_FOLD
;
1107 if gDefInterTime
< 0 then
1108 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1110 gInterEndTime
:= gDefInterTime
* 1000;
1113 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1115 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1116 SingleStat
.GameTime
:= gTime
;
1117 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1118 SingleStat
.TotalSecrets
:= gSecretsCount
;
1119 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1120 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1121 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1122 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1123 if SingleStat
.TwoPlayers
then
1125 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1126 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1129 g_Game_ExecuteEvent('onmapend');
1132 if gNextMap
<> '' then
1134 gMusic
.SetByName('MUSIC_INTERMUS');
1136 gState
:= STATE_INTERSINGLE
;
1139 g_Game_ExecuteEvent('oninter');
1141 else // Áîëüøå íåò êàðò
1143 // Çàòóõàþùèé ýêðàí:
1144 EndingGameCounter
:= 255;
1145 gState
:= STATE_FOLD
;
1150 // Îêîí÷àíèå îáðàáîòàíî:
1151 if gExit
<> EXIT_QUIT
then
1155 procedure drawTime(X
, Y
: Integer); inline;
1157 e_TextureFontPrint(x
, y
,
1158 Format('%d:%.2d:%.2d', [
1159 gTime
div 1000 div 3600,
1160 (gTime
div 1000 div 60) mod 60,
1161 gTime
div 1000 mod 60
1166 procedure DrawStat();
1168 pc
, x
, y
, w
, h
: Integer;
1169 w1
, w2
, w3
, w4
: Integer;
1171 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1174 stat
: TPlayerStatArray
;
1182 pc
:= g_Player_GetCount
;
1183 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1185 w
:= gScreenWidth
-(gScreenWidth
div 5);
1186 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1189 h
:= 40+ch
*5+(ch
+8)*pc
;
1190 x
:= (gScreenWidth
div 2)-(w
div 2);
1191 y
:= (gScreenHeight
div 2)-(h
div 2);
1193 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1194 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1196 drawTime(x
+w
-78, y
+8);
1198 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1199 map
:= g_ExtractFileName(gMapInfo
.Map
);
1200 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1202 case gGameSettings
.GameMode
of
1205 if gGameSettings
.MaxLives
= 0 then
1206 s1
:= _lc
[I_GAME_DM
]
1208 s1
:= _lc
[I_GAME_LMS
];
1209 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1210 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1215 if gGameSettings
.MaxLives
= 0 then
1216 s1
:= _lc
[I_GAME_TDM
]
1218 s1
:= _lc
[I_GAME_TLMS
];
1219 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1220 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1225 s1
:= _lc
[I_GAME_CTF
];
1226 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1227 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1232 if gGameSettings
.MaxLives
= 0 then
1233 s1
:= _lc
[I_GAME_COOP
]
1235 s1
:= _lc
[I_GAME_SURV
];
1236 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1237 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1248 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1250 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1252 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1254 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1255 gStdFont
, 200, 200, 200, 1);
1257 if NetMode
= NET_SERVER
then
1258 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1260 if NetMode
= NET_CLIENT
then
1261 e_TextureFontPrintEx(x
+8, y
+ 8,
1262 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1266 stat
:= g_Player_GetStats();
1269 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1270 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1272 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1274 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1278 for a
:= TEAM_RED
to TEAM_BLUE
do
1280 if a
= TEAM_RED
then
1282 s1
:= _lc
[I_GAME_TEAM_RED
];
1289 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1295 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1296 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1297 gStdFont
, r
, g
, b
, 1);
1299 _y
:= _y
+ch
+(ch
div 4);
1300 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1301 _y
:= _y
+(ch
div 4);
1303 for aa
:= 0 to High(stat
) do
1304 if stat
[aa
].Team
= a
then
1320 namestr
:= Format('[%5d] %s', [UID
, Name
])
1324 e_TextureFontPrintEx(x
+16, _y
, namestr
, gStdFont
, rr
, gg
, bb
, 1);
1326 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1328 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1330 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1337 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1340 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1341 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1342 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1343 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1346 for aa
:= 0 to High(stat
) do
1360 namestr
:= Format('[%5d] %s', [UID
, Name
])
1364 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1365 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1367 e_TextureFontPrintEx(x
+16+16+8, _y
+4, namestr
, gStdFont
, r
, g
, 0, 1);
1369 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1371 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1373 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1379 procedure g_Game_Init();
1382 knownFiles
: array of AnsiString = nil;
1384 wext
, s
: AnsiString;
1389 gTempDelete
:= False;
1391 sfsGCDisable(); // temporary disable removing of temporary volumes
1394 TEXTUREFILTER
:= GL_LINEAR
;
1395 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1396 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1397 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1398 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1399 TEXTUREFILTER
:= GL_NEAREST
;
1401 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1402 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1403 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1405 g_Game_ClearLoading();
1406 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1407 g_Game_SetLoadingText('', 0, False);
1409 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1412 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1413 g_PlayerModel_LoadData();
1415 // load models from all possible wad types, in all known directories
1416 // this does a loosy job (linear search, ooph!), but meh
1417 for wext
in wadExtensions
do
1419 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1421 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1425 for s
in knownFiles
do
1427 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1435 SetLength(knownFiles
, length(knownFiles
)+1);
1436 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1438 until (FindNext(SR
) <> 0);
1444 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1446 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
);
1447 for s
in knownFiles
do
1449 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1453 gPauseMain
:= false;
1454 gPauseHolmes
:= false;
1457 {e_MouseInfo.Accel := 1.0;}
1459 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1462 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1463 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1464 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1465 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1466 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1469 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1473 gMusic
:= TMusic
.Create();
1474 gMusic
.SetByName('MUSIC_MENU');
1477 gGameSettings
.WarmupTime
:= 30;
1479 gState
:= STATE_MENU
;
1481 SetLength(gEvents
, 6);
1482 gEvents
[0].Name
:= 'ongamestart';
1483 gEvents
[1].Name
:= 'ongameend';
1484 gEvents
[2].Name
:= 'onmapstart';
1485 gEvents
[3].Name
:= 'onmapend';
1486 gEvents
[4].Name
:= 'oninter';
1487 gEvents
[5].Name
:= 'onwadend';
1489 sfsGCEnable(); // enable releasing unused volumes
1493 procedure g_Game_Free(freeTextures
: Boolean=true);
1495 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1496 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1498 g_Map_Free(freeTextures
);
1500 g_Player_RemoveAllCorpses();
1502 gGameSettings
.GameType
:= GT_NONE
;
1503 if gGameSettings
.GameMode
= GM_SINGLE
then
1504 gGameSettings
.GameMode
:= GM_DM
;
1505 gSwitchGameMode
:= gGameSettings
.GameMode
;
1508 gExitByTrigger
:= False;
1511 function IsActivePlayer(p
: TPlayer
): Boolean;
1516 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1519 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1526 if gPlayers
= nil then
1528 for a
:= Low(gPlayers
) to High(gPlayers
) do
1529 if IsActivePlayer(gPlayers
[a
]) then
1531 if gPlayers
[a
].UID
<> ID
then
1533 Result
:= gPlayers
[a
];
1538 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1544 if gPlayers
= nil then
1548 for a
:= Low(gPlayers
) to High(gPlayers
) do
1549 if IsActivePlayer(gPlayers
[a
]) then
1551 SetLength(ids
, Length(ids
) + 1);
1552 ids
[High(ids
)] := gPlayers
[a
].UID
;
1553 if gPlayers
[a
].UID
= Skip
then
1556 if Length(ids
) = 0 then
1561 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1564 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1570 if gPlayers
= nil then
1574 for a
:= Low(gPlayers
) to High(gPlayers
) do
1575 if IsActivePlayer(gPlayers
[a
]) then
1577 SetLength(ids
, Length(ids
) + 1);
1578 ids
[High(ids
)] := gPlayers
[a
].UID
;
1579 if gPlayers
[a
].UID
= Skip
then
1582 if Length(ids
) = 0 then
1585 Result
:= ids
[Length(ids
) - 1]
1587 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1590 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1596 if gPlayers
= nil then
1600 for a
:= Low(gPlayers
) to High(gPlayers
) do
1601 if IsActivePlayer(gPlayers
[a
]) then
1603 SetLength(ids
, Length(ids
) + 1);
1604 ids
[High(ids
)] := gPlayers
[a
].UID
;
1605 if gPlayers
[a
].UID
= Skip
then
1608 if Length(ids
) = 0 then
1610 if Length(ids
) = 1 then
1615 Result
:= ids
[Random(Length(ids
))];
1617 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1619 Result
:= ids
[Random(Length(ids
))];
1624 function GetRandomSpectMode(Current
: Byte): Byte;
1631 0: Result
:= SPECT_STATS
;
1632 1: Result
:= SPECT_MAPVIEW
;
1633 2: Result
:= SPECT_MAPVIEW
;
1634 3: Result
:= SPECT_PLAYERS
;
1635 4: Result
:= SPECT_PLAYERS
;
1636 5: Result
:= SPECT_PLAYERS
;
1637 6: Result
:= SPECT_PLAYERS
;
1639 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1643 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1649 if (plr
= nil) then exit
;
1650 if (p
= 2) then time
:= 1000 else time
:= 1;
1651 strafeDir
:= MoveButton
shr 4;
1652 MoveButton
:= MoveButton
and $0F;
1654 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1655 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1656 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1657 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1658 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1659 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1661 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1662 if MoveButton
= 1 then
1663 plr
.PressKey(KEY_LEFT
, time
)
1664 else if MoveButton
= 2 then
1665 plr
.PressKey(KEY_RIGHT
, time
);
1667 // if we have "strafe" key, turn off old strafe mechanics
1668 if gPlayerAction
[p
, ACTION_STRAFE
] then
1670 // new strafe mechanics
1671 if (strafeDir
= 0) then
1672 strafeDir
:= MoveButton
; // start strafing
1673 // now set direction according to strafe (reversed)
1674 if (strafeDir
= 2) then
1675 plr
.SetDirection(TDirection
.D_LEFT
)
1676 else if (strafeDir
= 1) then
1677 plr
.SetDirection(TDirection
.D_RIGHT
)
1681 strafeDir
:= 0; // not strafing anymore
1682 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1683 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1684 plr
.SetDirection(TDirection
.D_LEFT
)
1685 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1686 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1687 plr
.SetDirection(TDirection
.D_RIGHT
)
1688 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1689 else if MoveButton
<> 0 then
1690 plr
.SetDirection(TDirection(MoveButton
-1))
1693 // fix movebutton state
1694 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1696 // Îñòàëüíûå êëàâèøè:
1697 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1698 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1699 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1700 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1701 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1703 for i
:= WP_FACT
to WP_LACT
do
1705 if gWeaponAction
[p
, i
] then
1707 plr
.ProcessWeaponAction(i
);
1708 gWeaponAction
[p
, i
] := False
1712 for i
:= WP_FIRST
to WP_LAST
do
1714 if gSelectWeapon
[p
, i
] then
1716 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1717 gSelectWeapon
[p
, i
] := False
1721 // HACK: add dynlight here
1722 if gwin_k8_enable_light_experiments
then
1724 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1726 g_playerLight
:= true;
1728 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1730 g_playerLight
:= false;
1734 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1737 // HACK: don't have a "key was pressed" function
1738 procedure InterReady();
1740 if InterReadyTime
> gTime
then Exit
;
1741 InterReadyTime
:= gTime
+ 3000;
1742 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1745 procedure g_Game_PreUpdate();
1747 // these are in separate PreUpdate functions because they can interact during Update()
1748 // and are synced over the net
1749 // we don't care that much about corpses and gibs
1750 g_Player_PreUpdate();
1751 g_Monsters_PreUpdate();
1752 g_Items_PreUpdate();
1753 g_Weapon_PreUpdate();
1756 procedure g_Game_Update();
1758 Msg
: g_gui
.TMessage
;
1764 function sendMonsPos (mon
: TMonster
): Boolean;
1766 result
:= false; // don't stop
1767 // this will also reset "need-send" flag
1768 if mon
.gncNeedSend
then
1770 MH_SEND_MonsterPos(mon
.UID
);
1772 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1774 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1776 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1778 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1782 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1784 result
:= false; // don't stop
1785 // this will also reset "need-send" flag
1786 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1789 function sendItemPos (it
: PItem
): Boolean;
1791 result
:= false; // don't stop
1794 MH_SEND_ItemPos(it
.myId
);
1795 it
.needSend
:= False;
1800 reliableUpdate
: Boolean;
1805 // Ïîðà âûêëþ÷àòü èãðó:
1806 if gExit
= EXIT_QUIT
then
1808 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1812 if gExit
= EXIT_QUIT
then
1816 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1817 // no need to, as we'll do it in event handler
1819 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1822 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1824 gExit
:= EXIT_SIMPLE
;
1829 // process master server communications
1830 g_Net_Slist_Pulse();
1833 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1834 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1835 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1836 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1838 if g_Game_IsNet
and g_Game_IsServer
then
1840 gInterTime
:= gInterTime
+ GAME_TICK
;
1841 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1842 if a
<> gServInterTime
then
1844 gServInterTime
:= a
;
1845 MH_SEND_TimeSync(gServInterTime
);
1849 if (not g_Game_IsClient
) and
1853 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1854 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1855 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1856 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1858 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1859 and (g_ActiveWindow
= nil)
1861 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1864 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1865 g_Game_StopAllSounds(True);
1867 if gMapOnce
then // Ýòî áûë òåñò
1868 gExit
:= EXIT_SIMPLE
1870 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1871 g_Game_ChangeMap(gNextMap
)
1872 else // Ñëåäóþùåé êàðòû íåò
1874 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1876 // Âûõîä â ãëàâíîå ìåíþ:
1878 g_GUI_ShowWindow('MainMenu');
1879 gMusic
.SetByName('MUSIC_MENU');
1881 gState
:= STATE_MENU
;
1884 // Ôèíàëüíàÿ êàðòèíêà:
1885 g_Game_ExecuteEvent('onwadend');
1887 if not gMusic
.SetByName('MUSIC_endmus') then
1888 gMusic
.SetByName('MUSIC_STDENDMUS');
1890 gState
:= STATE_ENDPIC
;
1892 g_Game_ExecuteEvent('ongameend');
1897 else if g_Game_IsClient
and
1900 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1901 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1902 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1903 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1905 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1906 and (g_ActiveWindow
= nil)
1914 if gState
= STATE_INTERTEXT
then
1915 if InterText
.counter
> 0 then
1916 InterText
.counter
:= InterText
.counter
- 1;
1919 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1921 if EndingGameCounter
= 0 then
1923 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1924 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1926 gState
:= STATE_INTERCUSTOM
;
1927 InterReadyTime
:= -1;
1928 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1930 g_Game_ExecuteEvent('onwadend');
1931 if not gMusic
.SetByName('MUSIC_endmus') then
1932 gMusic
.SetByName('MUSIC_STDENDMUS');
1935 gMusic
.SetByName('MUSIC_ROUNDMUS');
1939 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1941 gMusic
.SetByName('MUSIC_INTERMUS');
1943 gState
:= STATE_INTERSINGLE
;
1946 g_Game_ExecuteEvent('oninter');
1949 DecMin(EndingGameCounter
, 6, 0);
1952 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1954 if gMapOnce
then // Ýòî áûë òåñò
1956 gExit
:= EXIT_SIMPLE
;
1962 g_Serverlist_Control(slCurrent
, slTable
);
1965 // Ñòàòèñòèêà ïî Tab:
1967 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1970 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1972 // Âðåìÿ += 28 ìèëëèñåêóíä:
1973 gTime
:= gTime
+ GAME_TICK
;
1975 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1976 if MessageTime
= 0 then
1978 if MessageTime
> 0 then
1979 MessageTime
:= MessageTime
- 1;
1981 if (g_Game_IsServer
) then
1983 // Áûë çàäàí ëèìèò âðåìåíè:
1984 if (gGameSettings
.TimeLimit
> 0) then
1985 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1986 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1991 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1992 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1993 g_Game_RestartRound(gLMSSoftSpawn
);
1995 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1996 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1998 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2000 g_Console_Process(gVoteCommand
);
2002 gVotePassed
:= False;
2005 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2006 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2007 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2008 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2009 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2011 // Áûë çàäàí ëèìèò ïîáåä:
2012 if (gGameSettings
.GoalLimit
> 0) then
2016 if gGameSettings
.GameMode
= GM_DM
then
2017 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2018 for i
:= 0 to High(gPlayers
) do
2019 if gPlayers
[i
] <> nil then
2020 if gPlayers
[i
].Frags
> b
then
2021 b
:= gPlayers
[i
].Frags
;
2024 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2025 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2026 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2029 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2030 if b
>= gGameSettings
.GoalLimit
then
2037 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2038 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2039 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2040 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2042 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2043 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2044 end // if not console
2047 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2049 // process weapon switch queue
2053 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2054 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2056 if not gSpectKeyPress
then
2058 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2060 // switch spect mode
2062 SPECT_NONE
: ; // not spectator
2064 SPECT_MAPVIEW
: Inc(gSpectMode
);
2065 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2067 gSpectKeyPress
:= True;
2069 if (gSpectMode
= SPECT_MAPVIEW
)
2070 and (not gSpectAuto
) then
2072 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2073 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2074 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2075 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2076 if gPlayerAction
[0, ACTION_LOOKUP
] then
2077 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2078 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2079 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2080 if gWeaponAction
[0, WP_PREV
] then
2083 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2084 gWeaponAction
[0, WP_PREV
] := False;
2086 if gWeaponAction
[0, WP_NEXT
] then
2089 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2090 gWeaponAction
[0, WP_NEXT
] := False;
2093 if (gSpectMode
= SPECT_PLAYERS
)
2094 and (not gSpectAuto
) then
2096 if gPlayerAction
[0, ACTION_LOOKUP
] then
2099 gSpectViewTwo
:= True;
2100 gSpectKeyPress
:= True;
2102 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2104 // remove second view
2105 gSpectViewTwo
:= False;
2106 gSpectKeyPress
:= True;
2108 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2110 // prev player (view 1)
2111 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2112 gSpectKeyPress
:= True;
2114 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2116 // next player (view 1)
2117 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2118 gSpectKeyPress
:= True;
2120 if gWeaponAction
[0, WP_PREV
] then
2122 // prev player (view 2)
2123 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2124 gWeaponAction
[0, WP_PREV
] := False;
2126 if gWeaponAction
[0, WP_NEXT
] then
2128 // next player (view 2)
2129 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2130 gWeaponAction
[0, WP_NEXT
] := False;
2133 if gPlayerAction
[0, ACTION_ATTACK
] then
2135 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2138 gSpectAutoNext
:= 0;
2139 gSpectViewTwo
:= False;
2140 gSpectKeyPress
:= True;
2145 gSpectMode
:= SPECT_STATS
;
2146 gSpectAuto
:= False;
2147 gSpectKeyPress
:= True;
2152 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2153 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2154 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2155 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2156 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2157 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2158 gSpectKeyPress
:= False;
2162 if gSpectMode
= SPECT_MAPVIEW
then
2164 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2166 gSpectAutoNext
:= gTime
2169 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2171 gSpectAutoNext
:= gTime
2175 if gSpectAutoNext
<= gTime
then
2177 if gSpectAutoNext
> 0 then
2179 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2183 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2184 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2185 gSpectAutoStepX
:= Random(9) - 4;
2186 gSpectAutoStepY
:= Random(9) - 4;
2187 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2188 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2189 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2190 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2191 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2192 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2196 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2201 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2202 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2203 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2209 // Îáíîâëÿåì âñå îñòàëüíîå:
2212 g_Triggers_Update();
2214 g_Monsters_Update();
2216 g_Player_UpdateAll();
2217 g_Player_UpdatePhysicalObjects();
2219 // server: send newly spawned monsters unconditionally
2220 if (gGameSettings
.GameType
= GT_SERVER
) then
2222 if (Length(gMonstersSpawned
) > 0) then
2224 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2225 SetLength(gMonstersSpawned
, 0);
2229 if (gSoundTriggerTime
> 8) then
2231 g_Game_UpdateTriggerSounds();
2232 gSoundTriggerTime
:= 0;
2236 Inc(gSoundTriggerTime
);
2239 if (NetMode
= NET_SERVER
) then
2241 Inc(NetTimeToUpdate
);
2242 Inc(NetTimeToReliable
);
2244 // send monster updates
2245 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2247 // send all monsters (periodic sync)
2248 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2250 for I
:= 0 to High(gPlayers
) do
2252 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2255 g_Mons_ForEach(sendMonsPos
);
2257 // update flags that aren't stationary
2258 if gGameSettings
.GameMode
= GM_CTF
then
2259 for I
:= FLAG_RED
to FLAG_BLUE
do
2260 if gFlags
[I
].NeedSend
then
2262 gFlags
[I
].NeedSend
:= False;
2266 // update items that aren't stationary
2267 g_Items_ForEachAlive(sendItemPos
);
2269 if reliableUpdate
then
2271 NetTimeToReliable
:= 0;
2272 NetTimeToUpdate
:= NetUpdateRate
;
2276 NetTimeToUpdate
:= 0;
2281 // send only mosters with some unexpected changes
2282 g_Mons_ForEach(sendMonsPosUnexpected
);
2285 // send unexpected platform changes
2286 g_Map_NetSendInterestingPanels();
2288 g_Net_Slist_ServerUpdate();
2290 if NetUseMaster then
2292 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2294 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2296 NetTimeToMaster := gTime + NetMasterRate;
2301 else if (NetMode
= NET_CLIENT
) then
2303 MC_SEND_PlayerPos();
2305 end; // if gameOn ...
2307 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2308 if g_ActiveWindow
<> nil then
2310 w
:= e_GetFirstKeyPressed();
2312 if (w
<> IK_INVALID
) then
2314 Msg
.Msg
:= MESSAGE_DIKEY
;
2316 g_ActiveWindow
.OnMessage(Msg
);
2319 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2320 if g_ActiveWindow
<> nil then
2321 g_ActiveWindow
.Update();
2323 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2324 if gResolutionChange
then
2326 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2327 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2328 gResolutionChange
:= False;
2329 g_ActiveWindow
:= nil;
2332 // Íóæíî ñìåíèòü ÿçûê:
2333 if gLanguageChange
then
2335 //e_WriteLog('Read language file', MSG_NOTIFY);
2336 //g_Language_Load(DataDir + gLanguage + '.txt');
2337 g_Language_Set(gLanguage
);
2341 gLanguageChange
:= False;
2345 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2346 if e_KeyPressed(IK_F10
) and
2348 (not gConsoleShow
) and
2349 (g_ActiveWindow
= nil) then
2354 Time
:= sys_GetTicks() {div 1000};
2356 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2357 if gDelayedEvents
<> nil then
2358 for a
:= 0 to High(gDelayedEvents
) do
2359 if gDelayedEvents
[a
].Pending
and
2361 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2362 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2365 case gDelayedEvents
[a
].DEType
of
2367 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2370 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2374 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2375 if g_Game_IsNet
and g_Game_IsServer
then
2376 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2380 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2382 gDelayedEvents
[a
].Pending
:= False;
2385 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2386 UPSCounter
:= UPSCounter
+ 1;
2387 if Time
- UPSTime
>= 1000 then
2396 g_Weapon_AddDynLights();
2397 g_Items_AddDynLights();
2401 procedure g_Game_LoadChatSounds(Resource
: string);
2404 FileName
, Snd
: string;
2406 len
, cnt
, tags
, i
, j
: Integer;
2409 FileName
:= g_ExtractWadName(Resource
);
2411 WAD
:= TWADFile
.Create();
2412 WAD
.ReadFile(FileName
);
2414 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2421 cfg
:= TConfig
.CreateMem(p
, len
);
2422 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2424 SetLength(gChatSounds
, cnt
);
2425 for i
:= 0 to Length(gChatSounds
) - 1 do
2427 gChatSounds
[i
].Sound
:= nil;
2428 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2429 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2430 if (Snd
= '') or (Tags
<= 0) then
2432 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2433 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2434 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2435 SetLength(gChatSounds
[i
].Tags
, tags
);
2436 for j
:= 0 to tags
- 1 do
2437 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2438 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2445 procedure g_Game_FreeChatSounds();
2449 for i
:= 0 to Length(gChatSounds
) - 1 do
2451 gChatSounds
[i
].Sound
.Free();
2452 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2454 SetLength(gChatSounds
, 0);
2458 procedure g_Game_LoadData();
2465 if DataLoaded
then Exit
;
2467 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2469 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2470 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2471 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2472 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2473 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2474 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2475 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2476 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2477 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2478 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2479 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2480 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2481 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2482 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2483 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2486 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2487 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2488 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2489 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2493 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2494 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2495 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2496 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2497 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
2503 hasPBarGfx
:= false;
2507 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2508 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2509 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2510 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2511 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2512 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2513 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2514 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2515 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2516 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2517 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2518 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2519 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2520 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2521 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2522 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2523 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2524 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2525 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2526 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2527 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2528 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2529 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2530 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2531 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2532 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2533 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2534 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2535 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2536 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2537 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2538 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2539 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2540 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2541 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2542 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2543 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2544 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2545 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2547 goodsnd
[0] := TPlayableSound
.Create();
2548 goodsnd
[1] := TPlayableSound
.Create();
2549 goodsnd
[2] := TPlayableSound
.Create();
2550 goodsnd
[3] := TPlayableSound
.Create();
2552 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2553 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2554 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2555 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2557 killsnd
[0] := TPlayableSound
.Create();
2558 killsnd
[1] := TPlayableSound
.Create();
2559 killsnd
[2] := TPlayableSound
.Create();
2560 killsnd
[3] := TPlayableSound
.Create();
2562 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2563 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2564 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2565 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2567 hahasnd
[0] := TPlayableSound
.Create();
2568 hahasnd
[1] := TPlayableSound
.Create();
2569 hahasnd
[2] := TPlayableSound
.Create();
2571 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2572 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2573 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2575 sound_get_flag
[0] := TPlayableSound
.Create();
2576 sound_get_flag
[1] := TPlayableSound
.Create();
2577 sound_lost_flag
[0] := TPlayableSound
.Create();
2578 sound_lost_flag
[1] := TPlayableSound
.Create();
2579 sound_ret_flag
[0] := TPlayableSound
.Create();
2580 sound_ret_flag
[1] := TPlayableSound
.Create();
2581 sound_cap_flag
[0] := TPlayableSound
.Create();
2582 sound_cap_flag
[1] := TPlayableSound
.Create();
2584 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2585 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2586 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2587 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2588 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2589 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2590 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2591 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2593 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2595 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2598 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2599 g_Weapon_LoadData();
2601 g_Monsters_LoadData();
2606 procedure g_Game_FreeData();
2608 if not DataLoaded
then Exit
;
2611 g_Weapon_FreeData();
2612 g_Monsters_FreeData();
2614 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2616 g_Texture_Delete('NOTEXTURE');
2617 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2618 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2619 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2620 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2621 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2622 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2623 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2624 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2625 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2626 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2627 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2628 g_Frames_DeleteByName('FRAMES_TELEPORT');
2629 g_Frames_DeleteByName('FRAMES_PUNCH');
2630 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2631 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2632 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2633 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2634 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2635 g_Sound_Delete('SOUND_GAME_TELEPORT');
2636 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2637 g_Sound_Delete('SOUND_GAME_SECRET');
2638 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2639 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2640 g_Sound_Delete('SOUND_GAME_BULK1');
2641 g_Sound_Delete('SOUND_GAME_BULK2');
2642 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2643 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2644 g_Sound_Delete('SOUND_GAME_BURNING');
2645 g_Sound_Delete('SOUND_GAME_SWITCH1');
2646 g_Sound_Delete('SOUND_GAME_SWITCH0');
2653 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2654 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2655 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2656 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2663 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2664 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2665 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2666 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2672 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2673 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2674 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2676 sound_get_flag
[0].Free();
2677 sound_get_flag
[1].Free();
2678 sound_lost_flag
[0].Free();
2679 sound_lost_flag
[1].Free();
2680 sound_ret_flag
[0].Free();
2681 sound_ret_flag
[1].Free();
2682 sound_cap_flag
[0].Free();
2683 sound_cap_flag
[1].Free();
2685 g_Sound_Delete('SOUND_CTF_GET1');
2686 g_Sound_Delete('SOUND_CTF_GET2');
2687 g_Sound_Delete('SOUND_CTF_LOST1');
2688 g_Sound_Delete('SOUND_CTF_LOST2');
2689 g_Sound_Delete('SOUND_CTF_RETURN1');
2690 g_Sound_Delete('SOUND_CTF_RETURN2');
2691 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2692 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2694 g_Game_FreeChatSounds();
2696 DataLoaded
:= False;
2699 procedure DrawCustomStat();
2705 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2706 s1
, s2
, topstr
: String;
2708 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2712 if g_Console_Action(ACTION_SCORES
) then
2714 if not gStatsPressed
then
2716 gStatsOff
:= not gStatsOff
;
2717 gStatsPressed
:= True;
2721 gStatsPressed
:= False;
2725 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2726 w
:= (Length(s1
) * ww2
) div 2;
2727 x
:= gScreenWidth
div 2 - w
;
2729 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2733 if (gGameSettings
.GameMode
= GM_COOP
) then
2735 if gMissionFailed
then
2736 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2738 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2741 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2743 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2744 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2746 if g_Game_IsNet
then
2748 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2749 if not gChatShow
then
2750 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2751 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2754 if g_Game_IsClient
then
2755 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2757 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2758 if not gChatShow
then
2759 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2760 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2765 w
:= gScreenWidth
-x
*2;
2771 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2772 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2774 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2776 case CustomStat
.GameMode
of
2779 if gGameSettings
.MaxLives
= 0 then
2780 s1
:= _lc
[I_GAME_DM
]
2782 s1
:= _lc
[I_GAME_LMS
];
2786 if gGameSettings
.MaxLives
= 0 then
2787 s1
:= _lc
[I_GAME_TDM
]
2789 s1
:= _lc
[I_GAME_TLMS
];
2791 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2794 if gGameSettings
.MaxLives
= 0 then
2795 s1
:= _lc
[I_GAME_COOP
]
2797 s1
:= _lc
[I_GAME_SURV
];
2803 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2807 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2808 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2811 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2812 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2813 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2814 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2816 pc
:= Length(CustomStat
.PlayerStat
);
2817 if pc
= 0 then Exit
;
2819 if CustomStat
.GameMode
= GM_COOP
then
2821 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2823 s2
:= _lc
[I_GAME_MONSTERS
];
2824 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2825 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2827 s2
:= _lc
[I_GAME_SECRETS
];
2828 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2829 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2832 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2834 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2835 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2836 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2838 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2839 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2840 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2844 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2849 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2850 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2851 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2853 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2856 for t
:= TEAM_RED
to TEAM_BLUE
do
2858 if t
= TEAM_RED
then
2860 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2861 gStdFont
, 255, 0, 0, 1);
2862 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2863 gStdFont
, 255, 0, 0, 1);
2870 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2871 gStdFont
, 0, 0, 255, 1);
2872 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2873 gStdFont
, 0, 0, 255, 1);
2879 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2882 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2883 if CustomStat
.PlayerStat
[p
].Team
= t
then
2884 with CustomStat
.PlayerStat
[p
] do
2898 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2899 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2901 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2902 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2903 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2910 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2913 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2914 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2915 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2918 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2919 with CustomStat
.PlayerStat
[p
] do
2921 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2928 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2929 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2931 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2932 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2933 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2938 // HACK: take stats screenshot immediately after the first frame of the stats showing
2939 if gScreenshotStats
and (not StatShotDone
) and (Length(CustomStat
.PlayerStat
) > 1) then
2941 g_TakeScreenShot('stats/' + StatFilename
);
2942 StatShotDone
:= True;
2946 procedure DrawSingleStat();
2948 tm
, key_x
, val_x
, y
: Integer;
2952 procedure player_stat(n
: Integer);
2958 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2959 s2
:= Format(' %d', [gTotalMonsters
]);
2961 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2962 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2963 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2964 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2966 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2967 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2969 // "Kills-per-minute: ##.#":
2970 s1
:= _lc
[I_MENU_INTER_KPM
];
2972 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2974 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2975 s2
:= Format(' %.1f', [kpm
]);
2977 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2978 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2980 // "Secrets found: # / #":
2981 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2982 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2984 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2985 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2986 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2987 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2989 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2990 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2994 // "Level Complete":
2995 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2996 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2998 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2999 s1
:= _lc
[I_MENU_INTER_KPM
];
3000 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3003 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
3005 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
3006 val_x
:= key_x
+ w1
;
3009 tm
:= SingleStat
.GameTime
div 1000;
3010 s1
:= _lc
[I_MENU_INTER_TIME
];
3011 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
3013 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
3014 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
3016 if SingleStat
.TwoPlayers
then
3019 s1
:= _lc
[I_MENU_PLAYER_1
];
3020 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3021 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
3023 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3028 s1
:= _lc
[I_MENU_PLAYER_2
];
3029 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
3030 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
3032 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3038 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3044 procedure DrawLoadingStat();
3045 procedure drawRect (x
, y
, w
, h
: Integer);
3047 if (w
< 1) or (h
< 1) then exit
;
3049 glVertex2f(x
+0.375, y
+0.375);
3050 glVertex2f(x
+w
+0.375, y
+0.375);
3051 glVertex2f(x
+w
+0.375, y
+h
+0.375);
3052 glVertex2f(x
+0.375, y
+h
+0.375);
3056 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
3058 rectW
, rectH
: Integer;
3065 idl
, idr
, idb
, idm
: LongWord;
3069 if (total
< 1) then exit
;
3070 if (cur
< 1) then exit
; // don't blink
3071 if (not washere
) and (cur
>= total
) then exit
; // don't blink
3072 //if (cur < 0) then cur := 0;
3073 //if (cur > total) then cur := total;
3076 if (hasPBarGfx
) then
3078 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
3079 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
3080 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
3081 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
3082 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
3083 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
3084 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
3085 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
3087 //rectW := gScreenWidth-360;
3088 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
3091 x0
:= (gScreenWidth
-rectW
) div 2;
3092 y0
:= gScreenHeight
-rectH
-64;
3093 if (y0
< 2) then y0
:= 2;
3095 glEnable(GL_SCISSOR_TEST
);
3098 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
3099 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
3100 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
3103 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
3105 while (f
< x0
+rectW
) do
3107 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
3112 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
3113 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
3116 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
3117 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
3121 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
3127 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3131 rectW
:= gScreenWidth
-64;
3134 x0
:= (gScreenWidth
-rectW
) div 2;
3135 y0
:= gScreenHeight
-rectH
-64;
3136 if (y0
< 2) then y0
:= 2;
3138 glDisable(GL_BLEND
);
3139 glDisable(GL_TEXTURE_2D
);
3141 //glClearColor(0, 0, 0, 0);
3142 //glClear(GL_COLOR_BUFFER_BIT);
3144 glColor4ub(127, 127, 127, 255);
3145 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
3147 glColor4ub(0, 0, 0, 255);
3148 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
3150 glColor4ub(127, 127, 127, 255);
3151 wdt
:= rectW
*cur
div total
;
3152 if (wdt
> rectW
) then wdt
:= rectW
;
3153 drawRect(x0
, y0
, wdt
, rectH
);
3162 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
3164 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
3165 yy
:= (gScreenHeight
div 3);
3166 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3167 xx
:= (gScreenWidth
div 3);
3171 for i
:= 0 to NextMsg
-1 do
3173 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3174 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3178 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3179 yy
:= yy
+ LOADING_INTERLINE
;
3180 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3185 procedure DrawMenuBackground(tex
: AnsiString);
3191 if g_Texture_Get(tex
, ID
) then
3193 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3194 e_GetTextureSize(ID
, @w
, @h
);
3196 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3198 w
:= trunc(w
* (gScreenHeight
/ h
));
3199 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3201 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3204 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3206 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3208 function monDraw (mon
: TMonster
): Boolean;
3210 result
:= false; // don't stop
3215 // Ëåâûé âåðõíèé óãîë
3216 aX
:= Obj
.X
div ScaleSz
+ 1;
3217 aY
:= Obj
.Y
div ScaleSz
+ 1;
3219 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3220 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3221 // Ïðàâûé íèæíèé óãîë
3222 aX2
:= aX
+ aX2
- 1;
3223 aY2
:= aY
+ aY2
- 1;
3224 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3230 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3231 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3234 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3235 ScaleSz
:= 16 div Scale
;
3236 // Ðàçìåðû ìèíè-êàðòû:
3237 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3238 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3240 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3242 if gWalls
<> nil then
3245 for a
:= 0 to High(gWalls
) do
3247 if PanelType
<> 0 then
3249 // Ëåâûé âåðõíèé óãîë:
3250 aX
:= X
div ScaleSz
;
3251 aY
:= Y
div ScaleSz
;
3253 aX2
:= max(Width
div ScaleSz
, 1);
3254 aY2
:= max(Height
div ScaleSz
, 1);
3255 // Ïðàâûé íèæíèé óãîë:
3256 aX2
:= aX
+ aX2
- 1;
3257 aY2
:= aY
+ aY2
- 1;
3260 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3261 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3262 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3266 if gSteps
<> nil then
3269 for a
:= 0 to High(gSteps
) do
3271 if PanelType
<> 0 then
3273 // Ëåâûé âåðõíèé óãîë:
3274 aX
:= X
div ScaleSz
;
3275 aY
:= Y
div ScaleSz
;
3277 aX2
:= max(Width
div ScaleSz
, 1);
3278 aY2
:= max(Height
div ScaleSz
, 1);
3279 // Ïðàâûé íèæíèé óãîë:
3280 aX2
:= aX
+ aX2
- 1;
3281 aY2
:= aY
+ aY2
- 1;
3283 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3286 if gLifts
<> nil then
3289 for a
:= 0 to High(gLifts
) do
3291 if PanelType
<> 0 then
3293 // Ëåâûé âåðõíèé óãîë:
3294 aX
:= X
div ScaleSz
;
3295 aY
:= Y
div ScaleSz
;
3297 aX2
:= max(Width
div ScaleSz
, 1);
3298 aY2
:= max(Height
div ScaleSz
, 1);
3299 // Ïðàâûé íèæíèé óãîë:
3300 aX2
:= aX
+ aX2
- 1;
3301 aY2
:= aY
+ aY2
- 1;
3304 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3305 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3306 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3307 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3311 if gWater
<> nil then
3314 for a
:= 0 to High(gWater
) do
3316 if PanelType
<> 0 then
3318 // Ëåâûé âåðõíèé óãîë:
3319 aX
:= X
div ScaleSz
;
3320 aY
:= Y
div ScaleSz
;
3322 aX2
:= max(Width
div ScaleSz
, 1);
3323 aY2
:= max(Height
div ScaleSz
, 1);
3324 // Ïðàâûé íèæíèé óãîë:
3325 aX2
:= aX
+ aX2
- 1;
3326 aY2
:= aY
+ aY2
- 1;
3328 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3331 if gAcid1
<> nil then
3333 // Ðèñóåì êèñëîòó 1:
3334 for a
:= 0 to High(gAcid1
) do
3336 if PanelType
<> 0 then
3338 // Ëåâûé âåðõíèé óãîë:
3339 aX
:= X
div ScaleSz
;
3340 aY
:= Y
div ScaleSz
;
3342 aX2
:= max(Width
div ScaleSz
, 1);
3343 aY2
:= max(Height
div ScaleSz
, 1);
3344 // Ïðàâûé íèæíèé óãîë:
3345 aX2
:= aX
+ aX2
- 1;
3346 aY2
:= aY
+ aY2
- 1;
3348 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3351 if gAcid2
<> nil then
3353 // Ðèñóåì êèñëîòó 2:
3354 for a
:= 0 to High(gAcid2
) do
3356 if PanelType
<> 0 then
3358 // Ëåâûé âåðõíèé óãîë:
3359 aX
:= X
div ScaleSz
;
3360 aY
:= Y
div ScaleSz
;
3362 aX2
:= max(Width
div ScaleSz
, 1);
3363 aY2
:= max(Height
div ScaleSz
, 1);
3364 // Ïðàâûé íèæíèé óãîë:
3365 aX2
:= aX
+ aX2
- 1;
3366 aY2
:= aY
+ aY2
- 1;
3368 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3371 if gPlayers
<> nil then
3374 for a
:= 0 to High(gPlayers
) do
3375 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3377 // Ëåâûé âåðõíèé óãîë:
3378 aX
:= Obj
.X
div ScaleSz
+ 1;
3379 aY
:= Obj
.Y
div ScaleSz
+ 1;
3381 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3382 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3383 // Ïðàâûé íèæíèé óãîë:
3384 aX2
:= aX
+ aX2
- 1;
3385 aY2
:= aY
+ aY2
- 1;
3387 if gPlayers
[a
] = p
then
3388 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3391 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3392 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3393 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3398 g_Mons_ForEach(monDraw
);
3403 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3405 if not hasAmbient
then exit
;
3406 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3410 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3411 //FIXME: broken for splitscreen mode
3412 procedure renderDynLightsInternal ();
3414 //hasAmbient: Boolean;
3415 //ambColor: TDFColor;
3417 lx
, ly
, lrad
: Integer;
3418 scxywh
: array[0..3] of GLint
;
3421 if e_NoGraphics
then exit
;
3423 //TODO: lights should be in separate grid, i think
3424 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3425 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3428 //ambColor := gCurrentMap['light_ambient'].rgba;
3429 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3431 { // this will multiply incoming color to alpha from framebuffer
3433 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3437 * light rendering: (INVALID!)
3438 * glStencilFunc(GL_EQUAL, 0, $ff);
3440 * glClear(GL_STENCIL_BUFFER_BIT);
3441 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3442 * draw shadow volume into stencil buffer
3443 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3444 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3446 * draw color-less quad with light alpha (WARNING! don't touch color!)
3447 * glEnable(GL_BLEND);
3448 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3449 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3451 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3452 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3454 // setup OpenGL parameters
3455 glStencilMask($FFFFFFFF);
3456 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3457 glEnable(GL_STENCIL_TEST
);
3458 glEnable(GL_SCISSOR_TEST
);
3459 glClear(GL_STENCIL_BUFFER_BIT
);
3460 glStencilFunc(GL_EQUAL
, 0, $ff);
3462 for lln
:= 0 to g_dynLightCount
-1 do
3464 lx
:= g_dynLights
[lln
].x
;
3465 ly
:= g_dynLights
[lln
].y
;
3466 lrad
:= g_dynLights
[lln
].radius
;
3467 if (lrad
< 3) then continue
;
3469 if (lx
-sX
+lrad
< 0) then continue
;
3470 if (ly
-sY
+lrad
< 0) then continue
;
3471 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3472 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3474 // set scissor to optimize drawing
3475 if (g_dbg_scale
= 1.0) then
3477 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3481 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
3483 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3484 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3485 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3486 // draw extruded panels
3487 glDisable(GL_TEXTURE_2D
);
3488 glDisable(GL_BLEND
);
3489 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3490 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3491 // render light texture
3492 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3493 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3496 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3497 glEnable(GL_TEXTURE_2D
);
3498 // color and opacity
3499 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3500 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3502 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3503 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3504 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3505 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3510 glDisable(GL_STENCIL_TEST
);
3511 glDisable(GL_BLEND
);
3512 glDisable(GL_SCISSOR_TEST
);
3513 //glScissor(0, 0, sWidth, sHeight);
3515 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3516 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3520 function fixViewportForScale (): Boolean;
3522 nx0
, ny0
, nw
, nh
: Integer;
3525 if (g_dbg_scale
<> 1.0) then
3528 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3529 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3530 nw
:= round(sWidth
/g_dbg_scale
);
3531 nh
:= round(sHeight
/g_dbg_scale
);
3540 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3541 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3542 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3544 TDrawCB
= procedure ();
3547 hasAmbient
: Boolean;
3549 doAmbient
: Boolean = false;
3551 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3556 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3557 if gdbg_map_use_accel_render
then
3559 tagmask
:= panelTypeToTag(panType
);
3560 while (gDrawPanelList
.count
> 0) do
3562 pan
:= TPanel(gDrawPanelList
.front());
3563 if ((pan
.tag
and tagmask
) = 0) then break
;
3564 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3565 gDrawPanelList
.popFront();
3570 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3572 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3575 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3577 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3578 if assigned(cb
) then cb();
3579 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3583 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3585 // our accelerated renderer will collect all panels to gDrawPanelList
3586 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3587 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3588 if gdbg_map_use_accel_render
then
3590 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3592 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3594 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3595 g_Map_DrawBack(backXOfs
, backYOfs
);
3596 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3598 if setTransMatrix
then
3600 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3601 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3602 glTranslatef(-sX
, -sY
, 0);
3606 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3607 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3612 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3613 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3614 glClear(GL_COLOR_BUFFER_BIT);
3617 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3620 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3621 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3622 drawOther('items', @g_Items_Draw
);
3623 drawOther('weapons', @g_Weapon_Draw
);
3624 drawOther('shells', @g_Player_DrawShells
);
3625 drawOther('drawall', @g_Player_DrawAll
);
3626 drawOther('corpses', @g_Player_DrawCorpses
);
3627 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3628 drawOther('monsters', @g_Monsters_Draw
);
3629 drawOther('itemdrop', @g_Items_DrawDrop
);
3630 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3631 drawOther('gfx', @g_GFX_Draw
);
3632 drawOther('flags', @g_Map_DrawFlags
);
3633 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3634 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3635 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3636 drawOther('dynlights', @renderDynLightsInternal
);
3638 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3640 renderAmbientQuad(hasAmbient
, ambColor
);
3644 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3647 if g_debug_HealthBar
then
3649 g_Monsters_DrawHealth();
3650 g_Player_DrawHealth();
3653 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3657 procedure DrawMapView(x
, y
, w
, h
: Integer);
3664 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3665 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3672 fixViewportForScale();
3673 renderMapInternal(-bx
, -by
, true);
3679 procedure DrawPlayer(p
: TPlayer
);
3681 px
, py
, a
, b
, c
, d
, i
, fX
, fY
: Integer;
3685 if (p
= nil) or (p
.FDummy
) then
3688 g_Map_DrawBack(0, 0);
3693 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3694 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3700 camObj
:= p
.getCameraObj();
3701 camObj
.lerp(gLerpFactor
, fX
, fY
);
3702 px
:= fX
+ PLAYER_RECT_CX
;
3703 py
:= fY
+ PLAYER_RECT_CY
+nlerp(p
.SlopeOld
, camObj
.slopeUpLeft
, gLerpFactor
);
3705 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3707 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3708 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3710 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3711 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3713 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3714 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3717 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3720 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3721 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3724 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3729 // scaled, ignore level bounds
3730 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3731 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3736 sWidth
:= gPlayerScreenSize
.X
;
3737 sHeight
:= gPlayerScreenSize
.Y
;
3738 fixViewportForScale();
3740 i
:= py
- (sY
+ sHeight
div 2);
3741 if (p
.IncCam
> 0) then
3743 // clamp to level bounds
3744 if (sY
- p
.IncCam
< 0) then
3745 p
.IncCam
:= nclamp(sY
, 0, 120);
3746 // clamp around player position
3748 p
.IncCam
:= nclamp(p
.IncCam
, 0, max(0, 120 - i
));
3750 else if (p
.IncCam
< 0) then
3752 // clamp to level bounds
3753 if (sY
+ sHeight
- p
.IncCam
> gMapInfo
.Height
) then
3754 p
.IncCam
:= nclamp(sY
+ sHeight
- gMapInfo
.Height
, -120, 0);
3755 // clamp around player position
3757 p
.IncCam
:= nclamp(p
.IncCam
, min(0, -120 - i
), 0);
3760 sY
:= sY
- nlerp(p
.IncCamOld
, p
.IncCam
, gLerpFactor
);
3762 if (not g_dbg_ignore_bounds
) then
3764 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3765 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3766 if (sX
< 0) then sX
:= 0;
3767 if (sY
< 0) then sY
:= 0;
3770 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3771 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3773 //r_smallmap_h: 0: left; 1: center; 2: right
3774 //r_smallmap_v: 0: top; 1: center; 2: bottom
3776 if (gMapInfo
.Width
= sWidth
) then
3780 else if (gMapInfo
.Width
< sWidth
) then
3782 case r_smallmap_h
of
3783 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3784 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3785 else sX
:= 0; // left
3789 if (gMapInfo
.Height
= sHeight
) then
3793 else if (gMapInfo
.Height
< sHeight
) then
3795 case r_smallmap_v
of
3796 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3797 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3798 else sY
:= 0; // top
3804 p
.viewPortW
:= sWidth
;
3805 p
.viewPortH
:= sHeight
;
3807 {$IFDEF ENABLE_HOLMES}
3808 if (p
= gPlayer1
) then
3810 g_Holmes_plrViewPos(sX
, sY
);
3811 g_Holmes_plrViewSize(sWidth
, sHeight
);
3815 renderMapInternal(-c
, -d
, true);
3817 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3818 case gPlayerIndicator
of
3820 p
.DrawIndicator(_RGB(255, 255, 255));
3823 for i
:= 0 to High(gPlayers
) do
3824 if gPlayers
[i
] <> nil then
3825 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3826 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3827 if gPlayerIndicatorStyle
= 1 then
3828 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3829 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3833 for a := 0 to High(gCollideMap) do
3834 for b := 0 to High(gCollideMap[a]) do
3837 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3839 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3843 1: e_DrawPoint(1, b, a, 200, 200, 200);
3844 2: e_DrawPoint(1, b, a, 64, 64, 255);
3845 3: e_DrawPoint(1, b, a, 255, 0, 255);
3855 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3856 if g_Debug_Player
then
3857 g_Player_DrawDebug(p
);
3861 procedure drawProfilers ();
3866 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3867 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3868 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3871 procedure g_Game_Draw();
3878 plView1
, plView2
: TPlayer
;
3881 if gExit
= EXIT_QUIT
then Exit
;
3883 Time
:= sys_GetTicks() {div 1000};
3884 FPSCounter
:= FPSCounter
+1;
3885 if Time
- FPSTime
>= 1000 then
3892 e_SetRendertarget(True);
3893 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3895 if gGameOn
or (gState
= STATE_FOLD
) then
3897 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3899 gSpectMode
:= SPECT_NONE
;
3900 if not gRevertPlayers
then
3902 plView1
:= gPlayer1
;
3903 plView2
:= gPlayer2
;
3907 plView1
:= gPlayer2
;
3908 plView2
:= gPlayer1
;
3912 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3914 gSpectMode
:= SPECT_NONE
;
3915 if gPlayer2
= nil then
3918 plView1
:= gPlayer2
;
3927 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3928 gSpectMode
:= SPECT_STATS
;
3930 if gSpectMode
= SPECT_PLAYERS
then
3931 if gPlayers
<> nil then
3933 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3934 if plView1
= nil then
3936 gSpectPID1
:= GetActivePlayerID_Next();
3937 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3939 if gSpectViewTwo
then
3941 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3942 if plView2
= nil then
3944 gSpectPID2
:= GetActivePlayerID_Next();
3945 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3950 if gSpectMode
= SPECT_MAPVIEW
then
3952 // Ðåæèì ïðîñìîòðà êàðòû
3954 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3955 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3956 gHearPoint1
.Active
:= True;
3957 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3958 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3959 gHearPoint2
.Active
:= False;
3963 Split
:= (plView1
<> nil) and (plView2
<> nil);
3965 // Òî÷êè ñëóõà èãðîêîâ
3966 if plView1
<> nil then
3968 gHearPoint1
.Active
:= True;
3969 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3970 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3972 gHearPoint1
.Active
:= False;
3973 if plView2
<> nil then
3975 gHearPoint2
.Active
:= True;
3976 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3977 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3979 gHearPoint2
.Active
:= False;
3981 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3982 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3985 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3986 if gScreenHeight
mod 2 = 0 then
3987 Dec(gPlayerScreenSize
.Y
);
3990 gPlayerScreenSize
.Y
:= gScreenHeight
;
3993 if gScreenHeight
mod 2 = 0 then
3994 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3996 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3998 DrawPlayer(plView1
);
3999 gPlayer1ScreenCoord
.X
:= sX
;
4000 gPlayer1ScreenCoord
.Y
:= sY
;
4004 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
4006 DrawPlayer(plView2
);
4007 gPlayer2ScreenCoord
.X
:= sX
;
4008 gPlayer2ScreenCoord
.Y
:= sY
;
4011 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
4014 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
4017 {$IFDEF ENABLE_HOLMES}
4019 if (g_holmes_enabled
) then g_Holmes_Draw();
4022 if MessageText
<> '' then
4026 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
4028 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4029 (gScreenHeight
div 2)-(h
div 2), MessageText
)
4031 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4032 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
4035 if IsDrawStat
or (gSpectMode
= SPECT_STATS
) then
4038 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
4040 // Draw spectator GUI
4043 e_TextureFontGetSize(gStdFont
, ww
, hh
);
4046 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
4048 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
4050 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
4052 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
4053 if gSpectMode
= SPECT_STATS
then
4055 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
4056 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
4058 if gSpectMode
= SPECT_MAPVIEW
then
4060 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
4061 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
4062 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
4063 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
4064 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
4066 if gSpectMode
= SPECT_PLAYERS
then
4068 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
4069 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
4070 if gSpectViewTwo
then
4072 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
4073 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
4074 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4075 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4079 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
4080 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
4086 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
4088 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4089 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4091 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
4092 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
4093 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
4098 if (gState
= STATE_MENU
) then
4100 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
4101 // F3 at menu will show game loading dialog
4102 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
4103 if (g_ActiveWindow
<> nil) then
4105 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4106 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4110 // F3 at titlepic will show game loading dialog
4111 if e_KeyPressed(IK_F3
) then
4113 g_Menu_Show_LoadMenu(true);
4114 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4119 if gState
= STATE_FOLD
then
4121 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4124 if gState
= STATE_INTERCUSTOM
then
4126 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
4128 back
:= 'TEXTURE_endpic';
4129 if not g_Texture_Get(back
, ID
) then
4130 back
:= _lc
[I_TEXTURE_ENDPIC
];
4135 DrawMenuBackground(back
);
4139 if g_ActiveWindow
<> nil then
4141 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4142 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4146 if gState
= STATE_INTERSINGLE
then
4148 if EndingGameCounter
> 0 then
4150 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4156 DrawMenuBackground(back
);
4160 if g_ActiveWindow
<> nil then
4162 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4163 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4168 if gState
= STATE_ENDPIC
then
4171 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4172 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4174 if g_ActiveWindow
<> nil then
4176 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4177 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4181 if gState
= STATE_SLIST
then
4183 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4185 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4186 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4188 DrawMenuBackground('MENU_BACKGROUND');
4189 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4190 g_Serverlist_Draw(slCurrent
, slTable
);
4194 if g_ActiveWindow
<> nil then
4198 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4199 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4201 g_ActiveWindow
.Draw();
4208 if g_debug_Sounds
and gGameOn
then
4210 for w
:= 0 to High(e_SoundsArray
) do
4211 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4212 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4217 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4218 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4221 if gGameOn
and gShowTime
then
4222 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4224 if gGameOn
then drawProfilers();
4226 // TODO: draw this after the FBO and remap mouse click coordinates
4228 {$IFDEF ENABLE_HOLMES}
4232 // blit framebuffer to screen
4234 e_SetRendertarget(False);
4235 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
4236 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
4238 // draw the overlay stuff on top of it
4243 procedure g_Game_Quit();
4245 g_Game_StopAllSounds(True);
4248 g_PlayerModel_FreeData();
4249 g_Texture_DeleteAll();
4250 g_Frames_DeleteAll();
4252 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4255 if NetInitDone
then g_Net_Free
;
4257 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4258 if gMapToDelete
<> '' then
4259 g_Game_DeleteTestMap();
4265 procedure g_FatalError(Text: String);
4267 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4268 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4270 gExit
:= EXIT_SIMPLE
;
4271 if gGameOn
then EndGame
;
4274 procedure g_SimpleError(Text: String);
4276 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4277 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4280 procedure g_Game_SetupScreenSize();
4282 RES_FACTOR
= 4.0 / 3.0;
4288 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4289 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4290 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4291 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4293 gPlayerScreenSize
.Y
:= gScreenHeight
;
4295 // Ðàçìåð çàäíåãî ïëàíà:
4296 if BackID
<> DWORD(-1) then
4299 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4300 (gScreenHeight
*s
> gMapInfo
.Height
) then
4302 gBackSize
.X
:= gScreenWidth
;
4303 gBackSize
.Y
:= gScreenHeight
;
4307 e_GetTextureSize(BackID
, @bw
, @bh
);
4308 rf
:= Single(bw
) / Single(bh
);
4309 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4310 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4311 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4312 if (s
< 1.0) then s
:= 1.0;
4313 gBackSize
.X
:= Round(bw
*s
);
4314 gBackSize
.Y
:= Round(bh
*s
);
4319 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4321 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
4324 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4326 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4327 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4330 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
4333 if gPlayer1
= nil then
4335 if g_Game_IsClient
then
4337 if NetPlrUID1
> -1 then
4338 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4342 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4343 Team
:= gPlayer1Settings
.Team
;
4345 // Ñîçäàíèå ïåðâîãî èãðîêà:
4346 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4347 gPlayer1Settings
.Color
,
4349 if gPlayer1
= nil then
4350 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4353 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4354 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4355 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4356 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4357 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4358 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4359 if g_Game_IsServer
and g_Game_IsNet
then
4360 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4361 gPlayer1
.Respawn(False, True);
4362 g_Net_Slist_ServerPlayerComes();
4367 if gPlayer2
= nil then
4369 if g_Game_IsClient
then
4371 if NetPlrUID2
> -1 then
4372 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4376 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4377 Team
:= gPlayer2Settings
.Team
;
4379 // Ñîçäàíèå âòîðîãî èãðîêà:
4380 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4381 gPlayer2Settings
.Color
,
4383 if gPlayer2
= nil then
4384 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4387 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4388 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4389 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4390 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4391 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4392 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4393 if g_Game_IsServer
and g_Game_IsNet
then
4394 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4395 gPlayer2
.Respawn(False, True);
4396 g_Net_Slist_ServerPlayerComes();
4403 procedure g_Game_RemovePlayer();
4407 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4408 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4413 if g_Game_IsServer
then
4416 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4417 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4418 g_Player_Remove(Pl
.UID
);
4419 g_Net_Slist_ServerPlayerLeaves();
4423 gSpectLatchPID2
:= Pl
.UID
;
4431 if g_Game_IsServer
then
4434 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4435 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4436 g_Player_Remove(Pl
.UID
);
4437 g_Net_Slist_ServerPlayerLeaves();
4440 gSpectLatchPID1
:= Pl
.UID
;
4442 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4446 g_Net_Slist_ServerPlayerLeaves();
4449 procedure g_Game_Spectate();
4451 g_Game_RemovePlayer();
4452 if gPlayer1
<> nil then
4453 g_Game_RemovePlayer();
4456 procedure g_Game_SpectateCenterView();
4458 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4459 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4462 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4469 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4471 g_Game_ClearLoading();
4474 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4477 gGameSettings
.GameType
:= GT_SINGLE
;
4478 gGameSettings
.MaxLives
:= 0;
4479 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4480 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4481 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4482 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4483 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4484 gSwitchGameMode
:= GM_SINGLE
;
4486 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4487 gLMSRespawnTime
:= 0;
4488 gSpectLatchPID1
:= 0;
4489 gSpectLatchPID2
:= 0;
4491 g_Game_ExecuteEvent('ongamestart');
4493 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4494 g_Game_SetupScreenSize();
4496 // Ñîçäàíèå ïåðâîãî èãðîêà:
4497 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4498 gPlayer1Settings
.Color
,
4499 gPlayer1Settings
.Team
, False));
4500 if gPlayer1
= nil then
4502 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4506 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4507 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4508 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4509 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4510 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4513 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4516 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4517 gPlayer2Settings
.Color
,
4518 gPlayer2Settings
.Team
, False));
4519 if gPlayer2
= nil then
4521 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4525 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4526 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4527 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4528 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4529 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4533 // Çàãðóçêà è çàïóñê êàðòû:
4534 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4536 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4537 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4541 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4545 for i
:= nPl
+1 to nPlayers
do
4546 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4549 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4550 TimeLimit
, GoalLimit
: Word;
4552 Options
: LongWord; nPlayers
: Byte);
4558 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4560 g_Game_ClearLoading();
4563 gGameSettings
.GameType
:= GT_CUSTOM
;
4564 gGameSettings
.GameMode
:= GameMode
;
4565 gSwitchGameMode
:= GameMode
;
4566 gGameSettings
.TimeLimit
:= TimeLimit
;
4567 gGameSettings
.GoalLimit
:= GoalLimit
;
4568 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4569 gGameSettings
.Options
:= Options
;
4571 gCoopTotalMonstersKilled
:= 0;
4572 gCoopTotalSecretsFound
:= 0;
4573 gCoopTotalMonsters
:= 0;
4574 gCoopTotalSecrets
:= 0;
4578 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4579 gLMSRespawnTime
:= 0;
4580 gSpectLatchPID1
:= 0;
4581 gSpectLatchPID2
:= 0;
4583 g_Game_ExecuteEvent('ongamestart');
4585 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4586 g_Game_SetupScreenSize();
4588 // Ðåæèì íàáëþäàòåëÿ:
4589 if nPlayers
= 0 then
4596 if nPlayers
>= 1 then
4598 // Ñîçäàíèå ïåðâîãî èãðîêà:
4599 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4600 gPlayer1Settings
.Color
,
4601 gPlayer1Settings
.Team
, False));
4602 if gPlayer1
= nil then
4604 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4608 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4609 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4610 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4611 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4612 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4616 if nPlayers
>= 2 then
4618 // Ñîçäàíèå âòîðîãî èãðîêà:
4619 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4620 gPlayer2Settings
.Color
,
4621 gPlayer2Settings
.Team
, False));
4622 if gPlayer2
= nil then
4624 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4628 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4629 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4630 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4631 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4632 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4636 // Çàãðóçêà è çàïóñê êàðòû:
4637 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4639 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4643 // Íåò òî÷åê ïîÿâëåíèÿ:
4644 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4645 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4646 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4647 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4648 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4650 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4654 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4658 for i
:= nPl
+1 to nPlayers
do
4659 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4662 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4663 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4664 Options
: LongWord; nPlayers
: Byte;
4665 IPAddr
: LongWord; Port
: Word);
4668 g_Net_Slist_ServerClosed();
4670 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4672 g_Game_ClearLoading();
4675 gGameSettings
.GameType
:= GT_SERVER
;
4676 gGameSettings
.GameMode
:= GameMode
;
4677 gSwitchGameMode
:= GameMode
;
4678 gGameSettings
.TimeLimit
:= TimeLimit
;
4679 gGameSettings
.GoalLimit
:= GoalLimit
;
4680 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4681 gGameSettings
.Options
:= Options
;
4683 gCoopTotalMonstersKilled
:= 0;
4684 gCoopTotalSecretsFound
:= 0;
4685 gCoopTotalMonsters
:= 0;
4686 gCoopTotalSecrets
:= 0;
4690 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4691 gLMSRespawnTime
:= 0;
4692 gSpectLatchPID1
:= 0;
4693 gSpectLatchPID2
:= 0;
4695 g_Game_ExecuteEvent('ongamestart');
4697 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4698 g_Game_SetupScreenSize();
4700 // Ðåæèì íàáëþäàòåëÿ:
4701 if nPlayers
= 0 then
4707 if nPlayers
>= 1 then
4709 // Ñîçäàíèå ïåðâîãî èãðîêà:
4710 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4711 gPlayer1Settings
.Color
,
4712 gPlayer1Settings
.Team
, False));
4713 if gPlayer1
= nil then
4715 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4719 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4720 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4721 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4722 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4723 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4726 if nPlayers
>= 2 then
4728 // Ñîçäàíèå âòîðîãî èãðîêà:
4729 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4730 gPlayer2Settings
.Color
,
4731 gPlayer2Settings
.Team
, False));
4732 if gPlayer2
= nil then
4734 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4738 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4739 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4740 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4741 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4742 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
4745 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4746 if NetForwardPorts
then
4747 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4750 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4752 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4756 g_Net_Slist_Set(NetMasterList
);
4758 g_Net_Slist_ServerStarted();
4760 // Çàãðóçêà è çàïóñê êàðòû:
4761 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4763 g_Net_Slist_ServerClosed();
4764 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4768 // Íåò òî÷åê ïîÿâëåíèÿ:
4769 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4770 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4771 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4772 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4773 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4775 g_Net_Slist_ServerClosed();
4776 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4780 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4783 g_Net_Slist_ServerMapStarted();
4784 NetState
:= NET_STATE_GAME
;
4787 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4802 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4803 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4805 g_Game_ClearLoading();
4808 gGameSettings
.GameType
:= GT_CLIENT
;
4810 gCoopTotalMonstersKilled
:= 0;
4811 gCoopTotalSecretsFound
:= 0;
4812 gCoopTotalMonsters
:= 0;
4813 gCoopTotalSecrets
:= 0;
4817 g_Game_ExecuteEvent('ongamestart');
4819 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4820 g_Game_SetupScreenSize();
4822 NetState
:= NET_STATE_AUTH
;
4824 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4826 // create (or update) map/resource databases
4827 g_Res_CreateDatabases(true);
4829 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4830 gLMSRespawnTime
:= 0;
4831 gSpectLatchPID1
:= 0;
4832 gSpectLatchPID2
:= 0;
4835 if not g_Net_Connect(Addr
, Port
) then
4837 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4838 NetState
:= NET_STATE_NONE
;
4842 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4844 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4849 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4850 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4851 // thank you, enet. let's ignore failures altogether then.
4852 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4854 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4856 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4858 // ignore all download packets, they're processed by separate code
4859 enet_packet_destroy(NetEvent
.packet
);
4862 Ptr
:= NetEvent
.packet
^.data
;
4863 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4865 enet_packet_destroy(NetEvent
.packet
);
4869 InMsg
.ReadLongWord(); // skip size
4870 MID
:= InMsg
.ReadByte();
4872 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4874 NetMyID
:= InMsg
.ReadByte();
4875 NetPlrUID1
:= InMsg
.ReadWord();
4877 WadName
:= InMsg
.ReadString();
4878 Map
:= InMsg
.ReadString();
4880 gWADHash
:= InMsg
.ReadMD5();
4882 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4883 gSwitchGameMode
:= gGameSettings
.GameMode
;
4884 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4885 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4886 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4887 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4888 T
:= InMsg
.ReadLongWord();
4890 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4891 //if newResPath = '' then
4893 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4894 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4895 if newResPath
= '' then
4897 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4898 enet_packet_destroy(NetEvent
.packet
);
4899 NetState
:= NET_STATE_NONE
;
4902 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4904 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4907 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4908 gPlayer1Settings
.Color
,
4909 gPlayer1Settings
.Team
, False));
4911 if gPlayer1
= nil then
4913 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4915 enet_packet_destroy(NetEvent
.packet
);
4916 NetState
:= NET_STATE_NONE
;
4920 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4921 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4922 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4923 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4924 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
4925 gPlayer1
.UID
:= NetPlrUID1
;
4926 gPlayer1
.Reset(True);
4928 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4930 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4932 enet_packet_destroy(NetEvent
.packet
);
4933 NetState
:= NET_STATE_NONE
;
4941 enet_packet_destroy(NetEvent
.packet
);
4945 enet_packet_destroy(NetEvent
.packet
);
4949 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4952 if (NetEvent
.data
<= NET_DISC_MAX
) then
4953 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4954 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4961 ProcessLoading(true);
4963 if g_Net_UserRequestExit() then
4972 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4973 NetState
:= NET_STATE_NONE
;
4978 NetState
:= NET_STATE_GAME
;
4979 MC_SEND_FullStateRequest
;
4980 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4984 lastAsMegaWad
: Boolean = false;
4986 procedure g_Game_ChangeMap(const MapPath
: String);
4990 g_Game_ClearLoading();
4992 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4993 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4994 if gExitByTrigger
then
4997 gExitByTrigger
:= False;
4999 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
5000 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
5003 procedure g_Game_Restart();
5007 if g_Game_IsClient
then
5009 map
:= g_ExtractFileName(gMapInfo
.Map
);
5010 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
5014 g_Game_ClearLoading();
5015 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
5018 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
5020 NewWAD
, ResName
: String;
5024 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
5025 g_Player_RemoveAllCorpses();
5027 if (not g_Game_IsClient
) and
5028 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
5029 (gGameSettings
.GameMode
<> GM_SINGLE
) then
5031 if gSwitchGameMode
= GM_CTF
then
5032 gGameSettings
.MaxLives
:= 0;
5033 gGameSettings
.GameMode
:= gSwitchGameMode
;
5036 gSwitchGameMode
:= gGameSettings
.GameMode
;
5038 g_Player_ResetTeams();
5040 lastAsMegaWad
:= asMegawad
;
5041 if isWadPath(Map
) then
5043 NewWAD
:= g_ExtractWadName(Map
);
5044 ResName
:= g_ExtractFileName(Map
);
5045 if g_Game_IsServer
then
5047 nws
:= findDiskWad(NewWAD
);
5048 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5051 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5052 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5056 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5057 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5059 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5060 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5062 if (length(nws
) = 0) then
5064 ResName
:= ''; // failed
5069 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5070 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5071 g_Game_LoadWAD(NewWAD
);
5076 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5077 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5082 NewWAD
:= gGameSettings
.WAD
;
5088 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5090 if (ResName
<> '') and (NewWAD
<> '') then
5092 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5093 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5097 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5099 gState
:= STATE_NONE
;
5100 g_ActiveWindow
:= nil;
5106 if gGameSettings
.GameMode
= GM_CTF
then
5108 g_Map_ResetFlag(FLAG_RED
);
5109 g_Map_ResetFlag(FLAG_BLUE
);
5110 // CTF, à ôëàãîâ íåò:
5111 if not g_Map_HaveFlagPoints() then
5112 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5117 gState
:= STATE_MENU
;
5122 gPauseMain
:= false;
5123 gPauseHolmes
:= false;
5124 NetTimeToUpdate
:= 1;
5125 NetTimeToReliable
:= 0;
5126 NetTimeToMaster
:= NetMasterRate
;
5127 gSpectLatchPID1
:= 0;
5128 gSpectLatchPID2
:= 0;
5129 gMissionFailed
:= False;
5132 gCoopMonstersKilled
:= 0;
5133 gCoopSecretsFound
:= 0;
5135 gVoteInProgress
:= False;
5136 gVotePassed
:= False;
5142 if not gGameOn
then Exit
;
5144 g_Game_SpectateCenterView();
5146 if g_Game_IsServer
then
5148 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5150 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5151 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5152 gLMSSoftSpawn
:= True;
5153 if g_Game_IsNet
then
5154 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5158 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5159 gLMSRespawnTime
:= 0;
5163 if NetMode
= NET_SERVER
then
5165 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5168 g_Net_Slist_ServerMapStarted();
5170 if NetClients
<> nil then
5171 for I
:= 0 to High(NetClients
) do
5172 if NetClients
[I
].Used
then
5174 NetClients
[I
].Voted
:= False;
5175 if NetClients
[I
].RequestedFullUpdate
then
5177 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5178 NetClients
[I
].RequestedFullUpdate
:= False;
5182 g_Net_UnbanNonPermHosts();
5187 gCoopTotalMonstersKilled
:= 0;
5188 gCoopTotalSecretsFound
:= 0;
5189 gCoopTotalMonsters
:= 0;
5190 gCoopTotalSecrets
:= 0;
5194 g_Game_ExecuteEvent('onmapstart');
5197 procedure SetFirstLevel
;
5201 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5202 if MapList
= nil then
5205 SortSArray(MapList
);
5206 gNextMap
:= MapList
[Low(MapList
)];
5211 procedure g_Game_ExitLevel(const Map
: AnsiString);
5215 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5216 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5217 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5218 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5220 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5221 if gGameSettings
.GameType
= GT_SINGLE
then
5222 gExit
:= EXIT_ENDLEVELSINGLE
5223 else // Âûøëè â âûõîä â Ñâîåé èãðå
5225 gExit
:= EXIT_ENDLEVELCUSTOM
;
5226 if gGameSettings
.GameMode
= GM_COOP
then
5227 g_Player_RememberAll
;
5229 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5232 if gGameSettings
.GameMode
= GM_COOP
then
5235 gStatsPressed
:= True;
5236 gNextMap
:= 'MAP01';
5238 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5241 if g_Game_IsNet
then
5243 MH_SEND_GameStats();
5244 MH_SEND_CoopStats();
5250 procedure g_Game_RestartLevel();
5254 if gGameSettings
.GameMode
= GM_SINGLE
then
5259 gExit
:= EXIT_ENDLEVELCUSTOM
;
5260 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5264 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5266 gWAD
{, xwad}: String;
5269 if not g_Game_IsClient
then Exit
;
5270 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5272 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5277 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5281 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5284 g_Game_LoadWAD(NewWAD
);
5288 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5289 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5292 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5293 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5297 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5301 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5302 g_Game_LoadWAD(NewWAD);
5306 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5308 i
, n
, nb
, nr
: Integer;
5310 if not g_Game_IsServer
then Exit
;
5311 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5312 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5313 gLMSRespawnTime
:= 0;
5316 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5318 gMissionFailed
:= True;
5319 g_Game_RestartLevel
;
5323 n
:= 0; nb
:= 0; nr
:= 0;
5324 for i
:= Low(gPlayers
) to High(gPlayers
) do
5325 if (gPlayers
[i
] <> nil) and
5326 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5327 (gPlayers
[i
] is TBot
)) then
5330 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5331 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5334 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5336 // wait a second until the fuckers finally decide to join
5337 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5338 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5339 gLMSSoftSpawn
:= NoMapRestart
;
5340 if g_Game_IsNet
then
5341 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5345 g_Player_RemoveAllCorpses
;
5346 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5347 if g_Game_IsNet
then
5348 MH_SEND_GameEvent(NET_EV_LMS_START
);
5350 for i
:= Low(gPlayers
) to High(gPlayers
) do
5352 if gPlayers
[i
] = nil then continue
;
5353 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5354 // don't touch normal spectators
5355 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5357 gPlayers
[i
].FNoRespawn
:= True;
5358 gPlayers
[i
].Lives
:= 0;
5359 if g_Game_IsNet
then
5360 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5363 gPlayers
[i
].FNoRespawn
:= False;
5364 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5365 gPlayers
[i
].Respawn(False, True);
5366 if gGameSettings
.GameMode
= GM_COOP
then
5368 gPlayers
[i
].Frags
:= 0;
5369 gPlayers
[i
].RecallState
;
5371 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5372 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5373 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5374 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5377 g_Items_RestartRound();
5379 gLMSSoftSpawn
:= False;
5382 function g_Game_GetFirstMap(WAD
: String): String;
5386 MapList
:= g_Map_GetMapsList(WAD
);
5387 if MapList
= nil then
5390 SortSArray(MapList
);
5391 Result
:= MapList
[Low(MapList
)];
5393 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5399 function g_Game_GetNextMap(): String;
5406 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5407 if MapList
= nil then
5410 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5412 SortSArray(MapList
);
5414 for I
:= Low(MapList
) to High(MapList
) do
5415 if Map
= MapList
[I
] then
5421 if MapIndex
<> -255 then
5423 if MapIndex
= High(MapList
) then
5424 Result
:= MapList
[Low(MapList
)]
5426 Result
:= MapList
[MapIndex
+ 1];
5428 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5434 procedure g_Game_NextLevel();
5436 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5437 gExit
:= EXIT_ENDLEVELCUSTOM
5440 gExit
:= EXIT_ENDLEVELSINGLE
;
5444 if gNextMap
<> '' then Exit
;
5445 gNextMap
:= g_Game_GetNextMap();
5448 function g_Game_IsTestMap(): Boolean;
5450 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5453 procedure g_Game_DeleteTestMap();
5456 //MapName: AnsiString;
5464 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5465 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5466 if (a
= 0) then exit
;
5468 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5469 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5470 Delete(gMapToDelete
, 1, a
+5);
5471 gMapToDelete
:= UpperCase(gMapToDelete
);
5473 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5476 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5477 if MapName <> TEST_MAP_NAME then
5480 if not gTempDelete then
5482 time := g_GetFileTime(WadName);
5483 WAD := TWADFile.Create();
5486 if not WAD.ReadFile(WadName) then
5487 begin // Íåò òàêîãî WAD-ôàéëà
5492 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5494 MapList := WAD.GetResourcesList('');
5496 if MapList <> nil then
5497 for a := 0 to High(MapList) do
5498 if MapList[a] = MapName then
5500 // Óäàëÿåì è ñîõðàíÿåì:
5501 WAD.RemoveResource('', MapName);
5502 WAD.SaveTo(WadName);
5507 g_SetFileTime(WadName, time);
5510 if gTempDelete
then DeleteFile(WadName
);
5513 procedure GameCVars(P
: SSArray
);
5516 stat
: TPlayerStatArray
;
5519 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5523 if Length(P
) > 1 then
5528 gsGameFlags
:= gsGameFlags
or Flag
5530 gsGameFlags
:= gsGameFlags
and (not Flag
);
5532 if g_Game_IsServer
then
5535 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5537 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5538 if g_Game_IsNet
then MH_SEND_GameSettings
;
5542 if LongBool(gsGameFlags
and Flag
) then
5543 g_Console_Add(_lc
[OnMsg
])
5545 g_Console_Add(_lc
[OffMsg
]);
5547 if OnMapChange
and g_Game_IsServer
then
5548 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5553 cmd
:= LowerCase(P
[0]);
5555 if cmd
= 'g_gamemode' then
5557 if (Length(P
) > 1) then
5559 a
:= g_Game_TextToMode(P
[1]);
5560 if a
= GM_SINGLE
then a
:= GM_COOP
;
5561 gsGameMode
:= g_Game_ModeToText(a
);
5562 if g_Game_IsServer
then
5564 gSwitchGameMode
:= a
;
5565 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5566 (gState
= STATE_INTERSINGLE
) then
5567 gSwitchGameMode
:= GM_SINGLE
;
5569 gGameSettings
.GameMode
:= gSwitchGameMode
;
5573 if gSwitchGameMode
= gGameSettings
.GameMode
then
5574 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5575 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5577 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5578 [g_Game_ModeToText(gGameSettings
.GameMode
),
5579 g_Game_ModeToText(gSwitchGameMode
)]));
5581 else if cmd
= 'g_friendlyfire' then
5583 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5585 else if cmd
= 'g_friendly_absorb_damage' then
5587 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5589 else if cmd
= 'g_friendly_hit_trace' then
5591 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5593 else if cmd
= 'g_friendly_hit_projectile' then
5595 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5597 else if cmd
= 'g_weaponstay' then
5599 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5601 else if cmd
= 'g_allow_exit' then
5603 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5605 else if cmd
= 'g_allow_monsters' then
5607 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5609 else if cmd
= 'g_allow_dropflag' then
5611 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5613 else if cmd
= 'g_throw_flag' then
5615 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5617 else if cmd
= 'g_bot_vsplayers' then
5619 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5621 else if cmd
= 'g_bot_vsmonsters' then
5623 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5625 else if cmd
= 'g_dm_keys' then
5627 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5629 else if cmd
= 'g_gameflags' then
5631 if Length(P
) > 1 then
5633 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5634 if g_Game_IsServer
then
5636 gGameSettings
.Options
:= gsGameFlags
;
5637 if g_Game_IsNet
then MH_SEND_GameSettings
;
5641 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5643 else if cmd
= 'g_warmup_time' then
5645 if Length(P
) > 1 then
5647 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5648 if g_Game_IsServer
then
5650 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5651 // extend warmup if it's already going
5652 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5654 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5655 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5657 if g_Game_IsNet
then MH_SEND_GameSettings
;
5661 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5662 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5664 else if cmd
= 'g_spawn_invul' then
5666 if Length(P
) > 1 then
5668 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5669 if g_Game_IsServer
then
5671 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5672 if g_Game_IsNet
then MH_SEND_GameSettings
;
5676 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5678 else if cmd
= 'g_item_respawn_time' then
5680 if Length(P
) > 1 then
5682 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5683 if g_Game_IsServer
then
5685 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5686 if g_Game_IsNet
then MH_SEND_GameSettings
;
5690 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5691 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5693 else if cmd
= 'sv_intertime' then
5695 if (Length(P
) > 1) then
5696 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5698 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5700 else if cmd
= 'g_max_particles' then
5702 if Length(p
) = 2 then
5704 a
:= Max(0, StrToIntDef(p
[1], 0));
5707 else if Length(p
) = 1 then
5709 e_LogWritefln('%s', [g_GFX_GetMax()])
5713 e_LogWritefln('usage: %s <n>', [cmd
])
5716 else if cmd
= 'g_max_shells' then
5718 if Length(p
) = 2 then
5720 a
:= Max(0, StrToIntDef(p
[1], 0));
5723 else if Length(p
) = 1 then
5725 e_LogWritefln('%s', [g_Shells_GetMax()])
5729 e_LogWritefln('usage: %s <n>', [cmd
])
5732 else if cmd
= 'g_max_gibs' then
5734 if Length(p
) = 2 then
5736 a
:= Max(0, StrToIntDef(p
[1], 0));
5739 else if Length(p
) = 1 then
5741 e_LogWritefln('%s', [g_Gibs_GetMax()])
5745 e_LogWritefln('usage: %s <n>', [cmd
])
5748 else if cmd
= 'g_max_corpses' then
5750 if Length(p
) = 2 then
5752 a
:= Max(0, StrToIntDef(p
[1], 0));
5755 else if Length(p
) = 1 then
5757 e_LogWritefln('%s', [g_Corpses_GetMax()])
5761 e_LogWritefln('usage: %s <n>', [cmd
])
5764 else if cmd
= 'g_scorelimit' then
5766 if Length(P
) > 1 then
5768 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5770 if g_Game_IsServer
then
5773 if gGameSettings
.GameMode
= GM_DM
then
5775 stat
:= g_Player_GetStats();
5777 for a
:= 0 to High(stat
) do
5778 if stat
[a
].Frags
> b
then
5782 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5784 // if someone has a higher score, set it to that instead
5785 gsGoalLimit
:= max(gsGoalLimit
, b
);
5786 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5788 if g_Game_IsNet
then MH_SEND_GameSettings
;
5792 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5794 else if cmd
= 'g_timelimit' then
5796 if Length(P
) > 1 then
5798 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5799 if g_Game_IsServer
then
5801 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5802 if g_Game_IsNet
then MH_SEND_GameSettings
;
5805 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5806 [gsTimeLimit
div 3600,
5807 (gsTimeLimit
div 60) mod 60,
5808 gsTimeLimit
mod 60]));
5810 else if cmd
= 'g_maxlives' then
5812 if Length(P
) > 1 then
5814 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5815 if g_Game_IsServer
then
5817 gGameSettings
.MaxLives
:= gsMaxLives
;
5818 if g_Game_IsNet
then MH_SEND_GameSettings
;
5822 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5826 procedure PlayerSettingsCVars(P
: SSArray
);
5831 function ParseTeam(s
: string): Byte;
5835 'red', '1': result
:= TEAM_RED
;
5836 'blue', '2': result
:= TEAM_BLUE
;
5837 else result
:= TEAM_NONE
;
5841 cmd
:= LowerCase(P
[0]);
5845 if (Length(P
) > 1) then
5847 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5848 if g_Game_IsClient
then
5849 MC_SEND_PlayerSettings
5850 else if gGameOn
and (gPlayer1
<> nil) then
5852 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5853 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5859 if (Length(P
) > 1) then
5861 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5862 if g_Game_IsClient
then
5863 MC_SEND_PlayerSettings
5864 else if gGameOn
and (gPlayer2
<> nil) then
5866 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5867 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5873 if Length(P
) > 3 then
5875 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5876 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5877 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5878 if g_Game_IsClient
then
5879 MC_SEND_PlayerSettings
5880 else if gGameOn
and (gPlayer1
<> nil) then
5882 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5883 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5889 if Length(P
) > 3 then
5891 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5892 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5893 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5894 if g_Game_IsClient
then
5895 MC_SEND_PlayerSettings
5896 else if gGameOn
and (gPlayer2
<> nil) then
5898 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5899 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5905 if (Length(P
) > 1) then
5907 gPlayer1Settings
.Model
:= P
[1];
5908 if g_Game_IsClient
then
5909 MC_SEND_PlayerSettings
5910 else if gGameOn
and (gPlayer1
<> nil) then
5912 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5913 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5914 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5920 if (Length(P
) > 1) then
5922 gPlayer2Settings
.Model
:= P
[1];
5923 if g_Game_IsClient
then
5924 MC_SEND_PlayerSettings
5925 else if gGameOn
and (gPlayer2
<> nil) then
5927 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5928 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5929 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5935 // TODO: switch teams if in game or store this separately
5936 if (Length(P
) > 1) then
5938 team
:= ParseTeam(P
[1]);
5939 if team
= TEAM_NONE
then
5940 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5941 else if not gGameOn
and not g_Game_IsNet
then
5942 gPlayer1Settings
.Team
:= team
5944 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5949 // TODO: switch teams if in game or store this separately
5950 if (Length(P
) > 1) then
5952 team
:= ParseTeam(P
[1]);
5953 if team
= TEAM_NONE
then
5954 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5955 else if not gGameOn
and not g_Game_IsNet
then
5956 gPlayer2Settings
.Team
:= team
5958 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5963 if (Length(P
) = 2) then
5964 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
5968 if (Length(P
) = 2) then
5969 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
5973 if (Length(P
) = 2) then
5974 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5978 if (Length(P
) = 2) then
5979 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5983 if (Length(P
) = 2) then
5984 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5988 if (Length(P
) = 2) then
5989 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5991 'p1_priority_kastet':
5993 if (Length(P
) = 2) then
5994 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
5996 'p2_priority_kastet':
5998 if (Length(P
) = 2) then
5999 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6003 if (Length(P
) = 2) then
6004 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6008 if (Length(P
) = 2) then
6009 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6011 'p1_priority_pistol':
6013 if (Length(P
) = 2) then
6014 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6016 'p2_priority_pistol':
6018 if (Length(P
) = 2) then
6019 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6021 'p1_priority_shotgun1':
6023 if (Length(P
) = 2) then
6024 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6026 'p2_priority_shotgun1':
6028 if (Length(P
) = 2) then
6029 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6031 'p1_priority_shotgun2':
6033 if (Length(P
) = 2) then
6034 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6036 'p2_priority_shotgun2':
6038 if (Length(P
) = 2) then
6039 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6041 'p1_priority_chaingun':
6043 if (Length(P
) = 2) then
6044 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6046 'p2_priority_chaingun':
6048 if (Length(P
) = 2) then
6049 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6051 'p1_priority_rocketlauncher':
6053 if (Length(P
) = 2) then
6054 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6056 'p2_priority_rocketlauncher':
6058 if (Length(P
) = 2) then
6059 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6061 'p1_priority_plasma':
6063 if (Length(P
) = 2) then
6064 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6066 'p2_priority_plasma':
6068 if (Length(P
) = 2) then
6069 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6073 if (Length(P
) = 2) then
6074 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6078 if (Length(P
) = 2) then
6079 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6081 'p1_priority_super':
6083 if (Length(P
) = 2) then
6084 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6086 'p2_priority_super':
6088 if (Length(P
) = 2) then
6089 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6091 'p1_priority_flamethrower':
6093 if (Length(P
) = 2) then
6094 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6096 'p2_priority_flamethrower':
6098 if (Length(P
) = 2) then
6099 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6101 'p1_priority_berserk':
6103 if (Length(P
) = 2) then
6104 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6106 'p2_priority_berserk':
6108 if (Length(P
) = 2) then
6109 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6114 procedure PrintHeapStats();
6118 hs
:= GetFPCHeapStatus();
6119 e_LogWriteLn ('v===== heap status =====v');
6120 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
6121 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
6122 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
6123 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
6124 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
6125 e_LogWriteLn ('^=======================^');
6128 procedure DebugCommands(P
: SSArray
);
6135 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6136 if {gDebugMode}conIsCheatsEnabled
then
6138 cmd
:= LowerCase(P
[0]);
6139 if cmd
= 'd_window' then
6141 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6142 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6144 else if cmd
= 'd_sounds' then
6146 if (Length(P
) > 1) and
6147 ((P
[1] = '1') or (P
[1] = '0')) then
6148 g_Debug_Sounds
:= (P
[1][1] = '1');
6150 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
6152 else if cmd
= 'd_frames' then
6154 if (Length(P
) > 1) and
6155 ((P
[1] = '1') or (P
[1] = '0')) then
6156 g_Debug_Frames
:= (P
[1][1] = '1');
6158 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
6160 else if cmd
= 'd_winmsg' then
6162 if (Length(P
) > 1) and
6163 ((P
[1] = '1') or (P
[1] = '0')) then
6164 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6166 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6168 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6170 if (Length(P
) > 1) and
6171 ((P
[1] = '1') or (P
[1] = '0')) then
6172 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6174 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6176 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6178 if Length(P
) > 1 then
6180 '0': g_debug_BotAIOff
:= 0;
6181 '1': g_debug_BotAIOff
:= 1;
6182 '2': g_debug_BotAIOff
:= 2;
6183 '3': g_debug_BotAIOff
:= 3;
6186 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6188 else if cmd
= 'd_monster' then
6190 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6191 if Length(P
) < 2 then
6193 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6194 g_Console_Add('ID | Name');
6195 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6196 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6197 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6200 a
:= StrToIntDef(P
[1], 0);
6201 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6202 a
:= g_Mons_TypeIdByName(P
[1]);
6204 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6205 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6208 with gPlayer1
.Obj
do
6210 mon
:= g_Monsters_Create(a
,
6211 X
+ Rect
.X
+ (Rect
.Width
div 2),
6212 Y
+ Rect
.Y
+ Rect
.Height
,
6213 gPlayer1
.Direction
, True);
6215 if (Length(P
) > 2) and (mon
<> nil) then
6217 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6218 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6219 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6220 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6221 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6222 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6223 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6224 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6225 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6230 else if (cmd
= 'd_health') then
6232 if (Length(P
) > 1) and
6233 ((P
[1] = '1') or (P
[1] = '0')) then
6234 g_debug_HealthBar
:= (P
[1][1] = '1');
6236 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6238 else if (cmd
= 'd_player') then
6240 if (Length(P
) > 1) and
6241 ((P
[1] = '1') or (P
[1] = '0')) then
6242 g_debug_Player
:= (P
[1][1] = '1');
6244 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6246 else if (cmd
= 'd_mem') then
6252 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6256 procedure GameCheats(P
: SSArray
);
6262 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6264 g_Console_Add('not available');
6270 g_Console_Add('where is the player?!');
6273 cmd
:= LowerCase(P
[0]);
6277 plr
.GodMode
:= not plr
.GodMode
;
6278 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6281 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6282 if cmd
= 'give' then
6284 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6285 for f
:= 1 to High(P
) do
6287 cmd
:= LowerCase(P
[f
]);
6288 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6289 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6290 if cmd
= 'exit' then
6292 if gTriggers
<> nil then
6294 for a
:= 0 to High(gTriggers
) do
6296 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6298 g_Console_Add('player left the map');
6299 gExitByTrigger
:= True;
6300 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6301 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6309 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6310 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6311 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6312 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6313 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6315 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6316 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6318 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6319 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;
6321 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6322 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6324 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6325 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6327 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6328 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6330 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6331 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6332 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6334 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6335 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6336 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6337 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;
6338 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6339 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6341 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;
6342 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;
6343 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;
6344 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;
6345 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;
6346 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;
6348 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6349 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;
6351 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;
6352 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;
6354 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6356 if cmd
= 'ammo' then
6358 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6359 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6360 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6361 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6362 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6363 g_Console_Add('player got some ammo');
6367 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6368 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6370 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6371 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6373 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6374 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6376 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6377 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6379 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6381 if cmd
= 'weapons' then
6383 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6384 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6385 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6386 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6387 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6388 plr
.GiveItem(ITEM_WEAPON_BFG
);
6389 g_Console_Add('player got weapons');
6393 if cmd
= 'keys' then
6395 plr
.GiveItem(ITEM_KEY_RED
);
6396 plr
.GiveItem(ITEM_KEY_GREEN
);
6397 plr
.GiveItem(ITEM_KEY_BLUE
);
6398 g_Console_Add('player got all keys');
6402 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6407 if cmd
= 'open' then
6409 g_Console_Add('player activated sesame');
6410 g_Triggers_OpenAll();
6417 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6421 if cmd
= 'noclip' then
6424 g_Console_Add('wall hardeness adjusted');
6428 if cmd
= 'notarget' then
6430 plr
.NoTarget
:= not plr
.NoTarget
;
6431 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6435 if cmd
= 'noreload' then
6437 plr
.NoReload
:= not plr
.NoReload
;
6438 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6442 if cmd
= 'speedy' then
6444 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6445 g_Console_Add('speed adjusted');
6449 if cmd
= 'jumpy' then
6451 VEL_JUMP
:= 30-VEL_JUMP
;
6452 g_Console_Add('jump height adjusted');
6456 if cmd
= 'automap' then
6458 gShowMap
:= not gShowMap
;
6459 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6463 if cmd
= 'aimline' then
6465 gAimLine
:= not gAimLine
;
6466 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6471 procedure GameCommands(P
: SSArray
);
6477 pl
: pTNetClient
= nil;
6485 cmd
:= LowerCase(P
[0]);
6487 if cmd
= 'pause' then
6489 if (g_ActiveWindow
= nil) then
6490 g_Game_Pause(not gPauseMain
);
6492 else if cmd
= 'endgame' then
6493 gExit
:= EXIT_SIMPLE
6494 else if cmd
= 'restart' then
6496 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6498 if g_Game_IsClient
then
6500 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6505 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6507 else if cmd
= 'kick' then
6509 if g_Game_IsServer
then
6511 if Length(P
) < 2 then
6513 g_Console_Add('kick <name>');
6518 g_Console_Add('kick <name>');
6522 if g_Game_IsNet
then
6523 pl
:= g_Net_Client_ByName(P
[1]);
6526 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6527 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6528 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6529 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6530 g_Net_Slist_ServerPlayerLeaves();
6531 end else if gPlayers
<> nil then
6532 for a
:= Low(gPlayers
) to High(gPlayers
) do
6533 if gPlayers
[a
] <> nil then
6534 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6536 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6537 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6539 gPlayers
[a
].Lives
:= 0;
6540 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6541 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6542 g_Player_Remove(gPlayers
[a
].UID
);
6543 g_Net_Slist_ServerPlayerLeaves();
6544 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6548 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6550 else if cmd
= 'kick_id' then
6552 if g_Game_IsServer
and g_Game_IsNet
then
6554 if Length(P
) < 2 then
6556 g_Console_Add('kick_id <client ID>');
6561 g_Console_Add('kick_id <client ID>');
6565 a
:= StrToIntDef(P
[1], 0);
6566 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6568 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6570 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6571 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6572 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6573 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6574 g_Net_Slist_ServerPlayerLeaves();
6578 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6580 else if cmd
= 'kick_pid' then
6582 if g_Game_IsServer
and g_Game_IsNet
then
6584 if Length(P
) < 2 then
6586 g_Console_Add('kick_pid <player ID>');
6591 g_Console_Add('kick_pid <player ID>');
6595 a
:= StrToIntDef(P
[1], 0);
6596 pl
:= g_Net_Client_ByPlayer(a
);
6597 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6599 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6600 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6601 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6602 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6603 g_Net_Slist_ServerPlayerLeaves();
6606 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6608 else if cmd
= 'ban' then
6610 if g_Game_IsServer
and g_Game_IsNet
then
6612 if Length(P
) < 2 then
6614 g_Console_Add('ban <name>');
6619 g_Console_Add('ban <name>');
6623 pl
:= g_Net_Client_ByName(P
[1]);
6626 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6627 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6628 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6629 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6630 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6631 g_Net_Slist_ServerPlayerLeaves();
6633 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6635 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6637 else if cmd
= 'ban_id' then
6639 if g_Game_IsServer
and g_Game_IsNet
then
6641 if Length(P
) < 2 then
6643 g_Console_Add('ban_id <client ID>');
6648 g_Console_Add('ban_id <client ID>');
6652 a
:= StrToIntDef(P
[1], 0);
6653 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6654 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6656 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6657 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6658 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6659 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6660 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6661 g_Net_Slist_ServerPlayerLeaves();
6664 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6666 else if cmd
= 'ban_pid' then
6668 if g_Game_IsServer
and g_Game_IsNet
then
6670 if Length(P
) < 2 then
6672 g_Console_Add('ban_pid <player ID>');
6677 g_Console_Add('ban_pid <player ID>');
6681 a
:= StrToIntDef(P
[1], 0);
6682 pl
:= g_Net_Client_ByPlayer(a
);
6683 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6685 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6686 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6687 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6688 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6689 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6690 g_Net_Slist_ServerPlayerLeaves();
6693 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6695 else if cmd
= 'permban' then
6697 if g_Game_IsServer
and g_Game_IsNet
then
6699 if Length(P
) < 2 then
6701 g_Console_Add('permban <name>');
6706 g_Console_Add('permban <name>');
6710 pl
:= g_Net_Client_ByName(P
[1]);
6713 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6714 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6715 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6716 g_Net_SaveBanList();
6717 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6718 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6719 g_Net_Slist_ServerPlayerLeaves();
6721 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6723 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6725 else if cmd
= 'permban_id' then
6727 if g_Game_IsServer
and g_Game_IsNet
then
6729 if Length(P
) < 2 then
6731 g_Console_Add('permban_id <client ID>');
6736 g_Console_Add('permban_id <client ID>');
6740 a
:= StrToIntDef(P
[1], 0);
6741 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6742 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6744 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6745 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6746 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6747 g_Net_SaveBanList();
6748 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6749 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6750 g_Net_Slist_ServerPlayerLeaves();
6753 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6755 else if cmd
= 'permban_pid' then
6757 if g_Game_IsServer
and g_Game_IsNet
then
6759 if Length(P
) < 2 then
6761 g_Console_Add('permban_pid <player ID>');
6766 g_Console_Add('permban_pid <player ID>');
6770 a
:= StrToIntDef(P
[1], 0);
6771 pl
:= g_Net_Client_ByPlayer(a
);
6772 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6774 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6775 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6776 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6777 g_Net_SaveBanList();
6778 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6779 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6780 g_Net_Slist_ServerPlayerLeaves();
6783 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6785 else if cmd
= 'permban_ip' then
6787 if g_Game_IsServer
and g_Game_IsNet
then
6789 if Length(P
) < 2 then
6791 g_Console_Add('permban_ip <IP address>');
6796 g_Console_Add('permban_ip <IP address>');
6800 g_Net_BanHost(P
[1]);
6801 g_Net_SaveBanList();
6802 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6804 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6806 else if cmd
= 'unban' then
6808 if g_Game_IsServer
and g_Game_IsNet
then
6810 if Length(P
) < 2 then
6812 g_Console_Add('unban <IP Address>');
6817 g_Console_Add('unban <IP Address>');
6821 if g_Net_UnbanHost(P
[1]) then
6823 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6824 g_Net_SaveBanList();
6826 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6828 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6830 else if cmd
= 'clientlist' then
6832 if g_Game_IsServer
and g_Game_IsNet
then
6835 if NetClients
<> nil then
6836 for a
:= Low(NetClients
) to High(NetClients
) do
6837 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6839 plr
:= g_Player_Get(NetClients
[a
].Player
);
6840 if plr
= nil then continue
;
6842 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6843 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6846 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6848 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6850 else if cmd
= 'connect' then
6852 if (NetMode
= NET_NONE
) then
6854 if Length(P
) < 2 then
6856 g_Console_Add('connect <IP> [port] [password]');
6861 g_Console_Add('connect <IP> [port] [password]');
6865 if Length(P
) > 2 then
6866 prt
:= StrToIntDef(P
[2], 25666)
6870 if Length(P
) > 3 then
6875 g_Game_StartClient(P
[1], prt
, pw
);
6878 else if cmd
= 'disconnect' then
6880 if (NetMode
= NET_CLIENT
) then
6883 else if cmd
= 'reconnect' then
6885 if (NetMode
= NET_SERVER
) then
6888 if (NetMode
= NET_CLIENT
) then
6891 gExit
:= EXIT_SIMPLE
;
6895 //TODO: Use last successful password to reconnect, instead of ''
6896 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6898 else if (cmd
= 'addbot') or
6899 (cmd
= 'bot_add') then
6901 if Length(P
) > 2 then
6902 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6903 else if Length(P
) > 1 then
6904 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6906 g_Bot_Add(TEAM_NONE
, 2);
6908 else if cmd
= 'bot_addlist' then
6910 if Length(P
) > 1 then
6912 if Length(P
) = 2 then
6913 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6914 else if Length(P
) = 3 then
6915 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6917 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6920 else if cmd
= 'bot_removeall' then
6922 else if cmd
= 'chat' then
6924 if g_Game_IsNet
then
6926 if Length(P
) > 1 then
6928 for a
:= 1 to High(P
) do
6929 chstr
:= chstr
+ P
[a
] + ' ';
6931 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6933 if Length(chstr
) < 1 then
6935 g_Console_Add('chat <text>');
6939 chstr
:= b_Text_Format(chstr
);
6940 if g_Game_IsClient
then
6941 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6943 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6946 g_Console_Add('chat <text>');
6948 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6950 else if cmd
= 'teamchat' then
6952 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6954 if Length(P
) > 1 then
6956 for a
:= 1 to High(P
) do
6957 chstr
:= chstr
+ P
[a
] + ' ';
6959 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6961 if Length(chstr
) < 1 then
6963 g_Console_Add('teamchat <text>');
6967 chstr
:= b_Text_Format(chstr
);
6968 if g_Game_IsClient
then
6969 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6971 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6972 gPlayer1Settings
.Team
);
6975 g_Console_Add('teamchat <text>');
6977 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6979 else if cmd
= 'game' then
6981 if gGameSettings
.GameType
<> GT_NONE
then
6983 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6986 if Length(P
) = 1 then
6988 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6991 // game not started yet, load fist map from some wad
6993 s
:= addWadExtension(P
[1]);
6994 found
:= e_FindResource(AllMapDirs
, s
);
6998 P
[1] := ExpandFileName(P
[1]);
6999 // if map not choosed then set first map
7000 if Length(P
) < 3 then
7003 P
[2] := g_Game_GetFirstMap(P
[1]);
7006 s
:= P
[1] + ':\' + UpperCase(P
[2]);
7008 if g_Map_Exist(s
) then
7012 with gGameSettings
do
7014 Options
:= gsGameFlags
;
7015 GameMode
:= g_Game_TextToMode(gsGameMode
);
7016 if gSwitchGameMode
<> GM_NONE
then
7017 GameMode
:= gSwitchGameMode
;
7018 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7019 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7021 if Length(P
) >= 4 then
7022 b
:= StrToIntDef(P
[3], 1);
7023 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
7024 GoalLimit
, MaxLives
, Options
, b
);
7029 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7031 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
7033 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
7035 else if cmd
= 'host' then
7037 if gGameSettings
.GameType
<> GT_NONE
then
7039 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7042 if Length(P
) < 4 then
7044 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
7047 if not StrToIp(P
[1], listen
) then
7049 prt
:= StrToIntDef(P
[2], 25666);
7051 s
:= addWadExtension(P
[3]);
7052 found
:= e_FindResource(AllMapDirs
, s
);
7056 // get first map in wad, if not specified
7057 if Length(P
) < 5 then
7060 P
[4] := g_Game_GetFirstMap(P
[1]);
7062 s
:= P
[3] + ':\' + UpperCase(P
[4]);
7063 if g_Map_Exist(s
) then
7067 with gGameSettings
do
7069 Options
:= gsGameFlags
;
7070 GameMode
:= g_Game_TextToMode(gsGameMode
);
7071 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
7072 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7073 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7075 if Length(P
) >= 6 then
7076 b
:= StrToIntDef(P
[5], 0);
7077 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
7083 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
7085 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
7090 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
7093 else if cmd
= 'map' then
7095 if Length(P
) = 1 then
7097 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7099 g_Console_Add(cmd
+ ' <MAP>');
7100 g_Console_Add(cmd
+ ' <WAD> [MAP]')
7104 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7109 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7111 if Length(P
) < 3 then
7113 // first param is map or wad
7114 s
:= UpperCase(P
[1]);
7115 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7117 gExitByTrigger
:= False;
7120 // already in game, finish current map
7122 gExit
:= EXIT_ENDLEVELCUSTOM
;
7126 // intermission, so change map immediately
7133 found
:= e_FindResource(AllMapDirs
, s
);
7135 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
7138 // no such map, found wad
7141 P
[1] := ExpandFileName(pw
);
7142 P
[2] := g_Game_GetFirstMap(P
[1]);
7143 s
:= P
[1] + ':\' + P
[2];
7144 if g_Map_Exist(s
) then
7146 gExitByTrigger
:= False;
7149 // already in game, finish current map
7151 gExit
:= EXIT_ENDLEVELCUSTOM
7155 // intermission, so change map immediately
7162 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7164 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7169 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7175 s
:= addWadExtension(P
[1]);
7176 found
:= e_FindResource(AllMapDirs
, s
);
7180 P
[2] := UpperCase(P
[2]);
7181 s
:= P
[1] + ':\' + P
[2];
7182 if g_Map_Exist(s
) then
7184 gExitByTrigger
:= False;
7188 gExit
:= EXIT_ENDLEVELCUSTOM
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 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7212 else if cmd
= 'nextmap' then
7214 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7216 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7221 if Length(P
) = 1 then
7223 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7225 g_Console_Add(cmd
+ ' <MAP>');
7226 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7231 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7237 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7239 if Length(P
) < 3 then
7241 // first param is map or wad
7242 s
:= UpperCase(P
[1]);
7243 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7246 gExitByTrigger
:= False;
7252 // no such map, found wad
7253 pw
:= addWadExtension(P
[1]);
7254 found
:= e_FindResource(MapDirs
, pw
);
7256 found
:= e_FindResource(WadDirs
, pw
);
7258 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7261 // map not specified, select first map
7263 P
[2] := g_Game_GetFirstMap(P
[1]);
7264 s
:= P
[1] + ':\' + P
[2];
7265 if g_Map_Exist(s
) then
7267 gExitByTrigger
:= False;
7274 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7276 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7281 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7287 // specified two params wad + map
7288 pw
:= addWadExtension(P
[1]);
7289 found
:= e_FindResource(MapDirs
, pw
);
7291 found
:= e_FindResource(MapDirs
, pw
);
7295 P
[2] := UpperCase(P
[2]);
7296 s
:= P
[1] + ':\' + P
[2];
7297 if g_Map_Exist(s
) then
7299 gExitByTrigger
:= False;
7305 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7310 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7316 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7321 if gNextMap
= '' then
7322 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7324 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7328 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7332 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7336 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7338 gExitByTrigger
:= False;
7339 // next map not specified, try to find trigger EXIT
7340 if (gNextMap
= '') and (gTriggers
<> nil) then
7342 for a
:= 0 to High(gTriggers
) do
7344 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7346 gExitByTrigger
:= True;
7347 //gNextMap := gTriggers[a].Data.MapName;
7348 gNextMap
:= gTriggers
[a
].tgcMap
;
7353 if gNextMap
= '' then
7354 gNextMap
:= g_Game_GetNextMap();
7355 if not isWadPath(gNextMap
) then
7356 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7359 if g_Map_Exist(s
) then
7360 gExit
:= EXIT_ENDLEVELCUSTOM
7362 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7366 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7370 else if (cmd
= 'event') then
7372 if (Length(P
) <= 1) then
7374 for a
:= 0 to High(gEvents
) do
7375 if gEvents
[a
].Command
= '' then
7376 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7378 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7381 if (Length(P
) = 2) then
7383 for a
:= 0 to High(gEvents
) do
7384 if gEvents
[a
].Name
= P
[1] then
7385 if gEvents
[a
].Command
= '' then
7386 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7388 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7391 for a
:= 0 to High(gEvents
) do
7392 if gEvents
[a
].Name
= P
[1] then
7394 gEvents
[a
].Command
:= '';
7395 for b
:= 2 to High(P
) do
7396 if Pos(' ', P
[b
]) = 0 then
7397 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7399 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7400 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7404 else if cmd
= 'suicide' then
7408 if g_Game_IsClient
then
7409 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7412 if gPlayer1
<> nil then
7413 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7414 if gPlayer2
<> nil then
7415 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7419 else if cmd
= 'screenshot' then
7423 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7425 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7427 gWeaponAction
[0, WP_PREV
] := True;
7429 gWeaponAction
[0, WP_NEXT
] := True;
7431 else if cmd
= 'weapon' then
7433 if Length(p
) = 2 then
7435 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7436 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7437 gSelectWeapon
[0, a
] := True
7440 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7441 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7443 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7444 b
:= ord(cmd
[2]) - ord('1');
7446 gWeaponAction
[b
, WP_PREV
] := True;
7448 gWeaponAction
[b
, WP_NEXT
] := True;
7450 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7452 if Length(p
) = 2 then
7454 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
7455 b
:= ord(cmd
[2]) - ord('1');
7456 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7457 gSelectWeapon
[b
, a
] := True
7460 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
7462 b
:= ord(cmd
[2]) - ord('1');
7464 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
7466 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
7468 else if (cmd
= 'dropflag') then
7470 if g_Game_IsServer
then
7472 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7473 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7476 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7478 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7480 b
:= ord(cmd
[2]) - ord('1');
7481 if g_Game_IsServer
then
7483 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7484 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7487 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7489 // Êîìàíäû Ñâîåé èãðû:
7490 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7492 if cmd
= 'bot_addred' then
7494 if Length(P
) > 1 then
7495 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7497 g_Bot_Add(TEAM_RED
, 2);
7499 else if cmd
= 'bot_addblue' then
7501 if Length(P
) > 1 then
7502 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7504 g_Bot_Add(TEAM_BLUE
, 2);
7506 else if cmd
= 'spectate' then
7512 else if cmd
= 'say' then
7514 if g_Game_IsServer
and g_Game_IsNet
then
7516 if Length(P
) > 1 then
7519 for a
:= 1 to High(P
) do
7520 chstr
:= chstr
+ P
[a
] + ' ';
7522 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7524 if Length(chstr
) < 1 then
7526 g_Console_Add('say <text>');
7530 chstr
:= b_Text_Format(chstr
);
7531 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7533 else g_Console_Add('say <text>');
7535 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7537 else if cmd
= 'tell' then
7539 if g_Game_IsServer
and g_Game_IsNet
then
7541 if (Length(P
) > 2) and (P
[1] <> '') then
7544 for a
:= 2 to High(P
) do
7545 chstr
:= chstr
+ P
[a
] + ' ';
7547 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7549 if Length(chstr
) < 1 then
7551 g_Console_Add('tell <playername> <text>');
7555 pl
:= g_Net_Client_ByName(P
[1]);
7557 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7559 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7561 else g_Console_Add('tell <playername> <text>');
7563 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7565 else if cmd
= 'centerprint' then
7567 if (Length(P
) > 2) and (P
[1] <> '') then
7570 for a
:= 2 to High(P
) do
7571 chstr
:= chstr
+ P
[a
] + ' ';
7573 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7575 if Length(chstr
) < 1 then
7577 g_Console_Add('centerprint <timeout> <text>');
7581 a
:= StrToIntDef(P
[1], 100);
7582 chstr
:= b_Text_Format(chstr
);
7583 g_Game_Message(chstr
, a
);
7584 if g_Game_IsNet
and g_Game_IsServer
then
7585 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7587 else g_Console_Add('centerprint <timeout> <text>');
7589 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7591 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7593 // Äîïîëíèòåëüíîå âðåìÿ:
7594 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7596 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7597 [gGameSettings
.TimeLimit
div 3600,
7598 (gGameSettings
.TimeLimit
div 60) mod 60,
7599 gGameSettings
.TimeLimit
mod 60]));
7600 if g_Game_IsNet
then MH_SEND_GameSettings
;
7602 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7604 if (Length(P
) <= 1) then
7605 g_Console_Add('rcon_password <password>')
7607 MC_SEND_RCONPassword(P
[1]);
7609 else if cmd
= 'rcon' then
7611 if g_Game_IsClient
then
7613 if Length(P
) > 1 then
7616 for a
:= 1 to High(P
) do
7617 chstr
:= chstr
+ P
[a
] + ' ';
7619 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7621 if Length(chstr
) < 1 then
7623 g_Console_Add('rcon <command>');
7627 MC_SEND_RCONCommand(chstr
);
7629 else g_Console_Add('rcon <command>');
7632 else if cmd
= 'ready' then
7634 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7635 gLMSRespawnTime
:= gTime
+ 100;
7637 else if (cmd
= 'callvote') and g_Game_IsNet
then
7639 if Length(P
) > 1 then
7642 for a
:= 1 to High(P
) do begin
7643 if a
> 1 then chstr
:= chstr
+ ' ';
7644 chstr
:= chstr
+ P
[a
];
7647 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7649 if Length(chstr
) < 1 then
7651 g_Console_Add('callvote <command>');
7655 if g_Game_IsClient
then
7656 MC_SEND_Vote(True, chstr
)
7658 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7659 g_Console_Process('vote', True);
7662 g_Console_Add('callvote <command>');
7664 else if (cmd
= 'vote') and g_Game_IsNet
then
7666 if g_Game_IsClient
then
7668 else if gVoteInProgress
then
7670 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7671 a
:= Floor((NetClientCount
+1)/2.0) + 1
7673 a
:= Floor(NetClientCount
/2.0) + 1;
7678 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7679 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7685 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7686 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7694 procedure SystemCommands(P
: SSArray
);
7698 cmd
:= LowerCase(P
[0]);
7707 gRC_Width
:= Max(1, gRC_Width
);
7708 gRC_Height
:= Max(1, gRC_Height
);
7709 gBPP
:= Max(1, gBPP
);
7710 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7711 e_LogWriteln('resolution changed')
7713 e_LogWriteln('resolution not changed');
7714 sys_EnableVSync(gVSync
);
7718 if Length(p
) = 2 then
7720 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7722 gFrameTime
:= 1000 div gMaxFPS
7726 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7730 if Length(p
) = 2 then
7732 gAskLanguage
:= true;
7733 gLanguage
:= LANGUAGE_ENGLISH
;
7734 case LowerCase(p
[1]) of
7737 gAskLanguage
:= false;
7738 gLanguage
:= LANGUAGE_ENGLISH
;
7742 gAskLanguage
:= false;
7743 gLanguage
:= LANGUAGE_RUSSIAN
;
7747 gAskLanguage
:= true;
7748 gLanguage
:= LANGUAGE_ENGLISH
;
7751 g_Language_Set(gLanguage
);
7755 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7761 procedure g_TakeScreenShot(Filename
: string = '');
7762 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7764 if e_NoGraphics
then Exit
;
7766 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7768 if Filename
= '' then
7771 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7772 Filename
:= 'screenshot-' + date
;
7775 name
:= e_CatPath(dir
, Filename
+ '.png');
7776 s
:= createDiskFile(name
);
7778 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
7780 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7782 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7787 g_Console_Add('oh shit, i can''t create screenshot!')
7791 procedure g_Game_InGameMenu(Show
: Boolean);
7793 if (g_ActiveWindow
= nil) and Show
then
7795 if gGameSettings
.GameType
= GT_SINGLE
then
7796 g_GUI_ShowWindow('GameSingleMenu')
7799 if g_Game_IsClient
then
7800 g_GUI_ShowWindow('GameClientMenu')
7802 if g_Game_IsNet
then
7803 g_GUI_ShowWindow('GameServerMenu')
7805 g_GUI_ShowWindow('GameCustomMenu');
7807 g_Sound_PlayEx('MENU_OPEN');
7809 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7810 if (not g_Game_IsNet
) then
7814 if (g_ActiveWindow
<> nil) and (not Show
) then
7816 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7817 if (not g_Game_IsNet
) then
7818 g_Game_Pause(False);
7822 procedure g_Game_Pause (Enable
: Boolean);
7826 if not gGameOn
then exit
;
7828 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7831 gPauseMain
:= Enable
;
7833 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7836 procedure g_Game_HolmesPause (Enable
: Boolean);
7840 if not gGameOn
then exit
;
7841 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7844 gPauseHolmes
:= Enable
;
7846 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7849 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7854 if gTriggers
<> nil then
7855 for i
:= 0 to High(gTriggers
) do
7856 with gTriggers
[i
] do
7857 if (TriggerType
= TRIGGER_SOUND
) and
7859 Sound
.IsPlaying() then
7861 Sound
.Pause(Enable
);
7865 if gPlayers
<> nil then
7866 for i
:= 0 to High(gPlayers
) do
7867 if gPlayers
[i
] <> nil then
7868 gPlayers
[i
].PauseSounds(Enable
);
7871 if gMusic
<> nil then
7872 gMusic
.Pause(Enable
);
7875 procedure g_Game_StopAllSounds(all
: Boolean);
7879 if gTriggers
<> nil then
7880 for i
:= 0 to High(gTriggers
) do
7881 with gTriggers
[i
] do
7882 if (TriggerType
= TRIGGER_SOUND
) and
7886 if gMusic
<> nil then
7893 procedure g_Game_UpdateTriggerSounds
;
7896 if gTriggers
<> nil then
7897 for i
:= 0 to High(gTriggers
) do
7898 with gTriggers
[i
] do
7899 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7900 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7903 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7906 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7911 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7916 if gSpectMode
<> SPECT_PLAYERS
then
7918 if gSpectPID1
= UID
then
7923 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7930 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7935 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7940 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7945 if gSpectMode
<> SPECT_PLAYERS
then
7947 Pl
:= g_Player_Get(gSpectPID1
);
7948 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7953 if gSpectViewTwo
then
7955 Pl
:= g_Player_Get(gSpectPID2
);
7956 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7964 procedure g_Game_Message(Msg
: string; Time
: Word);
7966 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7967 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7968 MessageTime
:= Time
;
7971 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7973 punct
: Array[0..13] of String =
7974 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7980 function IsPunctuation(S
: String): Boolean;
7985 if Length(S
) <> 1 then
7987 for i
:= Low(punct
) to High(punct
) do
7988 if S
= punct
[i
] then
7994 function FilterPunctuation(S
: String): String;
7998 for i
:= Low(punct
) to High(punct
) do
7999 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
8005 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
8007 // remove player name
8008 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8009 // for FullWord check
8010 Text := toLowerCase1251(' ' + Text + ' ');
8011 fpText
:= FilterPunctuation(Text);
8013 for i
:= 0 to Length(gChatSounds
) - 1 do
8016 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
8018 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
8019 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
8021 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
8027 gChatSounds
[i
].Sound
.Play();
8033 g_Sound_PlayEx('SOUND_GAME_RADIO');
8036 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
8045 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8049 if goodsnd
[a
].IsPlaying() then
8052 goodsnd
[Random(4)].Play();
8055 procedure g_Game_Announce_KillCombo(Param
: Integer);
8062 UID
:= Param
and $FFFF;
8067 Pl
:= g_Player_Get(UID
);
8076 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
8080 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
8084 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
8088 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
8096 if not g_Game_IsWatchedPlayer(UID
) then
8099 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
8103 if killsnd
[n
].IsPlaying() then
8108 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
8116 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8120 if hahasnd
[a
].IsPlaying() then
8123 hahasnd
[Random(3)].Play();
8126 procedure g_Game_StartVote(Command
, Initiator
: string);
8130 if not gVotesEnabled
then Exit
;
8131 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8132 if gVoteInProgress
or gVotePassed
then
8134 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
8135 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
8138 gVoteInProgress
:= True;
8139 gVotePassed
:= False;
8140 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
8143 gVoteCommand
:= Command
;
8145 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8146 Need
:= Floor((NetClientCount
+1)/2.0)+1
8148 Need
:= Floor(NetClientCount
/2.0)+1;
8149 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
8150 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
8153 procedure g_Game_CheckVote
;
8157 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8158 if not gVoteInProgress
then Exit
;
8160 if (gTime
>= gVoteTimer
) then
8162 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8163 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8165 Need
:= Floor(NetClientCount
/2.0) + 1;
8166 if gVoteCount
>= Need
then
8168 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8169 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8170 gVotePassed
:= True;
8171 gVoteCmdTimer
:= gTime
+ 5000;
8175 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
8176 MH_SEND_VoteEvent(NET_VE_FAILED
);
8178 if NetClients
<> nil then
8179 for I
:= Low(NetClients
) to High(NetClients
) do
8180 if NetClients
[i
].Used
then
8181 NetClients
[i
].Voted
:= False;
8182 gVoteInProgress
:= False;
8188 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8189 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8191 Need
:= Floor(NetClientCount
/2.0) + 1;
8192 if gVoteCount
>= Need
then
8194 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8195 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8196 gVoteInProgress
:= False;
8197 gVotePassed
:= True;
8198 gVoteCmdTimer
:= gTime
+ 5000;
8201 if NetClients
<> nil then
8202 for I
:= Low(NetClients
) to High(NetClients
) do
8203 if NetClients
[i
].Used
then
8204 NetClients
[i
].Voted
:= False;
8209 procedure g_Game_LoadMapList(FileName
: string);
8217 if not FileExists(FileName
) then Exit
;
8219 AssignFile(ListFile
, FileName
);
8221 while not EOF(ListFile
) do
8223 ReadLn(ListFile
, s
);
8226 if s
= '' then Continue
;
8228 SetLength(MapList
, Length(MapList
)+1);
8229 MapList
[High(MapList
)] := s
;
8231 CloseFile(ListFile
);
8234 procedure g_Game_SetDebugMode();
8237 // ×èòû (äàæå â ñâîåé èãðå):
8241 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8245 if Length(LoadingStat
.Msgs
) = 0 then
8251 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8252 if NextMsg
= Length(Msgs
) then
8254 for i
:= 0 to High(Msgs
)-1 do
8255 Msgs
[i
] := Msgs
[i
+1];
8263 Msgs
[NextMsg
-1] := Text;
8267 PBarWasHere
:= false;
8270 g_ActiveWindow
:= nil;
8272 ProcessLoading(true);
8275 procedure g_Game_StepLoading(Value
: Integer = -1);
8286 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8294 procedure g_Game_ClearLoading();
8303 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8304 if len
< 1 then len
:= 1;
8305 SetLength(Msgs
, len
);
8306 for len
:= Low(Msgs
) to High(Msgs
) do
8309 PBarWasHere
:= false;
8313 procedure Parse_Params(var pars
: TParamStrValues
);
8320 while i
<= ParamCount
do
8323 if (Length(s
) > 1) and (s
[1] = '-') then
8325 if (Length(s
) > 2) and (s
[2] = '-') then
8326 begin // Îäèíî÷íûé ïàðàìåòð
8327 SetLength(pars
, Length(pars
) + 1);
8328 with pars
[High(pars
)] do
8330 Name
:= LowerCase(s
);
8335 if (i
< ParamCount
) then
8336 begin // Ïàðàìåòð ñî çíà÷åíèåì
8338 SetLength(pars
, Length(pars
) + 1);
8339 with pars
[High(pars
)] do
8341 Name
:= LowerCase(s
);
8342 Value
:= LowerCase(ParamStr(i
));
8351 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8356 for i
:= 0 to High(pars
) do
8357 if pars
[i
].Name
= aName
then
8359 Result
:= pars
[i
].Value
;
8364 procedure g_Game_Process_Params();
8366 pars
: TParamStrValues
;
8369 LimT
, LimS
: Integer;
8380 s
:= Find_Param_Value(pars
, '--debug');
8383 g_Game_SetDebugMode();
8384 s
:= Find_Param_Value(pars
, '--netdump');
8389 // Connect when game loads
8390 ip
:= Find_Param_Value(pars
, '-connect');
8394 s
:= Find_Param_Value(pars
, '-port');
8395 if (s
= '') or not TryStrToInt(s
, Port
) then
8398 s
:= Find_Param_Value(pars
, '-pw');
8400 g_Game_StartClient(ip
, Port
, s
);
8404 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8407 gDefaultMegawadStart
:= s
;
8410 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8411 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8413 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8416 // Start map when game loads:
8417 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8418 if isWadPath(map
) then
8421 s
:= Find_Param_Value(pars
, '-gm');
8422 GMode
:= g_Game_TextToMode(s
);
8423 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8424 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8427 s
:= Find_Param_Value(pars
, '-limt');
8428 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8434 s
:= Find_Param_Value(pars
, '-lims');
8435 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8441 s
:= Find_Param_Value(pars
, '-lives');
8442 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8448 s
:= Find_Param_Value(pars
, '-opt');
8452 Opt
:= StrToIntDef(s
, 0);
8455 s
:= Find_Param_Value(pars
, '--close');
8459 // Override map to test:
8460 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8463 if e_IsValidResourceName(s
) then
8464 e_FindResource(AllMapDirs
, s
);
8465 gTestMap
:= ExpandFileName(s
);
8468 // Delete test map after play:
8469 s
:= Find_Param_Value(pars
, '--testdelete');
8472 //gMapToDelete := MapsDir + map;
8473 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8477 // Delete temporary WAD after play:
8478 s
:= Find_Param_Value(pars
, '--tempdelete');
8479 if (s
<> '') and (gTestMap
<> '') then
8481 gMapToDelete
:= gTestMap
;
8482 gTempDelete
:= True;
8485 // Number of players:
8486 s
:= Find_Param_Value(pars
, '-pl');
8488 n
:= DEFAULT_PLAYERS
8490 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8493 s
:= Find_Param_Value(pars
, '-port');
8494 if (s
= '') or not TryStrToInt(s
, Port
) then
8495 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8497 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8500 // Execute script when game loads:
8501 s
:= Find_Param_Value(pars
, '-exec');
8504 // if not isWadPath(s) then
8505 // s := GameDir + '/' + s;
8510 if IOResult
<> 0 then
8512 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8513 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8517 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8518 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8523 if IOResult
<> 0 then
8525 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8526 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8530 if Pos('#', s
) <> 1 then // script comment
8531 g_Console_Process(s
, True);
8542 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8543 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8544 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8545 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8547 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8548 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8549 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8550 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8552 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8553 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8555 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8556 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8558 {$IFDEF ENABLE_HOLMES}
8559 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8562 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8564 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8565 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8567 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8568 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8570 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8571 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8573 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8574 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8575 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8576 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8577 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8578 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8579 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8580 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8581 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');