fix(marksilo): fuld fabrik — lånt vogn med last der holder ved et lager uden plads i 60 s, kører resten til et andet lager (gårdsilo) (v1.50.5.0)
This commit is contained in:
@@ -455,7 +455,12 @@ function ADFieldSilos.adoptOrphans(adEnv, silos)
|
||||
local silo = first ~= nil and byMarker[first.id] or nil
|
||||
if silo ~= nil then
|
||||
local fillType = module.getFillType ~= nil and module:getFillType() or nil
|
||||
loans[vehicle] = {siloId = silo.id, siloName = silo.name, fillType = fillType, liters = 0, startedMs = nowMs,
|
||||
local second = module.getSecondMarker ~= nil and module:getSecondMarker() or nil
|
||||
local storeId = nil
|
||||
for _, store in ipairs(ADFieldSilos.lastStores or {}) do
|
||||
if second ~= nil and store.markerId == second.id then storeId = store.id end
|
||||
end
|
||||
loans[vehicle] = {siloId = silo.id, storeId = storeId, siloName = silo.name, fillType = fillType, liters = 0, startedMs = nowMs,
|
||||
lastProgressMs = nowMs, lastFill = fillLevel(adEnv, vehicle), hasProgressed = true, adopted = true}
|
||||
Logging.info(ADFieldSilos.LOG_PREFIX .. "'%s' overtaget igen (AutoDrive kører fra %s efter genindlæsning)",
|
||||
tostring(ADRuns.vehicleLabel(vehicle)), tostring(silo.name))
|
||||
@@ -467,22 +472,41 @@ end
|
||||
-- Tom silo-vagt: en lånt vogn med last, der står stille ved en tom marksilo, kører resten videre — til en fabrik
|
||||
-- med plads til hele resten, ellers til et gårdlager (AutoDrive venter ellers til vognen er fuld).
|
||||
local warnedNoRestStore = {}
|
||||
local function checkRest(adEnv, vehicle, loan, moving, fill)
|
||||
if loan.delivering or loan.fetching then return end
|
||||
local silo = nil
|
||||
for _, candidate in ipairs(ADFieldSilos.lastSilos or {}) do
|
||||
if candidate.id == loan.siloId then silo = candidate end
|
||||
end
|
||||
local wayPoint = silo ~= nil and silo.markerId ~= nil and adEnv.ADGraphManager:getWayPointById(silo.markerId) or nil
|
||||
if wayPoint == nil or vehicle.rootNode == nil then return end
|
||||
local function isNear(adEnv, vehicle, markerId)
|
||||
local wayPoint = markerId ~= nil and adEnv.ADGraphManager:getWayPointById(markerId) or nil
|
||||
if wayPoint == nil or vehicle.rootNode == nil then return false end
|
||||
local x, _, z = getWorldTranslation(vehicle.rootNode)
|
||||
local atSilo = (x - wayPoint.x) ^ 2 + (z - wayPoint.z) ^ 2 <= ADFieldSilos.REST_SILO_DISTANCE ^ 2
|
||||
if moving or not atSilo then loan.stillSince = nil return end
|
||||
return (x - wayPoint.x) ^ 2 + (z - wayPoint.z) ^ 2 <= ADFieldSilos.REST_SILO_DISTANCE ^ 2
|
||||
end
|
||||
|
||||
local function findById(list, id)
|
||||
for _, item in ipairs(list or {}) do
|
||||
if item.id == id then return item end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function checkRest(adEnv, vehicle, loan, moving, fill)
|
||||
if loan.fetching then return end
|
||||
local silo = findById(ADFieldSilos.lastSilos, loan.siloId)
|
||||
if silo == nil then return end
|
||||
if moving then loan.stillSince = nil return end
|
||||
loan.stillSince = loan.stillSince or nowMs
|
||||
local state = {atSilo = atSilo, stillMs = nowMs - loan.stillSince,
|
||||
siloStock = (silo.stock or {})[loan.fillType] or 0, cargo = fill}
|
||||
if not ADFieldSiloPlanner.restDue(state) then return end
|
||||
local store = ADFieldSiloPlanner.restStore(ADFieldSilos.lastStores, silo, loan.fillType, fill)
|
||||
local stillMs = nowMs - loan.stillSince
|
||||
local fullStore = nil
|
||||
if not loan.delivering and isNear(adEnv, vehicle, silo.markerId) then
|
||||
-- tom marksilo med last på
|
||||
local state = {atSilo = true, stillMs = stillMs, siloStock = (silo.stock or {})[loan.fillType] or 0, cargo = fill}
|
||||
if not ADFieldSiloPlanner.restDue(state) then return end
|
||||
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
|
||||
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
|
||||
@@ -492,13 +516,14 @@ local function checkRest(adEnv, vehicle, loan, moving, fill)
|
||||
return
|
||||
end
|
||||
warnedNoRestStore[vehicle] = nil
|
||||
loan.delivering = true
|
||||
loan.delivering, loan.storeId, loan.stillSince = true, store.id, 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 er tom — kører resten (%d l %s) til %s",
|
||||
tostring(ADRuns.vehicleLabel(vehicle)), tostring(silo.name), math.floor(fill), fillTypeName(loan.fillType), tostring(store.name))
|
||||
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"),
|
||||
math.floor(fill), fillTypeName(loan.fillType), tostring(store.name))
|
||||
end
|
||||
|
||||
local function checkLoans(adEnv)
|
||||
|
||||
Reference in New Issue
Block a user