DEADSOFTWARE

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