feat: fabriksinput som foderkilde med 24 t reserve eller nødforsyning (v1.62.93)

This commit is contained in:
2026-10-08 19:34:23 +02:00
parent 17cde44ef6
commit a3616fb646
4 changed files with 46 additions and 22 deletions
+19 -21
View File
@@ -372,34 +372,32 @@ local function isProtectedHusbandryInput(station, fillTypes)
return false
end
local function isProtectedProductionInput(station, fillTypes)
if isProtectedHusbandryInput(station, fillTypes) then
return true
end
local productionPoint = getProductionPoint(station)
if productionPoint == nil or productionPoint.productions == nil then
return false
end
for _, fillType in ipairs(fillTypes) do
if ADSupplyPlanner.isProductionInput(productionPoint.productions, fillType) then
return true
end
end
return false
end
-- Bedste kilde der har varen: mindst fyldte først for lagervarer, fyldeste først for
-- varer hvis tanke løber fulde (ADSupplyPlanner). Siloer med varen i EGET lager går
-- altid forud for dem der kun kan låne fra naboer. Returnerer et valg eller nil.
local getLoadCapacity -- defineret længere nede (læs-kapacitet til kildevalget)
local function findBestSource(markerStations, fillTypes, farmId, loadCapacity)
-- Må kilden bruges? Dyrestaldens egne lagre aldrig; fabriksinput efter ADSupplyPlanner.mayTakeInput.
local function mayUseSource(station, fillTypes, level, loadCapacity, need)
if isProtectedHusbandryInput(station, fillTypes) then return false end
local productionPoint = getProductionPoint(station)
if productionPoint == nil or productionPoint.productions == nil then return true end
for _, fillType in ipairs(fillTypes) do
if ADSupplyPlanner.isProductionInput(productionPoint.productions, fillType) then
local perMinute = ADSupplyPlanner.inputUsePerMinute(productionPoint.productions, fillType)
if not ADSupplyPlanner.mayTakeInput(level, loadCapacity, perMinute, need) then return false end
end
end
return true
end
local function findBestSource(markerStations, fillTypes, farmId, loadCapacity, need)
local prefersFullest = ADSupplyPlanner.prefersFullestSource(getFillTypeNames(fillTypes))
local ample = ADSupplyPlanner.ampleLevel(loadCapacity)
local best = {[true] = {}, [false] = {}}
for _, entry in ipairs(markerStations) do
local level, isOwn = getStationFillLevel(entry.station, fillTypes, farmId)
if level >= ADSmartPickup.MIN_USEFUL_LITERS and not isProtectedProductionInput(entry.station, fillTypes)
if level >= ADSmartPickup.MIN_USEFUL_LITERS and mayUseSource(entry.station, fillTypes, level, loadCapacity, need)
and ADSupplyPlanner.isBetterSource(level, best[isOwn].level, prefersFullest, ample) then
best[isOwn] = {level = level, marker = entry.marker, station = entry.station, isOwn = isOwn}
end
@@ -798,7 +796,7 @@ local function logSupplyMiss(driver, ranked, bestFood, markerStations, farmId)
for _, entry in ipairs(markerStations or {}) do
local level = getStationFillLevel(entry.station, {need.fillType}, farmId)
if level >= ADSmartPickup.MIN_USEFUL_LITERS then
if isProtectedProductionInput(entry.station, {need.fillType}) then
if not mayUseSource(entry.station, {need.fillType}, level, nil, need) then
protected = protected + 1
else
withStock = withStock + 1
@@ -807,7 +805,7 @@ local function logSupplyMiss(driver, ranked, bestFood, markerStations, farmId)
end
end
local fillType = g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeByIndex ~= nil and g_fillTypeManager:getFillTypeByIndex(need.fillType) or nil
table.insert(parts, string.format("%s: fri %.0f l, %s, %d kilder med lager (bedst %.0f l), %d beskyttet produktionsinput",
table.insert(parts, string.format("%s: fri %.0f l, %s, %d kilder med lager (bedst %.0f l), %d beskyttet input (dyrestald / fabrik under 24 t reserve)",
fillType ~= nil and fillType.name or tostring(need.fillType), need.freeSpace or 0,
allowed and "tilladt" or "IKKE tilladt (bedre foder findes)", withStock, bestLevel, protected))
end
@@ -851,7 +849,7 @@ function ADSmartPickup.findSupplyPickup(adEnv, driver, ingredients, targetWayPoi
-- bedste foder først: lavere foder kun når truget er nødlidende (ADSupplyPlanner.isFoodAllowed)
local bestFood = ADSupplyPlanner.bestFoodPriority ~= nil and ADSupplyPlanner.bestFoodPriority(ranked) or nil
for _, need in ipairs(ranked) do
local choice = (ADSupplyPlanner.isFoodAllowed == nil or ADSupplyPlanner.isFoodAllowed(need, bestFood)) and findBestSource(markerStations, {need.fillType}, farmId, loadCapacity) or nil
local choice = (ADSupplyPlanner.isFoodAllowed == nil or ADSupplyPlanner.isFoodAllowed(need, bestFood)) and findBestSource(markerStations, {need.fillType}, farmId, loadCapacity, need) or nil
if choice ~= nil then
return {
markerIndex = choice.markerIndex,