DEADSOFTWARE

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