From c8d7811d45c2d34a7e297613e50570f253a0d8e9 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 9 Feb 2020 02:02:30 +0300 Subject: [PATCH] add spawn invulnerability; add option to disable all keys in DM --- src/game/g_console.pas | 2 ++ src/game/g_game.pas | 38 ++++++++++++++++++++++++++++++++++++++ src/game/g_language.pas | 21 +++++++++++++++------ src/game/g_net.pas | 2 +- src/game/g_netmsg.pas | 1 + src/game/g_options.pas | 22 ++++++++++++++++++++++ src/game/g_player.pas | 20 ++++++++++++++++---- 7 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 92e86c6..3f285b4 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -920,6 +920,7 @@ begin AddCommand('g_friendlyfire', GameCVars); AddCommand('g_weaponstay', GameCVars); AddCommand('g_allow_exit', GameCVars); + AddCommand('g_dm_keys', GameCVars); AddCommand('g_allow_monsters', GameCVars); AddCommand('g_bot_vsmonsters', GameCVars); AddCommand('g_bot_vsplayers', GameCVars); @@ -927,6 +928,7 @@ begin AddCommand('g_timelimit', GameCVars); AddCommand('g_maxlives', GameCVars); AddCommand('g_warmuptime', GameCVars); + AddCommand('g_spawn_invul', GameCVars); AddCommand('net_interp', GameCVars); AddCommand('net_forceplayerupdate', GameCVars); AddCommand('net_predictself', GameCVars); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index ef256d1..d03d02a 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -31,6 +31,7 @@ type TimeLimit: Word; GoalLimit: Word; WarmupTime: Word; + SpawnInvul: Word; MaxLives: Byte; Options: LongWord; WAD: String; @@ -178,6 +179,7 @@ const GAME_OPTION_MONSTERS = 16; GAME_OPTION_BOTVSPLAYER = 32; GAME_OPTION_BOTVSMONSTER = 64; + GAME_OPTION_DMKEYS = 128; STATE_NONE = 0; STATE_MENU = 1; @@ -5552,6 +5554,28 @@ begin if g_Game_IsNet then MH_SEND_GameSettings; end; end + else if (cmd = 'g_dm_keys') and not g_Game_IsClient then + begin + with gGameSettings do + begin + if (Length(P) > 1) and + ((P[1] = '1') or (P[1] = '0')) then + begin + if (P[1][1] = '1') then + Options := Options or GAME_OPTION_DMKEYS + else + Options := Options and (not GAME_OPTION_DMKEYS); + end; + + if (LongBool(Options and GAME_OPTION_DMKEYS)) then + g_Console_Add(_lc[I_MSG_DMKEYS_ON]) + else + g_Console_Add(_lc[I_MSG_DMKEYS_OFF]); + g_Console_Add(_lc[I_MSG_ONMAPCHANGE]); + + if g_Game_IsNet then MH_SEND_GameSettings; + end; + end else if (cmd = 'g_warmuptime') and not g_Game_IsClient then begin if Length(P) > 1 then @@ -5566,6 +5590,20 @@ begin [gGameSettings.WarmupTime])); g_Console_Add(_lc[I_MSG_ONMAPCHANGE]); end + else if (cmd = 'g_spawn_invul') and not g_Game_IsClient then + begin + if Length(P) > 1 then + begin + if StrToIntDef(P[1], gGameSettings.SpawnInvul) = 0 then + gGameSettings.SpawnInvul := 0 + else + gGameSettings.SpawnInvul := StrToIntDef(P[1], gGameSettings.SpawnInvul); + end; + + g_Console_Add(Format(_lc[I_MSG_SPAWNINVUL], + [gGameSettings.SpawnInvul])); + g_Console_Add(_lc[I_MSG_ONMAPCHANGE]); + end else if cmd = 'net_interp' then begin if (Length(P) > 1) then diff --git a/src/game/g_language.pas b/src/game/g_language.pas index 6f61382..8ccc8ea 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -571,6 +571,8 @@ type I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWMON_ON, I_MSG_ALLOWMON_OFF, + I_MSG_DMKEYS_ON, + I_MSG_DMKEYS_OFF, I_MSG_BOTSVSPLAYERS_ON, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSMONSTERS_ON, @@ -598,6 +600,7 @@ type I_MSG_TIME_LIMIT, I_MSG_LIVES, I_MSG_WARMUP, + I_MSG_SPAWNINVUL, I_MSG_WARMUP_START, I_MSG_NEXTMAP_SET, I_MSG_NEXTMAP_UNSET, @@ -973,8 +976,8 @@ const 'Ïîäîæäèòå, ïîêà ñìåíèòñÿ êàðòà íà ñåðâåðå'), ('MENU INTER NOTICE SPACE', 'Press [SPACE] to continue', 'Íàæìèòå [ÏÐÎÁÅË], ÷òîáû ïðîäîëæèòü'), - ('MENU INTER NOTICE TIME', '%d seconds till the next round', - 'Îñòàëîñü %d ñåêóíä äî ñëåäóþùåãî ðàóíäà'), + ('MENU INTER NOTICE TIME', '%d sec till the next round', + 'Îñòàëîñü %d ñåê äî ñëåäóþùåãî ðàóíäà'), ('MENU LOADING', 'Loading...', 'Çàãðóçêà...'), ('MENU PLAYER 1', 'Player 1', @@ -1696,6 +1699,10 @@ const 'Ìîíñòðû â DM âêëþ÷åíû*'), ('MSG ALLOWMON OFF', 'Monsters in DM disabled*', 'Ìîíñòðû â DM âûêëþ÷åíû*'), + ('MSG DMKEYS ON', 'Spawning with all keys in DM enabled*', + 'Ðåñïàâí ñî âñåìè êëþ÷àìè â DM âêëþ÷åí*'), + ('MSG DMKEYS OFF', 'Spawning with all keys in DM disabled*', + 'Ðåñïàâí ñî âñåìè êëþ÷àìè â DM âûêëþ÷åí*'), ('MSG BOTSVSPLAYERS ON', 'Bots attack players', 'Áîòû ïðîòèâ èãðîêîâ'), ('MSG BOTSVSPLAYERS OFF', 'Bots ignore players', @@ -1748,10 +1755,12 @@ const 'Ëèìèò âðåìåíè - %d:%.2d:%.2d'), ('MSG LIVES', 'Max lives: %d', 'Ìàêñ. æèçíåé ó èãðîêîâ: %d'), - ('MSG WARMUP', 'Warmup time: %d seconds*', - 'Âðåìÿ íà ïîäãîòîâêó ê èãðå: %d ñåêóíä*'), - ('MSG WARMUP START', '%d seconds until round start.', - '%d ñåêóíä äî íà÷àëà ðàóíäà.'), + ('MSG WARMUP', 'Warmup time: %d sec*', + 'Âðåìÿ íà ïîäãîòîâêó ê èãðå: %d ñåê*'), + ('MSG SPAWNINVUL', 'Spawn invulnerability time: %d sec*', + 'Íåóÿçâèìîñòü ïîñëå ðåñïàóíà: %d ñåê*'), + ('MSG WARMUP START', '%d sec until round start.', + '%d ñåê äî íà÷àëà ðàóíäà.'), ('MSG NEXTMAP SET', 'Next map: %s', 'Ñëåäóþùàÿ êàðòà: %s'), ('MSG NEXTMAP UNSET', 'Next map is not set.', diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 6388eeb..0f1cf30 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -21,7 +21,7 @@ uses e_log, e_msg, ENet, Classes, md5, MAPDEF{$IFDEF USE_MINIUPNPC}, miniupnpc;{$ELSE};{$ENDIF} const - NET_PROTOCOL_VER = 182; + NET_PROTOCOL_VER = 183; NET_MAXCLIENTS = 24; NET_CHANS = 12; diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 52e7ae6..235cbb1 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -1178,6 +1178,7 @@ begin NetOut.Write(Byte(FJetpack)); NetOut.Write(FFireTime); NetOut.Write(Byte(FFlaming)); + NetOut.Write(FSpawnInvul); end; g_Net_Host_Send(ID, True, NET_CHAN_PLAYER); diff --git a/src/game/g_options.pas b/src/game/g_options.pas index d4f92e8..c923a67 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -73,6 +73,8 @@ var gcWeaponStay: Boolean; gcMonsters: Boolean; gcBotsVS: String; + gcDeathmatchKeys: Boolean = True; + gcSpawnInvul: Integer = 0; gnMap: String; gnGameMode: String; gnTimeLimit: Word; @@ -84,6 +86,8 @@ var gnWeaponStay: Boolean; gnMonsters: Boolean; gnBotsVS: String; + gnDeathmatchKeys: Boolean = True; + gnSpawnInvul: Integer = 0; gsSDLSampleRate: Integer; gsSDLBufferSize: Integer; gDefaultMegawadStart: AnsiString; @@ -283,6 +287,8 @@ begin gcWeaponStay := False; gcMonsters := False; gcBotsVS := 'Everybody'; + gcDeathmatchKeys := True; + gcSpawnInvul := 0; (* section GameplayNetwork *) gnMap := ''; @@ -296,6 +302,8 @@ begin gnWeaponStay := False; gnMonsters := False; gnBotsVS := 'Everybody'; + gnDeathmatchKeys := True; + gnSpawnInvul := 0; (* section MasterServer *) NetSlistIP := 'mpms.doom2d.org'; @@ -410,6 +418,8 @@ begin ReadBoolean(gcWeaponStay, 'WeaponStay'); ReadBoolean(gcMonsters, 'Monsters'); ReadString(gcBotsVS, 'BotsVS'); + ReadBoolean(gcDeathmatchKeys, 'DeathmatchKeys'); + ReadInteger(gcSpawnInvul, 'SpawnInvul'); with gGameSettings do begin @@ -437,6 +447,8 @@ begin Options := Options or GAME_OPTION_BOTVSPLAYER; if gcBotsVS = 'Monsters' then Options := Options or GAME_OPTION_BOTVSMONSTER; + if gcDeathmatchKeys then + Options := Options or GAME_OPTION_DMKEYS; end; section := 'GameplayNetwork'; @@ -451,6 +463,8 @@ begin ReadBoolean(gnWeaponStay, 'WeaponStay'); ReadBoolean(gnMonsters, 'Monsters'); ReadString(gnBotsVS, 'BotsVS'); + ReadBoolean(gnDeathmatchKeys, 'DeathmatchKeys'); + ReadInteger(gnSpawnInvul, 'SpawnInvul'); section := 'MasterServer'; ReadString(NetSlistIP, 'IP'); @@ -521,6 +535,8 @@ begin config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay); config.WriteBool('GameplayCustom', 'Monsters', gcMonsters); config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS); + config.WriteBool('GameplayCustom', 'DeathmatchKeys', gcDeathmatchKeys); + config.WriteInt ('GameplayCustom', 'SpawnInvul', gcSpawnInvul); config.WriteStr ('GameplayNetwork', 'Map', gnMap); config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode); @@ -533,6 +549,8 @@ begin config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay); config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters); config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS); + config.WriteBool('GameplayNetwork', 'DeathmatchKeys', gnDeathmatchKeys); + config.WriteInt ('GameplayNetwork', 'SpawnInvul', gnSpawnInvul); config.WriteStr('MasterServer', 'IP', NetSlistIP); config.WriteInt('MasterServer', 'Port', NetSlistPort); @@ -579,6 +597,8 @@ begin config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay); config.WriteBool('GameplayCustom', 'Monsters', gcMonsters); config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS); + config.WriteBool('GameplayCustom', 'DeathmatchKeys', gcDeathmatchKeys); + config.WriteInt ('GameplayCustom', 'SpawnInvul', gcSpawnInvul); config.SaveFile(FileName); config.Free(); @@ -603,6 +623,8 @@ begin config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay); config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters); config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS); + config.WriteBool('GameplayNetwork', 'DeathmatchKeys', gnDeathmatchKeys); + config.WriteInt ('GameplayNetwork', 'SpawnInvul', gnSpawnInvul); config.SaveFile(FileName); config.Free(); diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 0cde3c0..b8a77bd 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -267,6 +267,7 @@ type FReady: Boolean; FDummy: Boolean; FFireTime: Integer; + FSpawnInvul: Integer; FHandicap: Integer; FWaitForFirstSpawn: Boolean; // set to `true` in server, used to spawn a player on first full state request @@ -2229,6 +2230,7 @@ begin FMegaRulez[MR_SUIT] := 0; FMegaRulez[MR_INVUL] := 0; FMegaRulez[MR_INVIS] := 0; + FSpawnInvul := 0; FBerserk := 0; end; @@ -2507,7 +2509,7 @@ begin end; end; - if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then + if (FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then begin e_GetTextureSize(ID, @w, @h); @@ -2875,7 +2877,7 @@ var dr: Boolean; begin // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí - if FMegaRulez[MR_INVUL] >= gTime then + if (FMegaRulez[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then begin if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300) @@ -3539,7 +3541,8 @@ begin PushItem(ITEM_JETPACK); // Âûáðîñ êëþ÷åé: - if not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then + if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or + LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then begin if R_KEY_RED in FRulez then PushItem(ITEM_KEY_RED); @@ -4279,6 +4282,7 @@ begin if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then begin FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME; + FSpawnInvul := 0; Result := True; remove := True; if gFlash = 2 then Inc(FPickup, 5); @@ -4634,7 +4638,8 @@ begin FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS]; FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL]; - if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then + if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and + LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE] else FRulez := []; @@ -4670,6 +4675,13 @@ begin for a := Low(FMegaRulez) to High(FMegaRulez) do FMegaRulez[a] := 0; +// Respawn invulnerability + if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then + begin + FMegaRulez[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000; + FSpawnInvul := FMegaRulez[MR_INVUL]; + end; + FDamageBuffer := 0; FJetpack := False; FCanJetpack := False; -- 2.29.2