chore(diag): Wait logger hvorfor andre run-mål blev valgt fra til resten (v1.62.243)

This commit is contained in:
2026-10-16 02:51:29 +02:00
parent ee4d74a9ee
commit 60010ee8ba
3 changed files with 24 additions and 6 deletions
+22 -5
View File
@@ -150,19 +150,29 @@ local function markerTakes(adEnv, vehicle, targetId, fillType)
end
-- Det af run'ets ANDRE mål der tager varen og har mest fri plads (≥ MIN_FREE_FOR_OTHER_TARGET) og vej.
local function findOtherTargetForRest(adEnv, vehicle, fillType, currentId)
-- diag (valgfri tabel): én tekst pr. andet mål med fri plads / trigger / vej — til loggen når intet findes
local function findOtherTargetForRest(adEnv, vehicle, fillType, currentId, diag)
local run = ADRunsController ~= nil and ADRunsController.getRunForVehicle ~= nil and activeRunOf(vehicle) or nil
if run == nil or (run.kind or "supply") ~= "supply" or vehicle.ad.stateModule.setSecondMarkerByWayPointId == nil then
if diag ~= nil then table.insert(diag, "intet forsyningsflow") end
return nil
end
local best, bestFree = nil, ADUnloadWait.MIN_FREE_FOR_OTHER_TARGET - 1
for _, targetId in ipairs(ADRunsController.getRunTargets(run)) do
if targetId ~= currentId then
local free = ADSmartPickup.getTargetFreeCapacity(adEnv, vehicle, fillType, false, targetId)
local marker = adEnv.ADGraphManager.getMapMarkerByWayPointId ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(targetId) or nil
local name = marker ~= nil and marker.name or tostring(targetId)
-- triggeren ved markøren skal tage varen, ikke bare stationen (foder til en halm-markør, in-game 14/10)
if free ~= nil and free > bestFree and markerTakes(adEnv, vehicle, targetId, fillType) and hasRouteTo(adEnv, vehicle, targetId) then
local marker = adEnv.ADGraphManager.getMapMarkerByWayPointId ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(targetId) or nil
best, bestFree = {id = targetId, name = marker ~= nil and marker.name or tostring(targetId)}, free
local enough = free ~= nil and free > bestFree
local takes = enough and markerTakes(adEnv, vehicle, targetId, fillType)
local route = takes and hasRouteTo(adEnv, vehicle, targetId)
if diag ~= nil then
table.insert(diag, string.format("%s: fri %s, trigger %s, vej %s", name, free ~= nil and string.format("%.0f l", free) or "ukendt",
enough and tostring(takes) or "-", takes and tostring(route) or "-"))
end
if route then
best, bestFree = {id = targetId, name = name}, free
end
end
end
@@ -333,7 +343,14 @@ local function updateWaiting(adEnv, task, wait, dt)
wait.otherCheckMs = (wait.otherCheckMs or ADUnloadWait.OTHER_TARGET_CHECK_MS) + (dt or 0)
if wait.otherCheckMs >= ADUnloadWait.OTHER_TARGET_CHECK_MS then
wait.otherCheckMs = 0
local other, otherFree = findOtherTargetForRest(adEnv, vehicle, fillType, home)
-- første tjek pr. ventetur: hvorfor blev de andre mål valgt fra (in-game 16/10: Kostald 2 tom, men ikke valgt)
local diag = not wait.otherDiagLogged and {} or nil
local other, otherFree = findOtherTargetForRest(adEnv, vehicle, fillType, home, diag)
if diag ~= nil then
wait.otherDiagLogged = true
Logging.info(ADUnloadWait.LOG_PREFIX .. "'%s' ved %s — andre mål til resten (%.0f l): %s", tostring(ADRuns.vehicleLabel(vehicle)),
tostring(wait.waitMarker.name), rest, #diag > 0 and table.concat(diag, "; ") or "ingen andre mål")
end
if other ~= nil and ADUnloadWait.isWorthLeavingWait(otherFree, free, rest) then
release(vehicle)
pendingTargetRestore[vehicle] = nil