feat: forsynings-miss viser hvorfor foder ikke købes (v1.62.123)
This commit is contained in:
@@ -955,25 +955,32 @@ function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute)
|
||||
end
|
||||
|
||||
-- Kun købestationer der sælger varen (dyrefoder som sidste udvej, 8/10). -> waypoint-id | nil
|
||||
-- -> waypoint-id | nil, diagnose {stations, withMarker, withRoute} (hvorfor intet købes — til loggen)
|
||||
function ADFieldWork.findBuyMarker(adEnv, vehicle, fillType, x, z, skipRoute)
|
||||
local best, bestDistance = nil, math.huge
|
||||
pcall(function()
|
||||
local info = {stations = 0, withMarker = 0, withRoute = 0}
|
||||
local ok, err = pcall(function()
|
||||
for _, placeable in pairs(g_currentMission.placeableSystem.placeables) do
|
||||
local spec = placeable.spec_buyingStation
|
||||
local station = spec ~= nil and spec.buyingStation or nil
|
||||
if station ~= nil and ADFieldWork.buyingSupports(station, fillType) then
|
||||
info.stations = info.stations + 1
|
||||
local wayPointId = markerAtStation(adEnv, vehicle, station, placeable)
|
||||
local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil
|
||||
if wayPoint ~= nil then
|
||||
info.withMarker = info.withMarker + 1
|
||||
local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
|
||||
if distance < bestDistance and (skipRoute or ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId)) then
|
||||
local routed = skipRoute or ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
if routed then info.withRoute = info.withRoute + 1 end
|
||||
if distance < bestDistance and routed then
|
||||
best, bestDistance = wayPointId, distance
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
return best
|
||||
if not ok then info.error = tostring(err) end
|
||||
return best, info
|
||||
end
|
||||
|
||||
-- Påfyldning undervejs (såmaskine/sprøjte/spreder): AutoDrive LOAD med hjælper = Courseplay. Når CP melder
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.122.0</version>
|
||||
<version>1.62.123.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user