Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,808 changes: 192 additions & 1,616 deletions LuaRules/Configs/dynamic_comm_defs.lua

Large diffs are not rendered by default.

29 changes: 26 additions & 3 deletions LuaRules/Gadgets/unit_commander_upgrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ local function ApplyWeaponData(unitID, weapon1, weapon2, shield, rangeMult, dama
end
end

weapon1 = weapon1 or "commweapon_beamlaser"
local chassis = Spring.GetUnitRulesParam(unitID, "comm_chassis")
weapon1 = weapon1 or (chassis and chassisDefs[chassis] and chassisDefs[chassis].initWeapon) or "commweapon_beamlaser"

if chassis and chassisDefs[chassis] and chassisDefs[chassis].secondPeashooter and (not weapon2) and Spring.GetUnitRulesParam(unitID, "comm_level") > 2 then
weapon2 = "commweapon_beamlaser"
Expand All @@ -101,6 +101,7 @@ end

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

local newAttributesEffect = {}
newAttributesEffect.cost = totalCost / ud.metalCost

Expand Down Expand Up @@ -152,8 +153,9 @@ local function ApplyModuleEffects(unitID, data, totalCost, images)
data.energyIncome = (data.energyIncome or 0)

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

newAttributesEffect.build = buildPowerMult

end

if data.metalIncome and GG.Overdrive then
Expand All @@ -162,11 +164,19 @@ local function ApplyModuleEffects(unitID, data, totalCost, images)
GG.Overdrive.AddUnitResourceGeneration(unitID, data.metalIncome, data.energyIncome, true)
end

---@type false|number
local newHealth = false

if data.healthBonus then
local health, maxHealth = Spring.GetUnitHealth(unitID)

newHealth = math.max(health + data.healthBonus, 1)

newAttributesEffect = newAttributesEffect or {}

newAttributesEffect.healthAdd = data.healthBonus


end

if data.skinOverride then
Expand Down Expand Up @@ -197,15 +207,24 @@ local function ApplyModuleEffects(unitID, data, totalCost, images)
end

local _, maxHealth = Spring.GetUnitHealth(unitID)


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 Expand Up @@ -279,6 +298,7 @@ local function InitializeDynamicCommander(unitID, level, chassis, totalCost, nam
Spring.SetUnitRulesParam(unitID, "comm_level", level, INLOS)
Spring.SetUnitRulesParam(unitID, "comm_chassis", chassis, INLOS)
Spring.SetUnitRulesParam(unitID, "comm_name", name, INLOS)

Spring.SetUnitRulesParam(unitID, "comm_baseUnitDefID", baseUnitDefID, INLOS)
Spring.SetUnitRulesParam(unitID, "comm_baseWreckID", baseWreckID, INLOS)
Spring.SetUnitRulesParam(unitID, "comm_baseHeapID", baseHeapID, INLOS)
Expand All @@ -291,6 +311,7 @@ local function InitializeDynamicCommander(unitID, level, chassis, totalCost, nam
Spring.SetUnitRulesParam(unitID, "comm_staticLevel", staticLevel, INLOS)
end


-- Set module unitRulesParams
-- Decorations are kept seperate from other module types.
-- basic_weapon, adv_weapon and module all count as modules.
Expand Down Expand Up @@ -418,11 +439,13 @@ local function Upgrades_CreateStarterDyncomm(dyncommID, x, y, z, facing, teamID,
local commProfileInfo = GG.ModularCommAPI.GetCommProfileInfo(dyncommID)
local chassisDefID = chassisDefNames[commProfileInfo.chassis]
if not chassisDefID then
Spring.Echo("Incorrect dynamic comm chassis", commProfileInfo.chassis)

Spring.Echo("Incorrect dynamic comm chassis", commProfileInfo.chassis, "dyncommID: " .. dyncommID)
return false
end

local chassisData = chassisDefs[chassisDefID]

if chassisData.notSelectable and not staticLevel then
Spring.Echo("Chassis not selectable", commProfileInfo.chassis)
return false
Expand Down
Loading