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 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4358 if g_Game_IsServer
and g_Game_IsNet
then
4359 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4360 gPlayer1
.Respawn(False, True);
4361 g_Net_Slist_ServerPlayerComes();
4366 if gPlayer2
= nil then
4368 if g_Game_IsClient
then
4370 if NetPlrUID2
> -1 then
4371 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4375 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4376 Team
:= gPlayer2Settings
.Team
;
4378 // Ñîçäàíèå âòîðîãî èãðîêà:
4379 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4380 gPlayer2Settings
.Color
,
4382 if gPlayer2
= nil then
4383 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4386 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4387 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4388 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4389 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4390 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4391 if g_Game_IsServer
and g_Game_IsNet
then
4392 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4393 gPlayer2
.Respawn(False, True);
4394 g_Net_Slist_ServerPlayerComes();
4401 procedure g_Game_RemovePlayer();
4405 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4406 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4411 if g_Game_IsServer
then
4414 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4415 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4416 g_Player_Remove(Pl
.UID
);
4417 g_Net_Slist_ServerPlayerLeaves();
4421 gSpectLatchPID2
:= Pl
.UID
;
4429 if g_Game_IsServer
then
4432 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4433 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4434 g_Player_Remove(Pl
.UID
);
4435 g_Net_Slist_ServerPlayerLeaves();
4438 gSpectLatchPID1
:= Pl
.UID
;
4440 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4444 g_Net_Slist_ServerPlayerLeaves();
4447 procedure g_Game_Spectate();
4449 g_Game_RemovePlayer();
4450 if gPlayer1
<> nil then
4451 g_Game_RemovePlayer();
4454 procedure g_Game_SpectateCenterView();
4456 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4457 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4460 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4467 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4469 g_Game_ClearLoading();
4472 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4475 gGameSettings
.GameType
:= GT_SINGLE
;
4476 gGameSettings
.MaxLives
:= 0;
4477 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4478 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4479 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4480 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
4481 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
4482 gSwitchGameMode
:= GM_SINGLE
;
4484 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4485 gLMSRespawnTime
:= 0;
4486 gSpectLatchPID1
:= 0;
4487 gSpectLatchPID2
:= 0;
4489 g_Game_ExecuteEvent('ongamestart');
4491 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4492 g_Game_SetupScreenSize();
4494 // Ñîçäàíèå ïåðâîãî èãðîêà:
4495 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4496 gPlayer1Settings
.Color
,
4497 gPlayer1Settings
.Team
, False));
4498 if gPlayer1
= nil then
4500 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4504 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4505 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4506 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4507 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4510 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4513 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4514 gPlayer2Settings
.Color
,
4515 gPlayer2Settings
.Team
, False));
4516 if gPlayer2
= nil then
4518 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4522 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4523 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4524 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4525 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4529 // Çàãðóçêà è çàïóñê êàðòû:
4530 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
4532 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4533 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4537 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4541 for i
:= nPl
+1 to nPlayers
do
4542 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4545 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4546 TimeLimit
, GoalLimit
: Word;
4548 Options
: LongWord; nPlayers
: Byte);
4554 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4556 g_Game_ClearLoading();
4559 gGameSettings
.GameType
:= GT_CUSTOM
;
4560 gGameSettings
.GameMode
:= GameMode
;
4561 gSwitchGameMode
:= GameMode
;
4562 gGameSettings
.TimeLimit
:= TimeLimit
;
4563 gGameSettings
.GoalLimit
:= GoalLimit
;
4564 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4565 gGameSettings
.Options
:= Options
;
4567 gCoopTotalMonstersKilled
:= 0;
4568 gCoopTotalSecretsFound
:= 0;
4569 gCoopTotalMonsters
:= 0;
4570 gCoopTotalSecrets
:= 0;
4574 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4575 gLMSRespawnTime
:= 0;
4576 gSpectLatchPID1
:= 0;
4577 gSpectLatchPID2
:= 0;
4579 g_Game_ExecuteEvent('ongamestart');
4581 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4582 g_Game_SetupScreenSize();
4584 // Ðåæèì íàáëþäàòåëÿ:
4585 if nPlayers
= 0 then
4592 if nPlayers
>= 1 then
4594 // Ñîçäàíèå ïåðâîãî èãðîêà:
4595 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4596 gPlayer1Settings
.Color
,
4597 gPlayer1Settings
.Team
, False));
4598 if gPlayer1
= nil then
4600 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4604 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4605 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4606 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4607 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4611 if nPlayers
>= 2 then
4613 // Ñîçäàíèå âòîðîãî èãðîêà:
4614 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4615 gPlayer2Settings
.Color
,
4616 gPlayer2Settings
.Team
, False));
4617 if gPlayer2
= nil then
4619 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4623 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4624 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4625 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4626 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4630 // Çàãðóçêà è çàïóñê êàðòû:
4631 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
4633 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4637 // Íåò òî÷åê ïîÿâëåíèÿ:
4638 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4639 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4640 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4641 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4642 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4644 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4648 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4652 for i
:= nPl
+1 to nPlayers
do
4653 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4656 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4657 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4658 Options
: LongWord; nPlayers
: Byte;
4659 IPAddr
: LongWord; Port
: Word);
4662 g_Net_Slist_ServerClosed();
4664 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4666 g_Game_ClearLoading();
4669 gGameSettings
.GameType
:= GT_SERVER
;
4670 gGameSettings
.GameMode
:= GameMode
;
4671 gSwitchGameMode
:= GameMode
;
4672 gGameSettings
.TimeLimit
:= TimeLimit
;
4673 gGameSettings
.GoalLimit
:= GoalLimit
;
4674 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4675 gGameSettings
.Options
:= Options
;
4677 gCoopTotalMonstersKilled
:= 0;
4678 gCoopTotalSecretsFound
:= 0;
4679 gCoopTotalMonsters
:= 0;
4680 gCoopTotalSecrets
:= 0;
4684 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4685 gLMSRespawnTime
:= 0;
4686 gSpectLatchPID1
:= 0;
4687 gSpectLatchPID2
:= 0;
4689 g_Game_ExecuteEvent('ongamestart');
4691 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4692 g_Game_SetupScreenSize();
4694 // Ðåæèì íàáëþäàòåëÿ:
4695 if nPlayers
= 0 then
4701 if nPlayers
>= 1 then
4703 // Ñîçäàíèå ïåðâîãî èãðîêà:
4704 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4705 gPlayer1Settings
.Color
,
4706 gPlayer1Settings
.Team
, False));
4707 if gPlayer1
= nil then
4709 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4713 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4714 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4715 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4716 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4719 if nPlayers
>= 2 then
4721 // Ñîçäàíèå âòîðîãî èãðîêà:
4722 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4723 gPlayer2Settings
.Color
,
4724 gPlayer2Settings
.Team
, False));
4725 if gPlayer2
= nil then
4727 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4731 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4732 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
4733 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
4734 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
4737 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4738 if NetForwardPorts
then
4739 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4742 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4744 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
4748 g_Net_Slist_Set(NetMasterList
);
4750 g_Net_Slist_ServerStarted();
4752 // Çàãðóçêà è çàïóñê êàðòû:
4753 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
4755 g_Net_Slist_ServerClosed();
4756 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4760 // Íåò òî÷åê ïîÿâëåíèÿ:
4761 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4762 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4763 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4764 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4765 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4767 g_Net_Slist_ServerClosed();
4768 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4772 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4775 g_Net_Slist_ServerMapStarted();
4776 NetState
:= NET_STATE_GAME
;
4779 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4794 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4795 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4797 g_Game_ClearLoading();
4800 gGameSettings
.GameType
:= GT_CLIENT
;
4802 gCoopTotalMonstersKilled
:= 0;
4803 gCoopTotalSecretsFound
:= 0;
4804 gCoopTotalMonsters
:= 0;
4805 gCoopTotalSecrets
:= 0;
4809 g_Game_ExecuteEvent('ongamestart');
4811 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4812 g_Game_SetupScreenSize();
4814 NetState
:= NET_STATE_AUTH
;
4816 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4818 // create (or update) map/resource databases
4819 g_Res_CreateDatabases(true);
4821 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4822 gLMSRespawnTime
:= 0;
4823 gSpectLatchPID1
:= 0;
4824 gSpectLatchPID2
:= 0;
4827 if not g_Net_Connect(Addr
, Port
) then
4829 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4830 NetState
:= NET_STATE_NONE
;
4834 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4836 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4841 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4842 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4843 // thank you, enet. let's ignore failures altogether then.
4844 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4846 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4848 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4850 // ignore all download packets, they're processed by separate code
4851 enet_packet_destroy(NetEvent
.packet
);
4854 Ptr
:= NetEvent
.packet
^.data
;
4855 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4857 enet_packet_destroy(NetEvent
.packet
);
4861 InMsg
.ReadLongWord(); // skip size
4862 MID
:= InMsg
.ReadByte();
4864 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4866 NetMyID
:= InMsg
.ReadByte();
4867 NetPlrUID1
:= InMsg
.ReadWord();
4869 WadName
:= InMsg
.ReadString();
4870 Map
:= InMsg
.ReadString();
4872 gWADHash
:= InMsg
.ReadMD5();
4874 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4875 gSwitchGameMode
:= gGameSettings
.GameMode
;
4876 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4877 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4878 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4879 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4880 T
:= InMsg
.ReadLongWord();
4882 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4883 //if newResPath = '' then
4885 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4886 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
4887 if newResPath
= '' then
4889 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4890 enet_packet_destroy(NetEvent
.packet
);
4891 NetState
:= NET_STATE_NONE
;
4894 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4896 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4899 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4900 gPlayer1Settings
.Color
,
4901 gPlayer1Settings
.Team
, False));
4903 if gPlayer1
= nil then
4905 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4907 enet_packet_destroy(NetEvent
.packet
);
4908 NetState
:= NET_STATE_NONE
;
4912 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4913 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
4914 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
4915 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
4916 gPlayer1
.UID
:= NetPlrUID1
;
4917 gPlayer1
.Reset(True);
4919 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
4921 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4923 enet_packet_destroy(NetEvent
.packet
);
4924 NetState
:= NET_STATE_NONE
;
4932 enet_packet_destroy(NetEvent
.packet
);
4936 enet_packet_destroy(NetEvent
.packet
);
4940 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4943 if (NetEvent
.data
<= NET_DISC_MAX
) then
4944 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4945 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4952 ProcessLoading(true);
4954 if g_Net_UserRequestExit() then
4963 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4964 NetState
:= NET_STATE_NONE
;
4969 NetState
:= NET_STATE_GAME
;
4970 MC_SEND_FullStateRequest
;
4971 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4975 lastAsMegaWad
: Boolean = false;
4977 procedure g_Game_ChangeMap(const MapPath
: String);
4981 g_Game_ClearLoading();
4983 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4984 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4985 if gExitByTrigger
then
4988 gExitByTrigger
:= False;
4990 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
4991 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4994 procedure g_Game_Restart();
4998 if g_Game_IsClient
then
5000 map
:= g_ExtractFileName(gMapInfo
.Map
);
5001 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
5005 g_Game_ClearLoading();
5006 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
5009 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
5011 NewWAD
, ResName
: String;
5015 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
5016 g_Player_RemoveAllCorpses();
5018 if (not g_Game_IsClient
) and
5019 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
5020 (gGameSettings
.GameMode
<> GM_SINGLE
) then
5022 if gSwitchGameMode
= GM_CTF
then
5023 gGameSettings
.MaxLives
:= 0;
5024 gGameSettings
.GameMode
:= gSwitchGameMode
;
5027 gSwitchGameMode
:= gGameSettings
.GameMode
;
5029 g_Player_ResetTeams();
5031 lastAsMegaWad
:= asMegawad
;
5032 if isWadPath(Map
) then
5034 NewWAD
:= g_ExtractWadName(Map
);
5035 ResName
:= g_ExtractFileName(Map
);
5036 if g_Game_IsServer
then
5038 nws
:= findDiskWad(NewWAD
);
5039 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5042 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5043 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5047 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
5048 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
5050 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5051 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5053 if (length(nws
) = 0) then
5055 ResName
:= ''; // failed
5060 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
5061 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5062 g_Game_LoadWAD(NewWAD
);
5067 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5068 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
5073 NewWAD
:= gGameSettings
.WAD
;
5079 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5081 if (ResName
<> '') and (NewWAD
<> '') then
5083 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5084 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
5088 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
5090 gState
:= STATE_NONE
;
5091 g_ActiveWindow
:= nil;
5097 if gGameSettings
.GameMode
= GM_CTF
then
5099 g_Map_ResetFlag(FLAG_RED
);
5100 g_Map_ResetFlag(FLAG_BLUE
);
5101 // CTF, à ôëàãîâ íåò:
5102 if not g_Map_HaveFlagPoints() then
5103 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
5108 gState
:= STATE_MENU
;
5113 gPauseMain
:= false;
5114 gPauseHolmes
:= false;
5115 NetTimeToUpdate
:= 1;
5116 NetTimeToReliable
:= 0;
5117 NetTimeToMaster
:= NetMasterRate
;
5118 gSpectLatchPID1
:= 0;
5119 gSpectLatchPID2
:= 0;
5120 gMissionFailed
:= False;
5123 gCoopMonstersKilled
:= 0;
5124 gCoopSecretsFound
:= 0;
5126 gVoteInProgress
:= False;
5127 gVotePassed
:= False;
5133 if not gGameOn
then Exit
;
5135 g_Game_SpectateCenterView();
5137 if g_Game_IsServer
then
5139 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
5141 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5142 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5143 gLMSSoftSpawn
:= True;
5144 if g_Game_IsNet
then
5145 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5149 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5150 gLMSRespawnTime
:= 0;
5154 if NetMode
= NET_SERVER
then
5156 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
5159 g_Net_Slist_ServerMapStarted();
5161 if NetClients
<> nil then
5162 for I
:= 0 to High(NetClients
) do
5163 if NetClients
[I
].Used
then
5165 NetClients
[I
].Voted
:= False;
5166 if NetClients
[I
].RequestedFullUpdate
then
5168 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
5169 NetClients
[I
].RequestedFullUpdate
:= False;
5173 g_Net_UnbanNonPermHosts();
5178 gCoopTotalMonstersKilled
:= 0;
5179 gCoopTotalSecretsFound
:= 0;
5180 gCoopTotalMonsters
:= 0;
5181 gCoopTotalSecrets
:= 0;
5185 g_Game_ExecuteEvent('onmapstart');
5188 procedure SetFirstLevel
;
5192 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5193 if MapList
= nil then
5196 SortSArray(MapList
);
5197 gNextMap
:= MapList
[Low(MapList
)];
5202 procedure g_Game_ExitLevel(const Map
: AnsiString);
5206 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
5207 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
5208 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
5209 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
5211 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5212 if gGameSettings
.GameType
= GT_SINGLE
then
5213 gExit
:= EXIT_ENDLEVELSINGLE
5214 else // Âûøëè â âûõîä â Ñâîåé èãðå
5216 gExit
:= EXIT_ENDLEVELCUSTOM
;
5217 if gGameSettings
.GameMode
= GM_COOP
then
5218 g_Player_RememberAll
;
5220 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5223 if gGameSettings
.GameMode
= GM_COOP
then
5226 gStatsPressed
:= True;
5227 gNextMap
:= 'MAP01';
5229 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
5232 if g_Game_IsNet
then
5234 MH_SEND_GameStats();
5235 MH_SEND_CoopStats();
5241 procedure g_Game_RestartLevel();
5245 if gGameSettings
.GameMode
= GM_SINGLE
then
5250 gExit
:= EXIT_ENDLEVELCUSTOM
;
5251 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5255 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
5257 gWAD
{, xwad}: String;
5260 if not g_Game_IsClient
then Exit
;
5261 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5263 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5268 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5272 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
5275 g_Game_LoadWAD(NewWAD
);
5279 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5280 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5283 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5284 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5288 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5292 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5293 g_Game_LoadWAD(NewWAD);
5297 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5299 i
, n
, nb
, nr
: Integer;
5301 if not g_Game_IsServer
then Exit
;
5302 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5303 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5304 gLMSRespawnTime
:= 0;
5307 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5309 gMissionFailed
:= True;
5310 g_Game_RestartLevel
;
5314 n
:= 0; nb
:= 0; nr
:= 0;
5315 for i
:= Low(gPlayers
) to High(gPlayers
) do
5316 if (gPlayers
[i
] <> nil) and
5317 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5318 (gPlayers
[i
] is TBot
)) then
5321 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5322 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5325 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5327 // wait a second until the fuckers finally decide to join
5328 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5329 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
5330 gLMSSoftSpawn
:= NoMapRestart
;
5331 if g_Game_IsNet
then
5332 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5336 g_Player_RemoveAllCorpses
;
5337 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5338 if g_Game_IsNet
then
5339 MH_SEND_GameEvent(NET_EV_LMS_START
);
5341 for i
:= Low(gPlayers
) to High(gPlayers
) do
5343 if gPlayers
[i
] = nil then continue
;
5344 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5345 // don't touch normal spectators
5346 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5348 gPlayers
[i
].FNoRespawn
:= True;
5349 gPlayers
[i
].Lives
:= 0;
5350 if g_Game_IsNet
then
5351 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5354 gPlayers
[i
].FNoRespawn
:= False;
5355 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5356 gPlayers
[i
].Respawn(False, True);
5357 if gGameSettings
.GameMode
= GM_COOP
then
5359 gPlayers
[i
].Frags
:= 0;
5360 gPlayers
[i
].RecallState
;
5362 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
5363 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
5364 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
5365 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
5368 g_Items_RestartRound();
5370 gLMSSoftSpawn
:= False;
5373 function g_Game_GetFirstMap(WAD
: String): String;
5377 MapList
:= g_Map_GetMapsList(WAD
);
5378 if MapList
= nil then
5381 SortSArray(MapList
);
5382 Result
:= MapList
[Low(MapList
)];
5384 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5390 function g_Game_GetNextMap(): String;
5397 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5398 if MapList
= nil then
5401 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5403 SortSArray(MapList
);
5405 for I
:= Low(MapList
) to High(MapList
) do
5406 if Map
= MapList
[I
] then
5412 if MapIndex
<> -255 then
5414 if MapIndex
= High(MapList
) then
5415 Result
:= MapList
[Low(MapList
)]
5417 Result
:= MapList
[MapIndex
+ 1];
5419 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5425 procedure g_Game_NextLevel();
5427 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5428 gExit
:= EXIT_ENDLEVELCUSTOM
5431 gExit
:= EXIT_ENDLEVELSINGLE
;
5435 if gNextMap
<> '' then Exit
;
5436 gNextMap
:= g_Game_GetNextMap();
5439 function g_Game_IsTestMap(): Boolean;
5441 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5444 procedure g_Game_DeleteTestMap();
5447 //MapName: AnsiString;
5455 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5456 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5457 if (a
= 0) then exit
;
5459 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5460 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5461 Delete(gMapToDelete
, 1, a
+5);
5462 gMapToDelete
:= UpperCase(gMapToDelete
);
5464 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5467 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5468 if MapName <> TEST_MAP_NAME then
5471 if not gTempDelete then
5473 time := g_GetFileTime(WadName);
5474 WAD := TWADFile.Create();
5477 if not WAD.ReadFile(WadName) then
5478 begin // Íåò òàêîãî WAD-ôàéëà
5483 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5485 MapList := WAD.GetResourcesList('');
5487 if MapList <> nil then
5488 for a := 0 to High(MapList) do
5489 if MapList[a] = MapName then
5491 // Óäàëÿåì è ñîõðàíÿåì:
5492 WAD.RemoveResource('', MapName);
5493 WAD.SaveTo(WadName);
5498 g_SetFileTime(WadName, time);
5501 if gTempDelete
then DeleteFile(WadName
);
5504 procedure GameCVars(P
: SSArray
);
5507 stat
: TPlayerStatArray
;
5510 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
5514 if Length(P
) > 1 then
5519 gsGameFlags
:= gsGameFlags
or Flag
5521 gsGameFlags
:= gsGameFlags
and (not Flag
);
5523 if g_Game_IsServer
then
5526 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
5528 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
5529 if g_Game_IsNet
then MH_SEND_GameSettings
;
5533 if LongBool(gsGameFlags
and Flag
) then
5534 g_Console_Add(_lc
[OnMsg
])
5536 g_Console_Add(_lc
[OffMsg
]);
5538 if OnMapChange
and g_Game_IsServer
then
5539 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5544 cmd
:= LowerCase(P
[0]);
5546 if cmd
= 'g_gamemode' then
5548 if (Length(P
) > 1) then
5550 a
:= g_Game_TextToMode(P
[1]);
5551 if a
= GM_SINGLE
then a
:= GM_COOP
;
5552 gsGameMode
:= g_Game_ModeToText(a
);
5553 if g_Game_IsServer
then
5555 gSwitchGameMode
:= a
;
5556 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5557 (gState
= STATE_INTERSINGLE
) then
5558 gSwitchGameMode
:= GM_SINGLE
;
5560 gGameSettings
.GameMode
:= gSwitchGameMode
;
5564 if gSwitchGameMode
= gGameSettings
.GameMode
then
5565 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5566 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5568 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5569 [g_Game_ModeToText(gGameSettings
.GameMode
),
5570 g_Game_ModeToText(gSwitchGameMode
)]));
5572 else if cmd
= 'g_friendlyfire' then
5574 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
5576 else if cmd
= 'g_friendly_absorb_damage' then
5578 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
5580 else if cmd
= 'g_friendly_hit_trace' then
5582 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
5584 else if cmd
= 'g_friendly_hit_projectile' then
5586 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
5588 else if cmd
= 'g_weaponstay' then
5590 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
5592 else if cmd
= 'g_allow_exit' then
5594 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
5596 else if cmd
= 'g_allow_monsters' then
5598 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
5600 else if cmd
= 'g_allow_dropflag' then
5602 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
5604 else if cmd
= 'g_throw_flag' then
5606 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
5608 else if cmd
= 'g_bot_vsplayers' then
5610 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
5612 else if cmd
= 'g_bot_vsmonsters' then
5614 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
5616 else if cmd
= 'g_dm_keys' then
5618 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
5620 else if cmd
= 'g_gameflags' then
5622 if Length(P
) > 1 then
5624 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
5625 if g_Game_IsServer
then
5627 gGameSettings
.Options
:= gsGameFlags
;
5628 if g_Game_IsNet
then MH_SEND_GameSettings
;
5632 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
5634 else if cmd
= 'g_warmup_time' then
5636 if Length(P
) > 1 then
5638 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
5639 if g_Game_IsServer
then
5641 gGameSettings
.WarmupTime
:= gsWarmupTime
;
5642 // extend warmup if it's already going
5643 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
5645 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
5646 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
5648 if g_Game_IsNet
then MH_SEND_GameSettings
;
5652 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
5653 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5655 else if cmd
= 'g_spawn_invul' then
5657 if Length(P
) > 1 then
5659 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
5660 if g_Game_IsServer
then
5662 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
5663 if g_Game_IsNet
then MH_SEND_GameSettings
;
5667 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
5669 else if cmd
= 'g_item_respawn_time' then
5671 if Length(P
) > 1 then
5673 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
5674 if g_Game_IsServer
then
5676 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
5677 if g_Game_IsNet
then MH_SEND_GameSettings
;
5681 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
5682 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5684 else if cmd
= 'sv_intertime' then
5686 if (Length(P
) > 1) then
5687 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5689 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5691 else if cmd
= 'g_max_particles' then
5693 if Length(p
) = 2 then
5695 a
:= Max(0, StrToInt(p
[1]));
5698 else if Length(p
) = 1 then
5700 e_LogWritefln('%s', [g_GFX_GetMax()])
5704 e_LogWritefln('usage: %s <n>', [cmd
])
5707 else if cmd
= 'g_max_shells' then
5709 if Length(p
) = 2 then
5711 a
:= Max(0, StrToInt(p
[1]));
5714 else if Length(p
) = 1 then
5716 e_LogWritefln('%s', [g_Shells_GetMax()])
5720 e_LogWritefln('usage: %s <n>', [cmd
])
5723 else if cmd
= 'g_max_gibs' then
5725 if Length(p
) = 2 then
5727 a
:= Max(0, StrToInt(p
[1]));
5730 else if Length(p
) = 1 then
5732 e_LogWritefln('%s', [g_Gibs_GetMax()])
5736 e_LogWritefln('usage: %s <n>', [cmd
])
5739 else if cmd
= 'g_max_corpses' then
5741 if Length(p
) = 2 then
5743 a
:= Max(0, StrToInt(p
[1]));
5746 else if Length(p
) = 1 then
5748 e_LogWritefln('%s', [g_Corpses_GetMax()])
5752 e_LogWritefln('usage: %s <n>', [cmd
])
5755 else if cmd
= 'g_scorelimit' then
5757 if Length(P
) > 1 then
5759 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
5761 if g_Game_IsServer
then
5764 if gGameSettings
.GameMode
= GM_DM
then
5766 stat
:= g_Player_GetStats();
5768 for a
:= 0 to High(stat
) do
5769 if stat
[a
].Frags
> b
then
5773 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5775 // if someone has a higher score, set it to that instead
5776 gsGoalLimit
:= max(gsGoalLimit
, b
);
5777 gGameSettings
.GoalLimit
:= gsGoalLimit
;
5779 if g_Game_IsNet
then MH_SEND_GameSettings
;
5783 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
5785 else if cmd
= 'g_timelimit' then
5787 if Length(P
) > 1 then
5789 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
5790 if g_Game_IsServer
then
5792 gGameSettings
.TimeLimit
:= gsTimeLimit
;
5793 if g_Game_IsNet
then MH_SEND_GameSettings
;
5796 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5797 [gsTimeLimit
div 3600,
5798 (gsTimeLimit
div 60) mod 60,
5799 gsTimeLimit
mod 60]));
5801 else if cmd
= 'g_maxlives' then
5803 if Length(P
) > 1 then
5805 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
5806 if g_Game_IsServer
then
5808 gGameSettings
.MaxLives
:= gsMaxLives
;
5809 if g_Game_IsNet
then MH_SEND_GameSettings
;
5813 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
5817 procedure PlayerSettingsCVars(P
: SSArray
);
5822 function ParseTeam(s
: string): Byte;
5826 'red', '1': result
:= TEAM_RED
;
5827 'blue', '2': result
:= TEAM_BLUE
;
5828 else result
:= TEAM_NONE
;
5832 cmd
:= LowerCase(P
[0]);
5836 if (Length(P
) > 1) then
5838 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5839 if g_Game_IsClient
then
5840 MC_SEND_PlayerSettings
5841 else if gGameOn
and (gPlayer1
<> nil) then
5843 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5844 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5850 if (Length(P
) > 1) then
5852 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5853 if g_Game_IsClient
then
5854 MC_SEND_PlayerSettings
5855 else if gGameOn
and (gPlayer2
<> nil) then
5857 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5858 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5864 if Length(P
) > 3 then
5866 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5867 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5868 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5869 if g_Game_IsClient
then
5870 MC_SEND_PlayerSettings
5871 else if gGameOn
and (gPlayer1
<> nil) then
5873 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
5874 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5880 if Length(P
) > 3 then
5882 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5883 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5884 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5885 if g_Game_IsClient
then
5886 MC_SEND_PlayerSettings
5887 else if gGameOn
and (gPlayer2
<> nil) then
5889 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
5890 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5896 if (Length(P
) > 1) then
5898 gPlayer1Settings
.Model
:= P
[1];
5899 if g_Game_IsClient
then
5900 MC_SEND_PlayerSettings
5901 else if gGameOn
and (gPlayer1
<> nil) then
5903 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
5904 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
5905 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5911 if (Length(P
) > 1) then
5913 gPlayer2Settings
.Model
:= P
[1];
5914 if g_Game_IsClient
then
5915 MC_SEND_PlayerSettings
5916 else if gGameOn
and (gPlayer2
<> nil) then
5918 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
5919 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
5920 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5926 // TODO: switch teams if in game or store this separately
5927 if (Length(P
) > 1) then
5929 team
:= ParseTeam(P
[1]);
5930 if team
= TEAM_NONE
then
5931 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5932 else if not gGameOn
and not g_Game_IsNet
then
5933 gPlayer1Settings
.Team
:= team
5935 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5940 // TODO: switch teams if in game or store this separately
5941 if (Length(P
) > 1) then
5943 team
:= ParseTeam(P
[1]);
5944 if team
= TEAM_NONE
then
5945 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5946 else if not gGameOn
and not g_Game_IsNet
then
5947 gPlayer2Settings
.Team
:= team
5949 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5954 if (Length(P
) = 2) then
5955 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
5959 if (Length(P
) = 2) then
5960 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
5964 if (Length(P
) = 2) then
5965 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5969 if (Length(P
) = 2) then
5970 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
5972 'p1_priority_kastet':
5974 if (Length(P
) = 2) then
5975 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
5977 'p2_priority_kastet':
5979 if (Length(P
) = 2) then
5980 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
5984 if (Length(P
) = 2) then
5985 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
5989 if (Length(P
) = 2) then
5990 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
5992 'p1_priority_pistol':
5994 if (Length(P
) = 2) then
5995 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
5997 'p2_priority_pistol':
5999 if (Length(P
) = 2) then
6000 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6002 'p1_priority_shotgun1':
6004 if (Length(P
) = 2) then
6005 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6007 'p2_priority_shotgun1':
6009 if (Length(P
) = 2) then
6010 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6012 'p1_priority_shotgun2':
6014 if (Length(P
) = 2) then
6015 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6017 'p2_priority_shotgun2':
6019 if (Length(P
) = 2) then
6020 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6022 'p1_priority_chaingun':
6024 if (Length(P
) = 2) then
6025 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6027 'p2_priority_chaingun':
6029 if (Length(P
) = 2) then
6030 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6032 'p1_priority_rocketlauncher':
6034 if (Length(P
) = 2) then
6035 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6037 'p2_priority_rocketlauncher':
6039 if (Length(P
) = 2) then
6040 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6042 'p1_priority_plasma':
6044 if (Length(P
) = 2) then
6045 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6047 'p2_priority_plasma':
6049 if (Length(P
) = 2) then
6050 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6054 if (Length(P
) = 2) then
6055 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6059 if (Length(P
) = 2) then
6060 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6062 'p1_priority_super':
6064 if (Length(P
) = 2) then
6065 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6067 'p2_priority_super':
6069 if (Length(P
) = 2) then
6070 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6072 'p1_priority_flamethrower':
6074 if (Length(P
) = 2) then
6075 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6077 'p2_priority_flamethrower':
6079 if (Length(P
) = 2) then
6080 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6082 'p1_priority_berserk':
6084 if (Length(P
) = 2) then
6085 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6087 'p2_priority_berserk':
6089 if (Length(P
) = 2) then
6090 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
6095 procedure PrintHeapStats();
6099 hs
:= GetFPCHeapStatus();
6100 e_LogWriteLn ('v===== heap status =====v');
6101 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
6102 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
6103 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
6104 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
6105 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
6106 e_LogWriteLn ('^=======================^');
6109 procedure DebugCommands(P
: SSArray
);
6116 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6117 if {gDebugMode}conIsCheatsEnabled
then
6119 cmd
:= LowerCase(P
[0]);
6120 if cmd
= 'd_window' then
6122 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6123 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
6125 else if cmd
= 'd_sounds' then
6127 if (Length(P
) > 1) and
6128 ((P
[1] = '1') or (P
[1] = '0')) then
6129 g_Debug_Sounds
:= (P
[1][1] = '1');
6131 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
6133 else if cmd
= 'd_frames' then
6135 if (Length(P
) > 1) and
6136 ((P
[1] = '1') or (P
[1] = '0')) then
6137 g_Debug_Frames
:= (P
[1][1] = '1');
6139 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
6141 else if cmd
= 'd_winmsg' then
6143 if (Length(P
) > 1) and
6144 ((P
[1] = '1') or (P
[1] = '0')) then
6145 g_Debug_WinMsgs
:= (P
[1][1] = '1');
6147 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
6149 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
6151 if (Length(P
) > 1) and
6152 ((P
[1] = '1') or (P
[1] = '0')) then
6153 g_Debug_MonsterOff
:= (P
[1][1] = '1');
6155 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
6157 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
6159 if Length(P
) > 1 then
6161 '0': g_debug_BotAIOff
:= 0;
6162 '1': g_debug_BotAIOff
:= 1;
6163 '2': g_debug_BotAIOff
:= 2;
6164 '3': g_debug_BotAIOff
:= 3;
6167 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
6169 else if cmd
= 'd_monster' then
6171 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
6172 if Length(P
) < 2 then
6174 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
6175 g_Console_Add('ID | Name');
6176 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
6177 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
6178 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6181 a
:= StrToIntDef(P
[1], 0);
6182 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6183 a
:= g_Mons_TypeIdByName(P
[1]);
6185 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
6186 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
6189 with gPlayer1
.Obj
do
6191 mon
:= g_Monsters_Create(a
,
6192 X
+ Rect
.X
+ (Rect
.Width
div 2),
6193 Y
+ Rect
.Y
+ Rect
.Height
,
6194 gPlayer1
.Direction
, True);
6196 if (Length(P
) > 2) and (mon
<> nil) then
6198 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
6199 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
6200 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
6201 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
6202 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
6203 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6204 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6205 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
6206 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
6211 else if (cmd
= 'd_health') then
6213 if (Length(P
) > 1) and
6214 ((P
[1] = '1') or (P
[1] = '0')) then
6215 g_debug_HealthBar
:= (P
[1][1] = '1');
6217 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
6219 else if (cmd
= 'd_player') then
6221 if (Length(P
) > 1) and
6222 ((P
[1] = '1') or (P
[1] = '0')) then
6223 g_debug_Player
:= (P
[1][1] = '1');
6225 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
6227 else if (cmd
= 'd_mem') then
6233 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
6237 procedure GameCheats(P
: SSArray
);
6243 if (not gGameOn
) or (not conIsCheatsEnabled
) then
6245 g_Console_Add('not available');
6251 g_Console_Add('where is the player?!');
6254 cmd
:= LowerCase(P
[0]);
6258 plr
.GodMode
:= not plr
.GodMode
;
6259 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6262 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6263 if cmd
= 'give' then
6265 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
6266 for f
:= 1 to High(P
) do
6268 cmd
:= LowerCase(P
[f
]);
6269 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
6270 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
6271 if cmd
= 'exit' then
6273 if gTriggers
<> nil then
6275 for a
:= 0 to High(gTriggers
) do
6277 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6279 g_Console_Add('player left the map');
6280 gExitByTrigger
:= True;
6281 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6282 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
6290 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
6291 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
6292 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
6293 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
6294 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
6296 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
6297 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
6299 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
6300 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;
6302 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6303 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6305 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6306 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6308 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6309 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6311 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6312 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6313 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6315 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6316 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6317 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6318 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;
6319 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6320 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6322 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;
6323 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;
6324 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;
6325 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;
6326 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;
6327 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;
6329 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6330 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;
6332 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;
6333 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;
6335 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6337 if cmd
= 'ammo' then
6339 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6340 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6341 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6342 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6343 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6344 g_Console_Add('player got some ammo');
6348 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6349 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6351 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6352 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6354 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6355 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6357 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6358 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6360 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6362 if cmd
= 'weapons' then
6364 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6365 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6366 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6367 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6368 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6369 plr
.GiveItem(ITEM_WEAPON_BFG
);
6370 g_Console_Add('player got weapons');
6374 if cmd
= 'keys' then
6376 plr
.GiveItem(ITEM_KEY_RED
);
6377 plr
.GiveItem(ITEM_KEY_GREEN
);
6378 plr
.GiveItem(ITEM_KEY_BLUE
);
6379 g_Console_Add('player got all keys');
6383 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6388 if cmd
= 'open' then
6390 g_Console_Add('player activated sesame');
6391 g_Triggers_OpenAll();
6398 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6402 if cmd
= 'noclip' then
6405 g_Console_Add('wall hardeness adjusted');
6409 if cmd
= 'notarget' then
6411 plr
.NoTarget
:= not plr
.NoTarget
;
6412 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6416 if cmd
= 'noreload' then
6418 plr
.NoReload
:= not plr
.NoReload
;
6419 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6423 if cmd
= 'speedy' then
6425 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6426 g_Console_Add('speed adjusted');
6430 if cmd
= 'jumpy' then
6432 VEL_JUMP
:= 30-VEL_JUMP
;
6433 g_Console_Add('jump height adjusted');
6437 if cmd
= 'automap' then
6439 gShowMap
:= not gShowMap
;
6440 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6444 if cmd
= 'aimline' then
6446 gAimLine
:= not gAimLine
;
6447 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6452 procedure GameCommands(P
: SSArray
);
6458 pl
: pTNetClient
= nil;
6466 cmd
:= LowerCase(P
[0]);
6468 if cmd
= 'pause' then
6470 if (g_ActiveWindow
= nil) then
6471 g_Game_Pause(not gPauseMain
);
6473 else if cmd
= 'endgame' then
6474 gExit
:= EXIT_SIMPLE
6475 else if cmd
= 'restart' then
6477 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6479 if g_Game_IsClient
then
6481 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6486 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6488 else if cmd
= 'kick' then
6490 if g_Game_IsServer
then
6492 if Length(P
) < 2 then
6494 g_Console_Add('kick <name>');
6499 g_Console_Add('kick <name>');
6503 if g_Game_IsNet
then
6504 pl
:= g_Net_Client_ByName(P
[1]);
6507 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6508 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6509 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6510 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6511 g_Net_Slist_ServerPlayerLeaves();
6512 end else if gPlayers
<> nil then
6513 for a
:= Low(gPlayers
) to High(gPlayers
) do
6514 if gPlayers
[a
] <> nil then
6515 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6517 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6518 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6520 gPlayers
[a
].Lives
:= 0;
6521 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6522 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6523 g_Player_Remove(gPlayers
[a
].UID
);
6524 g_Net_Slist_ServerPlayerLeaves();
6525 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6529 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6531 else if cmd
= 'kick_id' then
6533 if g_Game_IsServer
and g_Game_IsNet
then
6535 if Length(P
) < 2 then
6537 g_Console_Add('kick_id <client ID>');
6542 g_Console_Add('kick_id <client ID>');
6546 a
:= StrToIntDef(P
[1], 0);
6547 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6549 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6551 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6552 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6553 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6554 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6555 g_Net_Slist_ServerPlayerLeaves();
6559 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6561 else if cmd
= 'kick_pid' then
6563 if g_Game_IsServer
and g_Game_IsNet
then
6565 if Length(P
) < 2 then
6567 g_Console_Add('kick_pid <player ID>');
6572 g_Console_Add('kick_pid <player ID>');
6576 a
:= StrToIntDef(P
[1], 0);
6577 pl
:= g_Net_Client_ByPlayer(a
);
6578 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6580 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6581 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6582 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6583 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6584 g_Net_Slist_ServerPlayerLeaves();
6587 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6589 else if cmd
= 'ban' then
6591 if g_Game_IsServer
and g_Game_IsNet
then
6593 if Length(P
) < 2 then
6595 g_Console_Add('ban <name>');
6600 g_Console_Add('ban <name>');
6604 pl
:= g_Net_Client_ByName(P
[1]);
6607 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6608 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6609 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6610 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6611 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6612 g_Net_Slist_ServerPlayerLeaves();
6614 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6616 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6618 else if cmd
= 'ban_id' then
6620 if g_Game_IsServer
and g_Game_IsNet
then
6622 if Length(P
) < 2 then
6624 g_Console_Add('ban_id <client ID>');
6629 g_Console_Add('ban_id <client ID>');
6633 a
:= StrToIntDef(P
[1], 0);
6634 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6635 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6637 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6638 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6639 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6640 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6641 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6642 g_Net_Slist_ServerPlayerLeaves();
6645 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6647 else if cmd
= 'ban_pid' then
6649 if g_Game_IsServer
and g_Game_IsNet
then
6651 if Length(P
) < 2 then
6653 g_Console_Add('ban_pid <player ID>');
6658 g_Console_Add('ban_pid <player ID>');
6662 a
:= StrToIntDef(P
[1], 0);
6663 pl
:= g_Net_Client_ByPlayer(a
);
6664 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6666 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6667 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6668 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6669 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6670 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6671 g_Net_Slist_ServerPlayerLeaves();
6674 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6676 else if cmd
= 'permban' then
6678 if g_Game_IsServer
and g_Game_IsNet
then
6680 if Length(P
) < 2 then
6682 g_Console_Add('permban <name>');
6687 g_Console_Add('permban <name>');
6691 pl
:= g_Net_Client_ByName(P
[1]);
6694 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6695 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6696 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6697 g_Net_SaveBanList();
6698 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6699 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6700 g_Net_Slist_ServerPlayerLeaves();
6702 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6704 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6706 else if cmd
= 'permban_id' then
6708 if g_Game_IsServer
and g_Game_IsNet
then
6710 if Length(P
) < 2 then
6712 g_Console_Add('permban_id <client ID>');
6717 g_Console_Add('permban_id <client ID>');
6721 a
:= StrToIntDef(P
[1], 0);
6722 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6723 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6725 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6726 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6727 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6728 g_Net_SaveBanList();
6729 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6730 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6731 g_Net_Slist_ServerPlayerLeaves();
6734 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6736 else if cmd
= 'permban_pid' then
6738 if g_Game_IsServer
and g_Game_IsNet
then
6740 if Length(P
) < 2 then
6742 g_Console_Add('permban_pid <player ID>');
6747 g_Console_Add('permban_pid <player ID>');
6751 a
:= StrToIntDef(P
[1], 0);
6752 pl
:= g_Net_Client_ByPlayer(a
);
6753 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
6755 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6756 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6757 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6758 g_Net_SaveBanList();
6759 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6760 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6761 g_Net_Slist_ServerPlayerLeaves();
6764 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6766 else if cmd
= 'permban_ip' then
6768 if g_Game_IsServer
and g_Game_IsNet
then
6770 if Length(P
) < 2 then
6772 g_Console_Add('permban_ip <IP address>');
6777 g_Console_Add('permban_ip <IP address>');
6781 g_Net_BanHost(P
[1]);
6782 g_Net_SaveBanList();
6783 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
6785 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6787 else if cmd
= 'unban' then
6789 if g_Game_IsServer
and g_Game_IsNet
then
6791 if Length(P
) < 2 then
6793 g_Console_Add('unban <IP Address>');
6798 g_Console_Add('unban <IP Address>');
6802 if g_Net_UnbanHost(P
[1]) then
6804 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6805 g_Net_SaveBanList();
6807 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6809 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6811 else if cmd
= 'clientlist' then
6813 if g_Game_IsServer
and g_Game_IsNet
then
6816 if NetClients
<> nil then
6817 for a
:= Low(NetClients
) to High(NetClients
) do
6818 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6820 plr
:= g_Player_Get(NetClients
[a
].Player
);
6821 if plr
= nil then continue
;
6823 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6824 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6827 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6829 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6831 else if cmd
= 'connect' then
6833 if (NetMode
= NET_NONE
) then
6835 if Length(P
) < 2 then
6837 g_Console_Add('connect <IP> [port] [password]');
6842 g_Console_Add('connect <IP> [port] [password]');
6846 if Length(P
) > 2 then
6847 prt
:= StrToIntDef(P
[2], 25666)
6851 if Length(P
) > 3 then
6856 g_Game_StartClient(P
[1], prt
, pw
);
6859 else if cmd
= 'disconnect' then
6861 if (NetMode
= NET_CLIENT
) then
6864 else if cmd
= 'reconnect' then
6866 if (NetMode
= NET_SERVER
) then
6869 if (NetMode
= NET_CLIENT
) then
6872 gExit
:= EXIT_SIMPLE
;
6876 //TODO: Use last successful password to reconnect, instead of ''
6877 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6879 else if (cmd
= 'addbot') or
6880 (cmd
= 'bot_add') then
6882 if Length(P
) > 2 then
6883 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6884 else if Length(P
) > 1 then
6885 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6887 g_Bot_Add(TEAM_NONE
, 2);
6889 else if cmd
= 'bot_addlist' then
6891 if Length(P
) > 1 then
6893 if Length(P
) = 2 then
6894 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6895 else if Length(P
) = 3 then
6896 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6898 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6901 else if cmd
= 'bot_removeall' then
6903 else if cmd
= 'chat' then
6905 if g_Game_IsNet
then
6907 if Length(P
) > 1 then
6909 for a
:= 1 to High(P
) do
6910 chstr
:= chstr
+ P
[a
] + ' ';
6912 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6914 if Length(chstr
) < 1 then
6916 g_Console_Add('chat <text>');
6920 chstr
:= b_Text_Format(chstr
);
6921 if g_Game_IsClient
then
6922 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6924 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6927 g_Console_Add('chat <text>');
6929 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6931 else if cmd
= 'teamchat' then
6933 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6935 if Length(P
) > 1 then
6937 for a
:= 1 to High(P
) do
6938 chstr
:= chstr
+ P
[a
] + ' ';
6940 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6942 if Length(chstr
) < 1 then
6944 g_Console_Add('teamchat <text>');
6948 chstr
:= b_Text_Format(chstr
);
6949 if g_Game_IsClient
then
6950 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6952 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6953 gPlayer1Settings
.Team
);
6956 g_Console_Add('teamchat <text>');
6958 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6960 else if cmd
= 'game' then
6962 if gGameSettings
.GameType
<> GT_NONE
then
6964 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6967 if Length(P
) = 1 then
6969 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6972 // game not started yet, load fist map from some wad
6974 s
:= addWadExtension(P
[1]);
6975 found
:= e_FindResource(AllMapDirs
, s
);
6979 P
[1] := ExpandFileName(P
[1]);
6980 // if map not choosed then set first map
6981 if Length(P
) < 3 then
6984 P
[2] := g_Game_GetFirstMap(P
[1]);
6987 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6989 if g_Map_Exist(s
) then
6993 with gGameSettings
do
6995 Options
:= gsGameFlags
;
6996 GameMode
:= g_Game_TextToMode(gsGameMode
);
6997 if gSwitchGameMode
<> GM_NONE
then
6998 GameMode
:= gSwitchGameMode
;
6999 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7000 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7002 if Length(P
) >= 4 then
7003 b
:= StrToIntDef(P
[3], 1);
7004 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
7005 GoalLimit
, MaxLives
, Options
, b
);
7010 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7012 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
7014 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
7016 else if cmd
= 'host' then
7018 if gGameSettings
.GameType
<> GT_NONE
then
7020 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7023 if Length(P
) < 4 then
7025 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
7028 if not StrToIp(P
[1], listen
) then
7030 prt
:= StrToIntDef(P
[2], 25666);
7032 s
:= addWadExtension(P
[3]);
7033 found
:= e_FindResource(AllMapDirs
, s
);
7037 // get first map in wad, if not specified
7038 if Length(P
) < 5 then
7041 P
[4] := g_Game_GetFirstMap(P
[1]);
7043 s
:= P
[3] + ':\' + UpperCase(P
[4]);
7044 if g_Map_Exist(s
) then
7048 with gGameSettings
do
7050 Options
:= gsGameFlags
;
7051 GameMode
:= g_Game_TextToMode(gsGameMode
);
7052 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
7053 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
7054 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
7056 if Length(P
) >= 6 then
7057 b
:= StrToIntDef(P
[5], 0);
7058 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
7064 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
7066 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
7071 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
7074 else if cmd
= 'map' then
7076 if Length(P
) = 1 then
7078 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7080 g_Console_Add(cmd
+ ' <MAP>');
7081 g_Console_Add(cmd
+ ' <WAD> [MAP]')
7085 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7090 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7092 if Length(P
) < 3 then
7094 // first param is map or wad
7095 s
:= UpperCase(P
[1]);
7096 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7098 gExitByTrigger
:= False;
7101 // already in game, finish current map
7103 gExit
:= EXIT_ENDLEVELCUSTOM
;
7107 // intermission, so change map immediately
7114 found
:= e_FindResource(AllMapDirs
, s
);
7116 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
7119 // no such map, found wad
7122 P
[1] := ExpandFileName(pw
);
7123 P
[2] := g_Game_GetFirstMap(P
[1]);
7124 s
:= P
[1] + ':\' + P
[2];
7125 if g_Map_Exist(s
) then
7127 gExitByTrigger
:= False;
7130 // already in game, finish current map
7132 gExit
:= EXIT_ENDLEVELCUSTOM
7136 // intermission, so change map immediately
7143 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7145 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7150 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7156 s
:= addWadExtension(P
[1]);
7157 found
:= e_FindResource(AllMapDirs
, s
);
7161 P
[2] := UpperCase(P
[2]);
7162 s
:= P
[1] + ':\' + P
[2];
7163 if g_Map_Exist(s
) then
7165 gExitByTrigger
:= False;
7169 gExit
:= EXIT_ENDLEVELCUSTOM
7178 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7183 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7189 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7193 else if cmd
= 'nextmap' then
7195 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
7197 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7202 if Length(P
) = 1 then
7204 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7206 g_Console_Add(cmd
+ ' <MAP>');
7207 g_Console_Add(cmd
+ ' <WAD> [MAP]');
7212 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
7218 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7220 if Length(P
) < 3 then
7222 // first param is map or wad
7223 s
:= UpperCase(P
[1]);
7224 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
7227 gExitByTrigger
:= False;
7233 // no such map, found wad
7234 pw
:= addWadExtension(P
[1]);
7235 found
:= e_FindResource(MapDirs
, pw
);
7237 found
:= e_FindResource(WadDirs
, pw
);
7239 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
7242 // map not specified, select first map
7244 P
[2] := g_Game_GetFirstMap(P
[1]);
7245 s
:= P
[1] + ':\' + P
[2];
7246 if g_Map_Exist(s
) then
7248 gExitByTrigger
:= False;
7255 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
7257 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7262 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7268 // specified two params wad + map
7269 pw
:= addWadExtension(P
[1]);
7270 found
:= e_FindResource(MapDirs
, pw
);
7272 found
:= e_FindResource(MapDirs
, pw
);
7276 P
[2] := UpperCase(P
[2]);
7277 s
:= P
[1] + ':\' + P
[2];
7278 if g_Map_Exist(s
) then
7280 gExitByTrigger
:= False;
7286 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
7291 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
7297 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7302 if gNextMap
= '' then
7303 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
7305 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
7309 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
7313 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
7317 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
7319 gExitByTrigger
:= False;
7320 // next map not specified, try to find trigger EXIT
7321 if (gNextMap
= '') and (gTriggers
<> nil) then
7323 for a
:= 0 to High(gTriggers
) do
7325 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
7327 gExitByTrigger
:= True;
7328 //gNextMap := gTriggers[a].Data.MapName;
7329 gNextMap
:= gTriggers
[a
].tgcMap
;
7334 if gNextMap
= '' then
7335 gNextMap
:= g_Game_GetNextMap();
7336 if not isWadPath(gNextMap
) then
7337 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
7340 if g_Map_Exist(s
) then
7341 gExit
:= EXIT_ENDLEVELCUSTOM
7343 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
7347 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
7351 else if (cmd
= 'event') then
7353 if (Length(P
) <= 1) then
7355 for a
:= 0 to High(gEvents
) do
7356 if gEvents
[a
].Command
= '' then
7357 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7359 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7362 if (Length(P
) = 2) then
7364 for a
:= 0 to High(gEvents
) do
7365 if gEvents
[a
].Name
= P
[1] then
7366 if gEvents
[a
].Command
= '' then
7367 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
7369 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
7372 for a
:= 0 to High(gEvents
) do
7373 if gEvents
[a
].Name
= P
[1] then
7375 gEvents
[a
].Command
:= '';
7376 for b
:= 2 to High(P
) do
7377 if Pos(' ', P
[b
]) = 0 then
7378 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
7380 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
7381 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
7385 else if cmd
= 'suicide' then
7389 if g_Game_IsClient
then
7390 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
7393 if gPlayer1
<> nil then
7394 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
7395 if gPlayer2
<> nil then
7396 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
7400 else if cmd
= 'screenshot' then
7404 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
7406 a
:= 1 - (ord(cmd
[5]) - ord('n'));
7408 gWeaponAction
[0, WP_PREV
] := True;
7410 gWeaponAction
[0, WP_NEXT
] := True;
7412 else if cmd
= 'weapon' then
7414 if Length(p
) = 2 then
7416 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7417 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7418 gSelectWeapon
[0, a
] := True
7421 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
7422 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
7424 a
:= 1 - (ord(cmd
[8]) - ord('n'));
7425 b
:= ord(cmd
[2]) - ord('1');
7427 gWeaponAction
[b
, WP_PREV
] := True;
7429 gWeaponAction
[b
, WP_NEXT
] := True;
7431 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7433 if Length(p
) = 2 then
7435 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7436 b
:= ord(cmd
[2]) - ord('1');
7437 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7438 gSelectWeapon
[b
, a
] := True
7441 else if (cmd
= 'dropflag') then
7443 if g_Game_IsServer
then
7445 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
7446 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
7449 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7451 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
7453 b
:= ord(cmd
[2]) - ord('1');
7454 if g_Game_IsServer
then
7456 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
7457 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
7460 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
7462 // Êîìàíäû Ñâîåé èãðû:
7463 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7465 if cmd
= 'bot_addred' then
7467 if Length(P
) > 1 then
7468 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7470 g_Bot_Add(TEAM_RED
, 2);
7472 else if cmd
= 'bot_addblue' then
7474 if Length(P
) > 1 then
7475 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7477 g_Bot_Add(TEAM_BLUE
, 2);
7479 else if cmd
= 'spectate' then
7485 else if cmd
= 'say' then
7487 if g_Game_IsServer
and g_Game_IsNet
then
7489 if Length(P
) > 1 then
7492 for a
:= 1 to High(P
) do
7493 chstr
:= chstr
+ P
[a
] + ' ';
7495 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7497 if Length(chstr
) < 1 then
7499 g_Console_Add('say <text>');
7503 chstr
:= b_Text_Format(chstr
);
7504 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7506 else g_Console_Add('say <text>');
7508 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7510 else if cmd
= 'tell' then
7512 if g_Game_IsServer
and g_Game_IsNet
then
7514 if (Length(P
) > 2) and (P
[1] <> '') then
7517 for a
:= 2 to High(P
) do
7518 chstr
:= chstr
+ P
[a
] + ' ';
7520 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7522 if Length(chstr
) < 1 then
7524 g_Console_Add('tell <playername> <text>');
7528 pl
:= g_Net_Client_ByName(P
[1]);
7530 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7532 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7534 else g_Console_Add('tell <playername> <text>');
7536 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7538 else if cmd
= 'centerprint' then
7540 if (Length(P
) > 2) and (P
[1] <> '') then
7543 for a
:= 2 to High(P
) do
7544 chstr
:= chstr
+ P
[a
] + ' ';
7546 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7548 if Length(chstr
) < 1 then
7550 g_Console_Add('centerprint <timeout> <text>');
7554 a
:= StrToIntDef(P
[1], 100);
7555 chstr
:= b_Text_Format(chstr
);
7556 g_Game_Message(chstr
, a
);
7557 if g_Game_IsNet
and g_Game_IsServer
then
7558 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
7560 else g_Console_Add('centerprint <timeout> <text>');
7562 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7564 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7566 // Äîïîëíèòåëüíîå âðåìÿ:
7567 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7569 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7570 [gGameSettings
.TimeLimit
div 3600,
7571 (gGameSettings
.TimeLimit
div 60) mod 60,
7572 gGameSettings
.TimeLimit
mod 60]));
7573 if g_Game_IsNet
then MH_SEND_GameSettings
;
7575 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7577 if (Length(P
) <= 1) then
7578 g_Console_Add('rcon_password <password>')
7580 MC_SEND_RCONPassword(P
[1]);
7582 else if cmd
= 'rcon' then
7584 if g_Game_IsClient
then
7586 if Length(P
) > 1 then
7589 for a
:= 1 to High(P
) do
7590 chstr
:= chstr
+ P
[a
] + ' ';
7592 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7594 if Length(chstr
) < 1 then
7596 g_Console_Add('rcon <command>');
7600 MC_SEND_RCONCommand(chstr
);
7602 else g_Console_Add('rcon <command>');
7605 else if cmd
= 'ready' then
7607 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7608 gLMSRespawnTime
:= gTime
+ 100;
7610 else if (cmd
= 'callvote') and g_Game_IsNet
then
7612 if Length(P
) > 1 then
7615 for a
:= 1 to High(P
) do begin
7616 if a
> 1 then chstr
:= chstr
+ ' ';
7617 chstr
:= chstr
+ P
[a
];
7620 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7622 if Length(chstr
) < 1 then
7624 g_Console_Add('callvote <command>');
7628 if g_Game_IsClient
then
7629 MC_SEND_Vote(True, chstr
)
7631 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7632 g_Console_Process('vote', True);
7635 g_Console_Add('callvote <command>');
7637 else if (cmd
= 'vote') and g_Game_IsNet
then
7639 if g_Game_IsClient
then
7641 else if gVoteInProgress
then
7643 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7644 a
:= Floor((NetClientCount
+1)/2.0) + 1
7646 a
:= Floor(NetClientCount
/2.0) + 1;
7651 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7652 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7658 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7659 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7667 procedure SystemCommands(P
: SSArray
);
7671 cmd
:= LowerCase(P
[0]);
7680 gRC_Width
:= Max(1, gRC_Width
);
7681 gRC_Height
:= Max(1, gRC_Height
);
7682 gBPP
:= Max(1, gBPP
);
7683 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
7684 e_LogWriteln('resolution changed')
7686 e_LogWriteln('resolution not changed');
7687 sys_EnableVSync(gVSync
);
7691 if Length(p
) = 2 then
7693 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
7695 gFrameTime
:= 1000 div gMaxFPS
7699 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
7703 if Length(p
) = 2 then
7705 gAskLanguage
:= true;
7706 gLanguage
:= LANGUAGE_ENGLISH
;
7707 case LowerCase(p
[1]) of
7710 gAskLanguage
:= false;
7711 gLanguage
:= LANGUAGE_ENGLISH
;
7715 gAskLanguage
:= false;
7716 gLanguage
:= LANGUAGE_RUSSIAN
;
7720 gAskLanguage
:= true;
7721 gLanguage
:= LANGUAGE_ENGLISH
;
7724 g_Language_Set(gLanguage
);
7728 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
7734 procedure g_TakeScreenShot(Filename
: string = '');
7735 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
7737 if e_NoGraphics
then Exit
;
7739 dir
:= e_GetWriteableDir(ScreenshotDirs
);
7741 if Filename
= '' then
7744 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7745 Filename
:= 'screenshot-' + date
;
7748 name
:= e_CatPath(dir
, Filename
+ '.png');
7749 s
:= createDiskFile(name
);
7751 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7753 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7755 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
7760 g_Console_Add('oh shit, i can''t create screenshot!')
7764 procedure g_Game_InGameMenu(Show
: Boolean);
7766 if (g_ActiveWindow
= nil) and Show
then
7768 if gGameSettings
.GameType
= GT_SINGLE
then
7769 g_GUI_ShowWindow('GameSingleMenu')
7772 if g_Game_IsClient
then
7773 g_GUI_ShowWindow('GameClientMenu')
7775 if g_Game_IsNet
then
7776 g_GUI_ShowWindow('GameServerMenu')
7778 g_GUI_ShowWindow('GameCustomMenu');
7780 g_Sound_PlayEx('MENU_OPEN');
7782 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7783 if (not g_Game_IsNet
) then
7787 if (g_ActiveWindow
<> nil) and (not Show
) then
7789 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7790 if (not g_Game_IsNet
) then
7791 g_Game_Pause(False);
7795 procedure g_Game_Pause (Enable
: Boolean);
7799 if not gGameOn
then exit
;
7801 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7804 gPauseMain
:= Enable
;
7806 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7809 procedure g_Game_HolmesPause (Enable
: Boolean);
7813 if not gGameOn
then exit
;
7814 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7817 gPauseHolmes
:= Enable
;
7819 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7822 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7827 if gTriggers
<> nil then
7828 for i
:= 0 to High(gTriggers
) do
7829 with gTriggers
[i
] do
7830 if (TriggerType
= TRIGGER_SOUND
) and
7832 Sound
.IsPlaying() then
7834 Sound
.Pause(Enable
);
7838 if gPlayers
<> nil then
7839 for i
:= 0 to High(gPlayers
) do
7840 if gPlayers
[i
] <> nil then
7841 gPlayers
[i
].PauseSounds(Enable
);
7844 if gMusic
<> nil then
7845 gMusic
.Pause(Enable
);
7848 procedure g_Game_StopAllSounds(all
: Boolean);
7852 if gTriggers
<> nil then
7853 for i
:= 0 to High(gTriggers
) do
7854 with gTriggers
[i
] do
7855 if (TriggerType
= TRIGGER_SOUND
) and
7859 if gMusic
<> nil then
7866 procedure g_Game_UpdateTriggerSounds
;
7869 if gTriggers
<> nil then
7870 for i
:= 0 to High(gTriggers
) do
7871 with gTriggers
[i
] do
7872 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7873 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7876 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7879 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7884 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7889 if gSpectMode
<> SPECT_PLAYERS
then
7891 if gSpectPID1
= UID
then
7896 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7903 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7908 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7913 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7918 if gSpectMode
<> SPECT_PLAYERS
then
7920 Pl
:= g_Player_Get(gSpectPID1
);
7921 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7926 if gSpectViewTwo
then
7928 Pl
:= g_Player_Get(gSpectPID2
);
7929 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7937 procedure g_Game_Message(Msg
: string; Time
: Word);
7939 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7940 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7941 MessageTime
:= Time
;
7944 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7946 punct
: Array[0..13] of String =
7947 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7953 function IsPunctuation(S
: String): Boolean;
7958 if Length(S
) <> 1 then
7960 for i
:= Low(punct
) to High(punct
) do
7961 if S
= punct
[i
] then
7967 function FilterPunctuation(S
: String): String;
7971 for i
:= Low(punct
) to High(punct
) do
7972 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7978 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7980 // remove player name
7981 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7982 // for FullWord check
7983 Text := toLowerCase1251(' ' + Text + ' ');
7984 fpText
:= FilterPunctuation(Text);
7986 for i
:= 0 to Length(gChatSounds
) - 1 do
7989 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7991 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7992 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7994 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
8000 gChatSounds
[i
].Sound
.Play();
8006 g_Sound_PlayEx('SOUND_GAME_RADIO');
8009 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
8018 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8022 if goodsnd
[a
].IsPlaying() then
8025 goodsnd
[Random(4)].Play();
8028 procedure g_Game_Announce_KillCombo(Param
: Integer);
8035 UID
:= Param
and $FFFF;
8040 Pl
:= g_Player_Get(UID
);
8049 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
8053 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
8057 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
8061 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
8069 if not g_Game_IsWatchedPlayer(UID
) then
8072 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
8076 if killsnd
[n
].IsPlaying() then
8081 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
8089 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
8093 if hahasnd
[a
].IsPlaying() then
8096 hahasnd
[Random(3)].Play();
8099 procedure g_Game_StartVote(Command
, Initiator
: string);
8103 if not gVotesEnabled
then Exit
;
8104 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8105 if gVoteInProgress
or gVotePassed
then
8107 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
8108 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
8111 gVoteInProgress
:= True;
8112 gVotePassed
:= False;
8113 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
8116 gVoteCommand
:= Command
;
8118 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8119 Need
:= Floor((NetClientCount
+1)/2.0)+1
8121 Need
:= Floor(NetClientCount
/2.0)+1;
8122 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
8123 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
8126 procedure g_Game_CheckVote
;
8130 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
8131 if not gVoteInProgress
then Exit
;
8133 if (gTime
>= gVoteTimer
) then
8135 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8136 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8138 Need
:= Floor(NetClientCount
/2.0) + 1;
8139 if gVoteCount
>= Need
then
8141 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8142 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8143 gVotePassed
:= True;
8144 gVoteCmdTimer
:= gTime
+ 5000;
8148 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
8149 MH_SEND_VoteEvent(NET_VE_FAILED
);
8151 if NetClients
<> nil then
8152 for I
:= Low(NetClients
) to High(NetClients
) do
8153 if NetClients
[i
].Used
then
8154 NetClients
[i
].Voted
:= False;
8155 gVoteInProgress
:= False;
8161 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
8162 Need
:= Floor((NetClientCount
+1)/2.0) + 1
8164 Need
:= Floor(NetClientCount
/2.0) + 1;
8165 if gVoteCount
>= Need
then
8167 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
8168 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
8169 gVoteInProgress
:= False;
8170 gVotePassed
:= True;
8171 gVoteCmdTimer
:= gTime
+ 5000;
8174 if NetClients
<> nil then
8175 for I
:= Low(NetClients
) to High(NetClients
) do
8176 if NetClients
[i
].Used
then
8177 NetClients
[i
].Voted
:= False;
8182 procedure g_Game_LoadMapList(FileName
: string);
8190 if not FileExists(FileName
) then Exit
;
8192 AssignFile(ListFile
, FileName
);
8194 while not EOF(ListFile
) do
8196 ReadLn(ListFile
, s
);
8199 if s
= '' then Continue
;
8201 SetLength(MapList
, Length(MapList
)+1);
8202 MapList
[High(MapList
)] := s
;
8204 CloseFile(ListFile
);
8207 procedure g_Game_SetDebugMode();
8210 // ×èòû (äàæå â ñâîåé èãðå):
8214 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
8218 if Length(LoadingStat
.Msgs
) = 0 then
8224 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8225 if NextMsg
= Length(Msgs
) then
8227 for i
:= 0 to High(Msgs
)-1 do
8228 Msgs
[i
] := Msgs
[i
+1];
8236 Msgs
[NextMsg
-1] := Text;
8240 PBarWasHere
:= false;
8243 g_ActiveWindow
:= nil;
8245 ProcessLoading(true);
8248 procedure g_Game_StepLoading(Value
: Integer = -1);
8259 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
8267 procedure g_Game_ClearLoading();
8276 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
8277 if len
< 1 then len
:= 1;
8278 SetLength(Msgs
, len
);
8279 for len
:= Low(Msgs
) to High(Msgs
) do
8282 PBarWasHere
:= false;
8286 procedure Parse_Params(var pars
: TParamStrValues
);
8293 while i
<= ParamCount
do
8296 if (Length(s
) > 1) and (s
[1] = '-') then
8298 if (Length(s
) > 2) and (s
[2] = '-') then
8299 begin // Îäèíî÷íûé ïàðàìåòð
8300 SetLength(pars
, Length(pars
) + 1);
8301 with pars
[High(pars
)] do
8303 Name
:= LowerCase(s
);
8308 if (i
< ParamCount
) then
8309 begin // Ïàðàìåòð ñî çíà÷åíèåì
8311 SetLength(pars
, Length(pars
) + 1);
8312 with pars
[High(pars
)] do
8314 Name
:= LowerCase(s
);
8315 Value
:= LowerCase(ParamStr(i
));
8324 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
8329 for i
:= 0 to High(pars
) do
8330 if pars
[i
].Name
= aName
then
8332 Result
:= pars
[i
].Value
;
8337 procedure g_Game_Process_Params();
8339 pars
: TParamStrValues
;
8342 LimT
, LimS
: Integer;
8353 s
:= Find_Param_Value(pars
, '--debug');
8356 g_Game_SetDebugMode();
8357 s
:= Find_Param_Value(pars
, '--netdump');
8362 // Connect when game loads
8363 ip
:= Find_Param_Value(pars
, '-connect');
8367 s
:= Find_Param_Value(pars
, '-port');
8368 if (s
= '') or not TryStrToInt(s
, Port
) then
8371 s
:= Find_Param_Value(pars
, '-pw');
8373 g_Game_StartClient(ip
, Port
, s
);
8377 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
8380 gDefaultMegawadStart
:= s
;
8383 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
8384 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
8386 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
8389 // Start map when game loads:
8390 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
8391 if isWadPath(map
) then
8394 s
:= Find_Param_Value(pars
, '-gm');
8395 GMode
:= g_Game_TextToMode(s
);
8396 if GMode
= GM_NONE
then GMode
:= GM_DM
;
8397 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
8400 s
:= Find_Param_Value(pars
, '-limt');
8401 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
8407 s
:= Find_Param_Value(pars
, '-lims');
8408 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
8414 s
:= Find_Param_Value(pars
, '-lives');
8415 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
8421 s
:= Find_Param_Value(pars
, '-opt');
8425 Opt
:= StrToIntDef(s
, 0);
8428 s
:= Find_Param_Value(pars
, '--close');
8432 // Override map to test:
8433 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
8436 if e_IsValidResourceName(s
) then
8437 e_FindResource(AllMapDirs
, s
);
8438 gTestMap
:= ExpandFileName(s
);
8441 // Delete test map after play:
8442 s
:= Find_Param_Value(pars
, '--testdelete');
8445 //gMapToDelete := MapsDir + map;
8446 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
8450 // Delete temporary WAD after play:
8451 s
:= Find_Param_Value(pars
, '--tempdelete');
8452 if (s
<> '') and (gTestMap
<> '') then
8454 gMapToDelete
:= gTestMap
;
8455 gTempDelete
:= True;
8458 // Number of players:
8459 s
:= Find_Param_Value(pars
, '-pl');
8461 n
:= DEFAULT_PLAYERS
8463 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
8466 s
:= Find_Param_Value(pars
, '-port');
8467 if (s
= '') or not TryStrToInt(s
, Port
) then
8468 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
8470 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
8473 // Execute script when game loads:
8474 s
:= Find_Param_Value(pars
, '-exec');
8477 // if not isWadPath(s) then
8478 // s := GameDir + '/' + s;
8483 if IOResult
<> 0 then
8485 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8486 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8490 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
8491 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
8496 if IOResult
<> 0 then
8498 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
8499 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
8503 if Pos('#', s
) <> 1 then // script comment
8504 g_Console_Process(s
, True);
8515 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
8516 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8517 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
8518 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
8520 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
8521 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8522 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8523 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8525 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
8526 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
8528 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
8529 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
8531 {$IFDEF ENABLE_HOLMES}
8532 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
8535 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
8537 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
8538 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
8540 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
8541 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
8543 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8544 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8546 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8547 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
8548 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
8549 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
8550 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
8551 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
8552 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
8553 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
8554 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');