DEADSOFTWARE

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