fix: kæden kører palle-varer i udkørselsflows (forsyning kan ikke hente paller)
This commit is contained in:
@@ -217,12 +217,13 @@ function ADChain.activeRoots(chain, paused)
|
||||
return result
|
||||
end
|
||||
|
||||
-- Mest brugte Wait-pulje blandt forsyningsflows til bygningen, ellers "".
|
||||
-- Mest brugte Wait-pulje blandt flows der leverer til bygningen (forsyning og kædens palle-flows), ellers "".
|
||||
function ADChain.waitPoolFor(runs, building)
|
||||
local counts, best, bestCount = {}, "", 0
|
||||
for _, run in ipairs(runs or {}) do
|
||||
local group = run.waitPoolGroup
|
||||
if run.kind == "supply" and group ~= nil and group ~= "" and contains(run.targetBuildingIds, building) then
|
||||
-- forsyning (mål) og kædens palle-flows (udkørsel: Lever også til/Lager til)
|
||||
if group ~= nil and group ~= "" and contains(ADChainActions.deliversTo(run), building) then
|
||||
counts[group] = (counts[group] or 0) + 1
|
||||
end
|
||||
end
|
||||
@@ -236,9 +237,9 @@ function ADChain.flowName(fillTitle, buildingName)
|
||||
return "Kæde: " .. tostring(fillTitle) .. " → " .. tostring(buildingName)
|
||||
end
|
||||
|
||||
-- forsyning (mål + varer) og kædens palle-flows som udkørsel ("Lager til" + varer) — ADChainActions.coversEdge
|
||||
local function covers(run, edge)
|
||||
return contains(run.targetBuildingIds, edge.consumer)
|
||||
and (run.ingredientMode ~= "manual" or contains(run.ingredients, edge.fillType))
|
||||
return ADChainActions.coversEdge(run, edge)
|
||||
end
|
||||
|
||||
-- Bruger en af de aktuelle kanter stadig flowet? -> kantens rodnøgle (flowet flyttes dertil), ellers nil.
|
||||
@@ -256,7 +257,7 @@ function ADChain.flowStatus(edges, runs, noVehicle)
|
||||
-- udgangen står på Fordel: spillet leverer selv, intet flow
|
||||
local status = edge.delivery == "auto" and "auto" or "missing"
|
||||
for _, run in ipairs(edge.delivery == "auto" and {} or runs or {}) do
|
||||
if run.kind == "supply" and covers(run, edge) then
|
||||
if covers(run, edge) then
|
||||
if not run.stopped or run.sleeping then status = "ok"; break end -- sovende flow vågner selv
|
||||
local reason = (noVehicle or {})[run.id]
|
||||
if reason == "pallet" then status = "pallet"
|
||||
@@ -275,6 +276,8 @@ function ADChain.runsView(runs)
|
||||
for _, run in ipairs(runs or {}) do
|
||||
table.insert(list, {id = run.id, name = run.name, kind = run.kind, targetBuildingIds = run.targetBuildingIds,
|
||||
ingredientMode = run.ingredientMode, ingredients = run.ingredients, stopped = run.stopped == true and not run.sleeping,
|
||||
storeBuildingIds = run.storeBuildingIds, feedBuildingIds = run.feedBuildingIds, sourceBuildingIds = run.sourceBuildingIds,
|
||||
products = run.products,
|
||||
chain = run.chain, waitPoolGroup = run.waitPoolGroup,
|
||||
-- traktorerne: uden dem ligner alle kædeflows tomme (sammenlægning/sletning må kun ramme tomme)
|
||||
vehicleIds = run.vehicleIds or {}})
|
||||
|
||||
@@ -44,6 +44,18 @@ local function producerKeys(node)
|
||||
return keys
|
||||
end
|
||||
|
||||
-- Bygningerne der laver varen (fabrikker, stalde): kilder for et udkørselsflow med palle-varer
|
||||
local function producerBuildings(node)
|
||||
local list, seen = {}, {}
|
||||
for _, maker in ipairs(node.producers or {}) do
|
||||
if maker.building ~= nil and not seen[maker.building] then seen[maker.building] = true table.insert(list, maker.building) end
|
||||
end
|
||||
for _, herd in ipairs(node.herds or {}) do
|
||||
if herd.building ~= nil and not seen[herd.building] then seen[herd.building] = true table.insert(list, herd.building) end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
-- recipes (valgfri): gårdens opskrifter med outputModes -> kanten får delivery (se ADChainActions.delivery).
|
||||
function ADChainActions.edges(chain, recipes)
|
||||
local list, seen, byKey = {}, {}, nil
|
||||
@@ -57,7 +69,7 @@ function ADChainActions.edges(chain, recipes)
|
||||
if SUPPLIED[node.source] and node.consumer ~= nil and not seen[id] then
|
||||
seen[id] = true
|
||||
local edge = {fillType = node.fillType, consumer = node.consumer, consumerName = node.consumerName, rootKey = rootKey,
|
||||
producers = producerKeys(node)}
|
||||
producers = producerKeys(node), producerBuildings = producerBuildings(node)}
|
||||
edge.delivery = ADChainActions.delivery(edge, byKey)
|
||||
edge.soldBy = {}
|
||||
for _, key in ipairs(edge.producers) do
|
||||
@@ -74,12 +86,41 @@ end
|
||||
|
||||
local contains = ADUtil.contains
|
||||
|
||||
-- Palle-varer kører i et UDKØRSELSFLOW (20/10: forsyningen henter kun fra læssestationer, så "Kæde: Canola Oil" fandt
|
||||
-- aldrig olien ved Oil Mill's pallepladser): Fra = producenten, varen på Lager (palleskur når forbrugeren er fyldt),
|
||||
-- "Lever også til" = forbrugeren (et palleflows Lager-trin tilbyder kun palleskure).
|
||||
-- Bygningerne et flow leverer til: forsyning = målene, udkørsel = "Lever også til" + "Lager til".
|
||||
function ADChainActions.deliversTo(run)
|
||||
if run.kind ~= "outbound" then return run.targetBuildingIds or {} end
|
||||
local list = {}
|
||||
for _, key in ipairs({"feedBuildingIds", "storeBuildingIds"}) do
|
||||
for _, id in ipairs(run[key] or {}) do if not contains(list, id) then table.insert(list, id) end end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
-- Varerne et flow leverer: forsyning = ingredienserne, udkørsel = varer med lager-politik. nil = alt (automatisk forsyning)
|
||||
function ADChainActions.goodsOf(run)
|
||||
if run.kind == "outbound" then
|
||||
local names = {}
|
||||
for _, product in ipairs(run.products or {}) do
|
||||
if product.policy == "store" or product.policy == "sellElseStore" then table.insert(names, product.fillType) end
|
||||
end
|
||||
return names
|
||||
end
|
||||
if run.ingredientMode ~= "manual" then return nil end
|
||||
return run.ingredients or {}
|
||||
end
|
||||
|
||||
function ADChainActions.coversEdge(run, edge)
|
||||
if not contains(ADChainActions.deliversTo(run), edge.consumer) then return false end
|
||||
local goods = ADChainActions.goodsOf(run)
|
||||
return goods == nil or contains(goods, edge.fillType)
|
||||
end
|
||||
|
||||
function ADChainActions.isCovered(edge, runs)
|
||||
for _, run in ipairs(runs or {}) do
|
||||
if run.kind == "supply" and contains(run.targetBuildingIds, edge.consumer)
|
||||
and (run.ingredientMode ~= "manual" or contains(run.ingredients, edge.fillType)) then
|
||||
return true
|
||||
end
|
||||
if ADChainActions.coversEdge(run, edge) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
@@ -124,22 +165,51 @@ end
|
||||
-- ---- ét kædeflow pr. bygning (in-game 30/9: ét flow pr. vare og bygning gav mange stoppede flows) ----
|
||||
|
||||
-- Manglende kanter samlet pr. modtagerbygning: {consumer, consumerName, rootKey, fillTypes} i fundet rækkefølge.
|
||||
-- group.producers = {[vare] = {bygning, ...}}: kilderne til et palle-flow
|
||||
function ADChainActions.groupMissing(missing)
|
||||
local groups, byConsumer = {}, {}
|
||||
for _, edge in ipairs(missing or {}) do
|
||||
local group = byConsumer[edge.consumer]
|
||||
if group == nil then
|
||||
group = {consumer = edge.consumer, consumerName = edge.consumerName, rootKey = edge.rootKey, fillTypes = {}}
|
||||
group = {consumer = edge.consumer, consumerName = edge.consumerName, rootKey = edge.rootKey, fillTypes = {}, producers = {}}
|
||||
byConsumer[edge.consumer] = group
|
||||
table.insert(groups, group)
|
||||
end
|
||||
if not contains(group.fillTypes, edge.fillType) then table.insert(group.fillTypes, edge.fillType) end
|
||||
local list = group.producers[edge.fillType] or {}
|
||||
for _, building in ipairs(edge.producerBuildings or {}) do
|
||||
if not contains(list, building) then table.insert(list, building) end
|
||||
end
|
||||
group.producers[edge.fillType] = list
|
||||
end
|
||||
return groups
|
||||
end
|
||||
|
||||
-- Kildebygningerne for varerne (i fundet rækkefølge, uden dubletter). producers = group.producers
|
||||
function ADChainActions.sourcesFor(producers, fillTypes)
|
||||
local list = {}
|
||||
for _, name in ipairs(fillTypes or {}) do
|
||||
for _, building in ipairs((producers or {})[name] or {}) do
|
||||
if not contains(list, building) then table.insert(list, building) end
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
-- Ændringer der gør et (nyt eller gammelt) kædeflow til et palle-flow: udkørsel fra producenterne, varerne på Lager
|
||||
-- (palleskur, når forbrugeren er fyldt), forbrugeren under "Lever også til". Ren -> changes til ADRuns.updateRun
|
||||
function ADChainActions.palletFlowChanges(consumer, fillTypes, sources, rootKey, waitPoolGroup)
|
||||
local products = {}
|
||||
for _, name in ipairs(fillTypes or {}) do table.insert(products, {fillType = name, policy = "store"}) end
|
||||
return {kind = "outbound", sourceBuildingIds = sources or {}, products = products, feedBuildingIds = {consumer},
|
||||
storeBuildingIds = {}, targetBuildingIds = {}, ingredients = {}, collectRound = true, chain = rootKey,
|
||||
waitPoolGroup = waitPoolGroup or ""}
|
||||
end
|
||||
|
||||
-- Kædens egne flows: forsyning med manuelle varer, eller udkørsel (palle-varer)
|
||||
local function isChainRun(run)
|
||||
return run.chain ~= nil and run.chain ~= "" and run.kind == "supply" and run.ingredientMode == "manual"
|
||||
if run.chain == nil or run.chain == "" then return false end
|
||||
return run.kind == "outbound" or (run.kind == "supply" and run.ingredientMode == "manual")
|
||||
end
|
||||
|
||||
-- Kædens eget flow (manuelle varer) til bygningen -> run-id, så nye varer lægges i det i stedet for et nyt flow.
|
||||
@@ -149,7 +219,7 @@ function ADChainActions.chainRunFor(runs, consumer, kind, kindOf)
|
||||
for _, run in ipairs(runs or {}) do
|
||||
local runKind = kindOf ~= nil and kindOf(run) or nil
|
||||
-- et kombineret flow (én traktor, tipvogn + pallevogn: "mixed") tager begge slags
|
||||
if isChainRun(run) and contains(run.targetBuildingIds, consumer) and (kindOf == nil or runKind == kind or runKind == "mixed") then return run.id end
|
||||
if isChainRun(run) and contains(ADChainActions.deliversTo(run), consumer) and (kindOf == nil or runKind == kind or runKind == "mixed") then return run.id end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
@@ -170,9 +240,11 @@ end
|
||||
function ADChainActions.mergeIdle(runs, kindOf)
|
||||
local byConsumer, order = {}, {}
|
||||
for _, run in ipairs(runs or {}) do
|
||||
local target = (run.targetBuildingIds or {})[1]
|
||||
if isChainRun(run) and target ~= nil and #(run.targetBuildingIds or {}) == 1 and #(run.vehicleIds or {}) == 0 then
|
||||
local key = kindOf ~= nil and (tostring(target) .. "|" .. tostring(kindOf(run))) or target
|
||||
local consumers = ADChainActions.deliversTo(run)
|
||||
local target = consumers[1]
|
||||
if isChainRun(run) and target ~= nil and #consumers == 1 and #(run.vehicleIds or {}) == 0 then
|
||||
-- forsyning og udkørsel lægges aldrig sammen (forskellige flowtyper)
|
||||
local key = tostring(target) .. "|" .. tostring(run.kind) .. (kindOf ~= nil and ("|" .. tostring(kindOf(run))) or "")
|
||||
if byConsumer[key] == nil then byConsumer[key] = {}; table.insert(order, key) end
|
||||
table.insert(byConsumer[key], run)
|
||||
end
|
||||
@@ -181,14 +253,18 @@ function ADChainActions.mergeIdle(runs, kindOf)
|
||||
for _, target in ipairs(order) do
|
||||
local list = byConsumer[target]
|
||||
if #list > 1 then
|
||||
local keep, add, deleteIds = list[1], {}, {}
|
||||
local keep, add, deleteIds, addSources = list[1], {}, {}, {}
|
||||
for index = 2, #list do
|
||||
for _, name in ipairs(list[index].ingredients or {}) do
|
||||
if not contains(keep.ingredients, name) and not contains(add, name) then table.insert(add, name) end
|
||||
-- palle-flows (udkørsel): de slettede flows' kilder følger med
|
||||
for _, building in ipairs(list[index].sourceBuildingIds or {}) do
|
||||
if not contains(keep.sourceBuildingIds or {}, building) and not contains(addSources, building) then table.insert(addSources, building) end
|
||||
end
|
||||
for _, name in ipairs(ADChainActions.goodsOf(list[index]) or {}) do
|
||||
if not contains(ADChainActions.goodsOf(keep) or {}, name) and not contains(add, name) then table.insert(add, name) end
|
||||
end
|
||||
table.insert(deleteIds, list[index].id)
|
||||
end
|
||||
table.insert(merges, {keepId = keep.id, add = add, deleteIds = deleteIds})
|
||||
table.insert(merges, {keepId = keep.id, add = add, deleteIds = deleteIds, addSources = addSources})
|
||||
end
|
||||
end
|
||||
return merges
|
||||
@@ -213,6 +289,10 @@ function ADChainActions.farmUses(data, runs)
|
||||
if run.kind ~= "outbound" and run.ingredientMode == "manual" then
|
||||
for _, name in ipairs(run.ingredients or {}) do uses[name] = true end
|
||||
end
|
||||
-- kædens palle-flows (udkørsel til en forbruger) kører varen til gårdens egen fabrik
|
||||
if run.kind == "outbound" and run.chain ~= nil and run.chain ~= "" then
|
||||
for _, name in ipairs(ADChainActions.goodsOf(run)) do uses[name] = true end
|
||||
end
|
||||
end
|
||||
return uses
|
||||
end
|
||||
|
||||
@@ -235,14 +235,21 @@ end
|
||||
|
||||
local function createGroupFlow(adEnv, data, group, fillTypes, pool, used)
|
||||
local title = flowTitle(data, fillTypes)
|
||||
local created = ADRunsController.createRun(ADChain.flowName(title, group.consumerName or group.consumer), "supply")
|
||||
local runId = created.id
|
||||
ADRunsController.updateRun(runId, {targetBuildingIds = {group.consumer}, ingredientMode = "manual", ingredients = fillTypes,
|
||||
waitPoolGroup = ADChain.waitPoolFor(ADRunsController.store.runs, group.consumer), chain = group.rootKey})
|
||||
-- updateRun erstatter store'en: slå altid run'et op igen
|
||||
local run = ADRuns.getRun(ADRunsController.store, runId)
|
||||
local fillIndex = data.fillIndex[fillTypes[1]]
|
||||
local pallet = fillIndex ~= nil and ADSources.isPalletOnlyFillType(fillIndex)
|
||||
local waitPool = ADChain.waitPoolFor(ADRunsController.store.runs, group.consumer)
|
||||
-- palle-varer med kendte producenter: udkørselsflow (forsyningen kan ikke hente paller — 20/10 Canola Oil)
|
||||
local sources = pallet and ADChainActions.sourcesFor(group.producers, fillTypes) or {}
|
||||
local created = ADRunsController.createRun(ADChain.flowName(title, group.consumerName or group.consumer), #sources > 0 and "outbound" or "supply")
|
||||
local runId = created.id
|
||||
if #sources > 0 then
|
||||
ADRunsController.updateRun(runId, ADChainActions.palletFlowChanges(group.consumer, fillTypes, sources, group.rootKey, waitPool))
|
||||
else
|
||||
ADRunsController.updateRun(runId, {targetBuildingIds = {group.consumer}, ingredientMode = "manual", ingredients = fillTypes,
|
||||
waitPoolGroup = waitPool, chain = group.rootKey})
|
||||
end
|
||||
-- updateRun erstatter store'en: slå altid run'et op igen
|
||||
local run = ADRuns.getRun(ADRunsController.store, runId)
|
||||
if pool.implements == nil then pool.implements, pool.tractors = collectPool(adEnv) end
|
||||
if pool.blocked == nil then pool.blocked = ADPool.blocked(ADFieldJobs.now or 0) end
|
||||
local pair = ADChainRun.choosePair(pool.implements, pool.tractors, fillIndex, used, pool.blocked, pallet)
|
||||
@@ -256,10 +263,30 @@ local function createGroupFlow(adEnv, data, group, fillTypes, pool, used)
|
||||
startWithPair(adEnv, run, runId, pair, used)
|
||||
end
|
||||
|
||||
-- Nye varer til en bygning, der allerede har et kædeflow: lægges i det flow.
|
||||
local function extendFlow(runId, fillTypes)
|
||||
-- Nye varer til en bygning, der allerede har et kædeflow: lægges i det flow. Et palle-flow (udkørsel) får varerne på
|
||||
-- Lager og producenterne (sources) som kilder.
|
||||
local function extendFlow(runId, fillTypes, sources)
|
||||
local run = ADRuns.getRun(ADRunsController.store, runId)
|
||||
if run == nil then return false end
|
||||
if run.kind == "outbound" then
|
||||
local products, added = {}, {}
|
||||
local have = {}
|
||||
for _, product in ipairs(run.products or {}) do table.insert(products, {fillType = product.fillType, policy = product.policy}); have[product.fillType] = true end
|
||||
for _, name in ipairs(fillTypes) do
|
||||
if not have[name] then have[name] = true; table.insert(products, {fillType = name, policy = "store"}); table.insert(added, name) end
|
||||
end
|
||||
local sourceIds, newSource = {}, false
|
||||
for _, id in ipairs(run.sourceBuildingIds or {}) do table.insert(sourceIds, id) end
|
||||
for _, id in ipairs(sources or {}) do
|
||||
local present = false
|
||||
for _, have2 in ipairs(sourceIds) do if have2 == id then present = true end end
|
||||
if not present then table.insert(sourceIds, id); newSource = true end
|
||||
end
|
||||
if #added == 0 and not newSource then return false end
|
||||
ADRunsController.updateRun(runId, {products = products, sourceBuildingIds = sourceIds})
|
||||
log("flow '%s' får også %s", tostring(run.name), #added > 0 and table.concat(added, ", ") or "flere kilder")
|
||||
return true
|
||||
end
|
||||
local ingredients = {}
|
||||
for _, name in ipairs(run.ingredients or {}) do table.insert(ingredients, name) end
|
||||
local added = {}
|
||||
@@ -281,34 +308,80 @@ local function kindOfFor(data)
|
||||
local index = (data ~= nil and data.fillIndex or {})[name]
|
||||
return index ~= nil and ADSources.isPalletOnlyFillType(index)
|
||||
end
|
||||
return function(run) return ADChainActions.flowKind(run.ingredients, isPalletName) end, isPalletName
|
||||
return function(run) return ADChainActions.flowKind(ADChainActions.goodsOf(run) or run.ingredients, isPalletName) end, isPalletName
|
||||
end
|
||||
|
||||
-- Et kædeflow med traktor gøres klar til at blive delt/lavet om: stoppes (vognen hjem) og traktoren slippes.
|
||||
-- false = lad flowet være (låst sæt, eller stop fejlede — en traktor må ikke køre videre uden flow; review 20/10)
|
||||
local function releaseForRework(adEnv, run)
|
||||
if #(run.vehicleIds or {}) == 0 then return true end
|
||||
-- låst sæt: slå det rigtige flow op (kædens oversigt over flows har ikke alle felter)
|
||||
local full = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if full == nil or full.lockSet == true then return false end
|
||||
if adEnv ~= nil and adEnv.ADGraphManager ~= nil then
|
||||
local ok, err = pcall(ADRunsController.stopRun, adEnv, run.id)
|
||||
if not ok then
|
||||
warn("flow '%s' kunne ikke stoppes til omlægning: %s", tostring(run.name), tostring(err))
|
||||
return false
|
||||
end
|
||||
end
|
||||
for _, vehicleId in ipairs(run.vehicleIds) do
|
||||
ADRunsController.store = ADRuns.unassignVehicle(ADRunsController.store, vehicleId)
|
||||
end
|
||||
local fresh = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if fresh ~= nil then fresh.wagons, fresh.spareWagons, fresh.parkedLoaded = {}, {}, nil end
|
||||
return true
|
||||
end
|
||||
ADChainRun.releaseForRework = releaseForRework
|
||||
|
||||
-- Kædeflows uden traktor med både løsvarer og paller deles i to (brugerønske 18/10 18:34: "så skal den jo tildele 2
|
||||
-- traktorer og vogne"): løsvarerne bliver, palle-varerne får et nyt flow, så hver del får sin egen traktor + vogn.
|
||||
function ADChainRun.splitMixedFlows(adEnv, data, active)
|
||||
-- edges (valgfri): kanternes producenter. Et flow MED traktor deles kun, når palle-varernes producenter kendes (så
|
||||
-- palle-delen kan blive et udkørselsflow) — ellers er det kombinerede flow (tipvogn + pallevogn) det bedste (review 20/10)
|
||||
-- -> kilderne for varerne, og om HVER vare har mindst én kendt producent (flere kanter til samme vare flettes)
|
||||
local function palletSourcesFor(edges, consumer, names)
|
||||
local producers = {}
|
||||
for _, edge in ipairs(edges or {}) do
|
||||
if edge.consumer == consumer then
|
||||
local list = producers[edge.fillType] or {}
|
||||
for _, building in ipairs(edge.producerBuildings or {}) do
|
||||
local present = false
|
||||
for _, have in ipairs(list) do if have == building then present = true end end
|
||||
if not present then table.insert(list, building) end
|
||||
end
|
||||
producers[edge.fillType] = list
|
||||
end
|
||||
end
|
||||
local all = #(names or {}) > 0
|
||||
for _, name in ipairs(names or {}) do
|
||||
if #(producers[name] or {}) == 0 then all = false end
|
||||
end
|
||||
return ADChainActions.sourcesFor(producers, names), all
|
||||
end
|
||||
|
||||
function ADChainRun.splitMixedFlows(adEnv, data, active, edges)
|
||||
local kindOf, isPalletName = kindOfFor(data)
|
||||
local split = 0
|
||||
local pool, used = nil, nil
|
||||
for _, run in ipairs(ADChain.runsView(ADRunsController.store.runs)) do
|
||||
local bulk, pallets = {}, {}
|
||||
local mixed = run.chain ~= nil and run.chain ~= "" and #(run.vehicleIds or {}) == 0 and (active or {})[run.chain]
|
||||
and kindOf(run) == "mixed"
|
||||
local hadVehicles = #(run.vehicleIds or {}) > 0
|
||||
local palletNames = {}
|
||||
for _, name in ipairs(run.ingredients or {}) do if isPalletName(name) then table.insert(palletNames, name) end end
|
||||
-- også med traktor (et kombineret flow fra før 20/10: én traktor, tipvogn + pallevogn): stoppes og slippes først —
|
||||
-- men kun når palle-delen kan blive et udkørselsflow
|
||||
local mixed = run.chain ~= nil and run.chain ~= "" and (active or {})[run.chain] and kindOf(run) == "mixed"
|
||||
and (not hadVehicles or select(2, palletSourcesFor(edges, (run.targetBuildingIds or {})[1], palletNames)))
|
||||
and releaseForRework(adEnv, run)
|
||||
if mixed then
|
||||
-- altid delt: palle-delen bliver et udkørselsflow (convertPalletFlows) — et forsyningsflow kan ikke hente
|
||||
-- paller, heller ikke med en pallevogn som ekstra vogn (20/10)
|
||||
for _, name in ipairs(run.ingredients or {}) do table.insert(isPalletName(name) and pallets or bulk, name) end
|
||||
-- først: én traktor med tipvogn + pallevogn (flowet beholder alle varer)
|
||||
pool = pool or {}
|
||||
used = used or {}
|
||||
local full = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if full ~= nil and data.fillIndex[bulk[1]] ~= nil and staffCombined(adEnv, full, run.id, data.fillIndex[bulk[1]], pool, used, "får traktor") then
|
||||
local fresh = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if fresh ~= nil then fresh.chainIdle = nil end
|
||||
mixed = false
|
||||
split = split + 1
|
||||
end
|
||||
end
|
||||
if mixed then
|
||||
ADRunsController.updateRun(run.id, {ingredients = bulk})
|
||||
-- traktoren blev sluppet: løsvare-delen bemandes igen (staffIdleFlows)
|
||||
local kept = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if kept ~= nil and hadVehicles then kept.stopped, kept.chainIdle = true, true end
|
||||
local consumerName = tostring(run.name or ""):match("→%s*(.+)$") or tostring((run.targetBuildingIds or {})[1])
|
||||
local created = ADRunsController.createRun(ADChain.flowName(flowTitle(data, pallets), consumerName), "supply")
|
||||
ADRunsController.updateRun(created.id, {targetBuildingIds = run.targetBuildingIds, ingredientMode = "manual",
|
||||
@@ -322,10 +395,35 @@ function ADChainRun.splitMixedFlows(adEnv, data, active)
|
||||
return split
|
||||
end
|
||||
|
||||
-- Kædens palle-flows af den gamle slags (forsyning, kunne aldrig hente paller) laves om til udkørselsflows med
|
||||
-- producenterne fra kanterne som kilder. Har flowet en traktor, stoppes det og traktoren slippes først (flowet er
|
||||
-- kædens eget — chain er sat; review 20/10: ellers stod "Kæde: Canola Oil" ødelagt og "ok" i fanen). Det bemandes
|
||||
-- igen med en pallevogn (staffIdleFlows). -> antal lavet om
|
||||
-- active (valgfri): kun flows i aktive kæder (et pauset/slået-fra flow stoppes ikke — review 20/10)
|
||||
function ADChainRun.convertPalletFlows(adEnv, data, edges, active)
|
||||
local kindOf = kindOfFor(data)
|
||||
local converted = 0
|
||||
for _, run in ipairs(ADChain.runsView(ADRunsController.store.runs)) do
|
||||
local consumer = (run.targetBuildingIds or {})[1]
|
||||
if run.kind == "supply" and run.chain ~= nil and run.chain ~= "" and run.ingredientMode == "manual" and consumer ~= nil
|
||||
and (active == nil or active[run.chain]) and kindOf(run) == "pallet" then
|
||||
local sources, allKnown = palletSourcesFor(edges, consumer, run.ingredients)
|
||||
if allKnown and releaseForRework(adEnv, run) then
|
||||
ADRunsController.updateRun(run.id, ADChainActions.palletFlowChanges(consumer, run.ingredients, sources, run.chain, run.waitPoolGroup))
|
||||
local fresh = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if fresh ~= nil then fresh.stopped, fresh.chainIdle, fresh.wagons, fresh.spareWagons = true, true, {}, {} end
|
||||
log("flow '%s' er nu et udkørselsflow fra %d producent(er): palle-varer hentes ved pallepladserne (bemandes igen med en pallevogn)", tostring(run.name), #sources)
|
||||
converted = converted + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return converted
|
||||
end
|
||||
|
||||
function ADChainRun.mergeIdleFlows(adEnv, data)
|
||||
local merged = 0
|
||||
for _, merge in ipairs(ADChainActions.mergeIdle(ADChain.runsView(ADRunsController.store.runs), (kindOfFor(data)))) do
|
||||
if #merge.add > 0 then extendFlow(merge.keepId, merge.add) end
|
||||
if #merge.add > 0 or #(merge.addSources or {}) > 0 then extendFlow(merge.keepId, merge.add, merge.addSources) end
|
||||
for _, id in ipairs(merge.deleteIds) do
|
||||
local ok, err = pcall(ADRunsController.deleteRun, id, adEnv)
|
||||
if ok then
|
||||
@@ -353,7 +451,7 @@ function ADChainRun.staffableFlows(runs, fillIndex, isPalletOnly, opts)
|
||||
if run.chain ~= nil and run.chain ~= "" and #(run.vehicleIds or {}) == 0 and active[run.chain]
|
||||
and not paused[run.chain] and run.chainIdle == true then
|
||||
local bulk, pallet = nil, nil
|
||||
for _, name in ipairs(run.ingredients or {}) do
|
||||
for _, name in ipairs(ADChainActions.goodsOf(run) or run.ingredients or {}) do
|
||||
local index = (fillIndex or {})[name]
|
||||
if index ~= nil and isPalletOnly(index) then pallet = pallet or index
|
||||
elseif index ~= nil then bulk = bulk or index end
|
||||
@@ -470,8 +568,10 @@ function ADChainRun.createFlows(adEnv, data, edges)
|
||||
end
|
||||
local kindOf = kindOfFor(data)
|
||||
local ok, err = pcall(function()
|
||||
-- begge slags og intet kædeflow til bygningen endnu: helst ét flow med én traktor (tipvogn + pallevogn)
|
||||
if #bulk > 0 and #pallets > 0 and ADChainActions.chainRunFor(runs, group.consumer, "bulk", kindOf) == nil
|
||||
-- begge slags og intet kædeflow til bygningen endnu: helst ét flow med én traktor (tipvogn + pallevogn) —
|
||||
-- kun når paller ikke kan få et udkørselsflow (ukendte producenter)
|
||||
local palletSources = ADChainActions.sourcesFor(group.producers, pallets)
|
||||
if #bulk > 0 and #pallets > 0 and #palletSources == 0 and ADChainActions.chainRunFor(runs, group.consumer, "bulk", kindOf) == nil
|
||||
and ADChainActions.chainRunFor(runs, group.consumer, "pallet", kindOf) == nil
|
||||
and createCombinedFlow(adEnv, data, group, bulk, pallets, pool, used) then
|
||||
count = count + 1
|
||||
@@ -482,7 +582,8 @@ function ADChainRun.createFlows(adEnv, data, edges)
|
||||
if #part.goods > 0 then
|
||||
local existing = ADChainActions.chainRunFor(runs, group.consumer, part.kind, kindOf)
|
||||
if existing ~= nil then
|
||||
if extendFlow(existing, part.goods) then count = count + 1 end
|
||||
local sources = part.kind == "pallet" and ADChainActions.sourcesFor(group.producers, part.goods) or nil
|
||||
if extendFlow(existing, part.goods, sources) then count = count + 1 end
|
||||
else
|
||||
createGroupFlow(adEnv, data, group, part.goods, pool, used)
|
||||
count = count + 1
|
||||
@@ -633,11 +734,17 @@ function ADChainRun.apply(adEnv, data, result)
|
||||
-- blandede flows deles kun i aktive kæder og aldrig på delvise data (som bemandingen)
|
||||
local okSplit, splitCount = true, 0
|
||||
if not data.partial then
|
||||
okSplit, splitCount = pcall(ADChainRun.splitMixedFlows, adEnv, data, ADChain.activeRoots(result.chain, ADChain.state.paused))
|
||||
okSplit, splitCount = pcall(ADChainRun.splitMixedFlows, adEnv, data, ADChain.activeRoots(result.chain, ADChain.state.paused), result.edges)
|
||||
if not okSplit then warn("deling af blandede kædeflows fejlede: %s", tostring(splitCount)) end
|
||||
end
|
||||
local okMerge, mergedCount = pcall(ADChainRun.mergeIdleFlows, adEnv, data)
|
||||
if not okMerge then warn("sammenlægning af kædeflows fejlede: %s", tostring(mergedCount)) end
|
||||
-- gamle palle-flows (forsyning) -> udkørsel; aldrig på delvise data
|
||||
local okConvert, convertCount = true, 0
|
||||
if not data.partial then
|
||||
okConvert, convertCount = pcall(ADChainRun.convertPalletFlows, adEnv, data, result.edges, ADChain.activeRoots(result.chain, ADChain.state.paused))
|
||||
if not okConvert then warn("palle-flows kunne ikke laves om: %s", tostring(convertCount)) end
|
||||
end
|
||||
local okNew, created = pcall(ADChainRun.createFlows, adEnv, data, result.edges)
|
||||
-- tomme kædeflows bemandes kun i aktive kæder og aldrig på delvise data (en ulæselig rod ligner en slået-fra)
|
||||
local okStaff, staffed = true, 0
|
||||
@@ -651,7 +758,7 @@ function ADChainRun.apply(adEnv, data, result)
|
||||
if not okKeep then warn("mellemvarer fejlede: %s", tostring(keepErr)) end
|
||||
if not okNew then warn("nye flows fejlede: %s", tostring(created)) end
|
||||
-- ændringer tælles for sig (review: fejlede createFlows, blev deling/sammenlægning ikke gemt)
|
||||
local changed = (okNew and created or 0) + (okMerge and mergedCount or 0) + (okSplit and splitCount or 0)
|
||||
local changed = (okNew and created or 0) + (okMerge and mergedCount or 0) + (okSplit and splitCount or 0) + (okConvert and convertCount or 0)
|
||||
-- delvise data: en rod der ikke kunne læses, må ikke få sine flows stoppet
|
||||
local okStop, stopped = true, 0
|
||||
if not data.partial then
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.400.0</version>
|
||||
<version>1.62.401.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
<de>AD Smart Pickup</de>
|
||||
|
||||
Reference in New Issue
Block a user