DEADSOFTWARE

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