DEADSOFTWARE

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