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
+4 -1
View File
@@ -327,8 +327,11 @@ function ADRunsController.resolveMarkers(adEnv, run)
for _, wayPointId in ipairs(existing or {}) do
if not seen[wayPointId] and ADBuildings.byMarker(adEnv, farmId, wayPointId, role) == nil then
local keep = true
-- et rå id skal være en AD-markør: sletter man waypoints i AutoDrive, omnummereres alle
-- senere punkter, og et gammelt markør-id peger så på et tilfældigt vejpunkt
local isMarker = adEnv.ADGraphManager.getMapMarkerByWayPointId == nil or adEnv.ADGraphManager:getMapMarkerByWayPointId(wayPointId) ~= nil
if role == "load" and ADSources ~= nil and ADSources.identify ~= nil then
local source = ADSources.identify(adEnv, wayPointId, farmId)
local source = isMarker and ADSources.identify(adEnv, wayPointId, farmId) or nil
keep = source ~= nil and not (source.placeable ~= nil and chosenPlaceables[source.placeable])
elseif role == "unload" then
-- mål skal være en AD-MARKØR med aflæsningsstation (et slettet markør-id er kun et waypoint,
+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
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.16.2.0</version>
<version>1.16.3.0</version>
<title>
<en>AD Smart Pickup</en>
</title>
+12
View File
@@ -634,6 +634,18 @@ local pruneLogged = false
for _, line in ipairs(logLines) do if line:find("gamle markører fjernet", 1, true) then pruneLogged = true end end
check("CF1b logget", pruneLogged, true)
-- CF1c: et gammelt kilde-id der ikke længere er en AD-MARKØR (AutoDrive har omnummereret waypoints)
-- fjernes, selv om punktet ligger ved en kilde — ellers kører traktoren til et tilfældigt vejpunkt
local identifyBefore = ADSources.identify
ADSources.identify = function(adEnv_, id, farmId)
if id == 10873 then return {kind = "husbandry", wayPointId = id, name = "Anden stald", placeable = "anden-stald"} end
return identifyBefore(adEnv_, id, farmId)
end
ADRunsController.updateRun(flowOut.id, {sourceBuildingIds = {"barn1"}, sourceWayPointIds = {10, 11, 555, 10873}})
ADRunsController.resolveMarkers(adEnv, ADRuns.getRun(ADRunsController.store, flowOut.id))
check("CF1c vejpunkt uden markør fjernet", table.concat(ADRuns.getRun(ADRunsController.store, flowOut.id).sourceWayPointIds, ","), "10,11,555")
ADSources.identify = identifyBefore
-- CF2: forsyning: mål-bygninger -> targetWayPointIds + targetWayPointId
local flowIn = ADRunsController.createRun("Foder", "supply")
ADRunsController.updateRun(flowIn.id, {targetBuildingIds = {"barn1", "mill"}})
+8
View File
@@ -341,6 +341,14 @@ check("S14 bulk", products14[1].isPallet, false)
check("S14 isPalletAt stald = bulk", ADSources.isPalletAt(source14, MILK), false)
check("S14 kilde-markør i listen", ADRunsController ~= nil and true or true, true)
-- S14b: mælketank-udvidelse (siloExtension) — læssestationen trækker fra stald + tank; niveauet skal
-- være stationens samlede mængde, ikke kun staldens egen beholder
milkStation.getAllFillLevels = function(self, farmId) return {[MILK] = 1275 + 136912}, 10025000 end
local products14b = ADSources.getProducts(adEnv, source14, 1)
check("S14b stald + udvidelsestank", products14b[1].level, 138187)
check("S14b tilgængeligt = samlet", products14b[1].available, 138187)
milkStation.getAllFillLevels = nil
-- S15: forklaring af en markør til advarslen (hvad opslaget ser)
check("S15 forklaring stald", ADSources.explainMarker(adEnv, 10, 1), "læssestation ved markøren hører til 'Kostald' (stald)")
check("S15 forklaring ingen station", ADSources.explainMarker(adEnv, 4, 1), "ingen læssestation ved markøren, og ingen fabrik/objektlager inden for 40 m")