fix: kun fulde paller tæller for UAL-bil med fuld-filter (v1.62.131)

This commit is contained in:
2026-10-09 23:55:08 +02:00
parent 0513d843f6
commit 7b13021973
4 changed files with 48 additions and 10 deletions
+19 -3
View File
@@ -287,10 +287,22 @@ local function findStoreMarker(adEnv, vehicle, product, capacity, sources, liter
return {wayPointId = marker.id, name = tostring(marker.name), free = liters}
end
-- Tager bilens autoload kun fulde paller (Universal Autoload "Loading filter: full only")? Så tæller kun fulde
-- paller som tilgængelige — ellers kører bilen forgæves til hønsehuse med halvfyldte paller (in-game 9/10: Dragon kørte
-- alle seks huse rundt og kom hjem med 1 l).
function ADOutbound.loadsFullPalletsOnly(trailers)
for _, trailer in ipairs(trailers or {}) do
local spec = trailer.spec_universalAutoload
if spec ~= nil and spec.currentLoadingFilter == true then return true end
end
return false
end
-- input til ADOutboundPlanner.plan + kilder pr. waypoint-id.
function ADOutbound.buildPlanInput(adEnv, run, vehicle)
local farmId = ADSmartPickup.getFarmId(vehicle)
local capacity, hasAutoload = getVehicleCapacity(adEnv, vehicle)
local capacity, hasAutoload, trailers = getVehicleCapacity(adEnv, vehicle)
local fullOnly = hasAutoload and ADOutbound.loadsFullPalletsOnly(trailers)
local carriable = {}
for _, fillType in ipairs(ADRunsController.getCarriableFillTypes(adEnv, vehicle)) do
carriable[fillType] = true
@@ -324,6 +336,10 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle)
if usePallets and not item.isPallet then
available = item.palletLiters or 0
end
local palletCount = usePallets and (item.palletCount or 0) or 0
if usePallets and fullOnly then
available, palletCount = item.fullPalletLiters or 0, item.fullPalletCount or 0
end
-- andre køretøjer der allerede er på vej efter varen ved samme kilde: deres læs er taget (in-game 9/10:
-- begge mælkebiler planlagde samme sekund på de samme 30.000 l; den anden stod ved triggeren uden mælk)
if not usePallets then available = math.max(0, available - claimedLiters(vehicle, source.wayPointId, item.fillType)) end
@@ -336,7 +352,7 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle)
byName[item.name] = product
table.insert(products, product)
end
table.insert(product.sources, {wayPointId = source.wayPointId, available = available, level = item.level, capacity = item.capacity, palletCount = usePallets and (item.palletCount or 0) or 0})
table.insert(product.sources, {wayPointId = source.wayPointId, available = available, level = item.level, capacity = item.capacity, palletCount = palletCount})
end
end
end
@@ -751,7 +767,7 @@ local function describeLoadFailure(adEnv, vehicle, task, state, source)
for _, fillType in ipairs(state.trip.fillTypes) do wanted[fillType] = true end
for _, item in ipairs(ok and products or {}) do
if wanted[item.fillType] then
table.insert(parts, string.format("%s i kilden %.0f l", fillTypeName(item.fillType), item.available or item.level or 0))
table.insert(parts, string.format("%s i kilden %.0f l (%d paller, %d fulde)", fillTypeName(item.fillType), item.available or item.level or 0, item.palletCount or 0, item.fullPalletCount or 0))
end
end
local trailer = task.trailers ~= nil and task.trailers[1] or vehicle
+27 -6
View File
@@ -246,6 +246,23 @@ local function isPalletVehicle(vehicle)
return vehicle ~= nil and (vehicle.spec_pallet ~= nil or vehicle.isPallet == true)
end
-- Fuld palle som Universal Autoload regner det ("Loading filter: full only"): alle fyldenheder på 100 %.
function ADSources.isFullLevel(level, capacity)
return type(capacity) == "number" and capacity > 0 and (level or 0) / capacity >= 0.999
end
function ADSources.isFullPallet(vehicle)
if vehicle.getFillUnits == nil then return true end
for index in ipairs(vehicle:getFillUnits() or {}) do
if vehicle.getFillUnitFillLevelPercentage ~= nil then
if (vehicle:getFillUnitFillLevelPercentage(index) or 0) < 1 then return false end
elseif not ADSources.isFullLevel(vehicle:getFillUnitFillLevel(index), vehicle:getFillUnitCapacity(index)) then
return false
end
end
return true
end
local function getPalletContent(vehicle)
if vehicle.getFillUnitFillType ~= nil and vehicle.getFillUnitFillLevel ~= nil then
return vehicle:getFillUnitFillType(1), vehicle:getFillUnitFillLevel(1) or 0
@@ -327,7 +344,7 @@ local function getPalletsNearSpawner(placeable, fillType, farmId, spawner)
end
local rivals = cacheGet("palletSpawners", fillType, 10000, function() return findRivalSpawners(fillType) end)
local vehicles = g_currentMission ~= nil and g_currentMission.vehicleSystem ~= nil and g_currentMission.vehicleSystem.vehicles or {}
local total, count, lost = 0, 0, 0
local total, count, lost, fullTotal, fullCount = 0, 0, 0, 0, 0
local radius2 = ADSources.PALLET_RADIUS * ADSources.PALLET_RADIUS
for _, vehicle in pairs(vehicles) do
if isPalletVehicle(vehicle) and (vehicle.getOwnerFarmId == nil or vehicle:getOwnerFarmId() == farmId) then
@@ -338,6 +355,8 @@ local function getPalletsNearSpawner(placeable, fillType, farmId, spawner)
if isNearestSpawner(rivals, placeable, own, x, z) then
total = total + level
count = count + 1
-- hønsehusets paller fyldes løbende: en bil med "kun fulde paller" (UAL) kan kun tage de fulde (9/10)
if ADSources.isFullPallet(vehicle) then fullTotal, fullCount = fullTotal + level, fullCount + 1 end
else
lost = lost + 1
end
@@ -350,7 +369,7 @@ local function getPalletsNearSpawner(placeable, fillType, farmId, spawner)
ADSources.lastPalletNote[placeable] = now
Logging.info(ADSources.LOG_PREFIX .. "%s: %d paller inden for %d m tilhører nabo-spawnere (0 egne)", getPlaceableName(placeable, "?"), lost, ADSources.PALLET_RADIUS)
end
return total, count
return total, count, fullTotal, fullCount
end
-- canPallet: varen er en palletype (kan stå på paller); palletLiters: liter på paller ved
@@ -358,7 +377,7 @@ end
local function newProduct(fillType, available, level, capacity, isPallet)
local name = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(fillType) or tostring(fillType)
local title = g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeTitleByIndex ~= nil and g_fillTypeManager:getFillTypeTitleByIndex(fillType) or nil
return {fillType = fillType, name = name, title = title or name, available = available, level = level, capacity = capacity, isPallet = isPallet, canPallet = isPallet or ADSources.isPalletFillType(fillType), palletLiters = 0, palletCount = 0}
return {fillType = fillType, name = name, title = title or name, available = available, level = level, capacity = capacity, isPallet = isPallet, canPallet = isPallet or ADSources.isPalletFillType(fillType), palletLiters = 0, palletCount = 0, fullPalletLiters = 0, fullPalletCount = 0}
end
local function getFactoryProducts(source, farmId)
@@ -373,13 +392,14 @@ local function getFactoryProducts(source, farmId)
local level = storage ~= nil and storage.getFillLevel ~= nil and (storage:getFillLevel(fillType) or 0) or 0
local capacity = storage ~= nil and storage.getCapacity ~= nil and (storage:getCapacity(fillType) or 0) or 0
local isPallet = ADSources.isPalletAt(source, fillType)
local palletLiters, palletCount = 0, 0
local palletLiters, palletCount, fullLiters, fullCount = 0, 0, 0, 0
if ADSources.isPalletFillType(fillType) then
palletLiters, palletCount = getPalletsNearSpawner(source.placeable, fillType, farmId)
palletLiters, palletCount, fullLiters, fullCount = getPalletsNearSpawner(source.placeable, fillType, farmId)
end
local available = level + (isPallet and palletLiters or 0)
local product = newProduct(fillType, available, level, capacity, isPallet)
product.palletLiters, product.palletCount = palletLiters, palletCount
product.fullPalletLiters, product.fullPalletCount = fullLiters, fullCount
table.insert(products, product)
end
end
@@ -481,10 +501,11 @@ local function getHusbandryPalletProducts(source, farmId)
local products = {}
local spec = source.placeable.spec_husbandryPallets
for fillType, spawner in pairs(getHusbandryPalletSpawners(source.placeable) or {}) do
local liters, count = getPalletsNearSpawner(source.placeable, fillType, farmId, spawner)
local liters, count, fullLiters, fullCount = getPalletsNearSpawner(source.placeable, fillType, farmId, spawner)
local capacity = spec ~= nil and spec.capacities ~= nil and spec.capacities[fillType] or 0
local product = newProduct(fillType, liters, liters, math.max(capacity or 0, liters), true)
product.palletLiters, product.palletCount = liters, count
product.fullPalletLiters, product.fullPalletCount = fullLiters, fullCount
table.insert(products, product)
end
table.sort(products, function(a, b) return a.fillType < b.fillType end)
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.62.130.0</version>
<version>1.62.131.0</version>
<title>
<en>AD Smart Pickup</en>
</title>