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
+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)