feat: forsynings-miss viser hvorfor foder ikke købes (v1.62.123)

This commit is contained in:
2026-10-09 18:13:37 +02:00
parent db37b4b117
commit b32a429937
4 changed files with 35 additions and 10 deletions
+23 -6
View File
@@ -817,6 +817,7 @@ end
-- holdt ved Wait med tomt trug, mens gården havde 6,6 mio. l hø.
local supplyMissLoggedAt = setmetatable({}, {__mode = "k"})
ADSmartPickup.SUPPLY_MISS_LOG_MS = 5 * 60 * 1000
local buyMissReason = setmetatable({}, {__mode = "k"}) -- køretøj -> hvorfor buyFeed ikke købte (til loggen)
local function logSupplyMiss(driver, ranked, bestFood, markerStations, farmId, held)
local t = g_currentMission ~= nil and g_currentMission.time or 0
if supplyMissLoggedAt[driver] ~= nil and t - supplyMissLoggedAt[driver] < ADSmartPickup.SUPPLY_MISS_LOG_MS then return end
@@ -843,8 +844,8 @@ local function logSupplyMiss(driver, ranked, bestFood, markerStations, farmId, h
withStock, bestLevel, protected))
end
if #parts == 0 then table.insert(parts, "målet mangler intet (eller varerne kendes ikke)") end
Logging.info(ADSmartPickup.LOG_PREFIX .. "'%s' forsyning fandt intet: %s (%d markør-stationer)", tostring(ADRuns.vehicleLabel(driver)),
table.concat(parts, " | "), #(markerStations or {}))
Logging.info(ADSmartPickup.LOG_PREFIX .. "'%s' forsyning fandt intet: %s (%d markør-stationer) — køb: %s", tostring(ADRuns.vehicleLabel(driver)),
table.concat(parts, " | "), #(markerStations or {}), tostring(buyMissReason[driver] or "ikke forsøgt"))
end
-- Dyrenes forbrug af varen pr. måned (kædens data, 0 når dyrene ikke spiser den) og gårdens hentbare lager.
@@ -882,15 +883,30 @@ end
-- 150.000 l — med 848.000 l rest ville den købe igen i stedet for at aflevere resten).
local boughtLoggedAt = setmetatable({}, {__mode = "k"})
function ADSmartPickup.buyFeed(adEnv, driver, ranked, bestFood, targetWayPoint, wayPointId)
if ADFieldWork == nil or ADFieldWork.findBuyMarker == nil or targetWayPoint == nil then return nil end
for _, need in ipairs(ranked or {}) do
if need.trough and carriedLiters(adEnv, driver, need.fillType) > 0 then return nil end
if ADFieldWork == nil or ADFieldWork.findBuyMarker == nil or targetWayPoint == nil then
buyMissReason[driver] = "intet mål"
return nil
end
local function fillName(fillType) return tostring(g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(fillType) or fillType) end
for _, need in ipairs(ranked or {}) do
local carried = need.trough and carriedLiters(adEnv, driver, need.fillType) or 0
if carried > 0 then
buyMissReason[driver] = string.format("vognen har stadig %.0f l %s", carried, fillName(need.fillType))
return nil
end
end
local reasons = {}
for _, need in ipairs(ranked or {}) do
if need.trough and (ADSupplyPlanner.isFoodAllowed == nil or ADSupplyPlanner.isFoodAllowed(need, bestFood)) then
local markerId = ADFieldWork.findBuyMarker(adEnv, driver, need.fillType, targetWayPoint.x, targetWayPoint.z, driver.ad == nil)
local markerId, info = ADFieldWork.findBuyMarker(adEnv, driver, need.fillType, targetWayPoint.x, targetWayPoint.z, driver.ad == nil)
local marker = markerId ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(markerId) or nil
if marker == nil and #reasons < 4 then
info = info or {}
table.insert(reasons, string.format("%s: %d stationer sælger, %d med markør, %d med rute%s", fillName(need.fillType),
info.stations or 0, info.withMarker or 0, info.withRoute or 0, info.error ~= nil and (" (fejl " .. info.error .. ")") or ""))
end
if marker ~= nil then
buyMissReason[driver] = nil
local t = g_currentMission ~= nil and g_currentMission.time or 0
if boughtLoggedAt[driver] == nil or t - boughtLoggedAt[driver] > 5 * 60 * 1000 then
boughtLoggedAt[driver] = t
@@ -903,6 +919,7 @@ function ADSmartPickup.buyFeed(adEnv, driver, ranked, bestFood, targetWayPoint,
end
end
end
buyMissReason[driver] = #reasons > 0 and table.concat(reasons, "; ") or "intet trug-foder mangler"
return nil
end