fix: getStableSiloFillTypes flyttet under sine lokale hjælpere (nil-kald) (v1.62.144)

This commit is contained in:
2026-10-10 03:42:35 +02:00
parent 9fb6b97b52
commit 9ca9dde380
3 changed files with 34 additions and 33 deletions
+32 -32
View File
@@ -424,38 +424,6 @@ local function mayUseSource(station, fillTypes, level, loadCapacity, need)
return true
end
-- Stald-silo som mål: de varer staldene inden for stableSiloRange af siloen bruger (foder + halm). nil når målet ikke
-- er en ren silo, eller ingen stald står ved den (så fyldes siloen med alt, den tager — et almindeligt lager).
function ADSmartPickup.getStableSiloFillTypes(adEnv, stations, farmId)
local placeables = {}
for _, entry in ipairs(stations or {}) do
local placeable = entry.station ~= nil and entry.station.owningPlaceable or nil
if placeable == nil or placeable.spec_silo == nil or getHusbandry(entry.station) ~= nil or getProductionPoint(entry.station) ~= nil then return nil end
table.insert(placeables, placeable)
end
if #placeables == 0 or ADBuildings == nil then return nil end
local result, any = {}, false
local strawIndex = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeIndexByName("STRAW") or nil
for _, silo in ipairs(placeables) do
local siloId = ADBuildings.getId ~= nil and ADBuildings.getId(silo) or nil
local range = ADSettings ~= nil and ADSettings.get("stableSiloRange", siloId) or ADSupplyPlanner.STABLE_SILO_M
local okS, sx, _, sz = pcall(getWorldTranslation, silo.rootNode)
if okS then
for _, building in ipairs(ADBuildings.list(adEnv, farmId) or {}) do
local husbandry = building.kind == "husbandry" and building.placeable or nil
if husbandry ~= nil and husbandry.rootNode ~= nil then
local okH, hx, _, hz = pcall(getWorldTranslation, husbandry.rootNode)
if okH and math.sqrt((hx - sx) ^ 2 + (hz - sz) ^ 2) <= range then
for fillType in pairs(getHusbandryFoodFillTypes(husbandry) or {}) do result[fillType], any = true, true end
if strawIndex ~= nil and husbandry.spec_husbandryStraw ~= nil then result[strawIndex], any = true, true end
end
end
end
end
end
return any and result or nil
end
-- Behov pr. vare lige nu (til retfærdig fordeling): køretøj -> {free, at}
local demandRegistry = {}
ADSmartPickup.DEMAND_FRESH_MS = 10 * 60 * 1000
@@ -784,6 +752,38 @@ end
local getTargetLevelAndCapacity = ADSmartPickup.getStationLevelAndCapacity
-- Niveau + kapacitet pr. ingrediens i aflæsningsmålets lager; demand giver forbrug/min.
-- Stald-silo som mål: de varer staldene inden for stableSiloRange af siloen bruger (foder + halm). nil når målet ikke
-- er en ren silo, eller ingen stald står ved den (så fyldes siloen med alt, den tager — et almindeligt lager).
function ADSmartPickup.getStableSiloFillTypes(adEnv, stations, farmId)
local placeables = {}
for _, entry in ipairs(stations or {}) do
local placeable = entry.station ~= nil and entry.station.owningPlaceable or nil
if placeable == nil or placeable.spec_silo == nil or getHusbandry(entry.station) ~= nil or getProductionPoint(entry.station) ~= nil then return nil end
table.insert(placeables, placeable)
end
if #placeables == 0 or ADBuildings == nil then return nil end
local result, any = {}, false
local strawIndex = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeIndexByName("STRAW") or nil
for _, silo in ipairs(placeables) do
local siloId = ADBuildings.getId ~= nil and ADBuildings.getId(silo) or nil
local range = ADSettings ~= nil and ADSettings.get("stableSiloRange", siloId) or ADSupplyPlanner.STABLE_SILO_M
local okS, sx, _, sz = pcall(getWorldTranslation, silo.rootNode)
if okS then
for _, building in ipairs(ADBuildings.list(adEnv, farmId) or {}) do
local husbandry = building.kind == "husbandry" and building.placeable or nil
if husbandry ~= nil and husbandry.rootNode ~= nil then
local okH, hx, _, hz = pcall(getWorldTranslation, husbandry.rootNode)
if okH and math.sqrt((hx - sx) ^ 2 + (hz - sz) ^ 2) <= range then
for fillType in pairs(getHusbandryFoodFillTypes(husbandry) or {}) do result[fillType], any = true, true end
if strawIndex ~= nil and husbandry.spec_husbandryStraw ~= nil then result[strawIndex], any = true, true end
end
end
end
end
end
return any and result or nil
end
local function getTargetNeeds(station, ingredients, farmId, demand)
local needs = {}
-- trug-tærskel pr. stald (ADSettings "troughRefillPercent"): kør først når truget er under tærsklen