DEADSOFTWARE

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