Fix program termination sequence and a lot of memory leaks during it
[d2df-sdl.git] / src / game / g_game.pas
blob8509049647cf3f6e53941c8ea91acafbe9dccd3a
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,
23 g_basic, g_player, e_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameOption = (
29 //RESERVED = 0, // FIXME: reuse for something
30 TEAM_DAMAGE = 1,
31 ALLOW_EXIT,
32 WEAPONS_STAY,
33 MONSTERS,
34 BOTS_VS_PLAYERS,
35 BOTS_VS_MONSTERS,
36 DM_KEYS,
37 TEAM_HIT_TRACE,
38 TEAM_HIT_PROJECTILE,
39 TEAM_ABSORB_DAMAGE,
40 ALLOW_DROP_FLAG,
41 THROW_FLAG,
42 POWERUP_RANDOM,
43 ITEM_ALL_RANDOM,
44 ITEM_LIFE_RANDOM,
45 ITEM_AMMO_RANDOM,
46 ITEM_WEAPON_RANDOM
48 TGameOptions = set of TGameOption;
50 TGameSettings = record
51 GameType: Byte;
52 GameMode: Byte;
53 TimeLimit: Word;
54 ScoreLimit: Word;
55 WarmupTime: Word;
56 SpawnInvul: Word;
57 ItemRespawnTime: Word;
58 ItemRespawnRandom: Word;
59 PowerupRespawnTime: Word;
60 PowerupRespawnRandom: Word;
61 MaxLives: Byte;
62 Options: TGameOptions;
63 WAD: String;
64 end;
66 TGameEvent = record
67 Name: String;
68 Command: String;
69 end;
71 TDelayedEvent = record
72 Pending: Boolean;
73 Time: LongWord;
74 DEType: Byte;
75 DENum: Integer;
76 DEStr: String;
77 end;
79 TChatSound = record
80 Sound: TPlayableSound;
81 Tags: Array of String;
82 FullWord: Boolean;
83 end;
85 TPlayerSettings = record
86 Name: String;
87 Model: String;
88 Color: TRGB;
89 Team: Byte;
90 // ones below are sent only to the server
91 WeaponSwitch: Byte;
92 WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
93 SwitchToEmpty: Byte;
94 SkipIronFist: Byte;
95 end;
97 TMegaWADInfo = record
98 Name: String;
99 Description: String;
100 Author: String;
101 Pic: String;
102 end;
104 THearPoint = record
105 Active: Boolean;
106 Coords: TDFPoint;
107 end;
109 function g_Game_IsNet(): Boolean;
110 function g_Game_IsServer(): Boolean;
111 function g_Game_IsClient(): Boolean;
112 procedure g_Game_Init();
113 procedure g_Game_Free (freeTextures: Boolean=true);
114 procedure g_Game_LoadData();
115 procedure g_Game_FreeData();
116 procedure g_Game_Update();
117 procedure g_Game_PreUpdate();
118 procedure g_Game_Draw();
119 procedure g_Game_Quit();
120 procedure g_Game_SetupScreenSize();
121 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
122 function g_Game_ModeToText(Mode: Byte): string;
123 function g_Game_TextToMode(Mode: string): Byte;
124 procedure g_Game_ExecuteEvent(Name: String);
125 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
126 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
127 procedure g_Game_RemovePlayer();
128 procedure g_Game_Spectate();
129 procedure g_Game_SpectateCenterView();
130 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
131 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: TGameOptions; nPlayers: Byte);
132 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: TGameOptions; nPlayers: Byte; IPAddr: LongWord; Port: Word);
133 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
134 procedure g_Game_Restart();
135 procedure g_Game_RestartLevel();
136 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
137 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
138 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
139 procedure g_Game_ChangeMap(const MapPath: String);
140 procedure g_Game_ExitLevel(const Map: AnsiString);
141 function g_Game_GetFirstMap(WAD: String): String;
142 function g_Game_GetNextMap(): String;
143 procedure g_Game_NextLevel();
144 procedure g_Game_Pause(Enable: Boolean);
145 procedure g_Game_HolmesPause(Enable: Boolean);
146 procedure g_Game_InGameMenu(Show: Boolean);
147 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
148 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
149 procedure g_Game_Message(Msg: String; Time: Word);
150 procedure g_Game_LoadMapList(FileName: String);
151 procedure g_Game_PauseAllSounds(Enable: Boolean);
152 procedure g_Game_StopAllSounds(all: Boolean);
153 procedure g_Game_UpdateTriggerSounds();
154 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
155 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
156 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
157 procedure g_Game_Announce_KillCombo(Param: Integer);
158 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
159 procedure g_Game_Effect_Bubbles(fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean = False);
160 procedure g_Game_StartVote(Command, Initiator: string);
161 procedure g_Game_CheckVote;
162 procedure g_TakeScreenShot(Filename: string = '');
163 procedure g_FatalError(Text: String);
164 procedure g_SimpleError(Text: String);
165 function g_Game_IsTestMap(): Boolean;
166 procedure g_Game_DeleteTestMap();
167 procedure GameCVars(P: SSArray);
168 procedure PlayerSettingsCVars(P: SSArray);
169 procedure SystemCommands(P: SSArray);
170 procedure GameCommands(P: SSArray);
171 procedure GameCheats(P: SSArray);
172 procedure DebugCommands(P: SSArray);
173 procedure g_Game_Process_Params;
174 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
175 procedure g_Game_StepLoading(Value: Integer = -1);
176 procedure g_Game_ClearLoading();
177 procedure g_Game_SetDebugMode();
178 procedure DrawLoadingStat();
179 procedure DrawMenuBackground(tex: AnsiString);
181 { procedure SetWinPause(Enable: Boolean); }
183 const
184 GAME_TICK = 28;
186 LOADING_SHOW_STEP = 100;
187 LOADING_INTERLINE = 20;
189 GT_NONE = 0;
190 GT_SINGLE = 1;
191 GT_CUSTOM = 2;
192 GT_SERVER = 3;
193 GT_CLIENT = 4;
195 GM_NONE = 0;
196 GM_DM = 1;
197 GM_TDM = 2;
198 GM_CTF = 3;
199 GM_COOP = 4;
200 GM_SINGLE = 5;
202 MESSAGE_DIKEY = WM_USER + 1;
204 EXIT_QUIT = 1;
205 EXIT_SIMPLE = 2;
206 EXIT_RESTART = 3;
207 EXIT_ENDLEVELSINGLE = 4;
208 EXIT_ENDLEVELCUSTOM = 5;
210 STATE_NONE = 0;
211 STATE_MENU = 1;
212 STATE_FOLD = 2;
213 STATE_INTERCUSTOM = 3;
214 STATE_INTERSINGLE = 4;
215 STATE_INTERTEXT = 5;
216 STATE_INTERPIC = 6;
217 STATE_ENDPIC = 7;
218 STATE_SLIST = 8;
220 LMS_RESPAWN_NONE = 0;
221 LMS_RESPAWN_WARMUP = 1;
222 LMS_RESPAWN_FINAL = 2;
224 SPECT_NONE = 0;
225 SPECT_STATS = 1;
226 SPECT_MAPVIEW = 2;
227 SPECT_PLAYERS = 3;
229 DE_GLOBEVENT = 0;
230 DE_BFGHIT = 1;
231 DE_KILLCOMBO = 2;
232 DE_BODYKILL = 3;
234 ANNOUNCE_NONE = 0;
235 ANNOUNCE_ME = 1;
236 ANNOUNCE_MEPLUS = 2;
237 ANNOUNCE_ALL = 3;
239 CONFIG_FILENAME = 'Doom2DF.cfg';
241 TEST_MAP_NAME = '$$$_TEST_$$$';
243 STD_PLAYER_MODEL = 'Doomer';
245 {$IFDEF HEADLESS}
246 DEFAULT_PLAYERS = 0;
247 {$ELSE}
248 DEFAULT_PLAYERS = 1;
249 {$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 = nil;
263 gPlayer2: TPlayer = nil;
264 gPlayerDrawn: TPlayer = nil;
265 gTime: LongWord;
266 gLerpFactor: Single = 1.0;
267 gSwitchGameMode: Byte = GM_DM;
268 gHearPoint1, gHearPoint2: THearPoint;
269 gSoundEffectsDF: Boolean = False;
270 gSoundTriggerTime: Word = 0;
271 gAnnouncer: Integer = ANNOUNCE_NONE;
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 gBodyKillEvent: Integer = -1;
280 gDefInterTime: ShortInt = -1;
281 gInterEndTime: LongWord = 0;
282 gInterTime: LongWord = 0;
283 gServInterTime: Byte = 0;
284 gGameStartTime: LongWord = 0;
285 gTotalMonsters: Integer = 0;
286 gPauseMain: Boolean = false;
287 gPauseHolmes: Boolean = false;
288 gShowTime: Boolean = False;
289 gShowFPS: Boolean = False;
290 gShowScore: Boolean = True;
291 gShowStat: Boolean = True;
292 gShowPIDs: Boolean = False;
293 gShowKillMsg: Boolean = True;
294 gShowLives: Boolean = True;
295 gShowPing: Boolean = False;
296 gShowMap: Boolean = False;
297 gExit: Byte = 0;
298 gState: Byte = STATE_NONE;
299 sX, sY: Integer;
300 sWidth, sHeight: Word;
301 gSpectMode: Byte = SPECT_NONE;
302 gSpectHUD: Boolean = True;
303 gSpectKeyPress: Boolean = False;
304 gSpectX: Integer = 0;
305 gSpectY: Integer = 0;
306 gSpectStep: Byte = 8;
307 gSpectViewTwo: Boolean = False;
308 gSpectPID1: Integer = -1;
309 gSpectPID2: Integer = -1;
310 gSpectAuto: Boolean = False;
311 gSpectAutoNext: LongWord;
312 gSpectAutoStepX: Integer;
313 gSpectAutoStepY: Integer;
314 gMusic: TMusic = nil;
315 gLoadGameMode: Boolean;
316 gCheats: Boolean = False;
317 gMapOnce: Boolean = False;
318 gMapToDelete: String;
319 gTempDelete: Boolean = False;
320 gLastMap: Boolean = False;
321 gScreenWidth: Word;
322 gScreenHeight: Word;
323 gResolutionChange: Boolean = False;
324 gRC_Width, gRC_Height: Integer;
325 gRC_FullScreen, gRC_Maximized: Boolean;
326 gLanguageChange: Boolean = False;
327 gDebugMode: Boolean = False;
328 g_debug_Sounds: Boolean = False;
329 g_debug_Frames: Boolean = False;
330 g_debug_WinMsgs: Boolean = False;
331 g_debug_MonsterOff: Boolean = False;
332 g_debug_BotAIOff: Byte = 0;
333 g_debug_HealthBar: Boolean = False;
334 g_Debug_Player: Boolean = False;
335 gCoopMonstersKilled: Word = 0;
336 gCoopSecretsFound: Word = 0;
337 gCoopTotalMonstersKilled: Word = 0;
338 gCoopTotalSecretsFound: Word = 0;
339 gCoopTotalMonsters: Word = 0;
340 gCoopTotalSecrets: Word = 0;
341 gStatsOff: Boolean = False;
342 gStatsPressed: Boolean = False;
343 gExitByTrigger: Boolean = False;
344 gNextMap: String = '';
345 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
346 gLMSRespawnTime: Cardinal = 0;
347 gLMSSoftSpawn: Boolean = False;
348 gMissionFailed: Boolean = False;
349 gVoteInProgress: Boolean = False;
350 gVotePassed: Boolean = False;
351 gVoteCommand: string = '';
352 gVoteTimer: Cardinal = 0;
353 gVoteCmdTimer: Cardinal = 0;
354 gVoteCount: Integer = 0;
355 gVoteTimeout: Cardinal = 30;
356 gVoted: Boolean = False;
357 gVotesEnabled: Boolean = True;
358 gEvents: Array of TGameEvent;
359 gDelayedEvents: Array of TDelayedEvent;
360 gUseChatSounds: Boolean = True;
361 gChatSounds: Array of TChatSound;
362 gWeaponAction: Array [0..1, WP_FACT..WP_LACT] of Boolean; // [player, weapon_action]
363 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
364 gInterReadyCount: Integer = 0;
365 gMaxBots: Integer = 127;
367 g_dbg_ignore_bounds: Boolean = false;
368 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
369 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
371 // move button values:
372 // bits 0-1: l/r state:
373 // 0: neither left, nor right pressed
374 // 1: left pressed
375 // 2: right pressed
376 // bits 4-5: l/r state when strafe was pressed
377 P1MoveButton: Byte = 0;
378 P2MoveButton: Byte = 0;
380 g_profile_frame_update: Boolean = false;
381 g_profile_frame_draw: Boolean = false;
382 g_profile_collision: Boolean = false;
383 g_profile_los: Boolean = false;
384 g_profile_history_size: Integer = 1000;
386 g_rlayer_back: Boolean = true;
387 g_rlayer_step: Boolean = true;
388 g_rlayer_wall: Boolean = true;
389 g_rlayer_door: Boolean = true;
390 g_rlayer_acid1: Boolean = true;
391 g_rlayer_acid2: Boolean = true;
392 g_rlayer_water: Boolean = true;
393 g_rlayer_fore: Boolean = true;
396 procedure g_ResetDynlights ();
397 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
398 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
400 function conIsCheatsEnabled (): Boolean; inline;
401 function gPause (): Boolean; inline;
404 implementation
406 uses
407 {$INCLUDE ../nogl/noGLuses.inc}
408 {$IFDEF ENABLE_HOLMES}
409 g_holmes,
410 {$ENDIF}
411 e_texture, e_res, g_textures, g_window, g_menu,
412 e_input, e_log, g_console, g_items, g_map, g_panel,
413 g_playermodel, g_gfx, g_options, Math,
414 g_triggers, g_monsters, e_sound, CONFIG,
415 g_language, g_net, g_main, g_phys,
416 ENet, e_msg, g_netmsg, g_netmaster,
417 sfs, wadreader, g_system;
421 hasPBarGfx: Boolean = false;
424 // ////////////////////////////////////////////////////////////////////////// //
425 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
428 // ////////////////////////////////////////////////////////////////////////// //
429 function conIsCheatsEnabled (): Boolean; inline;
430 begin
431 result := false;
432 if g_Game_IsNet then exit;
433 if not gDebugMode then
434 begin
435 //if not gCheats then exit;
436 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
437 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
438 end;
439 result := true;
440 end;
443 // ////////////////////////////////////////////////////////////////////////// //
445 profileFrameDraw: TProfiler = nil;
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', [prof.bars[ii].name, prof.bars[ii].value]), gStdFont, 255, 255, 0, 1, false);
556 Inc(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 = False;
608 IsDrawStat: Boolean = False;
609 CustomStat: TEndCustomGameStat;
610 SingleStat: TEndSingleGameStat;
611 LoadingStat: TLoadingStat;
612 EndingGameCounter: Byte = 0;
613 MessageText: String;
614 MessageTime: Word;
615 MessageLineLength: Integer = 80;
616 MapList: SSArray = nil;
617 MapIndex: Integer = -1;
618 InterReadyTime: Integer = -1;
619 StatShotDone: Boolean = False;
620 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
621 StatDate: string = '';
622 MegaWAD: record
623 info: TMegaWADInfo;
624 endpic: String;
625 endmus: String;
626 res: record
627 text: Array of ShortString;
628 anim: Array of ShortString;
629 pic: Array of ShortString;
630 mus: Array of ShortString;
631 end;
632 triggers: Array of record
633 event: ShortString;
634 actions: Array of record
635 action, p1, p2: Integer;
636 end;
637 end;
638 cur_trigger: Integer;
639 cur_action: Integer;
640 end;
641 //InterPic: String;
642 InterText: record
643 lines: SSArray;
644 img: String;
645 cur_line: Integer;
646 cur_char: Integer;
647 counter: Integer;
648 endtext: Boolean;
649 end;
651 function Compare(a, b: TPlayerStat): Integer;
652 begin
653 if a.Spectator then Result := 1
654 else if b.Spectator then Result := -1
655 else if a.Frags < b.Frags then Result := 1
656 else if a.Frags > b.Frags then Result := -1
657 else if a.Deaths < b.Deaths then Result := -1
658 else if a.Deaths > b.Deaths then Result := 1
659 else if a.Kills < b.Kills then Result := -1
660 else Result := 1;
661 end;
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 := e_CatPath(dir, Path);
692 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
693 fname := e_CatPath(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): TMegaWADInfo;
824 w: TWADFile;
825 cfg: TConfig;
826 p: Pointer;
827 len: Integer;
828 begin
829 Result.name := ExtractFileName(WAD);
830 Result.description := '';
831 Result.author := '';
833 w := TWADFile.Create();
834 w.ReadFile(WAD);
836 if not w.GetResource('INTERSCRIPT', p, len) then
837 begin
838 w.Free();
839 Exit;
840 end;
842 cfg := TConfig.CreateMem(p, len);
843 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
844 Result.description := cfg.ReadStr('megawad', 'description', '');
845 Result.author := cfg.ReadStr('megawad', 'author', '');
846 Result.pic := cfg.ReadStr('megawad', 'pic', '');
847 cfg.Free();
849 FreeMem(p);
850 end;
852 procedure g_Game_FreeWAD();
854 a: Integer;
855 begin
856 for a := 0 to High(MegaWAD.res.pic) do
857 if MegaWAD.res.pic[a] <> '' then
858 g_Texture_Delete(MegaWAD.res.pic[a]);
860 for a := 0 to High(MegaWAD.res.mus) do
861 if MegaWAD.res.mus[a] <> '' then
862 g_Sound_Delete(MegaWAD.res.mus[a]);
864 MegaWAD.res.pic := nil;
865 MegaWAD.res.text := nil;
866 MegaWAD.res.anim := nil;
867 MegaWAD.res.mus := nil;
868 MegaWAD.triggers := nil;
870 g_Texture_Delete('TEXTURE_endpic');
871 g_Sound_Delete('MUSIC_endmus');
873 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
874 gGameSettings.WAD := '';
875 end;
877 procedure g_Game_LoadWAD(WAD: string);
879 w: TWADFile;
880 cfg: TConfig;
881 p: Pointer;
882 {b, }len: Integer;
883 s: AnsiString;
884 begin
885 g_Game_FreeWAD();
886 gGameSettings.WAD := WAD;
887 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
888 Exit;
890 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
892 w := TWADFile.Create();
893 w.ReadFile(WAD);
895 if not w.GetResource('INTERSCRIPT', p, len) then
896 begin
897 w.Free();
898 Exit;
899 end;
901 cfg := TConfig.CreateMem(p, len);
903 {b := 1;
904 while True do
905 begin
906 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
907 if s = '' then Break;
908 b := b+1;
910 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
911 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
913 g_Texture_CreateWADEx(s, s);
914 end;
916 b := 1;
917 while True do
918 begin
919 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
920 if s = '' then Break;
921 b := b+1;
923 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
924 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
926 g_Music_CreateWADEx(s, s);
927 end;}
929 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
930 if MegaWAD.endpic <> '' then
931 begin
932 TEXTUREFILTER := GL_LINEAR;
933 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
934 g_Texture_CreateWADEx('TEXTURE_endpic', s);
935 TEXTUREFILTER := GL_NEAREST;
936 end;
937 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
938 if MegaWAD.endmus <> '' then
939 begin
940 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
941 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
942 end;
944 cfg.Free();
945 FreeMem(p);
946 w.Free();
947 end;
949 {procedure start_trigger(t: string);
950 begin
951 end;
953 function next_trigger(): Boolean;
954 begin
955 end;}
957 procedure DisableCheats();
958 begin
959 MAX_RUNVEL := 8;
960 VEL_JUMP := 10;
961 gFly := False;
963 if gPlayer1 <> nil then gPlayer1.GodMode := False;
964 if gPlayer2 <> nil then gPlayer2.GodMode := False;
965 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
966 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
968 {$IF DEFINED(D2F_DEBUG)}
969 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
970 gAimLine := g_dbg_aimline_on;
971 {$ENDIF}
972 end;
974 procedure g_Game_ExecuteEvent(Name: String);
976 a: Integer;
977 begin
978 if Name = '' then
979 Exit;
980 if gEvents = nil then
981 Exit;
982 for a := 0 to High(gEvents) do
983 if gEvents[a].Name = Name then
984 begin
985 if gEvents[a].Command <> '' then
986 g_Console_Process(gEvents[a].Command, True);
987 break;
988 end;
989 end;
991 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
993 a, n: Integer;
994 begin
995 n := -1;
996 if gDelayedEvents <> nil then
997 for a := 0 to High(gDelayedEvents) do
998 if not gDelayedEvents[a].Pending then
999 begin
1000 n := a;
1001 break;
1002 end;
1003 if n = -1 then
1004 begin
1005 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
1006 n := High(gDelayedEvents);
1007 end;
1008 gDelayedEvents[n].Pending := True;
1009 gDelayedEvents[n].DEType := DEType;
1010 gDelayedEvents[n].DENum := Num;
1011 gDelayedEvents[n].DEStr := Str;
1012 if DEType = DE_GLOBEVENT then
1013 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
1014 else
1015 gDelayedEvents[n].Time := gTime + Time;
1016 Result := n;
1017 end;
1019 procedure EndGame();
1021 a: Integer;
1022 FileName: string;
1023 t: TDateTime;
1024 begin
1025 if g_Game_IsNet and g_Game_IsServer then
1026 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1028 // Ñòîï èãðà:
1029 gPauseMain := false;
1030 gPauseHolmes := false;
1031 gGameOn := false;
1033 g_Game_StopAllSounds(False);
1035 MessageTime := 0;
1036 MessageText := '';
1038 EndingGameCounter := 0;
1039 g_ActiveWindow := nil;
1041 gLMSRespawn := LMS_RESPAWN_NONE;
1042 gLMSRespawnTime := 0;
1044 case gExit of
1045 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1046 begin
1047 g_Game_Free();
1049 if gMapOnce then
1050 begin // Ýòî áûë òåñò
1051 gExit := EXIT_QUIT;
1053 else
1054 begin // Âûõîä â ãëàâíîå ìåíþ
1055 gMusic.SetByName('MUSIC_MENU');
1056 gMusic.Play();
1057 if gState <> STATE_SLIST then
1058 begin
1059 g_GUI_ShowWindow('MainMenu');
1060 gState := STATE_MENU;
1061 end else
1062 begin
1063 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1064 slReturnPressed := True;
1065 if g_Net_Slist_Fetch(slCurrent) then
1066 begin
1067 if slCurrent = nil then
1068 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1070 else
1071 slWaitStr := _lc[I_NET_SLIST_ERROR];
1072 g_Serverlist_GenerateTable(slCurrent, slTable);
1073 end;
1075 g_Game_ExecuteEvent('ongameend');
1076 end;
1077 end;
1079 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
1080 begin
1081 if not g_Game_IsClient then g_Game_Restart();
1082 end;
1084 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1085 begin
1086 // Ñòàòèñòèêà Ñâîåé èãðû:
1087 FileName := g_ExtractWadName(gMapInfo.Map);
1089 CustomStat.GameTime := gTime;
1090 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1091 CustomStat.MapName := gMapInfo.Name;
1092 CustomStat.GameMode := gGameSettings.GameMode;
1093 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1094 CustomStat.TeamStat := gTeamStat;
1096 CustomStat.PlayerStat := nil;
1098 // Ñòàòèñòèêà èãðîêîâ:
1099 if gPlayers <> nil then
1100 begin
1101 for a := 0 to High(gPlayers) do
1102 if gPlayers[a] <> nil then
1103 begin
1104 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1105 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1106 begin
1107 Num := a;
1108 Name := gPlayers[a].Name;
1109 Frags := gPlayers[a].Frags;
1110 Deaths := gPlayers[a].Death;
1111 Kills := gPlayers[a].Kills;
1112 Team := gPlayers[a].Team;
1113 Color := gPlayers[a].Model.Color;
1114 Spectator := gPlayers[a].FSpectator;
1115 end;
1116 end;
1118 SortGameStat(CustomStat.PlayerStat);
1120 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1121 begin
1122 t := Now;
1123 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1124 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1125 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1126 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1127 if gSaveStats then
1128 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1129 end;
1131 StatShotDone := False;
1132 end;
1134 g_Game_ExecuteEvent('onmapend');
1135 if not g_Game_IsClient then g_Player_ResetReady;
1136 gInterReadyCount := 0;
1138 // Çàòóõàþùèé ýêðàí:
1139 EndingGameCounter := 255;
1140 gState := STATE_FOLD;
1141 gInterTime := 0;
1142 if gDefInterTime < 0 then
1143 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1144 else
1145 gInterEndTime := gDefInterTime * 1000;
1146 end;
1148 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1149 begin
1150 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1151 SingleStat.GameTime := gTime;
1152 SingleStat.TwoPlayers := gPlayer2 <> nil;
1153 SingleStat.TotalSecrets := gSecretsCount;
1154 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1155 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1156 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1157 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1158 if SingleStat.TwoPlayers then
1159 begin
1160 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1161 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1162 end;
1164 g_Game_ExecuteEvent('onmapend');
1166 // Åñòü åùå êàðòû:
1167 if gNextMap <> '' then
1168 begin
1169 gMusic.SetByName('MUSIC_INTERMUS');
1170 gMusic.Play();
1171 gState := STATE_INTERSINGLE;
1172 e_UnpressAllKeys();
1174 g_Game_ExecuteEvent('oninter');
1176 else // Áîëüøå íåò êàðò
1177 begin
1178 // Çàòóõàþùèé ýêðàí:
1179 EndingGameCounter := 255;
1180 gState := STATE_FOLD;
1181 end;
1182 end;
1183 end;
1185 // Îêîí÷àíèå îáðàáîòàíî:
1186 if gExit <> EXIT_QUIT then
1187 gExit := 0;
1188 end;
1190 procedure drawTime(X, Y: Integer); inline;
1191 begin
1192 e_TextureFontPrint(x, y,
1193 Format('%d:%.2d:%.2d', [
1194 gTime div 1000 div 3600,
1195 (gTime div 1000 div 60) mod 60,
1196 gTime div 1000 mod 60
1198 gStdFont);
1199 end;
1201 procedure DrawStat();
1203 pc, x, y, w, h: Integer;
1204 w1, w2, w3, w4: Integer;
1205 a, aa: Integer;
1206 cw, ch, r, g, b, rr, gg, bb: Byte;
1207 s1, s2, s3: String;
1208 _y: Integer;
1209 stat: TPlayerStatArray;
1210 wad, map: string;
1211 mapstr: string;
1212 namestr: string;
1213 begin
1214 s1 := '';
1215 s2 := '';
1216 s3 := '';
1217 pc := g_Player_GetCount;
1218 e_TextureFontGetSize(gStdFont, cw, ch);
1220 w := gScreenWidth-(gScreenWidth div 5);
1221 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1222 h := 32+ch*(11+pc)
1223 else
1224 h := 40+ch*5+(ch+8)*pc;
1225 x := (gScreenWidth div 2)-(w div 2);
1226 y := (gScreenHeight div 2)-(h div 2);
1228 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1229 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1231 drawTime(x+w-78, y+8);
1233 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1234 map := g_ExtractFileName(gMapInfo.Map);
1235 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1237 case gGameSettings.GameMode of
1238 GM_DM:
1239 begin
1240 if gGameSettings.MaxLives = 0 then
1241 s1 := _lc[I_GAME_DM]
1242 else
1243 s1 := _lc[I_GAME_LMS];
1244 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1245 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1246 end;
1248 GM_TDM:
1249 begin
1250 if gGameSettings.MaxLives = 0 then
1251 s1 := _lc[I_GAME_TDM]
1252 else
1253 s1 := _lc[I_GAME_TLMS];
1254 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1255 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1256 end;
1258 GM_CTF:
1259 begin
1260 s1 := _lc[I_GAME_CTF];
1261 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
1262 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1263 end;
1265 GM_COOP:
1266 begin
1267 if gGameSettings.MaxLives = 0 then
1268 s1 := _lc[I_GAME_COOP]
1269 else
1270 s1 := _lc[I_GAME_SURV];
1271 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1272 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1273 end;
1275 else
1276 begin
1277 s1 := '';
1278 s2 := '';
1279 end;
1280 end;
1282 _y := y+8;
1283 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1284 _y := _y+ch+8;
1285 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1286 _y := _y+ch+8;
1287 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1289 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1290 gStdFont, 200, 200, 200, 1);
1292 if NetMode = NET_SERVER then
1293 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1294 else
1295 if NetMode = NET_CLIENT then
1296 e_TextureFontPrintEx(x+8, y + 8,
1297 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1299 if pc = 0 then
1300 Exit;
1301 stat := g_Player_GetStats();
1302 SortGameStat(stat);
1304 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1305 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1306 w4 := w3;
1307 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1309 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1310 begin
1311 _y := _y+ch+ch;
1313 for a := TEAM_RED to TEAM_BLUE do
1314 begin
1315 if a = TEAM_RED then
1316 begin
1317 s1 := _lc[I_GAME_TEAM_RED];
1318 r := 255;
1319 g := 0;
1320 b := 0;
1322 else
1323 begin
1324 s1 := _lc[I_GAME_TEAM_BLUE];
1325 r := 0;
1326 g := 0;
1327 b := 255;
1328 end;
1330 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1331 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Score),
1332 gStdFont, r, g, b, 1);
1334 _y := _y+ch+(ch div 4);
1335 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1336 _y := _y+(ch div 4);
1338 for aa := 0 to High(stat) do
1339 if stat[aa].Team = a then
1340 with stat[aa] do
1341 begin
1342 if Spectator then
1343 begin
1344 rr := r div 2;
1345 gg := g div 2;
1346 bb := b div 2;
1348 else
1349 begin
1350 rr := r;
1351 gg := g;
1352 bb := b;
1353 end;
1354 if gShowPIDs then
1355 namestr := Format('[%5d] %s', [UID, Name])
1356 else
1357 namestr := Name;
1358 // Èìÿ
1359 e_TextureFontPrintEx(x+16, _y, namestr, gStdFont, rr, gg, bb, 1);
1360 // Ïèíã/ïîòåðè
1361 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1362 // Ôðàãè
1363 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1364 // Ñìåðòè
1365 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1366 _y := _y+ch;
1367 end;
1369 _y := _y+ch;
1370 end;
1372 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1373 begin
1374 _y := _y+ch+ch;
1375 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1376 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1377 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1378 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1380 _y := _y+ch+8;
1381 for aa := 0 to High(stat) do
1382 with stat[aa] do
1383 begin
1384 if Spectator then
1385 begin
1386 r := 127;
1387 g := 64;
1389 else
1390 begin
1391 r := 255;
1392 g := 127;
1393 end;
1394 if gShowPIDs then
1395 namestr := Format('[%5d] %s', [UID, Name])
1396 else
1397 namestr := Name;
1398 // Öâåò èãðîêà
1399 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1400 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1401 // Èìÿ
1402 e_TextureFontPrintEx(x+16+16+8, _y+4, namestr, gStdFont, r, g, 0, 1);
1403 // Ïèíã/ïîòåðè
1404 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1405 // Ôðàãè
1406 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1407 // Ñìåðòè
1408 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1409 _y := _y+ch+8;
1410 end;
1412 end;
1414 procedure g_Game_Init();
1416 SR: TSearchRec;
1417 knownFiles: array of AnsiString = nil;
1418 found: Boolean;
1419 wext, s: AnsiString;
1420 f: Integer;
1421 begin
1422 gExit := 0;
1423 gMapToDelete := '';
1424 gTempDelete := False;
1426 sfsGCDisable(); // temporary disable removing of temporary volumes
1429 TEXTUREFILTER := GL_LINEAR;
1430 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1431 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1432 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1433 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1434 TEXTUREFILTER := GL_NEAREST;
1436 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1437 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1438 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1440 g_Game_ClearLoading();
1441 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1442 g_Game_SetLoadingText('', 0, False);
1444 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1445 g_Console_Init();
1447 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1448 g_PlayerModel_LoadData();
1450 // load models from all possible wad types, in all known directories
1451 // this does a loosy job (linear search, ooph!), but meh
1452 for wext in wadExtensions do
1453 begin
1454 for f := High(ModelDirs) downto Low(ModelDirs) do
1455 begin
1456 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1457 begin
1458 repeat
1459 found := false;
1460 for s in knownFiles do
1461 begin
1462 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1463 begin
1464 found := true;
1465 break;
1466 end;
1467 end;
1468 if not found then
1469 begin
1470 SetLength(knownFiles, length(knownFiles)+1);
1471 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1472 end;
1473 until (FindNext(SR) <> 0);
1474 end;
1475 FindClose(SR);
1476 end;
1477 end;
1479 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1481 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);
1482 for s in knownFiles do
1483 begin
1484 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1485 end;
1487 gGameOn := false;
1488 gPauseMain := false;
1489 gPauseHolmes := false;
1490 gTime := 0;
1492 {e_MouseInfo.Accel := 1.0;}
1494 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1495 g_Game_LoadData();
1497 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1498 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1499 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1500 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1501 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1503 {$IFNDEF HEADLESS}
1504 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1505 g_Menu_Init();
1506 {$ENDIF}
1508 gMusic := TMusic.Create();
1509 gMusic.SetByName('MUSIC_MENU');
1510 gMusic.Play();
1512 gGameSettings.WarmupTime := 30;
1514 gState := STATE_MENU;
1516 SetLength(gEvents, 6);
1517 gEvents[0].Name := 'ongamestart';
1518 gEvents[1].Name := 'ongameend';
1519 gEvents[2].Name := 'onmapstart';
1520 gEvents[3].Name := 'onmapend';
1521 gEvents[4].Name := 'oninter';
1522 gEvents[5].Name := 'onwadend';
1523 finally
1524 sfsGCEnable(); // enable releasing unused volumes
1525 end;
1526 end;
1528 procedure g_Game_Free(freeTextures: Boolean=true);
1529 begin
1530 e_WriteLog('g_Game_Free: completion of the gameplay', TMsgType.Notify);
1531 if NetMode = NET_CLIENT then g_Net_Disconnect();
1532 if NetMode = NET_SERVER then g_Net_Host_Die();
1534 g_Map_Free(freeTextures);
1535 g_Player_Free();
1536 g_Player_RemoveAllCorpses();
1538 gGameSettings.GameType := GT_NONE;
1539 if gGameSettings.GameMode = GM_SINGLE then
1540 gGameSettings.GameMode := GM_DM;
1541 gSwitchGameMode := gGameSettings.GameMode;
1543 gChatShow := False;
1544 gExitByTrigger := False;
1545 end;
1547 function IsActivePlayer(p: TPlayer): Boolean;
1548 begin
1549 Result := False;
1550 if p = nil then
1551 Exit;
1552 Result := (not p.FDummy) and (not p.FSpectator);
1553 end;
1555 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1557 a: Integer;
1558 begin
1559 Result := nil;
1560 if ID < 0 then
1561 Exit;
1562 if gPlayers = nil then
1563 Exit;
1564 for a := Low(gPlayers) to High(gPlayers) do
1565 if IsActivePlayer(gPlayers[a]) then
1566 begin
1567 if gPlayers[a].UID <> ID then
1568 continue;
1569 Result := gPlayers[a];
1570 break;
1571 end;
1572 end;
1574 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1576 a, idx: Integer;
1577 ids: Array of Word;
1578 begin
1579 Result := -1;
1580 if gPlayers = nil then
1581 Exit;
1582 SetLength(ids, 0);
1583 idx := -1;
1584 for a := Low(gPlayers) to High(gPlayers) do
1585 if IsActivePlayer(gPlayers[a]) then
1586 begin
1587 SetLength(ids, Length(ids) + 1);
1588 ids[High(ids)] := gPlayers[a].UID;
1589 if gPlayers[a].UID = Skip then
1590 idx := High(ids);
1591 end;
1592 if Length(ids) = 0 then
1593 Exit;
1594 if idx = -1 then
1595 Result := ids[0]
1596 else
1597 Result := ids[(idx + 1) mod Length(ids)];
1598 end;
1600 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1602 a, idx: Integer;
1603 ids: Array of Word;
1604 begin
1605 Result := -1;
1606 if gPlayers = nil then
1607 Exit;
1608 SetLength(ids, 0);
1609 idx := -1;
1610 for a := Low(gPlayers) to High(gPlayers) do
1611 if IsActivePlayer(gPlayers[a]) then
1612 begin
1613 SetLength(ids, Length(ids) + 1);
1614 ids[High(ids)] := gPlayers[a].UID;
1615 if gPlayers[a].UID = Skip then
1616 idx := High(ids);
1617 end;
1618 if Length(ids) = 0 then
1619 Exit;
1620 if idx = -1 then
1621 Result := ids[Length(ids) - 1]
1622 else
1623 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1624 end;
1626 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1628 a, idx: Integer;
1629 ids: Array of Word;
1630 begin
1631 Result := -1;
1632 if gPlayers = nil then
1633 Exit;
1634 SetLength(ids, 0);
1635 idx := -1;
1636 for a := Low(gPlayers) to High(gPlayers) do
1637 if IsActivePlayer(gPlayers[a]) then
1638 begin
1639 SetLength(ids, Length(ids) + 1);
1640 ids[High(ids)] := gPlayers[a].UID;
1641 if gPlayers[a].UID = Skip then
1642 idx := High(ids);
1643 end;
1644 if Length(ids) = 0 then
1645 Exit;
1646 if Length(ids) = 1 then
1647 begin
1648 Result := ids[0];
1649 Exit;
1650 end;
1651 Result := ids[Random(Length(ids))];
1652 a := 10;
1653 while (idx <> -1) and (Result = Skip) and (a > 0) do
1654 begin
1655 Result := ids[Random(Length(ids))];
1656 Dec(a);
1657 end;
1658 end;
1660 function GetRandomSpectMode(Current: Byte): Byte;
1661 label
1662 retry;
1663 begin
1664 Result := Current;
1665 retry:
1666 case Random(7) of
1667 0: Result := SPECT_STATS;
1668 1: Result := SPECT_MAPVIEW;
1669 2: Result := SPECT_MAPVIEW;
1670 3: Result := SPECT_PLAYERS;
1671 4: Result := SPECT_PLAYERS;
1672 5: Result := SPECT_PLAYERS;
1673 6: Result := SPECT_PLAYERS;
1674 end;
1675 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1676 goto retry;
1677 end;
1679 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1681 time: Word;
1682 strafeDir: Byte;
1683 i: Integer;
1684 begin
1685 if (plr = nil) then exit;
1686 if (p = 2) then time := 1000 else time := 1;
1687 strafeDir := MoveButton shr 4;
1688 MoveButton := MoveButton and $0F;
1690 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1691 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1692 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1693 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1694 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1695 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1697 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1698 if MoveButton = 1 then
1699 plr.PressKey(KEY_LEFT, time)
1700 else if MoveButton = 2 then
1701 plr.PressKey(KEY_RIGHT, time);
1703 // if we have "strafe" key, turn off old strafe mechanics
1704 if gPlayerAction[p, ACTION_STRAFE] then
1705 begin
1706 // new strafe mechanics
1707 if (strafeDir = 0) then
1708 strafeDir := MoveButton; // start strafing
1709 // now set direction according to strafe (reversed)
1710 if (strafeDir = 2) then
1711 plr.SetDirection(TDirection.D_LEFT)
1712 else if (strafeDir = 1) then
1713 plr.SetDirection(TDirection.D_RIGHT)
1715 else
1716 begin
1717 strafeDir := 0; // not strafing anymore
1718 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1719 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1720 plr.SetDirection(TDirection.D_LEFT)
1721 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1722 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1723 plr.SetDirection(TDirection.D_RIGHT)
1724 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1725 else if MoveButton <> 0 then
1726 plr.SetDirection(TDirection(MoveButton-1))
1727 end;
1729 // fix movebutton state
1730 MoveButton := MoveButton or (strafeDir shl 4);
1732 // Îñòàëüíûå êëàâèøè:
1733 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1734 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1735 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1736 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1737 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1739 for i := WP_FACT to WP_LACT do
1740 begin
1741 if gWeaponAction[p, i] then
1742 begin
1743 plr.ProcessWeaponAction(i);
1744 gWeaponAction[p, i] := False
1746 end;
1748 for i := WP_FIRST to WP_LAST do
1749 begin
1750 if gSelectWeapon[p, i] then
1751 begin
1752 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1753 gSelectWeapon[p, i] := False
1755 end;
1757 // HACK: add dynlight here
1758 if gwin_k8_enable_light_experiments then
1759 begin
1760 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1761 begin
1762 g_playerLight := true;
1763 end;
1764 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1765 begin
1766 g_playerLight := false;
1767 end;
1768 end;
1770 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1771 end;
1773 // HACK: don't have a "key was pressed" function
1774 procedure InterReady();
1775 begin
1776 if InterReadyTime > gTime then Exit;
1777 InterReadyTime := gTime + 3000;
1778 MC_SEND_CheatRequest(NET_CHEAT_READY);
1779 end;
1781 procedure g_Game_PreUpdate();
1782 begin
1783 // these are in separate PreUpdate functions because they can interact during Update()
1784 // and are synced over the net
1785 // we don't care that much about corpses and gibs
1786 g_Player_PreUpdate();
1787 g_Monsters_PreUpdate();
1788 g_Items_PreUpdate();
1789 g_Weapon_PreUpdate();
1790 end;
1792 procedure g_Game_Update();
1794 Msg: g_gui.TMessage;
1795 Time: Int64;
1796 a: Byte;
1797 w: Word;
1798 i, b: Integer;
1800 function sendMonsPos (mon: TMonster): Boolean;
1801 begin
1802 result := false; // don't stop
1803 // this will also reset "need-send" flag
1804 if mon.gncNeedSend then
1805 begin
1806 MH_SEND_MonsterPos(mon.UID);
1808 else if (mon.MonsterType = MONSTER_BARREL) then
1809 begin
1810 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1812 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1813 begin
1814 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1815 end;
1816 end;
1818 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1819 begin
1820 result := false; // don't stop
1821 // this will also reset "need-send" flag
1822 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1823 end;
1825 function sendItemPos (it: PItem): Boolean;
1826 begin
1827 result := false; // don't stop
1828 if it.needSend then
1829 begin
1830 MH_SEND_ItemPos(it.myId);
1831 it.needSend := False;
1832 end;
1833 end;
1836 reliableUpdate: Boolean;
1837 begin
1838 g_ResetDynlights();
1839 framePool.reset();
1841 // Ïîðà âûêëþ÷àòü èãðó:
1842 if gExit = EXIT_QUIT then
1843 Exit;
1844 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1845 if gExit <> 0 then
1846 begin
1847 EndGame();
1848 if gExit = EXIT_QUIT then
1849 Exit;
1850 end;
1852 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1853 // no need to, as we'll do it in event handler
1855 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1856 g_Console_Update();
1858 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1859 begin
1860 gExit := EXIT_SIMPLE;
1861 EndGame();
1862 Exit;
1863 end;
1865 // process master server communications
1866 g_Net_Slist_Pulse();
1868 case gState of
1869 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1870 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1871 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1872 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1873 begin
1874 if g_Game_IsNet and g_Game_IsServer then
1875 begin
1876 gInterTime := gInterTime + GAME_TICK;
1877 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1878 if a <> gServInterTime then
1879 begin
1880 gServInterTime := a;
1881 MH_SEND_TimeSync(gServInterTime);
1882 end;
1883 end;
1885 if (not g_Game_IsClient) and
1889 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1890 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1891 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1892 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1894 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1895 and (g_ActiveWindow = nil)
1897 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1899 then
1900 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1901 g_Game_StopAllSounds(True);
1903 if gMapOnce then // Ýòî áûë òåñò
1904 gExit := EXIT_SIMPLE
1905 else
1906 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1907 g_Game_ChangeMap(gNextMap)
1908 else // Ñëåäóþùåé êàðòû íåò
1909 begin
1910 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1911 begin
1912 // Âûõîä â ãëàâíîå ìåíþ:
1913 g_Game_Free();
1914 g_GUI_ShowWindow('MainMenu');
1915 gMusic.SetByName('MUSIC_MENU');
1916 gMusic.Play();
1917 gState := STATE_MENU;
1918 end else
1919 begin
1920 // Ôèíàëüíàÿ êàðòèíêà:
1921 g_Game_ExecuteEvent('onwadend');
1922 g_Game_Free();
1923 if not gMusic.SetByName('MUSIC_endmus') then
1924 gMusic.SetByName('MUSIC_STDENDMUS');
1925 gMusic.Play();
1926 gState := STATE_ENDPIC;
1927 end;
1928 g_Game_ExecuteEvent('ongameend');
1929 end;
1931 Exit;
1933 else if g_Game_IsClient and
1936 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1937 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1938 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1939 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1941 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1942 and (g_ActiveWindow = nil)
1944 then
1945 begin
1946 // ready / unready
1947 InterReady();
1948 end;
1950 if gState = STATE_INTERTEXT then
1951 if InterText.counter > 0 then
1952 InterText.counter := InterText.counter - 1;
1953 end;
1955 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1956 begin
1957 if EndingGameCounter = 0 then
1958 begin
1959 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1960 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1961 begin
1962 gState := STATE_INTERCUSTOM;
1963 InterReadyTime := -1;
1964 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1965 begin
1966 g_Game_ExecuteEvent('onwadend');
1967 if not gMusic.SetByName('MUSIC_endmus') then
1968 gMusic.SetByName('MUSIC_STDENDMUS');
1970 else
1971 gMusic.SetByName('MUSIC_ROUNDMUS');
1972 gMusic.Play();
1973 e_UnpressAllKeys();
1975 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1976 begin
1977 gMusic.SetByName('MUSIC_INTERMUS');
1978 gMusic.Play();
1979 gState := STATE_INTERSINGLE;
1980 e_UnpressAllKeys();
1981 end;
1982 g_Game_ExecuteEvent('oninter');
1984 else
1985 DecMin(EndingGameCounter, 6, 0);
1986 end;
1988 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1989 begin
1990 if gMapOnce then // Ýòî áûë òåñò
1991 begin
1992 gExit := EXIT_SIMPLE;
1993 Exit;
1994 end;
1995 end;
1997 STATE_SLIST:
1998 g_Serverlist_Control(slCurrent, slTable);
1999 end;
2001 // Ñòàòèñòèêà ïî Tab:
2002 if gGameOn then
2003 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
2005 // Èãðà èäåò:
2006 if gGameOn and not gPause and (gState <> STATE_FOLD) then
2007 begin
2008 // Âðåìÿ += 28 ìèëëèñåêóíä:
2009 gTime := gTime + GAME_TICK;
2011 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
2012 if MessageTime = 0 then
2013 MessageText := '';
2014 if MessageTime > 0 then
2015 MessageTime := MessageTime - 1;
2017 if (g_Game_IsServer) then
2018 begin
2019 // Áûë çàäàí ëèìèò âðåìåíè:
2020 if (gGameSettings.TimeLimit > 0) then
2021 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
2022 begin // Îí ïðîøåë => êîíåö óðîâíÿ
2023 g_Game_NextLevel();
2024 Exit;
2025 end;
2027 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
2028 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
2029 g_Game_RestartRound(gLMSSoftSpawn);
2031 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
2032 if gVoteInProgress and (gVoteTimer < gTime) then
2033 g_Game_CheckVote
2034 else if gVotePassed and (gVoteCmdTimer < gTime) then
2035 begin
2036 g_Console_Process(gVoteCommand);
2037 gVoteCommand := '';
2038 gVotePassed := False;
2039 end;
2041 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2042 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2043 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
2044 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2045 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
2047 // Áûë çàäàí ëèìèò ïîáåä:
2048 if (gGameSettings.ScoreLimit > 0) then
2049 begin
2050 b := 0;
2052 if gGameSettings.GameMode = GM_DM then
2053 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2054 for i := 0 to High(gPlayers) do
2055 if gPlayers[i] <> nil then
2056 if gPlayers[i].Frags > b then
2057 b := gPlayers[i].Frags;
2059 else
2060 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2061 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2062 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
2063 end;
2065 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2066 if b >= gGameSettings.ScoreLimit then
2067 begin
2068 g_Game_NextLevel();
2069 Exit;
2070 end;
2071 end;
2073 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2074 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2075 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2076 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2077 begin
2078 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2079 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2080 end // if not console
2081 else
2082 begin
2083 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2084 end;
2085 // process weapon switch queue
2086 end; // if server
2088 // Íàáëþäàòåëü
2089 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2090 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2091 begin
2092 if not gSpectKeyPress then
2093 begin
2094 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2095 begin
2096 // switch spect mode
2097 case gSpectMode of
2098 SPECT_NONE: ; // not spectator
2099 SPECT_STATS,
2100 SPECT_MAPVIEW: Inc(gSpectMode);
2101 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2102 end;
2103 gSpectKeyPress := True;
2104 end;
2105 if (gSpectMode = SPECT_MAPVIEW)
2106 and (not gSpectAuto) then
2107 begin
2108 if gPlayerAction[0, ACTION_MOVELEFT] then
2109 gSpectX := Max(gSpectX - gSpectStep, 0);
2110 if gPlayerAction[0, ACTION_MOVERIGHT] then
2111 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2112 if gPlayerAction[0, ACTION_LOOKUP] then
2113 gSpectY := Max(gSpectY - gSpectStep, 0);
2114 if gPlayerAction[0, ACTION_LOOKDOWN] then
2115 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2116 if gWeaponAction[0, WP_PREV] then
2117 begin
2118 // decrease step
2119 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2120 gWeaponAction[0, WP_PREV] := False;
2121 end;
2122 if gWeaponAction[0, WP_NEXT] then
2123 begin
2124 // increase step
2125 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2126 gWeaponAction[0, WP_NEXT] := False;
2127 end;
2128 end;
2129 if (gSpectMode = SPECT_PLAYERS)
2130 and (not gSpectAuto) then
2131 begin
2132 if gPlayerAction[0, ACTION_LOOKUP] then
2133 begin
2134 // add second view
2135 gSpectViewTwo := True;
2136 gSpectKeyPress := True;
2137 end;
2138 if gPlayerAction[0, ACTION_LOOKDOWN] then
2139 begin
2140 // remove second view
2141 gSpectViewTwo := False;
2142 gSpectKeyPress := True;
2143 end;
2144 if gPlayerAction[0, ACTION_MOVELEFT] then
2145 begin
2146 // prev player (view 1)
2147 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2148 gSpectKeyPress := True;
2149 end;
2150 if gPlayerAction[0, ACTION_MOVERIGHT] then
2151 begin
2152 // next player (view 1)
2153 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2154 gSpectKeyPress := True;
2155 end;
2156 if gWeaponAction[0, WP_PREV] then
2157 begin
2158 // prev player (view 2)
2159 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2160 gWeaponAction[0, WP_PREV] := False;
2161 end;
2162 if gWeaponAction[0, WP_NEXT] then
2163 begin
2164 // next player (view 2)
2165 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2166 gWeaponAction[0, WP_NEXT] := False;
2167 end;
2168 end;
2169 if gPlayerAction[0, ACTION_ATTACK] then
2170 begin
2171 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2172 begin
2173 gSpectAuto := True;
2174 gSpectAutoNext := 0;
2175 gSpectViewTwo := False;
2176 gSpectKeyPress := True;
2178 else
2179 if gSpectAuto then
2180 begin
2181 gSpectMode := SPECT_STATS;
2182 gSpectAuto := False;
2183 gSpectKeyPress := True;
2184 end;
2185 end;
2187 else
2188 if (not gPlayerAction[0, ACTION_JUMP]) and
2189 (not gPlayerAction[0, ACTION_ATTACK]) and
2190 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2191 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2192 (not gPlayerAction[0, ACTION_LOOKUP]) and
2193 (not gPlayerAction[0, ACTION_LOOKDOWN]) then
2194 gSpectKeyPress := False;
2196 if gSpectAuto then
2197 begin
2198 if gSpectMode = SPECT_MAPVIEW then
2199 begin
2200 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2201 if i = gSpectX then
2202 gSpectAutoNext := gTime
2203 else
2204 gSpectX := i;
2205 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2206 if i = gSpectY then
2207 gSpectAutoNext := gTime
2208 else
2209 gSpectY := i;
2210 end;
2211 if gSpectAutoNext <= gTime then
2212 begin
2213 if gSpectAutoNext > 0 then
2214 begin
2215 gSpectMode := GetRandomSpectMode(gSpectMode);
2216 case gSpectMode of
2217 SPECT_MAPVIEW:
2218 begin
2219 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2220 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2221 gSpectAutoStepX := Random(9) - 4;
2222 gSpectAutoStepY := Random(9) - 4;
2223 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2224 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2225 gSpectAutoStepX := gSpectAutoStepX * -1;
2226 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2227 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2228 gSpectAutoStepY := gSpectAutoStepY * -1;
2229 end;
2230 SPECT_PLAYERS:
2231 begin
2232 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2233 end;
2234 end;
2235 end;
2236 case gSpectMode of
2237 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2238 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2239 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2240 end;
2241 end;
2242 end;
2243 end;
2245 // Îáíîâëÿåì âñå îñòàëüíîå:
2246 g_Map_Update();
2247 g_Items_Update();
2248 g_Triggers_Update();
2249 g_Weapon_Update();
2250 g_Monsters_Update();
2251 g_GFX_Update();
2252 g_Player_UpdateAll();
2253 g_Player_UpdatePhysicalObjects();
2255 // server: send newly spawned monsters unconditionally
2256 if (gGameSettings.GameType = GT_SERVER) then
2257 begin
2258 if (Length(gMonstersSpawned) > 0) then
2259 begin
2260 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2261 SetLength(gMonstersSpawned, 0);
2262 end;
2263 end;
2265 if (gSoundTriggerTime > 8) then
2266 begin
2267 g_Game_UpdateTriggerSounds();
2268 gSoundTriggerTime := 0;
2270 else
2271 begin
2272 Inc(gSoundTriggerTime);
2273 end;
2275 if (NetMode = NET_SERVER) then
2276 begin
2277 Inc(NetTimeToUpdate);
2278 Inc(NetTimeToReliable);
2280 // send monster updates
2281 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2282 begin
2283 // send all monsters (periodic sync)
2284 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2286 for I := 0 to High(gPlayers) do
2287 begin
2288 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2289 end;
2291 g_Mons_ForEach(sendMonsPos);
2293 // update flags that aren't stationary
2294 if gGameSettings.GameMode = GM_CTF then
2295 for I := FLAG_RED to FLAG_BLUE do
2296 if gFlags[I].NeedSend then
2297 begin
2298 gFlags[I].NeedSend := False;
2299 MH_SEND_FlagPos(I);
2300 end;
2302 // update items that aren't stationary
2303 g_Items_ForEachAlive(sendItemPos);
2305 if reliableUpdate then
2306 begin
2307 NetTimeToReliable := 0;
2308 NetTimeToUpdate := NetUpdateRate;
2310 else
2311 begin
2312 NetTimeToUpdate := 0;
2313 end;
2315 else
2316 begin
2317 // send only mosters with some unexpected changes
2318 g_Mons_ForEach(sendMonsPosUnexpected);
2319 end;
2321 // send unexpected platform changes
2322 g_Map_NetSendInterestingPanels();
2324 g_Net_Slist_ServerUpdate();
2326 if NetUseMaster then
2327 begin
2328 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2329 begin
2330 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2331 g_Net_Slist_Update;
2332 NetTimeToMaster := gTime + NetMasterRate;
2333 end;
2334 end;
2337 else if (NetMode = NET_CLIENT) then
2338 begin
2339 MC_SEND_PlayerPos();
2340 end;
2341 end; // if gameOn ...
2343 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2344 if g_ActiveWindow <> nil then
2345 begin
2346 w := e_GetFirstKeyPressed();
2348 if (w <> IK_INVALID) then
2349 begin
2350 Msg.Msg := MESSAGE_DIKEY;
2351 Msg.wParam := w;
2352 g_ActiveWindow.OnMessage(Msg);
2353 end;
2355 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2356 if g_ActiveWindow <> nil then
2357 g_ActiveWindow.Update();
2359 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2360 if gResolutionChange then
2361 begin
2362 e_WriteLog('Changing resolution', TMsgType.Notify);
2363 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2364 gResolutionChange := False;
2365 g_ActiveWindow := nil;
2366 end;
2368 // Íóæíî ñìåíèòü ÿçûê:
2369 if gLanguageChange then
2370 begin
2371 //e_WriteLog('Read language file', MSG_NOTIFY);
2372 //g_Language_Load(DataDir + gLanguage + '.txt');
2373 g_Language_Set(gLanguage);
2374 {$IFNDEF HEADLESS}
2375 g_Menu_Reset();
2376 {$ENDIF}
2377 gLanguageChange := False;
2378 end;
2379 end;
2381 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2382 if e_KeyPressed(IK_F10) and
2383 gGameOn and
2384 (not gConsoleShow) and
2385 (g_ActiveWindow = nil) then
2386 begin
2387 KeyPress(IK_F10);
2388 end;
2390 Time := sys_GetTicks() {div 1000};
2392 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2393 if gDelayedEvents <> nil then
2394 for a := 0 to High(gDelayedEvents) do
2395 if gDelayedEvents[a].Pending and
2397 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2398 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2399 ) then
2400 begin
2401 case gDelayedEvents[a].DEType of
2402 DE_GLOBEVENT:
2403 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2404 DE_BFGHIT:
2405 if gGameOn then
2406 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2407 DE_KILLCOMBO:
2408 if gGameOn then
2409 begin
2410 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2411 if g_Game_IsNet and g_Game_IsServer then
2412 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2413 end;
2414 DE_BODYKILL:
2415 if gGameOn then
2416 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2417 end;
2418 gDelayedEvents[a].Pending := False;
2419 end;
2421 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2422 UPSCounter := UPSCounter + 1;
2423 if Time - UPSTime >= 1000 then
2424 begin
2425 UPS := UPSCounter;
2426 UPSCounter := 0;
2427 UPSTime := Time;
2428 end;
2430 if gGameOn then
2431 begin
2432 g_Weapon_AddDynLights();
2433 g_Items_AddDynLights();
2434 end;
2435 end;
2437 procedure g_Game_LoadChatSounds(Resource: string);
2439 WAD: TWADFile;
2440 FileName, Snd: string;
2441 p: Pointer;
2442 len, cnt, tags, i, j: Integer;
2443 cfg: TConfig;
2444 begin
2445 FileName := g_ExtractWadName(Resource);
2447 WAD := TWADFile.Create();
2448 WAD.ReadFile(FileName);
2450 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2451 begin
2452 gChatSounds := nil;
2453 WAD.Free();
2454 Exit;
2455 end;
2457 cfg := TConfig.CreateMem(p, len);
2458 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2460 SetLength(gChatSounds, cnt);
2461 for i := 0 to Length(gChatSounds) - 1 do
2462 begin
2463 gChatSounds[i].Sound := nil;
2464 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2465 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2466 if (Snd = '') or (Tags <= 0) then
2467 continue;
2468 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2469 gChatSounds[i].Sound := TPlayableSound.Create();
2470 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2471 SetLength(gChatSounds[i].Tags, tags);
2472 for j := 0 to tags - 1 do
2473 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2474 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2475 end;
2477 cfg.Free();
2478 WAD.Free();
2479 end;
2481 procedure g_Game_FreeChatSounds();
2483 i: Integer;
2484 begin
2485 for i := 0 to Length(gChatSounds) - 1 do
2486 begin
2487 gChatSounds[i].Sound.Free();
2488 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2489 end;
2490 SetLength(gChatSounds, 0);
2491 gChatSounds := nil;
2492 end;
2494 procedure g_Game_LoadData();
2496 wl, hl: Integer;
2497 wr, hr: Integer;
2498 wb, hb: Integer;
2499 wm, hm: Integer;
2500 begin
2501 if DataLoaded then Exit;
2503 e_WriteLog('Loading game data...', TMsgType.Notify);
2505 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2506 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2507 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2508 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2509 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2510 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2511 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2512 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2513 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2514 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2515 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2516 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2517 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2518 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2519 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2521 hasPBarGfx := true;
2522 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2523 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2524 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2525 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2527 if hasPBarGfx then
2528 begin
2529 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2530 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2531 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2532 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2533 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
2534 begin
2535 // yay!
2537 else
2538 begin
2539 hasPBarGfx := false;
2540 end;
2541 end;
2543 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2544 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2545 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2546 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2547 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2548 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2549 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2550 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2551 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2552 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2553 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2554 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2555 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2556 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2557 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2558 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2559 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2560 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2561 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2562 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2565 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2566 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2567 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2568 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2569 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2570 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2571 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2572 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2573 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2574 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2575 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2576 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2577 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2578 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2579 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2580 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2581 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2583 goodsnd[0] := TPlayableSound.Create();
2584 goodsnd[1] := TPlayableSound.Create();
2585 goodsnd[2] := TPlayableSound.Create();
2586 goodsnd[3] := TPlayableSound.Create();
2588 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2589 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2590 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2591 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2593 killsnd[0] := TPlayableSound.Create();
2594 killsnd[1] := TPlayableSound.Create();
2595 killsnd[2] := TPlayableSound.Create();
2596 killsnd[3] := TPlayableSound.Create();
2598 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2599 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2600 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2601 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2603 hahasnd[0] := TPlayableSound.Create();
2604 hahasnd[1] := TPlayableSound.Create();
2605 hahasnd[2] := TPlayableSound.Create();
2607 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2608 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2609 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2611 sound_get_flag[0] := TPlayableSound.Create();
2612 sound_get_flag[1] := TPlayableSound.Create();
2613 sound_lost_flag[0] := TPlayableSound.Create();
2614 sound_lost_flag[1] := TPlayableSound.Create();
2615 sound_ret_flag[0] := TPlayableSound.Create();
2616 sound_ret_flag[1] := TPlayableSound.Create();
2617 sound_cap_flag[0] := TPlayableSound.Create();
2618 sound_cap_flag[1] := TPlayableSound.Create();
2620 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2621 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2622 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2623 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2624 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2625 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2626 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2627 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2629 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2631 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2632 g_Items_LoadData();
2634 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2635 g_Weapon_LoadData();
2637 g_Monsters_LoadData();
2639 DataLoaded := True;
2640 end;
2642 procedure g_Game_FreeData();
2643 begin
2644 if not DataLoaded then Exit;
2646 g_Items_FreeData();
2647 g_Weapon_FreeData();
2648 g_Monsters_FreeData();
2650 e_WriteLog('Releasing game data...', TMsgType.Notify);
2652 g_Texture_Delete('NOTEXTURE');
2653 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2654 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2655 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2656 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2657 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2658 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2659 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2660 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2661 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2662 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2663 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2664 g_Frames_DeleteByName('FRAMES_TELEPORT');
2665 g_Frames_DeleteByName('FRAMES_PUNCH');
2666 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2667 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2668 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2669 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2670 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2671 g_Sound_Delete('SOUND_GAME_TELEPORT');
2672 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2673 g_Sound_Delete('SOUND_GAME_SECRET');
2674 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2675 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2676 g_Sound_Delete('SOUND_GAME_BULK1');
2677 g_Sound_Delete('SOUND_GAME_BULK2');
2678 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2679 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2680 g_Sound_Delete('SOUND_GAME_BURNING');
2681 g_Sound_Delete('SOUND_GAME_SWITCH1');
2682 g_Sound_Delete('SOUND_GAME_SWITCH0');
2684 goodsnd[0].Free();
2685 goodsnd[1].Free();
2686 goodsnd[2].Free();
2687 goodsnd[3].Free();
2689 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2690 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2691 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2692 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2694 killsnd[0].Free();
2695 killsnd[1].Free();
2696 killsnd[2].Free();
2697 killsnd[3].Free();
2699 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2700 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2701 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2702 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2704 hahasnd[0].Free();
2705 hahasnd[1].Free();
2706 hahasnd[2].Free();
2708 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2709 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2710 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2712 sound_get_flag[0].Free();
2713 sound_get_flag[1].Free();
2714 sound_lost_flag[0].Free();
2715 sound_lost_flag[1].Free();
2716 sound_ret_flag[0].Free();
2717 sound_ret_flag[1].Free();
2718 sound_cap_flag[0].Free();
2719 sound_cap_flag[1].Free();
2721 g_Sound_Delete('SOUND_CTF_GET1');
2722 g_Sound_Delete('SOUND_CTF_GET2');
2723 g_Sound_Delete('SOUND_CTF_LOST1');
2724 g_Sound_Delete('SOUND_CTF_LOST2');
2725 g_Sound_Delete('SOUND_CTF_RETURN1');
2726 g_Sound_Delete('SOUND_CTF_RETURN2');
2727 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2728 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2730 g_Game_FreeChatSounds();
2732 DataLoaded := False;
2733 end;
2735 procedure DrawCustomStat();
2737 pc, x, y, w, _y,
2738 w1, w2, w3,
2739 t, p, m: Integer;
2740 ww1, hh1: Word;
2741 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2742 s1, s2, topstr: String;
2743 begin
2744 e_TextureFontGetSize(gStdFont, ww2, hh2);
2746 sys_HandleEvents();
2748 if g_Console_Action(ACTION_SCORES) then
2749 begin
2750 if not gStatsPressed then
2751 begin
2752 gStatsOff := not gStatsOff;
2753 gStatsPressed := True;
2754 end;
2756 else
2757 gStatsPressed := False;
2759 if gStatsOff then
2760 begin
2761 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2762 w := (Length(s1) * ww2) div 2;
2763 x := gScreenWidth div 2 - w;
2764 y := 8;
2765 e_TextureFontPrint(x, y, s1, gStdFont);
2766 Exit;
2767 end;
2769 if (gGameSettings.GameMode = GM_COOP) then
2770 begin
2771 if gMissionFailed then
2772 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2773 else
2774 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2776 else
2777 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2779 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2780 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2782 if g_Game_IsNet then
2783 begin
2784 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2785 if not gChatShow then
2786 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2787 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2788 end;
2790 if g_Game_IsClient then
2791 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2792 else
2793 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2794 if not gChatShow then
2795 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2796 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2798 x := 32;
2799 y := 16+hh1+16;
2801 w := gScreenWidth-x*2;
2803 w2 := (w-16) div 6;
2804 w3 := w2;
2805 w1 := w-16-w2-w3;
2807 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2808 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2810 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2812 case CustomStat.GameMode of
2813 GM_DM:
2814 begin
2815 if gGameSettings.MaxLives = 0 then
2816 s1 := _lc[I_GAME_DM]
2817 else
2818 s1 := _lc[I_GAME_LMS];
2819 end;
2820 GM_TDM:
2821 begin
2822 if gGameSettings.MaxLives = 0 then
2823 s1 := _lc[I_GAME_TDM]
2824 else
2825 s1 := _lc[I_GAME_TLMS];
2826 end;
2827 GM_CTF: s1 := _lc[I_GAME_CTF];
2828 GM_COOP:
2829 begin
2830 if gGameSettings.MaxLives = 0 then
2831 s1 := _lc[I_GAME_COOP]
2832 else
2833 s1 := _lc[I_GAME_SURV];
2834 end;
2835 else s1 := '';
2836 end;
2838 _y := y+16;
2839 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2840 _y := _y+8;
2842 _y := _y+16;
2843 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2844 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2846 _y := _y+16;
2847 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2848 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2849 (CustomStat.GameTime div 1000 div 60) mod 60,
2850 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2852 pc := Length(CustomStat.PlayerStat);
2853 if pc = 0 then Exit;
2855 if CustomStat.GameMode = GM_COOP then
2856 begin
2857 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2858 _y := _y+32;
2859 s2 := _lc[I_GAME_MONSTERS];
2860 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2861 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2862 _y := _y+16;
2863 s2 := _lc[I_GAME_SECRETS];
2864 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2865 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2866 if gLastMap then
2867 begin
2868 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2869 _y := _y-16;
2870 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2871 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2872 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2873 _y := _y+16;
2874 s2 := _lc[I_GAME_SECRETS_TOTAL];
2875 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2876 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2877 end;
2878 end;
2880 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2881 begin
2882 _y := _y+16+16;
2884 with CustomStat do
2885 if TeamStat[TEAM_RED].Score > TeamStat[TEAM_BLUE].Score then s1 := _lc[I_GAME_WIN_RED]
2886 else if TeamStat[TEAM_BLUE].Score > TeamStat[TEAM_RED].Score then s1 := _lc[I_GAME_WIN_BLUE]
2887 else s1 := _lc[I_GAME_WIN_DRAW];
2889 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2890 _y := _y+40;
2892 for t := TEAM_RED to TEAM_BLUE do
2893 begin
2894 if t = TEAM_RED then
2895 begin
2896 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2897 gStdFont, 255, 0, 0, 1);
2898 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Score),
2899 gStdFont, 255, 0, 0, 1);
2900 r := 255;
2901 g := 0;
2902 b := 0;
2904 else
2905 begin
2906 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2907 gStdFont, 0, 0, 255, 1);
2908 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Score),
2909 gStdFont, 0, 0, 255, 1);
2910 r := 0;
2911 g := 0;
2912 b := 255;
2913 end;
2915 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2916 _y := _y+24;
2918 for p := 0 to High(CustomStat.PlayerStat) do
2919 if CustomStat.PlayerStat[p].Team = t then
2920 with CustomStat.PlayerStat[p] do
2921 begin
2922 if Spectator then
2923 begin
2924 rr := r div 2;
2925 gg := g div 2;
2926 bb := b div 2;
2928 else
2929 begin
2930 rr := r;
2931 gg := g;
2932 bb := b;
2933 end;
2934 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2935 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2936 else
2937 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2938 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2939 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2940 _y := _y+24;
2941 end;
2943 _y := _y+16+16;
2944 end;
2946 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2947 begin
2948 _y := _y+40;
2949 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2950 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2951 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2953 _y := _y+24;
2954 for p := 0 to High(CustomStat.PlayerStat) do
2955 with CustomStat.PlayerStat[p] do
2956 begin
2957 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2959 if Spectator then
2960 r := 127
2961 else
2962 r := 255;
2964 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2965 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2966 else
2967 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2968 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2969 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2970 _y := _y+24;
2971 end;
2972 end;
2974 // HACK: take stats screenshot immediately after the first frame of the stats showing
2975 if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
2976 begin
2977 g_TakeScreenShot('stats/' + StatFilename);
2978 StatShotDone := True;
2979 end;
2980 end;
2982 procedure DrawSingleStat();
2984 tm, key_x, val_x, y: Integer;
2985 w1, w2, h: Word;
2986 s1, s2: String;
2988 procedure player_stat(n: Integer);
2990 kpm: Real;
2992 begin
2993 // "Kills: # / #":
2994 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2995 s2 := Format(' %d', [gTotalMonsters]);
2997 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2998 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2999 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3000 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
3001 s1 := s1 + '/';
3002 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3003 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
3005 // "Kills-per-minute: ##.#":
3006 s1 := _lc[I_MENU_INTER_KPM];
3007 if tm > 0 then
3008 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
3009 else
3010 kpm := SingleStat.PlayerStat[n].Kills;
3011 s2 := Format(' %.1f', [kpm]);
3013 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
3014 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
3016 // "Secrets found: # / #":
3017 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
3018 s2 := Format(' %d', [SingleStat.TotalSecrets]);
3020 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
3021 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
3022 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3023 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
3024 s1 := s1 + '/';
3025 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3026 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
3027 end;
3029 begin
3030 // "Level Complete":
3031 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
3032 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
3034 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3035 s1 := _lc[I_MENU_INTER_KPM];
3036 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3037 Inc(w1, 16);
3038 s1 := ' 9999.9';
3039 e_CharFont_GetSize(gMenuFont, s1, w2, h);
3041 key_x := (gScreenWidth-w1-w2) div 2;
3042 val_x := key_x + w1;
3044 // "Time: #:##:##":
3045 tm := SingleStat.GameTime div 1000;
3046 s1 := _lc[I_MENU_INTER_TIME];
3047 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
3049 e_CharFont_Print(gMenuFont, key_x, 80, s1);
3050 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
3052 if SingleStat.TwoPlayers then
3053 begin
3054 // "Player 1":
3055 s1 := _lc[I_MENU_PLAYER_1];
3056 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3057 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
3059 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3060 y := 176;
3061 player_stat(0);
3063 // "Player 2":
3064 s1 := _lc[I_MENU_PLAYER_2];
3065 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3066 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
3068 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3069 y := 336;
3070 player_stat(1);
3072 else
3073 begin
3074 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3075 y := 128;
3076 player_stat(0);
3077 end;
3078 end;
3080 procedure DrawLoadingStat();
3081 procedure drawRect (x, y, w, h: Integer);
3082 begin
3083 if (w < 1) or (h < 1) then exit;
3084 glBegin(GL_QUADS);
3085 glVertex2f(x+0.375, y+0.375);
3086 glVertex2f(x+w+0.375, y+0.375);
3087 glVertex2f(x+w+0.375, y+h+0.375);
3088 glVertex2f(x+0.375, y+h+0.375);
3089 glEnd();
3090 end;
3092 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
3094 rectW, rectH: Integer;
3095 x0, y0: Integer;
3096 wdt: Integer;
3097 wl, hl: Integer;
3098 wr, hr: Integer;
3099 wb, hb: Integer;
3100 wm, hm: Integer;
3101 idl, idr, idb, idm: LongWord;
3102 f, my: Integer;
3103 begin
3104 result := false;
3105 if (total < 1) then exit;
3106 if (cur < 1) then exit; // don't blink
3107 if (not washere) and (cur >= total) then exit; // don't blink
3108 //if (cur < 0) then cur := 0;
3109 //if (cur > total) then cur := total;
3110 result := true;
3112 if (hasPBarGfx) then
3113 begin
3114 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
3115 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
3116 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
3117 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
3118 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
3119 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
3120 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
3121 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
3123 //rectW := gScreenWidth-360;
3124 rectW := trunc(624.0*gScreenWidth/1024.0);
3125 rectH := hl;
3127 x0 := (gScreenWidth-rectW) div 2;
3128 y0 := gScreenHeight-rectH-64;
3129 if (y0 < 2) then y0 := 2;
3131 glEnable(GL_SCISSOR_TEST);
3133 // left and right
3134 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
3135 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
3136 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
3138 // body
3139 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
3140 f := x0+wl;
3141 while (f < x0+rectW) do
3142 begin
3143 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
3144 f += wb;
3145 end;
3147 // filled part
3148 wdt := (rectW-wl-wr)*cur div total;
3149 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
3150 if (wdt > 0) then
3151 begin
3152 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
3153 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
3154 f := x0+wl;
3155 while (wdt > 0) do
3156 begin
3157 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
3158 f += wm;
3159 wdt -= wm;
3160 end;
3161 end;
3163 glScissor(0, 0, gScreenWidth, gScreenHeight);
3165 else
3166 begin
3167 rectW := gScreenWidth-64;
3168 rectH := 16;
3170 x0 := (gScreenWidth-rectW) div 2;
3171 y0 := gScreenHeight-rectH-64;
3172 if (y0 < 2) then y0 := 2;
3174 glDisable(GL_BLEND);
3175 glDisable(GL_TEXTURE_2D);
3177 //glClearColor(0, 0, 0, 0);
3178 //glClear(GL_COLOR_BUFFER_BIT);
3180 glColor4ub(127, 127, 127, 255);
3181 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3183 glColor4ub(0, 0, 0, 255);
3184 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3186 glColor4ub(127, 127, 127, 255);
3187 wdt := rectW*cur div total;
3188 if (wdt > rectW) then wdt := rectW;
3189 drawRect(x0, y0, wdt, rectH);
3190 end;
3191 end;
3194 ww, hh: Word;
3195 xx, yy, i: Integer;
3196 s: String;
3197 begin
3198 if (Length(LoadingStat.Msgs) = 0) then exit;
3200 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3201 yy := (gScreenHeight div 3);
3202 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3203 xx := (gScreenWidth div 3);
3205 with LoadingStat do
3206 begin
3207 for i := 0 to NextMsg-1 do
3208 begin
3209 if (i = (NextMsg-1)) and (MaxValue > 0) then
3210 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3211 else
3212 s := Msgs[i];
3214 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3215 yy := yy + LOADING_INTERLINE;
3216 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3217 end;
3218 end;
3219 end;
3221 procedure DrawMenuBackground(tex: AnsiString);
3223 w, h: Word;
3224 ID: DWord;
3226 begin
3227 if g_Texture_Get(tex, ID) then
3228 begin
3229 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3230 e_GetTextureSize(ID, @w, @h);
3231 if w = h then
3232 w := round(w * 1.333 * (gScreenHeight / h))
3233 else
3234 w := trunc(w * (gScreenHeight / h));
3235 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3237 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3238 end;
3240 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3242 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3244 function monDraw (mon: TMonster): Boolean;
3245 begin
3246 result := false; // don't stop
3247 with mon do
3248 begin
3249 if alive then
3250 begin
3251 // Ëåâûé âåðõíèé óãîë
3252 aX := Obj.X div ScaleSz + 1;
3253 aY := Obj.Y div ScaleSz + 1;
3254 // Ðàçìåðû
3255 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3256 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3257 // Ïðàâûé íèæíèé óãîë
3258 aX2 := aX + aX2 - 1;
3259 aY2 := aY + aY2 - 1;
3260 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3261 end;
3262 end;
3263 end;
3265 begin
3266 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3267 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3268 begin
3269 Scale := 1;
3270 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3271 ScaleSz := 16 div Scale;
3272 // Ðàçìåðû ìèíè-êàðòû:
3273 aX := max(gMapInfo.Width div ScaleSz, 1);
3274 aY := max(gMapInfo.Height div ScaleSz, 1);
3275 // Ðàìêà êàðòû:
3276 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3278 if gWalls <> nil then
3279 begin
3280 // Ðèñóåì ñòåíû:
3281 for a := 0 to High(gWalls) do
3282 with gWalls[a] do
3283 if PanelType <> 0 then
3284 begin
3285 // Ëåâûé âåðõíèé óãîë:
3286 aX := X div ScaleSz;
3287 aY := Y div ScaleSz;
3288 // Ðàçìåðû:
3289 aX2 := max(Width div ScaleSz, 1);
3290 aY2 := max(Height div ScaleSz, 1);
3291 // Ïðàâûé íèæíèé óãîë:
3292 aX2 := aX + aX2 - 1;
3293 aY2 := aY + aY2 - 1;
3295 case PanelType of
3296 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3297 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3298 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3299 end;
3300 end;
3301 end;
3302 if gSteps <> nil then
3303 begin
3304 // Ðèñóåì ñòóïåíè:
3305 for a := 0 to High(gSteps) do
3306 with gSteps[a] do
3307 if PanelType <> 0 then
3308 begin
3309 // Ëåâûé âåðõíèé óãîë:
3310 aX := X div ScaleSz;
3311 aY := Y div ScaleSz;
3312 // Ðàçìåðû:
3313 aX2 := max(Width div ScaleSz, 1);
3314 aY2 := max(Height div ScaleSz, 1);
3315 // Ïðàâûé íèæíèé óãîë:
3316 aX2 := aX + aX2 - 1;
3317 aY2 := aY + aY2 - 1;
3319 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3320 end;
3321 end;
3322 if gLifts <> nil then
3323 begin
3324 // Ðèñóåì ëèôòû:
3325 for a := 0 to High(gLifts) do
3326 with gLifts[a] do
3327 if PanelType <> 0 then
3328 begin
3329 // Ëåâûé âåðõíèé óãîë:
3330 aX := X div ScaleSz;
3331 aY := Y div ScaleSz;
3332 // Ðàçìåðû:
3333 aX2 := max(Width div ScaleSz, 1);
3334 aY2 := max(Height div ScaleSz, 1);
3335 // Ïðàâûé íèæíèé óãîë:
3336 aX2 := aX + aX2 - 1;
3337 aY2 := aY + aY2 - 1;
3339 case LiftType of
3340 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3341 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3342 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3343 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3344 end;
3345 end;
3346 end;
3347 if gWater <> nil then
3348 begin
3349 // Ðèñóåì âîäó:
3350 for a := 0 to High(gWater) do
3351 with gWater[a] do
3352 if PanelType <> 0 then
3353 begin
3354 // Ëåâûé âåðõíèé óãîë:
3355 aX := X div ScaleSz;
3356 aY := Y div ScaleSz;
3357 // Ðàçìåðû:
3358 aX2 := max(Width div ScaleSz, 1);
3359 aY2 := max(Height div ScaleSz, 1);
3360 // Ïðàâûé íèæíèé óãîë:
3361 aX2 := aX + aX2 - 1;
3362 aY2 := aY + aY2 - 1;
3364 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3365 end;
3366 end;
3367 if gAcid1 <> nil then
3368 begin
3369 // Ðèñóåì êèñëîòó 1:
3370 for a := 0 to High(gAcid1) do
3371 with gAcid1[a] do
3372 if PanelType <> 0 then
3373 begin
3374 // Ëåâûé âåðõíèé óãîë:
3375 aX := X div ScaleSz;
3376 aY := Y div ScaleSz;
3377 // Ðàçìåðû:
3378 aX2 := max(Width div ScaleSz, 1);
3379 aY2 := max(Height div ScaleSz, 1);
3380 // Ïðàâûé íèæíèé óãîë:
3381 aX2 := aX + aX2 - 1;
3382 aY2 := aY + aY2 - 1;
3384 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3385 end;
3386 end;
3387 if gAcid2 <> nil then
3388 begin
3389 // Ðèñóåì êèñëîòó 2:
3390 for a := 0 to High(gAcid2) do
3391 with gAcid2[a] do
3392 if PanelType <> 0 then
3393 begin
3394 // Ëåâûé âåðõíèé óãîë:
3395 aX := X div ScaleSz;
3396 aY := Y div ScaleSz;
3397 // Ðàçìåðû:
3398 aX2 := max(Width div ScaleSz, 1);
3399 aY2 := max(Height div ScaleSz, 1);
3400 // Ïðàâûé íèæíèé óãîë:
3401 aX2 := aX + aX2 - 1;
3402 aY2 := aY + aY2 - 1;
3404 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3405 end;
3406 end;
3407 if gPlayers <> nil then
3408 begin
3409 // Ðèñóåì èãðîêîâ:
3410 for a := 0 to High(gPlayers) do
3411 if gPlayers[a] <> nil then with gPlayers[a] do
3412 if alive then begin
3413 // Ëåâûé âåðõíèé óãîë:
3414 aX := Obj.X div ScaleSz + 1;
3415 aY := Obj.Y div ScaleSz + 1;
3416 // Ðàçìåðû:
3417 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3418 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3419 // Ïðàâûé íèæíèé óãîë:
3420 aX2 := aX + aX2 - 1;
3421 aY2 := aY + aY2 - 1;
3423 if gPlayers[a] = p then
3424 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3425 else
3426 case Team of
3427 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3428 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3429 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3430 end;
3431 end;
3432 end;
3433 // Ðèñóåì ìîíñòðîâ
3434 g_Mons_ForEach(monDraw);
3435 end;
3436 end;
3439 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3440 begin
3441 if not hasAmbient then exit;
3442 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3443 end;
3446 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3447 //FIXME: broken for splitscreen mode
3448 procedure renderDynLightsInternal ();
3450 //hasAmbient: Boolean;
3451 //ambColor: TDFColor;
3452 lln: Integer;
3453 lx, ly, lrad: Integer;
3454 scxywh: array[0..3] of GLint;
3455 wassc: Boolean;
3456 begin
3457 if e_NoGraphics then exit;
3459 //TODO: lights should be in separate grid, i think
3460 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3461 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3463 // rendering mode
3464 //ambColor := gCurrentMap['light_ambient'].rgba;
3465 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3467 { // this will multiply incoming color to alpha from framebuffer
3468 glEnable(GL_BLEND);
3469 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3473 * light rendering: (INVALID!)
3474 * glStencilFunc(GL_EQUAL, 0, $ff);
3475 * for each light:
3476 * glClear(GL_STENCIL_BUFFER_BIT);
3477 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3478 * draw shadow volume into stencil buffer
3479 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3480 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3481 * turn off blending
3482 * draw color-less quad with light alpha (WARNING! don't touch color!)
3483 * glEnable(GL_BLEND);
3484 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3485 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3487 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3488 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3490 // setup OpenGL parameters
3491 glStencilMask($FFFFFFFF);
3492 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3493 glEnable(GL_STENCIL_TEST);
3494 glEnable(GL_SCISSOR_TEST);
3495 glClear(GL_STENCIL_BUFFER_BIT);
3496 glStencilFunc(GL_EQUAL, 0, $ff);
3498 for lln := 0 to g_dynLightCount-1 do
3499 begin
3500 lx := g_dynLights[lln].x;
3501 ly := g_dynLights[lln].y;
3502 lrad := g_dynLights[lln].radius;
3503 if (lrad < 3) then continue;
3505 if (lx-sX+lrad < 0) then continue;
3506 if (ly-sY+lrad < 0) then continue;
3507 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3508 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3510 // set scissor to optimize drawing
3511 if (g_dbg_scale = 1.0) then
3512 begin
3513 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3515 else
3516 begin
3517 glScissor(0, 0, gScreenWidth, gScreenHeight);
3518 end;
3519 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3520 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3521 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3522 // draw extruded panels
3523 glDisable(GL_TEXTURE_2D);
3524 glDisable(GL_BLEND);
3525 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3526 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3527 // render light texture
3528 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3529 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3530 // blend it
3531 glEnable(GL_BLEND);
3532 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3533 glEnable(GL_TEXTURE_2D);
3534 // color and opacity
3535 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3536 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3537 glBegin(GL_QUADS);
3538 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3539 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3540 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3541 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3542 glEnd();
3543 end;
3545 // done
3546 glDisable(GL_STENCIL_TEST);
3547 glDisable(GL_BLEND);
3548 glDisable(GL_SCISSOR_TEST);
3549 //glScissor(0, 0, sWidth, sHeight);
3551 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3552 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3553 end;
3556 function fixViewportForScale (): Boolean;
3558 nx0, ny0, nw, nh: Integer;
3559 begin
3560 result := false;
3561 if (g_dbg_scale <> 1.0) then
3562 begin
3563 result := true;
3564 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3565 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3566 nw := round(sWidth/g_dbg_scale);
3567 nh := round(sHeight/g_dbg_scale);
3568 sX := nx0;
3569 sY := ny0;
3570 sWidth := nw;
3571 sHeight := nh;
3572 end;
3573 end;
3576 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3577 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3578 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3579 type
3580 TDrawCB = procedure ();
3583 hasAmbient: Boolean;
3584 ambColor: TDFColor;
3585 doAmbient: Boolean = false;
3587 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3589 tagmask: Integer;
3590 pan: TPanel;
3591 begin
3592 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3593 if gdbg_map_use_accel_render then
3594 begin
3595 tagmask := panelTypeToTag(panType);
3596 while (gDrawPanelList.count > 0) do
3597 begin
3598 pan := TPanel(gDrawPanelList.front());
3599 if ((pan.tag and tagmask) = 0) then break;
3600 if doDraw then pan.Draw(doAmbient, ambColor);
3601 gDrawPanelList.popFront();
3602 end;
3604 else
3605 begin
3606 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3607 end;
3608 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3609 end;
3611 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3612 begin
3613 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3614 if assigned(cb) then cb();
3615 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3616 end;
3618 begin
3619 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3621 // our accelerated renderer will collect all panels to gDrawPanelList
3622 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3623 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3624 if gdbg_map_use_accel_render then
3625 begin
3626 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3627 end;
3628 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3630 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3631 g_Map_DrawBack(backXOfs, backYOfs);
3632 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3634 if setTransMatrix then
3635 begin
3636 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3637 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3638 glTranslatef(-sX, -sY, 0);
3639 end;
3641 // rendering mode
3642 ambColor := gCurrentMap['light_ambient'].rgba;
3643 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3646 if hasAmbient then
3647 begin
3648 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3649 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3650 glClear(GL_COLOR_BUFFER_BIT);
3651 end;
3653 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3656 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3657 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3658 drawOther('items', @g_Items_Draw);
3659 drawOther('weapons', @g_Weapon_Draw);
3660 drawOther('shells', @g_Player_DrawShells);
3661 drawOther('drawall', @g_Player_DrawAll);
3662 drawOther('corpses', @g_Player_DrawCorpses);
3663 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3664 drawOther('monsters', @g_Monsters_Draw);
3665 drawOther('itemdrop', @g_Items_DrawDrop);
3666 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3667 drawOther('gfx', @g_GFX_Draw);
3668 drawOther('flags', @g_Map_DrawFlags);
3669 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3670 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3671 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3672 drawOther('dynlights', @renderDynLightsInternal);
3674 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3675 begin
3676 renderAmbientQuad(hasAmbient, ambColor);
3677 end;
3679 doAmbient := true;
3680 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3683 if g_debug_HealthBar then
3684 begin
3685 g_Monsters_DrawHealth();
3686 g_Player_DrawHealth();
3687 end;
3689 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3690 end;
3693 procedure DrawMapView(x, y, w, h: Integer);
3696 bx, by: Integer;
3697 begin
3698 glPushMatrix();
3700 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3701 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3703 sX := x;
3704 sY := y;
3705 sWidth := w;
3706 sHeight := h;
3708 fixViewportForScale();
3709 renderMapInternal(-bx, -by, true);
3711 glPopMatrix();
3712 end;
3715 procedure DrawPlayer(p: TPlayer);
3717 px, py, a, b, c, d, i, fX, fY: Integer;
3718 camObj: TObj;
3719 //R: TRect;
3720 begin
3721 if (p = nil) or (p.FDummy) then
3722 begin
3723 glPushMatrix();
3724 g_Map_DrawBack(0, 0);
3725 glPopMatrix();
3726 Exit;
3727 end;
3729 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3730 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3732 gPlayerDrawn := p;
3734 glPushMatrix();
3736 camObj := p.getCameraObj();
3737 camObj.lerp(gLerpFactor, fX, fY);
3738 px := fX + PLAYER_RECT_CX;
3739 py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, camObj.slopeUpLeft, gLerpFactor);
3741 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3742 begin
3743 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3744 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3746 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3747 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3749 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3750 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3751 begin
3752 // hcenter
3753 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3754 end;
3756 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3757 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3758 begin
3759 // vcenter
3760 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3761 end;
3763 else
3764 begin
3765 // scaled, ignore level bounds
3766 a := -px+(gPlayerScreenSize.X div 2);
3767 b := -py+(gPlayerScreenSize.Y div 2);
3768 end;
3770 sX := -a;
3771 sY := -b;
3772 sWidth := gPlayerScreenSize.X;
3773 sHeight := gPlayerScreenSize.Y;
3774 fixViewportForScale();
3776 i := py - (sY + sHeight div 2);
3777 if (p.IncCam > 0) then
3778 begin
3779 // clamp to level bounds
3780 if (sY - p.IncCam < 0) then
3781 p.IncCam := nclamp(sY, 0, 120);
3782 // clamp around player position
3783 if (i > 0) then
3784 p.IncCam := nclamp(p.IncCam, 0, max(0, 120 - i));
3786 else if (p.IncCam < 0) then
3787 begin
3788 // clamp to level bounds
3789 if (sY + sHeight - p.IncCam > gMapInfo.Height) then
3790 p.IncCam := nclamp(sY + sHeight - gMapInfo.Height, -120, 0);
3791 // clamp around player position
3792 if (i < 0) then
3793 p.IncCam := nclamp(p.IncCam, min(0, -120 - i), 0);
3794 end;
3796 sY := sY - nlerp(p.IncCamOld, p.IncCam, gLerpFactor);
3798 if (not g_dbg_ignore_bounds) then
3799 begin
3800 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3801 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3802 if (sX < 0) then sX := 0;
3803 if (sY < 0) then sY := 0;
3804 end;
3806 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3807 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3809 //r_smallmap_h: 0: left; 1: center; 2: right
3810 //r_smallmap_v: 0: top; 1: center; 2: bottom
3811 // horiz small map?
3812 if (gMapInfo.Width = sWidth) then
3813 begin
3814 sX := 0;
3816 else if (gMapInfo.Width < sWidth) then
3817 begin
3818 case r_smallmap_h of
3819 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3820 2: sX := -(sWidth-gMapInfo.Width); // right
3821 else sX := 0; // left
3822 end;
3823 end;
3824 // vert small map?
3825 if (gMapInfo.Height = sHeight) then
3826 begin
3827 sY := 0;
3829 else if (gMapInfo.Height < sHeight) then
3830 begin
3831 case r_smallmap_v of
3832 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3833 2: sY := -(sHeight-gMapInfo.Height); // bottom
3834 else sY := 0; // top
3835 end;
3836 end;
3838 p.viewPortX := sX;
3839 p.viewPortY := sY;
3840 p.viewPortW := sWidth;
3841 p.viewPortH := sHeight;
3843 {$IFDEF ENABLE_HOLMES}
3844 if (p = gPlayer1) then
3845 begin
3846 g_Holmes_plrViewPos(sX, sY);
3847 g_Holmes_plrViewSize(sWidth, sHeight);
3848 end;
3849 {$ENDIF}
3851 renderMapInternal(-c, -d, true);
3853 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3854 case gPlayerIndicator of
3856 p.DrawIndicator(_RGB(255, 255, 255));
3859 for i := 0 to High(gPlayers) do
3860 if gPlayers[i] <> nil then
3861 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3862 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3863 if gPlayerIndicatorStyle = 1 then
3864 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3865 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3866 end;
3869 for a := 0 to High(gCollideMap) do
3870 for b := 0 to High(gCollideMap[a]) do
3871 begin
3872 d := 0;
3873 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3874 d := d + 1;
3875 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3876 d := d + 2;
3878 case d of
3879 1: e_DrawPoint(1, b, a, 200, 200, 200);
3880 2: e_DrawPoint(1, b, a, 64, 64, 255);
3881 3: e_DrawPoint(1, b, a, 255, 0, 255);
3882 end;
3883 end;
3886 glPopMatrix();
3888 p.DrawPain();
3889 p.DrawPickup();
3890 p.DrawOverlay();
3891 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3892 if g_Debug_Player then
3893 g_Player_DrawDebug(p);
3894 p.DrawGUI();
3895 end;
3897 procedure drawProfilers ();
3899 px: Integer = -1;
3900 py: Integer = -1;
3901 begin
3902 if g_profile_frame_draw and (profileFrameDraw <> nil) then
3903 px -= drawProfiles(px, py, profileFrameDraw);
3905 if g_profile_collision and (profMapCollision <> nil) then
3906 begin
3907 px -= drawProfiles(px, py, profMapCollision);
3908 py -= calcProfilesHeight(profMonsLOS);
3909 end;
3911 if g_profile_los and (profMonsLOS <> nil) then
3912 begin
3913 px -= drawProfiles(px, py, profMonsLOS);
3914 py -= calcProfilesHeight(profMonsLOS);
3915 end;
3916 end;
3918 procedure g_Game_Draw();
3920 ID: DWORD;
3921 w, h: Word;
3922 ww, hh: Byte;
3923 Time: Int64;
3924 back: string;
3925 plView1, plView2: TPlayer;
3926 Split: Boolean;
3927 begin
3928 if gExit = EXIT_QUIT then Exit;
3930 Time := sys_GetTicks() {div 1000};
3931 FPSCounter := FPSCounter+1;
3932 if Time - FPSTime >= 1000 then
3933 begin
3934 FPS := FPSCounter;
3935 FPSCounter := 0;
3936 FPSTime := Time;
3937 end;
3939 e_SetRendertarget(True);
3940 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3942 if gGameOn or (gState = STATE_FOLD) then
3943 begin
3944 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3945 begin
3946 gSpectMode := SPECT_NONE;
3947 if not gRevertPlayers then
3948 begin
3949 plView1 := gPlayer1;
3950 plView2 := gPlayer2;
3952 else
3953 begin
3954 plView1 := gPlayer2;
3955 plView2 := gPlayer1;
3956 end;
3958 else
3959 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3960 begin
3961 gSpectMode := SPECT_NONE;
3962 if gPlayer2 = nil then
3963 plView1 := gPlayer1
3964 else
3965 plView1 := gPlayer2;
3966 plView2 := nil;
3968 else
3969 begin
3970 plView1 := nil;
3971 plView2 := nil;
3972 end;
3974 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3975 gSpectMode := SPECT_STATS;
3977 if gSpectMode = SPECT_PLAYERS then
3978 if gPlayers <> nil then
3979 begin
3980 plView1 := GetActivePlayer_ByID(gSpectPID1);
3981 if plView1 = nil then
3982 begin
3983 gSpectPID1 := GetActivePlayerID_Next();
3984 plView1 := GetActivePlayer_ByID(gSpectPID1);
3985 end;
3986 if gSpectViewTwo then
3987 begin
3988 plView2 := GetActivePlayer_ByID(gSpectPID2);
3989 if plView2 = nil then
3990 begin
3991 gSpectPID2 := GetActivePlayerID_Next();
3992 plView2 := GetActivePlayer_ByID(gSpectPID2);
3993 end;
3994 end;
3995 end;
3997 if gSpectMode = SPECT_MAPVIEW then
3998 begin
3999 // Ðåæèì ïðîñìîòðà êàðòû
4000 Split := False;
4001 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4002 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
4003 gHearPoint1.Active := True;
4004 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
4005 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
4006 gHearPoint2.Active := False;
4008 else
4009 begin
4010 Split := (plView1 <> nil) and (plView2 <> nil);
4012 // Òî÷êè ñëóõà èãðîêîâ
4013 if plView1 <> nil then
4014 begin
4015 gHearPoint1.Active := True;
4016 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
4017 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
4018 end else
4019 gHearPoint1.Active := False;
4020 if plView2 <> nil then
4021 begin
4022 gHearPoint2.Active := True;
4023 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
4024 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
4025 end else
4026 gHearPoint2.Active := False;
4028 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4029 gPlayerScreenSize.X := gScreenWidth-196;
4030 if Split then
4031 begin
4032 gPlayerScreenSize.Y := gScreenHeight div 2;
4033 if gScreenHeight mod 2 = 0 then
4034 Dec(gPlayerScreenSize.Y);
4036 else
4037 gPlayerScreenSize.Y := gScreenHeight;
4039 if Split then
4040 if gScreenHeight mod 2 = 0 then
4041 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
4042 else
4043 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4045 DrawPlayer(plView1);
4046 gPlayer1ScreenCoord.X := sX;
4047 gPlayer1ScreenCoord.Y := sY;
4049 if Split then
4050 begin
4051 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4053 DrawPlayer(plView2);
4054 gPlayer2ScreenCoord.X := sX;
4055 gPlayer2ScreenCoord.Y := sY;
4056 end;
4058 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4060 if Split then
4061 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
4062 end;
4064 {$IFDEF ENABLE_HOLMES}
4065 // draw inspector
4066 if (g_holmes_enabled) then g_Holmes_Draw();
4067 {$ENDIF}
4069 if MessageText <> '' then
4070 begin
4071 w := 0;
4072 h := 0;
4073 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
4074 if Split then
4075 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4076 (gScreenHeight div 2)-(h div 2), MessageText)
4077 else
4078 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4079 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4080 end;
4082 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4083 DrawStat();
4085 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4086 begin
4087 // Draw spectator GUI
4088 ww := 0;
4089 hh := 0;
4090 e_TextureFontGetSize(gStdFont, ww, hh);
4091 case gSpectMode of
4092 SPECT_STATS:
4093 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4094 SPECT_MAPVIEW:
4095 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4096 SPECT_PLAYERS:
4097 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4098 end;
4099 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4100 if gSpectMode = SPECT_STATS then
4101 begin
4102 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4103 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4104 end;
4105 if gSpectMode = SPECT_MAPVIEW then
4106 begin
4107 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4108 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4109 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4110 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4111 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4112 end;
4113 if gSpectMode = SPECT_PLAYERS then
4114 begin
4115 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4116 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4117 if gSpectViewTwo then
4118 begin
4119 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4120 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4121 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4122 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4124 else
4125 begin
4126 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4127 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4128 end;
4129 end;
4130 end;
4131 end;
4133 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4134 begin
4135 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4136 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4138 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4139 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4140 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4141 end;
4143 if not gGameOn then
4144 begin
4145 if (gState = STATE_MENU) then
4146 begin
4147 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4148 // F3 at menu will show game loading dialog
4149 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4150 if (g_ActiveWindow <> nil) then
4151 begin
4152 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4153 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4155 else
4156 begin
4157 // F3 at titlepic will show game loading dialog
4158 if e_KeyPressed(IK_F3) then
4159 begin
4160 g_Menu_Show_LoadMenu(true);
4161 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4162 end;
4163 end;
4164 end;
4166 if gState = STATE_FOLD then
4167 begin
4168 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4169 end;
4171 if gState = STATE_INTERCUSTOM then
4172 begin
4173 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4174 begin
4175 back := 'TEXTURE_endpic';
4176 if not g_Texture_Get(back, ID) then
4177 back := _lc[I_TEXTURE_ENDPIC];
4179 else
4180 back := 'INTER';
4182 DrawMenuBackground(back);
4184 DrawCustomStat();
4186 if g_ActiveWindow <> nil then
4187 begin
4188 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4189 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4190 end;
4191 end;
4193 if gState = STATE_INTERSINGLE then
4194 begin
4195 if EndingGameCounter > 0 then
4196 begin
4197 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4199 else
4200 begin
4201 back := 'INTER';
4203 DrawMenuBackground(back);
4205 DrawSingleStat();
4207 if g_ActiveWindow <> nil then
4208 begin
4209 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4210 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4211 end;
4212 end;
4213 end;
4215 if gState = STATE_ENDPIC then
4216 begin
4217 ID := DWORD(-1);
4218 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4219 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4221 if g_ActiveWindow <> nil then
4222 begin
4223 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4224 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4225 end;
4226 end;
4228 if gState = STATE_SLIST then
4229 begin
4230 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4231 // begin
4232 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4233 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4234 // end;
4235 DrawMenuBackground('MENU_BACKGROUND');
4236 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4237 g_Serverlist_Draw(slCurrent, slTable);
4238 end;
4239 end;
4241 if g_ActiveWindow <> nil then
4242 begin
4243 if gGameOn then
4244 begin
4245 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4246 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4247 end;
4248 g_ActiveWindow.Draw();
4249 end;
4251 {$IFNDEF HEADLESS}
4252 g_Console_Draw();
4253 {$ENDIF}
4255 if g_debug_Sounds and gGameOn then
4256 begin
4257 for w := 0 to High(e_SoundsArray) do
4258 for h := 0 to e_SoundsArray[w].nRefs do
4259 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4260 end;
4262 if gShowFPS then
4263 begin
4264 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4265 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4266 end;
4268 if gGameOn and gShowTime then
4269 drawTime(gScreenWidth-72, gScreenHeight-16);
4271 if gGameOn then drawProfilers();
4273 // TODO: draw this after the FBO and remap mouse click coordinates
4275 {$IFDEF ENABLE_HOLMES}
4276 g_Holmes_DrawUI();
4277 {$ENDIF}
4279 // blit framebuffer to screen
4281 e_SetRendertarget(False);
4282 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4283 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4285 // draw the overlay stuff on top of it
4287 g_Touch_Draw;
4288 end;
4290 // FIXME: This cannot be called from anywhere other than ProcessMessages(), because otherwise
4291 // remaining events in the system queue may cause use-after-free! Do 'gExit := EXIT_QUIT' instead.
4292 procedure g_Game_Quit();
4293 begin
4294 e_WriteLog('g_Game_Quit: cleanup assets before shutting down', TMsgType.Notify);
4295 g_Game_StopAllSounds(True);
4296 gMusic.Free();
4297 g_Game_FreeData();
4298 g_PlayerModel_FreeData();
4299 g_Texture_DeleteAll();
4300 g_Frames_DeleteAll();
4301 {$IFNDEF HEADLESS}
4302 g_Menu_Free();
4303 {$ENDIF}
4305 if NetInitDone then g_Net_Free;
4307 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4308 if gMapToDelete <> '' then
4309 g_Game_DeleteTestMap();
4311 sys_RequestQuit(); // FIXME: this posts an event that have no sense anymore at this moment.
4312 end;
4314 procedure g_FatalError(Text: String);
4315 begin
4316 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4317 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4319 gExit := EXIT_SIMPLE;
4320 if gGameOn then EndGame;
4321 end;
4323 procedure g_SimpleError(Text: String);
4324 begin
4325 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4326 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4327 end;
4329 procedure g_Game_SetupScreenSize();
4330 const
4331 RES_FACTOR = 4.0 / 3.0;
4333 s: Single;
4334 rf: Single;
4335 bw, bh: Word;
4336 begin
4337 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4338 gPlayerScreenSize.X := gScreenWidth-196;
4339 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4340 gPlayerScreenSize.Y := gScreenHeight div 2
4341 else
4342 gPlayerScreenSize.Y := gScreenHeight;
4344 // Ðàçìåð çàäíåãî ïëàíà:
4345 if BackID <> DWORD(-1) then
4346 begin
4347 s := SKY_STRETCH;
4348 if (gScreenWidth*s > gMapInfo.Width) or
4349 (gScreenHeight*s > gMapInfo.Height) then
4350 begin
4351 gBackSize.X := gScreenWidth;
4352 gBackSize.Y := gScreenHeight;
4354 else
4355 begin
4356 e_GetTextureSize(BackID, @bw, @bh);
4357 rf := Single(bw) / Single(bh);
4358 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4359 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4360 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4361 if (s < 1.0) then s := 1.0;
4362 gBackSize.X := Round(bw*s);
4363 gBackSize.Y := Round(bh*s);
4364 end;
4365 end;
4366 end;
4368 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4369 begin
4370 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4371 end;
4373 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4374 begin
4375 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4376 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4377 Exit;
4379 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4380 Exit;
4382 if gPlayer1 = nil then
4383 begin
4384 if g_Game_IsClient then
4385 begin
4386 if NetPlrUID1 > -1 then
4387 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4388 Exit;
4389 end;
4391 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4392 Team := gPlayer1Settings.Team;
4394 // Ñîçäàíèå ïåðâîãî èãðîêà:
4395 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4396 gPlayer1Settings.Color,
4397 Team, False));
4398 if gPlayer1 = nil then
4399 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4400 else
4401 begin
4402 gPlayer1.Name := gPlayer1Settings.Name;
4403 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4404 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4405 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4406 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4407 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4408 if g_Game_IsServer and g_Game_IsNet then
4409 MH_SEND_PlayerCreate(gPlayer1.UID);
4410 gPlayer1.Respawn(False, True);
4411 g_Net_Slist_ServerPlayerComes();
4412 end;
4414 Exit;
4415 end;
4416 if gPlayer2 = nil then
4417 begin
4418 if g_Game_IsClient then
4419 begin
4420 if NetPlrUID2 > -1 then
4421 gPlayer2 := g_Player_Get(NetPlrUID2);
4422 Exit;
4423 end;
4425 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4426 Team := gPlayer2Settings.Team;
4428 // Ñîçäàíèå âòîðîãî èãðîêà:
4429 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4430 gPlayer2Settings.Color,
4431 Team, False));
4432 if gPlayer2 = nil then
4433 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4434 else
4435 begin
4436 gPlayer2.Name := gPlayer2Settings.Name;
4437 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4438 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4439 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4440 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4441 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4442 if g_Game_IsServer and g_Game_IsNet then
4443 MH_SEND_PlayerCreate(gPlayer2.UID);
4444 gPlayer2.Respawn(False, True);
4445 g_Net_Slist_ServerPlayerComes();
4446 end;
4448 Exit;
4449 end;
4450 end;
4452 procedure g_Game_RemovePlayer();
4454 Pl: TPlayer;
4455 begin
4456 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4457 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4458 Exit;
4459 Pl := gPlayer2;
4460 if Pl <> nil then
4461 begin
4462 if g_Game_IsServer then
4463 begin
4464 Pl.Lives := 0;
4465 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4466 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4467 g_Player_Remove(Pl.UID);
4468 g_Net_Slist_ServerPlayerLeaves();
4470 else
4471 begin
4472 gSpectLatchPID2 := Pl.UID;
4473 gPlayer2 := nil;
4474 end;
4475 Exit;
4476 end;
4477 Pl := gPlayer1;
4478 if Pl <> nil then
4479 begin
4480 if g_Game_IsServer then
4481 begin
4482 Pl.Lives := 0;
4483 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4484 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4485 g_Player_Remove(Pl.UID);
4486 g_Net_Slist_ServerPlayerLeaves();
4487 end else
4488 begin
4489 gSpectLatchPID1 := Pl.UID;
4490 gPlayer1 := nil;
4491 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4492 end;
4493 Exit;
4494 end;
4495 g_Net_Slist_ServerPlayerLeaves();
4496 end;
4498 procedure g_Game_Spectate();
4499 begin
4500 g_Game_RemovePlayer();
4501 if gPlayer1 <> nil then
4502 g_Game_RemovePlayer();
4503 end;
4505 procedure g_Game_SpectateCenterView();
4506 begin
4507 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4508 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4509 end;
4511 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4513 i, nPl: Integer;
4514 tmps: AnsiString;
4515 begin
4516 g_Game_Free();
4518 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4520 g_Game_ClearLoading();
4522 // Íàñòðîéêè èãðû:
4523 gGameSettings := Default(TGameSettings);
4524 gAimLine := False;
4525 gShowMap := False;
4526 gGameSettings.GameType := GT_SINGLE;
4527 gGameSettings.MaxLives := 0;
4528 gGameSettings.Options := [TGameOption.ALLOW_EXIT, TGameOption.MONSTERS,
4529 TGameOption.BOTS_VS_MONSTERS, TGameOption.TEAM_HIT_PROJECTILE, TGameOption.TEAM_HIT_TRACE,
4530 TGameOption.POWERUP_RANDOM, TGameOption.ITEM_ALL_RANDOM, TGameOption.ITEM_LIFE_RANDOM,
4531 TGameOption.ITEM_AMMO_RANDOM, TGameOption.ITEM_WEAPON_RANDOM];
4532 gSwitchGameMode := GM_SINGLE;
4534 gLMSRespawn := LMS_RESPAWN_NONE;
4535 gLMSRespawnTime := 0;
4536 gSpectLatchPID1 := 0;
4537 gSpectLatchPID2 := 0;
4539 g_Game_ExecuteEvent('ongamestart');
4541 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4542 g_Game_SetupScreenSize();
4544 // Ñîçäàíèå ïåðâîãî èãðîêà:
4545 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4546 gPlayer1Settings.Color,
4547 gPlayer1Settings.Team, False));
4548 if gPlayer1 = nil then
4549 begin
4550 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4551 Exit;
4552 end;
4554 gPlayer1.Name := gPlayer1Settings.Name;
4555 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4556 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4557 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4558 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4559 nPl := 1;
4561 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4562 if TwoPlayers then
4563 begin
4564 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4565 gPlayer2Settings.Color,
4566 gPlayer2Settings.Team, False));
4567 if gPlayer2 = nil then
4568 begin
4569 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4570 Exit;
4571 end;
4573 gPlayer2.Name := gPlayer2Settings.Name;
4574 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4575 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4576 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4577 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4578 Inc(nPl);
4579 end;
4581 // Çàãðóçêà è çàïóñê êàðòû:
4582 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4583 begin
4584 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4585 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4586 Exit;
4587 end;
4589 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4590 g_Player_Init();
4592 // Ñîçäàåì áîòîâ:
4593 for i := nPl+1 to nPlayers do
4594 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4595 end;
4597 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4598 TimeLimit, ScoreLimit: Word;
4599 MaxLives: Byte;
4600 Options: TGameOptions; nPlayers: Byte);
4602 i, nPl: Integer;
4603 begin
4604 g_Game_Free();
4606 e_WriteLog('Starting custom game...', TMsgType.Notify);
4608 g_Game_ClearLoading();
4610 // Íàñòðîéêè èãðû:
4611 gGameSettings.GameType := GT_CUSTOM;
4612 gGameSettings.GameMode := GameMode;
4613 gSwitchGameMode := GameMode;
4614 gGameSettings.TimeLimit := TimeLimit;
4615 gGameSettings.ScoreLimit := ScoreLimit;
4616 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4617 gGameSettings.Options := Options;
4619 gCoopTotalMonstersKilled := 0;
4620 gCoopTotalSecretsFound := 0;
4621 gCoopTotalMonsters := 0;
4622 gCoopTotalSecrets := 0;
4623 gAimLine := False;
4624 gShowMap := False;
4626 gLMSRespawn := LMS_RESPAWN_NONE;
4627 gLMSRespawnTime := 0;
4628 gSpectLatchPID1 := 0;
4629 gSpectLatchPID2 := 0;
4631 g_Game_ExecuteEvent('ongamestart');
4633 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4634 g_Game_SetupScreenSize();
4636 // Ðåæèì íàáëþäàòåëÿ:
4637 if nPlayers = 0 then
4638 begin
4639 gPlayer1 := nil;
4640 gPlayer2 := nil;
4641 end;
4643 nPl := 0;
4644 if nPlayers >= 1 then
4645 begin
4646 // Ñîçäàíèå ïåðâîãî èãðîêà:
4647 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4648 gPlayer1Settings.Color,
4649 gPlayer1Settings.Team, False));
4650 if gPlayer1 = nil then
4651 begin
4652 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4653 Exit;
4654 end;
4656 gPlayer1.Name := gPlayer1Settings.Name;
4657 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4658 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4659 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4660 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4661 Inc(nPl);
4662 end;
4664 if nPlayers >= 2 then
4665 begin
4666 // Ñîçäàíèå âòîðîãî èãðîêà:
4667 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4668 gPlayer2Settings.Color,
4669 gPlayer2Settings.Team, False));
4670 if gPlayer2 = nil then
4671 begin
4672 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4673 Exit;
4674 end;
4676 gPlayer2.Name := gPlayer2Settings.Name;
4677 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4678 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4679 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4680 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4681 Inc(nPl);
4682 end;
4684 // Çàãðóçêà è çàïóñê êàðòû:
4685 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4686 begin
4687 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4688 Exit;
4689 end;
4691 // Íåò òî÷åê ïîÿâëåíèÿ:
4692 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4693 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4694 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4695 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4696 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4697 begin
4698 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4699 Exit;
4700 end;
4702 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4703 g_Player_Init();
4705 // Ñîçäàåì áîòîâ:
4706 for i := nPl+1 to nPlayers do
4707 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4708 end;
4710 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4711 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
4712 Options: TGameOptions; nPlayers: Byte;
4713 IPAddr: LongWord; Port: Word);
4714 begin
4715 g_Game_Free();
4716 g_Net_Slist_ServerClosed();
4718 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4720 g_Game_ClearLoading();
4722 ClearDebugCvars();
4724 // Íàñòðîéêè èãðû:
4725 gGameSettings.GameType := GT_SERVER;
4726 gGameSettings.GameMode := GameMode;
4727 gSwitchGameMode := GameMode;
4728 gGameSettings.TimeLimit := TimeLimit;
4729 gGameSettings.ScoreLimit := ScoreLimit;
4730 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4731 gGameSettings.Options := Options;
4733 gCoopTotalMonstersKilled := 0;
4734 gCoopTotalSecretsFound := 0;
4735 gCoopTotalMonsters := 0;
4736 gCoopTotalSecrets := 0;
4737 gAimLine := False;
4738 gShowMap := False;
4740 gLMSRespawn := LMS_RESPAWN_NONE;
4741 gLMSRespawnTime := 0;
4742 gSpectLatchPID1 := 0;
4743 gSpectLatchPID2 := 0;
4745 g_Game_ExecuteEvent('ongamestart');
4747 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4748 g_Game_SetupScreenSize();
4750 // Ðåæèì íàáëþäàòåëÿ:
4751 if nPlayers = 0 then
4752 begin
4753 gPlayer1 := nil;
4754 gPlayer2 := nil;
4755 end;
4757 if nPlayers >= 1 then
4758 begin
4759 // Ñîçäàíèå ïåðâîãî èãðîêà:
4760 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4761 gPlayer1Settings.Color,
4762 gPlayer1Settings.Team, False));
4763 if gPlayer1 = nil then
4764 begin
4765 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4766 Exit;
4767 end;
4769 gPlayer1.Name := gPlayer1Settings.Name;
4770 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4771 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4772 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4773 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4774 end;
4776 if nPlayers >= 2 then
4777 begin
4778 // Ñîçäàíèå âòîðîãî èãðîêà:
4779 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4780 gPlayer2Settings.Color,
4781 gPlayer2Settings.Team, False));
4782 if gPlayer2 = nil then
4783 begin
4784 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4785 Exit;
4786 end;
4788 gPlayer2.Name := gPlayer2Settings.Name;
4789 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4790 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4791 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4792 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4793 end;
4795 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4796 if NetForwardPorts then
4797 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4799 // Ñòàðòóåì ñåðâåð
4800 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4801 begin
4802 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4803 Exit;
4804 end;
4806 g_Net_Slist_Set(NetMasterList);
4808 g_Net_Slist_ServerStarted();
4810 // Çàãðóçêà è çàïóñê êàðòû:
4811 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4812 begin
4813 g_Net_Slist_ServerClosed();
4814 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4815 Exit;
4816 end;
4818 // Íåò òî÷åê ïîÿâëåíèÿ:
4819 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4820 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4821 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4822 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4823 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4824 begin
4825 g_Net_Slist_ServerClosed();
4826 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4827 Exit;
4828 end;
4830 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4831 g_Player_Init();
4833 g_Net_Slist_ServerMapStarted();
4834 NetState := NET_STATE_GAME;
4835 end;
4837 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4839 Map: String;
4840 WadName: string;
4841 Ptr: Pointer;
4842 T: Cardinal;
4843 MID: Byte;
4844 State: Byte;
4845 OuterLoop: Boolean;
4846 newResPath: string;
4847 InMsg: TMsg;
4848 begin
4849 g_Game_Free();
4851 State := 0;
4852 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4853 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4855 g_Game_ClearLoading();
4857 ClearDebugCvars();
4859 // Íàñòðîéêè èãðû:
4860 gGameSettings.GameType := GT_CLIENT;
4862 gCoopTotalMonstersKilled := 0;
4863 gCoopTotalSecretsFound := 0;
4864 gCoopTotalMonsters := 0;
4865 gCoopTotalSecrets := 0;
4866 gAimLine := False;
4867 gShowMap := False;
4869 g_Game_ExecuteEvent('ongamestart');
4871 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4872 g_Game_SetupScreenSize();
4874 NetState := NET_STATE_AUTH;
4876 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4878 // create (or update) map/resource databases
4879 g_Res_CreateDatabases(true);
4881 gLMSRespawn := LMS_RESPAWN_NONE;
4882 gLMSRespawnTime := 0;
4883 gSpectLatchPID1 := 0;
4884 gSpectLatchPID2 := 0;
4886 // Ñòàðòóåì êëèåíò
4887 if not g_Net_Connect(Addr, Port) then
4888 begin
4889 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4890 NetState := NET_STATE_NONE;
4891 Exit;
4892 end;
4894 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4895 MC_SEND_Info(PW);
4896 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4898 OuterLoop := True;
4899 while OuterLoop do
4900 begin
4901 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4902 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4903 // thank you, enet. let's ignore failures altogether then.
4904 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4905 begin
4906 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4907 begin
4908 Ptr := NetEvent.packet^.data;
4909 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4910 begin
4911 enet_packet_destroy(NetEvent.packet);
4912 continue;
4913 end;
4915 InMsg.ReadLongWord(); // skip size
4916 MID := InMsg.ReadByte();
4918 if (MID = NET_MSG_INFO) and (State = 0) then
4919 begin
4920 NetMyID := InMsg.ReadByte();
4921 NetPlrUID1 := InMsg.ReadWord();
4923 WadName := InMsg.ReadString();
4924 Map := InMsg.ReadString();
4926 gWADHash := InMsg.ReadMD5();
4928 gGameSettings.GameMode := InMsg.ReadByte();
4929 gSwitchGameMode := gGameSettings.GameMode;
4930 gGameSettings.ScoreLimit := InMsg.ReadWord();
4931 gGameSettings.TimeLimit := InMsg.ReadWord();
4932 gGameSettings.MaxLives := InMsg.ReadByte();
4933 gGameSettings.Options := TGameOptions(InMsg.ReadLongWord());
4934 T := InMsg.ReadLongWord();
4936 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4937 //if newResPath = '' then
4938 begin
4939 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4940 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4941 if newResPath = '' then
4942 begin
4943 g_FatalError(_lc[I_NET_ERR_HASH]);
4944 enet_packet_destroy(NetEvent.packet);
4945 NetState := NET_STATE_NONE;
4946 Exit;
4947 end;
4948 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4949 end;
4950 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4953 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4954 gPlayer1Settings.Color,
4955 gPlayer1Settings.Team, False));
4957 if gPlayer1 = nil then
4958 begin
4959 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4961 enet_packet_destroy(NetEvent.packet);
4962 NetState := NET_STATE_NONE;
4963 Exit;
4964 end;
4966 gPlayer1.Name := gPlayer1Settings.Name;
4967 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4968 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4969 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4970 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4971 gPlayer1.UID := NetPlrUID1;
4972 gPlayer1.Reset(True);
4974 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4975 begin
4976 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4978 enet_packet_destroy(NetEvent.packet);
4979 NetState := NET_STATE_NONE;
4980 Exit;
4981 end;
4983 gTime := T;
4985 State := 1;
4986 OuterLoop := False;
4987 enet_packet_destroy(NetEvent.packet);
4988 break;
4990 else
4991 enet_packet_destroy(NetEvent.packet);
4993 else
4994 begin
4995 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4996 begin
4997 State := 0;
4998 if (NetEvent.data <= NET_DISC_MAX) then
4999 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
5000 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
5001 OuterLoop := False;
5002 Break;
5003 end;
5004 end;
5005 end;
5007 ProcessLoading(True);
5008 if g_Net_UserRequestExit() then
5009 begin
5010 State := 0;
5011 break;
5012 end;
5013 end;
5015 if State <> 1 then
5016 begin
5017 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
5018 NetState := NET_STATE_NONE;
5019 Exit;
5020 end;
5022 g_Player_Init();
5023 NetState := NET_STATE_GAME;
5024 MC_SEND_FullStateRequest;
5025 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
5026 end;
5029 lastAsMegaWad: Boolean = false;
5031 procedure g_Game_ChangeMap(const MapPath: String);
5033 Force: Boolean;
5034 begin
5035 g_Game_ClearLoading();
5037 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
5038 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5039 if gExitByTrigger then
5040 begin
5041 Force := False;
5042 gExitByTrigger := False;
5043 end;
5044 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
5045 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
5046 end;
5048 procedure g_Game_Restart();
5050 Map: string;
5051 begin
5052 if g_Game_IsClient then
5053 Exit;
5054 map := g_ExtractFileName(gMapInfo.Map);
5055 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
5057 MessageTime := 0;
5058 gGameOn := False;
5059 g_Game_ClearLoading();
5060 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
5061 end;
5063 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
5065 NewWAD, ResName: String;
5066 I: Integer;
5067 nws: AnsiString;
5068 begin
5069 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
5070 g_Player_RemoveAllCorpses();
5072 if (not g_Game_IsClient) and
5073 (gSwitchGameMode <> gGameSettings.GameMode) and
5074 (gGameSettings.GameMode <> GM_SINGLE) then
5075 begin
5076 if gSwitchGameMode = GM_CTF then
5077 gGameSettings.MaxLives := 0;
5078 gGameSettings.GameMode := gSwitchGameMode;
5079 Force := True;
5080 end else
5081 gSwitchGameMode := gGameSettings.GameMode;
5083 g_Player_ResetTeams();
5085 lastAsMegaWad := asMegawad;
5086 if isWadPath(Map) then
5087 begin
5088 NewWAD := g_ExtractWadName(Map);
5089 ResName := g_ExtractFileName(Map);
5090 if g_Game_IsServer then
5091 begin
5092 nws := findDiskWad(NewWAD);
5093 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5094 if (asMegawad) then
5095 begin
5096 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5097 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5099 else
5100 begin
5101 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5102 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5103 end;
5104 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5105 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5106 //nws := NewWAD;
5107 if (length(nws) = 0) then
5108 begin
5109 ResName := ''; // failed
5111 else
5112 begin
5113 NewWAD := nws;
5114 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5115 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5116 g_Game_LoadWAD(NewWAD);
5117 end;
5119 else
5120 begin
5121 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5122 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5123 end;
5125 else
5126 begin
5127 NewWAD := gGameSettings.WAD;
5128 ResName := Map;
5129 end;
5131 gTime := 0;
5133 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5134 result := false;
5135 if (ResName <> '') and (NewWAD <> '') then
5136 begin
5137 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5138 result := g_Map_Load(NewWAD+':\'+ResName);
5139 end;
5140 if Result then
5141 begin
5142 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5144 gState := STATE_NONE;
5145 g_ActiveWindow := nil;
5146 gGameOn := True;
5148 DisableCheats();
5149 ResetTimer();
5151 if gGameSettings.GameMode = GM_CTF then
5152 begin
5153 g_Map_ResetFlag(FLAG_RED);
5154 g_Map_ResetFlag(FLAG_BLUE);
5155 // CTF, à ôëàãîâ íåò:
5156 if not g_Map_HaveFlagPoints() then
5157 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5158 end;
5160 else
5161 begin
5162 gState := STATE_MENU;
5163 gGameOn := False;
5164 end;
5166 gExit := 0;
5167 gPauseMain := false;
5168 gPauseHolmes := false;
5169 NetTimeToUpdate := 1;
5170 NetTimeToReliable := 0;
5171 NetTimeToMaster := NetMasterRate;
5172 gSpectLatchPID1 := 0;
5173 gSpectLatchPID2 := 0;
5174 gMissionFailed := False;
5175 gNextMap := '';
5177 gCoopMonstersKilled := 0;
5178 gCoopSecretsFound := 0;
5180 gVoteInProgress := False;
5181 gVotePassed := False;
5182 gVoteCount := 0;
5183 gVoted := False;
5185 gStatsOff := False;
5187 if not gGameOn then Exit;
5189 g_Game_SpectateCenterView();
5191 if g_Game_IsServer then
5192 begin
5193 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5194 begin
5195 gLMSRespawn := LMS_RESPAWN_WARMUP;
5196 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5197 gLMSSoftSpawn := True;
5198 if g_Game_IsNet then
5199 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5201 else
5202 begin
5203 gLMSRespawn := LMS_RESPAWN_NONE;
5204 gLMSRespawnTime := 0;
5205 end;
5206 end;
5208 if NetMode = NET_SERVER then
5209 begin
5210 // reset full state flags
5211 if NetClients <> nil then
5212 for I := 0 to High(NetClients) do
5213 NetClients[I].FullUpdateSent := False;
5215 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5217 // Ìàñòåðñåðâåð
5218 g_Net_Slist_ServerMapStarted();
5220 if NetClients <> nil then
5221 for I := 0 to High(NetClients) do
5222 if NetClients[I].Used then
5223 begin
5224 NetClients[I].Voted := False;
5225 if NetClients[I].RequestedFullUpdate then
5226 begin
5227 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5228 NetClients[I].RequestedFullUpdate := False;
5229 end;
5230 end;
5232 g_Net_UnbanNonPerm();
5233 end;
5235 if gLastMap then
5236 begin
5237 gCoopTotalMonstersKilled := 0;
5238 gCoopTotalSecretsFound := 0;
5239 gCoopTotalMonsters := 0;
5240 gCoopTotalSecrets := 0;
5241 gLastMap := False;
5242 end;
5244 g_Game_ExecuteEvent('onmapstart');
5245 end;
5247 procedure SetFirstLevel;
5248 begin
5249 gNextMap := '';
5251 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5252 if MapList = nil then
5253 Exit;
5255 SortSArray(MapList);
5256 gNextMap := MapList[Low(MapList)];
5258 MapList := nil;
5259 end;
5261 procedure g_Game_ExitLevel(const Map: AnsiString);
5262 begin
5263 gNextMap := Map;
5265 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5266 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5267 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5268 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5270 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5271 if gGameSettings.GameType = GT_SINGLE then
5272 gExit := EXIT_ENDLEVELSINGLE
5273 else // Âûøëè â âûõîä â Ñâîåé èãðå
5274 begin
5275 gExit := EXIT_ENDLEVELCUSTOM;
5276 if gGameSettings.GameMode = GM_COOP then
5277 g_Player_RememberAll;
5279 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5280 begin
5281 gLastMap := True;
5282 if gGameSettings.GameMode = GM_COOP then
5283 gStatsOff := True;
5285 gStatsPressed := True;
5286 gNextMap := 'MAP01';
5288 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5289 g_Game_NextLevel;
5291 if g_Game_IsNet then
5292 begin
5293 MH_SEND_GameStats();
5294 MH_SEND_CoopStats();
5295 end;
5296 end;
5297 end;
5298 end;
5300 procedure g_Game_RestartLevel();
5302 Map: string;
5303 begin
5304 if gGameSettings.GameMode = GM_SINGLE then
5305 begin
5306 g_Game_Restart();
5307 Exit;
5308 end;
5309 gExit := EXIT_ENDLEVELCUSTOM;
5310 Map := g_ExtractFileName(gMapInfo.Map);
5311 gNextMap := Map;
5312 end;
5314 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5316 gWAD{, xwad}: String;
5317 begin
5318 result := NewWAD;
5319 if not g_Game_IsClient then Exit;
5320 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5322 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5323 if gWAD = '' then
5324 begin
5325 result := '';
5326 g_Game_Free();
5327 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5328 Exit;
5329 end;
5331 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5332 NewWAD := gWAD;
5334 g_Game_LoadWAD(NewWAD);
5335 result := NewWAD;
5338 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5339 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5340 if gWAD = '' then
5341 begin
5342 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5343 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5344 if gWAD = '' then
5345 begin
5346 g_Game_Free();
5347 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5348 Exit;
5349 end;
5350 end;
5351 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5352 g_Game_LoadWAD(NewWAD);
5354 end;
5356 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5358 i, n, nb, nr: Integer;
5359 begin
5360 if not g_Game_IsServer then Exit;
5361 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5362 gLMSRespawn := LMS_RESPAWN_NONE;
5363 gLMSRespawnTime := 0;
5364 MessageTime := 0;
5366 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5367 begin
5368 gMissionFailed := True;
5369 g_Game_RestartLevel;
5370 Exit;
5371 end;
5373 n := 0; nb := 0; nr := 0;
5374 for i := Low(gPlayers) to High(gPlayers) do
5375 if (gPlayers[i] <> nil) and
5376 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5377 (gPlayers[i] is TBot)) then
5378 begin
5379 Inc(n);
5380 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5381 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5382 end;
5384 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5385 begin
5386 // wait a second until the fuckers finally decide to join
5387 gLMSRespawn := LMS_RESPAWN_WARMUP;
5388 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5389 gLMSSoftSpawn := NoMapRestart;
5390 if g_Game_IsNet then
5391 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5392 Exit;
5393 end;
5395 g_Player_RemoveAllCorpses;
5396 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5397 if g_Game_IsNet then
5398 MH_SEND_GameEvent(NET_EV_LMS_START);
5400 for i := Low(gPlayers) to High(gPlayers) do
5401 begin
5402 if gPlayers[i] = nil then continue;
5403 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5404 // don't touch normal spectators
5405 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5406 begin
5407 gPlayers[i].FNoRespawn := True;
5408 gPlayers[i].Lives := 0;
5409 if g_Game_IsNet then
5410 MH_SEND_PlayerStats(gPlayers[I].UID);
5411 continue;
5412 end;
5413 gPlayers[i].FNoRespawn := False;
5414 gPlayers[i].Lives := gGameSettings.MaxLives;
5415 gPlayers[i].Respawn(False, True);
5416 if gGameSettings.GameMode = GM_COOP then
5417 begin
5418 gPlayers[i].Frags := 0;
5419 gPlayers[i].RestoreState;
5420 end;
5421 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5422 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5423 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5424 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5425 end;
5427 g_Items_RestartRound();
5429 gLMSSoftSpawn := False;
5430 end;
5432 function g_Game_GetFirstMap(WAD: String): String;
5433 begin
5434 Result := '';
5436 MapList := g_Map_GetMapsList(WAD);
5437 if MapList = nil then
5438 Exit;
5440 SortSArray(MapList);
5441 Result := MapList[Low(MapList)];
5443 if not g_Map_Exist(WAD + ':\' + Result) then
5444 Result := '';
5446 MapList := nil;
5447 end;
5449 function g_Game_GetNextMap(): String;
5451 I: Integer;
5452 Map: string;
5453 begin
5454 Result := '';
5456 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5457 if MapList = nil then
5458 Exit;
5460 Map := g_ExtractFileName(gMapInfo.Map);
5462 SortSArray(MapList);
5463 MapIndex := -255;
5464 for I := Low(MapList) to High(MapList) do
5465 if Map = MapList[I] then
5466 begin
5467 MapIndex := I;
5468 Break;
5469 end;
5471 if MapIndex <> -255 then
5472 begin
5473 if MapIndex = High(MapList) then
5474 Result := MapList[Low(MapList)]
5475 else
5476 Result := MapList[MapIndex + 1];
5478 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5479 end;
5481 MapList := nil;
5482 end;
5484 procedure g_Game_NextLevel();
5485 begin
5486 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5487 gExit := EXIT_ENDLEVELCUSTOM
5488 else
5489 begin
5490 gExit := EXIT_ENDLEVELSINGLE;
5491 Exit;
5492 end;
5494 if gNextMap <> '' then Exit;
5495 gNextMap := g_Game_GetNextMap();
5496 end;
5498 function g_Game_IsTestMap(): Boolean;
5499 begin
5500 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5501 end;
5503 procedure g_Game_DeleteTestMap();
5505 a: Integer;
5506 //MapName: AnsiString;
5507 WadName: string;
5509 WAD: TWADFile;
5510 MapList: SSArray;
5511 time: Integer;
5513 begin
5514 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5515 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5516 if (a = 0) then exit;
5518 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5519 WadName := Copy(gMapToDelete, 1, a+3);
5520 Delete(gMapToDelete, 1, a+5);
5521 gMapToDelete := UpperCase(gMapToDelete);
5522 //MapName := '';
5523 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5526 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5527 if MapName <> TEST_MAP_NAME then
5528 Exit;
5530 if not gTempDelete then
5531 begin
5532 time := g_GetFileTime(WadName);
5533 WAD := TWADFile.Create();
5535 // ×èòàåì Wad-ôàéë:
5536 if not WAD.ReadFile(WadName) then
5537 begin // Íåò òàêîãî WAD-ôàéëà
5538 WAD.Free();
5539 Exit;
5540 end;
5542 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5543 WAD.CreateImage();
5544 MapList := WAD.GetResourcesList('');
5546 if MapList <> nil then
5547 for a := 0 to High(MapList) do
5548 if MapList[a] = MapName then
5549 begin
5550 // Óäàëÿåì è ñîõðàíÿåì:
5551 WAD.RemoveResource('', MapName);
5552 WAD.SaveTo(WadName);
5553 Break;
5554 end;
5556 WAD.Free();
5557 g_SetFileTime(WadName, time);
5558 end else
5560 if gTempDelete then DeleteFile(WadName);
5561 end;
5563 procedure GameCVars(P: SSArray);
5565 a, b: Integer;
5566 stat: TPlayerStatArray;
5567 cmd: string;
5568 it: PItem;
5570 procedure ParseGameFlag(Flag: TGameOption; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5572 x: Boolean;
5573 begin
5574 if Length(P) <= 1 then
5575 x := Flag in gsGameFlags
5576 else
5577 begin
5578 x := P[1] = '1';
5580 if x
5581 then gsGameFlags += [Flag]
5582 else gsGameFlags -= [Flag];
5584 if g_Game_IsServer then
5585 begin
5586 if x
5587 then gGameSettings.Options += [Flag]
5588 else gGameSettings.Options -= [Flag];
5589 if g_Game_IsNet then MH_SEND_GameSettings;
5590 end;
5591 end;
5593 if x
5594 then g_Console_Add(_lc[OnMsg])
5595 else g_Console_Add(_lc[OffMsg]);
5597 if OnMapChange and g_Game_IsServer then
5598 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5599 end;
5601 begin
5602 stat := nil;
5603 cmd := LowerCase(P[0]);
5605 case cmd of
5606 'g_gamemode': begin
5607 if (Length(P) > 1) then
5608 begin
5609 a := g_Game_TextToMode(P[1]);
5610 if a = GM_SINGLE then a := GM_COOP;
5611 gsGameMode := g_Game_ModeToText(a);
5612 if g_Game_IsServer then
5613 begin
5614 gSwitchGameMode := a;
5615 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5616 (gState = STATE_INTERSINGLE) then
5617 gSwitchGameMode := GM_SINGLE;
5618 if not gGameOn then
5619 gGameSettings.GameMode := gSwitchGameMode;
5620 end;
5621 end;
5623 if gSwitchGameMode = gGameSettings.GameMode then
5624 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5625 [g_Game_ModeToText(gGameSettings.GameMode)]))
5626 else
5627 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5628 [g_Game_ModeToText(gGameSettings.GameMode),
5629 g_Game_ModeToText(gSwitchGameMode)]));
5630 end;
5632 'g_friendlyfire':
5633 ParseGameFlag(TGameOption.TEAM_DAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5634 'g_friendly_absorb_damage':
5635 ParseGameFlag(TGameOption.TEAM_ABSORB_DAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5636 'g_friendly_hit_trace':
5637 ParseGameFlag(TGameOption.TEAM_HIT_TRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5638 'g_friendly_hit_projectile':
5639 ParseGameFlag(TGameOption.TEAM_HIT_PROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5640 'g_items_all_respawn_random':
5641 ParseGameFlag(TGameOption.ITEM_ALL_RANDOM, I_MSG_ITEM_ALL_RANDOM_OFF, I_MSG_ITEM_ALL_RANDOM_ON, False);
5642 'g_items_help_respawn_random':
5643 ParseGameFlag(TGameOption.ITEM_LIFE_RANDOM, I_MSG_ITEM_LIFE_RANDOM_OFF, I_MSG_ITEM_LIFE_RANDOM_ON, False);
5644 'g_items_ammo_respawn_random':
5645 ParseGameFlag(TGameOption.ITEM_AMMO_RANDOM, I_MSG_ITEM_AMMO_RANDOM_OFF, I_MSG_ITEM_AMMO_RANDOM_ON, False);
5646 'g_items_weapon_respawn_random':
5647 ParseGameFlag(TGameOption.ITEM_WEAPON_RANDOM, I_MSG_ITEM_WEAPON_RANDOM_OFF, I_MSG_ITEM_WEAPON_RANDOM_ON);
5648 'g_powerup_randomize_respawn':
5649 ParseGameFlag(TGameOption.POWERUP_RANDOM, I_MSG_POWERUP_RANDOM_OFF, I_MSG_POWERUP_RANDOM_ON, False);
5650 'g_weaponstay':
5651 ParseGameFlag(TGameOption.WEAPONS_STAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5652 'g_allow_exit':
5653 ParseGameFlag(TGameOption.ALLOW_EXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5654 'g_allow_monsters':
5655 ParseGameFlag(TGameOption.MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5656 'g_allow_dropflag':
5657 ParseGameFlag(TGameOption.ALLOW_DROP_FLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
5658 'g_throw_flag':
5659 ParseGameFlag(TGameOption.THROW_FLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
5660 'g_bot_vsplayers':
5661 ParseGameFlag(TGameOption.BOTS_VS_PLAYERS, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5662 'g_bot_vsmonsters':
5663 ParseGameFlag(TGameOption.BOTS_VS_MONSTERS, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5664 'g_dm_keys':
5665 ParseGameFlag(TGameOption.DM_KEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5667 'g_gameflags': begin
5668 if Length(P) > 1 then
5669 begin
5670 gsGameFlags := TGameOptions(StrToDWordDef(P[1], LongWord(gsGameFlags)));
5671 if g_Game_IsServer then
5672 begin
5673 gGameSettings.Options := gsGameFlags;
5674 if g_Game_IsNet then MH_SEND_GameSettings;
5675 end;
5676 end;
5678 g_Console_Add(Format('%s %u', [cmd, LongWord(gsGameFlags)]));
5679 end;
5681 'g_warmup_time': begin
5682 if Length(P) > 1 then
5683 begin
5684 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5685 if g_Game_IsServer then
5686 begin
5687 gGameSettings.WarmupTime := gsWarmupTime;
5688 // extend warmup if it's already going
5689 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5690 begin
5691 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5692 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5693 end;
5694 if g_Game_IsNet then MH_SEND_GameSettings;
5695 end;
5696 end;
5698 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5699 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5700 end;
5702 'g_spawn_invul': begin
5703 if Length(P) > 1 then
5704 begin
5705 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5706 if g_Game_IsServer then
5707 begin
5708 gGameSettings.SpawnInvul := gsSpawnInvul;
5709 if g_Game_IsNet then MH_SEND_GameSettings;
5710 end;
5711 end;
5713 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5714 end;
5716 'g_item_respawn_time': begin
5717 if Length(P) > 1 then
5718 begin
5719 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5720 if g_Game_IsServer then
5721 begin
5722 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5723 if g_Game_IsNet then MH_SEND_GameSettings;
5724 end;
5725 end;
5727 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5728 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5729 end;
5731 'g_item_time_random': begin
5732 if Length(P) > 1 then
5733 begin
5734 gsItemRespawnRandom := nclamp(StrToIntDef(P[1], gsItemRespawnRandom), 0, $FFFF);
5735 if g_Game_IsServer then
5736 begin
5737 gGameSettings.ItemRespawnRandom := gsItemRespawnRandom;
5738 if g_Game_IsNet then MH_SEND_GameSettings;
5739 end;
5740 end;
5742 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnRandom)]));
5743 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5744 end;
5746 'g_powerup_respawn_time': begin
5747 if Length(P) > 1 then
5748 begin
5749 gsPowerupRespawnTime := nclamp(StrToIntDef(P[1], gsPowerupRespawnTime), 0, $FFFF);
5750 if g_Game_IsServer then
5751 begin
5752 gGameSettings.PowerupRespawnTime := gsPowerupRespawnTime;
5753 if g_Game_IsNet then MH_SEND_GameSettings;
5754 end;
5755 end;
5757 g_Console_Add(Format('%s %d', [cmd, Integer(gsPowerupRespawnTime)]));
5758 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5759 end;
5761 'g_powerup_time_random': begin
5762 if Length(P) > 1 then
5763 begin
5764 gsPowerupRespawnRandom := nclamp(StrToIntDef(P[1], gsPowerupRespawnRandom), 0, $FFFF);
5765 if g_Game_IsServer then
5766 begin
5767 gGameSettings.PowerupRespawnRandom := gsPowerupRespawnRandom;
5768 if g_Game_IsNet then MH_SEND_GameSettings;
5769 end;
5770 end;
5772 g_Console_Add(Format('%s %d', [cmd, Integer(gsPowerupRespawnRandom)]));
5773 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5774 end;
5776 'sv_intertime': begin
5777 if (Length(P) > 1) then
5778 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5780 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5781 end;
5783 'g_max_particles': begin
5784 if Length(p) = 2 then
5785 begin
5786 a := Max(0, StrToIntDef(p[1], 0));
5787 g_GFX_SetMax(a)
5789 else if Length(p) = 1 then
5790 begin
5791 e_LogWritefln('%s', [g_GFX_GetMax()])
5793 else
5794 begin
5795 e_LogWritefln('usage: %s <n>', [cmd])
5797 end;
5799 'g_max_shells': begin
5800 if Length(p) = 2 then
5801 begin
5802 a := Max(0, StrToIntDef(p[1], 0));
5803 g_Shells_SetMax(a)
5805 else if Length(p) = 1 then
5806 begin
5807 e_LogWritefln('%s', [g_Shells_GetMax()])
5809 else
5810 begin
5811 e_LogWritefln('usage: %s <n>', [cmd])
5813 end;
5815 'g_max_gibs': begin
5816 if Length(p) = 2 then
5817 begin
5818 a := Max(0, StrToIntDef(p[1], 0));
5819 g_Gibs_SetMax(a)
5821 else if Length(p) = 1 then
5822 begin
5823 e_LogWritefln('%s', [g_Gibs_GetMax()])
5825 else
5826 begin
5827 e_LogWritefln('usage: %s <n>', [cmd])
5829 end;
5831 'g_max_corpses': begin
5832 if Length(p) = 2 then
5833 begin
5834 a := Max(0, StrToIntDef(p[1], 0));
5835 g_Corpses_SetMax(a)
5837 else if Length(p) = 1 then
5838 begin
5839 e_LogWritefln('%s', [g_Corpses_GetMax()])
5841 else
5842 begin
5843 e_LogWritefln('usage: %s <n>', [cmd])
5845 end;
5847 'g_force_model': begin
5848 if Length(p) = 2 then
5849 begin
5850 a := StrToIntDef(p[1], 0);
5851 g_Force_Model_Set(a);
5852 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5853 begin
5854 for a := Low(gPlayers) to High(gPlayers) do
5855 begin
5856 if (gPlayers[a] <> nil) then
5857 begin
5858 if (gPlayers[a].UID = gPlayer1.UID) then
5859 continue
5860 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5861 continue;
5862 gPlayers[a].setModel(g_Forced_Model_GetName());
5863 end;
5866 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
5867 begin
5868 for a := Low(gPlayers) to High(gPlayers) do
5869 begin
5870 if (gPlayers[a] <> nil) then
5871 begin
5872 if (gPlayers[a].UID = gPlayer1.UID) then
5873 continue
5874 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5875 continue;
5876 gPlayers[a].setModel(gPlayers[a].FActualModelName);
5877 end;
5881 end;
5883 'g_force_model_name': begin
5884 if (Length(P) > 1) then
5885 begin
5886 cmd := b_Text_Unformat(P[1]);
5887 g_Forced_Model_SetName(cmd);
5888 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5889 begin
5890 for a := Low(gPlayers) to High(gPlayers) do
5891 begin
5892 if (gPlayers[a] <> nil) then
5893 begin
5894 if (gPlayers[a].UID = gPlayer1.UID) then
5895 continue
5896 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5897 continue;
5898 gPlayers[a].setModel(g_Forced_Model_GetName());
5899 end;
5903 end;
5905 'g_scorelimit': begin
5906 if Length(P) > 1 then
5907 begin
5908 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
5910 if g_Game_IsServer then
5911 begin
5912 b := 0;
5913 if gGameSettings.GameMode = GM_DM then
5914 begin // DM
5915 stat := g_Player_GetStats();
5916 if stat <> nil then
5917 for a := 0 to High(stat) do
5918 if stat[a].Frags > b then
5919 b := stat[a].Frags;
5921 else // TDM/CTF
5922 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
5924 // if someone has a higher score, set it to that instead
5925 gsScoreLimit := max(gsScoreLimit, b);
5926 gGameSettings.ScoreLimit := gsScoreLimit;
5928 if g_Game_IsNet then MH_SEND_GameSettings;
5929 end;
5930 end;
5932 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
5933 end;
5935 'g_timelimit': begin
5936 if Length(P) > 1 then
5937 begin
5938 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5939 if g_Game_IsServer then
5940 begin
5941 gGameSettings.TimeLimit := gsTimeLimit;
5942 if g_Game_IsNet then MH_SEND_GameSettings;
5943 end;
5944 end;
5945 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5946 [gsTimeLimit div 3600,
5947 (gsTimeLimit div 60) mod 60,
5948 gsTimeLimit mod 60]));
5949 end;
5951 'g_max_bots': begin
5952 if Length(P) > 1 then
5953 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
5954 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
5955 end;
5957 'g_maxlives': begin
5958 if Length(P) > 1 then
5959 begin
5960 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5961 if g_Game_IsServer then
5962 begin
5963 gGameSettings.MaxLives := gsMaxLives;
5964 if g_Game_IsNet then MH_SEND_GameSettings;
5965 end;
5966 end;
5968 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5969 end;
5970 end;
5971 end;
5973 procedure PlayerSettingsCVars(P: SSArray);
5975 cmd: string;
5976 team: Byte;
5978 function ParseTeam(s: string): Byte;
5979 begin
5980 result := 0;
5981 case s of
5982 'red', '1': result := TEAM_RED;
5983 'blue', '2': result := TEAM_BLUE;
5984 else result := TEAM_NONE;
5985 end;
5986 end;
5987 begin
5988 cmd := LowerCase(P[0]);
5989 case cmd of
5990 'p1_name':
5991 begin
5992 if (Length(P) > 1) then
5993 begin
5994 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5995 if g_Game_IsClient then
5996 MC_SEND_PlayerSettings
5997 else if gGameOn and (gPlayer1 <> nil) then
5998 begin
5999 gPlayer1.Name := b_Text_Unformat(P[1]);
6000 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6001 end;
6002 end;
6003 end;
6004 'p2_name':
6005 begin
6006 if (Length(P) > 1) then
6007 begin
6008 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
6009 if g_Game_IsClient then
6010 MC_SEND_PlayerSettings
6011 else if gGameOn and (gPlayer2 <> nil) then
6012 begin
6013 gPlayer2.Name := b_Text_Unformat(P[1]);
6014 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6015 end;
6016 end;
6017 end;
6018 'p1_color':
6019 begin
6020 if Length(P) > 3 then
6021 begin
6022 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6023 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6024 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6025 if g_Game_IsClient then
6026 MC_SEND_PlayerSettings
6027 else if gGameOn and (gPlayer1 <> nil) then
6028 begin
6029 gPlayer1.SetColor(gPlayer1Settings.Color);
6030 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6031 end;
6032 end;
6033 end;
6034 'p2_color':
6035 begin
6036 if Length(P) > 3 then
6037 begin
6038 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6039 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6040 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6041 if g_Game_IsClient then
6042 MC_SEND_PlayerSettings
6043 else if gGameOn and (gPlayer2 <> nil) then
6044 begin
6045 gPlayer2.SetColor(gPlayer2Settings.Color);
6046 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6047 end;
6048 end;
6049 end;
6050 'p1_model':
6051 begin
6052 if (Length(P) > 1) then
6053 begin
6054 gPlayer1Settings.Model := P[1];
6055 if g_Game_IsClient then
6056 MC_SEND_PlayerSettings
6057 else if gGameOn and (gPlayer1 <> nil) then
6058 begin
6059 gPlayer1.FActualModelName := gPlayer1Settings.Model;
6060 gPlayer1.SetModel(gPlayer1Settings.Model);
6061 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6062 end;
6063 end;
6064 end;
6065 'p2_model':
6066 begin
6067 if (Length(P) > 1) then
6068 begin
6069 gPlayer2Settings.Model := P[1];
6070 if g_Game_IsClient then
6071 MC_SEND_PlayerSettings
6072 else if gGameOn and (gPlayer2 <> nil) then
6073 begin
6074 gPlayer2.FActualModelName := gPlayer2Settings.Model;
6075 gPlayer2.SetModel(gPlayer2Settings.Model);
6076 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6077 end;
6078 end;
6079 end;
6080 'p1_team':
6081 begin
6082 // TODO: switch teams if in game or store this separately
6083 if (Length(P) > 1) then
6084 begin
6085 team := ParseTeam(P[1]);
6086 if team = TEAM_NONE then
6087 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6088 else if not gGameOn and not g_Game_IsNet then
6089 gPlayer1Settings.Team := team
6090 else
6091 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6092 end;
6093 end;
6094 'p2_team':
6095 begin
6096 // TODO: switch teams if in game or store this separately
6097 if (Length(P) > 1) then
6098 begin
6099 team := ParseTeam(P[1]);
6100 if team = TEAM_NONE then
6101 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6102 else if not gGameOn and not g_Game_IsNet then
6103 gPlayer2Settings.Team := team
6104 else
6105 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6106 end;
6107 end;
6108 'p1_autoswitch':
6109 begin
6110 if (Length(P) = 2) then
6111 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6112 end;
6113 'p2_autoswitch':
6114 begin
6115 if (Length(P) = 2) then
6116 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6117 end;
6118 'p1_switch_empty':
6119 begin
6120 if (Length(P) = 2) then
6121 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6122 end;
6123 'p2_switch_empty':
6124 begin
6125 if (Length(P) = 2) then
6126 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6127 end;
6128 'p1_skip_ironfist':
6129 begin
6130 if (Length(P) = 2) then
6131 gPlayer1Settings.SkipIronFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6132 end;
6133 'p2_skip_ironfist':
6134 begin
6135 if (Length(P) = 2) then
6136 gPlayer2Settings.SkipIronFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6137 end;
6138 'p1_priority_ironfist':
6139 begin
6140 if (Length(P) = 2) then
6141 gPlayer1Settings.WeaponPreferences[WEAPON_IRONFIST] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6142 end;
6143 'p2_priority_ironfist':
6144 begin
6145 if (Length(P) = 2) then
6146 gPlayer2Settings.WeaponPreferences[WEAPON_IRONFIST] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6147 end;
6148 'p1_priority_saw':
6149 begin
6150 if (Length(P) = 2) then
6151 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6152 end;
6153 'p2_priority_saw':
6154 begin
6155 if (Length(P) = 2) then
6156 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6157 end;
6158 'p1_priority_pistol':
6159 begin
6160 if (Length(P) = 2) then
6161 gPlayer1Settings.WeaponPreferences[WEAPON_PISTOL] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6162 end;
6163 'p2_priority_pistol':
6164 begin
6165 if (Length(P) = 2) then
6166 gPlayer2Settings.WeaponPreferences[WEAPON_PISTOL] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6167 end;
6168 'p1_priority_shotgun1':
6169 begin
6170 if (Length(P) = 2) then
6171 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6172 end;
6173 'p2_priority_shotgun1':
6174 begin
6175 if (Length(P) = 2) then
6176 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6177 end;
6178 'p1_priority_shotgun2':
6179 begin
6180 if (Length(P) = 2) then
6181 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6182 end;
6183 'p2_priority_shotgun2':
6184 begin
6185 if (Length(P) = 2) then
6186 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6187 end;
6188 'p1_priority_chaingun':
6189 begin
6190 if (Length(P) = 2) then
6191 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6192 end;
6193 'p2_priority_chaingun':
6194 begin
6195 if (Length(P) = 2) then
6196 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6197 end;
6198 'p1_priority_rocketlauncher':
6199 begin
6200 if (Length(P) = 2) then
6201 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6202 end;
6203 'p2_priority_rocketlauncher':
6204 begin
6205 if (Length(P) = 2) then
6206 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6207 end;
6208 'p1_priority_plasma':
6209 begin
6210 if (Length(P) = 2) then
6211 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6212 end;
6213 'p2_priority_plasma':
6214 begin
6215 if (Length(P) = 2) then
6216 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6217 end;
6218 'p1_priority_bfg':
6219 begin
6220 if (Length(P) = 2) then
6221 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6222 end;
6223 'p2_priority_bfg':
6224 begin
6225 if (Length(P) = 2) then
6226 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6227 end;
6228 'p1_priority_superchaingun':
6229 begin
6230 if (Length(P) = 2) then
6231 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERCHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6232 end;
6233 'p2_priority_superchaingun':
6234 begin
6235 if (Length(P) = 2) then
6236 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERCHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6237 end;
6238 'p1_priority_flamethrower':
6239 begin
6240 if (Length(P) = 2) then
6241 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6242 end;
6243 'p2_priority_flamethrower':
6244 begin
6245 if (Length(P) = 2) then
6246 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6247 end;
6248 'p1_priority_berserk':
6249 begin
6250 if (Length(P) = 2) then
6251 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6252 end;
6253 'p2_priority_berserk':
6254 begin
6255 if (Length(P) = 2) then
6256 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6257 end;
6258 end;
6259 end;
6261 procedure PrintHeapStats();
6263 hs: TFPCHeapStatus;
6264 begin
6265 hs := GetFPCHeapStatus();
6266 e_LogWriteLn ('v===== heap status =====v');
6267 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
6268 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
6269 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
6270 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
6271 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
6272 e_LogWriteLn ('^=======================^');
6273 end;
6275 procedure DebugCommands(P: SSArray);
6277 a, b: Integer;
6278 cmd: string;
6279 //pt: TDFPoint;
6280 mon: TMonster;
6281 begin
6282 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6283 if {gDebugMode}conIsCheatsEnabled then
6284 begin
6285 cmd := LowerCase(P[0]);
6286 if cmd = 'd_window' then
6287 begin
6288 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6289 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
6291 else if cmd = 'd_sounds' then
6292 begin
6293 if (Length(P) > 1) and
6294 ((P[1] = '1') or (P[1] = '0')) then
6295 g_Debug_Sounds := (P[1][1] = '1');
6297 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
6299 else if cmd = 'd_frames' then
6300 begin
6301 if (Length(P) > 1) and
6302 ((P[1] = '1') or (P[1] = '0')) then
6303 g_Debug_Frames := (P[1][1] = '1');
6305 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
6307 else if cmd = 'd_winmsg' then
6308 begin
6309 if (Length(P) > 1) and
6310 ((P[1] = '1') or (P[1] = '0')) then
6311 g_Debug_WinMsgs := (P[1][1] = '1');
6313 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
6315 else if (cmd = 'd_monoff') and not g_Game_IsNet then
6316 begin
6317 if (Length(P) > 1) and
6318 ((P[1] = '1') or (P[1] = '0')) then
6319 g_Debug_MonsterOff := (P[1][1] = '1');
6321 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
6323 else if (cmd = 'd_botoff') and not g_Game_IsNet then
6324 begin
6325 if Length(P) > 1 then
6326 case P[1][1] of
6327 '0': g_debug_BotAIOff := 0;
6328 '1': g_debug_BotAIOff := 1;
6329 '2': g_debug_BotAIOff := 2;
6330 '3': g_debug_BotAIOff := 3;
6331 end;
6333 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
6335 else if cmd = 'd_monster' then
6336 begin
6337 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
6338 if Length(P) < 2 then
6339 begin
6340 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
6341 g_Console_Add('ID | Name');
6342 for b := MONSTER_DEMON to MONSTER_MAN do
6343 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
6344 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6345 end else
6346 begin
6347 a := StrToIntDef(P[1], 0);
6348 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6349 a := g_Mons_TypeIdByName(P[1]);
6351 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6352 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
6353 else
6354 begin
6355 with gPlayer1.Obj do
6356 begin
6357 mon := g_Monsters_Create(a,
6358 X + Rect.X + (Rect.Width div 2),
6359 Y + Rect.Y + Rect.Height,
6360 gPlayer1.Direction, True);
6361 end;
6362 if (Length(P) > 2) and (mon <> nil) then
6363 begin
6364 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
6365 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
6366 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
6367 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
6368 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
6369 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6370 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6371 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6372 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6373 end;
6374 end;
6375 end;
6377 else if (cmd = 'd_health') then
6378 begin
6379 if (Length(P) > 1) and
6380 ((P[1] = '1') or (P[1] = '0')) then
6381 g_debug_HealthBar := (P[1][1] = '1');
6383 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6385 else if (cmd = 'd_player') then
6386 begin
6387 if (Length(P) > 1) and
6388 ((P[1] = '1') or (P[1] = '0')) then
6389 g_debug_Player := (P[1][1] = '1');
6391 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6393 else if (cmd = 'd_mem') then
6394 begin
6395 PrintHeapStats();
6396 end;
6398 else
6399 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6400 end;
6403 procedure GameCheats(P: SSArray);
6405 cmd: string;
6406 f, a: Integer;
6407 plr: TPlayer;
6408 begin
6409 if (not gGameOn) or (not conIsCheatsEnabled) then
6410 begin
6411 g_Console_Add('not available');
6412 exit;
6413 end;
6414 plr := gPlayer1;
6415 if plr = nil then
6416 begin
6417 g_Console_Add('where is the player?!');
6418 exit;
6419 end;
6420 cmd := LowerCase(P[0]);
6421 // god
6422 if cmd = 'god' then
6423 begin
6424 plr.GodMode := not plr.GodMode;
6425 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6426 exit;
6427 end;
6428 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6429 if cmd = 'give' then
6430 begin
6431 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6432 for f := 1 to High(P) do
6433 begin
6434 cmd := LowerCase(P[f]);
6435 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6436 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.TankRamboCheats(False); g_Console_Add('player got the gifts'); continue; end;
6437 if cmd = 'exit' then
6438 begin
6439 if gTriggers <> nil then
6440 begin
6441 for a := 0 to High(gTriggers) do
6442 begin
6443 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6444 begin
6445 g_Console_Add('player left the map');
6446 gExitByTrigger := True;
6447 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6448 g_Game_ExitLevel(gTriggers[a].tgcMap);
6449 break;
6450 end;
6451 end;
6452 end;
6453 continue;
6454 end;
6456 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6457 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6458 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6459 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6460 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6462 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6463 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6465 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6466 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;
6468 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6469 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6471 if (cmd = 'soulsphere') or (cmd = 'soul') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a soul sphere'); continue; end;
6472 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a megasphere'); continue; end;
6474 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6475 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6477 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6478 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6479 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6481 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6482 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6483 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6484 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;
6485 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6486 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6488 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;
6489 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;
6490 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;
6491 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;
6492 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;
6493 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;
6495 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERCHAINGUN); g_Console_Add('player got a superchaingun'); continue; end;
6496 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;
6498 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;
6499 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;
6501 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6503 if cmd = 'ammo' then
6504 begin
6505 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6506 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6507 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6508 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6509 plr.GiveItem(ITEM_AMMO_FUELCAN);
6510 g_Console_Add('player got some ammo');
6511 continue;
6512 end;
6514 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6515 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6517 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6518 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6520 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6521 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6523 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6524 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6526 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6528 if cmd = 'weapons' then
6529 begin
6530 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6531 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6532 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6533 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6534 plr.GiveItem(ITEM_WEAPON_PLASMA);
6535 plr.GiveItem(ITEM_WEAPON_BFG);
6536 g_Console_Add('player got weapons');
6537 continue;
6538 end;
6540 if cmd = 'keys' then
6541 begin
6542 plr.GiveItem(ITEM_KEY_RED);
6543 plr.GiveItem(ITEM_KEY_GREEN);
6544 plr.GiveItem(ITEM_KEY_BLUE);
6545 g_Console_Add('player got all keys');
6546 continue;
6547 end;
6549 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6550 end;
6551 exit;
6552 end;
6553 // open
6554 if cmd = 'open' then
6555 begin
6556 g_Console_Add('player activated sesame');
6557 g_Triggers_OpenAll();
6558 exit;
6559 end;
6560 // fly
6561 if cmd = 'fly' then
6562 begin
6563 gFly := not gFly;
6564 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6565 exit;
6566 end;
6567 // noclip
6568 if cmd = 'noclip' then
6569 begin
6570 plr.SwitchNoClip;
6571 g_Console_Add('wall hardeness adjusted');
6572 exit;
6573 end;
6574 // notarget
6575 if cmd = 'notarget' then
6576 begin
6577 plr.NoTarget := not plr.NoTarget;
6578 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6579 exit;
6580 end;
6581 // noreload
6582 if cmd = 'noreload' then
6583 begin
6584 plr.NoReload := not plr.NoReload;
6585 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6586 exit;
6587 end;
6588 // speedy
6589 if cmd = 'speedy' then
6590 begin
6591 MAX_RUNVEL := 32-MAX_RUNVEL;
6592 g_Console_Add('speed adjusted');
6593 exit;
6594 end;
6595 // jumpy
6596 if cmd = 'jumpy' then
6597 begin
6598 VEL_JUMP := 30-VEL_JUMP;
6599 g_Console_Add('jump height adjusted');
6600 exit;
6601 end;
6602 // automap
6603 if cmd = 'automap' then
6604 begin
6605 gShowMap := not gShowMap;
6606 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6607 exit;
6608 end;
6609 // aimline
6610 if cmd = 'aimline' then
6611 begin
6612 gAimLine := not gAimLine;
6613 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6614 exit;
6615 end;
6616 end;
6618 procedure GameCommands(P: SSArray);
6620 a, b: Integer;
6621 s, pw: String;
6622 chstr: string;
6623 cmd: string;
6624 pl: pTNetClient = nil;
6625 plr: TPlayer;
6626 prt: Word;
6627 nm: Boolean;
6628 listen: LongWord;
6629 found: Boolean;
6630 t: Byte;
6631 begin
6632 // Îáùèå êîìàíäû:
6633 cmd := LowerCase(P[0]);
6634 chstr := '';
6635 if cmd = 'pause' then
6636 begin
6637 if (g_ActiveWindow = nil) then
6638 g_Game_Pause(not gPauseMain);
6640 else if cmd = 'endgame' then
6641 gExit := EXIT_SIMPLE
6642 else if cmd = 'restart' then
6643 begin
6644 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6645 begin
6646 if g_Game_IsClient then
6647 begin
6648 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6649 Exit;
6650 end;
6651 g_Game_Restart();
6652 end else
6653 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6655 else if cmd = 'kick' then
6656 begin
6657 if g_Game_IsServer then
6658 begin
6659 if Length(P) < 2 then
6660 begin
6661 g_Console_Add('kick <name>');
6662 Exit;
6663 end;
6664 if P[1] = '' then
6665 begin
6666 g_Console_Add('kick <name>');
6667 Exit;
6668 end;
6670 if g_Game_IsNet then
6671 pl := g_Net_Client_ByName(P[1]);
6672 if (pl <> nil) then
6673 begin
6674 s := g_Net_ClientName_ByID(pl^.ID);
6675 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6676 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6677 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6678 g_Net_Slist_ServerPlayerLeaves();
6679 end else if gPlayers <> nil then
6680 for a := Low(gPlayers) to High(gPlayers) do
6681 if gPlayers[a] <> nil then
6682 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6683 begin
6684 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6685 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6686 continue;
6687 gPlayers[a].Lives := 0;
6688 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6689 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6690 g_Player_Remove(gPlayers[a].UID);
6691 g_Net_Slist_ServerPlayerLeaves();
6692 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6693 g_Bot_MixNames();
6694 end;
6695 end else
6696 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6698 else if cmd = 'kick_id' then
6699 begin
6700 if g_Game_IsServer and g_Game_IsNet then
6701 begin
6702 if Length(P) < 2 then
6703 begin
6704 g_Console_Add('kick_id <client ID>');
6705 Exit;
6706 end;
6707 if P[1] = '' then
6708 begin
6709 g_Console_Add('kick_id <client ID>');
6710 Exit;
6711 end;
6713 a := StrToIntDef(P[1], 0);
6714 if (NetClients <> nil) and (a <= High(NetClients)) then
6715 begin
6716 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6717 begin
6718 s := g_Net_ClientName_ByID(NetClients[a].ID);
6719 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
6720 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6721 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6722 g_Net_Slist_ServerPlayerLeaves();
6723 end;
6724 end;
6725 end else
6726 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6728 else if cmd = 'kick_pid' then
6729 begin
6730 if g_Game_IsServer and g_Game_IsNet then
6731 begin
6732 if Length(P) < 2 then
6733 begin
6734 g_Console_Add('kick_pid <player ID>');
6735 Exit;
6736 end;
6737 if P[1] = '' then
6738 begin
6739 g_Console_Add('kick_pid <player ID>');
6740 Exit;
6741 end;
6743 a := StrToIntDef(P[1], 0);
6744 pl := g_Net_Client_ByPlayer(a);
6745 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6746 begin
6747 s := g_Net_ClientName_ByID(pl^.ID);
6748 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6749 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6750 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6751 g_Net_Slist_ServerPlayerLeaves();
6752 end;
6753 end else
6754 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6756 else if cmd = 'ban' then
6757 begin
6758 if g_Game_IsServer and g_Game_IsNet then
6759 begin
6760 if Length(P) < 2 then
6761 begin
6762 g_Console_Add('ban <name>');
6763 Exit;
6764 end;
6765 if P[1] = '' then
6766 begin
6767 g_Console_Add('ban <name>');
6768 Exit;
6769 end;
6771 pl := g_Net_Client_ByName(P[1]);
6772 if (pl <> nil) then
6773 g_Net_Host_Ban(pl, False)
6774 else
6775 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6776 end else
6777 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6779 else if cmd = 'ban_id' then
6780 begin
6781 if g_Game_IsServer and g_Game_IsNet then
6782 begin
6783 if Length(P) < 2 then
6784 begin
6785 g_Console_Add('ban_id <client ID>');
6786 Exit;
6787 end;
6788 if P[1] = '' then
6789 begin
6790 g_Console_Add('ban_id <client ID>');
6791 Exit;
6792 end;
6794 a := StrToIntDef(P[1], 0);
6795 if (NetClients <> nil) and (a <= High(NetClients)) then
6796 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6797 g_Net_Host_Ban(pl, False);
6798 end else
6799 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6801 else if cmd = 'ban_pid' then
6802 begin
6803 if g_Game_IsServer and g_Game_IsNet then
6804 begin
6805 if Length(P) < 2 then
6806 begin
6807 g_Console_Add('ban_pid <player ID>');
6808 Exit;
6809 end;
6810 if P[1] = '' then
6811 begin
6812 g_Console_Add('ban_pid <player ID>');
6813 Exit;
6814 end;
6816 a := StrToIntDef(P[1], 0);
6817 pl := g_Net_Client_ByPlayer(a);
6818 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6819 g_Net_Host_Ban(pl, False);
6820 end else
6821 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6823 else if cmd = 'permban' then
6824 begin
6825 if g_Game_IsServer and g_Game_IsNet then
6826 begin
6827 if Length(P) < 2 then
6828 begin
6829 g_Console_Add('permban <name>');
6830 Exit;
6831 end;
6832 if P[1] = '' then
6833 begin
6834 g_Console_Add('permban <name>');
6835 Exit;
6836 end;
6838 pl := g_Net_Client_ByName(P[1]);
6839 if (pl <> nil) then
6840 g_Net_Host_Ban(pl, True)
6841 else
6842 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6843 end else
6844 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6846 else if cmd = 'permban_id' then
6847 begin
6848 if g_Game_IsServer and g_Game_IsNet then
6849 begin
6850 if Length(P) < 2 then
6851 begin
6852 g_Console_Add('permban_id <client ID>');
6853 Exit;
6854 end;
6855 if P[1] = '' then
6856 begin
6857 g_Console_Add('permban_id <client ID>');
6858 Exit;
6859 end;
6861 a := StrToIntDef(P[1], 0);
6862 if (NetClients <> nil) and (a <= High(NetClients)) then
6863 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6864 g_Net_Host_Ban(@NetClients[a], True);
6865 end else
6866 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6868 else if cmd = 'permban_pid' then
6869 begin
6870 if g_Game_IsServer and g_Game_IsNet then
6871 begin
6872 if Length(P) < 2 then
6873 begin
6874 g_Console_Add('permban_pid <player ID>');
6875 Exit;
6876 end;
6877 if P[1] = '' then
6878 begin
6879 g_Console_Add('permban_pid <player ID>');
6880 Exit;
6881 end;
6883 a := StrToIntDef(P[1], 0);
6884 pl := g_Net_Client_ByPlayer(a);
6885 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6886 g_Net_Host_Ban(pl, True);
6887 end else
6888 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6890 else if cmd = 'permban_ip' then
6891 begin
6892 if g_Game_IsServer and g_Game_IsNet then
6893 begin
6894 if Length(P) < 2 then
6895 begin
6896 g_Console_Add('permban_ip <IP address>');
6897 Exit;
6898 end;
6899 if P[1] = '' then
6900 begin
6901 g_Console_Add('permban_ip <IP address>');
6902 Exit;
6903 end;
6905 g_Net_BanAddress(P[1]);
6906 g_Net_SaveBanList();
6907 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6908 end else
6909 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6911 else if cmd = 'unban' then
6912 begin
6913 if g_Game_IsServer and g_Game_IsNet then
6914 begin
6915 if Length(P) < 2 then
6916 begin
6917 g_Console_Add('unban <IP Address>');
6918 Exit;
6919 end;
6920 if P[1] = '' then
6921 begin
6922 g_Console_Add('unban <IP Address>');
6923 Exit;
6924 end;
6926 if g_Net_UnbanAddress(P[1]) then
6927 begin
6928 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6929 g_Net_SaveBanList();
6930 end else
6931 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6932 end else
6933 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6935 else if cmd = 'clientlist' then
6936 begin
6937 if g_Game_IsServer and g_Game_IsNet then
6938 begin
6939 b := 0;
6940 if NetClients <> nil then
6941 for a := Low(NetClients) to High(NetClients) do
6942 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6943 begin
6944 plr := g_Player_Get(NetClients[a].Player);
6945 if plr = nil then continue;
6946 Inc(b);
6947 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6948 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6949 end;
6950 if b = 0 then
6951 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6952 end else
6953 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6955 else if cmd = 'connect' then
6956 begin
6957 if (NetMode = NET_NONE) then
6958 begin
6959 if Length(P) < 2 then
6960 begin
6961 g_Console_Add('connect <IP> [port] [password]');
6962 Exit;
6963 end;
6964 if P[1] = '' then
6965 begin
6966 g_Console_Add('connect <IP> [port] [password]');
6967 Exit;
6968 end;
6970 if Length(P) > 2 then
6971 prt := StrToIntDef(P[2], 25666)
6972 else
6973 prt := 25666;
6975 if Length(P) > 3 then
6976 pw := P[3]
6977 else
6978 pw := '';
6980 g_Game_StartClient(P[1], prt, pw);
6981 end;
6983 else if cmd = 'disconnect' then
6984 begin
6985 if (NetMode = NET_CLIENT) then
6986 g_Net_Disconnect();
6988 else if cmd = 'reconnect' then
6989 begin
6990 if (NetMode = NET_SERVER) then
6991 Exit;
6993 if (NetMode = NET_CLIENT) then
6994 begin
6995 g_Net_Disconnect();
6996 gExit := EXIT_SIMPLE;
6997 EndGame;
6998 end;
7000 //TODO: Use last successful password to reconnect, instead of ''
7001 g_Game_StartClient(NetClientIP, NetClientPort, '');
7003 else if (cmd = 'addbot') or
7004 (cmd = 'bot_add') then
7005 begin
7006 case Length(P) of
7007 1: g_Bot_Add(TEAM_NONE, 2);
7008 2: g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2));
7009 else
7010 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100));
7011 end;
7013 else if cmd = 'bot_addlist' then
7014 begin
7015 case Length(P) of
7016 1: g_Bot_AddList(TEAM_NONE, '');
7017 2: g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1));
7018 else
7019 if P[2] = 'red' then
7020 t := TEAM_RED
7021 else if P[2] = 'blue' then
7022 t := TEAM_BLUE
7023 else
7024 t := TEAM_NONE;
7026 if Length(P) = 3
7027 then g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1))
7028 else g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[3], 100));
7029 end;
7031 else if cmd = 'bot_removeall' then
7032 g_Bot_RemoveAll()
7033 else if cmd = 'chat' then
7034 begin
7035 if g_Game_IsNet then
7036 begin
7037 if Length(P) > 1 then
7038 begin
7039 for a := 1 to High(P) do
7040 chstr := chstr + P[a] + ' ';
7042 if Length(chstr) > 200 then SetLength(chstr, 200);
7044 if Length(chstr) < 1 then
7045 begin
7046 g_Console_Add('chat <text>');
7047 Exit;
7048 end;
7050 chstr := b_Text_Format(chstr);
7051 if g_Game_IsClient then
7052 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
7053 else
7054 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
7056 else
7057 g_Console_Add('chat <text>');
7058 end else
7059 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7061 else if cmd = 'teamchat' then
7062 begin
7063 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
7064 begin
7065 if Length(P) > 1 then
7066 begin
7067 for a := 1 to High(P) do
7068 chstr := chstr + P[a] + ' ';
7070 if Length(chstr) > 200 then SetLength(chstr, 200);
7072 if Length(chstr) < 1 then
7073 begin
7074 g_Console_Add('teamchat <text>');
7075 Exit;
7076 end;
7078 chstr := b_Text_Format(chstr);
7079 if g_Game_IsClient then
7080 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
7081 else
7082 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
7083 gPlayer1Settings.Team);
7085 else
7086 g_Console_Add('teamchat <text>');
7087 end else
7088 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7090 else if (cmd = 'an') or (cmd = 'announce') then
7091 begin
7092 if g_Game_IsNet then
7093 begin
7094 if Length(P) > 1 then
7095 begin
7096 for a := 1 to High(P) do
7097 chstr := chstr + P[a] + ' ';
7099 if Length(chstr) > 200 then SetLength(chstr, 200);
7101 if Length(chstr) < 1 then
7102 begin
7103 g_Console_Add('announce <text>');
7104 Exit;
7105 end;
7107 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
7108 if g_Game_IsClient then
7109 MC_SEND_RCONCommand(chstr)
7110 else
7111 g_Console_Process(chstr, True);
7113 else
7114 g_Console_Add('announce <text>');
7115 end else
7116 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7118 else if cmd = 'game' then
7119 begin
7120 if gGameSettings.GameType <> GT_NONE then
7121 begin
7122 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7123 Exit;
7124 end;
7125 if Length(P) = 1 then
7126 begin
7127 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
7128 Exit;
7129 end;
7130 // game not started yet, load first map from some wad
7131 found := false;
7132 s := addWadExtension(P[1]);
7133 found := e_FindResource(AllMapDirs, s);
7134 P[1] := s;
7135 if found then
7136 begin
7137 P[1] := ExpandFileName(P[1]);
7138 // if map not choosed then set first map
7139 if Length(P) < 3 then
7140 begin
7141 SetLength(P, 3);
7142 P[2] := g_Game_GetFirstMap(P[1]);
7143 end;
7145 s := P[1] + ':\' + UpperCase(P[2]);
7147 if g_Map_Exist(s) then
7148 begin
7149 // start game
7150 g_Game_Free();
7151 with gGameSettings do
7152 begin
7153 Options := gsGameFlags;
7154 GameMode := g_Game_TextToMode(gsGameMode);
7155 if gSwitchGameMode <> GM_NONE then
7156 GameMode := gSwitchGameMode;
7157 if GameMode = GM_NONE then GameMode := GM_DM;
7158 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7159 b := 1;
7160 if Length(P) >= 4 then
7161 b := StrToIntDef(P[3], 1);
7162 g_Game_StartCustom(s, GameMode, TimeLimit,
7163 ScoreLimit, MaxLives, Options, b);
7164 end;
7166 else
7167 if P[2] = '' then
7168 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7169 else
7170 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
7171 end else
7172 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
7174 else if cmd = 'host' then
7175 begin
7176 if gGameSettings.GameType <> GT_NONE then
7177 begin
7178 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7179 Exit;
7180 end;
7181 if Length(P) < 4 then
7182 begin
7183 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
7184 Exit;
7185 end;
7186 if not StrToIp(P[1], listen) then
7187 Exit;
7188 prt := StrToIntDef(P[2], 25666);
7190 s := addWadExtension(P[3]);
7191 found := e_FindResource(AllMapDirs, s);
7192 P[3] := s;
7193 if found then
7194 begin
7195 // get first map in wad, if not specified
7196 if Length(P) < 5 then
7197 begin
7198 SetLength(P, 5);
7199 P[4] := g_Game_GetFirstMap(P[1]);
7200 end;
7201 s := P[3] + ':\' + UpperCase(P[4]);
7202 if g_Map_Exist(s) then
7203 begin
7204 // start game
7205 g_Game_Free();
7206 with gGameSettings do
7207 begin
7208 Options := gsGameFlags;
7209 GameMode := g_Game_TextToMode(gsGameMode);
7210 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
7211 if GameMode = GM_NONE then GameMode := GM_DM;
7212 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7213 b := 0;
7214 if Length(P) >= 6 then
7215 b := StrToIntDef(P[5], 0);
7216 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
7219 else
7220 begin
7221 if P[4] = '' then
7222 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
7223 else
7224 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
7227 else
7228 begin
7229 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
7232 else if cmd = 'map' then
7233 begin
7234 if Length(P) = 1 then
7235 begin
7236 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7237 begin
7238 g_Console_Add(cmd + ' <MAP>');
7239 g_Console_Add(cmd + ' <WAD> [MAP]')
7241 else
7242 begin
7243 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7246 else if not e_IsValidResourceName(P[1]) then
7247 begin
7248 g_Console_Add('wad name must not be absolute or relative');
7250 else
7251 begin
7252 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7253 begin
7254 if Length(P) < 3 then
7255 begin
7256 // first param is map or wad
7257 s := UpperCase(P[1]);
7258 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7259 begin
7260 gExitByTrigger := False;
7261 if gGameOn then
7262 begin
7263 // already in game, finish current map
7264 gNextMap := s;
7265 gExit := EXIT_ENDLEVELCUSTOM;
7267 else
7268 begin
7269 // intermission, so change map immediately
7270 g_Game_ChangeMap(s)
7273 else
7274 begin
7275 s := P[1];
7276 found := e_FindResource(AllMapDirs, s);
7277 P[1] := s;
7278 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
7279 if found then
7280 begin
7281 // no such map, found wad
7282 pw := P[1];
7283 SetLength(P, 3);
7284 P[1] := ExpandFileName(pw);
7285 P[2] := g_Game_GetFirstMap(P[1]);
7286 s := P[1] + ':\' + P[2];
7287 if g_Map_Exist(s) then
7288 begin
7289 gExitByTrigger := False;
7290 if gGameOn then
7291 begin
7292 // already in game, finish current map
7293 gNextMap := s;
7294 gExit := EXIT_ENDLEVELCUSTOM
7296 else
7297 begin
7298 // intermission, so change map immediately
7299 g_Game_ChangeMap(s)
7302 else
7303 begin
7304 if P[2] = '' then
7305 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7306 else
7307 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7310 else
7311 begin
7312 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7314 end;
7316 else
7317 begin
7318 s := addWadExtension(P[1]);
7319 found := e_FindResource(AllMapDirs, s);
7320 P[1] := s;
7321 if found then
7322 begin
7323 P[2] := UpperCase(P[2]);
7324 s := P[1] + ':\' + P[2];
7325 if g_Map_Exist(s) then
7326 begin
7327 gExitByTrigger := False;
7328 if gGameOn then
7329 begin
7330 gNextMap := s;
7331 gExit := EXIT_ENDLEVELCUSTOM
7333 else
7334 begin
7335 g_Game_ChangeMap(s)
7338 else
7339 begin
7340 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7343 else
7344 begin
7345 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7349 else
7350 begin
7351 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7355 else if cmd = 'nextmap' then
7356 begin
7357 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
7358 begin
7359 g_Console_Add(_lc[I_MSG_NOT_GAME])
7361 else
7362 begin
7363 nm := True;
7364 if Length(P) = 1 then
7365 begin
7366 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7367 begin
7368 g_Console_Add(cmd + ' <MAP>');
7369 g_Console_Add(cmd + ' <WAD> [MAP]');
7371 else
7372 begin
7373 nm := False;
7374 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7375 end;
7377 else if not e_IsValidResourceName(P[1]) then
7378 begin
7379 g_Console_Add('wad name must not be absolute or relative');
7381 else
7382 begin
7383 nm := False;
7384 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7385 begin
7386 if Length(P) < 3 then
7387 begin
7388 // first param is map or wad
7389 s := UpperCase(P[1]);
7390 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7391 begin
7392 // map founded
7393 gExitByTrigger := False;
7394 gNextMap := s;
7395 nm := True;
7397 else
7398 begin
7399 // no such map, found wad
7400 pw := addWadExtension(P[1]);
7401 found := e_FindResource(MapDirs, pw);
7402 if not found then
7403 found := e_FindResource(WadDirs, pw);
7404 P[1] := pw;
7405 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7406 if found then
7407 begin
7408 // map not specified, select first map
7409 SetLength(P, 3);
7410 P[2] := g_Game_GetFirstMap(P[1]);
7411 s := P[1] + ':\' + P[2];
7412 if g_Map_Exist(s) then
7413 begin
7414 gExitByTrigger := False;
7415 gNextMap := s;
7416 nm := True
7418 else
7419 begin
7420 if P[2] = '' then
7421 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7422 else
7423 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7426 else
7427 begin
7428 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7432 else
7433 begin
7434 // specified two params wad + map
7435 pw := addWadExtension(P[1]);
7436 found := e_FindResource(MapDirs, pw);
7437 if not found then
7438 found := e_FindResource(MapDirs, pw);
7439 P[1] := pw;
7440 if found then
7441 begin
7442 P[2] := UpperCase(P[2]);
7443 s := P[1] + ':\' + P[2];
7444 if g_Map_Exist(s) then
7445 begin
7446 gExitByTrigger := False;
7447 gNextMap := s;
7448 nm := True
7450 else
7451 begin
7452 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7455 else
7456 begin
7457 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7461 else
7462 begin
7463 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7465 end;
7466 if nm then
7467 begin
7468 if gNextMap = '' then
7469 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7470 else
7471 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7475 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7476 begin
7477 if not gGameOn then
7478 begin
7479 g_Console_Add(_lc[I_MSG_NOT_GAME])
7481 else
7482 begin
7483 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7484 begin
7485 gExitByTrigger := False;
7486 // next map not specified, try to find trigger EXIT
7487 if (gNextMap = '') and (gTriggers <> nil) then
7488 begin
7489 for a := 0 to High(gTriggers) do
7490 begin
7491 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7492 begin
7493 gExitByTrigger := True;
7494 //gNextMap := gTriggers[a].Data.MapName;
7495 gNextMap := gTriggers[a].tgcMap;
7496 Break
7499 end;
7500 if gNextMap = '' then
7501 gNextMap := g_Game_GetNextMap();
7502 if not isWadPath(gNextMap) then
7503 s := gGameSettings.WAD + ':\' + gNextMap
7504 else
7505 s := gNextMap;
7506 if g_Map_Exist(s) then
7507 gExit := EXIT_ENDLEVELCUSTOM
7508 else
7509 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7511 else
7512 begin
7513 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7517 else if (cmd = 'event') then
7518 begin
7519 if (Length(P) <= 1) then
7520 begin
7521 for a := 0 to High(gEvents) do
7522 if gEvents[a].Command = '' then
7523 g_Console_Add(gEvents[a].Name + ' <none>')
7524 else
7525 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7526 Exit;
7527 end;
7528 if (Length(P) = 2) then
7529 begin
7530 for a := 0 to High(gEvents) do
7531 if gEvents[a].Name = P[1] then
7532 if gEvents[a].Command = '' then
7533 g_Console_Add(gEvents[a].Name + ' <none>')
7534 else
7535 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7536 Exit;
7537 end;
7538 for a := 0 to High(gEvents) do
7539 if gEvents[a].Name = P[1] then
7540 begin
7541 gEvents[a].Command := '';
7542 for b := 2 to High(P) do
7543 if Pos(' ', P[b]) = 0 then
7544 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7545 else
7546 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7547 gEvents[a].Command := Trim(gEvents[a].Command);
7548 Exit;
7549 end;
7551 else if cmd = 'suicide' then
7552 begin
7553 if gGameOn then
7554 begin
7555 if g_Game_IsClient then
7556 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7557 else
7558 begin
7559 if gPlayer1 <> nil then
7560 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7561 if gPlayer2 <> nil then
7562 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7563 end;
7564 end;
7566 else if cmd = 'screenshot' then
7567 begin
7568 g_TakeScreenShot()
7570 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7571 begin
7572 a := 1 - (ord(cmd[5]) - ord('n'));
7573 if a = -1 then
7574 gWeaponAction[0, WP_PREV] := True;
7575 if a = 1 then
7576 gWeaponAction[0, WP_NEXT] := True;
7578 else if cmd = 'weapon' then
7579 begin
7580 if Length(p) = 2 then
7581 begin
7582 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7583 if (a >= WP_FIRST) and (a <= WP_LAST) then
7584 gSelectWeapon[0, a] := True
7587 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7588 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7589 begin
7590 a := 1 - (ord(cmd[8]) - ord('n'));
7591 b := ord(cmd[2]) - ord('1');
7592 if a = -1 then
7593 gWeaponAction[b, WP_PREV] := True;
7594 if a = 1 then
7595 gWeaponAction[b, WP_NEXT] := True;
7597 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7598 begin
7599 if Length(p) = 2 then
7600 begin
7601 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7602 b := ord(cmd[2]) - ord('1');
7603 if (a >= WP_FIRST) and (a <= WP_LAST) then
7604 gSelectWeapon[b, a] := True
7607 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
7608 begin
7609 b := ord(cmd[2]) - ord('1');
7610 if b = 0 then
7611 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
7612 else
7613 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
7615 else if (cmd = 'dropflag') then
7616 begin
7617 if g_Game_IsServer then
7618 begin
7619 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
7620 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
7622 else
7623 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7625 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
7626 begin
7627 b := ord(cmd[2]) - ord('1');
7628 if g_Game_IsServer then
7629 begin
7630 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
7631 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
7633 else
7634 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7636 // Êîìàíäû Ñâîåé èãðû:
7637 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7638 begin
7639 if cmd = 'bot_addred' then
7640 begin
7641 if Length(P) > 1 then
7642 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7643 else
7644 g_Bot_Add(TEAM_RED, 2);
7646 else if cmd = 'bot_addblue' then
7647 begin
7648 if Length(P) > 1 then
7649 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7650 else
7651 g_Bot_Add(TEAM_BLUE, 2);
7653 else if cmd = 'spectate' then
7654 begin
7655 if not gGameOn then
7656 Exit;
7657 g_Game_Spectate();
7659 else if cmd = 'say' then
7660 begin
7661 if g_Game_IsServer and g_Game_IsNet then
7662 begin
7663 if Length(P) > 1 then
7664 begin
7665 chstr := '';
7666 for a := 1 to High(P) do
7667 chstr := chstr + P[a] + ' ';
7669 if Length(chstr) > 200 then SetLength(chstr, 200);
7671 if Length(chstr) < 1 then
7672 begin
7673 g_Console_Add('say <text>');
7674 Exit;
7675 end;
7677 chstr := b_Text_Format(chstr);
7678 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7680 else g_Console_Add('say <text>');
7681 end else
7682 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7684 else if cmd = 'tell' then
7685 begin
7686 if g_Game_IsServer and g_Game_IsNet then
7687 begin
7688 if (Length(P) > 2) and (P[1] <> '') then
7689 begin
7690 chstr := '';
7691 for a := 2 to High(P) do
7692 chstr := chstr + P[a] + ' ';
7694 if Length(chstr) > 200 then SetLength(chstr, 200);
7696 if Length(chstr) < 1 then
7697 begin
7698 g_Console_Add('tell <playername> <text>');
7699 Exit;
7700 end;
7702 pl := g_Net_Client_ByName(P[1]);
7703 if pl <> nil then
7704 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7705 else
7706 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7708 else g_Console_Add('tell <playername> <text>');
7709 end else
7710 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7712 else if cmd = 'centerprint' then
7713 begin
7714 if (Length(P) > 2) and (P[1] <> '') then
7715 begin
7716 chstr := '';
7717 for a := 2 to High(P) do
7718 chstr := chstr + P[a] + ' ';
7720 if Length(chstr) > 200 then SetLength(chstr, 200);
7722 if Length(chstr) < 1 then
7723 begin
7724 g_Console_Add('centerprint <timeout> <text>');
7725 Exit;
7726 end;
7728 a := StrToIntDef(P[1], 100);
7729 chstr := b_Text_Format(chstr);
7730 g_Game_Message(chstr, a);
7731 if g_Game_IsNet and g_Game_IsServer then
7732 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7734 else g_Console_Add('centerprint <timeout> <text>');
7736 else if (cmd = 'overtime') and not g_Game_IsClient then
7737 begin
7738 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7739 Exit;
7740 // Äîïîëíèòåëüíîå âðåìÿ:
7741 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7743 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7744 [gGameSettings.TimeLimit div 3600,
7745 (gGameSettings.TimeLimit div 60) mod 60,
7746 gGameSettings.TimeLimit mod 60]));
7747 if g_Game_IsNet then MH_SEND_GameSettings;
7749 else if (cmd = 'rcon_password') and g_Game_IsClient then
7750 begin
7751 if (Length(P) <= 1) then
7752 g_Console_Add('rcon_password <password>')
7753 else
7754 MC_SEND_RCONPassword(P[1]);
7756 else if cmd = 'rcon' then
7757 begin
7758 if g_Game_IsClient then
7759 begin
7760 if Length(P) > 1 then
7761 begin
7762 chstr := '';
7763 for a := 1 to High(P) do
7764 chstr := chstr + P[a] + ' ';
7766 if Length(chstr) > 200 then SetLength(chstr, 200);
7768 if Length(chstr) < 1 then
7769 begin
7770 g_Console_Add('rcon <command>');
7771 Exit;
7772 end;
7774 MC_SEND_RCONCommand(chstr);
7776 else g_Console_Add('rcon <command>');
7777 end;
7779 else if cmd = 'ready' then
7780 begin
7781 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7782 gLMSRespawnTime := gTime + 100;
7784 else if (cmd = 'callvote') and g_Game_IsNet then
7785 begin
7786 if Length(P) > 1 then
7787 begin
7788 chstr := '';
7789 for a := 1 to High(P) do begin
7790 if a > 1 then chstr := chstr + ' ';
7791 chstr := chstr + P[a];
7792 end;
7794 if Length(chstr) > 200 then SetLength(chstr, 200);
7796 if Length(chstr) < 1 then
7797 begin
7798 g_Console_Add('callvote <command>');
7799 Exit;
7800 end;
7802 if g_Game_IsClient then
7803 MC_SEND_Vote(True, chstr)
7804 else
7805 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7806 g_Console_Process('vote', True);
7808 else
7809 g_Console_Add('callvote <command>');
7811 else if (cmd = 'vote') and g_Game_IsNet then
7812 begin
7813 if g_Game_IsClient then
7814 MC_SEND_Vote(False)
7815 else if gVoteInProgress then
7816 begin
7817 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7818 a := Floor((NetClientCount+1)/2.0) + 1
7819 else
7820 a := Floor(NetClientCount/2.0) + 1;
7821 if gVoted then
7822 begin
7823 Dec(gVoteCount);
7824 gVoted := False;
7825 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7826 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7828 else
7829 begin
7830 Inc(gVoteCount);
7831 gVoted := True;
7832 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7833 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7834 g_Game_CheckVote;
7835 end;
7836 end;
7838 end;
7839 end;
7841 procedure SystemCommands(P: SSArray);
7843 cmd: string;
7844 begin
7845 cmd := LowerCase(P[0]);
7846 case cmd of
7847 'exit', 'quit':
7848 begin
7849 g_Game_Free();
7850 gExit := EXIT_QUIT;
7851 end;
7852 'r_reset':
7853 begin
7854 gRC_Width := Max(1, gRC_Width);
7855 gRC_Height := Max(1, gRC_Height);
7856 gBPP := Max(1, gBPP);
7857 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7858 e_LogWriteln('resolution changed')
7859 else
7860 e_LogWriteln('resolution not changed');
7861 sys_EnableVSync(gVSync);
7862 end;
7863 'r_maxfps':
7864 begin
7865 if Length(p) = 2 then
7866 begin
7867 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7868 if gMaxFPS > 0 then
7869 gFrameTime := 1000 div gMaxFPS
7870 else
7871 gFrameTime := 0;
7872 end;
7873 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7874 end;
7875 'g_language':
7876 begin
7877 if Length(p) = 2 then
7878 begin
7879 gAskLanguage := true;
7880 gLanguage := LANGUAGE_ENGLISH;
7881 case LowerCase(p[1]) of
7882 'english':
7883 begin
7884 gAskLanguage := false;
7885 gLanguage := LANGUAGE_ENGLISH;
7886 end;
7887 'russian':
7888 begin
7889 gAskLanguage := false;
7890 gLanguage := LANGUAGE_RUSSIAN;
7891 end;
7892 'ask':
7893 begin
7894 gAskLanguage := true;
7895 gLanguage := LANGUAGE_ENGLISH;
7896 end;
7897 end;
7898 g_Language_Set(gLanguage);
7900 else
7901 begin
7902 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7904 end;
7905 end;
7906 end;
7908 procedure g_TakeScreenShot(Filename: string = '');
7909 var s: TStream; t: TDateTime; dir, date, name: String;
7910 begin
7911 if e_NoGraphics then Exit;
7913 dir := e_GetWriteableDir(ScreenshotDirs);
7915 if Filename = '' then
7916 begin
7917 t := Now;
7918 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7919 Filename := 'screenshot-' + date;
7920 end;
7922 name := e_CatPath(dir, Filename + '.png');
7923 s := createDiskFile(name);
7925 e_MakeScreenshot(s, gWinSizeX, gWinSizeY);
7926 s.Free;
7927 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7928 except
7929 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7930 s.Free;
7931 DeleteFile(name)
7933 except
7934 g_Console_Add('oh shit, i can''t create screenshot!')
7936 end;
7938 procedure g_Game_InGameMenu(Show: Boolean);
7939 begin
7940 if (g_ActiveWindow = nil) and Show then
7941 begin
7942 if gGameSettings.GameType = GT_SINGLE then
7943 g_GUI_ShowWindow('GameSingleMenu')
7944 else
7945 begin
7946 if g_Game_IsClient then
7947 g_GUI_ShowWindow('GameClientMenu')
7948 else
7949 if g_Game_IsNet then
7950 g_GUI_ShowWindow('GameServerMenu')
7951 else
7952 g_GUI_ShowWindow('GameCustomMenu');
7953 end;
7954 g_Sound_PlayEx('MENU_OPEN');
7956 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7957 if (not g_Game_IsNet) then
7958 g_Game_Pause(True);
7960 else
7961 if (g_ActiveWindow <> nil) and (not Show) then
7962 begin
7963 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7964 if (not g_Game_IsNet) then
7965 g_Game_Pause(False);
7966 end;
7967 end;
7969 procedure g_Game_Pause (Enable: Boolean);
7971 oldPause: Boolean;
7972 begin
7973 if not gGameOn then exit;
7975 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7977 oldPause := gPause;
7978 gPauseMain := Enable;
7980 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7981 end;
7983 procedure g_Game_HolmesPause (Enable: Boolean);
7985 oldPause: Boolean;
7986 begin
7987 if not gGameOn then exit;
7988 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7990 oldPause := gPause;
7991 gPauseHolmes := Enable;
7993 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7994 end;
7996 procedure g_Game_PauseAllSounds(Enable: Boolean);
7998 i: Integer;
7999 begin
8000 // Òðèããåðû:
8001 if gTriggers <> nil then
8002 for i := 0 to High(gTriggers) do
8003 with gTriggers[i] do
8004 if (TriggerType = TRIGGER_SOUND) and
8005 (Sound <> nil) and
8006 Sound.IsPlaying() then
8007 begin
8008 Sound.Pause(Enable);
8009 end;
8011 // Çâóêè èãðîêîâ:
8012 if gPlayers <> nil then
8013 for i := 0 to High(gPlayers) do
8014 if gPlayers[i] <> nil then
8015 gPlayers[i].PauseSounds(Enable);
8017 // Ìóçûêà:
8018 if gMusic <> nil then
8019 gMusic.Pause(Enable);
8020 end;
8022 procedure g_Game_StopAllSounds(all: Boolean);
8024 i: Integer;
8025 begin
8026 if gTriggers <> nil then
8027 for i := 0 to High(gTriggers) do
8028 with gTriggers[i] do
8029 if (TriggerType = TRIGGER_SOUND) and
8030 (Sound <> nil) then
8031 Sound.Stop();
8033 if gMusic <> nil then
8034 gMusic.Stop();
8036 if all then
8037 e_StopChannels();
8038 end;
8040 procedure g_Game_UpdateTriggerSounds;
8041 var i: Integer;
8042 begin
8043 if gTriggers <> nil then
8044 for i := 0 to High(gTriggers) do
8045 with gTriggers[i] do
8046 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
8047 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
8048 end;
8050 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
8051 begin
8052 Result := False;
8053 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
8054 begin
8055 Result := True;
8056 Exit;
8057 end;
8058 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
8059 begin
8060 Result := True;
8061 Exit;
8062 end;
8063 if gSpectMode <> SPECT_PLAYERS then
8064 Exit;
8065 if gSpectPID1 = UID then
8066 begin
8067 Result := True;
8068 Exit;
8069 end;
8070 if gSpectViewTwo and (gSpectPID2 = UID) then
8071 begin
8072 Result := True;
8073 Exit;
8074 end;
8075 end;
8077 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
8079 Pl: TPlayer;
8080 begin
8081 Result := False;
8082 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
8083 begin
8084 Result := True;
8085 Exit;
8086 end;
8087 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
8088 begin
8089 Result := True;
8090 Exit;
8091 end;
8092 if gSpectMode <> SPECT_PLAYERS then
8093 Exit;
8094 Pl := g_Player_Get(gSpectPID1);
8095 if (Pl <> nil) and (Pl.Team = Team) then
8096 begin
8097 Result := True;
8098 Exit;
8099 end;
8100 if gSpectViewTwo then
8101 begin
8102 Pl := g_Player_Get(gSpectPID2);
8103 if (Pl <> nil) and (Pl.Team = Team) then
8104 begin
8105 Result := True;
8106 Exit;
8107 end;
8108 end;
8109 end;
8111 procedure g_Game_Message(Msg: string; Time: Word);
8112 begin
8113 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
8114 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
8115 MessageTime := Time;
8116 end;
8118 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
8119 const
8120 punct: Array[0..13] of String =
8121 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8123 i, j: Integer;
8124 ok: Boolean;
8125 fpText: String;
8127 function IsPunctuation(S: String): Boolean;
8129 i: Integer;
8130 begin
8131 Result := False;
8132 if Length(S) <> 1 then
8133 Exit;
8134 for i := Low(punct) to High(punct) do
8135 if S = punct[i] then
8136 begin
8137 Result := True;
8138 break;
8139 end;
8140 end;
8141 function FilterPunctuation(S: String): String;
8143 i: Integer;
8144 begin
8145 for i := Low(punct) to High(punct) do
8146 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
8147 Result := S;
8148 end;
8149 begin
8150 ok := False;
8152 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
8153 begin
8154 // remove player name
8155 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8156 // for FullWord check
8157 Text := toLowerCase1251(' ' + Text + ' ');
8158 fpText := FilterPunctuation(Text);
8160 for i := 0 to Length(gChatSounds) - 1 do
8161 begin
8162 ok := True;
8163 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
8164 begin
8165 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
8166 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
8167 else
8168 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
8169 if not ok then
8170 break;
8171 end;
8172 if ok then
8173 begin
8174 gChatSounds[i].Sound.Play();
8175 break;
8176 end;
8177 end;
8178 end;
8179 if not ok then
8180 g_Sound_PlayEx('SOUND_GAME_RADIO');
8181 end;
8183 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
8185 a: Integer;
8186 begin
8187 case gAnnouncer of
8188 ANNOUNCE_NONE:
8189 Exit;
8190 ANNOUNCE_ME,
8191 ANNOUNCE_MEPLUS:
8192 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8193 Exit;
8194 end;
8195 for a := 0 to 3 do
8196 if goodsnd[a].IsPlaying() then
8197 Exit;
8199 goodsnd[Random(4)].Play();
8200 end;
8202 procedure g_Game_Announce_KillCombo(Param: Integer);
8204 UID: Word;
8205 c, n: Byte;
8206 Pl: TPlayer;
8207 Name: String;
8208 begin
8209 UID := Param and $FFFF;
8210 c := Param shr 16;
8211 if c < 2 then
8212 Exit;
8214 Pl := g_Player_Get(UID);
8215 if Pl = nil then
8216 Name := '?'
8217 else
8218 Name := Pl.Name;
8220 case c of
8221 2: begin
8222 n := 0;
8223 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
8224 end;
8225 3: begin
8226 n := 1;
8227 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
8228 end;
8229 4: begin
8230 n := 2;
8231 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
8232 end;
8233 else begin
8234 n := 3;
8235 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
8236 end;
8237 end;
8239 case gAnnouncer of
8240 ANNOUNCE_NONE:
8241 Exit;
8242 ANNOUNCE_ME:
8243 if not g_Game_IsWatchedPlayer(UID) then
8244 Exit;
8245 ANNOUNCE_MEPLUS:
8246 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
8247 Exit;
8248 end;
8250 if killsnd[n].IsPlaying() then
8251 killsnd[n].Stop();
8252 killsnd[n].Play();
8253 end;
8255 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
8257 a: Integer;
8258 begin
8259 case gAnnouncer of
8260 ANNOUNCE_NONE:
8261 Exit;
8262 ANNOUNCE_ME:
8263 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8264 Exit;
8265 end;
8266 for a := 0 to 2 do
8267 if hahasnd[a].IsPlaying() then
8268 Exit;
8270 hahasnd[Random(3)].Play();
8271 end;
8273 procedure g_Game_Effect_Bubbles (fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean);
8274 begin
8275 g_GFX_Bubbles(fX, fY, count, devX, devY);
8276 if not Silent then if Random(2) = 0
8277 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX, fY)
8278 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX, fY);
8279 end;
8281 procedure g_Game_StartVote(Command, Initiator: string);
8283 Need: Integer;
8284 begin
8285 if not gVotesEnabled then Exit;
8286 if gGameSettings.GameType <> GT_SERVER then Exit;
8287 if gVoteInProgress or gVotePassed then
8288 begin
8289 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
8290 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
8291 Exit;
8292 end;
8293 gVoteInProgress := True;
8294 gVotePassed := False;
8295 gVoteTimer := gTime + gVoteTimeout * 1000;
8296 gVoteCount := 0;
8297 gVoted := False;
8298 gVoteCommand := Command;
8300 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8301 Need := Floor((NetClientCount+1)/2.0)+1
8302 else
8303 Need := Floor(NetClientCount/2.0)+1;
8304 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
8305 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
8306 end;
8308 procedure g_Game_CheckVote;
8310 I, Need: Integer;
8311 begin
8312 if gGameSettings.GameType <> GT_SERVER then Exit;
8313 if not gVoteInProgress then Exit;
8315 if (gTime >= gVoteTimer) then
8316 begin
8317 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8318 Need := Floor((NetClientCount+1)/2.0) + 1
8319 else
8320 Need := Floor(NetClientCount/2.0) + 1;
8321 if gVoteCount >= Need then
8322 begin
8323 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8324 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8325 gVotePassed := True;
8326 gVoteCmdTimer := gTime + 5000;
8328 else
8329 begin
8330 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
8331 MH_SEND_VoteEvent(NET_VE_FAILED);
8332 end;
8333 if NetClients <> nil then
8334 for I := Low(NetClients) to High(NetClients) do
8335 if NetClients[i].Used then
8336 NetClients[i].Voted := False;
8337 gVoteInProgress := False;
8338 gVoted := False;
8339 gVoteCount := 0;
8341 else
8342 begin
8343 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8344 Need := Floor((NetClientCount+1)/2.0) + 1
8345 else
8346 Need := Floor(NetClientCount/2.0) + 1;
8347 if gVoteCount >= Need then
8348 begin
8349 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8350 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8351 gVoteInProgress := False;
8352 gVotePassed := True;
8353 gVoteCmdTimer := gTime + 5000;
8354 gVoted := False;
8355 gVoteCount := 0;
8356 if NetClients <> nil then
8357 for I := Low(NetClients) to High(NetClients) do
8358 if NetClients[i].Used then
8359 NetClients[i].Voted := False;
8360 end;
8361 end;
8362 end;
8364 procedure g_Game_LoadMapList(FileName: string);
8366 ListFile: TextFile;
8367 s: string;
8368 begin
8369 MapList := nil;
8370 MapIndex := -1;
8372 if not FileExists(FileName) then Exit;
8374 AssignFile(ListFile, FileName);
8375 Reset(ListFile);
8376 while not EOF(ListFile) do
8377 begin
8378 ReadLn(ListFile, s);
8380 s := Trim(s);
8381 if s = '' then Continue;
8383 SetLength(MapList, Length(MapList)+1);
8384 MapList[High(MapList)] := s;
8385 end;
8386 CloseFile(ListFile);
8387 end;
8389 procedure g_Game_SetDebugMode();
8390 begin
8391 gDebugMode := True;
8392 // ×èòû (äàæå â ñâîåé èãðå):
8393 gCheats := True;
8394 end;
8396 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
8398 i: Word;
8399 begin
8400 if Length(LoadingStat.Msgs) = 0 then
8401 Exit;
8403 with LoadingStat do
8404 begin
8405 if not reWrite then
8406 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8407 if NextMsg = Length(Msgs) then
8408 begin // scroll
8409 for i := 0 to High(Msgs)-1 do
8410 Msgs[i] := Msgs[i+1];
8412 else
8413 Inc(NextMsg);
8414 end else
8415 if NextMsg = 0 then
8416 Inc(NextMsg);
8418 Msgs[NextMsg-1] := Text;
8419 CurValue := 0;
8420 MaxValue := Max;
8421 ShowCount := 0;
8422 PBarWasHere := false;
8423 end;
8425 g_ActiveWindow := nil;
8426 ProcessLoading(True);
8427 end;
8429 procedure g_Game_StepLoading(Value: Integer = -1);
8430 begin
8431 with LoadingStat do
8432 begin
8433 if Value = -1 then
8434 begin
8435 Inc(CurValue);
8436 Inc(ShowCount);
8438 else
8439 CurValue := Value;
8441 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8442 begin
8443 ShowCount := 0;
8444 ProcessLoading(False);
8445 end;
8446 end;
8447 end;
8449 procedure g_Game_ClearLoading();
8451 len: Word;
8452 begin
8453 with LoadingStat do
8454 begin
8455 CurValue := 0;
8456 MaxValue := 0;
8457 ShowCount := 0;
8458 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8459 if len < 1 then len := 1;
8460 SetLength(Msgs, len);
8461 for len := Low(Msgs) to High(Msgs) do
8462 Msgs[len] := '';
8463 NextMsg := 0;
8464 PBarWasHere := false;
8465 end;
8466 end;
8468 procedure Parse_Params(var pars: TParamStrValues);
8470 i: Integer;
8471 s: String;
8472 begin
8473 SetLength(pars, 0);
8474 i := 1;
8475 while i <= ParamCount do
8476 begin
8477 s := ParamStr(i);
8478 if (Length(s) > 1) and (s[1] = '-') then
8479 begin
8480 if (Length(s) > 2) and (s[2] = '-') then
8481 begin // Îäèíî÷íûé ïàðàìåòð
8482 SetLength(pars, Length(pars) + 1);
8483 with pars[High(pars)] do
8484 begin
8485 Name := LowerCase(s);
8486 Value := '+';
8487 end;
8489 else
8490 if (i < ParamCount) then
8491 begin // Ïàðàìåòð ñî çíà÷åíèåì
8492 Inc(i);
8493 SetLength(pars, Length(pars) + 1);
8494 with pars[High(pars)] do
8495 begin
8496 Name := LowerCase(s);
8497 Value := LowerCase(ParamStr(i));
8498 end;
8499 end;
8500 end;
8502 Inc(i);
8503 end;
8504 end;
8506 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8508 i: Integer;
8509 begin
8510 Result := '';
8511 for i := 0 to High(pars) do
8512 if pars[i].Name = aName then
8513 begin
8514 Result := pars[i].Value;
8515 Break;
8516 end;
8517 end;
8519 procedure g_Game_Process_Params();
8521 pars: TParamStrValues;
8522 map: String;
8523 GMode, n: Byte;
8524 LimT, LimS: Integer;
8525 Opt: TGameOptions;
8526 Lives: Integer;
8527 s: String;
8528 Port: Integer;
8529 ip: String;
8530 F: TextFile;
8531 begin
8532 Parse_Params(pars);
8534 // Debug mode:
8535 s := Find_Param_Value(pars, '--debug');
8536 if (s <> '') then
8537 begin
8538 g_Game_SetDebugMode();
8539 s := Find_Param_Value(pars, '--netdump');
8540 if (s <> '') then
8541 NetDump := True;
8542 end;
8544 // Connect when game loads
8545 ip := Find_Param_Value(pars, '-connect');
8547 if ip <> '' then
8548 begin
8549 s := Find_Param_Value(pars, '-port');
8550 if (s = '') or not TryStrToInt(s, Port) then
8551 Port := 25666;
8553 s := Find_Param_Value(pars, '-pw');
8555 g_Game_StartClient(ip, Port, s);
8556 Exit;
8557 end;
8559 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8560 if (s <> '') then
8561 begin
8562 gDefaultMegawadStart := s;
8563 end;
8565 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8566 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8567 begin
8568 gDefaultMegawadStart := DF_Default_Megawad_Start;
8569 end;
8571 // Start map when game loads:
8572 map := LowerCase(Find_Param_Value(pars, '-map'));
8573 if isWadPath(map) then
8574 begin
8575 // Game mode:
8576 s := Find_Param_Value(pars, '-gm');
8577 GMode := g_Game_TextToMode(s);
8578 if GMode = GM_NONE then GMode := GM_DM;
8579 if GMode = GM_SINGLE then GMode := GM_COOP;
8581 // Time limit:
8582 s := Find_Param_Value(pars, '-limt');
8583 if (s = '') or (not TryStrToInt(s, LimT)) then
8584 LimT := 0;
8585 if LimT < 0 then
8586 LimT := 0;
8588 // Score limit:
8589 s := Find_Param_Value(pars, '-lims');
8590 if (s = '') or (not TryStrToInt(s, LimS)) then
8591 LimS := 0;
8592 if LimS < 0 then
8593 LimS := 0;
8595 // Lives limit:
8596 s := Find_Param_Value(pars, '-lives');
8597 if (s = '') or (not TryStrToInt(s, Lives)) then
8598 Lives := 0;
8599 if Lives < 0 then
8600 Lives := 0;
8602 // Options:
8603 s := Find_Param_Value(pars, '-opt');
8604 if (s = '')
8605 then Opt := gsGameFlags
8606 else Opt := TGameOptions(StrToIntDef(s, 0));
8608 // Close after map:
8609 s := Find_Param_Value(pars, '--close');
8610 if (s <> '') then
8611 gMapOnce := True;
8613 // Override map to test:
8614 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8615 if s <> '' then
8616 begin
8617 if e_IsValidResourceName(s) then
8618 e_FindResource(AllMapDirs, s);
8619 gTestMap := ExpandFileName(s);
8620 end;
8622 // Delete test map after play:
8623 s := Find_Param_Value(pars, '--testdelete');
8624 if (s <> '') then
8625 begin
8626 //gMapToDelete := MapsDir + map;
8627 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8628 Halt(1);
8629 end;
8631 // Delete temporary WAD after play:
8632 s := Find_Param_Value(pars, '--tempdelete');
8633 if (s <> '') and (gTestMap <> '') then
8634 begin
8635 gMapToDelete := gTestMap;
8636 gTempDelete := True;
8637 end;
8639 // Number of players:
8640 s := Find_Param_Value(pars, '-pl');
8641 if (s = '') then
8642 n := DEFAULT_PLAYERS
8643 else
8644 n := StrToIntDef(s, DEFAULT_PLAYERS);
8646 // Start:
8647 s := Find_Param_Value(pars, '-port');
8648 if (s = '') or not TryStrToInt(s, Port)
8649 then g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8650 else g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8651 end;
8653 // Execute script when game loads:
8654 s := Find_Param_Value(pars, '-exec');
8655 if s <> '' then
8656 begin
8657 // if not isWadPath(s) then
8658 // s := GameDir + '/' + s;
8660 {$I-}
8661 AssignFile(F, s);
8662 Reset(F);
8663 if IOResult <> 0 then
8664 begin
8665 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8666 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8667 CloseFile(F);
8668 Exit;
8669 end;
8670 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8671 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8673 while not EOF(F) do
8674 begin
8675 ReadLn(F, s);
8676 if IOResult <> 0 then
8677 begin
8678 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8679 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8680 CloseFile(F);
8681 Exit;
8682 end;
8683 if Pos('#', s) <> 1 then // script comment
8684 g_Console_Process(s, True);
8685 end;
8687 CloseFile(F);
8688 {$I+}
8689 end;
8691 SetLength(pars, 0);
8692 end;
8694 begin
8695 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8696 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8697 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8698 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8700 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8701 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8702 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8703 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8705 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8706 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8708 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8709 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8711 {$IFDEF ENABLE_HOLMES}
8712 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8713 {$ENDIF}
8715 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8717 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8718 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8720 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8721 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8723 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8724 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8726 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8727 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8728 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8729 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
8730 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8731 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8732 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8733 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8734 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8735 end.