feat: bistadernes pallespawner som udkørselskilde for honning (1.62.362)

This commit is contained in:
2026-10-19 02:16:19 +02:00
parent d7d68ecaea
commit 647ce73fdf
10 changed files with 127 additions and 34 deletions
+53 -14
View File
@@ -24,6 +24,18 @@ local function getHusbandryPalletSpawners(placeable)
return spec ~= nil and spec.fillTypeIndexToPalletSpawner or nil
end
-- Bygningens egne pallespawnere pr. vare: staldens (æg, uld) eller bistadernes (honning) -> {[fillType] = spawner} | nil.
local function getOwnPalletSpawners(placeable)
local husbandry = getHusbandryPalletSpawners(placeable)
if husbandry ~= nil then return husbandry end
local spawner, fillType = ADUtil.beehivePalletSpawner(placeable)
return spawner ~= nil and {[fillType] = spawner} or nil
end
local function isBeehiveSpawner(placeable)
return ADUtil.beehivePalletSpawner(placeable) ~= nil
end
local function distance2(ax, az, bx, bz)
local dx, dz = ax - bx, az - bz
@@ -91,6 +103,9 @@ function ADSources.isPalletAt(source, fillType)
if source.kind == "husbandry" then
local spawners = getHusbandryPalletSpawners(source.placeable)
return spawners ~= nil and spawners[fillType] ~= nil
elseif source.kind == "beehive" then
local _, honey = ADUtil.beehivePalletSpawner(source.placeable)
return honey ~= nil and honey == fillType
elseif source.kind == "silo" then
return false
elseif source.kind == "objectStorage" then
@@ -110,9 +125,9 @@ local function getPlaceableAnchor(placeable)
local productionPoint = getProductionPoint(placeable)
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
if spawner == nil then
for _, husbandrySpawner in pairs(getHusbandryPalletSpawners(placeable) or {}) do spawner = husbandrySpawner break end
for _, ownSpawner in pairs(getOwnPalletSpawners(placeable) or {}) do spawner = ownSpawner break end
end
local place = spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] or nil
local place = ADUtil.spawnPlaces(spawner)[1]
local node = place ~= nil and place.startNode or placeable.rootNode
local x, z = getNodePosition(node)
if x == nil and node ~= placeable.rootNode then
@@ -149,7 +164,7 @@ local function isProductionPoint(placeable)
return getProductionPoint(placeable) ~= nil
end
-- {kind = "factory"|"silo"|"objectStorage", placeable, station|nil, wayPointId, name} eller nil.
-- {kind = "factory"|"silo"|"husbandry"|"storage"|"beehive"|"objectStorage", placeable, station|nil, wayPointId, name} eller nil.
function ADSources.identify(adEnv, wayPointId, farmId)
return cacheGet("identify", tostring(wayPointId) .. ":" .. tostring(farmId), 10000, function()
return ADSources.identifyUncached(adEnv, wayPointId, farmId)
@@ -196,11 +211,16 @@ function ADSources.identifyUncached(adEnv, wayPointId, farmId)
-- ofte ved siden af markøren. Løst opslag inden for 40 m — men aldrig for siloer.
-- stald med egne pallespawnere (hønsehus: æg) — markøren står ved spawneren, ingen læssestation
local palletBarn, palletBarnDistance = findPlaceableNear(wayPoint, farmId, function(placeable) return placeable.getHusbandryFillLevel ~= nil and getHusbandryPalletSpawners(placeable) ~= nil end)
-- bistadernes pallespawner (honning) konkurrerer på samme vilkår: den nærmeste pallekilde vinder
local hive, hiveDistance = findPlaceableNear(wayPoint, farmId, isBeehiveSpawner)
if hive ~= nil and palletBarn ~= nil and palletBarnDistance <= hiveDistance then hive = nil end
if hive ~= nil then palletBarn = nil end
local palletDistance = hive ~= nil and hiveDistance or palletBarnDistance
if placeable == nil and ADSmartPickup.getLoadStationNearWayPointId ~= nil then
local loose, looseDistance = ADSmartPickup.getLoadStationNearWayPointId(adEnv, wayPointId, farmId, ADSources.MAX_DISTANCE)
local loosePlaceable = loose ~= nil and loose.owningPlaceable or nil
-- et nærmere hønsehus vinder over en fjernere læssestation (gyllestation 23 m fra "Æg Pickup 1")
if palletBarn ~= nil and looseDistance ~= nil and palletBarnDistance ~= nil and palletBarnDistance < looseDistance then
if (palletBarn ~= nil or hive ~= nil) and looseDistance ~= nil and palletDistance ~= nil and palletDistance < looseDistance then
loosePlaceable = nil
end
if loosePlaceable ~= nil and loosePlaceable.spec_silo == nil then
@@ -216,7 +236,11 @@ function ADSources.identifyUncached(adEnv, wayPointId, farmId)
end
-- Rene pallefabrikker (halmvarer, bageri ...) har ingen læssestation: find dem på afstand
-- til pallespawneren; dernæst objektlagre.
local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint)
local factory, factoryDistance = findPlaceableNear(wayPoint, farmId, isProductionPoint)
-- bistaderne (fundet ovenfor) mod en ren pallefabrik: den nærmeste vinder
if hive ~= nil and (factory == nil or hiveDistance < factoryDistance) then
return {kind = "beehive", placeable = hive, station = nil, wayPointId = wayPointId, name = getPlaceableName(hive, markerName)}
end
if factory ~= nil then
-- produktionspunktets egen læssestation (bulk-outputs), også når markøren ikke rammer triggeren
local loadingStation = getProductionPoint(factory).loadingStation
@@ -233,7 +257,7 @@ end
-- Siloer og objektlagre springes over (de har deres egne, strenge regler), og stalde med pallespawnere (hønsehus,
-- fårestald) beholder den gamle vej — en station dér ville skjule pallevarerne. Stationen er den af bygningens
-- læssestationer hvis trigger står nærmest markøren (en stald har ofte en til mælk og en til gylle).
local ASSIGNED_KINDS = {husbandry = "husbandry", factory = "factory", storage = "storage"}
local ASSIGNED_KINDS = {husbandry = "husbandry", factory = "factory", storage = "storage", beehive = "beehive"}
local function nearestOwnedStation(placeable, wayPoint)
local storage = g_currentMission ~= nil and g_currentMission.storageSystem or nil
@@ -263,7 +287,7 @@ function ADSources.assignedBuilding(adEnv, wayPointId, farmId)
-- hønsehus m.fl. (pallespawnere): bygningslistens tildeling gælder, men uden station — varerne er pallerne ved
-- spawneren (in-game 17/10: 'Coop 1 Egg Pickup' står 7 m fra Hønsehus 2 og 9 m fra Hønsehus 3; listen gav den
-- Hønsehus 3, "nærmeste hønsehus" gav Hønsehus 2 -> vognen stod ved det forkerte hus og fandt ingen paller)
if kind == "husbandry" and getHusbandryPalletSpawners(placeable) ~= nil then
if (kind == "husbandry" and getHusbandryPalletSpawners(placeable) ~= nil) or kind == "beehive" then
return {kind = kind, placeable = placeable, station = nil, wayPointId = wayPointId}
end
local production = getProductionPoint(placeable)
@@ -302,7 +326,8 @@ function ADSources.explainMarker(adEnv, wayPointId, farmId)
if getProductionPoint(placeable) ~= nil then kind = "fabrik"
elseif placeable.spec_silo ~= nil then kind = "silo"
elseif placeable.getHusbandryFillLevel ~= nil then kind = "stald"
elseif placeable.spec_objectStorage ~= nil then kind = "objektlager" end
elseif placeable.spec_objectStorage ~= nil then kind = "objektlager"
elseif isBeehiveSpawner(placeable) then kind = "bistader" end
return string.format("læssestation ved markøren hører til '%s' (%s)", getPlaceableName(placeable, "?"), kind)
end
@@ -341,9 +366,9 @@ end
-- Spawnerens område som segmenter {ax, az, bx, bz}: hver spawnPlace fra start til slut (startNode/endNode,
-- eller PlacementUtil-felterne startX/startZ + dirX/dirZ*width). Et hønsehus har to rækker; måles kun
-- til første række, ligger den anden række tættere på naboens start end husets egen.
local function spawnerSegments(spawner)
local function spawnerSegments(spawner, fillType)
local segments = {}
for _, place in ipairs(spawner ~= nil and spawner.spawnPlaces or {}) do
for _, place in ipairs(ADUtil.spawnPlaces(spawner, fillType)) do
local ax, az = getNodePosition(place.startNode)
local bx, bz = getNodePosition(place.endNode)
if ax == nil and place.startX ~= nil and place.startZ ~= nil then
@@ -378,10 +403,10 @@ 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 ownSpawners = getOwnPalletSpawners(placeable)
local productionPoint = getProductionPoint(placeable)
local spawner = husbandrySpawners ~= nil and husbandrySpawners[fillType] or (productionPoint ~= nil and productionPoint.palletSpawner or nil)
local segments = spawnerSegments(spawner)
local spawner = ownSpawners ~= nil and ownSpawners[fillType] or (productionPoint ~= nil and productionPoint.palletSpawner or nil)
local segments = spawnerSegments(spawner, fillType)
if #segments > 0 then table.insert(rivals, {placeable = placeable, segments = segments}) end
end
return rivals
@@ -400,7 +425,7 @@ ADSources.lastPalletNote = {}
-- det er dér varen fysisk er). spawner = staldens spawner for varen; nil = fabrikkens pallespawner.
local function getPalletsNearSpawner(placeable, fillType, farmId, spawner)
local productionPoint = getProductionPoint(placeable)
local segments = spawnerSegments(spawner or (productionPoint ~= nil and productionPoint.palletSpawner or nil))
local segments = spawnerSegments(spawner or (productionPoint ~= nil and productionPoint.palletSpawner or nil), fillType)
if #segments == 0 then
local rx, rz = getNodePosition(placeable.rootNode)
if rx == nil then return 0, 0 end
@@ -589,6 +614,18 @@ local function getHusbandryPalletProducts(source, farmId)
return products
end
-- Bistader: honningen står på paller ved spawneren (spillets pendingLiters er endnu ikke spawnet og kan ikke hentes).
-- Kapacitet = det der står; fulde paller tælles som æg/uld (UAL-biler tager kun fulde).
local function getBeehiveProducts(source, farmId)
local spawner, fillType = ADUtil.beehivePalletSpawner(source.placeable)
if spawner == nil then return {} end
local liters, count, fullLiters, fullCount = getPalletsNearSpawner(source.placeable, fillType, farmId, spawner)
local product = newProduct(fillType, liters, liters, liters, true)
product.palletLiters, product.palletCount = liters, count
product.fullPalletLiters, product.fullPalletCount = fullLiters, fullCount
return {product}
end
local function getHusbandryProducts(adEnv, source)
local placeable, station = source.placeable, source.station
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
@@ -666,6 +703,8 @@ function ADSources.getProducts(adEnv, source, farmId, includeEmpty)
return getHusbandryProducts(adEnv, source)
elseif source.kind == "storage" then
return getStationProducts(source)
elseif source.kind == "beehive" then
return getBeehiveProducts(source, farmId or 1)
elseif source.kind == "objectStorage" then
return getObjectStorageProducts(source)
end