feat: sovende flows siger hvorfor — planlæggerens grund i oversigten (Sover — EGG 86 % (kræver 90)) og i loggen højst én gang i timen pr. flow — 1.62.303
This commit is contained in:
@@ -59,6 +59,35 @@ function ADFlowSleep.falseWakesAfterSleep(previous, hadTrip)
|
||||
return previous + 1
|
||||
end
|
||||
|
||||
-- ---- hvorfor sover flowet? (in-game 17/10: 'Coop Egg Pickup' stod "sleeping" med fulde hønsehuse, fordi ægprisen
|
||||
-- lå på 86 % af top mod krævet 90 — men det stod ingen steder) ----
|
||||
|
||||
ADFlowSleep.REASON_LOG_MS = 60 * 60 * 1000 -- samme grund logges højst så tit pr. flow
|
||||
|
||||
-- Grundtekst til oversigt/log: planlæggerens grund, ellers en kort standard pr. flowtype.
|
||||
function ADFlowSleep.sleepReasonText(why, kind)
|
||||
if why ~= nil and why ~= "" then return why end
|
||||
if kind == "outbound" then return "intet at køre ud med" end
|
||||
return "intet at hente til målene"
|
||||
end
|
||||
|
||||
-- Skal grunden logges nu? last = {ms, text} fra sidste logning (nil = aldrig). Ny tekst logges straks, samme tekst
|
||||
-- igen først efter REASON_LOG_MS.
|
||||
-- Kort form til oversigtens smalle statuscelle: første grund, uden "af top" og uden lager-delen
|
||||
-- ("EGG 86 % af top (kræver 90), lager 100 %; MILK …" -> "EGG 86 % (kræver 90)"). Hele teksten står i loggen.
|
||||
function ADFlowSleep.shortReason(text)
|
||||
if text == nil then return nil end
|
||||
local first = string.match(text, "^(.-);") or text
|
||||
first = string.gsub(first, " af top", "")
|
||||
first = string.gsub(first, ",%s*lager [^,]*$", "")
|
||||
return first
|
||||
end
|
||||
|
||||
function ADFlowSleep.reasonLogDue(last, nowMs, text)
|
||||
if last == nil or last.text ~= text then return true end
|
||||
return nowMs - (last.ms or 0) >= ADFlowSleep.REASON_LOG_MS
|
||||
end
|
||||
|
||||
local function nearest(list, x, z)
|
||||
local best, bestDistance = nil, math.huge
|
||||
for _, item in ipairs(list or {}) do
|
||||
@@ -143,6 +172,8 @@ end
|
||||
|
||||
-- ---- spil-adapter ----
|
||||
|
||||
local sleepReason = {} -- runId -> grund fra seneste vågn-tjek uden tur (vises i oversigten)
|
||||
local reasonLogged = {} -- runId -> {ms, text} for seneste loggede grund
|
||||
local idleSince = {} -- runId -> ms
|
||||
local lastCheck = {} -- runId -> ms
|
||||
local checkFailures = {} -- runId -> fejlede arbejdstjek i træk
|
||||
@@ -217,9 +248,13 @@ function ADFlowSleep.hasWork(adEnv, run, byId, onlyTractorId)
|
||||
local cargo = cargoVehicleOf(run, byId, onlyTractorId)
|
||||
if cargo == nil then return onlyTractorId == nil, "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 string.format("%s til %s, vogn '%s'", table.concat(trip.names or {}, "+"),
|
||||
tostring(trip.targetName or "?"), tostring(ADRuns.vehicleLabel(cargo))) or nil
|
||||
local trip, reasons = ADOutboundPlanner.plan(ADOutbound.buildPlanInput(adEnv, run, cargo))
|
||||
if trip == nil then
|
||||
-- planlæggerens grunde ("EGG 86 % af top (kræver 90), lager 100 %") — det er dem, spilleren skal se
|
||||
return false, #(reasons or {}) > 0 and table.concat(reasons, "; ") or nil
|
||||
end
|
||||
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
|
||||
@@ -263,8 +298,27 @@ local function freeTractors(adEnv, taken)
|
||||
return result
|
||||
end
|
||||
|
||||
-- Oversigtens tekst for et sovende flow (nil når der ikke har været et vågn-tjek endnu).
|
||||
function ADFlowSleep.getSleepReason(runId)
|
||||
return sleepReason[runId]
|
||||
end
|
||||
|
||||
local function noteNoWork(run, why, now)
|
||||
local text = ADFlowSleep.sleepReasonText(why, run.kind)
|
||||
sleepReason[run.id] = text
|
||||
if run.kind == "outbound" and why ~= nil and ADOutbound ~= nil and ADOutbound.setRunReasons ~= nil then
|
||||
pcall(ADOutbound.setRunReasons, run.id, {why})
|
||||
end
|
||||
if ADFlowSleep.reasonLogDue(reasonLogged[run.id], now, text) then
|
||||
reasonLogged[run.id] = {ms = now, text = text}
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s' sover videre: %s", tostring(run.name), text)
|
||||
end
|
||||
end
|
||||
|
||||
local function wake(adEnv, run, byId, why)
|
||||
run.sleeping = nil
|
||||
sleepReason[run.id] = nil
|
||||
reasonLogged[run.id] = nil
|
||||
local taken = {}
|
||||
for _, tractorId in ipairs(run.vehicleIds or {}) do
|
||||
local own = byId[tractorId]
|
||||
@@ -324,6 +378,9 @@ local function sleep(adEnv, run, byId)
|
||||
run.sleeping = true
|
||||
idleSince[run.id] = nil
|
||||
lastCheck[run.id] = nowMs()
|
||||
-- ny dvale: ingen gammel grund i oversigten, og første vågn-tjek må logge sin grund igen
|
||||
sleepReason[run.id] = nil
|
||||
reasonLogged[run.id] = nil
|
||||
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 "")
|
||||
@@ -439,6 +496,8 @@ local function tickRun(adEnv, run, byId, now)
|
||||
local state = wakeState[run.id] or {}
|
||||
wakeState[run.id] = {falseWakes = state.falseWakes or 0, woke = true, hadTrip = false}
|
||||
wake(adEnv, run, byId, why)
|
||||
else
|
||||
noteNoWork(run, why, now)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user