DEADSOFTWARE

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