Skip to content

Commit

Permalink
feat (shields rework): Allow deactivation of shield units (#3841)
Browse files Browse the repository at this point in the history
* Enable the on/off toggle for all units with shields
* Set shield charge to 0 when disabled
* The above only apply when the "Shields Rework" experimental mod is enabled
* Toggle visual shield effects along with building state
  • Loading branch information
aldrenean authored Nov 14, 2024
1 parent e5ff253 commit 157be4d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions gamedata/alldefs_post.lua
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,15 @@ function UnitDef_Post(name, uDef)
end
end

-- Shield Rework
if modOptions.shieldsrework == true and uDef.weapondefs then
for _, weapon in pairs(uDef.weapondefs) do
if weapon.shield and weapon.shield.repulser then
uDef.onoffable = true
end
end
end

--- EMP rework
if modOptions.emprework == true then
if name == "armstil" then
Expand Down
4 changes: 4 additions & 0 deletions luamocks/SpringLuaApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,10 @@ assert(type(unitID) == "number","Argument unitID is of invalid type - expected n
return booleanMock
end

function Spring.GetUnitIsActive (unitID)
assert(type(unitID) == "number","Argument unitID is of invalid type - expected number");
return booleanMock
end

function Spring.SetLastMessagePosition ( x, y, z)
assert(type(x) == "number","Argument x is of invalid type - expected number");
Expand Down
8 changes: 7 additions & 1 deletion luarules/gadgets/lups_shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ local function UpdateVisibility(unitID, unitData, unitVisible, forceUpdate)
unitVisible = GetVisibleSearch(ux, uz, unitData.search)
end

local unitIsActive = Spring.GetUnitIsActive(unitID)
if unitIsActive ~= unitData.isActive then
forceUpdate = true
unitData.isActive = unitIsActive
end

if unitVisible == unitData.unitVisible and not forceUpdate then
return
end
Expand All @@ -237,7 +243,7 @@ local function UpdateVisibility(unitID, unitData, unitVisible, forceUpdate)
local fxID = unitData.fxTable[i]
local fx = Lups.GetParticles(fxID)
if fx then
fx.visibleToMyAllyTeam = unitVisible
fx.visibleToMyAllyTeam = unitIsActive and unitVisible
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions luarules/gadgets/unit_shield_behaviour.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local spGetUnitsInSphere = Spring.GetUnitsInSphere
local spGetProjectilesInRectangle = Spring.GetProjectilesInRectangle
local spGetUnitIsStunned = Spring.GetUnitIsStunned
local spAreTeamsAllied = Spring.AreTeamsAllied
local spGetUnitIsActive = Spring.GetUnitIsActive

local shieldUnitDefs = {}
local shieldUnitsData = {}
Expand Down Expand Up @@ -216,6 +217,9 @@ function gadget:GameFrame(frame)
end

if frame % 10 == 0 then
if not spGetUnitIsActive(shieldUnitID) then
spSetUnitShieldState(shieldUnitID, shieldData.shieldWeaponNumber, 0)
end
if not shieldData.shieldEnabled and shieldData.downtimeReset ~= 0 and shieldData.downtimeReset <= gameSeconds then
shieldData.downtimeReset = 0
shieldData.shieldEnabled = true
Expand Down

0 comments on commit 157be4d

Please sign in to comment.