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,
+25
View File
@@ -95,6 +95,31 @@ end
-- Er varen et INPUT til fabrikken (og ikke også et output)? Så må den aldrig
-- hentes derfra — det ville tømme fabrikken for det, den skal bruge.
-- Fabriksinput som foderkilde (brugervalg 8/10, regel 3): frit når fabrikken har mindst INPUT_RESERVE_HOURS forbrug
-- tilbage efter læsset; ellers kun når dyrenes trug er næsten tomt (need.score = trugets fri andel). In-game 8/10:
-- savegame6 havde 6,6 mio. l hø og 2,5 mio. l ensilage som TMR-/fermentor-input, og fårene sultede.
ADSupplyPlanner.INPUT_RESERVE_HOURS = 24
ADSupplyPlanner.STARVING_TROUGH_FREE = 0.9
-- Fabrikkens forbrug af varen i l/min (alle produktioner der bruger den).
function ADSupplyPlanner.inputUsePerMinute(productions, fillType)
local perMinute = 0
for _, production in ipairs(productions or {}) do
local cyclesPerMinute = production.cyclesPerMinute or ((production.cyclesPerHour or 0) / 60)
for _, input in ipairs(production.inputs or {}) do
if input.type == fillType then perMinute = perMinute + (input.amount or 0) * cyclesPerMinute end
end
end
return perMinute
end
-- level = kildens lager, load = vognens læs, perMinute = fabrikkens forbrug, need (valgfri) = målets behov.
function ADSupplyPlanner.mayTakeInput(level, load, perMinute, need)
local reserve = (perMinute or 0) * 60 * ADSupplyPlanner.INPUT_RESERVE_HOURS
if (level or 0) - (load or 0) >= reserve then return true end
return need ~= nil and need.trough == true and (need.score or 0) >= ADSupplyPlanner.STARVING_TROUGH_FREE
end
function ADSupplyPlanner.isProductionInput(productions, fillType)
local isInput, isOutput = false, false
for _, production in ipairs(productions) do
+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.92.0</version>
<version>1.62.93.0</version>
<title>
<en>AD Smart Pickup</en>
</title>