Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/AbilityDisabled.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local spSetUnitRulesParam=Spring.SetUnitRulesParam

return {
---@type AttributesHandlerFactory
AbilityDisabled = {
handledAttributeNames={abilityDisabled=true},
new = function(unitID, unitDefID)
local abilityDisabledCur = false

return {
newDataHandler = function(frame)
local abilityDisabled = false

return {
fold = function(data)
abilityDisabled = abilityDisabled or data.abilityDisabled
end,
apply = function()
if abilityDisabled ~= abilityDisabledCur then
spSetUnitRulesParam(unitID, "att_abilityDisabled", abilityDisabled and 1 or 0)
abilityDisabledCur = abilityDisabled
end
end
}
end,
clear = function()
-- Reset logic can be added here if needed
end
}
end
}
}
50 changes: 50 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/BuildSpeed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
local REPAIR_ENERGY_COST_FACTOR = Game.repairEnergyCostFactor
local spSetUnitBuildSpeed=Spring.SetUnitBuildSpeed
local spSetUnitRulesParam=Spring.SetUnitRulesParam
local INLOS_ACCESS = {inlos = true}

GG.attRaw_BuildSpeed={}
return {
---@type AttributesHandlerFactory
BuildSpeed = {
handledAttributeNames={
build=true
},
new = function(unitID, unitDefID)
local ud = UnitDefs[unitDefID]
local buildSpeed = ud.buildSpeed or 0

local buildMultCur = 1

return {
newDataHandler = function(frame)
local buildMult = 1

return {
fold = function(data)
buildMult = buildMult * (data.build or 1)
end,
apply = function()
GG.attRaw_BuildSpeed[unitID] = buildSpeed*buildMult
spSetUnitRulesParam(unitID, "totalBuildPowerChange", buildMult, INLOS_ACCESS)
if buildMult ~= buildMultCur and buildSpeed > 0 then
local newBuildSpeed = buildSpeed * buildMult
spSetUnitBuildSpeed(unitID,
newBuildSpeed, -- build
newBuildSpeed / REPAIR_ENERGY_COST_FACTOR, -- repair
newBuildSpeed, -- reclaim
0.5 * newBuildSpeed -- rezz
)
buildMultCur = buildMult
end
end
}
end,
clear = function()
GG.attRaw_BuildSpeed[unitID] = nil
-- Reset logic can be added here if needed
end
}
end
}
}
31 changes: 31 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/DeathExplosion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local spSetUnitRulesParam=Spring.SetUnitRulesParam
local INLOS_ACCESS = {inlos = true}

GG.att_DeathExplodeMult={}
return {
---@type AttributesHandlerFactory
DeathExplosion = {
handledAttributeNames={deathExplode=true},
new = function(unitId)
return {
newDataHandler = function()
local deathExplodeMult = 1

return {
fold = function(data)
deathExplodeMult = deathExplodeMult * (data.deathExplode or 1)

end,
apply = function()
GG.att_DeathExplodeMult[unitId] = deathExplodeMult
spSetUnitRulesParam(unitId, "deathExplodeMult", deathExplodeMult, INLOS_ACCESS)
end
}
end,
clear = function()
GG.att_DeathExplodeMult[unitId] = nil
end
}
end
}
}
43 changes: 43 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/Economy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local INLOS_ACCESS = {inlos = true}
local spSetUnitRulesParam=Spring.SetUnitRulesParam

GG.att_EconomyChange={}
return {
---@type AttributesHandlerFactory
Economy = {
handledAttributeNames={econ=true,energy=true},
new = function(unitID, unitDefID)
local econMultCur = 1
local energyMultCur = 1

return {
newDataHandler = function(frame)
local econMult = 1
local energyMult = 1

return {
fold = function(data)
econMult = econMult * (data.econ or 1)
energyMult = energyMult * (data.energy or 1)
end,
apply = function()
GG.att_EconomyChange[unitID] = econMult
if econMult ~= econMultCur or energyMult ~= energyMultCur then
spSetUnitRulesParam(unitID, "totalEconomyChange", econMult, INLOS_ACCESS)
spSetUnitRulesParam(unitID, "metalGenerationFactor", econMult, INLOS_ACCESS)
spSetUnitRulesParam(unitID, "energyGenerationFactor", econMult * energyMult, INLOS_ACCESS)

econMultCur = econMult
energyMultCur = energyMult
end
end
}
end,
clear = function()
GG.att_EconomyChange[unitID] = nil
-- Reset logic can be added here if needed
end
}
end
}
}
94 changes: 94 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/HealthCostMass.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local INLOS_ACCESS = {inlos = true}

local function GetMass(health, cost)
return (((cost/2) + (health/8))^0.6)*6.5
end
local spGetUnitHealth=Spring.GetUnitHealth
local spSetUnitMaxHealth=Spring.SetUnitMaxHealth
local spSetUnitHealth=Spring.SetUnitHealth
local spSetUnitCosts=Spring.SetUnitCosts
local spSetUnitMass=Spring.SetUnitMass
local spSetUnitRulesParam=Spring.SetUnitRulesParam

GG.att_CostMult={}
GG.att_HealthMult={}

---@type {[string|number]:AttributesHandlerFactory}
return{
---@type AttributesHandlerFactory
HealthCostMass={
handledAttributeNames={
healthMult=true,healthAdd=true,cost=true,mass=true
},
new=function (unitID,unitDefID)
local ud=UnitDefs[unitDefID]
local origUnitHealth= ud.health
local origUnitCost= ud.buildTime
local HealthMultCur=1
local HealthAddCur=0
local CostMultCur=1
local MassMultCur=1
---@type AttributesHandler
return{
newDataHandler=function (frame)
local healthMult=1
local healthAdd=0
local costMult=1
local massMult=1

---@type AttributesDataHandler
return {
---@param data {healthAdd:number?,healthMult:number?,cost:number?,mass:number?}
fold=function (data)
healthMult=healthMult*(data.healthMult or 1)
healthAdd=healthAdd+(data.healthAdd or 0)
costMult=costMult*(data.cost or 1)
massMult=massMult*(data.mass or 1)
end,
apply=function ()
GG.att_CostMult[unitID] = costMult
GG.att_HealthMult[unitID] = healthMult
spSetUnitRulesParam(unitID, "costMult", costMult, INLOS_ACCESS)

if CostMultCur~=costMult or HealthAddCur~=healthAdd or MassMultCur~=massMult or HealthMultCur~=healthMult then

local newMaxHealth = (origUnitHealth + healthAdd) * healthMult
local oldHealth, oldMaxHealth = spGetUnitHealth(unitID)
spSetUnitMaxHealth(unitID, newMaxHealth)
spSetUnitHealth(unitID, oldHealth * newMaxHealth / oldMaxHealth)

local origCost = origUnitCost
local cost = origCost*costMult
spSetUnitCosts(unitID, {
metalCost = cost,
energyCost = cost,
buildTime = cost,
})

if massMult == 1 then
-- Default to update mass based on new stats, if a multiplier is not set.
local mass = GetMass(newMaxHealth, cost)
spSetUnitMass(unitID, mass)
spSetUnitRulesParam(unitID, "massOverride", mass, INLOS_ACCESS)
else
local mass = GetMass(origUnitHealth, origCost) * massMult
spSetUnitMass(unitID, mass)
spSetUnitRulesParam(unitID, "massOverride", mass, INLOS_ACCESS)
end
CostMultCur=costMult
HealthAddCur=healthAdd
MassMultCur=massMult
HealthMultCur=healthMult
end
end
}
end,
clear=function ()
GG.att_CostMult[unitID] = nil
GG.att_HealthMult[unitID] = nil

end
}
end
}
}
32 changes: 32 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/HealthRegen.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

local INLOS_ACCESS = {inlos = true}

GG.att_RegenChange={}
return {
---@type AttributesHandlerFactory
StaticAttributes = {
handledAttributeNames = {healthRegen=true},
new = function(unitID, unitDefID)

return {
newDataHandler = function(frame)

local healthRegen = 1

return {
fold = function(data)
healthRegen = healthRegen*(data.healthRegen or 1)
end,
apply = function()
GG.att_RegenChange[unitID] = healthRegen
end
}
end,
clear = function()
GG.att_RegenChange[unitID] = nil
-- Reset logic can be added here if needed
end
}
end
}
}
33 changes: 33 additions & 0 deletions LuaRules/Configs/UnitAttributeHandlers/JumpRange.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local spSetUnitRulesParam=Spring.SetUnitRulesParam
local INLOS_ACCESS = {inlos = true}

GG.att_JumpRangeChange={}
return {
---@type AttributesHandlerFactory
JumpRange = {
handledAttributeNames={
build=true
},
new = function(unitID, unitDefID)
return {
newDataHandler = function(frame)
local jumpRangeMult = 1

return {
fold = function(data)
jumpRangeMult = jumpRangeMult * (data.jumpRange or 1)
end,
apply = function()
GG.att_JumpRangeChange[unitID] = jumpRangeMult
spSetUnitRulesParam(unitID, "jumpRangeMult", jumpRangeMult, INLOS_ACCESS)
end
}
end,
clear = function()
GG.att_JumpRangeChange[unitID] = nil
-- Reset logic can be added here if needed
end
}
end
}
}
Loading