fix: marksilo-vogn ved Wait efter genindlæsning sendes til lager med plads (v1.62.133)

This commit is contained in:
2026-10-10 00:30:16 +02:00
parent ceea868586
commit 9ac0e591cb
4 changed files with 32 additions and 9 deletions
+22 -8
View File
@@ -497,6 +497,13 @@ local function findById(list, id)
return nil
end
-- Står AutoDrives mål (2. markør) på et Wait-punkt?
local function isAtWaitMarker(vehicle)
local module = vehicle.ad ~= nil and vehicle.ad.stateModule or nil
local marker = module ~= nil and module.getSecondMarker ~= nil and module:getSecondMarker() or nil
return marker ~= nil and ADSupplyPlanner ~= nil and ADSupplyPlanner.isWaitMarker ~= nil and ADSupplyPlanner.isWaitMarker(marker) == true
end
local function checkRest(adEnv, vehicle, loan, moving, fill)
if loan.fetching then return end
local silo = findById(ADFieldSilos.lastSilos, loan.siloId)
@@ -512,28 +519,35 @@ local function checkRest(adEnv, vehicle, loan, moving, fill)
else
-- fuldt lager (fabrik der kun tager sit forbrug) med last på
local current = findById(ADFieldSilos.lastStores, loan.storeId)
if current == nil or not isNear(adEnv, vehicle, current.markerId) then return end
local state = {atStore = true, stillMs = stillMs, cargo = fill, storeFree = (current.free or {})[loan.fillType] or 0}
if not ADFieldSiloPlanner.storeFullDue(state) then return end
fullStore = current
if current == nil or not isNear(adEnv, vehicle, current.markerId) then
-- holder ved et Wait-punkt med last (ventetilstanden gik tabt ved genindlæsning): prøv et lager med plads
if not ADFieldSiloPlanner.waitRestDue({atWait = isAtWaitMarker(vehicle), stillMs = stillMs, cargo = fill}) then return end
loan.atWait = true
else
local state = {atStore = true, stillMs = stillMs, cargo = fill, storeFree = (current.free or {})[loan.fillType] or 0}
if not ADFieldSiloPlanner.storeFullDue(state) then return end
fullStore = current
end
end
local store = ADFieldSiloPlanner.restStore(ADFieldSilos.lastStores, silo, loan.fillType, fill, fullStore ~= nil and fullStore.id or nil)
if store == nil then
if not warnedNoRestStore[vehicle] then
warnedNoRestStore[vehicle] = true
Logging.warning(ADFieldSilos.LOG_PREFIX .. "'%s' har %d l %s fra tom %s, men intet lager har plads",
tostring(ADRuns.vehicleLabel(vehicle)), math.floor(fill), fillTypeName(loan.fillType), tostring(silo.name))
Logging.warning(ADFieldSilos.LOG_PREFIX .. "'%s' har %d l %s fra %s%s, men intet lager har plads",
tostring(ADRuns.vehicleLabel(vehicle)), math.floor(fill), fillTypeName(loan.fillType), tostring(silo.name),
loan.atWait and " (holder ved Wait)" or "")
end
return
end
warnedNoRestStore[vehicle] = nil
loan.delivering, loan.storeId, loan.stillSince = true, store.id, nil
local wasAtWait = loan.atWait
loan.delivering, loan.storeId, loan.stillSince, loan.atWait = true, store.id, nil, nil
loan.startedMs, loan.hasProgressed = nowMs, true
local isPool = ADHitch ~= nil and #ADHitch.poolParkIds(adEnv, vehicle) > 0
if not isPool then ADFieldWork.enableParkAtJobFinished(vehicle) end
ADFieldWork.startAd(adEnv, vehicle, adEnv.AutoDrive.MODE_DELIVERTO, store.markerId, nil, loan.fillType)
Logging.info(ADFieldSilos.LOG_PREFIX .. "'%s': %s — kører resten (%d l %s) til %s",
tostring(ADRuns.vehicleLabel(vehicle)), fullStore ~= nil and (tostring(fullStore.name) .. " er fuld") or (tostring(silo.name) .. " er tom"),
tostring(ADRuns.vehicleLabel(vehicle)), fullStore ~= nil and (tostring(fullStore.name) .. " er fuld") or (wasAtWait and "holdt ved Wait med last" or (tostring(silo.name) .. " er tom")),
math.floor(fill), fillTypeName(loan.fillType), tostring(store.name))
end