DEADSOFTWARE

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