DEADSOFTWARE

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