DEADSOFTWARE

net: add some more gulag tools
[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 = 1) then DrawStat();
4003 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4004 begin
4005 // Draw spectator GUI
4006 ww := 0;
4007 hh := 0;
4008 e_TextureFontGetSize(gStdFont, ww, hh);
4009 case gSpectMode of
4010 SPECT_STATS:
4011 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4012 SPECT_MAPVIEW:
4013 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4014 SPECT_PLAYERS:
4015 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4016 end;
4017 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4018 if gSpectMode = SPECT_STATS then
4019 begin
4020 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4021 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4022 end;
4023 if gSpectMode = SPECT_MAPVIEW then
4024 begin
4025 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4026 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4027 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4028 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4029 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4030 end;
4031 if gSpectMode = SPECT_PLAYERS then
4032 begin
4033 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4034 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4035 if gSpectViewTwo then
4036 begin
4037 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4038 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4039 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4040 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4041 end
4042 else
4043 begin
4044 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4045 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4046 end;
4047 end;
4048 end;
4049 end;
4051 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4052 begin
4053 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4054 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4056 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4057 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4058 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4059 end;
4061 if not gGameOn then
4062 begin
4063 if (gState = STATE_MENU) then
4064 begin
4065 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4066 // F3 at menu will show game loading dialog
4067 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4068 if (g_ActiveWindow <> nil) then
4069 begin
4070 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4071 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4072 end
4073 else
4074 begin
4075 // F3 at titlepic will show game loading dialog
4076 if e_KeyPressed(IK_F3) then
4077 begin
4078 g_Menu_Show_LoadMenu(true);
4079 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4080 end;
4081 end;
4082 end;
4084 if gState = STATE_FOLD then
4085 begin
4086 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4087 end;
4089 if gState = STATE_INTERCUSTOM then
4090 begin
4091 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4092 begin
4093 back := 'TEXTURE_endpic';
4094 if not g_Texture_Get(back, ID) then
4095 back := _lc[I_TEXTURE_ENDPIC];
4096 end
4097 else
4098 back := 'INTER';
4100 DrawMenuBackground(back);
4102 DrawCustomStat();
4104 if g_ActiveWindow <> nil then
4105 begin
4106 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4107 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4108 end;
4109 end;
4111 if gState = STATE_INTERSINGLE then
4112 begin
4113 if EndingGameCounter > 0 then
4114 begin
4115 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4116 end
4117 else
4118 begin
4119 back := 'INTER';
4121 DrawMenuBackground(back);
4123 DrawSingleStat();
4125 if g_ActiveWindow <> nil then
4126 begin
4127 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4128 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4129 end;
4130 end;
4131 end;
4133 if gState = STATE_ENDPIC then
4134 begin
4135 ID := DWORD(-1);
4136 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4137 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4139 if g_ActiveWindow <> nil then
4140 begin
4141 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4142 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4143 end;
4144 end;
4146 if gState = STATE_SLIST then
4147 begin
4148 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4149 // begin
4150 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4151 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4152 // end;
4153 DrawMenuBackground('MENU_BACKGROUND');
4154 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4155 g_Serverlist_Draw(slCurrent, slTable);
4156 end;
4157 end;
4159 if g_ActiveWindow <> nil then
4160 begin
4161 if gGameOn then
4162 begin
4163 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4164 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4165 end;
4166 g_ActiveWindow.Draw();
4167 end;
4169 {$IFNDEF HEADLESS}
4170 g_Console_Draw();
4171 {$ENDIF}
4173 if g_debug_Sounds and gGameOn then
4174 begin
4175 for w := 0 to High(e_SoundsArray) do
4176 for h := 0 to e_SoundsArray[w].nRefs do
4177 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4178 end;
4180 if gShowFPS then
4181 begin
4182 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4183 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4184 end;
4186 if gGameOn and gShowTime then
4187 drawTime(gScreenWidth-72, gScreenHeight-16);
4189 if gGameOn then drawProfilers();
4191 // TODO: draw this after the FBO and remap mouse click coordinates
4193 {$IFDEF ENABLE_HOLMES}
4194 g_Holmes_DrawUI();
4195 {$ENDIF}
4197 // blit framebuffer to screen
4199 e_SetRendertarget(False);
4200 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4201 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4203 // draw the overlay stuff on top of it
4205 g_Touch_Draw;
4206 end;
4208 procedure g_Game_Quit();
4209 begin
4210 g_Game_StopAllSounds(True);
4211 gMusic.Free();
4212 g_Game_FreeData();
4213 g_PlayerModel_FreeData();
4214 g_Texture_DeleteAll();
4215 g_Frames_DeleteAll();
4216 {$IFNDEF HEADLESS}
4217 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4218 {$ENDIF}
4220 if NetInitDone then g_Net_Free;
4222 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4223 if gMapToDelete <> '' then
4224 g_Game_DeleteTestMap();
4226 gExit := EXIT_QUIT;
4227 sys_RequestQuit;
4228 end;
4230 procedure g_FatalError(Text: String);
4231 begin
4232 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4233 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4235 gExit := EXIT_SIMPLE;
4236 if gGameOn then EndGame;
4237 end;
4239 procedure g_SimpleError(Text: String);
4240 begin
4241 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4242 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4243 end;
4245 procedure g_Game_SetupScreenSize();
4246 const
4247 RES_FACTOR = 4.0 / 3.0;
4248 var
4249 s: Single;
4250 rf: Single;
4251 bw, bh: Word;
4252 begin
4253 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4254 gPlayerScreenSize.X := gScreenWidth-196;
4255 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4256 gPlayerScreenSize.Y := gScreenHeight div 2
4257 else
4258 gPlayerScreenSize.Y := gScreenHeight;
4260 // Ðàçìåð çàäíåãî ïëàíà:
4261 if BackID <> DWORD(-1) then
4262 begin
4263 s := SKY_STRETCH;
4264 if (gScreenWidth*s > gMapInfo.Width) or
4265 (gScreenHeight*s > gMapInfo.Height) then
4266 begin
4267 gBackSize.X := gScreenWidth;
4268 gBackSize.Y := gScreenHeight;
4269 end
4270 else
4271 begin
4272 e_GetTextureSize(BackID, @bw, @bh);
4273 rf := Single(bw) / Single(bh);
4274 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4275 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4276 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4277 if (s < 1.0) then s := 1.0;
4278 gBackSize.X := Round(bw*s);
4279 gBackSize.Y := Round(bh*s);
4280 end;
4281 end;
4282 end;
4284 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4285 begin
4286 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4287 end;
4289 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4290 begin
4291 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4292 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4293 Exit;
4295 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4296 Exit;
4298 if gPlayer1 = nil then
4299 begin
4300 if g_Game_IsClient then
4301 begin
4302 if NetPlrUID1 > -1 then
4303 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4304 Exit;
4305 end;
4307 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4308 Team := gPlayer1Settings.Team;
4310 // Ñîçäàíèå ïåðâîãî èãðîêà:
4311 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4312 gPlayer1Settings.Color,
4313 Team, False));
4314 if gPlayer1 = nil then
4315 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4316 else
4317 begin
4318 gPlayer1.Name := gPlayer1Settings.Name;
4319 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4320 if g_Game_IsServer and g_Game_IsNet then
4321 MH_SEND_PlayerCreate(gPlayer1.UID);
4322 gPlayer1.Respawn(False, True);
4323 g_Net_Slist_ServerPlayerComes();
4324 end;
4326 Exit;
4327 end;
4328 if gPlayer2 = nil then
4329 begin
4330 if g_Game_IsClient then
4331 begin
4332 if NetPlrUID2 > -1 then
4333 gPlayer2 := g_Player_Get(NetPlrUID2);
4334 Exit;
4335 end;
4337 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4338 Team := gPlayer2Settings.Team;
4340 // Ñîçäàíèå âòîðîãî èãðîêà:
4341 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4342 gPlayer2Settings.Color,
4343 Team, False));
4344 if gPlayer2 = nil then
4345 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4346 else
4347 begin
4348 gPlayer2.Name := gPlayer2Settings.Name;
4349 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4350 if g_Game_IsServer and g_Game_IsNet then
4351 MH_SEND_PlayerCreate(gPlayer2.UID);
4352 gPlayer2.Respawn(False, True);
4353 g_Net_Slist_ServerPlayerComes();
4354 end;
4356 Exit;
4357 end;
4358 end;
4360 procedure g_Game_RemovePlayer();
4361 var
4362 Pl: TPlayer;
4363 begin
4364 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4365 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4366 Exit;
4367 Pl := gPlayer2;
4368 if Pl <> nil then
4369 begin
4370 if g_Game_IsServer then
4371 begin
4372 Pl.Lives := 0;
4373 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4374 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4375 g_Player_Remove(Pl.UID);
4376 g_Net_Slist_ServerPlayerLeaves();
4377 end
4378 else
4379 begin
4380 gSpectLatchPID2 := Pl.UID;
4381 gPlayer2 := nil;
4382 end;
4383 Exit;
4384 end;
4385 Pl := gPlayer1;
4386 if Pl <> nil then
4387 begin
4388 if g_Game_IsServer then
4389 begin
4390 Pl.Lives := 0;
4391 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4392 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4393 g_Player_Remove(Pl.UID);
4394 g_Net_Slist_ServerPlayerLeaves();
4395 end else
4396 begin
4397 gSpectLatchPID1 := Pl.UID;
4398 gPlayer1 := nil;
4399 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4400 end;
4401 Exit;
4402 end;
4403 g_Net_Slist_ServerPlayerLeaves();
4404 end;
4406 procedure g_Game_Spectate();
4407 begin
4408 g_Game_RemovePlayer();
4409 if gPlayer1 <> nil then
4410 g_Game_RemovePlayer();
4411 end;
4413 procedure g_Game_SpectateCenterView();
4414 begin
4415 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4416 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4417 end;
4419 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4420 var
4421 i, nPl: Integer;
4422 tmps: AnsiString;
4423 begin
4424 g_Game_Free();
4426 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4428 g_Game_ClearLoading();
4430 // Íàñòðîéêè èãðû:
4431 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4432 gAimLine := False;
4433 gShowMap := False;
4434 gGameSettings.GameType := GT_SINGLE;
4435 gGameSettings.MaxLives := 0;
4436 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4437 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4438 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4439 gSwitchGameMode := GM_SINGLE;
4441 gLMSRespawn := LMS_RESPAWN_NONE;
4442 gLMSRespawnTime := 0;
4443 gSpectLatchPID1 := 0;
4444 gSpectLatchPID2 := 0;
4446 g_Game_ExecuteEvent('ongamestart');
4448 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4449 g_Game_SetupScreenSize();
4451 // Ñîçäàíèå ïåðâîãî èãðîêà:
4452 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4453 gPlayer1Settings.Color,
4454 gPlayer1Settings.Team, False));
4455 if gPlayer1 = nil then
4456 begin
4457 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4458 Exit;
4459 end;
4461 gPlayer1.Name := gPlayer1Settings.Name;
4462 nPl := 1;
4464 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4465 if TwoPlayers then
4466 begin
4467 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4468 gPlayer2Settings.Color,
4469 gPlayer2Settings.Team, False));
4470 if gPlayer2 = nil then
4471 begin
4472 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4473 Exit;
4474 end;
4476 gPlayer2.Name := gPlayer2Settings.Name;
4477 Inc(nPl);
4478 end;
4480 // Çàãðóçêà è çàïóñê êàðòû:
4481 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4482 begin
4483 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4484 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4485 Exit;
4486 end;
4488 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4489 g_Player_Init();
4491 // Ñîçäàåì áîòîâ:
4492 for i := nPl+1 to nPlayers do
4493 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4494 end;
4496 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4497 TimeLimit, GoalLimit: Word;
4498 MaxLives: Byte;
4499 Options: LongWord; nPlayers: Byte);
4500 var
4501 i, nPl: Integer;
4502 begin
4503 g_Game_Free();
4505 e_WriteLog('Starting custom game...', TMsgType.Notify);
4507 g_Game_ClearLoading();
4509 // Íàñòðîéêè èãðû:
4510 gGameSettings.GameType := GT_CUSTOM;
4511 gGameSettings.GameMode := GameMode;
4512 gSwitchGameMode := GameMode;
4513 gGameSettings.TimeLimit := TimeLimit;
4514 gGameSettings.GoalLimit := GoalLimit;
4515 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4516 gGameSettings.Options := Options;
4518 gCoopTotalMonstersKilled := 0;
4519 gCoopTotalSecretsFound := 0;
4520 gCoopTotalMonsters := 0;
4521 gCoopTotalSecrets := 0;
4522 gAimLine := False;
4523 gShowMap := False;
4525 gLMSRespawn := LMS_RESPAWN_NONE;
4526 gLMSRespawnTime := 0;
4527 gSpectLatchPID1 := 0;
4528 gSpectLatchPID2 := 0;
4530 g_Game_ExecuteEvent('ongamestart');
4532 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4533 g_Game_SetupScreenSize();
4535 // Ðåæèì íàáëþäàòåëÿ:
4536 if nPlayers = 0 then
4537 begin
4538 gPlayer1 := nil;
4539 gPlayer2 := nil;
4540 end;
4542 nPl := 0;
4543 if nPlayers >= 1 then
4544 begin
4545 // Ñîçäàíèå ïåðâîãî èãðîêà:
4546 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4547 gPlayer1Settings.Color,
4548 gPlayer1Settings.Team, False));
4549 if gPlayer1 = nil then
4550 begin
4551 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4552 Exit;
4553 end;
4555 gPlayer1.Name := gPlayer1Settings.Name;
4556 Inc(nPl);
4557 end;
4559 if nPlayers >= 2 then
4560 begin
4561 // Ñîçäàíèå âòîðîãî èãðîêà:
4562 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4563 gPlayer2Settings.Color,
4564 gPlayer2Settings.Team, False));
4565 if gPlayer2 = nil then
4566 begin
4567 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4568 Exit;
4569 end;
4571 gPlayer2.Name := gPlayer2Settings.Name;
4572 Inc(nPl);
4573 end;
4575 // Çàãðóçêà è çàïóñê êàðòû:
4576 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4577 begin
4578 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4579 Exit;
4580 end;
4582 // Íåò òî÷åê ïîÿâëåíèÿ:
4583 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4584 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4585 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4586 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4587 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4588 begin
4589 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4590 Exit;
4591 end;
4593 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4594 g_Player_Init();
4596 // Ñîçäàåì áîòîâ:
4597 for i := nPl+1 to nPlayers do
4598 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4599 end;
4601 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4602 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4603 Options: LongWord; nPlayers: Byte;
4604 IPAddr: LongWord; Port: Word);
4605 begin
4606 g_Game_Free();
4607 g_Net_Slist_ServerClosed();
4609 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4611 g_Game_ClearLoading();
4613 // Íàñòðîéêè èãðû:
4614 gGameSettings.GameType := GT_SERVER;
4615 gGameSettings.GameMode := GameMode;
4616 gSwitchGameMode := GameMode;
4617 gGameSettings.TimeLimit := TimeLimit;
4618 gGameSettings.GoalLimit := GoalLimit;
4619 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4620 gGameSettings.Options := Options;
4622 gCoopTotalMonstersKilled := 0;
4623 gCoopTotalSecretsFound := 0;
4624 gCoopTotalMonsters := 0;
4625 gCoopTotalSecrets := 0;
4626 gAimLine := False;
4627 gShowMap := False;
4629 gLMSRespawn := LMS_RESPAWN_NONE;
4630 gLMSRespawnTime := 0;
4631 gSpectLatchPID1 := 0;
4632 gSpectLatchPID2 := 0;
4634 g_Game_ExecuteEvent('ongamestart');
4636 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4637 g_Game_SetupScreenSize();
4639 // Ðåæèì íàáëþäàòåëÿ:
4640 if nPlayers = 0 then
4641 begin
4642 gPlayer1 := nil;
4643 gPlayer2 := nil;
4644 end;
4646 if nPlayers >= 1 then
4647 begin
4648 // Ñîçäàíèå ïåðâîãî èãðîêà:
4649 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4650 gPlayer1Settings.Color,
4651 gPlayer1Settings.Team, False));
4652 if gPlayer1 = nil then
4653 begin
4654 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4655 Exit;
4656 end;
4658 gPlayer1.Name := gPlayer1Settings.Name;
4659 end;
4661 if nPlayers >= 2 then
4662 begin
4663 // Ñîçäàíèå âòîðîãî èãðîêà:
4664 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4665 gPlayer2Settings.Color,
4666 gPlayer2Settings.Team, False));
4667 if gPlayer2 = nil then
4668 begin
4669 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4670 Exit;
4671 end;
4673 gPlayer2.Name := gPlayer2Settings.Name;
4674 end;
4676 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4677 if NetForwardPorts then
4678 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4680 // Ñòàðòóåì ñåðâåð
4681 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4682 begin
4683 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4684 Exit;
4685 end;
4687 g_Net_Slist_Set(NetMasterList);
4689 g_Net_Slist_ServerStarted();
4691 // Çàãðóçêà è çàïóñê êàðòû:
4692 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4693 begin
4694 g_Net_Slist_ServerClosed();
4695 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4696 Exit;
4697 end;
4699 // Íåò òî÷åê ïîÿâëåíèÿ:
4700 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4701 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4702 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4703 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4704 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4705 begin
4706 g_Net_Slist_ServerClosed();
4707 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4708 Exit;
4709 end;
4711 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4712 g_Player_Init();
4714 g_Net_Slist_ServerMapStarted();
4715 NetState := NET_STATE_GAME;
4716 end;
4718 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4719 var
4720 Map: String;
4721 WadName: string;
4722 Ptr: Pointer;
4723 T: Cardinal;
4724 MID: Byte;
4725 State: Byte;
4726 OuterLoop: Boolean;
4727 newResPath: string;
4728 InMsg: TMsg;
4729 begin
4730 g_Game_Free();
4732 State := 0;
4733 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4734 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4736 g_Game_ClearLoading();
4738 // Íàñòðîéêè èãðû:
4739 gGameSettings.GameType := GT_CLIENT;
4741 gCoopTotalMonstersKilled := 0;
4742 gCoopTotalSecretsFound := 0;
4743 gCoopTotalMonsters := 0;
4744 gCoopTotalSecrets := 0;
4745 gAimLine := False;
4746 gShowMap := False;
4748 g_Game_ExecuteEvent('ongamestart');
4750 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4751 g_Game_SetupScreenSize();
4753 NetState := NET_STATE_AUTH;
4755 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4757 // create (or update) map/resource databases
4758 g_Res_CreateDatabases(true);
4760 gLMSRespawn := LMS_RESPAWN_NONE;
4761 gLMSRespawnTime := 0;
4762 gSpectLatchPID1 := 0;
4763 gSpectLatchPID2 := 0;
4765 // Ñòàðòóåì êëèåíò
4766 if not g_Net_Connect(Addr, Port) then
4767 begin
4768 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4769 NetState := NET_STATE_NONE;
4770 Exit;
4771 end;
4773 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4774 MC_SEND_Info(PW);
4775 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4777 OuterLoop := True;
4778 while OuterLoop do
4779 begin
4780 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4781 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4782 // thank you, enet. let's ignore failures altogether then.
4783 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4784 begin
4785 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4786 begin
4787 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
4788 begin
4789 // ignore all download packets, they're processed by separate code
4790 enet_packet_destroy(NetEvent.packet);
4791 continue;
4792 end;
4793 Ptr := NetEvent.packet^.data;
4794 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4795 begin
4796 enet_packet_destroy(NetEvent.packet);
4797 continue;
4798 end;
4800 InMsg.ReadLongWord(); // skip size
4801 MID := InMsg.ReadByte();
4803 if (MID = NET_MSG_INFO) and (State = 0) then
4804 begin
4805 NetMyID := InMsg.ReadByte();
4806 NetPlrUID1 := InMsg.ReadWord();
4808 WadName := InMsg.ReadString();
4809 Map := InMsg.ReadString();
4811 gWADHash := InMsg.ReadMD5();
4813 gGameSettings.GameMode := InMsg.ReadByte();
4814 gSwitchGameMode := gGameSettings.GameMode;
4815 gGameSettings.GoalLimit := InMsg.ReadWord();
4816 gGameSettings.TimeLimit := InMsg.ReadWord();
4817 gGameSettings.MaxLives := InMsg.ReadByte();
4818 gGameSettings.Options := InMsg.ReadLongWord();
4819 T := InMsg.ReadLongWord();
4821 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4822 //if newResPath = '' then
4823 begin
4824 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4825 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4826 if newResPath = '' then
4827 begin
4828 g_FatalError(_lc[I_NET_ERR_HASH]);
4829 enet_packet_destroy(NetEvent.packet);
4830 NetState := NET_STATE_NONE;
4831 Exit;
4832 end;
4833 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4834 end;
4835 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4838 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4839 gPlayer1Settings.Color,
4840 gPlayer1Settings.Team, False));
4842 if gPlayer1 = nil then
4843 begin
4844 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4846 enet_packet_destroy(NetEvent.packet);
4847 NetState := NET_STATE_NONE;
4848 Exit;
4849 end;
4851 gPlayer1.Name := gPlayer1Settings.Name;
4852 gPlayer1.UID := NetPlrUID1;
4853 gPlayer1.Reset(True);
4855 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4856 begin
4857 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4859 enet_packet_destroy(NetEvent.packet);
4860 NetState := NET_STATE_NONE;
4861 Exit;
4862 end;
4864 gTime := T;
4866 State := 1;
4867 OuterLoop := False;
4868 enet_packet_destroy(NetEvent.packet);
4869 break;
4870 end
4871 else
4872 enet_packet_destroy(NetEvent.packet);
4873 end
4874 else
4875 begin
4876 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4877 begin
4878 State := 0;
4879 if (NetEvent.data <= NET_DISC_MAX) then
4880 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4881 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4882 OuterLoop := False;
4883 Break;
4884 end;
4885 end;
4886 end;
4888 ProcessLoading(true);
4890 if g_Net_UserRequestExit() then
4891 begin
4892 State := 0;
4893 break;
4894 end;
4895 end;
4897 if State <> 1 then
4898 begin
4899 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4900 NetState := NET_STATE_NONE;
4901 Exit;
4902 end;
4904 g_Player_Init();
4905 NetState := NET_STATE_GAME;
4906 MC_SEND_FullStateRequest;
4907 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4908 end;
4910 var
4911 lastAsMegaWad: Boolean = false;
4913 procedure g_Game_ChangeMap(const MapPath: String);
4914 var
4915 Force: Boolean;
4916 begin
4917 g_Game_ClearLoading();
4919 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4920 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4921 if gExitByTrigger then
4922 begin
4923 Force := False;
4924 gExitByTrigger := False;
4925 end;
4926 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
4927 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4928 end;
4930 procedure g_Game_Restart();
4931 var
4932 Map: string;
4933 begin
4934 if g_Game_IsClient then
4935 Exit;
4936 map := g_ExtractFileName(gMapInfo.Map);
4937 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
4939 MessageTime := 0;
4940 gGameOn := False;
4941 g_Game_ClearLoading();
4942 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
4943 end;
4945 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4946 var
4947 NewWAD, ResName: String;
4948 I: Integer;
4949 nws: AnsiString;
4950 begin
4951 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4952 g_Player_RemoveAllCorpses();
4954 if (not g_Game_IsClient) and
4955 (gSwitchGameMode <> gGameSettings.GameMode) and
4956 (gGameSettings.GameMode <> GM_SINGLE) then
4957 begin
4958 if gSwitchGameMode = GM_CTF then
4959 gGameSettings.MaxLives := 0;
4960 gGameSettings.GameMode := gSwitchGameMode;
4961 Force := True;
4962 end else
4963 gSwitchGameMode := gGameSettings.GameMode;
4965 g_Player_ResetTeams();
4967 lastAsMegaWad := asMegawad;
4968 if isWadPath(Map) then
4969 begin
4970 NewWAD := g_ExtractWadName(Map);
4971 ResName := g_ExtractFileName(Map);
4972 if g_Game_IsServer then
4973 begin
4974 nws := findDiskWad(NewWAD);
4975 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4976 if (asMegawad) then
4977 begin
4978 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4979 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4980 end
4981 else
4982 begin
4983 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4984 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4985 end;
4986 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4987 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4988 //nws := NewWAD;
4989 if (length(nws) = 0) then
4990 begin
4991 ResName := ''; // failed
4992 end
4993 else
4994 begin
4995 NewWAD := nws;
4996 if (g_Game_IsNet) then gWADHash := MD5File(nws);
4997 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4998 g_Game_LoadWAD(NewWAD);
4999 end;
5000 end
5001 else
5002 begin
5003 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5004 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5005 end;
5006 end
5007 else
5008 begin
5009 NewWAD := gGameSettings.WAD;
5010 ResName := Map;
5011 end;
5013 gTime := 0;
5015 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5016 result := false;
5017 if (ResName <> '') and (NewWAD <> '') then
5018 begin
5019 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5020 result := g_Map_Load(NewWAD+':\'+ResName);
5021 end;
5022 if Result then
5023 begin
5024 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5026 gState := STATE_NONE;
5027 g_ActiveWindow := nil;
5028 gGameOn := True;
5030 DisableCheats();
5031 ResetTimer();
5033 if gGameSettings.GameMode = GM_CTF then
5034 begin
5035 g_Map_ResetFlag(FLAG_RED);
5036 g_Map_ResetFlag(FLAG_BLUE);
5037 // CTF, à ôëàãîâ íåò:
5038 if not g_Map_HaveFlagPoints() then
5039 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5040 end;
5041 end
5042 else
5043 begin
5044 gState := STATE_MENU;
5045 gGameOn := False;
5046 end;
5048 gExit := 0;
5049 gPauseMain := false;
5050 gPauseHolmes := false;
5051 NetTimeToUpdate := 1;
5052 NetTimeToReliable := 0;
5053 NetTimeToMaster := NetMasterRate;
5054 gSpectLatchPID1 := 0;
5055 gSpectLatchPID2 := 0;
5056 gMissionFailed := False;
5057 gNextMap := '';
5059 gCoopMonstersKilled := 0;
5060 gCoopSecretsFound := 0;
5062 gVoteInProgress := False;
5063 gVotePassed := False;
5064 gVoteCount := 0;
5065 gVoted := False;
5067 gStatsOff := False;
5069 if not gGameOn then Exit;
5071 g_Game_SpectateCenterView();
5073 if g_Game_IsServer then
5074 begin
5075 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5076 begin
5077 gLMSRespawn := LMS_RESPAWN_WARMUP;
5078 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5079 gLMSSoftSpawn := True;
5080 if g_Game_IsNet then
5081 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5082 end
5083 else
5084 begin
5085 gLMSRespawn := LMS_RESPAWN_NONE;
5086 gLMSRespawnTime := 0;
5087 end;
5088 end;
5090 if NetMode = NET_SERVER then
5091 begin
5092 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5094 // Ìàñòåðñåðâåð
5095 g_Net_Slist_ServerMapStarted();
5097 if NetClients <> nil then
5098 for I := 0 to High(NetClients) do
5099 if NetClients[I].Used then
5100 begin
5101 NetClients[I].Voted := False;
5102 if NetClients[I].RequestedFullUpdate then
5103 begin
5104 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5105 NetClients[I].RequestedFullUpdate := False;
5106 end;
5107 end;
5109 g_Net_UnbanNonPermHosts();
5110 end;
5112 if gLastMap then
5113 begin
5114 gCoopTotalMonstersKilled := 0;
5115 gCoopTotalSecretsFound := 0;
5116 gCoopTotalMonsters := 0;
5117 gCoopTotalSecrets := 0;
5118 gLastMap := False;
5119 end;
5121 g_Game_ExecuteEvent('onmapstart');
5122 end;
5124 procedure SetFirstLevel;
5125 begin
5126 gNextMap := '';
5128 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5129 if MapList = nil then
5130 Exit;
5132 SortSArray(MapList);
5133 gNextMap := MapList[Low(MapList)];
5135 MapList := nil;
5136 end;
5138 procedure g_Game_ExitLevel(const Map: AnsiString);
5139 begin
5140 gNextMap := Map;
5142 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5143 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5144 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5145 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5147 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5148 if gGameSettings.GameType = GT_SINGLE then
5149 gExit := EXIT_ENDLEVELSINGLE
5150 else // Âûøëè â âûõîä â Ñâîåé èãðå
5151 begin
5152 gExit := EXIT_ENDLEVELCUSTOM;
5153 if gGameSettings.GameMode = GM_COOP then
5154 g_Player_RememberAll;
5156 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5157 begin
5158 gLastMap := True;
5159 if gGameSettings.GameMode = GM_COOP then
5160 gStatsOff := True;
5162 gStatsPressed := True;
5163 gNextMap := 'MAP01';
5165 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5166 g_Game_NextLevel;
5168 if g_Game_IsNet then
5169 begin
5170 MH_SEND_GameStats();
5171 MH_SEND_CoopStats();
5172 end;
5173 end;
5174 end;
5175 end;
5177 procedure g_Game_RestartLevel();
5178 var
5179 Map: string;
5180 begin
5181 if gGameSettings.GameMode = GM_SINGLE then
5182 begin
5183 g_Game_Restart();
5184 Exit;
5185 end;
5186 gExit := EXIT_ENDLEVELCUSTOM;
5187 Map := g_ExtractFileName(gMapInfo.Map);
5188 gNextMap := Map;
5189 end;
5191 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5192 var
5193 gWAD{, xwad}: String;
5194 begin
5195 result := NewWAD;
5196 if not g_Game_IsClient then Exit;
5197 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5199 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5200 if gWAD = '' then
5201 begin
5202 result := '';
5203 g_Game_Free();
5204 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5205 Exit;
5206 end;
5208 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5209 NewWAD := gWAD;
5211 g_Game_LoadWAD(NewWAD);
5212 result := NewWAD;
5215 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5216 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5217 if gWAD = '' then
5218 begin
5219 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5220 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5221 if gWAD = '' then
5222 begin
5223 g_Game_Free();
5224 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5225 Exit;
5226 end;
5227 end;
5228 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5229 g_Game_LoadWAD(NewWAD);
5231 end;
5233 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5234 var
5235 i, n, nb, nr: Integer;
5236 begin
5237 if not g_Game_IsServer then Exit;
5238 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5239 gLMSRespawn := LMS_RESPAWN_NONE;
5240 gLMSRespawnTime := 0;
5241 MessageTime := 0;
5243 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5244 begin
5245 gMissionFailed := True;
5246 g_Game_RestartLevel;
5247 Exit;
5248 end;
5250 n := 0; nb := 0; nr := 0;
5251 for i := Low(gPlayers) to High(gPlayers) do
5252 if (gPlayers[i] <> nil) and
5253 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5254 (gPlayers[i] is TBot)) then
5255 begin
5256 Inc(n);
5257 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5258 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5259 end;
5261 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5262 begin
5263 // wait a second until the fuckers finally decide to join
5264 gLMSRespawn := LMS_RESPAWN_WARMUP;
5265 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5266 gLMSSoftSpawn := NoMapRestart;
5267 if g_Game_IsNet then
5268 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5269 Exit;
5270 end;
5272 g_Player_RemoveAllCorpses;
5273 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5274 if g_Game_IsNet then
5275 MH_SEND_GameEvent(NET_EV_LMS_START);
5277 for i := Low(gPlayers) to High(gPlayers) do
5278 begin
5279 if gPlayers[i] = nil then continue;
5280 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5281 // don't touch normal spectators
5282 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5283 begin
5284 gPlayers[i].FNoRespawn := True;
5285 gPlayers[i].Lives := 0;
5286 if g_Game_IsNet then
5287 MH_SEND_PlayerStats(gPlayers[I].UID);
5288 continue;
5289 end;
5290 gPlayers[i].FNoRespawn := False;
5291 gPlayers[i].Lives := gGameSettings.MaxLives;
5292 gPlayers[i].Respawn(False, True);
5293 if gGameSettings.GameMode = GM_COOP then
5294 begin
5295 gPlayers[i].Frags := 0;
5296 gPlayers[i].RecallState;
5297 end;
5298 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5299 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5300 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5301 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5302 end;
5304 g_Items_RestartRound();
5306 gLMSSoftSpawn := False;
5307 end;
5309 function g_Game_GetFirstMap(WAD: String): String;
5310 begin
5311 Result := '';
5313 MapList := g_Map_GetMapsList(WAD);
5314 if MapList = nil then
5315 Exit;
5317 SortSArray(MapList);
5318 Result := MapList[Low(MapList)];
5320 if not g_Map_Exist(WAD + ':\' + Result) then
5321 Result := '';
5323 MapList := nil;
5324 end;
5326 function g_Game_GetNextMap(): String;
5327 var
5328 I: Integer;
5329 Map: string;
5330 begin
5331 Result := '';
5333 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5334 if MapList = nil then
5335 Exit;
5337 Map := g_ExtractFileName(gMapInfo.Map);
5339 SortSArray(MapList);
5340 MapIndex := -255;
5341 for I := Low(MapList) to High(MapList) do
5342 if Map = MapList[I] then
5343 begin
5344 MapIndex := I;
5345 Break;
5346 end;
5348 if MapIndex <> -255 then
5349 begin
5350 if MapIndex = High(MapList) then
5351 Result := MapList[Low(MapList)]
5352 else
5353 Result := MapList[MapIndex + 1];
5355 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5356 end;
5358 MapList := nil;
5359 end;
5361 procedure g_Game_NextLevel();
5362 begin
5363 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5364 gExit := EXIT_ENDLEVELCUSTOM
5365 else
5366 begin
5367 gExit := EXIT_ENDLEVELSINGLE;
5368 Exit;
5369 end;
5371 if gNextMap <> '' then Exit;
5372 gNextMap := g_Game_GetNextMap();
5373 end;
5375 function g_Game_IsTestMap(): Boolean;
5376 begin
5377 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5378 end;
5380 procedure g_Game_DeleteTestMap();
5381 var
5382 a: Integer;
5383 //MapName: AnsiString;
5384 WadName: string;
5386 WAD: TWADFile;
5387 MapList: SSArray;
5388 time: Integer;
5390 begin
5391 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5392 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5393 if (a = 0) then exit;
5395 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5396 WadName := Copy(gMapToDelete, 1, a+3);
5397 Delete(gMapToDelete, 1, a+5);
5398 gMapToDelete := UpperCase(gMapToDelete);
5399 //MapName := '';
5400 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5403 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5404 if MapName <> TEST_MAP_NAME then
5405 Exit;
5407 if not gTempDelete then
5408 begin
5409 time := g_GetFileTime(WadName);
5410 WAD := TWADFile.Create();
5412 // ×èòàåì Wad-ôàéë:
5413 if not WAD.ReadFile(WadName) then
5414 begin // Íåò òàêîãî WAD-ôàéëà
5415 WAD.Free();
5416 Exit;
5417 end;
5419 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5420 WAD.CreateImage();
5421 MapList := WAD.GetResourcesList('');
5423 if MapList <> nil then
5424 for a := 0 to High(MapList) do
5425 if MapList[a] = MapName then
5426 begin
5427 // Óäàëÿåì è ñîõðàíÿåì:
5428 WAD.RemoveResource('', MapName);
5429 WAD.SaveTo(WadName);
5430 Break;
5431 end;
5433 WAD.Free();
5434 g_SetFileTime(WadName, time);
5435 end else
5437 if gTempDelete then DeleteFile(WadName);
5438 end;
5440 procedure GameCVars(P: SSArray);
5441 var
5442 a, b: Integer;
5443 stat: TPlayerStatArray;
5444 cmd: string;
5446 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5447 var
5448 x: Boolean;
5449 begin
5450 if Length(P) > 1 then
5451 begin
5452 x := P[1] = '1';
5454 if x then
5455 gsGameFlags := gsGameFlags or Flag
5456 else
5457 gsGameFlags := gsGameFlags and (not Flag);
5459 if g_Game_IsServer then
5460 begin
5461 if x then
5462 gGameSettings.Options := gGameSettings.Options or Flag
5463 else
5464 gGameSettings.Options := gGameSettings.Options and (not Flag);
5465 if g_Game_IsNet then MH_SEND_GameSettings;
5466 end;
5467 end;
5469 if LongBool(gsGameFlags and Flag) then
5470 g_Console_Add(_lc[OnMsg])
5471 else
5472 g_Console_Add(_lc[OffMsg]);
5474 if OnMapChange and g_Game_IsServer then
5475 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5476 end;
5478 begin
5479 stat := nil;
5480 cmd := LowerCase(P[0]);
5482 if cmd = 'g_gamemode' then
5483 begin
5484 if (Length(P) > 1) then
5485 begin
5486 a := g_Game_TextToMode(P[1]);
5487 if a = GM_SINGLE then a := GM_COOP;
5488 gsGameMode := g_Game_ModeToText(a);
5489 if g_Game_IsServer then
5490 begin
5491 gSwitchGameMode := a;
5492 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5493 (gState = STATE_INTERSINGLE) then
5494 gSwitchGameMode := GM_SINGLE;
5495 if not gGameOn then
5496 gGameSettings.GameMode := gSwitchGameMode;
5497 end;
5498 end;
5500 if gSwitchGameMode = gGameSettings.GameMode then
5501 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5502 [g_Game_ModeToText(gGameSettings.GameMode)]))
5503 else
5504 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5505 [g_Game_ModeToText(gGameSettings.GameMode),
5506 g_Game_ModeToText(gSwitchGameMode)]));
5507 end
5508 else if cmd = 'g_friendlyfire' then
5509 begin
5510 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5511 end
5512 else if cmd = 'g_weaponstay' then
5513 begin
5514 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5515 end
5516 else if cmd = 'g_allow_exit' then
5517 begin
5518 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5519 end
5520 else if cmd = 'g_allow_monsters' then
5521 begin
5522 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5523 end
5524 else if cmd = 'g_bot_vsplayers' then
5525 begin
5526 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5527 end
5528 else if cmd = 'g_bot_vsmonsters' then
5529 begin
5530 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5531 end
5532 else if cmd = 'g_dm_keys' then
5533 begin
5534 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5535 end
5536 else if cmd = 'g_gameflags' then
5537 begin
5538 if Length(P) > 1 then
5539 begin
5540 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5541 if g_Game_IsServer then
5542 begin
5543 gGameSettings.Options := gsGameFlags;
5544 if g_Game_IsNet then MH_SEND_GameSettings;
5545 end;
5546 end;
5548 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5549 end
5550 else if cmd = 'g_warmup_time' then
5551 begin
5552 if Length(P) > 1 then
5553 begin
5554 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5555 if g_Game_IsServer then
5556 begin
5557 gGameSettings.WarmupTime := gsWarmupTime;
5558 // extend warmup if it's already going
5559 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5560 begin
5561 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5562 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5563 end;
5564 if g_Game_IsNet then MH_SEND_GameSettings;
5565 end;
5566 end;
5568 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5569 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5570 end
5571 else if cmd = 'g_spawn_invul' then
5572 begin
5573 if Length(P) > 1 then
5574 begin
5575 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5576 if g_Game_IsServer then
5577 begin
5578 gGameSettings.SpawnInvul := gsSpawnInvul;
5579 if g_Game_IsNet then MH_SEND_GameSettings;
5580 end;
5581 end;
5583 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5584 end
5585 else if cmd = 'g_item_respawn_time' then
5586 begin
5587 if Length(P) > 1 then
5588 begin
5589 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5590 if g_Game_IsServer then
5591 begin
5592 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5593 if g_Game_IsNet then MH_SEND_GameSettings;
5594 end;
5595 end;
5597 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5598 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5599 end
5600 else if cmd = 'sv_intertime' then
5601 begin
5602 if (Length(P) > 1) then
5603 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5605 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5606 end
5607 else if cmd = 'g_max_particles' then
5608 begin
5609 if Length(p) = 2 then
5610 begin
5611 a := Max(0, StrToInt(p[1]));
5612 g_GFX_SetMax(a)
5613 end
5614 else if Length(p) = 1 then
5615 begin
5616 e_LogWritefln('%s', [g_GFX_GetMax()])
5617 end
5618 else
5619 begin
5620 e_LogWritefln('usage: %s <n>', [cmd])
5621 end
5622 end
5623 else if cmd = 'g_max_shells' then
5624 begin
5625 if Length(p) = 2 then
5626 begin
5627 a := Max(0, StrToInt(p[1]));
5628 g_Shells_SetMax(a)
5629 end
5630 else if Length(p) = 1 then
5631 begin
5632 e_LogWritefln('%s', [g_Shells_GetMax()])
5633 end
5634 else
5635 begin
5636 e_LogWritefln('usage: %s <n>', [cmd])
5637 end
5638 end
5639 else if cmd = 'g_max_gibs' then
5640 begin
5641 if Length(p) = 2 then
5642 begin
5643 a := Max(0, StrToInt(p[1]));
5644 g_Gibs_SetMax(a)
5645 end
5646 else if Length(p) = 1 then
5647 begin
5648 e_LogWritefln('%s', [g_Gibs_GetMax()])
5649 end
5650 else
5651 begin
5652 e_LogWritefln('usage: %s <n>', [cmd])
5653 end
5654 end
5655 else if cmd = 'g_max_corpses' then
5656 begin
5657 if Length(p) = 2 then
5658 begin
5659 a := Max(0, StrToInt(p[1]));
5660 g_Corpses_SetMax(a)
5661 end
5662 else if Length(p) = 1 then
5663 begin
5664 e_LogWritefln('%s', [g_Corpses_GetMax()])
5665 end
5666 else
5667 begin
5668 e_LogWritefln('usage: %s <n>', [cmd])
5669 end
5670 end
5671 else if cmd = 'g_scorelimit' then
5672 begin
5673 if Length(P) > 1 then
5674 begin
5675 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
5677 if g_Game_IsServer then
5678 begin
5679 b := 0;
5680 if gGameSettings.GameMode = GM_DM then
5681 begin // DM
5682 stat := g_Player_GetStats();
5683 if stat <> nil then
5684 for a := 0 to High(stat) do
5685 if stat[a].Frags > b then
5686 b := stat[a].Frags;
5687 end
5688 else // TDM/CTF
5689 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5691 // if someone has a higher score, set it to that instead
5692 gsGoalLimit := max(gsGoalLimit, b);
5693 gGameSettings.GoalLimit := gsGoalLimit;
5695 if g_Game_IsNet then MH_SEND_GameSettings;
5696 end;
5697 end;
5699 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
5700 end
5701 else if cmd = 'g_timelimit' then
5702 begin
5703 if Length(P) > 1 then
5704 begin
5705 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5706 if g_Game_IsServer then
5707 begin
5708 gGameSettings.TimeLimit := gsTimeLimit;
5709 if g_Game_IsNet then MH_SEND_GameSettings;
5710 end;
5711 end;
5712 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5713 [gsTimeLimit div 3600,
5714 (gsTimeLimit div 60) mod 60,
5715 gsTimeLimit mod 60]));
5716 end
5717 else if cmd = 'g_maxlives' then
5718 begin
5719 if Length(P) > 1 then
5720 begin
5721 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5722 if g_Game_IsServer then
5723 begin
5724 gGameSettings.MaxLives := gsMaxLives;
5725 if g_Game_IsNet then MH_SEND_GameSettings;
5726 end;
5727 end;
5729 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5730 end;
5731 end;
5733 procedure PlayerSettingsCVars(P: SSArray);
5734 var
5735 cmd: string;
5736 begin
5737 cmd := LowerCase(P[0]);
5738 case cmd of
5739 'p1_name':
5740 begin
5741 if (Length(P) > 1) then
5742 begin
5743 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5744 if g_Game_IsClient then
5745 MC_SEND_PlayerSettings
5746 else if gGameOn and (gPlayer1 <> nil) then
5747 begin
5748 gPlayer1.Name := b_Text_Unformat(P[1]);
5749 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5750 end;
5751 end;
5752 end;
5753 'p2_name':
5754 begin
5755 if (Length(P) > 1) then
5756 begin
5757 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5758 if g_Game_IsClient then
5759 MC_SEND_PlayerSettings
5760 else if gGameOn and (gPlayer2 <> nil) then
5761 begin
5762 gPlayer2.Name := b_Text_Unformat(P[1]);
5763 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5764 end;
5765 end;
5766 end;
5767 'p1_color':
5768 begin
5769 if Length(P) > 3 then
5770 begin
5771 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5772 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5773 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5774 if g_Game_IsClient then
5775 MC_SEND_PlayerSettings
5776 else if gGameOn and (gPlayer1 <> nil) then
5777 begin
5778 gPlayer1.SetColor(gPlayer1Settings.Color);
5779 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5780 end;
5781 end;
5782 end;
5783 'p2_color':
5784 begin
5785 if Length(P) > 3 then
5786 begin
5787 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5788 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5789 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5790 if g_Game_IsClient then
5791 MC_SEND_PlayerSettings
5792 else if gGameOn and (gPlayer2 <> nil) then
5793 begin
5794 gPlayer2.SetColor(gPlayer2Settings.Color);
5795 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5796 end;
5797 end;
5798 end;
5799 'p1_model':
5800 begin
5801 if (Length(P) > 1) then
5802 begin
5803 gPlayer1Settings.Model := P[1];
5804 if g_Game_IsClient then
5805 MC_SEND_PlayerSettings
5806 else if gGameOn and (gPlayer1 <> nil) then
5807 begin
5808 gPlayer1.FActualModelName := gPlayer1Settings.Model;
5809 gPlayer1.SetModel(gPlayer1Settings.Model);
5810 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5811 end;
5812 end;
5813 end;
5814 'p2_model':
5815 begin
5816 if (Length(P) > 1) then
5817 begin
5818 gPlayer2Settings.Model := P[1];
5819 if g_Game_IsClient then
5820 MC_SEND_PlayerSettings
5821 else if gGameOn and (gPlayer2 <> nil) then
5822 begin
5823 gPlayer2.FActualModelName := gPlayer2Settings.Model;
5824 gPlayer2.SetModel(gPlayer2Settings.Model);
5825 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5826 end;
5827 end;
5828 end;
5829 end;
5830 end;
5832 procedure PrintHeapStats();
5833 var
5834 hs: TFPCHeapStatus;
5835 begin
5836 hs := GetFPCHeapStatus();
5837 e_LogWriteLn ('v===== heap status =====v');
5838 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5839 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5840 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5841 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5842 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5843 e_LogWriteLn ('^=======================^');
5844 end;
5846 procedure DebugCommands(P: SSArray);
5847 var
5848 a, b: Integer;
5849 cmd: string;
5850 //pt: TDFPoint;
5851 mon: TMonster;
5852 begin
5853 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5854 if {gDebugMode}conIsCheatsEnabled then
5855 begin
5856 cmd := LowerCase(P[0]);
5857 if cmd = 'd_window' then
5858 begin
5859 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5860 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5861 end
5862 else if cmd = 'd_sounds' then
5863 begin
5864 if (Length(P) > 1) and
5865 ((P[1] = '1') or (P[1] = '0')) then
5866 g_Debug_Sounds := (P[1][1] = '1');
5868 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5869 end
5870 else if cmd = 'd_frames' then
5871 begin
5872 if (Length(P) > 1) and
5873 ((P[1] = '1') or (P[1] = '0')) then
5874 g_Debug_Frames := (P[1][1] = '1');
5876 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5877 end
5878 else if cmd = 'd_winmsg' then
5879 begin
5880 if (Length(P) > 1) and
5881 ((P[1] = '1') or (P[1] = '0')) then
5882 g_Debug_WinMsgs := (P[1][1] = '1');
5884 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5885 end
5886 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5887 begin
5888 if (Length(P) > 1) and
5889 ((P[1] = '1') or (P[1] = '0')) then
5890 g_Debug_MonsterOff := (P[1][1] = '1');
5892 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5893 end
5894 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5895 begin
5896 if Length(P) > 1 then
5897 case P[1][1] of
5898 '0': g_debug_BotAIOff := 0;
5899 '1': g_debug_BotAIOff := 1;
5900 '2': g_debug_BotAIOff := 2;
5901 '3': g_debug_BotAIOff := 3;
5902 end;
5904 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5905 end
5906 else if cmd = 'd_monster' then
5907 begin
5908 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5909 if Length(P) < 2 then
5910 begin
5911 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5912 g_Console_Add('ID | Name');
5913 for b := MONSTER_DEMON to MONSTER_MAN do
5914 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5915 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5916 end else
5917 begin
5918 a := StrToIntDef(P[1], 0);
5919 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5920 a := g_Mons_TypeIdByName(P[1]);
5922 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5923 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5924 else
5925 begin
5926 with gPlayer1.Obj do
5927 begin
5928 mon := g_Monsters_Create(a,
5929 X + Rect.X + (Rect.Width div 2),
5930 Y + Rect.Y + Rect.Height,
5931 gPlayer1.Direction, True);
5932 end;
5933 if (Length(P) > 2) and (mon <> nil) then
5934 begin
5935 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5936 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5937 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5938 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5939 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5940 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5941 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5942 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5943 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5944 end;
5945 end;
5946 end;
5947 end
5948 else if (cmd = 'd_health') then
5949 begin
5950 if (Length(P) > 1) and
5951 ((P[1] = '1') or (P[1] = '0')) then
5952 g_debug_HealthBar := (P[1][1] = '1');
5954 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5955 end
5956 else if (cmd = 'd_player') then
5957 begin
5958 if (Length(P) > 1) and
5959 ((P[1] = '1') or (P[1] = '0')) then
5960 g_debug_Player := (P[1][1] = '1');
5962 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5963 end
5964 else if (cmd = 'd_mem') then
5965 begin
5966 PrintHeapStats();
5967 end;
5968 end
5969 else
5970 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5971 end;
5974 procedure GameCheats(P: SSArray);
5975 var
5976 cmd: string;
5977 f, a: Integer;
5978 plr: TPlayer;
5979 begin
5980 if (not gGameOn) or (not conIsCheatsEnabled) then
5981 begin
5982 g_Console_Add('not available');
5983 exit;
5984 end;
5985 plr := gPlayer1;
5986 if plr = nil then
5987 begin
5988 g_Console_Add('where is the player?!');
5989 exit;
5990 end;
5991 cmd := LowerCase(P[0]);
5992 // god
5993 if cmd = 'god' then
5994 begin
5995 plr.GodMode := not plr.GodMode;
5996 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5997 exit;
5998 end;
5999 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6000 if cmd = 'give' then
6001 begin
6002 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6003 for f := 1 to High(P) do
6004 begin
6005 cmd := LowerCase(P[f]);
6006 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6007 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6008 if cmd = 'exit' then
6009 begin
6010 if gTriggers <> nil then
6011 begin
6012 for a := 0 to High(gTriggers) do
6013 begin
6014 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6015 begin
6016 g_Console_Add('player left the map');
6017 gExitByTrigger := True;
6018 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6019 g_Game_ExitLevel(gTriggers[a].tgcMap);
6020 break;
6021 end;
6022 end;
6023 end;
6024 continue;
6025 end;
6027 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6028 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6029 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6030 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6031 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6033 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6034 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6036 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6037 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;
6039 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6040 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6042 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6043 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6045 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6046 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6048 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6049 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6050 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6052 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6053 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6054 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6055 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;
6056 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6057 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6059 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;
6060 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;
6061 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;
6062 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;
6063 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;
6064 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;
6066 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6067 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;
6069 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;
6070 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;
6072 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6074 if cmd = 'ammo' then
6075 begin
6076 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6077 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6078 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6079 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6080 plr.GiveItem(ITEM_AMMO_FUELCAN);
6081 g_Console_Add('player got some ammo');
6082 continue;
6083 end;
6085 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6086 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6088 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6089 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6091 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6092 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6094 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6095 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6097 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6099 if cmd = 'weapons' then
6100 begin
6101 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6102 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6103 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6104 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6105 plr.GiveItem(ITEM_WEAPON_PLASMA);
6106 plr.GiveItem(ITEM_WEAPON_BFG);
6107 g_Console_Add('player got weapons');
6108 continue;
6109 end;
6111 if cmd = 'keys' then
6112 begin
6113 plr.GiveItem(ITEM_KEY_RED);
6114 plr.GiveItem(ITEM_KEY_GREEN);
6115 plr.GiveItem(ITEM_KEY_BLUE);
6116 g_Console_Add('player got all keys');
6117 continue;
6118 end;
6120 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6121 end;
6122 exit;
6123 end;
6124 // open
6125 if cmd = 'open' then
6126 begin
6127 g_Console_Add('player activated sesame');
6128 g_Triggers_OpenAll();
6129 exit;
6130 end;
6131 // fly
6132 if cmd = 'fly' then
6133 begin
6134 gFly := not gFly;
6135 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6136 exit;
6137 end;
6138 // noclip
6139 if cmd = 'noclip' then
6140 begin
6141 plr.SwitchNoClip;
6142 g_Console_Add('wall hardeness adjusted');
6143 exit;
6144 end;
6145 // notarget
6146 if cmd = 'notarget' then
6147 begin
6148 plr.NoTarget := not plr.NoTarget;
6149 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6150 exit;
6151 end;
6152 // noreload
6153 if cmd = 'noreload' then
6154 begin
6155 plr.NoReload := not plr.NoReload;
6156 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6157 exit;
6158 end;
6159 // speedy
6160 if cmd = 'speedy' then
6161 begin
6162 MAX_RUNVEL := 32-MAX_RUNVEL;
6163 g_Console_Add('speed adjusted');
6164 exit;
6165 end;
6166 // jumpy
6167 if cmd = 'jumpy' then
6168 begin
6169 VEL_JUMP := 30-VEL_JUMP;
6170 g_Console_Add('jump height adjusted');
6171 exit;
6172 end;
6173 // automap
6174 if cmd = 'automap' then
6175 begin
6176 gShowMap := not gShowMap;
6177 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6178 exit;
6179 end;
6180 // aimline
6181 if cmd = 'aimline' then
6182 begin
6183 gAimLine := not gAimLine;
6184 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6185 exit;
6186 end;
6187 end;
6189 procedure GameCommands(P: SSArray);
6190 var
6191 a, b: Integer;
6192 s, pw: String;
6193 chstr: string;
6194 cmd: string;
6195 pl: pTNetClient = nil;
6196 plr: TPlayer;
6197 prt: Word;
6198 nm: Boolean;
6199 listen: LongWord;
6200 found: Boolean;
6201 begin
6202 // Îáùèå êîìàíäû:
6203 cmd := LowerCase(P[0]);
6204 chstr := '';
6205 if cmd = 'pause' then
6206 begin
6207 if (g_ActiveWindow = nil) then
6208 g_Game_Pause(not gPauseMain);
6209 end
6210 else if cmd = 'endgame' then
6211 gExit := EXIT_SIMPLE
6212 else if cmd = 'restart' then
6213 begin
6214 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6215 begin
6216 if g_Game_IsClient then
6217 begin
6218 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6219 Exit;
6220 end;
6221 g_Game_Restart();
6222 end else
6223 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6224 end
6225 else if cmd = 'kick' then
6226 begin
6227 if g_Game_IsServer then
6228 begin
6229 if Length(P) < 2 then
6230 begin
6231 g_Console_Add('kick <name>');
6232 Exit;
6233 end;
6234 if P[1] = '' then
6235 begin
6236 g_Console_Add('kick <name>');
6237 Exit;
6238 end;
6240 if g_Game_IsNet then
6241 pl := g_Net_Client_ByName(P[1]);
6242 if (pl <> nil) then
6243 begin
6244 s := g_Net_ClientName_ByID(pl^.ID);
6245 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6246 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6247 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6248 g_Net_Slist_ServerPlayerLeaves();
6249 end else if gPlayers <> nil then
6250 for a := Low(gPlayers) to High(gPlayers) do
6251 if gPlayers[a] <> nil then
6252 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6253 begin
6254 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6255 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6256 continue;
6257 gPlayers[a].Lives := 0;
6258 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6259 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6260 g_Player_Remove(gPlayers[a].UID);
6261 g_Net_Slist_ServerPlayerLeaves();
6262 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6263 g_Bot_MixNames();
6264 end;
6265 end else
6266 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6267 end
6268 else if cmd = 'kick_id' then
6269 begin
6270 if g_Game_IsServer and g_Game_IsNet then
6271 begin
6272 if Length(P) < 2 then
6273 begin
6274 g_Console_Add('kick_id <client ID>');
6275 Exit;
6276 end;
6277 if P[1] = '' then
6278 begin
6279 g_Console_Add('kick_id <client ID>');
6280 Exit;
6281 end;
6283 a := StrToIntDef(P[1], 0);
6284 if (NetClients <> nil) and (a <= High(NetClients)) then
6285 begin
6286 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6287 begin
6288 s := g_Net_ClientName_ByID(NetClients[a].ID);
6289 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6290 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6291 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6292 g_Net_Slist_ServerPlayerLeaves();
6293 end;
6294 end;
6295 end else
6296 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6297 end
6298 else if cmd = 'kick_pid' then
6299 begin
6300 if g_Game_IsServer and g_Game_IsNet then
6301 begin
6302 if Length(P) < 2 then
6303 begin
6304 g_Console_Add('kick_pid <player ID>');
6305 Exit;
6306 end;
6307 if P[1] = '' then
6308 begin
6309 g_Console_Add('kick_pid <player ID>');
6310 Exit;
6311 end;
6313 a := StrToIntDef(P[1], 0);
6314 pl := g_Net_Client_ByPlayer(a);
6315 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6316 begin
6317 s := g_Net_ClientName_ByID(pl^.ID);
6318 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6319 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6320 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6321 g_Net_Slist_ServerPlayerLeaves();
6322 end;
6323 end else
6324 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6325 end
6326 else if cmd = 'ban' then
6327 begin
6328 if g_Game_IsServer and g_Game_IsNet then
6329 begin
6330 if Length(P) < 2 then
6331 begin
6332 g_Console_Add('ban <name>');
6333 Exit;
6334 end;
6335 if P[1] = '' then
6336 begin
6337 g_Console_Add('ban <name>');
6338 Exit;
6339 end;
6341 pl := g_Net_Client_ByName(P[1]);
6342 if (pl <> nil) then
6343 begin
6344 s := g_Net_ClientName_ByID(pl^.ID);
6345 g_Net_BanHost(pl^.Peer^.address.host, False);
6346 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6347 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6348 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6349 g_Net_Slist_ServerPlayerLeaves();
6350 end else
6351 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6352 end else
6353 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6354 end
6355 else if cmd = 'ban_id' then
6356 begin
6357 if g_Game_IsServer and g_Game_IsNet then
6358 begin
6359 if Length(P) < 2 then
6360 begin
6361 g_Console_Add('ban_id <client ID>');
6362 Exit;
6363 end;
6364 if P[1] = '' then
6365 begin
6366 g_Console_Add('ban_id <client ID>');
6367 Exit;
6368 end;
6370 a := StrToIntDef(P[1], 0);
6371 if (NetClients <> nil) and (a <= High(NetClients)) then
6372 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6373 begin
6374 s := g_Net_ClientName_ByID(NetClients[a].ID);
6375 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6376 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6377 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6378 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6379 g_Net_Slist_ServerPlayerLeaves();
6380 end;
6381 end else
6382 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6383 end
6384 else if cmd = 'ban_pid' then
6385 begin
6386 if g_Game_IsServer and g_Game_IsNet then
6387 begin
6388 if Length(P) < 2 then
6389 begin
6390 g_Console_Add('ban_pid <player ID>');
6391 Exit;
6392 end;
6393 if P[1] = '' then
6394 begin
6395 g_Console_Add('ban_pid <player ID>');
6396 Exit;
6397 end;
6399 a := StrToIntDef(P[1], 0);
6400 pl := g_Net_Client_ByPlayer(a);
6401 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6402 begin
6403 s := g_Net_ClientName_ByID(pl^.ID);
6404 g_Net_BanHost(pl^.Peer^.address.host, False);
6405 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6406 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6407 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6408 g_Net_Slist_ServerPlayerLeaves();
6409 end;
6410 end else
6411 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6412 end
6413 else if cmd = 'permban' then
6414 begin
6415 if g_Game_IsServer and g_Game_IsNet then
6416 begin
6417 if Length(P) < 2 then
6418 begin
6419 g_Console_Add('permban <name>');
6420 Exit;
6421 end;
6422 if P[1] = '' then
6423 begin
6424 g_Console_Add('permban <name>');
6425 Exit;
6426 end;
6428 pl := g_Net_Client_ByName(P[1]);
6429 if (pl <> nil) then
6430 begin
6431 s := g_Net_ClientName_ByID(pl^.ID);
6432 g_Net_BanHost(pl^.Peer^.address.host);
6433 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6434 g_Net_SaveBanList();
6435 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6436 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6437 g_Net_Slist_ServerPlayerLeaves();
6438 end else
6439 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6440 end else
6441 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6442 end
6443 else if cmd = 'permban_id' then
6444 begin
6445 if g_Game_IsServer and g_Game_IsNet then
6446 begin
6447 if Length(P) < 2 then
6448 begin
6449 g_Console_Add('permban_id <client ID>');
6450 Exit;
6451 end;
6452 if P[1] = '' then
6453 begin
6454 g_Console_Add('permban_id <client ID>');
6455 Exit;
6456 end;
6458 a := StrToIntDef(P[1], 0);
6459 if (NetClients <> nil) and (a <= High(NetClients)) then
6460 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6461 begin
6462 s := g_Net_ClientName_ByID(NetClients[a].ID);
6463 g_Net_BanHost(NetClients[a].Peer^.address.host);
6464 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6465 g_Net_SaveBanList();
6466 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6467 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6468 g_Net_Slist_ServerPlayerLeaves();
6469 end;
6470 end else
6471 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6472 end
6473 else if cmd = 'permban_pid' then
6474 begin
6475 if g_Game_IsServer and g_Game_IsNet then
6476 begin
6477 if Length(P) < 2 then
6478 begin
6479 g_Console_Add('permban_pid <player ID>');
6480 Exit;
6481 end;
6482 if P[1] = '' then
6483 begin
6484 g_Console_Add('permban_pid <player ID>');
6485 Exit;
6486 end;
6488 a := StrToIntDef(P[1], 0);
6489 pl := g_Net_Client_ByPlayer(a);
6490 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6491 begin
6492 s := g_Net_ClientName_ByID(pl^.ID);
6493 g_Net_BanHost(pl^.Peer^.address.host);
6494 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6495 g_Net_SaveBanList();
6496 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6497 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6498 g_Net_Slist_ServerPlayerLeaves();
6499 end;
6500 end else
6501 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6502 end
6503 else if cmd = 'permban_ip' then
6504 begin
6505 if g_Game_IsServer and g_Game_IsNet then
6506 begin
6507 if Length(P) < 2 then
6508 begin
6509 g_Console_Add('permban_ip <IP address>');
6510 Exit;
6511 end;
6512 if P[1] = '' then
6513 begin
6514 g_Console_Add('permban_ip <IP address>');
6515 Exit;
6516 end;
6518 g_Net_BanHost(P[1]);
6519 g_Net_SaveBanList();
6520 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6521 end else
6522 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6523 end
6524 else if cmd = 'unban' then
6525 begin
6526 if g_Game_IsServer and g_Game_IsNet then
6527 begin
6528 if Length(P) < 2 then
6529 begin
6530 g_Console_Add('unban <IP Address>');
6531 Exit;
6532 end;
6533 if P[1] = '' then
6534 begin
6535 g_Console_Add('unban <IP Address>');
6536 Exit;
6537 end;
6539 if g_Net_UnbanHost(P[1]) then
6540 begin
6541 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6542 g_Net_SaveBanList();
6543 end else
6544 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6545 end else
6546 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6547 end
6548 else if cmd = 'clientlist' then
6549 begin
6550 if g_Game_IsServer and g_Game_IsNet then
6551 begin
6552 b := 0;
6553 if NetClients <> nil then
6554 for a := Low(NetClients) to High(NetClients) do
6555 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6556 begin
6557 plr := g_Player_Get(NetClients[a].Player);
6558 if plr = nil then continue;
6559 Inc(b);
6560 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6561 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6562 end;
6563 if b = 0 then
6564 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6565 end else
6566 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6567 end
6568 else if cmd = 'connect' then
6569 begin
6570 if (NetMode = NET_NONE) then
6571 begin
6572 if Length(P) < 2 then
6573 begin
6574 g_Console_Add('connect <IP> [port] [password]');
6575 Exit;
6576 end;
6577 if P[1] = '' then
6578 begin
6579 g_Console_Add('connect <IP> [port] [password]');
6580 Exit;
6581 end;
6583 if Length(P) > 2 then
6584 prt := StrToIntDef(P[2], 25666)
6585 else
6586 prt := 25666;
6588 if Length(P) > 3 then
6589 pw := P[3]
6590 else
6591 pw := '';
6593 g_Game_StartClient(P[1], prt, pw);
6594 end;
6595 end
6596 else if cmd = 'disconnect' then
6597 begin
6598 if (NetMode = NET_CLIENT) then
6599 g_Net_Disconnect();
6600 end
6601 else if cmd = 'reconnect' then
6602 begin
6603 if (NetMode = NET_SERVER) then
6604 Exit;
6606 if (NetMode = NET_CLIENT) then
6607 begin
6608 g_Net_Disconnect();
6609 gExit := EXIT_SIMPLE;
6610 EndGame;
6611 end;
6613 //TODO: Use last successful password to reconnect, instead of ''
6614 g_Game_StartClient(NetClientIP, NetClientPort, '');
6615 end
6616 else if (cmd = 'addbot') or
6617 (cmd = 'bot_add') then
6618 begin
6619 if Length(P) > 2 then
6620 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6621 else if Length(P) > 1 then
6622 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6623 else
6624 g_Bot_Add(TEAM_NONE, 2);
6625 end
6626 else if cmd = 'bot_addlist' then
6627 begin
6628 if Length(P) > 1 then
6629 begin
6630 if Length(P) = 2 then
6631 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6632 else if Length(P) = 3 then
6633 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6634 else
6635 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6636 end;
6637 end
6638 else if cmd = 'bot_removeall' then
6639 g_Bot_RemoveAll()
6640 else if cmd = 'chat' then
6641 begin
6642 if g_Game_IsNet then
6643 begin
6644 if Length(P) > 1 then
6645 begin
6646 for a := 1 to High(P) do
6647 chstr := chstr + P[a] + ' ';
6649 if Length(chstr) > 200 then SetLength(chstr, 200);
6651 if Length(chstr) < 1 then
6652 begin
6653 g_Console_Add('chat <text>');
6654 Exit;
6655 end;
6657 chstr := b_Text_Format(chstr);
6658 if g_Game_IsClient then
6659 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6660 else
6661 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6662 end
6663 else
6664 g_Console_Add('chat <text>');
6665 end else
6666 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6667 end
6668 else if cmd = 'teamchat' then
6669 begin
6670 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6671 begin
6672 if Length(P) > 1 then
6673 begin
6674 for a := 1 to High(P) do
6675 chstr := chstr + P[a] + ' ';
6677 if Length(chstr) > 200 then SetLength(chstr, 200);
6679 if Length(chstr) < 1 then
6680 begin
6681 g_Console_Add('teamchat <text>');
6682 Exit;
6683 end;
6685 chstr := b_Text_Format(chstr);
6686 if g_Game_IsClient then
6687 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6688 else
6689 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6690 gPlayer1Settings.Team);
6691 end
6692 else
6693 g_Console_Add('teamchat <text>');
6694 end else
6695 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6696 end
6697 else if cmd = 'game' then
6698 begin
6699 if gGameSettings.GameType <> GT_NONE then
6700 begin
6701 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6702 Exit;
6703 end;
6704 if Length(P) = 1 then
6705 begin
6706 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6707 Exit;
6708 end;
6709 // game not started yet, load fist map from some wad
6710 found := false;
6711 s := addWadExtension(P[1]);
6712 found := e_FindResource(AllMapDirs, s);
6713 P[1] := s;
6714 if found then
6715 begin
6716 P[1] := ExpandFileName(P[1]);
6717 // if map not choosed then set first map
6718 if Length(P) < 3 then
6719 begin
6720 SetLength(P, 3);
6721 P[2] := g_Game_GetFirstMap(P[1]);
6722 end;
6724 s := P[1] + ':\' + UpperCase(P[2]);
6726 if g_Map_Exist(s) then
6727 begin
6728 // start game
6729 g_Game_Free();
6730 with gGameSettings do
6731 begin
6732 Options := gsGameFlags;
6733 GameMode := g_Game_TextToMode(gsGameMode);
6734 if gSwitchGameMode <> GM_NONE then
6735 GameMode := gSwitchGameMode;
6736 if GameMode = GM_NONE then GameMode := GM_DM;
6737 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6738 b := 1;
6739 if Length(P) >= 4 then
6740 b := StrToIntDef(P[3], 1);
6741 g_Game_StartCustom(s, GameMode, TimeLimit,
6742 GoalLimit, MaxLives, Options, b);
6743 end;
6744 end
6745 else
6746 if P[2] = '' then
6747 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6748 else
6749 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6750 end else
6751 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6752 end
6753 else if cmd = 'host' then
6754 begin
6755 if gGameSettings.GameType <> GT_NONE then
6756 begin
6757 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6758 Exit;
6759 end;
6760 if Length(P) < 4 then
6761 begin
6762 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6763 Exit;
6764 end;
6765 if not StrToIp(P[1], listen) then
6766 Exit;
6767 prt := StrToIntDef(P[2], 25666);
6769 s := addWadExtension(P[3]);
6770 found := e_FindResource(AllMapDirs, s);
6771 P[3] := s;
6772 if found then
6773 begin
6774 // get first map in wad, if not specified
6775 if Length(P) < 5 then
6776 begin
6777 SetLength(P, 5);
6778 P[4] := g_Game_GetFirstMap(P[1]);
6779 end;
6780 s := P[3] + ':\' + UpperCase(P[4]);
6781 if g_Map_Exist(s) then
6782 begin
6783 // start game
6784 g_Game_Free();
6785 with gGameSettings do
6786 begin
6787 Options := gsGameFlags;
6788 GameMode := g_Game_TextToMode(gsGameMode);
6789 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
6790 if GameMode = GM_NONE then GameMode := GM_DM;
6791 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6792 b := 0;
6793 if Length(P) >= 6 then
6794 b := StrToIntDef(P[5], 0);
6795 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
6796 end
6797 end
6798 else
6799 begin
6800 if P[4] = '' then
6801 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6802 else
6803 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
6804 end
6805 end
6806 else
6807 begin
6808 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
6809 end
6810 end
6811 else if cmd = 'map' then
6812 begin
6813 if Length(P) = 1 then
6814 begin
6815 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6816 begin
6817 g_Console_Add(cmd + ' <MAP>');
6818 g_Console_Add(cmd + ' <WAD> [MAP]')
6819 end
6820 else
6821 begin
6822 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6823 end
6824 end
6825 else
6826 begin
6827 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6828 begin
6829 if Length(P) < 3 then
6830 begin
6831 // first param is map or wad
6832 s := UpperCase(P[1]);
6833 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6834 begin
6835 gExitByTrigger := False;
6836 if gGameOn then
6837 begin
6838 // already in game, finish current map
6839 gNextMap := s;
6840 gExit := EXIT_ENDLEVELCUSTOM;
6841 end
6842 else
6843 begin
6844 // intermission, so change map immediately
6845 g_Game_ChangeMap(s)
6846 end
6847 end
6848 else
6849 begin
6850 s := P[1];
6851 found := e_FindResource(AllMapDirs, s);
6852 P[1] := s;
6853 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6854 if found then
6855 begin
6856 // no such map, found wad
6857 pw := P[1];
6858 SetLength(P, 3);
6859 P[1] := ExpandFileName(pw);
6860 P[2] := g_Game_GetFirstMap(P[1]);
6861 s := P[1] + ':\' + P[2];
6862 if g_Map_Exist(s) then
6863 begin
6864 gExitByTrigger := False;
6865 if gGameOn then
6866 begin
6867 // already in game, finish current map
6868 gNextMap := s;
6869 gExit := EXIT_ENDLEVELCUSTOM
6870 end
6871 else
6872 begin
6873 // intermission, so change map immediately
6874 g_Game_ChangeMap(s)
6875 end
6876 end
6877 else
6878 begin
6879 if P[2] = '' then
6880 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6881 else
6882 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6883 end
6884 end
6885 else
6886 begin
6887 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6888 end
6889 end;
6890 end
6891 else
6892 begin
6893 s := addWadExtension(P[1]);
6894 found := e_FindResource(AllMapDirs, s);
6895 P[1] := s;
6896 if found then
6897 begin
6898 P[2] := UpperCase(P[2]);
6899 s := P[1] + ':\' + P[2];
6900 if g_Map_Exist(s) then
6901 begin
6902 gExitByTrigger := False;
6903 if gGameOn then
6904 begin
6905 gNextMap := s;
6906 gExit := EXIT_ENDLEVELCUSTOM
6907 end
6908 else
6909 begin
6910 g_Game_ChangeMap(s)
6911 end
6912 end
6913 else
6914 begin
6915 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6916 end
6917 end
6918 else
6919 begin
6920 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6921 end
6922 end
6923 end
6924 else
6925 begin
6926 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6927 end
6928 end
6929 end
6930 else if cmd = 'nextmap' then
6931 begin
6932 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6933 begin
6934 g_Console_Add(_lc[I_MSG_NOT_GAME])
6935 end
6936 else
6937 begin
6938 nm := True;
6939 if Length(P) = 1 then
6940 begin
6941 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6942 begin
6943 g_Console_Add(cmd + ' <MAP>');
6944 g_Console_Add(cmd + ' <WAD> [MAP]');
6945 end
6946 else
6947 begin
6948 nm := False;
6949 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6950 end;
6951 end
6952 else
6953 begin
6954 nm := False;
6955 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6956 begin
6957 if Length(P) < 3 then
6958 begin
6959 // first param is map or wad
6960 s := UpperCase(P[1]);
6961 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6962 begin
6963 // map founded
6964 gExitByTrigger := False;
6965 gNextMap := s;
6966 nm := True;
6967 end
6968 else
6969 begin
6970 // no such map, found wad
6971 pw := addWadExtension(P[1]);
6972 found := e_FindResource(MapDirs, pw);
6973 if not found then
6974 found := e_FindResource(WadDirs, pw);
6975 P[1] := pw;
6976 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6977 if found then
6978 begin
6979 // map not specified, select first map
6980 SetLength(P, 3);
6981 P[2] := g_Game_GetFirstMap(P[1]);
6982 s := P[1] + ':\' + P[2];
6983 if g_Map_Exist(s) then
6984 begin
6985 gExitByTrigger := False;
6986 gNextMap := s;
6987 nm := True
6988 end
6989 else
6990 begin
6991 if P[2] = '' then
6992 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6993 else
6994 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6995 end
6996 end
6997 else
6998 begin
6999 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7000 end
7001 end
7002 end
7003 else
7004 begin
7005 // specified two params wad + map
7006 pw := addWadExtension(P[1]);
7007 found := e_FindResource(MapDirs, pw);
7008 if not found then
7009 found := e_FindResource(MapDirs, pw);
7010 P[1] := pw;
7011 if found then
7012 begin
7013 P[2] := UpperCase(P[2]);
7014 s := P[1] + ':\' + P[2];
7015 if g_Map_Exist(s) then
7016 begin
7017 gExitByTrigger := False;
7018 gNextMap := s;
7019 nm := True
7020 end
7021 else
7022 begin
7023 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7024 end
7025 end
7026 else
7027 begin
7028 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7029 end
7030 end
7031 end
7032 else
7033 begin
7034 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7035 end
7036 end;
7037 if nm then
7038 begin
7039 if gNextMap = '' then
7040 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7041 else
7042 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7043 end
7044 end
7045 end
7046 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7047 begin
7048 if not gGameOn then
7049 begin
7050 g_Console_Add(_lc[I_MSG_NOT_GAME])
7051 end
7052 else
7053 begin
7054 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7055 begin
7056 gExitByTrigger := False;
7057 // next map not specified, try to find trigger EXIT
7058 if (gNextMap = '') and (gTriggers <> nil) then
7059 begin
7060 for a := 0 to High(gTriggers) do
7061 begin
7062 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7063 begin
7064 gExitByTrigger := True;
7065 //gNextMap := gTriggers[a].Data.MapName;
7066 gNextMap := gTriggers[a].tgcMap;
7067 Break
7068 end
7069 end
7070 end;
7071 if gNextMap = '' then
7072 gNextMap := g_Game_GetNextMap();
7073 if not isWadPath(gNextMap) then
7074 s := gGameSettings.WAD + ':\' + gNextMap
7075 else
7076 s := gNextMap;
7077 if g_Map_Exist(s) then
7078 gExit := EXIT_ENDLEVELCUSTOM
7079 else
7080 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7081 end
7082 else
7083 begin
7084 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7085 end
7086 end
7087 end
7088 else if (cmd = 'event') then
7089 begin
7090 if (Length(P) <= 1) then
7091 begin
7092 for a := 0 to High(gEvents) do
7093 if gEvents[a].Command = '' then
7094 g_Console_Add(gEvents[a].Name + ' <none>')
7095 else
7096 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7097 Exit;
7098 end;
7099 if (Length(P) = 2) then
7100 begin
7101 for a := 0 to High(gEvents) do
7102 if gEvents[a].Name = P[1] then
7103 if gEvents[a].Command = '' then
7104 g_Console_Add(gEvents[a].Name + ' <none>')
7105 else
7106 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7107 Exit;
7108 end;
7109 for a := 0 to High(gEvents) do
7110 if gEvents[a].Name = P[1] then
7111 begin
7112 gEvents[a].Command := '';
7113 for b := 2 to High(P) do
7114 if Pos(' ', P[b]) = 0 then
7115 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7116 else
7117 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7118 gEvents[a].Command := Trim(gEvents[a].Command);
7119 Exit;
7120 end;
7121 end
7122 else if cmd = 'suicide' then
7123 begin
7124 if gGameOn then
7125 begin
7126 if g_Game_IsClient then
7127 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7128 else
7129 begin
7130 if gPlayer1 <> nil then
7131 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7132 if gPlayer2 <> nil then
7133 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7134 end;
7135 end;
7136 end
7137 else if cmd = 'screenshot' then
7138 begin
7139 g_TakeScreenShot()
7140 end
7141 else if cmd = 'weapon' then
7142 begin
7143 if Length(p) = 2 then
7144 begin
7145 a := WP_FIRST + StrToInt(p[1]) - 1;
7146 if (a >= WP_FIRST) and (a <= WP_LAST) then
7147 gSelectWeapon[0, a] := True
7148 end
7149 end
7150 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7151 begin
7152 if Length(p) = 2 then
7153 begin
7154 a := WP_FIRST + StrToInt(p[1]) - 1;
7155 b := ord(cmd[2]) - ord('1');
7156 if (a >= WP_FIRST) and (a <= WP_LAST) then
7157 gSelectWeapon[b, a] := True
7158 end
7159 end
7160 // Êîìàíäû Ñâîåé èãðû:
7161 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7162 begin
7163 if cmd = 'bot_addred' then
7164 begin
7165 if Length(P) > 1 then
7166 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7167 else
7168 g_Bot_Add(TEAM_RED, 2);
7169 end
7170 else if cmd = 'bot_addblue' then
7171 begin
7172 if Length(P) > 1 then
7173 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7174 else
7175 g_Bot_Add(TEAM_BLUE, 2);
7176 end
7177 else if cmd = 'spectate' then
7178 begin
7179 if not gGameOn then
7180 Exit;
7181 g_Game_Spectate();
7182 end
7183 else if cmd = 'say' then
7184 begin
7185 if g_Game_IsServer and g_Game_IsNet then
7186 begin
7187 if Length(P) > 1 then
7188 begin
7189 chstr := '';
7190 for a := 1 to High(P) do
7191 chstr := chstr + P[a] + ' ';
7193 if Length(chstr) > 200 then SetLength(chstr, 200);
7195 if Length(chstr) < 1 then
7196 begin
7197 g_Console_Add('say <text>');
7198 Exit;
7199 end;
7201 chstr := b_Text_Format(chstr);
7202 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7203 end
7204 else g_Console_Add('say <text>');
7205 end else
7206 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7207 end
7208 else if cmd = 'tell' then
7209 begin
7210 if g_Game_IsServer and g_Game_IsNet then
7211 begin
7212 if (Length(P) > 2) and (P[1] <> '') then
7213 begin
7214 chstr := '';
7215 for a := 2 to High(P) do
7216 chstr := chstr + P[a] + ' ';
7218 if Length(chstr) > 200 then SetLength(chstr, 200);
7220 if Length(chstr) < 1 then
7221 begin
7222 g_Console_Add('tell <playername> <text>');
7223 Exit;
7224 end;
7226 pl := g_Net_Client_ByName(P[1]);
7227 if pl <> nil then
7228 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7229 else
7230 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7231 end
7232 else g_Console_Add('tell <playername> <text>');
7233 end else
7234 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7235 end
7236 else if cmd = 'centerprint' then
7237 begin
7238 if (Length(P) > 2) and (P[1] <> '') then
7239 begin
7240 chstr := '';
7241 for a := 2 to High(P) do
7242 chstr := chstr + P[a] + ' ';
7244 if Length(chstr) > 200 then SetLength(chstr, 200);
7246 if Length(chstr) < 1 then
7247 begin
7248 g_Console_Add('centerprint <timeout> <text>');
7249 Exit;
7250 end;
7252 a := StrToIntDef(P[1], 100);
7253 chstr := b_Text_Format(chstr);
7254 g_Game_Message(chstr, a);
7255 if g_Game_IsNet and g_Game_IsServer then
7256 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7257 end
7258 else g_Console_Add('centerprint <timeout> <text>');
7259 end
7260 else if (cmd = 'overtime') and not g_Game_IsClient then
7261 begin
7262 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7263 Exit;
7264 // Äîïîëíèòåëüíîå âðåìÿ:
7265 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7267 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7268 [gGameSettings.TimeLimit div 3600,
7269 (gGameSettings.TimeLimit div 60) mod 60,
7270 gGameSettings.TimeLimit mod 60]));
7271 if g_Game_IsNet then MH_SEND_GameSettings;
7272 end
7273 else if (cmd = 'rcon_password') and g_Game_IsClient then
7274 begin
7275 if (Length(P) <= 1) then
7276 g_Console_Add('rcon_password <password>')
7277 else
7278 MC_SEND_RCONPassword(P[1]);
7279 end
7280 else if cmd = 'rcon' then
7281 begin
7282 if g_Game_IsClient then
7283 begin
7284 if Length(P) > 1 then
7285 begin
7286 chstr := '';
7287 for a := 1 to High(P) do
7288 chstr := chstr + P[a] + ' ';
7290 if Length(chstr) > 200 then SetLength(chstr, 200);
7292 if Length(chstr) < 1 then
7293 begin
7294 g_Console_Add('rcon <command>');
7295 Exit;
7296 end;
7298 MC_SEND_RCONCommand(chstr);
7299 end
7300 else g_Console_Add('rcon <command>');
7301 end;
7302 end
7303 else if cmd = 'ready' then
7304 begin
7305 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7306 gLMSRespawnTime := gTime + 100;
7307 end
7308 else if (cmd = 'callvote') and g_Game_IsNet then
7309 begin
7310 if Length(P) > 1 then
7311 begin
7312 chstr := '';
7313 for a := 1 to High(P) do begin
7314 if a > 1 then chstr := chstr + ' ';
7315 chstr := chstr + P[a];
7316 end;
7318 if Length(chstr) > 200 then SetLength(chstr, 200);
7320 if Length(chstr) < 1 then
7321 begin
7322 g_Console_Add('callvote <command>');
7323 Exit;
7324 end;
7326 if g_Game_IsClient then
7327 MC_SEND_Vote(True, chstr)
7328 else
7329 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7330 g_Console_Process('vote', True);
7331 end
7332 else
7333 g_Console_Add('callvote <command>');
7334 end
7335 else if (cmd = 'vote') and g_Game_IsNet then
7336 begin
7337 if g_Game_IsClient then
7338 MC_SEND_Vote(False)
7339 else if gVoteInProgress then
7340 begin
7341 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7342 a := Floor((NetClientCount+1)/2.0) + 1
7343 else
7344 a := Floor(NetClientCount/2.0) + 1;
7345 if gVoted then
7346 begin
7347 Dec(gVoteCount);
7348 gVoted := False;
7349 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7350 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7351 end
7352 else
7353 begin
7354 Inc(gVoteCount);
7355 gVoted := True;
7356 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7357 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7358 g_Game_CheckVote;
7359 end;
7360 end;
7361 end
7362 end;
7363 end;
7365 procedure SystemCommands(P: SSArray);
7366 var
7367 cmd: string;
7368 begin
7369 cmd := LowerCase(P[0]);
7370 case cmd of
7371 'exit', 'quit':
7372 begin
7373 g_Game_Free();
7374 g_Game_Quit();
7375 end;
7376 'r_reset':
7377 begin
7378 gRC_Width := Max(1, gRC_Width);
7379 gRC_Height := Max(1, gRC_Height);
7380 gBPP := Max(1, gBPP);
7381 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7382 e_LogWriteln('resolution changed')
7383 else
7384 e_LogWriteln('resolution not changed');
7385 sys_EnableVSync(gVSync);
7386 end;
7387 'r_maxfps':
7388 begin
7389 if Length(p) = 2 then
7390 begin
7391 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7392 if gMaxFPS > 0 then
7393 gFrameTime := 1000 div gMaxFPS
7394 else
7395 gFrameTime := 0;
7396 end;
7397 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7398 end;
7399 'g_language':
7400 begin
7401 if Length(p) = 2 then
7402 begin
7403 gAskLanguage := true;
7404 gLanguage := LANGUAGE_ENGLISH;
7405 case LowerCase(p[1]) of
7406 'english':
7407 begin
7408 gAskLanguage := false;
7409 gLanguage := LANGUAGE_ENGLISH;
7410 end;
7411 'russian':
7412 begin
7413 gAskLanguage := false;
7414 gLanguage := LANGUAGE_RUSSIAN;
7415 end;
7416 'ask':
7417 begin
7418 gAskLanguage := true;
7419 gLanguage := LANGUAGE_ENGLISH;
7420 end;
7421 end;
7422 g_Language_Set(gLanguage);
7423 end
7424 else
7425 begin
7426 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7427 end
7428 end;
7429 end;
7430 end;
7432 procedure g_TakeScreenShot(Filename: string = '');
7433 var s: TStream; t: TDateTime; dir, date, name: String;
7434 begin
7435 if e_NoGraphics then Exit;
7436 try
7437 dir := e_GetWriteableDir(ScreenshotDirs);
7439 if Filename = '' then
7440 begin
7441 t := Now;
7442 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7443 Filename := 'screenshot-' + date;
7444 end;
7446 name := e_CatPath(dir, Filename + '.png');
7447 s := createDiskFile(name);
7448 try
7449 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
7450 s.Free;
7451 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7452 except
7453 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7454 s.Free;
7455 DeleteFile(name)
7456 end
7457 except
7458 g_Console_Add('oh shit, i can''t create screenshot!')
7459 end
7460 end;
7462 procedure g_Game_InGameMenu(Show: Boolean);
7463 begin
7464 if (g_ActiveWindow = nil) and Show then
7465 begin
7466 if gGameSettings.GameType = GT_SINGLE then
7467 g_GUI_ShowWindow('GameSingleMenu')
7468 else
7469 begin
7470 if g_Game_IsClient then
7471 g_GUI_ShowWindow('GameClientMenu')
7472 else
7473 if g_Game_IsNet then
7474 g_GUI_ShowWindow('GameServerMenu')
7475 else
7476 g_GUI_ShowWindow('GameCustomMenu');
7477 end;
7478 g_Sound_PlayEx('MENU_OPEN');
7480 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7481 if (not g_Game_IsNet) then
7482 g_Game_Pause(True);
7483 end
7484 else
7485 if (g_ActiveWindow <> nil) and (not Show) then
7486 begin
7487 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7488 if (not g_Game_IsNet) then
7489 g_Game_Pause(False);
7490 end;
7491 end;
7493 procedure g_Game_Pause (Enable: Boolean);
7494 var
7495 oldPause: Boolean;
7496 begin
7497 if not gGameOn then exit;
7499 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7501 oldPause := gPause;
7502 gPauseMain := Enable;
7504 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7505 end;
7507 procedure g_Game_HolmesPause (Enable: Boolean);
7508 var
7509 oldPause: Boolean;
7510 begin
7511 if not gGameOn then exit;
7512 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7514 oldPause := gPause;
7515 gPauseHolmes := Enable;
7517 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7518 end;
7520 procedure g_Game_PauseAllSounds(Enable: Boolean);
7521 var
7522 i: Integer;
7523 begin
7524 // Òðèããåðû:
7525 if gTriggers <> nil then
7526 for i := 0 to High(gTriggers) do
7527 with gTriggers[i] do
7528 if (TriggerType = TRIGGER_SOUND) and
7529 (Sound <> nil) and
7530 Sound.IsPlaying() then
7531 begin
7532 Sound.Pause(Enable);
7533 end;
7535 // Çâóêè èãðîêîâ:
7536 if gPlayers <> nil then
7537 for i := 0 to High(gPlayers) do
7538 if gPlayers[i] <> nil then
7539 gPlayers[i].PauseSounds(Enable);
7541 // Ìóçûêà:
7542 if gMusic <> nil then
7543 gMusic.Pause(Enable);
7544 end;
7546 procedure g_Game_StopAllSounds(all: Boolean);
7547 var
7548 i: Integer;
7549 begin
7550 if gTriggers <> nil then
7551 for i := 0 to High(gTriggers) do
7552 with gTriggers[i] do
7553 if (TriggerType = TRIGGER_SOUND) and
7554 (Sound <> nil) then
7555 Sound.Stop();
7557 if gMusic <> nil then
7558 gMusic.Stop();
7560 if all then
7561 e_StopChannels();
7562 end;
7564 procedure g_Game_UpdateTriggerSounds;
7565 var i: Integer;
7566 begin
7567 if gTriggers <> nil then
7568 for i := 0 to High(gTriggers) do
7569 with gTriggers[i] do
7570 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7571 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7572 end;
7574 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7575 begin
7576 Result := False;
7577 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7578 begin
7579 Result := True;
7580 Exit;
7581 end;
7582 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7583 begin
7584 Result := True;
7585 Exit;
7586 end;
7587 if gSpectMode <> SPECT_PLAYERS then
7588 Exit;
7589 if gSpectPID1 = UID then
7590 begin
7591 Result := True;
7592 Exit;
7593 end;
7594 if gSpectViewTwo and (gSpectPID2 = UID) then
7595 begin
7596 Result := True;
7597 Exit;
7598 end;
7599 end;
7601 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7602 var
7603 Pl: TPlayer;
7604 begin
7605 Result := False;
7606 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7607 begin
7608 Result := True;
7609 Exit;
7610 end;
7611 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7612 begin
7613 Result := True;
7614 Exit;
7615 end;
7616 if gSpectMode <> SPECT_PLAYERS then
7617 Exit;
7618 Pl := g_Player_Get(gSpectPID1);
7619 if (Pl <> nil) and (Pl.Team = Team) then
7620 begin
7621 Result := True;
7622 Exit;
7623 end;
7624 if gSpectViewTwo then
7625 begin
7626 Pl := g_Player_Get(gSpectPID2);
7627 if (Pl <> nil) and (Pl.Team = Team) then
7628 begin
7629 Result := True;
7630 Exit;
7631 end;
7632 end;
7633 end;
7635 procedure g_Game_Message(Msg: string; Time: Word);
7636 begin
7637 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7638 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7639 MessageTime := Time;
7640 end;
7642 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7643 const
7644 punct: Array[0..13] of String =
7645 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7646 var
7647 i, j: Integer;
7648 ok: Boolean;
7649 fpText: String;
7651 function IsPunctuation(S: String): Boolean;
7652 var
7653 i: Integer;
7654 begin
7655 Result := False;
7656 if Length(S) <> 1 then
7657 Exit;
7658 for i := Low(punct) to High(punct) do
7659 if S = punct[i] then
7660 begin
7661 Result := True;
7662 break;
7663 end;
7664 end;
7665 function FilterPunctuation(S: String): String;
7666 var
7667 i: Integer;
7668 begin
7669 for i := Low(punct) to High(punct) do
7670 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7671 Result := S;
7672 end;
7673 begin
7674 ok := False;
7676 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7677 begin
7678 // remove player name
7679 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7680 // for FullWord check
7681 Text := toLowerCase1251(' ' + Text + ' ');
7682 fpText := FilterPunctuation(Text);
7684 for i := 0 to Length(gChatSounds) - 1 do
7685 begin
7686 ok := True;
7687 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7688 begin
7689 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7690 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7691 else
7692 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7693 if not ok then
7694 break;
7695 end;
7696 if ok then
7697 begin
7698 gChatSounds[i].Sound.Play();
7699 break;
7700 end;
7701 end;
7702 end;
7703 if not ok then
7704 g_Sound_PlayEx('SOUND_GAME_RADIO');
7705 end;
7707 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7708 var
7709 a: Integer;
7710 begin
7711 case gAnnouncer of
7712 ANNOUNCE_NONE:
7713 Exit;
7714 ANNOUNCE_ME,
7715 ANNOUNCE_MEPLUS:
7716 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7717 Exit;
7718 end;
7719 for a := 0 to 3 do
7720 if goodsnd[a].IsPlaying() then
7721 Exit;
7723 goodsnd[Random(4)].Play();
7724 end;
7726 procedure g_Game_Announce_KillCombo(Param: Integer);
7727 var
7728 UID: Word;
7729 c, n: Byte;
7730 Pl: TPlayer;
7731 Name: String;
7732 begin
7733 UID := Param and $FFFF;
7734 c := Param shr 16;
7735 if c < 2 then
7736 Exit;
7738 Pl := g_Player_Get(UID);
7739 if Pl = nil then
7740 Name := '?'
7741 else
7742 Name := Pl.Name;
7744 case c of
7745 2: begin
7746 n := 0;
7747 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7748 end;
7749 3: begin
7750 n := 1;
7751 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7752 end;
7753 4: begin
7754 n := 2;
7755 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7756 end;
7757 else begin
7758 n := 3;
7759 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7760 end;
7761 end;
7763 case gAnnouncer of
7764 ANNOUNCE_NONE:
7765 Exit;
7766 ANNOUNCE_ME:
7767 if not g_Game_IsWatchedPlayer(UID) then
7768 Exit;
7769 ANNOUNCE_MEPLUS:
7770 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7771 Exit;
7772 end;
7774 if killsnd[n].IsPlaying() then
7775 killsnd[n].Stop();
7776 killsnd[n].Play();
7777 end;
7779 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7780 var
7781 a: Integer;
7782 begin
7783 case gAnnouncer of
7784 ANNOUNCE_NONE:
7785 Exit;
7786 ANNOUNCE_ME:
7787 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7788 Exit;
7789 end;
7790 for a := 0 to 2 do
7791 if hahasnd[a].IsPlaying() then
7792 Exit;
7794 hahasnd[Random(3)].Play();
7795 end;
7797 procedure g_Game_StartVote(Command, Initiator: string);
7798 var
7799 Need: Integer;
7800 begin
7801 if not gVotesEnabled then Exit;
7802 if gGameSettings.GameType <> GT_SERVER then Exit;
7803 if gVoteInProgress or gVotePassed then
7804 begin
7805 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7806 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7807 Exit;
7808 end;
7809 gVoteInProgress := True;
7810 gVotePassed := False;
7811 gVoteTimer := gTime + gVoteTimeout * 1000;
7812 gVoteCount := 0;
7813 gVoted := False;
7814 gVoteCommand := Command;
7816 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7817 Need := Floor((NetClientCount+1)/2.0)+1
7818 else
7819 Need := Floor(NetClientCount/2.0)+1;
7820 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7821 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7822 end;
7824 procedure g_Game_CheckVote;
7825 var
7826 I, Need: Integer;
7827 begin
7828 if gGameSettings.GameType <> GT_SERVER then Exit;
7829 if not gVoteInProgress then Exit;
7831 if (gTime >= gVoteTimer) then
7832 begin
7833 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7834 Need := Floor((NetClientCount+1)/2.0) + 1
7835 else
7836 Need := Floor(NetClientCount/2.0) + 1;
7837 if gVoteCount >= Need then
7838 begin
7839 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7840 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7841 gVotePassed := True;
7842 gVoteCmdTimer := gTime + 5000;
7843 end
7844 else
7845 begin
7846 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7847 MH_SEND_VoteEvent(NET_VE_FAILED);
7848 end;
7849 if NetClients <> nil then
7850 for I := Low(NetClients) to High(NetClients) do
7851 if NetClients[i].Used then
7852 NetClients[i].Voted := False;
7853 gVoteInProgress := False;
7854 gVoted := False;
7855 gVoteCount := 0;
7856 end
7857 else
7858 begin
7859 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7860 Need := Floor((NetClientCount+1)/2.0) + 1
7861 else
7862 Need := Floor(NetClientCount/2.0) + 1;
7863 if gVoteCount >= Need then
7864 begin
7865 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7866 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7867 gVoteInProgress := False;
7868 gVotePassed := True;
7869 gVoteCmdTimer := gTime + 5000;
7870 gVoted := False;
7871 gVoteCount := 0;
7872 if NetClients <> nil then
7873 for I := Low(NetClients) to High(NetClients) do
7874 if NetClients[i].Used then
7875 NetClients[i].Voted := False;
7876 end;
7877 end;
7878 end;
7880 procedure g_Game_LoadMapList(FileName: string);
7881 var
7882 ListFile: TextFile;
7883 s: string;
7884 begin
7885 MapList := nil;
7886 MapIndex := -1;
7888 if not FileExists(FileName) then Exit;
7890 AssignFile(ListFile, FileName);
7891 Reset(ListFile);
7892 while not EOF(ListFile) do
7893 begin
7894 ReadLn(ListFile, s);
7896 s := Trim(s);
7897 if s = '' then Continue;
7899 SetLength(MapList, Length(MapList)+1);
7900 MapList[High(MapList)] := s;
7901 end;
7902 CloseFile(ListFile);
7903 end;
7905 procedure g_Game_SetDebugMode();
7906 begin
7907 gDebugMode := True;
7908 // ×èòû (äàæå â ñâîåé èãðå):
7909 gCheats := True;
7910 end;
7912 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7913 var
7914 i: Word;
7915 begin
7916 if Length(LoadingStat.Msgs) = 0 then
7917 Exit;
7919 with LoadingStat do
7920 begin
7921 if not reWrite then
7922 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7923 if NextMsg = Length(Msgs) then
7924 begin // scroll
7925 for i := 0 to High(Msgs)-1 do
7926 Msgs[i] := Msgs[i+1];
7927 end
7928 else
7929 Inc(NextMsg);
7930 end else
7931 if NextMsg = 0 then
7932 Inc(NextMsg);
7934 Msgs[NextMsg-1] := Text;
7935 CurValue := 0;
7936 MaxValue := Max;
7937 ShowCount := 0;
7938 PBarWasHere := false;
7939 end;
7941 g_ActiveWindow := nil;
7943 ProcessLoading(true);
7944 end;
7946 procedure g_Game_StepLoading(Value: Integer = -1);
7947 begin
7948 with LoadingStat do
7949 begin
7950 if Value = -1 then
7951 begin
7952 Inc(CurValue);
7953 Inc(ShowCount);
7954 end
7955 else
7956 CurValue := Value;
7957 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7958 begin
7959 ShowCount := 0;
7960 ProcessLoading();
7961 end;
7962 end;
7963 end;
7965 procedure g_Game_ClearLoading();
7966 var
7967 len: Word;
7968 begin
7969 with LoadingStat do
7970 begin
7971 CurValue := 0;
7972 MaxValue := 0;
7973 ShowCount := 0;
7974 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7975 if len < 1 then len := 1;
7976 SetLength(Msgs, len);
7977 for len := Low(Msgs) to High(Msgs) do
7978 Msgs[len] := '';
7979 NextMsg := 0;
7980 PBarWasHere := false;
7981 end;
7982 end;
7984 procedure Parse_Params(var pars: TParamStrValues);
7985 var
7986 i: Integer;
7987 s: String;
7988 begin
7989 SetLength(pars, 0);
7990 i := 1;
7991 while i <= ParamCount do
7992 begin
7993 s := ParamStr(i);
7994 if (s[1] = '-') and (Length(s) > 1) then
7995 begin
7996 if (s[2] = '-') and (Length(s) > 2) then
7997 begin // Îäèíî÷íûé ïàðàìåòð
7998 SetLength(pars, Length(pars) + 1);
7999 with pars[High(pars)] do
8000 begin
8001 Name := LowerCase(s);
8002 Value := '+';
8003 end;
8004 end
8005 else
8006 if (i < ParamCount) then
8007 begin // Ïàðàìåòð ñî çíà÷åíèåì
8008 Inc(i);
8009 SetLength(pars, Length(pars) + 1);
8010 with pars[High(pars)] do
8011 begin
8012 Name := LowerCase(s);
8013 Value := LowerCase(ParamStr(i));
8014 end;
8015 end;
8016 end;
8018 Inc(i);
8019 end;
8020 end;
8022 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8023 var
8024 i: Integer;
8025 begin
8026 Result := '';
8027 for i := 0 to High(pars) do
8028 if pars[i].Name = aName then
8029 begin
8030 Result := pars[i].Value;
8031 Break;
8032 end;
8033 end;
8035 procedure g_Game_Process_Params();
8036 var
8037 pars: TParamStrValues;
8038 map: String;
8039 GMode, n: Byte;
8040 LimT, LimS: Integer;
8041 Opt: LongWord;
8042 Lives: Integer;
8043 s: String;
8044 Port: Integer;
8045 ip: String;
8046 F: TextFile;
8047 begin
8048 Parse_Params(pars);
8050 // Debug mode:
8051 s := Find_Param_Value(pars, '--debug');
8052 if (s <> '') then
8053 begin
8054 g_Game_SetDebugMode();
8055 s := Find_Param_Value(pars, '--netdump');
8056 if (s <> '') then
8057 NetDump := True;
8058 end;
8060 // Connect when game loads
8061 ip := Find_Param_Value(pars, '-connect');
8063 if ip <> '' then
8064 begin
8065 s := Find_Param_Value(pars, '-port');
8066 if (s = '') or not TryStrToInt(s, Port) then
8067 Port := 25666;
8069 s := Find_Param_Value(pars, '-pw');
8071 g_Game_StartClient(ip, Port, s);
8072 Exit;
8073 end;
8075 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8076 if (s <> '') then
8077 begin
8078 gDefaultMegawadStart := s;
8079 end;
8081 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8082 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8083 begin
8084 gDefaultMegawadStart := DF_Default_Megawad_Start;
8085 end;
8087 // Start map when game loads:
8088 map := LowerCase(Find_Param_Value(pars, '-map'));
8089 if isWadPath(map) then
8090 begin
8091 // Game mode:
8092 s := Find_Param_Value(pars, '-gm');
8093 GMode := g_Game_TextToMode(s);
8094 if GMode = GM_NONE then GMode := GM_DM;
8095 if GMode = GM_SINGLE then GMode := GM_COOP;
8097 // Time limit:
8098 s := Find_Param_Value(pars, '-limt');
8099 if (s = '') or (not TryStrToInt(s, LimT)) then
8100 LimT := 0;
8101 if LimT < 0 then
8102 LimT := 0;
8104 // Goal limit:
8105 s := Find_Param_Value(pars, '-lims');
8106 if (s = '') or (not TryStrToInt(s, LimS)) then
8107 LimS := 0;
8108 if LimS < 0 then
8109 LimS := 0;
8111 // Lives limit:
8112 s := Find_Param_Value(pars, '-lives');
8113 if (s = '') or (not TryStrToInt(s, Lives)) then
8114 Lives := 0;
8115 if Lives < 0 then
8116 Lives := 0;
8118 // Options:
8119 s := Find_Param_Value(pars, '-opt');
8120 if (s = '') then
8121 Opt := gsGameFlags
8122 else
8123 Opt := StrToIntDef(s, 0);
8125 // Close after map:
8126 s := Find_Param_Value(pars, '--close');
8127 if (s <> '') then
8128 gMapOnce := True;
8130 // Override map to test:
8131 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8132 if s <> '' then
8133 begin
8134 if e_IsValidResourceName(s) then
8135 e_FindResource(AllMapDirs, s);
8136 gTestMap := ExpandFileName(s);
8137 end;
8139 // Delete test map after play:
8140 s := Find_Param_Value(pars, '--testdelete');
8141 if (s <> '') then
8142 begin
8143 //gMapToDelete := MapsDir + map;
8144 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8145 Halt(1);
8146 end;
8148 // Delete temporary WAD after play:
8149 s := Find_Param_Value(pars, '--tempdelete');
8150 if (s <> '') and (gTestMap <> '') then
8151 begin
8152 gMapToDelete := gTestMap;
8153 gTempDelete := True;
8154 end;
8156 // Number of players:
8157 s := Find_Param_Value(pars, '-pl');
8158 if (s = '') then
8159 n := DEFAULT_PLAYERS
8160 else
8161 n := StrToIntDef(s, DEFAULT_PLAYERS);
8163 // Start:
8164 s := Find_Param_Value(pars, '-port');
8165 if (s = '') or not TryStrToInt(s, Port) then
8166 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8167 else
8168 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8169 end;
8171 // Execute script when game loads:
8172 s := Find_Param_Value(pars, '-exec');
8173 if s <> '' then
8174 begin
8175 // if not isWadPath(s) then
8176 // s := GameDir + '/' + s;
8178 {$I-}
8179 AssignFile(F, s);
8180 Reset(F);
8181 if IOResult <> 0 then
8182 begin
8183 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8184 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8185 CloseFile(F);
8186 Exit;
8187 end;
8188 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8189 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8191 while not EOF(F) do
8192 begin
8193 ReadLn(F, s);
8194 if IOResult <> 0 then
8195 begin
8196 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8197 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8198 CloseFile(F);
8199 Exit;
8200 end;
8201 if Pos('#', s) <> 1 then // script comment
8202 g_Console_Process(s, True);
8203 end;
8205 CloseFile(F);
8206 {$I+}
8207 end;
8209 SetLength(pars, 0);
8210 end;
8212 begin
8213 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8214 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8215 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8216 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8218 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8219 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8220 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8221 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8223 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8224 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8226 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8227 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8229 {$IFDEF ENABLE_HOLMES}
8230 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8231 {$ENDIF}
8233 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8235 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8236 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8238 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8239 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8241 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8242 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8244 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8245 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8246 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8247 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
8248 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8249 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8250 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8251 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8252 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8253 end.