fix(kæde): spillerens tændte produktioner leverer til andre rødder med fuld kapacitet
This commit is contained in:
@@ -50,13 +50,17 @@ end
|
|||||||
function ADChainModel.build(recipes, husbandry, crops)
|
function ADChainModel.build(recipes, husbandry, crops)
|
||||||
local chain = {roots = {}, demand = {}, fieldDemand = {}, needRecipes = {}, problems = {}}
|
local chain = {roots = {}, demand = {}, fieldDemand = {}, needRecipes = {}, problems = {}}
|
||||||
local producers, herds = indexProducers(recipes), indexHerds(husbandry)
|
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
|
for _, recipe in ipairs(recipes or {}) do
|
||||||
capacity[recipe.key] = recipe.cyclesPerMonth or 0
|
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
|
end
|
||||||
table.sort(roots, byKey)
|
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)
|
local function problem(kind, fillType, rootKey, detail)
|
||||||
table.insert(chain.problems, {kind = kind, fillType = fillType, rootKey = rootKey, detail = detail})
|
table.insert(chain.problems, {kind = kind, fillType = fillType, rootKey = rootKey, detail = detail})
|
||||||
@@ -96,10 +100,12 @@ function ADChainModel.build(recipes, husbandry, crops)
|
|||||||
if cycles > 0 then
|
if cycles > 0 then
|
||||||
capacity[recipe.key] = capacity[recipe.key] - cycles
|
capacity[recipe.key] = capacity[recipe.key] - cycles
|
||||||
rest = rest - cycles * perCycle
|
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})
|
table.insert(node.producers, {key = recipe.key, building = recipe.building, buildingName = recipe.buildingName, cycles = cycles})
|
||||||
|
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
|
for _, child in ipairs(inputsOf(recipe, cycles, depth, path, rootKey)) do table.insert(node.children, child) end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if rest <= 1e-9 then break end
|
if rest <= 1e-9 then break end
|
||||||
end
|
end
|
||||||
if rest > 1e-9 and #node.producers > 0 then
|
if rest > 1e-9 and #node.producers > 0 then
|
||||||
|
|||||||
Reference in New Issue
Block a user