Skip to content
Open
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
52 changes: 35 additions & 17 deletions scripts/RmAdjustStorageCapacity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ function RmAdjustStorageCapacity:applyProportionalLoadSpeed(placeable, multiplie
return
end

if multiplier <= 0 or multiplier == 1.0 then
Log:debug("applyProportionalLoadSpeed: multiplier is %.2f, no change needed", multiplier)
return -- No change needed
if multiplier <= 0 then
Log:debug("applyProportionalLoadSpeed: multiplier is %.2f, no change applied", multiplier)
return
end

local uniqueId = placeable.uniqueId
Expand Down Expand Up @@ -721,6 +721,33 @@ function RmAdjustStorageCapacity:applyProportionalLoadSpeed(placeable, multiplie
end
end

--- Refresh load speed from the placeable's complete set of capacity overrides
---@param placeable table The placeable
---@param fallbackCapacity table|nil Capacity settings to use when no stored entry exists
function RmAdjustStorageCapacity:refreshLoadSpeed(placeable, fallbackCapacity)
if placeable == nil then
return
end

if not self.autoScaleSpeed then
self:resetLoadSpeed(placeable)
return
end

local uniqueId = placeable.uniqueId
local customCapacity = uniqueId ~= nil and self.customCapacities[uniqueId] or nil
customCapacity = customCapacity or fallbackCapacity

if customCapacity == nil then
self:resetLoadSpeed(placeable)
return
end

local multiplier = self:getMaxCapacityMultiplier(placeable, customCapacity)
Log:debug("Capacity multiplier for %s: %.2f", placeable:getName(), multiplier)
self:applyProportionalLoadSpeed(placeable, multiplier)
end

--- Update visual fill planes after capacity change
--- Call this after modifying storage capacities to update the visual representation
---@param placeable table The placeable
Expand Down Expand Up @@ -1110,17 +1137,8 @@ function RmAdjustStorageCapacity:applyCapacitiesToPlaceable(placeable, customCap
if applied > 0 then
Log:debug("Applied %d capacity changes to %s", applied, placeable:getName())

-- Apply proportional load speed based on capacity multiplier
local multiplier = self:getMaxCapacityMultiplier(placeable, customCapacity)
Log:debug("Capacity multiplier for %s: %.2f (sharedCapacity=%s, fillTypes=%s)",
placeable:getName(), multiplier,
tostring(customCapacity.sharedCapacity),
customCapacity.fillTypes and "yes" or "no")
if multiplier ~= 1.0 then
self:applyProportionalLoadSpeed(placeable, multiplier)
else
Log:debug("Skipping load speed adjustment for %s (multiplier is 1.0)", placeable:getName())
end
-- Recalculate from every stored override, not only the fields applied by this call.
self:refreshLoadSpeed(placeable, customCapacity)

-- Update visual fill planes to reflect new capacity
-- Skip during savegame load - fill levels are 0 at this point, so recreating
Expand Down Expand Up @@ -1440,6 +1458,7 @@ function RmAdjustStorageCapacity:setCapacity(placeable, fillTypeIndex, newCapaci
-- Update visual fill planes
self:updatePlaceableFillPlanes(placeable)
end
self:refreshLoadSpeed(placeable)

Log:info("Set HusbandryFood capacity for %s to %d", placeable:getName(), newCapacity)
else
Expand Down Expand Up @@ -1599,9 +1618,6 @@ function RmAdjustStorageCapacity:resetCapacity(placeable, fillTypeIndex)
self:clampExcessFill(info.storage)
end

-- Reset load speed to original
self:resetLoadSpeed(placeable)

self.customCapacities[uniqueId] = nil
Log:info("Reset all capacities for %s to original", placeable:getName())
end
Expand All @@ -1623,6 +1639,8 @@ function RmAdjustStorageCapacity:resetCapacity(placeable, fillTypeIndex)
end
end

self:refreshLoadSpeed(placeable)

return true, nil
end

Expand Down