DEADSOFTWARE

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