feat: dvale for flows uden arbejde — traktor og vogn frigives, flowet vågner selv (v1.62.58)
This commit is contained in:
@@ -257,7 +257,7 @@ function ADChain.flowStatus(edges, runs, noVehicle)
|
||||
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 not run.stopped then status = "ok"; break end
|
||||
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"
|
||||
elseif reason then status = "noVehicle"
|
||||
@@ -274,7 +274,7 @@ function ADChain.runsView(runs)
|
||||
local list = {}
|
||||
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,
|
||||
ingredientMode = run.ingredientMode, ingredients = run.ingredients, stopped = run.stopped == true and not run.sleeping,
|
||||
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 {}})
|
||||
|
||||
@@ -478,7 +478,7 @@ end
|
||||
function ADChainData.acceptsMap(data, flows, goods)
|
||||
local result = {}
|
||||
for _, flow in ipairs(flows or {}) do
|
||||
if flow.kind ~= "outbound" and not flow.stopped and flow.ingredientMode ~= "manual" then
|
||||
if flow.kind ~= "outbound" and (not flow.stopped or flow.sleeping) and flow.ingredientMode ~= "manual" then
|
||||
for _, id in ipairs(flow.targetBuildingIds or {}) do
|
||||
local placeable = data.placeables[id]
|
||||
if result[id] == nil and placeable ~= nil then
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
-- AD Flow Sleep
|
||||
-- Dvale for flows: har alle et flows traktorer holdt ved Wait uden noget at lave i SLEEP_AFTER_MS (tomme, med vogn
|
||||
-- bagpå), stoppes flowet som med Stop-knappen — vognen sættes på sin parkering og traktoren kører hjem, så begge er
|
||||
-- ledige for maskinpuljen/markarbejdet — og markeres run.sleeping. Hvert WAKE_CHECK_MS spørges flowets planlægning
|
||||
-- (udkørsel: ADOutboundPlanner; forsyning: ADSmartPickup.findSupplyPickup) med den parkerede vogn som "køretøj", om
|
||||
-- der er en tur. Så vækkes flowet: er traktoren lånt ud, tager den nærmeste ledige traktor der kan trække vognen
|
||||
-- dens plads. Lastbiler med eget lad sover aldrig (intet at frigive). Spilleren der trykker Start/Stop sletter dvalen.
|
||||
-- Ren logik øverst (testes med luajit), spil-adapter nederst.
|
||||
|
||||
ADFlowSleep = {}
|
||||
ADFlowSleep.LOG_PREFIX = "ADSmartPickup: dvale: "
|
||||
ADFlowSleep.SLEEP_AFTER_MS = 10 * 60 * 1000 -- tomgang så længe før flowet sover
|
||||
ADFlowSleep.WAKE_CHECK_MS = 60 * 1000 -- så tit et sovende flow tjekkes for arbejde
|
||||
ADFlowSleep.TICK_MS = 1000
|
||||
ADFlowSleep.MIN_CARGO_LITERS = 1 -- mindre end dette på vognen = tom
|
||||
ADFlowSleep.MAX_CHECK_FAILURES = 3 -- arbejdstjek der fejler så mange gange i træk vækker flowet alligevel
|
||||
|
||||
-- ---- ren logik ----
|
||||
|
||||
-- s = {stopped, vehicles = {{holding, hasWagon, cargo} | false}} (false = traktoren findes ikke) -> tomgang?
|
||||
function ADFlowSleep.isIdle(s)
|
||||
if s.stopped or #(s.vehicles or {}) == 0 then return false end
|
||||
for _, vehicle in ipairs(s.vehicles) do
|
||||
if not vehicle or not vehicle.holding or not vehicle.hasWagon or (vehicle.cargo or 0) >= ADFlowSleep.MIN_CARGO_LITERS then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- Tomgangsuret: starter ved første tomgang, nulstilles (nil) så snart flowet laver noget.
|
||||
function ADFlowSleep.track(since, isIdle, nowMs)
|
||||
if not isIdle then return nil end
|
||||
return since or nowMs
|
||||
end
|
||||
|
||||
function ADFlowSleep.shouldSleep(since, nowMs)
|
||||
return since ~= nil and nowMs - since >= ADFlowSleep.SLEEP_AFTER_MS
|
||||
end
|
||||
|
||||
function ADFlowSleep.isCheckDue(lastCheck, nowMs)
|
||||
return lastCheck == nil or nowMs - lastCheck >= ADFlowSleep.WAKE_CHECK_MS
|
||||
end
|
||||
|
||||
local function nearest(list, x, z)
|
||||
local best, bestDistance = nil, math.huge
|
||||
for _, item in ipairs(list or {}) do
|
||||
local d = ((item.x or 0) - (x or 0)) ^ 2 + ((item.z or 0) - (z or 0)) ^ 2
|
||||
if d < bestDistance then best, bestDistance = item, d end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
-- Traktor ved opvågning. s = {own, ownFree, candidates, wagon = {x, z, neededHp}, bestFit?(candidates, wagon)}:
|
||||
-- egen hvis ledig; ellers bedste ledige (bestFit, ellers nærmeste vognen); ellers egen (startes og venter på den).
|
||||
function ADFlowSleep.chooseTractor(s)
|
||||
if s.own ~= nil and s.ownFree then return s.own end
|
||||
local wagon = s.wagon or {}
|
||||
local other = nil
|
||||
if #(s.candidates or {}) > 0 then
|
||||
other = s.bestFit ~= nil and s.bestFit(s.candidates, wagon) or nearest(s.candidates, wagon.x, wagon.z)
|
||||
end
|
||||
return other or s.own
|
||||
end
|
||||
|
||||
-- Ny vehicleIds-liste og vogntabel hvor newId tager oldId's plads og vogn. Originalen røres ikke.
|
||||
function ADFlowSleep.swapTractor(run, oldId, newId)
|
||||
local ids, wagons = {}, {}
|
||||
for _, id in ipairs(run.vehicleIds or {}) do table.insert(ids, id == oldId and newId or id) end
|
||||
for tractorId, wagonId in pairs(run.wagons or {}) do wagons[tractorId] = wagonId end
|
||||
if oldId ~= newId then
|
||||
wagons[newId] = wagons[oldId]
|
||||
wagons[oldId] = nil
|
||||
end
|
||||
return ids, wagons
|
||||
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)
|
||||
local count = (failures or 0) + 1
|
||||
return count, count >= ADFlowSleep.MAX_CHECK_FAILURES
|
||||
end
|
||||
|
||||
-- Fik opvågningen mindst én traktor i gang? results = ADRunsController.startRun's poster {ok, reason}.
|
||||
function ADFlowSleep.anyStarted(results)
|
||||
for _, result in ipairs(results or {}) do
|
||||
if result.ok then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Flowets egen hjemtur efter dvale (tømmer/kører hjem) — traktoren er ikke lånt ud, den skal bare bruges igen.
|
||||
function ADFlowSleep.isOwnTrip(wagonStatus)
|
||||
return wagonStatus == "homing" or wagonStatus == "emptying"
|
||||
end
|
||||
|
||||
-- ---- spil-adapter ----
|
||||
|
||||
local idleSince = {} -- runId -> ms
|
||||
local lastCheck = {} -- runId -> ms
|
||||
local checkFailures = {} -- runId -> fejlede arbejdstjek i træk
|
||||
local loggedErrors = {}
|
||||
local timerMs = 0
|
||||
|
||||
local function nowMs()
|
||||
if g_currentMission ~= nil and type(g_currentMission.time) == "number" then return g_currentMission.time end
|
||||
return os.clock() * 1000
|
||||
end
|
||||
|
||||
local function logOnce(key, text)
|
||||
if loggedErrors[key] then return end
|
||||
loggedErrors[key] = true
|
||||
Logging.warning(ADFlowSleep.LOG_PREFIX .. "%s", tostring(text))
|
||||
end
|
||||
|
||||
-- Alle køretøjer (også frakoblede vogne, som ikke står i AutoDrives liste).
|
||||
local function findVehicle(id)
|
||||
if id == nil then return nil end
|
||||
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||
if ADRunsController.getVehicleId(vehicle) == id then return vehicle end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function cargoOf(adEnv, vehicle)
|
||||
local autoDrive = adEnv.AutoDrive
|
||||
if autoDrive == nil or autoDrive.getAllUnits == nil or autoDrive.getAllFillLevels == nil then return 0 end
|
||||
local level = autoDrive.getAllFillLevels(autoDrive.getAllUnits(vehicle))
|
||||
return type(level) == "number" and level or 0
|
||||
end
|
||||
|
||||
local function hasCargoWagon(vehicle)
|
||||
for _, implement in ipairs(ADHitch.rearImplementsOf(vehicle)) do
|
||||
local object = implement.object
|
||||
if object ~= nil and (object.spec_fillUnit ~= nil or object.spec_trailer ~= nil) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function vehicleState(adEnv, vehicle)
|
||||
local held = ADOutbound ~= nil and ADOutbound.getHoldFor ~= nil and ADOutbound.getHoldFor(vehicle) ~= nil
|
||||
-- venter med rest-last ved et fuldt mål (ADUnloadWait) er ikke tomgang
|
||||
local waitingWithLoad = ADUnloadWait ~= nil and ADUnloadWait.getWaitFor ~= nil and ADUnloadWait.getWaitFor(vehicle) ~= nil
|
||||
return {holding = held and not waitingWithLoad, hasWagon = hasCargoWagon(vehicle), cargo = cargoOf(adEnv, vehicle)}
|
||||
end
|
||||
|
||||
-- Vognen (eller lastbilen selv) som planlægningen kan regne med: kapacitet og varer den kan bære.
|
||||
local function cargoVehicleOf(run, byId)
|
||||
for _, tractorId in ipairs(run.vehicleIds or {}) do
|
||||
local wagon = findVehicle((run.wagons or {})[tractorId])
|
||||
if wagon ~= nil then return wagon end
|
||||
if byId[tractorId] ~= nil and hasCargoWagon(byId[tractorId]) then return byId[tractorId] end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Har det sovende flow en tur nu? -> bool, begrundelse
|
||||
function ADFlowSleep.hasWork(adEnv, run, byId)
|
||||
local cargo = cargoVehicleOf(run, byId)
|
||||
if cargo == nil then return true, "ingen vogn at regne med" end
|
||||
if run.kind == "outbound" then
|
||||
local trip = ADOutboundPlanner.plan(ADOutbound.buildPlanInput(adEnv, run, cargo))
|
||||
return trip ~= nil, trip ~= nil and tostring(trip.targetName or "tur") or nil
|
||||
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 return true, string.format("hent ved %s", tostring(choice.markerName)) end
|
||||
end
|
||||
return false, nil
|
||||
end
|
||||
|
||||
local function positionOf(vehicle)
|
||||
if vehicle == nil or vehicle.rootNode == nil then return nil, nil end
|
||||
local x, _, z = getWorldTranslation(vehicle.rootNode)
|
||||
return x, z
|
||||
end
|
||||
|
||||
local function isOwnFree(vehicle, tractorId)
|
||||
if vehicle == nil then return false end
|
||||
-- egen hjemtur efter dvalen: startVehicle afbryder den (ADFlowWagons.abortHomeTripOnStart)
|
||||
if ADFlowWagons ~= nil and ADFlowWagons.statusOf ~= nil and ADFlowSleep.isOwnTrip(ADFlowWagons.statusOf(vehicle)) then return true end
|
||||
if ADPool ~= nil and ADPool.isFreeFromFlows ~= nil and not ADPool.isFreeFromFlows(vehicle) then return false end
|
||||
if ADFieldWork ~= nil and ADFieldWork.isBusyVehicle ~= nil and ADFieldWork.isBusyVehicle(vehicle, tractorId) then return false end
|
||||
return not (ADFlowWagons ~= nil and ADFlowWagons.isPoolBusy ~= nil and ADFlowWagons.isPoolBusy(vehicle, tractorId))
|
||||
end
|
||||
|
||||
-- Ledige puljetraktorer der ikke hører til noget flow (heller ikke et sovende/stoppet) og ikke er reserveret.
|
||||
local function freeTractors(adEnv, taken)
|
||||
local _, tractors = ADPool.collect(adEnv, function(vehicle) return ADFieldWork.isBusyVehicle(vehicle, ADRunsController.getVehicleId(vehicle)) end)
|
||||
local blocked = ADPool.blocked(nowMs())
|
||||
local result = {}
|
||||
for _, tractor in ipairs(tractors or {}) do
|
||||
if not blocked[tractor.id] and not taken[tractor.id] and not tractor.offNetwork
|
||||
and ADRunsController.getRunForVehicle(tractor.vehicle) == nil then
|
||||
table.insert(result, tractor)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function wake(adEnv, run, byId, why)
|
||||
run.sleeping = nil
|
||||
local taken = {}
|
||||
for _, tractorId in ipairs(run.vehicleIds or {}) do
|
||||
local own = byId[tractorId]
|
||||
if not isOwnFree(own, tractorId) then
|
||||
local wagon = findVehicle((run.wagons or {})[tractorId])
|
||||
local x, z = positionOf(wagon or own)
|
||||
local okHp, neededHp = pcall(ADPool.readNeededHp, wagon)
|
||||
local okFree, candidates = pcall(freeTractors, adEnv, taken)
|
||||
local chosen = ADFlowSleep.chooseTractor({own = own ~= nil and {id = tractorId} or nil, ownFree = false,
|
||||
candidates = okFree and candidates or {}, wagon = {x = x, z = z, neededHp = okHp and neededHp or nil},
|
||||
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)
|
||||
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))
|
||||
end
|
||||
end
|
||||
end
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s' vågner (%s)", tostring(run.name), tostring(why or "arbejde"))
|
||||
local results = ADRunsController.startRun(adEnv, run.id)
|
||||
if not ADFlowSleep.anyStarted(results) then
|
||||
-- ingen traktor kunne starte (fx ugyldig markør): tilbage i dvale, ellers står flowet "tændt" uden at køre
|
||||
local reasons = {}
|
||||
for _, result in ipairs(results or {}) do table.insert(reasons, tostring(result.reason)) end
|
||||
ADRunsController.stopRun(adEnv, run.id)
|
||||
run.sleeping = true
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s' kunne ikke starte (%s) — sover videre", tostring(run.name), table.concat(reasons, ", "))
|
||||
end
|
||||
end
|
||||
|
||||
local function sleep(adEnv, run)
|
||||
ADRunsController.stopRun(adEnv, run.id)
|
||||
run.sleeping = true
|
||||
idleSince[run.id] = nil
|
||||
lastCheck[run.id] = nowMs()
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s' sover — intet at lave i %d min; traktor og vogn er ledige til andet",
|
||||
tostring(run.name), math.floor(ADFlowSleep.SLEEP_AFTER_MS / 60000))
|
||||
end
|
||||
|
||||
local function farmVehiclesById(adEnv)
|
||||
local byId = {}
|
||||
for _, vehicle in ipairs(ADRunsController.getFarmVehicles(adEnv)) do
|
||||
local id = ADRunsController.getVehicleId(vehicle)
|
||||
if id ~= nil then byId[id] = vehicle end
|
||||
end
|
||||
return byId
|
||||
end
|
||||
|
||||
local function tickRun(adEnv, run, byId, now)
|
||||
if run.sleeping and run.stopped then
|
||||
if not ADFlowSleep.isCheckDue(lastCheck[run.id], now) then return end
|
||||
lastCheck[run.id] = now
|
||||
local ok, hasWork, why = pcall(ADFlowSleep.hasWork, adEnv, run, byId)
|
||||
if ok then
|
||||
checkFailures[run.id] = nil
|
||||
else
|
||||
logOnce("hasWork:" .. tostring(run.id), string.format("'%s': arbejdstjek fejlede: %s", tostring(run.name), tostring(hasWork)))
|
||||
local wakeNow
|
||||
checkFailures[run.id], wakeNow = ADFlowSleep.onCheckError(checkFailures[run.id])
|
||||
hasWork, why = wakeNow, "arbejdstjekket fejlede " .. tostring(checkFailures[run.id]) .. " gange"
|
||||
if wakeNow then checkFailures[run.id] = nil end
|
||||
end
|
||||
if hasWork then wake(adEnv, run, byId, why) end
|
||||
return
|
||||
end
|
||||
-- startet af spilleren (fx "Start alle") mens det sov
|
||||
if run.sleeping and not run.stopped then run.sleeping = nil end
|
||||
local vehicles = {}
|
||||
for index, id in ipairs(run.vehicleIds or {}) do
|
||||
local vehicle = byId[id]
|
||||
vehicles[index] = vehicle ~= nil and vehicleState(adEnv, vehicle) or false
|
||||
end
|
||||
idleSince[run.id] = ADFlowSleep.track(idleSince[run.id], ADFlowSleep.isIdle({stopped = run.stopped, vehicles = vehicles}), now)
|
||||
if ADFlowSleep.shouldSleep(idleSince[run.id], now) then sleep(adEnv, run) end
|
||||
end
|
||||
|
||||
function ADFlowSleep.tick(adEnv, dt)
|
||||
timerMs = timerMs + (dt or 0)
|
||||
if timerMs < ADFlowSleep.TICK_MS then return end
|
||||
timerMs = 0
|
||||
if adEnv == nil or ADRunsController == nil or ADRunsController.store == nil then return end
|
||||
local byId = farmVehiclesById(adEnv)
|
||||
local now = nowMs()
|
||||
for _, run in ipairs(ADRunsController.store.runs or {}) do
|
||||
local ok, err = pcall(tickRun, adEnv, run, byId, now)
|
||||
if not ok then logOnce("tick:" .. tostring(run.id), string.format("'%s': %s", tostring(run.name), tostring(err))) end
|
||||
end
|
||||
end
|
||||
@@ -271,7 +271,7 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle)
|
||||
local farmId = ADSmartPickup.getFarmId(vehicle)
|
||||
local capacity, hasAutoload = getVehicleCapacity(adEnv, vehicle)
|
||||
local carriable = {}
|
||||
for _, fillType in ipairs(adEnv.AutoDrive.getSupportedFillTypesOfAllUnitsAlphabetically(vehicle) or {}) do
|
||||
for _, fillType in ipairs(ADRunsController.getCarriableFillTypes(adEnv, vehicle)) do
|
||||
carriable[fillType] = true
|
||||
end
|
||||
local sources, sourcesById = {}, {}
|
||||
|
||||
@@ -96,6 +96,7 @@ local function copyRun(run)
|
||||
returnBelowPercent = run.returnBelowPercent,
|
||||
vehicleIds = copyList(run.vehicleIds),
|
||||
stopped = run.stopped == true,
|
||||
sleeping = run.sleeping == true or nil, -- stoppet af dvale (ADFlowSleep), vækkes når der er arbejde
|
||||
wagons = ADRuns.copyWagons(run.wagons),
|
||||
chain = run.chain or "",
|
||||
}
|
||||
@@ -443,6 +444,7 @@ function ADRuns.toRecords(store)
|
||||
sellAbove = run.sellAbovePercent or 0,
|
||||
collectRound = run.collectRound and 1 or 0,
|
||||
stopped = run.stopped and 1 or 0,
|
||||
sleeping = run.sleeping and 1 or 0,
|
||||
wagons = ADRuns.serializeWagons(run.wagons),
|
||||
chain = run.chain or "",
|
||||
}
|
||||
@@ -498,6 +500,7 @@ function ADRuns.fromRecords(records)
|
||||
returnBelowPercent = clampPercent(record.returnBelow),
|
||||
vehicleIds = copyList(record.vehicleIds),
|
||||
stopped = tonumber(record.stopped) == 1,
|
||||
sleeping = tonumber(record.sleeping) == 1 or nil,
|
||||
wagons = ADRuns.parseWagons(record.wagons),
|
||||
chain = record.chain or "",
|
||||
})
|
||||
|
||||
@@ -266,10 +266,30 @@ end
|
||||
|
||||
-- ---- varer ----
|
||||
|
||||
-- Varer køretøjet kan bære. En frakoblet vogn (dvale-tjekket regner med flowets parkerede vogn) har ingen AutoDrive-
|
||||
-- tilstand (.ad), og så giver AD's opslag en tom liste for alt andet end autoload-vogne — læs vognens egne fyldenheder.
|
||||
function ADRunsController.getCarriableFillTypes(adEnv, vehicle)
|
||||
if vehicle ~= nil and vehicle.ad == nil and vehicle.getFillUnits ~= nil then
|
||||
return ADRunsController.fillTypesOfUnits(vehicle)
|
||||
end
|
||||
return adEnv.AutoDrive.getSupportedFillTypesOfAllUnitsAlphabetically(vehicle) or {}
|
||||
end
|
||||
|
||||
-- Alle varer køretøjets fyldenheder tager, sorteret efter indeks (uden dubletter).
|
||||
function ADRunsController.fillTypesOfUnits(vehicle)
|
||||
local seen, result = {}, {}
|
||||
for index in ipairs(vehicle:getFillUnits() or {}) do
|
||||
for fillType, supported in pairs(vehicle:getFillUnitSupportedFillTypes(index) or {}) do
|
||||
if supported and not seen[fillType] then
|
||||
seen[fillType] = true
|
||||
table.insert(result, fillType)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(result)
|
||||
return result
|
||||
end
|
||||
|
||||
-- Auto-listen: det vognen kan bære, som målet også tager. Er målet en fabrik, indsnævrer
|
||||
-- findSupplyPickup selv til de ønskede produktioners inputs bagefter.
|
||||
-- Run'ets mål som liste (flere stalde pr. run); gamle runs har kun targetWayPointId.
|
||||
@@ -1109,6 +1129,7 @@ function ADRunsController.startRun(adEnv, runId)
|
||||
return results
|
||||
end
|
||||
run.stopped = false
|
||||
run.sleeping = nil -- Start (spilleren eller opvågning): ikke længere i dvale
|
||||
local vehiclesById = getFarmVehiclesById(adEnv)
|
||||
for _, vehicleId in ipairs(run.vehicleIds) do
|
||||
local vehicle = vehiclesById[vehicleId]
|
||||
@@ -1260,6 +1281,7 @@ function ADRunsController.stopRun(adEnv, runId)
|
||||
if run == nil then
|
||||
return stopped
|
||||
end
|
||||
run.sleeping = nil -- Stop fra spilleren aflyser dvalen (ADFlowSleep sætter den igen efter sit eget stop)
|
||||
-- allerede stoppet: traktorerne kan være lånt ud af maskinpuljen — de må ikke trækkes væk midt i et job
|
||||
if run.stopped then
|
||||
ADRunsController.runningRuns[runId] = nil
|
||||
|
||||
@@ -50,6 +50,7 @@ function ADRunsStorage.writeRecords(xmlFile, records)
|
||||
xmlFile:setInt(key .. "#collectRound", record.collectRound or 0)
|
||||
-- maskinpulje: flowet stoppet + husket vogn pr. traktor
|
||||
xmlFile:setInt(key .. "#stopped", record.stopped or 0)
|
||||
xmlFile:setInt(key .. "#sleeping", record.sleeping or 0)
|
||||
xmlFile:setString(key .. "#wagons", record.wagons or "")
|
||||
xmlFile:setString(key .. "#chain", record.chain or "")
|
||||
for vehicleIndex, vehicleId in ipairs(record.vehicleIds) do
|
||||
@@ -82,6 +83,7 @@ function ADRunsStorage.readRecords(xmlFile)
|
||||
sellAbove = xmlFile:getInt(key .. "#sellAbove"),
|
||||
collectRound = xmlFile:getInt(key .. "#collectRound"),
|
||||
stopped = xmlFile:getInt(key .. "#stopped"),
|
||||
sleeping = xmlFile:getInt(key .. "#sleeping"),
|
||||
wagons = xmlFile:getString(key .. "#wagons"),
|
||||
chain = xmlFile:getString(key .. "#chain"),
|
||||
vehicleIds = {},
|
||||
|
||||
@@ -474,7 +474,7 @@ local function getProductionDemand(adEnv, station, driver)
|
||||
return {}
|
||||
end
|
||||
local canCarry = {}
|
||||
for _, fillType in ipairs(adEnv.AutoDrive.getSupportedFillTypesOfAllUnitsAlphabetically(driver) or {}) do
|
||||
for _, fillType in ipairs(ADRunsController.getCarriableFillTypes(adEnv, driver)) do
|
||||
canCarry[fillType] = true
|
||||
end
|
||||
local missingInputs = ProductionPoint ~= nil and ProductionPoint.PROD_STATUS ~= nil and ProductionPoint.PROD_STATUS.MISSING_INPUTS or nil
|
||||
@@ -784,9 +784,13 @@ end
|
||||
|
||||
-- Behovsstyret: den ingrediens aflæsningsmålet mangler mest, som også findes i en silo.
|
||||
function ADSmartPickup.findSupplyPickup(adEnv, driver, ingredients, targetWayPointId)
|
||||
local secondMarker = driver.ad.stateModule:getSecondMarker()
|
||||
-- med eksplicit mål bruges AD's tilstand ikke (dvale-tjekket kalder med flowets parkerede vogn, der ingen .ad har)
|
||||
local wayPointId = targetWayPointId
|
||||
if wayPointId == nil then
|
||||
local secondMarker = driver.ad.stateModule:getSecondMarker()
|
||||
wayPointId = secondMarker ~= nil and secondMarker.id or nil
|
||||
end
|
||||
local farmId = getFarmId(driver)
|
||||
local wayPointId = targetWayPointId or (secondMarker ~= nil and secondMarker.id or nil)
|
||||
if wayPointId == nil or farmId == nil then
|
||||
return nil
|
||||
end
|
||||
@@ -1346,6 +1350,10 @@ function ADSmartPickup:update(dt)
|
||||
local okFlow, errFlow = pcall(ADFlowWagons.tick, getAutoDriveEnv(), dt)
|
||||
if not okFlow then Logging.warning(ADSmartPickup.LOG_PREFIX .. "flow-vogne fejlede: %s", tostring(errFlow)) end
|
||||
end
|
||||
if ADFlowSleep ~= nil then
|
||||
local okSleep, errSleep = pcall(ADFlowSleep.tick, getAutoDriveEnv(), dt)
|
||||
if not okSleep then Logging.warning(ADSmartPickup.LOG_PREFIX .. "dvale fejlede: %s", tostring(errSleep)) end
|
||||
end
|
||||
if ADHitch ~= nil then
|
||||
local okHitch, errHitch = pcall(ADHitch.tick, getAutoDriveEnv(), dt)
|
||||
if not okHitch then
|
||||
|
||||
@@ -210,6 +210,11 @@ function ADWaitPool.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
if graph.getPathTo == nil then
|
||||
return true
|
||||
end
|
||||
-- frakoblet vogn (dvale-tjekket): AD's rutesøgning læser vehicle.ad.frontNode og fejler — godtag; turen
|
||||
-- rutetjekkes igen af traktoren, når flowet er vækket
|
||||
if vehicle ~= nil and vehicle.ad == nil and vehicle.spec_attachable ~= nil and vehicle.spec_motorized == nil then
|
||||
return true
|
||||
end
|
||||
local now = clockMs()
|
||||
local key = now ~= nil and routeKey(vehicle, wayPointId) or nil
|
||||
local cached = key ~= nil and routeCache[key] or nil
|
||||
|
||||
@@ -66,6 +66,7 @@ function SmartPickupFrame:flowCells(adEnv, run)
|
||||
end
|
||||
-- kædeflow uden traktor: sig hvorfor det står stille i stedet for flowets regel
|
||||
if ADFlowView.isIdleChain(run) then status = i18n:getText("spu_flow_chainIdle") end
|
||||
if run.sleeping then status = i18n:getText("spu_flow_sleeping") end
|
||||
local name = (run.id == self.selectedRunId and "> " or "") .. ADFlowView.listName(run)
|
||||
return {name, products, from, to, string.format("%d/%d", row.running, row.total), status}
|
||||
end
|
||||
|
||||
@@ -354,6 +354,7 @@
|
||||
<text name="spu_flow_noVehicle" text="(ingen traktor)"/>
|
||||
<text name="spu_flow_ruleSellAlways" text="sælg altid"/>
|
||||
<text name="spu_flow_chainIdle" text="mangler traktor/vogn"/>
|
||||
<text name="spu_flow_sleeping" text="Sover — vågner når der er arbejde (traktor og vogn er ledige imens)"/>
|
||||
<text name="spu_flow_ruleSell" text="pris >= %d %%"/>
|
||||
<text name="spu_flow_ruleStore" text="lager > %d %%"/>
|
||||
<text name="spu_flow_ruleOut" text="pris >= %d %%, lager > %d %%"/>
|
||||
|
||||
@@ -354,6 +354,7 @@
|
||||
<text name="spu_flow_noVehicle" text="(no tractor)"/>
|
||||
<text name="spu_flow_ruleSellAlways" text="always sell"/>
|
||||
<text name="spu_flow_chainIdle" text="needs a tractor/trailer"/>
|
||||
<text name="spu_flow_sleeping" text="Sleeping — wakes when there is work (tractor and wagon are free meanwhile)"/>
|
||||
<text name="spu_flow_ruleSell" text="price >= %d %%"/>
|
||||
<text name="spu_flow_ruleStore" text="storage > %d %%"/>
|
||||
<text name="spu_flow_ruleOut" text="price >= %d %%, storage > %d %%"/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.57.0</version>
|
||||
<version>1.62.58.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
@@ -56,6 +56,7 @@
|
||||
<sourceFile filename="adHitchApproach.lua"/>
|
||||
<sourceFile filename="adPool.lua"/>
|
||||
<sourceFile filename="adFlowWagons.lua"/>
|
||||
<sourceFile filename="adFlowSleep.lua"/>
|
||||
<sourceFile filename="adFleetNames.lua"/>
|
||||
<sourceFile filename="adFieldJobs.lua"/>
|
||||
<sourceFile filename="adMonthView.lua"/>
|
||||
|
||||
Reference in New Issue
Block a user