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