DEADSOFTWARE

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