fix(kæde): spillerens tændte produktioner leverer til andre rødder med fuld kapacitet

This commit is contained in:
2026-09-30 14:21:23 +02:00
parent e394a77833
commit 9c9c2badeb
+11 -5
View File
@@ -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