DEADSOFTWARE

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