DEADSOFTWARE

game: execute onwadend event after state is changed to INTERCUSTOM
[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 gState := STATE_INTERCUSTOM;
1910 InterReadyTime := -1;
1911 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1912 begin
1913 g_Game_ExecuteEvent('onwadend');
1914 if not gMusic.SetByName('MUSIC_endmus') then
1915 gMusic.SetByName('MUSIC_STDENDMUS');
1916 end
1917 else
1918 gMusic.SetByName('MUSIC_ROUNDMUS');
1919 gMusic.Play();
1920 e_UnpressAllKeys();
1921 end
1922 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1923 begin
1924 gMusic.SetByName('MUSIC_INTERMUS');
1925 gMusic.Play();
1926 gState := STATE_INTERSINGLE;
1927 e_UnpressAllKeys();
1928 end;
1929 g_Game_ExecuteEvent('oninter');
1930 end
1931 else
1932 DecMin(EndingGameCounter, 6, 0);
1933 end;
1935 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1936 begin
1937 if gMapOnce then // Ýòî áûë òåñò
1938 begin
1939 gExit := EXIT_SIMPLE;
1940 Exit;
1941 end;
1942 end;
1944 STATE_SLIST:
1945 g_Serverlist_Control(slCurrent, slTable);
1946 end;
1948 // Ñòàòèñòèêà ïî Tab:
1949 if gGameOn then
1950 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1952 // Èãðà èäåò:
1953 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1954 begin
1955 // Âðåìÿ += 28 ìèëëèñåêóíä:
1956 gTime := gTime + GAME_TICK;
1958 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1959 if MessageTime = 0 then
1960 MessageText := '';
1961 if MessageTime > 0 then
1962 MessageTime := MessageTime - 1;
1964 if (g_Game_IsServer) then
1965 begin
1966 // Áûë çàäàí ëèìèò âðåìåíè:
1967 if (gGameSettings.TimeLimit > 0) then
1968 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1969 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1970 g_Game_NextLevel();
1971 Exit;
1972 end;
1974 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1975 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1976 g_Game_RestartRound(gLMSSoftSpawn);
1978 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1979 if gVoteInProgress and (gVoteTimer < gTime) then
1980 g_Game_CheckVote
1981 else if gVotePassed and (gVoteCmdTimer < gTime) then
1982 begin
1983 g_Console_Process(gVoteCommand);
1984 gVoteCommand := '';
1985 gVotePassed := False;
1986 end;
1988 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1989 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1990 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1991 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1992 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1994 // Áûë çàäàí ëèìèò ïîáåä:
1995 if (gGameSettings.GoalLimit > 0) then
1996 begin
1997 b := 0;
1999 if gGameSettings.GameMode = GM_DM then
2000 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2001 for i := 0 to High(gPlayers) do
2002 if gPlayers[i] <> nil then
2003 if gPlayers[i].Frags > b then
2004 b := gPlayers[i].Frags;
2005 end
2006 else
2007 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2008 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2009 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
2010 end;
2012 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2013 if b >= gGameSettings.GoalLimit then
2014 begin
2015 g_Game_NextLevel();
2016 Exit;
2017 end;
2018 end;
2020 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2021 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2022 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2023 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2024 begin
2025 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2026 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2027 end // if not console
2028 else
2029 begin
2030 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2031 end;
2032 // process weapon switch queue
2033 end; // if server
2035 // Íàáëþäàòåëü
2036 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2037 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2038 begin
2039 if not gSpectKeyPress then
2040 begin
2041 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2042 begin
2043 // switch spect mode
2044 case gSpectMode of
2045 SPECT_NONE: ; // not spectator
2046 SPECT_STATS,
2047 SPECT_MAPVIEW: Inc(gSpectMode);
2048 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2049 end;
2050 gSpectKeyPress := True;
2051 end;
2052 if (gSpectMode = SPECT_MAPVIEW)
2053 and (not gSpectAuto) then
2054 begin
2055 if gPlayerAction[0, ACTION_MOVELEFT] then
2056 gSpectX := Max(gSpectX - gSpectStep, 0);
2057 if gPlayerAction[0, ACTION_MOVERIGHT] then
2058 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2059 if gPlayerAction[0, ACTION_LOOKUP] then
2060 gSpectY := Max(gSpectY - gSpectStep, 0);
2061 if gPlayerAction[0, ACTION_LOOKDOWN] then
2062 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2063 if gWeaponAction[0, WP_PREV] then
2064 begin
2065 // decrease step
2066 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2067 gWeaponAction[0, WP_PREV] := False;
2068 end;
2069 if gWeaponAction[0, WP_NEXT] then
2070 begin
2071 // increase step
2072 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2073 gWeaponAction[0, WP_NEXT] := False;
2074 end;
2075 end;
2076 if (gSpectMode = SPECT_PLAYERS)
2077 and (not gSpectAuto) then
2078 begin
2079 if gPlayerAction[0, ACTION_LOOKUP] then
2080 begin
2081 // add second view
2082 gSpectViewTwo := True;
2083 gSpectKeyPress := True;
2084 end;
2085 if gPlayerAction[0, ACTION_LOOKDOWN] then
2086 begin
2087 // remove second view
2088 gSpectViewTwo := False;
2089 gSpectKeyPress := True;
2090 end;
2091 if gPlayerAction[0, ACTION_MOVELEFT] then
2092 begin
2093 // prev player (view 1)
2094 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2095 gSpectKeyPress := True;
2096 end;
2097 if gPlayerAction[0, ACTION_MOVERIGHT] then
2098 begin
2099 // next player (view 1)
2100 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2101 gSpectKeyPress := True;
2102 end;
2103 if gWeaponAction[0, WP_PREV] then
2104 begin
2105 // prev player (view 2)
2106 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2107 gWeaponAction[0, WP_PREV] := False;
2108 end;
2109 if gWeaponAction[0, WP_NEXT] then
2110 begin
2111 // next player (view 2)
2112 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2113 gWeaponAction[0, WP_NEXT] := False;
2114 end;
2115 end;
2116 if gPlayerAction[0, ACTION_ATTACK] then
2117 begin
2118 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2119 begin
2120 gSpectAuto := True;
2121 gSpectAutoNext := 0;
2122 gSpectViewTwo := False;
2123 gSpectKeyPress := True;
2124 end
2125 else
2126 if gSpectAuto then
2127 begin
2128 gSpectMode := SPECT_STATS;
2129 gSpectAuto := False;
2130 gSpectKeyPress := True;
2131 end;
2132 end;
2133 end
2134 else
2135 if (not gPlayerAction[0, ACTION_JUMP]) and
2136 (not gPlayerAction[0, ACTION_ATTACK]) and
2137 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2138 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2139 (not gPlayerAction[0, ACTION_LOOKUP]) and
2140 (not gPlayerAction[0, ACTION_LOOKDOWN]) then
2141 gSpectKeyPress := False;
2143 if gSpectAuto then
2144 begin
2145 if gSpectMode = SPECT_MAPVIEW then
2146 begin
2147 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2148 if i = gSpectX then
2149 gSpectAutoNext := gTime
2150 else
2151 gSpectX := i;
2152 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2153 if i = gSpectY then
2154 gSpectAutoNext := gTime
2155 else
2156 gSpectY := i;
2157 end;
2158 if gSpectAutoNext <= gTime then
2159 begin
2160 if gSpectAutoNext > 0 then
2161 begin
2162 gSpectMode := GetRandomSpectMode(gSpectMode);
2163 case gSpectMode of
2164 SPECT_MAPVIEW:
2165 begin
2166 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2167 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2168 gSpectAutoStepX := Random(9) - 4;
2169 gSpectAutoStepY := Random(9) - 4;
2170 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2171 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2172 gSpectAutoStepX := gSpectAutoStepX * -1;
2173 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2174 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2175 gSpectAutoStepY := gSpectAutoStepY * -1;
2176 end;
2177 SPECT_PLAYERS:
2178 begin
2179 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2180 end;
2181 end;
2182 end;
2183 case gSpectMode of
2184 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2185 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2186 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2187 end;
2188 end;
2189 end;
2190 end;
2192 // Îáíîâëÿåì âñå îñòàëüíîå:
2193 g_Map_Update();
2194 g_Items_Update();
2195 g_Triggers_Update();
2196 g_Weapon_Update();
2197 g_Monsters_Update();
2198 g_GFX_Update();
2199 g_Player_UpdateAll();
2200 g_Player_UpdatePhysicalObjects();
2202 // server: send newly spawned monsters unconditionally
2203 if (gGameSettings.GameType = GT_SERVER) then
2204 begin
2205 if (Length(gMonstersSpawned) > 0) then
2206 begin
2207 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2208 SetLength(gMonstersSpawned, 0);
2209 end;
2210 end;
2212 if (gSoundTriggerTime > 8) then
2213 begin
2214 g_Game_UpdateTriggerSounds();
2215 gSoundTriggerTime := 0;
2216 end
2217 else
2218 begin
2219 Inc(gSoundTriggerTime);
2220 end;
2222 if (NetMode = NET_SERVER) then
2223 begin
2224 Inc(NetTimeToUpdate);
2225 Inc(NetTimeToReliable);
2227 // send monster updates
2228 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2229 begin
2230 // send all monsters (periodic sync)
2231 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2233 for I := 0 to High(gPlayers) do
2234 begin
2235 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2236 end;
2238 g_Mons_ForEach(sendMonsPos);
2240 if reliableUpdate then
2241 begin
2242 NetTimeToReliable := 0;
2243 NetTimeToUpdate := NetUpdateRate;
2244 end
2245 else
2246 begin
2247 NetTimeToUpdate := 0;
2248 end;
2249 end
2250 else
2251 begin
2252 // send only mosters with some unexpected changes
2253 g_Mons_ForEach(sendMonsPosUnexpected);
2254 end;
2256 // send unexpected platform changes
2257 g_Map_NetSendInterestingPanels();
2259 g_Net_Slist_ServerUpdate();
2261 if NetUseMaster then
2262 begin
2263 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2264 begin
2265 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2266 g_Net_Slist_Update;
2267 NetTimeToMaster := gTime + NetMasterRate;
2268 end;
2269 end;
2271 end
2272 else if (NetMode = NET_CLIENT) then
2273 begin
2274 MC_SEND_PlayerPos();
2275 end;
2276 end; // if gameOn ...
2278 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2279 if g_ActiveWindow <> nil then
2280 begin
2281 w := e_GetFirstKeyPressed();
2283 if (w <> IK_INVALID) then
2284 begin
2285 Msg.Msg := MESSAGE_DIKEY;
2286 Msg.wParam := w;
2287 g_ActiveWindow.OnMessage(Msg);
2288 end;
2290 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2291 if g_ActiveWindow <> nil then
2292 g_ActiveWindow.Update();
2294 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2295 if gResolutionChange then
2296 begin
2297 e_WriteLog('Changing resolution', TMsgType.Notify);
2298 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2299 gResolutionChange := False;
2300 g_ActiveWindow := nil;
2301 end;
2303 // Íóæíî ñìåíèòü ÿçûê:
2304 if gLanguageChange then
2305 begin
2306 //e_WriteLog('Read language file', MSG_NOTIFY);
2307 //g_Language_Load(DataDir + gLanguage + '.txt');
2308 g_Language_Set(gLanguage);
2309 {$IFNDEF HEADLESS}
2310 g_Menu_Reset();
2311 {$ENDIF}
2312 gLanguageChange := False;
2313 end;
2314 end;
2316 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2317 if e_KeyPressed(IK_F10) and
2318 gGameOn and
2319 (not gConsoleShow) and
2320 (g_ActiveWindow = nil) then
2321 begin
2322 KeyPress(IK_F10);
2323 end;
2325 Time := sys_GetTicks() {div 1000};
2327 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2328 if gDelayedEvents <> nil then
2329 for a := 0 to High(gDelayedEvents) do
2330 if gDelayedEvents[a].Pending and
2332 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2333 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2334 ) then
2335 begin
2336 case gDelayedEvents[a].DEType of
2337 DE_GLOBEVENT:
2338 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2339 DE_BFGHIT:
2340 if gGameOn then
2341 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2342 DE_KILLCOMBO:
2343 if gGameOn then
2344 begin
2345 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2346 if g_Game_IsNet and g_Game_IsServer then
2347 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2348 end;
2349 DE_BODYKILL:
2350 if gGameOn then
2351 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2352 end;
2353 gDelayedEvents[a].Pending := False;
2354 end;
2356 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2357 UPSCounter := UPSCounter + 1;
2358 if Time - UPSTime >= 1000 then
2359 begin
2360 UPS := UPSCounter;
2361 UPSCounter := 0;
2362 UPSTime := Time;
2363 end;
2365 if gGameOn then
2366 begin
2367 g_Weapon_AddDynLights();
2368 g_Items_AddDynLights();
2369 end;
2370 end;
2372 procedure g_Game_LoadChatSounds(Resource: string);
2373 var
2374 WAD: TWADFile;
2375 FileName, Snd: string;
2376 p: Pointer;
2377 len, cnt, tags, i, j: Integer;
2378 cfg: TConfig;
2379 begin
2380 FileName := g_ExtractWadName(Resource);
2382 WAD := TWADFile.Create();
2383 WAD.ReadFile(FileName);
2385 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2386 begin
2387 gChatSounds := nil;
2388 WAD.Free();
2389 Exit;
2390 end;
2392 cfg := TConfig.CreateMem(p, len);
2393 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2395 SetLength(gChatSounds, cnt);
2396 for i := 0 to Length(gChatSounds) - 1 do
2397 begin
2398 gChatSounds[i].Sound := nil;
2399 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2400 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2401 if (Snd = '') or (Tags <= 0) then
2402 continue;
2403 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2404 gChatSounds[i].Sound := TPlayableSound.Create();
2405 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2406 SetLength(gChatSounds[i].Tags, tags);
2407 for j := 0 to tags - 1 do
2408 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2409 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2410 end;
2412 cfg.Free();
2413 WAD.Free();
2414 end;
2416 procedure g_Game_FreeChatSounds();
2417 var
2418 i: Integer;
2419 begin
2420 for i := 0 to Length(gChatSounds) - 1 do
2421 begin
2422 gChatSounds[i].Sound.Free();
2423 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2424 end;
2425 SetLength(gChatSounds, 0);
2426 gChatSounds := nil;
2427 end;
2429 procedure g_Game_LoadData();
2430 var
2431 wl, hl: Integer;
2432 wr, hr: Integer;
2433 wb, hb: Integer;
2434 wm, hm: Integer;
2435 begin
2436 if DataLoaded then Exit;
2438 e_WriteLog('Loading game data...', TMsgType.Notify);
2440 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2441 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2442 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2443 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2444 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2445 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2446 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2447 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2448 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2449 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2450 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2451 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2452 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2453 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2454 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2456 hasPBarGfx := true;
2457 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2458 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2459 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2460 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2462 if hasPBarGfx then
2463 begin
2464 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2465 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2466 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2467 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2468 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
2469 begin
2470 // yay!
2471 end
2472 else
2473 begin
2474 hasPBarGfx := false;
2475 end;
2476 end;
2478 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2479 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2480 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2481 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2482 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2483 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2484 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2485 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2486 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2487 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2488 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2489 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2490 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2491 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2492 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2493 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2494 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2495 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2496 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2497 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2498 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2499 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2500 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2507 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2508 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2509 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2510 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2511 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2512 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2513 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2514 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2515 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2516 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2518 goodsnd[0] := TPlayableSound.Create();
2519 goodsnd[1] := TPlayableSound.Create();
2520 goodsnd[2] := TPlayableSound.Create();
2521 goodsnd[3] := TPlayableSound.Create();
2523 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2524 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2525 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2526 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2528 killsnd[0] := TPlayableSound.Create();
2529 killsnd[1] := TPlayableSound.Create();
2530 killsnd[2] := TPlayableSound.Create();
2531 killsnd[3] := TPlayableSound.Create();
2533 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2534 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2535 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2536 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2538 hahasnd[0] := TPlayableSound.Create();
2539 hahasnd[1] := TPlayableSound.Create();
2540 hahasnd[2] := TPlayableSound.Create();
2542 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2543 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2544 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2546 sound_get_flag[0] := TPlayableSound.Create();
2547 sound_get_flag[1] := TPlayableSound.Create();
2548 sound_lost_flag[0] := TPlayableSound.Create();
2549 sound_lost_flag[1] := TPlayableSound.Create();
2550 sound_ret_flag[0] := TPlayableSound.Create();
2551 sound_ret_flag[1] := TPlayableSound.Create();
2552 sound_cap_flag[0] := TPlayableSound.Create();
2553 sound_cap_flag[1] := TPlayableSound.Create();
2555 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2556 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2557 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2558 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2559 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2560 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2561 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2562 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2564 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2566 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2567 g_Items_LoadData();
2569 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2570 g_Weapon_LoadData();
2572 g_Monsters_LoadData();
2574 DataLoaded := True;
2575 end;
2577 procedure g_Game_FreeData();
2578 begin
2579 if not DataLoaded then Exit;
2581 g_Items_FreeData();
2582 g_Weapon_FreeData();
2583 g_Monsters_FreeData();
2585 e_WriteLog('Releasing game data...', TMsgType.Notify);
2587 g_Texture_Delete('NOTEXTURE');
2588 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2589 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2590 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2591 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2592 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2593 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2594 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2595 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2596 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2597 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2598 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2599 g_Frames_DeleteByName('FRAMES_TELEPORT');
2600 g_Frames_DeleteByName('FRAMES_PUNCH');
2601 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2602 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2603 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2604 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2605 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2606 g_Sound_Delete('SOUND_GAME_TELEPORT');
2607 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2608 g_Sound_Delete('SOUND_GAME_SECRET');
2609 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2610 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2611 g_Sound_Delete('SOUND_GAME_BULK1');
2612 g_Sound_Delete('SOUND_GAME_BULK2');
2613 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2614 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2615 g_Sound_Delete('SOUND_GAME_BURNING');
2616 g_Sound_Delete('SOUND_GAME_SWITCH1');
2617 g_Sound_Delete('SOUND_GAME_SWITCH0');
2619 goodsnd[0].Free();
2620 goodsnd[1].Free();
2621 goodsnd[2].Free();
2622 goodsnd[3].Free();
2624 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2625 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2626 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2627 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2629 killsnd[0].Free();
2630 killsnd[1].Free();
2631 killsnd[2].Free();
2632 killsnd[3].Free();
2634 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2635 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2636 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2637 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2639 hahasnd[0].Free();
2640 hahasnd[1].Free();
2641 hahasnd[2].Free();
2643 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2644 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2645 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2647 sound_get_flag[0].Free();
2648 sound_get_flag[1].Free();
2649 sound_lost_flag[0].Free();
2650 sound_lost_flag[1].Free();
2651 sound_ret_flag[0].Free();
2652 sound_ret_flag[1].Free();
2653 sound_cap_flag[0].Free();
2654 sound_cap_flag[1].Free();
2656 g_Sound_Delete('SOUND_CTF_GET1');
2657 g_Sound_Delete('SOUND_CTF_GET2');
2658 g_Sound_Delete('SOUND_CTF_LOST1');
2659 g_Sound_Delete('SOUND_CTF_LOST2');
2660 g_Sound_Delete('SOUND_CTF_RETURN1');
2661 g_Sound_Delete('SOUND_CTF_RETURN2');
2662 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2663 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2665 g_Game_FreeChatSounds();
2667 DataLoaded := False;
2668 end;
2670 procedure DrawCustomStat();
2671 var
2672 pc, x, y, w, _y,
2673 w1, w2, w3,
2674 t, p, m: Integer;
2675 ww1, hh1: Word;
2676 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2677 s1, s2, topstr: String;
2678 begin
2679 e_TextureFontGetSize(gStdFont, ww2, hh2);
2681 sys_HandleInput;
2683 if g_Console_Action(ACTION_SCORES) then
2684 begin
2685 if not gStatsPressed then
2686 begin
2687 gStatsOff := not gStatsOff;
2688 gStatsPressed := True;
2689 end;
2690 end
2691 else
2692 gStatsPressed := False;
2694 if gStatsOff then
2695 begin
2696 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2697 w := (Length(s1) * ww2) div 2;
2698 x := gScreenWidth div 2 - w;
2699 y := 8;
2700 e_TextureFontPrint(x, y, s1, gStdFont);
2701 Exit;
2702 end;
2704 if (gGameSettings.GameMode = GM_COOP) then
2705 begin
2706 if gMissionFailed then
2707 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2708 else
2709 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2710 end
2711 else
2712 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2714 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2715 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2717 if g_Game_IsNet then
2718 begin
2719 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2720 if not gChatShow then
2721 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2722 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2723 end;
2725 if g_Game_IsClient then
2726 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2727 else
2728 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2729 if not gChatShow then
2730 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2731 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2733 x := 32;
2734 y := 16+hh1+16;
2736 w := gScreenWidth-x*2;
2738 w2 := (w-16) div 6;
2739 w3 := w2;
2740 w1 := w-16-w2-w3;
2742 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2743 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2745 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2747 case CustomStat.GameMode of
2748 GM_DM:
2749 begin
2750 if gGameSettings.MaxLives = 0 then
2751 s1 := _lc[I_GAME_DM]
2752 else
2753 s1 := _lc[I_GAME_LMS];
2754 end;
2755 GM_TDM:
2756 begin
2757 if gGameSettings.MaxLives = 0 then
2758 s1 := _lc[I_GAME_TDM]
2759 else
2760 s1 := _lc[I_GAME_TLMS];
2761 end;
2762 GM_CTF: s1 := _lc[I_GAME_CTF];
2763 GM_COOP:
2764 begin
2765 if gGameSettings.MaxLives = 0 then
2766 s1 := _lc[I_GAME_COOP]
2767 else
2768 s1 := _lc[I_GAME_SURV];
2769 end;
2770 else s1 := '';
2771 end;
2773 _y := y+16;
2774 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2775 _y := _y+8;
2777 _y := _y+16;
2778 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2779 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2781 _y := _y+16;
2782 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2783 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2784 (CustomStat.GameTime div 1000 div 60) mod 60,
2785 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2787 pc := Length(CustomStat.PlayerStat);
2788 if pc = 0 then Exit;
2790 if CustomStat.GameMode = GM_COOP then
2791 begin
2792 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2793 _y := _y+32;
2794 s2 := _lc[I_GAME_MONSTERS];
2795 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2796 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2797 _y := _y+16;
2798 s2 := _lc[I_GAME_SECRETS];
2799 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2800 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2801 if gLastMap then
2802 begin
2803 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2804 _y := _y-16;
2805 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2806 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2807 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2808 _y := _y+16;
2809 s2 := _lc[I_GAME_SECRETS_TOTAL];
2810 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2811 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2812 end;
2813 end;
2815 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2816 begin
2817 _y := _y+16+16;
2819 with CustomStat do
2820 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2821 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2822 else s1 := _lc[I_GAME_WIN_DRAW];
2824 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2825 _y := _y+40;
2827 for t := TEAM_RED to TEAM_BLUE do
2828 begin
2829 if t = TEAM_RED then
2830 begin
2831 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2832 gStdFont, 255, 0, 0, 1);
2833 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2834 gStdFont, 255, 0, 0, 1);
2835 r := 255;
2836 g := 0;
2837 b := 0;
2838 end
2839 else
2840 begin
2841 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2842 gStdFont, 0, 0, 255, 1);
2843 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2844 gStdFont, 0, 0, 255, 1);
2845 r := 0;
2846 g := 0;
2847 b := 255;
2848 end;
2850 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2851 _y := _y+24;
2853 for p := 0 to High(CustomStat.PlayerStat) do
2854 if CustomStat.PlayerStat[p].Team = t then
2855 with CustomStat.PlayerStat[p] do
2856 begin
2857 if Spectator then
2858 begin
2859 rr := r div 2;
2860 gg := g div 2;
2861 bb := b div 2;
2862 end
2863 else
2864 begin
2865 rr := r;
2866 gg := g;
2867 bb := b;
2868 end;
2869 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2870 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2871 else
2872 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2873 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2874 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2875 _y := _y+24;
2876 end;
2878 _y := _y+16+16;
2879 end;
2880 end
2881 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2882 begin
2883 _y := _y+40;
2884 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2885 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2886 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2888 _y := _y+24;
2889 for p := 0 to High(CustomStat.PlayerStat) do
2890 with CustomStat.PlayerStat[p] do
2891 begin
2892 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2894 if Spectator then
2895 r := 127
2896 else
2897 r := 255;
2899 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2900 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2901 else
2902 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2903 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2904 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2905 _y := _y+24;
2906 end;
2907 end;
2909 // HACK: take stats screenshot immediately after the first frame of the stats showing
2910 if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
2911 begin
2912 g_TakeScreenShot('stats/' + StatFilename);
2913 StatShotDone := True;
2914 end;
2915 end;
2917 procedure DrawSingleStat();
2918 var
2919 tm, key_x, val_x, y: Integer;
2920 w1, w2, h: Word;
2921 s1, s2: String;
2923 procedure player_stat(n: Integer);
2924 var
2925 kpm: Real;
2927 begin
2928 // "Kills: # / #":
2929 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2930 s2 := Format(' %d', [gTotalMonsters]);
2932 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2933 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2934 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2935 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2936 s1 := s1 + '/';
2937 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2938 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2940 // "Kills-per-minute: ##.#":
2941 s1 := _lc[I_MENU_INTER_KPM];
2942 if tm > 0 then
2943 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2944 else
2945 kpm := SingleStat.PlayerStat[n].Kills;
2946 s2 := Format(' %.1f', [kpm]);
2948 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2949 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2951 // "Secrets found: # / #":
2952 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2953 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2955 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2956 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2957 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2958 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2959 s1 := s1 + '/';
2960 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2961 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2962 end;
2964 begin
2965 // "Level Complete":
2966 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2967 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2969 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2970 s1 := _lc[I_MENU_INTER_KPM];
2971 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2972 Inc(w1, 16);
2973 s1 := ' 9999.9';
2974 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2976 key_x := (gScreenWidth-w1-w2) div 2;
2977 val_x := key_x + w1;
2979 // "Time: #:##:##":
2980 tm := SingleStat.GameTime div 1000;
2981 s1 := _lc[I_MENU_INTER_TIME];
2982 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2984 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2985 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2987 if SingleStat.TwoPlayers then
2988 begin
2989 // "Player 1":
2990 s1 := _lc[I_MENU_PLAYER_1];
2991 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2992 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2994 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2995 y := 176;
2996 player_stat(0);
2998 // "Player 2":
2999 s1 := _lc[I_MENU_PLAYER_2];
3000 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3001 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
3003 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3004 y := 336;
3005 player_stat(1);
3006 end
3007 else
3008 begin
3009 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3010 y := 128;
3011 player_stat(0);
3012 end;
3013 end;
3015 procedure DrawLoadingStat();
3016 procedure drawRect (x, y, w, h: Integer);
3017 begin
3018 if (w < 1) or (h < 1) then exit;
3019 glBegin(GL_QUADS);
3020 glVertex2f(x+0.375, y+0.375);
3021 glVertex2f(x+w+0.375, y+0.375);
3022 glVertex2f(x+w+0.375, y+h+0.375);
3023 glVertex2f(x+0.375, y+h+0.375);
3024 glEnd();
3025 end;
3027 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
3028 var
3029 rectW, rectH: Integer;
3030 x0, y0: Integer;
3031 wdt: Integer;
3032 wl, hl: Integer;
3033 wr, hr: Integer;
3034 wb, hb: Integer;
3035 wm, hm: Integer;
3036 idl, idr, idb, idm: LongWord;
3037 f, my: Integer;
3038 begin
3039 result := false;
3040 if (total < 1) then exit;
3041 if (cur < 1) then exit; // don't blink
3042 if (not washere) and (cur >= total) then exit; // don't blink
3043 //if (cur < 0) then cur := 0;
3044 //if (cur > total) then cur := total;
3045 result := true;
3047 if (hasPBarGfx) then
3048 begin
3049 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
3050 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
3051 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
3052 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
3053 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
3054 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
3055 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
3056 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
3058 //rectW := gScreenWidth-360;
3059 rectW := trunc(624.0*gScreenWidth/1024.0);
3060 rectH := hl;
3062 x0 := (gScreenWidth-rectW) div 2;
3063 y0 := gScreenHeight-rectH-64;
3064 if (y0 < 2) then y0 := 2;
3066 glEnable(GL_SCISSOR_TEST);
3068 // left and right
3069 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
3070 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
3071 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
3073 // body
3074 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
3075 f := x0+wl;
3076 while (f < x0+rectW) do
3077 begin
3078 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
3079 f += wb;
3080 end;
3082 // filled part
3083 wdt := (rectW-wl-wr)*cur div total;
3084 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
3085 if (wdt > 0) then
3086 begin
3087 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
3088 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
3089 f := x0+wl;
3090 while (wdt > 0) do
3091 begin
3092 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
3093 f += wm;
3094 wdt -= wm;
3095 end;
3096 end;
3098 glScissor(0, 0, gScreenWidth, gScreenHeight);
3099 end
3100 else
3101 begin
3102 rectW := gScreenWidth-64;
3103 rectH := 16;
3105 x0 := (gScreenWidth-rectW) div 2;
3106 y0 := gScreenHeight-rectH-64;
3107 if (y0 < 2) then y0 := 2;
3109 glDisable(GL_BLEND);
3110 glDisable(GL_TEXTURE_2D);
3112 //glClearColor(0, 0, 0, 0);
3113 //glClear(GL_COLOR_BUFFER_BIT);
3115 glColor4ub(127, 127, 127, 255);
3116 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3118 glColor4ub(0, 0, 0, 255);
3119 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3121 glColor4ub(127, 127, 127, 255);
3122 wdt := rectW*cur div total;
3123 if (wdt > rectW) then wdt := rectW;
3124 drawRect(x0, y0, wdt, rectH);
3125 end;
3126 end;
3128 var
3129 ww, hh: Word;
3130 xx, yy, i: Integer;
3131 s: String;
3132 begin
3133 if (Length(LoadingStat.Msgs) = 0) then exit;
3135 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3136 yy := (gScreenHeight div 3);
3137 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3138 xx := (gScreenWidth div 3);
3140 with LoadingStat do
3141 begin
3142 for i := 0 to NextMsg-1 do
3143 begin
3144 if (i = (NextMsg-1)) and (MaxValue > 0) then
3145 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3146 else
3147 s := Msgs[i];
3149 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3150 yy := yy + LOADING_INTERLINE;
3151 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3152 end;
3153 end;
3154 end;
3156 procedure DrawMenuBackground(tex: AnsiString);
3157 var
3158 w, h: Word;
3159 ID: DWord;
3161 begin
3162 if g_Texture_Get(tex, ID) then
3163 begin
3164 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3165 e_GetTextureSize(ID, @w, @h);
3166 if w = h then
3167 w := round(w * 1.333 * (gScreenHeight / h))
3168 else
3169 w := trunc(w * (gScreenHeight / h));
3170 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3171 end
3172 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3173 end;
3175 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3176 var
3177 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3179 function monDraw (mon: TMonster): Boolean;
3180 begin
3181 result := false; // don't stop
3182 with mon do
3183 begin
3184 if alive then
3185 begin
3186 // Ëåâûé âåðõíèé óãîë
3187 aX := Obj.X div ScaleSz + 1;
3188 aY := Obj.Y div ScaleSz + 1;
3189 // Ðàçìåðû
3190 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3191 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3192 // Ïðàâûé íèæíèé óãîë
3193 aX2 := aX + aX2 - 1;
3194 aY2 := aY + aY2 - 1;
3195 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3196 end;
3197 end;
3198 end;
3200 begin
3201 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3202 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3203 begin
3204 Scale := 1;
3205 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3206 ScaleSz := 16 div Scale;
3207 // Ðàçìåðû ìèíè-êàðòû:
3208 aX := max(gMapInfo.Width div ScaleSz, 1);
3209 aY := max(gMapInfo.Height div ScaleSz, 1);
3210 // Ðàìêà êàðòû:
3211 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3213 if gWalls <> nil then
3214 begin
3215 // Ðèñóåì ñòåíû:
3216 for a := 0 to High(gWalls) do
3217 with gWalls[a] do
3218 if PanelType <> 0 then
3219 begin
3220 // Ëåâûé âåðõíèé óãîë:
3221 aX := X div ScaleSz;
3222 aY := Y div ScaleSz;
3223 // Ðàçìåðû:
3224 aX2 := max(Width div ScaleSz, 1);
3225 aY2 := max(Height div ScaleSz, 1);
3226 // Ïðàâûé íèæíèé óãîë:
3227 aX2 := aX + aX2 - 1;
3228 aY2 := aY + aY2 - 1;
3230 case PanelType of
3231 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3232 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3233 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3234 end;
3235 end;
3236 end;
3237 if gSteps <> nil then
3238 begin
3239 // Ðèñóåì ñòóïåíè:
3240 for a := 0 to High(gSteps) do
3241 with gSteps[a] do
3242 if PanelType <> 0 then
3243 begin
3244 // Ëåâûé âåðõíèé óãîë:
3245 aX := X div ScaleSz;
3246 aY := Y div ScaleSz;
3247 // Ðàçìåðû:
3248 aX2 := max(Width div ScaleSz, 1);
3249 aY2 := max(Height div ScaleSz, 1);
3250 // Ïðàâûé íèæíèé óãîë:
3251 aX2 := aX + aX2 - 1;
3252 aY2 := aY + aY2 - 1;
3254 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3255 end;
3256 end;
3257 if gLifts <> nil then
3258 begin
3259 // Ðèñóåì ëèôòû:
3260 for a := 0 to High(gLifts) do
3261 with gLifts[a] do
3262 if PanelType <> 0 then
3263 begin
3264 // Ëåâûé âåðõíèé óãîë:
3265 aX := X div ScaleSz;
3266 aY := Y div ScaleSz;
3267 // Ðàçìåðû:
3268 aX2 := max(Width div ScaleSz, 1);
3269 aY2 := max(Height div ScaleSz, 1);
3270 // Ïðàâûé íèæíèé óãîë:
3271 aX2 := aX + aX2 - 1;
3272 aY2 := aY + aY2 - 1;
3274 case LiftType of
3275 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3276 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3277 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3278 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3279 end;
3280 end;
3281 end;
3282 if gWater <> nil then
3283 begin
3284 // Ðèñóåì âîäó:
3285 for a := 0 to High(gWater) do
3286 with gWater[a] do
3287 if PanelType <> 0 then
3288 begin
3289 // Ëåâûé âåðõíèé óãîë:
3290 aX := X div ScaleSz;
3291 aY := Y div ScaleSz;
3292 // Ðàçìåðû:
3293 aX2 := max(Width div ScaleSz, 1);
3294 aY2 := max(Height div ScaleSz, 1);
3295 // Ïðàâûé íèæíèé óãîë:
3296 aX2 := aX + aX2 - 1;
3297 aY2 := aY + aY2 - 1;
3299 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3300 end;
3301 end;
3302 if gAcid1 <> nil then
3303 begin
3304 // Ðèñóåì êèñëîòó 1:
3305 for a := 0 to High(gAcid1) do
3306 with gAcid1[a] do
3307 if PanelType <> 0 then
3308 begin
3309 // Ëåâûé âåðõíèé óãîë:
3310 aX := X div ScaleSz;
3311 aY := Y div ScaleSz;
3312 // Ðàçìåðû:
3313 aX2 := max(Width div ScaleSz, 1);
3314 aY2 := max(Height div ScaleSz, 1);
3315 // Ïðàâûé íèæíèé óãîë:
3316 aX2 := aX + aX2 - 1;
3317 aY2 := aY + aY2 - 1;
3319 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3320 end;
3321 end;
3322 if gAcid2 <> nil then
3323 begin
3324 // Ðèñóåì êèñëîòó 2:
3325 for a := 0 to High(gAcid2) do
3326 with gAcid2[a] do
3327 if PanelType <> 0 then
3328 begin
3329 // Ëåâûé âåðõíèé óãîë:
3330 aX := X div ScaleSz;
3331 aY := Y div ScaleSz;
3332 // Ðàçìåðû:
3333 aX2 := max(Width div ScaleSz, 1);
3334 aY2 := max(Height div ScaleSz, 1);
3335 // Ïðàâûé íèæíèé óãîë:
3336 aX2 := aX + aX2 - 1;
3337 aY2 := aY + aY2 - 1;
3339 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3340 end;
3341 end;
3342 if gPlayers <> nil then
3343 begin
3344 // Ðèñóåì èãðîêîâ:
3345 for a := 0 to High(gPlayers) do
3346 if gPlayers[a] <> nil then with gPlayers[a] do
3347 if alive then begin
3348 // Ëåâûé âåðõíèé óãîë:
3349 aX := Obj.X div ScaleSz + 1;
3350 aY := Obj.Y div ScaleSz + 1;
3351 // Ðàçìåðû:
3352 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3353 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3354 // Ïðàâûé íèæíèé óãîë:
3355 aX2 := aX + aX2 - 1;
3356 aY2 := aY + aY2 - 1;
3358 if gPlayers[a] = p then
3359 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3360 else
3361 case Team of
3362 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3363 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3364 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3365 end;
3366 end;
3367 end;
3368 // Ðèñóåì ìîíñòðîâ
3369 g_Mons_ForEach(monDraw);
3370 end;
3371 end;
3374 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3375 begin
3376 if not hasAmbient then exit;
3377 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3378 end;
3381 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3382 //FIXME: broken for splitscreen mode
3383 procedure renderDynLightsInternal ();
3384 var
3385 //hasAmbient: Boolean;
3386 //ambColor: TDFColor;
3387 lln: Integer;
3388 lx, ly, lrad: Integer;
3389 scxywh: array[0..3] of GLint;
3390 wassc: Boolean;
3391 begin
3392 if e_NoGraphics then exit;
3394 //TODO: lights should be in separate grid, i think
3395 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3396 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3398 // rendering mode
3399 //ambColor := gCurrentMap['light_ambient'].rgba;
3400 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3402 { // this will multiply incoming color to alpha from framebuffer
3403 glEnable(GL_BLEND);
3404 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3407 (*
3408 * light rendering: (INVALID!)
3409 * glStencilFunc(GL_EQUAL, 0, $ff);
3410 * for each light:
3411 * glClear(GL_STENCIL_BUFFER_BIT);
3412 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3413 * draw shadow volume into stencil buffer
3414 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3415 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3416 * turn off blending
3417 * draw color-less quad with light alpha (WARNING! don't touch color!)
3418 * glEnable(GL_BLEND);
3419 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3420 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3421 *)
3422 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3423 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3425 // setup OpenGL parameters
3426 glStencilMask($FFFFFFFF);
3427 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3428 glEnable(GL_STENCIL_TEST);
3429 glEnable(GL_SCISSOR_TEST);
3430 glClear(GL_STENCIL_BUFFER_BIT);
3431 glStencilFunc(GL_EQUAL, 0, $ff);
3433 for lln := 0 to g_dynLightCount-1 do
3434 begin
3435 lx := g_dynLights[lln].x;
3436 ly := g_dynLights[lln].y;
3437 lrad := g_dynLights[lln].radius;
3438 if (lrad < 3) then continue;
3440 if (lx-sX+lrad < 0) then continue;
3441 if (ly-sY+lrad < 0) then continue;
3442 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3443 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3445 // set scissor to optimize drawing
3446 if (g_dbg_scale = 1.0) then
3447 begin
3448 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3449 end
3450 else
3451 begin
3452 glScissor(0, 0, gScreenWidth, gScreenHeight);
3453 end;
3454 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3455 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3456 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3457 // draw extruded panels
3458 glDisable(GL_TEXTURE_2D);
3459 glDisable(GL_BLEND);
3460 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3461 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3462 // render light texture
3463 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3464 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3465 // blend it
3466 glEnable(GL_BLEND);
3467 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3468 glEnable(GL_TEXTURE_2D);
3469 // color and opacity
3470 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3471 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3472 glBegin(GL_QUADS);
3473 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3474 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3475 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3476 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3477 glEnd();
3478 end;
3480 // done
3481 glDisable(GL_STENCIL_TEST);
3482 glDisable(GL_BLEND);
3483 glDisable(GL_SCISSOR_TEST);
3484 //glScissor(0, 0, sWidth, sHeight);
3486 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3487 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3488 end;
3491 function fixViewportForScale (): Boolean;
3492 var
3493 nx0, ny0, nw, nh: Integer;
3494 begin
3495 result := false;
3496 if (g_dbg_scale <> 1.0) then
3497 begin
3498 result := true;
3499 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3500 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3501 nw := round(sWidth/g_dbg_scale);
3502 nh := round(sHeight/g_dbg_scale);
3503 sX := nx0;
3504 sY := ny0;
3505 sWidth := nw;
3506 sHeight := nh;
3507 end;
3508 end;
3511 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3512 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3513 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3514 type
3515 TDrawCB = procedure ();
3517 var
3518 hasAmbient: Boolean;
3519 ambColor: TDFColor;
3520 doAmbient: Boolean = false;
3522 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3523 var
3524 tagmask: Integer;
3525 pan: TPanel;
3526 begin
3527 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3528 if gdbg_map_use_accel_render then
3529 begin
3530 tagmask := panelTypeToTag(panType);
3531 while (gDrawPanelList.count > 0) do
3532 begin
3533 pan := TPanel(gDrawPanelList.front());
3534 if ((pan.tag and tagmask) = 0) then break;
3535 if doDraw then pan.Draw(doAmbient, ambColor);
3536 gDrawPanelList.popFront();
3537 end;
3538 end
3539 else
3540 begin
3541 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3542 end;
3543 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3544 end;
3546 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3547 begin
3548 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3549 if assigned(cb) then cb();
3550 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3551 end;
3553 begin
3554 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3556 // our accelerated renderer will collect all panels to gDrawPanelList
3557 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3558 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3559 if gdbg_map_use_accel_render then
3560 begin
3561 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3562 end;
3563 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3565 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3566 g_Map_DrawBack(backXOfs, backYOfs);
3567 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3569 if setTransMatrix then
3570 begin
3571 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3572 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3573 glTranslatef(-sX, -sY, 0);
3574 end;
3576 // rendering mode
3577 ambColor := gCurrentMap['light_ambient'].rgba;
3578 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3581 if hasAmbient then
3582 begin
3583 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3584 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3585 glClear(GL_COLOR_BUFFER_BIT);
3586 end;
3588 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3591 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3592 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3593 drawOther('items', @g_Items_Draw);
3594 drawOther('weapons', @g_Weapon_Draw);
3595 drawOther('shells', @g_Player_DrawShells);
3596 drawOther('drawall', @g_Player_DrawAll);
3597 drawOther('corpses', @g_Player_DrawCorpses);
3598 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3599 drawOther('monsters', @g_Monsters_Draw);
3600 drawOther('itemdrop', @g_Items_DrawDrop);
3601 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3602 drawOther('gfx', @g_GFX_Draw);
3603 drawOther('flags', @g_Map_DrawFlags);
3604 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3605 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3606 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3607 drawOther('dynlights', @renderDynLightsInternal);
3609 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3610 begin
3611 renderAmbientQuad(hasAmbient, ambColor);
3612 end;
3614 doAmbient := true;
3615 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3618 if g_debug_HealthBar then
3619 begin
3620 g_Monsters_DrawHealth();
3621 g_Player_DrawHealth();
3622 end;
3624 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3625 end;
3628 procedure DrawMapView(x, y, w, h: Integer);
3630 var
3631 bx, by: Integer;
3632 begin
3633 glPushMatrix();
3635 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3636 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3638 sX := x;
3639 sY := y;
3640 sWidth := w;
3641 sHeight := h;
3643 fixViewportForScale();
3644 renderMapInternal(-bx, -by, true);
3646 glPopMatrix();
3647 end;
3650 procedure DrawPlayer(p: TPlayer);
3651 var
3652 px, py, a, b, c, d, i, fX, fY: Integer;
3653 camObj: TObj;
3654 //R: TRect;
3655 begin
3656 if (p = nil) or (p.FDummy) then
3657 begin
3658 glPushMatrix();
3659 g_Map_DrawBack(0, 0);
3660 glPopMatrix();
3661 Exit;
3662 end;
3664 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3665 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3667 gPlayerDrawn := p;
3669 glPushMatrix();
3671 camObj := p.getCameraObj();
3672 camObj.lerp(gLerpFactor, fX, fY);
3673 px := fX + PLAYER_RECT_CX;
3674 py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, camObj.slopeUpLeft, gLerpFactor);
3676 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3677 begin
3678 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3679 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3681 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3682 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3684 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3685 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3686 begin
3687 // hcenter
3688 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3689 end;
3691 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3692 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3693 begin
3694 // vcenter
3695 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3696 end;
3697 end
3698 else
3699 begin
3700 // scaled, ignore level bounds
3701 a := -px+(gPlayerScreenSize.X div 2);
3702 b := -py+(gPlayerScreenSize.Y div 2);
3703 end;
3705 sX := -a;
3706 sY := -b;
3707 sWidth := gPlayerScreenSize.X;
3708 sHeight := gPlayerScreenSize.Y;
3709 fixViewportForScale();
3711 i := py - (sY + sHeight div 2);
3712 if (p.IncCam > 0) then
3713 begin
3714 // clamp to level bounds
3715 if (sY - p.IncCam < 0) then
3716 p.IncCam := nclamp(sY, 0, 120);
3717 // clamp around player position
3718 if (i > 0) then
3719 p.IncCam := nclamp(p.IncCam, 0, max(0, 120 - i));
3720 end
3721 else if (p.IncCam < 0) then
3722 begin
3723 // clamp to level bounds
3724 if (sY + sHeight - p.IncCam > gMapInfo.Height) then
3725 p.IncCam := nclamp(sY + sHeight - gMapInfo.Height, -120, 0);
3726 // clamp around player position
3727 if (i < 0) then
3728 p.IncCam := nclamp(p.IncCam, min(0, -120 - i), 0);
3729 end;
3731 sY := sY - nlerp(p.IncCamOld, p.IncCam, gLerpFactor);
3733 if (not g_dbg_ignore_bounds) then
3734 begin
3735 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3736 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3737 if (sX < 0) then sX := 0;
3738 if (sY < 0) then sY := 0;
3739 end;
3741 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3742 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3744 //r_smallmap_h: 0: left; 1: center; 2: right
3745 //r_smallmap_v: 0: top; 1: center; 2: bottom
3746 // horiz small map?
3747 if (gMapInfo.Width = sWidth) then
3748 begin
3749 sX := 0;
3750 end
3751 else if (gMapInfo.Width < sWidth) then
3752 begin
3753 case r_smallmap_h of
3754 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3755 2: sX := -(sWidth-gMapInfo.Width); // right
3756 else sX := 0; // left
3757 end;
3758 end;
3759 // vert small map?
3760 if (gMapInfo.Height = sHeight) then
3761 begin
3762 sY := 0;
3763 end
3764 else if (gMapInfo.Height < sHeight) then
3765 begin
3766 case r_smallmap_v of
3767 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3768 2: sY := -(sHeight-gMapInfo.Height); // bottom
3769 else sY := 0; // top
3770 end;
3771 end;
3773 p.viewPortX := sX;
3774 p.viewPortY := sY;
3775 p.viewPortW := sWidth;
3776 p.viewPortH := sHeight;
3778 {$IFDEF ENABLE_HOLMES}
3779 if (p = gPlayer1) then
3780 begin
3781 g_Holmes_plrViewPos(sX, sY);
3782 g_Holmes_plrViewSize(sWidth, sHeight);
3783 end;
3784 {$ENDIF}
3786 renderMapInternal(-c, -d, true);
3788 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3789 case gPlayerIndicator of
3790 1:
3791 p.DrawIndicator(_RGB(255, 255, 255));
3793 2:
3794 for i := 0 to High(gPlayers) do
3795 if gPlayers[i] <> nil then
3796 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3797 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3798 if gPlayerIndicatorStyle = 1 then
3799 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3800 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3801 end;
3804 for a := 0 to High(gCollideMap) do
3805 for b := 0 to High(gCollideMap[a]) do
3806 begin
3807 d := 0;
3808 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3809 d := d + 1;
3810 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3811 d := d + 2;
3813 case d of
3814 1: e_DrawPoint(1, b, a, 200, 200, 200);
3815 2: e_DrawPoint(1, b, a, 64, 64, 255);
3816 3: e_DrawPoint(1, b, a, 255, 0, 255);
3817 end;
3818 end;
3821 glPopMatrix();
3823 p.DrawPain();
3824 p.DrawPickup();
3825 p.DrawRulez();
3826 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3827 if g_Debug_Player then
3828 g_Player_DrawDebug(p);
3829 p.DrawGUI();
3830 end;
3832 procedure drawProfilers ();
3833 var
3834 px: Integer = -1;
3835 py: Integer = -1;
3836 begin
3837 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3838 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3839 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3840 end;
3842 procedure g_Game_Draw();
3843 var
3844 ID: DWORD;
3845 w, h: Word;
3846 ww, hh: Byte;
3847 Time: Int64;
3848 back: string;
3849 plView1, plView2: TPlayer;
3850 Split: Boolean;
3851 begin
3852 if gExit = EXIT_QUIT then Exit;
3854 Time := sys_GetTicks() {div 1000};
3855 FPSCounter := FPSCounter+1;
3856 if Time - FPSTime >= 1000 then
3857 begin
3858 FPS := FPSCounter;
3859 FPSCounter := 0;
3860 FPSTime := Time;
3861 end;
3863 e_SetRendertarget(True);
3864 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3866 if gGameOn or (gState = STATE_FOLD) then
3867 begin
3868 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3869 begin
3870 gSpectMode := SPECT_NONE;
3871 if not gRevertPlayers then
3872 begin
3873 plView1 := gPlayer1;
3874 plView2 := gPlayer2;
3875 end
3876 else
3877 begin
3878 plView1 := gPlayer2;
3879 plView2 := gPlayer1;
3880 end;
3881 end
3882 else
3883 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3884 begin
3885 gSpectMode := SPECT_NONE;
3886 if gPlayer2 = nil then
3887 plView1 := gPlayer1
3888 else
3889 plView1 := gPlayer2;
3890 plView2 := nil;
3891 end
3892 else
3893 begin
3894 plView1 := nil;
3895 plView2 := nil;
3896 end;
3898 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3899 gSpectMode := SPECT_STATS;
3901 if gSpectMode = SPECT_PLAYERS then
3902 if gPlayers <> nil then
3903 begin
3904 plView1 := GetActivePlayer_ByID(gSpectPID1);
3905 if plView1 = nil then
3906 begin
3907 gSpectPID1 := GetActivePlayerID_Next();
3908 plView1 := GetActivePlayer_ByID(gSpectPID1);
3909 end;
3910 if gSpectViewTwo then
3911 begin
3912 plView2 := GetActivePlayer_ByID(gSpectPID2);
3913 if plView2 = nil then
3914 begin
3915 gSpectPID2 := GetActivePlayerID_Next();
3916 plView2 := GetActivePlayer_ByID(gSpectPID2);
3917 end;
3918 end;
3919 end;
3921 if gSpectMode = SPECT_MAPVIEW then
3922 begin
3923 // Ðåæèì ïðîñìîòðà êàðòû
3924 Split := False;
3925 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3926 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3927 gHearPoint1.Active := True;
3928 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3929 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3930 gHearPoint2.Active := False;
3931 end
3932 else
3933 begin
3934 Split := (plView1 <> nil) and (plView2 <> nil);
3936 // Òî÷êè ñëóõà èãðîêîâ
3937 if plView1 <> nil then
3938 begin
3939 gHearPoint1.Active := True;
3940 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3941 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3942 end else
3943 gHearPoint1.Active := False;
3944 if plView2 <> nil then
3945 begin
3946 gHearPoint2.Active := True;
3947 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3948 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3949 end else
3950 gHearPoint2.Active := False;
3952 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3953 gPlayerScreenSize.X := gScreenWidth-196;
3954 if Split then
3955 begin
3956 gPlayerScreenSize.Y := gScreenHeight div 2;
3957 if gScreenHeight mod 2 = 0 then
3958 Dec(gPlayerScreenSize.Y);
3959 end
3960 else
3961 gPlayerScreenSize.Y := gScreenHeight;
3963 if Split then
3964 if gScreenHeight mod 2 = 0 then
3965 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3966 else
3967 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3969 DrawPlayer(plView1);
3970 gPlayer1ScreenCoord.X := sX;
3971 gPlayer1ScreenCoord.Y := sY;
3973 if Split then
3974 begin
3975 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3977 DrawPlayer(plView2);
3978 gPlayer2ScreenCoord.X := sX;
3979 gPlayer2ScreenCoord.Y := sY;
3980 end;
3982 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3984 if Split then
3985 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3986 end;
3988 {$IFDEF ENABLE_HOLMES}
3989 // draw inspector
3990 if (g_holmes_enabled) then g_Holmes_Draw();
3991 {$ENDIF}
3993 if MessageText <> '' then
3994 begin
3995 w := 0;
3996 h := 0;
3997 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3998 if Split then
3999 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4000 (gScreenHeight div 2)-(h div 2), MessageText)
4001 else
4002 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4003 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4004 end;
4006 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4007 DrawStat();
4009 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4010 begin
4011 // Draw spectator GUI
4012 ww := 0;
4013 hh := 0;
4014 e_TextureFontGetSize(gStdFont, ww, hh);
4015 case gSpectMode of
4016 SPECT_STATS:
4017 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4018 SPECT_MAPVIEW:
4019 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4020 SPECT_PLAYERS:
4021 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4022 end;
4023 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4024 if gSpectMode = SPECT_STATS then
4025 begin
4026 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4027 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4028 end;
4029 if gSpectMode = SPECT_MAPVIEW then
4030 begin
4031 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4032 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4033 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4034 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4035 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4036 end;
4037 if gSpectMode = SPECT_PLAYERS then
4038 begin
4039 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4040 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4041 if gSpectViewTwo then
4042 begin
4043 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4044 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4045 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4046 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4047 end
4048 else
4049 begin
4050 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4051 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4052 end;
4053 end;
4054 end;
4055 end;
4057 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4058 begin
4059 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4060 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4062 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4063 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4064 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4065 end;
4067 if not gGameOn then
4068 begin
4069 if (gState = STATE_MENU) then
4070 begin
4071 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4072 // F3 at menu will show game loading dialog
4073 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4074 if (g_ActiveWindow <> nil) then
4075 begin
4076 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4077 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4078 end
4079 else
4080 begin
4081 // F3 at titlepic will show game loading dialog
4082 if e_KeyPressed(IK_F3) then
4083 begin
4084 g_Menu_Show_LoadMenu(true);
4085 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4086 end;
4087 end;
4088 end;
4090 if gState = STATE_FOLD then
4091 begin
4092 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4093 end;
4095 if gState = STATE_INTERCUSTOM then
4096 begin
4097 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4098 begin
4099 back := 'TEXTURE_endpic';
4100 if not g_Texture_Get(back, ID) then
4101 back := _lc[I_TEXTURE_ENDPIC];
4102 end
4103 else
4104 back := 'INTER';
4106 DrawMenuBackground(back);
4108 DrawCustomStat();
4110 if g_ActiveWindow <> nil then
4111 begin
4112 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4113 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4114 end;
4115 end;
4117 if gState = STATE_INTERSINGLE then
4118 begin
4119 if EndingGameCounter > 0 then
4120 begin
4121 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4122 end
4123 else
4124 begin
4125 back := 'INTER';
4127 DrawMenuBackground(back);
4129 DrawSingleStat();
4131 if g_ActiveWindow <> nil then
4132 begin
4133 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4134 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4135 end;
4136 end;
4137 end;
4139 if gState = STATE_ENDPIC then
4140 begin
4141 ID := DWORD(-1);
4142 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4143 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4145 if g_ActiveWindow <> nil then
4146 begin
4147 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4148 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4149 end;
4150 end;
4152 if gState = STATE_SLIST then
4153 begin
4154 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4155 // begin
4156 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4157 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4158 // end;
4159 DrawMenuBackground('MENU_BACKGROUND');
4160 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4161 g_Serverlist_Draw(slCurrent, slTable);
4162 end;
4163 end;
4165 if g_ActiveWindow <> nil then
4166 begin
4167 if gGameOn then
4168 begin
4169 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4170 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4171 end;
4172 g_ActiveWindow.Draw();
4173 end;
4175 {$IFNDEF HEADLESS}
4176 g_Console_Draw();
4177 {$ENDIF}
4179 if g_debug_Sounds and gGameOn then
4180 begin
4181 for w := 0 to High(e_SoundsArray) do
4182 for h := 0 to e_SoundsArray[w].nRefs do
4183 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4184 end;
4186 if gShowFPS then
4187 begin
4188 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4189 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4190 end;
4192 if gGameOn and gShowTime then
4193 drawTime(gScreenWidth-72, gScreenHeight-16);
4195 if gGameOn then drawProfilers();
4197 // TODO: draw this after the FBO and remap mouse click coordinates
4199 {$IFDEF ENABLE_HOLMES}
4200 g_Holmes_DrawUI();
4201 {$ENDIF}
4203 // blit framebuffer to screen
4205 e_SetRendertarget(False);
4206 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4207 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4209 // draw the overlay stuff on top of it
4211 g_Touch_Draw;
4212 end;
4214 procedure g_Game_Quit();
4215 begin
4216 g_Game_StopAllSounds(True);
4217 gMusic.Free();
4218 g_Game_FreeData();
4219 g_PlayerModel_FreeData();
4220 g_Texture_DeleteAll();
4221 g_Frames_DeleteAll();
4222 {$IFNDEF HEADLESS}
4223 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4224 {$ENDIF}
4226 if NetInitDone then g_Net_Free;
4228 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4229 if gMapToDelete <> '' then
4230 g_Game_DeleteTestMap();
4232 gExit := EXIT_QUIT;
4233 sys_RequestQuit;
4234 end;
4236 procedure g_FatalError(Text: String);
4237 begin
4238 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4239 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4241 gExit := EXIT_SIMPLE;
4242 if gGameOn then EndGame;
4243 end;
4245 procedure g_SimpleError(Text: String);
4246 begin
4247 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4248 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4249 end;
4251 procedure g_Game_SetupScreenSize();
4252 const
4253 RES_FACTOR = 4.0 / 3.0;
4254 var
4255 s: Single;
4256 rf: Single;
4257 bw, bh: Word;
4258 begin
4259 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4260 gPlayerScreenSize.X := gScreenWidth-196;
4261 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4262 gPlayerScreenSize.Y := gScreenHeight div 2
4263 else
4264 gPlayerScreenSize.Y := gScreenHeight;
4266 // Ðàçìåð çàäíåãî ïëàíà:
4267 if BackID <> DWORD(-1) then
4268 begin
4269 s := SKY_STRETCH;
4270 if (gScreenWidth*s > gMapInfo.Width) or
4271 (gScreenHeight*s > gMapInfo.Height) then
4272 begin
4273 gBackSize.X := gScreenWidth;
4274 gBackSize.Y := gScreenHeight;
4275 end
4276 else
4277 begin
4278 e_GetTextureSize(BackID, @bw, @bh);
4279 rf := Single(bw) / Single(bh);
4280 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4281 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4282 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4283 if (s < 1.0) then s := 1.0;
4284 gBackSize.X := Round(bw*s);
4285 gBackSize.Y := Round(bh*s);
4286 end;
4287 end;
4288 end;
4290 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4291 begin
4292 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4293 end;
4295 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4296 begin
4297 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4298 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4299 Exit;
4301 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4302 Exit;
4304 if gPlayer1 = nil then
4305 begin
4306 if g_Game_IsClient then
4307 begin
4308 if NetPlrUID1 > -1 then
4309 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4310 Exit;
4311 end;
4313 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4314 Team := gPlayer1Settings.Team;
4316 // Ñîçäàíèå ïåðâîãî èãðîêà:
4317 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4318 gPlayer1Settings.Color,
4319 Team, False));
4320 if gPlayer1 = nil then
4321 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4322 else
4323 begin
4324 gPlayer1.Name := gPlayer1Settings.Name;
4325 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4326 if g_Game_IsServer and g_Game_IsNet then
4327 MH_SEND_PlayerCreate(gPlayer1.UID);
4328 gPlayer1.Respawn(False, True);
4329 g_Net_Slist_ServerPlayerComes();
4330 end;
4332 Exit;
4333 end;
4334 if gPlayer2 = nil then
4335 begin
4336 if g_Game_IsClient then
4337 begin
4338 if NetPlrUID2 > -1 then
4339 gPlayer2 := g_Player_Get(NetPlrUID2);
4340 Exit;
4341 end;
4343 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4344 Team := gPlayer2Settings.Team;
4346 // Ñîçäàíèå âòîðîãî èãðîêà:
4347 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4348 gPlayer2Settings.Color,
4349 Team, False));
4350 if gPlayer2 = nil then
4351 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4352 else
4353 begin
4354 gPlayer2.Name := gPlayer2Settings.Name;
4355 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4356 if g_Game_IsServer and g_Game_IsNet then
4357 MH_SEND_PlayerCreate(gPlayer2.UID);
4358 gPlayer2.Respawn(False, True);
4359 g_Net_Slist_ServerPlayerComes();
4360 end;
4362 Exit;
4363 end;
4364 end;
4366 procedure g_Game_RemovePlayer();
4367 var
4368 Pl: TPlayer;
4369 begin
4370 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4371 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4372 Exit;
4373 Pl := gPlayer2;
4374 if Pl <> nil then
4375 begin
4376 if g_Game_IsServer then
4377 begin
4378 Pl.Lives := 0;
4379 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4380 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4381 g_Player_Remove(Pl.UID);
4382 g_Net_Slist_ServerPlayerLeaves();
4383 end
4384 else
4385 begin
4386 gSpectLatchPID2 := Pl.UID;
4387 gPlayer2 := nil;
4388 end;
4389 Exit;
4390 end;
4391 Pl := gPlayer1;
4392 if Pl <> nil then
4393 begin
4394 if g_Game_IsServer then
4395 begin
4396 Pl.Lives := 0;
4397 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4398 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4399 g_Player_Remove(Pl.UID);
4400 g_Net_Slist_ServerPlayerLeaves();
4401 end else
4402 begin
4403 gSpectLatchPID1 := Pl.UID;
4404 gPlayer1 := nil;
4405 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4406 end;
4407 Exit;
4408 end;
4409 g_Net_Slist_ServerPlayerLeaves();
4410 end;
4412 procedure g_Game_Spectate();
4413 begin
4414 g_Game_RemovePlayer();
4415 if gPlayer1 <> nil then
4416 g_Game_RemovePlayer();
4417 end;
4419 procedure g_Game_SpectateCenterView();
4420 begin
4421 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4422 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4423 end;
4425 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4426 var
4427 i, nPl: Integer;
4428 tmps: AnsiString;
4429 begin
4430 g_Game_Free();
4432 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4434 g_Game_ClearLoading();
4436 // Íàñòðîéêè èãðû:
4437 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4438 gAimLine := False;
4439 gShowMap := False;
4440 gGameSettings.GameType := GT_SINGLE;
4441 gGameSettings.MaxLives := 0;
4442 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4443 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4444 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4445 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
4446 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
4447 gSwitchGameMode := GM_SINGLE;
4449 gLMSRespawn := LMS_RESPAWN_NONE;
4450 gLMSRespawnTime := 0;
4451 gSpectLatchPID1 := 0;
4452 gSpectLatchPID2 := 0;
4454 g_Game_ExecuteEvent('ongamestart');
4456 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4457 g_Game_SetupScreenSize();
4459 // Ñîçäàíèå ïåðâîãî èãðîêà:
4460 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4461 gPlayer1Settings.Color,
4462 gPlayer1Settings.Team, False));
4463 if gPlayer1 = nil then
4464 begin
4465 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4466 Exit;
4467 end;
4469 gPlayer1.Name := gPlayer1Settings.Name;
4470 nPl := 1;
4472 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4473 if TwoPlayers then
4474 begin
4475 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4476 gPlayer2Settings.Color,
4477 gPlayer2Settings.Team, False));
4478 if gPlayer2 = nil then
4479 begin
4480 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4481 Exit;
4482 end;
4484 gPlayer2.Name := gPlayer2Settings.Name;
4485 Inc(nPl);
4486 end;
4488 // Çàãðóçêà è çàïóñê êàðòû:
4489 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4490 begin
4491 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4492 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4493 Exit;
4494 end;
4496 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4497 g_Player_Init();
4499 // Ñîçäàåì áîòîâ:
4500 for i := nPl+1 to nPlayers do
4501 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4502 end;
4504 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4505 TimeLimit, GoalLimit: Word;
4506 MaxLives: Byte;
4507 Options: LongWord; nPlayers: Byte);
4508 var
4509 i, nPl: Integer;
4510 begin
4511 g_Game_Free();
4513 e_WriteLog('Starting custom game...', TMsgType.Notify);
4515 g_Game_ClearLoading();
4517 // Íàñòðîéêè èãðû:
4518 gGameSettings.GameType := GT_CUSTOM;
4519 gGameSettings.GameMode := GameMode;
4520 gSwitchGameMode := GameMode;
4521 gGameSettings.TimeLimit := TimeLimit;
4522 gGameSettings.GoalLimit := GoalLimit;
4523 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4524 gGameSettings.Options := Options;
4526 gCoopTotalMonstersKilled := 0;
4527 gCoopTotalSecretsFound := 0;
4528 gCoopTotalMonsters := 0;
4529 gCoopTotalSecrets := 0;
4530 gAimLine := False;
4531 gShowMap := False;
4533 gLMSRespawn := LMS_RESPAWN_NONE;
4534 gLMSRespawnTime := 0;
4535 gSpectLatchPID1 := 0;
4536 gSpectLatchPID2 := 0;
4538 g_Game_ExecuteEvent('ongamestart');
4540 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4541 g_Game_SetupScreenSize();
4543 // Ðåæèì íàáëþäàòåëÿ:
4544 if nPlayers = 0 then
4545 begin
4546 gPlayer1 := nil;
4547 gPlayer2 := nil;
4548 end;
4550 nPl := 0;
4551 if nPlayers >= 1 then
4552 begin
4553 // Ñîçäàíèå ïåðâîãî èãðîêà:
4554 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4555 gPlayer1Settings.Color,
4556 gPlayer1Settings.Team, False));
4557 if gPlayer1 = nil then
4558 begin
4559 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4560 Exit;
4561 end;
4563 gPlayer1.Name := gPlayer1Settings.Name;
4564 Inc(nPl);
4565 end;
4567 if nPlayers >= 2 then
4568 begin
4569 // Ñîçäàíèå âòîðîãî èãðîêà:
4570 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4571 gPlayer2Settings.Color,
4572 gPlayer2Settings.Team, False));
4573 if gPlayer2 = nil then
4574 begin
4575 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4576 Exit;
4577 end;
4579 gPlayer2.Name := gPlayer2Settings.Name;
4580 Inc(nPl);
4581 end;
4583 // Çàãðóçêà è çàïóñê êàðòû:
4584 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4585 begin
4586 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4587 Exit;
4588 end;
4590 // Íåò òî÷åê ïîÿâëåíèÿ:
4591 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4592 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4593 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4594 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4595 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4596 begin
4597 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4598 Exit;
4599 end;
4601 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4602 g_Player_Init();
4604 // Ñîçäàåì áîòîâ:
4605 for i := nPl+1 to nPlayers do
4606 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4607 end;
4609 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4610 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4611 Options: LongWord; nPlayers: Byte;
4612 IPAddr: LongWord; Port: Word);
4613 begin
4614 g_Game_Free();
4615 g_Net_Slist_ServerClosed();
4617 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4619 g_Game_ClearLoading();
4621 // Íàñòðîéêè èãðû:
4622 gGameSettings.GameType := GT_SERVER;
4623 gGameSettings.GameMode := GameMode;
4624 gSwitchGameMode := GameMode;
4625 gGameSettings.TimeLimit := TimeLimit;
4626 gGameSettings.GoalLimit := GoalLimit;
4627 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4628 gGameSettings.Options := Options;
4630 gCoopTotalMonstersKilled := 0;
4631 gCoopTotalSecretsFound := 0;
4632 gCoopTotalMonsters := 0;
4633 gCoopTotalSecrets := 0;
4634 gAimLine := False;
4635 gShowMap := False;
4637 gLMSRespawn := LMS_RESPAWN_NONE;
4638 gLMSRespawnTime := 0;
4639 gSpectLatchPID1 := 0;
4640 gSpectLatchPID2 := 0;
4642 g_Game_ExecuteEvent('ongamestart');
4644 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4645 g_Game_SetupScreenSize();
4647 // Ðåæèì íàáëþäàòåëÿ:
4648 if nPlayers = 0 then
4649 begin
4650 gPlayer1 := nil;
4651 gPlayer2 := nil;
4652 end;
4654 if nPlayers >= 1 then
4655 begin
4656 // Ñîçäàíèå ïåðâîãî èãðîêà:
4657 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4658 gPlayer1Settings.Color,
4659 gPlayer1Settings.Team, False));
4660 if gPlayer1 = nil then
4661 begin
4662 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4663 Exit;
4664 end;
4666 gPlayer1.Name := gPlayer1Settings.Name;
4667 end;
4669 if nPlayers >= 2 then
4670 begin
4671 // Ñîçäàíèå âòîðîãî èãðîêà:
4672 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4673 gPlayer2Settings.Color,
4674 gPlayer2Settings.Team, False));
4675 if gPlayer2 = nil then
4676 begin
4677 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4678 Exit;
4679 end;
4681 gPlayer2.Name := gPlayer2Settings.Name;
4682 end;
4684 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4685 if NetForwardPorts then
4686 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4688 // Ñòàðòóåì ñåðâåð
4689 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4690 begin
4691 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4692 Exit;
4693 end;
4695 g_Net_Slist_Set(NetMasterList);
4697 g_Net_Slist_ServerStarted();
4699 // Çàãðóçêà è çàïóñê êàðòû:
4700 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4701 begin
4702 g_Net_Slist_ServerClosed();
4703 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4704 Exit;
4705 end;
4707 // Íåò òî÷åê ïîÿâëåíèÿ:
4708 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4709 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4710 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4711 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4712 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4713 begin
4714 g_Net_Slist_ServerClosed();
4715 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4716 Exit;
4717 end;
4719 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4720 g_Player_Init();
4722 g_Net_Slist_ServerMapStarted();
4723 NetState := NET_STATE_GAME;
4724 end;
4726 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4727 var
4728 Map: String;
4729 WadName: string;
4730 Ptr: Pointer;
4731 T: Cardinal;
4732 MID: Byte;
4733 State: Byte;
4734 OuterLoop: Boolean;
4735 newResPath: string;
4736 InMsg: TMsg;
4737 begin
4738 g_Game_Free();
4740 State := 0;
4741 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4742 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4744 g_Game_ClearLoading();
4746 // Íàñòðîéêè èãðû:
4747 gGameSettings.GameType := GT_CLIENT;
4749 gCoopTotalMonstersKilled := 0;
4750 gCoopTotalSecretsFound := 0;
4751 gCoopTotalMonsters := 0;
4752 gCoopTotalSecrets := 0;
4753 gAimLine := False;
4754 gShowMap := False;
4756 g_Game_ExecuteEvent('ongamestart');
4758 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4759 g_Game_SetupScreenSize();
4761 NetState := NET_STATE_AUTH;
4763 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4765 // create (or update) map/resource databases
4766 g_Res_CreateDatabases(true);
4768 gLMSRespawn := LMS_RESPAWN_NONE;
4769 gLMSRespawnTime := 0;
4770 gSpectLatchPID1 := 0;
4771 gSpectLatchPID2 := 0;
4773 // Ñòàðòóåì êëèåíò
4774 if not g_Net_Connect(Addr, Port) then
4775 begin
4776 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4777 NetState := NET_STATE_NONE;
4778 Exit;
4779 end;
4781 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4782 MC_SEND_Info(PW);
4783 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4785 OuterLoop := True;
4786 while OuterLoop do
4787 begin
4788 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4789 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4790 // thank you, enet. let's ignore failures altogether then.
4791 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4792 begin
4793 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4794 begin
4795 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
4796 begin
4797 // ignore all download packets, they're processed by separate code
4798 enet_packet_destroy(NetEvent.packet);
4799 continue;
4800 end;
4801 Ptr := NetEvent.packet^.data;
4802 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4803 begin
4804 enet_packet_destroy(NetEvent.packet);
4805 continue;
4806 end;
4808 InMsg.ReadLongWord(); // skip size
4809 MID := InMsg.ReadByte();
4811 if (MID = NET_MSG_INFO) and (State = 0) then
4812 begin
4813 NetMyID := InMsg.ReadByte();
4814 NetPlrUID1 := InMsg.ReadWord();
4816 WadName := InMsg.ReadString();
4817 Map := InMsg.ReadString();
4819 gWADHash := InMsg.ReadMD5();
4821 gGameSettings.GameMode := InMsg.ReadByte();
4822 gSwitchGameMode := gGameSettings.GameMode;
4823 gGameSettings.GoalLimit := InMsg.ReadWord();
4824 gGameSettings.TimeLimit := InMsg.ReadWord();
4825 gGameSettings.MaxLives := InMsg.ReadByte();
4826 gGameSettings.Options := InMsg.ReadLongWord();
4827 T := InMsg.ReadLongWord();
4829 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4830 //if newResPath = '' then
4831 begin
4832 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4833 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4834 if newResPath = '' then
4835 begin
4836 g_FatalError(_lc[I_NET_ERR_HASH]);
4837 enet_packet_destroy(NetEvent.packet);
4838 NetState := NET_STATE_NONE;
4839 Exit;
4840 end;
4841 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4842 end;
4843 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4846 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4847 gPlayer1Settings.Color,
4848 gPlayer1Settings.Team, False));
4850 if gPlayer1 = nil then
4851 begin
4852 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4854 enet_packet_destroy(NetEvent.packet);
4855 NetState := NET_STATE_NONE;
4856 Exit;
4857 end;
4859 gPlayer1.Name := gPlayer1Settings.Name;
4860 gPlayer1.UID := NetPlrUID1;
4861 gPlayer1.Reset(True);
4863 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4864 begin
4865 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4867 enet_packet_destroy(NetEvent.packet);
4868 NetState := NET_STATE_NONE;
4869 Exit;
4870 end;
4872 gTime := T;
4874 State := 1;
4875 OuterLoop := False;
4876 enet_packet_destroy(NetEvent.packet);
4877 break;
4878 end
4879 else
4880 enet_packet_destroy(NetEvent.packet);
4881 end
4882 else
4883 begin
4884 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4885 begin
4886 State := 0;
4887 if (NetEvent.data <= NET_DISC_MAX) then
4888 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4889 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4890 OuterLoop := False;
4891 Break;
4892 end;
4893 end;
4894 end;
4896 ProcessLoading(true);
4898 if g_Net_UserRequestExit() then
4899 begin
4900 State := 0;
4901 break;
4902 end;
4903 end;
4905 if State <> 1 then
4906 begin
4907 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4908 NetState := NET_STATE_NONE;
4909 Exit;
4910 end;
4912 g_Player_Init();
4913 NetState := NET_STATE_GAME;
4914 MC_SEND_FullStateRequest;
4915 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4916 end;
4918 var
4919 lastAsMegaWad: Boolean = false;
4921 procedure g_Game_ChangeMap(const MapPath: String);
4922 var
4923 Force: Boolean;
4924 begin
4925 g_Game_ClearLoading();
4927 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4928 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4929 if gExitByTrigger then
4930 begin
4931 Force := False;
4932 gExitByTrigger := False;
4933 end;
4934 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
4935 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4936 end;
4938 procedure g_Game_Restart();
4939 var
4940 Map: string;
4941 begin
4942 if g_Game_IsClient then
4943 Exit;
4944 map := g_ExtractFileName(gMapInfo.Map);
4945 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
4947 MessageTime := 0;
4948 gGameOn := False;
4949 g_Game_ClearLoading();
4950 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
4951 end;
4953 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4954 var
4955 NewWAD, ResName: String;
4956 I: Integer;
4957 nws: AnsiString;
4958 begin
4959 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4960 g_Player_RemoveAllCorpses();
4962 if (not g_Game_IsClient) and
4963 (gSwitchGameMode <> gGameSettings.GameMode) and
4964 (gGameSettings.GameMode <> GM_SINGLE) then
4965 begin
4966 if gSwitchGameMode = GM_CTF then
4967 gGameSettings.MaxLives := 0;
4968 gGameSettings.GameMode := gSwitchGameMode;
4969 Force := True;
4970 end else
4971 gSwitchGameMode := gGameSettings.GameMode;
4973 g_Player_ResetTeams();
4975 lastAsMegaWad := asMegawad;
4976 if isWadPath(Map) then
4977 begin
4978 NewWAD := g_ExtractWadName(Map);
4979 ResName := g_ExtractFileName(Map);
4980 if g_Game_IsServer then
4981 begin
4982 nws := findDiskWad(NewWAD);
4983 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4984 if (asMegawad) then
4985 begin
4986 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4987 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4988 end
4989 else
4990 begin
4991 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4992 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4993 end;
4994 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4995 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4996 //nws := NewWAD;
4997 if (length(nws) = 0) then
4998 begin
4999 ResName := ''; // failed
5000 end
5001 else
5002 begin
5003 NewWAD := nws;
5004 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5005 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5006 g_Game_LoadWAD(NewWAD);
5007 end;
5008 end
5009 else
5010 begin
5011 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5012 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5013 end;
5014 end
5015 else
5016 begin
5017 NewWAD := gGameSettings.WAD;
5018 ResName := Map;
5019 end;
5021 gTime := 0;
5023 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5024 result := false;
5025 if (ResName <> '') and (NewWAD <> '') then
5026 begin
5027 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5028 result := g_Map_Load(NewWAD+':\'+ResName);
5029 end;
5030 if Result then
5031 begin
5032 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5034 gState := STATE_NONE;
5035 g_ActiveWindow := nil;
5036 gGameOn := True;
5038 DisableCheats();
5039 ResetTimer();
5041 if gGameSettings.GameMode = GM_CTF then
5042 begin
5043 g_Map_ResetFlag(FLAG_RED);
5044 g_Map_ResetFlag(FLAG_BLUE);
5045 // CTF, à ôëàãîâ íåò:
5046 if not g_Map_HaveFlagPoints() then
5047 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5048 end;
5049 end
5050 else
5051 begin
5052 gState := STATE_MENU;
5053 gGameOn := False;
5054 end;
5056 gExit := 0;
5057 gPauseMain := false;
5058 gPauseHolmes := false;
5059 NetTimeToUpdate := 1;
5060 NetTimeToReliable := 0;
5061 NetTimeToMaster := NetMasterRate;
5062 gSpectLatchPID1 := 0;
5063 gSpectLatchPID2 := 0;
5064 gMissionFailed := False;
5065 gNextMap := '';
5067 gCoopMonstersKilled := 0;
5068 gCoopSecretsFound := 0;
5070 gVoteInProgress := False;
5071 gVotePassed := False;
5072 gVoteCount := 0;
5073 gVoted := False;
5075 gStatsOff := False;
5077 if not gGameOn then Exit;
5079 g_Game_SpectateCenterView();
5081 if g_Game_IsServer then
5082 begin
5083 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5084 begin
5085 gLMSRespawn := LMS_RESPAWN_WARMUP;
5086 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5087 gLMSSoftSpawn := True;
5088 if g_Game_IsNet then
5089 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5090 end
5091 else
5092 begin
5093 gLMSRespawn := LMS_RESPAWN_NONE;
5094 gLMSRespawnTime := 0;
5095 end;
5096 end;
5098 if NetMode = NET_SERVER then
5099 begin
5100 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5102 // Ìàñòåðñåðâåð
5103 g_Net_Slist_ServerMapStarted();
5105 if NetClients <> nil then
5106 for I := 0 to High(NetClients) do
5107 if NetClients[I].Used then
5108 begin
5109 NetClients[I].Voted := False;
5110 if NetClients[I].RequestedFullUpdate then
5111 begin
5112 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5113 NetClients[I].RequestedFullUpdate := False;
5114 end;
5115 end;
5117 g_Net_UnbanNonPermHosts();
5118 end;
5120 if gLastMap then
5121 begin
5122 gCoopTotalMonstersKilled := 0;
5123 gCoopTotalSecretsFound := 0;
5124 gCoopTotalMonsters := 0;
5125 gCoopTotalSecrets := 0;
5126 gLastMap := False;
5127 end;
5129 g_Game_ExecuteEvent('onmapstart');
5130 end;
5132 procedure SetFirstLevel;
5133 begin
5134 gNextMap := '';
5136 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5137 if MapList = nil then
5138 Exit;
5140 SortSArray(MapList);
5141 gNextMap := MapList[Low(MapList)];
5143 MapList := nil;
5144 end;
5146 procedure g_Game_ExitLevel(const Map: AnsiString);
5147 begin
5148 gNextMap := Map;
5150 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5151 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5152 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5153 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5155 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5156 if gGameSettings.GameType = GT_SINGLE then
5157 gExit := EXIT_ENDLEVELSINGLE
5158 else // Âûøëè â âûõîä â Ñâîåé èãðå
5159 begin
5160 gExit := EXIT_ENDLEVELCUSTOM;
5161 if gGameSettings.GameMode = GM_COOP then
5162 g_Player_RememberAll;
5164 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5165 begin
5166 gLastMap := True;
5167 if gGameSettings.GameMode = GM_COOP then
5168 gStatsOff := True;
5170 gStatsPressed := True;
5171 gNextMap := 'MAP01';
5173 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5174 g_Game_NextLevel;
5176 if g_Game_IsNet then
5177 begin
5178 MH_SEND_GameStats();
5179 MH_SEND_CoopStats();
5180 end;
5181 end;
5182 end;
5183 end;
5185 procedure g_Game_RestartLevel();
5186 var
5187 Map: string;
5188 begin
5189 if gGameSettings.GameMode = GM_SINGLE then
5190 begin
5191 g_Game_Restart();
5192 Exit;
5193 end;
5194 gExit := EXIT_ENDLEVELCUSTOM;
5195 Map := g_ExtractFileName(gMapInfo.Map);
5196 gNextMap := Map;
5197 end;
5199 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5200 var
5201 gWAD{, xwad}: String;
5202 begin
5203 result := NewWAD;
5204 if not g_Game_IsClient then Exit;
5205 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5207 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5208 if gWAD = '' then
5209 begin
5210 result := '';
5211 g_Game_Free();
5212 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5213 Exit;
5214 end;
5216 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5217 NewWAD := gWAD;
5219 g_Game_LoadWAD(NewWAD);
5220 result := NewWAD;
5223 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5224 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5225 if gWAD = '' then
5226 begin
5227 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5228 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5229 if gWAD = '' then
5230 begin
5231 g_Game_Free();
5232 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5233 Exit;
5234 end;
5235 end;
5236 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5237 g_Game_LoadWAD(NewWAD);
5239 end;
5241 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5242 var
5243 i, n, nb, nr: Integer;
5244 begin
5245 if not g_Game_IsServer then Exit;
5246 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5247 gLMSRespawn := LMS_RESPAWN_NONE;
5248 gLMSRespawnTime := 0;
5249 MessageTime := 0;
5251 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5252 begin
5253 gMissionFailed := True;
5254 g_Game_RestartLevel;
5255 Exit;
5256 end;
5258 n := 0; nb := 0; nr := 0;
5259 for i := Low(gPlayers) to High(gPlayers) do
5260 if (gPlayers[i] <> nil) and
5261 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5262 (gPlayers[i] is TBot)) then
5263 begin
5264 Inc(n);
5265 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5266 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5267 end;
5269 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5270 begin
5271 // wait a second until the fuckers finally decide to join
5272 gLMSRespawn := LMS_RESPAWN_WARMUP;
5273 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5274 gLMSSoftSpawn := NoMapRestart;
5275 if g_Game_IsNet then
5276 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5277 Exit;
5278 end;
5280 g_Player_RemoveAllCorpses;
5281 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5282 if g_Game_IsNet then
5283 MH_SEND_GameEvent(NET_EV_LMS_START);
5285 for i := Low(gPlayers) to High(gPlayers) do
5286 begin
5287 if gPlayers[i] = nil then continue;
5288 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5289 // don't touch normal spectators
5290 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5291 begin
5292 gPlayers[i].FNoRespawn := True;
5293 gPlayers[i].Lives := 0;
5294 if g_Game_IsNet then
5295 MH_SEND_PlayerStats(gPlayers[I].UID);
5296 continue;
5297 end;
5298 gPlayers[i].FNoRespawn := False;
5299 gPlayers[i].Lives := gGameSettings.MaxLives;
5300 gPlayers[i].Respawn(False, True);
5301 if gGameSettings.GameMode = GM_COOP then
5302 begin
5303 gPlayers[i].Frags := 0;
5304 gPlayers[i].RecallState;
5305 end;
5306 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5307 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5308 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5309 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5310 end;
5312 g_Items_RestartRound();
5314 gLMSSoftSpawn := False;
5315 end;
5317 function g_Game_GetFirstMap(WAD: String): String;
5318 begin
5319 Result := '';
5321 MapList := g_Map_GetMapsList(WAD);
5322 if MapList = nil then
5323 Exit;
5325 SortSArray(MapList);
5326 Result := MapList[Low(MapList)];
5328 if not g_Map_Exist(WAD + ':\' + Result) then
5329 Result := '';
5331 MapList := nil;
5332 end;
5334 function g_Game_GetNextMap(): String;
5335 var
5336 I: Integer;
5337 Map: string;
5338 begin
5339 Result := '';
5341 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5342 if MapList = nil then
5343 Exit;
5345 Map := g_ExtractFileName(gMapInfo.Map);
5347 SortSArray(MapList);
5348 MapIndex := -255;
5349 for I := Low(MapList) to High(MapList) do
5350 if Map = MapList[I] then
5351 begin
5352 MapIndex := I;
5353 Break;
5354 end;
5356 if MapIndex <> -255 then
5357 begin
5358 if MapIndex = High(MapList) then
5359 Result := MapList[Low(MapList)]
5360 else
5361 Result := MapList[MapIndex + 1];
5363 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5364 end;
5366 MapList := nil;
5367 end;
5369 procedure g_Game_NextLevel();
5370 begin
5371 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5372 gExit := EXIT_ENDLEVELCUSTOM
5373 else
5374 begin
5375 gExit := EXIT_ENDLEVELSINGLE;
5376 Exit;
5377 end;
5379 if gNextMap <> '' then Exit;
5380 gNextMap := g_Game_GetNextMap();
5381 end;
5383 function g_Game_IsTestMap(): Boolean;
5384 begin
5385 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5386 end;
5388 procedure g_Game_DeleteTestMap();
5389 var
5390 a: Integer;
5391 //MapName: AnsiString;
5392 WadName: string;
5394 WAD: TWADFile;
5395 MapList: SSArray;
5396 time: Integer;
5398 begin
5399 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5400 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5401 if (a = 0) then exit;
5403 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5404 WadName := Copy(gMapToDelete, 1, a+3);
5405 Delete(gMapToDelete, 1, a+5);
5406 gMapToDelete := UpperCase(gMapToDelete);
5407 //MapName := '';
5408 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5411 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5412 if MapName <> TEST_MAP_NAME then
5413 Exit;
5415 if not gTempDelete then
5416 begin
5417 time := g_GetFileTime(WadName);
5418 WAD := TWADFile.Create();
5420 // ×èòàåì Wad-ôàéë:
5421 if not WAD.ReadFile(WadName) then
5422 begin // Íåò òàêîãî WAD-ôàéëà
5423 WAD.Free();
5424 Exit;
5425 end;
5427 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5428 WAD.CreateImage();
5429 MapList := WAD.GetResourcesList('');
5431 if MapList <> nil then
5432 for a := 0 to High(MapList) do
5433 if MapList[a] = MapName then
5434 begin
5435 // Óäàëÿåì è ñîõðàíÿåì:
5436 WAD.RemoveResource('', MapName);
5437 WAD.SaveTo(WadName);
5438 Break;
5439 end;
5441 WAD.Free();
5442 g_SetFileTime(WadName, time);
5443 end else
5445 if gTempDelete then DeleteFile(WadName);
5446 end;
5448 procedure GameCVars(P: SSArray);
5449 var
5450 a, b: Integer;
5451 stat: TPlayerStatArray;
5452 cmd: string;
5454 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5455 var
5456 x: Boolean;
5457 begin
5458 if Length(P) > 1 then
5459 begin
5460 x := P[1] = '1';
5462 if x then
5463 gsGameFlags := gsGameFlags or Flag
5464 else
5465 gsGameFlags := gsGameFlags and (not Flag);
5467 if g_Game_IsServer then
5468 begin
5469 if x then
5470 gGameSettings.Options := gGameSettings.Options or Flag
5471 else
5472 gGameSettings.Options := gGameSettings.Options and (not Flag);
5473 if g_Game_IsNet then MH_SEND_GameSettings;
5474 end;
5475 end;
5477 if LongBool(gsGameFlags and Flag) then
5478 g_Console_Add(_lc[OnMsg])
5479 else
5480 g_Console_Add(_lc[OffMsg]);
5482 if OnMapChange and g_Game_IsServer then
5483 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5484 end;
5486 begin
5487 stat := nil;
5488 cmd := LowerCase(P[0]);
5490 if cmd = 'g_gamemode' then
5491 begin
5492 if (Length(P) > 1) then
5493 begin
5494 a := g_Game_TextToMode(P[1]);
5495 if a = GM_SINGLE then a := GM_COOP;
5496 gsGameMode := g_Game_ModeToText(a);
5497 if g_Game_IsServer then
5498 begin
5499 gSwitchGameMode := a;
5500 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5501 (gState = STATE_INTERSINGLE) then
5502 gSwitchGameMode := GM_SINGLE;
5503 if not gGameOn then
5504 gGameSettings.GameMode := gSwitchGameMode;
5505 end;
5506 end;
5508 if gSwitchGameMode = gGameSettings.GameMode then
5509 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5510 [g_Game_ModeToText(gGameSettings.GameMode)]))
5511 else
5512 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5513 [g_Game_ModeToText(gGameSettings.GameMode),
5514 g_Game_ModeToText(gSwitchGameMode)]));
5515 end
5516 else if cmd = 'g_friendlyfire' then
5517 begin
5518 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5519 end
5520 else if cmd = 'g_friendly_absorb_damage' then
5521 begin
5522 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5523 end
5524 else if cmd = 'g_friendly_hit_trace' then
5525 begin
5526 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5527 end
5528 else if cmd = 'g_friendly_hit_projectile' then
5529 begin
5530 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5531 end
5532 else if cmd = 'g_weaponstay' then
5533 begin
5534 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5535 end
5536 else if cmd = 'g_allow_exit' then
5537 begin
5538 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5539 end
5540 else if cmd = 'g_allow_monsters' then
5541 begin
5542 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5543 end
5544 else if cmd = 'g_bot_vsplayers' then
5545 begin
5546 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5547 end
5548 else if cmd = 'g_bot_vsmonsters' then
5549 begin
5550 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5551 end
5552 else if cmd = 'g_dm_keys' then
5553 begin
5554 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5555 end
5556 else if cmd = 'g_gameflags' then
5557 begin
5558 if Length(P) > 1 then
5559 begin
5560 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5561 if g_Game_IsServer then
5562 begin
5563 gGameSettings.Options := gsGameFlags;
5564 if g_Game_IsNet then MH_SEND_GameSettings;
5565 end;
5566 end;
5568 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5569 end
5570 else if cmd = 'g_warmup_time' then
5571 begin
5572 if Length(P) > 1 then
5573 begin
5574 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5575 if g_Game_IsServer then
5576 begin
5577 gGameSettings.WarmupTime := gsWarmupTime;
5578 // extend warmup if it's already going
5579 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5580 begin
5581 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5582 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5583 end;
5584 if g_Game_IsNet then MH_SEND_GameSettings;
5585 end;
5586 end;
5588 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5589 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5590 end
5591 else if cmd = 'g_spawn_invul' then
5592 begin
5593 if Length(P) > 1 then
5594 begin
5595 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5596 if g_Game_IsServer then
5597 begin
5598 gGameSettings.SpawnInvul := gsSpawnInvul;
5599 if g_Game_IsNet then MH_SEND_GameSettings;
5600 end;
5601 end;
5603 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5604 end
5605 else if cmd = 'g_item_respawn_time' then
5606 begin
5607 if Length(P) > 1 then
5608 begin
5609 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5610 if g_Game_IsServer then
5611 begin
5612 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5613 if g_Game_IsNet then MH_SEND_GameSettings;
5614 end;
5615 end;
5617 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5618 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5619 end
5620 else if cmd = 'sv_intertime' then
5621 begin
5622 if (Length(P) > 1) then
5623 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5625 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5626 end
5627 else if cmd = 'g_max_particles' then
5628 begin
5629 if Length(p) = 2 then
5630 begin
5631 a := Max(0, StrToInt(p[1]));
5632 g_GFX_SetMax(a)
5633 end
5634 else if Length(p) = 1 then
5635 begin
5636 e_LogWritefln('%s', [g_GFX_GetMax()])
5637 end
5638 else
5639 begin
5640 e_LogWritefln('usage: %s <n>', [cmd])
5641 end
5642 end
5643 else if cmd = 'g_max_shells' then
5644 begin
5645 if Length(p) = 2 then
5646 begin
5647 a := Max(0, StrToInt(p[1]));
5648 g_Shells_SetMax(a)
5649 end
5650 else if Length(p) = 1 then
5651 begin
5652 e_LogWritefln('%s', [g_Shells_GetMax()])
5653 end
5654 else
5655 begin
5656 e_LogWritefln('usage: %s <n>', [cmd])
5657 end
5658 end
5659 else if cmd = 'g_max_gibs' then
5660 begin
5661 if Length(p) = 2 then
5662 begin
5663 a := Max(0, StrToInt(p[1]));
5664 g_Gibs_SetMax(a)
5665 end
5666 else if Length(p) = 1 then
5667 begin
5668 e_LogWritefln('%s', [g_Gibs_GetMax()])
5669 end
5670 else
5671 begin
5672 e_LogWritefln('usage: %s <n>', [cmd])
5673 end
5674 end
5675 else if cmd = 'g_max_corpses' then
5676 begin
5677 if Length(p) = 2 then
5678 begin
5679 a := Max(0, StrToInt(p[1]));
5680 g_Corpses_SetMax(a)
5681 end
5682 else if Length(p) = 1 then
5683 begin
5684 e_LogWritefln('%s', [g_Corpses_GetMax()])
5685 end
5686 else
5687 begin
5688 e_LogWritefln('usage: %s <n>', [cmd])
5689 end
5690 end
5691 else if cmd = 'g_scorelimit' then
5692 begin
5693 if Length(P) > 1 then
5694 begin
5695 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
5697 if g_Game_IsServer then
5698 begin
5699 b := 0;
5700 if gGameSettings.GameMode = GM_DM then
5701 begin // DM
5702 stat := g_Player_GetStats();
5703 if stat <> nil then
5704 for a := 0 to High(stat) do
5705 if stat[a].Frags > b then
5706 b := stat[a].Frags;
5707 end
5708 else // TDM/CTF
5709 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5711 // if someone has a higher score, set it to that instead
5712 gsGoalLimit := max(gsGoalLimit, b);
5713 gGameSettings.GoalLimit := gsGoalLimit;
5715 if g_Game_IsNet then MH_SEND_GameSettings;
5716 end;
5717 end;
5719 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
5720 end
5721 else if cmd = 'g_timelimit' then
5722 begin
5723 if Length(P) > 1 then
5724 begin
5725 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5726 if g_Game_IsServer then
5727 begin
5728 gGameSettings.TimeLimit := gsTimeLimit;
5729 if g_Game_IsNet then MH_SEND_GameSettings;
5730 end;
5731 end;
5732 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5733 [gsTimeLimit div 3600,
5734 (gsTimeLimit div 60) mod 60,
5735 gsTimeLimit mod 60]));
5736 end
5737 else if cmd = 'g_maxlives' then
5738 begin
5739 if Length(P) > 1 then
5740 begin
5741 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5742 if g_Game_IsServer then
5743 begin
5744 gGameSettings.MaxLives := gsMaxLives;
5745 if g_Game_IsNet then MH_SEND_GameSettings;
5746 end;
5747 end;
5749 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5750 end;
5751 end;
5753 procedure PlayerSettingsCVars(P: SSArray);
5754 var
5755 cmd: string;
5756 team: Byte;
5758 function ParseTeam(s: string): Byte;
5759 begin
5760 result := 0;
5761 case s of
5762 'red', '1': result := TEAM_RED;
5763 'blue', '2': result := TEAM_BLUE;
5764 else result := TEAM_NONE;
5765 end;
5766 end;
5767 begin
5768 cmd := LowerCase(P[0]);
5769 case cmd of
5770 'p1_name':
5771 begin
5772 if (Length(P) > 1) then
5773 begin
5774 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5775 if g_Game_IsClient then
5776 MC_SEND_PlayerSettings
5777 else if gGameOn and (gPlayer1 <> nil) then
5778 begin
5779 gPlayer1.Name := b_Text_Unformat(P[1]);
5780 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5781 end;
5782 end;
5783 end;
5784 'p2_name':
5785 begin
5786 if (Length(P) > 1) then
5787 begin
5788 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5789 if g_Game_IsClient then
5790 MC_SEND_PlayerSettings
5791 else if gGameOn and (gPlayer2 <> nil) then
5792 begin
5793 gPlayer2.Name := b_Text_Unformat(P[1]);
5794 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5795 end;
5796 end;
5797 end;
5798 'p1_color':
5799 begin
5800 if Length(P) > 3 then
5801 begin
5802 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5803 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5804 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5805 if g_Game_IsClient then
5806 MC_SEND_PlayerSettings
5807 else if gGameOn and (gPlayer1 <> nil) then
5808 begin
5809 gPlayer1.SetColor(gPlayer1Settings.Color);
5810 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5811 end;
5812 end;
5813 end;
5814 'p2_color':
5815 begin
5816 if Length(P) > 3 then
5817 begin
5818 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5819 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5820 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5821 if g_Game_IsClient then
5822 MC_SEND_PlayerSettings
5823 else if gGameOn and (gPlayer2 <> nil) then
5824 begin
5825 gPlayer2.SetColor(gPlayer2Settings.Color);
5826 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5827 end;
5828 end;
5829 end;
5830 'p1_model':
5831 begin
5832 if (Length(P) > 1) then
5833 begin
5834 gPlayer1Settings.Model := P[1];
5835 if g_Game_IsClient then
5836 MC_SEND_PlayerSettings
5837 else if gGameOn and (gPlayer1 <> nil) then
5838 begin
5839 gPlayer1.FActualModelName := gPlayer1Settings.Model;
5840 gPlayer1.SetModel(gPlayer1Settings.Model);
5841 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5842 end;
5843 end;
5844 end;
5845 'p2_model':
5846 begin
5847 if (Length(P) > 1) then
5848 begin
5849 gPlayer2Settings.Model := P[1];
5850 if g_Game_IsClient then
5851 MC_SEND_PlayerSettings
5852 else if gGameOn and (gPlayer2 <> nil) then
5853 begin
5854 gPlayer2.FActualModelName := gPlayer2Settings.Model;
5855 gPlayer2.SetModel(gPlayer2Settings.Model);
5856 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5857 end;
5858 end;
5859 end;
5860 'p1_team':
5861 begin
5862 // TODO: switch teams if in game or store this separately
5863 if (Length(P) > 1) then
5864 begin
5865 team := ParseTeam(P[1]);
5866 if team = TEAM_NONE then
5867 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5868 else if not gGameOn and not g_Game_IsNet then
5869 gPlayer1Settings.Team := team
5870 else
5871 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5872 end;
5873 end;
5874 'p2_team':
5875 begin
5876 // TODO: switch teams if in game or store this separately
5877 if (Length(P) > 1) then
5878 begin
5879 team := ParseTeam(P[1]);
5880 if team = TEAM_NONE then
5881 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5882 else if not gGameOn and not g_Game_IsNet then
5883 gPlayer2Settings.Team := team
5884 else
5885 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5886 end;
5887 end;
5888 end;
5889 end;
5891 procedure PrintHeapStats();
5892 var
5893 hs: TFPCHeapStatus;
5894 begin
5895 hs := GetFPCHeapStatus();
5896 e_LogWriteLn ('v===== heap status =====v');
5897 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5898 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5899 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5900 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5901 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5902 e_LogWriteLn ('^=======================^');
5903 end;
5905 procedure DebugCommands(P: SSArray);
5906 var
5907 a, b: Integer;
5908 cmd: string;
5909 //pt: TDFPoint;
5910 mon: TMonster;
5911 begin
5912 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5913 if {gDebugMode}conIsCheatsEnabled then
5914 begin
5915 cmd := LowerCase(P[0]);
5916 if cmd = 'd_window' then
5917 begin
5918 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5919 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5920 end
5921 else if cmd = 'd_sounds' then
5922 begin
5923 if (Length(P) > 1) and
5924 ((P[1] = '1') or (P[1] = '0')) then
5925 g_Debug_Sounds := (P[1][1] = '1');
5927 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5928 end
5929 else if cmd = 'd_frames' then
5930 begin
5931 if (Length(P) > 1) and
5932 ((P[1] = '1') or (P[1] = '0')) then
5933 g_Debug_Frames := (P[1][1] = '1');
5935 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5936 end
5937 else if cmd = 'd_winmsg' then
5938 begin
5939 if (Length(P) > 1) and
5940 ((P[1] = '1') or (P[1] = '0')) then
5941 g_Debug_WinMsgs := (P[1][1] = '1');
5943 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5944 end
5945 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5946 begin
5947 if (Length(P) > 1) and
5948 ((P[1] = '1') or (P[1] = '0')) then
5949 g_Debug_MonsterOff := (P[1][1] = '1');
5951 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5952 end
5953 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5954 begin
5955 if Length(P) > 1 then
5956 case P[1][1] of
5957 '0': g_debug_BotAIOff := 0;
5958 '1': g_debug_BotAIOff := 1;
5959 '2': g_debug_BotAIOff := 2;
5960 '3': g_debug_BotAIOff := 3;
5961 end;
5963 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5964 end
5965 else if cmd = 'd_monster' then
5966 begin
5967 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5968 if Length(P) < 2 then
5969 begin
5970 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5971 g_Console_Add('ID | Name');
5972 for b := MONSTER_DEMON to MONSTER_MAN do
5973 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5974 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5975 end else
5976 begin
5977 a := StrToIntDef(P[1], 0);
5978 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5979 a := g_Mons_TypeIdByName(P[1]);
5981 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5982 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5983 else
5984 begin
5985 with gPlayer1.Obj do
5986 begin
5987 mon := g_Monsters_Create(a,
5988 X + Rect.X + (Rect.Width div 2),
5989 Y + Rect.Y + Rect.Height,
5990 gPlayer1.Direction, True);
5991 end;
5992 if (Length(P) > 2) and (mon <> nil) then
5993 begin
5994 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5995 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5996 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5997 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5998 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5999 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6000 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6001 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6002 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6003 end;
6004 end;
6005 end;
6006 end
6007 else if (cmd = 'd_health') then
6008 begin
6009 if (Length(P) > 1) and
6010 ((P[1] = '1') or (P[1] = '0')) then
6011 g_debug_HealthBar := (P[1][1] = '1');
6013 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6014 end
6015 else if (cmd = 'd_player') then
6016 begin
6017 if (Length(P) > 1) and
6018 ((P[1] = '1') or (P[1] = '0')) then
6019 g_debug_Player := (P[1][1] = '1');
6021 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6022 end
6023 else if (cmd = 'd_mem') then
6024 begin
6025 PrintHeapStats();
6026 end;
6027 end
6028 else
6029 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6030 end;
6033 procedure GameCheats(P: SSArray);
6034 var
6035 cmd: string;
6036 f, a: Integer;
6037 plr: TPlayer;
6038 begin
6039 if (not gGameOn) or (not conIsCheatsEnabled) then
6040 begin
6041 g_Console_Add('not available');
6042 exit;
6043 end;
6044 plr := gPlayer1;
6045 if plr = nil then
6046 begin
6047 g_Console_Add('where is the player?!');
6048 exit;
6049 end;
6050 cmd := LowerCase(P[0]);
6051 // god
6052 if cmd = 'god' then
6053 begin
6054 plr.GodMode := not plr.GodMode;
6055 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6056 exit;
6057 end;
6058 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6059 if cmd = 'give' then
6060 begin
6061 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6062 for f := 1 to High(P) do
6063 begin
6064 cmd := LowerCase(P[f]);
6065 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6066 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6067 if cmd = 'exit' then
6068 begin
6069 if gTriggers <> nil then
6070 begin
6071 for a := 0 to High(gTriggers) do
6072 begin
6073 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6074 begin
6075 g_Console_Add('player left the map');
6076 gExitByTrigger := True;
6077 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6078 g_Game_ExitLevel(gTriggers[a].tgcMap);
6079 break;
6080 end;
6081 end;
6082 end;
6083 continue;
6084 end;
6086 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6087 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6088 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6089 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6090 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6092 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6093 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6095 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6096 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;
6098 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6099 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6101 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6102 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6104 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6105 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6107 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6108 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6109 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6111 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6112 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6113 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6114 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;
6115 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6116 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6118 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;
6119 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;
6120 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;
6121 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;
6122 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;
6123 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;
6125 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6126 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;
6128 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;
6129 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;
6131 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6133 if cmd = 'ammo' then
6134 begin
6135 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6136 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6137 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6138 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6139 plr.GiveItem(ITEM_AMMO_FUELCAN);
6140 g_Console_Add('player got some ammo');
6141 continue;
6142 end;
6144 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6145 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6147 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6148 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6150 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6151 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6153 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6154 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6156 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6158 if cmd = 'weapons' then
6159 begin
6160 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6161 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6162 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6163 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6164 plr.GiveItem(ITEM_WEAPON_PLASMA);
6165 plr.GiveItem(ITEM_WEAPON_BFG);
6166 g_Console_Add('player got weapons');
6167 continue;
6168 end;
6170 if cmd = 'keys' then
6171 begin
6172 plr.GiveItem(ITEM_KEY_RED);
6173 plr.GiveItem(ITEM_KEY_GREEN);
6174 plr.GiveItem(ITEM_KEY_BLUE);
6175 g_Console_Add('player got all keys');
6176 continue;
6177 end;
6179 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6180 end;
6181 exit;
6182 end;
6183 // open
6184 if cmd = 'open' then
6185 begin
6186 g_Console_Add('player activated sesame');
6187 g_Triggers_OpenAll();
6188 exit;
6189 end;
6190 // fly
6191 if cmd = 'fly' then
6192 begin
6193 gFly := not gFly;
6194 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6195 exit;
6196 end;
6197 // noclip
6198 if cmd = 'noclip' then
6199 begin
6200 plr.SwitchNoClip;
6201 g_Console_Add('wall hardeness adjusted');
6202 exit;
6203 end;
6204 // notarget
6205 if cmd = 'notarget' then
6206 begin
6207 plr.NoTarget := not plr.NoTarget;
6208 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6209 exit;
6210 end;
6211 // noreload
6212 if cmd = 'noreload' then
6213 begin
6214 plr.NoReload := not plr.NoReload;
6215 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6216 exit;
6217 end;
6218 // speedy
6219 if cmd = 'speedy' then
6220 begin
6221 MAX_RUNVEL := 32-MAX_RUNVEL;
6222 g_Console_Add('speed adjusted');
6223 exit;
6224 end;
6225 // jumpy
6226 if cmd = 'jumpy' then
6227 begin
6228 VEL_JUMP := 30-VEL_JUMP;
6229 g_Console_Add('jump height adjusted');
6230 exit;
6231 end;
6232 // automap
6233 if cmd = 'automap' then
6234 begin
6235 gShowMap := not gShowMap;
6236 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6237 exit;
6238 end;
6239 // aimline
6240 if cmd = 'aimline' then
6241 begin
6242 gAimLine := not gAimLine;
6243 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6244 exit;
6245 end;
6246 end;
6248 procedure GameCommands(P: SSArray);
6249 var
6250 a, b: Integer;
6251 s, pw: String;
6252 chstr: string;
6253 cmd: string;
6254 pl: pTNetClient = nil;
6255 plr: TPlayer;
6256 prt: Word;
6257 nm: Boolean;
6258 listen: LongWord;
6259 found: Boolean;
6260 begin
6261 // Îáùèå êîìàíäû:
6262 cmd := LowerCase(P[0]);
6263 chstr := '';
6264 if cmd = 'pause' then
6265 begin
6266 if (g_ActiveWindow = nil) then
6267 g_Game_Pause(not gPauseMain);
6268 end
6269 else if cmd = 'endgame' then
6270 gExit := EXIT_SIMPLE
6271 else if cmd = 'restart' then
6272 begin
6273 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6274 begin
6275 if g_Game_IsClient then
6276 begin
6277 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6278 Exit;
6279 end;
6280 g_Game_Restart();
6281 end else
6282 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6283 end
6284 else if cmd = 'kick' then
6285 begin
6286 if g_Game_IsServer then
6287 begin
6288 if Length(P) < 2 then
6289 begin
6290 g_Console_Add('kick <name>');
6291 Exit;
6292 end;
6293 if P[1] = '' then
6294 begin
6295 g_Console_Add('kick <name>');
6296 Exit;
6297 end;
6299 if g_Game_IsNet then
6300 pl := g_Net_Client_ByName(P[1]);
6301 if (pl <> nil) then
6302 begin
6303 s := g_Net_ClientName_ByID(pl^.ID);
6304 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6305 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6306 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6307 g_Net_Slist_ServerPlayerLeaves();
6308 end else if gPlayers <> nil then
6309 for a := Low(gPlayers) to High(gPlayers) do
6310 if gPlayers[a] <> nil then
6311 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6312 begin
6313 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6314 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6315 continue;
6316 gPlayers[a].Lives := 0;
6317 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6318 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6319 g_Player_Remove(gPlayers[a].UID);
6320 g_Net_Slist_ServerPlayerLeaves();
6321 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6322 g_Bot_MixNames();
6323 end;
6324 end else
6325 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6326 end
6327 else if cmd = 'kick_id' then
6328 begin
6329 if g_Game_IsServer and g_Game_IsNet then
6330 begin
6331 if Length(P) < 2 then
6332 begin
6333 g_Console_Add('kick_id <client ID>');
6334 Exit;
6335 end;
6336 if P[1] = '' then
6337 begin
6338 g_Console_Add('kick_id <client ID>');
6339 Exit;
6340 end;
6342 a := StrToIntDef(P[1], 0);
6343 if (NetClients <> nil) and (a <= High(NetClients)) then
6344 begin
6345 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6346 begin
6347 s := g_Net_ClientName_ByID(NetClients[a].ID);
6348 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6349 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6350 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6351 g_Net_Slist_ServerPlayerLeaves();
6352 end;
6353 end;
6354 end else
6355 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6356 end
6357 else if cmd = 'kick_pid' then
6358 begin
6359 if g_Game_IsServer and g_Game_IsNet then
6360 begin
6361 if Length(P) < 2 then
6362 begin
6363 g_Console_Add('kick_pid <player ID>');
6364 Exit;
6365 end;
6366 if P[1] = '' then
6367 begin
6368 g_Console_Add('kick_pid <player ID>');
6369 Exit;
6370 end;
6372 a := StrToIntDef(P[1], 0);
6373 pl := g_Net_Client_ByPlayer(a);
6374 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6375 begin
6376 s := g_Net_ClientName_ByID(pl^.ID);
6377 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6378 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6379 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6380 g_Net_Slist_ServerPlayerLeaves();
6381 end;
6382 end else
6383 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6384 end
6385 else if cmd = 'ban' then
6386 begin
6387 if g_Game_IsServer and g_Game_IsNet then
6388 begin
6389 if Length(P) < 2 then
6390 begin
6391 g_Console_Add('ban <name>');
6392 Exit;
6393 end;
6394 if P[1] = '' then
6395 begin
6396 g_Console_Add('ban <name>');
6397 Exit;
6398 end;
6400 pl := g_Net_Client_ByName(P[1]);
6401 if (pl <> nil) then
6402 begin
6403 s := g_Net_ClientName_ByID(pl^.ID);
6404 g_Net_BanHost(pl^.Peer^.address.host, False);
6405 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6406 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6407 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6408 g_Net_Slist_ServerPlayerLeaves();
6409 end else
6410 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6411 end else
6412 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6413 end
6414 else if cmd = 'ban_id' then
6415 begin
6416 if g_Game_IsServer and g_Game_IsNet then
6417 begin
6418 if Length(P) < 2 then
6419 begin
6420 g_Console_Add('ban_id <client ID>');
6421 Exit;
6422 end;
6423 if P[1] = '' then
6424 begin
6425 g_Console_Add('ban_id <client ID>');
6426 Exit;
6427 end;
6429 a := StrToIntDef(P[1], 0);
6430 if (NetClients <> nil) and (a <= High(NetClients)) then
6431 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6432 begin
6433 s := g_Net_ClientName_ByID(NetClients[a].ID);
6434 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6435 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6436 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6437 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6438 g_Net_Slist_ServerPlayerLeaves();
6439 end;
6440 end else
6441 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6442 end
6443 else if cmd = 'ban_pid' then
6444 begin
6445 if g_Game_IsServer and g_Game_IsNet then
6446 begin
6447 if Length(P) < 2 then
6448 begin
6449 g_Console_Add('ban_pid <player ID>');
6450 Exit;
6451 end;
6452 if P[1] = '' then
6453 begin
6454 g_Console_Add('ban_pid <player ID>');
6455 Exit;
6456 end;
6458 a := StrToIntDef(P[1], 0);
6459 pl := g_Net_Client_ByPlayer(a);
6460 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6461 begin
6462 s := g_Net_ClientName_ByID(pl^.ID);
6463 g_Net_BanHost(pl^.Peer^.address.host, False);
6464 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6465 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6466 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6467 g_Net_Slist_ServerPlayerLeaves();
6468 end;
6469 end else
6470 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6471 end
6472 else if cmd = 'permban' then
6473 begin
6474 if g_Game_IsServer and g_Game_IsNet then
6475 begin
6476 if Length(P) < 2 then
6477 begin
6478 g_Console_Add('permban <name>');
6479 Exit;
6480 end;
6481 if P[1] = '' then
6482 begin
6483 g_Console_Add('permban <name>');
6484 Exit;
6485 end;
6487 pl := g_Net_Client_ByName(P[1]);
6488 if (pl <> nil) then
6489 begin
6490 s := g_Net_ClientName_ByID(pl^.ID);
6491 g_Net_BanHost(pl^.Peer^.address.host);
6492 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6493 g_Net_SaveBanList();
6494 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6495 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6496 g_Net_Slist_ServerPlayerLeaves();
6497 end else
6498 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6499 end else
6500 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6501 end
6502 else if cmd = 'permban_id' then
6503 begin
6504 if g_Game_IsServer and g_Game_IsNet then
6505 begin
6506 if Length(P) < 2 then
6507 begin
6508 g_Console_Add('permban_id <client ID>');
6509 Exit;
6510 end;
6511 if P[1] = '' then
6512 begin
6513 g_Console_Add('permban_id <client ID>');
6514 Exit;
6515 end;
6517 a := StrToIntDef(P[1], 0);
6518 if (NetClients <> nil) and (a <= High(NetClients)) then
6519 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6520 begin
6521 s := g_Net_ClientName_ByID(NetClients[a].ID);
6522 g_Net_BanHost(NetClients[a].Peer^.address.host);
6523 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6524 g_Net_SaveBanList();
6525 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6526 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6527 g_Net_Slist_ServerPlayerLeaves();
6528 end;
6529 end else
6530 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6531 end
6532 else if cmd = 'permban_pid' then
6533 begin
6534 if g_Game_IsServer and g_Game_IsNet then
6535 begin
6536 if Length(P) < 2 then
6537 begin
6538 g_Console_Add('permban_pid <player ID>');
6539 Exit;
6540 end;
6541 if P[1] = '' then
6542 begin
6543 g_Console_Add('permban_pid <player ID>');
6544 Exit;
6545 end;
6547 a := StrToIntDef(P[1], 0);
6548 pl := g_Net_Client_ByPlayer(a);
6549 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6550 begin
6551 s := g_Net_ClientName_ByID(pl^.ID);
6552 g_Net_BanHost(pl^.Peer^.address.host);
6553 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6554 g_Net_SaveBanList();
6555 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6556 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6557 g_Net_Slist_ServerPlayerLeaves();
6558 end;
6559 end else
6560 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6561 end
6562 else if cmd = 'permban_ip' then
6563 begin
6564 if g_Game_IsServer and g_Game_IsNet then
6565 begin
6566 if Length(P) < 2 then
6567 begin
6568 g_Console_Add('permban_ip <IP address>');
6569 Exit;
6570 end;
6571 if P[1] = '' then
6572 begin
6573 g_Console_Add('permban_ip <IP address>');
6574 Exit;
6575 end;
6577 g_Net_BanHost(P[1]);
6578 g_Net_SaveBanList();
6579 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6580 end else
6581 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6582 end
6583 else if cmd = 'unban' then
6584 begin
6585 if g_Game_IsServer and g_Game_IsNet then
6586 begin
6587 if Length(P) < 2 then
6588 begin
6589 g_Console_Add('unban <IP Address>');
6590 Exit;
6591 end;
6592 if P[1] = '' then
6593 begin
6594 g_Console_Add('unban <IP Address>');
6595 Exit;
6596 end;
6598 if g_Net_UnbanHost(P[1]) then
6599 begin
6600 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6601 g_Net_SaveBanList();
6602 end else
6603 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6604 end else
6605 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6606 end
6607 else if cmd = 'clientlist' then
6608 begin
6609 if g_Game_IsServer and g_Game_IsNet then
6610 begin
6611 b := 0;
6612 if NetClients <> nil then
6613 for a := Low(NetClients) to High(NetClients) do
6614 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6615 begin
6616 plr := g_Player_Get(NetClients[a].Player);
6617 if plr = nil then continue;
6618 Inc(b);
6619 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6620 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6621 end;
6622 if b = 0 then
6623 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6624 end else
6625 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6626 end
6627 else if cmd = 'connect' then
6628 begin
6629 if (NetMode = NET_NONE) then
6630 begin
6631 if Length(P) < 2 then
6632 begin
6633 g_Console_Add('connect <IP> [port] [password]');
6634 Exit;
6635 end;
6636 if P[1] = '' then
6637 begin
6638 g_Console_Add('connect <IP> [port] [password]');
6639 Exit;
6640 end;
6642 if Length(P) > 2 then
6643 prt := StrToIntDef(P[2], 25666)
6644 else
6645 prt := 25666;
6647 if Length(P) > 3 then
6648 pw := P[3]
6649 else
6650 pw := '';
6652 g_Game_StartClient(P[1], prt, pw);
6653 end;
6654 end
6655 else if cmd = 'disconnect' then
6656 begin
6657 if (NetMode = NET_CLIENT) then
6658 g_Net_Disconnect();
6659 end
6660 else if cmd = 'reconnect' then
6661 begin
6662 if (NetMode = NET_SERVER) then
6663 Exit;
6665 if (NetMode = NET_CLIENT) then
6666 begin
6667 g_Net_Disconnect();
6668 gExit := EXIT_SIMPLE;
6669 EndGame;
6670 end;
6672 //TODO: Use last successful password to reconnect, instead of ''
6673 g_Game_StartClient(NetClientIP, NetClientPort, '');
6674 end
6675 else if (cmd = 'addbot') or
6676 (cmd = 'bot_add') then
6677 begin
6678 if Length(P) > 2 then
6679 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6680 else if Length(P) > 1 then
6681 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6682 else
6683 g_Bot_Add(TEAM_NONE, 2);
6684 end
6685 else if cmd = 'bot_addlist' then
6686 begin
6687 if Length(P) > 1 then
6688 begin
6689 if Length(P) = 2 then
6690 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6691 else if Length(P) = 3 then
6692 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6693 else
6694 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6695 end;
6696 end
6697 else if cmd = 'bot_removeall' then
6698 g_Bot_RemoveAll()
6699 else if cmd = 'chat' then
6700 begin
6701 if g_Game_IsNet then
6702 begin
6703 if Length(P) > 1 then
6704 begin
6705 for a := 1 to High(P) do
6706 chstr := chstr + P[a] + ' ';
6708 if Length(chstr) > 200 then SetLength(chstr, 200);
6710 if Length(chstr) < 1 then
6711 begin
6712 g_Console_Add('chat <text>');
6713 Exit;
6714 end;
6716 chstr := b_Text_Format(chstr);
6717 if g_Game_IsClient then
6718 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6719 else
6720 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6721 end
6722 else
6723 g_Console_Add('chat <text>');
6724 end else
6725 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6726 end
6727 else if cmd = 'teamchat' then
6728 begin
6729 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6730 begin
6731 if Length(P) > 1 then
6732 begin
6733 for a := 1 to High(P) do
6734 chstr := chstr + P[a] + ' ';
6736 if Length(chstr) > 200 then SetLength(chstr, 200);
6738 if Length(chstr) < 1 then
6739 begin
6740 g_Console_Add('teamchat <text>');
6741 Exit;
6742 end;
6744 chstr := b_Text_Format(chstr);
6745 if g_Game_IsClient then
6746 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6747 else
6748 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6749 gPlayer1Settings.Team);
6750 end
6751 else
6752 g_Console_Add('teamchat <text>');
6753 end else
6754 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6755 end
6756 else if cmd = 'game' then
6757 begin
6758 if gGameSettings.GameType <> GT_NONE then
6759 begin
6760 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6761 Exit;
6762 end;
6763 if Length(P) = 1 then
6764 begin
6765 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6766 Exit;
6767 end;
6768 // game not started yet, load fist map from some wad
6769 found := false;
6770 s := addWadExtension(P[1]);
6771 found := e_FindResource(AllMapDirs, s);
6772 P[1] := s;
6773 if found then
6774 begin
6775 P[1] := ExpandFileName(P[1]);
6776 // if map not choosed then set first map
6777 if Length(P) < 3 then
6778 begin
6779 SetLength(P, 3);
6780 P[2] := g_Game_GetFirstMap(P[1]);
6781 end;
6783 s := P[1] + ':\' + UpperCase(P[2]);
6785 if g_Map_Exist(s) then
6786 begin
6787 // start game
6788 g_Game_Free();
6789 with gGameSettings do
6790 begin
6791 Options := gsGameFlags;
6792 GameMode := g_Game_TextToMode(gsGameMode);
6793 if gSwitchGameMode <> GM_NONE then
6794 GameMode := gSwitchGameMode;
6795 if GameMode = GM_NONE then GameMode := GM_DM;
6796 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6797 b := 1;
6798 if Length(P) >= 4 then
6799 b := StrToIntDef(P[3], 1);
6800 g_Game_StartCustom(s, GameMode, TimeLimit,
6801 GoalLimit, MaxLives, Options, b);
6802 end;
6803 end
6804 else
6805 if P[2] = '' then
6806 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6807 else
6808 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6809 end else
6810 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6811 end
6812 else if cmd = 'host' then
6813 begin
6814 if gGameSettings.GameType <> GT_NONE then
6815 begin
6816 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6817 Exit;
6818 end;
6819 if Length(P) < 4 then
6820 begin
6821 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6822 Exit;
6823 end;
6824 if not StrToIp(P[1], listen) then
6825 Exit;
6826 prt := StrToIntDef(P[2], 25666);
6828 s := addWadExtension(P[3]);
6829 found := e_FindResource(AllMapDirs, s);
6830 P[3] := s;
6831 if found then
6832 begin
6833 // get first map in wad, if not specified
6834 if Length(P) < 5 then
6835 begin
6836 SetLength(P, 5);
6837 P[4] := g_Game_GetFirstMap(P[1]);
6838 end;
6839 s := P[3] + ':\' + UpperCase(P[4]);
6840 if g_Map_Exist(s) then
6841 begin
6842 // start game
6843 g_Game_Free();
6844 with gGameSettings do
6845 begin
6846 Options := gsGameFlags;
6847 GameMode := g_Game_TextToMode(gsGameMode);
6848 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
6849 if GameMode = GM_NONE then GameMode := GM_DM;
6850 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6851 b := 0;
6852 if Length(P) >= 6 then
6853 b := StrToIntDef(P[5], 0);
6854 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
6855 end
6856 end
6857 else
6858 begin
6859 if P[4] = '' then
6860 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6861 else
6862 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
6863 end
6864 end
6865 else
6866 begin
6867 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
6868 end
6869 end
6870 else if cmd = 'map' then
6871 begin
6872 if Length(P) = 1 then
6873 begin
6874 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6875 begin
6876 g_Console_Add(cmd + ' <MAP>');
6877 g_Console_Add(cmd + ' <WAD> [MAP]')
6878 end
6879 else
6880 begin
6881 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6882 end
6883 end
6884 else
6885 begin
6886 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6887 begin
6888 if Length(P) < 3 then
6889 begin
6890 // first param is map or wad
6891 s := UpperCase(P[1]);
6892 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6893 begin
6894 gExitByTrigger := False;
6895 if gGameOn then
6896 begin
6897 // already in game, finish current map
6898 gNextMap := s;
6899 gExit := EXIT_ENDLEVELCUSTOM;
6900 end
6901 else
6902 begin
6903 // intermission, so change map immediately
6904 g_Game_ChangeMap(s)
6905 end
6906 end
6907 else
6908 begin
6909 s := P[1];
6910 found := e_FindResource(AllMapDirs, s);
6911 P[1] := s;
6912 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6913 if found then
6914 begin
6915 // no such map, found wad
6916 pw := P[1];
6917 SetLength(P, 3);
6918 P[1] := ExpandFileName(pw);
6919 P[2] := g_Game_GetFirstMap(P[1]);
6920 s := P[1] + ':\' + P[2];
6921 if g_Map_Exist(s) then
6922 begin
6923 gExitByTrigger := False;
6924 if gGameOn then
6925 begin
6926 // already in game, finish current map
6927 gNextMap := s;
6928 gExit := EXIT_ENDLEVELCUSTOM
6929 end
6930 else
6931 begin
6932 // intermission, so change map immediately
6933 g_Game_ChangeMap(s)
6934 end
6935 end
6936 else
6937 begin
6938 if P[2] = '' then
6939 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6940 else
6941 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6942 end
6943 end
6944 else
6945 begin
6946 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6947 end
6948 end;
6949 end
6950 else
6951 begin
6952 s := addWadExtension(P[1]);
6953 found := e_FindResource(AllMapDirs, s);
6954 P[1] := s;
6955 if found then
6956 begin
6957 P[2] := UpperCase(P[2]);
6958 s := P[1] + ':\' + P[2];
6959 if g_Map_Exist(s) then
6960 begin
6961 gExitByTrigger := False;
6962 if gGameOn then
6963 begin
6964 gNextMap := s;
6965 gExit := EXIT_ENDLEVELCUSTOM
6966 end
6967 else
6968 begin
6969 g_Game_ChangeMap(s)
6970 end
6971 end
6972 else
6973 begin
6974 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6975 end
6976 end
6977 else
6978 begin
6979 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6980 end
6981 end
6982 end
6983 else
6984 begin
6985 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6986 end
6987 end
6988 end
6989 else if cmd = 'nextmap' then
6990 begin
6991 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6992 begin
6993 g_Console_Add(_lc[I_MSG_NOT_GAME])
6994 end
6995 else
6996 begin
6997 nm := True;
6998 if Length(P) = 1 then
6999 begin
7000 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7001 begin
7002 g_Console_Add(cmd + ' <MAP>');
7003 g_Console_Add(cmd + ' <WAD> [MAP]');
7004 end
7005 else
7006 begin
7007 nm := False;
7008 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7009 end;
7010 end
7011 else
7012 begin
7013 nm := False;
7014 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7015 begin
7016 if Length(P) < 3 then
7017 begin
7018 // first param is map or wad
7019 s := UpperCase(P[1]);
7020 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7021 begin
7022 // map founded
7023 gExitByTrigger := False;
7024 gNextMap := s;
7025 nm := True;
7026 end
7027 else
7028 begin
7029 // no such map, found wad
7030 pw := addWadExtension(P[1]);
7031 found := e_FindResource(MapDirs, pw);
7032 if not found then
7033 found := e_FindResource(WadDirs, pw);
7034 P[1] := pw;
7035 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7036 if found then
7037 begin
7038 // map not specified, select first map
7039 SetLength(P, 3);
7040 P[2] := g_Game_GetFirstMap(P[1]);
7041 s := P[1] + ':\' + P[2];
7042 if g_Map_Exist(s) then
7043 begin
7044 gExitByTrigger := False;
7045 gNextMap := s;
7046 nm := True
7047 end
7048 else
7049 begin
7050 if P[2] = '' then
7051 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7052 else
7053 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7054 end
7055 end
7056 else
7057 begin
7058 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7059 end
7060 end
7061 end
7062 else
7063 begin
7064 // specified two params wad + map
7065 pw := addWadExtension(P[1]);
7066 found := e_FindResource(MapDirs, pw);
7067 if not found then
7068 found := e_FindResource(MapDirs, pw);
7069 P[1] := pw;
7070 if found then
7071 begin
7072 P[2] := UpperCase(P[2]);
7073 s := P[1] + ':\' + P[2];
7074 if g_Map_Exist(s) then
7075 begin
7076 gExitByTrigger := False;
7077 gNextMap := s;
7078 nm := True
7079 end
7080 else
7081 begin
7082 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7083 end
7084 end
7085 else
7086 begin
7087 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7088 end
7089 end
7090 end
7091 else
7092 begin
7093 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7094 end
7095 end;
7096 if nm then
7097 begin
7098 if gNextMap = '' then
7099 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7100 else
7101 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7102 end
7103 end
7104 end
7105 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7106 begin
7107 if not gGameOn then
7108 begin
7109 g_Console_Add(_lc[I_MSG_NOT_GAME])
7110 end
7111 else
7112 begin
7113 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7114 begin
7115 gExitByTrigger := False;
7116 // next map not specified, try to find trigger EXIT
7117 if (gNextMap = '') and (gTriggers <> nil) then
7118 begin
7119 for a := 0 to High(gTriggers) do
7120 begin
7121 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7122 begin
7123 gExitByTrigger := True;
7124 //gNextMap := gTriggers[a].Data.MapName;
7125 gNextMap := gTriggers[a].tgcMap;
7126 Break
7127 end
7128 end
7129 end;
7130 if gNextMap = '' then
7131 gNextMap := g_Game_GetNextMap();
7132 if not isWadPath(gNextMap) then
7133 s := gGameSettings.WAD + ':\' + gNextMap
7134 else
7135 s := gNextMap;
7136 if g_Map_Exist(s) then
7137 gExit := EXIT_ENDLEVELCUSTOM
7138 else
7139 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7140 end
7141 else
7142 begin
7143 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7144 end
7145 end
7146 end
7147 else if (cmd = 'event') then
7148 begin
7149 if (Length(P) <= 1) then
7150 begin
7151 for a := 0 to High(gEvents) do
7152 if gEvents[a].Command = '' then
7153 g_Console_Add(gEvents[a].Name + ' <none>')
7154 else
7155 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7156 Exit;
7157 end;
7158 if (Length(P) = 2) then
7159 begin
7160 for a := 0 to High(gEvents) do
7161 if gEvents[a].Name = P[1] then
7162 if gEvents[a].Command = '' then
7163 g_Console_Add(gEvents[a].Name + ' <none>')
7164 else
7165 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7166 Exit;
7167 end;
7168 for a := 0 to High(gEvents) do
7169 if gEvents[a].Name = P[1] then
7170 begin
7171 gEvents[a].Command := '';
7172 for b := 2 to High(P) do
7173 if Pos(' ', P[b]) = 0 then
7174 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7175 else
7176 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7177 gEvents[a].Command := Trim(gEvents[a].Command);
7178 Exit;
7179 end;
7180 end
7181 else if cmd = 'suicide' then
7182 begin
7183 if gGameOn then
7184 begin
7185 if g_Game_IsClient then
7186 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7187 else
7188 begin
7189 if gPlayer1 <> nil then
7190 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7191 if gPlayer2 <> nil then
7192 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7193 end;
7194 end;
7195 end
7196 else if cmd = 'screenshot' then
7197 begin
7198 g_TakeScreenShot()
7199 end
7200 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7201 begin
7202 a := 1 - (ord(cmd[5]) - ord('n'));
7203 if a = -1 then
7204 gWeaponAction[0, WP_PREV] := True;
7205 if a = 1 then
7206 gWeaponAction[0, WP_NEXT] := True;
7207 end
7208 else if cmd = 'weapon' then
7209 begin
7210 if Length(p) = 2 then
7211 begin
7212 a := WP_FIRST + StrToInt(p[1]) - 1;
7213 if (a >= WP_FIRST) and (a <= WP_LAST) then
7214 gSelectWeapon[0, a] := True
7215 end
7216 end
7217 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7218 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7219 begin
7220 a := 1 - (ord(cmd[8]) - ord('n'));
7221 b := ord(cmd[2]) - ord('1');
7222 if a = -1 then
7223 gWeaponAction[b, WP_PREV] := True;
7224 if a = 1 then
7225 gWeaponAction[b, WP_NEXT] := True;
7226 end
7227 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7228 begin
7229 if Length(p) = 2 then
7230 begin
7231 a := WP_FIRST + StrToInt(p[1]) - 1;
7232 b := ord(cmd[2]) - ord('1');
7233 if (a >= WP_FIRST) and (a <= WP_LAST) then
7234 gSelectWeapon[b, a] := True
7235 end
7236 end
7237 // Êîìàíäû Ñâîåé èãðû:
7238 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7239 begin
7240 if cmd = 'bot_addred' then
7241 begin
7242 if Length(P) > 1 then
7243 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7244 else
7245 g_Bot_Add(TEAM_RED, 2);
7246 end
7247 else if cmd = 'bot_addblue' then
7248 begin
7249 if Length(P) > 1 then
7250 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7251 else
7252 g_Bot_Add(TEAM_BLUE, 2);
7253 end
7254 else if cmd = 'spectate' then
7255 begin
7256 if not gGameOn then
7257 Exit;
7258 g_Game_Spectate();
7259 end
7260 else if cmd = 'say' then
7261 begin
7262 if g_Game_IsServer and g_Game_IsNet then
7263 begin
7264 if Length(P) > 1 then
7265 begin
7266 chstr := '';
7267 for a := 1 to High(P) do
7268 chstr := chstr + P[a] + ' ';
7270 if Length(chstr) > 200 then SetLength(chstr, 200);
7272 if Length(chstr) < 1 then
7273 begin
7274 g_Console_Add('say <text>');
7275 Exit;
7276 end;
7278 chstr := b_Text_Format(chstr);
7279 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7280 end
7281 else g_Console_Add('say <text>');
7282 end else
7283 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7284 end
7285 else if cmd = 'tell' then
7286 begin
7287 if g_Game_IsServer and g_Game_IsNet then
7288 begin
7289 if (Length(P) > 2) and (P[1] <> '') then
7290 begin
7291 chstr := '';
7292 for a := 2 to High(P) do
7293 chstr := chstr + P[a] + ' ';
7295 if Length(chstr) > 200 then SetLength(chstr, 200);
7297 if Length(chstr) < 1 then
7298 begin
7299 g_Console_Add('tell <playername> <text>');
7300 Exit;
7301 end;
7303 pl := g_Net_Client_ByName(P[1]);
7304 if pl <> nil then
7305 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7306 else
7307 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7308 end
7309 else g_Console_Add('tell <playername> <text>');
7310 end else
7311 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7312 end
7313 else if cmd = 'centerprint' then
7314 begin
7315 if (Length(P) > 2) and (P[1] <> '') then
7316 begin
7317 chstr := '';
7318 for a := 2 to High(P) do
7319 chstr := chstr + P[a] + ' ';
7321 if Length(chstr) > 200 then SetLength(chstr, 200);
7323 if Length(chstr) < 1 then
7324 begin
7325 g_Console_Add('centerprint <timeout> <text>');
7326 Exit;
7327 end;
7329 a := StrToIntDef(P[1], 100);
7330 chstr := b_Text_Format(chstr);
7331 g_Game_Message(chstr, a);
7332 if g_Game_IsNet and g_Game_IsServer then
7333 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7334 end
7335 else g_Console_Add('centerprint <timeout> <text>');
7336 end
7337 else if (cmd = 'overtime') and not g_Game_IsClient then
7338 begin
7339 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7340 Exit;
7341 // Äîïîëíèòåëüíîå âðåìÿ:
7342 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7344 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7345 [gGameSettings.TimeLimit div 3600,
7346 (gGameSettings.TimeLimit div 60) mod 60,
7347 gGameSettings.TimeLimit mod 60]));
7348 if g_Game_IsNet then MH_SEND_GameSettings;
7349 end
7350 else if (cmd = 'rcon_password') and g_Game_IsClient then
7351 begin
7352 if (Length(P) <= 1) then
7353 g_Console_Add('rcon_password <password>')
7354 else
7355 MC_SEND_RCONPassword(P[1]);
7356 end
7357 else if cmd = 'rcon' then
7358 begin
7359 if g_Game_IsClient then
7360 begin
7361 if Length(P) > 1 then
7362 begin
7363 chstr := '';
7364 for a := 1 to High(P) do
7365 chstr := chstr + P[a] + ' ';
7367 if Length(chstr) > 200 then SetLength(chstr, 200);
7369 if Length(chstr) < 1 then
7370 begin
7371 g_Console_Add('rcon <command>');
7372 Exit;
7373 end;
7375 MC_SEND_RCONCommand(chstr);
7376 end
7377 else g_Console_Add('rcon <command>');
7378 end;
7379 end
7380 else if cmd = 'ready' then
7381 begin
7382 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7383 gLMSRespawnTime := gTime + 100;
7384 end
7385 else if (cmd = 'callvote') and g_Game_IsNet then
7386 begin
7387 if Length(P) > 1 then
7388 begin
7389 chstr := '';
7390 for a := 1 to High(P) do begin
7391 if a > 1 then chstr := chstr + ' ';
7392 chstr := chstr + P[a];
7393 end;
7395 if Length(chstr) > 200 then SetLength(chstr, 200);
7397 if Length(chstr) < 1 then
7398 begin
7399 g_Console_Add('callvote <command>');
7400 Exit;
7401 end;
7403 if g_Game_IsClient then
7404 MC_SEND_Vote(True, chstr)
7405 else
7406 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7407 g_Console_Process('vote', True);
7408 end
7409 else
7410 g_Console_Add('callvote <command>');
7411 end
7412 else if (cmd = 'vote') and g_Game_IsNet then
7413 begin
7414 if g_Game_IsClient then
7415 MC_SEND_Vote(False)
7416 else if gVoteInProgress then
7417 begin
7418 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7419 a := Floor((NetClientCount+1)/2.0) + 1
7420 else
7421 a := Floor(NetClientCount/2.0) + 1;
7422 if gVoted then
7423 begin
7424 Dec(gVoteCount);
7425 gVoted := False;
7426 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7427 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7428 end
7429 else
7430 begin
7431 Inc(gVoteCount);
7432 gVoted := True;
7433 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7434 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7435 g_Game_CheckVote;
7436 end;
7437 end;
7438 end
7439 end;
7440 end;
7442 procedure SystemCommands(P: SSArray);
7443 var
7444 cmd: string;
7445 begin
7446 cmd := LowerCase(P[0]);
7447 case cmd of
7448 'exit', 'quit':
7449 begin
7450 g_Game_Free();
7451 g_Game_Quit();
7452 end;
7453 'r_reset':
7454 begin
7455 gRC_Width := Max(1, gRC_Width);
7456 gRC_Height := Max(1, gRC_Height);
7457 gBPP := Max(1, gBPP);
7458 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7459 e_LogWriteln('resolution changed')
7460 else
7461 e_LogWriteln('resolution not changed');
7462 sys_EnableVSync(gVSync);
7463 end;
7464 'r_maxfps':
7465 begin
7466 if Length(p) = 2 then
7467 begin
7468 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7469 if gMaxFPS > 0 then
7470 gFrameTime := 1000 div gMaxFPS
7471 else
7472 gFrameTime := 0;
7473 end;
7474 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7475 end;
7476 'g_language':
7477 begin
7478 if Length(p) = 2 then
7479 begin
7480 gAskLanguage := true;
7481 gLanguage := LANGUAGE_ENGLISH;
7482 case LowerCase(p[1]) of
7483 'english':
7484 begin
7485 gAskLanguage := false;
7486 gLanguage := LANGUAGE_ENGLISH;
7487 end;
7488 'russian':
7489 begin
7490 gAskLanguage := false;
7491 gLanguage := LANGUAGE_RUSSIAN;
7492 end;
7493 'ask':
7494 begin
7495 gAskLanguage := true;
7496 gLanguage := LANGUAGE_ENGLISH;
7497 end;
7498 end;
7499 g_Language_Set(gLanguage);
7500 end
7501 else
7502 begin
7503 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7504 end
7505 end;
7506 end;
7507 end;
7509 procedure g_TakeScreenShot(Filename: string = '');
7510 var s: TStream; t: TDateTime; dir, date, name: String;
7511 begin
7512 if e_NoGraphics then Exit;
7513 try
7514 dir := e_GetWriteableDir(ScreenshotDirs);
7516 if Filename = '' then
7517 begin
7518 t := Now;
7519 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7520 Filename := 'screenshot-' + date;
7521 end;
7523 name := e_CatPath(dir, Filename + '.png');
7524 s := createDiskFile(name);
7525 try
7526 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
7527 s.Free;
7528 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7529 except
7530 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7531 s.Free;
7532 DeleteFile(name)
7533 end
7534 except
7535 g_Console_Add('oh shit, i can''t create screenshot!')
7536 end
7537 end;
7539 procedure g_Game_InGameMenu(Show: Boolean);
7540 begin
7541 if (g_ActiveWindow = nil) and Show then
7542 begin
7543 if gGameSettings.GameType = GT_SINGLE then
7544 g_GUI_ShowWindow('GameSingleMenu')
7545 else
7546 begin
7547 if g_Game_IsClient then
7548 g_GUI_ShowWindow('GameClientMenu')
7549 else
7550 if g_Game_IsNet then
7551 g_GUI_ShowWindow('GameServerMenu')
7552 else
7553 g_GUI_ShowWindow('GameCustomMenu');
7554 end;
7555 g_Sound_PlayEx('MENU_OPEN');
7557 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7558 if (not g_Game_IsNet) then
7559 g_Game_Pause(True);
7560 end
7561 else
7562 if (g_ActiveWindow <> nil) and (not Show) then
7563 begin
7564 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7565 if (not g_Game_IsNet) then
7566 g_Game_Pause(False);
7567 end;
7568 end;
7570 procedure g_Game_Pause (Enable: Boolean);
7571 var
7572 oldPause: Boolean;
7573 begin
7574 if not gGameOn then exit;
7576 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7578 oldPause := gPause;
7579 gPauseMain := Enable;
7581 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7582 end;
7584 procedure g_Game_HolmesPause (Enable: Boolean);
7585 var
7586 oldPause: Boolean;
7587 begin
7588 if not gGameOn then exit;
7589 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7591 oldPause := gPause;
7592 gPauseHolmes := Enable;
7594 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7595 end;
7597 procedure g_Game_PauseAllSounds(Enable: Boolean);
7598 var
7599 i: Integer;
7600 begin
7601 // Òðèããåðû:
7602 if gTriggers <> nil then
7603 for i := 0 to High(gTriggers) do
7604 with gTriggers[i] do
7605 if (TriggerType = TRIGGER_SOUND) and
7606 (Sound <> nil) and
7607 Sound.IsPlaying() then
7608 begin
7609 Sound.Pause(Enable);
7610 end;
7612 // Çâóêè èãðîêîâ:
7613 if gPlayers <> nil then
7614 for i := 0 to High(gPlayers) do
7615 if gPlayers[i] <> nil then
7616 gPlayers[i].PauseSounds(Enable);
7618 // Ìóçûêà:
7619 if gMusic <> nil then
7620 gMusic.Pause(Enable);
7621 end;
7623 procedure g_Game_StopAllSounds(all: Boolean);
7624 var
7625 i: Integer;
7626 begin
7627 if gTriggers <> nil then
7628 for i := 0 to High(gTriggers) do
7629 with gTriggers[i] do
7630 if (TriggerType = TRIGGER_SOUND) and
7631 (Sound <> nil) then
7632 Sound.Stop();
7634 if gMusic <> nil then
7635 gMusic.Stop();
7637 if all then
7638 e_StopChannels();
7639 end;
7641 procedure g_Game_UpdateTriggerSounds;
7642 var i: Integer;
7643 begin
7644 if gTriggers <> nil then
7645 for i := 0 to High(gTriggers) do
7646 with gTriggers[i] do
7647 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7648 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7649 end;
7651 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7652 begin
7653 Result := False;
7654 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7655 begin
7656 Result := True;
7657 Exit;
7658 end;
7659 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7660 begin
7661 Result := True;
7662 Exit;
7663 end;
7664 if gSpectMode <> SPECT_PLAYERS then
7665 Exit;
7666 if gSpectPID1 = UID then
7667 begin
7668 Result := True;
7669 Exit;
7670 end;
7671 if gSpectViewTwo and (gSpectPID2 = UID) then
7672 begin
7673 Result := True;
7674 Exit;
7675 end;
7676 end;
7678 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7679 var
7680 Pl: TPlayer;
7681 begin
7682 Result := False;
7683 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7684 begin
7685 Result := True;
7686 Exit;
7687 end;
7688 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7689 begin
7690 Result := True;
7691 Exit;
7692 end;
7693 if gSpectMode <> SPECT_PLAYERS then
7694 Exit;
7695 Pl := g_Player_Get(gSpectPID1);
7696 if (Pl <> nil) and (Pl.Team = Team) then
7697 begin
7698 Result := True;
7699 Exit;
7700 end;
7701 if gSpectViewTwo then
7702 begin
7703 Pl := g_Player_Get(gSpectPID2);
7704 if (Pl <> nil) and (Pl.Team = Team) then
7705 begin
7706 Result := True;
7707 Exit;
7708 end;
7709 end;
7710 end;
7712 procedure g_Game_Message(Msg: string; Time: Word);
7713 begin
7714 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7715 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7716 MessageTime := Time;
7717 end;
7719 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7720 const
7721 punct: Array[0..13] of String =
7722 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7723 var
7724 i, j: Integer;
7725 ok: Boolean;
7726 fpText: String;
7728 function IsPunctuation(S: String): Boolean;
7729 var
7730 i: Integer;
7731 begin
7732 Result := False;
7733 if Length(S) <> 1 then
7734 Exit;
7735 for i := Low(punct) to High(punct) do
7736 if S = punct[i] then
7737 begin
7738 Result := True;
7739 break;
7740 end;
7741 end;
7742 function FilterPunctuation(S: String): String;
7743 var
7744 i: Integer;
7745 begin
7746 for i := Low(punct) to High(punct) do
7747 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7748 Result := S;
7749 end;
7750 begin
7751 ok := False;
7753 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7754 begin
7755 // remove player name
7756 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7757 // for FullWord check
7758 Text := toLowerCase1251(' ' + Text + ' ');
7759 fpText := FilterPunctuation(Text);
7761 for i := 0 to Length(gChatSounds) - 1 do
7762 begin
7763 ok := True;
7764 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7765 begin
7766 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7767 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7768 else
7769 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7770 if not ok then
7771 break;
7772 end;
7773 if ok then
7774 begin
7775 gChatSounds[i].Sound.Play();
7776 break;
7777 end;
7778 end;
7779 end;
7780 if not ok then
7781 g_Sound_PlayEx('SOUND_GAME_RADIO');
7782 end;
7784 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7785 var
7786 a: Integer;
7787 begin
7788 case gAnnouncer of
7789 ANNOUNCE_NONE:
7790 Exit;
7791 ANNOUNCE_ME,
7792 ANNOUNCE_MEPLUS:
7793 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7794 Exit;
7795 end;
7796 for a := 0 to 3 do
7797 if goodsnd[a].IsPlaying() then
7798 Exit;
7800 goodsnd[Random(4)].Play();
7801 end;
7803 procedure g_Game_Announce_KillCombo(Param: Integer);
7804 var
7805 UID: Word;
7806 c, n: Byte;
7807 Pl: TPlayer;
7808 Name: String;
7809 begin
7810 UID := Param and $FFFF;
7811 c := Param shr 16;
7812 if c < 2 then
7813 Exit;
7815 Pl := g_Player_Get(UID);
7816 if Pl = nil then
7817 Name := '?'
7818 else
7819 Name := Pl.Name;
7821 case c of
7822 2: begin
7823 n := 0;
7824 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7825 end;
7826 3: begin
7827 n := 1;
7828 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7829 end;
7830 4: begin
7831 n := 2;
7832 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7833 end;
7834 else begin
7835 n := 3;
7836 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7837 end;
7838 end;
7840 case gAnnouncer of
7841 ANNOUNCE_NONE:
7842 Exit;
7843 ANNOUNCE_ME:
7844 if not g_Game_IsWatchedPlayer(UID) then
7845 Exit;
7846 ANNOUNCE_MEPLUS:
7847 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7848 Exit;
7849 end;
7851 if killsnd[n].IsPlaying() then
7852 killsnd[n].Stop();
7853 killsnd[n].Play();
7854 end;
7856 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7857 var
7858 a: Integer;
7859 begin
7860 case gAnnouncer of
7861 ANNOUNCE_NONE:
7862 Exit;
7863 ANNOUNCE_ME:
7864 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7865 Exit;
7866 end;
7867 for a := 0 to 2 do
7868 if hahasnd[a].IsPlaying() then
7869 Exit;
7871 hahasnd[Random(3)].Play();
7872 end;
7874 procedure g_Game_StartVote(Command, Initiator: string);
7875 var
7876 Need: Integer;
7877 begin
7878 if not gVotesEnabled then Exit;
7879 if gGameSettings.GameType <> GT_SERVER then Exit;
7880 if gVoteInProgress or gVotePassed then
7881 begin
7882 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7883 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7884 Exit;
7885 end;
7886 gVoteInProgress := True;
7887 gVotePassed := False;
7888 gVoteTimer := gTime + gVoteTimeout * 1000;
7889 gVoteCount := 0;
7890 gVoted := False;
7891 gVoteCommand := Command;
7893 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7894 Need := Floor((NetClientCount+1)/2.0)+1
7895 else
7896 Need := Floor(NetClientCount/2.0)+1;
7897 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7898 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7899 end;
7901 procedure g_Game_CheckVote;
7902 var
7903 I, Need: Integer;
7904 begin
7905 if gGameSettings.GameType <> GT_SERVER then Exit;
7906 if not gVoteInProgress then Exit;
7908 if (gTime >= gVoteTimer) then
7909 begin
7910 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7911 Need := Floor((NetClientCount+1)/2.0) + 1
7912 else
7913 Need := Floor(NetClientCount/2.0) + 1;
7914 if gVoteCount >= Need then
7915 begin
7916 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7917 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7918 gVotePassed := True;
7919 gVoteCmdTimer := gTime + 5000;
7920 end
7921 else
7922 begin
7923 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7924 MH_SEND_VoteEvent(NET_VE_FAILED);
7925 end;
7926 if NetClients <> nil then
7927 for I := Low(NetClients) to High(NetClients) do
7928 if NetClients[i].Used then
7929 NetClients[i].Voted := False;
7930 gVoteInProgress := False;
7931 gVoted := False;
7932 gVoteCount := 0;
7933 end
7934 else
7935 begin
7936 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7937 Need := Floor((NetClientCount+1)/2.0) + 1
7938 else
7939 Need := Floor(NetClientCount/2.0) + 1;
7940 if gVoteCount >= Need then
7941 begin
7942 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7943 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7944 gVoteInProgress := False;
7945 gVotePassed := True;
7946 gVoteCmdTimer := gTime + 5000;
7947 gVoted := False;
7948 gVoteCount := 0;
7949 if NetClients <> nil then
7950 for I := Low(NetClients) to High(NetClients) do
7951 if NetClients[i].Used then
7952 NetClients[i].Voted := False;
7953 end;
7954 end;
7955 end;
7957 procedure g_Game_LoadMapList(FileName: string);
7958 var
7959 ListFile: TextFile;
7960 s: string;
7961 begin
7962 MapList := nil;
7963 MapIndex := -1;
7965 if not FileExists(FileName) then Exit;
7967 AssignFile(ListFile, FileName);
7968 Reset(ListFile);
7969 while not EOF(ListFile) do
7970 begin
7971 ReadLn(ListFile, s);
7973 s := Trim(s);
7974 if s = '' then Continue;
7976 SetLength(MapList, Length(MapList)+1);
7977 MapList[High(MapList)] := s;
7978 end;
7979 CloseFile(ListFile);
7980 end;
7982 procedure g_Game_SetDebugMode();
7983 begin
7984 gDebugMode := True;
7985 // ×èòû (äàæå â ñâîåé èãðå):
7986 gCheats := True;
7987 end;
7989 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7990 var
7991 i: Word;
7992 begin
7993 if Length(LoadingStat.Msgs) = 0 then
7994 Exit;
7996 with LoadingStat do
7997 begin
7998 if not reWrite then
7999 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8000 if NextMsg = Length(Msgs) then
8001 begin // scroll
8002 for i := 0 to High(Msgs)-1 do
8003 Msgs[i] := Msgs[i+1];
8004 end
8005 else
8006 Inc(NextMsg);
8007 end else
8008 if NextMsg = 0 then
8009 Inc(NextMsg);
8011 Msgs[NextMsg-1] := Text;
8012 CurValue := 0;
8013 MaxValue := Max;
8014 ShowCount := 0;
8015 PBarWasHere := false;
8016 end;
8018 g_ActiveWindow := nil;
8020 ProcessLoading(true);
8021 end;
8023 procedure g_Game_StepLoading(Value: Integer = -1);
8024 begin
8025 with LoadingStat do
8026 begin
8027 if Value = -1 then
8028 begin
8029 Inc(CurValue);
8030 Inc(ShowCount);
8031 end
8032 else
8033 CurValue := Value;
8034 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8035 begin
8036 ShowCount := 0;
8037 ProcessLoading();
8038 end;
8039 end;
8040 end;
8042 procedure g_Game_ClearLoading();
8043 var
8044 len: Word;
8045 begin
8046 with LoadingStat do
8047 begin
8048 CurValue := 0;
8049 MaxValue := 0;
8050 ShowCount := 0;
8051 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8052 if len < 1 then len := 1;
8053 SetLength(Msgs, len);
8054 for len := Low(Msgs) to High(Msgs) do
8055 Msgs[len] := '';
8056 NextMsg := 0;
8057 PBarWasHere := false;
8058 end;
8059 end;
8061 procedure Parse_Params(var pars: TParamStrValues);
8062 var
8063 i: Integer;
8064 s: String;
8065 begin
8066 SetLength(pars, 0);
8067 i := 1;
8068 while i <= ParamCount do
8069 begin
8070 s := ParamStr(i);
8071 if (Length(s) > 1) and (s[1] = '-') then
8072 begin
8073 if (Length(s) > 2) and (s[2] = '-') then
8074 begin // Îäèíî÷íûé ïàðàìåòð
8075 SetLength(pars, Length(pars) + 1);
8076 with pars[High(pars)] do
8077 begin
8078 Name := LowerCase(s);
8079 Value := '+';
8080 end;
8081 end
8082 else
8083 if (i < ParamCount) then
8084 begin // Ïàðàìåòð ñî çíà÷åíèåì
8085 Inc(i);
8086 SetLength(pars, Length(pars) + 1);
8087 with pars[High(pars)] do
8088 begin
8089 Name := LowerCase(s);
8090 Value := LowerCase(ParamStr(i));
8091 end;
8092 end;
8093 end;
8095 Inc(i);
8096 end;
8097 end;
8099 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8100 var
8101 i: Integer;
8102 begin
8103 Result := '';
8104 for i := 0 to High(pars) do
8105 if pars[i].Name = aName then
8106 begin
8107 Result := pars[i].Value;
8108 Break;
8109 end;
8110 end;
8112 procedure g_Game_Process_Params();
8113 var
8114 pars: TParamStrValues;
8115 map: String;
8116 GMode, n: Byte;
8117 LimT, LimS: Integer;
8118 Opt: LongWord;
8119 Lives: Integer;
8120 s: String;
8121 Port: Integer;
8122 ip: String;
8123 F: TextFile;
8124 begin
8125 Parse_Params(pars);
8127 // Debug mode:
8128 s := Find_Param_Value(pars, '--debug');
8129 if (s <> '') then
8130 begin
8131 g_Game_SetDebugMode();
8132 s := Find_Param_Value(pars, '--netdump');
8133 if (s <> '') then
8134 NetDump := True;
8135 end;
8137 // Connect when game loads
8138 ip := Find_Param_Value(pars, '-connect');
8140 if ip <> '' then
8141 begin
8142 s := Find_Param_Value(pars, '-port');
8143 if (s = '') or not TryStrToInt(s, Port) then
8144 Port := 25666;
8146 s := Find_Param_Value(pars, '-pw');
8148 g_Game_StartClient(ip, Port, s);
8149 Exit;
8150 end;
8152 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8153 if (s <> '') then
8154 begin
8155 gDefaultMegawadStart := s;
8156 end;
8158 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8159 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8160 begin
8161 gDefaultMegawadStart := DF_Default_Megawad_Start;
8162 end;
8164 // Start map when game loads:
8165 map := LowerCase(Find_Param_Value(pars, '-map'));
8166 if isWadPath(map) then
8167 begin
8168 // Game mode:
8169 s := Find_Param_Value(pars, '-gm');
8170 GMode := g_Game_TextToMode(s);
8171 if GMode = GM_NONE then GMode := GM_DM;
8172 if GMode = GM_SINGLE then GMode := GM_COOP;
8174 // Time limit:
8175 s := Find_Param_Value(pars, '-limt');
8176 if (s = '') or (not TryStrToInt(s, LimT)) then
8177 LimT := 0;
8178 if LimT < 0 then
8179 LimT := 0;
8181 // Goal limit:
8182 s := Find_Param_Value(pars, '-lims');
8183 if (s = '') or (not TryStrToInt(s, LimS)) then
8184 LimS := 0;
8185 if LimS < 0 then
8186 LimS := 0;
8188 // Lives limit:
8189 s := Find_Param_Value(pars, '-lives');
8190 if (s = '') or (not TryStrToInt(s, Lives)) then
8191 Lives := 0;
8192 if Lives < 0 then
8193 Lives := 0;
8195 // Options:
8196 s := Find_Param_Value(pars, '-opt');
8197 if (s = '') then
8198 Opt := gsGameFlags
8199 else
8200 Opt := StrToIntDef(s, 0);
8202 // Close after map:
8203 s := Find_Param_Value(pars, '--close');
8204 if (s <> '') then
8205 gMapOnce := True;
8207 // Override map to test:
8208 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8209 if s <> '' then
8210 begin
8211 if e_IsValidResourceName(s) then
8212 e_FindResource(AllMapDirs, s);
8213 gTestMap := ExpandFileName(s);
8214 end;
8216 // Delete test map after play:
8217 s := Find_Param_Value(pars, '--testdelete');
8218 if (s <> '') then
8219 begin
8220 //gMapToDelete := MapsDir + map;
8221 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8222 Halt(1);
8223 end;
8225 // Delete temporary WAD after play:
8226 s := Find_Param_Value(pars, '--tempdelete');
8227 if (s <> '') and (gTestMap <> '') then
8228 begin
8229 gMapToDelete := gTestMap;
8230 gTempDelete := True;
8231 end;
8233 // Number of players:
8234 s := Find_Param_Value(pars, '-pl');
8235 if (s = '') then
8236 n := DEFAULT_PLAYERS
8237 else
8238 n := StrToIntDef(s, DEFAULT_PLAYERS);
8240 // Start:
8241 s := Find_Param_Value(pars, '-port');
8242 if (s = '') or not TryStrToInt(s, Port) then
8243 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8244 else
8245 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8246 end;
8248 // Execute script when game loads:
8249 s := Find_Param_Value(pars, '-exec');
8250 if s <> '' then
8251 begin
8252 // if not isWadPath(s) then
8253 // s := GameDir + '/' + s;
8255 {$I-}
8256 AssignFile(F, s);
8257 Reset(F);
8258 if IOResult <> 0 then
8259 begin
8260 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8261 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8262 CloseFile(F);
8263 Exit;
8264 end;
8265 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8266 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8268 while not EOF(F) do
8269 begin
8270 ReadLn(F, s);
8271 if IOResult <> 0 then
8272 begin
8273 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8274 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8275 CloseFile(F);
8276 Exit;
8277 end;
8278 if Pos('#', s) <> 1 then // script comment
8279 g_Console_Process(s, True);
8280 end;
8282 CloseFile(F);
8283 {$I+}
8284 end;
8286 SetLength(pars, 0);
8287 end;
8289 begin
8290 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8291 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8292 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8293 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8295 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8296 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8297 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8298 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8300 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8301 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8303 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8304 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8306 {$IFDEF ENABLE_HOLMES}
8307 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8308 {$ENDIF}
8310 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8312 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8313 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8315 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8316 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8318 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8319 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8321 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8322 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8323 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8324 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
8325 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8326 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8327 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8328 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8329 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8330 end.