DEADSOFTWARE

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