fix(stald): mængde = læssestationens samlede beholdning (stald + Milk Tank Extension); gamle kilde-id'er skal være AD-markører (omnummerering efter slettede waypoints) (v1.16.3.0)

This commit is contained in:
2026-09-24 03:10:27 +02:00
parent 23c94b49df
commit d63f0fcd5e
5 changed files with 54 additions and 6 deletions
+29 -4
View File
@@ -368,14 +368,21 @@ local function getHusbandryProducts(adEnv, source)
end
end
table.sort(fillTypes)
-- Læssestationen trækker fra staldens beholder OG tilknyttede udvidelser (fx Milk Tank Extension,
-- en siloExtension inden for storageRadius). getHusbandryFillLevel ser kun staldens egen beholder.
local stationLevels = nil
if station ~= nil and station.getAllFillLevels ~= nil then
local ok, levels = pcall(station.getAllFillLevels, station, g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1)
if ok and type(levels) == "table" then stationLevels = levels end
end
local products = {}
for _, fillType in ipairs(fillTypes) do
local level = placeable:getHusbandryFillLevel(fillType) or 0
local level = math.max(placeable:getHusbandryFillLevel(fillType) or 0, stationLevels ~= nil and stationLevels[fillType] or 0)
local capacity = placeable.getHusbandryCapacity ~= nil and (placeable:getHusbandryCapacity(fillType) or 0) or 0
if capacity <= 0 and placeable.getHusbandryFreeCapacity ~= nil then
capacity = level + (placeable:getHusbandryFreeCapacity(fillType) or 0)
end
table.insert(products, newProduct(fillType, level, level, capacity, false))
table.insert(products, newProduct(fillType, level, level, math.max(capacity, level), false))
end
return products
end
@@ -828,8 +835,25 @@ local function objectStorageEntries(placeable)
return entries
end
-- Stald + udvidelsestanke: højeste niveau pr. vare blandt staldens læssestationer (de deler beholdere).
local function getHusbandryStationLevels(placeable)
local storage = g_currentMission ~= nil and g_currentMission.storageSystem or nil
local result = {}
if storage == nil or storage.getLoadingStations == nil then return result end
for _, station in pairs(storage:getLoadingStations()) do
if station.owningPlaceable == placeable and station.getAllFillLevels ~= nil then
local ok, levels = pcall(station.getAllFillLevels, station, g_currentMission:getFarmId())
for fillType, level in pairs(ok and type(levels) == "table" and levels or {}) do
result[fillType] = math.max(result[fillType] or 0, level or 0)
end
end
end
return result
end
local function husbandryEntries(placeable)
local entries, seen = {}, {}
local stationLevels = getHusbandryStationLevels(placeable)
local food = placeable.spec_husbandryFood
if food ~= nil then
local total = 0
@@ -850,10 +874,11 @@ local function husbandryEntries(placeable)
end
end
if fillType ~= nil and not seen[fillType] and placeable.getHusbandryIsFillTypeSupported ~= nil and placeable:getHusbandryIsFillTypeSupported(fillType) then
local level = placeable.getHusbandryFillLevel ~= nil and (placeable:getHusbandryFillLevel(fillType) or 0) or 0
local own = placeable.getHusbandryFillLevel ~= nil and (placeable:getHusbandryFillLevel(fillType) or 0) or 0
local level = math.max(own, stationLevels[fillType] or 0)
if level > 0 then
local free = placeable.getHusbandryFreeCapacity ~= nil and (placeable:getHusbandryFreeCapacity(fillType) or 0) or 0
addEntry(entries, fillType, level, level + free)
addEntry(entries, fillType, level, math.max(level, own + free))
end
end
end