DEADSOFTWARE

gl: draw custom game stats
[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 // Обновляем все остальное:
2241 g_Map_Update();
2242 g_Items_Update();
2243 g_Triggers_Update();
2244 g_Weapon_Update();
2245 g_Monsters_Update();
2246 {$IFDEF ENABLE_GFX}
2247 g_GFX_Update;
2248 {$ENDIF}
2249 g_Player_UpdateAll();
2250 {$IFDEF ENABLE_GIBS}
2251 g_Gibs_Update;
2252 {$ENDIF}
2253 {$IFDEF ENABLE_CORPSES}
2254 g_Corpses_Update;
2255 {$ENDIF}
2256 {$IFDEF ENABLE_SHELLS}
2257 g_Shells_Update;
2258 {$ENDIF}
2260 // server: send newly spawned monsters unconditionally
2261 if (gGameSettings.GameType = GT_SERVER) then
2262 begin
2263 if (Length(gMonstersSpawned) > 0) then
2264 begin
2265 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2266 SetLength(gMonstersSpawned, 0);
2267 end;
2268 end;
2270 if (gSoundTriggerTime > 8) then
2271 begin
2272 g_Game_UpdateTriggerSounds();
2273 gSoundTriggerTime := 0;
2274 end
2275 else
2276 begin
2277 Inc(gSoundTriggerTime);
2278 end;
2280 if (NetMode = NET_SERVER) then
2281 begin
2282 Inc(NetTimeToUpdate);
2283 Inc(NetTimeToReliable);
2285 // send monster updates
2286 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2287 begin
2288 // send all monsters (periodic sync)
2289 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2291 for I := 0 to High(gPlayers) do
2292 begin
2293 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2294 end;
2296 g_Mons_ForEach(sendMonsPos);
2298 // update flags that aren't stationary
2299 if gGameSettings.GameMode = GM_CTF then
2300 for I := FLAG_RED to FLAG_BLUE do
2301 if gFlags[I].NeedSend then
2302 begin
2303 gFlags[I].NeedSend := False;
2304 MH_SEND_FlagPos(I);
2305 end;
2307 // update items that aren't stationary
2308 g_Items_ForEachAlive(sendItemPos);
2310 if reliableUpdate then
2311 begin
2312 NetTimeToReliable := 0;
2313 NetTimeToUpdate := NetUpdateRate;
2314 end
2315 else
2316 begin
2317 NetTimeToUpdate := 0;
2318 end;
2319 end
2320 else
2321 begin
2322 // send only mosters with some unexpected changes
2323 g_Mons_ForEach(sendMonsPosUnexpected);
2324 end;
2326 // send unexpected platform changes
2327 g_Map_NetSendInterestingPanels();
2329 g_Net_Slist_ServerUpdate();
2331 if NetUseMaster then
2332 begin
2333 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2334 begin
2335 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2336 g_Net_Slist_Update;
2337 NetTimeToMaster := gTime + NetMasterRate;
2338 end;
2339 end;
2341 end
2342 else if (NetMode = NET_CLIENT) then
2343 begin
2344 MC_SEND_PlayerPos();
2345 end;
2346 end; // if gameOn ...
2348 // Активно окно интерфейса - передаем клавиши ему:
2349 {$IFDEF ENABLE_MENU}
2350 if g_ActiveWindow <> nil then
2351 begin
2352 w := e_GetFirstKeyPressed();
2354 if (w <> IK_INVALID) then
2355 begin
2356 Msg.Msg := MESSAGE_DIKEY;
2357 Msg.wParam := w;
2358 g_ActiveWindow.OnMessage(Msg);
2359 end;
2361 // Если оно от этого не закрылось, то обновляем:
2362 if g_ActiveWindow <> nil then
2363 g_ActiveWindow.Update();
2365 // Нужно сменить разрешение:
2366 if gResolutionChange then
2367 begin
2368 {$IFDEF ENABLE_RENDER}
2369 e_WriteLog('Changing resolution', TMsgType.Notify);
2370 r_Render_Apply;
2371 {$ENDIF}
2372 gResolutionChange := False;
2373 g_ActiveWindow := nil;
2374 end;
2376 // Нужно сменить язык:
2377 if gLanguageChange then
2378 begin
2379 //e_WriteLog('Read language file', MSG_NOTIFY);
2380 //g_Language_Load(DataDir + gLanguage + '.txt');
2381 g_Language_Set(gLanguage);
2382 g_Menu_Reset();
2383 gLanguageChange := False;
2384 end;
2385 end;
2387 // Горячая клавиша для вызова меню выхода из игры (F10):
2388 if e_KeyPressed(IK_F10) and
2389 gGameOn and
2390 (not gConsoleShow) and
2391 (g_ActiveWindow = nil) then
2392 begin
2393 KeyPress(IK_F10);
2394 end;
2395 {$ENDIF}
2397 Time := GetTickCount64() {div 1000};
2399 // Обработка отложенных событий:
2400 if gDelayedEvents <> nil then
2401 for a := 0 to High(gDelayedEvents) do
2402 if gDelayedEvents[a].Pending and
2404 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2405 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2406 ) then
2407 begin
2408 case gDelayedEvents[a].DEType of
2409 DE_GLOBEVENT:
2410 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2411 DE_BFGHIT:
2412 if gGameOn then
2413 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2414 DE_KILLCOMBO:
2415 if gGameOn then
2416 begin
2417 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2418 if g_Game_IsNet and g_Game_IsServer then
2419 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2420 end;
2421 DE_BODYKILL:
2422 if gGameOn then
2423 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2424 end;
2425 gDelayedEvents[a].Pending := False;
2426 end;
2428 // Каждую секунду обновляем счетчик обновлений:
2429 UPSCounter := UPSCounter + 1;
2430 if Time - UPSTime >= 1000 then
2431 begin
2432 UPS := UPSCounter;
2433 UPSCounter := 0;
2434 UPSTime := Time;
2435 end;
2437 if gGameOn then
2438 begin
2439 g_Weapon_AddDynLights();
2440 g_Items_AddDynLights();
2441 end;
2442 end;
2444 procedure g_Game_LoadChatSounds(Resource: string);
2445 var
2446 WAD: TWADFile;
2447 FileName, Snd: string;
2448 p: Pointer;
2449 len, cnt, tags, i, j: Integer;
2450 cfg: TConfig;
2451 begin
2452 FileName := g_ExtractWadName(Resource);
2454 WAD := TWADFile.Create();
2455 WAD.ReadFile(FileName);
2457 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2458 begin
2459 gChatSounds := nil;
2460 WAD.Free();
2461 Exit;
2462 end;
2464 cfg := TConfig.CreateMem(p, len);
2465 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2467 SetLength(gChatSounds, cnt);
2468 for i := 0 to Length(gChatSounds) - 1 do
2469 begin
2470 gChatSounds[i].Sound := nil;
2471 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2472 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2473 if (Snd = '') or (Tags <= 0) then
2474 continue;
2475 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2476 gChatSounds[i].Sound := TPlayableSound.Create();
2477 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2478 SetLength(gChatSounds[i].Tags, tags);
2479 for j := 0 to tags - 1 do
2480 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2481 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2482 end;
2484 cfg.Free();
2485 WAD.Free();
2486 end;
2488 procedure g_Game_FreeChatSounds();
2489 var
2490 i: Integer;
2491 begin
2492 for i := 0 to Length(gChatSounds) - 1 do
2493 begin
2494 gChatSounds[i].Sound.Free();
2495 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2496 end;
2497 SetLength(gChatSounds, 0);
2498 gChatSounds := nil;
2499 end;
2501 procedure g_Game_LoadData();
2502 begin
2503 if DataLoaded then Exit;
2505 e_WriteLog('Loading game data...', TMsgType.Notify);
2507 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2508 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2509 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2510 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2511 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2512 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2513 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2514 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2515 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2516 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2517 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2518 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2519 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2520 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2521 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2522 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2523 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2524 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2525 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2526 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2527 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2528 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2529 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2530 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2531 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2532 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2533 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2534 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2535 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2536 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2537 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2538 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2540 goodsnd[0] := TPlayableSound.Create();
2541 goodsnd[1] := TPlayableSound.Create();
2542 goodsnd[2] := TPlayableSound.Create();
2543 goodsnd[3] := TPlayableSound.Create();
2545 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2546 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2547 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2548 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2550 killsnd[0] := TPlayableSound.Create();
2551 killsnd[1] := TPlayableSound.Create();
2552 killsnd[2] := TPlayableSound.Create();
2553 killsnd[3] := TPlayableSound.Create();
2555 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2556 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2557 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2558 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2560 hahasnd[0] := TPlayableSound.Create();
2561 hahasnd[1] := TPlayableSound.Create();
2562 hahasnd[2] := TPlayableSound.Create();
2564 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2565 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2566 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2568 sound_get_flag[0] := TPlayableSound.Create();
2569 sound_get_flag[1] := TPlayableSound.Create();
2570 sound_lost_flag[0] := TPlayableSound.Create();
2571 sound_lost_flag[1] := TPlayableSound.Create();
2572 sound_ret_flag[0] := TPlayableSound.Create();
2573 sound_ret_flag[1] := TPlayableSound.Create();
2574 sound_cap_flag[0] := TPlayableSound.Create();
2575 sound_cap_flag[1] := TPlayableSound.Create();
2577 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2578 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2579 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2580 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2581 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2582 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2583 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2584 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2586 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2588 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2589 g_Items_LoadData();
2591 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2592 g_Weapon_LoadData();
2594 g_Monsters_LoadData();
2596 DataLoaded := True;
2597 end;
2599 procedure g_Game_Quit();
2600 begin
2601 g_Game_StopAllSounds(True);
2602 gMusic.Free();
2603 g_Game_FreeData();
2604 g_PlayerModel_FreeData();
2605 {$IFDEF ENABLE_MENU}
2606 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2607 {$ENDIF}
2609 if NetInitDone then g_Net_Free;
2611 // remove map after test
2612 if gMapToDelete <> '' then
2613 g_Game_DeleteTestMap();
2615 gExit := EXIT_QUIT;
2617 {$IFDEF ENABLE_SYSTEM}
2618 sys_RequestQuit;
2619 {$ENDIF}
2620 end;
2622 procedure g_Game_FreeData();
2623 begin
2624 if not DataLoaded then Exit;
2626 g_Items_FreeData();
2627 g_Weapon_FreeData();
2628 g_Monsters_FreeData();
2630 e_WriteLog('Releasing game data...', TMsgType.Notify);
2632 g_Sound_Delete('SOUND_GAME_TELEPORT');
2633 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2634 g_Sound_Delete('SOUND_GAME_SECRET');
2635 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2636 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2637 g_Sound_Delete('SOUND_GAME_BULK1');
2638 g_Sound_Delete('SOUND_GAME_BULK2');
2639 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2640 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2641 g_Sound_Delete('SOUND_GAME_BURNING');
2642 g_Sound_Delete('SOUND_GAME_SWITCH1');
2643 g_Sound_Delete('SOUND_GAME_SWITCH0');
2645 goodsnd[0].Free();
2646 goodsnd[1].Free();
2647 goodsnd[2].Free();
2648 goodsnd[3].Free();
2650 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2651 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2652 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2653 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2655 killsnd[0].Free();
2656 killsnd[1].Free();
2657 killsnd[2].Free();
2658 killsnd[3].Free();
2660 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2661 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2662 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2663 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2665 hahasnd[0].Free();
2666 hahasnd[1].Free();
2667 hahasnd[2].Free();
2669 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2670 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2671 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2673 sound_get_flag[0].Free();
2674 sound_get_flag[1].Free();
2675 sound_lost_flag[0].Free();
2676 sound_lost_flag[1].Free();
2677 sound_ret_flag[0].Free();
2678 sound_ret_flag[1].Free();
2679 sound_cap_flag[0].Free();
2680 sound_cap_flag[1].Free();
2682 g_Sound_Delete('SOUND_CTF_GET1');
2683 g_Sound_Delete('SOUND_CTF_GET2');
2684 g_Sound_Delete('SOUND_CTF_LOST1');
2685 g_Sound_Delete('SOUND_CTF_LOST2');
2686 g_Sound_Delete('SOUND_CTF_RETURN1');
2687 g_Sound_Delete('SOUND_CTF_RETURN2');
2688 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2689 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2691 g_Game_FreeChatSounds();
2693 DataLoaded := False;
2694 end;
2696 procedure g_FatalError(Text: String);
2697 begin
2698 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2699 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2701 gExit := EXIT_SIMPLE;
2702 if gGameOn then EndGame;
2703 end;
2705 procedure g_SimpleError(Text: String);
2706 begin
2707 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2708 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2709 end;
2711 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2712 begin
2713 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2714 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2715 Exit;
2717 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2718 Exit;
2720 if gPlayer1 = nil then
2721 begin
2722 if g_Game_IsClient then
2723 begin
2724 if NetPlrUID1 > -1 then
2725 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2726 Exit;
2727 end;
2729 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2730 Team := gPlayer1Settings.Team;
2732 // Создание первого игрока:
2733 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2734 gPlayer1Settings.Color,
2735 Team, False));
2736 if gPlayer1 = nil then
2737 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2738 else
2739 begin
2740 gPlayer1.Name := gPlayer1Settings.Name;
2741 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2742 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2743 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2744 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2745 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2746 if g_Game_IsServer and g_Game_IsNet then
2747 MH_SEND_PlayerCreate(gPlayer1.UID);
2748 gPlayer1.Respawn(False, True);
2749 g_Net_Slist_ServerPlayerComes();
2750 end;
2752 Exit;
2753 end;
2754 if gPlayer2 = nil then
2755 begin
2756 if g_Game_IsClient then
2757 begin
2758 if NetPlrUID2 > -1 then
2759 gPlayer2 := g_Player_Get(NetPlrUID2);
2760 Exit;
2761 end;
2763 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2764 Team := gPlayer2Settings.Team;
2766 // Создание второго игрока:
2767 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2768 gPlayer2Settings.Color,
2769 Team, False));
2770 if gPlayer2 = nil then
2771 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2772 else
2773 begin
2774 gPlayer2.Name := gPlayer2Settings.Name;
2775 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2776 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2777 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2778 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2779 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2780 if g_Game_IsServer and g_Game_IsNet then
2781 MH_SEND_PlayerCreate(gPlayer2.UID);
2782 gPlayer2.Respawn(False, True);
2783 g_Net_Slist_ServerPlayerComes();
2784 end;
2786 Exit;
2787 end;
2788 end;
2790 procedure g_Game_RemovePlayer();
2791 var
2792 Pl: TPlayer;
2793 begin
2794 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2795 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2796 Exit;
2797 Pl := gPlayer2;
2798 if Pl <> nil then
2799 begin
2800 if g_Game_IsServer then
2801 begin
2802 Pl.Lives := 0;
2803 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2804 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2805 g_Player_Remove(Pl.UID);
2806 g_Net_Slist_ServerPlayerLeaves();
2807 end
2808 else
2809 begin
2810 gSpectLatchPID2 := Pl.UID;
2811 gPlayer2 := nil;
2812 end;
2813 Exit;
2814 end;
2815 Pl := gPlayer1;
2816 if Pl <> nil then
2817 begin
2818 if g_Game_IsServer then
2819 begin
2820 Pl.Lives := 0;
2821 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2822 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2823 g_Player_Remove(Pl.UID);
2824 g_Net_Slist_ServerPlayerLeaves();
2825 end else
2826 begin
2827 gSpectLatchPID1 := Pl.UID;
2828 gPlayer1 := nil;
2829 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2830 end;
2831 Exit;
2832 end;
2833 g_Net_Slist_ServerPlayerLeaves();
2834 end;
2836 procedure g_Game_Spectate();
2837 begin
2838 g_Game_RemovePlayer();
2839 if gPlayer1 <> nil then
2840 g_Game_RemovePlayer();
2841 end;
2843 procedure g_Game_SpectateCenterView();
2844 begin
2845 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2846 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2847 end;
2849 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2850 var
2851 i, nPl: Integer;
2852 tmps: AnsiString;
2853 begin
2854 g_Game_Free();
2856 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2858 g_Game_ClearLoading();
2860 // Настройки игры:
2861 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2862 gAimLine := False;
2863 gShowMap := False;
2864 gGameSettings.GameType := GT_SINGLE;
2865 gGameSettings.MaxLives := 0;
2866 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2867 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2868 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2869 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2870 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2871 gSwitchGameMode := GM_SINGLE;
2873 gLMSRespawn := LMS_RESPAWN_NONE;
2874 gLMSRespawnTime := 0;
2875 gSpectLatchPID1 := 0;
2876 gSpectLatchPID2 := 0;
2878 g_Game_ExecuteEvent('ongamestart');
2880 // Создание первого игрока:
2881 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2882 gPlayer1Settings.Color,
2883 gPlayer1Settings.Team, False));
2884 if gPlayer1 = nil then
2885 begin
2886 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2887 Exit;
2888 end;
2890 gPlayer1.Name := gPlayer1Settings.Name;
2891 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2892 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2893 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2894 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2895 nPl := 1;
2897 // Создание второго игрока, если есть:
2898 if TwoPlayers then
2899 begin
2900 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2901 gPlayer2Settings.Color,
2902 gPlayer2Settings.Team, False));
2903 if gPlayer2 = nil then
2904 begin
2905 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2906 Exit;
2907 end;
2909 gPlayer2.Name := gPlayer2Settings.Name;
2910 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2911 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2912 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2913 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2914 Inc(nPl);
2915 end;
2917 // Загрузка и запуск карты:
2918 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2919 begin
2920 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2921 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2922 Exit;
2923 end;
2925 // Настройки игроков и ботов:
2926 g_Player_Init();
2928 // Создаем ботов:
2929 for i := nPl+1 to nPlayers do
2930 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2931 end;
2933 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
2934 TimeLimit, ScoreLimit: Word;
2935 MaxLives: Byte;
2936 Options: LongWord; nPlayers: Byte);
2937 var
2938 i, nPl: Integer;
2939 begin
2940 g_Game_Free();
2942 e_WriteLog('Starting custom game...', TMsgType.Notify);
2944 g_Game_ClearLoading();
2946 // Настройки игры:
2947 gGameSettings.GameType := GT_CUSTOM;
2948 gGameSettings.GameMode := GameMode;
2949 gSwitchGameMode := GameMode;
2950 gGameSettings.TimeLimit := TimeLimit;
2951 gGameSettings.ScoreLimit := ScoreLimit;
2952 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
2953 gGameSettings.Options := Options;
2955 gCoopTotalMonstersKilled := 0;
2956 gCoopTotalSecretsFound := 0;
2957 gCoopTotalMonsters := 0;
2958 gCoopTotalSecrets := 0;
2959 gAimLine := False;
2960 gShowMap := False;
2962 gLMSRespawn := LMS_RESPAWN_NONE;
2963 gLMSRespawnTime := 0;
2964 gSpectLatchPID1 := 0;
2965 gSpectLatchPID2 := 0;
2967 g_Game_ExecuteEvent('ongamestart');
2969 // Режим наблюдателя:
2970 if nPlayers = 0 then
2971 begin
2972 gPlayer1 := nil;
2973 gPlayer2 := nil;
2974 end;
2976 nPl := 0;
2977 if nPlayers >= 1 then
2978 begin
2979 // Создание первого игрока:
2980 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2981 gPlayer1Settings.Color,
2982 gPlayer1Settings.Team, False));
2983 if gPlayer1 = nil then
2984 begin
2985 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2986 Exit;
2987 end;
2989 gPlayer1.Name := gPlayer1Settings.Name;
2990 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2991 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2992 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2993 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2994 Inc(nPl);
2995 end;
2997 if nPlayers >= 2 then
2998 begin
2999 // Создание второго игрока:
3000 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3001 gPlayer2Settings.Color,
3002 gPlayer2Settings.Team, False));
3003 if gPlayer2 = nil then
3004 begin
3005 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3006 Exit;
3007 end;
3009 gPlayer2.Name := gPlayer2Settings.Name;
3010 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
3011 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
3012 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
3013 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
3014 Inc(nPl);
3015 end;
3017 // Загрузка и запуск карты:
3018 if not g_Game_StartMap(true{asMegawad}, Map, True) then
3019 begin
3020 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3021 Exit;
3022 end;
3024 // Нет точек появления:
3025 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3026 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3027 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3028 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3029 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3030 begin
3031 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3032 Exit;
3033 end;
3035 // Настройки игроков и ботов:
3036 g_Player_Init();
3038 // Создаем ботов:
3039 for i := nPl+1 to nPlayers do
3040 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3041 end;
3043 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3044 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
3045 Options: LongWord; nPlayers: Byte;
3046 IPAddr: LongWord; Port: Word);
3047 begin
3048 g_Game_Free();
3049 g_Net_Slist_ServerClosed();
3051 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
3053 g_Game_ClearLoading();
3055 ClearDebugCvars();
3057 // Настройки игры:
3058 gGameSettings.GameType := GT_SERVER;
3059 gGameSettings.GameMode := GameMode;
3060 gSwitchGameMode := GameMode;
3061 gGameSettings.TimeLimit := TimeLimit;
3062 gGameSettings.ScoreLimit := ScoreLimit;
3063 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3064 gGameSettings.Options := Options;
3066 gCoopTotalMonstersKilled := 0;
3067 gCoopTotalSecretsFound := 0;
3068 gCoopTotalMonsters := 0;
3069 gCoopTotalSecrets := 0;
3070 gAimLine := False;
3071 gShowMap := False;
3073 gLMSRespawn := LMS_RESPAWN_NONE;
3074 gLMSRespawnTime := 0;
3075 gSpectLatchPID1 := 0;
3076 gSpectLatchPID2 := 0;
3078 g_Game_ExecuteEvent('ongamestart');
3080 // Режим наблюдателя:
3081 if nPlayers = 0 then
3082 begin
3083 gPlayer1 := nil;
3084 gPlayer2 := nil;
3085 end;
3087 if nPlayers >= 1 then
3088 begin
3089 // Создание первого игрока:
3090 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3091 gPlayer1Settings.Color,
3092 gPlayer1Settings.Team, False));
3093 if gPlayer1 = nil then
3094 begin
3095 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3096 Exit;
3097 end;
3099 gPlayer1.Name := gPlayer1Settings.Name;
3100 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
3101 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
3102 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
3103 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
3104 end;
3106 if nPlayers >= 2 then
3107 begin
3108 // Создание второго игрока:
3109 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3110 gPlayer2Settings.Color,
3111 gPlayer2Settings.Team, False));
3112 if gPlayer2 = nil then
3113 begin
3114 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3115 Exit;
3116 end;
3118 gPlayer2.Name := gPlayer2Settings.Name;
3119 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
3120 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
3121 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
3122 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
3123 end;
3125 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
3126 if NetForwardPorts then
3127 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
3129 // Стартуем сервер
3130 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3131 begin
3132 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
3133 Exit;
3134 end;
3136 g_Net_Slist_Set(NetMasterList);
3138 g_Net_Slist_ServerStarted();
3140 // Загрузка и запуск карты:
3141 if not g_Game_StartMap(false{asMegawad}, Map, True) then
3142 begin
3143 g_Net_Slist_ServerClosed();
3144 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3145 Exit;
3146 end;
3148 // Нет точек появления:
3149 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3150 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3151 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3152 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3153 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3154 begin
3155 g_Net_Slist_ServerClosed();
3156 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3157 Exit;
3158 end;
3160 // Настройки игроков и ботов:
3161 g_Player_Init();
3163 g_Net_Slist_ServerMapStarted();
3164 NetState := NET_STATE_GAME;
3165 end;
3167 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3168 var
3169 Map: String;
3170 WadName: string;
3171 Ptr: Pointer;
3172 T: Cardinal;
3173 MID: Byte;
3174 State: Byte;
3175 OuterLoop: Boolean;
3176 newResPath: string;
3177 InMsg: TMsg;
3178 begin
3179 g_Game_Free();
3181 State := 0;
3182 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
3183 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
3185 g_Game_ClearLoading();
3187 ClearDebugCvars();
3189 // Настройки игры:
3190 gGameSettings.GameType := GT_CLIENT;
3192 gCoopTotalMonstersKilled := 0;
3193 gCoopTotalSecretsFound := 0;
3194 gCoopTotalMonsters := 0;
3195 gCoopTotalSecrets := 0;
3196 gAimLine := False;
3197 gShowMap := False;
3199 g_Game_ExecuteEvent('ongamestart');
3201 NetState := NET_STATE_AUTH;
3203 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3205 // create (or update) map/resource databases
3206 g_Res_CreateDatabases(true);
3208 gLMSRespawn := LMS_RESPAWN_NONE;
3209 gLMSRespawnTime := 0;
3210 gSpectLatchPID1 := 0;
3211 gSpectLatchPID2 := 0;
3213 // Стартуем клиент
3214 if not g_Net_Connect(Addr, Port) then
3215 begin
3216 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3217 NetState := NET_STATE_NONE;
3218 Exit;
3219 end;
3221 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3222 MC_SEND_Info(PW);
3223 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3225 OuterLoop := True;
3226 while OuterLoop do
3227 begin
3228 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3229 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3230 // thank you, enet. let's ignore failures altogether then.
3231 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3232 begin
3233 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3234 begin
3235 Ptr := NetEvent.packet^.data;
3236 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3237 begin
3238 enet_packet_destroy(NetEvent.packet);
3239 continue;
3240 end;
3242 InMsg.ReadLongWord(); // skip size
3243 MID := InMsg.ReadByte();
3245 if (MID = NET_MSG_INFO) and (State = 0) then
3246 begin
3247 NetMyID := InMsg.ReadByte();
3248 NetPlrUID1 := InMsg.ReadWord();
3250 WadName := InMsg.ReadString();
3251 Map := InMsg.ReadString();
3253 gWADHash := InMsg.ReadMD5();
3255 gGameSettings.GameMode := InMsg.ReadByte();
3256 gSwitchGameMode := gGameSettings.GameMode;
3257 gGameSettings.ScoreLimit := InMsg.ReadWord();
3258 gGameSettings.TimeLimit := InMsg.ReadWord();
3259 gGameSettings.MaxLives := InMsg.ReadByte();
3260 gGameSettings.Options := InMsg.ReadLongWord();
3261 T := InMsg.ReadLongWord();
3263 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3264 //if newResPath = '' then
3265 begin
3266 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3267 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3268 if newResPath = '' then
3269 begin
3270 g_FatalError(_lc[I_NET_ERR_HASH]);
3271 enet_packet_destroy(NetEvent.packet);
3272 NetState := NET_STATE_NONE;
3273 Exit;
3274 end;
3275 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3276 end;
3277 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3280 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3281 gPlayer1Settings.Color,
3282 gPlayer1Settings.Team, False));
3284 if gPlayer1 = nil then
3285 begin
3286 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3288 enet_packet_destroy(NetEvent.packet);
3289 NetState := NET_STATE_NONE;
3290 Exit;
3291 end;
3293 gPlayer1.Name := gPlayer1Settings.Name;
3294 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
3295 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
3296 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
3297 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
3298 gPlayer1.UID := NetPlrUID1;
3299 gPlayer1.Reset(True);
3301 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3302 begin
3303 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3305 enet_packet_destroy(NetEvent.packet);
3306 NetState := NET_STATE_NONE;
3307 Exit;
3308 end;
3310 gTime := T;
3312 State := 1;
3313 OuterLoop := False;
3314 enet_packet_destroy(NetEvent.packet);
3315 break;
3316 end
3317 else
3318 enet_packet_destroy(NetEvent.packet);
3319 end
3320 else
3321 begin
3322 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3323 begin
3324 State := 0;
3325 if (NetEvent.data <= NET_DISC_MAX) then
3326 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3327 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3328 OuterLoop := False;
3329 Break;
3330 end;
3331 end;
3332 end;
3334 ProcessLoading(True);
3335 if g_Net_UserRequestExit() then
3336 begin
3337 State := 0;
3338 break;
3339 end;
3340 end;
3342 if State <> 1 then
3343 begin
3344 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3345 NetState := NET_STATE_NONE;
3346 Exit;
3347 end;
3349 g_Player_Init();
3350 NetState := NET_STATE_GAME;
3351 MC_SEND_FullStateRequest;
3352 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3353 end;
3355 var
3356 lastAsMegaWad: Boolean = false;
3358 procedure g_Game_ChangeMap(const MapPath: String);
3359 var
3360 Force: Boolean;
3361 begin
3362 g_Game_ClearLoading();
3364 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3365 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3366 if gExitByTrigger then
3367 begin
3368 Force := False;
3369 gExitByTrigger := False;
3370 end;
3371 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3372 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3373 end;
3375 procedure g_Game_Restart();
3376 var
3377 Map: string;
3378 begin
3379 if g_Game_IsClient then
3380 Exit;
3381 map := g_ExtractFileName(gMapInfo.Map);
3382 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3384 MessageTime := 0;
3385 gGameOn := False;
3386 g_Game_ClearLoading();
3387 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3388 end;
3390 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3391 var
3392 NewWAD, ResName: String;
3393 I: Integer;
3394 nws: AnsiString;
3395 begin
3396 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3398 {$IFDEF ENABLE_GIBS}
3399 g_Gibs_RemoveAll;
3400 {$ENDIF}
3401 {$IFDEF ENALBE_SHELLS}
3402 g_Shells_RemoveAll;
3403 {$ENDIF}
3404 {$IFDEF ENABLE_CORPSES}
3405 g_Corpses_RemoveAll;
3406 {$ENDIF}
3408 if (not g_Game_IsClient) and
3409 (gSwitchGameMode <> gGameSettings.GameMode) and
3410 (gGameSettings.GameMode <> GM_SINGLE) then
3411 begin
3412 if gSwitchGameMode = GM_CTF then
3413 gGameSettings.MaxLives := 0;
3414 gGameSettings.GameMode := gSwitchGameMode;
3415 Force := True;
3416 end else
3417 gSwitchGameMode := gGameSettings.GameMode;
3419 g_Player_ResetTeams();
3421 lastAsMegaWad := asMegawad;
3422 if isWadPath(Map) then
3423 begin
3424 NewWAD := g_ExtractWadName(Map);
3425 ResName := g_ExtractFileName(Map);
3426 if g_Game_IsServer then
3427 begin
3428 nws := findDiskWad(NewWAD);
3429 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3430 if (asMegawad) then
3431 begin
3432 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3433 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3434 end
3435 else
3436 begin
3437 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3438 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3439 end;
3440 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3441 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3442 //nws := NewWAD;
3443 if (length(nws) = 0) then
3444 begin
3445 ResName := ''; // failed
3446 end
3447 else
3448 begin
3449 NewWAD := nws;
3450 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3451 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3452 g_Game_LoadWAD(NewWAD);
3453 end;
3454 end
3455 else
3456 begin
3457 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3458 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3459 end;
3460 end
3461 else
3462 begin
3463 NewWAD := gGameSettings.WAD;
3464 ResName := Map;
3465 end;
3467 gTime := 0;
3469 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3470 result := false;
3471 if (ResName <> '') and (NewWAD <> '') then
3472 begin
3473 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3474 result := g_Map_Load(NewWAD+':\'+ResName);
3475 {$IFDEF ENABLE_RENDER}
3476 r_Render_LoadTextures;
3477 {$ENDIF}
3478 end;
3479 if Result then
3480 begin
3481 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3483 gState := STATE_NONE;
3484 {$IFDEF ENABLE_MENU}
3485 g_ActiveWindow := nil;
3486 {$ENDIF}
3487 gGameOn := True;
3489 DisableCheats();
3490 wNeedTimeReset := True;
3492 if gGameSettings.GameMode = GM_CTF then
3493 begin
3494 g_Map_ResetFlag(FLAG_RED);
3495 g_Map_ResetFlag(FLAG_BLUE);
3496 // CTF, а флагов нет:
3497 if not g_Map_HaveFlagPoints() then
3498 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3499 end;
3500 end
3501 else
3502 begin
3503 gState := STATE_MENU;
3504 gGameOn := False;
3505 end;
3507 gExit := 0;
3508 gPauseMain := false;
3509 gPauseHolmes := false;
3510 NetTimeToUpdate := 1;
3511 NetTimeToReliable := 0;
3512 NetTimeToMaster := NetMasterRate;
3513 gSpectLatchPID1 := 0;
3514 gSpectLatchPID2 := 0;
3515 gMissionFailed := False;
3516 gNextMap := '';
3518 gCoopMonstersKilled := 0;
3519 gCoopSecretsFound := 0;
3521 gVoteInProgress := False;
3522 gVotePassed := False;
3523 gVoteCount := 0;
3524 gVoted := False;
3526 gStatsOff := False;
3528 if not gGameOn then Exit;
3530 g_Game_SpectateCenterView();
3532 if g_Game_IsServer then
3533 begin
3534 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3535 begin
3536 gLMSRespawn := LMS_RESPAWN_WARMUP;
3537 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3538 gLMSSoftSpawn := True;
3539 if g_Game_IsNet then
3540 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3541 end
3542 else
3543 begin
3544 gLMSRespawn := LMS_RESPAWN_NONE;
3545 gLMSRespawnTime := 0;
3546 end;
3547 end;
3549 if NetMode = NET_SERVER then
3550 begin
3551 // reset full state flags
3552 if NetClients <> nil then
3553 for I := 0 to High(NetClients) do
3554 NetClients[I].FullUpdateSent := False;
3556 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3558 // Мастерсервер
3559 g_Net_Slist_ServerMapStarted();
3561 if NetClients <> nil then
3562 for I := 0 to High(NetClients) do
3563 if NetClients[I].Used then
3564 begin
3565 NetClients[I].Voted := False;
3566 if NetClients[I].RequestedFullUpdate then
3567 begin
3568 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3569 NetClients[I].RequestedFullUpdate := False;
3570 end;
3571 end;
3573 g_Net_UnbanNonPermHosts();
3574 end;
3576 if gLastMap then
3577 begin
3578 gCoopTotalMonstersKilled := 0;
3579 gCoopTotalSecretsFound := 0;
3580 gCoopTotalMonsters := 0;
3581 gCoopTotalSecrets := 0;
3582 gLastMap := False;
3583 end;
3585 g_Game_ExecuteEvent('onmapstart');
3586 end;
3588 procedure SetFirstLevel;
3589 begin
3590 gNextMap := '';
3592 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3593 if MapList = nil then
3594 Exit;
3596 SortSArray(MapList);
3597 gNextMap := MapList[Low(MapList)];
3599 MapList := nil;
3600 end;
3602 procedure g_Game_ExitLevel(const Map: AnsiString);
3603 begin
3604 gNextMap := Map;
3606 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3607 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3608 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3609 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3611 // Вышли в выход в Одиночной игре:
3612 if gGameSettings.GameType = GT_SINGLE then
3613 gExit := EXIT_ENDLEVELSINGLE
3614 else // Вышли в выход в Своей игре
3615 begin
3616 gExit := EXIT_ENDLEVELCUSTOM;
3617 if gGameSettings.GameMode = GM_COOP then
3618 g_Player_RememberAll;
3620 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3621 begin
3622 gLastMap := True;
3623 if gGameSettings.GameMode = GM_COOP then
3624 gStatsOff := True;
3626 gStatsPressed := True;
3627 gNextMap := 'MAP01';
3629 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3630 g_Game_NextLevel;
3632 if g_Game_IsNet then
3633 begin
3634 MH_SEND_GameStats();
3635 MH_SEND_CoopStats();
3636 end;
3637 end;
3638 end;
3639 end;
3641 procedure g_Game_RestartLevel();
3642 var
3643 Map: string;
3644 begin
3645 if gGameSettings.GameMode = GM_SINGLE then
3646 begin
3647 g_Game_Restart();
3648 Exit;
3649 end;
3650 gExit := EXIT_ENDLEVELCUSTOM;
3651 Map := g_ExtractFileName(gMapInfo.Map);
3652 gNextMap := Map;
3653 end;
3655 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3656 var
3657 gWAD{, xwad}: String;
3658 begin
3659 result := NewWAD;
3660 if not g_Game_IsClient then Exit;
3661 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3663 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3664 if gWAD = '' then
3665 begin
3666 result := '';
3667 g_Game_Free();
3668 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3669 Exit;
3670 end;
3672 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3673 NewWAD := gWAD;
3675 g_Game_LoadWAD(NewWAD);
3676 result := NewWAD;
3679 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3680 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3681 if gWAD = '' then
3682 begin
3683 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3684 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3685 if gWAD = '' then
3686 begin
3687 g_Game_Free();
3688 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3689 Exit;
3690 end;
3691 end;
3692 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3693 g_Game_LoadWAD(NewWAD);
3695 end;
3697 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3698 var
3699 i, n, nb, nr: Integer;
3700 begin
3701 if not g_Game_IsServer then Exit;
3702 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3703 gLMSRespawn := LMS_RESPAWN_NONE;
3704 gLMSRespawnTime := 0;
3705 MessageTime := 0;
3707 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3708 begin
3709 gMissionFailed := True;
3710 g_Game_RestartLevel;
3711 Exit;
3712 end;
3714 n := 0; nb := 0; nr := 0;
3715 for i := Low(gPlayers) to High(gPlayers) do
3716 if (gPlayers[i] <> nil) and
3717 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3718 (gPlayers[i] is TBot)) then
3719 begin
3720 Inc(n);
3721 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3722 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3723 end;
3725 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3726 begin
3727 // wait a second until the fuckers finally decide to join
3728 gLMSRespawn := LMS_RESPAWN_WARMUP;
3729 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3730 gLMSSoftSpawn := NoMapRestart;
3731 if g_Game_IsNet then
3732 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3733 Exit;
3734 end;
3736 {$IFDEF ENABLE_GIBS}
3737 g_Gibs_RemoveAll;
3738 {$ENDIF}
3739 {$IFDEF ENALBE_SHELLS}
3740 g_Shells_RemoveAll;
3741 {$ENDIF}
3742 {$IFDEF ENABLE_CORPSES}
3743 g_Corpses_RemoveAll;
3744 {$ENDIF}
3746 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3747 if g_Game_IsNet then
3748 MH_SEND_GameEvent(NET_EV_LMS_START);
3750 for i := Low(gPlayers) to High(gPlayers) do
3751 begin
3752 if gPlayers[i] = nil then continue;
3753 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3754 // don't touch normal spectators
3755 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3756 begin
3757 gPlayers[i].FNoRespawn := True;
3758 gPlayers[i].Lives := 0;
3759 if g_Game_IsNet then
3760 MH_SEND_PlayerStats(gPlayers[I].UID);
3761 continue;
3762 end;
3763 gPlayers[i].FNoRespawn := False;
3764 gPlayers[i].Lives := gGameSettings.MaxLives;
3765 gPlayers[i].Respawn(False, True);
3766 if gGameSettings.GameMode = GM_COOP then
3767 begin
3768 gPlayers[i].Frags := 0;
3769 gPlayers[i].RecallState;
3770 end;
3771 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3772 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3773 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3774 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3775 end;
3777 g_Items_RestartRound();
3779 gLMSSoftSpawn := False;
3780 end;
3782 function g_Game_GetFirstMap(WAD: String): String;
3783 begin
3784 Result := '';
3786 MapList := g_Map_GetMapsList(WAD);
3787 if MapList = nil then
3788 Exit;
3790 SortSArray(MapList);
3791 Result := MapList[Low(MapList)];
3793 if not g_Map_Exist(WAD + ':\' + Result) then
3794 Result := '';
3796 MapList := nil;
3797 end;
3799 function g_Game_GetNextMap(): String;
3800 var
3801 I: Integer;
3802 Map: string;
3803 begin
3804 Result := '';
3806 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3807 if MapList = nil then
3808 Exit;
3810 Map := g_ExtractFileName(gMapInfo.Map);
3812 SortSArray(MapList);
3813 MapIndex := -255;
3814 for I := Low(MapList) to High(MapList) do
3815 if Map = MapList[I] then
3816 begin
3817 MapIndex := I;
3818 Break;
3819 end;
3821 if MapIndex <> -255 then
3822 begin
3823 if MapIndex = High(MapList) then
3824 Result := MapList[Low(MapList)]
3825 else
3826 Result := MapList[MapIndex + 1];
3828 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3829 end;
3831 MapList := nil;
3832 end;
3834 procedure g_Game_NextLevel();
3835 begin
3836 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3837 gExit := EXIT_ENDLEVELCUSTOM
3838 else
3839 begin
3840 gExit := EXIT_ENDLEVELSINGLE;
3841 Exit;
3842 end;
3844 if gNextMap <> '' then Exit;
3845 gNextMap := g_Game_GetNextMap();
3846 end;
3848 function g_Game_IsTestMap(): Boolean;
3849 begin
3850 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3851 end;
3853 procedure g_Game_DeleteTestMap();
3854 var
3855 a: Integer;
3856 //MapName: AnsiString;
3857 WadName: string;
3859 WAD: TWADFile;
3860 MapList: SSArray;
3861 time: Integer;
3863 begin
3864 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3865 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3866 if (a = 0) then exit;
3868 // Выделяем имя wad-файла и имя карты
3869 WadName := Copy(gMapToDelete, 1, a+3);
3870 Delete(gMapToDelete, 1, a+5);
3871 gMapToDelete := UpperCase(gMapToDelete);
3872 //MapName := '';
3873 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3876 // Имя карты не стандартное тестовое:
3877 if MapName <> TEST_MAP_NAME then
3878 Exit;
3880 if not gTempDelete then
3881 begin
3882 time := g_GetFileTime(WadName);
3883 WAD := TWADFile.Create();
3885 // Читаем Wad-файл:
3886 if not WAD.ReadFile(WadName) then
3887 begin // Нет такого WAD-файла
3888 WAD.Free();
3889 Exit;
3890 end;
3892 // Составляем список карт и ищем нужную:
3893 WAD.CreateImage();
3894 MapList := WAD.GetResourcesList('');
3896 if MapList <> nil then
3897 for a := 0 to High(MapList) do
3898 if MapList[a] = MapName then
3899 begin
3900 // Удаляем и сохраняем:
3901 WAD.RemoveResource('', MapName);
3902 WAD.SaveTo(WadName);
3903 Break;
3904 end;
3906 WAD.Free();
3907 g_SetFileTime(WadName, time);
3908 end else
3910 if gTempDelete then DeleteFile(WadName);
3911 end;
3913 procedure GameCVars(P: SSArray);
3914 var
3915 a, b: Integer;
3916 stat: TPlayerStatArray;
3917 cmd: string;
3919 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3920 var
3921 x: Boolean;
3922 begin
3923 if Length(P) > 1 then
3924 begin
3925 x := P[1] = '1';
3927 if x then
3928 gsGameFlags := gsGameFlags or Flag
3929 else
3930 gsGameFlags := gsGameFlags and (not Flag);
3932 if g_Game_IsServer then
3933 begin
3934 if x then
3935 gGameSettings.Options := gGameSettings.Options or Flag
3936 else
3937 gGameSettings.Options := gGameSettings.Options and (not Flag);
3938 if g_Game_IsNet then MH_SEND_GameSettings;
3939 end;
3940 end;
3942 if LongBool(gsGameFlags and Flag) then
3943 g_Console_Add(_lc[OnMsg])
3944 else
3945 g_Console_Add(_lc[OffMsg]);
3947 if OnMapChange and g_Game_IsServer then
3948 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3949 end;
3951 begin
3952 stat := nil;
3953 cmd := LowerCase(P[0]);
3955 if cmd = 'g_gamemode' then
3956 begin
3957 if (Length(P) > 1) then
3958 begin
3959 a := g_Game_TextToMode(P[1]);
3960 if a = GM_SINGLE then a := GM_COOP;
3961 gsGameMode := g_Game_ModeToText(a);
3962 if g_Game_IsServer then
3963 begin
3964 gSwitchGameMode := a;
3965 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
3966 (gState = STATE_INTERSINGLE) then
3967 gSwitchGameMode := GM_SINGLE;
3968 if not gGameOn then
3969 gGameSettings.GameMode := gSwitchGameMode;
3970 end;
3971 end;
3973 if gSwitchGameMode = gGameSettings.GameMode then
3974 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
3975 [g_Game_ModeToText(gGameSettings.GameMode)]))
3976 else
3977 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
3978 [g_Game_ModeToText(gGameSettings.GameMode),
3979 g_Game_ModeToText(gSwitchGameMode)]));
3980 end
3981 else if cmd = 'g_friendlyfire' then
3982 begin
3983 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
3984 end
3985 else if cmd = 'g_friendly_absorb_damage' then
3986 begin
3987 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
3988 end
3989 else if cmd = 'g_friendly_hit_trace' then
3990 begin
3991 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
3992 end
3993 else if cmd = 'g_friendly_hit_projectile' then
3994 begin
3995 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
3996 end
3997 else if cmd = 'g_weaponstay' then
3998 begin
3999 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
4000 end
4001 else if cmd = 'g_allow_exit' then
4002 begin
4003 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
4004 end
4005 else if cmd = 'g_allow_monsters' then
4006 begin
4007 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
4008 end
4009 else if cmd = 'g_allow_dropflag' then
4010 begin
4011 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
4012 end
4013 else if cmd = 'g_throw_flag' then
4014 begin
4015 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
4016 end
4017 else if cmd = 'g_bot_vsplayers' then
4018 begin
4019 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
4020 end
4021 else if cmd = 'g_bot_vsmonsters' then
4022 begin
4023 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
4024 end
4025 else if cmd = 'g_dm_keys' then
4026 begin
4027 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
4028 end
4029 else if cmd = 'g_gameflags' then
4030 begin
4031 if Length(P) > 1 then
4032 begin
4033 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
4034 if g_Game_IsServer then
4035 begin
4036 gGameSettings.Options := gsGameFlags;
4037 if g_Game_IsNet then MH_SEND_GameSettings;
4038 end;
4039 end;
4041 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
4042 end
4043 else if cmd = 'g_warmup_time' then
4044 begin
4045 if Length(P) > 1 then
4046 begin
4047 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
4048 if g_Game_IsServer then
4049 begin
4050 gGameSettings.WarmupTime := gsWarmupTime;
4051 // extend warmup if it's already going
4052 if gLMSRespawn = LMS_RESPAWN_WARMUP then
4053 begin
4054 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
4055 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
4056 end;
4057 if g_Game_IsNet then MH_SEND_GameSettings;
4058 end;
4059 end;
4061 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
4062 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4063 end
4064 else if cmd = 'g_spawn_invul' then
4065 begin
4066 if Length(P) > 1 then
4067 begin
4068 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
4069 if g_Game_IsServer then
4070 begin
4071 gGameSettings.SpawnInvul := gsSpawnInvul;
4072 if g_Game_IsNet then MH_SEND_GameSettings;
4073 end;
4074 end;
4076 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
4077 end
4078 else if cmd = 'g_item_respawn_time' then
4079 begin
4080 if Length(P) > 1 then
4081 begin
4082 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
4083 if g_Game_IsServer then
4084 begin
4085 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
4086 if g_Game_IsNet then MH_SEND_GameSettings;
4087 end;
4088 end;
4090 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
4091 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4092 end
4093 else if cmd = 'sv_intertime' then
4094 begin
4095 if (Length(P) > 1) then
4096 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4098 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4099 end
4100 else if cmd = 'g_max_particles' then
4101 begin
4102 if Length(p) = 2 then
4103 begin
4104 {$IFDEF ENABLE_GFX}
4105 a := Max(0, StrToIntDef(p[1], 0));
4106 g_GFX_SetMax(a)
4107 {$ENDIF}
4108 end
4109 else if Length(p) = 1 then
4110 begin
4111 {$IFDEF ENABLE_GFX}
4112 e_LogWritefln('%s', [g_GFX_GetMax()])
4113 {$ELSE}
4114 e_LogWritefln('%s', [0])
4115 {$ENDIF}
4116 end
4117 else
4118 begin
4119 e_LogWritefln('usage: %s <n>', [cmd])
4120 end
4121 end
4122 else if cmd = 'g_max_shells' then
4123 begin
4124 if Length(p) = 2 then
4125 begin
4126 {$IFDEF ENABLE_SHELLS}
4127 a := Max(0, StrToIntDef(p[1], 0));
4128 g_Shells_SetMax(a)
4129 {$ENDIF}
4130 end
4131 else if Length(p) = 1 then
4132 begin
4133 {$IFDEF ENABLE_SHELLS}
4134 e_LogWritefln('%s', [g_Shells_GetMax()])
4135 {$ELSE}
4136 e_LogWritefln('%s', [0])
4137 {$ENDIF}
4138 end
4139 else
4140 begin
4141 e_LogWritefln('usage: %s <n>', [cmd])
4142 end
4143 end
4144 else if cmd = 'g_max_gibs' then
4145 begin
4146 if Length(p) = 2 then
4147 begin
4148 {$IFDEF ENABLE_GIBS}
4149 a := Max(0, StrToIntDef(p[1], 0));
4150 g_Gibs_SetMax(a)
4151 {$ENDIF}
4152 end
4153 else if Length(p) = 1 then
4154 begin
4155 {$IFDEF ENABLE_GIBS}
4156 e_LogWritefln('%s', [g_Gibs_GetMax()])
4157 {$ELSE}
4158 e_LogWritefln('%s', [0])
4159 {$ENDIF}
4160 end
4161 else
4162 begin
4163 e_LogWritefln('usage: %s <n>', [cmd])
4164 end
4165 end
4166 else if cmd = 'g_max_corpses' then
4167 begin
4168 if Length(p) = 2 then
4169 begin
4170 {$IFDEF ENABLE_CORPSES}
4171 a := Max(0, StrToIntDef(p[1], 0));
4172 g_Corpses_SetMax(a)
4173 {$ENDIF}
4174 end
4175 else if Length(p) = 1 then
4176 begin
4177 {$IFDEF ENABLE_CORPSES}
4178 e_LogWritefln('%s', [g_Corpses_GetMax()])
4179 {$ELSE}
4180 e_LogWritefln('%s', [0])
4181 {$ENDIF}
4182 end
4183 else
4184 begin
4185 e_LogWritefln('usage: %s <n>', [cmd])
4186 end
4187 end
4188 else if cmd = 'g_force_model' then
4189 begin
4190 if Length(p) = 2 then
4191 begin
4192 a := StrToIntDef(p[1], 0);
4193 g_Force_Model_Set(a);
4194 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
4195 begin
4196 for a := Low(gPlayers) to High(gPlayers) do
4197 begin
4198 if (gPlayers[a] <> nil) then
4199 begin
4200 if (gPlayers[a].UID = gPlayer1.UID) then
4201 continue
4202 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
4203 continue;
4204 gPlayers[a].setModel(g_Forced_Model_GetName());
4205 end;
4206 end
4207 end
4208 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
4209 begin
4210 for a := Low(gPlayers) to High(gPlayers) do
4211 begin
4212 if (gPlayers[a] <> nil) then
4213 begin
4214 if (gPlayers[a].UID = gPlayer1.UID) then
4215 continue
4216 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
4217 continue;
4218 gPlayers[a].setModel(gPlayers[a].FActualModelName);
4219 end;
4220 end
4221 end
4222 end
4223 end
4224 else if cmd = 'g_force_model_name' then
4225 begin
4226 if (Length(P) > 1) then
4227 begin
4228 cmd := b_Text_Unformat(P[1]);
4229 g_Forced_Model_SetName(cmd);
4230 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
4231 begin
4232 for a := Low(gPlayers) to High(gPlayers) do
4233 begin
4234 if (gPlayers[a] <> nil) then
4235 begin
4236 if (gPlayers[a].UID = gPlayer1.UID) then
4237 continue
4238 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
4239 continue;
4240 gPlayers[a].setModel(g_Forced_Model_GetName());
4241 end;
4242 end
4243 end
4244 end
4245 end
4246 else if cmd = 'g_scorelimit' then
4247 begin
4248 if Length(P) > 1 then
4249 begin
4250 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
4252 if g_Game_IsServer then
4253 begin
4254 b := 0;
4255 if gGameSettings.GameMode = GM_DM then
4256 begin // DM
4257 stat := g_Player_GetStats();
4258 if stat <> nil then
4259 for a := 0 to High(stat) do
4260 if stat[a].Frags > b then
4261 b := stat[a].Frags;
4262 end
4263 else // TDM/CTF
4264 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
4266 // if someone has a higher score, set it to that instead
4267 gsScoreLimit := max(gsScoreLimit, b);
4268 gGameSettings.ScoreLimit := gsScoreLimit;
4270 if g_Game_IsNet then MH_SEND_GameSettings;
4271 end;
4272 end;
4274 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
4275 end
4276 else if cmd = 'g_timelimit' then
4277 begin
4278 if Length(P) > 1 then
4279 begin
4280 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4281 if g_Game_IsServer then
4282 begin
4283 gGameSettings.TimeLimit := gsTimeLimit;
4284 if g_Game_IsNet then MH_SEND_GameSettings;
4285 end;
4286 end;
4287 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4288 [gsTimeLimit div 3600,
4289 (gsTimeLimit div 60) mod 60,
4290 gsTimeLimit mod 60]));
4291 end
4292 else if cmd = 'g_max_bots' then
4293 begin
4294 if Length(P) > 1 then
4295 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
4296 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
4297 end
4298 else if cmd = 'g_maxlives' then
4299 begin
4300 if Length(P) > 1 then
4301 begin
4302 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4303 if g_Game_IsServer then
4304 begin
4305 gGameSettings.MaxLives := gsMaxLives;
4306 if g_Game_IsNet then MH_SEND_GameSettings;
4307 end;
4308 end;
4310 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4311 end;
4312 end;
4314 procedure PlayerSettingsCVars(P: SSArray);
4315 var
4316 cmd: string;
4317 team: Byte;
4319 function ParseTeam(s: string): Byte;
4320 begin
4321 result := 0;
4322 case s of
4323 'red', '1': result := TEAM_RED;
4324 'blue', '2': result := TEAM_BLUE;
4325 else result := TEAM_NONE;
4326 end;
4327 end;
4328 begin
4329 cmd := LowerCase(P[0]);
4330 case cmd of
4331 'p1_name':
4332 begin
4333 if (Length(P) > 1) then
4334 begin
4335 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4336 if g_Game_IsClient then
4337 MC_SEND_PlayerSettings
4338 else if gGameOn and (gPlayer1 <> nil) then
4339 begin
4340 gPlayer1.Name := b_Text_Unformat(P[1]);
4341 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4342 end;
4343 end;
4344 end;
4345 'p2_name':
4346 begin
4347 if (Length(P) > 1) then
4348 begin
4349 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4350 if g_Game_IsClient then
4351 MC_SEND_PlayerSettings
4352 else if gGameOn and (gPlayer2 <> nil) then
4353 begin
4354 gPlayer2.Name := b_Text_Unformat(P[1]);
4355 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4356 end;
4357 end;
4358 end;
4359 'p1_color':
4360 begin
4361 if Length(P) > 3 then
4362 begin
4363 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4364 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4365 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4366 if g_Game_IsClient then
4367 MC_SEND_PlayerSettings
4368 else if gGameOn and (gPlayer1 <> nil) then
4369 begin
4370 gPlayer1.SetColor(gPlayer1Settings.Color);
4371 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4372 end;
4373 end;
4374 end;
4375 'p2_color':
4376 begin
4377 if Length(P) > 3 then
4378 begin
4379 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4380 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4381 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4382 if g_Game_IsClient then
4383 MC_SEND_PlayerSettings
4384 else if gGameOn and (gPlayer2 <> nil) then
4385 begin
4386 gPlayer2.SetColor(gPlayer2Settings.Color);
4387 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4388 end;
4389 end;
4390 end;
4391 'p1_model':
4392 begin
4393 if (Length(P) > 1) then
4394 begin
4395 gPlayer1Settings.Model := P[1];
4396 if g_Game_IsClient then
4397 MC_SEND_PlayerSettings
4398 else if gGameOn and (gPlayer1 <> nil) then
4399 begin
4400 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4401 gPlayer1.SetModel(gPlayer1Settings.Model);
4402 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4403 end;
4404 end;
4405 end;
4406 'p2_model':
4407 begin
4408 if (Length(P) > 1) then
4409 begin
4410 gPlayer2Settings.Model := P[1];
4411 if g_Game_IsClient then
4412 MC_SEND_PlayerSettings
4413 else if gGameOn and (gPlayer2 <> nil) then
4414 begin
4415 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4416 gPlayer2.SetModel(gPlayer2Settings.Model);
4417 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4418 end;
4419 end;
4420 end;
4421 'p1_team':
4422 begin
4423 // TODO: switch teams if in game or store this separately
4424 if (Length(P) > 1) then
4425 begin
4426 team := ParseTeam(P[1]);
4427 if team = TEAM_NONE then
4428 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4429 else if not gGameOn and not g_Game_IsNet then
4430 gPlayer1Settings.Team := team
4431 else
4432 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4433 end;
4434 end;
4435 'p2_team':
4436 begin
4437 // TODO: switch teams if in game or store this separately
4438 if (Length(P) > 1) then
4439 begin
4440 team := ParseTeam(P[1]);
4441 if team = TEAM_NONE then
4442 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4443 else if not gGameOn and not g_Game_IsNet then
4444 gPlayer2Settings.Team := team
4445 else
4446 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4447 end;
4448 end;
4449 'p1_autoswitch':
4450 begin
4451 if (Length(P) = 2) then
4452 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
4453 end;
4454 'p2_autoswitch':
4455 begin
4456 if (Length(P) = 2) then
4457 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
4458 end;
4459 'p1_switch_empty':
4460 begin
4461 if (Length(P) = 2) then
4462 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4463 end;
4464 'p2_switch_empty':
4465 begin
4466 if (Length(P) = 2) then
4467 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4468 end;
4469 'p1_skip_fist':
4470 begin
4471 if (Length(P) = 2) then
4472 gPlayer1Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4473 end;
4474 'p2_skip_fist':
4475 begin
4476 if (Length(P) = 2) then
4477 gPlayer2Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4478 end;
4479 'p1_priority_kastet':
4480 begin
4481 if (Length(P) = 2) then
4482 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4483 end;
4484 'p2_priority_kastet':
4485 begin
4486 if (Length(P) = 2) then
4487 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4488 end;
4489 'p1_priority_saw':
4490 begin
4491 if (Length(P) = 2) then
4492 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4493 end;
4494 'p2_priority_saw':
4495 begin
4496 if (Length(P) = 2) then
4497 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4498 end;
4499 'p1_priority_pistol':
4500 begin
4501 if (Length(P) = 2) then
4502 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4503 end;
4504 'p2_priority_pistol':
4505 begin
4506 if (Length(P) = 2) then
4507 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4508 end;
4509 'p1_priority_shotgun1':
4510 begin
4511 if (Length(P) = 2) then
4512 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4513 end;
4514 'p2_priority_shotgun1':
4515 begin
4516 if (Length(P) = 2) then
4517 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4518 end;
4519 'p1_priority_shotgun2':
4520 begin
4521 if (Length(P) = 2) then
4522 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4523 end;
4524 'p2_priority_shotgun2':
4525 begin
4526 if (Length(P) = 2) then
4527 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4528 end;
4529 'p1_priority_chaingun':
4530 begin
4531 if (Length(P) = 2) then
4532 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4533 end;
4534 'p2_priority_chaingun':
4535 begin
4536 if (Length(P) = 2) then
4537 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4538 end;
4539 'p1_priority_rocketlauncher':
4540 begin
4541 if (Length(P) = 2) then
4542 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4543 end;
4544 'p2_priority_rocketlauncher':
4545 begin
4546 if (Length(P) = 2) then
4547 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4548 end;
4549 'p1_priority_plasma':
4550 begin
4551 if (Length(P) = 2) then
4552 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4553 end;
4554 'p2_priority_plasma':
4555 begin
4556 if (Length(P) = 2) then
4557 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4558 end;
4559 'p1_priority_bfg':
4560 begin
4561 if (Length(P) = 2) then
4562 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4563 end;
4564 'p2_priority_bfg':
4565 begin
4566 if (Length(P) = 2) then
4567 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4568 end;
4569 'p1_priority_super':
4570 begin
4571 if (Length(P) = 2) then
4572 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4573 end;
4574 'p2_priority_super':
4575 begin
4576 if (Length(P) = 2) then
4577 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4578 end;
4579 'p1_priority_flamethrower':
4580 begin
4581 if (Length(P) = 2) then
4582 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4583 end;
4584 'p2_priority_flamethrower':
4585 begin
4586 if (Length(P) = 2) then
4587 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4588 end;
4589 'p1_priority_berserk':
4590 begin
4591 if (Length(P) = 2) then
4592 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4593 end;
4594 'p2_priority_berserk':
4595 begin
4596 if (Length(P) = 2) then
4597 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4598 end;
4599 end;
4600 end;
4602 procedure PrintHeapStats();
4603 var
4604 hs: TFPCHeapStatus;
4605 begin
4606 hs := GetFPCHeapStatus();
4607 e_LogWriteLn ('v===== heap status =====v');
4608 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4609 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4610 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4611 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4612 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4613 e_LogWriteLn ('^=======================^');
4614 end;
4616 procedure DebugCommands(P: SSArray);
4617 var
4618 a, b: Integer;
4619 cmd: string;
4620 //pt: TDFPoint;
4621 mon: TMonster;
4622 begin
4623 // Команды отладочного режима:
4624 if {gDebugMode}conIsCheatsEnabled then
4625 begin
4626 cmd := LowerCase(P[0]);
4627 if cmd = 'd_window' then
4628 begin
4629 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4630 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4631 end
4632 else if cmd = 'd_sounds' then
4633 begin
4634 if (Length(P) > 1) and
4635 ((P[1] = '1') or (P[1] = '0')) then
4636 g_Debug_Sounds := (P[1][1] = '1');
4638 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4639 end
4640 else if cmd = 'd_frames' then
4641 begin
4642 if (Length(P) > 1) and
4643 ((P[1] = '1') or (P[1] = '0')) then
4644 g_Debug_Frames := (P[1][1] = '1');
4646 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4647 end
4648 else if cmd = 'd_winmsg' then
4649 begin
4650 if (Length(P) > 1) and
4651 ((P[1] = '1') or (P[1] = '0')) then
4652 g_Debug_WinMsgs := (P[1][1] = '1');
4654 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4655 end
4656 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4657 begin
4658 if (Length(P) > 1) and
4659 ((P[1] = '1') or (P[1] = '0')) then
4660 g_Debug_MonsterOff := (P[1][1] = '1');
4662 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4663 end
4664 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4665 begin
4666 if Length(P) > 1 then
4667 case P[1][1] of
4668 '0': g_debug_BotAIOff := 0;
4669 '1': g_debug_BotAIOff := 1;
4670 '2': g_debug_BotAIOff := 2;
4671 '3': g_debug_BotAIOff := 3;
4672 end;
4674 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4675 end
4676 else if cmd = 'd_monster' then
4677 begin
4678 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4679 if Length(P) < 2 then
4680 begin
4681 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4682 g_Console_Add('ID | Name');
4683 for b := MONSTER_DEMON to MONSTER_MAN do
4684 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4685 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4686 end else
4687 begin
4688 a := StrToIntDef(P[1], 0);
4689 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4690 a := g_Mons_TypeIdByName(P[1]);
4692 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4693 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4694 else
4695 begin
4696 with gPlayer1.Obj do
4697 begin
4698 mon := g_Monsters_Create(a,
4699 X + Rect.X + (Rect.Width div 2),
4700 Y + Rect.Y + Rect.Height,
4701 gPlayer1.Direction, True);
4702 end;
4703 if (Length(P) > 2) and (mon <> nil) then
4704 begin
4705 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4706 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4707 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4708 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4709 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4710 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4711 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4712 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4713 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4714 end;
4715 end;
4716 end;
4717 end
4718 else if (cmd = 'd_health') then
4719 begin
4720 if (Length(P) > 1) and
4721 ((P[1] = '1') or (P[1] = '0')) then
4722 g_debug_HealthBar := (P[1][1] = '1');
4724 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4725 end
4726 else if (cmd = 'd_player') then
4727 begin
4728 if (Length(P) > 1) and
4729 ((P[1] = '1') or (P[1] = '0')) then
4730 g_debug_Player := (P[1][1] = '1');
4732 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4733 end
4734 else if (cmd = 'd_mem') then
4735 begin
4736 PrintHeapStats();
4737 end;
4738 end
4739 else
4740 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4741 end;
4744 procedure GameCheats(P: SSArray);
4745 var
4746 cmd: string;
4747 f, a: Integer;
4748 plr: TPlayer;
4749 begin
4750 if (not gGameOn) or (not conIsCheatsEnabled) then
4751 begin
4752 g_Console_Add('not available');
4753 exit;
4754 end;
4755 plr := gPlayer1;
4756 if plr = nil then
4757 begin
4758 g_Console_Add('where is the player?!');
4759 exit;
4760 end;
4761 cmd := LowerCase(P[0]);
4762 // god
4763 if cmd = 'god' then
4764 begin
4765 plr.GodMode := not plr.GodMode;
4766 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4767 exit;
4768 end;
4769 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4770 if cmd = 'give' then
4771 begin
4772 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4773 for f := 1 to High(P) do
4774 begin
4775 cmd := LowerCase(P[f]);
4776 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4777 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4778 if cmd = 'exit' then
4779 begin
4780 if gTriggers <> nil then
4781 begin
4782 for a := 0 to High(gTriggers) do
4783 begin
4784 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4785 begin
4786 g_Console_Add('player left the map');
4787 gExitByTrigger := True;
4788 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4789 g_Game_ExitLevel(gTriggers[a].tgcMap);
4790 break;
4791 end;
4792 end;
4793 end;
4794 continue;
4795 end;
4797 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4798 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4799 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4800 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4801 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4803 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4804 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4806 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4807 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;
4809 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4810 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4812 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4813 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4815 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4816 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4818 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4819 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4820 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4822 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4823 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4824 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4825 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;
4826 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4827 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4829 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;
4830 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;
4831 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;
4832 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;
4833 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;
4834 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;
4836 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4837 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;
4839 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;
4840 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;
4842 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4844 if cmd = 'ammo' then
4845 begin
4846 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4847 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4848 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4849 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4850 plr.GiveItem(ITEM_AMMO_FUELCAN);
4851 g_Console_Add('player got some ammo');
4852 continue;
4853 end;
4855 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4856 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4858 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4859 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4861 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4862 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4864 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4865 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4867 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4869 if cmd = 'weapons' then
4870 begin
4871 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4872 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4873 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4874 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4875 plr.GiveItem(ITEM_WEAPON_PLASMA);
4876 plr.GiveItem(ITEM_WEAPON_BFG);
4877 g_Console_Add('player got weapons');
4878 continue;
4879 end;
4881 if cmd = 'keys' then
4882 begin
4883 plr.GiveItem(ITEM_KEY_RED);
4884 plr.GiveItem(ITEM_KEY_GREEN);
4885 plr.GiveItem(ITEM_KEY_BLUE);
4886 g_Console_Add('player got all keys');
4887 continue;
4888 end;
4890 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4891 end;
4892 exit;
4893 end;
4894 // open
4895 if cmd = 'open' then
4896 begin
4897 g_Console_Add('player activated sesame');
4898 g_Triggers_OpenAll();
4899 exit;
4900 end;
4901 // fly
4902 if cmd = 'fly' then
4903 begin
4904 gFly := not gFly;
4905 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4906 exit;
4907 end;
4908 // noclip
4909 if cmd = 'noclip' then
4910 begin
4911 plr.SwitchNoClip;
4912 g_Console_Add('wall hardeness adjusted');
4913 exit;
4914 end;
4915 // notarget
4916 if cmd = 'notarget' then
4917 begin
4918 plr.NoTarget := not plr.NoTarget;
4919 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4920 exit;
4921 end;
4922 // noreload
4923 if cmd = 'noreload' then
4924 begin
4925 plr.NoReload := not plr.NoReload;
4926 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4927 exit;
4928 end;
4929 // speedy
4930 if cmd = 'speedy' then
4931 begin
4932 MAX_RUNVEL := 32-MAX_RUNVEL;
4933 g_Console_Add('speed adjusted');
4934 exit;
4935 end;
4936 // jumpy
4937 if cmd = 'jumpy' then
4938 begin
4939 VEL_JUMP := 30-VEL_JUMP;
4940 g_Console_Add('jump height adjusted');
4941 exit;
4942 end;
4943 // automap
4944 if cmd = 'automap' then
4945 begin
4946 gShowMap := not gShowMap;
4947 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4948 exit;
4949 end;
4950 // aimline
4951 if cmd = 'aimline' then
4952 begin
4953 gAimLine := not gAimLine;
4954 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4955 exit;
4956 end;
4957 end;
4959 procedure GameCommands(P: SSArray);
4960 var
4961 a, b: Integer;
4962 s, pw: String;
4963 chstr: string;
4964 cmd: string;
4965 pl: pTNetClient = nil;
4966 plr: TPlayer;
4967 prt: Word;
4968 nm: Boolean;
4969 listen: LongWord;
4970 found: Boolean;
4971 begin
4972 // Общие команды:
4973 cmd := LowerCase(P[0]);
4974 chstr := '';
4975 if cmd = 'pause' then
4976 begin
4977 {$IFDEF ENABLE_MENU}
4978 if (g_ActiveWindow = nil) then
4979 g_Game_Pause(not gPauseMain);
4980 {$ELSE}
4981 g_Game_Pause(not gPauseMain);
4982 {$ENDIF}
4983 end
4984 else if cmd = 'endgame' then
4985 gExit := EXIT_SIMPLE
4986 else if cmd = 'restart' then
4987 begin
4988 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4989 begin
4990 if g_Game_IsClient then
4991 begin
4992 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4993 Exit;
4994 end;
4995 g_Game_Restart();
4996 end else
4997 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4998 end
4999 else if cmd = 'kick' then
5000 begin
5001 if g_Game_IsServer then
5002 begin
5003 if Length(P) < 2 then
5004 begin
5005 g_Console_Add('kick <name>');
5006 Exit;
5007 end;
5008 if P[1] = '' then
5009 begin
5010 g_Console_Add('kick <name>');
5011 Exit;
5012 end;
5014 if g_Game_IsNet then
5015 pl := g_Net_Client_ByName(P[1]);
5016 if (pl <> nil) then
5017 begin
5018 s := g_Net_ClientName_ByID(pl^.ID);
5019 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
5020 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5021 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5022 g_Net_Slist_ServerPlayerLeaves();
5023 end else if gPlayers <> nil then
5024 for a := Low(gPlayers) to High(gPlayers) do
5025 if gPlayers[a] <> nil then
5026 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
5027 begin
5028 // Не отключать основных игроков в сингле
5029 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
5030 continue;
5031 gPlayers[a].Lives := 0;
5032 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
5033 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
5034 g_Player_Remove(gPlayers[a].UID);
5035 g_Net_Slist_ServerPlayerLeaves();
5036 // Если не перемешать, при добавлении новых ботов появятся старые
5037 g_Bot_MixNames();
5038 end;
5039 end else
5040 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5041 end
5042 else if cmd = 'kick_id' then
5043 begin
5044 if g_Game_IsServer and g_Game_IsNet then
5045 begin
5046 if Length(P) < 2 then
5047 begin
5048 g_Console_Add('kick_id <client ID>');
5049 Exit;
5050 end;
5051 if P[1] = '' then
5052 begin
5053 g_Console_Add('kick_id <client ID>');
5054 Exit;
5055 end;
5057 a := StrToIntDef(P[1], 0);
5058 if (NetClients <> nil) and (a <= High(NetClients)) then
5059 begin
5060 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5061 begin
5062 s := g_Net_ClientName_ByID(NetClients[a].ID);
5063 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
5064 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5065 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5066 g_Net_Slist_ServerPlayerLeaves();
5067 end;
5068 end;
5069 end else
5070 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5071 end
5072 else if cmd = 'kick_pid' then
5073 begin
5074 if g_Game_IsServer and g_Game_IsNet then
5075 begin
5076 if Length(P) < 2 then
5077 begin
5078 g_Console_Add('kick_pid <player ID>');
5079 Exit;
5080 end;
5081 if P[1] = '' then
5082 begin
5083 g_Console_Add('kick_pid <player ID>');
5084 Exit;
5085 end;
5087 a := StrToIntDef(P[1], 0);
5088 pl := g_Net_Client_ByPlayer(a);
5089 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5090 begin
5091 s := g_Net_ClientName_ByID(pl^.ID);
5092 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
5093 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5094 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5095 g_Net_Slist_ServerPlayerLeaves();
5096 end;
5097 end else
5098 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5099 end
5100 else if cmd = 'ban' then
5101 begin
5102 if g_Game_IsServer and g_Game_IsNet then
5103 begin
5104 if Length(P) < 2 then
5105 begin
5106 g_Console_Add('ban <name>');
5107 Exit;
5108 end;
5109 if P[1] = '' then
5110 begin
5111 g_Console_Add('ban <name>');
5112 Exit;
5113 end;
5115 pl := g_Net_Client_ByName(P[1]);
5116 if (pl <> nil) then
5117 begin
5118 s := g_Net_ClientName_ByID(pl^.ID);
5119 g_Net_BanHost(pl^.Peer^.address.host, False);
5120 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5121 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5122 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5123 g_Net_Slist_ServerPlayerLeaves();
5124 end else
5125 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5126 end else
5127 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5128 end
5129 else if cmd = 'ban_id' then
5130 begin
5131 if g_Game_IsServer and g_Game_IsNet then
5132 begin
5133 if Length(P) < 2 then
5134 begin
5135 g_Console_Add('ban_id <client ID>');
5136 Exit;
5137 end;
5138 if P[1] = '' then
5139 begin
5140 g_Console_Add('ban_id <client ID>');
5141 Exit;
5142 end;
5144 a := StrToIntDef(P[1], 0);
5145 if (NetClients <> nil) and (a <= High(NetClients)) then
5146 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5147 begin
5148 s := g_Net_ClientName_ByID(NetClients[a].ID);
5149 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
5150 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_TEMPBAN);
5151 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5152 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5153 g_Net_Slist_ServerPlayerLeaves();
5154 end;
5155 end else
5156 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5157 end
5158 else if cmd = 'ban_pid' then
5159 begin
5160 if g_Game_IsServer and g_Game_IsNet then
5161 begin
5162 if Length(P) < 2 then
5163 begin
5164 g_Console_Add('ban_pid <player ID>');
5165 Exit;
5166 end;
5167 if P[1] = '' then
5168 begin
5169 g_Console_Add('ban_pid <player ID>');
5170 Exit;
5171 end;
5173 a := StrToIntDef(P[1], 0);
5174 pl := g_Net_Client_ByPlayer(a);
5175 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5176 begin
5177 s := g_Net_ClientName_ByID(pl^.ID);
5178 g_Net_BanHost(pl^.Peer^.address.host, False);
5179 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5180 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5181 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5182 g_Net_Slist_ServerPlayerLeaves();
5183 end;
5184 end else
5185 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5186 end
5187 else if cmd = 'permban' then
5188 begin
5189 if g_Game_IsServer and g_Game_IsNet then
5190 begin
5191 if Length(P) < 2 then
5192 begin
5193 g_Console_Add('permban <name>');
5194 Exit;
5195 end;
5196 if P[1] = '' then
5197 begin
5198 g_Console_Add('permban <name>');
5199 Exit;
5200 end;
5202 pl := g_Net_Client_ByName(P[1]);
5203 if (pl <> nil) then
5204 begin
5205 s := g_Net_ClientName_ByID(pl^.ID);
5206 g_Net_BanHost(pl^.Peer^.address.host);
5207 g_Net_Host_Kick(pl^.ID, NET_DISC_BAN);
5208 g_Net_SaveBanList();
5209 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5210 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5211 g_Net_Slist_ServerPlayerLeaves();
5212 end else
5213 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5214 end else
5215 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5216 end
5217 else if cmd = 'permban_id' then
5218 begin
5219 if g_Game_IsServer and g_Game_IsNet then
5220 begin
5221 if Length(P) < 2 then
5222 begin
5223 g_Console_Add('permban_id <client ID>');
5224 Exit;
5225 end;
5226 if P[1] = '' then
5227 begin
5228 g_Console_Add('permban_id <client ID>');
5229 Exit;
5230 end;
5232 a := StrToIntDef(P[1], 0);
5233 if (NetClients <> nil) and (a <= High(NetClients)) then
5234 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5235 begin
5236 s := g_Net_ClientName_ByID(NetClients[a].ID);
5237 g_Net_BanHost(NetClients[a].Peer^.address.host);
5238 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_BAN);
5239 g_Net_SaveBanList();
5240 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5241 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5242 g_Net_Slist_ServerPlayerLeaves();
5243 end;
5244 end else
5245 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5246 end
5247 else if cmd = 'permban_pid' then
5248 begin
5249 if g_Game_IsServer and g_Game_IsNet then
5250 begin
5251 if Length(P) < 2 then
5252 begin
5253 g_Console_Add('permban_pid <player ID>');
5254 Exit;
5255 end;
5256 if P[1] = '' then
5257 begin
5258 g_Console_Add('permban_pid <player ID>');
5259 Exit;
5260 end;
5262 a := StrToIntDef(P[1], 0);
5263 pl := g_Net_Client_ByPlayer(a);
5264 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5265 begin
5266 s := g_Net_ClientName_ByID(pl^.ID);
5267 g_Net_BanHost(pl^.Peer^.address.host);
5268 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5269 g_Net_SaveBanList();
5270 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5271 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5272 g_Net_Slist_ServerPlayerLeaves();
5273 end;
5274 end else
5275 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5276 end
5277 else if cmd = 'permban_ip' then
5278 begin
5279 if g_Game_IsServer and g_Game_IsNet then
5280 begin
5281 if Length(P) < 2 then
5282 begin
5283 g_Console_Add('permban_ip <IP address>');
5284 Exit;
5285 end;
5286 if P[1] = '' then
5287 begin
5288 g_Console_Add('permban_ip <IP address>');
5289 Exit;
5290 end;
5292 g_Net_BanHost(P[1]);
5293 g_Net_SaveBanList();
5294 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
5295 end else
5296 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5297 end
5298 else if cmd = 'unban' then
5299 begin
5300 if g_Game_IsServer and g_Game_IsNet then
5301 begin
5302 if Length(P) < 2 then
5303 begin
5304 g_Console_Add('unban <IP Address>');
5305 Exit;
5306 end;
5307 if P[1] = '' then
5308 begin
5309 g_Console_Add('unban <IP Address>');
5310 Exit;
5311 end;
5313 if g_Net_UnbanHost(P[1]) then
5314 begin
5315 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5316 g_Net_SaveBanList();
5317 end else
5318 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5319 end else
5320 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5321 end
5322 else if cmd = 'clientlist' then
5323 begin
5324 if g_Game_IsServer and g_Game_IsNet then
5325 begin
5326 b := 0;
5327 if NetClients <> nil then
5328 for a := Low(NetClients) to High(NetClients) do
5329 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5330 begin
5331 plr := g_Player_Get(NetClients[a].Player);
5332 if plr = nil then continue;
5333 Inc(b);
5334 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5335 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5336 end;
5337 if b = 0 then
5338 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5339 end else
5340 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5341 end
5342 else if cmd = 'connect' then
5343 begin
5344 if (NetMode = NET_NONE) then
5345 begin
5346 if Length(P) < 2 then
5347 begin
5348 g_Console_Add('connect <IP> [port] [password]');
5349 Exit;
5350 end;
5351 if P[1] = '' then
5352 begin
5353 g_Console_Add('connect <IP> [port] [password]');
5354 Exit;
5355 end;
5357 if Length(P) > 2 then
5358 prt := StrToIntDef(P[2], 25666)
5359 else
5360 prt := 25666;
5362 if Length(P) > 3 then
5363 pw := P[3]
5364 else
5365 pw := '';
5367 g_Game_StartClient(P[1], prt, pw);
5368 end;
5369 end
5370 else if cmd = 'disconnect' then
5371 begin
5372 if (NetMode = NET_CLIENT) then
5373 g_Net_Disconnect();
5374 end
5375 else if cmd = 'reconnect' then
5376 begin
5377 if (NetMode = NET_SERVER) then
5378 Exit;
5380 if (NetMode = NET_CLIENT) then
5381 begin
5382 g_Net_Disconnect();
5383 gExit := EXIT_SIMPLE;
5384 EndGame;
5385 end;
5387 //TODO: Use last successful password to reconnect, instead of ''
5388 g_Game_StartClient(NetClientIP, NetClientPort, '');
5389 end
5390 else if (cmd = 'addbot') or
5391 (cmd = 'bot_add') then
5392 begin
5393 if Length(P) > 2 then
5394 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
5395 else if Length(P) > 1 then
5396 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5397 else
5398 g_Bot_Add(TEAM_NONE, 2);
5399 end
5400 else if cmd = 'bot_addlist' then
5401 begin
5402 if Length(P) > 1 then
5403 begin
5404 if Length(P) = 2 then
5405 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5406 else if Length(P) = 3 then
5407 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5408 else
5409 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5410 end;
5411 end
5412 else if cmd = 'bot_removeall' then
5413 g_Bot_RemoveAll()
5414 else if cmd = 'chat' then
5415 begin
5416 if g_Game_IsNet then
5417 begin
5418 if Length(P) > 1 then
5419 begin
5420 for a := 1 to High(P) do
5421 chstr := chstr + P[a] + ' ';
5423 if Length(chstr) > 200 then SetLength(chstr, 200);
5425 if Length(chstr) < 1 then
5426 begin
5427 g_Console_Add('chat <text>');
5428 Exit;
5429 end;
5431 chstr := b_Text_Format(chstr);
5432 if g_Game_IsClient then
5433 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5434 else
5435 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5436 end
5437 else
5438 g_Console_Add('chat <text>');
5439 end else
5440 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5441 end
5442 else if cmd = 'teamchat' then
5443 begin
5444 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5445 begin
5446 if Length(P) > 1 then
5447 begin
5448 for a := 1 to High(P) do
5449 chstr := chstr + P[a] + ' ';
5451 if Length(chstr) > 200 then SetLength(chstr, 200);
5453 if Length(chstr) < 1 then
5454 begin
5455 g_Console_Add('teamchat <text>');
5456 Exit;
5457 end;
5459 chstr := b_Text_Format(chstr);
5460 if g_Game_IsClient then
5461 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5462 else
5463 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5464 gPlayer1Settings.Team);
5465 end
5466 else
5467 g_Console_Add('teamchat <text>');
5468 end else
5469 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5470 end
5471 else if (cmd = 'an') or (cmd = 'announce') then
5472 begin
5473 if g_Game_IsNet then
5474 begin
5475 if Length(P) > 1 then
5476 begin
5477 for a := 1 to High(P) do
5478 chstr := chstr + P[a] + ' ';
5480 if Length(chstr) > 200 then SetLength(chstr, 200);
5482 if Length(chstr) < 1 then
5483 begin
5484 g_Console_Add('announce <text>');
5485 Exit;
5486 end;
5488 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
5489 if g_Game_IsClient then
5490 MC_SEND_RCONCommand(chstr)
5491 else
5492 g_Console_Process(chstr, True);
5493 end
5494 else
5495 g_Console_Add('announce <text>');
5496 end else
5497 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5498 end
5499 else if cmd = 'game' then
5500 begin
5501 if gGameSettings.GameType <> GT_NONE then
5502 begin
5503 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5504 Exit;
5505 end;
5506 if Length(P) = 1 then
5507 begin
5508 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5509 Exit;
5510 end;
5511 // game not started yet, load fist map from some wad
5512 found := false;
5513 s := addWadExtension(P[1]);
5514 found := e_FindResource(AllMapDirs, s);
5515 P[1] := s;
5516 if found then
5517 begin
5518 P[1] := ExpandFileName(P[1]);
5519 // if map not choosed then set first map
5520 if Length(P) < 3 then
5521 begin
5522 SetLength(P, 3);
5523 P[2] := g_Game_GetFirstMap(P[1]);
5524 end;
5526 s := P[1] + ':\' + UpperCase(P[2]);
5528 if g_Map_Exist(s) then
5529 begin
5530 // start game
5531 g_Game_Free();
5532 with gGameSettings do
5533 begin
5534 Options := gsGameFlags;
5535 GameMode := g_Game_TextToMode(gsGameMode);
5536 if gSwitchGameMode <> GM_NONE then
5537 GameMode := gSwitchGameMode;
5538 if GameMode = GM_NONE then GameMode := GM_DM;
5539 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5540 b := 1;
5541 if Length(P) >= 4 then
5542 b := StrToIntDef(P[3], 1);
5543 g_Game_StartCustom(s, GameMode, TimeLimit,
5544 ScoreLimit, MaxLives, Options, b);
5545 end;
5546 end
5547 else
5548 if P[2] = '' then
5549 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5550 else
5551 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5552 end else
5553 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5554 end
5555 else if cmd = 'host' then
5556 begin
5557 if gGameSettings.GameType <> GT_NONE then
5558 begin
5559 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5560 Exit;
5561 end;
5562 if Length(P) < 4 then
5563 begin
5564 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5565 Exit;
5566 end;
5567 if not StrToIp(P[1], listen) then
5568 Exit;
5569 prt := StrToIntDef(P[2], 25666);
5571 s := addWadExtension(P[3]);
5572 found := e_FindResource(AllMapDirs, s);
5573 P[3] := s;
5574 if found then
5575 begin
5576 // get first map in wad, if not specified
5577 if Length(P) < 5 then
5578 begin
5579 SetLength(P, 5);
5580 P[4] := g_Game_GetFirstMap(P[1]);
5581 end;
5582 s := P[3] + ':\' + UpperCase(P[4]);
5583 if g_Map_Exist(s) then
5584 begin
5585 // start game
5586 g_Game_Free();
5587 with gGameSettings do
5588 begin
5589 Options := gsGameFlags;
5590 GameMode := g_Game_TextToMode(gsGameMode);
5591 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5592 if GameMode = GM_NONE then GameMode := GM_DM;
5593 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5594 b := 0;
5595 if Length(P) >= 6 then
5596 b := StrToIntDef(P[5], 0);
5597 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
5598 end
5599 end
5600 else
5601 begin
5602 if P[4] = '' then
5603 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5604 else
5605 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5606 end
5607 end
5608 else
5609 begin
5610 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5611 end
5612 end
5613 else if cmd = 'map' then
5614 begin
5615 if Length(P) = 1 then
5616 begin
5617 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5618 begin
5619 g_Console_Add(cmd + ' <MAP>');
5620 g_Console_Add(cmd + ' <WAD> [MAP]')
5621 end
5622 else
5623 begin
5624 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5625 end
5626 end
5627 else
5628 begin
5629 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5630 begin
5631 if Length(P) < 3 then
5632 begin
5633 // first param is map or wad
5634 s := UpperCase(P[1]);
5635 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5636 begin
5637 gExitByTrigger := False;
5638 if gGameOn then
5639 begin
5640 // already in game, finish current map
5641 gNextMap := s;
5642 gExit := EXIT_ENDLEVELCUSTOM;
5643 end
5644 else
5645 begin
5646 // intermission, so change map immediately
5647 g_Game_ChangeMap(s)
5648 end
5649 end
5650 else
5651 begin
5652 s := P[1];
5653 found := e_FindResource(AllMapDirs, s);
5654 P[1] := s;
5655 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5656 if found then
5657 begin
5658 // no such map, found wad
5659 pw := P[1];
5660 SetLength(P, 3);
5661 P[1] := ExpandFileName(pw);
5662 P[2] := g_Game_GetFirstMap(P[1]);
5663 s := P[1] + ':\' + P[2];
5664 if g_Map_Exist(s) then
5665 begin
5666 gExitByTrigger := False;
5667 if gGameOn then
5668 begin
5669 // already in game, finish current map
5670 gNextMap := s;
5671 gExit := EXIT_ENDLEVELCUSTOM
5672 end
5673 else
5674 begin
5675 // intermission, so change map immediately
5676 g_Game_ChangeMap(s)
5677 end
5678 end
5679 else
5680 begin
5681 if P[2] = '' then
5682 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5683 else
5684 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5685 end
5686 end
5687 else
5688 begin
5689 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5690 end
5691 end;
5692 end
5693 else
5694 begin
5695 s := addWadExtension(P[1]);
5696 found := e_FindResource(AllMapDirs, s);
5697 P[1] := s;
5698 if found then
5699 begin
5700 P[2] := UpperCase(P[2]);
5701 s := P[1] + ':\' + P[2];
5702 if g_Map_Exist(s) then
5703 begin
5704 gExitByTrigger := False;
5705 if gGameOn then
5706 begin
5707 gNextMap := s;
5708 gExit := EXIT_ENDLEVELCUSTOM
5709 end
5710 else
5711 begin
5712 g_Game_ChangeMap(s)
5713 end
5714 end
5715 else
5716 begin
5717 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5718 end
5719 end
5720 else
5721 begin
5722 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5723 end
5724 end
5725 end
5726 else
5727 begin
5728 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5729 end
5730 end
5731 end
5732 else if cmd = 'nextmap' then
5733 begin
5734 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5735 begin
5736 g_Console_Add(_lc[I_MSG_NOT_GAME])
5737 end
5738 else
5739 begin
5740 nm := True;
5741 if Length(P) = 1 then
5742 begin
5743 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5744 begin
5745 g_Console_Add(cmd + ' <MAP>');
5746 g_Console_Add(cmd + ' <WAD> [MAP]');
5747 end
5748 else
5749 begin
5750 nm := False;
5751 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5752 end;
5753 end
5754 else
5755 begin
5756 nm := False;
5757 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5758 begin
5759 if Length(P) < 3 then
5760 begin
5761 // first param is map or wad
5762 s := UpperCase(P[1]);
5763 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5764 begin
5765 // map founded
5766 gExitByTrigger := False;
5767 gNextMap := s;
5768 nm := True;
5769 end
5770 else
5771 begin
5772 // no such map, found wad
5773 pw := addWadExtension(P[1]);
5774 found := e_FindResource(MapDirs, pw);
5775 if not found then
5776 found := e_FindResource(WadDirs, pw);
5777 P[1] := pw;
5778 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5779 if found then
5780 begin
5781 // map not specified, select first map
5782 SetLength(P, 3);
5783 P[2] := g_Game_GetFirstMap(P[1]);
5784 s := P[1] + ':\' + P[2];
5785 if g_Map_Exist(s) then
5786 begin
5787 gExitByTrigger := False;
5788 gNextMap := s;
5789 nm := True
5790 end
5791 else
5792 begin
5793 if P[2] = '' then
5794 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5795 else
5796 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5797 end
5798 end
5799 else
5800 begin
5801 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5802 end
5803 end
5804 end
5805 else
5806 begin
5807 // specified two params wad + map
5808 pw := addWadExtension(P[1]);
5809 found := e_FindResource(MapDirs, pw);
5810 if not found then
5811 found := e_FindResource(MapDirs, pw);
5812 P[1] := pw;
5813 if found then
5814 begin
5815 P[2] := UpperCase(P[2]);
5816 s := P[1] + ':\' + P[2];
5817 if g_Map_Exist(s) then
5818 begin
5819 gExitByTrigger := False;
5820 gNextMap := s;
5821 nm := True
5822 end
5823 else
5824 begin
5825 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5826 end
5827 end
5828 else
5829 begin
5830 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5831 end
5832 end
5833 end
5834 else
5835 begin
5836 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5837 end
5838 end;
5839 if nm then
5840 begin
5841 if gNextMap = '' then
5842 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5843 else
5844 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5845 end
5846 end
5847 end
5848 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5849 begin
5850 if not gGameOn then
5851 begin
5852 g_Console_Add(_lc[I_MSG_NOT_GAME])
5853 end
5854 else
5855 begin
5856 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5857 begin
5858 gExitByTrigger := False;
5859 // next map not specified, try to find trigger EXIT
5860 if (gNextMap = '') and (gTriggers <> nil) then
5861 begin
5862 for a := 0 to High(gTriggers) do
5863 begin
5864 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5865 begin
5866 gExitByTrigger := True;
5867 //gNextMap := gTriggers[a].Data.MapName;
5868 gNextMap := gTriggers[a].tgcMap;
5869 Break
5870 end
5871 end
5872 end;
5873 if gNextMap = '' then
5874 gNextMap := g_Game_GetNextMap();
5875 if not isWadPath(gNextMap) then
5876 s := gGameSettings.WAD + ':\' + gNextMap
5877 else
5878 s := gNextMap;
5879 if g_Map_Exist(s) then
5880 gExit := EXIT_ENDLEVELCUSTOM
5881 else
5882 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5883 end
5884 else
5885 begin
5886 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5887 end
5888 end
5889 end
5890 else if (cmd = 'event') then
5891 begin
5892 if (Length(P) <= 1) then
5893 begin
5894 for a := 0 to High(gEvents) do
5895 if gEvents[a].Command = '' then
5896 g_Console_Add(gEvents[a].Name + ' <none>')
5897 else
5898 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5899 Exit;
5900 end;
5901 if (Length(P) = 2) then
5902 begin
5903 for a := 0 to High(gEvents) do
5904 if gEvents[a].Name = P[1] then
5905 if gEvents[a].Command = '' then
5906 g_Console_Add(gEvents[a].Name + ' <none>')
5907 else
5908 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5909 Exit;
5910 end;
5911 for a := 0 to High(gEvents) do
5912 if gEvents[a].Name = P[1] then
5913 begin
5914 gEvents[a].Command := '';
5915 for b := 2 to High(P) do
5916 if Pos(' ', P[b]) = 0 then
5917 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5918 else
5919 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5920 gEvents[a].Command := Trim(gEvents[a].Command);
5921 Exit;
5922 end;
5923 end
5924 else if cmd = 'suicide' then
5925 begin
5926 if gGameOn then
5927 begin
5928 if g_Game_IsClient then
5929 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5930 else
5931 begin
5932 if gPlayer1 <> nil then
5933 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5934 if gPlayer2 <> nil then
5935 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5936 end;
5937 end;
5938 end
5939 else if cmd = 'screenshot' then
5940 begin
5941 {$IFDEF ENABLE_RENDER}
5942 g_TakeScreenShot;
5943 {$ENDIF}
5944 end
5945 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
5946 begin
5947 a := 1 - (ord(cmd[5]) - ord('n'));
5948 if a = -1 then
5949 gWeaponAction[0, WP_PREV] := True;
5950 if a = 1 then
5951 gWeaponAction[0, WP_NEXT] := True;
5952 end
5953 else if cmd = 'weapon' then
5954 begin
5955 if Length(p) = 2 then
5956 begin
5957 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
5958 if (a >= WP_FIRST) and (a <= WP_LAST) then
5959 gSelectWeapon[0, a] := True
5960 end
5961 end
5962 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
5963 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
5964 begin
5965 a := 1 - (ord(cmd[8]) - ord('n'));
5966 b := ord(cmd[2]) - ord('1');
5967 if a = -1 then
5968 gWeaponAction[b, WP_PREV] := True;
5969 if a = 1 then
5970 gWeaponAction[b, WP_NEXT] := True;
5971 end
5972 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5973 begin
5974 if Length(p) = 2 then
5975 begin
5976 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
5977 b := ord(cmd[2]) - ord('1');
5978 if (a >= WP_FIRST) and (a <= WP_LAST) then
5979 gSelectWeapon[b, a] := True
5980 end
5981 end
5982 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
5983 begin
5984 b := ord(cmd[2]) - ord('1');
5985 if b = 0 then
5986 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
5987 else
5988 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
5989 end
5990 else if (cmd = 'dropflag') then
5991 begin
5992 if g_Game_IsServer then
5993 begin
5994 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
5995 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
5996 end
5997 else
5998 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
5999 end
6000 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
6001 begin
6002 b := ord(cmd[2]) - ord('1');
6003 if g_Game_IsServer then
6004 begin
6005 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
6006 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
6007 end
6008 else
6009 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
6010 end
6011 // Команды Своей игры:
6012 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6013 begin
6014 if cmd = 'bot_addred' then
6015 begin
6016 if Length(P) > 1 then
6017 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6018 else
6019 g_Bot_Add(TEAM_RED, 2);
6020 end
6021 else if cmd = 'bot_addblue' then
6022 begin
6023 if Length(P) > 1 then
6024 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6025 else
6026 g_Bot_Add(TEAM_BLUE, 2);
6027 end
6028 else if cmd = 'spectate' then
6029 begin
6030 if not gGameOn then
6031 Exit;
6032 g_Game_Spectate();
6033 end
6034 else if cmd = 'say' then
6035 begin
6036 if g_Game_IsServer and g_Game_IsNet then
6037 begin
6038 if Length(P) > 1 then
6039 begin
6040 chstr := '';
6041 for a := 1 to High(P) do
6042 chstr := chstr + P[a] + ' ';
6044 if Length(chstr) > 200 then SetLength(chstr, 200);
6046 if Length(chstr) < 1 then
6047 begin
6048 g_Console_Add('say <text>');
6049 Exit;
6050 end;
6052 chstr := b_Text_Format(chstr);
6053 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6054 end
6055 else g_Console_Add('say <text>');
6056 end else
6057 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6058 end
6059 else if cmd = 'tell' then
6060 begin
6061 if g_Game_IsServer and g_Game_IsNet then
6062 begin
6063 if (Length(P) > 2) and (P[1] <> '') then
6064 begin
6065 chstr := '';
6066 for a := 2 to High(P) do
6067 chstr := chstr + P[a] + ' ';
6069 if Length(chstr) > 200 then SetLength(chstr, 200);
6071 if Length(chstr) < 1 then
6072 begin
6073 g_Console_Add('tell <playername> <text>');
6074 Exit;
6075 end;
6077 pl := g_Net_Client_ByName(P[1]);
6078 if pl <> nil then
6079 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6080 else
6081 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6082 end
6083 else g_Console_Add('tell <playername> <text>');
6084 end else
6085 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6086 end
6087 else if cmd = 'centerprint' then
6088 begin
6089 if (Length(P) > 2) and (P[1] <> '') then
6090 begin
6091 chstr := '';
6092 for a := 2 to High(P) do
6093 chstr := chstr + P[a] + ' ';
6095 if Length(chstr) > 200 then SetLength(chstr, 200);
6097 if Length(chstr) < 1 then
6098 begin
6099 g_Console_Add('centerprint <timeout> <text>');
6100 Exit;
6101 end;
6103 a := StrToIntDef(P[1], 100);
6104 chstr := b_Text_Format(chstr);
6105 g_Game_Message(chstr, a);
6106 if g_Game_IsNet and g_Game_IsServer then
6107 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
6108 end
6109 else g_Console_Add('centerprint <timeout> <text>');
6110 end
6111 else if (cmd = 'overtime') and not g_Game_IsClient then
6112 begin
6113 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6114 Exit;
6115 // Дополнительное время:
6116 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6118 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6119 [gGameSettings.TimeLimit div 3600,
6120 (gGameSettings.TimeLimit div 60) mod 60,
6121 gGameSettings.TimeLimit mod 60]));
6122 if g_Game_IsNet then MH_SEND_GameSettings;
6123 end
6124 else if (cmd = 'rcon_password') and g_Game_IsClient then
6125 begin
6126 if (Length(P) <= 1) then
6127 g_Console_Add('rcon_password <password>')
6128 else
6129 MC_SEND_RCONPassword(P[1]);
6130 end
6131 else if cmd = 'rcon' then
6132 begin
6133 if g_Game_IsClient then
6134 begin
6135 if Length(P) > 1 then
6136 begin
6137 chstr := '';
6138 for a := 1 to High(P) do
6139 chstr := chstr + P[a] + ' ';
6141 if Length(chstr) > 200 then SetLength(chstr, 200);
6143 if Length(chstr) < 1 then
6144 begin
6145 g_Console_Add('rcon <command>');
6146 Exit;
6147 end;
6149 MC_SEND_RCONCommand(chstr);
6150 end
6151 else g_Console_Add('rcon <command>');
6152 end;
6153 end
6154 else if cmd = 'ready' then
6155 begin
6156 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
6157 gLMSRespawnTime := gTime + 100;
6158 end
6159 else if (cmd = 'callvote') and g_Game_IsNet then
6160 begin
6161 if Length(P) > 1 then
6162 begin
6163 chstr := '';
6164 for a := 1 to High(P) do begin
6165 if a > 1 then chstr := chstr + ' ';
6166 chstr := chstr + P[a];
6167 end;
6169 if Length(chstr) > 200 then SetLength(chstr, 200);
6171 if Length(chstr) < 1 then
6172 begin
6173 g_Console_Add('callvote <command>');
6174 Exit;
6175 end;
6177 if g_Game_IsClient then
6178 MC_SEND_Vote(True, chstr)
6179 else
6180 g_Game_StartVote(chstr, gPlayer1Settings.Name);
6181 g_Console_Process('vote', True);
6182 end
6183 else
6184 g_Console_Add('callvote <command>');
6185 end
6186 else if (cmd = 'vote') and g_Game_IsNet then
6187 begin
6188 if g_Game_IsClient then
6189 MC_SEND_Vote(False)
6190 else if gVoteInProgress then
6191 begin
6192 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6193 a := Floor((NetClientCount+1)/2.0) + 1
6194 else
6195 a := Floor(NetClientCount/2.0) + 1;
6196 if gVoted then
6197 begin
6198 Dec(gVoteCount);
6199 gVoted := False;
6200 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
6201 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
6202 end
6203 else
6204 begin
6205 Inc(gVoteCount);
6206 gVoted := True;
6207 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
6208 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
6209 g_Game_CheckVote;
6210 end;
6211 end;
6212 end
6213 end;
6214 end;
6216 procedure SystemCommands(P: SSArray);
6217 var
6218 cmd: string;
6219 begin
6220 cmd := LowerCase(P[0]);
6221 case cmd of
6222 'exit', 'quit':
6223 begin
6224 g_Game_Free();
6225 g_Game_Quit();
6226 end;
6227 {$IFDEF ENABLE_RENDER}
6228 'r_reset':
6229 r_Render_Apply;
6230 {$ENDIF}
6231 'r_maxfps':
6232 begin
6233 if Length(p) = 2 then
6234 begin
6235 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
6236 if gMaxFPS > 0 then
6237 gFrameTime := 1000 div gMaxFPS
6238 else
6239 gFrameTime := 0;
6240 end;
6241 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
6242 end;
6243 'g_language':
6244 begin
6245 if Length(p) = 2 then
6246 begin
6247 gAskLanguage := true;
6248 gLanguage := LANGUAGE_ENGLISH;
6249 case LowerCase(p[1]) of
6250 'english':
6251 begin
6252 gAskLanguage := false;
6253 gLanguage := LANGUAGE_ENGLISH;
6254 end;
6255 'russian':
6256 begin
6257 gAskLanguage := false;
6258 gLanguage := LANGUAGE_RUSSIAN;
6259 end;
6260 'ask':
6261 begin
6262 gAskLanguage := true;
6263 gLanguage := LANGUAGE_ENGLISH;
6264 end;
6265 end;
6266 g_Language_Set(gLanguage);
6267 end
6268 else
6269 begin
6270 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
6271 end
6272 end;
6273 end;
6274 end;
6276 {$IFDEF ENABLE_RENDER}
6277 procedure g_TakeScreenShot(Filename: string = '');
6278 var t: TDateTime; dir, date, name: String;
6279 begin
6280 if e_NoGraphics then
6281 Exit;
6283 dir := e_GetWriteableDir(ScreenshotDirs);
6284 if Filename = '' then
6285 begin
6286 t := Now;
6287 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
6288 Filename := 'screenshot-' + date;
6289 end;
6291 name := e_CatPath(dir, Filename + '.png');
6292 if r_Render_WriteScreenShot(name) then
6293 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
6294 else
6295 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
6296 end;
6297 {$ENDIF}
6299 {$IFDEF ENABLE_MENU}
6300 procedure g_Game_InGameMenu(Show: Boolean);
6301 begin
6302 if (g_ActiveWindow = nil) and Show then
6303 begin
6304 if gGameSettings.GameType = GT_SINGLE then
6305 g_GUI_ShowWindow('GameSingleMenu')
6306 else
6307 begin
6308 if g_Game_IsClient then
6309 g_GUI_ShowWindow('GameClientMenu')
6310 else
6311 if g_Game_IsNet then
6312 g_GUI_ShowWindow('GameServerMenu')
6313 else
6314 g_GUI_ShowWindow('GameCustomMenu');
6315 end;
6316 g_Sound_PlayEx('MENU_OPEN');
6318 // Пауза при меню только в одиночной игре:
6319 if (not g_Game_IsNet) then
6320 g_Game_Pause(True);
6321 end
6322 else
6323 if (g_ActiveWindow <> nil) and (not Show) then
6324 begin
6325 // Пауза при меню только в одиночной игре:
6326 if (not g_Game_IsNet) then
6327 g_Game_Pause(False);
6328 end;
6329 end;
6330 {$ENDIF}
6332 procedure g_Game_Pause (Enable: Boolean);
6333 var
6334 oldPause: Boolean;
6335 begin
6336 if not gGameOn then exit;
6338 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6340 oldPause := gPause;
6341 gPauseMain := Enable;
6343 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6344 end;
6346 procedure g_Game_HolmesPause (Enable: Boolean);
6347 var
6348 oldPause: Boolean;
6349 begin
6350 if not gGameOn then exit;
6351 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6353 oldPause := gPause;
6354 gPauseHolmes := Enable;
6356 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6357 end;
6359 procedure g_Game_PauseAllSounds(Enable: Boolean);
6360 var
6361 i: Integer;
6362 begin
6363 // Триггеры:
6364 if gTriggers <> nil then
6365 for i := 0 to High(gTriggers) do
6366 with gTriggers[i] do
6367 if (TriggerType = TRIGGER_SOUND) and
6368 (Sound <> nil) and
6369 Sound.IsPlaying() then
6370 begin
6371 Sound.Pause(Enable);
6372 end;
6374 // Звуки игроков:
6375 if gPlayers <> nil then
6376 for i := 0 to High(gPlayers) do
6377 if gPlayers[i] <> nil then
6378 gPlayers[i].PauseSounds(Enable);
6380 // Музыка:
6381 if gMusic <> nil then
6382 gMusic.Pause(Enable);
6383 end;
6385 procedure g_Game_StopAllSounds(all: Boolean);
6386 var
6387 i: Integer;
6388 begin
6389 if gTriggers <> nil then
6390 for i := 0 to High(gTriggers) do
6391 with gTriggers[i] do
6392 if (TriggerType = TRIGGER_SOUND) and
6393 (Sound <> nil) then
6394 Sound.Stop();
6396 if gMusic <> nil then
6397 gMusic.Stop();
6399 if all then
6400 e_StopChannels();
6401 end;
6403 procedure g_Game_UpdateTriggerSounds;
6404 var i: Integer;
6405 begin
6406 if gTriggers <> nil then
6407 for i := 0 to High(gTriggers) do
6408 with gTriggers[i] do
6409 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
6410 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
6411 end;
6413 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
6414 begin
6415 Result := False;
6416 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6417 begin
6418 Result := True;
6419 Exit;
6420 end;
6421 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6422 begin
6423 Result := True;
6424 Exit;
6425 end;
6426 if gSpectMode <> SPECT_PLAYERS then
6427 Exit;
6428 if gSpectPID1 = UID then
6429 begin
6430 Result := True;
6431 Exit;
6432 end;
6433 if gSpectViewTwo and (gSpectPID2 = UID) then
6434 begin
6435 Result := True;
6436 Exit;
6437 end;
6438 end;
6440 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6441 var
6442 Pl: TPlayer;
6443 begin
6444 Result := False;
6445 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6446 begin
6447 Result := True;
6448 Exit;
6449 end;
6450 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6451 begin
6452 Result := True;
6453 Exit;
6454 end;
6455 if gSpectMode <> SPECT_PLAYERS then
6456 Exit;
6457 Pl := g_Player_Get(gSpectPID1);
6458 if (Pl <> nil) and (Pl.Team = Team) then
6459 begin
6460 Result := True;
6461 Exit;
6462 end;
6463 if gSpectViewTwo then
6464 begin
6465 Pl := g_Player_Get(gSpectPID2);
6466 if (Pl <> nil) and (Pl.Team = Team) then
6467 begin
6468 Result := True;
6469 Exit;
6470 end;
6471 end;
6472 end;
6474 procedure g_Game_Message (Msg: string; Time: Word);
6475 begin
6476 MessageText := Msg;
6477 MessageTime := Time;
6478 end;
6480 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6481 const
6482 punct: Array[0..13] of String =
6483 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6484 var
6485 i, j: Integer;
6486 ok: Boolean;
6487 fpText: String;
6489 function IsPunctuation(S: String): Boolean;
6490 var
6491 i: Integer;
6492 begin
6493 Result := False;
6494 if Length(S) <> 1 then
6495 Exit;
6496 for i := Low(punct) to High(punct) do
6497 if S = punct[i] then
6498 begin
6499 Result := True;
6500 break;
6501 end;
6502 end;
6503 function FilterPunctuation(S: String): String;
6504 var
6505 i: Integer;
6506 begin
6507 for i := Low(punct) to High(punct) do
6508 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6509 Result := S;
6510 end;
6511 begin
6512 ok := False;
6514 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6515 begin
6516 // remove player name
6517 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6518 // for FullWord check
6519 Text := toLowerCase1251(' ' + Text + ' ');
6520 fpText := FilterPunctuation(Text);
6522 for i := 0 to Length(gChatSounds) - 1 do
6523 begin
6524 ok := True;
6525 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6526 begin
6527 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6528 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6529 else
6530 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6531 if not ok then
6532 break;
6533 end;
6534 if ok then
6535 begin
6536 gChatSounds[i].Sound.Play();
6537 break;
6538 end;
6539 end;
6540 end;
6541 if not ok then
6542 g_Sound_PlayEx('SOUND_GAME_RADIO');
6543 end;
6545 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6546 var
6547 a: Integer;
6548 begin
6549 case gAnnouncer of
6550 ANNOUNCE_NONE:
6551 Exit;
6552 ANNOUNCE_ME,
6553 ANNOUNCE_MEPLUS:
6554 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6555 Exit;
6556 end;
6557 for a := 0 to 3 do
6558 if goodsnd[a].IsPlaying() then
6559 Exit;
6561 goodsnd[Random(4)].Play();
6562 end;
6564 procedure g_Game_Announce_KillCombo(Param: Integer);
6565 var
6566 UID: Word;
6567 c, n: Byte;
6568 Pl: TPlayer;
6569 Name: String;
6570 begin
6571 UID := Param and $FFFF;
6572 c := Param shr 16;
6573 if c < 2 then
6574 Exit;
6576 Pl := g_Player_Get(UID);
6577 if Pl = nil then
6578 Name := '?'
6579 else
6580 Name := Pl.Name;
6582 case c of
6583 2: begin
6584 n := 0;
6585 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6586 end;
6587 3: begin
6588 n := 1;
6589 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6590 end;
6591 4: begin
6592 n := 2;
6593 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6594 end;
6595 else begin
6596 n := 3;
6597 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6598 end;
6599 end;
6601 case gAnnouncer of
6602 ANNOUNCE_NONE:
6603 Exit;
6604 ANNOUNCE_ME:
6605 if not g_Game_IsWatchedPlayer(UID) then
6606 Exit;
6607 ANNOUNCE_MEPLUS:
6608 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6609 Exit;
6610 end;
6612 if killsnd[n].IsPlaying() then
6613 killsnd[n].Stop();
6614 killsnd[n].Play();
6615 end;
6617 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6618 var
6619 a: Integer;
6620 begin
6621 case gAnnouncer of
6622 ANNOUNCE_NONE:
6623 Exit;
6624 ANNOUNCE_ME:
6625 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6626 Exit;
6627 end;
6628 for a := 0 to 2 do
6629 if hahasnd[a].IsPlaying() then
6630 Exit;
6632 hahasnd[Random(3)].Play();
6633 end;
6635 procedure g_Game_StartVote(Command, Initiator: string);
6636 var
6637 Need: Integer;
6638 begin
6639 if not gVotesEnabled then Exit;
6640 if gGameSettings.GameType <> GT_SERVER then Exit;
6641 if gVoteInProgress or gVotePassed then
6642 begin
6643 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6644 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6645 Exit;
6646 end;
6647 gVoteInProgress := True;
6648 gVotePassed := False;
6649 gVoteTimer := gTime + gVoteTimeout * 1000;
6650 gVoteCount := 0;
6651 gVoted := False;
6652 gVoteCommand := Command;
6654 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6655 Need := Floor((NetClientCount+1)/2.0)+1
6656 else
6657 Need := Floor(NetClientCount/2.0)+1;
6658 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6659 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6660 end;
6662 procedure g_Game_CheckVote;
6663 var
6664 I, Need: Integer;
6665 begin
6666 if gGameSettings.GameType <> GT_SERVER then Exit;
6667 if not gVoteInProgress then Exit;
6669 if (gTime >= gVoteTimer) then
6670 begin
6671 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6672 Need := Floor((NetClientCount+1)/2.0) + 1
6673 else
6674 Need := Floor(NetClientCount/2.0) + 1;
6675 if gVoteCount >= Need then
6676 begin
6677 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6678 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6679 gVotePassed := True;
6680 gVoteCmdTimer := gTime + 5000;
6681 end
6682 else
6683 begin
6684 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6685 MH_SEND_VoteEvent(NET_VE_FAILED);
6686 end;
6687 if NetClients <> nil then
6688 for I := Low(NetClients) to High(NetClients) do
6689 if NetClients[i].Used then
6690 NetClients[i].Voted := False;
6691 gVoteInProgress := False;
6692 gVoted := False;
6693 gVoteCount := 0;
6694 end
6695 else
6696 begin
6697 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6698 Need := Floor((NetClientCount+1)/2.0) + 1
6699 else
6700 Need := Floor(NetClientCount/2.0) + 1;
6701 if gVoteCount >= Need then
6702 begin
6703 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6704 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6705 gVoteInProgress := False;
6706 gVotePassed := True;
6707 gVoteCmdTimer := gTime + 5000;
6708 gVoted := False;
6709 gVoteCount := 0;
6710 if NetClients <> nil then
6711 for I := Low(NetClients) to High(NetClients) do
6712 if NetClients[i].Used then
6713 NetClients[i].Voted := False;
6714 end;
6715 end;
6716 end;
6718 procedure g_Game_LoadMapList(FileName: string);
6719 var
6720 ListFile: TextFile;
6721 s: string;
6722 begin
6723 MapList := nil;
6724 MapIndex := -1;
6726 if not FileExists(FileName) then Exit;
6728 AssignFile(ListFile, FileName);
6729 Reset(ListFile);
6730 while not EOF(ListFile) do
6731 begin
6732 ReadLn(ListFile, s);
6734 s := Trim(s);
6735 if s = '' then Continue;
6737 SetLength(MapList, Length(MapList)+1);
6738 MapList[High(MapList)] := s;
6739 end;
6740 CloseFile(ListFile);
6741 end;
6743 procedure g_Game_SetDebugMode();
6744 begin
6745 gDebugMode := True;
6746 // Читы (даже в своей игре):
6747 gCheats := True;
6748 end;
6750 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6751 var
6752 i: Word;
6753 begin
6754 if Length(LoadingStat.Msgs) = 0 then
6755 Exit;
6757 with LoadingStat do
6758 begin
6759 if not reWrite then
6760 begin // Переходим на следующую строку или скроллируем:
6761 if NextMsg = Length(Msgs) then
6762 begin // scroll
6763 for i := 0 to High(Msgs)-1 do
6764 Msgs[i] := Msgs[i+1];
6765 end
6766 else
6767 Inc(NextMsg);
6768 end else
6769 if NextMsg = 0 then
6770 Inc(NextMsg);
6772 Msgs[NextMsg-1] := Text;
6773 CurValue := 0;
6774 MaxValue := Max;
6775 ShowCount := 0;
6776 PBarWasHere := false;
6777 end;
6779 {$IFDEF ENABLE_MENU}
6780 g_ActiveWindow := nil;
6781 {$ENDIF}
6783 ProcessLoading(true);
6784 end;
6786 procedure g_Game_StepLoading(Value: Integer = -1);
6787 begin
6788 with LoadingStat do
6789 begin
6790 if Value = -1 then
6791 begin
6792 Inc(CurValue);
6793 Inc(ShowCount);
6794 end
6795 else
6796 CurValue := Value;
6798 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
6799 begin
6800 ShowCount := 0;
6801 ProcessLoading(False);
6802 end;
6803 end;
6804 end;
6806 procedure g_Game_ClearLoading();
6807 var
6808 len: Word;
6809 begin
6810 with LoadingStat do
6811 begin
6812 CurValue := 0;
6813 MaxValue := 0;
6814 ShowCount := 0;
6815 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6816 if len < 1 then len := 1;
6817 SetLength(Msgs, len);
6818 for len := Low(Msgs) to High(Msgs) do
6819 Msgs[len] := '';
6820 NextMsg := 0;
6821 PBarWasHere := false;
6822 end;
6823 end;
6825 procedure Parse_Params(var pars: TParamStrValues);
6826 var
6827 i: Integer;
6828 s: String;
6829 begin
6830 SetLength(pars, 0);
6831 i := 1;
6832 while i <= ParamCount do
6833 begin
6834 s := ParamStr(i);
6835 if (Length(s) > 1) and (s[1] = '-') then
6836 begin
6837 if (Length(s) > 2) and (s[2] = '-') then
6838 begin // Одиночный параметр
6839 SetLength(pars, Length(pars) + 1);
6840 with pars[High(pars)] do
6841 begin
6842 Name := LowerCase(s);
6843 Value := '+';
6844 end;
6845 end
6846 else
6847 if (i < ParamCount) then
6848 begin // Параметр со значением
6849 Inc(i);
6850 SetLength(pars, Length(pars) + 1);
6851 with pars[High(pars)] do
6852 begin
6853 Name := LowerCase(s);
6854 Value := LowerCase(ParamStr(i));
6855 end;
6856 end;
6857 end;
6859 Inc(i);
6860 end;
6861 end;
6863 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6864 var
6865 i: Integer;
6866 begin
6867 Result := '';
6868 for i := 0 to High(pars) do
6869 if pars[i].Name = aName then
6870 begin
6871 Result := pars[i].Value;
6872 Break;
6873 end;
6874 end;
6876 procedure g_Game_Process_Params();
6877 var
6878 pars: TParamStrValues;
6879 map: String;
6880 GMode, n: Byte;
6881 LimT, LimS: Integer;
6882 Opt: LongWord;
6883 Lives: Integer;
6884 s: String;
6885 Port: Integer;
6886 ip: String;
6887 F: TextFile;
6888 begin
6889 Parse_Params(pars);
6891 // Debug mode:
6892 s := Find_Param_Value(pars, '--debug');
6893 if (s <> '') then
6894 begin
6895 g_Game_SetDebugMode();
6896 s := Find_Param_Value(pars, '--netdump');
6897 if (s <> '') then
6898 NetDump := True;
6899 end;
6901 // Connect when game loads
6902 ip := Find_Param_Value(pars, '-connect');
6904 if ip <> '' then
6905 begin
6906 s := Find_Param_Value(pars, '-port');
6907 if (s = '') or not TryStrToInt(s, Port) then
6908 Port := 25666;
6910 s := Find_Param_Value(pars, '-pw');
6912 g_Game_StartClient(ip, Port, s);
6913 Exit;
6914 end;
6916 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6917 if (s <> '') then
6918 begin
6919 gDefaultMegawadStart := s;
6920 end;
6922 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6923 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6924 begin
6925 gDefaultMegawadStart := DF_Default_Megawad_Start;
6926 end;
6928 // Start map when game loads:
6929 map := LowerCase(Find_Param_Value(pars, '-map'));
6930 if isWadPath(map) then
6931 begin
6932 // Game mode:
6933 s := Find_Param_Value(pars, '-gm');
6934 GMode := g_Game_TextToMode(s);
6935 if GMode = GM_NONE then GMode := GM_DM;
6936 if GMode = GM_SINGLE then GMode := GM_COOP;
6938 // Time limit:
6939 s := Find_Param_Value(pars, '-limt');
6940 if (s = '') or (not TryStrToInt(s, LimT)) then
6941 LimT := 0;
6942 if LimT < 0 then
6943 LimT := 0;
6945 // Score limit:
6946 s := Find_Param_Value(pars, '-lims');
6947 if (s = '') or (not TryStrToInt(s, LimS)) then
6948 LimS := 0;
6949 if LimS < 0 then
6950 LimS := 0;
6952 // Lives limit:
6953 s := Find_Param_Value(pars, '-lives');
6954 if (s = '') or (not TryStrToInt(s, Lives)) then
6955 Lives := 0;
6956 if Lives < 0 then
6957 Lives := 0;
6959 // Options:
6960 s := Find_Param_Value(pars, '-opt');
6961 if (s = '') then
6962 Opt := gsGameFlags
6963 else
6964 Opt := StrToIntDef(s, 0);
6966 // Close after map:
6967 s := Find_Param_Value(pars, '--close');
6968 if (s <> '') then
6969 gMapOnce := True;
6971 // Override map to test:
6972 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6973 if s <> '' then
6974 begin
6975 if e_IsValidResourceName(s) then
6976 e_FindResource(AllMapDirs, s);
6977 gTestMap := ExpandFileName(s);
6978 end;
6980 // Delete test map after play:
6981 s := Find_Param_Value(pars, '--testdelete');
6982 if (s <> '') then
6983 begin
6984 //gMapToDelete := MapsDir + map;
6985 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6986 Halt(1);
6987 end;
6989 // Delete temporary WAD after play:
6990 s := Find_Param_Value(pars, '--tempdelete');
6991 if (s <> '') and (gTestMap <> '') then
6992 begin
6993 gMapToDelete := gTestMap;
6994 gTempDelete := True;
6995 end;
6997 // Number of players:
6998 s := Find_Param_Value(pars, '-pl');
6999 if (s = '') then
7000 n := DEFAULT_PLAYERS
7001 else
7002 n := StrToIntDef(s, DEFAULT_PLAYERS);
7004 // Start:
7005 s := Find_Param_Value(pars, '-port');
7006 if (s = '') or not TryStrToInt(s, Port) then
7007 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7008 else
7009 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7010 end;
7012 // Execute script when game loads:
7013 s := Find_Param_Value(pars, '-exec');
7014 if s <> '' then
7015 begin
7016 // if not isWadPath(s) then
7017 // s := GameDir + '/' + s;
7019 {$I-}
7020 AssignFile(F, s);
7021 Reset(F);
7022 if IOResult <> 0 then
7023 begin
7024 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7025 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7026 CloseFile(F);
7027 Exit;
7028 end;
7029 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7030 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7032 while not EOF(F) do
7033 begin
7034 ReadLn(F, s);
7035 if IOResult <> 0 then
7036 begin
7037 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7038 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7039 CloseFile(F);
7040 Exit;
7041 end;
7042 if Pos('#', s) <> 1 then // script comment
7043 g_Console_Process(s, True);
7044 end;
7046 CloseFile(F);
7047 {$I+}
7048 end;
7050 SetLength(pars, 0);
7051 end;
7053 begin
7054 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
7055 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7056 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
7057 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
7059 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
7060 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7061 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7062 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7064 {$IFDEF ENABLE_GFX}
7065 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
7066 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
7067 {$ENDIF}
7069 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
7070 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
7072 {$IFDEF ENABLE_HOLMES}
7073 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
7074 {$ENDIF}
7076 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
7078 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
7079 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
7081 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7082 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7084 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7085 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
7086 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
7087 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
7088 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
7089 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
7090 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
7091 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
7092 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
7093 end.