DEADSOFTWARE

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