feat: forsyning henter kun på gården eller stald-silo; marksiloer udelades (v1.62.138)

This commit is contained in:
2026-10-10 02:28:46 +02:00
parent f3f8927e97
commit e8b362dc38
5 changed files with 69 additions and 2 deletions
+40 -1
View File
@@ -423,6 +423,34 @@ local function mayUseSource(station, fillTypes, level, loadCapacity, need)
return true
end
-- Kun gårdens lagre eller en silo ved stalden (ADSupplyPlanner.filterSupplySources); marksiloer udelades.
function ADSmartPickup.restrictSupplySources(adEnv, markerStations, targetPlaceable)
local fieldSiloIds = {}
for _, silo in ipairs(ADFieldSilos ~= nil and ADFieldSilos.lastSilos or {}) do fieldSiloIds[silo.id] = true end
local tx, tz = nil, nil
if targetPlaceable ~= nil and targetPlaceable.rootNode ~= nil then
local ok, x, _, z = pcall(getWorldTranslation, targetPlaceable.rootNode)
if ok then tx, tz = x, z end
end
local entries = {}
for _, entry in ipairs(markerStations) do
local placeable = entry.station ~= nil and entry.station.owningPlaceable or nil
local id = placeable ~= nil and ADBuildings ~= nil and ADBuildings.getId ~= nil and ADBuildings.getId(placeable) or nil
local distance = nil
if tx ~= nil and placeable ~= nil and placeable.rootNode ~= nil then
local ok, x, _, z = pcall(getWorldTranslation, placeable.rootNode)
if ok then distance = math.sqrt((x - tx) ^ 2 + (z - tz) ^ 2) end
end
table.insert(entries, {marker = entry.marker, station = entry.station, isFieldSilo = id ~= nil and fieldSiloIds[id] == true,
isSilo = placeable ~= nil and placeable.spec_silo ~= nil, distance = distance})
end
local near, farm = ADSupplyPlanner.filterSupplySources(entries)
local all = {}
for _, entry in ipairs(near) do table.insert(all, entry) end
for _, entry in ipairs(farm) do table.insert(all, entry) end
return {near, farm}, all
end
local function findBestSource(markerStations, fillTypes, farmId, loadCapacity, need)
local prefersFullest = ADSupplyPlanner.prefersFullestSource(getFillTypeNames(fillTypes))
local ample = ADSupplyPlanner.ampleLevel(loadCapacity)
@@ -457,6 +485,15 @@ local function findBestSource(markerStations, fillTypes, farmId, loadCapacity, n
}
end
-- Stald-silo først (tier 1), ellers gårdens lagre (tier 2): en tom stald-silo må ikke spærre for gården.
local function findBestSourceTiered(tiers, fillTypes, farmId, loadCapacity, need)
for _, tier in ipairs(tiers or {}) do
local choice = #tier > 0 and findBestSource(tier, fillTypes, farmId, loadCapacity, need) or nil
if choice ~= nil then return choice end
end
return nil
end
-- Mappe-logik: mappens mindst fyldte silo der har den/de valgte varer, ellers nil.
function ADSmartPickup.findLeastFilledPickup(adEnv, driver)
local firstMarker = driver.ad.stateModule:getFirstMarker()
@@ -952,6 +989,8 @@ function ADSmartPickup.findSupplyPickup(adEnv, driver, ingredients, targetWayPoi
local allMarkers = adEnv.ADGraphManager:getMapMarkers()
local markerStations = collectMarkerStations(adEnv, allMarkers, farmId, target.owningPlaceable)
local sourceTiers
sourceTiers, markerStations = ADSmartPickup.restrictSupplySources(adEnv, markerStations, target.owningPlaceable)
local loadCapacity = getLoadCapacity(adEnv, driver)
local needs = ADSupplyPlanner.applyPending(getTargetNeeds(target, ingredients, farmId, demand), ADSmartPickup.getPending(wayPointId, driver))
local ranked = ADSupplyPlanner.rankNeeds(needs, loadCapacity)
@@ -965,7 +1004,7 @@ function ADSmartPickup.findSupplyPickup(adEnv, driver, ingredients, targetWayPoi
end
for _, need in ipairs(ranked) do
local choice = not held[need] and (ADSupplyPlanner.isFoodAllowed == nil or ADSupplyPlanner.isFoodAllowed(need, bestFood))
and findBestSource(markerStations, {need.fillType}, farmId, loadCapacity, need) or nil
and findBestSourceTiered(sourceTiers, {need.fillType}, farmId, loadCapacity, need) or nil
if choice ~= nil then
return {
markerIndex = choice.markerIndex,
+17
View File
@@ -406,3 +406,20 @@ function ADSupplyPlanner.cargoFor(fillType, liters, ingredients)
end
return nil
end
-- Forsyningens kilder: kun gårdens lagre — eller en silo der står ved stalden (stald-silo, inden for STABLE_SILO_M af
-- målet). Marksiloer (siloer ved markerne) bruges ikke: dem tømmer marksilo-flowet hjem til gården (brugerønske 10/10).
-- entries = {{isFieldSilo = bool, isSilo = bool, distance = m}}; -> stald-siloer (prøves først), gårdens lagre (ellers).
ADSupplyPlanner.STABLE_SILO_M = 80
function ADSupplyPlanner.filterSupplySources(entries)
local near, farm = {}, {}
for _, entry in ipairs(entries or {}) do
local isNear = entry.distance ~= nil and entry.distance <= ADSupplyPlanner.STABLE_SILO_M
if isNear and entry.isSilo then
table.insert(near, entry)
elseif not entry.isFieldSilo then
table.insert(farm, entry)
end
end
return near, farm
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.62.137.0</version>
<version>1.62.138.0</version>
<title>
<en>AD Smart Pickup</en>
</title>