DEADSOFTWARE

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