DEADSOFTWARE

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