DEADSOFTWARE

added some new msgs for friendlyfire options
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF,
23 g_basic, g_player, e_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameSettings = record
29 GameType: Byte;
30 GameMode: Byte;
31 TimeLimit: Word;
32 GoalLimit: Word;
33 WarmupTime: Word;
34 SpawnInvul: Word;
35 ItemRespawnTime: Word;
36 MaxLives: Byte;
37 Options: LongWord;
38 WAD: String;
39 end;
41 TGameEvent = record
42 Name: String;
43 Command: String;
44 end;
46 TDelayedEvent = record
47 Pending: Boolean;
48 Time: LongWord;
49 DEType: Byte;
50 DENum: Integer;
51 DEStr: String;
52 end;
54 TChatSound = record
55 Sound: TPlayableSound;
56 Tags: Array of String;
57 FullWord: Boolean;
58 end;
60 TPlayerSettings = record
61 Name: String;
62 Model: String;
63 Color: TRGB;
64 Team: Byte;
65 end;
67 TMegaWADInfo = record
68 Name: String;
69 Description: String;
70 Author: String;
71 Pic: String;
72 end;
74 THearPoint = record
75 Active: Boolean;
76 Coords: TDFPoint;
77 end;
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Draw();
89 procedure g_Game_Quit();
90 procedure g_Game_SetupScreenSize();
91 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
92 function g_Game_ModeToText(Mode: Byte): string;
93 function g_Game_TextToMode(Mode: string): Byte;
94 procedure g_Game_ExecuteEvent(Name: String);
95 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
96 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
97 procedure g_Game_RemovePlayer();
98 procedure g_Game_Spectate();
99 procedure g_Game_SpectateCenterView();
100 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
101 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
102 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
103 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
104 procedure g_Game_Restart();
105 procedure g_Game_RestartLevel();
106 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
107 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
108 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
109 procedure g_Game_ChangeMap(const MapPath: String);
110 procedure g_Game_ExitLevel(const Map: AnsiString);
111 function g_Game_GetFirstMap(WAD: String): String;
112 function g_Game_GetNextMap(): String;
113 procedure g_Game_NextLevel();
114 procedure g_Game_Pause(Enable: Boolean);
115 procedure g_Game_HolmesPause(Enable: Boolean);
116 procedure g_Game_InGameMenu(Show: Boolean);
117 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
118 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
119 procedure g_Game_Message(Msg: String; Time: Word);
120 procedure g_Game_LoadMapList(FileName: String);
121 procedure g_Game_PauseAllSounds(Enable: Boolean);
122 procedure g_Game_StopAllSounds(all: Boolean);
123 procedure g_Game_UpdateTriggerSounds();
124 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
125 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
126 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
127 procedure g_Game_Announce_KillCombo(Param: Integer);
128 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
129 procedure g_Game_StartVote(Command, Initiator: string);
130 procedure g_Game_CheckVote;
131 procedure g_TakeScreenShot(Filename: string = '');
132 procedure g_FatalError(Text: String);
133 procedure g_SimpleError(Text: String);
134 function g_Game_IsTestMap(): Boolean;
135 procedure g_Game_DeleteTestMap();
136 procedure GameCVars(P: SSArray);
137 procedure PlayerSettingsCVars(P: SSArray);
138 procedure SystemCommands(P: SSArray);
139 procedure GameCommands(P: SSArray);
140 procedure GameCheats(P: SSArray);
141 procedure DebugCommands(P: SSArray);
142 procedure g_Game_Process_Params;
143 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
144 procedure g_Game_StepLoading(Value: Integer = -1);
145 procedure g_Game_ClearLoading();
146 procedure g_Game_SetDebugMode();
147 procedure DrawLoadingStat();
148 procedure DrawMenuBackground(tex: AnsiString);
150 { procedure SetWinPause(Enable: Boolean); }
152 const
153 GAME_TICK = 28;
155 LOADING_SHOW_STEP = 100;
156 LOADING_INTERLINE = 20;
158 GT_NONE = 0;
159 GT_SINGLE = 1;
160 GT_CUSTOM = 2;
161 GT_SERVER = 3;
162 GT_CLIENT = 4;
164 GM_NONE = 0;
165 GM_DM = 1;
166 GM_TDM = 2;
167 GM_CTF = 3;
168 GM_COOP = 4;
169 GM_SINGLE = 5;
171 MESSAGE_DIKEY = WM_USER + 1;
173 EXIT_QUIT = 1;
174 EXIT_SIMPLE = 2;
175 EXIT_RESTART = 3;
176 EXIT_ENDLEVELSINGLE = 4;
177 EXIT_ENDLEVELCUSTOM = 5;
179 GAME_OPTION_RESERVED = 1;
180 GAME_OPTION_TEAMDAMAGE = 2;
181 GAME_OPTION_ALLOWEXIT = 4;
182 GAME_OPTION_WEAPONSTAY = 8;
183 GAME_OPTION_MONSTERS = 16;
184 GAME_OPTION_BOTVSPLAYER = 32;
185 GAME_OPTION_BOTVSMONSTER = 64;
186 GAME_OPTION_DMKEYS = 128;
187 GAME_OPTION_TEAMHITTRACE = 256;
188 GAME_OPTION_TEAMHITPROJECTILE = 512;
189 GAME_OPTION_TEAMABSORBDAMAGE = 1024;
191 STATE_NONE = 0;
192 STATE_MENU = 1;
193 STATE_FOLD = 2;
194 STATE_INTERCUSTOM = 3;
195 STATE_INTERSINGLE = 4;
196 STATE_INTERTEXT = 5;
197 STATE_INTERPIC = 6;
198 STATE_ENDPIC = 7;
199 STATE_SLIST = 8;
201 LMS_RESPAWN_NONE = 0;
202 LMS_RESPAWN_WARMUP = 1;
203 LMS_RESPAWN_FINAL = 2;
205 SPECT_NONE = 0;
206 SPECT_STATS = 1;
207 SPECT_MAPVIEW = 2;
208 SPECT_PLAYERS = 3;
210 DE_GLOBEVENT = 0;
211 DE_BFGHIT = 1;
212 DE_KILLCOMBO = 2;
213 DE_BODYKILL = 3;
215 ANNOUNCE_NONE = 0;
216 ANNOUNCE_ME = 1;
217 ANNOUNCE_MEPLUS = 2;
218 ANNOUNCE_ALL = 3;
220 CONFIG_FILENAME = 'Doom2DF.cfg';
222 TEST_MAP_NAME = '$$$_TEST_$$$';
224 STD_PLAYER_MODEL = 'Doomer';
226 {$IFDEF HEADLESS}
227 DEFAULT_PLAYERS = 0;
228 {$ELSE}
229 DEFAULT_PLAYERS = 1;
230 {$ENDIF}
232 STATFILE_VERSION = $03;
234 var
235 gStdFont: DWORD;
236 gGameSettings: TGameSettings;
237 gPlayer1Settings: TPlayerSettings;
238 gPlayer2Settings: TPlayerSettings;
239 gGameOn: Boolean;
240 gPlayerScreenSize: TDFPoint;
241 gPlayer1ScreenCoord: TDFPoint;
242 gPlayer2ScreenCoord: TDFPoint;
243 gPlayer1: TPlayer = nil;
244 gPlayer2: TPlayer = nil;
245 gPlayerDrawn: TPlayer = nil;
246 gTime: LongWord;
247 gLerpFactor: Single = 1.0;
248 gSwitchGameMode: Byte = GM_DM;
249 gHearPoint1, gHearPoint2: THearPoint;
250 gSoundEffectsDF: Boolean = False;
251 gSoundTriggerTime: Word = 0;
252 gAnnouncer: Integer = ANNOUNCE_NONE;
253 goodsnd: array[0..3] of TPlayableSound;
254 killsnd: array[0..3] of TPlayableSound;
255 hahasnd: array[0..2] of TPlayableSound;
256 sound_get_flag: array[0..1] of TPlayableSound;
257 sound_lost_flag: array[0..1] of TPlayableSound;
258 sound_ret_flag: array[0..1] of TPlayableSound;
259 sound_cap_flag: array[0..1] of TPlayableSound;
260 gBodyKillEvent: Integer = -1;
261 gDefInterTime: ShortInt = -1;
262 gInterEndTime: LongWord = 0;
263 gInterTime: LongWord = 0;
264 gServInterTime: Byte = 0;
265 gGameStartTime: LongWord = 0;
266 gTotalMonsters: Integer = 0;
267 gPauseMain: Boolean = false;
268 gPauseHolmes: Boolean = false;
269 gShowTime: Boolean = False;
270 gShowFPS: Boolean = False;
271 gShowGoals: Boolean = True;
272 gShowStat: Boolean = True;
273 gShowPIDs: Boolean = False;
274 gShowKillMsg: Boolean = True;
275 gShowLives: Boolean = True;
276 gShowPing: Boolean = False;
277 gShowMap: Boolean = False;
278 gExit: Byte = 0;
279 gState: Byte = STATE_NONE;
280 sX, sY: Integer;
281 sWidth, sHeight: Word;
282 gSpectMode: Byte = SPECT_NONE;
283 gSpectHUD: Boolean = True;
284 gSpectKeyPress: Boolean = False;
285 gSpectX: Integer = 0;
286 gSpectY: Integer = 0;
287 gSpectStep: Byte = 8;
288 gSpectViewTwo: Boolean = False;
289 gSpectPID1: Integer = -1;
290 gSpectPID2: Integer = -1;
291 gSpectAuto: Boolean = False;
292 gSpectAutoNext: LongWord;
293 gSpectAutoStepX: Integer;
294 gSpectAutoStepY: Integer;
295 gMusic: TMusic = nil;
296 gLoadGameMode: Boolean;
297 gCheats: Boolean = False;
298 gMapOnce: Boolean = False;
299 gMapToDelete: String;
300 gTempDelete: Boolean = False;
301 gLastMap: Boolean = False;
302 gScreenWidth: Word;
303 gScreenHeight: Word;
304 gResolutionChange: Boolean = False;
305 gRC_Width, gRC_Height: Integer;
306 gRC_FullScreen, gRC_Maximized: Boolean;
307 gLanguageChange: Boolean = False;
308 gDebugMode: Boolean = False;
309 g_debug_Sounds: Boolean = False;
310 g_debug_Frames: Boolean = False;
311 g_debug_WinMsgs: Boolean = False;
312 g_debug_MonsterOff: Boolean = False;
313 g_debug_BotAIOff: Byte = 0;
314 g_debug_HealthBar: Boolean = False;
315 g_Debug_Player: Boolean = False;
316 gCoopMonstersKilled: Word = 0;
317 gCoopSecretsFound: Word = 0;
318 gCoopTotalMonstersKilled: Word = 0;
319 gCoopTotalSecretsFound: Word = 0;
320 gCoopTotalMonsters: Word = 0;
321 gCoopTotalSecrets: Word = 0;
322 gStatsOff: Boolean = False;
323 gStatsPressed: Boolean = False;
324 gExitByTrigger: Boolean = False;
325 gNextMap: String = '';
326 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
327 gLMSRespawnTime: Cardinal = 0;
328 gLMSSoftSpawn: Boolean = False;
329 gMissionFailed: Boolean = False;
330 gVoteInProgress: Boolean = False;
331 gVotePassed: Boolean = False;
332 gVoteCommand: string = '';
333 gVoteTimer: Cardinal = 0;
334 gVoteCmdTimer: Cardinal = 0;
335 gVoteCount: Integer = 0;
336 gVoteTimeout: Cardinal = 30;
337 gVoted: Boolean = False;
338 gVotesEnabled: Boolean = True;
339 gEvents: Array of TGameEvent;
340 gDelayedEvents: Array of TDelayedEvent;
341 gUseChatSounds: Boolean = True;
342 gChatSounds: Array of TChatSound;
343 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
344 gInterReadyCount: Integer = 0;
346 g_dbg_ignore_bounds: Boolean = false;
347 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
348 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
350 // move button values:
351 // bits 0-1: l/r state:
352 // 0: neither left, nor right pressed
353 // 1: left pressed
354 // 2: right pressed
355 // bits 4-5: l/r state when strafe was pressed
356 P1MoveButton: Byte = 0;
357 P2MoveButton: Byte = 0;
359 g_profile_frame_update: Boolean = false;
360 g_profile_frame_draw: Boolean = false;
361 g_profile_collision: Boolean = false;
362 g_profile_los: Boolean = false;
363 g_profile_history_size: Integer = 1000;
365 g_rlayer_back: Boolean = true;
366 g_rlayer_step: Boolean = true;
367 g_rlayer_wall: Boolean = true;
368 g_rlayer_door: Boolean = true;
369 g_rlayer_acid1: Boolean = true;
370 g_rlayer_acid2: Boolean = true;
371 g_rlayer_water: Boolean = true;
372 g_rlayer_fore: Boolean = true;
375 procedure g_ResetDynlights ();
376 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
377 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
379 function conIsCheatsEnabled (): Boolean; inline;
380 function gPause (): Boolean; inline;
383 implementation
385 uses
386 {$INCLUDE ../nogl/noGLuses.inc}
387 {$IFDEF ENABLE_HOLMES}
388 g_holmes,
389 {$ENDIF}
390 e_texture, e_res, g_textures, g_window, g_menu,
391 e_input, e_log, g_console, g_items, g_map, g_panel,
392 g_playermodel, g_gfx, g_options, Math,
393 g_triggers, g_monsters, e_sound, CONFIG,
394 g_language, g_net, g_main, g_phys,
395 ENet, e_msg, g_netmsg, g_netmaster,
396 sfs, wadreader, g_system;
399 var
400 hasPBarGfx: Boolean = false;
403 // ////////////////////////////////////////////////////////////////////////// //
404 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
407 // ////////////////////////////////////////////////////////////////////////// //
408 function conIsCheatsEnabled (): Boolean; inline;
409 begin
410 result := false;
411 if g_Game_IsNet then exit;
412 if not gDebugMode then
413 begin
414 //if not gCheats then exit;
415 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
416 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
417 end;
418 result := true;
419 end;
422 // ////////////////////////////////////////////////////////////////////////// //
423 var
424 profileFrameDraw: TProfiler = nil;
427 // ////////////////////////////////////////////////////////////////////////// //
428 type
429 TDynLight = record
430 x, y, radius: Integer;
431 r, g, b, a: Single;
432 exploCount: Integer;
433 exploRadius: Integer;
434 end;
436 var
437 g_dynLights: array of TDynLight = nil;
438 g_dynLightCount: Integer = 0;
439 g_playerLight: Boolean = false;
441 procedure g_ResetDynlights ();
442 var
443 lnum, idx: Integer;
444 begin
445 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
446 lnum := 0;
447 for idx := 0 to g_dynLightCount-1 do
448 begin
449 if g_dynLights[idx].exploCount = -666 then
450 begin
451 // skip it
452 end
453 else
454 begin
455 // explosion
456 Inc(g_dynLights[idx].exploCount);
457 if (g_dynLights[idx].exploCount < 10) then
458 begin
459 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
460 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
461 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
462 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
463 Inc(lnum);
464 end;
465 end;
466 end;
467 g_dynLightCount := lnum;
468 end;
470 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
471 begin
472 if not gwin_has_stencil then exit;
473 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
474 g_dynLights[g_dynLightCount].x := x;
475 g_dynLights[g_dynLightCount].y := y;
476 g_dynLights[g_dynLightCount].radius := radius;
477 g_dynLights[g_dynLightCount].r := r;
478 g_dynLights[g_dynLightCount].g := g;
479 g_dynLights[g_dynLightCount].b := b;
480 g_dynLights[g_dynLightCount].a := a;
481 g_dynLights[g_dynLightCount].exploCount := -666;
482 Inc(g_dynLightCount);
483 end;
485 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
486 begin
487 if not gwin_has_stencil then exit;
488 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
489 g_dynLights[g_dynLightCount].x := x;
490 g_dynLights[g_dynLightCount].y := y;
491 g_dynLights[g_dynLightCount].radius := 0;
492 g_dynLights[g_dynLightCount].exploRadius := radius;
493 g_dynLights[g_dynLightCount].r := r;
494 g_dynLights[g_dynLightCount].g := g;
495 g_dynLights[g_dynLightCount].b := b;
496 g_dynLights[g_dynLightCount].a := 0;
497 g_dynLights[g_dynLightCount].exploCount := 0;
498 Inc(g_dynLightCount);
499 end;
502 // ////////////////////////////////////////////////////////////////////////// //
503 function calcProfilesHeight (prof: TProfiler): Integer;
504 begin
505 result := 0;
506 if (prof = nil) then exit;
507 if (length(prof.bars) = 0) then exit;
508 result := length(prof.bars)*(16+2);
509 end;
511 // returns width
512 function drawProfiles (x, y: Integer; prof: TProfiler): Integer;
513 var
514 wdt, hgt: Integer;
515 yy: Integer;
516 ii: Integer;
517 begin
518 result := 0;
519 if (prof = nil) then exit;
520 // gScreenWidth
521 if (length(prof.bars) = 0) then exit;
522 wdt := 192;
523 hgt := calcProfilesHeight(prof);
524 if (x < 0) then x := gScreenWidth-(wdt-1)+x;
525 if (y < 0) then y := gScreenHeight-(hgt-1)+y;
526 // background
527 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
528 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
529 e_DarkenQuadWH(x, y, wdt, hgt, 150);
530 // title
531 yy := y+2;
532 for ii := 0 to High(prof.bars) do
533 begin
534 e_TextureFontPrintEx(x+2+4*prof.bars[ii].level, yy, Format('%s: %d', [prof.bars[ii].name, prof.bars[ii].value]), gStdFont, 255, 255, 0, 1, false);
535 Inc(yy, 16+2);
536 end;
537 result := wdt;
538 end;
541 // ////////////////////////////////////////////////////////////////////////// //
542 type
543 TEndCustomGameStat = record
544 PlayerStat: TPlayerStatArray;
545 TeamStat: TTeamStat;
546 GameTime: LongWord;
547 GameMode: Byte;
548 Map, MapName: String;
549 end;
551 TEndSingleGameStat = record
552 PlayerStat: Array [0..1] of record
553 Kills: Integer;
554 Secrets: Integer;
555 end;
556 GameTime: LongWord;
557 TwoPlayers: Boolean;
558 TotalSecrets: Integer;
559 end;
561 TLoadingStat = record
562 CurValue: Integer;
563 MaxValue: Integer;
564 ShowCount: Integer;
565 Msgs: Array of String;
566 NextMsg: Word;
567 PBarWasHere: Boolean; // did we draw a progress bar for this message?
568 end;
570 TParamStrValue = record
571 Name: String;
572 Value: String;
573 end;
575 TParamStrValues = Array of TParamStrValue;
577 const
578 INTER_ACTION_TEXT = 1;
579 INTER_ACTION_PIC = 2;
580 INTER_ACTION_MUSIC = 3;
582 var
583 FPS, UPS: Word;
584 FPSCounter, UPSCounter: Word;
585 FPSTime, UPSTime: LongWord;
586 DataLoaded: Boolean = False;
587 IsDrawStat: Boolean = False;
588 CustomStat: TEndCustomGameStat;
589 SingleStat: TEndSingleGameStat;
590 LoadingStat: TLoadingStat;
591 EndingGameCounter: Byte = 0;
592 MessageText: String;
593 MessageTime: Word;
594 MessageLineLength: Integer = 80;
595 MapList: SSArray = nil;
596 MapIndex: Integer = -1;
597 InterReadyTime: Integer = -1;
598 StatShotDone: Boolean = False;
599 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
600 StatDate: string = '';
601 MegaWAD: record
602 info: TMegaWADInfo;
603 endpic: String;
604 endmus: String;
605 res: record
606 text: Array of ShortString;
607 anim: Array of ShortString;
608 pic: Array of ShortString;
609 mus: Array of ShortString;
610 end;
611 triggers: Array of record
612 event: ShortString;
613 actions: Array of record
614 action, p1, p2: Integer;
615 end;
616 end;
617 cur_trigger: Integer;
618 cur_action: Integer;
619 end;
620 //InterPic: String;
621 InterText: record
622 lines: SSArray;
623 img: String;
624 cur_line: Integer;
625 cur_char: Integer;
626 counter: Integer;
627 endtext: Boolean;
628 end;
630 function Compare(a, b: TPlayerStat): Integer;
631 begin
632 if a.Spectator then Result := 1
633 else if b.Spectator then Result := -1
634 else if a.Frags < b.Frags then Result := 1
635 else if a.Frags > b.Frags then Result := -1
636 else if a.Deaths < b.Deaths then Result := -1
637 else if a.Deaths > b.Deaths then Result := 1
638 else if a.Kills < b.Kills then Result := -1
639 else Result := 1;
640 end;
642 procedure SortGameStat(var stat: TPlayerStatArray);
643 var
644 I, J: Integer;
645 T: TPlayerStat;
646 begin
647 if stat = nil then Exit;
649 for I := High(stat) downto Low(stat) do
650 for J := Low(stat) to High(stat) - 1 do
651 if Compare(stat[J], stat[J + 1]) = 1 then
652 begin
653 T := stat[J];
654 stat[J] := stat[J + 1];
655 stat[J + 1] := T;
656 end;
657 end;
659 // saves a shitty CSV containing the game stats passed to it
660 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
661 var
662 s: TextFile;
663 dir, fname, map, mode, etime: String;
664 I: Integer;
665 begin
666 try
667 dir := e_GetWriteableDir(StatsDirs);
668 // stats are placed in stats/yy/mm/dd/*.csv
669 fname := e_CatPath(dir, Path);
670 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
671 fname := e_CatPath(fname, StatFilename + '.csv');
672 AssignFile(s, fname);
673 try
674 Rewrite(s);
675 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
676 if g_Game_IsNet then fname := NetServerName else fname := '';
677 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
678 mode := g_Game_ModeToText(Stat.GameMode);
679 etime := Format('%d:%.2d:%.2d', [
680 Stat.GameTime div 1000 div 3600,
681 (Stat.GameTime div 1000 div 60) mod 60,
682 Stat.GameTime div 1000 mod 60
683 ]);
684 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
685 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
686 STATFILE_VERSION,
687 StatDate,
688 dquoteStr(fname),
689 dquoteStr(map),
690 mode,
691 gGameSettings.TimeLimit,
692 gGameSettings.GoalLimit,
693 gGameSettings.Options,
694 etime,
695 Length(Stat.PlayerStat)
696 ]));
697 // line 2: game specific shit
698 // if it's a team game: red score, blue score
699 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
700 // otherwise nothing
701 if Stat.GameMode in [GM_TDM, GM_CTF] then
702 WriteLn(s,
703 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Goals, Stat.TeamStat[TEAM_BLUE].Goals]))
704 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
705 WriteLn(s,
706 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
707 // lines 3-...: team, player name, frags, deaths
708 WriteLn(s, 'team,name,frags,deaths');
709 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
710 with Stat.PlayerStat[I] do
711 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
712 except
713 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
714 end;
715 except
716 g_Console_Add('could not create gamestats file "' + fname + '"');
717 end;
718 CloseFile(s);
719 end;
721 function g_Game_ModeToText(Mode: Byte): string;
722 begin
723 Result := '';
724 case Mode of
725 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
726 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
727 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
728 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
729 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
730 end;
731 end;
733 function g_Game_TextToMode(Mode: string): Byte;
734 begin
735 Result := GM_NONE;
736 Mode := UpperCase(Mode);
737 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
738 begin
739 Result := GM_DM;
740 Exit;
741 end;
742 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
743 begin
744 Result := GM_TDM;
745 Exit;
746 end;
747 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
748 begin
749 Result := GM_CTF;
750 Exit;
751 end;
752 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
753 begin
754 Result := GM_COOP;
755 Exit;
756 end;
757 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
758 begin
759 Result := GM_SINGLE;
760 Exit;
761 end;
762 end;
764 function g_Game_IsNet(): Boolean;
765 begin
766 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
767 end;
769 function g_Game_IsServer(): Boolean;
770 begin
771 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
772 end;
774 function g_Game_IsClient(): Boolean;
775 begin
776 Result := (gGameSettings.GameType = GT_CLIENT);
777 end;
779 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
780 var
781 w: TWADFile;
782 cfg: TConfig;
783 p: Pointer;
784 len: Integer;
785 begin
786 Result.name := ExtractFileName(WAD);
787 Result.description := '';
788 Result.author := '';
790 w := TWADFile.Create();
791 w.ReadFile(WAD);
793 if not w.GetResource('INTERSCRIPT', p, len) then
794 begin
795 w.Free();
796 Exit;
797 end;
799 cfg := TConfig.CreateMem(p, len);
800 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
801 Result.description := cfg.ReadStr('megawad', 'description', '');
802 Result.author := cfg.ReadStr('megawad', 'author', '');
803 Result.pic := cfg.ReadStr('megawad', 'pic', '');
804 cfg.Free();
806 FreeMem(p);
807 end;
809 procedure g_Game_FreeWAD();
810 var
811 a: Integer;
812 begin
813 for a := 0 to High(MegaWAD.res.pic) do
814 if MegaWAD.res.pic[a] <> '' then
815 g_Texture_Delete(MegaWAD.res.pic[a]);
817 for a := 0 to High(MegaWAD.res.mus) do
818 if MegaWAD.res.mus[a] <> '' then
819 g_Sound_Delete(MegaWAD.res.mus[a]);
821 MegaWAD.res.pic := nil;
822 MegaWAD.res.text := nil;
823 MegaWAD.res.anim := nil;
824 MegaWAD.res.mus := nil;
825 MegaWAD.triggers := nil;
827 g_Texture_Delete('TEXTURE_endpic');
828 g_Sound_Delete('MUSIC_endmus');
830 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
831 gGameSettings.WAD := '';
832 end;
834 procedure g_Game_LoadWAD(WAD: string);
835 var
836 w: TWADFile;
837 cfg: TConfig;
838 p: Pointer;
839 {b, }len: Integer;
840 s: AnsiString;
841 begin
842 g_Game_FreeWAD();
843 gGameSettings.WAD := WAD;
844 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
845 Exit;
847 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
849 w := TWADFile.Create();
850 w.ReadFile(WAD);
852 if not w.GetResource('INTERSCRIPT', p, len) then
853 begin
854 w.Free();
855 Exit;
856 end;
858 cfg := TConfig.CreateMem(p, len);
860 {b := 1;
861 while True do
862 begin
863 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
864 if s = '' then Break;
865 b := b+1;
867 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
868 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
870 g_Texture_CreateWADEx(s, s);
871 end;
873 b := 1;
874 while True do
875 begin
876 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
877 if s = '' then Break;
878 b := b+1;
880 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
881 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
883 g_Music_CreateWADEx(s, s);
884 end;}
886 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
887 if MegaWAD.endpic <> '' then
888 begin
889 TEXTUREFILTER := GL_LINEAR;
890 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
891 g_Texture_CreateWADEx('TEXTURE_endpic', s);
892 TEXTUREFILTER := GL_NEAREST;
893 end;
894 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
895 if MegaWAD.endmus <> '' then
896 begin
897 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
898 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
899 end;
901 cfg.Free();
902 FreeMem(p);
903 w.Free();
904 end;
906 {procedure start_trigger(t: string);
907 begin
908 end;
910 function next_trigger(): Boolean;
911 begin
912 end;}
914 procedure DisableCheats();
915 begin
916 MAX_RUNVEL := 8;
917 VEL_JUMP := 10;
918 gFly := False;
920 if gPlayer1 <> nil then gPlayer1.GodMode := False;
921 if gPlayer2 <> nil then gPlayer2.GodMode := False;
922 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
923 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
925 {$IF DEFINED(D2F_DEBUG)}
926 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
927 gAimLine := g_dbg_aimline_on;
928 {$ENDIF}
929 end;
931 procedure g_Game_ExecuteEvent(Name: String);
932 var
933 a: Integer;
934 begin
935 if Name = '' then
936 Exit;
937 if gEvents = nil then
938 Exit;
939 for a := 0 to High(gEvents) do
940 if gEvents[a].Name = Name then
941 begin
942 if gEvents[a].Command <> '' then
943 g_Console_Process(gEvents[a].Command, True);
944 break;
945 end;
946 end;
948 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
949 var
950 a, n: Integer;
951 begin
952 n := -1;
953 if gDelayedEvents <> nil then
954 for a := 0 to High(gDelayedEvents) do
955 if not gDelayedEvents[a].Pending then
956 begin
957 n := a;
958 break;
959 end;
960 if n = -1 then
961 begin
962 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
963 n := High(gDelayedEvents);
964 end;
965 gDelayedEvents[n].Pending := True;
966 gDelayedEvents[n].DEType := DEType;
967 gDelayedEvents[n].DENum := Num;
968 gDelayedEvents[n].DEStr := Str;
969 if DEType = DE_GLOBEVENT then
970 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
971 else
972 gDelayedEvents[n].Time := gTime + Time;
973 Result := n;
974 end;
976 procedure EndGame();
977 var
978 a: Integer;
979 FileName: string;
980 t: TDateTime;
981 begin
982 if g_Game_IsNet and g_Game_IsServer then
983 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
985 // Ñòîï èãðà:
986 gPauseMain := false;
987 gPauseHolmes := false;
988 gGameOn := false;
990 g_Game_StopAllSounds(False);
992 MessageTime := 0;
993 MessageText := '';
995 EndingGameCounter := 0;
996 g_ActiveWindow := nil;
998 gLMSRespawn := LMS_RESPAWN_NONE;
999 gLMSRespawnTime := 0;
1001 case gExit of
1002 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1003 begin
1004 g_Game_Free();
1006 if gMapOnce then
1007 begin // Ýòî áûë òåñò
1008 g_Game_Quit();
1009 end
1010 else
1011 begin // Âûõîä â ãëàâíîå ìåíþ
1012 gMusic.SetByName('MUSIC_MENU');
1013 gMusic.Play();
1014 if gState <> STATE_SLIST then
1015 begin
1016 g_GUI_ShowWindow('MainMenu');
1017 gState := STATE_MENU;
1018 end else
1019 begin
1020 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1021 slReturnPressed := True;
1022 if g_Net_Slist_Fetch(slCurrent) then
1023 begin
1024 if slCurrent = nil then
1025 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1026 end
1027 else
1028 slWaitStr := _lc[I_NET_SLIST_ERROR];
1029 g_Serverlist_GenerateTable(slCurrent, slTable);
1030 end;
1032 g_Game_ExecuteEvent('ongameend');
1033 end;
1034 end;
1036 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
1037 begin
1038 if not g_Game_IsClient then g_Game_Restart();
1039 end;
1041 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1042 begin
1043 // Ñòàòèñòèêà Ñâîåé èãðû:
1044 FileName := g_ExtractWadName(gMapInfo.Map);
1046 CustomStat.GameTime := gTime;
1047 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1048 CustomStat.MapName := gMapInfo.Name;
1049 CustomStat.GameMode := gGameSettings.GameMode;
1050 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1051 CustomStat.TeamStat := gTeamStat;
1053 CustomStat.PlayerStat := nil;
1055 // Ñòàòèñòèêà èãðîêîâ:
1056 if gPlayers <> nil then
1057 begin
1058 for a := 0 to High(gPlayers) do
1059 if gPlayers[a] <> nil then
1060 begin
1061 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1062 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1063 begin
1064 Num := a;
1065 Name := gPlayers[a].Name;
1066 Frags := gPlayers[a].Frags;
1067 Deaths := gPlayers[a].Death;
1068 Kills := gPlayers[a].Kills;
1069 Team := gPlayers[a].Team;
1070 Color := gPlayers[a].Model.Color;
1071 Spectator := gPlayers[a].FSpectator;
1072 end;
1073 end;
1075 SortGameStat(CustomStat.PlayerStat);
1077 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1078 begin
1079 t := Now;
1080 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1081 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1082 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1083 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1084 if gSaveStats then
1085 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1086 end;
1088 StatShotDone := False;
1089 end;
1091 g_Game_ExecuteEvent('onmapend');
1092 if not g_Game_IsClient then g_Player_ResetReady;
1093 gInterReadyCount := 0;
1095 // Çàòóõàþùèé ýêðàí:
1096 EndingGameCounter := 255;
1097 gState := STATE_FOLD;
1098 gInterTime := 0;
1099 if gDefInterTime < 0 then
1100 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1101 else
1102 gInterEndTime := gDefInterTime * 1000;
1103 end;
1105 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1106 begin
1107 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1108 SingleStat.GameTime := gTime;
1109 SingleStat.TwoPlayers := gPlayer2 <> nil;
1110 SingleStat.TotalSecrets := gSecretsCount;
1111 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1112 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1113 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1114 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1115 if SingleStat.TwoPlayers then
1116 begin
1117 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1118 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1119 end;
1121 g_Game_ExecuteEvent('onmapend');
1123 // Åñòü åùå êàðòû:
1124 if gNextMap <> '' then
1125 begin
1126 gMusic.SetByName('MUSIC_INTERMUS');
1127 gMusic.Play();
1128 gState := STATE_INTERSINGLE;
1129 e_UnpressAllKeys();
1131 g_Game_ExecuteEvent('oninter');
1132 end
1133 else // Áîëüøå íåò êàðò
1134 begin
1135 // Çàòóõàþùèé ýêðàí:
1136 EndingGameCounter := 255;
1137 gState := STATE_FOLD;
1138 end;
1139 end;
1140 end;
1142 // Îêîí÷àíèå îáðàáîòàíî:
1143 if gExit <> EXIT_QUIT then
1144 gExit := 0;
1145 end;
1147 procedure drawTime(X, Y: Integer); inline;
1148 begin
1149 e_TextureFontPrint(x, y,
1150 Format('%d:%.2d:%.2d', [
1151 gTime div 1000 div 3600,
1152 (gTime div 1000 div 60) mod 60,
1153 gTime div 1000 mod 60
1154 ]),
1155 gStdFont);
1156 end;
1158 procedure DrawStat();
1159 var
1160 pc, x, y, w, h: Integer;
1161 w1, w2, w3, w4: Integer;
1162 a, aa: Integer;
1163 cw, ch, r, g, b, rr, gg, bb: Byte;
1164 s1, s2, s3: String;
1165 _y: Integer;
1166 stat: TPlayerStatArray;
1167 wad, map: string;
1168 mapstr: string;
1169 namestr: string;
1170 begin
1171 s1 := '';
1172 s2 := '';
1173 s3 := '';
1174 pc := g_Player_GetCount;
1175 e_TextureFontGetSize(gStdFont, cw, ch);
1177 w := gScreenWidth-(gScreenWidth div 5);
1178 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1179 h := 32+ch*(11+pc)
1180 else
1181 h := 40+ch*5+(ch+8)*pc;
1182 x := (gScreenWidth div 2)-(w div 2);
1183 y := (gScreenHeight div 2)-(h div 2);
1185 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1186 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1188 drawTime(x+w-78, y+8);
1190 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1191 map := g_ExtractFileName(gMapInfo.Map);
1192 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1194 case gGameSettings.GameMode of
1195 GM_DM:
1196 begin
1197 if gGameSettings.MaxLives = 0 then
1198 s1 := _lc[I_GAME_DM]
1199 else
1200 s1 := _lc[I_GAME_LMS];
1201 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1202 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1203 end;
1205 GM_TDM:
1206 begin
1207 if gGameSettings.MaxLives = 0 then
1208 s1 := _lc[I_GAME_TDM]
1209 else
1210 s1 := _lc[I_GAME_TLMS];
1211 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1212 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1213 end;
1215 GM_CTF:
1216 begin
1217 s1 := _lc[I_GAME_CTF];
1218 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]);
1219 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1220 end;
1222 GM_COOP:
1223 begin
1224 if gGameSettings.MaxLives = 0 then
1225 s1 := _lc[I_GAME_COOP]
1226 else
1227 s1 := _lc[I_GAME_SURV];
1228 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1229 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1230 end;
1232 else
1233 begin
1234 s1 := '';
1235 s2 := '';
1236 end;
1237 end;
1239 _y := y+8;
1240 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1241 _y := _y+ch+8;
1242 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1243 _y := _y+ch+8;
1244 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1246 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1247 gStdFont, 200, 200, 200, 1);
1249 if NetMode = NET_SERVER then
1250 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1251 else
1252 if NetMode = NET_CLIENT then
1253 e_TextureFontPrintEx(x+8, y + 8,
1254 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1256 if pc = 0 then
1257 Exit;
1258 stat := g_Player_GetStats();
1259 SortGameStat(stat);
1261 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1262 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1263 w4 := w3;
1264 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1266 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1267 begin
1268 _y := _y+ch+ch;
1270 for a := TEAM_RED to TEAM_BLUE do
1271 begin
1272 if a = TEAM_RED then
1273 begin
1274 s1 := _lc[I_GAME_TEAM_RED];
1275 r := 255;
1276 g := 0;
1277 b := 0;
1278 end
1279 else
1280 begin
1281 s1 := _lc[I_GAME_TEAM_BLUE];
1282 r := 0;
1283 g := 0;
1284 b := 255;
1285 end;
1287 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1288 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals),
1289 gStdFont, r, g, b, 1);
1291 _y := _y+ch+(ch div 4);
1292 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1293 _y := _y+(ch div 4);
1295 for aa := 0 to High(stat) do
1296 if stat[aa].Team = a then
1297 with stat[aa] do
1298 begin
1299 if Spectator then
1300 begin
1301 rr := r div 2;
1302 gg := g div 2;
1303 bb := b div 2;
1304 end
1305 else
1306 begin
1307 rr := r;
1308 gg := g;
1309 bb := b;
1310 end;
1311 if gShowPIDs then
1312 namestr := Format('[%5d] %s', [UID, Name])
1313 else
1314 namestr := Name;
1315 // Èìÿ
1316 e_TextureFontPrintEx(x+16, _y, namestr, gStdFont, rr, gg, bb, 1);
1317 // Ïèíã/ïîòåðè
1318 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1319 // Ôðàãè
1320 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1321 // Ñìåðòè
1322 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1323 _y := _y+ch;
1324 end;
1326 _y := _y+ch;
1327 end;
1328 end
1329 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1330 begin
1331 _y := _y+ch+ch;
1332 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1333 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1334 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1335 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1337 _y := _y+ch+8;
1338 for aa := 0 to High(stat) do
1339 with stat[aa] do
1340 begin
1341 if Spectator then
1342 begin
1343 r := 127;
1344 g := 64;
1345 end
1346 else
1347 begin
1348 r := 255;
1349 g := 127;
1350 end;
1351 if gShowPIDs then
1352 namestr := Format('[%5d] %s', [UID, Name])
1353 else
1354 namestr := Name;
1355 // Öâåò èãðîêà
1356 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1357 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1358 // Èìÿ
1359 e_TextureFontPrintEx(x+16+16+8, _y+4, namestr, gStdFont, r, g, 0, 1);
1360 // Ïèíã/ïîòåðè
1361 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1362 // Ôðàãè
1363 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1364 // Ñìåðòè
1365 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1366 _y := _y+ch+8;
1367 end;
1368 end
1369 end;
1371 procedure g_Game_Init();
1372 var
1373 SR: TSearchRec;
1374 knownFiles: array of AnsiString = nil;
1375 found: Boolean;
1376 wext, s: AnsiString;
1377 f: Integer;
1378 begin
1379 gExit := 0;
1380 gMapToDelete := '';
1381 gTempDelete := False;
1383 sfsGCDisable(); // temporary disable removing of temporary volumes
1385 try
1386 TEXTUREFILTER := GL_LINEAR;
1387 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1388 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1389 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1390 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1391 TEXTUREFILTER := GL_NEAREST;
1393 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1394 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1395 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1397 g_Game_ClearLoading();
1398 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1399 g_Game_SetLoadingText('', 0, False);
1401 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1402 g_Console_Init();
1404 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1405 g_PlayerModel_LoadData();
1407 // load models from all possible wad types, in all known directories
1408 // this does a loosy job (linear search, ooph!), but meh
1409 for wext in wadExtensions do
1410 begin
1411 for f := High(ModelDirs) downto Low(ModelDirs) do
1412 begin
1413 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1414 begin
1415 repeat
1416 found := false;
1417 for s in knownFiles do
1418 begin
1419 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1420 begin
1421 found := true;
1422 break;
1423 end;
1424 end;
1425 if not found then
1426 begin
1427 SetLength(knownFiles, length(knownFiles)+1);
1428 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1429 end;
1430 until (FindNext(SR) <> 0);
1431 end;
1432 FindClose(SR);
1433 end;
1434 end;
1436 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1438 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);
1439 for s in knownFiles do
1440 begin
1441 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1442 end;
1444 gGameOn := false;
1445 gPauseMain := false;
1446 gPauseHolmes := false;
1447 gTime := 0;
1449 {e_MouseInfo.Accel := 1.0;}
1451 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1452 g_Game_LoadData();
1454 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1455 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1456 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1457 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1458 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1460 {$IFNDEF HEADLESS}
1461 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1462 g_Menu_Init();
1463 {$ENDIF}
1465 gMusic := TMusic.Create();
1466 gMusic.SetByName('MUSIC_MENU');
1467 gMusic.Play();
1469 gGameSettings.WarmupTime := 30;
1471 gState := STATE_MENU;
1473 SetLength(gEvents, 6);
1474 gEvents[0].Name := 'ongamestart';
1475 gEvents[1].Name := 'ongameend';
1476 gEvents[2].Name := 'onmapstart';
1477 gEvents[3].Name := 'onmapend';
1478 gEvents[4].Name := 'oninter';
1479 gEvents[5].Name := 'onwadend';
1480 finally
1481 sfsGCEnable(); // enable releasing unused volumes
1482 end;
1483 end;
1485 procedure g_Game_Free(freeTextures: Boolean=true);
1486 begin
1487 if NetMode = NET_CLIENT then g_Net_Disconnect();
1488 if NetMode = NET_SERVER then g_Net_Host_Die();
1490 g_Map_Free(freeTextures);
1491 g_Player_Free();
1492 g_Player_RemoveAllCorpses();
1494 gGameSettings.GameType := GT_NONE;
1495 if gGameSettings.GameMode = GM_SINGLE then
1496 gGameSettings.GameMode := GM_DM;
1497 gSwitchGameMode := gGameSettings.GameMode;
1499 gChatShow := False;
1500 gExitByTrigger := False;
1501 end;
1503 function IsActivePlayer(p: TPlayer): Boolean;
1504 begin
1505 Result := False;
1506 if p = nil then
1507 Exit;
1508 Result := (not p.FDummy) and (not p.FSpectator);
1509 end;
1511 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1512 var
1513 a: Integer;
1514 begin
1515 Result := nil;
1516 if ID < 0 then
1517 Exit;
1518 if gPlayers = nil then
1519 Exit;
1520 for a := Low(gPlayers) to High(gPlayers) do
1521 if IsActivePlayer(gPlayers[a]) then
1522 begin
1523 if gPlayers[a].UID <> ID then
1524 continue;
1525 Result := gPlayers[a];
1526 break;
1527 end;
1528 end;
1530 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1531 var
1532 a, idx: Integer;
1533 ids: Array of Word;
1534 begin
1535 Result := -1;
1536 if gPlayers = nil then
1537 Exit;
1538 SetLength(ids, 0);
1539 idx := -1;
1540 for a := Low(gPlayers) to High(gPlayers) do
1541 if IsActivePlayer(gPlayers[a]) then
1542 begin
1543 SetLength(ids, Length(ids) + 1);
1544 ids[High(ids)] := gPlayers[a].UID;
1545 if gPlayers[a].UID = Skip then
1546 idx := High(ids);
1547 end;
1548 if Length(ids) = 0 then
1549 Exit;
1550 if idx = -1 then
1551 Result := ids[0]
1552 else
1553 Result := ids[(idx + 1) mod Length(ids)];
1554 end;
1556 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1557 var
1558 a, idx: Integer;
1559 ids: Array of Word;
1560 begin
1561 Result := -1;
1562 if gPlayers = nil then
1563 Exit;
1564 SetLength(ids, 0);
1565 idx := -1;
1566 for a := Low(gPlayers) to High(gPlayers) do
1567 if IsActivePlayer(gPlayers[a]) then
1568 begin
1569 SetLength(ids, Length(ids) + 1);
1570 ids[High(ids)] := gPlayers[a].UID;
1571 if gPlayers[a].UID = Skip then
1572 idx := High(ids);
1573 end;
1574 if Length(ids) = 0 then
1575 Exit;
1576 if idx = -1 then
1577 Result := ids[Length(ids) - 1]
1578 else
1579 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1580 end;
1582 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1583 var
1584 a, idx: Integer;
1585 ids: Array of Word;
1586 begin
1587 Result := -1;
1588 if gPlayers = nil then
1589 Exit;
1590 SetLength(ids, 0);
1591 idx := -1;
1592 for a := Low(gPlayers) to High(gPlayers) do
1593 if IsActivePlayer(gPlayers[a]) then
1594 begin
1595 SetLength(ids, Length(ids) + 1);
1596 ids[High(ids)] := gPlayers[a].UID;
1597 if gPlayers[a].UID = Skip then
1598 idx := High(ids);
1599 end;
1600 if Length(ids) = 0 then
1601 Exit;
1602 if Length(ids) = 1 then
1603 begin
1604 Result := ids[0];
1605 Exit;
1606 end;
1607 Result := ids[Random(Length(ids))];
1608 a := 10;
1609 while (idx <> -1) and (Result = Skip) and (a > 0) do
1610 begin
1611 Result := ids[Random(Length(ids))];
1612 Dec(a);
1613 end;
1614 end;
1616 function GetRandomSpectMode(Current: Byte): Byte;
1617 label
1618 retry;
1619 begin
1620 Result := Current;
1621 retry:
1622 case Random(7) of
1623 0: Result := SPECT_STATS;
1624 1: Result := SPECT_MAPVIEW;
1625 2: Result := SPECT_MAPVIEW;
1626 3: Result := SPECT_PLAYERS;
1627 4: Result := SPECT_PLAYERS;
1628 5: Result := SPECT_PLAYERS;
1629 6: Result := SPECT_PLAYERS;
1630 end;
1631 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1632 goto retry;
1633 end;
1635 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1636 var
1637 time: Word;
1638 strafeDir: Byte;
1639 i: Integer;
1640 begin
1641 if (plr = nil) then exit;
1642 if (p = 2) then time := 1000 else time := 1;
1643 strafeDir := MoveButton shr 4;
1644 MoveButton := MoveButton and $0F;
1646 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1647 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1648 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1649 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1650 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1651 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1653 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1654 if MoveButton = 1 then
1655 plr.PressKey(KEY_LEFT, time)
1656 else if MoveButton = 2 then
1657 plr.PressKey(KEY_RIGHT, time);
1659 // if we have "strafe" key, turn off old strafe mechanics
1660 if gPlayerAction[p, ACTION_STRAFE] then
1661 begin
1662 // new strafe mechanics
1663 if (strafeDir = 0) then
1664 strafeDir := MoveButton; // start strafing
1665 // now set direction according to strafe (reversed)
1666 if (strafeDir = 2) then
1667 plr.SetDirection(TDirection.D_LEFT)
1668 else if (strafeDir = 1) then
1669 plr.SetDirection(TDirection.D_RIGHT)
1670 end
1671 else
1672 begin
1673 strafeDir := 0; // not strafing anymore
1674 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1675 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1676 plr.SetDirection(TDirection.D_LEFT)
1677 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1678 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1679 plr.SetDirection(TDirection.D_RIGHT)
1680 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1681 else if MoveButton <> 0 then
1682 plr.SetDirection(TDirection(MoveButton-1))
1683 end;
1685 // fix movebutton state
1686 MoveButton := MoveButton or (strafeDir shl 4);
1688 // Îñòàëüíûå êëàâèøè:
1689 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1690 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1691 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1692 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1693 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1694 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1695 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1697 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1698 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1700 for i := WP_FIRST to WP_LAST do
1701 begin
1702 if gSelectWeapon[p, i] then
1703 begin
1704 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1705 gSelectWeapon[p, i] := False
1706 end
1707 end;
1709 // HACK: add dynlight here
1710 if gwin_k8_enable_light_experiments then
1711 begin
1712 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1713 begin
1714 g_playerLight := true;
1715 end;
1716 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1717 begin
1718 g_playerLight := false;
1719 end;
1720 end;
1722 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1723 end;
1725 // HACK: don't have a "key was pressed" function
1726 procedure InterReady();
1727 begin
1728 if InterReadyTime > gTime then Exit;
1729 InterReadyTime := gTime + 3000;
1730 MC_SEND_CheatRequest(NET_CHEAT_READY);
1731 end;
1733 procedure g_Game_PreUpdate();
1734 begin
1735 // these are in separate PreUpdate functions because they can interact during Update()
1736 // and are synced over the net
1737 // we don't care that much about corpses and gibs
1738 g_Player_PreUpdate();
1739 g_Monsters_PreUpdate();
1740 g_Items_PreUpdate();
1741 g_Weapon_PreUpdate();
1742 end;
1744 procedure g_Game_Update();
1745 var
1746 Msg: g_gui.TMessage;
1747 Time: Int64;
1748 a: Byte;
1749 w: Word;
1750 i, b: Integer;
1752 function sendMonsPos (mon: TMonster): Boolean;
1753 begin
1754 result := false; // don't stop
1755 // this will also reset "need-send" flag
1756 if mon.gncNeedSend then
1757 begin
1758 MH_SEND_MonsterPos(mon.UID);
1759 end
1760 else if (mon.MonsterType = MONSTER_BARREL) then
1761 begin
1762 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1763 end
1764 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1765 begin
1766 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1767 end;
1768 end;
1770 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1771 begin
1772 result := false; // don't stop
1773 // this will also reset "need-send" flag
1774 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1775 end;
1777 var
1778 reliableUpdate: Boolean;
1779 begin
1780 g_ResetDynlights();
1781 framePool.reset();
1783 // Ïîðà âûêëþ÷àòü èãðó:
1784 if gExit = EXIT_QUIT then
1785 Exit;
1786 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1787 if gExit <> 0 then
1788 begin
1789 EndGame();
1790 if gExit = EXIT_QUIT then
1791 Exit;
1792 end;
1794 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1795 // no need to, as we'll do it in event handler
1797 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1798 g_Console_Update();
1800 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1801 begin
1802 gExit := EXIT_SIMPLE;
1803 EndGame();
1804 Exit;
1805 end;
1807 // process master server communications
1808 g_Net_Slist_Pulse();
1810 case gState of
1811 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1812 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1813 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1814 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1815 begin
1816 if g_Game_IsNet and g_Game_IsServer then
1817 begin
1818 gInterTime := gInterTime + GAME_TICK;
1819 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1820 if a <> gServInterTime then
1821 begin
1822 gServInterTime := a;
1823 MH_SEND_TimeSync(gServInterTime);
1824 end;
1825 end;
1827 if (not g_Game_IsClient) and
1831 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1832 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1833 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1834 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1836 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1837 and (g_ActiveWindow = nil)
1839 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1841 then
1842 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1843 g_Game_StopAllSounds(True);
1845 if gMapOnce then // Ýòî áûë òåñò
1846 gExit := EXIT_SIMPLE
1847 else
1848 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1849 g_Game_ChangeMap(gNextMap)
1850 else // Ñëåäóþùåé êàðòû íåò
1851 begin
1852 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1853 begin
1854 // Âûõîä â ãëàâíîå ìåíþ:
1855 g_Game_Free;
1856 g_GUI_ShowWindow('MainMenu');
1857 gMusic.SetByName('MUSIC_MENU');
1858 gMusic.Play();
1859 gState := STATE_MENU;
1860 end else
1861 begin
1862 // Ôèíàëüíàÿ êàðòèíêà:
1863 g_Game_ExecuteEvent('onwadend');
1864 g_Game_Free();
1865 if not gMusic.SetByName('MUSIC_endmus') then
1866 gMusic.SetByName('MUSIC_STDENDMUS');
1867 gMusic.Play();
1868 gState := STATE_ENDPIC;
1869 end;
1870 g_Game_ExecuteEvent('ongameend');
1871 end;
1873 Exit;
1874 end
1875 else if g_Game_IsClient and
1878 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1879 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1880 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1881 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1883 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1884 and (g_ActiveWindow = nil)
1886 then
1887 begin
1888 // ready / unready
1889 InterReady();
1890 end;
1892 if gState = STATE_INTERTEXT then
1893 if InterText.counter > 0 then
1894 InterText.counter := InterText.counter - 1;
1895 end;
1897 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1898 begin
1899 if EndingGameCounter = 0 then
1900 begin
1901 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1902 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1903 begin
1904 InterReadyTime := -1;
1905 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1906 begin
1907 g_Game_ExecuteEvent('onwadend');
1908 if not gMusic.SetByName('MUSIC_endmus') then
1909 gMusic.SetByName('MUSIC_STDENDMUS');
1910 end
1911 else
1912 gMusic.SetByName('MUSIC_ROUNDMUS');
1914 gMusic.Play();
1915 gState := STATE_INTERCUSTOM;
1916 e_UnpressAllKeys();
1917 end
1918 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1919 begin
1920 gMusic.SetByName('MUSIC_INTERMUS');
1921 gMusic.Play();
1922 gState := STATE_INTERSINGLE;
1923 e_UnpressAllKeys();
1924 end;
1925 g_Game_ExecuteEvent('oninter');
1926 end
1927 else
1928 DecMin(EndingGameCounter, 6, 0);
1929 end;
1931 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1932 begin
1933 if gMapOnce then // Ýòî áûë òåñò
1934 begin
1935 gExit := EXIT_SIMPLE;
1936 Exit;
1937 end;
1938 end;
1940 STATE_SLIST:
1941 g_Serverlist_Control(slCurrent, slTable);
1942 end;
1944 // Ñòàòèñòèêà ïî Tab:
1945 if gGameOn then
1946 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1948 // Èãðà èäåò:
1949 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1950 begin
1951 // Âðåìÿ += 28 ìèëëèñåêóíä:
1952 gTime := gTime + GAME_TICK;
1954 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1955 if MessageTime = 0 then
1956 MessageText := '';
1957 if MessageTime > 0 then
1958 MessageTime := MessageTime - 1;
1960 if (g_Game_IsServer) then
1961 begin
1962 // Áûë çàäàí ëèìèò âðåìåíè:
1963 if (gGameSettings.TimeLimit > 0) then
1964 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1965 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1966 g_Game_NextLevel();
1967 Exit;
1968 end;
1970 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1971 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1972 g_Game_RestartRound(gLMSSoftSpawn);
1974 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1975 if gVoteInProgress and (gVoteTimer < gTime) then
1976 g_Game_CheckVote
1977 else if gVotePassed and (gVoteCmdTimer < gTime) then
1978 begin
1979 g_Console_Process(gVoteCommand);
1980 gVoteCommand := '';
1981 gVotePassed := False;
1982 end;
1984 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1985 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1986 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1987 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1988 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1990 // Áûë çàäàí ëèìèò ïîáåä:
1991 if (gGameSettings.GoalLimit > 0) then
1992 begin
1993 b := 0;
1995 if gGameSettings.GameMode = GM_DM then
1996 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1997 for i := 0 to High(gPlayers) do
1998 if gPlayers[i] <> nil then
1999 if gPlayers[i].Frags > b then
2000 b := gPlayers[i].Frags;
2001 end
2002 else
2003 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2004 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2005 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
2006 end;
2008 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2009 if b >= gGameSettings.GoalLimit then
2010 begin
2011 g_Game_NextLevel();
2012 Exit;
2013 end;
2014 end;
2016 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2017 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2018 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2019 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2020 begin
2021 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2022 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2023 end // if not console
2024 else
2025 begin
2026 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2027 end;
2028 // process weapon switch queue
2029 end; // if server
2031 // Íàáëþäàòåëü
2032 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2033 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2034 begin
2035 if not gSpectKeyPress then
2036 begin
2037 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2038 begin
2039 // switch spect mode
2040 case gSpectMode of
2041 SPECT_NONE: ; // not spectator
2042 SPECT_STATS,
2043 SPECT_MAPVIEW: Inc(gSpectMode);
2044 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2045 end;
2046 gSpectKeyPress := True;
2047 end;
2048 if (gSpectMode = SPECT_MAPVIEW)
2049 and (not gSpectAuto) then
2050 begin
2051 if gPlayerAction[0, ACTION_MOVELEFT] then
2052 gSpectX := Max(gSpectX - gSpectStep, 0);
2053 if gPlayerAction[0, ACTION_MOVERIGHT] then
2054 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2055 if gPlayerAction[0, ACTION_LOOKUP] then
2056 gSpectY := Max(gSpectY - gSpectStep, 0);
2057 if gPlayerAction[0, ACTION_LOOKDOWN] then
2058 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2059 if gPlayerAction[0, ACTION_WEAPPREV] then
2060 begin
2061 // decrease step
2062 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2063 gSpectKeyPress := True;
2064 end;
2065 if gPlayerAction[0, ACTION_WEAPNEXT] then
2066 begin
2067 // increase step
2068 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2069 gSpectKeyPress := True;
2070 end;
2071 end;
2072 if (gSpectMode = SPECT_PLAYERS)
2073 and (not gSpectAuto) then
2074 begin
2075 if gPlayerAction[0, ACTION_LOOKUP] then
2076 begin
2077 // add second view
2078 gSpectViewTwo := True;
2079 gSpectKeyPress := True;
2080 end;
2081 if gPlayerAction[0, ACTION_LOOKDOWN] then
2082 begin
2083 // remove second view
2084 gSpectViewTwo := False;
2085 gSpectKeyPress := True;
2086 end;
2087 if gPlayerAction[0, ACTION_MOVELEFT] then
2088 begin
2089 // prev player (view 1)
2090 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2091 gSpectKeyPress := True;
2092 end;
2093 if gPlayerAction[0, ACTION_MOVERIGHT] then
2094 begin
2095 // next player (view 1)
2096 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2097 gSpectKeyPress := True;
2098 end;
2099 if gPlayerAction[0, ACTION_WEAPPREV] then
2100 begin
2101 // prev player (view 2)
2102 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2103 gSpectKeyPress := True;
2104 end;
2105 if gPlayerAction[0, ACTION_WEAPNEXT] then
2106 begin
2107 // next player (view 2)
2108 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2109 gSpectKeyPress := True;
2110 end;
2111 end;
2112 if gPlayerAction[0, ACTION_ATTACK] then
2113 begin
2114 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2115 begin
2116 gSpectAuto := True;
2117 gSpectAutoNext := 0;
2118 gSpectViewTwo := False;
2119 gSpectKeyPress := True;
2120 end
2121 else
2122 if gSpectAuto then
2123 begin
2124 gSpectMode := SPECT_STATS;
2125 gSpectAuto := False;
2126 gSpectKeyPress := True;
2127 end;
2128 end;
2129 end
2130 else
2131 if (not gPlayerAction[0, ACTION_JUMP]) and
2132 (not gPlayerAction[0, ACTION_ATTACK]) and
2133 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2134 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2135 (not gPlayerAction[0, ACTION_LOOKUP]) and
2136 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2137 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2138 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2139 gSpectKeyPress := False;
2141 if gSpectAuto then
2142 begin
2143 if gSpectMode = SPECT_MAPVIEW then
2144 begin
2145 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2146 if i = gSpectX then
2147 gSpectAutoNext := gTime
2148 else
2149 gSpectX := i;
2150 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2151 if i = gSpectY then
2152 gSpectAutoNext := gTime
2153 else
2154 gSpectY := i;
2155 end;
2156 if gSpectAutoNext <= gTime then
2157 begin
2158 if gSpectAutoNext > 0 then
2159 begin
2160 gSpectMode := GetRandomSpectMode(gSpectMode);
2161 case gSpectMode of
2162 SPECT_MAPVIEW:
2163 begin
2164 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2165 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2166 gSpectAutoStepX := Random(9) - 4;
2167 gSpectAutoStepY := Random(9) - 4;
2168 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2169 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2170 gSpectAutoStepX := gSpectAutoStepX * -1;
2171 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2172 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2173 gSpectAutoStepY := gSpectAutoStepY * -1;
2174 end;
2175 SPECT_PLAYERS:
2176 begin
2177 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2178 end;
2179 end;
2180 end;
2181 case gSpectMode of
2182 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2183 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2184 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2185 end;
2186 end;
2187 end;
2188 end;
2190 // Îáíîâëÿåì âñå îñòàëüíîå:
2191 g_Map_Update();
2192 g_Items_Update();
2193 g_Triggers_Update();
2194 g_Weapon_Update();
2195 g_Monsters_Update();
2196 g_GFX_Update();
2197 g_Player_UpdateAll();
2198 g_Player_UpdatePhysicalObjects();
2200 // server: send newly spawned monsters unconditionally
2201 if (gGameSettings.GameType = GT_SERVER) then
2202 begin
2203 if (Length(gMonstersSpawned) > 0) then
2204 begin
2205 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2206 SetLength(gMonstersSpawned, 0);
2207 end;
2208 end;
2210 if (gSoundTriggerTime > 8) then
2211 begin
2212 g_Game_UpdateTriggerSounds();
2213 gSoundTriggerTime := 0;
2214 end
2215 else
2216 begin
2217 Inc(gSoundTriggerTime);
2218 end;
2220 if (NetMode = NET_SERVER) then
2221 begin
2222 Inc(NetTimeToUpdate);
2223 Inc(NetTimeToReliable);
2225 // send monster updates
2226 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2227 begin
2228 // send all monsters (periodic sync)
2229 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2231 for I := 0 to High(gPlayers) do
2232 begin
2233 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2234 end;
2236 g_Mons_ForEach(sendMonsPos);
2238 if reliableUpdate then
2239 begin
2240 NetTimeToReliable := 0;
2241 NetTimeToUpdate := NetUpdateRate;
2242 end
2243 else
2244 begin
2245 NetTimeToUpdate := 0;
2246 end;
2247 end
2248 else
2249 begin
2250 // send only mosters with some unexpected changes
2251 g_Mons_ForEach(sendMonsPosUnexpected);
2252 end;
2254 // send unexpected platform changes
2255 g_Map_NetSendInterestingPanels();
2257 g_Net_Slist_ServerUpdate();
2259 if NetUseMaster then
2260 begin
2261 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2262 begin
2263 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2264 g_Net_Slist_Update;
2265 NetTimeToMaster := gTime + NetMasterRate;
2266 end;
2267 end;
2269 end
2270 else if (NetMode = NET_CLIENT) then
2271 begin
2272 MC_SEND_PlayerPos();
2273 end;
2274 end; // if gameOn ...
2276 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2277 if g_ActiveWindow <> nil then
2278 begin
2279 w := e_GetFirstKeyPressed();
2281 if (w <> IK_INVALID) then
2282 begin
2283 Msg.Msg := MESSAGE_DIKEY;
2284 Msg.wParam := w;
2285 g_ActiveWindow.OnMessage(Msg);
2286 end;
2288 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2289 if g_ActiveWindow <> nil then
2290 g_ActiveWindow.Update();
2292 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2293 if gResolutionChange then
2294 begin
2295 e_WriteLog('Changing resolution', TMsgType.Notify);
2296 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2297 gResolutionChange := False;
2298 g_ActiveWindow := nil;
2299 end;
2301 // Íóæíî ñìåíèòü ÿçûê:
2302 if gLanguageChange then
2303 begin
2304 //e_WriteLog('Read language file', MSG_NOTIFY);
2305 //g_Language_Load(DataDir + gLanguage + '.txt');
2306 g_Language_Set(gLanguage);
2307 {$IFNDEF HEADLESS}
2308 g_Menu_Reset();
2309 {$ENDIF}
2310 gLanguageChange := False;
2311 end;
2312 end;
2314 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2315 if e_KeyPressed(IK_F10) and
2316 gGameOn and
2317 (not gConsoleShow) and
2318 (g_ActiveWindow = nil) then
2319 begin
2320 KeyPress(IK_F10);
2321 end;
2323 Time := sys_GetTicks() {div 1000};
2325 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2326 if gDelayedEvents <> nil then
2327 for a := 0 to High(gDelayedEvents) do
2328 if gDelayedEvents[a].Pending and
2330 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2331 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2332 ) then
2333 begin
2334 case gDelayedEvents[a].DEType of
2335 DE_GLOBEVENT:
2336 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2337 DE_BFGHIT:
2338 if gGameOn then
2339 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2340 DE_KILLCOMBO:
2341 if gGameOn then
2342 begin
2343 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2344 if g_Game_IsNet and g_Game_IsServer then
2345 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2346 end;
2347 DE_BODYKILL:
2348 if gGameOn then
2349 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2350 end;
2351 gDelayedEvents[a].Pending := False;
2352 end;
2354 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2355 UPSCounter := UPSCounter + 1;
2356 if Time - UPSTime >= 1000 then
2357 begin
2358 UPS := UPSCounter;
2359 UPSCounter := 0;
2360 UPSTime := Time;
2361 end;
2363 if gGameOn then
2364 begin
2365 g_Weapon_AddDynLights();
2366 g_Items_AddDynLights();
2367 end;
2368 end;
2370 procedure g_Game_LoadChatSounds(Resource: string);
2371 var
2372 WAD: TWADFile;
2373 FileName, Snd: string;
2374 p: Pointer;
2375 len, cnt, tags, i, j: Integer;
2376 cfg: TConfig;
2377 begin
2378 FileName := g_ExtractWadName(Resource);
2380 WAD := TWADFile.Create();
2381 WAD.ReadFile(FileName);
2383 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2384 begin
2385 gChatSounds := nil;
2386 WAD.Free();
2387 Exit;
2388 end;
2390 cfg := TConfig.CreateMem(p, len);
2391 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2393 SetLength(gChatSounds, cnt);
2394 for i := 0 to Length(gChatSounds) - 1 do
2395 begin
2396 gChatSounds[i].Sound := nil;
2397 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2398 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2399 if (Snd = '') or (Tags <= 0) then
2400 continue;
2401 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2402 gChatSounds[i].Sound := TPlayableSound.Create();
2403 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2404 SetLength(gChatSounds[i].Tags, tags);
2405 for j := 0 to tags - 1 do
2406 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2407 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2408 end;
2410 cfg.Free();
2411 WAD.Free();
2412 end;
2414 procedure g_Game_FreeChatSounds();
2415 var
2416 i: Integer;
2417 begin
2418 for i := 0 to Length(gChatSounds) - 1 do
2419 begin
2420 gChatSounds[i].Sound.Free();
2421 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2422 end;
2423 SetLength(gChatSounds, 0);
2424 gChatSounds := nil;
2425 end;
2427 procedure g_Game_LoadData();
2428 var
2429 wl, hl: Integer;
2430 wr, hr: Integer;
2431 wb, hb: Integer;
2432 wm, hm: Integer;
2433 begin
2434 if DataLoaded then Exit;
2436 e_WriteLog('Loading game data...', TMsgType.Notify);
2438 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2439 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2440 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2441 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2442 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2443 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2444 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2445 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2446 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2447 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2448 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2449 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2450 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2451 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2452 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2454 hasPBarGfx := true;
2455 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2456 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2457 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2458 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2460 if hasPBarGfx then
2461 begin
2462 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2463 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2464 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2465 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2466 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
2467 begin
2468 // yay!
2469 end
2470 else
2471 begin
2472 hasPBarGfx := false;
2473 end;
2474 end;
2476 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2477 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2478 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2479 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2480 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2481 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2482 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2483 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2484 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2485 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2486 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2487 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2488 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2489 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2490 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2491 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2492 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2493 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2494 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2495 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2496 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2497 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2498 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2499 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2500 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2507 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2508 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2509 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2510 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2511 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2512 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2513 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2514 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2516 goodsnd[0] := TPlayableSound.Create();
2517 goodsnd[1] := TPlayableSound.Create();
2518 goodsnd[2] := TPlayableSound.Create();
2519 goodsnd[3] := TPlayableSound.Create();
2521 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2522 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2523 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2524 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2526 killsnd[0] := TPlayableSound.Create();
2527 killsnd[1] := TPlayableSound.Create();
2528 killsnd[2] := TPlayableSound.Create();
2529 killsnd[3] := TPlayableSound.Create();
2531 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2532 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2533 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2534 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2536 hahasnd[0] := TPlayableSound.Create();
2537 hahasnd[1] := TPlayableSound.Create();
2538 hahasnd[2] := TPlayableSound.Create();
2540 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2541 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2542 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2544 sound_get_flag[0] := TPlayableSound.Create();
2545 sound_get_flag[1] := TPlayableSound.Create();
2546 sound_lost_flag[0] := TPlayableSound.Create();
2547 sound_lost_flag[1] := TPlayableSound.Create();
2548 sound_ret_flag[0] := TPlayableSound.Create();
2549 sound_ret_flag[1] := TPlayableSound.Create();
2550 sound_cap_flag[0] := TPlayableSound.Create();
2551 sound_cap_flag[1] := TPlayableSound.Create();
2553 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2554 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2555 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2556 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2557 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2558 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2559 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2560 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2562 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2564 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2565 g_Items_LoadData();
2567 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2568 g_Weapon_LoadData();
2570 g_Monsters_LoadData();
2572 DataLoaded := True;
2573 end;
2575 procedure g_Game_FreeData();
2576 begin
2577 if not DataLoaded then Exit;
2579 g_Items_FreeData();
2580 g_Weapon_FreeData();
2581 g_Monsters_FreeData();
2583 e_WriteLog('Releasing game data...', TMsgType.Notify);
2585 g_Texture_Delete('NOTEXTURE');
2586 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2587 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2588 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2589 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2590 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2591 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2592 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2593 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2594 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2595 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2596 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2597 g_Frames_DeleteByName('FRAMES_TELEPORT');
2598 g_Frames_DeleteByName('FRAMES_PUNCH');
2599 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2600 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2601 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2602 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2603 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2604 g_Sound_Delete('SOUND_GAME_TELEPORT');
2605 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2606 g_Sound_Delete('SOUND_GAME_SECRET');
2607 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2608 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2609 g_Sound_Delete('SOUND_GAME_BULK1');
2610 g_Sound_Delete('SOUND_GAME_BULK2');
2611 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2612 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2613 g_Sound_Delete('SOUND_GAME_BURNING');
2614 g_Sound_Delete('SOUND_GAME_SWITCH1');
2615 g_Sound_Delete('SOUND_GAME_SWITCH0');
2617 goodsnd[0].Free();
2618 goodsnd[1].Free();
2619 goodsnd[2].Free();
2620 goodsnd[3].Free();
2622 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2623 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2624 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2625 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2627 killsnd[0].Free();
2628 killsnd[1].Free();
2629 killsnd[2].Free();
2630 killsnd[3].Free();
2632 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2633 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2634 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2635 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2637 hahasnd[0].Free();
2638 hahasnd[1].Free();
2639 hahasnd[2].Free();
2641 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2642 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2643 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2645 sound_get_flag[0].Free();
2646 sound_get_flag[1].Free();
2647 sound_lost_flag[0].Free();
2648 sound_lost_flag[1].Free();
2649 sound_ret_flag[0].Free();
2650 sound_ret_flag[1].Free();
2651 sound_cap_flag[0].Free();
2652 sound_cap_flag[1].Free();
2654 g_Sound_Delete('SOUND_CTF_GET1');
2655 g_Sound_Delete('SOUND_CTF_GET2');
2656 g_Sound_Delete('SOUND_CTF_LOST1');
2657 g_Sound_Delete('SOUND_CTF_LOST2');
2658 g_Sound_Delete('SOUND_CTF_RETURN1');
2659 g_Sound_Delete('SOUND_CTF_RETURN2');
2660 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2661 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2663 g_Game_FreeChatSounds();
2665 DataLoaded := False;
2666 end;
2668 procedure DrawCustomStat();
2669 var
2670 pc, x, y, w, _y,
2671 w1, w2, w3,
2672 t, p, m: Integer;
2673 ww1, hh1: Word;
2674 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2675 s1, s2, topstr: String;
2676 begin
2677 e_TextureFontGetSize(gStdFont, ww2, hh2);
2679 sys_HandleInput;
2681 if g_Console_Action(ACTION_SCORES) then
2682 begin
2683 if not gStatsPressed then
2684 begin
2685 gStatsOff := not gStatsOff;
2686 gStatsPressed := True;
2687 end;
2688 end
2689 else
2690 gStatsPressed := False;
2692 if gStatsOff then
2693 begin
2694 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2695 w := (Length(s1) * ww2) div 2;
2696 x := gScreenWidth div 2 - w;
2697 y := 8;
2698 e_TextureFontPrint(x, y, s1, gStdFont);
2699 Exit;
2700 end;
2702 if (gGameSettings.GameMode = GM_COOP) then
2703 begin
2704 if gMissionFailed then
2705 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2706 else
2707 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2708 end
2709 else
2710 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2712 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2713 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2715 if g_Game_IsNet then
2716 begin
2717 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2718 if not gChatShow then
2719 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2720 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2721 end;
2723 if g_Game_IsClient then
2724 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2725 else
2726 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2727 if not gChatShow then
2728 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2729 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2731 x := 32;
2732 y := 16+hh1+16;
2734 w := gScreenWidth-x*2;
2736 w2 := (w-16) div 6;
2737 w3 := w2;
2738 w1 := w-16-w2-w3;
2740 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2741 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2743 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2745 case CustomStat.GameMode of
2746 GM_DM:
2747 begin
2748 if gGameSettings.MaxLives = 0 then
2749 s1 := _lc[I_GAME_DM]
2750 else
2751 s1 := _lc[I_GAME_LMS];
2752 end;
2753 GM_TDM:
2754 begin
2755 if gGameSettings.MaxLives = 0 then
2756 s1 := _lc[I_GAME_TDM]
2757 else
2758 s1 := _lc[I_GAME_TLMS];
2759 end;
2760 GM_CTF: s1 := _lc[I_GAME_CTF];
2761 GM_COOP:
2762 begin
2763 if gGameSettings.MaxLives = 0 then
2764 s1 := _lc[I_GAME_COOP]
2765 else
2766 s1 := _lc[I_GAME_SURV];
2767 end;
2768 else s1 := '';
2769 end;
2771 _y := y+16;
2772 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2773 _y := _y+8;
2775 _y := _y+16;
2776 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2777 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2779 _y := _y+16;
2780 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2781 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2782 (CustomStat.GameTime div 1000 div 60) mod 60,
2783 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2785 pc := Length(CustomStat.PlayerStat);
2786 if pc = 0 then Exit;
2788 if CustomStat.GameMode = GM_COOP then
2789 begin
2790 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2791 _y := _y+32;
2792 s2 := _lc[I_GAME_MONSTERS];
2793 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2794 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2795 _y := _y+16;
2796 s2 := _lc[I_GAME_SECRETS];
2797 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2798 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2799 if gLastMap then
2800 begin
2801 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2802 _y := _y-16;
2803 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2804 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2805 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2806 _y := _y+16;
2807 s2 := _lc[I_GAME_SECRETS_TOTAL];
2808 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2809 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2810 end;
2811 end;
2813 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2814 begin
2815 _y := _y+16+16;
2817 with CustomStat do
2818 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2819 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2820 else s1 := _lc[I_GAME_WIN_DRAW];
2822 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2823 _y := _y+40;
2825 for t := TEAM_RED to TEAM_BLUE do
2826 begin
2827 if t = TEAM_RED then
2828 begin
2829 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2830 gStdFont, 255, 0, 0, 1);
2831 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2832 gStdFont, 255, 0, 0, 1);
2833 r := 255;
2834 g := 0;
2835 b := 0;
2836 end
2837 else
2838 begin
2839 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2840 gStdFont, 0, 0, 255, 1);
2841 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2842 gStdFont, 0, 0, 255, 1);
2843 r := 0;
2844 g := 0;
2845 b := 255;
2846 end;
2848 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2849 _y := _y+24;
2851 for p := 0 to High(CustomStat.PlayerStat) do
2852 if CustomStat.PlayerStat[p].Team = t then
2853 with CustomStat.PlayerStat[p] do
2854 begin
2855 if Spectator then
2856 begin
2857 rr := r div 2;
2858 gg := g div 2;
2859 bb := b div 2;
2860 end
2861 else
2862 begin
2863 rr := r;
2864 gg := g;
2865 bb := b;
2866 end;
2867 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2868 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2869 else
2870 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2871 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2872 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2873 _y := _y+24;
2874 end;
2876 _y := _y+16+16;
2877 end;
2878 end
2879 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2880 begin
2881 _y := _y+40;
2882 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2883 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2884 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2886 _y := _y+24;
2887 for p := 0 to High(CustomStat.PlayerStat) do
2888 with CustomStat.PlayerStat[p] do
2889 begin
2890 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2892 if Spectator then
2893 r := 127
2894 else
2895 r := 255;
2897 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2898 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2899 else
2900 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2901 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2902 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2903 _y := _y+24;
2904 end;
2905 end;
2907 // HACK: take stats screenshot immediately after the first frame of the stats showing
2908 if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
2909 begin
2910 g_TakeScreenShot('stats/' + StatFilename);
2911 StatShotDone := True;
2912 end;
2913 end;
2915 procedure DrawSingleStat();
2916 var
2917 tm, key_x, val_x, y: Integer;
2918 w1, w2, h: Word;
2919 s1, s2: String;
2921 procedure player_stat(n: Integer);
2922 var
2923 kpm: Real;
2925 begin
2926 // "Kills: # / #":
2927 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2928 s2 := Format(' %d', [gTotalMonsters]);
2930 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2931 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2932 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2933 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2934 s1 := s1 + '/';
2935 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2936 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2938 // "Kills-per-minute: ##.#":
2939 s1 := _lc[I_MENU_INTER_KPM];
2940 if tm > 0 then
2941 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2942 else
2943 kpm := SingleStat.PlayerStat[n].Kills;
2944 s2 := Format(' %.1f', [kpm]);
2946 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2947 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2949 // "Secrets found: # / #":
2950 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2951 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2953 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2954 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2955 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2956 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2957 s1 := s1 + '/';
2958 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2959 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2960 end;
2962 begin
2963 // "Level Complete":
2964 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2965 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2967 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2968 s1 := _lc[I_MENU_INTER_KPM];
2969 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2970 Inc(w1, 16);
2971 s1 := ' 9999.9';
2972 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2974 key_x := (gScreenWidth-w1-w2) div 2;
2975 val_x := key_x + w1;
2977 // "Time: #:##:##":
2978 tm := SingleStat.GameTime div 1000;
2979 s1 := _lc[I_MENU_INTER_TIME];
2980 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2982 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2983 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2985 if SingleStat.TwoPlayers then
2986 begin
2987 // "Player 1":
2988 s1 := _lc[I_MENU_PLAYER_1];
2989 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2990 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2992 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2993 y := 176;
2994 player_stat(0);
2996 // "Player 2":
2997 s1 := _lc[I_MENU_PLAYER_2];
2998 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2999 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
3001 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3002 y := 336;
3003 player_stat(1);
3004 end
3005 else
3006 begin
3007 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3008 y := 128;
3009 player_stat(0);
3010 end;
3011 end;
3013 procedure DrawLoadingStat();
3014 procedure drawRect (x, y, w, h: Integer);
3015 begin
3016 if (w < 1) or (h < 1) then exit;
3017 glBegin(GL_QUADS);
3018 glVertex2f(x+0.375, y+0.375);
3019 glVertex2f(x+w+0.375, y+0.375);
3020 glVertex2f(x+w+0.375, y+h+0.375);
3021 glVertex2f(x+0.375, y+h+0.375);
3022 glEnd();
3023 end;
3025 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
3026 var
3027 rectW, rectH: Integer;
3028 x0, y0: Integer;
3029 wdt: Integer;
3030 wl, hl: Integer;
3031 wr, hr: Integer;
3032 wb, hb: Integer;
3033 wm, hm: Integer;
3034 idl, idr, idb, idm: LongWord;
3035 f, my: Integer;
3036 begin
3037 result := false;
3038 if (total < 1) then exit;
3039 if (cur < 1) then exit; // don't blink
3040 if (not washere) and (cur >= total) then exit; // don't blink
3041 //if (cur < 0) then cur := 0;
3042 //if (cur > total) then cur := total;
3043 result := true;
3045 if (hasPBarGfx) then
3046 begin
3047 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
3048 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
3049 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
3050 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
3051 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
3052 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
3053 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
3054 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
3056 //rectW := gScreenWidth-360;
3057 rectW := trunc(624.0*gScreenWidth/1024.0);
3058 rectH := hl;
3060 x0 := (gScreenWidth-rectW) div 2;
3061 y0 := gScreenHeight-rectH-64;
3062 if (y0 < 2) then y0 := 2;
3064 glEnable(GL_SCISSOR_TEST);
3066 // left and right
3067 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
3068 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
3069 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
3071 // body
3072 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
3073 f := x0+wl;
3074 while (f < x0+rectW) do
3075 begin
3076 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
3077 f += wb;
3078 end;
3080 // filled part
3081 wdt := (rectW-wl-wr)*cur div total;
3082 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
3083 if (wdt > 0) then
3084 begin
3085 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
3086 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
3087 f := x0+wl;
3088 while (wdt > 0) do
3089 begin
3090 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
3091 f += wm;
3092 wdt -= wm;
3093 end;
3094 end;
3096 glScissor(0, 0, gScreenWidth, gScreenHeight);
3097 end
3098 else
3099 begin
3100 rectW := gScreenWidth-64;
3101 rectH := 16;
3103 x0 := (gScreenWidth-rectW) div 2;
3104 y0 := gScreenHeight-rectH-64;
3105 if (y0 < 2) then y0 := 2;
3107 glDisable(GL_BLEND);
3108 glDisable(GL_TEXTURE_2D);
3110 //glClearColor(0, 0, 0, 0);
3111 //glClear(GL_COLOR_BUFFER_BIT);
3113 glColor4ub(127, 127, 127, 255);
3114 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3116 glColor4ub(0, 0, 0, 255);
3117 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3119 glColor4ub(127, 127, 127, 255);
3120 wdt := rectW*cur div total;
3121 if (wdt > rectW) then wdt := rectW;
3122 drawRect(x0, y0, wdt, rectH);
3123 end;
3124 end;
3126 var
3127 ww, hh: Word;
3128 xx, yy, i: Integer;
3129 s: String;
3130 begin
3131 if (Length(LoadingStat.Msgs) = 0) then exit;
3133 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3134 yy := (gScreenHeight div 3);
3135 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3136 xx := (gScreenWidth div 3);
3138 with LoadingStat do
3139 begin
3140 for i := 0 to NextMsg-1 do
3141 begin
3142 if (i = (NextMsg-1)) and (MaxValue > 0) then
3143 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3144 else
3145 s := Msgs[i];
3147 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3148 yy := yy + LOADING_INTERLINE;
3149 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3150 end;
3151 end;
3152 end;
3154 procedure DrawMenuBackground(tex: AnsiString);
3155 var
3156 w, h: Word;
3157 ID: DWord;
3159 begin
3160 if g_Texture_Get(tex, ID) then
3161 begin
3162 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3163 e_GetTextureSize(ID, @w, @h);
3164 if w = h then
3165 w := round(w * 1.333 * (gScreenHeight / h))
3166 else
3167 w := trunc(w * (gScreenHeight / h));
3168 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3169 end
3170 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3171 end;
3173 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3174 var
3175 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3177 function monDraw (mon: TMonster): Boolean;
3178 begin
3179 result := false; // don't stop
3180 with mon do
3181 begin
3182 if alive then
3183 begin
3184 // Ëåâûé âåðõíèé óãîë
3185 aX := Obj.X div ScaleSz + 1;
3186 aY := Obj.Y div ScaleSz + 1;
3187 // Ðàçìåðû
3188 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3189 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3190 // Ïðàâûé íèæíèé óãîë
3191 aX2 := aX + aX2 - 1;
3192 aY2 := aY + aY2 - 1;
3193 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3194 end;
3195 end;
3196 end;
3198 begin
3199 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3200 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3201 begin
3202 Scale := 1;
3203 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3204 ScaleSz := 16 div Scale;
3205 // Ðàçìåðû ìèíè-êàðòû:
3206 aX := max(gMapInfo.Width div ScaleSz, 1);
3207 aY := max(gMapInfo.Height div ScaleSz, 1);
3208 // Ðàìêà êàðòû:
3209 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3211 if gWalls <> nil then
3212 begin
3213 // Ðèñóåì ñòåíû:
3214 for a := 0 to High(gWalls) do
3215 with gWalls[a] do
3216 if PanelType <> 0 then
3217 begin
3218 // Ëåâûé âåðõíèé óãîë:
3219 aX := X div ScaleSz;
3220 aY := Y div ScaleSz;
3221 // Ðàçìåðû:
3222 aX2 := max(Width div ScaleSz, 1);
3223 aY2 := max(Height div ScaleSz, 1);
3224 // Ïðàâûé íèæíèé óãîë:
3225 aX2 := aX + aX2 - 1;
3226 aY2 := aY + aY2 - 1;
3228 case PanelType of
3229 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3230 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3231 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3232 end;
3233 end;
3234 end;
3235 if gSteps <> nil then
3236 begin
3237 // Ðèñóåì ñòóïåíè:
3238 for a := 0 to High(gSteps) do
3239 with gSteps[a] do
3240 if PanelType <> 0 then
3241 begin
3242 // Ëåâûé âåðõíèé óãîë:
3243 aX := X div ScaleSz;
3244 aY := Y div ScaleSz;
3245 // Ðàçìåðû:
3246 aX2 := max(Width div ScaleSz, 1);
3247 aY2 := max(Height div ScaleSz, 1);
3248 // Ïðàâûé íèæíèé óãîë:
3249 aX2 := aX + aX2 - 1;
3250 aY2 := aY + aY2 - 1;
3252 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3253 end;
3254 end;
3255 if gLifts <> nil then
3256 begin
3257 // Ðèñóåì ëèôòû:
3258 for a := 0 to High(gLifts) do
3259 with gLifts[a] do
3260 if PanelType <> 0 then
3261 begin
3262 // Ëåâûé âåðõíèé óãîë:
3263 aX := X div ScaleSz;
3264 aY := Y div ScaleSz;
3265 // Ðàçìåðû:
3266 aX2 := max(Width div ScaleSz, 1);
3267 aY2 := max(Height div ScaleSz, 1);
3268 // Ïðàâûé íèæíèé óãîë:
3269 aX2 := aX + aX2 - 1;
3270 aY2 := aY + aY2 - 1;
3272 case LiftType of
3273 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3274 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3275 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3276 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3277 end;
3278 end;
3279 end;
3280 if gWater <> nil then
3281 begin
3282 // Ðèñóåì âîäó:
3283 for a := 0 to High(gWater) do
3284 with gWater[a] do
3285 if PanelType <> 0 then
3286 begin
3287 // Ëåâûé âåðõíèé óãîë:
3288 aX := X div ScaleSz;
3289 aY := Y div ScaleSz;
3290 // Ðàçìåðû:
3291 aX2 := max(Width div ScaleSz, 1);
3292 aY2 := max(Height div ScaleSz, 1);
3293 // Ïðàâûé íèæíèé óãîë:
3294 aX2 := aX + aX2 - 1;
3295 aY2 := aY + aY2 - 1;
3297 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3298 end;
3299 end;
3300 if gAcid1 <> nil then
3301 begin
3302 // Ðèñóåì êèñëîòó 1:
3303 for a := 0 to High(gAcid1) do
3304 with gAcid1[a] do
3305 if PanelType <> 0 then
3306 begin
3307 // Ëåâûé âåðõíèé óãîë:
3308 aX := X div ScaleSz;
3309 aY := Y div ScaleSz;
3310 // Ðàçìåðû:
3311 aX2 := max(Width div ScaleSz, 1);
3312 aY2 := max(Height div ScaleSz, 1);
3313 // Ïðàâûé íèæíèé óãîë:
3314 aX2 := aX + aX2 - 1;
3315 aY2 := aY + aY2 - 1;
3317 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3318 end;
3319 end;
3320 if gAcid2 <> nil then
3321 begin
3322 // Ðèñóåì êèñëîòó 2:
3323 for a := 0 to High(gAcid2) do
3324 with gAcid2[a] do
3325 if PanelType <> 0 then
3326 begin
3327 // Ëåâûé âåðõíèé óãîë:
3328 aX := X div ScaleSz;
3329 aY := Y div ScaleSz;
3330 // Ðàçìåðû:
3331 aX2 := max(Width div ScaleSz, 1);
3332 aY2 := max(Height div ScaleSz, 1);
3333 // Ïðàâûé íèæíèé óãîë:
3334 aX2 := aX + aX2 - 1;
3335 aY2 := aY + aY2 - 1;
3337 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3338 end;
3339 end;
3340 if gPlayers <> nil then
3341 begin
3342 // Ðèñóåì èãðîêîâ:
3343 for a := 0 to High(gPlayers) do
3344 if gPlayers[a] <> nil then with gPlayers[a] do
3345 if alive then begin
3346 // Ëåâûé âåðõíèé óãîë:
3347 aX := Obj.X div ScaleSz + 1;
3348 aY := Obj.Y div ScaleSz + 1;
3349 // Ðàçìåðû:
3350 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3351 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3352 // Ïðàâûé íèæíèé óãîë:
3353 aX2 := aX + aX2 - 1;
3354 aY2 := aY + aY2 - 1;
3356 if gPlayers[a] = p then
3357 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3358 else
3359 case Team of
3360 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3361 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3362 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3363 end;
3364 end;
3365 end;
3366 // Ðèñóåì ìîíñòðîâ
3367 g_Mons_ForEach(monDraw);
3368 end;
3369 end;
3372 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3373 begin
3374 if not hasAmbient then exit;
3375 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3376 end;
3379 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3380 //FIXME: broken for splitscreen mode
3381 procedure renderDynLightsInternal ();
3382 var
3383 //hasAmbient: Boolean;
3384 //ambColor: TDFColor;
3385 lln: Integer;
3386 lx, ly, lrad: Integer;
3387 scxywh: array[0..3] of GLint;
3388 wassc: Boolean;
3389 begin
3390 if e_NoGraphics then exit;
3392 //TODO: lights should be in separate grid, i think
3393 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3394 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3396 // rendering mode
3397 //ambColor := gCurrentMap['light_ambient'].rgba;
3398 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3400 { // this will multiply incoming color to alpha from framebuffer
3401 glEnable(GL_BLEND);
3402 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3405 (*
3406 * light rendering: (INVALID!)
3407 * glStencilFunc(GL_EQUAL, 0, $ff);
3408 * for each light:
3409 * glClear(GL_STENCIL_BUFFER_BIT);
3410 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3411 * draw shadow volume into stencil buffer
3412 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3413 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3414 * turn off blending
3415 * draw color-less quad with light alpha (WARNING! don't touch color!)
3416 * glEnable(GL_BLEND);
3417 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3418 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3419 *)
3420 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3421 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3423 // setup OpenGL parameters
3424 glStencilMask($FFFFFFFF);
3425 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3426 glEnable(GL_STENCIL_TEST);
3427 glEnable(GL_SCISSOR_TEST);
3428 glClear(GL_STENCIL_BUFFER_BIT);
3429 glStencilFunc(GL_EQUAL, 0, $ff);
3431 for lln := 0 to g_dynLightCount-1 do
3432 begin
3433 lx := g_dynLights[lln].x;
3434 ly := g_dynLights[lln].y;
3435 lrad := g_dynLights[lln].radius;
3436 if (lrad < 3) then continue;
3438 if (lx-sX+lrad < 0) then continue;
3439 if (ly-sY+lrad < 0) then continue;
3440 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3441 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3443 // set scissor to optimize drawing
3444 if (g_dbg_scale = 1.0) then
3445 begin
3446 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3447 end
3448 else
3449 begin
3450 glScissor(0, 0, gScreenWidth, gScreenHeight);
3451 end;
3452 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3453 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3454 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3455 // draw extruded panels
3456 glDisable(GL_TEXTURE_2D);
3457 glDisable(GL_BLEND);
3458 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3459 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3460 // render light texture
3461 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3462 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3463 // blend it
3464 glEnable(GL_BLEND);
3465 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3466 glEnable(GL_TEXTURE_2D);
3467 // color and opacity
3468 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3469 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3470 glBegin(GL_QUADS);
3471 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3472 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3473 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3474 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3475 glEnd();
3476 end;
3478 // done
3479 glDisable(GL_STENCIL_TEST);
3480 glDisable(GL_BLEND);
3481 glDisable(GL_SCISSOR_TEST);
3482 //glScissor(0, 0, sWidth, sHeight);
3484 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3485 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3486 end;
3489 function fixViewportForScale (): Boolean;
3490 var
3491 nx0, ny0, nw, nh: Integer;
3492 begin
3493 result := false;
3494 if (g_dbg_scale <> 1.0) then
3495 begin
3496 result := true;
3497 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3498 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3499 nw := round(sWidth/g_dbg_scale);
3500 nh := round(sHeight/g_dbg_scale);
3501 sX := nx0;
3502 sY := ny0;
3503 sWidth := nw;
3504 sHeight := nh;
3505 end;
3506 end;
3509 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3510 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3511 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3512 type
3513 TDrawCB = procedure ();
3515 var
3516 hasAmbient: Boolean;
3517 ambColor: TDFColor;
3518 doAmbient: Boolean = false;
3520 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3521 var
3522 tagmask: Integer;
3523 pan: TPanel;
3524 begin
3525 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3526 if gdbg_map_use_accel_render then
3527 begin
3528 tagmask := panelTypeToTag(panType);
3529 while (gDrawPanelList.count > 0) do
3530 begin
3531 pan := TPanel(gDrawPanelList.front());
3532 if ((pan.tag and tagmask) = 0) then break;
3533 if doDraw then pan.Draw(doAmbient, ambColor);
3534 gDrawPanelList.popFront();
3535 end;
3536 end
3537 else
3538 begin
3539 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3540 end;
3541 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3542 end;
3544 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3545 begin
3546 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3547 if assigned(cb) then cb();
3548 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3549 end;
3551 begin
3552 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3554 // our accelerated renderer will collect all panels to gDrawPanelList
3555 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3556 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3557 if gdbg_map_use_accel_render then
3558 begin
3559 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3560 end;
3561 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3563 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3564 g_Map_DrawBack(backXOfs, backYOfs);
3565 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3567 if setTransMatrix then
3568 begin
3569 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3570 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3571 glTranslatef(-sX, -sY, 0);
3572 end;
3574 // rendering mode
3575 ambColor := gCurrentMap['light_ambient'].rgba;
3576 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3579 if hasAmbient then
3580 begin
3581 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3582 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3583 glClear(GL_COLOR_BUFFER_BIT);
3584 end;
3586 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3589 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3590 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3591 drawOther('items', @g_Items_Draw);
3592 drawOther('weapons', @g_Weapon_Draw);
3593 drawOther('shells', @g_Player_DrawShells);
3594 drawOther('drawall', @g_Player_DrawAll);
3595 drawOther('corpses', @g_Player_DrawCorpses);
3596 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3597 drawOther('monsters', @g_Monsters_Draw);
3598 drawOther('itemdrop', @g_Items_DrawDrop);
3599 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3600 drawOther('gfx', @g_GFX_Draw);
3601 drawOther('flags', @g_Map_DrawFlags);
3602 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3603 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3604 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3605 drawOther('dynlights', @renderDynLightsInternal);
3607 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3608 begin
3609 renderAmbientQuad(hasAmbient, ambColor);
3610 end;
3612 doAmbient := true;
3613 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3616 if g_debug_HealthBar then
3617 begin
3618 g_Monsters_DrawHealth();
3619 g_Player_DrawHealth();
3620 end;
3622 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3623 end;
3626 procedure DrawMapView(x, y, w, h: Integer);
3628 var
3629 bx, by: Integer;
3630 begin
3631 glPushMatrix();
3633 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3634 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3636 sX := x;
3637 sY := y;
3638 sWidth := w;
3639 sHeight := h;
3641 fixViewportForScale();
3642 renderMapInternal(-bx, -by, true);
3644 glPopMatrix();
3645 end;
3648 procedure DrawPlayer(p: TPlayer);
3649 var
3650 px, py, a, b, c, d, i, fX, fY: Integer;
3651 camObj: TObj;
3652 //R: TRect;
3653 begin
3654 if (p = nil) or (p.FDummy) then
3655 begin
3656 glPushMatrix();
3657 g_Map_DrawBack(0, 0);
3658 glPopMatrix();
3659 Exit;
3660 end;
3662 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3663 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3665 gPlayerDrawn := p;
3667 glPushMatrix();
3669 camObj := p.getCameraObj();
3670 camObj.lerp(gLerpFactor, fX, fY);
3671 px := fX + PLAYER_RECT_CX;
3672 py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, camObj.slopeUpLeft, gLerpFactor);
3674 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3675 begin
3676 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3677 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3679 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3680 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3682 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3683 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3684 begin
3685 // hcenter
3686 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3687 end;
3689 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3690 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3691 begin
3692 // vcenter
3693 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3694 end;
3695 end
3696 else
3697 begin
3698 // scaled, ignore level bounds
3699 a := -px+(gPlayerScreenSize.X div 2);
3700 b := -py+(gPlayerScreenSize.Y div 2);
3701 end;
3703 sX := -a;
3704 sY := -b;
3705 sWidth := gPlayerScreenSize.X;
3706 sHeight := gPlayerScreenSize.Y;
3707 fixViewportForScale();
3709 i := py - (sY + sHeight div 2);
3710 if (p.IncCam > 0) then
3711 begin
3712 // clamp to level bounds
3713 if (sY - p.IncCam < 0) then
3714 p.IncCam := nclamp(sY, 0, 120);
3715 // clamp around player position
3716 if (i > 0) then
3717 p.IncCam := nclamp(p.IncCam, 0, max(0, 120 - i));
3718 end
3719 else if (p.IncCam < 0) then
3720 begin
3721 // clamp to level bounds
3722 if (sY + sHeight - p.IncCam > gMapInfo.Height) then
3723 p.IncCam := nclamp(sY + sHeight - gMapInfo.Height, -120, 0);
3724 // clamp around player position
3725 if (i < 0) then
3726 p.IncCam := nclamp(p.IncCam, min(0, -120 - i), 0);
3727 end;
3729 sY := sY - nlerp(p.IncCamOld, p.IncCam, gLerpFactor);
3731 if (not g_dbg_ignore_bounds) then
3732 begin
3733 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3734 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3735 if (sX < 0) then sX := 0;
3736 if (sY < 0) then sY := 0;
3737 end;
3739 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3740 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3742 //r_smallmap_h: 0: left; 1: center; 2: right
3743 //r_smallmap_v: 0: top; 1: center; 2: bottom
3744 // horiz small map?
3745 if (gMapInfo.Width = sWidth) then
3746 begin
3747 sX := 0;
3748 end
3749 else if (gMapInfo.Width < sWidth) then
3750 begin
3751 case r_smallmap_h of
3752 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3753 2: sX := -(sWidth-gMapInfo.Width); // right
3754 else sX := 0; // left
3755 end;
3756 end;
3757 // vert small map?
3758 if (gMapInfo.Height = sHeight) then
3759 begin
3760 sY := 0;
3761 end
3762 else if (gMapInfo.Height < sHeight) then
3763 begin
3764 case r_smallmap_v of
3765 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3766 2: sY := -(sHeight-gMapInfo.Height); // bottom
3767 else sY := 0; // top
3768 end;
3769 end;
3771 p.viewPortX := sX;
3772 p.viewPortY := sY;
3773 p.viewPortW := sWidth;
3774 p.viewPortH := sHeight;
3776 {$IFDEF ENABLE_HOLMES}
3777 if (p = gPlayer1) then
3778 begin
3779 g_Holmes_plrViewPos(sX, sY);
3780 g_Holmes_plrViewSize(sWidth, sHeight);
3781 end;
3782 {$ENDIF}
3784 renderMapInternal(-c, -d, true);
3786 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3787 case gPlayerIndicator of
3788 1:
3789 p.DrawIndicator(_RGB(255, 255, 255));
3791 2:
3792 for i := 0 to High(gPlayers) do
3793 if gPlayers[i] <> nil then
3794 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3795 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3796 if gPlayerIndicatorStyle = 1 then
3797 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3798 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3799 end;
3802 for a := 0 to High(gCollideMap) do
3803 for b := 0 to High(gCollideMap[a]) do
3804 begin
3805 d := 0;
3806 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3807 d := d + 1;
3808 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3809 d := d + 2;
3811 case d of
3812 1: e_DrawPoint(1, b, a, 200, 200, 200);
3813 2: e_DrawPoint(1, b, a, 64, 64, 255);
3814 3: e_DrawPoint(1, b, a, 255, 0, 255);
3815 end;
3816 end;
3819 glPopMatrix();
3821 p.DrawPain();
3822 p.DrawPickup();
3823 p.DrawRulez();
3824 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3825 if g_Debug_Player then
3826 g_Player_DrawDebug(p);
3827 p.DrawGUI();
3828 end;
3830 procedure drawProfilers ();
3831 var
3832 px: Integer = -1;
3833 py: Integer = -1;
3834 begin
3835 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3836 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3837 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3838 end;
3840 procedure g_Game_Draw();
3841 var
3842 ID: DWORD;
3843 w, h: Word;
3844 ww, hh: Byte;
3845 Time: Int64;
3846 back: string;
3847 plView1, plView2: TPlayer;
3848 Split: Boolean;
3849 begin
3850 if gExit = EXIT_QUIT then Exit;
3852 Time := sys_GetTicks() {div 1000};
3853 FPSCounter := FPSCounter+1;
3854 if Time - FPSTime >= 1000 then
3855 begin
3856 FPS := FPSCounter;
3857 FPSCounter := 0;
3858 FPSTime := Time;
3859 end;
3861 e_SetRendertarget(True);
3862 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3864 if gGameOn or (gState = STATE_FOLD) then
3865 begin
3866 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3867 begin
3868 gSpectMode := SPECT_NONE;
3869 if not gRevertPlayers then
3870 begin
3871 plView1 := gPlayer1;
3872 plView2 := gPlayer2;
3873 end
3874 else
3875 begin
3876 plView1 := gPlayer2;
3877 plView2 := gPlayer1;
3878 end;
3879 end
3880 else
3881 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3882 begin
3883 gSpectMode := SPECT_NONE;
3884 if gPlayer2 = nil then
3885 plView1 := gPlayer1
3886 else
3887 plView1 := gPlayer2;
3888 plView2 := nil;
3889 end
3890 else
3891 begin
3892 plView1 := nil;
3893 plView2 := nil;
3894 end;
3896 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3897 gSpectMode := SPECT_STATS;
3899 if gSpectMode = SPECT_PLAYERS then
3900 if gPlayers <> nil then
3901 begin
3902 plView1 := GetActivePlayer_ByID(gSpectPID1);
3903 if plView1 = nil then
3904 begin
3905 gSpectPID1 := GetActivePlayerID_Next();
3906 plView1 := GetActivePlayer_ByID(gSpectPID1);
3907 end;
3908 if gSpectViewTwo then
3909 begin
3910 plView2 := GetActivePlayer_ByID(gSpectPID2);
3911 if plView2 = nil then
3912 begin
3913 gSpectPID2 := GetActivePlayerID_Next();
3914 plView2 := GetActivePlayer_ByID(gSpectPID2);
3915 end;
3916 end;
3917 end;
3919 if gSpectMode = SPECT_MAPVIEW then
3920 begin
3921 // Ðåæèì ïðîñìîòðà êàðòû
3922 Split := False;
3923 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3924 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3925 gHearPoint1.Active := True;
3926 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3927 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3928 gHearPoint2.Active := False;
3929 end
3930 else
3931 begin
3932 Split := (plView1 <> nil) and (plView2 <> nil);
3934 // Òî÷êè ñëóõà èãðîêîâ
3935 if plView1 <> nil then
3936 begin
3937 gHearPoint1.Active := True;
3938 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3939 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3940 end else
3941 gHearPoint1.Active := False;
3942 if plView2 <> nil then
3943 begin
3944 gHearPoint2.Active := True;
3945 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3946 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3947 end else
3948 gHearPoint2.Active := False;
3950 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3951 gPlayerScreenSize.X := gScreenWidth-196;
3952 if Split then
3953 begin
3954 gPlayerScreenSize.Y := gScreenHeight div 2;
3955 if gScreenHeight mod 2 = 0 then
3956 Dec(gPlayerScreenSize.Y);
3957 end
3958 else
3959 gPlayerScreenSize.Y := gScreenHeight;
3961 if Split then
3962 if gScreenHeight mod 2 = 0 then
3963 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3964 else
3965 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3967 DrawPlayer(plView1);
3968 gPlayer1ScreenCoord.X := sX;
3969 gPlayer1ScreenCoord.Y := sY;
3971 if Split then
3972 begin
3973 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3975 DrawPlayer(plView2);
3976 gPlayer2ScreenCoord.X := sX;
3977 gPlayer2ScreenCoord.Y := sY;
3978 end;
3980 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3982 if Split then
3983 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3984 end;
3986 {$IFDEF ENABLE_HOLMES}
3987 // draw inspector
3988 if (g_holmes_enabled) then g_Holmes_Draw();
3989 {$ENDIF}
3991 if MessageText <> '' then
3992 begin
3993 w := 0;
3994 h := 0;
3995 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3996 if Split then
3997 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3998 (gScreenHeight div 2)-(h div 2), MessageText)
3999 else
4000 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4001 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4002 end;
4004 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4005 DrawStat();
4007 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4008 begin
4009 // Draw spectator GUI
4010 ww := 0;
4011 hh := 0;
4012 e_TextureFontGetSize(gStdFont, ww, hh);
4013 case gSpectMode of
4014 SPECT_STATS:
4015 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4016 SPECT_MAPVIEW:
4017 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4018 SPECT_PLAYERS:
4019 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4020 end;
4021 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4022 if gSpectMode = SPECT_STATS then
4023 begin
4024 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4025 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4026 end;
4027 if gSpectMode = SPECT_MAPVIEW then
4028 begin
4029 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4030 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4031 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4032 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4033 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4034 end;
4035 if gSpectMode = SPECT_PLAYERS then
4036 begin
4037 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4038 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4039 if gSpectViewTwo then
4040 begin
4041 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4042 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4043 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4044 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4045 end
4046 else
4047 begin
4048 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4049 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4050 end;
4051 end;
4052 end;
4053 end;
4055 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4056 begin
4057 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4058 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4060 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4061 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4062 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4063 end;
4065 if not gGameOn then
4066 begin
4067 if (gState = STATE_MENU) then
4068 begin
4069 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4070 // F3 at menu will show game loading dialog
4071 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4072 if (g_ActiveWindow <> nil) then
4073 begin
4074 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4075 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4076 end
4077 else
4078 begin
4079 // F3 at titlepic will show game loading dialog
4080 if e_KeyPressed(IK_F3) then
4081 begin
4082 g_Menu_Show_LoadMenu(true);
4083 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4084 end;
4085 end;
4086 end;
4088 if gState = STATE_FOLD then
4089 begin
4090 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4091 end;
4093 if gState = STATE_INTERCUSTOM then
4094 begin
4095 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4096 begin
4097 back := 'TEXTURE_endpic';
4098 if not g_Texture_Get(back, ID) then
4099 back := _lc[I_TEXTURE_ENDPIC];
4100 end
4101 else
4102 back := 'INTER';
4104 DrawMenuBackground(back);
4106 DrawCustomStat();
4108 if g_ActiveWindow <> nil then
4109 begin
4110 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4111 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4112 end;
4113 end;
4115 if gState = STATE_INTERSINGLE then
4116 begin
4117 if EndingGameCounter > 0 then
4118 begin
4119 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4120 end
4121 else
4122 begin
4123 back := 'INTER';
4125 DrawMenuBackground(back);
4127 DrawSingleStat();
4129 if g_ActiveWindow <> nil then
4130 begin
4131 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4132 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4133 end;
4134 end;
4135 end;
4137 if gState = STATE_ENDPIC then
4138 begin
4139 ID := DWORD(-1);
4140 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4141 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4143 if g_ActiveWindow <> nil then
4144 begin
4145 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4146 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4147 end;
4148 end;
4150 if gState = STATE_SLIST then
4151 begin
4152 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4153 // begin
4154 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4155 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4156 // end;
4157 DrawMenuBackground('MENU_BACKGROUND');
4158 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4159 g_Serverlist_Draw(slCurrent, slTable);
4160 end;
4161 end;
4163 if g_ActiveWindow <> nil then
4164 begin
4165 if gGameOn then
4166 begin
4167 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4168 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4169 end;
4170 g_ActiveWindow.Draw();
4171 end;
4173 {$IFNDEF HEADLESS}
4174 g_Console_Draw();
4175 {$ENDIF}
4177 if g_debug_Sounds and gGameOn then
4178 begin
4179 for w := 0 to High(e_SoundsArray) do
4180 for h := 0 to e_SoundsArray[w].nRefs do
4181 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4182 end;
4184 if gShowFPS then
4185 begin
4186 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4187 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4188 end;
4190 if gGameOn and gShowTime then
4191 drawTime(gScreenWidth-72, gScreenHeight-16);
4193 if gGameOn then drawProfilers();
4195 // TODO: draw this after the FBO and remap mouse click coordinates
4197 {$IFDEF ENABLE_HOLMES}
4198 g_Holmes_DrawUI();
4199 {$ENDIF}
4201 // blit framebuffer to screen
4203 e_SetRendertarget(False);
4204 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4205 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4207 // draw the overlay stuff on top of it
4209 g_Touch_Draw;
4210 end;
4212 procedure g_Game_Quit();
4213 begin
4214 g_Game_StopAllSounds(True);
4215 gMusic.Free();
4216 g_Game_FreeData();
4217 g_PlayerModel_FreeData();
4218 g_Texture_DeleteAll();
4219 g_Frames_DeleteAll();
4220 {$IFNDEF HEADLESS}
4221 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4222 {$ENDIF}
4224 if NetInitDone then g_Net_Free;
4226 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4227 if gMapToDelete <> '' then
4228 g_Game_DeleteTestMap();
4230 gExit := EXIT_QUIT;
4231 sys_RequestQuit;
4232 end;
4234 procedure g_FatalError(Text: String);
4235 begin
4236 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4237 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4239 gExit := EXIT_SIMPLE;
4240 if gGameOn then EndGame;
4241 end;
4243 procedure g_SimpleError(Text: String);
4244 begin
4245 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4246 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4247 end;
4249 procedure g_Game_SetupScreenSize();
4250 const
4251 RES_FACTOR = 4.0 / 3.0;
4252 var
4253 s: Single;
4254 rf: Single;
4255 bw, bh: Word;
4256 begin
4257 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4258 gPlayerScreenSize.X := gScreenWidth-196;
4259 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4260 gPlayerScreenSize.Y := gScreenHeight div 2
4261 else
4262 gPlayerScreenSize.Y := gScreenHeight;
4264 // Ðàçìåð çàäíåãî ïëàíà:
4265 if BackID <> DWORD(-1) then
4266 begin
4267 s := SKY_STRETCH;
4268 if (gScreenWidth*s > gMapInfo.Width) or
4269 (gScreenHeight*s > gMapInfo.Height) then
4270 begin
4271 gBackSize.X := gScreenWidth;
4272 gBackSize.Y := gScreenHeight;
4273 end
4274 else
4275 begin
4276 e_GetTextureSize(BackID, @bw, @bh);
4277 rf := Single(bw) / Single(bh);
4278 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4279 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4280 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4281 if (s < 1.0) then s := 1.0;
4282 gBackSize.X := Round(bw*s);
4283 gBackSize.Y := Round(bh*s);
4284 end;
4285 end;
4286 end;
4288 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4289 begin
4290 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4291 end;
4293 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4294 begin
4295 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4296 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4297 Exit;
4299 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4300 Exit;
4302 if gPlayer1 = nil then
4303 begin
4304 if g_Game_IsClient then
4305 begin
4306 if NetPlrUID1 > -1 then
4307 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4308 Exit;
4309 end;
4311 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4312 Team := gPlayer1Settings.Team;
4314 // Ñîçäàíèå ïåðâîãî èãðîêà:
4315 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4316 gPlayer1Settings.Color,
4317 Team, False));
4318 if gPlayer1 = nil then
4319 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4320 else
4321 begin
4322 gPlayer1.Name := gPlayer1Settings.Name;
4323 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4324 if g_Game_IsServer and g_Game_IsNet then
4325 MH_SEND_PlayerCreate(gPlayer1.UID);
4326 gPlayer1.Respawn(False, True);
4327 g_Net_Slist_ServerPlayerComes();
4328 end;
4330 Exit;
4331 end;
4332 if gPlayer2 = nil then
4333 begin
4334 if g_Game_IsClient then
4335 begin
4336 if NetPlrUID2 > -1 then
4337 gPlayer2 := g_Player_Get(NetPlrUID2);
4338 Exit;
4339 end;
4341 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4342 Team := gPlayer2Settings.Team;
4344 // Ñîçäàíèå âòîðîãî èãðîêà:
4345 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4346 gPlayer2Settings.Color,
4347 Team, False));
4348 if gPlayer2 = nil then
4349 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4350 else
4351 begin
4352 gPlayer2.Name := gPlayer2Settings.Name;
4353 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4354 if g_Game_IsServer and g_Game_IsNet then
4355 MH_SEND_PlayerCreate(gPlayer2.UID);
4356 gPlayer2.Respawn(False, True);
4357 g_Net_Slist_ServerPlayerComes();
4358 end;
4360 Exit;
4361 end;
4362 end;
4364 procedure g_Game_RemovePlayer();
4365 var
4366 Pl: TPlayer;
4367 begin
4368 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4369 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4370 Exit;
4371 Pl := gPlayer2;
4372 if Pl <> nil then
4373 begin
4374 if g_Game_IsServer then
4375 begin
4376 Pl.Lives := 0;
4377 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4378 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4379 g_Player_Remove(Pl.UID);
4380 g_Net_Slist_ServerPlayerLeaves();
4381 end
4382 else
4383 begin
4384 gSpectLatchPID2 := Pl.UID;
4385 gPlayer2 := nil;
4386 end;
4387 Exit;
4388 end;
4389 Pl := gPlayer1;
4390 if Pl <> nil then
4391 begin
4392 if g_Game_IsServer then
4393 begin
4394 Pl.Lives := 0;
4395 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4396 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4397 g_Player_Remove(Pl.UID);
4398 g_Net_Slist_ServerPlayerLeaves();
4399 end else
4400 begin
4401 gSpectLatchPID1 := Pl.UID;
4402 gPlayer1 := nil;
4403 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4404 end;
4405 Exit;
4406 end;
4407 g_Net_Slist_ServerPlayerLeaves();
4408 end;
4410 procedure g_Game_Spectate();
4411 begin
4412 g_Game_RemovePlayer();
4413 if gPlayer1 <> nil then
4414 g_Game_RemovePlayer();
4415 end;
4417 procedure g_Game_SpectateCenterView();
4418 begin
4419 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4420 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4421 end;
4423 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4424 var
4425 i, nPl: Integer;
4426 tmps: AnsiString;
4427 begin
4428 g_Game_Free();
4430 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4432 g_Game_ClearLoading();
4434 // Íàñòðîéêè èãðû:
4435 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4436 gAimLine := False;
4437 gShowMap := False;
4438 gGameSettings.GameType := GT_SINGLE;
4439 gGameSettings.MaxLives := 0;
4440 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4441 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4442 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4443 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
4444 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
4445 gSwitchGameMode := GM_SINGLE;
4447 gLMSRespawn := LMS_RESPAWN_NONE;
4448 gLMSRespawnTime := 0;
4449 gSpectLatchPID1 := 0;
4450 gSpectLatchPID2 := 0;
4452 g_Game_ExecuteEvent('ongamestart');
4454 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4455 g_Game_SetupScreenSize();
4457 // Ñîçäàíèå ïåðâîãî èãðîêà:
4458 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4459 gPlayer1Settings.Color,
4460 gPlayer1Settings.Team, False));
4461 if gPlayer1 = nil then
4462 begin
4463 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4464 Exit;
4465 end;
4467 gPlayer1.Name := gPlayer1Settings.Name;
4468 nPl := 1;
4470 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4471 if TwoPlayers then
4472 begin
4473 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4474 gPlayer2Settings.Color,
4475 gPlayer2Settings.Team, False));
4476 if gPlayer2 = nil then
4477 begin
4478 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4479 Exit;
4480 end;
4482 gPlayer2.Name := gPlayer2Settings.Name;
4483 Inc(nPl);
4484 end;
4486 // Çàãðóçêà è çàïóñê êàðòû:
4487 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4488 begin
4489 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4490 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4491 Exit;
4492 end;
4494 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4495 g_Player_Init();
4497 // Ñîçäàåì áîòîâ:
4498 for i := nPl+1 to nPlayers do
4499 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4500 end;
4502 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4503 TimeLimit, GoalLimit: Word;
4504 MaxLives: Byte;
4505 Options: LongWord; nPlayers: Byte);
4506 var
4507 i, nPl: Integer;
4508 begin
4509 g_Game_Free();
4511 e_WriteLog('Starting custom game...', TMsgType.Notify);
4513 g_Game_ClearLoading();
4515 // Íàñòðîéêè èãðû:
4516 gGameSettings.GameType := GT_CUSTOM;
4517 gGameSettings.GameMode := GameMode;
4518 gSwitchGameMode := GameMode;
4519 gGameSettings.TimeLimit := TimeLimit;
4520 gGameSettings.GoalLimit := GoalLimit;
4521 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4522 gGameSettings.Options := Options;
4524 gCoopTotalMonstersKilled := 0;
4525 gCoopTotalSecretsFound := 0;
4526 gCoopTotalMonsters := 0;
4527 gCoopTotalSecrets := 0;
4528 gAimLine := False;
4529 gShowMap := False;
4531 gLMSRespawn := LMS_RESPAWN_NONE;
4532 gLMSRespawnTime := 0;
4533 gSpectLatchPID1 := 0;
4534 gSpectLatchPID2 := 0;
4536 g_Game_ExecuteEvent('ongamestart');
4538 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4539 g_Game_SetupScreenSize();
4541 // Ðåæèì íàáëþäàòåëÿ:
4542 if nPlayers = 0 then
4543 begin
4544 gPlayer1 := nil;
4545 gPlayer2 := nil;
4546 end;
4548 nPl := 0;
4549 if nPlayers >= 1 then
4550 begin
4551 // Ñîçäàíèå ïåðâîãî èãðîêà:
4552 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4553 gPlayer1Settings.Color,
4554 gPlayer1Settings.Team, False));
4555 if gPlayer1 = nil then
4556 begin
4557 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4558 Exit;
4559 end;
4561 gPlayer1.Name := gPlayer1Settings.Name;
4562 Inc(nPl);
4563 end;
4565 if nPlayers >= 2 then
4566 begin
4567 // Ñîçäàíèå âòîðîãî èãðîêà:
4568 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4569 gPlayer2Settings.Color,
4570 gPlayer2Settings.Team, False));
4571 if gPlayer2 = nil then
4572 begin
4573 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4574 Exit;
4575 end;
4577 gPlayer2.Name := gPlayer2Settings.Name;
4578 Inc(nPl);
4579 end;
4581 // Çàãðóçêà è çàïóñê êàðòû:
4582 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4583 begin
4584 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4585 Exit;
4586 end;
4588 // Íåò òî÷åê ïîÿâëåíèÿ:
4589 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4590 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4591 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4592 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4593 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4594 begin
4595 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4596 Exit;
4597 end;
4599 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4600 g_Player_Init();
4602 // Ñîçäàåì áîòîâ:
4603 for i := nPl+1 to nPlayers do
4604 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4605 end;
4607 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4608 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4609 Options: LongWord; nPlayers: Byte;
4610 IPAddr: LongWord; Port: Word);
4611 begin
4612 g_Game_Free();
4613 g_Net_Slist_ServerClosed();
4615 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4617 g_Game_ClearLoading();
4619 // Íàñòðîéêè èãðû:
4620 gGameSettings.GameType := GT_SERVER;
4621 gGameSettings.GameMode := GameMode;
4622 gSwitchGameMode := GameMode;
4623 gGameSettings.TimeLimit := TimeLimit;
4624 gGameSettings.GoalLimit := GoalLimit;
4625 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4626 gGameSettings.Options := Options;
4628 gCoopTotalMonstersKilled := 0;
4629 gCoopTotalSecretsFound := 0;
4630 gCoopTotalMonsters := 0;
4631 gCoopTotalSecrets := 0;
4632 gAimLine := False;
4633 gShowMap := False;
4635 gLMSRespawn := LMS_RESPAWN_NONE;
4636 gLMSRespawnTime := 0;
4637 gSpectLatchPID1 := 0;
4638 gSpectLatchPID2 := 0;
4640 g_Game_ExecuteEvent('ongamestart');
4642 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4643 g_Game_SetupScreenSize();
4645 // Ðåæèì íàáëþäàòåëÿ:
4646 if nPlayers = 0 then
4647 begin
4648 gPlayer1 := nil;
4649 gPlayer2 := nil;
4650 end;
4652 if nPlayers >= 1 then
4653 begin
4654 // Ñîçäàíèå ïåðâîãî èãðîêà:
4655 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4656 gPlayer1Settings.Color,
4657 gPlayer1Settings.Team, False));
4658 if gPlayer1 = nil then
4659 begin
4660 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4661 Exit;
4662 end;
4664 gPlayer1.Name := gPlayer1Settings.Name;
4665 end;
4667 if nPlayers >= 2 then
4668 begin
4669 // Ñîçäàíèå âòîðîãî èãðîêà:
4670 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4671 gPlayer2Settings.Color,
4672 gPlayer2Settings.Team, False));
4673 if gPlayer2 = nil then
4674 begin
4675 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4676 Exit;
4677 end;
4679 gPlayer2.Name := gPlayer2Settings.Name;
4680 end;
4682 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4683 if NetForwardPorts then
4684 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4686 // Ñòàðòóåì ñåðâåð
4687 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4688 begin
4689 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4690 Exit;
4691 end;
4693 g_Net_Slist_Set(NetMasterList);
4695 g_Net_Slist_ServerStarted();
4697 // Çàãðóçêà è çàïóñê êàðòû:
4698 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4699 begin
4700 g_Net_Slist_ServerClosed();
4701 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4702 Exit;
4703 end;
4705 // Íåò òî÷åê ïîÿâëåíèÿ:
4706 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4707 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4708 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4709 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4710 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4711 begin
4712 g_Net_Slist_ServerClosed();
4713 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4714 Exit;
4715 end;
4717 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4718 g_Player_Init();
4720 g_Net_Slist_ServerMapStarted();
4721 NetState := NET_STATE_GAME;
4722 end;
4724 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4725 var
4726 Map: String;
4727 WadName: string;
4728 Ptr: Pointer;
4729 T: Cardinal;
4730 MID: Byte;
4731 State: Byte;
4732 OuterLoop: Boolean;
4733 newResPath: string;
4734 InMsg: TMsg;
4735 begin
4736 g_Game_Free();
4738 State := 0;
4739 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4740 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4742 g_Game_ClearLoading();
4744 // Íàñòðîéêè èãðû:
4745 gGameSettings.GameType := GT_CLIENT;
4747 gCoopTotalMonstersKilled := 0;
4748 gCoopTotalSecretsFound := 0;
4749 gCoopTotalMonsters := 0;
4750 gCoopTotalSecrets := 0;
4751 gAimLine := False;
4752 gShowMap := False;
4754 g_Game_ExecuteEvent('ongamestart');
4756 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4757 g_Game_SetupScreenSize();
4759 NetState := NET_STATE_AUTH;
4761 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4763 // create (or update) map/resource databases
4764 g_Res_CreateDatabases(true);
4766 gLMSRespawn := LMS_RESPAWN_NONE;
4767 gLMSRespawnTime := 0;
4768 gSpectLatchPID1 := 0;
4769 gSpectLatchPID2 := 0;
4771 // Ñòàðòóåì êëèåíò
4772 if not g_Net_Connect(Addr, Port) then
4773 begin
4774 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4775 NetState := NET_STATE_NONE;
4776 Exit;
4777 end;
4779 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4780 MC_SEND_Info(PW);
4781 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4783 OuterLoop := True;
4784 while OuterLoop do
4785 begin
4786 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4787 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4788 // thank you, enet. let's ignore failures altogether then.
4789 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4790 begin
4791 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4792 begin
4793 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
4794 begin
4795 // ignore all download packets, they're processed by separate code
4796 enet_packet_destroy(NetEvent.packet);
4797 continue;
4798 end;
4799 Ptr := NetEvent.packet^.data;
4800 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4801 begin
4802 enet_packet_destroy(NetEvent.packet);
4803 continue;
4804 end;
4806 InMsg.ReadLongWord(); // skip size
4807 MID := InMsg.ReadByte();
4809 if (MID = NET_MSG_INFO) and (State = 0) then
4810 begin
4811 NetMyID := InMsg.ReadByte();
4812 NetPlrUID1 := InMsg.ReadWord();
4814 WadName := InMsg.ReadString();
4815 Map := InMsg.ReadString();
4817 gWADHash := InMsg.ReadMD5();
4819 gGameSettings.GameMode := InMsg.ReadByte();
4820 gSwitchGameMode := gGameSettings.GameMode;
4821 gGameSettings.GoalLimit := InMsg.ReadWord();
4822 gGameSettings.TimeLimit := InMsg.ReadWord();
4823 gGameSettings.MaxLives := InMsg.ReadByte();
4824 gGameSettings.Options := InMsg.ReadLongWord();
4825 T := InMsg.ReadLongWord();
4827 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4828 //if newResPath = '' then
4829 begin
4830 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4831 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4832 if newResPath = '' then
4833 begin
4834 g_FatalError(_lc[I_NET_ERR_HASH]);
4835 enet_packet_destroy(NetEvent.packet);
4836 NetState := NET_STATE_NONE;
4837 Exit;
4838 end;
4839 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4840 end;
4841 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4844 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4845 gPlayer1Settings.Color,
4846 gPlayer1Settings.Team, False));
4848 if gPlayer1 = nil then
4849 begin
4850 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4852 enet_packet_destroy(NetEvent.packet);
4853 NetState := NET_STATE_NONE;
4854 Exit;
4855 end;
4857 gPlayer1.Name := gPlayer1Settings.Name;
4858 gPlayer1.UID := NetPlrUID1;
4859 gPlayer1.Reset(True);
4861 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4862 begin
4863 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4865 enet_packet_destroy(NetEvent.packet);
4866 NetState := NET_STATE_NONE;
4867 Exit;
4868 end;
4870 gTime := T;
4872 State := 1;
4873 OuterLoop := False;
4874 enet_packet_destroy(NetEvent.packet);
4875 break;
4876 end
4877 else
4878 enet_packet_destroy(NetEvent.packet);
4879 end
4880 else
4881 begin
4882 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4883 begin
4884 State := 0;
4885 if (NetEvent.data <= NET_DISC_MAX) then
4886 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4887 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4888 OuterLoop := False;
4889 Break;
4890 end;
4891 end;
4892 end;
4894 ProcessLoading(true);
4896 if g_Net_UserRequestExit() then
4897 begin
4898 State := 0;
4899 break;
4900 end;
4901 end;
4903 if State <> 1 then
4904 begin
4905 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4906 NetState := NET_STATE_NONE;
4907 Exit;
4908 end;
4910 g_Player_Init();
4911 NetState := NET_STATE_GAME;
4912 MC_SEND_FullStateRequest;
4913 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4914 end;
4916 var
4917 lastAsMegaWad: Boolean = false;
4919 procedure g_Game_ChangeMap(const MapPath: String);
4920 var
4921 Force: Boolean;
4922 begin
4923 g_Game_ClearLoading();
4925 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4926 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4927 if gExitByTrigger then
4928 begin
4929 Force := False;
4930 gExitByTrigger := False;
4931 end;
4932 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
4933 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4934 end;
4936 procedure g_Game_Restart();
4937 var
4938 Map: string;
4939 begin
4940 if g_Game_IsClient then
4941 Exit;
4942 map := g_ExtractFileName(gMapInfo.Map);
4943 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
4945 MessageTime := 0;
4946 gGameOn := False;
4947 g_Game_ClearLoading();
4948 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
4949 end;
4951 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4952 var
4953 NewWAD, ResName: String;
4954 I: Integer;
4955 nws: AnsiString;
4956 begin
4957 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4958 g_Player_RemoveAllCorpses();
4960 if (not g_Game_IsClient) and
4961 (gSwitchGameMode <> gGameSettings.GameMode) and
4962 (gGameSettings.GameMode <> GM_SINGLE) then
4963 begin
4964 if gSwitchGameMode = GM_CTF then
4965 gGameSettings.MaxLives := 0;
4966 gGameSettings.GameMode := gSwitchGameMode;
4967 Force := True;
4968 end else
4969 gSwitchGameMode := gGameSettings.GameMode;
4971 g_Player_ResetTeams();
4973 lastAsMegaWad := asMegawad;
4974 if isWadPath(Map) then
4975 begin
4976 NewWAD := g_ExtractWadName(Map);
4977 ResName := g_ExtractFileName(Map);
4978 if g_Game_IsServer then
4979 begin
4980 nws := findDiskWad(NewWAD);
4981 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4982 if (asMegawad) then
4983 begin
4984 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4985 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4986 end
4987 else
4988 begin
4989 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4990 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4991 end;
4992 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4993 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4994 //nws := NewWAD;
4995 if (length(nws) = 0) then
4996 begin
4997 ResName := ''; // failed
4998 end
4999 else
5000 begin
5001 NewWAD := nws;
5002 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5003 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5004 g_Game_LoadWAD(NewWAD);
5005 end;
5006 end
5007 else
5008 begin
5009 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5010 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5011 end;
5012 end
5013 else
5014 begin
5015 NewWAD := gGameSettings.WAD;
5016 ResName := Map;
5017 end;
5019 gTime := 0;
5021 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5022 result := false;
5023 if (ResName <> '') and (NewWAD <> '') then
5024 begin
5025 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5026 result := g_Map_Load(NewWAD+':\'+ResName);
5027 end;
5028 if Result then
5029 begin
5030 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5032 gState := STATE_NONE;
5033 g_ActiveWindow := nil;
5034 gGameOn := True;
5036 DisableCheats();
5037 ResetTimer();
5039 if gGameSettings.GameMode = GM_CTF then
5040 begin
5041 g_Map_ResetFlag(FLAG_RED);
5042 g_Map_ResetFlag(FLAG_BLUE);
5043 // CTF, à ôëàãîâ íåò:
5044 if not g_Map_HaveFlagPoints() then
5045 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5046 end;
5047 end
5048 else
5049 begin
5050 gState := STATE_MENU;
5051 gGameOn := False;
5052 end;
5054 gExit := 0;
5055 gPauseMain := false;
5056 gPauseHolmes := false;
5057 NetTimeToUpdate := 1;
5058 NetTimeToReliable := 0;
5059 NetTimeToMaster := NetMasterRate;
5060 gSpectLatchPID1 := 0;
5061 gSpectLatchPID2 := 0;
5062 gMissionFailed := False;
5063 gNextMap := '';
5065 gCoopMonstersKilled := 0;
5066 gCoopSecretsFound := 0;
5068 gVoteInProgress := False;
5069 gVotePassed := False;
5070 gVoteCount := 0;
5071 gVoted := False;
5073 gStatsOff := False;
5075 if not gGameOn then Exit;
5077 g_Game_SpectateCenterView();
5079 if g_Game_IsServer then
5080 begin
5081 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5082 begin
5083 gLMSRespawn := LMS_RESPAWN_WARMUP;
5084 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5085 gLMSSoftSpawn := True;
5086 if g_Game_IsNet then
5087 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5088 end
5089 else
5090 begin
5091 gLMSRespawn := LMS_RESPAWN_NONE;
5092 gLMSRespawnTime := 0;
5093 end;
5094 end;
5096 if NetMode = NET_SERVER then
5097 begin
5098 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5100 // Ìàñòåðñåðâåð
5101 g_Net_Slist_ServerMapStarted();
5103 if NetClients <> nil then
5104 for I := 0 to High(NetClients) do
5105 if NetClients[I].Used then
5106 begin
5107 NetClients[I].Voted := False;
5108 if NetClients[I].RequestedFullUpdate then
5109 begin
5110 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5111 NetClients[I].RequestedFullUpdate := False;
5112 end;
5113 end;
5115 g_Net_UnbanNonPermHosts();
5116 end;
5118 if gLastMap then
5119 begin
5120 gCoopTotalMonstersKilled := 0;
5121 gCoopTotalSecretsFound := 0;
5122 gCoopTotalMonsters := 0;
5123 gCoopTotalSecrets := 0;
5124 gLastMap := False;
5125 end;
5127 g_Game_ExecuteEvent('onmapstart');
5128 end;
5130 procedure SetFirstLevel;
5131 begin
5132 gNextMap := '';
5134 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5135 if MapList = nil then
5136 Exit;
5138 SortSArray(MapList);
5139 gNextMap := MapList[Low(MapList)];
5141 MapList := nil;
5142 end;
5144 procedure g_Game_ExitLevel(const Map: AnsiString);
5145 begin
5146 gNextMap := Map;
5148 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5149 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5150 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5151 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5153 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5154 if gGameSettings.GameType = GT_SINGLE then
5155 gExit := EXIT_ENDLEVELSINGLE
5156 else // Âûøëè â âûõîä â Ñâîåé èãðå
5157 begin
5158 gExit := EXIT_ENDLEVELCUSTOM;
5159 if gGameSettings.GameMode = GM_COOP then
5160 g_Player_RememberAll;
5162 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5163 begin
5164 gLastMap := True;
5165 if gGameSettings.GameMode = GM_COOP then
5166 gStatsOff := True;
5168 gStatsPressed := True;
5169 gNextMap := 'MAP01';
5171 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5172 g_Game_NextLevel;
5174 if g_Game_IsNet then
5175 begin
5176 MH_SEND_GameStats();
5177 MH_SEND_CoopStats();
5178 end;
5179 end;
5180 end;
5181 end;
5183 procedure g_Game_RestartLevel();
5184 var
5185 Map: string;
5186 begin
5187 if gGameSettings.GameMode = GM_SINGLE then
5188 begin
5189 g_Game_Restart();
5190 Exit;
5191 end;
5192 gExit := EXIT_ENDLEVELCUSTOM;
5193 Map := g_ExtractFileName(gMapInfo.Map);
5194 gNextMap := Map;
5195 end;
5197 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5198 var
5199 gWAD{, xwad}: String;
5200 begin
5201 result := NewWAD;
5202 if not g_Game_IsClient then Exit;
5203 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5205 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5206 if gWAD = '' then
5207 begin
5208 result := '';
5209 g_Game_Free();
5210 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5211 Exit;
5212 end;
5214 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5215 NewWAD := gWAD;
5217 g_Game_LoadWAD(NewWAD);
5218 result := NewWAD;
5221 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5222 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5223 if gWAD = '' then
5224 begin
5225 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5226 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5227 if gWAD = '' then
5228 begin
5229 g_Game_Free();
5230 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5231 Exit;
5232 end;
5233 end;
5234 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5235 g_Game_LoadWAD(NewWAD);
5237 end;
5239 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5240 var
5241 i, n, nb, nr: Integer;
5242 begin
5243 if not g_Game_IsServer then Exit;
5244 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5245 gLMSRespawn := LMS_RESPAWN_NONE;
5246 gLMSRespawnTime := 0;
5247 MessageTime := 0;
5249 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5250 begin
5251 gMissionFailed := True;
5252 g_Game_RestartLevel;
5253 Exit;
5254 end;
5256 n := 0; nb := 0; nr := 0;
5257 for i := Low(gPlayers) to High(gPlayers) do
5258 if (gPlayers[i] <> nil) and
5259 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5260 (gPlayers[i] is TBot)) then
5261 begin
5262 Inc(n);
5263 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5264 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5265 end;
5267 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5268 begin
5269 // wait a second until the fuckers finally decide to join
5270 gLMSRespawn := LMS_RESPAWN_WARMUP;
5271 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5272 gLMSSoftSpawn := NoMapRestart;
5273 if g_Game_IsNet then
5274 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5275 Exit;
5276 end;
5278 g_Player_RemoveAllCorpses;
5279 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5280 if g_Game_IsNet then
5281 MH_SEND_GameEvent(NET_EV_LMS_START);
5283 for i := Low(gPlayers) to High(gPlayers) do
5284 begin
5285 if gPlayers[i] = nil then continue;
5286 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5287 // don't touch normal spectators
5288 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5289 begin
5290 gPlayers[i].FNoRespawn := True;
5291 gPlayers[i].Lives := 0;
5292 if g_Game_IsNet then
5293 MH_SEND_PlayerStats(gPlayers[I].UID);
5294 continue;
5295 end;
5296 gPlayers[i].FNoRespawn := False;
5297 gPlayers[i].Lives := gGameSettings.MaxLives;
5298 gPlayers[i].Respawn(False, True);
5299 if gGameSettings.GameMode = GM_COOP then
5300 begin
5301 gPlayers[i].Frags := 0;
5302 gPlayers[i].RecallState;
5303 end;
5304 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5305 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5306 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5307 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5308 end;
5310 g_Items_RestartRound();
5312 gLMSSoftSpawn := False;
5313 end;
5315 function g_Game_GetFirstMap(WAD: String): String;
5316 begin
5317 Result := '';
5319 MapList := g_Map_GetMapsList(WAD);
5320 if MapList = nil then
5321 Exit;
5323 SortSArray(MapList);
5324 Result := MapList[Low(MapList)];
5326 if not g_Map_Exist(WAD + ':\' + Result) then
5327 Result := '';
5329 MapList := nil;
5330 end;
5332 function g_Game_GetNextMap(): String;
5333 var
5334 I: Integer;
5335 Map: string;
5336 begin
5337 Result := '';
5339 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5340 if MapList = nil then
5341 Exit;
5343 Map := g_ExtractFileName(gMapInfo.Map);
5345 SortSArray(MapList);
5346 MapIndex := -255;
5347 for I := Low(MapList) to High(MapList) do
5348 if Map = MapList[I] then
5349 begin
5350 MapIndex := I;
5351 Break;
5352 end;
5354 if MapIndex <> -255 then
5355 begin
5356 if MapIndex = High(MapList) then
5357 Result := MapList[Low(MapList)]
5358 else
5359 Result := MapList[MapIndex + 1];
5361 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5362 end;
5364 MapList := nil;
5365 end;
5367 procedure g_Game_NextLevel();
5368 begin
5369 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5370 gExit := EXIT_ENDLEVELCUSTOM
5371 else
5372 begin
5373 gExit := EXIT_ENDLEVELSINGLE;
5374 Exit;
5375 end;
5377 if gNextMap <> '' then Exit;
5378 gNextMap := g_Game_GetNextMap();
5379 end;
5381 function g_Game_IsTestMap(): Boolean;
5382 begin
5383 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5384 end;
5386 procedure g_Game_DeleteTestMap();
5387 var
5388 a: Integer;
5389 //MapName: AnsiString;
5390 WadName: string;
5392 WAD: TWADFile;
5393 MapList: SSArray;
5394 time: Integer;
5396 begin
5397 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5398 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5399 if (a = 0) then exit;
5401 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5402 WadName := Copy(gMapToDelete, 1, a+3);
5403 Delete(gMapToDelete, 1, a+5);
5404 gMapToDelete := UpperCase(gMapToDelete);
5405 //MapName := '';
5406 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5409 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5410 if MapName <> TEST_MAP_NAME then
5411 Exit;
5413 if not gTempDelete then
5414 begin
5415 time := g_GetFileTime(WadName);
5416 WAD := TWADFile.Create();
5418 // ×èòàåì Wad-ôàéë:
5419 if not WAD.ReadFile(WadName) then
5420 begin // Íåò òàêîãî WAD-ôàéëà
5421 WAD.Free();
5422 Exit;
5423 end;
5425 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5426 WAD.CreateImage();
5427 MapList := WAD.GetResourcesList('');
5429 if MapList <> nil then
5430 for a := 0 to High(MapList) do
5431 if MapList[a] = MapName then
5432 begin
5433 // Óäàëÿåì è ñîõðàíÿåì:
5434 WAD.RemoveResource('', MapName);
5435 WAD.SaveTo(WadName);
5436 Break;
5437 end;
5439 WAD.Free();
5440 g_SetFileTime(WadName, time);
5441 end else
5443 if gTempDelete then DeleteFile(WadName);
5444 end;
5446 procedure GameCVars(P: SSArray);
5447 var
5448 a, b: Integer;
5449 stat: TPlayerStatArray;
5450 cmd: string;
5452 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5453 var
5454 x: Boolean;
5455 begin
5456 if Length(P) > 1 then
5457 begin
5458 x := P[1] = '1';
5460 if x then
5461 gsGameFlags := gsGameFlags or Flag
5462 else
5463 gsGameFlags := gsGameFlags and (not Flag);
5465 if g_Game_IsServer then
5466 begin
5467 if x then
5468 gGameSettings.Options := gGameSettings.Options or Flag
5469 else
5470 gGameSettings.Options := gGameSettings.Options and (not Flag);
5471 if g_Game_IsNet then MH_SEND_GameSettings;
5472 end;
5473 end;
5475 if LongBool(gsGameFlags and Flag) then
5476 g_Console_Add(_lc[OnMsg])
5477 else
5478 g_Console_Add(_lc[OffMsg]);
5480 if OnMapChange and g_Game_IsServer then
5481 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5482 end;
5484 begin
5485 stat := nil;
5486 cmd := LowerCase(P[0]);
5488 if cmd = 'g_gamemode' then
5489 begin
5490 if (Length(P) > 1) then
5491 begin
5492 a := g_Game_TextToMode(P[1]);
5493 if a = GM_SINGLE then a := GM_COOP;
5494 gsGameMode := g_Game_ModeToText(a);
5495 if g_Game_IsServer then
5496 begin
5497 gSwitchGameMode := a;
5498 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5499 (gState = STATE_INTERSINGLE) then
5500 gSwitchGameMode := GM_SINGLE;
5501 if not gGameOn then
5502 gGameSettings.GameMode := gSwitchGameMode;
5503 end;
5504 end;
5506 if gSwitchGameMode = gGameSettings.GameMode then
5507 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5508 [g_Game_ModeToText(gGameSettings.GameMode)]))
5509 else
5510 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5511 [g_Game_ModeToText(gGameSettings.GameMode),
5512 g_Game_ModeToText(gSwitchGameMode)]));
5513 end
5514 else if cmd = 'g_friendlyfire' then
5515 begin
5516 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5517 end
5518 else if cmd = 'g_friendly_absorb_damage' then
5519 begin
5520 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5521 end
5522 else if cmd = 'g_friendly_hit_trace' then
5523 begin
5524 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5525 end
5526 else if cmd = 'g_friendly_hit_projectile' then
5527 begin
5528 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5529 end
5530 else if cmd = 'g_weaponstay' then
5531 begin
5532 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5533 end
5534 else if cmd = 'g_allow_exit' then
5535 begin
5536 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5537 end
5538 else if cmd = 'g_allow_monsters' then
5539 begin
5540 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5541 end
5542 else if cmd = 'g_bot_vsplayers' then
5543 begin
5544 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5545 end
5546 else if cmd = 'g_bot_vsmonsters' then
5547 begin
5548 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5549 end
5550 else if cmd = 'g_dm_keys' then
5551 begin
5552 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5553 end
5554 else if cmd = 'g_gameflags' then
5555 begin
5556 if Length(P) > 1 then
5557 begin
5558 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5559 if g_Game_IsServer then
5560 begin
5561 gGameSettings.Options := gsGameFlags;
5562 if g_Game_IsNet then MH_SEND_GameSettings;
5563 end;
5564 end;
5566 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5567 end
5568 else if cmd = 'g_warmup_time' then
5569 begin
5570 if Length(P) > 1 then
5571 begin
5572 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5573 if g_Game_IsServer then
5574 begin
5575 gGameSettings.WarmupTime := gsWarmupTime;
5576 // extend warmup if it's already going
5577 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5578 begin
5579 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5580 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5581 end;
5582 if g_Game_IsNet then MH_SEND_GameSettings;
5583 end;
5584 end;
5586 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5587 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5588 end
5589 else if cmd = 'g_spawn_invul' then
5590 begin
5591 if Length(P) > 1 then
5592 begin
5593 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5594 if g_Game_IsServer then
5595 begin
5596 gGameSettings.SpawnInvul := gsSpawnInvul;
5597 if g_Game_IsNet then MH_SEND_GameSettings;
5598 end;
5599 end;
5601 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5602 end
5603 else if cmd = 'g_item_respawn_time' then
5604 begin
5605 if Length(P) > 1 then
5606 begin
5607 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5608 if g_Game_IsServer then
5609 begin
5610 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5611 if g_Game_IsNet then MH_SEND_GameSettings;
5612 end;
5613 end;
5615 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5616 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5617 end
5618 else if cmd = 'sv_intertime' then
5619 begin
5620 if (Length(P) > 1) then
5621 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5623 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5624 end
5625 else if cmd = 'g_max_particles' then
5626 begin
5627 if Length(p) = 2 then
5628 begin
5629 a := Max(0, StrToInt(p[1]));
5630 g_GFX_SetMax(a)
5631 end
5632 else if Length(p) = 1 then
5633 begin
5634 e_LogWritefln('%s', [g_GFX_GetMax()])
5635 end
5636 else
5637 begin
5638 e_LogWritefln('usage: %s <n>', [cmd])
5639 end
5640 end
5641 else if cmd = 'g_max_shells' then
5642 begin
5643 if Length(p) = 2 then
5644 begin
5645 a := Max(0, StrToInt(p[1]));
5646 g_Shells_SetMax(a)
5647 end
5648 else if Length(p) = 1 then
5649 begin
5650 e_LogWritefln('%s', [g_Shells_GetMax()])
5651 end
5652 else
5653 begin
5654 e_LogWritefln('usage: %s <n>', [cmd])
5655 end
5656 end
5657 else if cmd = 'g_max_gibs' then
5658 begin
5659 if Length(p) = 2 then
5660 begin
5661 a := Max(0, StrToInt(p[1]));
5662 g_Gibs_SetMax(a)
5663 end
5664 else if Length(p) = 1 then
5665 begin
5666 e_LogWritefln('%s', [g_Gibs_GetMax()])
5667 end
5668 else
5669 begin
5670 e_LogWritefln('usage: %s <n>', [cmd])
5671 end
5672 end
5673 else if cmd = 'g_max_corpses' then
5674 begin
5675 if Length(p) = 2 then
5676 begin
5677 a := Max(0, StrToInt(p[1]));
5678 g_Corpses_SetMax(a)
5679 end
5680 else if Length(p) = 1 then
5681 begin
5682 e_LogWritefln('%s', [g_Corpses_GetMax()])
5683 end
5684 else
5685 begin
5686 e_LogWritefln('usage: %s <n>', [cmd])
5687 end
5688 end
5689 else if cmd = 'g_scorelimit' then
5690 begin
5691 if Length(P) > 1 then
5692 begin
5693 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
5695 if g_Game_IsServer then
5696 begin
5697 b := 0;
5698 if gGameSettings.GameMode = GM_DM then
5699 begin // DM
5700 stat := g_Player_GetStats();
5701 if stat <> nil then
5702 for a := 0 to High(stat) do
5703 if stat[a].Frags > b then
5704 b := stat[a].Frags;
5705 end
5706 else // TDM/CTF
5707 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5709 // if someone has a higher score, set it to that instead
5710 gsGoalLimit := max(gsGoalLimit, b);
5711 gGameSettings.GoalLimit := gsGoalLimit;
5713 if g_Game_IsNet then MH_SEND_GameSettings;
5714 end;
5715 end;
5717 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
5718 end
5719 else if cmd = 'g_timelimit' then
5720 begin
5721 if Length(P) > 1 then
5722 begin
5723 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5724 if g_Game_IsServer then
5725 begin
5726 gGameSettings.TimeLimit := gsTimeLimit;
5727 if g_Game_IsNet then MH_SEND_GameSettings;
5728 end;
5729 end;
5730 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5731 [gsTimeLimit div 3600,
5732 (gsTimeLimit div 60) mod 60,
5733 gsTimeLimit mod 60]));
5734 end
5735 else if cmd = 'g_maxlives' then
5736 begin
5737 if Length(P) > 1 then
5738 begin
5739 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5740 if g_Game_IsServer then
5741 begin
5742 gGameSettings.MaxLives := gsMaxLives;
5743 if g_Game_IsNet then MH_SEND_GameSettings;
5744 end;
5745 end;
5747 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5748 end;
5749 end;
5751 procedure PlayerSettingsCVars(P: SSArray);
5752 var
5753 cmd: string;
5754 team: Byte;
5756 function ParseTeam(s: string): Byte;
5757 begin
5758 result := 0;
5759 case s of
5760 'red', '1': result := TEAM_RED;
5761 'blue', '2': result := TEAM_BLUE;
5762 else result := TEAM_NONE;
5763 end;
5764 end;
5765 begin
5766 cmd := LowerCase(P[0]);
5767 case cmd of
5768 'p1_name':
5769 begin
5770 if (Length(P) > 1) then
5771 begin
5772 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5773 if g_Game_IsClient then
5774 MC_SEND_PlayerSettings
5775 else if gGameOn and (gPlayer1 <> nil) then
5776 begin
5777 gPlayer1.Name := b_Text_Unformat(P[1]);
5778 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5779 end;
5780 end;
5781 end;
5782 'p2_name':
5783 begin
5784 if (Length(P) > 1) then
5785 begin
5786 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5787 if g_Game_IsClient then
5788 MC_SEND_PlayerSettings
5789 else if gGameOn and (gPlayer2 <> nil) then
5790 begin
5791 gPlayer2.Name := b_Text_Unformat(P[1]);
5792 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5793 end;
5794 end;
5795 end;
5796 'p1_color':
5797 begin
5798 if Length(P) > 3 then
5799 begin
5800 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5801 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5802 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5803 if g_Game_IsClient then
5804 MC_SEND_PlayerSettings
5805 else if gGameOn and (gPlayer1 <> nil) then
5806 begin
5807 gPlayer1.SetColor(gPlayer1Settings.Color);
5808 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5809 end;
5810 end;
5811 end;
5812 'p2_color':
5813 begin
5814 if Length(P) > 3 then
5815 begin
5816 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5817 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5818 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5819 if g_Game_IsClient then
5820 MC_SEND_PlayerSettings
5821 else if gGameOn and (gPlayer2 <> nil) then
5822 begin
5823 gPlayer2.SetColor(gPlayer2Settings.Color);
5824 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5825 end;
5826 end;
5827 end;
5828 'p1_model':
5829 begin
5830 if (Length(P) > 1) then
5831 begin
5832 gPlayer1Settings.Model := P[1];
5833 if g_Game_IsClient then
5834 MC_SEND_PlayerSettings
5835 else if gGameOn and (gPlayer1 <> nil) then
5836 begin
5837 gPlayer1.FActualModelName := gPlayer1Settings.Model;
5838 gPlayer1.SetModel(gPlayer1Settings.Model);
5839 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5840 end;
5841 end;
5842 end;
5843 'p2_model':
5844 begin
5845 if (Length(P) > 1) then
5846 begin
5847 gPlayer2Settings.Model := P[1];
5848 if g_Game_IsClient then
5849 MC_SEND_PlayerSettings
5850 else if gGameOn and (gPlayer2 <> nil) then
5851 begin
5852 gPlayer2.FActualModelName := gPlayer2Settings.Model;
5853 gPlayer2.SetModel(gPlayer2Settings.Model);
5854 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5855 end;
5856 end;
5857 end;
5858 'p1_team':
5859 begin
5860 // TODO: switch teams if in game or store this separately
5861 if (Length(P) > 1) then
5862 begin
5863 team := ParseTeam(P[1]);
5864 if team = TEAM_NONE then
5865 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5866 else if not gGameOn and not g_Game_IsNet then
5867 gPlayer1Settings.Team := team
5868 else
5869 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5870 end;
5871 end;
5872 'p2_team':
5873 begin
5874 // TODO: switch teams if in game or store this separately
5875 if (Length(P) > 1) then
5876 begin
5877 team := ParseTeam(P[1]);
5878 if team = TEAM_NONE then
5879 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5880 else if not gGameOn and not g_Game_IsNet then
5881 gPlayer2Settings.Team := team
5882 else
5883 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5884 end;
5885 end;
5886 end;
5887 end;
5889 procedure PrintHeapStats();
5890 var
5891 hs: TFPCHeapStatus;
5892 begin
5893 hs := GetFPCHeapStatus();
5894 e_LogWriteLn ('v===== heap status =====v');
5895 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5896 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5897 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5898 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5899 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5900 e_LogWriteLn ('^=======================^');
5901 end;
5903 procedure DebugCommands(P: SSArray);
5904 var
5905 a, b: Integer;
5906 cmd: string;
5907 //pt: TDFPoint;
5908 mon: TMonster;
5909 begin
5910 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5911 if {gDebugMode}conIsCheatsEnabled then
5912 begin
5913 cmd := LowerCase(P[0]);
5914 if cmd = 'd_window' then
5915 begin
5916 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5917 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5918 end
5919 else if cmd = 'd_sounds' then
5920 begin
5921 if (Length(P) > 1) and
5922 ((P[1] = '1') or (P[1] = '0')) then
5923 g_Debug_Sounds := (P[1][1] = '1');
5925 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5926 end
5927 else if cmd = 'd_frames' then
5928 begin
5929 if (Length(P) > 1) and
5930 ((P[1] = '1') or (P[1] = '0')) then
5931 g_Debug_Frames := (P[1][1] = '1');
5933 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5934 end
5935 else if cmd = 'd_winmsg' then
5936 begin
5937 if (Length(P) > 1) and
5938 ((P[1] = '1') or (P[1] = '0')) then
5939 g_Debug_WinMsgs := (P[1][1] = '1');
5941 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5942 end
5943 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5944 begin
5945 if (Length(P) > 1) and
5946 ((P[1] = '1') or (P[1] = '0')) then
5947 g_Debug_MonsterOff := (P[1][1] = '1');
5949 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5950 end
5951 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5952 begin
5953 if Length(P) > 1 then
5954 case P[1][1] of
5955 '0': g_debug_BotAIOff := 0;
5956 '1': g_debug_BotAIOff := 1;
5957 '2': g_debug_BotAIOff := 2;
5958 '3': g_debug_BotAIOff := 3;
5959 end;
5961 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5962 end
5963 else if cmd = 'd_monster' then
5964 begin
5965 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5966 if Length(P) < 2 then
5967 begin
5968 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5969 g_Console_Add('ID | Name');
5970 for b := MONSTER_DEMON to MONSTER_MAN do
5971 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5972 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5973 end else
5974 begin
5975 a := StrToIntDef(P[1], 0);
5976 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5977 a := g_Mons_TypeIdByName(P[1]);
5979 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5980 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5981 else
5982 begin
5983 with gPlayer1.Obj do
5984 begin
5985 mon := g_Monsters_Create(a,
5986 X + Rect.X + (Rect.Width div 2),
5987 Y + Rect.Y + Rect.Height,
5988 gPlayer1.Direction, True);
5989 end;
5990 if (Length(P) > 2) and (mon <> nil) then
5991 begin
5992 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5993 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5994 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5995 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5996 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5997 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5998 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5999 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6000 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6001 end;
6002 end;
6003 end;
6004 end
6005 else if (cmd = 'd_health') then
6006 begin
6007 if (Length(P) > 1) and
6008 ((P[1] = '1') or (P[1] = '0')) then
6009 g_debug_HealthBar := (P[1][1] = '1');
6011 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6012 end
6013 else if (cmd = 'd_player') then
6014 begin
6015 if (Length(P) > 1) and
6016 ((P[1] = '1') or (P[1] = '0')) then
6017 g_debug_Player := (P[1][1] = '1');
6019 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6020 end
6021 else if (cmd = 'd_mem') then
6022 begin
6023 PrintHeapStats();
6024 end;
6025 end
6026 else
6027 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6028 end;
6031 procedure GameCheats(P: SSArray);
6032 var
6033 cmd: string;
6034 f, a: Integer;
6035 plr: TPlayer;
6036 begin
6037 if (not gGameOn) or (not conIsCheatsEnabled) then
6038 begin
6039 g_Console_Add('not available');
6040 exit;
6041 end;
6042 plr := gPlayer1;
6043 if plr = nil then
6044 begin
6045 g_Console_Add('where is the player?!');
6046 exit;
6047 end;
6048 cmd := LowerCase(P[0]);
6049 // god
6050 if cmd = 'god' then
6051 begin
6052 plr.GodMode := not plr.GodMode;
6053 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6054 exit;
6055 end;
6056 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6057 if cmd = 'give' then
6058 begin
6059 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6060 for f := 1 to High(P) do
6061 begin
6062 cmd := LowerCase(P[f]);
6063 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6064 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6065 if cmd = 'exit' then
6066 begin
6067 if gTriggers <> nil then
6068 begin
6069 for a := 0 to High(gTriggers) do
6070 begin
6071 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6072 begin
6073 g_Console_Add('player left the map');
6074 gExitByTrigger := True;
6075 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6076 g_Game_ExitLevel(gTriggers[a].tgcMap);
6077 break;
6078 end;
6079 end;
6080 end;
6081 continue;
6082 end;
6084 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6085 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6086 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6087 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6088 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6090 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6091 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6093 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6094 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;
6096 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6097 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6099 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6100 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6102 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6103 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6105 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6106 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6107 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6109 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6110 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6111 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6112 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;
6113 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6114 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6116 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;
6117 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;
6118 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;
6119 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;
6120 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;
6121 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;
6123 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6124 if cmd = 'superchaingunzz' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a superchaingun'); continue; end;
6126 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;
6127 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;
6129 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6131 if cmd = 'ammo' then
6132 begin
6133 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6134 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6135 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6136 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6137 plr.GiveItem(ITEM_AMMO_FUELCAN);
6138 g_Console_Add('player got some ammo');
6139 continue;
6140 end;
6142 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6143 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6145 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6146 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6148 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6149 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6151 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6152 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6154 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6156 if cmd = 'weapons' then
6157 begin
6158 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6159 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6160 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6161 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6162 plr.GiveItem(ITEM_WEAPON_PLASMA);
6163 plr.GiveItem(ITEM_WEAPON_BFG);
6164 g_Console_Add('player got weapons');
6165 continue;
6166 end;
6168 if cmd = 'keys' then
6169 begin
6170 plr.GiveItem(ITEM_KEY_RED);
6171 plr.GiveItem(ITEM_KEY_GREEN);
6172 plr.GiveItem(ITEM_KEY_BLUE);
6173 g_Console_Add('player got all keys');
6174 continue;
6175 end;
6177 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6178 end;
6179 exit;
6180 end;
6181 // open
6182 if cmd = 'open' then
6183 begin
6184 g_Console_Add('player activated sesame');
6185 g_Triggers_OpenAll();
6186 exit;
6187 end;
6188 // fly
6189 if cmd = 'fly' then
6190 begin
6191 gFly := not gFly;
6192 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6193 exit;
6194 end;
6195 // noclip
6196 if cmd = 'noclip' then
6197 begin
6198 plr.SwitchNoClip;
6199 g_Console_Add('wall hardeness adjusted');
6200 exit;
6201 end;
6202 // notarget
6203 if cmd = 'notarget' then
6204 begin
6205 plr.NoTarget := not plr.NoTarget;
6206 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6207 exit;
6208 end;
6209 // noreload
6210 if cmd = 'noreload' then
6211 begin
6212 plr.NoReload := not plr.NoReload;
6213 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6214 exit;
6215 end;
6216 // speedy
6217 if cmd = 'speedy' then
6218 begin
6219 MAX_RUNVEL := 32-MAX_RUNVEL;
6220 g_Console_Add('speed adjusted');
6221 exit;
6222 end;
6223 // jumpy
6224 if cmd = 'jumpy' then
6225 begin
6226 VEL_JUMP := 30-VEL_JUMP;
6227 g_Console_Add('jump height adjusted');
6228 exit;
6229 end;
6230 // automap
6231 if cmd = 'automap' then
6232 begin
6233 gShowMap := not gShowMap;
6234 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6235 exit;
6236 end;
6237 // aimline
6238 if cmd = 'aimline' then
6239 begin
6240 gAimLine := not gAimLine;
6241 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6242 exit;
6243 end;
6244 end;
6246 procedure GameCommands(P: SSArray);
6247 var
6248 a, b: Integer;
6249 s, pw: String;
6250 chstr: string;
6251 cmd: string;
6252 pl: pTNetClient = nil;
6253 plr: TPlayer;
6254 prt: Word;
6255 nm: Boolean;
6256 listen: LongWord;
6257 found: Boolean;
6258 begin
6259 // Îáùèå êîìàíäû:
6260 cmd := LowerCase(P[0]);
6261 chstr := '';
6262 if cmd = 'pause' then
6263 begin
6264 if (g_ActiveWindow = nil) then
6265 g_Game_Pause(not gPauseMain);
6266 end
6267 else if cmd = 'endgame' then
6268 gExit := EXIT_SIMPLE
6269 else if cmd = 'restart' then
6270 begin
6271 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6272 begin
6273 if g_Game_IsClient then
6274 begin
6275 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6276 Exit;
6277 end;
6278 g_Game_Restart();
6279 end else
6280 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6281 end
6282 else if cmd = 'kick' then
6283 begin
6284 if g_Game_IsServer then
6285 begin
6286 if Length(P) < 2 then
6287 begin
6288 g_Console_Add('kick <name>');
6289 Exit;
6290 end;
6291 if P[1] = '' then
6292 begin
6293 g_Console_Add('kick <name>');
6294 Exit;
6295 end;
6297 if g_Game_IsNet then
6298 pl := g_Net_Client_ByName(P[1]);
6299 if (pl <> nil) then
6300 begin
6301 s := g_Net_ClientName_ByID(pl^.ID);
6302 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6303 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6304 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6305 g_Net_Slist_ServerPlayerLeaves();
6306 end else if gPlayers <> nil then
6307 for a := Low(gPlayers) to High(gPlayers) do
6308 if gPlayers[a] <> nil then
6309 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6310 begin
6311 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6312 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6313 continue;
6314 gPlayers[a].Lives := 0;
6315 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6316 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6317 g_Player_Remove(gPlayers[a].UID);
6318 g_Net_Slist_ServerPlayerLeaves();
6319 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6320 g_Bot_MixNames();
6321 end;
6322 end else
6323 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6324 end
6325 else if cmd = 'kick_id' then
6326 begin
6327 if g_Game_IsServer and g_Game_IsNet then
6328 begin
6329 if Length(P) < 2 then
6330 begin
6331 g_Console_Add('kick_id <client ID>');
6332 Exit;
6333 end;
6334 if P[1] = '' then
6335 begin
6336 g_Console_Add('kick_id <client ID>');
6337 Exit;
6338 end;
6340 a := StrToIntDef(P[1], 0);
6341 if (NetClients <> nil) and (a <= High(NetClients)) then
6342 begin
6343 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6344 begin
6345 s := g_Net_ClientName_ByID(NetClients[a].ID);
6346 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6347 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6348 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6349 g_Net_Slist_ServerPlayerLeaves();
6350 end;
6351 end;
6352 end else
6353 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6354 end
6355 else if cmd = 'kick_pid' then
6356 begin
6357 if g_Game_IsServer and g_Game_IsNet then
6358 begin
6359 if Length(P) < 2 then
6360 begin
6361 g_Console_Add('kick_pid <player ID>');
6362 Exit;
6363 end;
6364 if P[1] = '' then
6365 begin
6366 g_Console_Add('kick_pid <player ID>');
6367 Exit;
6368 end;
6370 a := StrToIntDef(P[1], 0);
6371 pl := g_Net_Client_ByPlayer(a);
6372 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6373 begin
6374 s := g_Net_ClientName_ByID(pl^.ID);
6375 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6376 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6377 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6378 g_Net_Slist_ServerPlayerLeaves();
6379 end;
6380 end else
6381 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6382 end
6383 else if cmd = 'ban' then
6384 begin
6385 if g_Game_IsServer and g_Game_IsNet then
6386 begin
6387 if Length(P) < 2 then
6388 begin
6389 g_Console_Add('ban <name>');
6390 Exit;
6391 end;
6392 if P[1] = '' then
6393 begin
6394 g_Console_Add('ban <name>');
6395 Exit;
6396 end;
6398 pl := g_Net_Client_ByName(P[1]);
6399 if (pl <> nil) then
6400 begin
6401 s := g_Net_ClientName_ByID(pl^.ID);
6402 g_Net_BanHost(pl^.Peer^.address.host, False);
6403 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6404 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6405 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6406 g_Net_Slist_ServerPlayerLeaves();
6407 end else
6408 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6409 end else
6410 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6411 end
6412 else if cmd = 'ban_id' then
6413 begin
6414 if g_Game_IsServer and g_Game_IsNet then
6415 begin
6416 if Length(P) < 2 then
6417 begin
6418 g_Console_Add('ban_id <client ID>');
6419 Exit;
6420 end;
6421 if P[1] = '' then
6422 begin
6423 g_Console_Add('ban_id <client ID>');
6424 Exit;
6425 end;
6427 a := StrToIntDef(P[1], 0);
6428 if (NetClients <> nil) and (a <= High(NetClients)) then
6429 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6430 begin
6431 s := g_Net_ClientName_ByID(NetClients[a].ID);
6432 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6433 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6434 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6435 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6436 g_Net_Slist_ServerPlayerLeaves();
6437 end;
6438 end else
6439 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6440 end
6441 else if cmd = 'ban_pid' then
6442 begin
6443 if g_Game_IsServer and g_Game_IsNet then
6444 begin
6445 if Length(P) < 2 then
6446 begin
6447 g_Console_Add('ban_pid <player ID>');
6448 Exit;
6449 end;
6450 if P[1] = '' then
6451 begin
6452 g_Console_Add('ban_pid <player ID>');
6453 Exit;
6454 end;
6456 a := StrToIntDef(P[1], 0);
6457 pl := g_Net_Client_ByPlayer(a);
6458 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6459 begin
6460 s := g_Net_ClientName_ByID(pl^.ID);
6461 g_Net_BanHost(pl^.Peer^.address.host, False);
6462 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6463 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6464 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6465 g_Net_Slist_ServerPlayerLeaves();
6466 end;
6467 end else
6468 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6469 end
6470 else if cmd = 'permban' then
6471 begin
6472 if g_Game_IsServer and g_Game_IsNet then
6473 begin
6474 if Length(P) < 2 then
6475 begin
6476 g_Console_Add('permban <name>');
6477 Exit;
6478 end;
6479 if P[1] = '' then
6480 begin
6481 g_Console_Add('permban <name>');
6482 Exit;
6483 end;
6485 pl := g_Net_Client_ByName(P[1]);
6486 if (pl <> nil) then
6487 begin
6488 s := g_Net_ClientName_ByID(pl^.ID);
6489 g_Net_BanHost(pl^.Peer^.address.host);
6490 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6491 g_Net_SaveBanList();
6492 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6493 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6494 g_Net_Slist_ServerPlayerLeaves();
6495 end else
6496 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6497 end else
6498 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6499 end
6500 else if cmd = 'permban_id' then
6501 begin
6502 if g_Game_IsServer and g_Game_IsNet then
6503 begin
6504 if Length(P) < 2 then
6505 begin
6506 g_Console_Add('permban_id <client ID>');
6507 Exit;
6508 end;
6509 if P[1] = '' then
6510 begin
6511 g_Console_Add('permban_id <client ID>');
6512 Exit;
6513 end;
6515 a := StrToIntDef(P[1], 0);
6516 if (NetClients <> nil) and (a <= High(NetClients)) then
6517 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6518 begin
6519 s := g_Net_ClientName_ByID(NetClients[a].ID);
6520 g_Net_BanHost(NetClients[a].Peer^.address.host);
6521 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6522 g_Net_SaveBanList();
6523 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6524 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6525 g_Net_Slist_ServerPlayerLeaves();
6526 end;
6527 end else
6528 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6529 end
6530 else if cmd = 'permban_pid' then
6531 begin
6532 if g_Game_IsServer and g_Game_IsNet then
6533 begin
6534 if Length(P) < 2 then
6535 begin
6536 g_Console_Add('permban_pid <player ID>');
6537 Exit;
6538 end;
6539 if P[1] = '' then
6540 begin
6541 g_Console_Add('permban_pid <player ID>');
6542 Exit;
6543 end;
6545 a := StrToIntDef(P[1], 0);
6546 pl := g_Net_Client_ByPlayer(a);
6547 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6548 begin
6549 s := g_Net_ClientName_ByID(pl^.ID);
6550 g_Net_BanHost(pl^.Peer^.address.host);
6551 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6552 g_Net_SaveBanList();
6553 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6554 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6555 g_Net_Slist_ServerPlayerLeaves();
6556 end;
6557 end else
6558 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6559 end
6560 else if cmd = 'permban_ip' then
6561 begin
6562 if g_Game_IsServer and g_Game_IsNet then
6563 begin
6564 if Length(P) < 2 then
6565 begin
6566 g_Console_Add('permban_ip <IP address>');
6567 Exit;
6568 end;
6569 if P[1] = '' then
6570 begin
6571 g_Console_Add('permban_ip <IP address>');
6572 Exit;
6573 end;
6575 g_Net_BanHost(P[1]);
6576 g_Net_SaveBanList();
6577 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6578 end else
6579 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6580 end
6581 else if cmd = 'unban' then
6582 begin
6583 if g_Game_IsServer and g_Game_IsNet then
6584 begin
6585 if Length(P) < 2 then
6586 begin
6587 g_Console_Add('unban <IP Address>');
6588 Exit;
6589 end;
6590 if P[1] = '' then
6591 begin
6592 g_Console_Add('unban <IP Address>');
6593 Exit;
6594 end;
6596 if g_Net_UnbanHost(P[1]) then
6597 begin
6598 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6599 g_Net_SaveBanList();
6600 end else
6601 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6602 end else
6603 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6604 end
6605 else if cmd = 'clientlist' then
6606 begin
6607 if g_Game_IsServer and g_Game_IsNet then
6608 begin
6609 b := 0;
6610 if NetClients <> nil then
6611 for a := Low(NetClients) to High(NetClients) do
6612 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6613 begin
6614 plr := g_Player_Get(NetClients[a].Player);
6615 if plr = nil then continue;
6616 Inc(b);
6617 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6618 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6619 end;
6620 if b = 0 then
6621 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6622 end else
6623 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6624 end
6625 else if cmd = 'connect' then
6626 begin
6627 if (NetMode = NET_NONE) then
6628 begin
6629 if Length(P) < 2 then
6630 begin
6631 g_Console_Add('connect <IP> [port] [password]');
6632 Exit;
6633 end;
6634 if P[1] = '' then
6635 begin
6636 g_Console_Add('connect <IP> [port] [password]');
6637 Exit;
6638 end;
6640 if Length(P) > 2 then
6641 prt := StrToIntDef(P[2], 25666)
6642 else
6643 prt := 25666;
6645 if Length(P) > 3 then
6646 pw := P[3]
6647 else
6648 pw := '';
6650 g_Game_StartClient(P[1], prt, pw);
6651 end;
6652 end
6653 else if cmd = 'disconnect' then
6654 begin
6655 if (NetMode = NET_CLIENT) then
6656 g_Net_Disconnect();
6657 end
6658 else if cmd = 'reconnect' then
6659 begin
6660 if (NetMode = NET_SERVER) then
6661 Exit;
6663 if (NetMode = NET_CLIENT) then
6664 begin
6665 g_Net_Disconnect();
6666 gExit := EXIT_SIMPLE;
6667 EndGame;
6668 end;
6670 //TODO: Use last successful password to reconnect, instead of ''
6671 g_Game_StartClient(NetClientIP, NetClientPort, '');
6672 end
6673 else if (cmd = 'addbot') or
6674 (cmd = 'bot_add') then
6675 begin
6676 if Length(P) > 2 then
6677 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6678 else if Length(P) > 1 then
6679 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6680 else
6681 g_Bot_Add(TEAM_NONE, 2);
6682 end
6683 else if cmd = 'bot_addlist' then
6684 begin
6685 if Length(P) > 1 then
6686 begin
6687 if Length(P) = 2 then
6688 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6689 else if Length(P) = 3 then
6690 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6691 else
6692 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6693 end;
6694 end
6695 else if cmd = 'bot_removeall' then
6696 g_Bot_RemoveAll()
6697 else if cmd = 'chat' then
6698 begin
6699 if g_Game_IsNet then
6700 begin
6701 if Length(P) > 1 then
6702 begin
6703 for a := 1 to High(P) do
6704 chstr := chstr + P[a] + ' ';
6706 if Length(chstr) > 200 then SetLength(chstr, 200);
6708 if Length(chstr) < 1 then
6709 begin
6710 g_Console_Add('chat <text>');
6711 Exit;
6712 end;
6714 chstr := b_Text_Format(chstr);
6715 if g_Game_IsClient then
6716 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6717 else
6718 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6719 end
6720 else
6721 g_Console_Add('chat <text>');
6722 end else
6723 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6724 end
6725 else if cmd = 'teamchat' then
6726 begin
6727 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6728 begin
6729 if Length(P) > 1 then
6730 begin
6731 for a := 1 to High(P) do
6732 chstr := chstr + P[a] + ' ';
6734 if Length(chstr) > 200 then SetLength(chstr, 200);
6736 if Length(chstr) < 1 then
6737 begin
6738 g_Console_Add('teamchat <text>');
6739 Exit;
6740 end;
6742 chstr := b_Text_Format(chstr);
6743 if g_Game_IsClient then
6744 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6745 else
6746 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6747 gPlayer1Settings.Team);
6748 end
6749 else
6750 g_Console_Add('teamchat <text>');
6751 end else
6752 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6753 end
6754 else if cmd = 'game' then
6755 begin
6756 if gGameSettings.GameType <> GT_NONE then
6757 begin
6758 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6759 Exit;
6760 end;
6761 if Length(P) = 1 then
6762 begin
6763 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6764 Exit;
6765 end;
6766 // game not started yet, load fist map from some wad
6767 found := false;
6768 s := addWadExtension(P[1]);
6769 found := e_FindResource(AllMapDirs, s);
6770 P[1] := s;
6771 if found then
6772 begin
6773 P[1] := ExpandFileName(P[1]);
6774 // if map not choosed then set first map
6775 if Length(P) < 3 then
6776 begin
6777 SetLength(P, 3);
6778 P[2] := g_Game_GetFirstMap(P[1]);
6779 end;
6781 s := P[1] + ':\' + UpperCase(P[2]);
6783 if g_Map_Exist(s) then
6784 begin
6785 // start game
6786 g_Game_Free();
6787 with gGameSettings do
6788 begin
6789 Options := gsGameFlags;
6790 GameMode := g_Game_TextToMode(gsGameMode);
6791 if gSwitchGameMode <> GM_NONE then
6792 GameMode := gSwitchGameMode;
6793 if GameMode = GM_NONE then GameMode := GM_DM;
6794 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6795 b := 1;
6796 if Length(P) >= 4 then
6797 b := StrToIntDef(P[3], 1);
6798 g_Game_StartCustom(s, GameMode, TimeLimit,
6799 GoalLimit, MaxLives, Options, b);
6800 end;
6801 end
6802 else
6803 if P[2] = '' then
6804 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6805 else
6806 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6807 end else
6808 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6809 end
6810 else if cmd = 'host' then
6811 begin
6812 if gGameSettings.GameType <> GT_NONE then
6813 begin
6814 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6815 Exit;
6816 end;
6817 if Length(P) < 4 then
6818 begin
6819 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6820 Exit;
6821 end;
6822 if not StrToIp(P[1], listen) then
6823 Exit;
6824 prt := StrToIntDef(P[2], 25666);
6826 s := addWadExtension(P[3]);
6827 found := e_FindResource(AllMapDirs, s);
6828 P[3] := s;
6829 if found then
6830 begin
6831 // get first map in wad, if not specified
6832 if Length(P) < 5 then
6833 begin
6834 SetLength(P, 5);
6835 P[4] := g_Game_GetFirstMap(P[1]);
6836 end;
6837 s := P[3] + ':\' + UpperCase(P[4]);
6838 if g_Map_Exist(s) then
6839 begin
6840 // start game
6841 g_Game_Free();
6842 with gGameSettings do
6843 begin
6844 Options := gsGameFlags;
6845 GameMode := g_Game_TextToMode(gsGameMode);
6846 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
6847 if GameMode = GM_NONE then GameMode := GM_DM;
6848 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6849 b := 0;
6850 if Length(P) >= 6 then
6851 b := StrToIntDef(P[5], 0);
6852 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
6853 end
6854 end
6855 else
6856 begin
6857 if P[4] = '' then
6858 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6859 else
6860 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
6861 end
6862 end
6863 else
6864 begin
6865 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
6866 end
6867 end
6868 else if cmd = 'map' then
6869 begin
6870 if Length(P) = 1 then
6871 begin
6872 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6873 begin
6874 g_Console_Add(cmd + ' <MAP>');
6875 g_Console_Add(cmd + ' <WAD> [MAP]')
6876 end
6877 else
6878 begin
6879 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6880 end
6881 end
6882 else
6883 begin
6884 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6885 begin
6886 if Length(P) < 3 then
6887 begin
6888 // first param is map or wad
6889 s := UpperCase(P[1]);
6890 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6891 begin
6892 gExitByTrigger := False;
6893 if gGameOn then
6894 begin
6895 // already in game, finish current map
6896 gNextMap := s;
6897 gExit := EXIT_ENDLEVELCUSTOM;
6898 end
6899 else
6900 begin
6901 // intermission, so change map immediately
6902 g_Game_ChangeMap(s)
6903 end
6904 end
6905 else
6906 begin
6907 s := P[1];
6908 found := e_FindResource(AllMapDirs, s);
6909 P[1] := s;
6910 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6911 if found then
6912 begin
6913 // no such map, found wad
6914 pw := P[1];
6915 SetLength(P, 3);
6916 P[1] := ExpandFileName(pw);
6917 P[2] := g_Game_GetFirstMap(P[1]);
6918 s := P[1] + ':\' + P[2];
6919 if g_Map_Exist(s) then
6920 begin
6921 gExitByTrigger := False;
6922 if gGameOn then
6923 begin
6924 // already in game, finish current map
6925 gNextMap := s;
6926 gExit := EXIT_ENDLEVELCUSTOM
6927 end
6928 else
6929 begin
6930 // intermission, so change map immediately
6931 g_Game_ChangeMap(s)
6932 end
6933 end
6934 else
6935 begin
6936 if P[2] = '' then
6937 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6938 else
6939 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6940 end
6941 end
6942 else
6943 begin
6944 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6945 end
6946 end;
6947 end
6948 else
6949 begin
6950 s := addWadExtension(P[1]);
6951 found := e_FindResource(AllMapDirs, s);
6952 P[1] := s;
6953 if found then
6954 begin
6955 P[2] := UpperCase(P[2]);
6956 s := P[1] + ':\' + P[2];
6957 if g_Map_Exist(s) then
6958 begin
6959 gExitByTrigger := False;
6960 if gGameOn then
6961 begin
6962 gNextMap := s;
6963 gExit := EXIT_ENDLEVELCUSTOM
6964 end
6965 else
6966 begin
6967 g_Game_ChangeMap(s)
6968 end
6969 end
6970 else
6971 begin
6972 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6973 end
6974 end
6975 else
6976 begin
6977 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6978 end
6979 end
6980 end
6981 else
6982 begin
6983 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6984 end
6985 end
6986 end
6987 else if cmd = 'nextmap' then
6988 begin
6989 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6990 begin
6991 g_Console_Add(_lc[I_MSG_NOT_GAME])
6992 end
6993 else
6994 begin
6995 nm := True;
6996 if Length(P) = 1 then
6997 begin
6998 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6999 begin
7000 g_Console_Add(cmd + ' <MAP>');
7001 g_Console_Add(cmd + ' <WAD> [MAP]');
7002 end
7003 else
7004 begin
7005 nm := False;
7006 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7007 end;
7008 end
7009 else
7010 begin
7011 nm := False;
7012 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7013 begin
7014 if Length(P) < 3 then
7015 begin
7016 // first param is map or wad
7017 s := UpperCase(P[1]);
7018 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7019 begin
7020 // map founded
7021 gExitByTrigger := False;
7022 gNextMap := s;
7023 nm := True;
7024 end
7025 else
7026 begin
7027 // no such map, found wad
7028 pw := addWadExtension(P[1]);
7029 found := e_FindResource(MapDirs, pw);
7030 if not found then
7031 found := e_FindResource(WadDirs, pw);
7032 P[1] := pw;
7033 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7034 if found then
7035 begin
7036 // map not specified, select first map
7037 SetLength(P, 3);
7038 P[2] := g_Game_GetFirstMap(P[1]);
7039 s := P[1] + ':\' + P[2];
7040 if g_Map_Exist(s) then
7041 begin
7042 gExitByTrigger := False;
7043 gNextMap := s;
7044 nm := True
7045 end
7046 else
7047 begin
7048 if P[2] = '' then
7049 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7050 else
7051 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7052 end
7053 end
7054 else
7055 begin
7056 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7057 end
7058 end
7059 end
7060 else
7061 begin
7062 // specified two params wad + map
7063 pw := addWadExtension(P[1]);
7064 found := e_FindResource(MapDirs, pw);
7065 if not found then
7066 found := e_FindResource(MapDirs, pw);
7067 P[1] := pw;
7068 if found then
7069 begin
7070 P[2] := UpperCase(P[2]);
7071 s := P[1] + ':\' + P[2];
7072 if g_Map_Exist(s) then
7073 begin
7074 gExitByTrigger := False;
7075 gNextMap := s;
7076 nm := True
7077 end
7078 else
7079 begin
7080 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7081 end
7082 end
7083 else
7084 begin
7085 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7086 end
7087 end
7088 end
7089 else
7090 begin
7091 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7092 end
7093 end;
7094 if nm then
7095 begin
7096 if gNextMap = '' then
7097 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7098 else
7099 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7100 end
7101 end
7102 end
7103 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7104 begin
7105 if not gGameOn then
7106 begin
7107 g_Console_Add(_lc[I_MSG_NOT_GAME])
7108 end
7109 else
7110 begin
7111 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7112 begin
7113 gExitByTrigger := False;
7114 // next map not specified, try to find trigger EXIT
7115 if (gNextMap = '') and (gTriggers <> nil) then
7116 begin
7117 for a := 0 to High(gTriggers) do
7118 begin
7119 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7120 begin
7121 gExitByTrigger := True;
7122 //gNextMap := gTriggers[a].Data.MapName;
7123 gNextMap := gTriggers[a].tgcMap;
7124 Break
7125 end
7126 end
7127 end;
7128 if gNextMap = '' then
7129 gNextMap := g_Game_GetNextMap();
7130 if not isWadPath(gNextMap) then
7131 s := gGameSettings.WAD + ':\' + gNextMap
7132 else
7133 s := gNextMap;
7134 if g_Map_Exist(s) then
7135 gExit := EXIT_ENDLEVELCUSTOM
7136 else
7137 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7138 end
7139 else
7140 begin
7141 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7142 end
7143 end
7144 end
7145 else if (cmd = 'event') then
7146 begin
7147 if (Length(P) <= 1) then
7148 begin
7149 for a := 0 to High(gEvents) do
7150 if gEvents[a].Command = '' then
7151 g_Console_Add(gEvents[a].Name + ' <none>')
7152 else
7153 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7154 Exit;
7155 end;
7156 if (Length(P) = 2) then
7157 begin
7158 for a := 0 to High(gEvents) do
7159 if gEvents[a].Name = P[1] then
7160 if gEvents[a].Command = '' then
7161 g_Console_Add(gEvents[a].Name + ' <none>')
7162 else
7163 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7164 Exit;
7165 end;
7166 for a := 0 to High(gEvents) do
7167 if gEvents[a].Name = P[1] then
7168 begin
7169 gEvents[a].Command := '';
7170 for b := 2 to High(P) do
7171 if Pos(' ', P[b]) = 0 then
7172 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7173 else
7174 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7175 gEvents[a].Command := Trim(gEvents[a].Command);
7176 Exit;
7177 end;
7178 end
7179 else if cmd = 'suicide' then
7180 begin
7181 if gGameOn then
7182 begin
7183 if g_Game_IsClient then
7184 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7185 else
7186 begin
7187 if gPlayer1 <> nil then
7188 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7189 if gPlayer2 <> nil then
7190 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7191 end;
7192 end;
7193 end
7194 else if cmd = 'screenshot' then
7195 begin
7196 g_TakeScreenShot()
7197 end
7198 else if cmd = 'weapon' then
7199 begin
7200 if Length(p) = 2 then
7201 begin
7202 a := WP_FIRST + StrToInt(p[1]) - 1;
7203 if (a >= WP_FIRST) and (a <= WP_LAST) then
7204 gSelectWeapon[0, a] := True
7205 end
7206 end
7207 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7208 begin
7209 if Length(p) = 2 then
7210 begin
7211 a := WP_FIRST + StrToInt(p[1]) - 1;
7212 b := ord(cmd[2]) - ord('1');
7213 if (a >= WP_FIRST) and (a <= WP_LAST) then
7214 gSelectWeapon[b, a] := True
7215 end
7216 end
7217 // Êîìàíäû Ñâîåé èãðû:
7218 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7219 begin
7220 if cmd = 'bot_addred' then
7221 begin
7222 if Length(P) > 1 then
7223 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7224 else
7225 g_Bot_Add(TEAM_RED, 2);
7226 end
7227 else if cmd = 'bot_addblue' then
7228 begin
7229 if Length(P) > 1 then
7230 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7231 else
7232 g_Bot_Add(TEAM_BLUE, 2);
7233 end
7234 else if cmd = 'spectate' then
7235 begin
7236 if not gGameOn then
7237 Exit;
7238 g_Game_Spectate();
7239 end
7240 else if cmd = 'say' then
7241 begin
7242 if g_Game_IsServer and g_Game_IsNet then
7243 begin
7244 if Length(P) > 1 then
7245 begin
7246 chstr := '';
7247 for a := 1 to High(P) do
7248 chstr := chstr + P[a] + ' ';
7250 if Length(chstr) > 200 then SetLength(chstr, 200);
7252 if Length(chstr) < 1 then
7253 begin
7254 g_Console_Add('say <text>');
7255 Exit;
7256 end;
7258 chstr := b_Text_Format(chstr);
7259 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7260 end
7261 else g_Console_Add('say <text>');
7262 end else
7263 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7264 end
7265 else if cmd = 'tell' then
7266 begin
7267 if g_Game_IsServer and g_Game_IsNet then
7268 begin
7269 if (Length(P) > 2) and (P[1] <> '') then
7270 begin
7271 chstr := '';
7272 for a := 2 to High(P) do
7273 chstr := chstr + P[a] + ' ';
7275 if Length(chstr) > 200 then SetLength(chstr, 200);
7277 if Length(chstr) < 1 then
7278 begin
7279 g_Console_Add('tell <playername> <text>');
7280 Exit;
7281 end;
7283 pl := g_Net_Client_ByName(P[1]);
7284 if pl <> nil then
7285 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7286 else
7287 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7288 end
7289 else g_Console_Add('tell <playername> <text>');
7290 end else
7291 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7292 end
7293 else if cmd = 'centerprint' then
7294 begin
7295 if (Length(P) > 2) and (P[1] <> '') then
7296 begin
7297 chstr := '';
7298 for a := 2 to High(P) do
7299 chstr := chstr + P[a] + ' ';
7301 if Length(chstr) > 200 then SetLength(chstr, 200);
7303 if Length(chstr) < 1 then
7304 begin
7305 g_Console_Add('centerprint <timeout> <text>');
7306 Exit;
7307 end;
7309 a := StrToIntDef(P[1], 100);
7310 chstr := b_Text_Format(chstr);
7311 g_Game_Message(chstr, a);
7312 if g_Game_IsNet and g_Game_IsServer then
7313 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7314 end
7315 else g_Console_Add('centerprint <timeout> <text>');
7316 end
7317 else if (cmd = 'overtime') and not g_Game_IsClient then
7318 begin
7319 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7320 Exit;
7321 // Äîïîëíèòåëüíîå âðåìÿ:
7322 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7324 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7325 [gGameSettings.TimeLimit div 3600,
7326 (gGameSettings.TimeLimit div 60) mod 60,
7327 gGameSettings.TimeLimit mod 60]));
7328 if g_Game_IsNet then MH_SEND_GameSettings;
7329 end
7330 else if (cmd = 'rcon_password') and g_Game_IsClient then
7331 begin
7332 if (Length(P) <= 1) then
7333 g_Console_Add('rcon_password <password>')
7334 else
7335 MC_SEND_RCONPassword(P[1]);
7336 end
7337 else if cmd = 'rcon' then
7338 begin
7339 if g_Game_IsClient then
7340 begin
7341 if Length(P) > 1 then
7342 begin
7343 chstr := '';
7344 for a := 1 to High(P) do
7345 chstr := chstr + P[a] + ' ';
7347 if Length(chstr) > 200 then SetLength(chstr, 200);
7349 if Length(chstr) < 1 then
7350 begin
7351 g_Console_Add('rcon <command>');
7352 Exit;
7353 end;
7355 MC_SEND_RCONCommand(chstr);
7356 end
7357 else g_Console_Add('rcon <command>');
7358 end;
7359 end
7360 else if cmd = 'ready' then
7361 begin
7362 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7363 gLMSRespawnTime := gTime + 100;
7364 end
7365 else if (cmd = 'callvote') and g_Game_IsNet then
7366 begin
7367 if Length(P) > 1 then
7368 begin
7369 chstr := '';
7370 for a := 1 to High(P) do begin
7371 if a > 1 then chstr := chstr + ' ';
7372 chstr := chstr + P[a];
7373 end;
7375 if Length(chstr) > 200 then SetLength(chstr, 200);
7377 if Length(chstr) < 1 then
7378 begin
7379 g_Console_Add('callvote <command>');
7380 Exit;
7381 end;
7383 if g_Game_IsClient then
7384 MC_SEND_Vote(True, chstr)
7385 else
7386 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7387 g_Console_Process('vote', True);
7388 end
7389 else
7390 g_Console_Add('callvote <command>');
7391 end
7392 else if (cmd = 'vote') and g_Game_IsNet then
7393 begin
7394 if g_Game_IsClient then
7395 MC_SEND_Vote(False)
7396 else if gVoteInProgress then
7397 begin
7398 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7399 a := Floor((NetClientCount+1)/2.0) + 1
7400 else
7401 a := Floor(NetClientCount/2.0) + 1;
7402 if gVoted then
7403 begin
7404 Dec(gVoteCount);
7405 gVoted := False;
7406 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7407 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7408 end
7409 else
7410 begin
7411 Inc(gVoteCount);
7412 gVoted := True;
7413 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7414 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7415 g_Game_CheckVote;
7416 end;
7417 end;
7418 end
7419 end;
7420 end;
7422 procedure SystemCommands(P: SSArray);
7423 var
7424 cmd: string;
7425 begin
7426 cmd := LowerCase(P[0]);
7427 case cmd of
7428 'exit', 'quit':
7429 begin
7430 g_Game_Free();
7431 g_Game_Quit();
7432 end;
7433 'r_reset':
7434 begin
7435 gRC_Width := Max(1, gRC_Width);
7436 gRC_Height := Max(1, gRC_Height);
7437 gBPP := Max(1, gBPP);
7438 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7439 e_LogWriteln('resolution changed')
7440 else
7441 e_LogWriteln('resolution not changed');
7442 sys_EnableVSync(gVSync);
7443 end;
7444 'r_maxfps':
7445 begin
7446 if Length(p) = 2 then
7447 begin
7448 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7449 if gMaxFPS > 0 then
7450 gFrameTime := 1000 div gMaxFPS
7451 else
7452 gFrameTime := 0;
7453 end;
7454 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7455 end;
7456 'g_language':
7457 begin
7458 if Length(p) = 2 then
7459 begin
7460 gAskLanguage := true;
7461 gLanguage := LANGUAGE_ENGLISH;
7462 case LowerCase(p[1]) of
7463 'english':
7464 begin
7465 gAskLanguage := false;
7466 gLanguage := LANGUAGE_ENGLISH;
7467 end;
7468 'russian':
7469 begin
7470 gAskLanguage := false;
7471 gLanguage := LANGUAGE_RUSSIAN;
7472 end;
7473 'ask':
7474 begin
7475 gAskLanguage := true;
7476 gLanguage := LANGUAGE_ENGLISH;
7477 end;
7478 end;
7479 g_Language_Set(gLanguage);
7480 end
7481 else
7482 begin
7483 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7484 end
7485 end;
7486 end;
7487 end;
7489 procedure g_TakeScreenShot(Filename: string = '');
7490 var s: TStream; t: TDateTime; dir, date, name: String;
7491 begin
7492 if e_NoGraphics then Exit;
7493 try
7494 dir := e_GetWriteableDir(ScreenshotDirs);
7496 if Filename = '' then
7497 begin
7498 t := Now;
7499 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7500 Filename := 'screenshot-' + date;
7501 end;
7503 name := e_CatPath(dir, Filename + '.png');
7504 s := createDiskFile(name);
7505 try
7506 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
7507 s.Free;
7508 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7509 except
7510 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7511 s.Free;
7512 DeleteFile(name)
7513 end
7514 except
7515 g_Console_Add('oh shit, i can''t create screenshot!')
7516 end
7517 end;
7519 procedure g_Game_InGameMenu(Show: Boolean);
7520 begin
7521 if (g_ActiveWindow = nil) and Show then
7522 begin
7523 if gGameSettings.GameType = GT_SINGLE then
7524 g_GUI_ShowWindow('GameSingleMenu')
7525 else
7526 begin
7527 if g_Game_IsClient then
7528 g_GUI_ShowWindow('GameClientMenu')
7529 else
7530 if g_Game_IsNet then
7531 g_GUI_ShowWindow('GameServerMenu')
7532 else
7533 g_GUI_ShowWindow('GameCustomMenu');
7534 end;
7535 g_Sound_PlayEx('MENU_OPEN');
7537 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7538 if (not g_Game_IsNet) then
7539 g_Game_Pause(True);
7540 end
7541 else
7542 if (g_ActiveWindow <> nil) and (not Show) then
7543 begin
7544 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7545 if (not g_Game_IsNet) then
7546 g_Game_Pause(False);
7547 end;
7548 end;
7550 procedure g_Game_Pause (Enable: Boolean);
7551 var
7552 oldPause: Boolean;
7553 begin
7554 if not gGameOn then exit;
7556 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7558 oldPause := gPause;
7559 gPauseMain := Enable;
7561 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7562 end;
7564 procedure g_Game_HolmesPause (Enable: Boolean);
7565 var
7566 oldPause: Boolean;
7567 begin
7568 if not gGameOn then exit;
7569 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7571 oldPause := gPause;
7572 gPauseHolmes := Enable;
7574 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7575 end;
7577 procedure g_Game_PauseAllSounds(Enable: Boolean);
7578 var
7579 i: Integer;
7580 begin
7581 // Òðèããåðû:
7582 if gTriggers <> nil then
7583 for i := 0 to High(gTriggers) do
7584 with gTriggers[i] do
7585 if (TriggerType = TRIGGER_SOUND) and
7586 (Sound <> nil) and
7587 Sound.IsPlaying() then
7588 begin
7589 Sound.Pause(Enable);
7590 end;
7592 // Çâóêè èãðîêîâ:
7593 if gPlayers <> nil then
7594 for i := 0 to High(gPlayers) do
7595 if gPlayers[i] <> nil then
7596 gPlayers[i].PauseSounds(Enable);
7598 // Ìóçûêà:
7599 if gMusic <> nil then
7600 gMusic.Pause(Enable);
7601 end;
7603 procedure g_Game_StopAllSounds(all: Boolean);
7604 var
7605 i: Integer;
7606 begin
7607 if gTriggers <> nil then
7608 for i := 0 to High(gTriggers) do
7609 with gTriggers[i] do
7610 if (TriggerType = TRIGGER_SOUND) and
7611 (Sound <> nil) then
7612 Sound.Stop();
7614 if gMusic <> nil then
7615 gMusic.Stop();
7617 if all then
7618 e_StopChannels();
7619 end;
7621 procedure g_Game_UpdateTriggerSounds;
7622 var i: Integer;
7623 begin
7624 if gTriggers <> nil then
7625 for i := 0 to High(gTriggers) do
7626 with gTriggers[i] do
7627 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7628 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7629 end;
7631 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7632 begin
7633 Result := False;
7634 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7635 begin
7636 Result := True;
7637 Exit;
7638 end;
7639 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7640 begin
7641 Result := True;
7642 Exit;
7643 end;
7644 if gSpectMode <> SPECT_PLAYERS then
7645 Exit;
7646 if gSpectPID1 = UID then
7647 begin
7648 Result := True;
7649 Exit;
7650 end;
7651 if gSpectViewTwo and (gSpectPID2 = UID) then
7652 begin
7653 Result := True;
7654 Exit;
7655 end;
7656 end;
7658 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7659 var
7660 Pl: TPlayer;
7661 begin
7662 Result := False;
7663 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7664 begin
7665 Result := True;
7666 Exit;
7667 end;
7668 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7669 begin
7670 Result := True;
7671 Exit;
7672 end;
7673 if gSpectMode <> SPECT_PLAYERS then
7674 Exit;
7675 Pl := g_Player_Get(gSpectPID1);
7676 if (Pl <> nil) and (Pl.Team = Team) then
7677 begin
7678 Result := True;
7679 Exit;
7680 end;
7681 if gSpectViewTwo then
7682 begin
7683 Pl := g_Player_Get(gSpectPID2);
7684 if (Pl <> nil) and (Pl.Team = Team) then
7685 begin
7686 Result := True;
7687 Exit;
7688 end;
7689 end;
7690 end;
7692 procedure g_Game_Message(Msg: string; Time: Word);
7693 begin
7694 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7695 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7696 MessageTime := Time;
7697 end;
7699 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7700 const
7701 punct: Array[0..13] of String =
7702 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7703 var
7704 i, j: Integer;
7705 ok: Boolean;
7706 fpText: String;
7708 function IsPunctuation(S: String): Boolean;
7709 var
7710 i: Integer;
7711 begin
7712 Result := False;
7713 if Length(S) <> 1 then
7714 Exit;
7715 for i := Low(punct) to High(punct) do
7716 if S = punct[i] then
7717 begin
7718 Result := True;
7719 break;
7720 end;
7721 end;
7722 function FilterPunctuation(S: String): String;
7723 var
7724 i: Integer;
7725 begin
7726 for i := Low(punct) to High(punct) do
7727 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7728 Result := S;
7729 end;
7730 begin
7731 ok := False;
7733 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7734 begin
7735 // remove player name
7736 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7737 // for FullWord check
7738 Text := toLowerCase1251(' ' + Text + ' ');
7739 fpText := FilterPunctuation(Text);
7741 for i := 0 to Length(gChatSounds) - 1 do
7742 begin
7743 ok := True;
7744 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7745 begin
7746 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7747 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7748 else
7749 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7750 if not ok then
7751 break;
7752 end;
7753 if ok then
7754 begin
7755 gChatSounds[i].Sound.Play();
7756 break;
7757 end;
7758 end;
7759 end;
7760 if not ok then
7761 g_Sound_PlayEx('SOUND_GAME_RADIO');
7762 end;
7764 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7765 var
7766 a: Integer;
7767 begin
7768 case gAnnouncer of
7769 ANNOUNCE_NONE:
7770 Exit;
7771 ANNOUNCE_ME,
7772 ANNOUNCE_MEPLUS:
7773 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7774 Exit;
7775 end;
7776 for a := 0 to 3 do
7777 if goodsnd[a].IsPlaying() then
7778 Exit;
7780 goodsnd[Random(4)].Play();
7781 end;
7783 procedure g_Game_Announce_KillCombo(Param: Integer);
7784 var
7785 UID: Word;
7786 c, n: Byte;
7787 Pl: TPlayer;
7788 Name: String;
7789 begin
7790 UID := Param and $FFFF;
7791 c := Param shr 16;
7792 if c < 2 then
7793 Exit;
7795 Pl := g_Player_Get(UID);
7796 if Pl = nil then
7797 Name := '?'
7798 else
7799 Name := Pl.Name;
7801 case c of
7802 2: begin
7803 n := 0;
7804 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7805 end;
7806 3: begin
7807 n := 1;
7808 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7809 end;
7810 4: begin
7811 n := 2;
7812 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7813 end;
7814 else begin
7815 n := 3;
7816 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7817 end;
7818 end;
7820 case gAnnouncer of
7821 ANNOUNCE_NONE:
7822 Exit;
7823 ANNOUNCE_ME:
7824 if not g_Game_IsWatchedPlayer(UID) then
7825 Exit;
7826 ANNOUNCE_MEPLUS:
7827 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7828 Exit;
7829 end;
7831 if killsnd[n].IsPlaying() then
7832 killsnd[n].Stop();
7833 killsnd[n].Play();
7834 end;
7836 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7837 var
7838 a: Integer;
7839 begin
7840 case gAnnouncer of
7841 ANNOUNCE_NONE:
7842 Exit;
7843 ANNOUNCE_ME:
7844 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7845 Exit;
7846 end;
7847 for a := 0 to 2 do
7848 if hahasnd[a].IsPlaying() then
7849 Exit;
7851 hahasnd[Random(3)].Play();
7852 end;
7854 procedure g_Game_StartVote(Command, Initiator: string);
7855 var
7856 Need: Integer;
7857 begin
7858 if not gVotesEnabled then Exit;
7859 if gGameSettings.GameType <> GT_SERVER then Exit;
7860 if gVoteInProgress or gVotePassed then
7861 begin
7862 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7863 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7864 Exit;
7865 end;
7866 gVoteInProgress := True;
7867 gVotePassed := False;
7868 gVoteTimer := gTime + gVoteTimeout * 1000;
7869 gVoteCount := 0;
7870 gVoted := False;
7871 gVoteCommand := Command;
7873 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7874 Need := Floor((NetClientCount+1)/2.0)+1
7875 else
7876 Need := Floor(NetClientCount/2.0)+1;
7877 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7878 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7879 end;
7881 procedure g_Game_CheckVote;
7882 var
7883 I, Need: Integer;
7884 begin
7885 if gGameSettings.GameType <> GT_SERVER then Exit;
7886 if not gVoteInProgress then Exit;
7888 if (gTime >= gVoteTimer) then
7889 begin
7890 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7891 Need := Floor((NetClientCount+1)/2.0) + 1
7892 else
7893 Need := Floor(NetClientCount/2.0) + 1;
7894 if gVoteCount >= Need then
7895 begin
7896 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7897 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7898 gVotePassed := True;
7899 gVoteCmdTimer := gTime + 5000;
7900 end
7901 else
7902 begin
7903 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7904 MH_SEND_VoteEvent(NET_VE_FAILED);
7905 end;
7906 if NetClients <> nil then
7907 for I := Low(NetClients) to High(NetClients) do
7908 if NetClients[i].Used then
7909 NetClients[i].Voted := False;
7910 gVoteInProgress := False;
7911 gVoted := False;
7912 gVoteCount := 0;
7913 end
7914 else
7915 begin
7916 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7917 Need := Floor((NetClientCount+1)/2.0) + 1
7918 else
7919 Need := Floor(NetClientCount/2.0) + 1;
7920 if gVoteCount >= Need then
7921 begin
7922 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7923 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7924 gVoteInProgress := False;
7925 gVotePassed := True;
7926 gVoteCmdTimer := gTime + 5000;
7927 gVoted := False;
7928 gVoteCount := 0;
7929 if NetClients <> nil then
7930 for I := Low(NetClients) to High(NetClients) do
7931 if NetClients[i].Used then
7932 NetClients[i].Voted := False;
7933 end;
7934 end;
7935 end;
7937 procedure g_Game_LoadMapList(FileName: string);
7938 var
7939 ListFile: TextFile;
7940 s: string;
7941 begin
7942 MapList := nil;
7943 MapIndex := -1;
7945 if not FileExists(FileName) then Exit;
7947 AssignFile(ListFile, FileName);
7948 Reset(ListFile);
7949 while not EOF(ListFile) do
7950 begin
7951 ReadLn(ListFile, s);
7953 s := Trim(s);
7954 if s = '' then Continue;
7956 SetLength(MapList, Length(MapList)+1);
7957 MapList[High(MapList)] := s;
7958 end;
7959 CloseFile(ListFile);
7960 end;
7962 procedure g_Game_SetDebugMode();
7963 begin
7964 gDebugMode := True;
7965 // ×èòû (äàæå â ñâîåé èãðå):
7966 gCheats := True;
7967 end;
7969 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7970 var
7971 i: Word;
7972 begin
7973 if Length(LoadingStat.Msgs) = 0 then
7974 Exit;
7976 with LoadingStat do
7977 begin
7978 if not reWrite then
7979 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7980 if NextMsg = Length(Msgs) then
7981 begin // scroll
7982 for i := 0 to High(Msgs)-1 do
7983 Msgs[i] := Msgs[i+1];
7984 end
7985 else
7986 Inc(NextMsg);
7987 end else
7988 if NextMsg = 0 then
7989 Inc(NextMsg);
7991 Msgs[NextMsg-1] := Text;
7992 CurValue := 0;
7993 MaxValue := Max;
7994 ShowCount := 0;
7995 PBarWasHere := false;
7996 end;
7998 g_ActiveWindow := nil;
8000 ProcessLoading(true);
8001 end;
8003 procedure g_Game_StepLoading(Value: Integer = -1);
8004 begin
8005 with LoadingStat do
8006 begin
8007 if Value = -1 then
8008 begin
8009 Inc(CurValue);
8010 Inc(ShowCount);
8011 end
8012 else
8013 CurValue := Value;
8014 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8015 begin
8016 ShowCount := 0;
8017 ProcessLoading();
8018 end;
8019 end;
8020 end;
8022 procedure g_Game_ClearLoading();
8023 var
8024 len: Word;
8025 begin
8026 with LoadingStat do
8027 begin
8028 CurValue := 0;
8029 MaxValue := 0;
8030 ShowCount := 0;
8031 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8032 if len < 1 then len := 1;
8033 SetLength(Msgs, len);
8034 for len := Low(Msgs) to High(Msgs) do
8035 Msgs[len] := '';
8036 NextMsg := 0;
8037 PBarWasHere := false;
8038 end;
8039 end;
8041 procedure Parse_Params(var pars: TParamStrValues);
8042 var
8043 i: Integer;
8044 s: String;
8045 begin
8046 SetLength(pars, 0);
8047 i := 1;
8048 while i <= ParamCount do
8049 begin
8050 s := ParamStr(i);
8051 if (s[1] = '-') and (Length(s) > 1) then
8052 begin
8053 if (s[2] = '-') and (Length(s) > 2) then
8054 begin // Îäèíî÷íûé ïàðàìåòð
8055 SetLength(pars, Length(pars) + 1);
8056 with pars[High(pars)] do
8057 begin
8058 Name := LowerCase(s);
8059 Value := '+';
8060 end;
8061 end
8062 else
8063 if (i < ParamCount) then
8064 begin // Ïàðàìåòð ñî çíà÷åíèåì
8065 Inc(i);
8066 SetLength(pars, Length(pars) + 1);
8067 with pars[High(pars)] do
8068 begin
8069 Name := LowerCase(s);
8070 Value := LowerCase(ParamStr(i));
8071 end;
8072 end;
8073 end;
8075 Inc(i);
8076 end;
8077 end;
8079 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8080 var
8081 i: Integer;
8082 begin
8083 Result := '';
8084 for i := 0 to High(pars) do
8085 if pars[i].Name = aName then
8086 begin
8087 Result := pars[i].Value;
8088 Break;
8089 end;
8090 end;
8092 procedure g_Game_Process_Params();
8093 var
8094 pars: TParamStrValues;
8095 map: String;
8096 GMode, n: Byte;
8097 LimT, LimS: Integer;
8098 Opt: LongWord;
8099 Lives: Integer;
8100 s: String;
8101 Port: Integer;
8102 ip: String;
8103 F: TextFile;
8104 begin
8105 Parse_Params(pars);
8107 // Debug mode:
8108 s := Find_Param_Value(pars, '--debug');
8109 if (s <> '') then
8110 begin
8111 g_Game_SetDebugMode();
8112 s := Find_Param_Value(pars, '--netdump');
8113 if (s <> '') then
8114 NetDump := True;
8115 end;
8117 // Connect when game loads
8118 ip := Find_Param_Value(pars, '-connect');
8120 if ip <> '' then
8121 begin
8122 s := Find_Param_Value(pars, '-port');
8123 if (s = '') or not TryStrToInt(s, Port) then
8124 Port := 25666;
8126 s := Find_Param_Value(pars, '-pw');
8128 g_Game_StartClient(ip, Port, s);
8129 Exit;
8130 end;
8132 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8133 if (s <> '') then
8134 begin
8135 gDefaultMegawadStart := s;
8136 end;
8138 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8139 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8140 begin
8141 gDefaultMegawadStart := DF_Default_Megawad_Start;
8142 end;
8144 // Start map when game loads:
8145 map := LowerCase(Find_Param_Value(pars, '-map'));
8146 if isWadPath(map) then
8147 begin
8148 // Game mode:
8149 s := Find_Param_Value(pars, '-gm');
8150 GMode := g_Game_TextToMode(s);
8151 if GMode = GM_NONE then GMode := GM_DM;
8152 if GMode = GM_SINGLE then GMode := GM_COOP;
8154 // Time limit:
8155 s := Find_Param_Value(pars, '-limt');
8156 if (s = '') or (not TryStrToInt(s, LimT)) then
8157 LimT := 0;
8158 if LimT < 0 then
8159 LimT := 0;
8161 // Goal limit:
8162 s := Find_Param_Value(pars, '-lims');
8163 if (s = '') or (not TryStrToInt(s, LimS)) then
8164 LimS := 0;
8165 if LimS < 0 then
8166 LimS := 0;
8168 // Lives limit:
8169 s := Find_Param_Value(pars, '-lives');
8170 if (s = '') or (not TryStrToInt(s, Lives)) then
8171 Lives := 0;
8172 if Lives < 0 then
8173 Lives := 0;
8175 // Options:
8176 s := Find_Param_Value(pars, '-opt');
8177 if (s = '') then
8178 Opt := gsGameFlags
8179 else
8180 Opt := StrToIntDef(s, 0);
8182 // Close after map:
8183 s := Find_Param_Value(pars, '--close');
8184 if (s <> '') then
8185 gMapOnce := True;
8187 // Override map to test:
8188 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8189 if s <> '' then
8190 begin
8191 if e_IsValidResourceName(s) then
8192 e_FindResource(AllMapDirs, s);
8193 gTestMap := ExpandFileName(s);
8194 end;
8196 // Delete test map after play:
8197 s := Find_Param_Value(pars, '--testdelete');
8198 if (s <> '') then
8199 begin
8200 //gMapToDelete := MapsDir + map;
8201 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8202 Halt(1);
8203 end;
8205 // Delete temporary WAD after play:
8206 s := Find_Param_Value(pars, '--tempdelete');
8207 if (s <> '') and (gTestMap <> '') then
8208 begin
8209 gMapToDelete := gTestMap;
8210 gTempDelete := True;
8211 end;
8213 // Number of players:
8214 s := Find_Param_Value(pars, '-pl');
8215 if (s = '') then
8216 n := DEFAULT_PLAYERS
8217 else
8218 n := StrToIntDef(s, DEFAULT_PLAYERS);
8220 // Start:
8221 s := Find_Param_Value(pars, '-port');
8222 if (s = '') or not TryStrToInt(s, Port) then
8223 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8224 else
8225 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8226 end;
8228 // Execute script when game loads:
8229 s := Find_Param_Value(pars, '-exec');
8230 if s <> '' then
8231 begin
8232 // if not isWadPath(s) then
8233 // s := GameDir + '/' + s;
8235 {$I-}
8236 AssignFile(F, s);
8237 Reset(F);
8238 if IOResult <> 0 then
8239 begin
8240 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8241 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8242 CloseFile(F);
8243 Exit;
8244 end;
8245 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8246 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8248 while not EOF(F) do
8249 begin
8250 ReadLn(F, s);
8251 if IOResult <> 0 then
8252 begin
8253 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8254 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8255 CloseFile(F);
8256 Exit;
8257 end;
8258 if Pos('#', s) <> 1 then // script comment
8259 g_Console_Process(s, True);
8260 end;
8262 CloseFile(F);
8263 {$I+}
8264 end;
8266 SetLength(pars, 0);
8267 end;
8269 begin
8270 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8271 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8272 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8273 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8275 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8276 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8277 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8278 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8280 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8281 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8283 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8284 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8286 {$IFDEF ENABLE_HOLMES}
8287 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8288 {$ENDIF}
8290 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8292 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8293 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8295 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8296 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8298 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8299 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8301 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8302 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8303 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8304 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
8305 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8306 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8307 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8308 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8309 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8310 end.