Skip to content

Commit

Permalink
Disable lobster attack is default, and actually removes the command.
Browse files Browse the repository at this point in the history
Reset disable lobster attack settings to default.
  • Loading branch information
GoogleFrog committed Jul 9, 2023
1 parent 0365963 commit 5d94455
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion LuaRules/Gadgets/unit_thrower.lua
Expand Up @@ -40,6 +40,8 @@ local IterableMap = VFS.Include("LuaRules/Gadgets/Include/IterableMap.lua")
local applyBlockingFrame = {}
local unitIsNotBlocking = {}

local cachedAttackCommandDesc = false

-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-- Constants
Expand All @@ -64,6 +66,7 @@ local RECENT_INT_WIDTH = 1
local MAX_ALTITUDE_AIM = 60

local NO_BLOCK_TIME = 5
local ATTACK_BLOCK_DEFAULT = 1

-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
Expand Down Expand Up @@ -294,6 +297,16 @@ end
--------------------------------------------------------------------------------
-- Command Handling

local function CacheAttackCommandDesc(unitID)
local cmdTable = Spring.GetUnitCmdDescs(unitID)
for i = 1, #cmdTable do
if cmdTable[i].id == CMD.ATTACK then
cachedAttackCommandDesc = cmdTable[i]
return
end
end
end

local function BlockAttackToggle(unitID, cmdParams)
local data = IterableMap.Get(throwUnits, unitID)
if data then
Expand All @@ -307,8 +320,17 @@ local function BlockAttackToggle(unitID, cmdParams)
if state == 1 then
local cmdDesc = spFindUnitCmdDesc(unitID, CMD.ATTACK)
if cmdDesc then
if not cachedAttackCommandDesc then
CacheAttackCommandDesc(unitID)
Spring.Utilities.TableEcho(cachedAttackCommandDesc, "cmdDesc")
end
spRemoveUnitCmdDesc(unitID, cmdDesc)
end
elseif cachedAttackCommandDesc then
local cmdDesc = spFindUnitCmdDesc(unitID, CMD.ATTACK)
if not cmdDesc then
spInsertUnitCmdDesc(unitID, cachedAttackCommandDesc)
end
end
data.blockAttack = (state == 1)
end
Expand Down Expand Up @@ -367,7 +389,7 @@ function gadget:UnitCreated(unitID, unitDefID, teamID)
)

spInsertUnitCmdDesc(unitID, unitBlockAttackCmd)
BlockAttackToggle(unitID, {0})
BlockAttackToggle(unitID, {ATTACK_BLOCK_DEFAULT})
end
end

Expand Down
2 changes: 1 addition & 1 deletion LuaUI/Widgets/unit_start_state.lua
Expand Up @@ -1037,7 +1037,7 @@ local function addUnit(defName, path)
end

if ud.customParams.attack_toggle then
options[defName .. "_disableattack"] = {
options[defName .. "_disableattack_0"] = {
name = " Disable Attack Commands",
desc = "Check the box to make the unit not respond to attack commands.",
type = 'bool',
Expand Down

0 comments on commit 5d94455

Please sign in to comment.