DEADSOFTWARE

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