DEADSOFTWARE

cleanup: remove g_main.pas
[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_base, g_basic, g_player, r_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 GoalLimit: 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 end;
67 TMegaWADInfo = record
68 Name: String;
69 Description: String;
70 Author: String;
71 Pic: String;
72 end;
74 THearPoint = record
75 Active: Boolean;
76 Coords: TDFPoint;
77 end;
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Quit();
89 procedure g_Game_SetupScreenSize();
90 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
91 function g_Game_ModeToText(Mode: Byte): string;
92 function g_Game_TextToMode(Mode: string): Byte;
93 procedure g_Game_ExecuteEvent(Name: String);
94 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
95 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
96 procedure g_Game_RemovePlayer();
97 procedure g_Game_Spectate();
98 procedure g_Game_SpectateCenterView();
99 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
100 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
101 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
102 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
103 procedure g_Game_Restart();
104 procedure g_Game_RestartLevel();
105 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
106 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
107 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath: String);
109 procedure g_Game_ExitLevel(const Map: AnsiString);
110 function g_Game_GetFirstMap(WAD: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable: Boolean);
114 procedure g_Game_HolmesPause(Enable: Boolean);
115 procedure g_Game_InGameMenu(Show: Boolean);
116 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
118 procedure g_Game_Message(Msg: String; Time: Word);
119 procedure g_Game_LoadMapList(FileName: String);
120 procedure g_Game_PauseAllSounds(Enable: Boolean);
121 procedure g_Game_StopAllSounds(all: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
124 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
126 procedure g_Game_Announce_KillCombo(Param: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
128 procedure g_Game_StartVote(Command, Initiator: string);
129 procedure g_Game_CheckVote;
130 procedure g_TakeScreenShot(Filename: string = '');
131 procedure g_FatalError(Text: String);
132 procedure g_SimpleError(Text: String);
133 function g_Game_IsTestMap(): Boolean;
134 procedure g_Game_DeleteTestMap();
135 procedure GameCVars(P: SSArray);
136 procedure PlayerSettingsCVars(P: SSArray);
137 procedure SystemCommands(P: SSArray);
138 procedure GameCommands(P: SSArray);
139 procedure GameCheats(P: SSArray);
140 procedure DebugCommands(P: SSArray);
141 procedure g_Game_Process_Params;
142 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
143 procedure g_Game_StepLoading(Value: Integer = -1);
144 procedure g_Game_ClearLoading();
145 procedure g_Game_SetDebugMode();
147 function IsActivePlayer(p: TPlayer): Boolean;
148 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
149 procedure SortGameStat(var stat: TPlayerStatArray);
151 procedure KeyPress (K: Word);
152 procedure CharPress (C: AnsiChar);
154 { procedure SetWinPause(Enable: Boolean); }
156 const
157 GAME_TICK = 28;
159 LOADING_SHOW_STEP = 100;
160 LOADING_INTERLINE = 20;
162 GT_NONE = 0;
163 GT_SINGLE = 1;
164 GT_CUSTOM = 2;
165 GT_SERVER = 3;
166 GT_CLIENT = 4;
168 GM_NONE = 0;
169 GM_DM = 1;
170 GM_TDM = 2;
171 GM_CTF = 3;
172 GM_COOP = 4;
173 GM_SINGLE = 5;
175 MESSAGE_DIKEY = WM_USER + 1;
177 EXIT_QUIT = 1;
178 EXIT_SIMPLE = 2;
179 EXIT_RESTART = 3;
180 EXIT_ENDLEVELSINGLE = 4;
181 EXIT_ENDLEVELCUSTOM = 5;
183 GAME_OPTION_RESERVED = 1;
184 GAME_OPTION_TEAMDAMAGE = 2;
185 GAME_OPTION_ALLOWEXIT = 4;
186 GAME_OPTION_WEAPONSTAY = 8;
187 GAME_OPTION_MONSTERS = 16;
188 GAME_OPTION_BOTVSPLAYER = 32;
189 GAME_OPTION_BOTVSMONSTER = 64;
190 GAME_OPTION_DMKEYS = 128;
191 GAME_OPTION_TEAMHITTRACE = 256;
192 GAME_OPTION_TEAMHITPROJECTILE = 512;
193 GAME_OPTION_TEAMABSORBDAMAGE = 1024;
195 STATE_NONE = 0;
196 STATE_MENU = 1;
197 STATE_FOLD = 2;
198 STATE_INTERCUSTOM = 3;
199 STATE_INTERSINGLE = 4;
200 STATE_INTERTEXT = 5;
201 STATE_INTERPIC = 6;
202 STATE_ENDPIC = 7;
203 STATE_SLIST = 8;
205 LMS_RESPAWN_NONE = 0;
206 LMS_RESPAWN_WARMUP = 1;
207 LMS_RESPAWN_FINAL = 2;
209 SPECT_NONE = 0;
210 SPECT_STATS = 1;
211 SPECT_MAPVIEW = 2;
212 SPECT_PLAYERS = 3;
214 DE_GLOBEVENT = 0;
215 DE_BFGHIT = 1;
216 DE_KILLCOMBO = 2;
217 DE_BODYKILL = 3;
219 ANNOUNCE_NONE = 0;
220 ANNOUNCE_ME = 1;
221 ANNOUNCE_MEPLUS = 2;
222 ANNOUNCE_ALL = 3;
224 CONFIG_FILENAME = 'Doom2DF.cfg';
226 TEST_MAP_NAME = '$$$_TEST_$$$';
228 STD_PLAYER_MODEL = 'Doomer';
230 {$IFDEF HEADLESS}
231 DEFAULT_PLAYERS = 0;
232 {$ELSE}
233 DEFAULT_PLAYERS = 1;
234 {$ENDIF}
236 STATFILE_VERSION = $03;
238 var
239 gStdFont: DWORD;
240 gGameSettings: TGameSettings;
241 gPlayer1Settings: TPlayerSettings;
242 gPlayer2Settings: TPlayerSettings;
243 gGameOn: Boolean;
244 gPlayerScreenSize: TDFPoint;
245 gPlayer1ScreenCoord: TDFPoint;
246 gPlayer2ScreenCoord: TDFPoint;
247 gPlayer1: TPlayer = nil;
248 gPlayer2: TPlayer = nil;
249 gPlayerDrawn: TPlayer = nil;
250 gTime: LongWord;
251 gLerpFactor: Single = 1.0;
252 gSwitchGameMode: Byte = GM_DM;
253 gHearPoint1, gHearPoint2: THearPoint;
254 gSoundEffectsDF: Boolean = False;
255 gSoundTriggerTime: Word = 0;
256 gAnnouncer: Integer = ANNOUNCE_NONE;
257 goodsnd: array[0..3] of TPlayableSound;
258 killsnd: array[0..3] of TPlayableSound;
259 hahasnd: array[0..2] of TPlayableSound;
260 sound_get_flag: array[0..1] of TPlayableSound;
261 sound_lost_flag: array[0..1] of TPlayableSound;
262 sound_ret_flag: array[0..1] of TPlayableSound;
263 sound_cap_flag: array[0..1] of TPlayableSound;
264 gBodyKillEvent: Integer = -1;
265 gDefInterTime: ShortInt = -1;
266 gInterEndTime: LongWord = 0;
267 gInterTime: LongWord = 0;
268 gServInterTime: Byte = 0;
269 gGameStartTime: LongWord = 0;
270 gTotalMonsters: Integer = 0;
271 gPauseMain: Boolean = false;
272 gPauseHolmes: Boolean = false;
273 gShowTime: Boolean = False;
274 gShowFPS: Boolean = False;
275 gShowGoals: Boolean = True;
276 gShowStat: Boolean = True;
277 gShowPIDs: Boolean = False;
278 gShowKillMsg: Boolean = True;
279 gShowLives: Boolean = True;
280 gShowPing: Boolean = False;
281 gShowMap: Boolean = False;
282 gExit: Byte = 0;
283 gState: Byte = STATE_NONE;
284 sX, sY: Integer;
285 sWidth, sHeight: Word;
286 gSpectMode: Byte = SPECT_NONE;
287 gSpectHUD: Boolean = True;
288 gSpectKeyPress: Boolean = False;
289 gSpectX: Integer = 0;
290 gSpectY: Integer = 0;
291 gSpectStep: Byte = 8;
292 gSpectViewTwo: Boolean = False;
293 gSpectPID1: Integer = -1;
294 gSpectPID2: Integer = -1;
295 gSpectAuto: Boolean = False;
296 gSpectAutoNext: LongWord;
297 gSpectAutoStepX: Integer;
298 gSpectAutoStepY: Integer;
299 gMusic: TMusic = nil;
300 gLoadGameMode: Boolean;
301 gCheats: Boolean = False;
302 gMapOnce: Boolean = False;
303 gMapToDelete: String;
304 gTempDelete: Boolean = False;
305 gLastMap: Boolean = False;
306 gScreenWidth: Word;
307 gScreenHeight: Word;
308 gResolutionChange: Boolean = False;
309 gRC_Width, gRC_Height: Integer;
310 gRC_FullScreen, gRC_Maximized: Boolean;
311 gLanguageChange: Boolean = False;
312 gDebugMode: Boolean = False;
313 g_debug_Sounds: Boolean = False;
314 g_debug_Frames: Boolean = False;
315 g_debug_WinMsgs: Boolean = False;
316 g_debug_MonsterOff: Boolean = False;
317 g_debug_BotAIOff: Byte = 0;
318 g_debug_HealthBar: Boolean = False;
319 g_Debug_Player: Boolean = False;
320 gCoopMonstersKilled: Word = 0;
321 gCoopSecretsFound: Word = 0;
322 gCoopTotalMonstersKilled: Word = 0;
323 gCoopTotalSecretsFound: Word = 0;
324 gCoopTotalMonsters: Word = 0;
325 gCoopTotalSecrets: Word = 0;
326 gStatsOff: Boolean = False;
327 gStatsPressed: Boolean = False;
328 gExitByTrigger: Boolean = False;
329 gNextMap: String = '';
330 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
331 gLMSRespawnTime: Cardinal = 0;
332 gLMSSoftSpawn: Boolean = False;
333 gMissionFailed: Boolean = False;
334 gVoteInProgress: Boolean = False;
335 gVotePassed: Boolean = False;
336 gVoteCommand: string = '';
337 gVoteTimer: Cardinal = 0;
338 gVoteCmdTimer: Cardinal = 0;
339 gVoteCount: Integer = 0;
340 gVoteTimeout: Cardinal = 30;
341 gVoted: Boolean = False;
342 gVotesEnabled: Boolean = True;
343 gEvents: Array of TGameEvent;
344 gDelayedEvents: Array of TDelayedEvent;
345 gUseChatSounds: Boolean = True;
346 gChatSounds: Array of TChatSound;
347 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
348 gInterReadyCount: Integer = 0;
350 g_dbg_ignore_bounds: Boolean = false;
351 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
352 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
354 // move button values:
355 // bits 0-1: l/r state:
356 // 0: neither left, nor right pressed
357 // 1: left pressed
358 // 2: right pressed
359 // bits 4-5: l/r state when strafe was pressed
360 P1MoveButton: Byte = 0;
361 P2MoveButton: Byte = 0;
363 g_profile_frame_update: Boolean = false;
364 g_profile_frame_draw: Boolean = false;
365 g_profile_collision: Boolean = false;
366 g_profile_los: Boolean = false;
367 g_profile_history_size: Integer = 1000;
369 g_rlayer_back: Boolean = true;
370 g_rlayer_step: Boolean = true;
371 g_rlayer_wall: Boolean = true;
372 g_rlayer_door: Boolean = true;
373 g_rlayer_acid1: Boolean = true;
374 g_rlayer_acid2: Boolean = true;
375 g_rlayer_water: Boolean = true;
376 g_rlayer_fore: Boolean = true;
379 procedure g_ResetDynlights ();
380 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
381 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
383 function conIsCheatsEnabled (): Boolean; inline;
384 function gPause (): Boolean; inline;
386 type (* private state *)
387 TEndCustomGameStat = record
388 PlayerStat: TPlayerStatArray;
389 TeamStat: TTeamStat;
390 GameTime: LongWord;
391 GameMode: Byte;
392 Map, MapName: String;
393 end;
395 TEndSingleGameStat = record
396 PlayerStat: Array [0..1] of record
397 Kills: Integer;
398 Secrets: Integer;
399 end;
400 GameTime: LongWord;
401 TwoPlayers: Boolean;
402 TotalSecrets: Integer;
403 end;
405 TLoadingStat = record
406 CurValue: Integer;
407 MaxValue: Integer;
408 ShowCount: Integer;
409 Msgs: Array of String;
410 NextMsg: Word;
411 PBarWasHere: Boolean; // did we draw a progress bar for this message?
412 end;
414 TDynLight = record
415 x, y, radius: Integer;
416 r, g, b, a: Single;
417 exploCount: Integer;
418 exploRadius: Integer;
419 end;
421 var (* private state *)
422 CustomStat: TEndCustomGameStat;
423 StatShotDone: Boolean;
424 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
425 SingleStat: TEndSingleGameStat;
426 hasPBarGfx: Boolean;
427 LoadingStat: TLoadingStat;
428 MessageText: String;
429 IsDrawStat: Boolean;
430 EndingGameCounter: Byte;
431 UPS: Word;
432 g_playerLight: Boolean;
433 g_dynLights: array of TDynLight = nil;
434 g_dynLightCount: Integer = 0;
436 implementation
438 uses
439 {$IFDEF ENABLE_HOLMES}
440 g_holmes,
441 {$ENDIF}
442 e_res, g_textures, g_window, g_menu,
443 e_input, e_log, g_console, r_console, g_items, g_map, g_panel,
444 g_playermodel, g_gfx, g_options, Math,
445 g_triggers, g_monsters, e_sound, CONFIG,
446 g_language, g_net, g_phys,
447 ENet, e_msg, g_netmsg, g_netmaster,
448 sfs, wadreader, g_system, r_playermodel;
450 var
451 charbuff: packed array [0..15] of AnsiChar = (
452 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
453 );
455 function Translit (const S: AnsiString): AnsiString;
456 var
457 i: Integer;
458 begin
459 Result := S;
460 for i := 1 to Length(Result) do
461 begin
462 case Result[i] of
463 #$C9: Result[i] := 'Q';
464 #$D6: Result[i] := 'W';
465 #$D3: Result[i] := 'E';
466 #$CA: Result[i] := 'R';
467 #$C5: Result[i] := 'T';
468 #$CD: Result[i] := 'Y';
469 #$C3: Result[i] := 'U';
470 #$D8: Result[i] := 'I';
471 #$D9: Result[i] := 'O';
472 #$C7: Result[i] := 'P';
473 #$D5: Result[i] := '['; //Chr(219);
474 #$DA: Result[i] := ']'; //Chr(221);
475 #$D4: Result[i] := 'A';
476 #$DB: Result[i] := 'S';
477 #$C2: Result[i] := 'D';
478 #$C0: Result[i] := 'F';
479 #$CF: Result[i] := 'G';
480 #$D0: Result[i] := 'H';
481 #$CE: Result[i] := 'J';
482 #$CB: Result[i] := 'K';
483 #$C4: Result[i] := 'L';
484 #$C6: Result[i] := ';'; //Chr(186);
485 #$DD: Result[i] := #39; //Chr(222);
486 #$DF: Result[i] := 'Z';
487 #$D7: Result[i] := 'X';
488 #$D1: Result[i] := 'C';
489 #$CC: Result[i] := 'V';
490 #$C8: Result[i] := 'B';
491 #$D2: Result[i] := 'N';
492 #$DC: Result[i] := 'M';
493 #$C1: Result[i] := ','; //Chr(188);
494 #$DE: Result[i] := '.'; //Chr(190);
495 end;
496 end;
497 end;
500 function CheckCheat (ct: TStrings_Locale; eofs: Integer=0): Boolean;
501 var
502 ls1, ls2: string;
503 begin
504 ls1 := CheatEng[ct];
505 ls2 := Translit(CheatRus[ct]);
506 if length(ls1) = 0 then ls1 := '~';
507 if length(ls2) = 0 then ls2 := '~';
508 result :=
509 (Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)) = ls1) or
510 (Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))) = ls1) or
511 (Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)) = ls2) or
512 (Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))) = ls2);
514 if ct = I_GAME_CHEAT_JETPACK then
515 begin
516 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
517 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
518 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
519 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
520 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
521 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
522 end;
524 end;
526 procedure Cheat ();
527 const
528 CHEAT_DAMAGE = 500;
529 label
530 Cheated;
531 var
532 s, s2: string;
533 c: ShortString;
534 a: Integer;
535 begin
537 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
538 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
539 or g_Game_IsNet then Exit;
541 if not gGameOn then exit;
542 if not conIsCheatsEnabled then exit;
544 s := 'SOUND_GAME_RADIO';
546 //
547 if CheckCheat(I_GAME_CHEAT_GODMODE) then
548 begin
549 if gPlayer1 <> nil then gPlayer1.GodMode := not gPlayer1.GodMode;
550 if gPlayer2 <> nil then gPlayer2.GodMode := not gPlayer2.GodMode;
551 goto Cheated;
552 end;
553 // RAMBO
554 if CheckCheat(I_GAME_CHEAT_WEAPONS) then
555 begin
556 if gPlayer1 <> nil then gPlayer1.AllRulez(False);
557 if gPlayer2 <> nil then gPlayer2.AllRulez(False);
558 goto Cheated;
559 end;
560 // TANK
561 if CheckCheat(I_GAME_CHEAT_HEALTH) then
562 begin
563 if gPlayer1 <> nil then gPlayer1.AllRulez(True);
564 if gPlayer2 <> nil then gPlayer2.AllRulez(True);
565 goto Cheated;
566 end;
567 // IDDQD
568 if CheckCheat(I_GAME_CHEAT_DEATH) then
569 begin
570 if gPlayer1 <> nil then gPlayer1.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP);
571 if gPlayer2 <> nil then gPlayer2.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP);
572 s := 'SOUND_MONSTER_HAHA';
573 goto Cheated;
574 end;
575 //
576 if CheckCheat(I_GAME_CHEAT_DOORS) then
577 begin
578 g_Triggers_OpenAll();
579 goto Cheated;
580 end;
581 // GOODBYE
582 if CheckCheat(I_GAME_CHEAT_NEXTMAP) then
583 begin
584 if gTriggers <> nil then
585 for a := 0 to High(gTriggers) do
586 if gTriggers[a].TriggerType = TRIGGER_EXIT then
587 begin
588 gExitByTrigger := True;
589 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
590 g_Game_ExitLevel(gTriggers[a].tgcMap);
591 Break;
592 end;
593 goto Cheated;
594 end;
595 //
596 s2 := Copy(charbuff, 15, 2);
597 if CheckCheat(I_GAME_CHEAT_CHANGEMAP, 2) and (s2[1] >= '0') and (s2[1] <= '9') and (s2[2] >= '0') and (s2[2] <= '9') then
598 begin
599 if g_Map_Exist(gGameSettings.WAD + ':\MAP' + s2) then
600 begin
601 c := 'MAP' + s2;
602 g_Game_ExitLevel(c);
603 end;
604 goto Cheated;
605 end;
606 //
607 if CheckCheat(I_GAME_CHEAT_FLY) then
608 begin
609 gFly := not gFly;
610 goto Cheated;
611 end;
612 // BULLFROG
613 if CheckCheat(I_GAME_CHEAT_JUMPS) then
614 begin
615 VEL_JUMP := 30-VEL_JUMP;
616 goto Cheated;
617 end;
618 // FORMULA1
619 if CheckCheat(I_GAME_CHEAT_SPEED) then
620 begin
621 MAX_RUNVEL := 32-MAX_RUNVEL;
622 goto Cheated;
623 end;
624 // CONDOM
625 if CheckCheat(I_GAME_CHEAT_SUIT) then
626 begin
627 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_SUIT);
628 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_SUIT);
629 goto Cheated;
630 end;
631 //
632 if CheckCheat(I_GAME_CHEAT_AIR) then
633 begin
634 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_OXYGEN);
635 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_OXYGEN);
636 goto Cheated;
637 end;
638 // PURELOVE
639 if CheckCheat(I_GAME_CHEAT_BERSERK) then
640 begin
641 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_MEDKIT_BLACK);
642 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_MEDKIT_BLACK);
643 goto Cheated;
644 end;
645 //
646 if CheckCheat(I_GAME_CHEAT_JETPACK) then
647 begin
648 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_JETPACK);
649 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_JETPACK);
650 goto Cheated;
651 end;
652 // CASPER
653 if CheckCheat(I_GAME_CHEAT_NOCLIP) then
654 begin
655 if gPlayer1 <> nil then gPlayer1.SwitchNoClip;
656 if gPlayer2 <> nil then gPlayer2.SwitchNoClip;
657 goto Cheated;
658 end;
659 //
660 if CheckCheat(I_GAME_CHEAT_NOTARGET) then
661 begin
662 if gPlayer1 <> nil then gPlayer1.NoTarget := not gPlayer1.NoTarget;
663 if gPlayer2 <> nil then gPlayer2.NoTarget := not gPlayer2.NoTarget;
664 goto Cheated;
665 end;
666 // INFERNO
667 if CheckCheat(I_GAME_CHEAT_NORELOAD) then
668 begin
669 if gPlayer1 <> nil then gPlayer1.NoReload := not gPlayer1.NoReload;
670 if gPlayer2 <> nil then gPlayer2.NoReload := not gPlayer2.NoReload;
671 goto Cheated;
672 end;
673 if CheckCheat(I_GAME_CHEAT_AIMLINE) then
674 begin
675 gAimLine := not gAimLine;
676 goto Cheated;
677 end;
678 if CheckCheat(I_GAME_CHEAT_AUTOMAP) then
679 begin
680 gShowMap := not gShowMap;
681 goto Cheated;
682 end;
683 Exit;
685 Cheated:
686 g_Sound_PlayEx(s);
687 end;
690 procedure KeyPress (K: Word);
691 {$IFNDEF HEADLESS}
692 var
693 Msg: g_gui.TMessage;
694 {$ENDIF}
695 begin
696 {$IFNDEF HEADLESS}
697 case K of
698 VK_ESCAPE: // <Esc>:
699 begin
700 if (g_ActiveWindow <> nil) then
701 begin
702 Msg.Msg := WM_KEYDOWN;
703 Msg.WParam := VK_ESCAPE;
704 g_ActiveWindow.OnMessage(Msg);
705 if (not g_Game_IsNet) and (g_ActiveWindow = nil) then g_Game_Pause(false); //Fn loves to do this
706 end
707 else if (gState <> STATE_FOLD) then
708 begin
709 if gGameOn or (gState = STATE_INTERSINGLE) or (gState = STATE_INTERCUSTOM) then
710 begin
711 g_Game_InGameMenu(True);
712 end
713 else if (gExit = 0) and (gState <> STATE_SLIST) then
714 begin
715 if (gState <> STATE_MENU) then
716 begin
717 if (NetMode <> NET_NONE) then
718 begin
719 g_Game_StopAllSounds(True);
720 g_Game_Free;
721 gState := STATE_MENU;
722 Exit;
723 end;
724 end;
725 g_GUI_ShowWindow('MainMenu');
726 g_Sound_PlayEx('MENU_OPEN');
727 end;
728 end;
729 end;
731 IK_F2, IK_F3, IK_F4, IK_F5, IK_F6, IK_F7, IK_F10:
732 begin // <F2> .. <F6> � <F12>
733 if gGameOn and (not gConsoleShow) and (not gChatShow) then
734 begin
735 while (g_ActiveWindow <> nil) do g_GUI_HideWindow(False);
736 if (not g_Game_IsNet) then g_Game_Pause(True);
737 case K of
738 IK_F2: g_Menu_Show_SaveMenu();
739 IK_F3: g_Menu_Show_LoadMenu();
740 IK_F4: g_Menu_Show_GameSetGame();
741 IK_F5: g_Menu_Show_OptionsVideo();
742 IK_F6: g_Menu_Show_OptionsSound();
743 IK_F7: g_Menu_Show_EndGameMenu();
744 IK_F10: g_Menu_Show_QuitGameMenu();
745 end;
746 end;
747 end;
749 else
750 begin
751 gJustChatted := False;
752 if gConsoleShow or gChatShow then
753 begin
754 g_Console_Control(K);
755 end
756 else if (g_ActiveWindow <> nil) then
757 begin
758 Msg.Msg := WM_KEYDOWN;
759 Msg.WParam := K;
760 g_ActiveWindow.OnMessage(Msg);
761 end
762 else if (gState = STATE_MENU) then
763 begin
764 g_GUI_ShowWindow('MainMenu');
765 g_Sound_PlayEx('MENU_OPEN');
766 end;
767 end;
768 end;
769 {$ENDIF}
770 end;
772 procedure CharPress (C: AnsiChar);
773 var
774 Msg: g_gui.TMessage;
775 a: Integer;
776 begin
777 if gConsoleShow or gChatShow then
778 begin
779 g_Console_Char(C)
780 end
781 else if (g_ActiveWindow <> nil) then
782 begin
783 Msg.Msg := WM_CHAR;
784 Msg.WParam := Ord(C);
785 g_ActiveWindow.OnMessage(Msg);
786 end
787 else
788 begin
789 for a := 0 to 14 do charbuff[a] := charbuff[a+1];
790 charbuff[15] := upcase1251(C);
791 Cheat();
792 end;
793 end;
796 // ////////////////////////////////////////////////////////////////////////// //
797 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
799 procedure g_ResetDynlights ();
800 var
801 lnum, idx: Integer;
802 begin
803 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
804 lnum := 0;
805 for idx := 0 to g_dynLightCount-1 do
806 begin
807 if g_dynLights[idx].exploCount = -666 then
808 begin
809 // skip it
810 end
811 else
812 begin
813 // explosion
814 Inc(g_dynLights[idx].exploCount);
815 if (g_dynLights[idx].exploCount < 10) then
816 begin
817 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
818 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
819 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
820 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
821 Inc(lnum);
822 end;
823 end;
824 end;
825 g_dynLightCount := lnum;
826 end;
828 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
829 begin
830 if not gwin_has_stencil then exit;
831 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
832 g_dynLights[g_dynLightCount].x := x;
833 g_dynLights[g_dynLightCount].y := y;
834 g_dynLights[g_dynLightCount].radius := radius;
835 g_dynLights[g_dynLightCount].r := r;
836 g_dynLights[g_dynLightCount].g := g;
837 g_dynLights[g_dynLightCount].b := b;
838 g_dynLights[g_dynLightCount].a := a;
839 g_dynLights[g_dynLightCount].exploCount := -666;
840 Inc(g_dynLightCount);
841 end;
843 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
844 begin
845 if not gwin_has_stencil then exit;
846 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
847 g_dynLights[g_dynLightCount].x := x;
848 g_dynLights[g_dynLightCount].y := y;
849 g_dynLights[g_dynLightCount].radius := 0;
850 g_dynLights[g_dynLightCount].exploRadius := radius;
851 g_dynLights[g_dynLightCount].r := r;
852 g_dynLights[g_dynLightCount].g := g;
853 g_dynLights[g_dynLightCount].b := b;
854 g_dynLights[g_dynLightCount].a := 0;
855 g_dynLights[g_dynLightCount].exploCount := 0;
856 Inc(g_dynLightCount);
857 end;
859 // ////////////////////////////////////////////////////////////////////////// //
860 function conIsCheatsEnabled (): Boolean; inline;
861 begin
862 result := false;
863 if g_Game_IsNet then exit;
864 if not gDebugMode then
865 begin
866 //if not gCheats then exit;
867 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
868 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
869 end;
870 result := true;
871 end;
873 // ////////////////////////////////////////////////////////////////////////// //
874 type
875 TParamStrValue = record
876 Name: String;
877 Value: String;
878 end;
880 TParamStrValues = Array of TParamStrValue;
882 const
883 INTER_ACTION_TEXT = 1;
884 INTER_ACTION_PIC = 2;
885 INTER_ACTION_MUSIC = 3;
887 var
888 UPSCounter: Word;
889 UPSTime: LongWord;
890 DataLoaded: Boolean = False;
891 MessageTime: Word;
892 MessageLineLength: Integer = 80;
893 MapList: SSArray = nil;
894 MapIndex: Integer = -1;
895 InterReadyTime: Integer = -1;
896 StatDate: string = '';
897 MegaWAD: record
898 info: TMegaWADInfo;
899 endpic: String;
900 endmus: String;
901 res: record
902 text: Array of ShortString;
903 anim: Array of ShortString;
904 pic: Array of ShortString;
905 mus: Array of ShortString;
906 end;
907 triggers: Array of record
908 event: ShortString;
909 actions: Array of record
910 action, p1, p2: Integer;
911 end;
912 end;
913 cur_trigger: Integer;
914 cur_action: Integer;
915 end;
916 //InterPic: String;
917 InterText: record
918 lines: SSArray;
919 img: String;
920 cur_line: Integer;
921 cur_char: Integer;
922 counter: Integer;
923 endtext: Boolean;
924 end;
926 function Compare(a, b: TPlayerStat): Integer;
927 begin
928 if a.Spectator then Result := 1
929 else if b.Spectator then Result := -1
930 else if a.Frags < b.Frags then Result := 1
931 else if a.Frags > b.Frags then Result := -1
932 else if a.Deaths < b.Deaths then Result := -1
933 else if a.Deaths > b.Deaths then Result := 1
934 else if a.Kills < b.Kills then Result := -1
935 else Result := 1;
936 end;
938 procedure SortGameStat(var stat: TPlayerStatArray);
939 var
940 I, J: Integer;
941 T: TPlayerStat;
942 begin
943 if stat = nil then Exit;
945 for I := High(stat) downto Low(stat) do
946 for J := Low(stat) to High(stat) - 1 do
947 if Compare(stat[J], stat[J + 1]) = 1 then
948 begin
949 T := stat[J];
950 stat[J] := stat[J + 1];
951 stat[J + 1] := T;
952 end;
953 end;
955 // saves a shitty CSV containing the game stats passed to it
956 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
957 var
958 s: TextFile;
959 dir, fname, map, mode, etime: String;
960 I: Integer;
961 begin
962 try
963 dir := e_GetWriteableDir(StatsDirs);
964 // stats are placed in stats/yy/mm/dd/*.csv
965 fname := e_CatPath(dir, Path);
966 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
967 fname := e_CatPath(fname, StatFilename + '.csv');
968 AssignFile(s, fname);
969 try
970 Rewrite(s);
971 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
972 if g_Game_IsNet then fname := NetServerName else fname := '';
973 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
974 mode := g_Game_ModeToText(Stat.GameMode);
975 etime := Format('%d:%.2d:%.2d', [
976 Stat.GameTime div 1000 div 3600,
977 (Stat.GameTime div 1000 div 60) mod 60,
978 Stat.GameTime div 1000 mod 60
979 ]);
980 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
981 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
982 STATFILE_VERSION,
983 StatDate,
984 dquoteStr(fname),
985 dquoteStr(map),
986 mode,
987 gGameSettings.TimeLimit,
988 gGameSettings.GoalLimit,
989 gGameSettings.Options,
990 etime,
991 Length(Stat.PlayerStat)
992 ]));
993 // line 2: game specific shit
994 // if it's a team game: red score, blue score
995 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
996 // otherwise nothing
997 if Stat.GameMode in [GM_TDM, GM_CTF] then
998 WriteLn(s,
999 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Goals, Stat.TeamStat[TEAM_BLUE].Goals]))
1000 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
1001 WriteLn(s,
1002 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
1003 // lines 3-...: team, player name, frags, deaths
1004 WriteLn(s, 'team,name,frags,deaths');
1005 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
1006 with Stat.PlayerStat[I] do
1007 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
1008 except
1009 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
1010 end;
1011 except
1012 g_Console_Add('could not create gamestats file "' + fname + '"');
1013 end;
1014 CloseFile(s);
1015 end;
1017 function g_Game_ModeToText(Mode: Byte): string;
1018 begin
1019 Result := '';
1020 case Mode of
1021 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
1022 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
1023 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
1024 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
1025 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
1026 end;
1027 end;
1029 function g_Game_TextToMode(Mode: string): Byte;
1030 begin
1031 Result := GM_NONE;
1032 Mode := UpperCase(Mode);
1033 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
1034 begin
1035 Result := GM_DM;
1036 Exit;
1037 end;
1038 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
1039 begin
1040 Result := GM_TDM;
1041 Exit;
1042 end;
1043 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
1044 begin
1045 Result := GM_CTF;
1046 Exit;
1047 end;
1048 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
1049 begin
1050 Result := GM_COOP;
1051 Exit;
1052 end;
1053 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
1054 begin
1055 Result := GM_SINGLE;
1056 Exit;
1057 end;
1058 end;
1060 function g_Game_IsNet(): Boolean;
1061 begin
1062 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
1063 end;
1065 function g_Game_IsServer(): Boolean;
1066 begin
1067 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
1068 end;
1070 function g_Game_IsClient(): Boolean;
1071 begin
1072 Result := (gGameSettings.GameType = GT_CLIENT);
1073 end;
1075 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
1076 var
1077 w: TWADFile;
1078 cfg: TConfig;
1079 p: Pointer;
1080 len: Integer;
1081 begin
1082 Result.name := ExtractFileName(WAD);
1083 Result.description := '';
1084 Result.author := '';
1086 w := TWADFile.Create();
1087 w.ReadFile(WAD);
1089 if not w.GetResource('INTERSCRIPT', p, len) then
1090 begin
1091 w.Free();
1092 Exit;
1093 end;
1095 cfg := TConfig.CreateMem(p, len);
1096 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
1097 Result.description := cfg.ReadStr('megawad', 'description', '');
1098 Result.author := cfg.ReadStr('megawad', 'author', '');
1099 Result.pic := cfg.ReadStr('megawad', 'pic', '');
1100 cfg.Free();
1102 FreeMem(p);
1103 end;
1105 procedure g_Game_FreeWAD();
1106 var
1107 a: Integer;
1108 begin
1109 for a := 0 to High(MegaWAD.res.pic) do
1110 if MegaWAD.res.pic[a] <> '' then
1111 g_Texture_Delete(MegaWAD.res.pic[a]);
1113 for a := 0 to High(MegaWAD.res.mus) do
1114 if MegaWAD.res.mus[a] <> '' then
1115 g_Sound_Delete(MegaWAD.res.mus[a]);
1117 MegaWAD.res.pic := nil;
1118 MegaWAD.res.text := nil;
1119 MegaWAD.res.anim := nil;
1120 MegaWAD.res.mus := nil;
1121 MegaWAD.triggers := nil;
1123 g_Texture_Delete('TEXTURE_endpic');
1124 g_Sound_Delete('MUSIC_endmus');
1126 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
1127 gGameSettings.WAD := '';
1128 end;
1130 procedure g_Game_LoadWAD(WAD: string);
1131 var
1132 w: TWADFile;
1133 cfg: TConfig;
1134 p: Pointer;
1135 {b, }len: Integer;
1136 s: AnsiString;
1137 begin
1138 g_Game_FreeWAD();
1139 gGameSettings.WAD := WAD;
1140 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
1141 Exit;
1143 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
1145 w := TWADFile.Create();
1146 w.ReadFile(WAD);
1148 if not w.GetResource('INTERSCRIPT', p, len) then
1149 begin
1150 w.Free();
1151 Exit;
1152 end;
1154 cfg := TConfig.CreateMem(p, len);
1156 {b := 1;
1157 while True do
1158 begin
1159 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
1160 if s = '' then Break;
1161 b := b+1;
1163 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
1164 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
1166 g_Texture_CreateWADEx(s, s);
1167 end;
1169 b := 1;
1170 while True do
1171 begin
1172 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
1173 if s = '' then Break;
1174 b := b+1;
1176 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
1177 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
1179 g_Music_CreateWADEx(s, s);
1180 end;}
1182 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
1183 if MegaWAD.endpic <> '' then
1184 begin
1185 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
1186 g_Texture_CreateWADEx('TEXTURE_endpic', s, gTextureFilter);
1187 end;
1188 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1189 if MegaWAD.endmus <> '' then
1190 begin
1191 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
1192 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
1193 end;
1195 cfg.Free();
1196 FreeMem(p);
1197 w.Free();
1198 end;
1200 {procedure start_trigger(t: string);
1201 begin
1202 end;
1204 function next_trigger(): Boolean;
1205 begin
1206 end;}
1208 procedure DisableCheats();
1209 begin
1210 MAX_RUNVEL := 8;
1211 VEL_JUMP := 10;
1212 gFly := False;
1214 if gPlayer1 <> nil then gPlayer1.GodMode := False;
1215 if gPlayer2 <> nil then gPlayer2.GodMode := False;
1216 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
1217 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
1219 {$IF DEFINED(D2F_DEBUG)}
1220 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
1221 gAimLine := g_dbg_aimline_on;
1222 {$ENDIF}
1223 end;
1225 procedure g_Game_ExecuteEvent(Name: String);
1226 var
1227 a: Integer;
1228 begin
1229 if Name = '' then
1230 Exit;
1231 if gEvents = nil then
1232 Exit;
1233 for a := 0 to High(gEvents) do
1234 if gEvents[a].Name = Name then
1235 begin
1236 if gEvents[a].Command <> '' then
1237 g_Console_Process(gEvents[a].Command, True);
1238 break;
1239 end;
1240 end;
1242 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
1243 var
1244 a, n: Integer;
1245 begin
1246 n := -1;
1247 if gDelayedEvents <> nil then
1248 for a := 0 to High(gDelayedEvents) do
1249 if not gDelayedEvents[a].Pending then
1250 begin
1251 n := a;
1252 break;
1253 end;
1254 if n = -1 then
1255 begin
1256 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
1257 n := High(gDelayedEvents);
1258 end;
1259 gDelayedEvents[n].Pending := True;
1260 gDelayedEvents[n].DEType := DEType;
1261 gDelayedEvents[n].DENum := Num;
1262 gDelayedEvents[n].DEStr := Str;
1263 if DEType = DE_GLOBEVENT then
1264 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
1265 else
1266 gDelayedEvents[n].Time := gTime + Time;
1267 Result := n;
1268 end;
1270 procedure EndGame();
1271 var
1272 a: Integer;
1273 FileName: string;
1274 t: TDateTime;
1275 begin
1276 if g_Game_IsNet and g_Game_IsServer then
1277 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1279 // Стоп игра:
1280 gPauseMain := false;
1281 gPauseHolmes := false;
1282 gGameOn := false;
1284 g_Game_StopAllSounds(False);
1286 MessageTime := 0;
1287 MessageText := '';
1289 EndingGameCounter := 0;
1290 g_ActiveWindow := nil;
1292 gLMSRespawn := LMS_RESPAWN_NONE;
1293 gLMSRespawnTime := 0;
1295 case gExit of
1296 EXIT_SIMPLE: // Выход через меню или конец теста
1297 begin
1298 g_Game_Free();
1300 if gMapOnce then
1301 begin // Это был тест
1302 g_Game_Quit();
1303 end
1304 else
1305 begin // Выход в главное меню
1306 gMusic.SetByName('MUSIC_MENU');
1307 gMusic.Play();
1308 if gState <> STATE_SLIST then
1309 begin
1310 g_GUI_ShowWindow('MainMenu');
1311 gState := STATE_MENU;
1312 end else
1313 begin
1314 // Обновляем список серверов
1315 slReturnPressed := True;
1316 if g_Net_Slist_Fetch(slCurrent) then
1317 begin
1318 if slCurrent = nil then
1319 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1320 end
1321 else
1322 slWaitStr := _lc[I_NET_SLIST_ERROR];
1323 g_Serverlist_GenerateTable(slCurrent, slTable);
1324 end;
1326 g_Game_ExecuteEvent('ongameend');
1327 end;
1328 end;
1330 EXIT_RESTART: // Начать уровень сначала
1331 begin
1332 if not g_Game_IsClient then g_Game_Restart();
1333 end;
1335 EXIT_ENDLEVELCUSTOM: // Закончился уровень в Своей игре
1336 begin
1337 // Статистика Своей игры:
1338 FileName := g_ExtractWadName(gMapInfo.Map);
1340 CustomStat.GameTime := gTime;
1341 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1342 CustomStat.MapName := gMapInfo.Name;
1343 CustomStat.GameMode := gGameSettings.GameMode;
1344 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1345 CustomStat.TeamStat := gTeamStat;
1347 CustomStat.PlayerStat := nil;
1349 // Статистика игроков:
1350 if gPlayers <> nil then
1351 begin
1352 for a := 0 to High(gPlayers) do
1353 if gPlayers[a] <> nil then
1354 begin
1355 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1356 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1357 begin
1358 Num := a;
1359 Name := gPlayers[a].Name;
1360 Frags := gPlayers[a].Frags;
1361 Deaths := gPlayers[a].Death;
1362 Kills := gPlayers[a].Kills;
1363 Team := gPlayers[a].Team;
1364 Color := gPlayers[a].Model.Color;
1365 Spectator := gPlayers[a].FSpectator;
1366 end;
1367 end;
1369 SortGameStat(CustomStat.PlayerStat);
1371 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1372 begin
1373 t := Now;
1374 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1375 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1376 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1377 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1378 if gSaveStats then
1379 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1380 end;
1382 StatShotDone := False;
1383 end;
1385 g_Game_ExecuteEvent('onmapend');
1386 if not g_Game_IsClient then g_Player_ResetReady;
1387 gInterReadyCount := 0;
1389 // Затухающий экран:
1390 EndingGameCounter := 255;
1391 gState := STATE_FOLD;
1392 gInterTime := 0;
1393 if gDefInterTime < 0 then
1394 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1395 else
1396 gInterEndTime := gDefInterTime * 1000;
1397 end;
1399 EXIT_ENDLEVELSINGLE: // Закончился уровень в Одиночной игре
1400 begin
1401 // Статистика Одиночной игры:
1402 SingleStat.GameTime := gTime;
1403 SingleStat.TwoPlayers := gPlayer2 <> nil;
1404 SingleStat.TotalSecrets := gSecretsCount;
1405 // Статистика первого игрока:
1406 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1407 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1408 // Статистика второго игрока (если есть):
1409 if SingleStat.TwoPlayers then
1410 begin
1411 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1412 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1413 end;
1415 g_Game_ExecuteEvent('onmapend');
1417 // Есть еще карты:
1418 if gNextMap <> '' then
1419 begin
1420 gMusic.SetByName('MUSIC_INTERMUS');
1421 gMusic.Play();
1422 gState := STATE_INTERSINGLE;
1423 e_UnpressAllKeys();
1425 g_Game_ExecuteEvent('oninter');
1426 end
1427 else // Больше нет карт
1428 begin
1429 // Затухающий экран:
1430 EndingGameCounter := 255;
1431 gState := STATE_FOLD;
1432 end;
1433 end;
1434 end;
1436 // Окончание обработано:
1437 if gExit <> EXIT_QUIT then
1438 gExit := 0;
1439 end;
1441 procedure g_Game_Init();
1442 var
1443 SR: TSearchRec;
1444 knownFiles: array of AnsiString = nil;
1445 found: Boolean;
1446 wext, s: AnsiString;
1447 f: Integer;
1448 begin
1449 gExit := 0;
1450 gMapToDelete := '';
1451 gTempDelete := False;
1453 sfsGCDisable(); // temporary disable removing of temporary volumes
1455 try
1456 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE', gTextureFilter);
1457 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER', gTextureFilter);
1458 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN', gTextureFilter);
1459 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU', gTextureFilter);
1461 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1462 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1463 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1465 g_Game_ClearLoading();
1466 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1467 g_Game_SetLoadingText('', 0, False);
1469 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1470 r_Console_Init;
1471 g_Console_Init();
1473 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1474 r_PlayerModel_Initialize;
1476 // load models from all possible wad types, in all known directories
1477 // this does a loosy job (linear search, ooph!), but meh
1478 for wext in wadExtensions do
1479 begin
1480 for f := High(ModelDirs) downto Low(ModelDirs) do
1481 begin
1482 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1483 begin
1484 repeat
1485 found := false;
1486 for s in knownFiles do
1487 begin
1488 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1489 begin
1490 found := true;
1491 break;
1492 end;
1493 end;
1494 if not found then
1495 begin
1496 SetLength(knownFiles, length(knownFiles)+1);
1497 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1498 end;
1499 until (FindNext(SR) <> 0);
1500 end;
1501 FindClose(SR);
1502 end;
1503 end;
1505 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1507 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);
1508 for s in knownFiles do
1509 begin
1510 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1511 end;
1513 gGameOn := false;
1514 gPauseMain := false;
1515 gPauseHolmes := false;
1516 gTime := 0;
1518 {e_MouseInfo.Accel := 1.0;}
1520 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1521 g_Game_LoadData();
1523 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1524 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1525 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1526 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1527 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1529 {$IFNDEF HEADLESS}
1530 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1531 g_Menu_Init();
1532 {$ENDIF}
1534 gMusic := TMusic.Create();
1535 gMusic.SetByName('MUSIC_MENU');
1536 gMusic.Play();
1538 gGameSettings.WarmupTime := 30;
1540 gState := STATE_MENU;
1542 SetLength(gEvents, 6);
1543 gEvents[0].Name := 'ongamestart';
1544 gEvents[1].Name := 'ongameend';
1545 gEvents[2].Name := 'onmapstart';
1546 gEvents[3].Name := 'onmapend';
1547 gEvents[4].Name := 'oninter';
1548 gEvents[5].Name := 'onwadend';
1549 finally
1550 sfsGCEnable(); // enable releasing unused volumes
1551 end;
1552 end;
1554 procedure g_Game_Free(freeTextures: Boolean=true);
1555 begin
1556 if NetMode = NET_CLIENT then g_Net_Disconnect();
1557 if NetMode = NET_SERVER then g_Net_Host_Die();
1559 g_Map_Free(freeTextures);
1560 g_Player_Free();
1561 g_Player_RemoveAllCorpses();
1563 gGameSettings.GameType := GT_NONE;
1564 if gGameSettings.GameMode = GM_SINGLE then
1565 gGameSettings.GameMode := GM_DM;
1566 gSwitchGameMode := gGameSettings.GameMode;
1568 gChatShow := False;
1569 gExitByTrigger := False;
1570 end;
1572 function IsActivePlayer(p: TPlayer): Boolean;
1573 begin
1574 Result := False;
1575 if p = nil then
1576 Exit;
1577 Result := (not p.FDummy) and (not p.FSpectator);
1578 end;
1580 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1581 var
1582 a, idx: Integer;
1583 ids: Array of Word;
1584 begin
1585 Result := -1;
1586 if gPlayers = nil then
1587 Exit;
1588 SetLength(ids, 0);
1589 idx := -1;
1590 for a := Low(gPlayers) to High(gPlayers) do
1591 if IsActivePlayer(gPlayers[a]) then
1592 begin
1593 SetLength(ids, Length(ids) + 1);
1594 ids[High(ids)] := gPlayers[a].UID;
1595 if gPlayers[a].UID = Skip then
1596 idx := High(ids);
1597 end;
1598 if Length(ids) = 0 then
1599 Exit;
1600 if idx = -1 then
1601 Result := ids[0]
1602 else
1603 Result := ids[(idx + 1) mod Length(ids)];
1604 end;
1606 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1607 var
1608 a, idx: Integer;
1609 ids: Array of Word;
1610 begin
1611 Result := -1;
1612 if gPlayers = nil then
1613 Exit;
1614 SetLength(ids, 0);
1615 idx := -1;
1616 for a := Low(gPlayers) to High(gPlayers) do
1617 if IsActivePlayer(gPlayers[a]) then
1618 begin
1619 SetLength(ids, Length(ids) + 1);
1620 ids[High(ids)] := gPlayers[a].UID;
1621 if gPlayers[a].UID = Skip then
1622 idx := High(ids);
1623 end;
1624 if Length(ids) = 0 then
1625 Exit;
1626 if idx = -1 then
1627 Result := ids[Length(ids) - 1]
1628 else
1629 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1630 end;
1632 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1633 var
1634 a, idx: Integer;
1635 ids: Array of Word;
1636 begin
1637 Result := -1;
1638 if gPlayers = nil then
1639 Exit;
1640 SetLength(ids, 0);
1641 idx := -1;
1642 for a := Low(gPlayers) to High(gPlayers) do
1643 if IsActivePlayer(gPlayers[a]) then
1644 begin
1645 SetLength(ids, Length(ids) + 1);
1646 ids[High(ids)] := gPlayers[a].UID;
1647 if gPlayers[a].UID = Skip then
1648 idx := High(ids);
1649 end;
1650 if Length(ids) = 0 then
1651 Exit;
1652 if Length(ids) = 1 then
1653 begin
1654 Result := ids[0];
1655 Exit;
1656 end;
1657 Result := ids[Random(Length(ids))];
1658 a := 10;
1659 while (idx <> -1) and (Result = Skip) and (a > 0) do
1660 begin
1661 Result := ids[Random(Length(ids))];
1662 Dec(a);
1663 end;
1664 end;
1666 function GetRandomSpectMode(Current: Byte): Byte;
1667 label
1668 retry;
1669 begin
1670 Result := Current;
1671 retry:
1672 case Random(7) of
1673 0: Result := SPECT_STATS;
1674 1: Result := SPECT_MAPVIEW;
1675 2: Result := SPECT_MAPVIEW;
1676 3: Result := SPECT_PLAYERS;
1677 4: Result := SPECT_PLAYERS;
1678 5: Result := SPECT_PLAYERS;
1679 6: Result := SPECT_PLAYERS;
1680 end;
1681 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1682 goto retry;
1683 end;
1685 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1686 var
1687 time: Word;
1688 strafeDir: Byte;
1689 i: Integer;
1690 begin
1691 if (plr = nil) then exit;
1692 if (p = 2) then time := 1000 else time := 1;
1693 strafeDir := MoveButton shr 4;
1694 MoveButton := MoveButton and $0F;
1696 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1697 MoveButton := 1 // Нажата только "Влево"
1698 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1699 MoveButton := 2 // Нажата только "Вправо"
1700 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1701 MoveButton := 0; // Не нажаты ни "Влево", ни "Вправо"
1703 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1704 if MoveButton = 1 then
1705 plr.PressKey(KEY_LEFT, time)
1706 else if MoveButton = 2 then
1707 plr.PressKey(KEY_RIGHT, time);
1709 // if we have "strafe" key, turn off old strafe mechanics
1710 if gPlayerAction[p, ACTION_STRAFE] then
1711 begin
1712 // new strafe mechanics
1713 if (strafeDir = 0) then
1714 strafeDir := MoveButton; // start strafing
1715 // now set direction according to strafe (reversed)
1716 if (strafeDir = 2) then
1717 plr.SetDirection(TDirection.D_LEFT)
1718 else if (strafeDir = 1) then
1719 plr.SetDirection(TDirection.D_RIGHT)
1720 end
1721 else
1722 begin
1723 strafeDir := 0; // not strafing anymore
1724 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1725 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1726 plr.SetDirection(TDirection.D_LEFT)
1727 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1728 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1729 plr.SetDirection(TDirection.D_RIGHT)
1730 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1731 else if MoveButton <> 0 then
1732 plr.SetDirection(TDirection(MoveButton-1))
1733 end;
1735 // fix movebutton state
1736 MoveButton := MoveButton or (strafeDir shl 4);
1738 // Остальные клавиши:
1739 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1740 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1741 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1742 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1743 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1744 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1745 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1747 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1748 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1750 for i := WP_FIRST to WP_LAST do
1751 begin
1752 if gSelectWeapon[p, i] then
1753 begin
1754 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1755 gSelectWeapon[p, i] := False
1756 end
1757 end;
1759 // HACK: add dynlight here
1760 if gwin_k8_enable_light_experiments then
1761 begin
1762 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1763 begin
1764 g_playerLight := true;
1765 end;
1766 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1767 begin
1768 g_playerLight := false;
1769 end;
1770 end;
1772 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1773 end;
1775 // HACK: don't have a "key was pressed" function
1776 procedure InterReady();
1777 begin
1778 if InterReadyTime > gTime then Exit;
1779 InterReadyTime := gTime + 3000;
1780 MC_SEND_CheatRequest(NET_CHEAT_READY);
1781 end;
1783 procedure g_Game_PreUpdate();
1784 begin
1785 // these are in separate PreUpdate functions because they can interact during Update()
1786 // and are synced over the net
1787 // we don't care that much about corpses and gibs
1788 g_Player_PreUpdate();
1789 g_Monsters_PreUpdate();
1790 g_Items_PreUpdate();
1791 g_Weapon_PreUpdate();
1792 end;
1794 procedure g_Game_Update();
1795 var
1796 Msg: g_gui.TMessage;
1797 Time: Int64;
1798 a: Byte;
1799 w: Word;
1800 i, b: Integer;
1802 function sendMonsPos (mon: TMonster): Boolean;
1803 begin
1804 result := false; // don't stop
1805 // this will also reset "need-send" flag
1806 if mon.gncNeedSend then
1807 begin
1808 MH_SEND_MonsterPos(mon.UID);
1809 end
1810 else if (mon.MonsterType = MONSTER_BARREL) then
1811 begin
1812 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1813 end
1814 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1815 begin
1816 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1817 end;
1818 end;
1820 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1821 begin
1822 result := false; // don't stop
1823 // this will also reset "need-send" flag
1824 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1825 end;
1827 var
1828 reliableUpdate: Boolean;
1829 begin
1830 g_ResetDynlights();
1831 framePool.reset();
1833 // Пора выключать игру:
1834 if gExit = EXIT_QUIT then
1835 Exit;
1836 // Игра закончилась - обрабатываем:
1837 if gExit <> 0 then
1838 begin
1839 EndGame();
1840 if gExit = EXIT_QUIT then
1841 Exit;
1842 end;
1844 // Читаем клавиатуру и джойстик, если окно активно
1845 // no need to, as we'll do it in event handler
1847 // Обновляем консоль (движение и сообщения):
1848 r_Console_Update;
1849 g_Console_Update();
1851 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1852 begin
1853 gExit := EXIT_SIMPLE;
1854 EndGame();
1855 Exit;
1856 end;
1858 // process master server communications
1859 g_Net_Slist_Pulse();
1861 case gState of
1862 STATE_INTERSINGLE, // Статистка после прохождения уровня в Одиночной игре
1863 STATE_INTERCUSTOM, // Статистка после прохождения уровня в Своей игре
1864 STATE_INTERTEXT, // Текст между уровнями
1865 STATE_INTERPIC: // Картинка между уровнями
1866 begin
1867 if g_Game_IsNet and g_Game_IsServer then
1868 begin
1869 gInterTime := gInterTime + GAME_TICK;
1870 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1871 if a <> gServInterTime then
1872 begin
1873 gServInterTime := a;
1874 MH_SEND_TimeSync(gServInterTime);
1875 end;
1876 end;
1878 if (not g_Game_IsClient) and
1882 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1883 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1884 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1885 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1887 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1888 and (g_ActiveWindow = nil)
1890 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1892 then
1893 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1894 g_Game_StopAllSounds(True);
1896 if gMapOnce then // Это был тест
1897 gExit := EXIT_SIMPLE
1898 else
1899 if gNextMap <> '' then // Переходим на следующую карту
1900 g_Game_ChangeMap(gNextMap)
1901 else // Следующей карты нет
1902 begin
1903 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1904 begin
1905 // Выход в главное меню:
1906 g_Game_Free;
1907 g_GUI_ShowWindow('MainMenu');
1908 gMusic.SetByName('MUSIC_MENU');
1909 gMusic.Play();
1910 gState := STATE_MENU;
1911 end else
1912 begin
1913 // Финальная картинка:
1914 g_Game_ExecuteEvent('onwadend');
1915 g_Game_Free();
1916 if not gMusic.SetByName('MUSIC_endmus') then
1917 gMusic.SetByName('MUSIC_STDENDMUS');
1918 gMusic.Play();
1919 gState := STATE_ENDPIC;
1920 end;
1921 g_Game_ExecuteEvent('ongameend');
1922 end;
1924 Exit;
1925 end
1926 else if g_Game_IsClient and
1929 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1930 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1931 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1932 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1934 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1935 and (g_ActiveWindow = nil)
1937 then
1938 begin
1939 // ready / unready
1940 InterReady();
1941 end;
1943 if gState = STATE_INTERTEXT then
1944 if InterText.counter > 0 then
1945 InterText.counter := InterText.counter - 1;
1946 end;
1948 STATE_FOLD: // Затухание экрана
1949 begin
1950 if EndingGameCounter = 0 then
1951 begin
1952 // Закончился уровень в Своей игре:
1953 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1954 begin
1955 InterReadyTime := -1;
1956 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1957 begin
1958 g_Game_ExecuteEvent('onwadend');
1959 if not gMusic.SetByName('MUSIC_endmus') then
1960 gMusic.SetByName('MUSIC_STDENDMUS');
1961 end
1962 else
1963 gMusic.SetByName('MUSIC_ROUNDMUS');
1965 gMusic.Play();
1966 gState := STATE_INTERCUSTOM;
1967 e_UnpressAllKeys();
1968 end
1969 else // Закончилась последняя карта в Одиночной игре
1970 begin
1971 gMusic.SetByName('MUSIC_INTERMUS');
1972 gMusic.Play();
1973 gState := STATE_INTERSINGLE;
1974 e_UnpressAllKeys();
1975 end;
1976 g_Game_ExecuteEvent('oninter');
1977 end
1978 else
1979 DecMin(EndingGameCounter, 6, 0);
1980 end;
1982 STATE_ENDPIC: // Картинка окончания мегаВада
1983 begin
1984 if gMapOnce then // Это был тест
1985 begin
1986 gExit := EXIT_SIMPLE;
1987 Exit;
1988 end;
1989 end;
1991 STATE_SLIST:
1992 g_Serverlist_Control(slCurrent, slTable);
1993 end;
1995 // Статистика по Tab:
1996 if gGameOn then
1997 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1999 // Игра идет:
2000 if gGameOn and not gPause and (gState <> STATE_FOLD) then
2001 begin
2002 // Время += 28 миллисекунд:
2003 gTime := gTime + GAME_TICK;
2005 // Сообщение посередине экрана:
2006 if MessageTime = 0 then
2007 MessageText := '';
2008 if MessageTime > 0 then
2009 MessageTime := MessageTime - 1;
2011 if (g_Game_IsServer) then
2012 begin
2013 // Был задан лимит времени:
2014 if (gGameSettings.TimeLimit > 0) then
2015 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
2016 begin // Он прошел => конец уровня
2017 g_Game_NextLevel();
2018 Exit;
2019 end;
2021 // Надо респавнить игроков в LMS:
2022 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
2023 g_Game_RestartRound(gLMSSoftSpawn);
2025 // Проверим результат голосования, если время прошло
2026 if gVoteInProgress and (gVoteTimer < gTime) then
2027 g_Game_CheckVote
2028 else if gVotePassed and (gVoteCmdTimer < gTime) then
2029 begin
2030 g_Console_Process(gVoteCommand);
2031 gVoteCommand := '';
2032 gVotePassed := False;
2033 end;
2035 // Замеряем время захвата флагов
2036 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2037 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
2038 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2039 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
2041 // Был задан лимит побед:
2042 if (gGameSettings.GoalLimit > 0) then
2043 begin
2044 b := 0;
2046 if gGameSettings.GameMode = GM_DM then
2047 begin // В DM ищем игрока с max фрагами
2048 for i := 0 to High(gPlayers) do
2049 if gPlayers[i] <> nil then
2050 if gPlayers[i].Frags > b then
2051 b := gPlayers[i].Frags;
2052 end
2053 else
2054 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2055 begin // В CTF/TDM выбираем команду с наибольшим счетом
2056 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
2057 end;
2059 // Лимит побед набран => конец уровня:
2060 if b >= gGameSettings.GoalLimit then
2061 begin
2062 g_Game_NextLevel();
2063 Exit;
2064 end;
2065 end;
2067 // Обрабатываем клавиши игроков:
2068 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2069 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2070 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2071 begin
2072 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2073 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2074 end // if not console
2075 else
2076 begin
2077 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2078 end;
2079 // process weapon switch queue
2080 end; // if server
2082 // Наблюдатель
2083 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2084 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2085 begin
2086 if not gSpectKeyPress then
2087 begin
2088 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2089 begin
2090 // switch spect mode
2091 case gSpectMode of
2092 SPECT_NONE: ; // not spectator
2093 SPECT_STATS,
2094 SPECT_MAPVIEW: Inc(gSpectMode);
2095 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2096 end;
2097 gSpectKeyPress := True;
2098 end;
2099 if (gSpectMode = SPECT_MAPVIEW)
2100 and (not gSpectAuto) then
2101 begin
2102 if gPlayerAction[0, ACTION_MOVELEFT] then
2103 gSpectX := Max(gSpectX - gSpectStep, 0);
2104 if gPlayerAction[0, ACTION_MOVERIGHT] then
2105 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2106 if gPlayerAction[0, ACTION_LOOKUP] then
2107 gSpectY := Max(gSpectY - gSpectStep, 0);
2108 if gPlayerAction[0, ACTION_LOOKDOWN] then
2109 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2110 if gPlayerAction[0, ACTION_WEAPPREV] then
2111 begin
2112 // decrease step
2113 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2114 gSpectKeyPress := True;
2115 end;
2116 if gPlayerAction[0, ACTION_WEAPNEXT] then
2117 begin
2118 // increase step
2119 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2120 gSpectKeyPress := True;
2121 end;
2122 end;
2123 if (gSpectMode = SPECT_PLAYERS)
2124 and (not gSpectAuto) then
2125 begin
2126 if gPlayerAction[0, ACTION_LOOKUP] then
2127 begin
2128 // add second view
2129 gSpectViewTwo := True;
2130 gSpectKeyPress := True;
2131 end;
2132 if gPlayerAction[0, ACTION_LOOKDOWN] then
2133 begin
2134 // remove second view
2135 gSpectViewTwo := False;
2136 gSpectKeyPress := True;
2137 end;
2138 if gPlayerAction[0, ACTION_MOVELEFT] then
2139 begin
2140 // prev player (view 1)
2141 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2142 gSpectKeyPress := True;
2143 end;
2144 if gPlayerAction[0, ACTION_MOVERIGHT] then
2145 begin
2146 // next player (view 1)
2147 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2148 gSpectKeyPress := True;
2149 end;
2150 if gPlayerAction[0, ACTION_WEAPPREV] then
2151 begin
2152 // prev player (view 2)
2153 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2154 gSpectKeyPress := True;
2155 end;
2156 if gPlayerAction[0, ACTION_WEAPNEXT] then
2157 begin
2158 // next player (view 2)
2159 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2160 gSpectKeyPress := True;
2161 end;
2162 end;
2163 if gPlayerAction[0, ACTION_ATTACK] then
2164 begin
2165 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2166 begin
2167 gSpectAuto := True;
2168 gSpectAutoNext := 0;
2169 gSpectViewTwo := False;
2170 gSpectKeyPress := True;
2171 end
2172 else
2173 if gSpectAuto then
2174 begin
2175 gSpectMode := SPECT_STATS;
2176 gSpectAuto := False;
2177 gSpectKeyPress := True;
2178 end;
2179 end;
2180 end
2181 else
2182 if (not gPlayerAction[0, ACTION_JUMP]) and
2183 (not gPlayerAction[0, ACTION_ATTACK]) and
2184 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2185 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2186 (not gPlayerAction[0, ACTION_LOOKUP]) and
2187 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2188 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2189 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2190 gSpectKeyPress := False;
2192 if gSpectAuto then
2193 begin
2194 if gSpectMode = SPECT_MAPVIEW then
2195 begin
2196 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2197 if i = gSpectX then
2198 gSpectAutoNext := gTime
2199 else
2200 gSpectX := i;
2201 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2202 if i = gSpectY then
2203 gSpectAutoNext := gTime
2204 else
2205 gSpectY := i;
2206 end;
2207 if gSpectAutoNext <= gTime then
2208 begin
2209 if gSpectAutoNext > 0 then
2210 begin
2211 gSpectMode := GetRandomSpectMode(gSpectMode);
2212 case gSpectMode of
2213 SPECT_MAPVIEW:
2214 begin
2215 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2216 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2217 gSpectAutoStepX := Random(9) - 4;
2218 gSpectAutoStepY := Random(9) - 4;
2219 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2220 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2221 gSpectAutoStepX := gSpectAutoStepX * -1;
2222 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2223 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2224 gSpectAutoStepY := gSpectAutoStepY * -1;
2225 end;
2226 SPECT_PLAYERS:
2227 begin
2228 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2229 end;
2230 end;
2231 end;
2232 case gSpectMode of
2233 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2234 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2235 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2236 end;
2237 end;
2238 end;
2239 end;
2241 // Обновляем все остальное:
2242 g_Map_Update();
2243 g_Items_Update();
2244 g_Triggers_Update();
2245 g_Weapon_Update();
2246 g_Monsters_Update();
2247 g_GFX_Update();
2248 g_Player_UpdateAll();
2249 g_Player_UpdatePhysicalObjects();
2251 // server: send newly spawned monsters unconditionally
2252 if (gGameSettings.GameType = GT_SERVER) then
2253 begin
2254 if (Length(gMonstersSpawned) > 0) then
2255 begin
2256 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2257 SetLength(gMonstersSpawned, 0);
2258 end;
2259 end;
2261 if (gSoundTriggerTime > 8) then
2262 begin
2263 g_Game_UpdateTriggerSounds();
2264 gSoundTriggerTime := 0;
2265 end
2266 else
2267 begin
2268 Inc(gSoundTriggerTime);
2269 end;
2271 if (NetMode = NET_SERVER) then
2272 begin
2273 Inc(NetTimeToUpdate);
2274 Inc(NetTimeToReliable);
2276 // send monster updates
2277 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2278 begin
2279 // send all monsters (periodic sync)
2280 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2282 for I := 0 to High(gPlayers) do
2283 begin
2284 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2285 end;
2287 g_Mons_ForEach(sendMonsPos);
2289 if reliableUpdate then
2290 begin
2291 NetTimeToReliable := 0;
2292 NetTimeToUpdate := NetUpdateRate;
2293 end
2294 else
2295 begin
2296 NetTimeToUpdate := 0;
2297 end;
2298 end
2299 else
2300 begin
2301 // send only mosters with some unexpected changes
2302 g_Mons_ForEach(sendMonsPosUnexpected);
2303 end;
2305 // send unexpected platform changes
2306 g_Map_NetSendInterestingPanels();
2308 g_Net_Slist_ServerUpdate();
2310 if NetUseMaster then
2311 begin
2312 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2313 begin
2314 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2315 g_Net_Slist_Update;
2316 NetTimeToMaster := gTime + NetMasterRate;
2317 end;
2318 end;
2320 end
2321 else if (NetMode = NET_CLIENT) then
2322 begin
2323 MC_SEND_PlayerPos();
2324 end;
2325 end; // if gameOn ...
2327 // Активно окно интерфейса - передаем клавиши ему:
2328 if g_ActiveWindow <> nil then
2329 begin
2330 w := e_GetFirstKeyPressed();
2332 if (w <> IK_INVALID) then
2333 begin
2334 Msg.Msg := MESSAGE_DIKEY;
2335 Msg.wParam := w;
2336 g_ActiveWindow.OnMessage(Msg);
2337 end;
2339 // Если оно от этого не закрылось, то обновляем:
2340 if g_ActiveWindow <> nil then
2341 g_ActiveWindow.Update();
2343 // Нужно сменить разрешение:
2344 if gResolutionChange then
2345 begin
2346 e_WriteLog('Changing resolution', TMsgType.Notify);
2347 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2348 gResolutionChange := False;
2349 g_ActiveWindow := nil;
2350 end;
2352 // Нужно сменить язык:
2353 if gLanguageChange then
2354 begin
2355 //e_WriteLog('Read language file', MSG_NOTIFY);
2356 //g_Language_Load(DataDir + gLanguage + '.txt');
2357 g_Language_Set(gLanguage);
2358 {$IFNDEF HEADLESS}
2359 g_Menu_Reset();
2360 {$ENDIF}
2361 gLanguageChange := False;
2362 end;
2363 end;
2365 // Горячая клавиша для вызова меню выхода из игры (F10):
2366 if e_KeyPressed(IK_F10) and
2367 gGameOn and
2368 (not gConsoleShow) and
2369 (g_ActiveWindow = nil) then
2370 begin
2371 KeyPress(IK_F10);
2372 end;
2374 Time := sys_GetTicks() {div 1000};
2376 // Обработка отложенных событий:
2377 if gDelayedEvents <> nil then
2378 for a := 0 to High(gDelayedEvents) do
2379 if gDelayedEvents[a].Pending and
2381 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2382 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2383 ) then
2384 begin
2385 case gDelayedEvents[a].DEType of
2386 DE_GLOBEVENT:
2387 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2388 DE_BFGHIT:
2389 if gGameOn then
2390 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2391 DE_KILLCOMBO:
2392 if gGameOn then
2393 begin
2394 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2395 if g_Game_IsNet and g_Game_IsServer then
2396 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2397 end;
2398 DE_BODYKILL:
2399 if gGameOn then
2400 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2401 end;
2402 gDelayedEvents[a].Pending := False;
2403 end;
2405 // Каждую секунду обновляем счетчик обновлений:
2406 UPSCounter := UPSCounter + 1;
2407 if Time - UPSTime >= 1000 then
2408 begin
2409 UPS := UPSCounter;
2410 UPSCounter := 0;
2411 UPSTime := Time;
2412 end;
2414 if gGameOn then
2415 begin
2416 g_Weapon_AddDynLights();
2417 g_Items_AddDynLights();
2418 end;
2419 end;
2421 procedure g_Game_LoadChatSounds(Resource: string);
2422 var
2423 WAD: TWADFile;
2424 FileName, Snd: string;
2425 p: Pointer;
2426 len, cnt, tags, i, j: Integer;
2427 cfg: TConfig;
2428 begin
2429 FileName := g_ExtractWadName(Resource);
2431 WAD := TWADFile.Create();
2432 WAD.ReadFile(FileName);
2434 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2435 begin
2436 gChatSounds := nil;
2437 WAD.Free();
2438 Exit;
2439 end;
2441 cfg := TConfig.CreateMem(p, len);
2442 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2444 SetLength(gChatSounds, cnt);
2445 for i := 0 to Length(gChatSounds) - 1 do
2446 begin
2447 gChatSounds[i].Sound := nil;
2448 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2449 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2450 if (Snd = '') or (Tags <= 0) then
2451 continue;
2452 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2453 gChatSounds[i].Sound := TPlayableSound.Create();
2454 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2455 SetLength(gChatSounds[i].Tags, tags);
2456 for j := 0 to tags - 1 do
2457 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2458 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2459 end;
2461 cfg.Free();
2462 WAD.Free();
2463 end;
2465 procedure g_Game_FreeChatSounds();
2466 var
2467 i: Integer;
2468 begin
2469 for i := 0 to Length(gChatSounds) - 1 do
2470 begin
2471 gChatSounds[i].Sound.Free();
2472 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2473 end;
2474 SetLength(gChatSounds, 0);
2475 gChatSounds := nil;
2476 end;
2478 procedure g_Game_LoadData();
2479 var
2480 wl, hl: Integer;
2481 wr, hr: Integer;
2482 wb, hb: Integer;
2483 wm, hm: Integer;
2484 begin
2485 if DataLoaded then Exit;
2487 e_WriteLog('Loading game data...', TMsgType.Notify);
2489 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2494 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2495 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2496 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2497 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2498 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2499 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2500 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2501 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2502 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2503 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2505 hasPBarGfx := true;
2506 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2507 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2508 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2509 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2511 if hasPBarGfx then
2512 begin
2513 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2514 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2515 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2516 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2517 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
2518 begin
2519 // yay!
2520 end
2521 else
2522 begin
2523 hasPBarGfx := false;
2524 end;
2525 end;
2527 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2528 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2529 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2530 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2531 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2532 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2533 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2534 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2535 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2536 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2537 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2538 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2539 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2540 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2541 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2542 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2543 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2544 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2545 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2546 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2547 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2548 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2549 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2550 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2551 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2552 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2553 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2554 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2555 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2556 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2557 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2558 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2559 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2560 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2561 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2562 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2563 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2564 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2565 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2567 goodsnd[0] := TPlayableSound.Create();
2568 goodsnd[1] := TPlayableSound.Create();
2569 goodsnd[2] := TPlayableSound.Create();
2570 goodsnd[3] := TPlayableSound.Create();
2572 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2573 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2574 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2575 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2577 killsnd[0] := TPlayableSound.Create();
2578 killsnd[1] := TPlayableSound.Create();
2579 killsnd[2] := TPlayableSound.Create();
2580 killsnd[3] := TPlayableSound.Create();
2582 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2583 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2584 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2585 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2587 hahasnd[0] := TPlayableSound.Create();
2588 hahasnd[1] := TPlayableSound.Create();
2589 hahasnd[2] := TPlayableSound.Create();
2591 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2592 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2593 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2595 sound_get_flag[0] := TPlayableSound.Create();
2596 sound_get_flag[1] := TPlayableSound.Create();
2597 sound_lost_flag[0] := TPlayableSound.Create();
2598 sound_lost_flag[1] := TPlayableSound.Create();
2599 sound_ret_flag[0] := TPlayableSound.Create();
2600 sound_ret_flag[1] := TPlayableSound.Create();
2601 sound_cap_flag[0] := TPlayableSound.Create();
2602 sound_cap_flag[1] := TPlayableSound.Create();
2604 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2605 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2606 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2607 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2608 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2609 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2610 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2611 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2613 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2615 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2616 g_Items_LoadData();
2618 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2619 g_Weapon_LoadData();
2621 g_Monsters_LoadData();
2623 DataLoaded := True;
2624 end;
2626 procedure g_Game_Quit();
2627 begin
2628 g_Game_StopAllSounds(True);
2629 gMusic.Free();
2630 g_Game_FreeData();
2631 r_PlayerModel_Finalize;
2632 g_PlayerModel_FreeData();
2633 g_Texture_DeleteAll();
2634 g_Frames_DeleteAll();
2635 {$IFNDEF HEADLESS}
2636 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2637 {$ENDIF}
2639 if NetInitDone then g_Net_Free;
2641 // remove map after test
2642 if gMapToDelete <> '' then
2643 g_Game_DeleteTestMap();
2645 gExit := EXIT_QUIT;
2646 sys_RequestQuit;
2647 end;
2649 procedure g_Game_FreeData();
2650 begin
2651 if not DataLoaded then Exit;
2653 g_Items_FreeData();
2654 g_Weapon_FreeData();
2655 g_Monsters_FreeData();
2657 e_WriteLog('Releasing game data...', TMsgType.Notify);
2659 g_Texture_Delete('NOTEXTURE');
2660 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2661 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2662 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2663 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2664 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2665 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2666 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2667 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2668 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2669 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2670 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2671 g_Frames_DeleteByName('FRAMES_TELEPORT');
2672 g_Frames_DeleteByName('FRAMES_PUNCH');
2673 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2674 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2675 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2676 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2677 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2678 g_Sound_Delete('SOUND_GAME_TELEPORT');
2679 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2680 g_Sound_Delete('SOUND_GAME_SECRET');
2681 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2682 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2683 g_Sound_Delete('SOUND_GAME_BULK1');
2684 g_Sound_Delete('SOUND_GAME_BULK2');
2685 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2686 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2687 g_Sound_Delete('SOUND_GAME_BURNING');
2688 g_Sound_Delete('SOUND_GAME_SWITCH1');
2689 g_Sound_Delete('SOUND_GAME_SWITCH0');
2691 goodsnd[0].Free();
2692 goodsnd[1].Free();
2693 goodsnd[2].Free();
2694 goodsnd[3].Free();
2696 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2697 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2698 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2699 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2701 killsnd[0].Free();
2702 killsnd[1].Free();
2703 killsnd[2].Free();
2704 killsnd[3].Free();
2706 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2707 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2708 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2709 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2711 hahasnd[0].Free();
2712 hahasnd[1].Free();
2713 hahasnd[2].Free();
2715 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2716 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2717 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2719 sound_get_flag[0].Free();
2720 sound_get_flag[1].Free();
2721 sound_lost_flag[0].Free();
2722 sound_lost_flag[1].Free();
2723 sound_ret_flag[0].Free();
2724 sound_ret_flag[1].Free();
2725 sound_cap_flag[0].Free();
2726 sound_cap_flag[1].Free();
2728 g_Sound_Delete('SOUND_CTF_GET1');
2729 g_Sound_Delete('SOUND_CTF_GET2');
2730 g_Sound_Delete('SOUND_CTF_LOST1');
2731 g_Sound_Delete('SOUND_CTF_LOST2');
2732 g_Sound_Delete('SOUND_CTF_RETURN1');
2733 g_Sound_Delete('SOUND_CTF_RETURN2');
2734 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2735 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2737 g_Game_FreeChatSounds();
2739 DataLoaded := False;
2740 end;
2742 procedure g_FatalError(Text: String);
2743 begin
2744 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2745 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2747 gExit := EXIT_SIMPLE;
2748 if gGameOn then EndGame;
2749 end;
2751 procedure g_SimpleError(Text: String);
2752 begin
2753 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2754 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2755 end;
2757 procedure g_Game_SetupScreenSize();
2758 const
2759 RES_FACTOR = 4.0 / 3.0;
2760 var
2761 s: Single;
2762 rf: Single;
2763 bw, bh: Word;
2764 begin
2765 // Размер экранов игроков:
2766 gPlayerScreenSize.X := gScreenWidth-196;
2767 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
2768 gPlayerScreenSize.Y := gScreenHeight div 2
2769 else
2770 gPlayerScreenSize.Y := gScreenHeight;
2772 // Размер заднего плана:
2773 if BackID <> DWORD(-1) then
2774 begin
2775 s := SKY_STRETCH;
2776 if (gScreenWidth*s > gMapInfo.Width) or
2777 (gScreenHeight*s > gMapInfo.Height) then
2778 begin
2779 gBackSize.X := gScreenWidth;
2780 gBackSize.Y := gScreenHeight;
2781 end
2782 else
2783 begin
2784 e_GetTextureSize(BackID, @bw, @bh);
2785 rf := Single(bw) / Single(bh);
2786 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
2787 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
2788 s := Max(gScreenWidth / bw, gScreenHeight / bh);
2789 if (s < 1.0) then s := 1.0;
2790 gBackSize.X := Round(bw*s);
2791 gBackSize.Y := Round(bh*s);
2792 end;
2793 end;
2794 end;
2796 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
2797 begin
2798 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
2799 end;
2801 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2802 begin
2803 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2804 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2805 Exit;
2807 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2808 Exit;
2810 if gPlayer1 = nil then
2811 begin
2812 if g_Game_IsClient then
2813 begin
2814 if NetPlrUID1 > -1 then
2815 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2816 Exit;
2817 end;
2819 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2820 Team := gPlayer1Settings.Team;
2822 // Создание первого игрока:
2823 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2824 gPlayer1Settings.Color,
2825 Team, False));
2826 if gPlayer1 = nil then
2827 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2828 else
2829 begin
2830 gPlayer1.Name := gPlayer1Settings.Name;
2831 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2832 if g_Game_IsServer and g_Game_IsNet then
2833 MH_SEND_PlayerCreate(gPlayer1.UID);
2834 gPlayer1.Respawn(False, True);
2835 g_Net_Slist_ServerPlayerComes();
2836 end;
2838 Exit;
2839 end;
2840 if gPlayer2 = nil then
2841 begin
2842 if g_Game_IsClient then
2843 begin
2844 if NetPlrUID2 > -1 then
2845 gPlayer2 := g_Player_Get(NetPlrUID2);
2846 Exit;
2847 end;
2849 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2850 Team := gPlayer2Settings.Team;
2852 // Создание второго игрока:
2853 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2854 gPlayer2Settings.Color,
2855 Team, False));
2856 if gPlayer2 = nil then
2857 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2858 else
2859 begin
2860 gPlayer2.Name := gPlayer2Settings.Name;
2861 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2862 if g_Game_IsServer and g_Game_IsNet then
2863 MH_SEND_PlayerCreate(gPlayer2.UID);
2864 gPlayer2.Respawn(False, True);
2865 g_Net_Slist_ServerPlayerComes();
2866 end;
2868 Exit;
2869 end;
2870 end;
2872 procedure g_Game_RemovePlayer();
2873 var
2874 Pl: TPlayer;
2875 begin
2876 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2877 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2878 Exit;
2879 Pl := gPlayer2;
2880 if Pl <> nil then
2881 begin
2882 if g_Game_IsServer then
2883 begin
2884 Pl.Lives := 0;
2885 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2886 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2887 g_Player_Remove(Pl.UID);
2888 g_Net_Slist_ServerPlayerLeaves();
2889 end
2890 else
2891 begin
2892 gSpectLatchPID2 := Pl.UID;
2893 gPlayer2 := nil;
2894 end;
2895 Exit;
2896 end;
2897 Pl := gPlayer1;
2898 if Pl <> nil then
2899 begin
2900 if g_Game_IsServer then
2901 begin
2902 Pl.Lives := 0;
2903 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2904 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2905 g_Player_Remove(Pl.UID);
2906 g_Net_Slist_ServerPlayerLeaves();
2907 end else
2908 begin
2909 gSpectLatchPID1 := Pl.UID;
2910 gPlayer1 := nil;
2911 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2912 end;
2913 Exit;
2914 end;
2915 g_Net_Slist_ServerPlayerLeaves();
2916 end;
2918 procedure g_Game_Spectate();
2919 begin
2920 g_Game_RemovePlayer();
2921 if gPlayer1 <> nil then
2922 g_Game_RemovePlayer();
2923 end;
2925 procedure g_Game_SpectateCenterView();
2926 begin
2927 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2928 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2929 end;
2931 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2932 var
2933 i, nPl: Integer;
2934 tmps: AnsiString;
2935 begin
2936 g_Game_Free();
2938 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2940 g_Game_ClearLoading();
2942 // Настройки игры:
2943 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2944 gAimLine := False;
2945 gShowMap := False;
2946 gGameSettings.GameType := GT_SINGLE;
2947 gGameSettings.MaxLives := 0;
2948 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2949 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2950 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2951 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2952 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2953 gSwitchGameMode := GM_SINGLE;
2955 gLMSRespawn := LMS_RESPAWN_NONE;
2956 gLMSRespawnTime := 0;
2957 gSpectLatchPID1 := 0;
2958 gSpectLatchPID2 := 0;
2960 g_Game_ExecuteEvent('ongamestart');
2962 // Установка размеров окон игроков:
2963 g_Game_SetupScreenSize();
2965 // Создание первого игрока:
2966 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2967 gPlayer1Settings.Color,
2968 gPlayer1Settings.Team, False));
2969 if gPlayer1 = nil then
2970 begin
2971 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2972 Exit;
2973 end;
2975 gPlayer1.Name := gPlayer1Settings.Name;
2976 nPl := 1;
2978 // Создание второго игрока, если есть:
2979 if TwoPlayers then
2980 begin
2981 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2982 gPlayer2Settings.Color,
2983 gPlayer2Settings.Team, False));
2984 if gPlayer2 = nil then
2985 begin
2986 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2987 Exit;
2988 end;
2990 gPlayer2.Name := gPlayer2Settings.Name;
2991 Inc(nPl);
2992 end;
2994 // Загрузка и запуск карты:
2995 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2996 begin
2997 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2998 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2999 Exit;
3000 end;
3002 // Настройки игроков и ботов:
3003 g_Player_Init();
3005 // Создаем ботов:
3006 for i := nPl+1 to nPlayers do
3007 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3008 end;
3010 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
3011 TimeLimit, GoalLimit: Word;
3012 MaxLives: Byte;
3013 Options: LongWord; nPlayers: Byte);
3014 var
3015 i, nPl: Integer;
3016 begin
3017 g_Game_Free();
3019 e_WriteLog('Starting custom game...', TMsgType.Notify);
3021 g_Game_ClearLoading();
3023 // Настройки игры:
3024 gGameSettings.GameType := GT_CUSTOM;
3025 gGameSettings.GameMode := GameMode;
3026 gSwitchGameMode := GameMode;
3027 gGameSettings.TimeLimit := TimeLimit;
3028 gGameSettings.GoalLimit := GoalLimit;
3029 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3030 gGameSettings.Options := Options;
3032 gCoopTotalMonstersKilled := 0;
3033 gCoopTotalSecretsFound := 0;
3034 gCoopTotalMonsters := 0;
3035 gCoopTotalSecrets := 0;
3036 gAimLine := False;
3037 gShowMap := False;
3039 gLMSRespawn := LMS_RESPAWN_NONE;
3040 gLMSRespawnTime := 0;
3041 gSpectLatchPID1 := 0;
3042 gSpectLatchPID2 := 0;
3044 g_Game_ExecuteEvent('ongamestart');
3046 // Установка размеров окон игроков:
3047 g_Game_SetupScreenSize();
3049 // Режим наблюдателя:
3050 if nPlayers = 0 then
3051 begin
3052 gPlayer1 := nil;
3053 gPlayer2 := nil;
3054 end;
3056 nPl := 0;
3057 if nPlayers >= 1 then
3058 begin
3059 // Создание первого игрока:
3060 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3061 gPlayer1Settings.Color,
3062 gPlayer1Settings.Team, False));
3063 if gPlayer1 = nil then
3064 begin
3065 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3066 Exit;
3067 end;
3069 gPlayer1.Name := gPlayer1Settings.Name;
3070 Inc(nPl);
3071 end;
3073 if nPlayers >= 2 then
3074 begin
3075 // Создание второго игрока:
3076 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3077 gPlayer2Settings.Color,
3078 gPlayer2Settings.Team, False));
3079 if gPlayer2 = nil then
3080 begin
3081 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3082 Exit;
3083 end;
3085 gPlayer2.Name := gPlayer2Settings.Name;
3086 Inc(nPl);
3087 end;
3089 // Загрузка и запуск карты:
3090 if not g_Game_StartMap(true{asMegawad}, Map, True) then
3091 begin
3092 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3093 Exit;
3094 end;
3096 // Нет точек появления:
3097 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3098 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3099 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3100 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3101 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3102 begin
3103 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3104 Exit;
3105 end;
3107 // Настройки игроков и ботов:
3108 g_Player_Init();
3110 // Создаем ботов:
3111 for i := nPl+1 to nPlayers do
3112 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3113 end;
3115 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3116 TimeLimit, GoalLimit: Word; MaxLives: Byte;
3117 Options: LongWord; nPlayers: Byte;
3118 IPAddr: LongWord; Port: Word);
3119 begin
3120 g_Game_Free();
3121 g_Net_Slist_ServerClosed();
3123 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
3125 g_Game_ClearLoading();
3127 // Настройки игры:
3128 gGameSettings.GameType := GT_SERVER;
3129 gGameSettings.GameMode := GameMode;
3130 gSwitchGameMode := GameMode;
3131 gGameSettings.TimeLimit := TimeLimit;
3132 gGameSettings.GoalLimit := GoalLimit;
3133 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3134 gGameSettings.Options := Options;
3136 gCoopTotalMonstersKilled := 0;
3137 gCoopTotalSecretsFound := 0;
3138 gCoopTotalMonsters := 0;
3139 gCoopTotalSecrets := 0;
3140 gAimLine := False;
3141 gShowMap := False;
3143 gLMSRespawn := LMS_RESPAWN_NONE;
3144 gLMSRespawnTime := 0;
3145 gSpectLatchPID1 := 0;
3146 gSpectLatchPID2 := 0;
3148 g_Game_ExecuteEvent('ongamestart');
3150 // Установка размеров окна игрока
3151 g_Game_SetupScreenSize();
3153 // Режим наблюдателя:
3154 if nPlayers = 0 then
3155 begin
3156 gPlayer1 := nil;
3157 gPlayer2 := nil;
3158 end;
3160 if nPlayers >= 1 then
3161 begin
3162 // Создание первого игрока:
3163 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3164 gPlayer1Settings.Color,
3165 gPlayer1Settings.Team, False));
3166 if gPlayer1 = nil then
3167 begin
3168 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3169 Exit;
3170 end;
3172 gPlayer1.Name := gPlayer1Settings.Name;
3173 end;
3175 if nPlayers >= 2 then
3176 begin
3177 // Создание второго игрока:
3178 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3179 gPlayer2Settings.Color,
3180 gPlayer2Settings.Team, False));
3181 if gPlayer2 = nil then
3182 begin
3183 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3184 Exit;
3185 end;
3187 gPlayer2.Name := gPlayer2Settings.Name;
3188 end;
3190 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
3191 if NetForwardPorts then
3192 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
3194 // Стартуем сервер
3195 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3196 begin
3197 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
3198 Exit;
3199 end;
3201 g_Net_Slist_Set(NetMasterList);
3203 g_Net_Slist_ServerStarted();
3205 // Загрузка и запуск карты:
3206 if not g_Game_StartMap(false{asMegawad}, Map, True) then
3207 begin
3208 g_Net_Slist_ServerClosed();
3209 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3210 Exit;
3211 end;
3213 // Нет точек появления:
3214 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3215 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3216 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3217 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3218 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3219 begin
3220 g_Net_Slist_ServerClosed();
3221 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3222 Exit;
3223 end;
3225 // Настройки игроков и ботов:
3226 g_Player_Init();
3228 g_Net_Slist_ServerMapStarted();
3229 NetState := NET_STATE_GAME;
3230 end;
3232 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3233 var
3234 Map: String;
3235 WadName: string;
3236 Ptr: Pointer;
3237 T: Cardinal;
3238 MID: Byte;
3239 State: Byte;
3240 OuterLoop: Boolean;
3241 newResPath: string;
3242 InMsg: TMsg;
3243 begin
3244 g_Game_Free();
3246 State := 0;
3247 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
3248 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
3250 g_Game_ClearLoading();
3252 // Настройки игры:
3253 gGameSettings.GameType := GT_CLIENT;
3255 gCoopTotalMonstersKilled := 0;
3256 gCoopTotalSecretsFound := 0;
3257 gCoopTotalMonsters := 0;
3258 gCoopTotalSecrets := 0;
3259 gAimLine := False;
3260 gShowMap := False;
3262 g_Game_ExecuteEvent('ongamestart');
3264 // Установка размеров окон игроков:
3265 g_Game_SetupScreenSize();
3267 NetState := NET_STATE_AUTH;
3269 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3271 // create (or update) map/resource databases
3272 g_Res_CreateDatabases(true);
3274 gLMSRespawn := LMS_RESPAWN_NONE;
3275 gLMSRespawnTime := 0;
3276 gSpectLatchPID1 := 0;
3277 gSpectLatchPID2 := 0;
3279 // Стартуем клиент
3280 if not g_Net_Connect(Addr, Port) then
3281 begin
3282 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3283 NetState := NET_STATE_NONE;
3284 Exit;
3285 end;
3287 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3288 MC_SEND_Info(PW);
3289 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3291 OuterLoop := True;
3292 while OuterLoop do
3293 begin
3294 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3295 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3296 // thank you, enet. let's ignore failures altogether then.
3297 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3298 begin
3299 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3300 begin
3301 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
3302 begin
3303 // ignore all download packets, they're processed by separate code
3304 enet_packet_destroy(NetEvent.packet);
3305 continue;
3306 end;
3307 Ptr := NetEvent.packet^.data;
3308 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3309 begin
3310 enet_packet_destroy(NetEvent.packet);
3311 continue;
3312 end;
3314 InMsg.ReadLongWord(); // skip size
3315 MID := InMsg.ReadByte();
3317 if (MID = NET_MSG_INFO) and (State = 0) then
3318 begin
3319 NetMyID := InMsg.ReadByte();
3320 NetPlrUID1 := InMsg.ReadWord();
3322 WadName := InMsg.ReadString();
3323 Map := InMsg.ReadString();
3325 gWADHash := InMsg.ReadMD5();
3327 gGameSettings.GameMode := InMsg.ReadByte();
3328 gSwitchGameMode := gGameSettings.GameMode;
3329 gGameSettings.GoalLimit := InMsg.ReadWord();
3330 gGameSettings.TimeLimit := InMsg.ReadWord();
3331 gGameSettings.MaxLives := InMsg.ReadByte();
3332 gGameSettings.Options := InMsg.ReadLongWord();
3333 T := InMsg.ReadLongWord();
3335 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3336 //if newResPath = '' then
3337 begin
3338 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3339 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3340 if newResPath = '' then
3341 begin
3342 g_FatalError(_lc[I_NET_ERR_HASH]);
3343 enet_packet_destroy(NetEvent.packet);
3344 NetState := NET_STATE_NONE;
3345 Exit;
3346 end;
3347 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3348 end;
3349 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3352 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3353 gPlayer1Settings.Color,
3354 gPlayer1Settings.Team, False));
3356 if gPlayer1 = nil then
3357 begin
3358 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3360 enet_packet_destroy(NetEvent.packet);
3361 NetState := NET_STATE_NONE;
3362 Exit;
3363 end;
3365 gPlayer1.Name := gPlayer1Settings.Name;
3366 gPlayer1.UID := NetPlrUID1;
3367 gPlayer1.Reset(True);
3369 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3370 begin
3371 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3373 enet_packet_destroy(NetEvent.packet);
3374 NetState := NET_STATE_NONE;
3375 Exit;
3376 end;
3378 gTime := T;
3380 State := 1;
3381 OuterLoop := False;
3382 enet_packet_destroy(NetEvent.packet);
3383 break;
3384 end
3385 else
3386 enet_packet_destroy(NetEvent.packet);
3387 end
3388 else
3389 begin
3390 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3391 begin
3392 State := 0;
3393 if (NetEvent.data <= NET_DISC_MAX) then
3394 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3395 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3396 OuterLoop := False;
3397 Break;
3398 end;
3399 end;
3400 end;
3402 ProcessLoading(true);
3404 if g_Net_UserRequestExit() then
3405 begin
3406 State := 0;
3407 break;
3408 end;
3409 end;
3411 if State <> 1 then
3412 begin
3413 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3414 NetState := NET_STATE_NONE;
3415 Exit;
3416 end;
3418 g_Player_Init();
3419 NetState := NET_STATE_GAME;
3420 MC_SEND_FullStateRequest;
3421 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3422 end;
3424 var
3425 lastAsMegaWad: Boolean = false;
3427 procedure g_Game_ChangeMap(const MapPath: String);
3428 var
3429 Force: Boolean;
3430 begin
3431 g_Game_ClearLoading();
3433 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3434 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3435 if gExitByTrigger then
3436 begin
3437 Force := False;
3438 gExitByTrigger := False;
3439 end;
3440 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3441 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3442 end;
3444 procedure g_Game_Restart();
3445 var
3446 Map: string;
3447 begin
3448 if g_Game_IsClient then
3449 Exit;
3450 map := g_ExtractFileName(gMapInfo.Map);
3451 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3453 MessageTime := 0;
3454 gGameOn := False;
3455 g_Game_ClearLoading();
3456 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3457 end;
3459 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3460 var
3461 NewWAD, ResName: String;
3462 I: Integer;
3463 nws: AnsiString;
3464 begin
3465 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3466 g_Player_RemoveAllCorpses();
3468 if (not g_Game_IsClient) and
3469 (gSwitchGameMode <> gGameSettings.GameMode) and
3470 (gGameSettings.GameMode <> GM_SINGLE) then
3471 begin
3472 if gSwitchGameMode = GM_CTF then
3473 gGameSettings.MaxLives := 0;
3474 gGameSettings.GameMode := gSwitchGameMode;
3475 Force := True;
3476 end else
3477 gSwitchGameMode := gGameSettings.GameMode;
3479 g_Player_ResetTeams();
3481 lastAsMegaWad := asMegawad;
3482 if isWadPath(Map) then
3483 begin
3484 NewWAD := g_ExtractWadName(Map);
3485 ResName := g_ExtractFileName(Map);
3486 if g_Game_IsServer then
3487 begin
3488 nws := findDiskWad(NewWAD);
3489 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3490 if (asMegawad) then
3491 begin
3492 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3493 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3494 end
3495 else
3496 begin
3497 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3498 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3499 end;
3500 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3501 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3502 //nws := NewWAD;
3503 if (length(nws) = 0) then
3504 begin
3505 ResName := ''; // failed
3506 end
3507 else
3508 begin
3509 NewWAD := nws;
3510 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3511 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3512 g_Game_LoadWAD(NewWAD);
3513 end;
3514 end
3515 else
3516 begin
3517 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3518 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3519 end;
3520 end
3521 else
3522 begin
3523 NewWAD := gGameSettings.WAD;
3524 ResName := Map;
3525 end;
3527 gTime := 0;
3529 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3530 result := false;
3531 if (ResName <> '') and (NewWAD <> '') then
3532 begin
3533 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3534 result := g_Map_Load(NewWAD+':\'+ResName);
3535 end;
3536 if Result then
3537 begin
3538 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3540 gState := STATE_NONE;
3541 g_ActiveWindow := nil;
3542 gGameOn := True;
3544 DisableCheats();
3545 ResetTimer();
3547 if gGameSettings.GameMode = GM_CTF then
3548 begin
3549 g_Map_ResetFlag(FLAG_RED);
3550 g_Map_ResetFlag(FLAG_BLUE);
3551 // CTF, а флагов нет:
3552 if not g_Map_HaveFlagPoints() then
3553 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3554 end;
3555 end
3556 else
3557 begin
3558 gState := STATE_MENU;
3559 gGameOn := False;
3560 end;
3562 gExit := 0;
3563 gPauseMain := false;
3564 gPauseHolmes := false;
3565 NetTimeToUpdate := 1;
3566 NetTimeToReliable := 0;
3567 NetTimeToMaster := NetMasterRate;
3568 gSpectLatchPID1 := 0;
3569 gSpectLatchPID2 := 0;
3570 gMissionFailed := False;
3571 gNextMap := '';
3573 gCoopMonstersKilled := 0;
3574 gCoopSecretsFound := 0;
3576 gVoteInProgress := False;
3577 gVotePassed := False;
3578 gVoteCount := 0;
3579 gVoted := False;
3581 gStatsOff := False;
3583 if not gGameOn then Exit;
3585 g_Game_SpectateCenterView();
3587 if g_Game_IsServer then
3588 begin
3589 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3590 begin
3591 gLMSRespawn := LMS_RESPAWN_WARMUP;
3592 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3593 gLMSSoftSpawn := True;
3594 if g_Game_IsNet then
3595 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3596 end
3597 else
3598 begin
3599 gLMSRespawn := LMS_RESPAWN_NONE;
3600 gLMSRespawnTime := 0;
3601 end;
3602 end;
3604 if NetMode = NET_SERVER then
3605 begin
3606 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3608 // Мастерсервер
3609 g_Net_Slist_ServerMapStarted();
3611 if NetClients <> nil then
3612 for I := 0 to High(NetClients) do
3613 if NetClients[I].Used then
3614 begin
3615 NetClients[I].Voted := False;
3616 if NetClients[I].RequestedFullUpdate then
3617 begin
3618 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3619 NetClients[I].RequestedFullUpdate := False;
3620 end;
3621 end;
3623 g_Net_UnbanNonPermHosts();
3624 end;
3626 if gLastMap then
3627 begin
3628 gCoopTotalMonstersKilled := 0;
3629 gCoopTotalSecretsFound := 0;
3630 gCoopTotalMonsters := 0;
3631 gCoopTotalSecrets := 0;
3632 gLastMap := False;
3633 end;
3635 g_Game_ExecuteEvent('onmapstart');
3636 end;
3638 procedure SetFirstLevel;
3639 begin
3640 gNextMap := '';
3642 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3643 if MapList = nil then
3644 Exit;
3646 SortSArray(MapList);
3647 gNextMap := MapList[Low(MapList)];
3649 MapList := nil;
3650 end;
3652 procedure g_Game_ExitLevel(const Map: AnsiString);
3653 begin
3654 gNextMap := Map;
3656 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3657 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3658 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3659 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3661 // Вышли в выход в Одиночной игре:
3662 if gGameSettings.GameType = GT_SINGLE then
3663 gExit := EXIT_ENDLEVELSINGLE
3664 else // Вышли в выход в Своей игре
3665 begin
3666 gExit := EXIT_ENDLEVELCUSTOM;
3667 if gGameSettings.GameMode = GM_COOP then
3668 g_Player_RememberAll;
3670 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3671 begin
3672 gLastMap := True;
3673 if gGameSettings.GameMode = GM_COOP then
3674 gStatsOff := True;
3676 gStatsPressed := True;
3677 gNextMap := 'MAP01';
3679 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3680 g_Game_NextLevel;
3682 if g_Game_IsNet then
3683 begin
3684 MH_SEND_GameStats();
3685 MH_SEND_CoopStats();
3686 end;
3687 end;
3688 end;
3689 end;
3691 procedure g_Game_RestartLevel();
3692 var
3693 Map: string;
3694 begin
3695 if gGameSettings.GameMode = GM_SINGLE then
3696 begin
3697 g_Game_Restart();
3698 Exit;
3699 end;
3700 gExit := EXIT_ENDLEVELCUSTOM;
3701 Map := g_ExtractFileName(gMapInfo.Map);
3702 gNextMap := Map;
3703 end;
3705 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3706 var
3707 gWAD{, xwad}: String;
3708 begin
3709 result := NewWAD;
3710 if not g_Game_IsClient then Exit;
3711 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3713 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3714 if gWAD = '' then
3715 begin
3716 result := '';
3717 g_Game_Free();
3718 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3719 Exit;
3720 end;
3722 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3723 NewWAD := gWAD;
3725 g_Game_LoadWAD(NewWAD);
3726 result := NewWAD;
3729 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3730 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3731 if gWAD = '' then
3732 begin
3733 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3734 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3735 if gWAD = '' then
3736 begin
3737 g_Game_Free();
3738 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3739 Exit;
3740 end;
3741 end;
3742 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3743 g_Game_LoadWAD(NewWAD);
3745 end;
3747 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3748 var
3749 i, n, nb, nr: Integer;
3750 begin
3751 if not g_Game_IsServer then Exit;
3752 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3753 gLMSRespawn := LMS_RESPAWN_NONE;
3754 gLMSRespawnTime := 0;
3755 MessageTime := 0;
3757 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3758 begin
3759 gMissionFailed := True;
3760 g_Game_RestartLevel;
3761 Exit;
3762 end;
3764 n := 0; nb := 0; nr := 0;
3765 for i := Low(gPlayers) to High(gPlayers) do
3766 if (gPlayers[i] <> nil) and
3767 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3768 (gPlayers[i] is TBot)) then
3769 begin
3770 Inc(n);
3771 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3772 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3773 end;
3775 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3776 begin
3777 // wait a second until the fuckers finally decide to join
3778 gLMSRespawn := LMS_RESPAWN_WARMUP;
3779 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3780 gLMSSoftSpawn := NoMapRestart;
3781 if g_Game_IsNet then
3782 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3783 Exit;
3784 end;
3786 g_Player_RemoveAllCorpses;
3787 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3788 if g_Game_IsNet then
3789 MH_SEND_GameEvent(NET_EV_LMS_START);
3791 for i := Low(gPlayers) to High(gPlayers) do
3792 begin
3793 if gPlayers[i] = nil then continue;
3794 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3795 // don't touch normal spectators
3796 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3797 begin
3798 gPlayers[i].FNoRespawn := True;
3799 gPlayers[i].Lives := 0;
3800 if g_Game_IsNet then
3801 MH_SEND_PlayerStats(gPlayers[I].UID);
3802 continue;
3803 end;
3804 gPlayers[i].FNoRespawn := False;
3805 gPlayers[i].Lives := gGameSettings.MaxLives;
3806 gPlayers[i].Respawn(False, True);
3807 if gGameSettings.GameMode = GM_COOP then
3808 begin
3809 gPlayers[i].Frags := 0;
3810 gPlayers[i].RecallState;
3811 end;
3812 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3813 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3814 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3815 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3816 end;
3818 g_Items_RestartRound();
3820 gLMSSoftSpawn := False;
3821 end;
3823 function g_Game_GetFirstMap(WAD: String): String;
3824 begin
3825 Result := '';
3827 MapList := g_Map_GetMapsList(WAD);
3828 if MapList = nil then
3829 Exit;
3831 SortSArray(MapList);
3832 Result := MapList[Low(MapList)];
3834 if not g_Map_Exist(WAD + ':\' + Result) then
3835 Result := '';
3837 MapList := nil;
3838 end;
3840 function g_Game_GetNextMap(): String;
3841 var
3842 I: Integer;
3843 Map: string;
3844 begin
3845 Result := '';
3847 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3848 if MapList = nil then
3849 Exit;
3851 Map := g_ExtractFileName(gMapInfo.Map);
3853 SortSArray(MapList);
3854 MapIndex := -255;
3855 for I := Low(MapList) to High(MapList) do
3856 if Map = MapList[I] then
3857 begin
3858 MapIndex := I;
3859 Break;
3860 end;
3862 if MapIndex <> -255 then
3863 begin
3864 if MapIndex = High(MapList) then
3865 Result := MapList[Low(MapList)]
3866 else
3867 Result := MapList[MapIndex + 1];
3869 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3870 end;
3872 MapList := nil;
3873 end;
3875 procedure g_Game_NextLevel();
3876 begin
3877 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3878 gExit := EXIT_ENDLEVELCUSTOM
3879 else
3880 begin
3881 gExit := EXIT_ENDLEVELSINGLE;
3882 Exit;
3883 end;
3885 if gNextMap <> '' then Exit;
3886 gNextMap := g_Game_GetNextMap();
3887 end;
3889 function g_Game_IsTestMap(): Boolean;
3890 begin
3891 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3892 end;
3894 procedure g_Game_DeleteTestMap();
3895 var
3896 a: Integer;
3897 //MapName: AnsiString;
3898 WadName: string;
3900 WAD: TWADFile;
3901 MapList: SSArray;
3902 time: Integer;
3904 begin
3905 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3906 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3907 if (a = 0) then exit;
3909 // Выделяем имя wad-файла и имя карты
3910 WadName := Copy(gMapToDelete, 1, a+3);
3911 Delete(gMapToDelete, 1, a+5);
3912 gMapToDelete := UpperCase(gMapToDelete);
3913 //MapName := '';
3914 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3917 // Имя карты не стандартное тестовое:
3918 if MapName <> TEST_MAP_NAME then
3919 Exit;
3921 if not gTempDelete then
3922 begin
3923 time := g_GetFileTime(WadName);
3924 WAD := TWADFile.Create();
3926 // Читаем Wad-файл:
3927 if not WAD.ReadFile(WadName) then
3928 begin // Нет такого WAD-файла
3929 WAD.Free();
3930 Exit;
3931 end;
3933 // Составляем список карт и ищем нужную:
3934 WAD.CreateImage();
3935 MapList := WAD.GetResourcesList('');
3937 if MapList <> nil then
3938 for a := 0 to High(MapList) do
3939 if MapList[a] = MapName then
3940 begin
3941 // Удаляем и сохраняем:
3942 WAD.RemoveResource('', MapName);
3943 WAD.SaveTo(WadName);
3944 Break;
3945 end;
3947 WAD.Free();
3948 g_SetFileTime(WadName, time);
3949 end else
3951 if gTempDelete then DeleteFile(WadName);
3952 end;
3954 procedure GameCVars(P: SSArray);
3955 var
3956 a, b: Integer;
3957 stat: TPlayerStatArray;
3958 cmd: string;
3960 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3961 var
3962 x: Boolean;
3963 begin
3964 if Length(P) > 1 then
3965 begin
3966 x := P[1] = '1';
3968 if x then
3969 gsGameFlags := gsGameFlags or Flag
3970 else
3971 gsGameFlags := gsGameFlags and (not Flag);
3973 if g_Game_IsServer then
3974 begin
3975 if x then
3976 gGameSettings.Options := gGameSettings.Options or Flag
3977 else
3978 gGameSettings.Options := gGameSettings.Options and (not Flag);
3979 if g_Game_IsNet then MH_SEND_GameSettings;
3980 end;
3981 end;
3983 if LongBool(gsGameFlags and Flag) then
3984 g_Console_Add(_lc[OnMsg])
3985 else
3986 g_Console_Add(_lc[OffMsg]);
3988 if OnMapChange and g_Game_IsServer then
3989 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3990 end;
3992 begin
3993 stat := nil;
3994 cmd := LowerCase(P[0]);
3996 if cmd = 'g_gamemode' then
3997 begin
3998 if (Length(P) > 1) then
3999 begin
4000 a := g_Game_TextToMode(P[1]);
4001 if a = GM_SINGLE then a := GM_COOP;
4002 gsGameMode := g_Game_ModeToText(a);
4003 if g_Game_IsServer then
4004 begin
4005 gSwitchGameMode := a;
4006 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4007 (gState = STATE_INTERSINGLE) then
4008 gSwitchGameMode := GM_SINGLE;
4009 if not gGameOn then
4010 gGameSettings.GameMode := gSwitchGameMode;
4011 end;
4012 end;
4014 if gSwitchGameMode = gGameSettings.GameMode then
4015 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4016 [g_Game_ModeToText(gGameSettings.GameMode)]))
4017 else
4018 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4019 [g_Game_ModeToText(gGameSettings.GameMode),
4020 g_Game_ModeToText(gSwitchGameMode)]));
4021 end
4022 else if cmd = 'g_friendlyfire' then
4023 begin
4024 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4025 end
4026 else if cmd = 'g_friendly_absorb_damage' then
4027 begin
4028 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4029 end
4030 else if cmd = 'g_friendly_hit_trace' then
4031 begin
4032 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4033 end
4034 else if cmd = 'g_friendly_hit_projectile' then
4035 begin
4036 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4037 end
4038 else if cmd = 'g_weaponstay' then
4039 begin
4040 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
4041 end
4042 else if cmd = 'g_allow_exit' then
4043 begin
4044 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
4045 end
4046 else if cmd = 'g_allow_monsters' then
4047 begin
4048 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
4049 end
4050 else if cmd = 'g_bot_vsplayers' then
4051 begin
4052 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
4053 end
4054 else if cmd = 'g_bot_vsmonsters' then
4055 begin
4056 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
4057 end
4058 else if cmd = 'g_dm_keys' then
4059 begin
4060 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
4061 end
4062 else if cmd = 'g_gameflags' then
4063 begin
4064 if Length(P) > 1 then
4065 begin
4066 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
4067 if g_Game_IsServer then
4068 begin
4069 gGameSettings.Options := gsGameFlags;
4070 if g_Game_IsNet then MH_SEND_GameSettings;
4071 end;
4072 end;
4074 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
4075 end
4076 else if cmd = 'g_warmup_time' then
4077 begin
4078 if Length(P) > 1 then
4079 begin
4080 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
4081 if g_Game_IsServer then
4082 begin
4083 gGameSettings.WarmupTime := gsWarmupTime;
4084 // extend warmup if it's already going
4085 if gLMSRespawn = LMS_RESPAWN_WARMUP then
4086 begin
4087 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
4088 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
4089 end;
4090 if g_Game_IsNet then MH_SEND_GameSettings;
4091 end;
4092 end;
4094 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
4095 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4096 end
4097 else if cmd = 'g_spawn_invul' then
4098 begin
4099 if Length(P) > 1 then
4100 begin
4101 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
4102 if g_Game_IsServer then
4103 begin
4104 gGameSettings.SpawnInvul := gsSpawnInvul;
4105 if g_Game_IsNet then MH_SEND_GameSettings;
4106 end;
4107 end;
4109 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
4110 end
4111 else if cmd = 'g_item_respawn_time' then
4112 begin
4113 if Length(P) > 1 then
4114 begin
4115 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
4116 if g_Game_IsServer then
4117 begin
4118 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
4119 if g_Game_IsNet then MH_SEND_GameSettings;
4120 end;
4121 end;
4123 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
4124 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4125 end
4126 else if cmd = 'sv_intertime' then
4127 begin
4128 if (Length(P) > 1) then
4129 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4131 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4132 end
4133 else if cmd = 'g_max_particles' then
4134 begin
4135 if Length(p) = 2 then
4136 begin
4137 a := Max(0, StrToInt(p[1]));
4138 g_GFX_SetMax(a)
4139 end
4140 else if Length(p) = 1 then
4141 begin
4142 e_LogWritefln('%s', [g_GFX_GetMax()])
4143 end
4144 else
4145 begin
4146 e_LogWritefln('usage: %s <n>', [cmd])
4147 end
4148 end
4149 else if cmd = 'g_max_shells' then
4150 begin
4151 if Length(p) = 2 then
4152 begin
4153 a := Max(0, StrToInt(p[1]));
4154 g_Shells_SetMax(a)
4155 end
4156 else if Length(p) = 1 then
4157 begin
4158 e_LogWritefln('%s', [g_Shells_GetMax()])
4159 end
4160 else
4161 begin
4162 e_LogWritefln('usage: %s <n>', [cmd])
4163 end
4164 end
4165 else if cmd = 'g_max_gibs' then
4166 begin
4167 if Length(p) = 2 then
4168 begin
4169 a := Max(0, StrToInt(p[1]));
4170 g_Gibs_SetMax(a)
4171 end
4172 else if Length(p) = 1 then
4173 begin
4174 e_LogWritefln('%s', [g_Gibs_GetMax()])
4175 end
4176 else
4177 begin
4178 e_LogWritefln('usage: %s <n>', [cmd])
4179 end
4180 end
4181 else if cmd = 'g_max_corpses' then
4182 begin
4183 if Length(p) = 2 then
4184 begin
4185 a := Max(0, StrToInt(p[1]));
4186 g_Corpses_SetMax(a)
4187 end
4188 else if Length(p) = 1 then
4189 begin
4190 e_LogWritefln('%s', [g_Corpses_GetMax()])
4191 end
4192 else
4193 begin
4194 e_LogWritefln('usage: %s <n>', [cmd])
4195 end
4196 end
4197 else if cmd = 'g_scorelimit' then
4198 begin
4199 if Length(P) > 1 then
4200 begin
4201 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
4203 if g_Game_IsServer then
4204 begin
4205 b := 0;
4206 if gGameSettings.GameMode = GM_DM then
4207 begin // DM
4208 stat := g_Player_GetStats();
4209 if stat <> nil then
4210 for a := 0 to High(stat) do
4211 if stat[a].Frags > b then
4212 b := stat[a].Frags;
4213 end
4214 else // TDM/CTF
4215 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4217 // if someone has a higher score, set it to that instead
4218 gsGoalLimit := max(gsGoalLimit, b);
4219 gGameSettings.GoalLimit := gsGoalLimit;
4221 if g_Game_IsNet then MH_SEND_GameSettings;
4222 end;
4223 end;
4225 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
4226 end
4227 else if cmd = 'g_timelimit' then
4228 begin
4229 if Length(P) > 1 then
4230 begin
4231 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4232 if g_Game_IsServer then
4233 begin
4234 gGameSettings.TimeLimit := gsTimeLimit;
4235 if g_Game_IsNet then MH_SEND_GameSettings;
4236 end;
4237 end;
4238 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4239 [gsTimeLimit div 3600,
4240 (gsTimeLimit div 60) mod 60,
4241 gsTimeLimit mod 60]));
4242 end
4243 else if cmd = 'g_maxlives' then
4244 begin
4245 if Length(P) > 1 then
4246 begin
4247 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4248 if g_Game_IsServer then
4249 begin
4250 gGameSettings.MaxLives := gsMaxLives;
4251 if g_Game_IsNet then MH_SEND_GameSettings;
4252 end;
4253 end;
4255 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4256 end;
4257 end;
4259 procedure PlayerSettingsCVars(P: SSArray);
4260 var
4261 cmd: string;
4262 team: Byte;
4264 function ParseTeam(s: string): Byte;
4265 begin
4266 result := 0;
4267 case s of
4268 'red', '1': result := TEAM_RED;
4269 'blue', '2': result := TEAM_BLUE;
4270 else result := TEAM_NONE;
4271 end;
4272 end;
4273 begin
4274 cmd := LowerCase(P[0]);
4275 case cmd of
4276 'p1_name':
4277 begin
4278 if (Length(P) > 1) then
4279 begin
4280 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4281 if g_Game_IsClient then
4282 MC_SEND_PlayerSettings
4283 else if gGameOn and (gPlayer1 <> nil) then
4284 begin
4285 gPlayer1.Name := b_Text_Unformat(P[1]);
4286 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4287 end;
4288 end;
4289 end;
4290 'p2_name':
4291 begin
4292 if (Length(P) > 1) then
4293 begin
4294 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4295 if g_Game_IsClient then
4296 MC_SEND_PlayerSettings
4297 else if gGameOn and (gPlayer2 <> nil) then
4298 begin
4299 gPlayer2.Name := b_Text_Unformat(P[1]);
4300 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4301 end;
4302 end;
4303 end;
4304 'p1_color':
4305 begin
4306 if Length(P) > 3 then
4307 begin
4308 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4309 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4310 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4311 if g_Game_IsClient then
4312 MC_SEND_PlayerSettings
4313 else if gGameOn and (gPlayer1 <> nil) then
4314 begin
4315 gPlayer1.SetColor(gPlayer1Settings.Color);
4316 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4317 end;
4318 end;
4319 end;
4320 'p2_color':
4321 begin
4322 if Length(P) > 3 then
4323 begin
4324 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4325 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4326 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4327 if g_Game_IsClient then
4328 MC_SEND_PlayerSettings
4329 else if gGameOn and (gPlayer2 <> nil) then
4330 begin
4331 gPlayer2.SetColor(gPlayer2Settings.Color);
4332 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4333 end;
4334 end;
4335 end;
4336 'p1_model':
4337 begin
4338 if (Length(P) > 1) then
4339 begin
4340 gPlayer1Settings.Model := P[1];
4341 if g_Game_IsClient then
4342 MC_SEND_PlayerSettings
4343 else if gGameOn and (gPlayer1 <> nil) then
4344 begin
4345 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4346 gPlayer1.SetModel(gPlayer1Settings.Model);
4347 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4348 end;
4349 end;
4350 end;
4351 'p2_model':
4352 begin
4353 if (Length(P) > 1) then
4354 begin
4355 gPlayer2Settings.Model := P[1];
4356 if g_Game_IsClient then
4357 MC_SEND_PlayerSettings
4358 else if gGameOn and (gPlayer2 <> nil) then
4359 begin
4360 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4361 gPlayer2.SetModel(gPlayer2Settings.Model);
4362 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4363 end;
4364 end;
4365 end;
4366 'p1_team':
4367 begin
4368 // TODO: switch teams if in game or store this separately
4369 if (Length(P) > 1) then
4370 begin
4371 team := ParseTeam(P[1]);
4372 if team = TEAM_NONE then
4373 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4374 else if not gGameOn and not g_Game_IsNet then
4375 gPlayer1Settings.Team := team
4376 else
4377 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4378 end;
4379 end;
4380 'p2_team':
4381 begin
4382 // TODO: switch teams if in game or store this separately
4383 if (Length(P) > 1) then
4384 begin
4385 team := ParseTeam(P[1]);
4386 if team = TEAM_NONE then
4387 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4388 else if not gGameOn and not g_Game_IsNet then
4389 gPlayer2Settings.Team := team
4390 else
4391 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4392 end;
4393 end;
4394 end;
4395 end;
4397 procedure PrintHeapStats();
4398 var
4399 hs: TFPCHeapStatus;
4400 begin
4401 hs := GetFPCHeapStatus();
4402 e_LogWriteLn ('v===== heap status =====v');
4403 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4404 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4405 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4406 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4407 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4408 e_LogWriteLn ('^=======================^');
4409 end;
4411 procedure DebugCommands(P: SSArray);
4412 var
4413 a, b: Integer;
4414 cmd: string;
4415 //pt: TDFPoint;
4416 mon: TMonster;
4417 begin
4418 // Команды отладочного режима:
4419 if {gDebugMode}conIsCheatsEnabled then
4420 begin
4421 cmd := LowerCase(P[0]);
4422 if cmd = 'd_window' then
4423 begin
4424 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4425 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4426 end
4427 else if cmd = 'd_sounds' then
4428 begin
4429 if (Length(P) > 1) and
4430 ((P[1] = '1') or (P[1] = '0')) then
4431 g_Debug_Sounds := (P[1][1] = '1');
4433 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4434 end
4435 else if cmd = 'd_frames' then
4436 begin
4437 if (Length(P) > 1) and
4438 ((P[1] = '1') or (P[1] = '0')) then
4439 g_Debug_Frames := (P[1][1] = '1');
4441 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4442 end
4443 else if cmd = 'd_winmsg' then
4444 begin
4445 if (Length(P) > 1) and
4446 ((P[1] = '1') or (P[1] = '0')) then
4447 g_Debug_WinMsgs := (P[1][1] = '1');
4449 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4450 end
4451 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4452 begin
4453 if (Length(P) > 1) and
4454 ((P[1] = '1') or (P[1] = '0')) then
4455 g_Debug_MonsterOff := (P[1][1] = '1');
4457 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4458 end
4459 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4460 begin
4461 if Length(P) > 1 then
4462 case P[1][1] of
4463 '0': g_debug_BotAIOff := 0;
4464 '1': g_debug_BotAIOff := 1;
4465 '2': g_debug_BotAIOff := 2;
4466 '3': g_debug_BotAIOff := 3;
4467 end;
4469 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4470 end
4471 else if cmd = 'd_monster' then
4472 begin
4473 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4474 if Length(P) < 2 then
4475 begin
4476 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4477 g_Console_Add('ID | Name');
4478 for b := MONSTER_DEMON to MONSTER_MAN do
4479 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4480 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4481 end else
4482 begin
4483 a := StrToIntDef(P[1], 0);
4484 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4485 a := g_Mons_TypeIdByName(P[1]);
4487 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4488 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4489 else
4490 begin
4491 with gPlayer1.Obj do
4492 begin
4493 mon := g_Monsters_Create(a,
4494 X + Rect.X + (Rect.Width div 2),
4495 Y + Rect.Y + Rect.Height,
4496 gPlayer1.Direction, True);
4497 end;
4498 if (Length(P) > 2) and (mon <> nil) then
4499 begin
4500 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4501 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4502 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4503 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4504 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4505 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4506 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4507 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4508 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4509 end;
4510 end;
4511 end;
4512 end
4513 else if (cmd = 'd_health') then
4514 begin
4515 if (Length(P) > 1) and
4516 ((P[1] = '1') or (P[1] = '0')) then
4517 g_debug_HealthBar := (P[1][1] = '1');
4519 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4520 end
4521 else if (cmd = 'd_player') then
4522 begin
4523 if (Length(P) > 1) and
4524 ((P[1] = '1') or (P[1] = '0')) then
4525 g_debug_Player := (P[1][1] = '1');
4527 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4528 end
4529 else if (cmd = 'd_mem') then
4530 begin
4531 PrintHeapStats();
4532 end;
4533 end
4534 else
4535 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4536 end;
4539 procedure GameCheats(P: SSArray);
4540 var
4541 cmd: string;
4542 f, a: Integer;
4543 plr: TPlayer;
4544 begin
4545 if (not gGameOn) or (not conIsCheatsEnabled) then
4546 begin
4547 g_Console_Add('not available');
4548 exit;
4549 end;
4550 plr := gPlayer1;
4551 if plr = nil then
4552 begin
4553 g_Console_Add('where is the player?!');
4554 exit;
4555 end;
4556 cmd := LowerCase(P[0]);
4557 // god
4558 if cmd = 'god' then
4559 begin
4560 plr.GodMode := not plr.GodMode;
4561 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4562 exit;
4563 end;
4564 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4565 if cmd = 'give' then
4566 begin
4567 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4568 for f := 1 to High(P) do
4569 begin
4570 cmd := LowerCase(P[f]);
4571 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4572 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4573 if cmd = 'exit' then
4574 begin
4575 if gTriggers <> nil then
4576 begin
4577 for a := 0 to High(gTriggers) do
4578 begin
4579 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4580 begin
4581 g_Console_Add('player left the map');
4582 gExitByTrigger := True;
4583 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4584 g_Game_ExitLevel(gTriggers[a].tgcMap);
4585 break;
4586 end;
4587 end;
4588 end;
4589 continue;
4590 end;
4592 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4593 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4594 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4595 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4596 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4598 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4599 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4601 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4602 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;
4604 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4605 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4607 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4608 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4610 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4611 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4613 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4614 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4615 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4617 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4618 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4619 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4620 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;
4621 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4622 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4624 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;
4625 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;
4626 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;
4627 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;
4628 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;
4629 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;
4631 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4632 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;
4634 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;
4635 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;
4637 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4639 if cmd = 'ammo' then
4640 begin
4641 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4642 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4643 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4644 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4645 plr.GiveItem(ITEM_AMMO_FUELCAN);
4646 g_Console_Add('player got some ammo');
4647 continue;
4648 end;
4650 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4651 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4653 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4654 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4656 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4657 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4659 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4660 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4662 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4664 if cmd = 'weapons' then
4665 begin
4666 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4667 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4668 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4669 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4670 plr.GiveItem(ITEM_WEAPON_PLASMA);
4671 plr.GiveItem(ITEM_WEAPON_BFG);
4672 g_Console_Add('player got weapons');
4673 continue;
4674 end;
4676 if cmd = 'keys' then
4677 begin
4678 plr.GiveItem(ITEM_KEY_RED);
4679 plr.GiveItem(ITEM_KEY_GREEN);
4680 plr.GiveItem(ITEM_KEY_BLUE);
4681 g_Console_Add('player got all keys');
4682 continue;
4683 end;
4685 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4686 end;
4687 exit;
4688 end;
4689 // open
4690 if cmd = 'open' then
4691 begin
4692 g_Console_Add('player activated sesame');
4693 g_Triggers_OpenAll();
4694 exit;
4695 end;
4696 // fly
4697 if cmd = 'fly' then
4698 begin
4699 gFly := not gFly;
4700 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4701 exit;
4702 end;
4703 // noclip
4704 if cmd = 'noclip' then
4705 begin
4706 plr.SwitchNoClip;
4707 g_Console_Add('wall hardeness adjusted');
4708 exit;
4709 end;
4710 // notarget
4711 if cmd = 'notarget' then
4712 begin
4713 plr.NoTarget := not plr.NoTarget;
4714 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4715 exit;
4716 end;
4717 // noreload
4718 if cmd = 'noreload' then
4719 begin
4720 plr.NoReload := not plr.NoReload;
4721 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4722 exit;
4723 end;
4724 // speedy
4725 if cmd = 'speedy' then
4726 begin
4727 MAX_RUNVEL := 32-MAX_RUNVEL;
4728 g_Console_Add('speed adjusted');
4729 exit;
4730 end;
4731 // jumpy
4732 if cmd = 'jumpy' then
4733 begin
4734 VEL_JUMP := 30-VEL_JUMP;
4735 g_Console_Add('jump height adjusted');
4736 exit;
4737 end;
4738 // automap
4739 if cmd = 'automap' then
4740 begin
4741 gShowMap := not gShowMap;
4742 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4743 exit;
4744 end;
4745 // aimline
4746 if cmd = 'aimline' then
4747 begin
4748 gAimLine := not gAimLine;
4749 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4750 exit;
4751 end;
4752 end;
4754 procedure GameCommands(P: SSArray);
4755 var
4756 a, b: Integer;
4757 s, pw: String;
4758 chstr: string;
4759 cmd: string;
4760 pl: pTNetClient = nil;
4761 plr: TPlayer;
4762 prt: Word;
4763 nm: Boolean;
4764 listen: LongWord;
4765 found: Boolean;
4766 begin
4767 // Общие команды:
4768 cmd := LowerCase(P[0]);
4769 chstr := '';
4770 if cmd = 'pause' then
4771 begin
4772 if (g_ActiveWindow = nil) then
4773 g_Game_Pause(not gPauseMain);
4774 end
4775 else if cmd = 'endgame' then
4776 gExit := EXIT_SIMPLE
4777 else if cmd = 'restart' then
4778 begin
4779 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4780 begin
4781 if g_Game_IsClient then
4782 begin
4783 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4784 Exit;
4785 end;
4786 g_Game_Restart();
4787 end else
4788 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4789 end
4790 else if cmd = 'kick' then
4791 begin
4792 if g_Game_IsServer then
4793 begin
4794 if Length(P) < 2 then
4795 begin
4796 g_Console_Add('kick <name>');
4797 Exit;
4798 end;
4799 if P[1] = '' then
4800 begin
4801 g_Console_Add('kick <name>');
4802 Exit;
4803 end;
4805 if g_Game_IsNet then
4806 pl := g_Net_Client_ByName(P[1]);
4807 if (pl <> nil) then
4808 begin
4809 s := g_Net_ClientName_ByID(pl^.ID);
4810 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4811 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4812 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4813 g_Net_Slist_ServerPlayerLeaves();
4814 end else if gPlayers <> nil then
4815 for a := Low(gPlayers) to High(gPlayers) do
4816 if gPlayers[a] <> nil then
4817 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4818 begin
4819 // Не отключать основных игроков в сингле
4820 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4821 continue;
4822 gPlayers[a].Lives := 0;
4823 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4824 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4825 g_Player_Remove(gPlayers[a].UID);
4826 g_Net_Slist_ServerPlayerLeaves();
4827 // Если не перемешать, при добавлении новых ботов появятся старые
4828 g_Bot_MixNames();
4829 end;
4830 end else
4831 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4832 end
4833 else if cmd = 'kick_id' then
4834 begin
4835 if g_Game_IsServer and g_Game_IsNet then
4836 begin
4837 if Length(P) < 2 then
4838 begin
4839 g_Console_Add('kick_id <client ID>');
4840 Exit;
4841 end;
4842 if P[1] = '' then
4843 begin
4844 g_Console_Add('kick_id <client ID>');
4845 Exit;
4846 end;
4848 a := StrToIntDef(P[1], 0);
4849 if (NetClients <> nil) and (a <= High(NetClients)) then
4850 begin
4851 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4852 begin
4853 s := g_Net_ClientName_ByID(NetClients[a].ID);
4854 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4855 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4856 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4857 g_Net_Slist_ServerPlayerLeaves();
4858 end;
4859 end;
4860 end else
4861 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4862 end
4863 else if cmd = 'kick_pid' then
4864 begin
4865 if g_Game_IsServer and g_Game_IsNet then
4866 begin
4867 if Length(P) < 2 then
4868 begin
4869 g_Console_Add('kick_pid <player ID>');
4870 Exit;
4871 end;
4872 if P[1] = '' then
4873 begin
4874 g_Console_Add('kick_pid <player ID>');
4875 Exit;
4876 end;
4878 a := StrToIntDef(P[1], 0);
4879 pl := g_Net_Client_ByPlayer(a);
4880 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4881 begin
4882 s := g_Net_ClientName_ByID(pl^.ID);
4883 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4884 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4885 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4886 g_Net_Slist_ServerPlayerLeaves();
4887 end;
4888 end else
4889 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4890 end
4891 else if cmd = 'ban' then
4892 begin
4893 if g_Game_IsServer and g_Game_IsNet then
4894 begin
4895 if Length(P) < 2 then
4896 begin
4897 g_Console_Add('ban <name>');
4898 Exit;
4899 end;
4900 if P[1] = '' then
4901 begin
4902 g_Console_Add('ban <name>');
4903 Exit;
4904 end;
4906 pl := g_Net_Client_ByName(P[1]);
4907 if (pl <> nil) then
4908 begin
4909 s := g_Net_ClientName_ByID(pl^.ID);
4910 g_Net_BanHost(pl^.Peer^.address.host, False);
4911 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4912 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4913 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4914 g_Net_Slist_ServerPlayerLeaves();
4915 end else
4916 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4917 end else
4918 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4919 end
4920 else if cmd = 'ban_id' then
4921 begin
4922 if g_Game_IsServer and g_Game_IsNet then
4923 begin
4924 if Length(P) < 2 then
4925 begin
4926 g_Console_Add('ban_id <client ID>');
4927 Exit;
4928 end;
4929 if P[1] = '' then
4930 begin
4931 g_Console_Add('ban_id <client ID>');
4932 Exit;
4933 end;
4935 a := StrToIntDef(P[1], 0);
4936 if (NetClients <> nil) and (a <= High(NetClients)) then
4937 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4938 begin
4939 s := g_Net_ClientName_ByID(NetClients[a].ID);
4940 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4941 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4942 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4943 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4944 g_Net_Slist_ServerPlayerLeaves();
4945 end;
4946 end else
4947 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4948 end
4949 else if cmd = 'ban_pid' then
4950 begin
4951 if g_Game_IsServer and g_Game_IsNet then
4952 begin
4953 if Length(P) < 2 then
4954 begin
4955 g_Console_Add('ban_pid <player ID>');
4956 Exit;
4957 end;
4958 if P[1] = '' then
4959 begin
4960 g_Console_Add('ban_pid <player ID>');
4961 Exit;
4962 end;
4964 a := StrToIntDef(P[1], 0);
4965 pl := g_Net_Client_ByPlayer(a);
4966 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4967 begin
4968 s := g_Net_ClientName_ByID(pl^.ID);
4969 g_Net_BanHost(pl^.Peer^.address.host, False);
4970 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4971 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4972 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4973 g_Net_Slist_ServerPlayerLeaves();
4974 end;
4975 end else
4976 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4977 end
4978 else if cmd = 'permban' then
4979 begin
4980 if g_Game_IsServer and g_Game_IsNet then
4981 begin
4982 if Length(P) < 2 then
4983 begin
4984 g_Console_Add('permban <name>');
4985 Exit;
4986 end;
4987 if P[1] = '' then
4988 begin
4989 g_Console_Add('permban <name>');
4990 Exit;
4991 end;
4993 pl := g_Net_Client_ByName(P[1]);
4994 if (pl <> nil) then
4995 begin
4996 s := g_Net_ClientName_ByID(pl^.ID);
4997 g_Net_BanHost(pl^.Peer^.address.host);
4998 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4999 g_Net_SaveBanList();
5000 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5001 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5002 g_Net_Slist_ServerPlayerLeaves();
5003 end else
5004 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5005 end else
5006 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5007 end
5008 else if cmd = 'permban_id' then
5009 begin
5010 if g_Game_IsServer and g_Game_IsNet then
5011 begin
5012 if Length(P) < 2 then
5013 begin
5014 g_Console_Add('permban_id <client ID>');
5015 Exit;
5016 end;
5017 if P[1] = '' then
5018 begin
5019 g_Console_Add('permban_id <client ID>');
5020 Exit;
5021 end;
5023 a := StrToIntDef(P[1], 0);
5024 if (NetClients <> nil) and (a <= High(NetClients)) then
5025 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5026 begin
5027 s := g_Net_ClientName_ByID(NetClients[a].ID);
5028 g_Net_BanHost(NetClients[a].Peer^.address.host);
5029 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
5030 g_Net_SaveBanList();
5031 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5032 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5033 g_Net_Slist_ServerPlayerLeaves();
5034 end;
5035 end else
5036 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5037 end
5038 else if cmd = 'permban_pid' then
5039 begin
5040 if g_Game_IsServer and g_Game_IsNet then
5041 begin
5042 if Length(P) < 2 then
5043 begin
5044 g_Console_Add('permban_pid <player ID>');
5045 Exit;
5046 end;
5047 if P[1] = '' then
5048 begin
5049 g_Console_Add('permban_pid <player ID>');
5050 Exit;
5051 end;
5053 a := StrToIntDef(P[1], 0);
5054 pl := g_Net_Client_ByPlayer(a);
5055 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5056 begin
5057 s := g_Net_ClientName_ByID(pl^.ID);
5058 g_Net_BanHost(pl^.Peer^.address.host);
5059 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
5060 g_Net_SaveBanList();
5061 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5062 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5063 g_Net_Slist_ServerPlayerLeaves();
5064 end;
5065 end else
5066 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5067 end
5068 else if cmd = 'permban_ip' then
5069 begin
5070 if g_Game_IsServer and g_Game_IsNet then
5071 begin
5072 if Length(P) < 2 then
5073 begin
5074 g_Console_Add('permban_ip <IP address>');
5075 Exit;
5076 end;
5077 if P[1] = '' then
5078 begin
5079 g_Console_Add('permban_ip <IP address>');
5080 Exit;
5081 end;
5083 g_Net_BanHost(P[1]);
5084 g_Net_SaveBanList();
5085 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
5086 end else
5087 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5088 end
5089 else if cmd = 'unban' then
5090 begin
5091 if g_Game_IsServer and g_Game_IsNet then
5092 begin
5093 if Length(P) < 2 then
5094 begin
5095 g_Console_Add('unban <IP Address>');
5096 Exit;
5097 end;
5098 if P[1] = '' then
5099 begin
5100 g_Console_Add('unban <IP Address>');
5101 Exit;
5102 end;
5104 if g_Net_UnbanHost(P[1]) then
5105 begin
5106 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5107 g_Net_SaveBanList();
5108 end else
5109 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5110 end else
5111 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5112 end
5113 else if cmd = 'clientlist' then
5114 begin
5115 if g_Game_IsServer and g_Game_IsNet then
5116 begin
5117 b := 0;
5118 if NetClients <> nil then
5119 for a := Low(NetClients) to High(NetClients) do
5120 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5121 begin
5122 plr := g_Player_Get(NetClients[a].Player);
5123 if plr = nil then continue;
5124 Inc(b);
5125 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5126 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5127 end;
5128 if b = 0 then
5129 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5130 end else
5131 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5132 end
5133 else if cmd = 'connect' then
5134 begin
5135 if (NetMode = NET_NONE) then
5136 begin
5137 if Length(P) < 2 then
5138 begin
5139 g_Console_Add('connect <IP> [port] [password]');
5140 Exit;
5141 end;
5142 if P[1] = '' then
5143 begin
5144 g_Console_Add('connect <IP> [port] [password]');
5145 Exit;
5146 end;
5148 if Length(P) > 2 then
5149 prt := StrToIntDef(P[2], 25666)
5150 else
5151 prt := 25666;
5153 if Length(P) > 3 then
5154 pw := P[3]
5155 else
5156 pw := '';
5158 g_Game_StartClient(P[1], prt, pw);
5159 end;
5160 end
5161 else if cmd = 'disconnect' then
5162 begin
5163 if (NetMode = NET_CLIENT) then
5164 g_Net_Disconnect();
5165 end
5166 else if cmd = 'reconnect' then
5167 begin
5168 if (NetMode = NET_SERVER) then
5169 Exit;
5171 if (NetMode = NET_CLIENT) then
5172 begin
5173 g_Net_Disconnect();
5174 gExit := EXIT_SIMPLE;
5175 EndGame;
5176 end;
5178 //TODO: Use last successful password to reconnect, instead of ''
5179 g_Game_StartClient(NetClientIP, NetClientPort, '');
5180 end
5181 else if (cmd = 'addbot') or
5182 (cmd = 'bot_add') then
5183 begin
5184 if Length(P) > 2 then
5185 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
5186 else if Length(P) > 1 then
5187 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5188 else
5189 g_Bot_Add(TEAM_NONE, 2);
5190 end
5191 else if cmd = 'bot_addlist' then
5192 begin
5193 if Length(P) > 1 then
5194 begin
5195 if Length(P) = 2 then
5196 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5197 else if Length(P) = 3 then
5198 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5199 else
5200 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5201 end;
5202 end
5203 else if cmd = 'bot_removeall' then
5204 g_Bot_RemoveAll()
5205 else if cmd = 'chat' then
5206 begin
5207 if g_Game_IsNet then
5208 begin
5209 if Length(P) > 1 then
5210 begin
5211 for a := 1 to High(P) do
5212 chstr := chstr + P[a] + ' ';
5214 if Length(chstr) > 200 then SetLength(chstr, 200);
5216 if Length(chstr) < 1 then
5217 begin
5218 g_Console_Add('chat <text>');
5219 Exit;
5220 end;
5222 chstr := b_Text_Format(chstr);
5223 if g_Game_IsClient then
5224 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5225 else
5226 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5227 end
5228 else
5229 g_Console_Add('chat <text>');
5230 end else
5231 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5232 end
5233 else if cmd = 'teamchat' then
5234 begin
5235 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5236 begin
5237 if Length(P) > 1 then
5238 begin
5239 for a := 1 to High(P) do
5240 chstr := chstr + P[a] + ' ';
5242 if Length(chstr) > 200 then SetLength(chstr, 200);
5244 if Length(chstr) < 1 then
5245 begin
5246 g_Console_Add('teamchat <text>');
5247 Exit;
5248 end;
5250 chstr := b_Text_Format(chstr);
5251 if g_Game_IsClient then
5252 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5253 else
5254 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5255 gPlayer1Settings.Team);
5256 end
5257 else
5258 g_Console_Add('teamchat <text>');
5259 end else
5260 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5261 end
5262 else if cmd = 'game' then
5263 begin
5264 if gGameSettings.GameType <> GT_NONE then
5265 begin
5266 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5267 Exit;
5268 end;
5269 if Length(P) = 1 then
5270 begin
5271 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5272 Exit;
5273 end;
5274 // game not started yet, load fist map from some wad
5275 found := false;
5276 s := addWadExtension(P[1]);
5277 found := e_FindResource(AllMapDirs, s);
5278 P[1] := s;
5279 if found then
5280 begin
5281 P[1] := ExpandFileName(P[1]);
5282 // if map not choosed then set first map
5283 if Length(P) < 3 then
5284 begin
5285 SetLength(P, 3);
5286 P[2] := g_Game_GetFirstMap(P[1]);
5287 end;
5289 s := P[1] + ':\' + UpperCase(P[2]);
5291 if g_Map_Exist(s) then
5292 begin
5293 // start game
5294 g_Game_Free();
5295 with gGameSettings do
5296 begin
5297 Options := gsGameFlags;
5298 GameMode := g_Game_TextToMode(gsGameMode);
5299 if gSwitchGameMode <> GM_NONE then
5300 GameMode := gSwitchGameMode;
5301 if GameMode = GM_NONE then GameMode := GM_DM;
5302 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5303 b := 1;
5304 if Length(P) >= 4 then
5305 b := StrToIntDef(P[3], 1);
5306 g_Game_StartCustom(s, GameMode, TimeLimit,
5307 GoalLimit, MaxLives, Options, b);
5308 end;
5309 end
5310 else
5311 if P[2] = '' then
5312 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5313 else
5314 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5315 end else
5316 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5317 end
5318 else if cmd = 'host' then
5319 begin
5320 if gGameSettings.GameType <> GT_NONE then
5321 begin
5322 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5323 Exit;
5324 end;
5325 if Length(P) < 4 then
5326 begin
5327 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5328 Exit;
5329 end;
5330 if not StrToIp(P[1], listen) then
5331 Exit;
5332 prt := StrToIntDef(P[2], 25666);
5334 s := addWadExtension(P[3]);
5335 found := e_FindResource(AllMapDirs, s);
5336 P[3] := s;
5337 if found then
5338 begin
5339 // get first map in wad, if not specified
5340 if Length(P) < 5 then
5341 begin
5342 SetLength(P, 5);
5343 P[4] := g_Game_GetFirstMap(P[1]);
5344 end;
5345 s := P[3] + ':\' + UpperCase(P[4]);
5346 if g_Map_Exist(s) then
5347 begin
5348 // start game
5349 g_Game_Free();
5350 with gGameSettings do
5351 begin
5352 Options := gsGameFlags;
5353 GameMode := g_Game_TextToMode(gsGameMode);
5354 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5355 if GameMode = GM_NONE then GameMode := GM_DM;
5356 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5357 b := 0;
5358 if Length(P) >= 6 then
5359 b := StrToIntDef(P[5], 0);
5360 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
5361 end
5362 end
5363 else
5364 begin
5365 if P[4] = '' then
5366 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5367 else
5368 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5369 end
5370 end
5371 else
5372 begin
5373 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5374 end
5375 end
5376 else if cmd = 'map' then
5377 begin
5378 if Length(P) = 1 then
5379 begin
5380 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5381 begin
5382 g_Console_Add(cmd + ' <MAP>');
5383 g_Console_Add(cmd + ' <WAD> [MAP]')
5384 end
5385 else
5386 begin
5387 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5388 end
5389 end
5390 else
5391 begin
5392 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5393 begin
5394 if Length(P) < 3 then
5395 begin
5396 // first param is map or wad
5397 s := UpperCase(P[1]);
5398 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5399 begin
5400 gExitByTrigger := False;
5401 if gGameOn then
5402 begin
5403 // already in game, finish current map
5404 gNextMap := s;
5405 gExit := EXIT_ENDLEVELCUSTOM;
5406 end
5407 else
5408 begin
5409 // intermission, so change map immediately
5410 g_Game_ChangeMap(s)
5411 end
5412 end
5413 else
5414 begin
5415 s := P[1];
5416 found := e_FindResource(AllMapDirs, s);
5417 P[1] := s;
5418 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5419 if found then
5420 begin
5421 // no such map, found wad
5422 pw := P[1];
5423 SetLength(P, 3);
5424 P[1] := ExpandFileName(pw);
5425 P[2] := g_Game_GetFirstMap(P[1]);
5426 s := P[1] + ':\' + P[2];
5427 if g_Map_Exist(s) then
5428 begin
5429 gExitByTrigger := False;
5430 if gGameOn then
5431 begin
5432 // already in game, finish current map
5433 gNextMap := s;
5434 gExit := EXIT_ENDLEVELCUSTOM
5435 end
5436 else
5437 begin
5438 // intermission, so change map immediately
5439 g_Game_ChangeMap(s)
5440 end
5441 end
5442 else
5443 begin
5444 if P[2] = '' then
5445 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5446 else
5447 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5448 end
5449 end
5450 else
5451 begin
5452 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5453 end
5454 end;
5455 end
5456 else
5457 begin
5458 s := addWadExtension(P[1]);
5459 found := e_FindResource(AllMapDirs, s);
5460 P[1] := s;
5461 if found then
5462 begin
5463 P[2] := UpperCase(P[2]);
5464 s := P[1] + ':\' + P[2];
5465 if g_Map_Exist(s) then
5466 begin
5467 gExitByTrigger := False;
5468 if gGameOn then
5469 begin
5470 gNextMap := s;
5471 gExit := EXIT_ENDLEVELCUSTOM
5472 end
5473 else
5474 begin
5475 g_Game_ChangeMap(s)
5476 end
5477 end
5478 else
5479 begin
5480 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5481 end
5482 end
5483 else
5484 begin
5485 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5486 end
5487 end
5488 end
5489 else
5490 begin
5491 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5492 end
5493 end
5494 end
5495 else if cmd = 'nextmap' then
5496 begin
5497 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5498 begin
5499 g_Console_Add(_lc[I_MSG_NOT_GAME])
5500 end
5501 else
5502 begin
5503 nm := True;
5504 if Length(P) = 1 then
5505 begin
5506 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5507 begin
5508 g_Console_Add(cmd + ' <MAP>');
5509 g_Console_Add(cmd + ' <WAD> [MAP]');
5510 end
5511 else
5512 begin
5513 nm := False;
5514 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5515 end;
5516 end
5517 else
5518 begin
5519 nm := False;
5520 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5521 begin
5522 if Length(P) < 3 then
5523 begin
5524 // first param is map or wad
5525 s := UpperCase(P[1]);
5526 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5527 begin
5528 // map founded
5529 gExitByTrigger := False;
5530 gNextMap := s;
5531 nm := True;
5532 end
5533 else
5534 begin
5535 // no such map, found wad
5536 pw := addWadExtension(P[1]);
5537 found := e_FindResource(MapDirs, pw);
5538 if not found then
5539 found := e_FindResource(WadDirs, pw);
5540 P[1] := pw;
5541 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5542 if found then
5543 begin
5544 // map not specified, select first map
5545 SetLength(P, 3);
5546 P[2] := g_Game_GetFirstMap(P[1]);
5547 s := P[1] + ':\' + P[2];
5548 if g_Map_Exist(s) then
5549 begin
5550 gExitByTrigger := False;
5551 gNextMap := s;
5552 nm := True
5553 end
5554 else
5555 begin
5556 if P[2] = '' then
5557 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5558 else
5559 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5560 end
5561 end
5562 else
5563 begin
5564 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5565 end
5566 end
5567 end
5568 else
5569 begin
5570 // specified two params wad + map
5571 pw := addWadExtension(P[1]);
5572 found := e_FindResource(MapDirs, pw);
5573 if not found then
5574 found := e_FindResource(MapDirs, pw);
5575 P[1] := pw;
5576 if found then
5577 begin
5578 P[2] := UpperCase(P[2]);
5579 s := P[1] + ':\' + P[2];
5580 if g_Map_Exist(s) then
5581 begin
5582 gExitByTrigger := False;
5583 gNextMap := s;
5584 nm := True
5585 end
5586 else
5587 begin
5588 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5589 end
5590 end
5591 else
5592 begin
5593 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5594 end
5595 end
5596 end
5597 else
5598 begin
5599 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5600 end
5601 end;
5602 if nm then
5603 begin
5604 if gNextMap = '' then
5605 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5606 else
5607 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5608 end
5609 end
5610 end
5611 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5612 begin
5613 if not gGameOn then
5614 begin
5615 g_Console_Add(_lc[I_MSG_NOT_GAME])
5616 end
5617 else
5618 begin
5619 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5620 begin
5621 gExitByTrigger := False;
5622 // next map not specified, try to find trigger EXIT
5623 if (gNextMap = '') and (gTriggers <> nil) then
5624 begin
5625 for a := 0 to High(gTriggers) do
5626 begin
5627 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5628 begin
5629 gExitByTrigger := True;
5630 //gNextMap := gTriggers[a].Data.MapName;
5631 gNextMap := gTriggers[a].tgcMap;
5632 Break
5633 end
5634 end
5635 end;
5636 if gNextMap = '' then
5637 gNextMap := g_Game_GetNextMap();
5638 if not isWadPath(gNextMap) then
5639 s := gGameSettings.WAD + ':\' + gNextMap
5640 else
5641 s := gNextMap;
5642 if g_Map_Exist(s) then
5643 gExit := EXIT_ENDLEVELCUSTOM
5644 else
5645 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5646 end
5647 else
5648 begin
5649 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5650 end
5651 end
5652 end
5653 else if (cmd = 'event') then
5654 begin
5655 if (Length(P) <= 1) then
5656 begin
5657 for a := 0 to High(gEvents) do
5658 if gEvents[a].Command = '' then
5659 g_Console_Add(gEvents[a].Name + ' <none>')
5660 else
5661 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5662 Exit;
5663 end;
5664 if (Length(P) = 2) then
5665 begin
5666 for a := 0 to High(gEvents) do
5667 if gEvents[a].Name = P[1] then
5668 if gEvents[a].Command = '' then
5669 g_Console_Add(gEvents[a].Name + ' <none>')
5670 else
5671 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5672 Exit;
5673 end;
5674 for a := 0 to High(gEvents) do
5675 if gEvents[a].Name = P[1] then
5676 begin
5677 gEvents[a].Command := '';
5678 for b := 2 to High(P) do
5679 if Pos(' ', P[b]) = 0 then
5680 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5681 else
5682 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5683 gEvents[a].Command := Trim(gEvents[a].Command);
5684 Exit;
5685 end;
5686 end
5687 else if cmd = 'suicide' then
5688 begin
5689 if gGameOn then
5690 begin
5691 if g_Game_IsClient then
5692 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5693 else
5694 begin
5695 if gPlayer1 <> nil then
5696 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5697 if gPlayer2 <> nil then
5698 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5699 end;
5700 end;
5701 end
5702 else if cmd = 'screenshot' then
5703 begin
5704 g_TakeScreenShot()
5705 end
5706 else if cmd = 'weapon' then
5707 begin
5708 if Length(p) = 2 then
5709 begin
5710 a := WP_FIRST + StrToInt(p[1]) - 1;
5711 if (a >= WP_FIRST) and (a <= WP_LAST) then
5712 gSelectWeapon[0, a] := True
5713 end
5714 end
5715 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5716 begin
5717 if Length(p) = 2 then
5718 begin
5719 a := WP_FIRST + StrToInt(p[1]) - 1;
5720 b := ord(cmd[2]) - ord('1');
5721 if (a >= WP_FIRST) and (a <= WP_LAST) then
5722 gSelectWeapon[b, a] := True
5723 end
5724 end
5725 // Команды Своей игры:
5726 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5727 begin
5728 if cmd = 'bot_addred' then
5729 begin
5730 if Length(P) > 1 then
5731 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5732 else
5733 g_Bot_Add(TEAM_RED, 2);
5734 end
5735 else if cmd = 'bot_addblue' then
5736 begin
5737 if Length(P) > 1 then
5738 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5739 else
5740 g_Bot_Add(TEAM_BLUE, 2);
5741 end
5742 else if cmd = 'spectate' then
5743 begin
5744 if not gGameOn then
5745 Exit;
5746 g_Game_Spectate();
5747 end
5748 else if cmd = 'say' then
5749 begin
5750 if g_Game_IsServer and g_Game_IsNet then
5751 begin
5752 if Length(P) > 1 then
5753 begin
5754 chstr := '';
5755 for a := 1 to High(P) do
5756 chstr := chstr + P[a] + ' ';
5758 if Length(chstr) > 200 then SetLength(chstr, 200);
5760 if Length(chstr) < 1 then
5761 begin
5762 g_Console_Add('say <text>');
5763 Exit;
5764 end;
5766 chstr := b_Text_Format(chstr);
5767 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5768 end
5769 else g_Console_Add('say <text>');
5770 end else
5771 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5772 end
5773 else if cmd = 'tell' then
5774 begin
5775 if g_Game_IsServer and g_Game_IsNet then
5776 begin
5777 if (Length(P) > 2) and (P[1] <> '') then
5778 begin
5779 chstr := '';
5780 for a := 2 to High(P) do
5781 chstr := chstr + P[a] + ' ';
5783 if Length(chstr) > 200 then SetLength(chstr, 200);
5785 if Length(chstr) < 1 then
5786 begin
5787 g_Console_Add('tell <playername> <text>');
5788 Exit;
5789 end;
5791 pl := g_Net_Client_ByName(P[1]);
5792 if pl <> nil then
5793 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5794 else
5795 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5796 end
5797 else g_Console_Add('tell <playername> <text>');
5798 end else
5799 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5800 end
5801 else if cmd = 'centerprint' then
5802 begin
5803 if (Length(P) > 2) and (P[1] <> '') then
5804 begin
5805 chstr := '';
5806 for a := 2 to High(P) do
5807 chstr := chstr + P[a] + ' ';
5809 if Length(chstr) > 200 then SetLength(chstr, 200);
5811 if Length(chstr) < 1 then
5812 begin
5813 g_Console_Add('centerprint <timeout> <text>');
5814 Exit;
5815 end;
5817 a := StrToIntDef(P[1], 100);
5818 chstr := b_Text_Format(chstr);
5819 g_Game_Message(chstr, a);
5820 if g_Game_IsNet and g_Game_IsServer then
5821 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
5822 end
5823 else g_Console_Add('centerprint <timeout> <text>');
5824 end
5825 else if (cmd = 'overtime') and not g_Game_IsClient then
5826 begin
5827 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5828 Exit;
5829 // Дополнительное время:
5830 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5832 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5833 [gGameSettings.TimeLimit div 3600,
5834 (gGameSettings.TimeLimit div 60) mod 60,
5835 gGameSettings.TimeLimit mod 60]));
5836 if g_Game_IsNet then MH_SEND_GameSettings;
5837 end
5838 else if (cmd = 'rcon_password') and g_Game_IsClient then
5839 begin
5840 if (Length(P) <= 1) then
5841 g_Console_Add('rcon_password <password>')
5842 else
5843 MC_SEND_RCONPassword(P[1]);
5844 end
5845 else if cmd = 'rcon' then
5846 begin
5847 if g_Game_IsClient then
5848 begin
5849 if Length(P) > 1 then
5850 begin
5851 chstr := '';
5852 for a := 1 to High(P) do
5853 chstr := chstr + P[a] + ' ';
5855 if Length(chstr) > 200 then SetLength(chstr, 200);
5857 if Length(chstr) < 1 then
5858 begin
5859 g_Console_Add('rcon <command>');
5860 Exit;
5861 end;
5863 MC_SEND_RCONCommand(chstr);
5864 end
5865 else g_Console_Add('rcon <command>');
5866 end;
5867 end
5868 else if cmd = 'ready' then
5869 begin
5870 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5871 gLMSRespawnTime := gTime + 100;
5872 end
5873 else if (cmd = 'callvote') and g_Game_IsNet then
5874 begin
5875 if Length(P) > 1 then
5876 begin
5877 chstr := '';
5878 for a := 1 to High(P) do begin
5879 if a > 1 then chstr := chstr + ' ';
5880 chstr := chstr + P[a];
5881 end;
5883 if Length(chstr) > 200 then SetLength(chstr, 200);
5885 if Length(chstr) < 1 then
5886 begin
5887 g_Console_Add('callvote <command>');
5888 Exit;
5889 end;
5891 if g_Game_IsClient then
5892 MC_SEND_Vote(True, chstr)
5893 else
5894 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5895 g_Console_Process('vote', True);
5896 end
5897 else
5898 g_Console_Add('callvote <command>');
5899 end
5900 else if (cmd = 'vote') and g_Game_IsNet then
5901 begin
5902 if g_Game_IsClient then
5903 MC_SEND_Vote(False)
5904 else if gVoteInProgress then
5905 begin
5906 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5907 a := Floor((NetClientCount+1)/2.0) + 1
5908 else
5909 a := Floor(NetClientCount/2.0) + 1;
5910 if gVoted then
5911 begin
5912 Dec(gVoteCount);
5913 gVoted := False;
5914 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5915 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5916 end
5917 else
5918 begin
5919 Inc(gVoteCount);
5920 gVoted := True;
5921 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5922 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5923 g_Game_CheckVote;
5924 end;
5925 end;
5926 end
5927 end;
5928 end;
5930 procedure SystemCommands(P: SSArray);
5931 var
5932 cmd: string;
5933 begin
5934 cmd := LowerCase(P[0]);
5935 case cmd of
5936 'exit', 'quit':
5937 begin
5938 g_Game_Free();
5939 g_Game_Quit();
5940 end;
5941 'r_reset':
5942 begin
5943 gRC_Width := Max(1, gRC_Width);
5944 gRC_Height := Max(1, gRC_Height);
5945 gBPP := Max(1, gBPP);
5946 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
5947 e_LogWriteln('resolution changed')
5948 else
5949 e_LogWriteln('resolution not changed');
5950 sys_EnableVSync(gVSync);
5951 end;
5952 'r_maxfps':
5953 begin
5954 if Length(p) = 2 then
5955 begin
5956 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
5957 if gMaxFPS > 0 then
5958 gFrameTime := 1000 div gMaxFPS
5959 else
5960 gFrameTime := 0;
5961 end;
5962 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
5963 end;
5964 'g_language':
5965 begin
5966 if Length(p) = 2 then
5967 begin
5968 gAskLanguage := true;
5969 gLanguage := LANGUAGE_ENGLISH;
5970 case LowerCase(p[1]) of
5971 'english':
5972 begin
5973 gAskLanguage := false;
5974 gLanguage := LANGUAGE_ENGLISH;
5975 end;
5976 'russian':
5977 begin
5978 gAskLanguage := false;
5979 gLanguage := LANGUAGE_RUSSIAN;
5980 end;
5981 'ask':
5982 begin
5983 gAskLanguage := true;
5984 gLanguage := LANGUAGE_ENGLISH;
5985 end;
5986 end;
5987 g_Language_Set(gLanguage);
5988 end
5989 else
5990 begin
5991 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
5992 end
5993 end;
5994 end;
5995 end;
5997 procedure g_TakeScreenShot(Filename: string = '');
5998 var s: TStream; t: TDateTime; dir, date, name: String;
5999 begin
6000 if e_NoGraphics then Exit;
6001 try
6002 dir := e_GetWriteableDir(ScreenshotDirs);
6004 if Filename = '' then
6005 begin
6006 t := Now;
6007 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
6008 Filename := 'screenshot-' + date;
6009 end;
6011 name := e_CatPath(dir, Filename + '.png');
6012 s := createDiskFile(name);
6013 try
6014 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
6015 s.Free;
6016 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
6017 except
6018 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
6019 s.Free;
6020 DeleteFile(name)
6021 end
6022 except
6023 g_Console_Add('oh shit, i can''t create screenshot!')
6024 end
6025 end;
6027 procedure g_Game_InGameMenu(Show: Boolean);
6028 begin
6029 if (g_ActiveWindow = nil) and Show then
6030 begin
6031 if gGameSettings.GameType = GT_SINGLE then
6032 g_GUI_ShowWindow('GameSingleMenu')
6033 else
6034 begin
6035 if g_Game_IsClient then
6036 g_GUI_ShowWindow('GameClientMenu')
6037 else
6038 if g_Game_IsNet then
6039 g_GUI_ShowWindow('GameServerMenu')
6040 else
6041 g_GUI_ShowWindow('GameCustomMenu');
6042 end;
6043 g_Sound_PlayEx('MENU_OPEN');
6045 // Пауза при меню только в одиночной игре:
6046 if (not g_Game_IsNet) then
6047 g_Game_Pause(True);
6048 end
6049 else
6050 if (g_ActiveWindow <> nil) and (not Show) then
6051 begin
6052 // Пауза при меню только в одиночной игре:
6053 if (not g_Game_IsNet) then
6054 g_Game_Pause(False);
6055 end;
6056 end;
6058 procedure g_Game_Pause (Enable: Boolean);
6059 var
6060 oldPause: Boolean;
6061 begin
6062 if not gGameOn then exit;
6064 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6066 oldPause := gPause;
6067 gPauseMain := Enable;
6069 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6070 end;
6072 procedure g_Game_HolmesPause (Enable: Boolean);
6073 var
6074 oldPause: Boolean;
6075 begin
6076 if not gGameOn then exit;
6077 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6079 oldPause := gPause;
6080 gPauseHolmes := Enable;
6082 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6083 end;
6085 procedure g_Game_PauseAllSounds(Enable: Boolean);
6086 var
6087 i: Integer;
6088 begin
6089 // Триггеры:
6090 if gTriggers <> nil then
6091 for i := 0 to High(gTriggers) do
6092 with gTriggers[i] do
6093 if (TriggerType = TRIGGER_SOUND) and
6094 (Sound <> nil) and
6095 Sound.IsPlaying() then
6096 begin
6097 Sound.Pause(Enable);
6098 end;
6100 // Звуки игроков:
6101 if gPlayers <> nil then
6102 for i := 0 to High(gPlayers) do
6103 if gPlayers[i] <> nil then
6104 gPlayers[i].PauseSounds(Enable);
6106 // Музыка:
6107 if gMusic <> nil then
6108 gMusic.Pause(Enable);
6109 end;
6111 procedure g_Game_StopAllSounds(all: Boolean);
6112 var
6113 i: Integer;
6114 begin
6115 if gTriggers <> nil then
6116 for i := 0 to High(gTriggers) do
6117 with gTriggers[i] do
6118 if (TriggerType = TRIGGER_SOUND) and
6119 (Sound <> nil) then
6120 Sound.Stop();
6122 if gMusic <> nil then
6123 gMusic.Stop();
6125 if all then
6126 e_StopChannels();
6127 end;
6129 procedure g_Game_UpdateTriggerSounds;
6130 var i: Integer;
6131 begin
6132 if gTriggers <> nil then
6133 for i := 0 to High(gTriggers) do
6134 with gTriggers[i] do
6135 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
6136 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
6137 end;
6139 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
6140 begin
6141 Result := False;
6142 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6143 begin
6144 Result := True;
6145 Exit;
6146 end;
6147 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6148 begin
6149 Result := True;
6150 Exit;
6151 end;
6152 if gSpectMode <> SPECT_PLAYERS then
6153 Exit;
6154 if gSpectPID1 = UID then
6155 begin
6156 Result := True;
6157 Exit;
6158 end;
6159 if gSpectViewTwo and (gSpectPID2 = UID) then
6160 begin
6161 Result := True;
6162 Exit;
6163 end;
6164 end;
6166 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6167 var
6168 Pl: TPlayer;
6169 begin
6170 Result := False;
6171 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6172 begin
6173 Result := True;
6174 Exit;
6175 end;
6176 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6177 begin
6178 Result := True;
6179 Exit;
6180 end;
6181 if gSpectMode <> SPECT_PLAYERS then
6182 Exit;
6183 Pl := g_Player_Get(gSpectPID1);
6184 if (Pl <> nil) and (Pl.Team = Team) then
6185 begin
6186 Result := True;
6187 Exit;
6188 end;
6189 if gSpectViewTwo then
6190 begin
6191 Pl := g_Player_Get(gSpectPID2);
6192 if (Pl <> nil) and (Pl.Team = Team) then
6193 begin
6194 Result := True;
6195 Exit;
6196 end;
6197 end;
6198 end;
6200 procedure g_Game_Message(Msg: string; Time: Word);
6201 begin
6202 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
6203 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
6204 MessageTime := Time;
6205 end;
6207 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6208 const
6209 punct: Array[0..13] of String =
6210 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6211 var
6212 i, j: Integer;
6213 ok: Boolean;
6214 fpText: String;
6216 function IsPunctuation(S: String): Boolean;
6217 var
6218 i: Integer;
6219 begin
6220 Result := False;
6221 if Length(S) <> 1 then
6222 Exit;
6223 for i := Low(punct) to High(punct) do
6224 if S = punct[i] then
6225 begin
6226 Result := True;
6227 break;
6228 end;
6229 end;
6230 function FilterPunctuation(S: String): String;
6231 var
6232 i: Integer;
6233 begin
6234 for i := Low(punct) to High(punct) do
6235 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6236 Result := S;
6237 end;
6238 begin
6239 ok := False;
6241 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6242 begin
6243 // remove player name
6244 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6245 // for FullWord check
6246 Text := toLowerCase1251(' ' + Text + ' ');
6247 fpText := FilterPunctuation(Text);
6249 for i := 0 to Length(gChatSounds) - 1 do
6250 begin
6251 ok := True;
6252 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6253 begin
6254 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6255 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6256 else
6257 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6258 if not ok then
6259 break;
6260 end;
6261 if ok then
6262 begin
6263 gChatSounds[i].Sound.Play();
6264 break;
6265 end;
6266 end;
6267 end;
6268 if not ok then
6269 g_Sound_PlayEx('SOUND_GAME_RADIO');
6270 end;
6272 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6273 var
6274 a: Integer;
6275 begin
6276 case gAnnouncer of
6277 ANNOUNCE_NONE:
6278 Exit;
6279 ANNOUNCE_ME,
6280 ANNOUNCE_MEPLUS:
6281 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6282 Exit;
6283 end;
6284 for a := 0 to 3 do
6285 if goodsnd[a].IsPlaying() then
6286 Exit;
6288 goodsnd[Random(4)].Play();
6289 end;
6291 procedure g_Game_Announce_KillCombo(Param: Integer);
6292 var
6293 UID: Word;
6294 c, n: Byte;
6295 Pl: TPlayer;
6296 Name: String;
6297 begin
6298 UID := Param and $FFFF;
6299 c := Param shr 16;
6300 if c < 2 then
6301 Exit;
6303 Pl := g_Player_Get(UID);
6304 if Pl = nil then
6305 Name := '?'
6306 else
6307 Name := Pl.Name;
6309 case c of
6310 2: begin
6311 n := 0;
6312 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6313 end;
6314 3: begin
6315 n := 1;
6316 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6317 end;
6318 4: begin
6319 n := 2;
6320 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6321 end;
6322 else begin
6323 n := 3;
6324 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6325 end;
6326 end;
6328 case gAnnouncer of
6329 ANNOUNCE_NONE:
6330 Exit;
6331 ANNOUNCE_ME:
6332 if not g_Game_IsWatchedPlayer(UID) then
6333 Exit;
6334 ANNOUNCE_MEPLUS:
6335 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6336 Exit;
6337 end;
6339 if killsnd[n].IsPlaying() then
6340 killsnd[n].Stop();
6341 killsnd[n].Play();
6342 end;
6344 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6345 var
6346 a: Integer;
6347 begin
6348 case gAnnouncer of
6349 ANNOUNCE_NONE:
6350 Exit;
6351 ANNOUNCE_ME:
6352 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6353 Exit;
6354 end;
6355 for a := 0 to 2 do
6356 if hahasnd[a].IsPlaying() then
6357 Exit;
6359 hahasnd[Random(3)].Play();
6360 end;
6362 procedure g_Game_StartVote(Command, Initiator: string);
6363 var
6364 Need: Integer;
6365 begin
6366 if not gVotesEnabled then Exit;
6367 if gGameSettings.GameType <> GT_SERVER then Exit;
6368 if gVoteInProgress or gVotePassed then
6369 begin
6370 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6371 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6372 Exit;
6373 end;
6374 gVoteInProgress := True;
6375 gVotePassed := False;
6376 gVoteTimer := gTime + gVoteTimeout * 1000;
6377 gVoteCount := 0;
6378 gVoted := False;
6379 gVoteCommand := Command;
6381 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6382 Need := Floor((NetClientCount+1)/2.0)+1
6383 else
6384 Need := Floor(NetClientCount/2.0)+1;
6385 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6386 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6387 end;
6389 procedure g_Game_CheckVote;
6390 var
6391 I, Need: Integer;
6392 begin
6393 if gGameSettings.GameType <> GT_SERVER then Exit;
6394 if not gVoteInProgress then Exit;
6396 if (gTime >= gVoteTimer) then
6397 begin
6398 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6399 Need := Floor((NetClientCount+1)/2.0) + 1
6400 else
6401 Need := Floor(NetClientCount/2.0) + 1;
6402 if gVoteCount >= Need then
6403 begin
6404 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6405 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6406 gVotePassed := True;
6407 gVoteCmdTimer := gTime + 5000;
6408 end
6409 else
6410 begin
6411 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6412 MH_SEND_VoteEvent(NET_VE_FAILED);
6413 end;
6414 if NetClients <> nil then
6415 for I := Low(NetClients) to High(NetClients) do
6416 if NetClients[i].Used then
6417 NetClients[i].Voted := False;
6418 gVoteInProgress := False;
6419 gVoted := False;
6420 gVoteCount := 0;
6421 end
6422 else
6423 begin
6424 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6425 Need := Floor((NetClientCount+1)/2.0) + 1
6426 else
6427 Need := Floor(NetClientCount/2.0) + 1;
6428 if gVoteCount >= Need then
6429 begin
6430 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6431 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6432 gVoteInProgress := False;
6433 gVotePassed := True;
6434 gVoteCmdTimer := gTime + 5000;
6435 gVoted := False;
6436 gVoteCount := 0;
6437 if NetClients <> nil then
6438 for I := Low(NetClients) to High(NetClients) do
6439 if NetClients[i].Used then
6440 NetClients[i].Voted := False;
6441 end;
6442 end;
6443 end;
6445 procedure g_Game_LoadMapList(FileName: string);
6446 var
6447 ListFile: TextFile;
6448 s: string;
6449 begin
6450 MapList := nil;
6451 MapIndex := -1;
6453 if not FileExists(FileName) then Exit;
6455 AssignFile(ListFile, FileName);
6456 Reset(ListFile);
6457 while not EOF(ListFile) do
6458 begin
6459 ReadLn(ListFile, s);
6461 s := Trim(s);
6462 if s = '' then Continue;
6464 SetLength(MapList, Length(MapList)+1);
6465 MapList[High(MapList)] := s;
6466 end;
6467 CloseFile(ListFile);
6468 end;
6470 procedure g_Game_SetDebugMode();
6471 begin
6472 gDebugMode := True;
6473 // Читы (даже в своей игре):
6474 gCheats := True;
6475 end;
6477 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6478 var
6479 i: Word;
6480 begin
6481 if Length(LoadingStat.Msgs) = 0 then
6482 Exit;
6484 with LoadingStat do
6485 begin
6486 if not reWrite then
6487 begin // Переходим на следующую строку или скроллируем:
6488 if NextMsg = Length(Msgs) then
6489 begin // scroll
6490 for i := 0 to High(Msgs)-1 do
6491 Msgs[i] := Msgs[i+1];
6492 end
6493 else
6494 Inc(NextMsg);
6495 end else
6496 if NextMsg = 0 then
6497 Inc(NextMsg);
6499 Msgs[NextMsg-1] := Text;
6500 CurValue := 0;
6501 MaxValue := Max;
6502 ShowCount := 0;
6503 PBarWasHere := false;
6504 end;
6506 g_ActiveWindow := nil;
6508 ProcessLoading(true);
6509 end;
6511 procedure g_Game_StepLoading(Value: Integer = -1);
6512 begin
6513 with LoadingStat do
6514 begin
6515 if Value = -1 then
6516 begin
6517 Inc(CurValue);
6518 Inc(ShowCount);
6519 end
6520 else
6521 CurValue := Value;
6522 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
6523 begin
6524 ShowCount := 0;
6525 ProcessLoading();
6526 end;
6527 end;
6528 end;
6530 procedure g_Game_ClearLoading();
6531 var
6532 len: Word;
6533 begin
6534 with LoadingStat do
6535 begin
6536 CurValue := 0;
6537 MaxValue := 0;
6538 ShowCount := 0;
6539 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6540 if len < 1 then len := 1;
6541 SetLength(Msgs, len);
6542 for len := Low(Msgs) to High(Msgs) do
6543 Msgs[len] := '';
6544 NextMsg := 0;
6545 PBarWasHere := false;
6546 end;
6547 end;
6549 procedure Parse_Params(var pars: TParamStrValues);
6550 var
6551 i: Integer;
6552 s: String;
6553 begin
6554 SetLength(pars, 0);
6555 i := 1;
6556 while i <= ParamCount do
6557 begin
6558 s := ParamStr(i);
6559 if (s[1] = '-') and (Length(s) > 1) then
6560 begin
6561 if (s[2] = '-') and (Length(s) > 2) then
6562 begin // Одиночный параметр
6563 SetLength(pars, Length(pars) + 1);
6564 with pars[High(pars)] do
6565 begin
6566 Name := LowerCase(s);
6567 Value := '+';
6568 end;
6569 end
6570 else
6571 if (i < ParamCount) then
6572 begin // Параметр со значением
6573 Inc(i);
6574 SetLength(pars, Length(pars) + 1);
6575 with pars[High(pars)] do
6576 begin
6577 Name := LowerCase(s);
6578 Value := LowerCase(ParamStr(i));
6579 end;
6580 end;
6581 end;
6583 Inc(i);
6584 end;
6585 end;
6587 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6588 var
6589 i: Integer;
6590 begin
6591 Result := '';
6592 for i := 0 to High(pars) do
6593 if pars[i].Name = aName then
6594 begin
6595 Result := pars[i].Value;
6596 Break;
6597 end;
6598 end;
6600 procedure g_Game_Process_Params();
6601 var
6602 pars: TParamStrValues;
6603 map: String;
6604 GMode, n: Byte;
6605 LimT, LimS: Integer;
6606 Opt: LongWord;
6607 Lives: Integer;
6608 s: String;
6609 Port: Integer;
6610 ip: String;
6611 F: TextFile;
6612 begin
6613 Parse_Params(pars);
6615 // Debug mode:
6616 s := Find_Param_Value(pars, '--debug');
6617 if (s <> '') then
6618 begin
6619 g_Game_SetDebugMode();
6620 s := Find_Param_Value(pars, '--netdump');
6621 if (s <> '') then
6622 NetDump := True;
6623 end;
6625 // Connect when game loads
6626 ip := Find_Param_Value(pars, '-connect');
6628 if ip <> '' then
6629 begin
6630 s := Find_Param_Value(pars, '-port');
6631 if (s = '') or not TryStrToInt(s, Port) then
6632 Port := 25666;
6634 s := Find_Param_Value(pars, '-pw');
6636 g_Game_StartClient(ip, Port, s);
6637 Exit;
6638 end;
6640 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6641 if (s <> '') then
6642 begin
6643 gDefaultMegawadStart := s;
6644 end;
6646 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6647 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6648 begin
6649 gDefaultMegawadStart := DF_Default_Megawad_Start;
6650 end;
6652 // Start map when game loads:
6653 map := LowerCase(Find_Param_Value(pars, '-map'));
6654 if isWadPath(map) then
6655 begin
6656 // Game mode:
6657 s := Find_Param_Value(pars, '-gm');
6658 GMode := g_Game_TextToMode(s);
6659 if GMode = GM_NONE then GMode := GM_DM;
6660 if GMode = GM_SINGLE then GMode := GM_COOP;
6662 // Time limit:
6663 s := Find_Param_Value(pars, '-limt');
6664 if (s = '') or (not TryStrToInt(s, LimT)) then
6665 LimT := 0;
6666 if LimT < 0 then
6667 LimT := 0;
6669 // Goal limit:
6670 s := Find_Param_Value(pars, '-lims');
6671 if (s = '') or (not TryStrToInt(s, LimS)) then
6672 LimS := 0;
6673 if LimS < 0 then
6674 LimS := 0;
6676 // Lives limit:
6677 s := Find_Param_Value(pars, '-lives');
6678 if (s = '') or (not TryStrToInt(s, Lives)) then
6679 Lives := 0;
6680 if Lives < 0 then
6681 Lives := 0;
6683 // Options:
6684 s := Find_Param_Value(pars, '-opt');
6685 if (s = '') then
6686 Opt := gsGameFlags
6687 else
6688 Opt := StrToIntDef(s, 0);
6690 // Close after map:
6691 s := Find_Param_Value(pars, '--close');
6692 if (s <> '') then
6693 gMapOnce := True;
6695 // Override map to test:
6696 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6697 if s <> '' then
6698 begin
6699 if e_IsValidResourceName(s) then
6700 e_FindResource(AllMapDirs, s);
6701 gTestMap := ExpandFileName(s);
6702 end;
6704 // Delete test map after play:
6705 s := Find_Param_Value(pars, '--testdelete');
6706 if (s <> '') then
6707 begin
6708 //gMapToDelete := MapsDir + map;
6709 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6710 Halt(1);
6711 end;
6713 // Delete temporary WAD after play:
6714 s := Find_Param_Value(pars, '--tempdelete');
6715 if (s <> '') and (gTestMap <> '') then
6716 begin
6717 gMapToDelete := gTestMap;
6718 gTempDelete := True;
6719 end;
6721 // Number of players:
6722 s := Find_Param_Value(pars, '-pl');
6723 if (s = '') then
6724 n := DEFAULT_PLAYERS
6725 else
6726 n := StrToIntDef(s, DEFAULT_PLAYERS);
6728 // Start:
6729 s := Find_Param_Value(pars, '-port');
6730 if (s = '') or not TryStrToInt(s, Port) then
6731 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6732 else
6733 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6734 end;
6736 // Execute script when game loads:
6737 s := Find_Param_Value(pars, '-exec');
6738 if s <> '' then
6739 begin
6740 // if not isWadPath(s) then
6741 // s := GameDir + '/' + s;
6743 {$I-}
6744 AssignFile(F, s);
6745 Reset(F);
6746 if IOResult <> 0 then
6747 begin
6748 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6749 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6750 CloseFile(F);
6751 Exit;
6752 end;
6753 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
6754 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6756 while not EOF(F) do
6757 begin
6758 ReadLn(F, s);
6759 if IOResult <> 0 then
6760 begin
6761 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6762 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6763 CloseFile(F);
6764 Exit;
6765 end;
6766 if Pos('#', s) <> 1 then // script comment
6767 g_Console_Process(s, True);
6768 end;
6770 CloseFile(F);
6771 {$I+}
6772 end;
6774 SetLength(pars, 0);
6775 end;
6777 begin
6778 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
6779 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6780 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
6781 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
6783 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
6784 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6785 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6786 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6788 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
6789 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
6791 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
6792 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
6794 {$IFDEF ENABLE_HOLMES}
6795 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
6796 {$ENDIF}
6798 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
6800 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
6801 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
6803 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6804 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6806 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
6807 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
6808 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
6809 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
6810 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
6811 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
6812 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
6813 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
6814 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
6815 end.