fix: en fabriks inputs stjæles aldrig som kilde; stalde læses via getHusbandry* (v1.6.1.0)
In-game 2026-09-22: fire Fastrac'er med halm+TMR til to kostalde kørte med 'Rotér mål: kun aflæsning' og fast pålæsning ved 'TMR Load' -> AutoDrive læssede halm (fabrikkens input) dér uden at modden var i spil. Med modden i spil ville 'mindst fyldte først' have valgt samme lager. - ADSupplyPlanner.isProductionInput: vare der er input (og ikke output) i en fabriks produktioner udelukkes som kilde i findBestSource (mappe + behov). - Stald som mål: niveau/kapacitet/understøttelse fra placeable:getHusbandry* (stationen selv siger nej til halm) -> halm rangeres og hentes. - README: to stalde = kun pålæsnings-rotation (AD vælger pickup FØR deliver roteres).
This commit is contained in:
@@ -206,6 +206,30 @@ local function getFillTypeNames(fillTypes)
|
||||
return names
|
||||
end
|
||||
|
||||
local function getProductionPoint(station)
|
||||
local placeable = station.owningPlaceable
|
||||
if placeable ~= nil and placeable.spec_productionPoint ~= nil then
|
||||
return placeable.spec_productionPoint.productionPoint
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- En fabriks læssestation udleverer også dens INPUTS (fx halm i en TMR-fabrik).
|
||||
-- Dem stjæler vi aldrig — fabrikken ville løbe tør for det, den skal bruge.
|
||||
-- Outputs (og varer der både er input og output i en kæde) må gerne hentes.
|
||||
local function isProtectedProductionInput(station, fillTypes)
|
||||
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.
|
||||
@@ -214,7 +238,8 @@ local function findBestSource(markerStations, fillTypes, farmId)
|
||||
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 ADSupplyPlanner.isBetterSource(level, best[isOwn].level, prefersFullest) then
|
||||
if level >= ADSmartPickup.MIN_USEFUL_LITERS and not isProtectedProductionInput(entry.station, fillTypes)
|
||||
and ADSupplyPlanner.isBetterSource(level, best[isOwn].level, prefersFullest) then
|
||||
best[isOwn] = {level = level, marker = entry.marker, station = entry.station, isOwn = isOwn}
|
||||
end
|
||||
end
|
||||
@@ -250,14 +275,6 @@ function ADSmartPickup.findLeastFilledPickup(adEnv, driver)
|
||||
return findBestSource(collectMarkerStations(adEnv, groupMarkers, farmId, nil), fillTypes, farmId)
|
||||
end
|
||||
|
||||
local function getProductionPoint(station)
|
||||
local placeable = station.owningPlaceable
|
||||
if placeable ~= nil and placeable.spec_productionPoint ~= nil then
|
||||
return placeable.spec_productionPoint.productionPoint
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Lagrene bag aflæsningsstationen; produktionspunkter uden targetStorages læses direkte.
|
||||
local function getTargetStorages(station)
|
||||
if station.targetStorages ~= nil and next(station.targetStorages) ~= nil then
|
||||
@@ -323,12 +340,33 @@ local function logFactoryFallbackOnce(driver, station)
|
||||
end
|
||||
end
|
||||
|
||||
-- Stalde (kostald m.fl.) holder foder/halm/vand i egne lagre bag én aflæsningsstation,
|
||||
-- der ikke nødvendigvis siger ja til alle varer. Stalden selv svarer for alle.
|
||||
local function getHusbandry(station)
|
||||
local placeable = station.owningPlaceable
|
||||
if placeable ~= nil and placeable.getHusbandryFillLevel ~= nil and placeable.getHusbandryCapacity ~= nil then
|
||||
return placeable
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function isFillTypeAccepted(station, husbandry, fillType)
|
||||
if husbandry ~= nil and husbandry.getHusbandryIsFillTypeSupported ~= nil then
|
||||
return husbandry:getHusbandryIsFillTypeSupported(fillType)
|
||||
end
|
||||
return station.getIsFillTypeSupported == nil or station:getIsFillTypeSupported(fillType)
|
||||
end
|
||||
|
||||
-- Niveau + kapacitet pr. ingrediens i aflæsningsmålets lager; demand giver forbrug/min.
|
||||
local function getTargetNeeds(station, ingredients, farmId, demand)
|
||||
local needs = {}
|
||||
local storages = getTargetStorages(station)
|
||||
local husbandry = getHusbandry(station)
|
||||
for _, fillType in ipairs(ingredients) do
|
||||
if station.getIsFillTypeSupported == nil or station:getIsFillTypeSupported(fillType) then
|
||||
if husbandry ~= nil and isFillTypeAccepted(station, husbandry, fillType) then
|
||||
local level = husbandry:getHusbandryFillLevel(fillType) or 0
|
||||
table.insert(needs, {fillType = fillType, level = level, capacity = husbandry:getHusbandryCapacity(fillType) or level, litersPerMinute = demand[fillType]})
|
||||
elseif isFillTypeAccepted(station, husbandry, fillType) then
|
||||
local level, freeSpace = 0, 0
|
||||
for _, storage in pairs(storages) do
|
||||
level = level + (storage:getFillLevel(fillType) or 0)
|
||||
|
||||
Reference in New Issue
Block a user