DEADSOFTWARE

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