fix: stald-siloer regnes ikke som marksiloer (v1.62.146)

This commit is contained in:
2026-10-10 03:58:54 +02:00
parent 795c9ff7a1
commit 04a7aa8008
6 changed files with 33 additions and 5 deletions
+22 -1
View File
@@ -6,6 +6,7 @@
ADFields = {}
ADFields.FIELD_SILO_DISTANCE = 150
ADFields.STABLE_SILO_M = 80 -- standard når ADSettings ikke er indlæst (ellers "stableSiloRange")
ADFields.MARKER_MAX_DISTANCE = 400
ADFields.cache = {}
ADFields.order = {}
@@ -727,13 +728,33 @@ function ADFields.getInfo(id)
return ADFields.cache[id]
end
-- Stald-silo: en silo inden for stableSiloRange (ADSettings, standard 80 m) af en stald i bygningslisten. Den er
-- staldens eget lager (forsyningen henter dér), ikke en marksilo — også når den står op ad en mark.
function ADFields.isStableSilo(building, buildings)
if building == nil or building.kind ~= "silo" or building.placeable == nil or building.placeable.rootNode == nil then return false end
local okS, sx, _, sz = pcall(getWorldTranslation, building.placeable.rootNode)
if not okS or sx == nil then return false end
local range = ADSettings ~= nil and ADSettings.get("stableSiloRange", building.id) or ADFields.STABLE_SILO_M
for _, other in ipairs(buildings or {}) do
local node = other.kind == "husbandry" and other.placeable ~= nil and other.placeable.rootNode or nil
if node ~= nil then
local okH, hx, _, hz = pcall(getWorldTranslation, node)
if okH and hx ~= nil and (hx - sx) ^ 2 + (hz - sz) ^ 2 <= range ^ 2 then return true end
end
end
return false
end
-- Siloer tæt på markens polygon (eller centrum): mellemlagre, som et udkørselsflow skal tømme hjem.
-- Stald-siloer (ADFields.isStableSilo) tælles ikke med: de hører til stalden, ikke marken.
function ADFields.fieldSilos(adEnv, farmId, info)
local result = {}
if ADBuildings == nil or info == nil or info.x == nil then return result end
local anchors = #info.verts > 0 and info.verts or {{x = info.x, z = info.z}}
for _, building in ipairs(ADBuildings.list(adEnv, farmId)) do
local buildings = ADBuildings.list(adEnv, farmId)
for _, building in ipairs(buildings) do
local node = building.kind == "silo" and building.placeable ~= nil and building.placeable.rootNode or nil
if node ~= nil and ADFields.isStableSilo(building, buildings) then node = nil end
if node ~= nil then
local bx, _, bz = getWorldTranslation(node)
for _, anchor in ipairs(anchors) do