feat: én traktor, flere vogne i samme flow — skifter vogn mellem ture; kæden laver kombinerede flows (1.62.337)
Brugerønske 18/10 18:36: færre traktorer. spareWagons pr. traktor, ADWagonSwap vurderer vognene før hver tur og bruger flowets vognbytte.
This commit is contained in:
@@ -134,6 +134,16 @@ function ADFlowSleep.swapTractor(run, oldId, newId)
|
||||
return ids, wagons
|
||||
end
|
||||
|
||||
-- Ekstra vogne flyttes fra den gamle traktor til den nye. -> ny tabel
|
||||
function ADFlowSleep.swapSpares(spares, oldId, newId)
|
||||
local copy = ADRuns.copySpares(spares)
|
||||
if oldId ~= newId and copy[oldId] ~= nil then
|
||||
copy[newId] = copy[oldId]
|
||||
copy[oldId] = nil
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
-- Arbejdstjekket fejlede: én fejl mere -> ny tæller, vækkes nu? Et tjek der altid fejler må ikke efterlade flowet
|
||||
-- sovende for altid, men én fejl må heller ikke vække det (ellers vågner og sover det hvert 11. minut).
|
||||
function ADFlowSleep.onCheckError(failures)
|
||||
@@ -270,14 +280,32 @@ function ADFlowSleep.hasWork(adEnv, run, byId, onlyTractorId)
|
||||
return true, string.format("%s til %s, vogn '%s'", table.concat(trip.names or {}, "+"),
|
||||
tostring(trip.targetName or "?"), tostring(ADRuns.vehicleLabel(cargo)))
|
||||
end
|
||||
local ingredients = ADRunsController.getRunIngredients(adEnv, run, cargo)
|
||||
for _, targetId in ipairs(ADRunsController.getRunTargets(run)) do
|
||||
local choice = ADSmartPickup.findSupplyPickup(adEnv, cargo, ingredients, targetId)
|
||||
if choice ~= nil then
|
||||
local name = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(choice.fillType) or tostring(choice.fillType)
|
||||
return true, string.format("hent %s ved %s (%.0f l der, mål mangler %.0f l), vogn '%s'", tostring(name),
|
||||
tostring(choice.markerName), choice.level or -1, choice.need ~= nil and choice.need.freeSpace or -1,
|
||||
tostring(ADRuns.vehicleLabel(cargo))), choice, targetId
|
||||
-- den aktive vogn først, så traktorernes ekstra vogne (ADWagonSwap: én traktor, flere vogne) — har en af dem en
|
||||
-- tur, har flowet arbejde (traktoren skifter vogn ved start)
|
||||
local cargos = {cargo}
|
||||
for tractorId, list in pairs(run.spareWagons or {}) do
|
||||
if onlyTractorId == nil or tractorId == onlyTractorId then
|
||||
for _, wagonId in ipairs(list) do
|
||||
local spare = findVehicle(wagonId)
|
||||
-- kun en vogn traktoren faktisk kan hente (ikke udlånt, reserveret eller uden Connect — review)
|
||||
if spare ~= nil and spare ~= cargo and (ADWagonSwap == nil or ADWagonSwap.isFetchable(adEnv, spare, wagonId)) then
|
||||
table.insert(cargos, spare)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for index, candidate in ipairs(cargos) do
|
||||
local ingredients = ADRunsController.getRunIngredients(adEnv, run, candidate)
|
||||
if index > 1 and ADWagonSwap ~= nil then ingredients = ADWagonSwap.goodsFor(candidate, ingredients) end
|
||||
for _, targetId in ipairs(ADRunsController.getRunTargets(run)) do
|
||||
local choice = index == 1 and ADSmartPickup.findSupplyPickup(adEnv, candidate, ingredients, targetId)
|
||||
or ADSmartPickup.probeSupplyPickup(adEnv, candidate, ingredients, targetId)
|
||||
if choice ~= nil then
|
||||
local name = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(choice.fillType) or tostring(choice.fillType)
|
||||
return true, string.format("hent %s ved %s (%.0f l der, mål mangler %.0f l), vogn '%s'", tostring(name),
|
||||
tostring(choice.markerName), choice.level or -1, choice.need ~= nil and choice.need.freeSpace or -1,
|
||||
tostring(ADRuns.vehicleLabel(candidate))), choice, targetId
|
||||
end
|
||||
end
|
||||
end
|
||||
return false, nil
|
||||
@@ -382,6 +410,8 @@ local function wake(adEnv, run, byId, why)
|
||||
bestFit = function(list, implement) return ADPool.bestFit(list, implement, "unloader") end})
|
||||
if chosen ~= nil and chosen.id ~= tractorId then
|
||||
run.vehicleIds, run.wagons = ADFlowSleep.swapTractor(run, tractorId, chosen.id)
|
||||
-- ekstra vogne følger med til den nye traktor (ADWagonSwap)
|
||||
run.spareWagons = ADFlowSleep.swapSpares(run.spareWagons, tractorId, chosen.id)
|
||||
taken[chosen.id] = true
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s': '%s' er optaget — '%s' tager turen", tostring(run.name),
|
||||
own ~= nil and tostring(ADRuns.vehicleLabel(own)) or tostring(tractorId), tostring(chosen.name or chosen.id))
|
||||
|
||||
Reference in New Issue
Block a user