DEADSOFTWARE

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