fix: find DLC-fabrikkers pallespawner uden for productionPoint (young trout ved Young Fish Breeding)
This commit is contained in:
@@ -129,7 +129,7 @@ local function collectNodes(placeable, loadStations, unloadStations)
|
||||
end
|
||||
end
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
|
||||
local spawner = ADUtil.productionPalletSpawner(productionPoint, placeable)
|
||||
local factoryGroup = ADBuildings.spawnerGroup(spawner)
|
||||
if factoryGroup ~= nil then table.insert(loadGroups, factoryGroup) end
|
||||
-- bistadernes pallespawner: én læssegruppe ved pallepladserne ("Honey Pickup")
|
||||
@@ -970,6 +970,15 @@ function ADBuildings.dumpTriggers(adEnv, farmId)
|
||||
Logging.info("ADSmartPickup: TRIGGER bygning '%s' art=%s pos=%s rotY=%.1f fil=%s", tostring(name), kind, fmt(x, z),
|
||||
math.deg(ry or 0), tostring(placeable.configFileName))
|
||||
local okNodes, loadGroups, unloadNodes = pcall(collectNodes, placeable, loadStations, unloadStations)
|
||||
if okNodes and kind == "factory" and #(loadGroups or {}) == 0 then
|
||||
-- fabrik uden læssested: hvor ligger dens pallespawner? (20/10: Young Fish Breeding — DLC-bygning)
|
||||
local specs = {}
|
||||
for key in pairs(placeable) do
|
||||
if type(key) == "string" and key:sub(1, 5) == "spec_" then table.insert(specs, key) end
|
||||
end
|
||||
table.sort(specs)
|
||||
Logging.info("ADSmartPickup: TRIGGER '%s' ingen læssested/pallespawner fundet; specs: %s", tostring(name), table.concat(specs, " "))
|
||||
end
|
||||
if okNodes then
|
||||
for index, nodes in ipairs(loadGroups or {}) do
|
||||
for _, node in ipairs(nodes) do
|
||||
|
||||
@@ -126,7 +126,7 @@ end
|
||||
-- stald med paller) eller rodnoden.
|
||||
local function getPlaceableAnchor(placeable)
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
|
||||
local spawner = ADUtil.productionPalletSpawner(productionPoint, placeable)
|
||||
if spawner == nil then
|
||||
for _, ownSpawner in pairs(getOwnPalletSpawners(placeable) or {}) do spawner = ownSpawner break end
|
||||
end
|
||||
@@ -408,7 +408,7 @@ local function findRivalSpawners(fillType)
|
||||
for _, placeable in pairs(placeables) do
|
||||
local ownSpawners = getOwnPalletSpawners(placeable)
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
local spawner = ownSpawners ~= nil and ownSpawners[fillType] or (productionPoint ~= nil and productionPoint.palletSpawner or nil)
|
||||
local spawner = ownSpawners ~= nil and ownSpawners[fillType] or ADUtil.productionPalletSpawner(productionPoint, placeable)
|
||||
local segments = spawnerSegments(spawner, fillType)
|
||||
if #segments > 0 then table.insert(rivals, {placeable = placeable, segments = segments}) end
|
||||
end
|
||||
@@ -428,7 +428,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), fillType)
|
||||
local segments = spawnerSegments(spawner or ADUtil.productionPalletSpawner(productionPoint, placeable), fillType)
|
||||
if #segments == 0 then
|
||||
local rx, rz = getNodePosition(placeable.rootNode)
|
||||
if rx == nil then return 0, 0 end
|
||||
|
||||
@@ -85,3 +85,72 @@ function ADUtil.spawnPlaces(spawner, fillType)
|
||||
if fillType ~= nil and byFillType ~= nil and byFillType[fillType] ~= nil then return byFillType[fillType] end
|
||||
return spawner.spawnPlaces or {}
|
||||
end
|
||||
|
||||
-- Fabrikkens pallespawner. Spillets ProductionPoint har den i productionPoint.palletSpawner; DLC-bygninger kan have
|
||||
-- den andetsteds (in-game 20/10: Young Fish Breeding fra Highlands Fishing laver young trout-paller, men havde ingen
|
||||
-- productionPoint.palletSpawner — derfor ingen læssested og ingen vare). Så findes et spawner-objekt (har
|
||||
-- getOrSpawnPallet) i produktionspunktet eller bygningens spec_*-tabeller, højst ét niveau nede, i fast navneorden og
|
||||
-- uden stald-/bistade-/palleforhandler-spawnere. Kun for fabrikker; resultatet gemmes pr. bygning.
|
||||
local spawnerCache = setmetatable({}, {__mode = "k"})
|
||||
local loggedSpawner = setmetatable({}, {__mode = "k"})
|
||||
|
||||
local function isSpawner(value)
|
||||
return type(value) == "table" and type(value.getOrSpawnPallet) == "function"
|
||||
end
|
||||
|
||||
-- Spawnere i tabellens felter (og én liste nede), med sti -> {{spawner, path}}; nøgler sorteret, så valget er fast
|
||||
local function sortedKeys(tbl)
|
||||
local keys = {}
|
||||
for key in pairs(tbl) do table.insert(keys, key) end
|
||||
table.sort(keys, function(a, b) return tostring(a) < tostring(b) end)
|
||||
return keys
|
||||
end
|
||||
|
||||
local function scanForSpawners(tbl, depth, prefix, found)
|
||||
if type(tbl) ~= "table" then return found end
|
||||
for _, key in ipairs(sortedKeys(tbl)) do
|
||||
local value = tbl[key]
|
||||
local path = prefix .. "." .. tostring(key)
|
||||
if isSpawner(value) then
|
||||
table.insert(found, {spawner = value, path = path})
|
||||
elseif depth > 0 and type(value) == "table" and getmetatable(value) == nil then
|
||||
scanForSpawners(value, depth - 1, path, found)
|
||||
end
|
||||
end
|
||||
return found
|
||||
end
|
||||
|
||||
-- andre slags spawnere på samme bygning: stald (æg/uld), bistader (honning), palleforhandler (købte paller)
|
||||
local FOREIGN_SPECS = {spec_productionPoint = true, spec_husbandryPallets = true, spec_beehivePalletSpawner = true, spec_palletBuyingStation = true}
|
||||
|
||||
-- Produktionspunktet først, så spec_*-tabellerne i navneorden -> spawner, sti, antal fundne | nil
|
||||
local function findFallbackSpawner(productionPoint, placeable)
|
||||
local found = scanForSpawners(productionPoint, 1, "productionPoint", {})
|
||||
if #found == 0 and type(placeable) == "table" then
|
||||
for _, key in ipairs(sortedKeys(placeable)) do
|
||||
if type(key) == "string" and key:sub(1, 5) == "spec_" and not FOREIGN_SPECS[key] then
|
||||
scanForSpawners(placeable[key], 1, key, found)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #found == 0 then return nil end
|
||||
return found[1].spawner, found[1].path, #found
|
||||
end
|
||||
|
||||
function ADUtil.productionPalletSpawner(productionPoint, placeable)
|
||||
if productionPoint == nil then return nil end
|
||||
if productionPoint.palletSpawner ~= nil then return productionPoint.palletSpawner end
|
||||
local key = placeable or productionPoint
|
||||
local cached = spawnerCache[key]
|
||||
if cached ~= nil then return cached or nil end
|
||||
local ok, found, path, count = pcall(findFallbackSpawner, productionPoint, placeable)
|
||||
found = ok and found or nil
|
||||
spawnerCache[key] = found or false
|
||||
if found ~= nil and not loggedSpawner[key] then
|
||||
loggedSpawner[key] = true
|
||||
local okName, name = pcall(function() return placeable ~= nil and placeable.getName ~= nil and placeable:getName() or nil end)
|
||||
logInfo("ADSmartPickup: '%s' har sin pallespawner i %s (ikke productionPoint.palletSpawner, %d fundet) — bruges som læssested",
|
||||
tostring(okName and name or "?"), tostring(path), count or 1)
|
||||
end
|
||||
return found
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.402.0</version>
|
||||
<version>1.62.403.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
<de>AD Smart Pickup</de>
|
||||
|
||||
Reference in New Issue
Block a user