DEADSOFTWARE

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