feat(stald): æg/uld-paller fra staldens egne pallespawnere (hønsehus) som udkørselskilde; brændstoftanke er ikke lager-kilder (v1.18.8.0)
This commit is contained in:
@@ -104,6 +104,19 @@ local function collectNodes(placeable, loadStations, unloadStations)
|
||||
end
|
||||
if #nodes > 0 then table.insert(loadGroups, nodes) end
|
||||
end
|
||||
-- stald med egne pallespawnere (hønsehus: æg, fårestald: uld) — én læssegruppe pr. spawner
|
||||
local husbandryPallets = placeable.spec_husbandryPallets
|
||||
local seenSpawners = {}
|
||||
for _, palletSpawner in pairs(husbandryPallets ~= nil and husbandryPallets.fillTypeIndexToPalletSpawner or {}) do
|
||||
if not seenSpawners[palletSpawner] then
|
||||
seenSpawners[palletSpawner] = true
|
||||
local nodes = {}
|
||||
for _, place in ipairs(palletSpawner.spawnPlaces or {}) do
|
||||
if place.startNode ~= nil then table.insert(nodes, place.startNode) end
|
||||
end
|
||||
if #nodes > 0 then table.insert(loadGroups, nodes) end
|
||||
end
|
||||
end
|
||||
if placeable.spec_objectStorage ~= nil and placeable.rootNode ~= nil then
|
||||
table.insert(loadGroups, {placeable.rootNode})
|
||||
table.insert(unloadNodes, placeable.rootNode)
|
||||
@@ -249,9 +262,25 @@ local function isSellPlaceable(placeable, unloadStations)
|
||||
return false
|
||||
end
|
||||
|
||||
-- Brændstof er ikke en vare der køres rundt (gårdens tankanlæg har en læssestation til diesel).
|
||||
local FUEL_FILL_TYPES = {DIESEL = true, DEF = true, ELECTRICCHARGE = true, METHANE = true}
|
||||
|
||||
local function isFuelOnly(station)
|
||||
local supported = station.supportedFillTypes
|
||||
if supported == nil or next(supported) == nil or g_fillTypeManager == nil then
|
||||
return false
|
||||
end
|
||||
for fillType, isSupported in pairs(supported) do
|
||||
if isSupported and not FUEL_FILL_TYPES[tostring(g_fillTypeManager:getFillTypeNameByIndex(fillType))] then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function hasOwnLoadingStation(placeable, loadStations)
|
||||
for _, station in pairs(loadStations) do
|
||||
if station.owningPlaceable == placeable then return true end
|
||||
if station.owningPlaceable == placeable and not isFuelOnly(station) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -11,6 +11,17 @@ ADSources.MAX_DISTANCE = 40
|
||||
-- Paller der står inden for denne afstand af fabrikkens pallespawner tæller som fabrikkens output.
|
||||
ADSources.PALLET_RADIUS = 25
|
||||
|
||||
-- Staldens egne pallespawnere (hønsehus: æg, fårestald: uld): {[fillType] = spawner}.
|
||||
local function getHusbandryPalletSpawners(placeable)
|
||||
local spec = placeable ~= nil and placeable.spec_husbandryPallets or nil
|
||||
return spec ~= nil and spec.fillTypeIndexToPalletSpawner or nil
|
||||
end
|
||||
|
||||
local function firstSpawnerNode(spawner)
|
||||
return spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] ~= nil and spawner.spawnPlaces[1].startNode or nil
|
||||
end
|
||||
|
||||
|
||||
local function distance2(ax, az, bx, bz)
|
||||
local dx, dz = ax - bx, az - bz
|
||||
return dx * dx + dz * dz
|
||||
@@ -63,7 +74,10 @@ end
|
||||
-- Palle eller bulk ved DENNE kilde: silo = bulk; objektlager = palle; fabrik = bulk hvis
|
||||
-- markørens læssestation udleverer varen, ellers palle hvis varen er en palletype.
|
||||
function ADSources.isPalletAt(source, fillType)
|
||||
if source.kind == "silo" or source.kind == "husbandry" then
|
||||
if source.kind == "husbandry" then
|
||||
local spawners = getHusbandryPalletSpawners(source.placeable)
|
||||
return spawners ~= nil and spawners[fillType] ~= nil
|
||||
elseif source.kind == "silo" then
|
||||
return false
|
||||
elseif source.kind == "objectStorage" then
|
||||
return true
|
||||
@@ -76,11 +90,14 @@ function ADSources.isPalletAt(source, fillType)
|
||||
return ADSources.isPalletFillType(fillType)
|
||||
end
|
||||
|
||||
-- Placeable'ns "nærmeste punkt" for kildegenkendelse: pallespawnerens første plads (fabrik)
|
||||
-- eller rodnoden.
|
||||
-- Placeable'ns "nærmeste punkt" for kildegenkendelse: pallespawnerens første plads (fabrik,
|
||||
-- stald med paller) eller rodnoden.
|
||||
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
|
||||
end
|
||||
local place = spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] or nil
|
||||
local node = place ~= nil and place.startNode or placeable.rootNode
|
||||
local x, z = getNodePosition(node)
|
||||
@@ -158,6 +175,11 @@ function ADSources.identify(adEnv, wayPointId, farmId)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- stald med egne pallespawnere (hønsehus: æg) — markøren står ved spawneren, ingen læssestation
|
||||
local palletBarn = findPlaceableNear(wayPoint, farmId, function(placeable) return placeable.getHusbandryFillLevel ~= nil and getHusbandryPalletSpawners(placeable) ~= nil end)
|
||||
if palletBarn ~= nil then
|
||||
return {kind = "husbandry", placeable = palletBarn, station = nil, wayPointId = wayPointId, name = getPlaceableName(palletBarn, markerName)}
|
||||
end
|
||||
-- Rene pallefabrikker (halmvarer, bageri ...) har ingen læssestation: find dem på afstand
|
||||
-- til pallespawneren; dernæst objektlagre.
|
||||
local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint)
|
||||
@@ -221,10 +243,10 @@ 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).
|
||||
local function getPalletsNearSpawner(placeable, fillType, farmId)
|
||||
local function getPalletsNearSpawner(placeable, fillType, farmId, spawnerNode)
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
|
||||
local node = spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] ~= nil and spawner.spawnPlaces[1].startNode or placeable.rootNode
|
||||
local node = spawnerNode or (spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] ~= nil and spawner.spawnPlaces[1].startNode) or placeable.rootNode
|
||||
local sx, sz = getNodePosition(node)
|
||||
if sx == nil then
|
||||
return 0
|
||||
@@ -369,8 +391,27 @@ local function getNearestTriggerFillTypes(adEnv, source)
|
||||
return #list > 0 and list or nil
|
||||
end
|
||||
|
||||
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, firstSpawnerNode(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
|
||||
table.insert(products, product)
|
||||
end
|
||||
table.sort(products, function(a, b) return a.fillType < b.fillType end)
|
||||
return products
|
||||
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
|
||||
if station == nil then
|
||||
-- kilde via staldens pallespawner (hønsehus: æg): kun pallevarerne
|
||||
return getHusbandryPalletProducts(source, farmId)
|
||||
end
|
||||
local fillTypes = getNearestTriggerFillTypes(adEnv, source) or {}
|
||||
if #fillTypes == 0 then
|
||||
for fillType, supported in pairs(station ~= nil and station.supportedFillTypes or {}) do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.18.7.0</version>
|
||||
<version>1.18.8.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user