fix: gennemløbsfabrikker (tørreri hvede->hvede) er ikke producenter i kæden ('Loop around Wheat'); pålæsnings-rulning måler til triggerens midte som diagnosen — 1.62.301

This commit is contained in:
2026-10-17 09:17:20 +02:00
parent 2fd40f5929
commit 42a8fb8dea
5 changed files with 40 additions and 16 deletions
+13 -3
View File
@@ -7,12 +7,19 @@ ADChainModel.MAX_DEPTH = 8
local function byKey(a, b) return tostring(a.key) < tostring(b.key) end
-- Ren: gennemløb — fabrikken laver varen AF varen selv (tørreri: hvede -> hvede). Den skaber intet og må ikke tælle
-- som producent, ellers bider kæden sig selv i halen (in-game 17/10: "Animals' feed: Loop around Wheat" via AGI Westeel
-- Silo With Dryer, der "kunne kun lave 2,4k af 34,5k/md").
function ADChainModel.isPassThrough(recipe, name)
return ((recipe.inputs or {})[name] or 0) > 0
end
-- producenter pr. vare: tændte først, så stabil rækkefølge
local function indexProducers(recipes)
local index = {}
for _, recipe in ipairs(recipes or {}) do
for name, amount in pairs(recipe.outputs or {}) do
if (amount or 0) > 0 and (recipe.cyclesPerMonth or 0) > 0 then
if (amount or 0) > 0 and (recipe.cyclesPerMonth or 0) > 0 and not ADChainModel.isPassThrough(recipe, name) then
index[name] = index[name] or {}
table.insert(index[name], recipe)
end
@@ -187,7 +194,8 @@ function ADChainModel.build(recipes, husbandry, crops, fieldGoods, goodCrops, an
if (root.outputModes or {})[name] == "sell" then sells = true end
-- også når behovet allerede er dækket af en anden rod (rest 0): så kører denne slet ikke for dyrene
-- (in-game 8/10: tmr1 dækkede køerne, tmr2 blev derfor regnet som ikke-foder og kørte fuldt)
if animalLeft[name] ~= nil and (perCycle or 0) > 0 then
-- gennemløb (tørreri hvede -> hvede) fodrer ikke dyrene: varen kom ind som input (review 17/10)
if animalLeft[name] ~= nil and (perCycle or 0) > 0 and not ADChainModel.isPassThrough(root, name) then
feeds = true
feedCycles = math.max(feedCycles, animalLeft[name] / perCycle)
end
@@ -196,7 +204,9 @@ function ADChainModel.build(recipes, husbandry, crops, fieldGoods, goodCrops, an
local cycles = sells and (root.cyclesPerMonth or 0) or math.min(root.cyclesPerMonth or 0, feedCycles)
rootCycles[root.key] = cycles
for name, perCycle in pairs(root.outputs or {}) do
if animalLeft[name] ~= nil then animalLeft[name] = math.max(0, animalLeft[name] - cycles * perCycle) end
if animalLeft[name] ~= nil and not ADChainModel.isPassThrough(root, name) then
animalLeft[name] = math.max(0, animalLeft[name] - cycles * perCycle)
end
end
-- rodens råvarer er nu også foder (afledt): den der laver dem, begrænses i næste runde
for name, amount in pairs(root.inputs or {}) do
+21 -11
View File
@@ -64,8 +64,25 @@ function ADLoadDiag.describeOffset(x, y, z, radius)
radius ~= nil and string.format(" (triggerens radius %.1f m)", radius) or "")
end
-- Triggerens midte (bounding-sfærens centrum, ellers nodens nulpunkt) set fra den første fyldenheds exactFillRootNode,
-- i traktorens retning.
-- Triggerens midte i verden: bounding-sfærens centrum (nodens nulpunkt sidder tit i et hjørne), ellers nodens nulpunkt.
-- -> x, y, z, radius | nil. Bruges også af ADLoadRoll, så rulning og diagnose måler det samme sted (17/10: rulningen
-- målte til nodens nulpunkt og planlagde 0,4 m, mens midten lå 1,3-2,9 m længere fremme).
function ADLoadDiag.triggerCenter(trigger)
local node = trigger ~= nil and trigger.triggerNode or nil
if node == nil then return nil end
local cx, cy, cz, radius = 0, 0, 0, nil
if getShapeBoundingSphere ~= nil then
local okR, sx, sy, sz, r = pcall(getShapeBoundingSphere, node)
if okR and type(r) == "number" then
radius = r
if type(sx) == "number" and type(sy) == "number" and type(sz) == "number" then cx, cy, cz = sx, sy, sz end
end
end
local x, y, z = localToWorld(node, cx, cy, cz)
return x, y, z, radius
end
-- Triggerens midte set fra den første fyldenheds exactFillRootNode, i traktorens retning.
local function fillOffset(trigger, trailer, fillType, vehicle)
local node = trigger.triggerNode
if node == nil or trailer.getFillUnits == nil or vehicle == nil or vehicle.rootNode == nil then return nil end
@@ -74,15 +91,8 @@ local function fillOffset(trigger, trailer, fillType, vehicle)
local fillNode = trailer.getFillUnitExactFillRootNode ~= nil and trailer:getFillUnitExactFillRootNode(i) or nil
if fillNode ~= nil then
local fx, fy, fz = getWorldTranslation(fillNode)
local cx, cy, cz, radius = 0, 0, 0, nil
if getShapeBoundingSphere ~= nil then
local okR, sx, sy, sz, r = pcall(getShapeBoundingSphere, node)
if okR and type(r) == "number" then
radius = r
if type(sx) == "number" and type(sy) == "number" and type(sz) == "number" then cx, cy, cz = sx, sy, sz end
end
end
local tx, ty, tz = localToWorld(node, cx, cy, cz)
local tx, ty, tz, radius = ADLoadDiag.triggerCenter(trigger)
if tx == nil then return nil end
local x, _, z = worldDirectionToLocal(vehicle.rootNode, tx - fx, 0, tz - fz)
return ADLoadDiag.describeOffset(x, ty - fy, z, radius)
end
+4 -1
View File
@@ -102,7 +102,10 @@ local function offsetsFor(adEnv, vehicle, task)
local nx, _, nz = getWorldTranslation(node)
for _, trigger in pairs(manager.getLoadTriggers() or {}) do
if manager.triggerSupportsFillType(trigger, fillType) then
local tx, _, tz = manager.getTriggerPos(trigger)
-- triggerens MIDTE (bounding-sfære), ikke nodens nulpunkt — samme mål som diagnosen (17/10)
local tx, _, tz = nil, nil, nil
if ADLoadDiag ~= nil and ADLoadDiag.triggerCenter ~= nil then tx, _, tz = ADLoadDiag.triggerCenter(trigger) end
if tx == nil then tx, _, tz = manager.getTriggerPos(trigger) end
if tx ~= nil and (tx ~= 0 or tz ~= 0) and math.sqrt((tx - nx) ^ 2 + (tz - nz) ^ 2) <= ADLoadRoll.SEARCH_RADIUS then
local x, _, z = worldDirectionToLocal(vehicle.rootNode, tx - nx, 0, tz - nz)
table.insert(offsets, {x = x, z = z, inBox = inBox(trigger, trailer, i)})
+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.62.300.0</version>
<version>1.62.301.0</version>
<title>
<en>AD Smart Pickup</en>
</title>