fix: æg-paller tælles kun for nærmeste spawner — tomt hønsehus så naboernes paller (hus 1+2 blev aldrig hentet) (v1.28.1.0)

This commit is contained in:
2026-09-26 11:29:49 +02:00
parent 6fd917caca
commit cb68c81a3f
3 changed files with 53 additions and 2 deletions
+27 -1
View File
@@ -256,6 +256,31 @@ end
-- Liter af varen på paller der står ved fabrikkens spawner (pallespawneren tømmer lageret
-- ud på jorden løbende, så det er dér varen fysisk er).
-- Alle andre pallespawnere der kan lave varen (stalde med spawner for fillType, fabrikkers
-- pallespawner): {{x, z}, ...}. Står bygningerne tættere end PALLET_RADIUS (hønsehuse på række),
-- tilhører en palle den nærmeste spawner — ellers tæller et tomt hus naboernes paller med.
local function findRivalSpawners(fillType)
local rivals = {}
local placeables = g_currentMission ~= nil and g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
for _, placeable in pairs(placeables) do
local husbandrySpawners = getHusbandryPalletSpawners(placeable)
local productionPoint = getProductionPoint(placeable)
local node = firstSpawnerNode(husbandrySpawners ~= nil and husbandrySpawners[fillType] or nil)
or firstSpawnerNode(productionPoint ~= nil and productionPoint.palletSpawner or nil)
local x, z = getNodePosition(node)
if x ~= nil then table.insert(rivals, {x = x, z = z}) end
end
return rivals
end
local function isNearestSpawner(rivals, sx, sz, x, z)
local own = distance2(sx, sz, x, z)
for _, rival in ipairs(rivals) do
if distance2(rival.x, rival.z, x, z) < own then return false end
end
return true
end
local function getPalletsNearSpawner(placeable, fillType, farmId, spawnerNode)
local productionPoint = getProductionPoint(placeable)
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
@@ -264,6 +289,7 @@ local function getPalletsNearSpawner(placeable, fillType, farmId, spawnerNode)
if sx == nil then
return 0
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 = 0, 0
local radius2 = ADSources.PALLET_RADIUS * ADSources.PALLET_RADIUS
@@ -271,7 +297,7 @@ local function getPalletsNearSpawner(placeable, fillType, farmId, spawnerNode)
if isPalletVehicle(vehicle) and (vehicle.getOwnerFarmId == nil or vehicle:getOwnerFarmId() == farmId) then
local palletFillType, level = getPalletContent(vehicle)
local x, z = getNodePosition(vehicle.rootNode)
if palletFillType == fillType and x ~= nil and distance2(sx, sz, x, z) <= radius2 then
if palletFillType == fillType and x ~= nil and distance2(sx, sz, x, z) <= radius2 and isNearestSpawner(rivals, sx, sz, x, z) then
total = total + level
count = count + 1
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.28.0.0</version>
<version>1.28.1.0</version>
<title>
<en>AD Smart Pickup</en>
</title>
+25
View File
@@ -413,6 +413,31 @@ check("S14e æg på paller ved spawneren", eggs and eggs.available, 2800)
check("S14e tre paller", eggs and eggs.palletCount, 3)
check("S14e isPalletAt æg", coopSource and ADSources.isPalletAt(coopSource, EGGS), true)
-- S14f: hønsehuse på række 17 m fra hinanden (inden for PALLET_RADIUS) — en palle tæller kun for den
-- NÆRMESTE spawner, ellers "ser" et tomt hus naboernes æg og vognen kører forgæves derhen
local coop2Spawner = {spawnPlaces = {{startNode = {x = 8020, z = 0}}}}
local coop2 = {rootNode = {x = 8060, z = 0}, ownerFarmId = 1, getOwnerFarmId = function() return 1 end, getName = function() return "Chicken Coop" end,
getHusbandryFillLevel = function() return 0 end,
spec_husbandryPallets = {fillTypeIndexToPalletSpawner = {[EGGS] = coop2Spawner}, activeFillTypes = {EGGS}, fillLevels = {[EGGS] = 0}, capacities = {[EGGS] = 5000}}}
local emptyCoopSpawner = {spawnPlaces = {{startNode = {x = 8037, z = 0}}}}
local emptyCoop = {rootNode = {x = 8074, z = 0}, ownerFarmId = 1, getOwnerFarmId = function() return 1 end, getName = function() return "Chicken Coop" end,
getHusbandryFillLevel = function() return 0 end,
spec_husbandryPallets = {fillTypeIndexToPalletSpawner = {[EGGS] = emptyCoopSpawner}, activeFillTypes = {EGGS}, fillLevels = {[EGGS] = 0}, capacities = {[EGGS] = 5000}}}
table.insert(g_currentMission.placeableSystem.placeables, coop2)
table.insert(g_currentMission.placeableSystem.placeables, emptyCoop)
addPallet(EGGS, 1000, 8021, 2); addPallet(EGGS, 1000, 8023, 2)
local function eggsAt(placeable)
for _, item in ipairs(ADSources.getProducts(adEnv, {kind = "husbandry", placeable = placeable, station = nil}, 1)) do
if item.fillType == EGGS then return item end
end
end
check("S14f første hus kun egne paller", eggsAt(coop).available, 2800)
check("S14f nabohus kun egne paller", eggsAt(coop2).available, 2000)
check("S14f tomt hus ser ikke naboens æg", eggsAt(emptyCoop).available, 0)
check("S14f tomt hus 0 paller", eggsAt(emptyCoop).palletCount, 0)
table.remove(g_currentMission.placeableSystem.placeables)
table.remove(g_currentMission.placeableSystem.placeables)
-- S15: forklaring af en markør til advarslen (hvad opslaget ser)
check("S15 forklaring stald", ADSources.explainMarker(adEnv, 10, 1), "læssestation ved markøren hører til 'Kostald' (stald)")
check("S15 forklaring ingen station", ADSources.explainMarker(adEnv, 4, 1), "ingen læssestation ved markøren, og ingen fabrik/objektlager inden for 40 m")