DEADSOFTWARE

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