feat: forsyning henter kun på gården eller stald-silo; marksiloer udelades (v1.62.138)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user