sound: allow to completelly disable sound
[d2df-sdl.git] / src / game / g_game.pas
blob25b4c203da82832697a01e467ac6b0eb5baa90af
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}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF, CONFIG,
23 {$IFDEF ENABLE_SOUND}
24 e_sound, g_sound,
25 {$ENDIF}
26 g_basic, g_player, e_graphics, g_res_downloader,
27 g_gui, utils, md5, mempool, xprofiler,
28 g_touch, g_weapons;
30 type
31 TGameOption = (
32 //RESERVED = 0, // FIXME: reuse for something
33 TEAM_DAMAGE = 1,
34 ALLOW_EXIT,
35 WEAPONS_STAY,
36 MONSTERS,
37 BOTS_VS_PLAYERS,
38 BOTS_VS_MONSTERS,
39 DM_KEYS,
40 TEAM_HIT_TRACE,
41 TEAM_HIT_PROJECTILE,
42 TEAM_ABSORB_DAMAGE,
43 ALLOW_DROP_FLAG,
44 THROW_FLAG,
45 POWERUP_RANDOM,
46 ITEM_ALL_RANDOM,
47 ITEM_LIFE_RANDOM,
48 ITEM_AMMO_RANDOM,
49 ITEM_WEAPON_RANDOM
51 TGameOptions = set of TGameOption;
53 TGameSettings = record
54 GameType: Byte;
55 GameMode: Byte;
56 TimeLimit: Word;
57 ScoreLimit: Word;
58 WarmupTime: Word;
59 SpawnInvul: Word;
60 ItemRespawnTime: Word;
61 ItemRespawnRandom: Word;
62 PowerupRespawnTime: Word;
63 PowerupRespawnRandom: Word;
64 MaxLives: Byte;
65 Options: TGameOptions;
66 WAD: String;
67 end;
69 TGameEvent = record
70 Name: String;
71 Command: String;
72 end;
74 TDelayedEvent = record
75 Pending: Boolean;
76 Time: LongWord;
77 DEType: Byte;
78 DENum: Integer;
79 DEStr: String;
80 end;
82 {$IFDEF ENABLE_SOUND}
83 TChatSound = record
84 Sound: TPlayableSound;
85 Tags: Array of String;
86 FullWord: Boolean;
87 end;
88 {$ENDIF}
90 TPlayerSettings = record
91 Name: String;
92 Model: String;
93 Color: TRGB;
94 Team: Byte;
95 // ones below are sent only to the server
96 WeaponSwitch: Byte;
97 WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
98 SwitchToEmpty: Byte;
99 SkipIronFist: Byte;
100 end;
102 TMegaWADInfo = record
103 Name: String;
104 Description: String;
105 Author: String;
106 Pic: String;
107 end;
109 THearPoint = record
110 Active: Boolean;
111 Coords: TDFPoint;
112 end;
114 function g_Game_IsNet(): Boolean;
115 function g_Game_IsServer(): Boolean;
116 function g_Game_IsClient(): Boolean;
117 procedure g_Game_Init();
118 procedure g_Game_Free (freeTextures: Boolean=true);
119 procedure g_Game_LoadData();
120 procedure g_Game_FreeData();
121 procedure g_Game_Update();
122 procedure g_Game_PreUpdate();
123 procedure g_Game_Draw();
124 procedure g_Game_Quit();
125 procedure g_Game_SetupScreenSize();
126 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
127 function g_Game_ModeToText(Mode: Byte): string;
128 function g_Game_TextToMode(Mode: string): Byte;
129 procedure g_Game_ExecuteEvent(Name: String);
130 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
131 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
132 procedure g_Game_RemovePlayer();
133 procedure g_Game_Spectate();
134 procedure g_Game_SpectateCenterView();
135 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
136 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: TGameOptions; nPlayers: Byte);
137 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: TGameOptions; nPlayers: Byte; IPAddr: LongWord; Port: Word);
138 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
139 procedure g_Game_Restart();
140 procedure g_Game_RestartLevel();
141 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
142 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
143 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
144 procedure g_Game_ChangeMap(const MapPath: String);
145 procedure g_Game_ExitLevel(const Map: AnsiString);
146 function g_Game_GetFirstMap(WAD: String): String;
147 function g_Game_GetNextMap(): String;
148 procedure g_Game_NextLevel();
149 procedure g_Game_Pause(Enable: Boolean);
150 procedure g_Game_HolmesPause(Enable: Boolean);
151 procedure g_Game_InGameMenu(Show: Boolean);
152 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
153 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
154 procedure g_Game_Message(Msg: String; Time: Word);
156 {$IFDEF ENABLE_SOUND}
157 procedure g_Game_PauseAllSounds(Enable: Boolean);
158 procedure g_Game_StopAllSounds(all: Boolean);
159 procedure g_Game_UpdateTriggerSounds();
160 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
161 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
162 procedure g_Game_Announce_KillCombo(Param: Integer);
163 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
164 {$ENDIF}
166 function g_Game_GetMegaWADInfo(WAD: String; cfg: TConfig = nil): TMegaWADInfo;
167 procedure g_Game_Effect_Bubbles(fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean = False);
168 procedure g_Game_StartVote(Command, Initiator: string);
169 procedure g_Game_CheckVote;
170 procedure g_TakeScreenShot(Filename: string = '');
171 procedure g_FatalError(Text: String);
172 procedure g_SimpleError(Text: String);
173 function g_Game_IsTestMap(): Boolean;
174 procedure g_Game_DeleteTestMap();
175 procedure GameCVars(P: SSArray);
176 procedure PlayerSettingsCVars(P: SSArray);
177 procedure SystemCommands(P: SSArray);
178 procedure GameCommands(P: SSArray);
179 procedure GameCheats(P: SSArray);
180 procedure DebugCommands(P: SSArray);
181 procedure g_Game_Process_Params;
182 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
183 procedure g_Game_StepLoading(Value: Integer = -1);
184 procedure g_Game_ClearLoading();
185 procedure g_Game_SetDebugMode();
186 procedure DrawLoadingStat();
187 procedure DrawMenuBackground(tex: AnsiString);
189 { procedure SetWinPause(Enable: Boolean); }
191 const
192 GAME_TICK = 28;
194 LOADING_SHOW_STEP = 100;
195 LOADING_INTERLINE = 20;
197 GT_NONE = 0;
198 GT_SINGLE = 1;
199 GT_CUSTOM = 2;
200 GT_SERVER = 3;
201 GT_CLIENT = 4;
203 GM_NONE = 0;
204 GM_DM = 1;
205 GM_TDM = 2;
206 GM_CTF = 3;
207 GM_COOP = 4;
208 GM_SINGLE = 5;
210 MESSAGE_DIKEY = WM_USER + 1;
212 EXIT_QUIT = 1;
213 EXIT_SIMPLE = 2;
214 EXIT_RESTART = 3;
215 EXIT_ENDLEVELSINGLE = 4;
216 EXIT_ENDLEVELCUSTOM = 5;
218 STATE_NONE = 0;
219 STATE_MENU = 1;
220 STATE_FOLD = 2;
221 STATE_INTERCUSTOM = 3;
222 STATE_INTERSINGLE = 4;
223 STATE_INTERTEXT = 5;
224 STATE_INTERPIC = 6;
225 STATE_ENDPIC = 7;
226 STATE_SLIST = 8;
228 LMS_RESPAWN_NONE = 0;
229 LMS_RESPAWN_WARMUP = 1;
230 LMS_RESPAWN_FINAL = 2;
232 SPECT_NONE = 0;
233 SPECT_STATS = 1;
234 SPECT_MAPVIEW = 2;
235 SPECT_PLAYERS = 3;
237 DE_GLOBEVENT = 0;
238 DE_BFGHIT = 1;
239 DE_KILLCOMBO = 2;
240 DE_BODYKILL = 3;
242 ANNOUNCE_NONE = 0;
243 ANNOUNCE_ME = 1;
244 ANNOUNCE_MEPLUS = 2;
245 ANNOUNCE_ALL = 3;
247 CONFIG_FILENAME = 'Doom2DF.cfg';
248 TEST_MAP_NAME = '$$$_TEST_$$$';
249 STD_PLAYER_MODEL = 'Doomer';
250 DEFAULT_PLAYERS = {$IFNDEF HEADLESS}1{$ELSE}0{$ENDIF};
251 STATFILE_VERSION = $03;
254 gStdFont: DWORD;
255 gGameSettings: TGameSettings;
256 gPlayer1Settings: TPlayerSettings;
257 gPlayer2Settings: TPlayerSettings;
258 gGameOn: Boolean;
259 gPlayerScreenSize: TDFPoint;
260 gPlayer1ScreenCoord: TDFPoint;
261 gPlayer2ScreenCoord: TDFPoint;
262 gPlayer1: TPlayer;
263 gPlayer2: TPlayer;
264 gPlayerDrawn: TPlayer;
265 gTime: LongWord;
266 gLerpFactor: Single = 1.0;
267 gSwitchGameMode: Byte = GM_DM;
268 gHearPoint1, gHearPoint2: THearPoint;
269 {$IFDEF ENABLE_SOUND}
270 gSoundEffectsDF: Boolean;
271 gSoundTriggerTime: Word;
272 goodsnd: array[0..3] of TPlayableSound;
273 killsnd: array[0..3] of TPlayableSound;
274 hahasnd: array[0..2] of TPlayableSound;
275 sound_get_flag: array[0..1] of TPlayableSound;
276 sound_lost_flag: array[0..1] of TPlayableSound;
277 sound_ret_flag: array[0..1] of TPlayableSound;
278 sound_cap_flag: array[0..1] of TPlayableSound;
279 gUseChatSounds: Boolean = True;
280 gChatSounds: array of TChatSound;
281 gMusic: TMusic;
282 {$ELSE}
283 gMusicName: String = '';
284 gMusicPlay: Boolean = False;
285 gMusicPos: LongWord = 0;
286 gMusicPause: Boolean = False;
287 {$ENDIF}
288 gAnnouncer: Integer = ANNOUNCE_NONE;
289 gBodyKillEvent: Integer = -1;
290 gDefInterTime: ShortInt = -1;
291 gInterEndTime: LongWord;
292 gInterTime: LongWord;
293 gServInterTime: Byte;
294 gGameStartTime: LongWord;
295 gTotalMonsters: Integer;
296 gPauseMain: Boolean;
297 gPauseHolmes: Boolean;
298 gShowTime: Boolean;
299 gShowFPS: Boolean;
300 gShowScore: Boolean = True;
301 gShowStat: Boolean = True;
302 gShowPIDs: Boolean;
303 gShowKillMsg: Boolean = True;
304 gShowLives: Boolean = True;
305 gShowPing: Boolean;
306 gShowMap: Boolean;
307 gExit: Byte;
308 gState: Byte = STATE_NONE;
309 sX, sY: Integer;
310 sWidth, sHeight: Word;
311 gSpectMode: Byte = SPECT_NONE;
312 gSpectHUD: Boolean = True;
313 gSpectKeyPress: Boolean;
314 gSpectX: Integer;
315 gSpectY: Integer;
316 gSpectStep: Byte = 8;
317 gSpectViewTwo: Boolean;
318 gSpectPID1: Integer = -1;
319 gSpectPID2: Integer = -1;
320 gSpectAuto: Boolean;
321 gSpectAutoNext: LongWord;
322 gSpectAutoStepX: Integer;
323 gSpectAutoStepY: Integer;
324 gLoadGameMode: Boolean;
325 gCheats: Boolean;
326 gMapOnce: Boolean;
327 gMapToDelete: String;
328 gTempDelete: Boolean;
329 gLastMap: Boolean;
330 gScreenWidth: Word;
331 gScreenHeight: Word;
332 gResolutionChange: Boolean;
333 gRC_Width, gRC_Height: Integer;
334 gRC_FullScreen, gRC_Maximized: Boolean;
335 gLanguageChange: Boolean;
336 gDebugMode: Boolean;
337 g_debug_Sounds: Boolean;
338 g_debug_Frames: Boolean;
339 g_debug_WinMsgs: Boolean;
340 g_debug_MonsterOff: Boolean;
341 g_debug_BotAIOff: Byte;
342 g_debug_HealthBar: Boolean;
343 g_Debug_Player: Boolean;
344 gCoopMonstersKilled: Word;
345 gCoopSecretsFound: Word;
346 gCoopTotalMonstersKilled: Word;
347 gCoopTotalSecretsFound: Word;
348 gCoopTotalMonsters: Word;
349 gCoopTotalSecrets: Word;
350 gStatsOff: Boolean;
351 gStatsPressed: Boolean;
352 gExitByTrigger: Boolean;
353 gNextMap: String;
354 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
355 gLMSRespawnTime: Cardinal;
356 gLMSSoftSpawn: Boolean;
357 gMissionFailed: Boolean;
358 gVoteInProgress: Boolean;
359 gVotePassed: Boolean;
360 gVoteCommand: String;
361 gVoteTimer: Cardinal;
362 gVoteCmdTimer: Cardinal;
363 gVoteCount: Integer;
364 gVoteTimeout: Cardinal = 30;
365 gVoted: Boolean;
366 gVotesEnabled: Boolean = True;
367 gEvents: array of TGameEvent;
368 gDelayedEvents: array of TDelayedEvent;
369 gWeaponAction: array [0..1, WP_FACT..WP_LACT] of Boolean; // [player, weapon_action]
370 gSelectWeapon: array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
371 gInterReadyCount: Integer;
372 gMaxBots: Integer = 127;
374 g_dbg_ignore_bounds: Boolean;
375 r_smallmap_h: Integer; // 0: left; 1: center; 2: right
376 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
378 // move button values:
379 // bits 0-1: l/r state:
380 // 0: neither left, nor right pressed
381 // 1: left pressed
382 // 2: right pressed
383 // bits 4-5: l/r state when strafe was pressed
384 P1MoveButton: Byte;
385 P2MoveButton: Byte;
387 g_profile_frame_update: Boolean;
388 g_profile_frame_draw: Boolean;
389 g_profile_collision: Boolean;
390 g_profile_los: Boolean;
391 g_profile_history_size: Integer = 1000;
393 g_rlayer_back: Boolean = True;
394 g_rlayer_step: Boolean = True;
395 g_rlayer_wall: Boolean = True;
396 g_rlayer_door: Boolean = True;
397 g_rlayer_acid1: Boolean = True;
398 g_rlayer_acid2: Boolean = True;
399 g_rlayer_water: Boolean = True;
400 g_rlayer_fore: Boolean = True;
403 procedure g_ResetDynlights ();
404 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
405 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
407 function conIsCheatsEnabled (): Boolean; inline;
408 function gPause (): Boolean; inline;
410 implementation
412 uses
413 {$INCLUDE ../nogl/noGLuses.inc}
414 {$IFDEF ENABLE_HOLMES}
415 g_holmes,
416 {$ENDIF}
417 e_texture, e_res, g_textures, g_window, g_menu,
418 e_input, e_log, g_console, g_items, g_map, g_panel,
419 g_playermodel, g_gfx, g_options, Math,
420 g_triggers, g_monsters,
421 g_language, g_net, g_main, g_phys,
422 ENet, e_msg, g_netmsg, g_netmaster,
423 sfs, wadreader, g_system, Generics.Collections, Generics.Defaults;
426 hasPBarGfx: Boolean;
427 profileFrameDraw: TProfiler;
429 // ////////////////////////////////////////////////////////////////////////// //
430 function gPause (): Boolean; inline;
431 begin
432 Result := gPauseMain or gPauseHolmes;
433 end;
435 function conIsCheatsEnabled (): Boolean; inline;
436 begin
437 result := false;
438 if g_Game_IsNet then exit;
439 if not gDebugMode then
440 begin
441 //if not gCheats then exit;
442 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
443 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
444 end;
445 result := true;
446 end;
448 // ////////////////////////////////////////////////////////////////////////// //
449 type
450 TDynLight = record
451 x, y, radius: Integer;
452 r, g, b, a: Single;
453 exploCount: Integer;
454 exploRadius: Integer;
455 end;
458 g_dynLights: array of TDynLight = nil;
459 g_dynLightCount: Integer = 0;
460 g_playerLight: Boolean = false;
462 procedure g_ResetDynlights ();
464 lnum, idx: Integer;
465 begin
466 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
467 lnum := 0;
468 for idx := 0 to g_dynLightCount-1 do
469 begin
470 if g_dynLights[idx].exploCount = -666 then
471 begin
472 // skip it
474 else
475 begin
476 // explosion
477 Inc(g_dynLights[idx].exploCount);
478 if (g_dynLights[idx].exploCount < 10) then
479 begin
480 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
481 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
482 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
483 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
484 Inc(lnum);
485 end;
486 end;
487 end;
488 g_dynLightCount := lnum;
489 end;
491 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
492 begin
493 if not gwin_has_stencil then exit;
494 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
495 g_dynLights[g_dynLightCount].x := x;
496 g_dynLights[g_dynLightCount].y := y;
497 g_dynLights[g_dynLightCount].radius := radius;
498 g_dynLights[g_dynLightCount].r := r;
499 g_dynLights[g_dynLightCount].g := g;
500 g_dynLights[g_dynLightCount].b := b;
501 g_dynLights[g_dynLightCount].a := a;
502 g_dynLights[g_dynLightCount].exploCount := -666;
503 Inc(g_dynLightCount);
504 end;
506 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
507 begin
508 if not gwin_has_stencil then exit;
509 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
510 g_dynLights[g_dynLightCount].x := x;
511 g_dynLights[g_dynLightCount].y := y;
512 g_dynLights[g_dynLightCount].radius := 0;
513 g_dynLights[g_dynLightCount].exploRadius := radius;
514 g_dynLights[g_dynLightCount].r := r;
515 g_dynLights[g_dynLightCount].g := g;
516 g_dynLights[g_dynLightCount].b := b;
517 g_dynLights[g_dynLightCount].a := 0;
518 g_dynLights[g_dynLightCount].exploCount := 0;
519 Inc(g_dynLightCount);
520 end;
523 // ////////////////////////////////////////////////////////////////////////// //
524 function calcProfilesHeight (prof: TProfiler): Integer;
525 begin
526 result := 0;
527 if (prof = nil) then exit;
528 if (length(prof.bars) = 0) then exit;
529 result := length(prof.bars)*(16+2);
530 end;
532 // returns width
533 function drawProfiles (x, y: Integer; prof: TProfiler): Integer;
535 wdt, hgt: Integer;
536 yy: Integer;
537 ii: Integer;
538 begin
539 result := 0;
540 if (prof = nil) then exit;
541 // gScreenWidth
542 if (length(prof.bars) = 0) then exit;
543 wdt := 192;
544 hgt := calcProfilesHeight(prof);
545 if (x < 0) then x := gScreenWidth-(wdt-1)+x;
546 if (y < 0) then y := gScreenHeight-(hgt-1)+y;
547 // background
548 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
549 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
550 e_DarkenQuadWH(x, y, wdt, hgt, 150);
551 // title
552 yy := y+2;
553 for ii := 0 to High(prof.bars) do
554 begin
555 e_TextureFontPrintEx(x+2+4*prof.bars[ii].level, yy, Format('%s: %d µs', [prof.bars[ii].name, prof.bars[ii].value]), gStdFont, 255, 255, 0, 1, false);
556 yy += 16+2;
557 end;
558 result := wdt;
559 end;
562 // ////////////////////////////////////////////////////////////////////////// //
563 type
564 TEndCustomGameStat = record
565 PlayerStat: TPlayerStatArray;
566 TeamStat: TTeamStat;
567 GameTime: LongWord;
568 GameMode: Byte;
569 Map, MapName: String;
570 end;
572 TEndSingleGameStat = record
573 PlayerStat: Array [0..1] of record
574 Kills: Integer;
575 Secrets: Integer;
576 end;
577 GameTime: LongWord;
578 TwoPlayers: Boolean;
579 TotalSecrets: Integer;
580 end;
582 TLoadingStat = record
583 CurValue: Integer;
584 MaxValue: Integer;
585 ShowCount: Integer;
586 Msgs: Array of String;
587 NextMsg: Word;
588 PBarWasHere: Boolean; // did we draw a progress bar for this message?
589 end;
591 TParamStrValue = record
592 Name: String;
593 Value: String;
594 end;
596 TParamStrValues = Array of TParamStrValue;
598 const
599 INTER_ACTION_TEXT = 1;
600 INTER_ACTION_PIC = 2;
601 INTER_ACTION_MUSIC = 3;
604 FPS, UPS: Word;
605 FPSCounter, UPSCounter: Word;
606 FPSTime, UPSTime: LongWord;
607 DataLoaded: Boolean;
608 IsDrawStat: Boolean;
609 CustomStat: TEndCustomGameStat;
610 SingleStat: TEndSingleGameStat;
611 LoadingStat: TLoadingStat;
612 EndingGameCounter: Byte;
613 MessageText: String;
614 MessageTime: Word;
615 MessageLineLength: Integer = 80;
616 MapIndex: Integer = -1;
617 InterReadyTime: Integer = -1;
618 StatShotDone: Boolean;
619 StatFilename: String; // used by stat screenshot to save with the same name as the csv
620 StatDate: String;
621 MegaWAD: record
622 info: TMegaWADInfo;
623 endpic: String;
624 endmus: String;
625 res: record
626 text: Array of ShortString;
627 anim: Array of ShortString;
628 pic: Array of ShortString;
629 mus: Array of ShortString;
630 end;
631 triggers: Array of record
632 event: ShortString;
633 actions: Array of record
634 action, p1, p2: Integer;
635 end;
636 end;
637 cur_trigger: Integer;
638 cur_action: Integer;
639 end;
640 //InterPic: String;
641 InterText: record
642 lines: SSArray;
643 img: String;
644 cur_line: Integer;
645 cur_char: Integer;
646 counter: Integer;
647 endtext: Boolean;
648 end;
650 function Compare(a, b: TPlayerStat): Integer;
651 begin
652 if a.Spectator then Result := 1
653 else if b.Spectator then Result := -1
654 else if a.Frags < b.Frags then Result := 1
655 else if a.Frags > b.Frags then Result := -1
656 else if a.Deaths < b.Deaths then Result := -1
657 else if a.Deaths > b.Deaths then Result := 1
658 else if a.Kills < b.Kills then Result := -1
659 else Result := 1;
660 end;
662 // TODO: eliminate
663 procedure SortGameStat(var stat: TPlayerStatArray);
665 I, J: Integer;
666 T: TPlayerStat;
667 begin
668 if stat = nil then Exit;
670 for I := High(stat) downto Low(stat) do
671 for J := Low(stat) to High(stat) - 1 do
672 if Compare(stat[J], stat[J + 1]) = 1 then
673 begin
674 T := stat[J];
675 stat[J] := stat[J + 1];
676 stat[J + 1] := T;
677 end;
678 end;
680 // saves a shitty CSV containing the game stats passed to it
681 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
683 s: TextFile;
684 dir, fname, map, mode, etime, flags, strf: String;
685 flag: TGameOption;
686 I: Integer;
687 begin
689 dir := e_GetWriteableDir(StatsDirs);
690 // stats are placed in stats/yy/mm/dd/*.csv
691 fname := ConcatPaths([dir, Path]);
692 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
693 fname := ConcatPaths([fname, StatFilename + '.csv']);
694 AssignFile(s, fname);
696 SetTextCodePage(s, CP_UTF8);
697 Rewrite(s);
698 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
699 if g_Game_IsNet then fname := NetServerName else fname := '';
700 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
701 mode := g_Game_ModeToText(Stat.GameMode);
702 etime := Format('%d:%.2d:%.2d', [
703 Stat.GameTime div 1000 div 3600,
704 (Stat.GameTime div 1000 div 60) mod 60,
705 Stat.GameTime div 1000 mod 60
707 flags := '';
708 strf := '';
709 for flag in gGameSettings.Options do
710 begin
711 flags += strf;
712 System.WriteStr(strf, flag); // FIXME: rename our utils.WriteStr()
713 flags += strf;
714 strf := ', ';
715 end;
716 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
717 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,"%s",%s,%d', [
718 STATFILE_VERSION,
719 StatDate,
720 dquoteStr(fname),
721 dquoteStr(map),
722 mode,
723 gGameSettings.TimeLimit,
724 gGameSettings.ScoreLimit,
725 flags,
726 etime,
727 Length(Stat.PlayerStat)
728 ]));
729 // line 2: game specific shit
730 // if it's a team game: red score, blue score
731 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
732 // otherwise nothing
733 if Stat.GameMode in [GM_TDM, GM_CTF] then
734 WriteLn(s,
735 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Score, Stat.TeamStat[TEAM_BLUE].Score]))
736 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
737 WriteLn(s,
738 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
739 // lines 3-...: team, player name, frags, deaths
740 WriteLn(s, 'team,name,frags,deaths');
741 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
742 with Stat.PlayerStat[I] do
743 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
744 except
745 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
746 end;
747 except
748 g_Console_Add('could not create gamestats file "' + fname + '"');
749 end;
750 CloseFile(s);
751 end;
753 procedure ClearDebugCvars();
754 begin
755 g_debug_Sounds := False;
756 g_debug_Frames := False;
757 g_debug_WinMsgs := False;
758 g_debug_MonsterOff := False;
759 g_debug_BotAIOff := 0;
760 g_debug_HealthBar := False;
761 g_Debug_Player := False;
762 end;
764 function g_Game_ModeToText(Mode: Byte): string;
765 begin
766 Result := '';
767 case Mode of
768 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
769 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
770 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
771 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
772 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
773 end;
774 end;
776 function g_Game_TextToMode(Mode: string): Byte;
777 begin
778 Result := GM_NONE;
779 Mode := UpperCase(Mode);
780 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
781 begin
782 Result := GM_DM;
783 Exit;
784 end;
785 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
786 begin
787 Result := GM_TDM;
788 Exit;
789 end;
790 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
791 begin
792 Result := GM_CTF;
793 Exit;
794 end;
795 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
796 begin
797 Result := GM_COOP;
798 Exit;
799 end;
800 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
801 begin
802 Result := GM_SINGLE;
803 Exit;
804 end;
805 end;
807 function g_Game_IsNet(): Boolean;
808 begin
809 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
810 end;
812 function g_Game_IsServer(): Boolean;
813 begin
814 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
815 end;
817 function g_Game_IsClient(): Boolean;
818 begin
819 Result := (gGameSettings.GameType = GT_CLIENT);
820 end;
822 function g_Game_GetMegaWADInfo(WAD: String; cfg: TConfig): TMegaWADInfo;
824 w: TWADFile;
825 p: Pointer = nil;
826 len: Integer;
827 begin
828 if cfg = nil then
829 begin
830 w := TWADFile.Create();
831 w.ReadFile(WAD);
833 w.GetResource('INTERSCRIPT', p, len);
834 w.Destroy();
836 if p = nil then
837 begin
838 Result.name := ExtractFileName(WAD);
839 Exit;
840 end;
842 cfg := TConfig.CreateMem(p, len);
843 FreeMem(p);
844 end;
846 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
847 Result.description := cfg.ReadStr('megawad', 'description', '');
848 Result.author := cfg.ReadStr('megawad', 'author', '');
849 Result.pic := cfg.ReadStr('megawad', 'pic', '');
851 if p <> nil then
852 cfg.Destroy();
853 end;
855 procedure g_Game_FreeCurrentWAD();
857 a: Integer;
858 begin
859 for a := 0 to High(MegaWAD.res.pic) do
860 if MegaWAD.res.pic[a] <> '' then
861 g_Texture_Delete(MegaWAD.res.pic[a]);
863 {$IFDEF ENABLE_SOUND}
864 for a := 0 to High(MegaWAD.res.mus) do
865 if MegaWAD.res.mus[a] <> '' then
866 g_Sound_Delete(MegaWAD.res.mus[a]);
867 {$ENDIF}
869 MegaWAD.res.pic := nil;
870 MegaWAD.res.text := nil;
871 MegaWAD.res.anim := nil;
872 MegaWAD.res.mus := nil;
873 MegaWAD.triggers := nil;
875 g_Texture_Delete('TEXTURE_endpic');
877 {$IFDEF ENABLE_SOUND}
878 g_Sound_Delete('MUSIC_endmus');
879 {$ENDIF}
881 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
882 gGameSettings.WAD := '';
883 end;
885 procedure g_Game_SetCurrentWAD(WAD: string);
887 w: TWADFile;
888 cfg: TConfig;
889 p: Pointer = nil;
890 {b, }len: Integer;
891 s: AnsiString;
892 begin
893 g_Game_FreeCurrentWAD();
894 gGameSettings.WAD := WAD;
895 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
896 Exit;
898 w := TWADFile.Create();
899 w.ReadFile(WAD);
900 w.GetResource('INTERSCRIPT', p, len);
901 w.Destroy();
903 if p = nil then Exit;
904 cfg := TConfig.CreateMem(p, len);
905 FreeMem(p);
906 MegaWAD.info := g_Game_GetMegaWADInfo(WAD, cfg);
908 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
909 if MegaWAD.endpic <> '' then
910 begin
911 TEXTUREFILTER := GL_LINEAR;
912 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
913 g_Texture_CreateWADEx('TEXTURE_endpic', s);
914 TEXTUREFILTER := GL_NEAREST;
915 end;
916 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
918 {$IFDEF ENABLE_SOUND}
919 if MegaWAD.endmus <> '' then
920 begin
921 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
922 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
923 end;
924 {$ENDIF}
926 cfg.Destroy();
927 end;
929 {procedure start_trigger(t: string);
930 begin
931 end;
933 function next_trigger(): Boolean;
934 begin
935 end;}
937 procedure DisableCheats();
938 begin
939 MAX_RUNVEL := 8;
940 VEL_JUMP := 10;
941 gFly := False;
943 if gPlayer1 <> nil then gPlayer1.GodMode := False;
944 if gPlayer2 <> nil then gPlayer2.GodMode := False;
945 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
946 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
948 {$IF DEFINED(D2F_DEBUG)}
949 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
950 gAimLine := g_dbg_aimline_on;
951 {$ENDIF}
952 end;
954 procedure g_Game_ExecuteEvent(Name: String);
956 a: Integer;
957 begin
958 if Name = '' then
959 Exit;
960 if gEvents = nil then
961 Exit;
962 for a := 0 to High(gEvents) do
963 if gEvents[a].Name = Name then
964 begin
965 if gEvents[a].Command <> '' then
966 g_Console_Process(gEvents[a].Command, True);
967 break;
968 end;
969 end;
971 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
973 a, n: Integer;
974 begin
975 n := -1;
976 if gDelayedEvents <> nil then
977 for a := 0 to High(gDelayedEvents) do
978 if not gDelayedEvents[a].Pending then
979 begin
980 n := a;
981 break;
982 end;
983 if n = -1 then
984 begin
985 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
986 n := High(gDelayedEvents);
987 end;
988 gDelayedEvents[n].Pending := True;
989 gDelayedEvents[n].DEType := DEType;
990 gDelayedEvents[n].DENum := Num;
991 gDelayedEvents[n].DEStr := Str;
992 if DEType = DE_GLOBEVENT then
993 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
994 else
995 gDelayedEvents[n].Time := gTime + Time;
996 Result := n;
997 end;
999 procedure EndGame();
1001 a: Integer;
1002 FileName: string;
1003 t: TDateTime;
1004 begin
1005 if g_Game_IsNet and g_Game_IsServer then
1006 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1008 // Ñòîï èãðà:
1009 gPauseMain := false;
1010 gPauseHolmes := false;
1011 gGameOn := false;
1013 {$IFDEF ENABLE_SOUND}
1014 g_Game_StopAllSounds(False);
1015 {$ENDIF}
1017 MessageTime := 0;
1018 MessageText := '';
1020 EndingGameCounter := 0;
1021 g_ActiveWindow := nil;
1023 gLMSRespawn := LMS_RESPAWN_NONE;
1024 gLMSRespawnTime := 0;
1026 case gExit of
1027 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1028 begin
1029 g_Game_Free();
1031 if gMapOnce then
1032 begin // Ýòî áûë òåñò
1033 gExit := EXIT_QUIT;
1035 else
1036 begin // Âûõîä â ãëàâíîå ìåíþ
1037 {$IFDEF ENABLE_SOUND}
1038 gMusic.SetByName('MUSIC_MENU');
1039 gMusic.Play();
1040 {$ENDIF}
1041 if gState <> STATE_SLIST then
1042 begin
1043 g_GUI_ShowWindow('MainMenu');
1044 gState := STATE_MENU;
1045 end else
1046 begin
1047 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1048 slReturnPressed := True;
1049 if g_Net_Slist_Fetch(slCurrent) then
1050 begin
1051 if slCurrent = nil then
1052 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1054 else
1055 slWaitStr := _lc[I_NET_SLIST_ERROR];
1056 g_Serverlist_GenerateTable(slCurrent, slTable);
1057 end;
1059 g_Game_ExecuteEvent('ongameend');
1060 end;
1061 end;
1063 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
1064 begin
1065 if not g_Game_IsClient then g_Game_Restart();
1066 end;
1068 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1069 begin
1070 // Ñòàòèñòèêà Ñâîåé èãðû:
1071 FileName := g_ExtractWadName(gMapInfo.Map);
1073 CustomStat.GameTime := gTime;
1074 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1075 CustomStat.MapName := gMapInfo.Name;
1076 CustomStat.GameMode := gGameSettings.GameMode;
1077 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1078 CustomStat.TeamStat := gTeamStat;
1080 CustomStat.PlayerStat := nil;
1082 // Ñòàòèñòèêà èãðîêîâ:
1083 if gPlayers <> nil then
1084 begin
1085 for a := 0 to High(gPlayers) do
1086 if gPlayers[a] <> nil then
1087 begin
1088 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1089 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1090 begin
1091 Num := a;
1092 Name := gPlayers[a].Name;
1093 Frags := gPlayers[a].Frags;
1094 Deaths := gPlayers[a].Death;
1095 Kills := gPlayers[a].Kills;
1096 Team := gPlayers[a].Team;
1097 Color := gPlayers[a].Model.Color;
1098 Spectator := gPlayers[a].FSpectator;
1099 end;
1100 end;
1102 SortGameStat(CustomStat.PlayerStat);
1104 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1105 begin
1106 t := Now;
1107 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1108 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1109 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1110 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1111 if gSaveStats then
1112 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1113 end;
1115 StatShotDone := False;
1116 end;
1118 g_Game_ExecuteEvent('onmapend');
1119 if not g_Game_IsClient then g_Player_ResetReady;
1120 gInterReadyCount := 0;
1122 // Çàòóõàþùèé ýêðàí:
1123 EndingGameCounter := 255;
1124 gState := STATE_FOLD;
1125 gInterTime := 0;
1126 if gDefInterTime < 0 then
1127 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1128 else
1129 gInterEndTime := gDefInterTime * 1000;
1130 end;
1132 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1133 begin
1134 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1135 SingleStat.GameTime := gTime;
1136 SingleStat.TwoPlayers := gPlayer2 <> nil;
1137 SingleStat.TotalSecrets := gSecretsCount;
1138 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1139 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1140 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1141 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1142 if SingleStat.TwoPlayers then
1143 begin
1144 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1145 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1146 end;
1148 g_Game_ExecuteEvent('onmapend');
1150 // Åñòü åùå êàðòû:
1151 if gNextMap <> '' then
1152 begin
1153 {$IFDEF ENABLE_SOUND}
1154 gMusic.SetByName('MUSIC_INTERMUS');
1155 gMusic.Play();
1156 {$ENDIF}
1157 gState := STATE_INTERSINGLE;
1158 e_UnpressAllKeys();
1160 g_Game_ExecuteEvent('oninter');
1162 else // Áîëüøå íåò êàðò
1163 begin
1164 // Çàòóõàþùèé ýêðàí:
1165 EndingGameCounter := 255;
1166 gState := STATE_FOLD;
1167 end;
1168 end;
1169 end;
1171 // Îêîí÷àíèå îáðàáîòàíî:
1172 if gExit <> EXIT_QUIT then
1173 gExit := 0;
1174 end;
1176 procedure drawTime(X, Y: Integer); inline;
1177 begin
1178 e_TextureFontPrint(x, y,
1179 Format('%d:%.2d:%.2d', [
1180 gTime div 1000 div 3600,
1181 (gTime div 1000 div 60) mod 60,
1182 gTime div 1000 mod 60
1184 gStdFont);
1185 end;
1187 procedure DrawStat();
1189 pc, x, y, w, h: Integer;
1190 w1, w2, w3, w4: Integer;
1191 a, aa: Integer;
1192 cw, ch, r, g, b, rr, gg, bb: Byte;
1193 s1, s2, s3: String;
1194 _y: Integer;
1195 stat: TPlayerStatArray;
1196 wad, map: string;
1197 mapstr: string;
1198 namestr: string;
1199 begin
1200 s1 := '';
1201 s2 := '';
1202 s3 := '';
1203 pc := g_Player_GetCount;
1204 e_TextureFontGetSize(gStdFont, cw, ch);
1206 w := gScreenWidth-(gScreenWidth div 5);
1207 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1208 h := 32+ch*(11+pc)
1209 else
1210 h := 40+ch*5+(ch+8)*pc;
1211 x := (gScreenWidth div 2)-(w div 2);
1212 y := (gScreenHeight div 2)-(h div 2);
1214 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1215 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1217 drawTime(x+w-78, y+8);
1219 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1220 map := g_ExtractFileName(gMapInfo.Map);
1221 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1223 case gGameSettings.GameMode of
1224 GM_DM:
1225 begin
1226 if gGameSettings.MaxLives = 0 then
1227 s1 := _lc[I_GAME_DM]
1228 else
1229 s1 := _lc[I_GAME_LMS];
1230 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1231 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1232 end;
1234 GM_TDM:
1235 begin
1236 if gGameSettings.MaxLives = 0 then
1237 s1 := _lc[I_GAME_TDM]
1238 else
1239 s1 := _lc[I_GAME_TLMS];
1240 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1241 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1242 end;
1244 GM_CTF:
1245 begin
1246 s1 := _lc[I_GAME_CTF];
1247 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
1248 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1249 end;
1251 GM_COOP:
1252 begin
1253 if gGameSettings.MaxLives = 0 then
1254 s1 := _lc[I_GAME_COOP]
1255 else
1256 s1 := _lc[I_GAME_SURV];
1257 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1258 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1259 end;
1261 else
1262 begin
1263 s1 := '';
1264 s2 := '';
1265 end;
1266 end;
1268 _y := y+8;
1269 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1270 _y := _y+ch+8;
1271 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1272 _y := _y+ch+8;
1273 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1275 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1276 gStdFont, 200, 200, 200, 1);
1278 if NetMode = NET_SERVER then
1279 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1280 else
1281 if NetMode = NET_CLIENT then
1282 e_TextureFontPrintEx(x+8, y + 8,
1283 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1285 if pc = 0 then
1286 Exit;
1287 stat := g_Player_GetStats();
1288 SortGameStat(stat);
1290 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1291 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1292 w4 := w3;
1293 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1295 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1296 begin
1297 _y := _y+ch+ch;
1299 for a := TEAM_RED to TEAM_BLUE do
1300 begin
1301 if a = TEAM_RED then
1302 begin
1303 s1 := _lc[I_GAME_TEAM_RED];
1304 r := 255;
1305 g := 0;
1306 b := 0;
1308 else
1309 begin
1310 s1 := _lc[I_GAME_TEAM_BLUE];
1311 r := 0;
1312 g := 0;
1313 b := 255;
1314 end;
1316 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1317 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Score),
1318 gStdFont, r, g, b, 1);
1320 _y := _y+ch+(ch div 4);
1321 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1322 _y := _y+(ch div 4);
1324 for aa := 0 to High(stat) do
1325 if stat[aa].Team = a then
1326 with stat[aa] do
1327 begin
1328 if Spectator then
1329 begin
1330 rr := r div 2;
1331 gg := g div 2;
1332 bb := b div 2;
1334 else
1335 begin
1336 rr := r;
1337 gg := g;
1338 bb := b;
1339 end;
1340 if gShowPIDs then
1341 namestr := Format('[%5d] %s', [UID, Name])
1342 else
1343 namestr := Name;
1344 // Èìÿ
1345 e_TextureFontPrintEx(x+16, _y, namestr, gStdFont, rr, gg, bb, 1);
1346 // Ïèíã/ïîòåðè
1347 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1348 // Ôðàãè
1349 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1350 // Ñìåðòè
1351 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1352 _y := _y+ch;
1353 end;
1355 _y := _y+ch;
1356 end;
1358 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1359 begin
1360 _y := _y+ch+ch;
1361 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1362 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1363 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1364 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1366 _y := _y+ch+8;
1367 for aa := 0 to High(stat) do
1368 with stat[aa] do
1369 begin
1370 if Spectator then
1371 begin
1372 r := 127;
1373 g := 64;
1375 else
1376 begin
1377 r := 255;
1378 g := 127;
1379 end;
1380 if gShowPIDs then
1381 namestr := Format('[%5d] %s', [UID, Name])
1382 else
1383 namestr := Name;
1384 // Öâåò èãðîêà
1385 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1386 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1387 // Èìÿ
1388 e_TextureFontPrintEx(x+16+16+8, _y+4, namestr, gStdFont, r, g, 0, 1);
1389 // Ïèíã/ïîòåðè
1390 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1391 // Ôðàãè
1392 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1393 // Ñìåðòè
1394 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1395 _y := _y+ch+8;
1396 end;
1398 end;
1400 procedure g_Game_Init();
1402 SR: TSearchRec;
1403 knownFiles: array of AnsiString = nil;
1404 found: Boolean;
1405 wext, s: AnsiString;
1406 f: Integer;
1407 begin
1408 gExit := 0;
1409 gMapToDelete := '';
1410 gTempDelete := False;
1412 sfsGCDisable(); // temporary disable removing of temporary volumes
1415 TEXTUREFILTER := GL_LINEAR;
1416 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1417 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1418 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1419 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1420 TEXTUREFILTER := GL_NEAREST;
1422 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1423 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1424 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1426 g_Game_ClearLoading();
1427 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1428 g_Game_SetLoadingText('', 0, False);
1430 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1431 g_Console_Init();
1433 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1434 g_PlayerModel_LoadData();
1436 // load models from all possible wad types, in all known directories
1437 // this does a loosy job (linear search, ooph!), but meh
1438 for wext in wadExtensions do
1439 begin
1440 for f := High(ModelDirs) downto Low(ModelDirs) do
1441 begin
1442 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1443 begin
1444 repeat
1445 found := false;
1446 for s in knownFiles do
1447 begin
1448 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1449 begin
1450 found := true;
1451 break;
1452 end;
1453 end;
1454 if not found then
1455 begin
1456 SetLength(knownFiles, length(knownFiles)+1);
1457 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1458 end;
1459 until (FindNext(SR) <> 0);
1460 end;
1461 FindClose(SR);
1462 end;
1463 end;
1465 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1467 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);
1468 for s in knownFiles do
1469 begin
1470 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1471 end;
1473 gGameOn := false;
1474 gPauseMain := false;
1475 gPauseHolmes := false;
1476 gTime := 0;
1478 {e_MouseInfo.Accel := 1.0;}
1480 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1481 g_Game_LoadData();
1483 {$IFDEF ENABLE_SOUND}
1484 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1485 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1486 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1487 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1488 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1489 {$ENDIF}
1491 {$IFNDEF HEADLESS}
1492 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1493 g_Menu_Init();
1494 {$ENDIF}
1496 {$IFDEF ENABLE_SOUND}
1497 gMusic := TMusic.Create();
1498 gMusic.SetByName('MUSIC_MENU');
1499 gMusic.Play();
1500 {$ELSE}
1501 gMusicName := '';
1502 gMusicPlay := False;
1503 gMusicPos := 0;
1504 gMusicPause := False;
1505 {$ENDIF}
1507 gGameSettings.WarmupTime := 30;
1509 gState := STATE_MENU;
1511 SetLength(gEvents, 6);
1512 gEvents[0].Name := 'ongamestart';
1513 gEvents[1].Name := 'ongameend';
1514 gEvents[2].Name := 'onmapstart';
1515 gEvents[3].Name := 'onmapend';
1516 gEvents[4].Name := 'oninter';
1517 gEvents[5].Name := 'onwadend';
1518 finally
1519 sfsGCEnable(); // enable releasing unused volumes
1520 end;
1521 end;
1523 procedure g_Game_Free(freeTextures: Boolean=true);
1524 begin
1525 e_WriteLog('g_Game_Free: completion of the gameplay', TMsgType.Notify);
1526 if NetMode = NET_CLIENT then g_Net_Disconnect();
1527 if NetMode = NET_SERVER then g_Net_Host_Die();
1529 g_Map_Free(freeTextures);
1530 g_Player_Free();
1531 g_Player_RemoveAllCorpses();
1533 gGameSettings.GameType := GT_NONE;
1534 if gGameSettings.GameMode = GM_SINGLE then
1535 gGameSettings.GameMode := GM_DM;
1536 gSwitchGameMode := gGameSettings.GameMode;
1538 gChatShow := False;
1539 gExitByTrigger := False;
1540 end;
1542 function IsActivePlayer(p: TPlayer): Boolean;
1543 begin
1544 Result := False;
1545 if p = nil then
1546 Exit;
1547 Result := (not p.FDummy) and (not p.FSpectator);
1548 end;
1550 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1552 a: Integer;
1553 begin
1554 Result := nil;
1555 if ID < 0 then
1556 Exit;
1557 if gPlayers = nil then
1558 Exit;
1559 for a := Low(gPlayers) to High(gPlayers) do
1560 if IsActivePlayer(gPlayers[a]) then
1561 begin
1562 if gPlayers[a].UID <> ID then
1563 continue;
1564 Result := gPlayers[a];
1565 break;
1566 end;
1567 end;
1569 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1571 a, idx: Integer;
1572 ids: Array of Word;
1573 begin
1574 Result := -1;
1575 if gPlayers = nil then
1576 Exit;
1577 SetLength(ids, 0);
1578 idx := -1;
1579 for a := Low(gPlayers) to High(gPlayers) do
1580 if IsActivePlayer(gPlayers[a]) then
1581 begin
1582 SetLength(ids, Length(ids) + 1);
1583 ids[High(ids)] := gPlayers[a].UID;
1584 if gPlayers[a].UID = Skip then
1585 idx := High(ids);
1586 end;
1587 if Length(ids) = 0 then
1588 Exit;
1589 if idx = -1 then
1590 Result := ids[0]
1591 else
1592 Result := ids[(idx + 1) mod Length(ids)];
1593 end;
1595 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1597 a, idx: Integer;
1598 ids: Array of Word;
1599 begin
1600 Result := -1;
1601 if gPlayers = nil then
1602 Exit;
1603 SetLength(ids, 0);
1604 idx := -1;
1605 for a := Low(gPlayers) to High(gPlayers) do
1606 if IsActivePlayer(gPlayers[a]) then
1607 begin
1608 SetLength(ids, Length(ids) + 1);
1609 ids[High(ids)] := gPlayers[a].UID;
1610 if gPlayers[a].UID = Skip then
1611 idx := High(ids);
1612 end;
1613 if Length(ids) = 0 then
1614 Exit;
1615 if idx = -1 then
1616 Result := ids[Length(ids) - 1]
1617 else
1618 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1619 end;
1621 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1623 a, idx: Integer;
1624 ids: Array of Word;
1625 begin
1626 Result := -1;
1627 if gPlayers = nil then
1628 Exit;
1629 SetLength(ids, 0);
1630 idx := -1;
1631 for a := Low(gPlayers) to High(gPlayers) do
1632 if IsActivePlayer(gPlayers[a]) then
1633 begin
1634 SetLength(ids, Length(ids) + 1);
1635 ids[High(ids)] := gPlayers[a].UID;
1636 if gPlayers[a].UID = Skip then
1637 idx := High(ids);
1638 end;
1639 if Length(ids) = 0 then
1640 Exit;
1641 if Length(ids) = 1 then
1642 begin
1643 Result := ids[0];
1644 Exit;
1645 end;
1646 Result := ids[Random(Length(ids))];
1647 a := 10;
1648 while (idx <> -1) and (Result = Skip) and (a > 0) do
1649 begin
1650 Result := ids[Random(Length(ids))];
1651 Dec(a);
1652 end;
1653 end;
1655 function GetRandomSpectMode(Current: Byte): Byte;
1656 label
1657 retry;
1658 begin
1659 Result := Current;
1660 retry:
1661 case Random(7) of
1662 0: Result := SPECT_STATS;
1663 1: Result := SPECT_MAPVIEW;
1664 2: Result := SPECT_MAPVIEW;
1665 3: Result := SPECT_PLAYERS;
1666 4: Result := SPECT_PLAYERS;
1667 5: Result := SPECT_PLAYERS;
1668 6: Result := SPECT_PLAYERS;
1669 end;
1670 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1671 goto retry;
1672 end;
1674 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1676 time: Word;
1677 strafeDir: Byte;
1678 i: Integer;
1679 begin
1680 if (plr = nil) then exit;
1681 if (p = 2) then time := 1000 else time := 1;
1682 strafeDir := MoveButton shr 4;
1683 MoveButton := MoveButton and $0F;
1685 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1686 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1687 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1688 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1689 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1690 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1692 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1693 if MoveButton = 1 then
1694 plr.PressKey(KEY_LEFT, time)
1695 else if MoveButton = 2 then
1696 plr.PressKey(KEY_RIGHT, time);
1698 // if we have "strafe" key, turn off old strafe mechanics
1699 if gPlayerAction[p, ACTION_STRAFE] then
1700 begin
1701 // new strafe mechanics
1702 if (strafeDir = 0) then
1703 strafeDir := MoveButton; // start strafing
1704 // now set direction according to strafe (reversed)
1705 if (strafeDir = 2) then
1706 plr.SetDirection(TDirection.D_LEFT)
1707 else if (strafeDir = 1) then
1708 plr.SetDirection(TDirection.D_RIGHT)
1710 else
1711 begin
1712 strafeDir := 0; // not strafing anymore
1713 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1714 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1715 plr.SetDirection(TDirection.D_LEFT)
1716 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1717 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1718 plr.SetDirection(TDirection.D_RIGHT)
1719 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1720 else if MoveButton <> 0 then
1721 plr.SetDirection(TDirection(MoveButton-1))
1722 end;
1724 // fix movebutton state
1725 MoveButton := MoveButton or (strafeDir shl 4);
1727 // Îñòàëüíûå êëàâèøè:
1728 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1729 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1730 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1731 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1732 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1734 for i := WP_FACT to WP_LACT do
1735 begin
1736 if gWeaponAction[p, i] then
1737 begin
1738 plr.ProcessWeaponAction(i);
1739 gWeaponAction[p, i] := False
1741 end;
1743 for i := WP_FIRST to WP_LAST do
1744 begin
1745 if gSelectWeapon[p, i] then
1746 begin
1747 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1748 gSelectWeapon[p, i] := False
1750 end;
1752 // HACK: add dynlight here
1753 if gwin_k8_enable_light_experiments then
1754 begin
1755 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1756 begin
1757 g_playerLight := true;
1758 end;
1759 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1760 begin
1761 g_playerLight := false;
1762 end;
1763 end;
1765 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1766 end;
1768 // HACK: don't have a "key was pressed" function
1769 procedure InterReady();
1770 begin
1771 if InterReadyTime > gTime then Exit;
1772 InterReadyTime := gTime + 3000;
1773 MC_SEND_CheatRequest(NET_CHEAT_READY);
1774 end;
1776 procedure g_Game_PreUpdate();
1777 begin
1778 // these are in separate PreUpdate functions because they can interact during Update()
1779 // and are synced over the net
1780 // we don't care that much about corpses and gibs
1781 g_Player_PreUpdate();
1782 g_Monsters_PreUpdate();
1783 g_Items_PreUpdate();
1784 g_Weapon_PreUpdate();
1785 end;
1787 procedure g_Game_Update();
1789 Msg: g_gui.TMessage;
1790 Time: Int64;
1791 a: Byte;
1792 w: Word;
1793 i, b: Integer;
1795 function sendMonsPos (mon: TMonster): Boolean;
1796 begin
1797 result := false; // don't stop
1798 // this will also reset "need-send" flag
1799 if mon.gncNeedSend then
1800 begin
1801 MH_SEND_MonsterPos(mon.UID);
1803 else if (mon.MonsterType = MONSTER_BARREL) then
1804 begin
1805 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1807 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1808 begin
1809 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1810 end;
1811 end;
1813 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1814 begin
1815 result := false; // don't stop
1816 // this will also reset "need-send" flag
1817 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1818 end;
1820 function sendItemPos (it: PItem): Boolean;
1821 begin
1822 result := false; // don't stop
1823 if it.needSend then
1824 begin
1825 MH_SEND_ItemPos(it.myId);
1826 it.needSend := False;
1827 end;
1828 end;
1831 reliableUpdate: Boolean;
1832 begin
1833 g_ResetDynlights();
1834 framePool.reset();
1836 // Ïîðà âûêëþ÷àòü èãðó:
1837 if gExit = EXIT_QUIT then
1838 Exit;
1839 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1840 if gExit <> 0 then
1841 begin
1842 EndGame();
1843 if gExit = EXIT_QUIT then
1844 Exit;
1845 end;
1847 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1848 // no need to, as we'll do it in event handler
1850 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1851 g_Console_Update();
1853 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1854 begin
1855 gExit := EXIT_SIMPLE;
1856 EndGame();
1857 Exit;
1858 end;
1860 // process master server communications
1861 g_Net_Slist_Pulse();
1863 case gState of
1864 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1865 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1866 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1867 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1868 begin
1869 if g_Game_IsNet and g_Game_IsServer then
1870 begin
1871 gInterTime := gInterTime + GAME_TICK;
1872 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1873 if a <> gServInterTime then
1874 begin
1875 gServInterTime := a;
1876 MH_SEND_TimeSync(gServInterTime);
1877 end;
1878 end;
1880 if (not g_Game_IsClient) and
1884 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or e_KeyPressed(IK_SELECT) or
1885 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1886 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1887 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1889 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1890 and (g_ActiveWindow = nil)
1892 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1894 then
1895 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1896 {$IFDEF ENABLE_SOUND}
1897 g_Game_StopAllSounds(True);
1898 {$ENDIF}
1900 if gMapOnce then // Ýòî áûë òåñò
1901 gExit := EXIT_SIMPLE
1902 else
1903 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1904 g_Game_ChangeMap(gNextMap)
1905 else // Ñëåäóþùåé êàðòû íåò
1906 begin
1907 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1908 begin
1909 // Âûõîä â ãëàâíîå ìåíþ:
1910 g_Game_Free();
1911 g_GUI_ShowWindow('MainMenu');
1912 {$IFDEF ENABLE_SOUND}
1913 gMusic.SetByName('MUSIC_MENU');
1914 gMusic.Play();
1915 {$ENDIF}
1916 gState := STATE_MENU;
1917 end else
1918 begin
1919 // Ôèíàëüíàÿ êàðòèíêà:
1920 g_Game_ExecuteEvent('onwadend');
1921 g_Game_Free();
1922 {$IFDEF ENABLE_SOUND}
1923 if not gMusic.SetByName('MUSIC_endmus') then
1924 gMusic.SetByName('MUSIC_STDENDMUS');
1925 gMusic.Play();
1926 {$ENDIF}
1927 gState := STATE_ENDPIC;
1928 end;
1929 g_Game_ExecuteEvent('ongameend');
1930 end;
1932 Exit;
1934 else if g_Game_IsClient and
1937 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or e_KeyPressed(IK_SELECT) or
1938 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1939 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1940 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1942 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1943 and (g_ActiveWindow = nil)
1945 then
1946 begin
1947 // ready / unready
1948 InterReady();
1949 end;
1951 if gState = STATE_INTERTEXT then
1952 if InterText.counter > 0 then
1953 InterText.counter := InterText.counter - 1;
1954 end;
1956 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1957 begin
1958 if EndingGameCounter = 0 then
1959 begin
1960 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1961 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1962 begin
1963 gState := STATE_INTERCUSTOM;
1964 InterReadyTime := -1;
1965 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1966 begin
1967 g_Game_ExecuteEvent('onwadend');
1968 {$IFDEF ENABLE_SOUND}
1969 if not gMusic.SetByName('MUSIC_endmus') then
1970 gMusic.SetByName('MUSIC_STDENDMUS');
1971 {$ENDIF}
1973 else
1974 begin
1975 {$IFDEF ENABLE_SOUND}
1976 gMusic.SetByName('MUSIC_ROUNDMUS');
1977 {$ENDIF}
1978 end;
1979 {$IFDEF ENABLE_SOUND}
1980 gMusic.Play();
1981 {$ENDIF}
1982 e_UnpressAllKeys();
1984 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1985 begin
1986 {$IFDEF ENABLE_SOUND}
1987 gMusic.SetByName('MUSIC_INTERMUS');
1988 gMusic.Play();
1989 {$ENDIF}
1990 gState := STATE_INTERSINGLE;
1991 e_UnpressAllKeys();
1992 end;
1993 g_Game_ExecuteEvent('oninter');
1995 else
1996 DecMin(EndingGameCounter, 6, 0);
1997 end;
1999 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
2000 begin
2001 if gMapOnce then // Ýòî áûë òåñò
2002 begin
2003 gExit := EXIT_SIMPLE;
2004 Exit;
2005 end;
2006 end;
2008 STATE_SLIST:
2009 g_Serverlist_Control(slCurrent, slTable);
2010 end;
2012 // Ñòàòèñòèêà ïî Tab:
2013 if gGameOn then
2014 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
2016 // Èãðà èäåò:
2017 if gGameOn and not gPause and (gState <> STATE_FOLD) then
2018 begin
2019 // Âðåìÿ += 28 ìèëëèñåêóíä:
2020 gTime := gTime + GAME_TICK;
2022 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
2023 if MessageTime = 0 then
2024 MessageText := '';
2025 if MessageTime > 0 then
2026 MessageTime := MessageTime - 1;
2028 if (g_Game_IsServer) then
2029 begin
2030 // Áûë çàäàí ëèìèò âðåìåíè:
2031 if (gGameSettings.TimeLimit > 0) then
2032 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
2033 begin // Îí ïðîøåë => êîíåö óðîâíÿ
2034 g_Game_NextLevel();
2035 Exit;
2036 end;
2038 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
2039 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
2040 g_Game_RestartRound(gLMSSoftSpawn);
2042 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
2043 if gVoteInProgress and (gVoteTimer < gTime) then
2044 g_Game_CheckVote
2045 else if gVotePassed and (gVoteCmdTimer < gTime) then
2046 begin
2047 g_Console_Process(gVoteCommand);
2048 gVoteCommand := '';
2049 gVotePassed := False;
2050 end;
2052 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2053 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2054 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
2055 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2056 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
2058 // Áûë çàäàí ëèìèò ïîáåä:
2059 if (gGameSettings.ScoreLimit > 0) then
2060 begin
2061 b := 0;
2063 if gGameSettings.GameMode = GM_DM then
2064 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2065 for i := 0 to High(gPlayers) do
2066 if gPlayers[i] <> nil then
2067 if gPlayers[i].Frags > b then
2068 b := gPlayers[i].Frags;
2070 else
2071 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2072 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2073 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
2074 end;
2076 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2077 if b >= gGameSettings.ScoreLimit then
2078 begin
2079 g_Game_NextLevel();
2080 Exit;
2081 end;
2082 end;
2084 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2085 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2086 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2087 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2088 begin
2089 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2090 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2091 end // if not console
2092 else
2093 begin
2094 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2095 end;
2096 // process weapon switch queue
2097 end; // if server
2099 // Íàáëþäàòåëü
2100 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2101 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2102 begin
2103 if not gSpectKeyPress then
2104 begin
2105 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2106 begin
2107 // switch spect mode
2108 case gSpectMode of
2109 SPECT_NONE: ; // not spectator
2110 SPECT_STATS,
2111 SPECT_MAPVIEW: Inc(gSpectMode);
2112 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2113 end;
2114 gSpectKeyPress := True;
2115 end;
2116 if (gSpectMode = SPECT_MAPVIEW)
2117 and (not gSpectAuto) then
2118 begin
2119 if gPlayerAction[0, ACTION_MOVELEFT] then
2120 gSpectX := Max(gSpectX - gSpectStep, 0);
2121 if gPlayerAction[0, ACTION_MOVERIGHT] then
2122 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2123 if gPlayerAction[0, ACTION_LOOKUP] then
2124 gSpectY := Max(gSpectY - gSpectStep, 0);
2125 if gPlayerAction[0, ACTION_LOOKDOWN] then
2126 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2127 if gWeaponAction[0, WP_PREV] then
2128 begin
2129 // decrease step
2130 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2131 gWeaponAction[0, WP_PREV] := False;
2132 end;
2133 if gWeaponAction[0, WP_NEXT] then
2134 begin
2135 // increase step
2136 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2137 gWeaponAction[0, WP_NEXT] := False;
2138 end;
2139 end;
2140 if (gSpectMode = SPECT_PLAYERS)
2141 and (not gSpectAuto) then
2142 begin
2143 if gPlayerAction[0, ACTION_LOOKUP] then
2144 begin
2145 // add second view
2146 gSpectViewTwo := True;
2147 gSpectKeyPress := True;
2148 end;
2149 if gPlayerAction[0, ACTION_LOOKDOWN] then
2150 begin
2151 // remove second view
2152 gSpectViewTwo := False;
2153 gSpectKeyPress := True;
2154 end;
2155 if gPlayerAction[0, ACTION_MOVELEFT] then
2156 begin
2157 // prev player (view 1)
2158 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2159 gSpectKeyPress := True;
2160 end;
2161 if gPlayerAction[0, ACTION_MOVERIGHT] then
2162 begin
2163 // next player (view 1)
2164 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2165 gSpectKeyPress := True;
2166 end;
2167 if gWeaponAction[0, WP_PREV] then
2168 begin
2169 // prev player (view 2)
2170 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2171 gWeaponAction[0, WP_PREV] := False;
2172 end;
2173 if gWeaponAction[0, WP_NEXT] then
2174 begin
2175 // next player (view 2)
2176 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2177 gWeaponAction[0, WP_NEXT] := False;
2178 end;
2179 end;
2180 if gPlayerAction[0, ACTION_ATTACK] then
2181 begin
2182 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2183 begin
2184 gSpectAuto := True;
2185 gSpectAutoNext := 0;
2186 gSpectViewTwo := False;
2187 gSpectKeyPress := True;
2189 else
2190 if gSpectAuto then
2191 begin
2192 gSpectMode := SPECT_STATS;
2193 gSpectAuto := False;
2194 gSpectKeyPress := True;
2195 end;
2196 end;
2198 else
2199 if (not gPlayerAction[0, ACTION_JUMP]) and
2200 (not gPlayerAction[0, ACTION_ATTACK]) and
2201 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2202 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2203 (not gPlayerAction[0, ACTION_LOOKUP]) and
2204 (not gPlayerAction[0, ACTION_LOOKDOWN]) then
2205 gSpectKeyPress := False;
2207 if gSpectAuto then
2208 begin
2209 if gSpectMode = SPECT_MAPVIEW then
2210 begin
2211 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2212 if i = gSpectX then
2213 gSpectAutoNext := gTime
2214 else
2215 gSpectX := i;
2216 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2217 if i = gSpectY then
2218 gSpectAutoNext := gTime
2219 else
2220 gSpectY := i;
2221 end;
2222 if gSpectAutoNext <= gTime then
2223 begin
2224 if gSpectAutoNext > 0 then
2225 begin
2226 gSpectMode := GetRandomSpectMode(gSpectMode);
2227 case gSpectMode of
2228 SPECT_MAPVIEW:
2229 begin
2230 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2231 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2232 gSpectAutoStepX := Random(9) - 4;
2233 gSpectAutoStepY := Random(9) - 4;
2234 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2235 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2236 gSpectAutoStepX := gSpectAutoStepX * -1;
2237 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2238 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2239 gSpectAutoStepY := gSpectAutoStepY * -1;
2240 end;
2241 SPECT_PLAYERS:
2242 begin
2243 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2244 end;
2245 end;
2246 end;
2247 case gSpectMode of
2248 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2249 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2250 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2251 end;
2252 end;
2253 end;
2254 end;
2256 // Îáíîâëÿåì âñå îñòàëüíîå:
2257 g_Map_Update();
2258 g_Items_Update();
2259 g_Triggers_Update();
2260 g_Weapon_Update();
2261 g_Monsters_Update();
2262 g_GFX_Update();
2263 g_Player_UpdateAll();
2264 g_Player_UpdatePhysicalObjects();
2266 // server: send newly spawned monsters unconditionally
2267 if (gGameSettings.GameType = GT_SERVER) then
2268 begin
2269 if (Length(gMonstersSpawned) > 0) then
2270 begin
2271 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2272 SetLength(gMonstersSpawned, 0);
2273 end;
2274 end;
2276 {$IFDEF ENABLE_SOUND}
2277 if (gSoundTriggerTime > 8) then
2278 begin
2279 g_Game_UpdateTriggerSounds();
2280 gSoundTriggerTime := 0;
2282 else
2283 begin
2284 Inc(gSoundTriggerTime);
2285 end;
2286 {$ENDIF}
2288 if (NetMode = NET_SERVER) then
2289 begin
2290 Inc(NetTimeToUpdate);
2291 Inc(NetTimeToReliable);
2293 // send monster updates
2294 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2295 begin
2296 // send all monsters (periodic sync)
2297 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2299 for I := 0 to High(gPlayers) do
2300 begin
2301 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2302 end;
2304 g_Mons_ForEach(sendMonsPos);
2306 // update flags that aren't stationary
2307 if gGameSettings.GameMode = GM_CTF then
2308 for I := FLAG_RED to FLAG_BLUE do
2309 if gFlags[I].NeedSend then
2310 begin
2311 gFlags[I].NeedSend := False;
2312 MH_SEND_FlagPos(I);
2313 end;
2315 // update items that aren't stationary
2316 g_Items_ForEachAlive(sendItemPos);
2318 if reliableUpdate then
2319 begin
2320 NetTimeToReliable := 0;
2321 NetTimeToUpdate := NetUpdateRate;
2323 else
2324 begin
2325 NetTimeToUpdate := 0;
2326 end;
2328 else
2329 begin
2330 // send only mosters with some unexpected changes
2331 g_Mons_ForEach(sendMonsPosUnexpected);
2332 end;
2334 // send unexpected platform changes
2335 g_Map_NetSendInterestingPanels();
2337 g_Net_Slist_ServerUpdate();
2339 if NetUseMaster then
2340 begin
2341 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2342 begin
2343 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2344 g_Net_Slist_Update;
2345 NetTimeToMaster := gTime + NetMasterRate;
2346 end;
2347 end;
2350 else if (NetMode = NET_CLIENT) then
2351 begin
2352 MC_SEND_PlayerPos();
2353 end;
2354 end; // if gameOn ...
2356 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2357 if g_ActiveWindow <> nil then
2358 begin
2359 w := e_GetFirstKeyPressed();
2361 if (w <> IK_INVALID) then
2362 begin
2363 Msg.Msg := MESSAGE_DIKEY;
2364 Msg.wParam := w;
2365 g_ActiveWindow.OnMessage(Msg);
2366 end;
2368 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2369 if g_ActiveWindow <> nil then
2370 g_ActiveWindow.Update();
2372 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2373 if gResolutionChange then
2374 begin
2375 e_WriteLog('Changing resolution', TMsgType.Notify);
2376 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2377 gResolutionChange := False;
2378 g_ActiveWindow := nil;
2379 end;
2381 // Íóæíî ñìåíèòü ÿçûê:
2382 if gLanguageChange then
2383 begin
2384 //e_WriteLog('Read language file', MSG_NOTIFY);
2385 //g_Language_Load(DataDir + gLanguage + '.txt');
2386 g_Language_Set(gLanguage);
2387 {$IFNDEF HEADLESS}
2388 g_Menu_Reset();
2389 {$ENDIF}
2390 gLanguageChange := False;
2391 end;
2392 end;
2394 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2395 if e_KeyPressed(IK_F10) and
2396 gGameOn and
2397 (not gConsoleShow) and
2398 (g_ActiveWindow = nil) then
2399 begin
2400 KeyPress(IK_F10);
2401 end;
2403 Time := sys_GetTicks() {div 1000};
2405 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2406 if gDelayedEvents <> nil then
2407 for a := 0 to High(gDelayedEvents) do
2408 if gDelayedEvents[a].Pending and
2410 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2411 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2412 ) then
2413 begin
2414 case gDelayedEvents[a].DEType of
2415 DE_GLOBEVENT:
2416 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2417 DE_BFGHIT:
2418 if gGameOn then
2419 begin
2420 {$IFDEF ENABLE_SOUND}
2421 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2422 {$ENDIF}
2423 end;
2424 DE_KILLCOMBO:
2425 if gGameOn then
2426 begin
2427 {$IFDEF ENABLE_SOUND}
2428 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2429 {$ENDIF}
2430 if g_Game_IsNet and g_Game_IsServer then
2431 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2432 end;
2433 DE_BODYKILL:
2434 if gGameOn then
2435 begin
2436 {$IFDEF ENABLE_SOUND}
2437 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2438 {$ENDIF}
2439 end;
2440 end;
2441 gDelayedEvents[a].Pending := False;
2442 end;
2444 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2445 UPSCounter := UPSCounter + 1;
2446 if Time - UPSTime >= 1000 then
2447 begin
2448 UPS := UPSCounter;
2449 UPSCounter := 0;
2450 UPSTime := Time;
2451 end;
2453 if gGameOn then
2454 begin
2455 g_Weapon_AddDynLights();
2456 g_Items_AddDynLights();
2457 end;
2458 end;
2460 {$IFDEF ENABLE_SOUND}
2461 procedure g_Game_LoadChatSounds(Resource: string);
2463 WAD: TWADFile;
2464 FileName, Snd: string;
2465 p: Pointer;
2466 len, cnt, tags, i, j: Integer;
2467 cfg: TConfig;
2468 begin
2469 FileName := g_ExtractWadName(Resource);
2471 WAD := TWADFile.Create();
2472 WAD.ReadFile(FileName);
2474 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2475 begin
2476 gChatSounds := nil;
2477 WAD.Destroy();
2478 Exit;
2479 end;
2480 WAD.Destroy();
2482 cfg := TConfig.CreateMem(p, len);
2483 FreeMem(p);
2484 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2486 SetLength(gChatSounds, cnt);
2487 for i := 0 to Length(gChatSounds) - 1 do
2488 begin
2489 gChatSounds[i].Sound := nil;
2490 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2491 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2492 if (Snd = '') or (Tags <= 0) then
2493 continue;
2494 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2495 gChatSounds[i].Sound := TPlayableSound.Create();
2496 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2497 SetLength(gChatSounds[i].Tags, tags);
2498 for j := 0 to tags - 1 do
2499 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2500 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2501 end;
2503 cfg.Destroy();
2504 end;
2506 procedure g_Game_FreeChatSounds();
2508 i: Integer;
2509 begin
2510 for i := 0 to Length(gChatSounds) - 1 do
2511 begin
2512 gChatSounds[i].Sound.Free();
2513 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2514 end;
2515 SetLength(gChatSounds, 0);
2516 gChatSounds := nil;
2517 end;
2518 {$ENDIF}
2520 procedure g_Game_LoadData();
2522 wl, hl: Integer;
2523 wr, hr: Integer;
2524 wb, hb: Integer;
2525 wm, hm: Integer;
2526 begin
2527 if DataLoaded then Exit;
2529 e_WriteLog('Loading game data...', TMsgType.Notify);
2531 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2532 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2533 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2534 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2535 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2536 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2537 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2538 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2539 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2540 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2541 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2542 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2543 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2544 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2545 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2547 hasPBarGfx := true;
2548 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2549 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2550 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2551 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2553 if hasPBarGfx then
2554 begin
2555 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2556 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2557 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2558 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2559 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
2560 begin
2561 // yay!
2563 else
2564 begin
2565 hasPBarGfx := false;
2566 end;
2567 end;
2569 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2570 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2571 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2572 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2573 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2574 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2575 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2577 {$IFDEF ENABLE_SOUND}
2578 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2579 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2580 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2581 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2582 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2583 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2584 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2585 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2586 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2587 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2588 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2589 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2590 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2591 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2592 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2593 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2594 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2595 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2596 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2597 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2598 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2599 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2600 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2601 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2602 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2603 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2604 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2605 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2606 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2607 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2608 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2609 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2611 goodsnd[0] := TPlayableSound.Create();
2612 goodsnd[1] := TPlayableSound.Create();
2613 goodsnd[2] := TPlayableSound.Create();
2614 goodsnd[3] := TPlayableSound.Create();
2616 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2617 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2618 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2619 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2621 killsnd[0] := TPlayableSound.Create();
2622 killsnd[1] := TPlayableSound.Create();
2623 killsnd[2] := TPlayableSound.Create();
2624 killsnd[3] := TPlayableSound.Create();
2626 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2627 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2628 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2629 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2631 hahasnd[0] := TPlayableSound.Create();
2632 hahasnd[1] := TPlayableSound.Create();
2633 hahasnd[2] := TPlayableSound.Create();
2635 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2636 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2637 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2639 sound_get_flag[0] := TPlayableSound.Create();
2640 sound_get_flag[1] := TPlayableSound.Create();
2641 sound_lost_flag[0] := TPlayableSound.Create();
2642 sound_lost_flag[1] := TPlayableSound.Create();
2643 sound_ret_flag[0] := TPlayableSound.Create();
2644 sound_ret_flag[1] := TPlayableSound.Create();
2645 sound_cap_flag[0] := TPlayableSound.Create();
2646 sound_cap_flag[1] := TPlayableSound.Create();
2648 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2649 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2650 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2651 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2652 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2653 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2654 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2655 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2657 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2658 {$ENDIF}
2660 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2661 g_Items_LoadData();
2663 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2664 g_Weapon_LoadData();
2666 g_Monsters_LoadData();
2668 DataLoaded := True;
2669 end;
2671 procedure g_Game_FreeData();
2672 begin
2673 if not DataLoaded then Exit;
2675 g_Items_FreeData();
2676 g_Weapon_FreeData();
2677 g_Monsters_FreeData();
2679 e_WriteLog('Releasing game data...', TMsgType.Notify);
2681 g_Texture_Delete('NOTEXTURE');
2682 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2683 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2684 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2685 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2686 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2687 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2688 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2689 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2690 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2691 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2692 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2693 g_Frames_DeleteByName('FRAMES_TELEPORT');
2694 g_Frames_DeleteByName('FRAMES_PUNCH');
2695 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2696 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2697 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2698 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2699 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2701 {$IFDEF ENABLE_SOUND}
2702 g_Sound_Delete('SOUND_GAME_TELEPORT');
2703 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2704 g_Sound_Delete('SOUND_GAME_SECRET');
2705 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2706 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2707 g_Sound_Delete('SOUND_GAME_BULK1');
2708 g_Sound_Delete('SOUND_GAME_BULK2');
2709 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2710 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2711 g_Sound_Delete('SOUND_GAME_BURNING');
2712 g_Sound_Delete('SOUND_GAME_SWITCH1');
2713 g_Sound_Delete('SOUND_GAME_SWITCH0');
2715 goodsnd[0].Free();
2716 goodsnd[1].Free();
2717 goodsnd[2].Free();
2718 goodsnd[3].Free();
2720 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2721 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2722 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2723 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2725 killsnd[0].Free();
2726 killsnd[1].Free();
2727 killsnd[2].Free();
2728 killsnd[3].Free();
2730 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2731 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2732 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2733 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2735 hahasnd[0].Free();
2736 hahasnd[1].Free();
2737 hahasnd[2].Free();
2739 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2740 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2741 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2743 sound_get_flag[0].Free();
2744 sound_get_flag[1].Free();
2745 sound_lost_flag[0].Free();
2746 sound_lost_flag[1].Free();
2747 sound_ret_flag[0].Free();
2748 sound_ret_flag[1].Free();
2749 sound_cap_flag[0].Free();
2750 sound_cap_flag[1].Free();
2752 g_Sound_Delete('SOUND_CTF_GET1');
2753 g_Sound_Delete('SOUND_CTF_GET2');
2754 g_Sound_Delete('SOUND_CTF_LOST1');
2755 g_Sound_Delete('SOUND_CTF_LOST2');
2756 g_Sound_Delete('SOUND_CTF_RETURN1');
2757 g_Sound_Delete('SOUND_CTF_RETURN2');
2758 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2759 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2761 g_Game_FreeChatSounds();
2762 {$ENDIF}
2764 DataLoaded := False;
2765 end;
2767 procedure DrawCustomStat();
2769 pc, x, y, w, _y,
2770 w1, w2, w3,
2771 t, p, m: Integer;
2772 ww1, hh1: Word;
2773 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2774 s1, s2, topstr: String;
2775 begin
2776 e_TextureFontGetSize(gStdFont, ww2, hh2);
2778 sys_HandleEvents();
2780 if g_Console_Action(ACTION_SCORES) then
2781 begin
2782 if not gStatsPressed then
2783 begin
2784 gStatsOff := not gStatsOff;
2785 gStatsPressed := True;
2786 end;
2788 else
2789 gStatsPressed := False;
2791 if gStatsOff then
2792 begin
2793 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2794 w := (Length(s1) * ww2) div 2;
2795 x := gScreenWidth div 2 - w;
2796 y := 8;
2797 e_TextureFontPrint(x, y, s1, gStdFont);
2798 Exit;
2799 end;
2801 if (gGameSettings.GameMode = GM_COOP) then
2802 begin
2803 if gMissionFailed then
2804 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2805 else
2806 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2808 else
2809 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2811 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2812 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2814 if g_Game_IsNet then
2815 begin
2816 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2817 if not gChatShow then
2818 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2819 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2820 end;
2822 if g_Game_IsClient then
2823 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2824 else
2825 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2826 if not gChatShow then
2827 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2828 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2830 x := 32;
2831 y := 16+hh1+16;
2833 w := gScreenWidth-x*2;
2835 w2 := (w-16) div 6;
2836 w3 := w2;
2837 w1 := w-16-w2-w3;
2839 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2840 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2842 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2844 case CustomStat.GameMode of
2845 GM_DM:
2846 begin
2847 if gGameSettings.MaxLives = 0 then
2848 s1 := _lc[I_GAME_DM]
2849 else
2850 s1 := _lc[I_GAME_LMS];
2851 end;
2852 GM_TDM:
2853 begin
2854 if gGameSettings.MaxLives = 0 then
2855 s1 := _lc[I_GAME_TDM]
2856 else
2857 s1 := _lc[I_GAME_TLMS];
2858 end;
2859 GM_CTF: s1 := _lc[I_GAME_CTF];
2860 GM_COOP:
2861 begin
2862 if gGameSettings.MaxLives = 0 then
2863 s1 := _lc[I_GAME_COOP]
2864 else
2865 s1 := _lc[I_GAME_SURV];
2866 end;
2867 else s1 := '';
2868 end;
2870 _y := y+16;
2871 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2872 _y := _y+8;
2874 _y := _y+16;
2875 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2876 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2878 _y := _y+16;
2879 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2880 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2881 (CustomStat.GameTime div 1000 div 60) mod 60,
2882 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2884 pc := Length(CustomStat.PlayerStat);
2885 if pc = 0 then Exit;
2887 if CustomStat.GameMode = GM_COOP then
2888 begin
2889 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2890 _y := _y+32;
2891 s2 := _lc[I_GAME_MONSTERS];
2892 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2893 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2894 _y := _y+16;
2895 s2 := _lc[I_GAME_SECRETS];
2896 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2897 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2898 if gLastMap then
2899 begin
2900 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2901 _y := _y-16;
2902 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2903 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2904 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2905 _y := _y+16;
2906 s2 := _lc[I_GAME_SECRETS_TOTAL];
2907 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2908 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2909 end;
2910 end;
2912 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2913 begin
2914 _y := _y+16+16;
2916 with CustomStat do
2917 if TeamStat[TEAM_RED].Score > TeamStat[TEAM_BLUE].Score then s1 := _lc[I_GAME_WIN_RED]
2918 else if TeamStat[TEAM_BLUE].Score > TeamStat[TEAM_RED].Score then s1 := _lc[I_GAME_WIN_BLUE]
2919 else s1 := _lc[I_GAME_WIN_DRAW];
2921 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2922 _y := _y+40;
2924 for t := TEAM_RED to TEAM_BLUE do
2925 begin
2926 if t = TEAM_RED then
2927 begin
2928 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2929 gStdFont, 255, 0, 0, 1);
2930 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Score),
2931 gStdFont, 255, 0, 0, 1);
2932 r := 255;
2933 g := 0;
2934 b := 0;
2936 else
2937 begin
2938 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2939 gStdFont, 0, 0, 255, 1);
2940 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Score),
2941 gStdFont, 0, 0, 255, 1);
2942 r := 0;
2943 g := 0;
2944 b := 255;
2945 end;
2947 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2948 _y := _y+24;
2950 for p := 0 to High(CustomStat.PlayerStat) do
2951 if CustomStat.PlayerStat[p].Team = t then
2952 with CustomStat.PlayerStat[p] do
2953 begin
2954 if Spectator then
2955 begin
2956 rr := r div 2;
2957 gg := g div 2;
2958 bb := b div 2;
2960 else
2961 begin
2962 rr := r;
2963 gg := g;
2964 bb := b;
2965 end;
2966 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2967 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2968 else
2969 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2970 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2971 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2972 _y := _y+24;
2973 end;
2975 _y := _y+16+16;
2976 end;
2978 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2979 begin
2980 _y := _y+40;
2981 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2982 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2983 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2985 _y := _y+24;
2986 for p := 0 to High(CustomStat.PlayerStat) do
2987 with CustomStat.PlayerStat[p] do
2988 begin
2989 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2991 if Spectator then
2992 r := 127
2993 else
2994 r := 255;
2996 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2997 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2998 else
2999 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
3000 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
3001 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
3002 _y := _y+24;
3003 end;
3004 end;
3006 // HACK: take stats screenshot immediately after the first frame of the stats showing
3007 if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
3008 begin
3009 g_TakeScreenShot('stats/' + StatFilename);
3010 StatShotDone := True;
3011 end;
3012 end;
3014 procedure DrawSingleStat();
3016 tm, key_x, val_x, y: Integer;
3017 w1, w2, h: Word;
3018 s1, s2: String;
3020 procedure player_stat(n: Integer);
3022 kpm: Real;
3024 begin
3025 // "Kills: # / #":
3026 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
3027 s2 := Format(' %d', [gTotalMonsters]);
3029 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
3030 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
3031 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3032 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
3033 s1 := s1 + '/';
3034 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3035 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
3037 // "Kills-per-minute: ##.#":
3038 s1 := _lc[I_MENU_INTER_KPM];
3039 if tm > 0 then
3040 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
3041 else
3042 kpm := SingleStat.PlayerStat[n].Kills;
3043 s2 := Format(' %.1f', [kpm]);
3045 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
3046 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
3048 // "Secrets found: # / #":
3049 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
3050 s2 := Format(' %d', [SingleStat.TotalSecrets]);
3052 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
3053 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
3054 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3055 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
3056 s1 := s1 + '/';
3057 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3058 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
3059 end;
3061 begin
3062 // "Level Complete":
3063 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
3064 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
3066 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3067 s1 := _lc[I_MENU_INTER_KPM];
3068 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3069 Inc(w1, 16);
3070 s1 := ' 9999.9';
3071 e_CharFont_GetSize(gMenuFont, s1, w2, h);
3073 key_x := (gScreenWidth-w1-w2) div 2;
3074 val_x := key_x + w1;
3076 // "Time: #:##:##":
3077 tm := SingleStat.GameTime div 1000;
3078 s1 := _lc[I_MENU_INTER_TIME];
3079 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
3081 e_CharFont_Print(gMenuFont, key_x, 80, s1);
3082 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
3084 if SingleStat.TwoPlayers then
3085 begin
3086 // "Player 1":
3087 s1 := _lc[I_MENU_PLAYER_1];
3088 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3089 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
3091 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3092 y := 176;
3093 player_stat(0);
3095 // "Player 2":
3096 s1 := _lc[I_MENU_PLAYER_2];
3097 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3098 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
3100 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3101 y := 336;
3102 player_stat(1);
3104 else
3105 begin
3106 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3107 y := 128;
3108 player_stat(0);
3109 end;
3110 end;
3112 procedure DrawLoadingStat();
3113 procedure drawRect (x, y, w, h: Integer);
3114 begin
3115 if (w < 1) or (h < 1) then exit;
3116 glBegin(GL_QUADS);
3117 glVertex2f(x+0.375, y+0.375);
3118 glVertex2f(x+w+0.375, y+0.375);
3119 glVertex2f(x+w+0.375, y+h+0.375);
3120 glVertex2f(x+0.375, y+h+0.375);
3121 glEnd();
3122 end;
3124 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
3126 rectW, rectH: Integer;
3127 x0, y0: Integer;
3128 wdt: Integer;
3129 wl, hl: Integer;
3130 wr, hr: Integer;
3131 wb, hb: Integer;
3132 wm, hm: Integer;
3133 idl, idr, idb, idm: LongWord;
3134 f, my: Integer;
3135 begin
3136 result := false;
3137 if (total < 1) then exit;
3138 if (cur < 1) then exit; // don't blink
3139 if (not washere) and (cur >= total) then exit; // don't blink
3140 //if (cur < 0) then cur := 0;
3141 //if (cur > total) then cur := total;
3142 result := true;
3144 if (hasPBarGfx) then
3145 begin
3146 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
3147 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
3148 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
3149 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
3150 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
3151 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
3152 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
3153 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
3155 //rectW := gScreenWidth-360;
3156 rectW := trunc(624.0*gScreenWidth/1024.0);
3157 rectH := hl;
3159 x0 := (gScreenWidth-rectW) div 2;
3160 y0 := gScreenHeight-rectH-64;
3161 if (y0 < 2) then y0 := 2;
3163 glEnable(GL_SCISSOR_TEST);
3165 // left and right
3166 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
3167 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
3168 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
3170 // body
3171 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
3172 f := x0+wl;
3173 while (f < x0+rectW) do
3174 begin
3175 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
3176 f += wb;
3177 end;
3179 // filled part
3180 wdt := (rectW-wl-wr)*cur div total;
3181 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
3182 if (wdt > 0) then
3183 begin
3184 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
3185 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
3186 f := x0+wl;
3187 while (wdt > 0) do
3188 begin
3189 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
3190 f += wm;
3191 wdt -= wm;
3192 end;
3193 end;
3195 glScissor(0, 0, gScreenWidth, gScreenHeight);
3197 else
3198 begin
3199 rectW := gScreenWidth-64;
3200 rectH := 16;
3202 x0 := (gScreenWidth-rectW) div 2;
3203 y0 := gScreenHeight-rectH-64;
3204 if (y0 < 2) then y0 := 2;
3206 glDisable(GL_BLEND);
3207 glDisable(GL_TEXTURE_2D);
3209 //glClearColor(0, 0, 0, 0);
3210 //glClear(GL_COLOR_BUFFER_BIT);
3212 glColor4ub(127, 127, 127, 255);
3213 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3215 glColor4ub(0, 0, 0, 255);
3216 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3218 glColor4ub(127, 127, 127, 255);
3219 wdt := rectW*cur div total;
3220 if (wdt > rectW) then wdt := rectW;
3221 drawRect(x0, y0, wdt, rectH);
3222 end;
3223 end;
3226 ww, hh: Word;
3227 xx, yy, i: Integer;
3228 s: String;
3229 begin
3230 if (Length(LoadingStat.Msgs) = 0) then exit;
3232 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3233 yy := (gScreenHeight div 3);
3234 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3235 xx := (gScreenWidth div 3);
3237 with LoadingStat do
3238 begin
3239 for i := 0 to NextMsg-1 do
3240 begin
3241 if (i = (NextMsg-1)) and (MaxValue > 0) then
3242 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3243 else
3244 s := Msgs[i];
3246 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3247 yy := yy + LOADING_INTERLINE;
3248 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3249 end;
3250 end;
3251 end;
3253 procedure DrawMenuBackground(tex: AnsiString);
3255 w, h: Word;
3256 ID: DWord;
3258 begin
3259 if g_Texture_Get(tex, ID) then
3260 begin
3261 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3262 e_GetTextureSize(ID, @w, @h);
3263 if w = h then
3264 w := round(w * 1.333 * (gScreenHeight / h))
3265 else
3266 w := trunc(w * (gScreenHeight / h));
3267 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3269 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3270 end;
3272 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3274 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3276 function monDraw (mon: TMonster): Boolean;
3277 begin
3278 result := false; // don't stop
3279 with mon do
3280 begin
3281 if alive then
3282 begin
3283 // Ëåâûé âåðõíèé óãîë
3284 aX := Obj.X div ScaleSz + 1;
3285 aY := Obj.Y div ScaleSz + 1;
3286 // Ðàçìåðû
3287 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3288 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3289 // Ïðàâûé íèæíèé óãîë
3290 aX2 := aX + aX2 - 1;
3291 aY2 := aY + aY2 - 1;
3292 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3293 end;
3294 end;
3295 end;
3297 begin
3298 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3299 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3300 begin
3301 Scale := 1;
3302 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3303 ScaleSz := 16 div Scale;
3304 // Ðàçìåðû ìèíè-êàðòû:
3305 aX := max(gMapInfo.Width div ScaleSz, 1);
3306 aY := max(gMapInfo.Height div ScaleSz, 1);
3307 // Ðàìêà êàðòû:
3308 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3310 if gWalls <> nil then
3311 begin
3312 // Ðèñóåì ñòåíû:
3313 for a := 0 to High(gWalls) do
3314 with gWalls[a] do
3315 if PanelType <> 0 then
3316 begin
3317 // Ëåâûé âåðõíèé óãîë:
3318 aX := X div ScaleSz;
3319 aY := Y div ScaleSz;
3320 // Ðàçìåðû:
3321 aX2 := max(Width div ScaleSz, 1);
3322 aY2 := max(Height div ScaleSz, 1);
3323 // Ïðàâûé íèæíèé óãîë:
3324 aX2 := aX + aX2 - 1;
3325 aY2 := aY + aY2 - 1;
3327 case PanelType of
3328 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3329 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3330 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3331 end;
3332 end;
3333 end;
3334 if gSteps <> nil then
3335 begin
3336 // Ðèñóåì ñòóïåíè:
3337 for a := 0 to High(gSteps) do
3338 with gSteps[a] do
3339 if PanelType <> 0 then
3340 begin
3341 // Ëåâûé âåðõíèé óãîë:
3342 aX := X div ScaleSz;
3343 aY := Y div ScaleSz;
3344 // Ðàçìåðû:
3345 aX2 := max(Width div ScaleSz, 1);
3346 aY2 := max(Height div ScaleSz, 1);
3347 // Ïðàâûé íèæíèé óãîë:
3348 aX2 := aX + aX2 - 1;
3349 aY2 := aY + aY2 - 1;
3351 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3352 end;
3353 end;
3354 if gLifts <> nil then
3355 begin
3356 // Ðèñóåì ëèôòû:
3357 for a := 0 to High(gLifts) do
3358 with gLifts[a] do
3359 if PanelType <> 0 then
3360 begin
3361 // Ëåâûé âåðõíèé óãîë:
3362 aX := X div ScaleSz;
3363 aY := Y div ScaleSz;
3364 // Ðàçìåðû:
3365 aX2 := max(Width div ScaleSz, 1);
3366 aY2 := max(Height div ScaleSz, 1);
3367 // Ïðàâûé íèæíèé óãîë:
3368 aX2 := aX + aX2 - 1;
3369 aY2 := aY + aY2 - 1;
3371 case LiftType of
3372 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3373 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3374 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3375 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3376 end;
3377 end;
3378 end;
3379 if gWater <> nil then
3380 begin
3381 // Ðèñóåì âîäó:
3382 for a := 0 to High(gWater) do
3383 with gWater[a] do
3384 if PanelType <> 0 then
3385 begin
3386 // Ëåâûé âåðõíèé óãîë:
3387 aX := X div ScaleSz;
3388 aY := Y div ScaleSz;
3389 // Ðàçìåðû:
3390 aX2 := max(Width div ScaleSz, 1);
3391 aY2 := max(Height div ScaleSz, 1);
3392 // Ïðàâûé íèæíèé óãîë:
3393 aX2 := aX + aX2 - 1;
3394 aY2 := aY + aY2 - 1;
3396 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3397 end;
3398 end;
3399 if gAcid1 <> nil then
3400 begin
3401 // Ðèñóåì êèñëîòó 1:
3402 for a := 0 to High(gAcid1) do
3403 with gAcid1[a] do
3404 if PanelType <> 0 then
3405 begin
3406 // Ëåâûé âåðõíèé óãîë:
3407 aX := X div ScaleSz;
3408 aY := Y div ScaleSz;
3409 // Ðàçìåðû:
3410 aX2 := max(Width div ScaleSz, 1);
3411 aY2 := max(Height div ScaleSz, 1);
3412 // Ïðàâûé íèæíèé óãîë:
3413 aX2 := aX + aX2 - 1;
3414 aY2 := aY + aY2 - 1;
3416 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3417 end;
3418 end;
3419 if gAcid2 <> nil then
3420 begin
3421 // Ðèñóåì êèñëîòó 2:
3422 for a := 0 to High(gAcid2) do
3423 with gAcid2[a] do
3424 if PanelType <> 0 then
3425 begin
3426 // Ëåâûé âåðõíèé óãîë:
3427 aX := X div ScaleSz;
3428 aY := Y div ScaleSz;
3429 // Ðàçìåðû:
3430 aX2 := max(Width div ScaleSz, 1);
3431 aY2 := max(Height div ScaleSz, 1);
3432 // Ïðàâûé íèæíèé óãîë:
3433 aX2 := aX + aX2 - 1;
3434 aY2 := aY + aY2 - 1;
3436 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3437 end;
3438 end;
3439 if gPlayers <> nil then
3440 begin
3441 // Ðèñóåì èãðîêîâ:
3442 for a := 0 to High(gPlayers) do
3443 if gPlayers[a] <> nil then with gPlayers[a] do
3444 if alive then begin
3445 // Ëåâûé âåðõíèé óãîë:
3446 aX := Obj.X div ScaleSz + 1;
3447 aY := Obj.Y div ScaleSz + 1;
3448 // Ðàçìåðû:
3449 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3450 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3451 // Ïðàâûé íèæíèé óãîë:
3452 aX2 := aX + aX2 - 1;
3453 aY2 := aY + aY2 - 1;
3455 if gPlayers[a] = p then
3456 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3457 else
3458 case Team of
3459 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3460 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3461 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3462 end;
3463 end;
3464 end;
3465 // Ðèñóåì ìîíñòðîâ
3466 g_Mons_ForEach(monDraw);
3467 end;
3468 end;
3471 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3472 begin
3473 if not hasAmbient then exit;
3474 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3475 end;
3478 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3479 //FIXME: broken for splitscreen mode
3480 procedure renderDynLightsInternal ();
3482 //hasAmbient: Boolean;
3483 //ambColor: TDFColor;
3484 lln: Integer;
3485 lx, ly, lrad: Integer;
3486 scxywh: array[0..3] of GLint;
3487 wassc: Boolean;
3488 begin
3489 if e_NoGraphics then exit;
3491 //TODO: lights should be in separate grid, i think
3492 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3493 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3495 // rendering mode
3496 //ambColor := gCurrentMap['light_ambient'].rgba;
3497 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3499 { // this will multiply incoming color to alpha from framebuffer
3500 glEnable(GL_BLEND);
3501 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3505 * light rendering: (INVALID!)
3506 * glStencilFunc(GL_EQUAL, 0, $ff);
3507 * for each light:
3508 * glClear(GL_STENCIL_BUFFER_BIT);
3509 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3510 * draw shadow volume into stencil buffer
3511 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3512 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3513 * turn off blending
3514 * draw color-less quad with light alpha (WARNING! don't touch color!)
3515 * glEnable(GL_BLEND);
3516 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3517 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3519 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3520 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3522 // setup OpenGL parameters
3523 glStencilMask($FFFFFFFF);
3524 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3525 glEnable(GL_STENCIL_TEST);
3526 glEnable(GL_SCISSOR_TEST);
3527 glClear(GL_STENCIL_BUFFER_BIT);
3528 glStencilFunc(GL_EQUAL, 0, $ff);
3530 for lln := 0 to g_dynLightCount-1 do
3531 begin
3532 lx := g_dynLights[lln].x;
3533 ly := g_dynLights[lln].y;
3534 lrad := g_dynLights[lln].radius;
3535 if (lrad < 3) then continue;
3537 if (lx-sX+lrad < 0) then continue;
3538 if (ly-sY+lrad < 0) then continue;
3539 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3540 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3542 // set scissor to optimize drawing
3543 if (g_dbg_scale = 1.0) then
3544 begin
3545 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3547 else
3548 begin
3549 glScissor(0, 0, gScreenWidth, gScreenHeight);
3550 end;
3551 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3552 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3553 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3554 // draw extruded panels
3555 glDisable(GL_TEXTURE_2D);
3556 glDisable(GL_BLEND);
3557 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3558 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3559 // render light texture
3560 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3561 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3562 // blend it
3563 glEnable(GL_BLEND);
3564 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3565 glEnable(GL_TEXTURE_2D);
3566 // color and opacity
3567 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3568 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3569 glBegin(GL_QUADS);
3570 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3571 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3572 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3573 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3574 glEnd();
3575 end;
3577 // done
3578 glDisable(GL_STENCIL_TEST);
3579 glDisable(GL_BLEND);
3580 glDisable(GL_SCISSOR_TEST);
3581 //glScissor(0, 0, sWidth, sHeight);
3583 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3584 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3585 end;
3588 function fixViewportForScale (): Boolean;
3590 nx0, ny0, nw, nh: Integer;
3591 begin
3592 result := false;
3593 if (g_dbg_scale <> 1.0) then
3594 begin
3595 result := true;
3596 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3597 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3598 nw := round(sWidth/g_dbg_scale);
3599 nh := round(sHeight/g_dbg_scale);
3600 sX := nx0;
3601 sY := ny0;
3602 sWidth := nw;
3603 sHeight := nh;
3604 end;
3605 end;
3608 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3609 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3610 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3611 type
3612 TDrawCB = procedure ();
3615 hasAmbient: Boolean;
3616 ambColor: TDFColor;
3617 doAmbient: Boolean = false;
3619 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3621 tagmask: Integer;
3622 pan: TPanel;
3623 begin
3624 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3625 if gdbg_map_use_accel_render then
3626 begin
3627 tagmask := panelTypeToTag(panType);
3628 while (gDrawPanelList.count > 0) do
3629 begin
3630 pan := TPanel(gDrawPanelList.front());
3631 if ((pan.tag and tagmask) = 0) then break;
3632 if doDraw then pan.Draw(doAmbient, ambColor);
3633 gDrawPanelList.popFront();
3634 end;
3636 else
3637 begin
3638 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3639 end;
3640 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3641 end;
3643 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3644 begin
3645 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3646 if assigned(cb) then cb();
3647 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3648 end;
3650 begin
3651 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3653 // our accelerated renderer will collect all panels to gDrawPanelList
3654 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3655 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3656 if gdbg_map_use_accel_render then
3657 begin
3658 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3659 end;
3660 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3662 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3663 g_Map_DrawBack(backXOfs, backYOfs);
3664 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3666 if setTransMatrix then
3667 begin
3668 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3669 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3670 glTranslatef(-sX, -sY, 0);
3671 end;
3673 // rendering mode
3674 ambColor := gCurrentMap['light_ambient'].rgba;
3675 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3678 if hasAmbient then
3679 begin
3680 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3681 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3682 glClear(GL_COLOR_BUFFER_BIT);
3683 end;
3685 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3688 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3689 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3690 drawOther('items', @g_Items_Draw);
3691 drawOther('weapons', @g_Weapon_Draw);
3692 drawOther('shells', @g_Player_DrawShells);
3693 drawOther('drawall', @g_Player_DrawAll);
3694 drawOther('corpses', @g_Player_DrawCorpses);
3695 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3696 drawOther('monsters', @g_Monsters_Draw);
3697 drawOther('itemdrop', @g_Items_DrawDrop);
3698 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3699 drawOther('gfx', @g_GFX_Draw);
3700 drawOther('flags', @g_Map_DrawFlags);
3701 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3702 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3703 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3704 drawOther('dynlights', @renderDynLightsInternal);
3706 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3707 begin
3708 renderAmbientQuad(hasAmbient, ambColor);
3709 end;
3711 doAmbient := true;
3712 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3715 if g_debug_HealthBar then
3716 begin
3717 g_Monsters_DrawHealth();
3718 g_Player_DrawHealth();
3719 end;
3721 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3722 end;
3725 procedure DrawMapView(x, y, w, h: Integer);
3728 bx, by: Integer;
3729 begin
3730 glPushMatrix();
3732 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3733 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3735 sX := x;
3736 sY := y;
3737 sWidth := w;
3738 sHeight := h;
3740 fixViewportForScale();
3741 renderMapInternal(-bx, -by, true);
3743 glPopMatrix();
3744 end;
3747 procedure DrawPlayer(p: TPlayer);
3749 px, py, a, b, c, d, i, fX, fY: Integer;
3750 camObj: TObj;
3751 //R: TRect;
3752 begin
3753 if (p = nil) or (p.FDummy) then
3754 begin
3755 glPushMatrix();
3756 g_Map_DrawBack(0, 0);
3757 glPopMatrix();
3758 Exit;
3759 end;
3761 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3762 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3764 gPlayerDrawn := p;
3766 glPushMatrix();
3768 camObj := p.getCameraObj();
3769 camObj.lerp(gLerpFactor, fX, fY);
3770 px := fX + PLAYER_RECT_CX;
3771 py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, camObj.slopeUpLeft, gLerpFactor);
3773 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3774 begin
3775 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3776 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3778 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3779 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3781 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3782 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3783 begin
3784 // hcenter
3785 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3786 end;
3788 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3789 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3790 begin
3791 // vcenter
3792 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3793 end;
3795 else
3796 begin
3797 // scaled, ignore level bounds
3798 a := -px+(gPlayerScreenSize.X div 2);
3799 b := -py+(gPlayerScreenSize.Y div 2);
3800 end;
3802 sX := -a;
3803 sY := -b;
3804 sWidth := gPlayerScreenSize.X;
3805 sHeight := gPlayerScreenSize.Y;
3806 fixViewportForScale();
3808 i := py - (sY + sHeight div 2);
3809 if (p.IncCam > 0) then
3810 begin
3811 // clamp to level bounds
3812 if (sY - p.IncCam < 0) then
3813 p.IncCam := nclamp(sY, 0, 120);
3814 // clamp around player position
3815 if (i > 0) then
3816 p.IncCam := nclamp(p.IncCam, 0, max(0, 120 - i));
3818 else if (p.IncCam < 0) then
3819 begin
3820 // clamp to level bounds
3821 if (sY + sHeight - p.IncCam > gMapInfo.Height) then
3822 p.IncCam := nclamp(sY + sHeight - gMapInfo.Height, -120, 0);
3823 // clamp around player position
3824 if (i < 0) then
3825 p.IncCam := nclamp(p.IncCam, min(0, -120 - i), 0);
3826 end;
3828 sY := sY - nlerp(p.IncCamOld, p.IncCam, gLerpFactor);
3830 if (not g_dbg_ignore_bounds) then
3831 begin
3832 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3833 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3834 if (sX < 0) then sX := 0;
3835 if (sY < 0) then sY := 0;
3836 end;
3838 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3839 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3841 //r_smallmap_h: 0: left; 1: center; 2: right
3842 //r_smallmap_v: 0: top; 1: center; 2: bottom
3843 // horiz small map?
3844 if (gMapInfo.Width = sWidth) then
3845 begin
3846 sX := 0;
3848 else if (gMapInfo.Width < sWidth) then
3849 begin
3850 case r_smallmap_h of
3851 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3852 2: sX := -(sWidth-gMapInfo.Width); // right
3853 else sX := 0; // left
3854 end;
3855 end;
3856 // vert small map?
3857 if (gMapInfo.Height = sHeight) then
3858 begin
3859 sY := 0;
3861 else if (gMapInfo.Height < sHeight) then
3862 begin
3863 case r_smallmap_v of
3864 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3865 2: sY := -(sHeight-gMapInfo.Height); // bottom
3866 else sY := 0; // top
3867 end;
3868 end;
3870 p.viewPortX := sX;
3871 p.viewPortY := sY;
3872 p.viewPortW := sWidth;
3873 p.viewPortH := sHeight;
3875 {$IFDEF ENABLE_HOLMES}
3876 if (p = gPlayer1) then
3877 begin
3878 g_Holmes_plrViewPos(sX, sY);
3879 g_Holmes_plrViewSize(sWidth, sHeight);
3880 end;
3881 {$ENDIF}
3883 renderMapInternal(-c, -d, true);
3885 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3886 case gPlayerIndicator of
3888 p.DrawIndicator(_RGB(255, 255, 255));
3891 for i := 0 to High(gPlayers) do
3892 if gPlayers[i] <> nil then
3893 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3894 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3895 if gPlayerIndicatorStyle = 1 then
3896 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3897 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3898 end;
3901 for a := 0 to High(gCollideMap) do
3902 for b := 0 to High(gCollideMap[a]) do
3903 begin
3904 d := 0;
3905 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3906 d := d + 1;
3907 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3908 d := d + 2;
3910 case d of
3911 1: e_DrawPoint(1, b, a, 200, 200, 200);
3912 2: e_DrawPoint(1, b, a, 64, 64, 255);
3913 3: e_DrawPoint(1, b, a, 255, 0, 255);
3914 end;
3915 end;
3918 glPopMatrix();
3920 p.DrawPain();
3921 p.DrawPickup();
3922 p.DrawOverlay();
3923 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3924 if g_Debug_Player then
3925 g_Player_DrawDebug(p);
3926 p.DrawGUI();
3927 end;
3929 procedure drawProfilers ();
3931 px: Integer = -1;
3932 py: Integer = -1;
3933 begin
3934 if g_profile_frame_draw and (profileFrameDraw <> nil) then
3935 px -= drawProfiles(px, py, profileFrameDraw);
3937 if g_profile_collision and (profMapCollision <> nil) then
3938 begin
3939 px -= drawProfiles(px, py, profMapCollision);
3940 py -= calcProfilesHeight(profMonsLOS);
3941 end;
3943 if g_profile_los and (profMonsLOS <> nil) then
3944 begin
3945 px -= drawProfiles(px, py, profMonsLOS);
3946 py -= calcProfilesHeight(profMonsLOS);
3947 end;
3948 end;
3950 procedure g_Game_Draw();
3952 ID: DWORD;
3953 w, h: Word;
3954 ww, hh: Byte;
3955 Time: Int64;
3956 back: string;
3957 plView1, plView2: TPlayer;
3958 Split: Boolean;
3959 begin
3960 if gExit = EXIT_QUIT then Exit;
3962 Time := sys_GetTicks() {div 1000};
3963 FPSCounter := FPSCounter+1;
3964 if Time - FPSTime >= 1000 then
3965 begin
3966 FPS := FPSCounter;
3967 FPSCounter := 0;
3968 FPSTime := Time;
3969 end;
3971 e_SetRendertarget(True);
3972 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3974 if gGameOn or (gState = STATE_FOLD) then
3975 begin
3976 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3977 begin
3978 gSpectMode := SPECT_NONE;
3979 if not gRevertPlayers then
3980 begin
3981 plView1 := gPlayer1;
3982 plView2 := gPlayer2;
3984 else
3985 begin
3986 plView1 := gPlayer2;
3987 plView2 := gPlayer1;
3988 end;
3990 else
3991 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3992 begin
3993 gSpectMode := SPECT_NONE;
3994 if gPlayer2 = nil then
3995 plView1 := gPlayer1
3996 else
3997 plView1 := gPlayer2;
3998 plView2 := nil;
4000 else
4001 begin
4002 plView1 := nil;
4003 plView2 := nil;
4004 end;
4006 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
4007 gSpectMode := SPECT_STATS;
4009 if gSpectMode = SPECT_PLAYERS then
4010 if gPlayers <> nil then
4011 begin
4012 plView1 := GetActivePlayer_ByID(gSpectPID1);
4013 if plView1 = nil then
4014 begin
4015 gSpectPID1 := GetActivePlayerID_Next();
4016 plView1 := GetActivePlayer_ByID(gSpectPID1);
4017 end;
4018 if gSpectViewTwo then
4019 begin
4020 plView2 := GetActivePlayer_ByID(gSpectPID2);
4021 if plView2 = nil then
4022 begin
4023 gSpectPID2 := GetActivePlayerID_Next();
4024 plView2 := GetActivePlayer_ByID(gSpectPID2);
4025 end;
4026 end;
4027 end;
4029 if gSpectMode = SPECT_MAPVIEW then
4030 begin
4031 // Ðåæèì ïðîñìîòðà êàðòû
4032 Split := False;
4033 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4034 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
4035 gHearPoint1.Active := True;
4036 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
4037 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
4038 gHearPoint2.Active := False;
4040 else
4041 begin
4042 Split := (plView1 <> nil) and (plView2 <> nil);
4044 // Òî÷êè ñëóõà èãðîêîâ
4045 if plView1 <> nil then
4046 begin
4047 gHearPoint1.Active := True;
4048 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
4049 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
4050 end else
4051 gHearPoint1.Active := False;
4052 if plView2 <> nil then
4053 begin
4054 gHearPoint2.Active := True;
4055 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
4056 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
4057 end else
4058 gHearPoint2.Active := False;
4060 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4061 gPlayerScreenSize.X := gScreenWidth-196;
4062 if Split then
4063 begin
4064 gPlayerScreenSize.Y := gScreenHeight div 2;
4065 if gScreenHeight mod 2 = 0 then
4066 Dec(gPlayerScreenSize.Y);
4068 else
4069 gPlayerScreenSize.Y := gScreenHeight;
4071 if Split then
4072 if gScreenHeight mod 2 = 0 then
4073 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
4074 else
4075 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4077 DrawPlayer(plView1);
4078 gPlayer1ScreenCoord.X := sX;
4079 gPlayer1ScreenCoord.Y := sY;
4081 if Split then
4082 begin
4083 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4085 DrawPlayer(plView2);
4086 gPlayer2ScreenCoord.X := sX;
4087 gPlayer2ScreenCoord.Y := sY;
4088 end;
4090 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4092 if Split then
4093 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
4094 end;
4096 {$IFDEF ENABLE_HOLMES}
4097 // draw inspector
4098 if (g_holmes_enabled) then g_Holmes_Draw();
4099 {$ENDIF}
4101 if MessageText <> '' then
4102 begin
4103 w := 0;
4104 h := 0;
4105 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
4106 if Split then
4107 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4108 (gScreenHeight div 2)-(h div 2), MessageText)
4109 else
4110 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4111 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4112 end;
4114 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4115 DrawStat();
4117 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4118 begin
4119 // Draw spectator GUI
4120 ww := 0;
4121 hh := 0;
4122 e_TextureFontGetSize(gStdFont, ww, hh);
4123 case gSpectMode of
4124 SPECT_STATS:
4125 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4126 SPECT_MAPVIEW:
4127 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4128 SPECT_PLAYERS:
4129 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4130 end;
4131 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4132 if gSpectMode = SPECT_STATS then
4133 begin
4134 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4135 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4136 end;
4137 if gSpectMode = SPECT_MAPVIEW then
4138 begin
4139 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4140 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4141 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4142 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4143 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4144 end;
4145 if gSpectMode = SPECT_PLAYERS then
4146 begin
4147 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4148 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4149 if gSpectViewTwo then
4150 begin
4151 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4152 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4153 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4154 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4156 else
4157 begin
4158 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4159 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4160 end;
4161 end;
4162 end;
4163 end;
4165 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4166 begin
4167 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4168 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4170 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4171 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4172 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4173 end;
4175 if not gGameOn then
4176 begin
4177 if (gState = STATE_MENU) then
4178 begin
4179 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4180 // F3 at menu will show game loading dialog
4181 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4182 if (g_ActiveWindow <> nil) then
4183 begin
4184 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4185 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4187 else
4188 begin
4189 // F3 at titlepic will show game loading dialog
4190 if e_KeyPressed(IK_F3) then
4191 begin
4192 g_Menu_Show_LoadMenu(true);
4193 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4194 end;
4195 end;
4196 end;
4198 if gState = STATE_FOLD then
4199 begin
4200 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4201 end;
4203 if gState = STATE_INTERCUSTOM then
4204 begin
4205 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4206 begin
4207 back := 'TEXTURE_endpic';
4208 if not g_Texture_Get(back, ID) then
4209 back := _lc[I_TEXTURE_ENDPIC];
4211 else
4212 back := 'INTER';
4214 DrawMenuBackground(back);
4216 DrawCustomStat();
4218 if g_ActiveWindow <> nil then
4219 begin
4220 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4221 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4222 end;
4223 end;
4225 if gState = STATE_INTERSINGLE then
4226 begin
4227 if EndingGameCounter > 0 then
4228 begin
4229 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4231 else
4232 begin
4233 back := 'INTER';
4235 DrawMenuBackground(back);
4237 DrawSingleStat();
4239 if g_ActiveWindow <> nil then
4240 begin
4241 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4242 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4243 end;
4244 end;
4245 end;
4247 if gState = STATE_ENDPIC then
4248 begin
4249 ID := DWORD(-1);
4250 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4251 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4253 if g_ActiveWindow <> nil then
4254 begin
4255 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4256 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4257 end;
4258 end;
4260 if gState = STATE_SLIST then
4261 begin
4262 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4263 // begin
4264 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4265 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4266 // end;
4267 DrawMenuBackground('MENU_BACKGROUND');
4268 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4269 g_Serverlist_Draw(slCurrent, slTable);
4270 end;
4271 end;
4273 if g_ActiveWindow <> nil then
4274 begin
4275 if gGameOn then
4276 begin
4277 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4278 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4279 end;
4280 g_ActiveWindow.Draw();
4281 end;
4283 {$IFNDEF HEADLESS}
4284 g_Console_Draw();
4285 {$ENDIF}
4287 {$IFDEF ENABLE_SOUND}
4288 if g_debug_Sounds and gGameOn then
4289 begin
4290 for w := 0 to High(e_SoundsArray) do
4291 for h := 0 to e_SoundsArray[w].nRefs do
4292 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4293 end;
4294 {$ENDIF}
4296 if gShowFPS then
4297 begin
4298 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4299 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4300 end;
4302 if gGameOn and gShowTime then
4303 drawTime(gScreenWidth-72, gScreenHeight-16);
4305 if gGameOn then drawProfilers();
4307 // TODO: draw this after the FBO and remap mouse click coordinates
4309 {$IFDEF ENABLE_HOLMES}
4310 g_Holmes_DrawUI();
4311 {$ENDIF}
4313 // blit framebuffer to screen
4315 e_SetRendertarget(False);
4316 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4317 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4319 // draw the overlay stuff on top of it
4321 g_Touch_Draw;
4322 end;
4324 // FIXME: This cannot be called from anywhere other than ProcessMessages(), because otherwise
4325 // remaining events in the system queue may cause use-after-free! Do 'gExit := EXIT_QUIT' instead.
4326 procedure g_Game_Quit();
4327 begin
4328 e_WriteLog('g_Game_Quit: cleanup assets before shutting down', TMsgType.Notify);
4329 {$IFDEF ENABLE_SOUND}
4330 g_Game_StopAllSounds(True);
4331 gMusic.Free();
4332 {$ELSE}
4333 gMusicName := '';
4334 gMusicPlay := False;
4335 gMusicPos := 0;
4336 gMusicPause := False;
4337 {$ENDIF}
4338 g_Game_FreeData();
4339 g_PlayerModel_FreeData();
4340 g_Texture_DeleteAll();
4341 g_Frames_DeleteAll();
4342 {$IFNDEF HEADLESS}
4343 g_Menu_Free();
4344 {$ENDIF}
4346 if NetInitDone then g_Net_Free;
4348 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4349 if gMapToDelete <> '' then
4350 g_Game_DeleteTestMap();
4352 sys_RequestQuit(); // FIXME: this posts an event that have no sense anymore at this moment.
4353 end;
4355 procedure g_FatalError(Text: String);
4356 begin
4357 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4358 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4360 gExit := EXIT_SIMPLE;
4361 if gGameOn then EndGame;
4362 end;
4364 procedure g_SimpleError(Text: String);
4365 begin
4366 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4367 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4368 end;
4370 procedure g_Game_SetupScreenSize();
4371 const
4372 RES_FACTOR = 4.0 / 3.0;
4374 s: Single;
4375 rf: Single;
4376 bw, bh: Word;
4377 begin
4378 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4379 gPlayerScreenSize.X := gScreenWidth-196;
4380 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4381 gPlayerScreenSize.Y := gScreenHeight div 2
4382 else
4383 gPlayerScreenSize.Y := gScreenHeight;
4385 // Ðàçìåð çàäíåãî ïëàíà:
4386 if BackID <> DWORD(-1) then
4387 begin
4388 s := SKY_STRETCH;
4389 if (gScreenWidth*s > gMapInfo.Width) or
4390 (gScreenHeight*s > gMapInfo.Height) then
4391 begin
4392 gBackSize.X := gScreenWidth;
4393 gBackSize.Y := gScreenHeight;
4395 else
4396 begin
4397 e_GetTextureSize(BackID, @bw, @bh);
4398 rf := Single(bw) / Single(bh);
4399 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4400 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4401 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4402 if (s < 1.0) then s := 1.0;
4403 gBackSize.X := Round(bw*s);
4404 gBackSize.Y := Round(bh*s);
4405 end;
4406 end;
4407 end;
4409 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4410 begin
4411 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4412 end;
4414 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4415 begin
4416 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4417 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4418 Exit;
4420 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4421 Exit;
4423 if gPlayer1 = nil then
4424 begin
4425 if g_Game_IsClient then
4426 begin
4427 if NetPlrUID1 > -1 then
4428 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4429 Exit;
4430 end;
4432 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4433 Team := gPlayer1Settings.Team;
4435 // Ñîçäàíèå ïåðâîãî èãðîêà:
4436 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4437 gPlayer1Settings.Color,
4438 Team, False));
4439 if gPlayer1 = nil then
4440 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4441 else
4442 begin
4443 gPlayer1.Name := gPlayer1Settings.Name;
4444 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4445 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4446 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4447 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4448 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4449 if g_Game_IsServer and g_Game_IsNet then
4450 MH_SEND_PlayerCreate(gPlayer1.UID);
4451 gPlayer1.Respawn(False, True);
4452 g_Net_Slist_ServerPlayerComes();
4453 end;
4455 Exit;
4456 end;
4457 if gPlayer2 = nil then
4458 begin
4459 if g_Game_IsClient then
4460 begin
4461 if NetPlrUID2 > -1 then
4462 gPlayer2 := g_Player_Get(NetPlrUID2);
4463 Exit;
4464 end;
4466 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4467 Team := gPlayer2Settings.Team;
4469 // Ñîçäàíèå âòîðîãî èãðîêà:
4470 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4471 gPlayer2Settings.Color,
4472 Team, False));
4473 if gPlayer2 = nil then
4474 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4475 else
4476 begin
4477 gPlayer2.Name := gPlayer2Settings.Name;
4478 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4479 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4480 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4481 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4482 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4483 if g_Game_IsServer and g_Game_IsNet then
4484 MH_SEND_PlayerCreate(gPlayer2.UID);
4485 gPlayer2.Respawn(False, True);
4486 g_Net_Slist_ServerPlayerComes();
4487 end;
4489 Exit;
4490 end;
4491 end;
4493 procedure g_Game_RemovePlayer();
4495 Pl: TPlayer;
4496 begin
4497 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4498 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4499 Exit;
4500 Pl := gPlayer2;
4501 if Pl <> nil then
4502 begin
4503 if g_Game_IsServer then
4504 begin
4505 Pl.Lives := 0;
4506 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4507 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4508 g_Player_Remove(Pl.UID);
4509 g_Net_Slist_ServerPlayerLeaves();
4511 else
4512 begin
4513 gSpectLatchPID2 := Pl.UID;
4514 gPlayer2 := nil;
4515 end;
4516 Exit;
4517 end;
4518 Pl := gPlayer1;
4519 if Pl <> nil then
4520 begin
4521 if g_Game_IsServer then
4522 begin
4523 Pl.Lives := 0;
4524 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4525 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4526 g_Player_Remove(Pl.UID);
4527 g_Net_Slist_ServerPlayerLeaves();
4528 end else
4529 begin
4530 gSpectLatchPID1 := Pl.UID;
4531 gPlayer1 := nil;
4532 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4533 end;
4534 Exit;
4535 end;
4536 g_Net_Slist_ServerPlayerLeaves();
4537 end;
4539 procedure g_Game_Spectate();
4540 begin
4541 g_Game_RemovePlayer();
4542 if gPlayer1 <> nil then
4543 g_Game_RemovePlayer();
4544 end;
4546 procedure g_Game_SpectateCenterView();
4547 begin
4548 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4549 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4550 end;
4552 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4554 i, nPl: Integer;
4555 tmps: AnsiString;
4556 begin
4557 g_Game_Free();
4559 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4561 g_Game_ClearLoading();
4563 // Íàñòðîéêè èãðû:
4564 gGameSettings := Default(TGameSettings);
4565 gAimLine := False;
4566 gShowMap := False;
4567 gGameSettings.GameType := GT_SINGLE;
4568 gGameSettings.MaxLives := 0;
4569 gGameSettings.Options := [TGameOption.ALLOW_EXIT, TGameOption.MONSTERS,
4570 TGameOption.BOTS_VS_MONSTERS, TGameOption.TEAM_HIT_PROJECTILE, TGameOption.TEAM_HIT_TRACE,
4571 TGameOption.POWERUP_RANDOM, TGameOption.ITEM_ALL_RANDOM, TGameOption.ITEM_LIFE_RANDOM,
4572 TGameOption.ITEM_AMMO_RANDOM, TGameOption.ITEM_WEAPON_RANDOM];
4573 gSwitchGameMode := GM_SINGLE;
4575 gLMSRespawn := LMS_RESPAWN_NONE;
4576 gLMSRespawnTime := 0;
4577 gSpectLatchPID1 := 0;
4578 gSpectLatchPID2 := 0;
4580 g_Game_ExecuteEvent('ongamestart');
4582 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4583 g_Game_SetupScreenSize();
4585 // Ñîçäàíèå ïåðâîãî èãðîêà:
4586 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4587 gPlayer1Settings.Color,
4588 gPlayer1Settings.Team, False));
4589 if gPlayer1 = nil then
4590 begin
4591 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4592 Exit;
4593 end;
4595 gPlayer1.Name := gPlayer1Settings.Name;
4596 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4597 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4598 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4599 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4600 nPl := 1;
4602 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4603 if TwoPlayers then
4604 begin
4605 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4606 gPlayer2Settings.Color,
4607 gPlayer2Settings.Team, False));
4608 if gPlayer2 = nil then
4609 begin
4610 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4611 Exit;
4612 end;
4614 gPlayer2.Name := gPlayer2Settings.Name;
4615 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4616 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4617 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4618 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4619 Inc(nPl);
4620 end;
4622 // Çàãðóçêà è çàïóñê êàðòû:
4623 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4624 begin
4625 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4626 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4627 Exit;
4628 end;
4630 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4631 g_Player_Init();
4633 // Ñîçäàåì áîòîâ:
4634 for i := nPl+1 to nPlayers do
4635 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4636 end;
4638 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4639 TimeLimit, ScoreLimit: Word;
4640 MaxLives: Byte;
4641 Options: TGameOptions; nPlayers: Byte);
4643 i, nPl: Integer;
4644 begin
4645 g_Game_Free();
4647 e_WriteLog('Starting custom game...', TMsgType.Notify);
4649 g_Game_ClearLoading();
4651 // Íàñòðîéêè èãðû:
4652 gGameSettings.GameType := GT_CUSTOM;
4653 gGameSettings.GameMode := GameMode;
4654 gSwitchGameMode := GameMode;
4655 gGameSettings.TimeLimit := TimeLimit;
4656 gGameSettings.ScoreLimit := ScoreLimit;
4657 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4658 gGameSettings.Options := Options;
4660 gCoopTotalMonstersKilled := 0;
4661 gCoopTotalSecretsFound := 0;
4662 gCoopTotalMonsters := 0;
4663 gCoopTotalSecrets := 0;
4664 gAimLine := False;
4665 gShowMap := False;
4667 gLMSRespawn := LMS_RESPAWN_NONE;
4668 gLMSRespawnTime := 0;
4669 gSpectLatchPID1 := 0;
4670 gSpectLatchPID2 := 0;
4672 g_Game_ExecuteEvent('ongamestart');
4674 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4675 g_Game_SetupScreenSize();
4677 // Ðåæèì íàáëþäàòåëÿ:
4678 if nPlayers = 0 then
4679 begin
4680 gPlayer1 := nil;
4681 gPlayer2 := nil;
4682 end;
4684 nPl := 0;
4685 if nPlayers >= 1 then
4686 begin
4687 // Ñîçäàíèå ïåðâîãî èãðîêà:
4688 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4689 gPlayer1Settings.Color,
4690 gPlayer1Settings.Team, False));
4691 if gPlayer1 = nil then
4692 begin
4693 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4694 Exit;
4695 end;
4697 gPlayer1.Name := gPlayer1Settings.Name;
4698 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4699 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4700 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4701 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4702 Inc(nPl);
4703 end;
4705 if nPlayers >= 2 then
4706 begin
4707 // Ñîçäàíèå âòîðîãî èãðîêà:
4708 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4709 gPlayer2Settings.Color,
4710 gPlayer2Settings.Team, False));
4711 if gPlayer2 = nil then
4712 begin
4713 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4714 Exit;
4715 end;
4717 gPlayer2.Name := gPlayer2Settings.Name;
4718 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4719 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4720 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4721 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4722 Inc(nPl);
4723 end;
4725 // Çàãðóçêà è çàïóñê êàðòû:
4726 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4727 begin
4728 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4729 Exit;
4730 end;
4732 // Íåò òî÷åê ïîÿâëåíèÿ:
4733 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4734 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4735 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4736 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4737 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4738 begin
4739 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4740 Exit;
4741 end;
4743 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4744 g_Player_Init();
4746 // Ñîçäàåì áîòîâ:
4747 for i := nPl+1 to nPlayers do
4748 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4749 end;
4751 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4752 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
4753 Options: TGameOptions; nPlayers: Byte;
4754 IPAddr: LongWord; Port: Word);
4755 begin
4756 g_Game_Free();
4757 g_Net_Slist_ServerClosed();
4759 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4761 g_Game_ClearLoading();
4763 ClearDebugCvars();
4765 // Íàñòðîéêè èãðû:
4766 gGameSettings.GameType := GT_SERVER;
4767 gGameSettings.GameMode := GameMode;
4768 gSwitchGameMode := GameMode;
4769 gGameSettings.TimeLimit := TimeLimit;
4770 gGameSettings.ScoreLimit := ScoreLimit;
4771 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4772 gGameSettings.Options := Options;
4774 gCoopTotalMonstersKilled := 0;
4775 gCoopTotalSecretsFound := 0;
4776 gCoopTotalMonsters := 0;
4777 gCoopTotalSecrets := 0;
4778 gAimLine := False;
4779 gShowMap := False;
4781 gLMSRespawn := LMS_RESPAWN_NONE;
4782 gLMSRespawnTime := 0;
4783 gSpectLatchPID1 := 0;
4784 gSpectLatchPID2 := 0;
4786 g_Game_ExecuteEvent('ongamestart');
4788 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4789 g_Game_SetupScreenSize();
4791 // Ðåæèì íàáëþäàòåëÿ:
4792 if nPlayers = 0 then
4793 begin
4794 gPlayer1 := nil;
4795 gPlayer2 := nil;
4796 end;
4798 if nPlayers >= 1 then
4799 begin
4800 // Ñîçäàíèå ïåðâîãî èãðîêà:
4801 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4802 gPlayer1Settings.Color,
4803 gPlayer1Settings.Team, False));
4804 if gPlayer1 = nil then
4805 begin
4806 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4807 Exit;
4808 end;
4810 gPlayer1.Name := gPlayer1Settings.Name;
4811 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4812 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4813 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4814 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4815 end;
4817 if nPlayers >= 2 then
4818 begin
4819 // Ñîçäàíèå âòîðîãî èãðîêà:
4820 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4821 gPlayer2Settings.Color,
4822 gPlayer2Settings.Team, False));
4823 if gPlayer2 = nil then
4824 begin
4825 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4826 Exit;
4827 end;
4829 gPlayer2.Name := gPlayer2Settings.Name;
4830 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4831 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4832 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4833 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4834 end;
4836 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4837 if NetForwardPorts then
4838 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4840 // Ñòàðòóåì ñåðâåð
4841 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4842 begin
4843 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4844 Exit;
4845 end;
4847 g_Net_Slist_Set(NetMasterList);
4849 g_Net_Slist_ServerStarted();
4851 // Çàãðóçêà è çàïóñê êàðòû:
4852 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4853 begin
4854 g_Net_Slist_ServerClosed();
4855 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4856 Exit;
4857 end;
4859 // Íåò òî÷åê ïîÿâëåíèÿ:
4860 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4861 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4862 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4863 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4864 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4865 begin
4866 g_Net_Slist_ServerClosed();
4867 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4868 Exit;
4869 end;
4871 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4872 g_Player_Init();
4874 g_Net_Slist_ServerMapStarted();
4875 NetState := NET_STATE_GAME;
4876 end;
4878 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4880 Map: String;
4881 WadName: string;
4882 Ptr: Pointer;
4883 T: Cardinal;
4884 MID: Byte;
4885 State: Byte;
4886 OuterLoop: Boolean;
4887 newResPath: string;
4888 InMsg: TMsg;
4889 begin
4890 g_Game_Free();
4892 State := 0;
4893 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4894 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4896 g_Game_ClearLoading();
4898 ClearDebugCvars();
4900 // Íàñòðîéêè èãðû:
4901 gGameSettings.GameType := GT_CLIENT;
4903 gCoopTotalMonstersKilled := 0;
4904 gCoopTotalSecretsFound := 0;
4905 gCoopTotalMonsters := 0;
4906 gCoopTotalSecrets := 0;
4907 gAimLine := False;
4908 gShowMap := False;
4910 g_Game_ExecuteEvent('ongamestart');
4912 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4913 g_Game_SetupScreenSize();
4915 NetState := NET_STATE_AUTH;
4917 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4919 // create (or update) map/resource databases
4920 g_Res_CreateDatabases(true);
4922 gLMSRespawn := LMS_RESPAWN_NONE;
4923 gLMSRespawnTime := 0;
4924 gSpectLatchPID1 := 0;
4925 gSpectLatchPID2 := 0;
4927 // Ñòàðòóåì êëèåíò
4928 if not g_Net_Connect(Addr, Port) then
4929 begin
4930 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4931 NetState := NET_STATE_NONE;
4932 Exit;
4933 end;
4935 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4936 MC_SEND_Info(PW);
4937 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4939 OuterLoop := True;
4940 while OuterLoop do
4941 begin
4942 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4943 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4944 // thank you, enet. let's ignore failures altogether then.
4945 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4946 begin
4947 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4948 begin
4949 Ptr := NetEvent.packet^.data;
4950 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4951 begin
4952 enet_packet_destroy(NetEvent.packet);
4953 continue;
4954 end;
4956 InMsg.ReadLongWord(); // skip size
4957 MID := InMsg.ReadByte();
4959 if (MID = NET_MSG_INFO) and (State = 0) then
4960 begin
4961 NetMyID := InMsg.ReadByte();
4962 NetPlrUID1 := InMsg.ReadWord();
4964 WadName := InMsg.ReadString();
4965 Map := InMsg.ReadString();
4967 gWADHash := InMsg.ReadMD5();
4969 gGameSettings.GameMode := InMsg.ReadByte();
4970 gSwitchGameMode := gGameSettings.GameMode;
4971 gGameSettings.ScoreLimit := InMsg.ReadWord();
4972 gGameSettings.TimeLimit := InMsg.ReadWord();
4973 gGameSettings.MaxLives := InMsg.ReadByte();
4974 gGameSettings.Options := TGameOptions(InMsg.ReadLongWord());
4975 T := InMsg.ReadLongWord();
4977 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4978 //if newResPath = '' then
4979 begin
4980 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4981 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4982 if newResPath = '' then
4983 begin
4984 g_FatalError(_lc[I_NET_ERR_HASH]);
4985 enet_packet_destroy(NetEvent.packet);
4986 NetState := NET_STATE_NONE;
4987 Exit;
4988 end;
4989 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4990 end;
4991 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4994 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4995 gPlayer1Settings.Color,
4996 gPlayer1Settings.Team, False));
4998 if gPlayer1 = nil then
4999 begin
5000 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
5002 enet_packet_destroy(NetEvent.packet);
5003 NetState := NET_STATE_NONE;
5004 Exit;
5005 end;
5007 gPlayer1.Name := gPlayer1Settings.Name;
5008 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
5009 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
5010 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
5011 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
5012 gPlayer1.UID := NetPlrUID1;
5013 gPlayer1.Reset(True);
5015 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
5016 begin
5017 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
5019 enet_packet_destroy(NetEvent.packet);
5020 NetState := NET_STATE_NONE;
5021 Exit;
5022 end;
5024 gTime := T;
5026 State := 1;
5027 OuterLoop := False;
5028 enet_packet_destroy(NetEvent.packet);
5029 break;
5031 else
5032 enet_packet_destroy(NetEvent.packet);
5034 else
5035 begin
5036 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
5037 begin
5038 State := 0;
5039 if (NetEvent.data <= NET_DISC_MAX) then
5040 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
5041 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
5042 OuterLoop := False;
5043 Break;
5044 end;
5045 end;
5046 end;
5048 ProcessLoading(True);
5049 if g_Net_UserRequestExit() then
5050 begin
5051 State := 0;
5052 break;
5053 end;
5054 end;
5056 if State <> 1 then
5057 begin
5058 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
5059 NetState := NET_STATE_NONE;
5060 Exit;
5061 end;
5063 g_Player_Init();
5064 NetState := NET_STATE_GAME;
5065 MC_SEND_FullStateRequest;
5066 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
5067 end;
5070 lastAsMegaWad: Boolean = false;
5072 procedure g_Game_ChangeMap(const MapPath: String);
5074 Force: Boolean;
5075 begin
5076 g_Game_ClearLoading();
5078 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
5079 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5080 if gExitByTrigger then
5081 begin
5082 Force := False;
5083 gExitByTrigger := False;
5084 end;
5085 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
5086 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
5087 end;
5089 procedure g_Game_Restart();
5091 Map: string;
5092 begin
5093 if g_Game_IsClient then
5094 Exit;
5095 map := g_ExtractFileName(gMapInfo.Map);
5096 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
5098 MessageTime := 0;
5099 gGameOn := False;
5100 g_Game_ClearLoading();
5101 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
5102 end;
5104 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
5106 NewWAD, ResName: String;
5107 I: Integer;
5108 nws: AnsiString;
5109 begin
5110 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
5111 g_Player_RemoveAllCorpses();
5113 if (not g_Game_IsClient) and
5114 (gSwitchGameMode <> gGameSettings.GameMode) and
5115 (gGameSettings.GameMode <> GM_SINGLE) then
5116 begin
5117 if gSwitchGameMode = GM_CTF then
5118 gGameSettings.MaxLives := 0;
5119 gGameSettings.GameMode := gSwitchGameMode;
5120 Force := True;
5121 end else
5122 gSwitchGameMode := gGameSettings.GameMode;
5124 g_Player_ResetTeams();
5126 lastAsMegaWad := asMegawad;
5127 if isWadPath(Map) then
5128 begin
5129 NewWAD := g_ExtractWadName(Map);
5130 ResName := g_ExtractFileName(Map);
5131 if g_Game_IsServer then
5132 begin
5133 nws := findDiskWad(NewWAD);
5134 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5135 if (asMegawad) then
5136 begin
5137 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5138 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5140 else
5141 begin
5142 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5143 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5144 end;
5145 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5146 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5147 //nws := NewWAD;
5148 if (length(nws) = 0) then
5149 begin
5150 ResName := ''; // failed
5152 else
5153 begin
5154 NewWAD := nws;
5155 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5156 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5157 g_Game_SetCurrentWAD(NewWAD);
5158 end;
5160 else
5161 begin
5162 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5163 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5164 end;
5166 else
5167 begin
5168 NewWAD := gGameSettings.WAD;
5169 ResName := Map;
5170 end;
5172 gTime := 0;
5174 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5175 result := false;
5176 if (ResName <> '') and (NewWAD <> '') then
5177 begin
5178 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5179 result := g_Map_Load(NewWAD+':\'+ResName);
5180 end;
5181 if Result then
5182 begin
5183 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5185 gState := STATE_NONE;
5186 g_ActiveWindow := nil;
5187 gGameOn := True;
5189 DisableCheats();
5190 ResetTimer();
5192 if gGameSettings.GameMode = GM_CTF then
5193 begin
5194 g_Map_ResetFlag(FLAG_RED);
5195 g_Map_ResetFlag(FLAG_BLUE);
5196 // CTF, à ôëàãîâ íåò:
5197 if not g_Map_HaveFlagPoints() then
5198 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5199 end;
5201 else
5202 begin
5203 gState := STATE_MENU;
5204 gGameOn := False;
5205 end;
5207 gExit := 0;
5208 gPauseMain := false;
5209 gPauseHolmes := false;
5210 NetTimeToUpdate := 1;
5211 NetTimeToReliable := 0;
5212 NetTimeToMaster := NetMasterRate;
5213 gSpectLatchPID1 := 0;
5214 gSpectLatchPID2 := 0;
5215 gMissionFailed := False;
5216 gNextMap := '';
5218 gCoopMonstersKilled := 0;
5219 gCoopSecretsFound := 0;
5221 gVoteInProgress := False;
5222 gVotePassed := False;
5223 gVoteCount := 0;
5224 gVoted := False;
5226 gStatsOff := False;
5228 if not gGameOn then Exit;
5230 g_Game_SpectateCenterView();
5232 if g_Game_IsServer then
5233 begin
5234 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5235 begin
5236 gLMSRespawn := LMS_RESPAWN_WARMUP;
5237 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5238 gLMSSoftSpawn := True;
5239 if g_Game_IsNet then
5240 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5242 else
5243 begin
5244 gLMSRespawn := LMS_RESPAWN_NONE;
5245 gLMSRespawnTime := 0;
5246 end;
5247 end;
5249 if NetMode = NET_SERVER then
5250 begin
5251 // reset full state flags
5252 if NetClients <> nil then
5253 for I := 0 to High(NetClients) do
5254 NetClients[I].FullUpdateSent := False;
5256 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5258 // Ìàñòåðñåðâåð
5259 g_Net_Slist_ServerMapStarted();
5261 if NetClients <> nil then
5262 for I := 0 to High(NetClients) do
5263 if NetClients[I].Used then
5264 begin
5265 NetClients[I].Voted := False;
5266 if NetClients[I].RequestedFullUpdate then
5267 begin
5268 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5269 NetClients[I].RequestedFullUpdate := False;
5270 end;
5271 end;
5273 g_Net_UnbanNonPerm();
5274 end;
5276 if gLastMap then
5277 begin
5278 gCoopTotalMonstersKilled := 0;
5279 gCoopTotalSecretsFound := 0;
5280 gCoopTotalMonsters := 0;
5281 gCoopTotalSecrets := 0;
5282 gLastMap := False;
5283 end;
5285 g_Game_ExecuteEvent('onmapstart');
5286 end;
5288 procedure g_Game_ExitLevel(const Map: AnsiString);
5289 begin
5290 gNextMap := Map;
5292 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5293 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5294 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5295 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5297 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5298 if gGameSettings.GameType = GT_SINGLE then
5299 gExit := EXIT_ENDLEVELSINGLE
5300 else // Âûøëè â âûõîä â Ñâîåé èãðå
5301 begin
5302 gExit := EXIT_ENDLEVELCUSTOM;
5303 if gGameSettings.GameMode = GM_COOP then
5304 g_Player_RememberAll;
5306 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5307 begin
5308 gLastMap := True;
5309 if gGameSettings.GameMode = GM_COOP then
5310 gStatsOff := True;
5312 gStatsPressed := True;
5313 gNextMap := 'MAP01';
5315 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5316 g_Game_NextLevel;
5318 if g_Game_IsNet then
5319 begin
5320 MH_SEND_GameStats();
5321 MH_SEND_CoopStats();
5322 end;
5323 end;
5324 end;
5325 end;
5327 procedure g_Game_RestartLevel();
5329 Map: string;
5330 begin
5331 if gGameSettings.GameMode = GM_SINGLE then
5332 begin
5333 g_Game_Restart();
5334 Exit;
5335 end;
5336 gExit := EXIT_ENDLEVELCUSTOM;
5337 Map := g_ExtractFileName(gMapInfo.Map);
5338 gNextMap := Map;
5339 end;
5341 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5343 gWAD{, xwad}: String;
5344 begin
5345 result := NewWAD;
5346 if not g_Game_IsClient then Exit;
5347 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5349 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5350 if gWAD = '' then
5351 begin
5352 result := '';
5353 g_Game_Free();
5354 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5355 Exit;
5356 end;
5358 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5359 NewWAD := gWAD;
5361 g_Game_SetCurrentWAD(NewWAD);
5362 result := NewWAD;
5365 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5366 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5367 if gWAD = '' then
5368 begin
5369 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5370 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5371 if gWAD = '' then
5372 begin
5373 g_Game_Free();
5374 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5375 Exit;
5376 end;
5377 end;
5378 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5379 g_Game_SetCurrentWAD(NewWAD);
5381 end;
5383 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5385 i, n, nb, nr: Integer;
5386 begin
5387 if not g_Game_IsServer then Exit;
5388 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5389 gLMSRespawn := LMS_RESPAWN_NONE;
5390 gLMSRespawnTime := 0;
5391 MessageTime := 0;
5393 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5394 begin
5395 gMissionFailed := True;
5396 g_Game_RestartLevel;
5397 Exit;
5398 end;
5400 n := 0; nb := 0; nr := 0;
5401 for i := Low(gPlayers) to High(gPlayers) do
5402 if (gPlayers[i] <> nil) and
5403 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5404 (gPlayers[i] is TBot)) then
5405 begin
5406 Inc(n);
5407 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5408 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5409 end;
5411 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5412 begin
5413 // wait a second until the fuckers finally decide to join
5414 gLMSRespawn := LMS_RESPAWN_WARMUP;
5415 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5416 gLMSSoftSpawn := NoMapRestart;
5417 if g_Game_IsNet then
5418 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5419 Exit;
5420 end;
5422 g_Player_RemoveAllCorpses;
5423 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5424 if g_Game_IsNet then
5425 MH_SEND_GameEvent(NET_EV_LMS_START);
5427 for i := Low(gPlayers) to High(gPlayers) do
5428 begin
5429 if gPlayers[i] = nil then continue;
5430 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5431 // don't touch normal spectators
5432 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5433 begin
5434 gPlayers[i].FNoRespawn := True;
5435 gPlayers[i].Lives := 0;
5436 if g_Game_IsNet then
5437 MH_SEND_PlayerStats(gPlayers[I].UID);
5438 continue;
5439 end;
5440 gPlayers[i].FNoRespawn := False;
5441 gPlayers[i].Lives := gGameSettings.MaxLives;
5442 gPlayers[i].Respawn(False, True);
5443 if gGameSettings.GameMode = GM_COOP then
5444 begin
5445 gPlayers[i].Frags := 0;
5446 gPlayers[i].RestoreState;
5447 end;
5448 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5449 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5450 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5451 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5452 end;
5454 g_Items_RestartRound();
5456 gLMSSoftSpawn := False;
5457 end;
5459 function g_Game_GetFirstMap(WAD: String): String;
5461 MapList: SSArray;
5462 begin
5463 Result := '';
5465 MapList := g_Map_GetMapsList(WAD);
5466 if MapList = nil then
5467 Exit;
5469 // TODO: Replace with simple minimum lookup.
5470 specialize TArrayHelper<ShortString>.Sort(MapList,
5471 specialize TComparer<ShortString>.Construct(@ShortCompareText));
5472 Result := MapList[Low(MapList)];
5474 // BD: why should we check for a map we just found?
5475 // just to guarantee its presence at the archive root? but nobody does the opposite anyway.
5476 //if not g_Map_Exist(WAD + ':\' + Result) then
5477 // Result := '';
5478 end;
5480 function g_Game_GetNextMap(): String;
5482 I: Integer;
5483 Map: String;
5484 MapList: SSArray;
5485 begin
5486 Result := '';
5488 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5489 if MapList = nil then
5490 Exit;
5492 Map := g_ExtractFileName(gMapInfo.Map);
5493 specialize TArrayHelper<ShortString>.Sort(MapList,
5494 specialize TComparer<ShortString>.Construct(@ShortCompareText));
5496 MapIndex := -255;
5497 for I := Low(MapList) to High(MapList) do
5498 if Map = MapList[I] then
5499 begin
5500 MapIndex := I;
5501 Break;
5502 end;
5504 if MapIndex <> -255 then
5505 begin
5506 if MapIndex = High(MapList)
5507 then Result := MapList[Low(MapList)]
5508 else Result := MapList[MapIndex + 1];
5510 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5511 end;
5512 end;
5514 procedure g_Game_NextLevel();
5515 begin
5516 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5517 gExit := EXIT_ENDLEVELCUSTOM
5518 else
5519 begin
5520 gExit := EXIT_ENDLEVELSINGLE;
5521 Exit;
5522 end;
5524 if gNextMap <> '' then Exit;
5525 gNextMap := g_Game_GetNextMap();
5526 end;
5528 function g_Game_IsTestMap(): Boolean;
5529 begin
5530 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5531 end;
5533 procedure g_Game_DeleteTestMap();
5535 a: Integer;
5536 //MapName: AnsiString;
5537 WadName: string;
5539 WAD: TWADFile;
5540 MapList: SSArray;
5541 time: Integer;
5543 begin
5544 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5545 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5546 if (a = 0) then exit;
5548 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5549 WadName := Copy(gMapToDelete, 1, a+3);
5550 Delete(gMapToDelete, 1, a+5);
5551 gMapToDelete := UpperCase(gMapToDelete);
5552 //MapName := '';
5553 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5556 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5557 if MapName <> TEST_MAP_NAME then
5558 Exit;
5560 if not gTempDelete then
5561 begin
5562 time := g_GetFileTime(WadName);
5563 WAD := TWADFile.Create();
5565 // ×èòàåì Wad-ôàéë:
5566 if not WAD.ReadFile(WadName) then
5567 begin // Íåò òàêîãî WAD-ôàéëà
5568 WAD.Free();
5569 Exit;
5570 end;
5572 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5573 WAD.CreateImage();
5574 MapList := WAD.GetResourcesList('');
5576 if MapList <> nil then
5577 for a := 0 to High(MapList) do
5578 if MapList[a] = MapName then
5579 begin
5580 // Óäàëÿåì è ñîõðàíÿåì:
5581 WAD.RemoveResource('', MapName);
5582 WAD.SaveTo(WadName);
5583 Break;
5584 end;
5586 WAD.Free();
5587 g_SetFileTime(WadName, time);
5588 end else
5590 if gTempDelete then DeleteFile(WadName);
5591 end;
5593 procedure GameCVars(P: SSArray);
5595 a, b: Integer;
5596 stat: TPlayerStatArray;
5597 cmd: string;
5598 it: PItem;
5600 procedure ParseGameFlag(Flag: TGameOption; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5602 x: Boolean;
5603 begin
5604 if Length(P) <= 1 then
5605 x := Flag in gsGameFlags
5606 else
5607 begin
5608 x := P[1] = '1';
5610 if x
5611 then gsGameFlags += [Flag]
5612 else gsGameFlags -= [Flag];
5614 if g_Game_IsServer then
5615 begin
5616 if x
5617 then gGameSettings.Options += [Flag]
5618 else gGameSettings.Options -= [Flag];
5619 if g_Game_IsNet then MH_SEND_GameSettings;
5620 end;
5621 end;
5623 if x
5624 then g_Console_Add(_lc[OnMsg])
5625 else g_Console_Add(_lc[OffMsg]);
5627 if OnMapChange and g_Game_IsServer then
5628 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5629 end;
5631 begin
5632 stat := nil;
5633 cmd := LowerCase(P[0]);
5635 case cmd of
5636 'g_gamemode': begin
5637 if (Length(P) > 1) then
5638 begin
5639 a := g_Game_TextToMode(P[1]);
5640 if a = GM_SINGLE then a := GM_COOP;
5641 gsGameMode := g_Game_ModeToText(a);
5642 if g_Game_IsServer then
5643 begin
5644 gSwitchGameMode := a;
5645 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5646 (gState = STATE_INTERSINGLE) then
5647 gSwitchGameMode := GM_SINGLE;
5648 if not gGameOn then
5649 gGameSettings.GameMode := gSwitchGameMode;
5650 end;
5651 end;
5653 if gSwitchGameMode = gGameSettings.GameMode then
5654 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5655 [g_Game_ModeToText(gGameSettings.GameMode)]))
5656 else
5657 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5658 [g_Game_ModeToText(gGameSettings.GameMode),
5659 g_Game_ModeToText(gSwitchGameMode)]));
5660 end;
5662 'g_friendlyfire':
5663 ParseGameFlag(TGameOption.TEAM_DAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5664 'g_friendly_absorb_damage':
5665 ParseGameFlag(TGameOption.TEAM_ABSORB_DAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5666 'g_friendly_hit_trace':
5667 ParseGameFlag(TGameOption.TEAM_HIT_TRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5668 'g_friendly_hit_projectile':
5669 ParseGameFlag(TGameOption.TEAM_HIT_PROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5670 'g_items_all_respawn_random':
5671 ParseGameFlag(TGameOption.ITEM_ALL_RANDOM, I_MSG_ITEM_ALL_RANDOM_OFF, I_MSG_ITEM_ALL_RANDOM_ON, False);
5672 'g_items_help_respawn_random':
5673 ParseGameFlag(TGameOption.ITEM_LIFE_RANDOM, I_MSG_ITEM_LIFE_RANDOM_OFF, I_MSG_ITEM_LIFE_RANDOM_ON, False);
5674 'g_items_ammo_respawn_random':
5675 ParseGameFlag(TGameOption.ITEM_AMMO_RANDOM, I_MSG_ITEM_AMMO_RANDOM_OFF, I_MSG_ITEM_AMMO_RANDOM_ON, False);
5676 'g_items_weapon_respawn_random':
5677 ParseGameFlag(TGameOption.ITEM_WEAPON_RANDOM, I_MSG_ITEM_WEAPON_RANDOM_OFF, I_MSG_ITEM_WEAPON_RANDOM_ON);
5678 'g_powerup_randomize_respawn':
5679 ParseGameFlag(TGameOption.POWERUP_RANDOM, I_MSG_POWERUP_RANDOM_OFF, I_MSG_POWERUP_RANDOM_ON, False);
5680 'g_weaponstay':
5681 ParseGameFlag(TGameOption.WEAPONS_STAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5682 'g_allow_exit':
5683 ParseGameFlag(TGameOption.ALLOW_EXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5684 'g_allow_monsters':
5685 ParseGameFlag(TGameOption.MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5686 'g_allow_dropflag':
5687 ParseGameFlag(TGameOption.ALLOW_DROP_FLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
5688 'g_throw_flag':
5689 ParseGameFlag(TGameOption.THROW_FLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
5690 'g_bot_vsplayers':
5691 ParseGameFlag(TGameOption.BOTS_VS_PLAYERS, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5692 'g_bot_vsmonsters':
5693 ParseGameFlag(TGameOption.BOTS_VS_MONSTERS, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5694 'g_dm_keys':
5695 ParseGameFlag(TGameOption.DM_KEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5697 'g_gameflags': begin
5698 if Length(P) > 1 then
5699 begin
5700 gsGameFlags := TGameOptions(StrToDWordDef(P[1], LongWord(gsGameFlags)));
5701 if g_Game_IsServer then
5702 begin
5703 gGameSettings.Options := gsGameFlags;
5704 if g_Game_IsNet then MH_SEND_GameSettings;
5705 end;
5706 end;
5708 g_Console_Add(Format('%s %u', [cmd, LongWord(gsGameFlags)]));
5709 end;
5711 'g_warmup_time': begin
5712 if Length(P) > 1 then
5713 begin
5714 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5715 if g_Game_IsServer then
5716 begin
5717 gGameSettings.WarmupTime := gsWarmupTime;
5718 // extend warmup if it's already going
5719 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5720 begin
5721 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5722 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5723 end;
5724 if g_Game_IsNet then MH_SEND_GameSettings;
5725 end;
5726 end;
5728 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5729 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5730 end;
5732 'g_spawn_invul': begin
5733 if Length(P) > 1 then
5734 begin
5735 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5736 if g_Game_IsServer then
5737 begin
5738 gGameSettings.SpawnInvul := gsSpawnInvul;
5739 if g_Game_IsNet then MH_SEND_GameSettings;
5740 end;
5741 end;
5743 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5744 end;
5746 'g_item_respawn_time': begin
5747 if Length(P) > 1 then
5748 begin
5749 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5750 if g_Game_IsServer then
5751 begin
5752 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5753 if g_Game_IsNet then MH_SEND_GameSettings;
5754 end;
5755 end;
5757 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5758 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5759 end;
5761 'g_item_time_random': begin
5762 if Length(P) > 1 then
5763 begin
5764 gsItemRespawnRandom := nclamp(StrToIntDef(P[1], gsItemRespawnRandom), 0, $FFFF);
5765 if g_Game_IsServer then
5766 begin
5767 gGameSettings.ItemRespawnRandom := gsItemRespawnRandom;
5768 if g_Game_IsNet then MH_SEND_GameSettings;
5769 end;
5770 end;
5772 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnRandom)]));
5773 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5774 end;
5776 'g_powerup_respawn_time': begin
5777 if Length(P) > 1 then
5778 begin
5779 gsPowerupRespawnTime := nclamp(StrToIntDef(P[1], gsPowerupRespawnTime), 0, $FFFF);
5780 if g_Game_IsServer then
5781 begin
5782 gGameSettings.PowerupRespawnTime := gsPowerupRespawnTime;
5783 if g_Game_IsNet then MH_SEND_GameSettings;
5784 end;
5785 end;
5787 g_Console_Add(Format('%s %d', [cmd, Integer(gsPowerupRespawnTime)]));
5788 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5789 end;
5791 'g_powerup_time_random': begin
5792 if Length(P) > 1 then
5793 begin
5794 gsPowerupRespawnRandom := nclamp(StrToIntDef(P[1], gsPowerupRespawnRandom), 0, $FFFF);
5795 if g_Game_IsServer then
5796 begin
5797 gGameSettings.PowerupRespawnRandom := gsPowerupRespawnRandom;
5798 if g_Game_IsNet then MH_SEND_GameSettings;
5799 end;
5800 end;
5802 g_Console_Add(Format('%s %d', [cmd, Integer(gsPowerupRespawnRandom)]));
5803 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5804 end;
5806 'sv_intertime': begin
5807 if (Length(P) > 1) then
5808 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5810 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5811 end;
5813 'g_max_particles': begin
5814 if Length(p) = 2 then
5815 begin
5816 a := Max(0, StrToIntDef(p[1], 0));
5817 g_GFX_SetMax(a)
5819 else if Length(p) = 1 then
5820 begin
5821 e_LogWritefln('%s', [g_GFX_GetMax()])
5823 else
5824 begin
5825 e_LogWritefln('usage: %s <n>', [cmd])
5827 end;
5829 'g_max_shells': begin
5830 if Length(p) = 2 then
5831 begin
5832 a := Max(0, StrToIntDef(p[1], 0));
5833 g_Shells_SetMax(a)
5835 else if Length(p) = 1 then
5836 begin
5837 e_LogWritefln('%s', [g_Shells_GetMax()])
5839 else
5840 begin
5841 e_LogWritefln('usage: %s <n>', [cmd])
5843 end;
5845 'g_max_gibs': begin
5846 if Length(p) = 2 then
5847 begin
5848 a := Max(0, StrToIntDef(p[1], 0));
5849 g_Gibs_SetMax(a)
5851 else if Length(p) = 1 then
5852 begin
5853 e_LogWritefln('%s', [g_Gibs_GetMax()])
5855 else
5856 begin
5857 e_LogWritefln('usage: %s <n>', [cmd])
5859 end;
5861 'g_max_corpses': begin
5862 if Length(p) = 2 then
5863 begin
5864 a := Max(0, StrToIntDef(p[1], 0));
5865 g_Corpses_SetMax(a)
5867 else if Length(p) = 1 then
5868 begin
5869 e_LogWritefln('%s', [g_Corpses_GetMax()])
5871 else
5872 begin
5873 e_LogWritefln('usage: %s <n>', [cmd])
5875 end;
5877 'g_force_model': begin
5878 if Length(p) = 2 then
5879 begin
5880 a := StrToIntDef(p[1], 0);
5881 g_Force_Model_Set(a);
5882 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5883 begin
5884 for a := Low(gPlayers) to High(gPlayers) do
5885 begin
5886 if (gPlayers[a] <> nil) then
5887 begin
5888 if (gPlayers[a].UID = gPlayer1.UID) then
5889 continue
5890 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5891 continue;
5892 gPlayers[a].setModel(g_Forced_Model_GetName());
5893 end;
5896 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
5897 begin
5898 for a := Low(gPlayers) to High(gPlayers) do
5899 begin
5900 if (gPlayers[a] <> nil) then
5901 begin
5902 if (gPlayers[a].UID = gPlayer1.UID) then
5903 continue
5904 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5905 continue;
5906 gPlayers[a].setModel(gPlayers[a].FActualModelName);
5907 end;
5911 end;
5913 'g_force_model_name': begin
5914 if (Length(P) > 1) then
5915 begin
5916 cmd := b_Text_Unformat(P[1]);
5917 g_Forced_Model_SetName(cmd);
5918 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5919 begin
5920 for a := Low(gPlayers) to High(gPlayers) do
5921 begin
5922 if (gPlayers[a] <> nil) then
5923 begin
5924 if (gPlayers[a].UID = gPlayer1.UID) then
5925 continue
5926 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5927 continue;
5928 gPlayers[a].setModel(g_Forced_Model_GetName());
5929 end;
5933 end;
5935 'g_scorelimit': begin
5936 if Length(P) > 1 then
5937 begin
5938 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
5940 if g_Game_IsServer then
5941 begin
5942 b := 0;
5943 if gGameSettings.GameMode = GM_DM then
5944 begin // DM
5945 stat := g_Player_GetStats();
5946 if stat <> nil then
5947 for a := 0 to High(stat) do
5948 if stat[a].Frags > b then
5949 b := stat[a].Frags;
5951 else // TDM/CTF
5952 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
5954 // if someone has a higher score, set it to that instead
5955 gsScoreLimit := max(gsScoreLimit, b);
5956 gGameSettings.ScoreLimit := gsScoreLimit;
5958 if g_Game_IsNet then MH_SEND_GameSettings;
5959 end;
5960 end;
5962 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
5963 end;
5965 'g_timelimit': begin
5966 if Length(P) > 1 then
5967 begin
5968 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5969 if g_Game_IsServer then
5970 begin
5971 gGameSettings.TimeLimit := gsTimeLimit;
5972 if g_Game_IsNet then MH_SEND_GameSettings;
5973 end;
5974 end;
5975 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5976 [gsTimeLimit div 3600,
5977 (gsTimeLimit div 60) mod 60,
5978 gsTimeLimit mod 60]));
5979 end;
5981 'g_max_bots': begin
5982 if Length(P) > 1 then
5983 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
5984 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
5985 end;
5987 'g_maxlives': begin
5988 if Length(P) > 1 then
5989 begin
5990 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5991 if g_Game_IsServer then
5992 begin
5993 gGameSettings.MaxLives := gsMaxLives;
5994 if g_Game_IsNet then MH_SEND_GameSettings;
5995 end;
5996 end;
5998 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5999 end;
6000 end;
6001 end;
6003 procedure PlayerSettingsCVars(P: SSArray);
6005 cmd: string;
6006 team: Byte;
6008 function ParseTeam(s: string): Byte;
6009 begin
6010 result := 0;
6011 case s of
6012 'red', '1': result := TEAM_RED;
6013 'blue', '2': result := TEAM_BLUE;
6014 else result := TEAM_NONE;
6015 end;
6016 end;
6017 begin
6018 cmd := LowerCase(P[0]);
6019 case cmd of
6020 'p1_name':
6021 begin
6022 if (Length(P) > 1) then
6023 begin
6024 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
6025 if g_Game_IsClient then
6026 MC_SEND_PlayerSettings
6027 else if gGameOn and (gPlayer1 <> nil) then
6028 begin
6029 gPlayer1.Name := b_Text_Unformat(P[1]);
6030 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6031 end;
6032 end;
6033 end;
6034 'p2_name':
6035 begin
6036 if (Length(P) > 1) then
6037 begin
6038 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
6039 if g_Game_IsClient then
6040 MC_SEND_PlayerSettings
6041 else if gGameOn and (gPlayer2 <> nil) then
6042 begin
6043 gPlayer2.Name := b_Text_Unformat(P[1]);
6044 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6045 end;
6046 end;
6047 end;
6048 'p1_color':
6049 begin
6050 if Length(P) > 3 then
6051 begin
6052 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6053 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6054 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6055 if g_Game_IsClient then
6056 MC_SEND_PlayerSettings
6057 else if gGameOn and (gPlayer1 <> nil) then
6058 begin
6059 gPlayer1.SetColor(gPlayer1Settings.Color);
6060 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6061 end;
6062 end;
6063 end;
6064 'p2_color':
6065 begin
6066 if Length(P) > 3 then
6067 begin
6068 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6069 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6070 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6071 if g_Game_IsClient then
6072 MC_SEND_PlayerSettings
6073 else if gGameOn and (gPlayer2 <> nil) then
6074 begin
6075 gPlayer2.SetColor(gPlayer2Settings.Color);
6076 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6077 end;
6078 end;
6079 end;
6080 'p1_model':
6081 begin
6082 if (Length(P) > 1) then
6083 begin
6084 gPlayer1Settings.Model := P[1];
6085 if g_Game_IsClient then
6086 MC_SEND_PlayerSettings
6087 else if gGameOn and (gPlayer1 <> nil) then
6088 begin
6089 gPlayer1.FActualModelName := gPlayer1Settings.Model;
6090 gPlayer1.SetModel(gPlayer1Settings.Model);
6091 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6092 end;
6093 end;
6094 end;
6095 'p2_model':
6096 begin
6097 if (Length(P) > 1) then
6098 begin
6099 gPlayer2Settings.Model := P[1];
6100 if g_Game_IsClient then
6101 MC_SEND_PlayerSettings
6102 else if gGameOn and (gPlayer2 <> nil) then
6103 begin
6104 gPlayer2.FActualModelName := gPlayer2Settings.Model;
6105 gPlayer2.SetModel(gPlayer2Settings.Model);
6106 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6107 end;
6108 end;
6109 end;
6110 'p1_team':
6111 begin
6112 // TODO: switch teams if in game or store this separately
6113 if (Length(P) > 1) then
6114 begin
6115 team := ParseTeam(P[1]);
6116 if team = TEAM_NONE then
6117 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6118 else if not gGameOn and not g_Game_IsNet then
6119 gPlayer1Settings.Team := team
6120 else
6121 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6122 end;
6123 end;
6124 'p2_team':
6125 begin
6126 // TODO: switch teams if in game or store this separately
6127 if (Length(P) > 1) then
6128 begin
6129 team := ParseTeam(P[1]);
6130 if team = TEAM_NONE then
6131 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6132 else if not gGameOn and not g_Game_IsNet then
6133 gPlayer2Settings.Team := team
6134 else
6135 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6136 end;
6137 end;
6138 'p1_autoswitch':
6139 begin
6140 if (Length(P) = 2) then
6141 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6142 end;
6143 'p2_autoswitch':
6144 begin
6145 if (Length(P) = 2) then
6146 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6147 end;
6148 'p1_switch_empty':
6149 begin
6150 if (Length(P) = 2) then
6151 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6152 end;
6153 'p2_switch_empty':
6154 begin
6155 if (Length(P) = 2) then
6156 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6157 end;
6158 'p1_skip_ironfist':
6159 begin
6160 if (Length(P) = 2) then
6161 gPlayer1Settings.SkipIronFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6162 end;
6163 'p2_skip_ironfist':
6164 begin
6165 if (Length(P) = 2) then
6166 gPlayer2Settings.SkipIronFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6167 end;
6168 'p1_priority_ironfist':
6169 begin
6170 if (Length(P) = 2) then
6171 gPlayer1Settings.WeaponPreferences[WEAPON_IRONFIST] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6172 end;
6173 'p2_priority_ironfist':
6174 begin
6175 if (Length(P) = 2) then
6176 gPlayer2Settings.WeaponPreferences[WEAPON_IRONFIST] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6177 end;
6178 'p1_priority_saw':
6179 begin
6180 if (Length(P) = 2) then
6181 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6182 end;
6183 'p2_priority_saw':
6184 begin
6185 if (Length(P) = 2) then
6186 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6187 end;
6188 'p1_priority_pistol':
6189 begin
6190 if (Length(P) = 2) then
6191 gPlayer1Settings.WeaponPreferences[WEAPON_PISTOL] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6192 end;
6193 'p2_priority_pistol':
6194 begin
6195 if (Length(P) = 2) then
6196 gPlayer2Settings.WeaponPreferences[WEAPON_PISTOL] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6197 end;
6198 'p1_priority_shotgun1':
6199 begin
6200 if (Length(P) = 2) then
6201 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6202 end;
6203 'p2_priority_shotgun1':
6204 begin
6205 if (Length(P) = 2) then
6206 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6207 end;
6208 'p1_priority_shotgun2':
6209 begin
6210 if (Length(P) = 2) then
6211 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6212 end;
6213 'p2_priority_shotgun2':
6214 begin
6215 if (Length(P) = 2) then
6216 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6217 end;
6218 'p1_priority_chaingun':
6219 begin
6220 if (Length(P) = 2) then
6221 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6222 end;
6223 'p2_priority_chaingun':
6224 begin
6225 if (Length(P) = 2) then
6226 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6227 end;
6228 'p1_priority_rocketlauncher':
6229 begin
6230 if (Length(P) = 2) then
6231 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6232 end;
6233 'p2_priority_rocketlauncher':
6234 begin
6235 if (Length(P) = 2) then
6236 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6237 end;
6238 'p1_priority_plasma':
6239 begin
6240 if (Length(P) = 2) then
6241 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6242 end;
6243 'p2_priority_plasma':
6244 begin
6245 if (Length(P) = 2) then
6246 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6247 end;
6248 'p1_priority_bfg':
6249 begin
6250 if (Length(P) = 2) then
6251 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6252 end;
6253 'p2_priority_bfg':
6254 begin
6255 if (Length(P) = 2) then
6256 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6257 end;
6258 'p1_priority_superchaingun':
6259 begin
6260 if (Length(P) = 2) then
6261 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERCHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6262 end;
6263 'p2_priority_superchaingun':
6264 begin
6265 if (Length(P) = 2) then
6266 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERCHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6267 end;
6268 'p1_priority_flamethrower':
6269 begin
6270 if (Length(P) = 2) then
6271 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6272 end;
6273 'p2_priority_flamethrower':
6274 begin
6275 if (Length(P) = 2) then
6276 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6277 end;
6278 'p1_priority_berserk':
6279 begin
6280 if (Length(P) = 2) then
6281 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6282 end;
6283 'p2_priority_berserk':
6284 begin
6285 if (Length(P) = 2) then
6286 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6287 end;
6288 end;
6289 end;
6291 procedure PrintHeapStats();
6293 hs: TFPCHeapStatus;
6294 begin
6295 hs := GetFPCHeapStatus();
6296 e_LogWriteLn ('v===== heap status =====v');
6297 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
6298 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
6299 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
6300 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
6301 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
6302 e_LogWriteLn ('^=======================^');
6303 end;
6305 procedure DebugCommands(P: SSArray);
6307 a, b: Integer;
6308 cmd: string;
6309 //pt: TDFPoint;
6310 mon: TMonster;
6311 begin
6312 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6313 if {gDebugMode}conIsCheatsEnabled then
6314 begin
6315 cmd := LowerCase(P[0]);
6316 if cmd = 'd_window' then
6317 begin
6318 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6319 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
6321 else if cmd = 'd_sounds' then
6322 begin
6323 if (Length(P) > 1) and
6324 ((P[1] = '1') or (P[1] = '0')) then
6325 g_Debug_Sounds := (P[1][1] = '1');
6327 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
6329 else if cmd = 'd_frames' then
6330 begin
6331 if (Length(P) > 1) and
6332 ((P[1] = '1') or (P[1] = '0')) then
6333 g_Debug_Frames := (P[1][1] = '1');
6335 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
6337 else if cmd = 'd_winmsg' then
6338 begin
6339 if (Length(P) > 1) and
6340 ((P[1] = '1') or (P[1] = '0')) then
6341 g_Debug_WinMsgs := (P[1][1] = '1');
6343 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
6345 else if (cmd = 'd_monoff') and not g_Game_IsNet then
6346 begin
6347 if (Length(P) > 1) and
6348 ((P[1] = '1') or (P[1] = '0')) then
6349 g_Debug_MonsterOff := (P[1][1] = '1');
6351 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
6353 else if (cmd = 'd_botoff') and not g_Game_IsNet then
6354 begin
6355 if Length(P) > 1 then
6356 case P[1][1] of
6357 '0': g_debug_BotAIOff := 0;
6358 '1': g_debug_BotAIOff := 1;
6359 '2': g_debug_BotAIOff := 2;
6360 '3': g_debug_BotAIOff := 3;
6361 end;
6363 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
6365 else if cmd = 'd_monster' then
6366 begin
6367 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
6368 if Length(P) < 2 then
6369 begin
6370 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
6371 g_Console_Add('ID | Name');
6372 for b := MONSTER_DEMON to MONSTER_MAN do
6373 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
6374 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6375 end else
6376 begin
6377 a := StrToIntDef(P[1], 0);
6378 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6379 a := g_Mons_TypeIdByName(P[1]);
6381 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6382 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
6383 else
6384 begin
6385 with gPlayer1.Obj do
6386 begin
6387 mon := g_Monsters_Create(a,
6388 X + Rect.X + (Rect.Width div 2),
6389 Y + Rect.Y + Rect.Height,
6390 gPlayer1.Direction, True);
6391 end;
6392 if (Length(P) > 2) and (mon <> nil) then
6393 begin
6394 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
6395 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
6396 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
6397 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
6398 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
6399 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6400 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6401 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6402 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6403 end;
6404 end;
6405 end;
6407 else if (cmd = 'd_health') then
6408 begin
6409 if (Length(P) > 1) and
6410 ((P[1] = '1') or (P[1] = '0')) then
6411 g_debug_HealthBar := (P[1][1] = '1');
6413 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6415 else if (cmd = 'd_player') then
6416 begin
6417 if (Length(P) > 1) and
6418 ((P[1] = '1') or (P[1] = '0')) then
6419 g_debug_Player := (P[1][1] = '1');
6421 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6423 else if (cmd = 'd_mem') then
6424 begin
6425 PrintHeapStats();
6426 end;
6428 else
6429 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6430 end;
6433 procedure GameCheats(P: SSArray);
6435 cmd: string;
6436 f, a: Integer;
6437 plr: TPlayer;
6438 begin
6439 if (not gGameOn) or (not conIsCheatsEnabled) then
6440 begin
6441 g_Console_Add('not available');
6442 exit;
6443 end;
6444 plr := gPlayer1;
6445 if plr = nil then
6446 begin
6447 g_Console_Add('where is the player?!');
6448 exit;
6449 end;
6450 cmd := LowerCase(P[0]);
6451 // god
6452 if cmd = 'god' then
6453 begin
6454 plr.GodMode := not plr.GodMode;
6455 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6456 exit;
6457 end;
6458 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6459 if cmd = 'give' then
6460 begin
6461 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6462 for f := 1 to High(P) do
6463 begin
6464 cmd := LowerCase(P[f]);
6465 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6466 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.TankRamboCheats(False); g_Console_Add('player got the gifts'); continue; end;
6467 if cmd = 'exit' then
6468 begin
6469 if gTriggers <> nil then
6470 begin
6471 for a := 0 to High(gTriggers) do
6472 begin
6473 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6474 begin
6475 g_Console_Add('player left the map');
6476 gExitByTrigger := True;
6477 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6478 g_Game_ExitLevel(gTriggers[a].tgcMap);
6479 break;
6480 end;
6481 end;
6482 end;
6483 continue;
6484 end;
6486 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6487 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6488 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6489 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6490 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6492 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6493 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6495 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6496 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;
6498 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6499 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6501 if (cmd = 'soulsphere') or (cmd = 'soul') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a soul sphere'); continue; end;
6502 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a megasphere'); continue; end;
6504 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6505 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6507 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6508 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6509 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6511 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6512 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6513 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6514 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;
6515 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6516 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6518 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;
6519 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;
6520 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;
6521 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;
6522 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;
6523 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;
6525 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERCHAINGUN); g_Console_Add('player got a superchaingun'); continue; end;
6526 if cmd = 'superchaingunzz' then begin plr.GiveItem(ITEM_WEAPON_SUPERCHAINGUN); plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a superchaingun'); continue; end;
6528 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;
6529 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;
6531 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6533 if cmd = 'ammo' then
6534 begin
6535 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6536 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6537 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6538 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6539 plr.GiveItem(ITEM_AMMO_FUELCAN);
6540 g_Console_Add('player got some ammo');
6541 continue;
6542 end;
6544 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6545 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6547 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6548 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6550 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6551 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6553 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6554 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6556 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6558 if cmd = 'weapons' then
6559 begin
6560 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6561 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6562 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6563 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6564 plr.GiveItem(ITEM_WEAPON_PLASMA);
6565 plr.GiveItem(ITEM_WEAPON_BFG);
6566 g_Console_Add('player got weapons');
6567 continue;
6568 end;
6570 if cmd = 'keys' then
6571 begin
6572 plr.GiveItem(ITEM_KEY_RED);
6573 plr.GiveItem(ITEM_KEY_GREEN);
6574 plr.GiveItem(ITEM_KEY_BLUE);
6575 g_Console_Add('player got all keys');
6576 continue;
6577 end;
6579 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6580 end;
6581 exit;
6582 end;
6583 // open
6584 if cmd = 'open' then
6585 begin
6586 g_Console_Add('player activated sesame');
6587 g_Triggers_OpenAll();
6588 exit;
6589 end;
6590 // fly
6591 if cmd = 'fly' then
6592 begin
6593 gFly := not gFly;
6594 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6595 exit;
6596 end;
6597 // noclip
6598 if cmd = 'noclip' then
6599 begin
6600 plr.SwitchNoClip;
6601 g_Console_Add('wall hardeness adjusted');
6602 exit;
6603 end;
6604 // notarget
6605 if cmd = 'notarget' then
6606 begin
6607 plr.NoTarget := not plr.NoTarget;
6608 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6609 exit;
6610 end;
6611 // noreload
6612 if cmd = 'noreload' then
6613 begin
6614 plr.NoReload := not plr.NoReload;
6615 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6616 exit;
6617 end;
6618 // speedy
6619 if cmd = 'speedy' then
6620 begin
6621 MAX_RUNVEL := 32-MAX_RUNVEL;
6622 g_Console_Add('speed adjusted');
6623 exit;
6624 end;
6625 // jumpy
6626 if cmd = 'jumpy' then
6627 begin
6628 VEL_JUMP := 30-VEL_JUMP;
6629 g_Console_Add('jump height adjusted');
6630 exit;
6631 end;
6632 // automap
6633 if cmd = 'automap' then
6634 begin
6635 gShowMap := not gShowMap;
6636 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6637 exit;
6638 end;
6639 // aimline
6640 if cmd = 'aimline' then
6641 begin
6642 gAimLine := not gAimLine;
6643 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6644 exit;
6645 end;
6646 end;
6648 procedure GameCommands(P: SSArray);
6650 a, b: Integer;
6651 s, pw: String;
6652 chstr: string;
6653 cmd: string;
6654 pl: pTNetClient = nil;
6655 plr: TPlayer;
6656 prt: Word;
6657 nm: Boolean;
6658 listen: LongWord;
6659 found: Boolean;
6660 t: Byte;
6661 begin
6662 // Îáùèå êîìàíäû:
6663 cmd := LowerCase(P[0]);
6664 chstr := '';
6665 if cmd = 'pause' then
6666 begin
6667 if (g_ActiveWindow = nil) then
6668 g_Game_Pause(not gPauseMain);
6670 else if cmd = 'endgame' then
6671 gExit := EXIT_SIMPLE
6672 else if cmd = 'restart' then
6673 begin
6674 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6675 begin
6676 if g_Game_IsClient then
6677 begin
6678 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6679 Exit;
6680 end;
6681 g_Game_Restart();
6682 end else
6683 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6685 else if cmd = 'kick' then
6686 begin
6687 if g_Game_IsServer then
6688 begin
6689 if Length(P) < 2 then
6690 begin
6691 g_Console_Add('kick <name>');
6692 Exit;
6693 end;
6694 if P[1] = '' then
6695 begin
6696 g_Console_Add('kick <name>');
6697 Exit;
6698 end;
6700 if g_Game_IsNet then
6701 pl := g_Net_Client_ByName(P[1]);
6702 if (pl <> nil) then
6703 begin
6704 s := g_Net_ClientName_ByID(pl^.ID);
6705 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6706 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6707 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6708 g_Net_Slist_ServerPlayerLeaves();
6709 end else if gPlayers <> nil then
6710 for a := Low(gPlayers) to High(gPlayers) do
6711 if gPlayers[a] <> nil then
6712 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6713 begin
6714 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6715 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6716 continue;
6717 gPlayers[a].Lives := 0;
6718 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6719 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6720 g_Player_Remove(gPlayers[a].UID);
6721 g_Net_Slist_ServerPlayerLeaves();
6722 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6723 g_Bot_MixNames();
6724 end;
6725 end else
6726 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6728 else if cmd = 'kick_id' then
6729 begin
6730 if g_Game_IsServer and g_Game_IsNet then
6731 begin
6732 if Length(P) < 2 then
6733 begin
6734 g_Console_Add('kick_id <client ID>');
6735 Exit;
6736 end;
6737 if P[1] = '' then
6738 begin
6739 g_Console_Add('kick_id <client ID>');
6740 Exit;
6741 end;
6743 a := StrToIntDef(P[1], 0);
6744 if (NetClients <> nil) and (a <= High(NetClients)) then
6745 begin
6746 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6747 begin
6748 s := g_Net_ClientName_ByID(NetClients[a].ID);
6749 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
6750 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6751 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6752 g_Net_Slist_ServerPlayerLeaves();
6753 end;
6754 end;
6755 end else
6756 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6758 else if cmd = 'kick_pid' then
6759 begin
6760 if g_Game_IsServer and g_Game_IsNet then
6761 begin
6762 if Length(P) < 2 then
6763 begin
6764 g_Console_Add('kick_pid <player ID>');
6765 Exit;
6766 end;
6767 if P[1] = '' then
6768 begin
6769 g_Console_Add('kick_pid <player ID>');
6770 Exit;
6771 end;
6773 a := StrToIntDef(P[1], 0);
6774 pl := g_Net_Client_ByPlayer(a);
6775 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6776 begin
6777 s := g_Net_ClientName_ByID(pl^.ID);
6778 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6779 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6780 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6781 g_Net_Slist_ServerPlayerLeaves();
6782 end;
6783 end else
6784 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6786 else if cmd = 'ban' then
6787 begin
6788 if g_Game_IsServer and g_Game_IsNet then
6789 begin
6790 if Length(P) < 2 then
6791 begin
6792 g_Console_Add('ban <name>');
6793 Exit;
6794 end;
6795 if P[1] = '' then
6796 begin
6797 g_Console_Add('ban <name>');
6798 Exit;
6799 end;
6801 pl := g_Net_Client_ByName(P[1]);
6802 if (pl <> nil) then
6803 g_Net_Host_Ban(pl, False)
6804 else
6805 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6806 end else
6807 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6809 else if cmd = 'ban_id' then
6810 begin
6811 if g_Game_IsServer and g_Game_IsNet then
6812 begin
6813 if Length(P) < 2 then
6814 begin
6815 g_Console_Add('ban_id <client ID>');
6816 Exit;
6817 end;
6818 if P[1] = '' then
6819 begin
6820 g_Console_Add('ban_id <client ID>');
6821 Exit;
6822 end;
6824 a := StrToIntDef(P[1], 0);
6825 if (NetClients <> nil) and (a <= High(NetClients)) then
6826 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6827 g_Net_Host_Ban(pl, False);
6828 end else
6829 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6831 else if cmd = 'ban_pid' then
6832 begin
6833 if g_Game_IsServer and g_Game_IsNet then
6834 begin
6835 if Length(P) < 2 then
6836 begin
6837 g_Console_Add('ban_pid <player ID>');
6838 Exit;
6839 end;
6840 if P[1] = '' then
6841 begin
6842 g_Console_Add('ban_pid <player ID>');
6843 Exit;
6844 end;
6846 a := StrToIntDef(P[1], 0);
6847 pl := g_Net_Client_ByPlayer(a);
6848 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6849 g_Net_Host_Ban(pl, False);
6850 end else
6851 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6853 else if cmd = 'permban' then
6854 begin
6855 if g_Game_IsServer and g_Game_IsNet then
6856 begin
6857 if Length(P) < 2 then
6858 begin
6859 g_Console_Add('permban <name>');
6860 Exit;
6861 end;
6862 if P[1] = '' then
6863 begin
6864 g_Console_Add('permban <name>');
6865 Exit;
6866 end;
6868 pl := g_Net_Client_ByName(P[1]);
6869 if (pl <> nil) then
6870 g_Net_Host_Ban(pl, True)
6871 else
6872 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6873 end else
6874 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6876 else if cmd = 'permban_id' then
6877 begin
6878 if g_Game_IsServer and g_Game_IsNet then
6879 begin
6880 if Length(P) < 2 then
6881 begin
6882 g_Console_Add('permban_id <client ID>');
6883 Exit;
6884 end;
6885 if P[1] = '' then
6886 begin
6887 g_Console_Add('permban_id <client ID>');
6888 Exit;
6889 end;
6891 a := StrToIntDef(P[1], 0);
6892 if (NetClients <> nil) and (a <= High(NetClients)) then
6893 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6894 g_Net_Host_Ban(@NetClients[a], True);
6895 end else
6896 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6898 else if cmd = 'permban_pid' then
6899 begin
6900 if g_Game_IsServer and g_Game_IsNet then
6901 begin
6902 if Length(P) < 2 then
6903 begin
6904 g_Console_Add('permban_pid <player ID>');
6905 Exit;
6906 end;
6907 if P[1] = '' then
6908 begin
6909 g_Console_Add('permban_pid <player ID>');
6910 Exit;
6911 end;
6913 a := StrToIntDef(P[1], 0);
6914 pl := g_Net_Client_ByPlayer(a);
6915 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6916 g_Net_Host_Ban(pl, True);
6917 end else
6918 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6920 else if cmd = 'permban_ip' then
6921 begin
6922 if g_Game_IsServer and g_Game_IsNet then
6923 begin
6924 if Length(P) < 2 then
6925 begin
6926 g_Console_Add('permban_ip <IP address>');
6927 Exit;
6928 end;
6929 if P[1] = '' then
6930 begin
6931 g_Console_Add('permban_ip <IP address>');
6932 Exit;
6933 end;
6935 g_Net_BanAddress(P[1]);
6936 g_Net_SaveBanList();
6937 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6938 end else
6939 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6941 else if cmd = 'unban' then
6942 begin
6943 if g_Game_IsServer and g_Game_IsNet then
6944 begin
6945 if Length(P) < 2 then
6946 begin
6947 g_Console_Add('unban <IP Address>');
6948 Exit;
6949 end;
6950 if P[1] = '' then
6951 begin
6952 g_Console_Add('unban <IP Address>');
6953 Exit;
6954 end;
6956 if g_Net_UnbanAddress(P[1]) then
6957 begin
6958 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6959 g_Net_SaveBanList();
6960 end else
6961 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6962 end else
6963 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6965 else if cmd = 'clientlist' then
6966 begin
6967 if g_Game_IsServer and g_Game_IsNet then
6968 begin
6969 b := 0;
6970 if NetClients <> nil then
6971 for a := Low(NetClients) to High(NetClients) do
6972 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6973 begin
6974 plr := g_Player_Get(NetClients[a].Player);
6975 if plr = nil then continue;
6976 Inc(b);
6977 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6978 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6979 end;
6980 if b = 0 then
6981 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6982 end else
6983 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6985 else if cmd = 'connect' then
6986 begin
6987 if (NetMode = NET_NONE) then
6988 begin
6989 if Length(P) < 2 then
6990 begin
6991 g_Console_Add('connect <IP> [port] [password]');
6992 Exit;
6993 end;
6994 if P[1] = '' then
6995 begin
6996 g_Console_Add('connect <IP> [port] [password]');
6997 Exit;
6998 end;
7000 if Length(P) > 2 then
7001 prt := StrToIntDef(P[2], 25666)
7002 else
7003 prt := 25666;
7005 if Length(P) > 3 then
7006 pw := P[3]
7007 else
7008 pw := '';
7010 g_Game_StartClient(P[1], prt, pw);
7011 end;
7013 else if cmd = 'disconnect' then
7014 begin
7015 if (NetMode = NET_CLIENT) then
7016 g_Net_Disconnect();
7018 else if cmd = 'reconnect' then
7019 begin
7020 if (NetMode = NET_SERVER) then
7021 Exit;
7023 if (NetMode = NET_CLIENT) then
7024 begin
7025 g_Net_Disconnect();
7026 gExit := EXIT_SIMPLE;
7027 EndGame;
7028 end;
7030 //TODO: Use last successful password to reconnect, instead of ''
7031 g_Game_StartClient(NetClientIP, NetClientPort, '');
7033 else if (cmd = 'addbot') or
7034 (cmd = 'bot_add') then
7035 begin
7036 case Length(P) of
7037 1: g_Bot_Add(TEAM_NONE, 2);
7038 2: g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2));
7039 else
7040 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100));
7041 end;
7043 else if cmd = 'bot_addlist' then
7044 begin
7045 case Length(P) of
7046 1: g_Bot_AddList(TEAM_NONE, '');
7047 2: g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1));
7048 else
7049 if P[2] = 'red' then
7050 t := TEAM_RED
7051 else if P[2] = 'blue' then
7052 t := TEAM_BLUE
7053 else
7054 t := TEAM_NONE;
7056 if Length(P) = 3
7057 then g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1))
7058 else g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[3], 100));
7059 end;
7061 else if cmd = 'bot_removeall' then
7062 g_Bot_RemoveAll()
7063 else if cmd = 'chat' then
7064 begin
7065 if g_Game_IsNet then
7066 begin
7067 if Length(P) > 1 then
7068 begin
7069 for a := 1 to High(P) do
7070 chstr := chstr + P[a] + ' ';
7072 if Length(chstr) > 200 then SetLength(chstr, 200);
7074 if Length(chstr) < 1 then
7075 begin
7076 g_Console_Add('chat <text>');
7077 Exit;
7078 end;
7080 chstr := b_Text_Format(chstr);
7081 if g_Game_IsClient then
7082 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
7083 else
7084 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
7086 else
7087 g_Console_Add('chat <text>');
7088 end else
7089 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7091 else if cmd = 'teamchat' then
7092 begin
7093 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
7094 begin
7095 if Length(P) > 1 then
7096 begin
7097 for a := 1 to High(P) do
7098 chstr := chstr + P[a] + ' ';
7100 if Length(chstr) > 200 then SetLength(chstr, 200);
7102 if Length(chstr) < 1 then
7103 begin
7104 g_Console_Add('teamchat <text>');
7105 Exit;
7106 end;
7108 chstr := b_Text_Format(chstr);
7109 if g_Game_IsClient then
7110 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
7111 else
7112 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
7113 gPlayer1Settings.Team);
7115 else
7116 g_Console_Add('teamchat <text>');
7117 end else
7118 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7120 else if (cmd = 'an') or (cmd = 'announce') then
7121 begin
7122 if g_Game_IsNet then
7123 begin
7124 if Length(P) > 1 then
7125 begin
7126 for a := 1 to High(P) do
7127 chstr := chstr + P[a] + ' ';
7129 if Length(chstr) > 200 then SetLength(chstr, 200);
7131 if Length(chstr) < 1 then
7132 begin
7133 g_Console_Add('announce <text>');
7134 Exit;
7135 end;
7137 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
7138 if g_Game_IsClient then
7139 MC_SEND_RCONCommand(chstr)
7140 else
7141 g_Console_Process(chstr, True);
7143 else
7144 g_Console_Add('announce <text>');
7145 end else
7146 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7148 else if cmd = 'game' then
7149 begin
7150 if gGameSettings.GameType <> GT_NONE then
7151 begin
7152 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7153 Exit;
7154 end;
7155 if Length(P) = 1 then
7156 begin
7157 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
7158 Exit;
7159 end;
7160 // game not started yet, load first map from some wad
7161 found := false;
7162 s := addWadExtension(P[1]);
7163 found := e_FindResource(AllMapDirs, s);
7164 P[1] := s;
7165 if found then
7166 begin
7167 P[1] := ExpandFileName(P[1]);
7168 // if map not choosed then set first map
7169 if Length(P) < 3 then
7170 begin
7171 SetLength(P, 3);
7172 P[2] := g_Game_GetFirstMap(P[1]);
7173 end;
7175 s := P[1] + ':\' + UpperCase(P[2]);
7177 if g_Map_Exist(s) then
7178 begin
7179 // start game
7180 g_Game_Free();
7181 with gGameSettings do
7182 begin
7183 Options := gsGameFlags;
7184 GameMode := g_Game_TextToMode(gsGameMode);
7185 if gSwitchGameMode <> GM_NONE then
7186 GameMode := gSwitchGameMode;
7187 if GameMode = GM_NONE then GameMode := GM_DM;
7188 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7189 b := 1;
7190 if Length(P) >= 4 then
7191 b := StrToIntDef(P[3], 1);
7192 g_Game_StartCustom(s, GameMode, TimeLimit,
7193 ScoreLimit, MaxLives, Options, b);
7194 end;
7196 else
7197 if P[2] = '' then
7198 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7199 else
7200 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
7201 end else
7202 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
7204 else if cmd = 'host' then
7205 begin
7206 if gGameSettings.GameType <> GT_NONE then
7207 begin
7208 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7209 Exit;
7210 end;
7211 if Length(P) < 4 then
7212 begin
7213 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
7214 Exit;
7215 end;
7216 if not StrToIp(P[1], listen) then
7217 Exit;
7218 prt := StrToIntDef(P[2], 25666);
7220 s := addWadExtension(P[3]);
7221 found := e_FindResource(AllMapDirs, s);
7222 P[3] := s;
7223 if found then
7224 begin
7225 // get first map in wad, if not specified
7226 if Length(P) < 5 then
7227 begin
7228 SetLength(P, 5);
7229 P[4] := g_Game_GetFirstMap(P[1]);
7230 end;
7231 s := P[3] + ':\' + UpperCase(P[4]);
7232 if g_Map_Exist(s) then
7233 begin
7234 // start game
7235 g_Game_Free();
7236 with gGameSettings do
7237 begin
7238 Options := gsGameFlags;
7239 GameMode := g_Game_TextToMode(gsGameMode);
7240 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
7241 if GameMode = GM_NONE then GameMode := GM_DM;
7242 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7243 b := 0;
7244 if Length(P) >= 6 then
7245 b := StrToIntDef(P[5], 0);
7246 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
7249 else
7250 begin
7251 if P[4] = '' then
7252 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
7253 else
7254 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
7257 else
7258 begin
7259 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
7262 else if cmd = 'map' then
7263 begin
7264 if Length(P) = 1 then
7265 begin
7266 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7267 begin
7268 g_Console_Add(cmd + ' <MAP>');
7269 g_Console_Add(cmd + ' <WAD> [MAP]')
7271 else
7272 begin
7273 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7276 else if not e_IsValidResourceName(P[1]) then
7277 begin
7278 g_Console_Add('wad name must not be absolute or relative');
7280 else
7281 begin
7282 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7283 begin
7284 if Length(P) < 3 then
7285 begin
7286 // first param is map or wad
7287 s := UpperCase(P[1]);
7288 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7289 begin
7290 gExitByTrigger := False;
7291 if gGameOn then
7292 begin
7293 // already in game, finish current map
7294 gNextMap := s;
7295 gExit := EXIT_ENDLEVELCUSTOM;
7297 else
7298 begin
7299 // intermission, so change map immediately
7300 g_Game_ChangeMap(s)
7303 else
7304 begin
7305 s := P[1];
7306 found := e_FindResource(AllMapDirs, s);
7307 P[1] := s;
7308 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
7309 if found then
7310 begin
7311 // no such map, found wad
7312 pw := P[1];
7313 SetLength(P, 3);
7314 P[1] := ExpandFileName(pw);
7315 P[2] := g_Game_GetFirstMap(P[1]);
7316 s := P[1] + ':\' + P[2];
7317 if g_Map_Exist(s) then
7318 begin
7319 gExitByTrigger := False;
7320 if gGameOn then
7321 begin
7322 // already in game, finish current map
7323 gNextMap := s;
7324 gExit := EXIT_ENDLEVELCUSTOM
7326 else
7327 begin
7328 // intermission, so change map immediately
7329 g_Game_ChangeMap(s)
7332 else
7333 begin
7334 if P[2] = '' then
7335 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7336 else
7337 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7340 else
7341 begin
7342 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7344 end;
7346 else
7347 begin
7348 s := addWadExtension(P[1]);
7349 found := e_FindResource(AllMapDirs, s);
7350 P[1] := s;
7351 if found then
7352 begin
7353 P[2] := UpperCase(P[2]);
7354 s := P[1] + ':\' + P[2];
7355 if g_Map_Exist(s) then
7356 begin
7357 gExitByTrigger := False;
7358 if gGameOn then
7359 begin
7360 gNextMap := s;
7361 gExit := EXIT_ENDLEVELCUSTOM
7363 else
7364 begin
7365 g_Game_ChangeMap(s)
7368 else
7369 begin
7370 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7373 else
7374 begin
7375 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7379 else
7380 begin
7381 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7385 else if cmd = 'nextmap' then
7386 begin
7387 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
7388 begin
7389 g_Console_Add(_lc[I_MSG_NOT_GAME])
7391 else
7392 begin
7393 nm := True;
7394 if Length(P) = 1 then
7395 begin
7396 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7397 begin
7398 g_Console_Add(cmd + ' <MAP>');
7399 g_Console_Add(cmd + ' <WAD> [MAP]');
7401 else
7402 begin
7403 nm := False;
7404 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7405 end;
7407 else if not e_IsValidResourceName(P[1]) then
7408 begin
7409 g_Console_Add('wad name must not be absolute or relative');
7411 else
7412 begin
7413 nm := False;
7414 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7415 begin
7416 if Length(P) < 3 then
7417 begin
7418 // first param is map or wad
7419 s := UpperCase(P[1]);
7420 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7421 begin
7422 // map founded
7423 gExitByTrigger := False;
7424 gNextMap := s;
7425 nm := True;
7427 else
7428 begin
7429 // no such map, found wad
7430 pw := addWadExtension(P[1]);
7431 found := e_FindResource(MapDirs, pw);
7432 if not found then
7433 found := e_FindResource(WadDirs, pw);
7434 P[1] := pw;
7435 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7436 if found then
7437 begin
7438 // map not specified, select first map
7439 SetLength(P, 3);
7440 P[2] := g_Game_GetFirstMap(P[1]);
7441 s := P[1] + ':\' + P[2];
7442 if g_Map_Exist(s) then
7443 begin
7444 gExitByTrigger := False;
7445 gNextMap := s;
7446 nm := True
7448 else
7449 begin
7450 if P[2] = '' then
7451 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7452 else
7453 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7456 else
7457 begin
7458 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7462 else
7463 begin
7464 // specified two params wad + map
7465 pw := addWadExtension(P[1]);
7466 found := e_FindResource(MapDirs, pw);
7467 if not found then
7468 found := e_FindResource(MapDirs, pw);
7469 P[1] := pw;
7470 if found then
7471 begin
7472 P[2] := UpperCase(P[2]);
7473 s := P[1] + ':\' + P[2];
7474 if g_Map_Exist(s) then
7475 begin
7476 gExitByTrigger := False;
7477 gNextMap := s;
7478 nm := True
7480 else
7481 begin
7482 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7485 else
7486 begin
7487 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7491 else
7492 begin
7493 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7495 end;
7496 if nm then
7497 begin
7498 if gNextMap = '' then
7499 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7500 else
7501 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7505 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7506 begin
7507 if not gGameOn then
7508 begin
7509 g_Console_Add(_lc[I_MSG_NOT_GAME])
7511 else
7512 begin
7513 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7514 begin
7515 gExitByTrigger := False;
7516 // next map not specified, try to find trigger EXIT
7517 if (gNextMap = '') and (gTriggers <> nil) then
7518 begin
7519 for a := 0 to High(gTriggers) do
7520 begin
7521 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7522 begin
7523 gExitByTrigger := True;
7524 //gNextMap := gTriggers[a].Data.MapName;
7525 gNextMap := gTriggers[a].tgcMap;
7526 Break
7529 end;
7530 if gNextMap = '' then
7531 gNextMap := g_Game_GetNextMap();
7532 if not isWadPath(gNextMap) then
7533 s := gGameSettings.WAD + ':\' + gNextMap
7534 else
7535 s := gNextMap;
7536 if g_Map_Exist(s) then
7537 gExit := EXIT_ENDLEVELCUSTOM
7538 else
7539 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7541 else
7542 begin
7543 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7547 else if (cmd = 'event') then
7548 begin
7549 if (Length(P) <= 1) then
7550 begin
7551 for a := 0 to High(gEvents) do
7552 if gEvents[a].Command = '' then
7553 g_Console_Add(gEvents[a].Name + ' <none>')
7554 else
7555 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7556 Exit;
7557 end;
7558 if (Length(P) = 2) then
7559 begin
7560 for a := 0 to High(gEvents) do
7561 if gEvents[a].Name = P[1] then
7562 if gEvents[a].Command = '' then
7563 g_Console_Add(gEvents[a].Name + ' <none>')
7564 else
7565 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7566 Exit;
7567 end;
7568 for a := 0 to High(gEvents) do
7569 if gEvents[a].Name = P[1] then
7570 begin
7571 gEvents[a].Command := '';
7572 for b := 2 to High(P) do
7573 if Pos(' ', P[b]) = 0 then
7574 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7575 else
7576 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7577 gEvents[a].Command := Trim(gEvents[a].Command);
7578 Exit;
7579 end;
7581 else if cmd = 'suicide' then
7582 begin
7583 if gGameOn then
7584 begin
7585 if g_Game_IsClient then
7586 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7587 else
7588 begin
7589 if gPlayer1 <> nil then
7590 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7591 if gPlayer2 <> nil then
7592 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7593 end;
7594 end;
7596 else if cmd = 'screenshot' then
7597 begin
7598 g_TakeScreenShot()
7600 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7601 begin
7602 a := 1 - (ord(cmd[5]) - ord('n'));
7603 if a = -1 then
7604 gWeaponAction[0, WP_PREV] := True;
7605 if a = 1 then
7606 gWeaponAction[0, WP_NEXT] := True;
7608 else if cmd = 'weapon' then
7609 begin
7610 if Length(p) = 2 then
7611 begin
7612 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7613 if (a >= WP_FIRST) and (a <= WP_LAST) then
7614 gSelectWeapon[0, a] := True
7617 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7618 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7619 begin
7620 a := 1 - (ord(cmd[8]) - ord('n'));
7621 b := ord(cmd[2]) - ord('1');
7622 if a = -1 then
7623 gWeaponAction[b, WP_PREV] := True;
7624 if a = 1 then
7625 gWeaponAction[b, WP_NEXT] := True;
7627 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7628 begin
7629 if Length(p) = 2 then
7630 begin
7631 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7632 b := ord(cmd[2]) - ord('1');
7633 if (a >= WP_FIRST) and (a <= WP_LAST) then
7634 gSelectWeapon[b, a] := True
7637 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
7638 begin
7639 b := ord(cmd[2]) - ord('1');
7640 if b = 0 then
7641 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
7642 else
7643 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
7645 else if (cmd = 'dropflag') then
7646 begin
7647 if g_Game_IsServer then
7648 begin
7649 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
7650 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
7652 else
7653 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7655 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
7656 begin
7657 b := ord(cmd[2]) - ord('1');
7658 if g_Game_IsServer then
7659 begin
7660 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
7661 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
7663 else
7664 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7666 // Êîìàíäû Ñâîåé èãðû:
7667 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7668 begin
7669 if cmd = 'bot_addred' then
7670 begin
7671 if Length(P) > 1 then
7672 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7673 else
7674 g_Bot_Add(TEAM_RED, 2);
7676 else if cmd = 'bot_addblue' then
7677 begin
7678 if Length(P) > 1 then
7679 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7680 else
7681 g_Bot_Add(TEAM_BLUE, 2);
7683 else if cmd = 'spectate' then
7684 begin
7685 if not gGameOn then
7686 Exit;
7687 g_Game_Spectate();
7689 else if cmd = 'say' then
7690 begin
7691 if g_Game_IsServer and g_Game_IsNet then
7692 begin
7693 if Length(P) > 1 then
7694 begin
7695 chstr := '';
7696 for a := 1 to High(P) do
7697 chstr := chstr + P[a] + ' ';
7699 if Length(chstr) > 200 then SetLength(chstr, 200);
7701 if Length(chstr) < 1 then
7702 begin
7703 g_Console_Add('say <text>');
7704 Exit;
7705 end;
7707 chstr := b_Text_Format(chstr);
7708 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7710 else g_Console_Add('say <text>');
7711 end else
7712 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7714 else if cmd = 'tell' then
7715 begin
7716 if g_Game_IsServer and g_Game_IsNet then
7717 begin
7718 if (Length(P) > 2) and (P[1] <> '') then
7719 begin
7720 chstr := '';
7721 for a := 2 to High(P) do
7722 chstr := chstr + P[a] + ' ';
7724 if Length(chstr) > 200 then SetLength(chstr, 200);
7726 if Length(chstr) < 1 then
7727 begin
7728 g_Console_Add('tell <playername> <text>');
7729 Exit;
7730 end;
7732 pl := g_Net_Client_ByName(P[1]);
7733 if pl <> nil then
7734 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7735 else
7736 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7738 else g_Console_Add('tell <playername> <text>');
7739 end else
7740 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7742 else if cmd = 'centerprint' then
7743 begin
7744 if (Length(P) > 2) and (P[1] <> '') then
7745 begin
7746 chstr := '';
7747 for a := 2 to High(P) do
7748 chstr := chstr + P[a] + ' ';
7750 if Length(chstr) > 200 then SetLength(chstr, 200);
7752 if Length(chstr) < 1 then
7753 begin
7754 g_Console_Add('centerprint <timeout> <text>');
7755 Exit;
7756 end;
7758 a := StrToIntDef(P[1], 100);
7759 chstr := b_Text_Format(chstr);
7760 g_Game_Message(chstr, a);
7761 if g_Game_IsNet and g_Game_IsServer then
7762 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7764 else g_Console_Add('centerprint <timeout> <text>');
7766 else if (cmd = 'overtime') and not g_Game_IsClient then
7767 begin
7768 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7769 Exit;
7770 // Äîïîëíèòåëüíîå âðåìÿ:
7771 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7773 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7774 [gGameSettings.TimeLimit div 3600,
7775 (gGameSettings.TimeLimit div 60) mod 60,
7776 gGameSettings.TimeLimit mod 60]));
7777 if g_Game_IsNet then MH_SEND_GameSettings;
7779 else if (cmd = 'rcon_password') and g_Game_IsClient then
7780 begin
7781 if (Length(P) <= 1) then
7782 g_Console_Add('rcon_password <password>')
7783 else
7784 MC_SEND_RCONPassword(P[1]);
7786 else if cmd = 'rcon' then
7787 begin
7788 if g_Game_IsClient then
7789 begin
7790 if Length(P) > 1 then
7791 begin
7792 chstr := '';
7793 for a := 1 to High(P) do
7794 chstr := chstr + P[a] + ' ';
7796 if Length(chstr) > 200 then SetLength(chstr, 200);
7798 if Length(chstr) < 1 then
7799 begin
7800 g_Console_Add('rcon <command>');
7801 Exit;
7802 end;
7804 MC_SEND_RCONCommand(chstr);
7806 else g_Console_Add('rcon <command>');
7807 end;
7809 else if cmd = 'ready' then
7810 begin
7811 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7812 gLMSRespawnTime := gTime + 100;
7814 else if (cmd = 'callvote') and g_Game_IsNet then
7815 begin
7816 if Length(P) > 1 then
7817 begin
7818 chstr := '';
7819 for a := 1 to High(P) do begin
7820 if a > 1 then chstr := chstr + ' ';
7821 chstr := chstr + P[a];
7822 end;
7824 if Length(chstr) > 200 then SetLength(chstr, 200);
7826 if Length(chstr) < 1 then
7827 begin
7828 g_Console_Add('callvote <command>');
7829 Exit;
7830 end;
7832 if g_Game_IsClient then
7833 MC_SEND_Vote(True, chstr)
7834 else
7835 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7836 g_Console_Process('vote', True);
7838 else
7839 g_Console_Add('callvote <command>');
7841 else if (cmd = 'vote') and g_Game_IsNet then
7842 begin
7843 if g_Game_IsClient then
7844 MC_SEND_Vote(False)
7845 else if gVoteInProgress then
7846 begin
7847 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7848 a := Floor((NetClientCount+1)/2.0) + 1
7849 else
7850 a := Floor(NetClientCount/2.0) + 1;
7851 if gVoted then
7852 begin
7853 Dec(gVoteCount);
7854 gVoted := False;
7855 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7856 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7858 else
7859 begin
7860 Inc(gVoteCount);
7861 gVoted := True;
7862 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7863 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7864 g_Game_CheckVote;
7865 end;
7866 end;
7868 end;
7869 end;
7871 procedure SystemCommands(P: SSArray);
7873 cmd: string;
7874 begin
7875 cmd := LowerCase(P[0]);
7876 case cmd of
7877 'exit', 'quit':
7878 begin
7879 g_Game_Free();
7880 gExit := EXIT_QUIT;
7881 end;
7882 'r_reset':
7883 begin
7884 gRC_Width := Max(1, gRC_Width);
7885 gRC_Height := Max(1, gRC_Height);
7886 gBPP := Max(1, gBPP);
7887 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7888 e_LogWriteln('resolution changed')
7889 else
7890 e_LogWriteln('resolution not changed');
7891 sys_EnableVSync(gVSync);
7892 end;
7893 'r_maxfps':
7894 begin
7895 if Length(p) = 2 then
7896 begin
7897 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7898 if gMaxFPS > 0 then
7899 gFrameTime := 1000 div gMaxFPS
7900 else
7901 gFrameTime := 0;
7902 end;
7903 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7904 end;
7905 'g_language':
7906 begin
7907 if Length(p) = 2 then
7908 begin
7909 gAskLanguage := true;
7910 gLanguage := LANGUAGE_ENGLISH;
7911 case LowerCase(p[1]) of
7912 'english':
7913 begin
7914 gAskLanguage := false;
7915 gLanguage := LANGUAGE_ENGLISH;
7916 end;
7917 'russian':
7918 begin
7919 gAskLanguage := false;
7920 gLanguage := LANGUAGE_RUSSIAN;
7921 end;
7922 'ask':
7923 begin
7924 gAskLanguage := true;
7925 gLanguage := LANGUAGE_ENGLISH;
7926 end;
7927 end;
7928 g_Language_Set(gLanguage);
7930 else
7931 begin
7932 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7934 end;
7935 end;
7936 end;
7938 procedure g_TakeScreenShot(Filename: String);
7940 s: TStream;
7941 t: TDateTime;
7942 dir, date, name: String;
7943 begin
7944 if e_NoGraphics then Exit;
7946 dir := e_GetWriteableDir(ScreenshotDirs);
7948 if Filename = '' then
7949 begin
7950 t := Now();
7951 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7952 Filename := 'screenshot-' + date;
7953 end;
7955 name := Filename + '.png';
7956 // FIXME: hack for improper ConcatPaths(); see commit.
7957 if dir <> '' then name := ConcatPaths([dir, name]);
7959 s := createDiskFile(name);
7961 e_MakeScreenshot(s, gWinSizeX, gWinSizeY);
7962 s.Free;
7963 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7964 except
7965 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7966 s.Free;
7967 DeleteFile(name)
7969 except
7970 g_Console_Add('oh shit, i can''t create screenshot!')
7972 end;
7974 procedure g_Game_InGameMenu(Show: Boolean);
7975 begin
7976 if (g_ActiveWindow = nil) and Show then
7977 begin
7978 if gGameSettings.GameType = GT_SINGLE then
7979 g_GUI_ShowWindow('GameSingleMenu')
7980 else
7981 begin
7982 if g_Game_IsClient then
7983 g_GUI_ShowWindow('GameClientMenu')
7984 else
7985 if g_Game_IsNet then
7986 g_GUI_ShowWindow('GameServerMenu')
7987 else
7988 g_GUI_ShowWindow('GameCustomMenu');
7989 end;
7990 {$IFDEF ENABLE_SOUND}
7991 g_Sound_PlayEx('MENU_OPEN');
7992 {$ENDIF}
7994 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7995 if (not g_Game_IsNet) then
7996 g_Game_Pause(True);
7998 else
7999 if (g_ActiveWindow <> nil) and (not Show) then
8000 begin
8001 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
8002 if (not g_Game_IsNet) then
8003 g_Game_Pause(False);
8004 end;
8005 end;
8007 procedure g_Game_Pause (Enable: Boolean);
8009 oldPause: Boolean;
8010 begin
8011 if not gGameOn then exit;
8013 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
8015 oldPause := gPause;
8016 gPauseMain := Enable;
8018 {$IFDEF ENABLE_SOUND}
8019 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
8020 {$ENDIF}
8021 end;
8023 procedure g_Game_HolmesPause (Enable: Boolean);
8025 oldPause: Boolean;
8026 begin
8027 if not gGameOn then exit;
8028 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
8030 oldPause := gPause;
8031 gPauseHolmes := Enable;
8033 {$IFDEF ENABLE_SOUND}
8034 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
8035 {$ENDIF}
8036 end;
8038 {$IFDEF ENABLE_SOUND}
8039 procedure g_Game_PauseAllSounds(Enable: Boolean);
8041 i: Integer;
8042 begin
8043 // Òðèããåðû:
8044 if gTriggers <> nil then
8045 for i := 0 to High(gTriggers) do
8046 with gTriggers[i] do
8047 if (TriggerType = TRIGGER_SOUND) and
8048 (Sound <> nil) and
8049 Sound.IsPlaying() then
8050 begin
8051 Sound.Pause(Enable);
8052 end;
8054 // Çâóêè èãðîêîâ:
8055 if gPlayers <> nil then
8056 for i := 0 to High(gPlayers) do
8057 if gPlayers[i] <> nil then
8058 gPlayers[i].PauseSounds(Enable);
8060 // Ìóçûêà:
8061 if gMusic <> nil then
8062 gMusic.Pause(Enable);
8063 end;
8065 procedure g_Game_StopAllSounds(all: Boolean);
8067 i: Integer;
8068 begin
8069 if gTriggers <> nil then
8070 for i := 0 to High(gTriggers) do
8071 with gTriggers[i] do
8072 if (TriggerType = TRIGGER_SOUND) and
8073 (Sound <> nil) then
8074 Sound.Stop();
8076 if gMusic <> nil then
8077 gMusic.Stop();
8079 if all then
8080 e_StopChannels();
8081 end;
8083 procedure g_Game_UpdateTriggerSounds;
8084 var i: Integer;
8085 begin
8086 if gTriggers <> nil then
8087 for i := 0 to High(gTriggers) do
8088 with gTriggers[i] do
8089 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
8090 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
8091 end;
8092 {$ENDIF}
8094 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
8095 begin
8096 Result := False;
8097 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
8098 begin
8099 Result := True;
8100 Exit;
8101 end;
8102 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
8103 begin
8104 Result := True;
8105 Exit;
8106 end;
8107 if gSpectMode <> SPECT_PLAYERS then
8108 Exit;
8109 if gSpectPID1 = UID then
8110 begin
8111 Result := True;
8112 Exit;
8113 end;
8114 if gSpectViewTwo and (gSpectPID2 = UID) then
8115 begin
8116 Result := True;
8117 Exit;
8118 end;
8119 end;
8121 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
8123 Pl: TPlayer;
8124 begin
8125 Result := False;
8126 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
8127 begin
8128 Result := True;
8129 Exit;
8130 end;
8131 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
8132 begin
8133 Result := True;
8134 Exit;
8135 end;
8136 if gSpectMode <> SPECT_PLAYERS then
8137 Exit;
8138 Pl := g_Player_Get(gSpectPID1);
8139 if (Pl <> nil) and (Pl.Team = Team) then
8140 begin
8141 Result := True;
8142 Exit;
8143 end;
8144 if gSpectViewTwo then
8145 begin
8146 Pl := g_Player_Get(gSpectPID2);
8147 if (Pl <> nil) and (Pl.Team = Team) then
8148 begin
8149 Result := True;
8150 Exit;
8151 end;
8152 end;
8153 end;
8155 procedure g_Game_Message(Msg: string; Time: Word);
8156 begin
8157 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
8158 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
8159 MessageTime := Time;
8160 end;
8162 {$IFDEF ENABLE_SOUND}
8163 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
8164 const
8165 punct: Array[0..13] of String =
8166 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8168 i, j: Integer;
8169 ok: Boolean;
8170 fpText: String;
8172 function IsPunctuation(S: String): Boolean;
8174 i: Integer;
8175 begin
8176 Result := False;
8177 if Length(S) <> 1 then
8178 Exit;
8179 for i := Low(punct) to High(punct) do
8180 if S = punct[i] then
8181 begin
8182 Result := True;
8183 break;
8184 end;
8185 end;
8186 function FilterPunctuation(S: String): String;
8188 i: Integer;
8189 begin
8190 for i := Low(punct) to High(punct) do
8191 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
8192 Result := S;
8193 end;
8194 begin
8195 ok := False;
8197 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
8198 begin
8199 // remove player name
8200 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8201 // for FullWord check
8202 Text := toLowerCase1251(' ' + Text + ' ');
8203 fpText := FilterPunctuation(Text);
8205 for i := 0 to Length(gChatSounds) - 1 do
8206 begin
8207 ok := True;
8208 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
8209 begin
8210 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
8211 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
8212 else
8213 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
8214 if not ok then
8215 break;
8216 end;
8217 if ok then
8218 begin
8219 gChatSounds[i].Sound.Play();
8220 break;
8221 end;
8222 end;
8223 end;
8224 if not ok then
8225 g_Sound_PlayEx('SOUND_GAME_RADIO');
8226 end;
8228 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
8230 a: Integer;
8231 begin
8232 case gAnnouncer of
8233 ANNOUNCE_NONE:
8234 Exit;
8235 ANNOUNCE_ME,
8236 ANNOUNCE_MEPLUS:
8237 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8238 Exit;
8239 end;
8240 for a := 0 to 3 do
8241 if goodsnd[a].IsPlaying() then
8242 Exit;
8244 goodsnd[Random(4)].Play();
8245 end;
8247 procedure g_Game_Announce_KillCombo(Param: Integer);
8249 UID: Word;
8250 c, n: Byte;
8251 Pl: TPlayer;
8252 Name: String;
8253 begin
8254 UID := Param and $FFFF;
8255 c := Param shr 16;
8256 if c < 2 then
8257 Exit;
8259 Pl := g_Player_Get(UID);
8260 if Pl = nil then
8261 Name := '?'
8262 else
8263 Name := Pl.Name;
8265 case c of
8266 2: begin
8267 n := 0;
8268 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
8269 end;
8270 3: begin
8271 n := 1;
8272 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
8273 end;
8274 4: begin
8275 n := 2;
8276 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
8277 end;
8278 else begin
8279 n := 3;
8280 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
8281 end;
8282 end;
8284 case gAnnouncer of
8285 ANNOUNCE_NONE:
8286 Exit;
8287 ANNOUNCE_ME:
8288 if not g_Game_IsWatchedPlayer(UID) then
8289 Exit;
8290 ANNOUNCE_MEPLUS:
8291 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
8292 Exit;
8293 end;
8295 if killsnd[n].IsPlaying() then
8296 killsnd[n].Stop();
8297 killsnd[n].Play();
8298 end;
8300 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
8302 a: Integer;
8303 begin
8304 case gAnnouncer of
8305 ANNOUNCE_NONE:
8306 Exit;
8307 ANNOUNCE_ME:
8308 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8309 Exit;
8310 end;
8311 for a := 0 to 2 do
8312 if hahasnd[a].IsPlaying() then
8313 Exit;
8315 hahasnd[Random(3)].Play();
8316 end;
8317 {$ENDIF}
8319 procedure g_Game_Effect_Bubbles (fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean);
8320 begin
8321 g_GFX_Bubbles(fX, fY, count, devX, devY);
8322 {$IFDEF ENABLE_SOUND}
8323 if not Silent then if Random(2) = 0
8324 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX, fY)
8325 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX, fY);
8326 {$ENDIF}
8327 end;
8329 procedure g_Game_StartVote(Command, Initiator: string);
8331 Need: Integer;
8332 begin
8333 if not gVotesEnabled then Exit;
8334 if gGameSettings.GameType <> GT_SERVER then Exit;
8335 if gVoteInProgress or gVotePassed then
8336 begin
8337 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
8338 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
8339 Exit;
8340 end;
8341 gVoteInProgress := True;
8342 gVotePassed := False;
8343 gVoteTimer := gTime + gVoteTimeout * 1000;
8344 gVoteCount := 0;
8345 gVoted := False;
8346 gVoteCommand := Command;
8348 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8349 Need := Floor((NetClientCount+1)/2.0)+1
8350 else
8351 Need := Floor(NetClientCount/2.0)+1;
8352 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
8353 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
8354 end;
8356 procedure g_Game_CheckVote;
8358 I, Need: Integer;
8359 begin
8360 if gGameSettings.GameType <> GT_SERVER then Exit;
8361 if not gVoteInProgress then Exit;
8363 if (gTime >= gVoteTimer) then
8364 begin
8365 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8366 Need := Floor((NetClientCount+1)/2.0) + 1
8367 else
8368 Need := Floor(NetClientCount/2.0) + 1;
8369 if gVoteCount >= Need then
8370 begin
8371 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8372 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8373 gVotePassed := True;
8374 gVoteCmdTimer := gTime + 5000;
8376 else
8377 begin
8378 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
8379 MH_SEND_VoteEvent(NET_VE_FAILED);
8380 end;
8381 if NetClients <> nil then
8382 for I := Low(NetClients) to High(NetClients) do
8383 if NetClients[i].Used then
8384 NetClients[i].Voted := False;
8385 gVoteInProgress := False;
8386 gVoted := False;
8387 gVoteCount := 0;
8389 else
8390 begin
8391 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8392 Need := Floor((NetClientCount+1)/2.0) + 1
8393 else
8394 Need := Floor(NetClientCount/2.0) + 1;
8395 if gVoteCount >= Need then
8396 begin
8397 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8398 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8399 gVoteInProgress := False;
8400 gVotePassed := True;
8401 gVoteCmdTimer := gTime + 5000;
8402 gVoted := False;
8403 gVoteCount := 0;
8404 if NetClients <> nil then
8405 for I := Low(NetClients) to High(NetClients) do
8406 if NetClients[i].Used then
8407 NetClients[i].Voted := False;
8408 end;
8409 end;
8410 end;
8412 procedure g_Game_SetDebugMode();
8413 begin
8414 gDebugMode := True;
8415 // ×èòû (äàæå â ñâîåé èãðå):
8416 gCheats := True;
8417 end;
8419 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
8421 i: Word;
8422 begin
8423 if Length(LoadingStat.Msgs) = 0 then
8424 Exit;
8426 with LoadingStat do
8427 begin
8428 if not reWrite then
8429 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8430 if NextMsg = Length(Msgs) then
8431 begin // scroll
8432 for i := 0 to High(Msgs)-1 do
8433 Msgs[i] := Msgs[i+1];
8435 else
8436 Inc(NextMsg);
8437 end else
8438 if NextMsg = 0 then
8439 Inc(NextMsg);
8441 Msgs[NextMsg-1] := Text;
8442 CurValue := 0;
8443 MaxValue := Max;
8444 ShowCount := 0;
8445 PBarWasHere := false;
8446 end;
8448 g_ActiveWindow := nil;
8449 ProcessLoading(True);
8450 end;
8452 procedure g_Game_StepLoading(Value: Integer = -1);
8453 begin
8454 with LoadingStat do
8455 begin
8456 if Value = -1 then
8457 begin
8458 Inc(CurValue);
8459 Inc(ShowCount);
8461 else
8462 CurValue := Value;
8464 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8465 begin
8466 ShowCount := 0;
8467 ProcessLoading(False);
8468 end;
8469 end;
8470 end;
8472 procedure g_Game_ClearLoading();
8474 len: Word;
8475 begin
8476 with LoadingStat do
8477 begin
8478 CurValue := 0;
8479 MaxValue := 0;
8480 ShowCount := 0;
8481 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8482 if len < 1 then len := 1;
8483 SetLength(Msgs, len);
8484 for len := Low(Msgs) to High(Msgs) do
8485 Msgs[len] := '';
8486 NextMsg := 0;
8487 PBarWasHere := false;
8488 end;
8489 end;
8491 procedure Parse_Params(var pars: TParamStrValues);
8493 i: Integer;
8494 s: String;
8495 begin
8496 SetLength(pars, 0);
8497 i := 1;
8498 while i <= ParamCount do
8499 begin
8500 s := ParamStr(i);
8501 if (Length(s) > 1) and (s[1] = '-') then
8502 begin
8503 if (Length(s) > 2) and (s[2] = '-') then
8504 begin // Îäèíî÷íûé ïàðàìåòð
8505 SetLength(pars, Length(pars) + 1);
8506 with pars[High(pars)] do
8507 begin
8508 Name := LowerCase(s);
8509 Value := '+';
8510 end;
8512 else
8513 if (i < ParamCount) then
8514 begin // Ïàðàìåòð ñî çíà÷åíèåì
8515 Inc(i);
8516 SetLength(pars, Length(pars) + 1);
8517 with pars[High(pars)] do
8518 begin
8519 Name := LowerCase(s);
8520 Value := LowerCase(ParamStr(i));
8521 end;
8522 end;
8523 end;
8525 Inc(i);
8526 end;
8527 end;
8529 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8531 i: Integer;
8532 begin
8533 Result := '';
8534 for i := 0 to High(pars) do
8535 if pars[i].Name = aName then
8536 begin
8537 Result := pars[i].Value;
8538 Break;
8539 end;
8540 end;
8542 procedure g_Game_Process_Params();
8544 pars: TParamStrValues;
8545 map: String;
8546 GMode, n: Byte;
8547 LimT, LimS: Integer;
8548 Opt: TGameOptions;
8549 Lives: Integer;
8550 s: String;
8551 Port: Integer;
8552 ip: String;
8553 F: TextFile;
8554 begin
8555 Parse_Params(pars);
8557 // Debug mode:
8558 s := Find_Param_Value(pars, '--debug');
8559 if (s <> '') then
8560 begin
8561 g_Game_SetDebugMode();
8562 s := Find_Param_Value(pars, '--netdump');
8563 if (s <> '') then
8564 NetDump := True;
8565 end;
8567 // Connect when game loads
8568 ip := Find_Param_Value(pars, '-connect');
8570 if ip <> '' then
8571 begin
8572 s := Find_Param_Value(pars, '-port');
8573 if (s = '') or not TryStrToInt(s, Port) then
8574 Port := 25666;
8576 s := Find_Param_Value(pars, '-pw');
8578 g_Game_StartClient(ip, Port, s);
8579 Exit;
8580 end;
8582 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8583 if (s <> '') then
8584 begin
8585 gDefaultMegawadStart := s;
8586 end;
8588 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8589 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8590 begin
8591 gDefaultMegawadStart := DF_Default_Megawad_Start;
8592 end;
8594 // Start map when game loads:
8595 map := LowerCase(Find_Param_Value(pars, '-map'));
8596 if isWadPath(map) then
8597 begin
8598 // Game mode:
8599 s := Find_Param_Value(pars, '-gm');
8600 GMode := g_Game_TextToMode(s);
8601 if GMode = GM_NONE then GMode := GM_DM;
8602 if GMode = GM_SINGLE then GMode := GM_COOP;
8604 // Time limit:
8605 s := Find_Param_Value(pars, '-limt');
8606 if (s = '') or (not TryStrToInt(s, LimT)) then
8607 LimT := 0;
8608 if LimT < 0 then
8609 LimT := 0;
8611 // Score limit:
8612 s := Find_Param_Value(pars, '-lims');
8613 if (s = '') or (not TryStrToInt(s, LimS)) then
8614 LimS := 0;
8615 if LimS < 0 then
8616 LimS := 0;
8618 // Lives limit:
8619 s := Find_Param_Value(pars, '-lives');
8620 if (s = '') or (not TryStrToInt(s, Lives)) then
8621 Lives := 0;
8622 if Lives < 0 then
8623 Lives := 0;
8625 // Options:
8626 s := Find_Param_Value(pars, '-opt');
8627 if (s = '')
8628 then Opt := gsGameFlags
8629 else Opt := TGameOptions(StrToIntDef(s, 0));
8631 // Close after map:
8632 s := Find_Param_Value(pars, '--close');
8633 if (s <> '') then
8634 gMapOnce := True;
8636 // Override map to test:
8637 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8638 if s <> '' then
8639 begin
8640 if e_IsValidResourceName(s) then
8641 e_FindResource(AllMapDirs, s);
8642 gTestMap := ExpandFileName(s);
8643 end;
8645 // Delete test map after play:
8646 s := Find_Param_Value(pars, '--testdelete');
8647 if (s <> '') then
8648 begin
8649 //gMapToDelete := MapsDir + map;
8650 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8651 Halt(1);
8652 end;
8654 // Delete temporary WAD after play:
8655 s := Find_Param_Value(pars, '--tempdelete');
8656 if (s <> '') and (gTestMap <> '') then
8657 begin
8658 gMapToDelete := gTestMap;
8659 gTempDelete := True;
8660 end;
8662 // Number of players:
8663 s := Find_Param_Value(pars, '-pl');
8664 if (s = '') then
8665 n := DEFAULT_PLAYERS
8666 else
8667 n := StrToIntDef(s, DEFAULT_PLAYERS);
8669 // Start:
8670 s := Find_Param_Value(pars, '-port');
8671 if (s = '') or not TryStrToInt(s, Port)
8672 then g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8673 else g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8674 end;
8676 // Execute script when game loads:
8677 s := Find_Param_Value(pars, '-exec');
8678 if s <> '' then
8679 begin
8680 // if not isWadPath(s) then
8681 // s := GameDir + '/' + s;
8683 {$I-}
8684 AssignFile(F, s);
8685 Reset(F);
8686 if IOResult <> 0 then
8687 begin
8688 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8689 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8690 CloseFile(F);
8691 Exit;
8692 end;
8693 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8694 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8696 while not EOF(F) do
8697 begin
8698 ReadLn(F, s);
8699 if IOResult <> 0 then
8700 begin
8701 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8702 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8703 CloseFile(F);
8704 Exit;
8705 end;
8706 if Pos('#', s) <> 1 then // script comment
8707 g_Console_Process(s, True);
8708 end;
8710 CloseFile(F);
8711 {$I+}
8712 end;
8714 SetLength(pars, 0);
8715 end;
8717 initialization
8718 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8719 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8720 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8721 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8723 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8724 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8725 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8726 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8728 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8729 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8731 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8732 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8734 {$IFDEF ENABLE_HOLMES}
8735 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8736 {$ENDIF}
8738 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8740 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8741 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8743 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8744 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8746 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8747 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8749 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8750 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8751 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8752 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
8753 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8754 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8755 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8756 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8757 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8759 finalization
8760 profileFrameDraw.Free();
8762 end.