DEADSOFTWARE

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