DEADSOFTWARE

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