fix(påfyldning): tomt lager -> næste påfyldningssted; eget lager kræver 500 l (v1.62.257)

This commit is contained in:
2026-10-16 06:20:53 +02:00
parent 78e45ca2c3
commit 4e009c5100
4 changed files with 74 additions and 6 deletions
+37 -2
View File
@@ -1335,10 +1335,13 @@ end
-- efter behov — ingen lagerbeholdning, så de fandtes ikke før; in-game 26/9 "Liquid Buy Station").
-- skipRoute: rutetjekket springes over (frakoblet puljeredskab har ingen .ad, så AD's getPathTo fejler; traktoren
-- tjekkes igen i refillPlan efter påkobling).
function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute)
-- exclude (valgfri): {[wayPointId] = true} der springes over (fx et lager der er løbet tørt, mens vognen ventede)
ADFieldWork.MIN_REFILL_STOCK_L = 500 -- eget lager skal have mindst så meget af varen for at være påfyldningssted
function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute, exclude)
local farmId = vehicle:getOwnerFarmId()
local best, bestDistance = nil, math.huge
local function consider(wayPointId)
if exclude ~= nil and wayPointId ~= nil and exclude[wayPointId] then return end
local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil
if wayPoint == nil then return end
local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
@@ -1353,7 +1356,7 @@ function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute)
local supported = station.getAISupportedFillTypes ~= nil and station:getAISupportedFillTypes() or {}
local isShop = station.owningPlaceable ~= nil and station.owningPlaceable.spec_buyingStation ~= nil
if not isShop and g_currentMission.accessHandler:canFarmAccess(farmId, station) and supported[fillType]
and (station:getFillLevel(fillType, farmId) or 0) > 0 then
and (station:getFillLevel(fillType, farmId) or 0) >= ADFieldWork.MIN_REFILL_STOCK_L then
consider(markerAtStation(adEnv, vehicle, station, station.owningPlaceable))
end
end
@@ -1371,6 +1374,38 @@ function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute)
return best
end
-- Påfyldningsstedet er løbet tørt, mens vognen venter der (in-game 16/10: kalk-sprederen holdt ved "TMR Silo Farma",
-- der var tom): find næste sted uden det nuværende, og kør derhen. -> true når turen er flyttet.
function ADFieldWork.retargetEmptyRefill(adEnv, vehicle)
local module = vehicle.ad ~= nil and vehicle.ad.stateModule or nil
if module == nil or not module:isActive() or module:getMode() ~= adEnv.AutoDrive.MODE_LOAD then return false end
local first, second = module:getFirstMarker(), module:getSecondMarker()
local fillType = module.getFillType ~= nil and module:getFillType() or nil
if first == nil or second == nil or fillType == nil then return false end
-- kun når stedet BEVISELIGT ikke kan levere (review): eget lager under minimum, eller købestation der ikke sælger
-- varen. Kø ved stationen, langsom pumpe eller fuld tank flytter den ikke.
local station = markerOwner(adEnv, second.id)
if station ~= nil then
local shop = station.owningPlaceable ~= nil and station.owningPlaceable.spec_buyingStation ~= nil
if shop then
if ADFieldWork.buyingSupports(station, fillType) then return false end
else
local farmId = vehicle:getOwnerFarmId()
local okLevel, stock = pcall(station.getFillLevel, station, fillType, farmId)
if okLevel and (stock or 0) >= ADFieldWork.MIN_REFILL_STOCK_L then return false end
end
end
local x, z = vehiclePosition(vehicle)
local right = ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, true, {[second.id] = true})
if right == nil then return false end
startAd(adEnv, vehicle, adEnv.AutoDrive.MODE_LOAD, first.id, right, fillType)
local marker = adEnv.ADGraphManager:getMapMarkerByWayPointId(right)
local name = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(fillType) or tostring(fillType)
Logging.info("ADSmartPickup: påfyldning: '%s' fik intet %s ved %s — kører til %s", tostring(ADRuns.vehicleLabel(vehicle)),
tostring(name), tostring(second.name), tostring(marker ~= nil and marker.name or right))
return true
end
-- Genoptaget AD-tur i påfyldnings-tilstand (LOAD): påfyldningsstedet blev valgt før gem — måske af en ældre version
-- (in-game 16/10: kalk og gødning ved "Liquid Buy Silo", som ikke sælger dem; sprederne holdt der). Find det rigtige
-- sted for varen nu, og genstart turen dertil, hvis det er et andet.