Skip to content

Commit

Permalink
Fix incorrect morphed commander BP on the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Dec 24, 2024
1 parent 10b8d33 commit 09c8e1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions LuaRules/Gadgets/unit_commander_upgrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ end

local function ApplyModuleEffects(unitID, data, totalCost, images)
local ud = UnitDefs[Spring.GetUnitDefID(unitID)]
local newAttributesEffect = false

-- Update ApplyModuleEffectsFromUnitRulesParams if any non-unitRulesParams changes are made.
if data.speedMultPost or data.speedMod then
Expand Down Expand Up @@ -148,19 +149,25 @@ local function ApplyModuleEffects(unitID, data, totalCost, images)
local buildPowerMult = ((data.bonusBuildPower or 0) + ud.buildSpeed)/ud.buildSpeed
data.metalIncome = (data.metalIncome or 0)
data.energyIncome = (data.energyIncome or 0)
Spring.SetUnitRulesParam(unitID, "buildpower_mult", buildPowerMult, INLOS)

if buildPowerMult ~= 1 then
-- Needs to use the new system so static can be set, to display properly on the UI.
newAttributesEffect = newAttributesEffect or {}
newAttributesEffect.build = buildPowerMult
end

if data.metalIncome and GG.Overdrive then
Spring.SetUnitRulesParam(unitID, "comm_income_metal", data.metalIncome, INLOS)
Spring.SetUnitRulesParam(unitID, "comm_income_energy", data.energyIncome, INLOS)
GG.Overdrive.AddUnitResourceGeneration(unitID, data.metalIncome, data.energyIncome, true)
end

local newHealth = false
if data.healthBonus then
local health, maxHealth = Spring.GetUnitHealth(unitID)
local newHealth = math.max(health + data.healthBonus, 1)
GG.Attributes.AddEffect(unitID, "self_upgrade", {healthAdd = data.healthBonus, static = true})
Spring.SetUnitHealth(unitID, newHealth) -- Override scaled health change from GG.Attributes
newHealth = math.max(health + data.healthBonus, 1)
newAttributesEffect = newAttributesEffect or {}
newAttributesEffect.healthAdd = data.healthBonus
end

if data.skinOverride then
Expand Down Expand Up @@ -196,6 +203,13 @@ local function ApplyModuleEffects(unitID, data, totalCost, images)

ApplyWeaponData(unitID, data.weapon1, data.weapon2, data.shield, data.rangeMult, data.damageMult)

if newAttributesEffect then
newAttributesEffect.static = true
GG.Attributes.AddEffect(unitID, "comm_upgrade", newAttributesEffect)
if newHealth then
Spring.SetUnitHealth(unitID, newHealth) -- Override scaled health change from GG.Attributes
end
end
-- Do this all the time as it will be needed almost always.
GG.UpdateUnitAttributes(unitID)
end
Expand Down
2 changes: 1 addition & 1 deletion LuaUI/Widgets/gui_contextmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ local function printAbilities(ud, unitID)


if ud.buildSpeed > 0 and not cp.nobuildpower then
local buildSpeed = ud.buildSpeed * (unitID and Spring.GetUnitRulesParam(unitID, "buildpower_mult") or 1)
local buildSpeed = (unitID and Spring.Utilities.GetUnitBuildSpeed(unitID)) or ud.buildSpeed
cells[#cells+1] = 'Construction'
cells[#cells+1] = ''
cells[#cells+1] = ' - Buildpower: '
Expand Down

0 comments on commit 09c8e1b

Please sign in to comment.