fix: pause efter falske opvågninger og detaljeret vågn-log (v1.62.65)
This commit is contained in:
@@ -38,8 +38,23 @@ 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
|
||||
-- Pause før næste vågn-tjek efter falske opvågninger (vågnede, men sov igen uden en tur): 10 -> 30 -> 60 min.
|
||||
ADFlowSleep.FALSE_WAKE_BACKOFF_MS = {10 * 60 * 1000, 30 * 60 * 1000, 60 * 60 * 1000}
|
||||
function ADFlowSleep.wakeBackoffMs(falseWakes)
|
||||
if (falseWakes or 0) <= 0 then return ADFlowSleep.WAKE_CHECK_MS end
|
||||
local steps = ADFlowSleep.FALSE_WAKE_BACKOFF_MS
|
||||
return steps[math.min(falseWakes, #steps)]
|
||||
end
|
||||
|
||||
function ADFlowSleep.isCheckDue(lastCheck, nowMs, falseWakes)
|
||||
return lastCheck == nil or nowMs - lastCheck >= ADFlowSleep.wakeBackoffMs(falseWakes)
|
||||
end
|
||||
|
||||
-- Falske opvågninger i træk efter en ny dvale. previous = tælleren hvis flowet er vækket af dvalen (nil = første
|
||||
-- dvale); hadTrip = flowet har haft last på siden opvågningen.
|
||||
function ADFlowSleep.falseWakesAfterSleep(previous, hadTrip)
|
||||
if previous == nil or hadTrip then return 0 end
|
||||
return previous + 1
|
||||
end
|
||||
|
||||
local function nearest(list, x, z)
|
||||
@@ -100,6 +115,7 @@ end
|
||||
local idleSince = {} -- runId -> ms
|
||||
local lastCheck = {} -- runId -> ms
|
||||
local checkFailures = {} -- runId -> fejlede arbejdstjek i træk
|
||||
local wakeState = {} -- runId -> {falseWakes, woke (vækket af dvalen), hadTrip (last siden opvågningen)}
|
||||
local loggedErrors = {}
|
||||
local timerMs = 0
|
||||
|
||||
@@ -161,12 +177,18 @@ function ADFlowSleep.hasWork(adEnv, 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
|
||||
return trip ~= nil, trip ~= nil and string.format("%s til %s, vogn '%s'", table.concat(trip.names or {}, "+"),
|
||||
tostring(trip.targetName or "?"), tostring(ADRuns.vehicleLabel(cargo))) 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
|
||||
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)))
|
||||
end
|
||||
end
|
||||
return false, nil
|
||||
end
|
||||
@@ -234,12 +256,16 @@ local function wake(adEnv, run, byId, why)
|
||||
end
|
||||
|
||||
local function sleep(adEnv, run)
|
||||
local state = wakeState[run.id] or {}
|
||||
local falseWakes = ADFlowSleep.falseWakesAfterSleep(state.woke and (state.falseWakes or 0) or nil, state.hadTrip == true)
|
||||
wakeState[run.id] = {falseWakes = falseWakes}
|
||||
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))
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s' sover — intet at lave i %d min; traktor og vogn er ledige til andet%s",
|
||||
tostring(run.name), math.floor(ADFlowSleep.SLEEP_AFTER_MS / 60000), falseWakes > 0
|
||||
and string.format(" (vågnede uden tur %d gang(e) i træk — næste tjek om %d min)", falseWakes, math.floor(ADFlowSleep.wakeBackoffMs(falseWakes) / 60000)) or "")
|
||||
end
|
||||
|
||||
local function farmVehiclesById(adEnv)
|
||||
@@ -253,7 +279,7 @@ 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
|
||||
if not ADFlowSleep.isCheckDue(lastCheck[run.id], now, (wakeState[run.id] or {}).falseWakes) then return end
|
||||
lastCheck[run.id] = now
|
||||
local ok, hasWork, why = pcall(ADFlowSleep.hasWork, adEnv, run, byId)
|
||||
if ok then
|
||||
@@ -265,15 +291,24 @@ local function tickRun(adEnv, run, byId, now)
|
||||
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
|
||||
if hasWork then
|
||||
local state = wakeState[run.id] or {}
|
||||
wakeState[run.id] = {falseWakes = state.falseWakes or 0, woke = true, hadTrip = false}
|
||||
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 = {}
|
||||
local state = wakeState[run.id]
|
||||
for index, id in ipairs(run.vehicleIds or {}) do
|
||||
local vehicle = byId[id]
|
||||
vehicles[index] = vehicle ~= nil and vehicleState(adEnv, vehicle) or false
|
||||
-- last på efter opvågningen = opvågningen var ægte
|
||||
if state ~= nil and state.woke and vehicles[index] and (vehicles[index].cargo or 0) >= ADFlowSleep.MIN_CARGO_LITERS then
|
||||
state.hadTrip = true
|
||||
end
|
||||
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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.64.0</version>
|
||||
<version>1.62.65.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user