diff --git a/FS25_ADSmartPickup/adChainModel.lua b/FS25_ADSmartPickup/adChainModel.lua index 0342000..7948dc0 100644 --- a/FS25_ADSmartPickup/adChainModel.lua +++ b/FS25_ADSmartPickup/adChainModel.lua @@ -50,13 +50,17 @@ end function ADChainModel.build(recipes, husbandry, crops) local chain = {roots = {}, demand = {}, fieldDemand = {}, needRecipes = {}, problems = {}} local producers, herds = indexProducers(recipes), indexHerds(husbandry) - local capacity, roots = {}, {} + -- Rødderne kører for sig selv med fuld fart: deres egne input kræves af deres eget træ. Som leverandør til en + -- anden rod har de derfor fuld kapacitet, men deres input regnes ikke med igen (standalone = ingen rekursion). + local capacity, roots, standalone = {}, {}, {} for _, recipe in ipairs(recipes or {}) do capacity[recipe.key] = recipe.cyclesPerMonth or 0 - if recipe.enabled and not recipe.byChain then table.insert(roots, recipe) end + if recipe.enabled and not recipe.byChain then + table.insert(roots, recipe) + standalone[recipe.key] = true + end end table.sort(roots, byKey) - for _, root in ipairs(roots) do capacity[root.key] = 0 end -- rødderne kører for sig selv local function problem(kind, fillType, rootKey, detail) table.insert(chain.problems, {kind = kind, fillType = fillType, rootKey = rootKey, detail = detail}) @@ -96,9 +100,11 @@ function ADChainModel.build(recipes, husbandry, crops) if cycles > 0 then capacity[recipe.key] = capacity[recipe.key] - cycles rest = rest - cycles * perCycle - chain.needRecipes[recipe.key] = (chain.needRecipes[recipe.key] or 0) + cycles table.insert(node.producers, {key = recipe.key, building = recipe.building, buildingName = recipe.buildingName, cycles = cycles}) - for _, child in ipairs(inputsOf(recipe, cycles, depth, path, rootKey)) do table.insert(node.children, child) end + if not standalone[recipe.key] then + chain.needRecipes[recipe.key] = (chain.needRecipes[recipe.key] or 0) + cycles + for _, child in ipairs(inputsOf(recipe, cycles, depth, path, rootKey)) do table.insert(node.children, child) end + end end if rest <= 1e-9 then break end end