feat(lager): lagerture kan aflæsse i gårdens egne fabrikker der bruger varen som input (gylle -> biogasanlæg) (v1.17.6.0)

This commit is contained in:
2026-09-24 04:41:51 +02:00
parent 73e886ee26
commit b603bd7765
8 changed files with 57 additions and 13 deletions
+30 -3
View File
@@ -42,6 +42,33 @@ local function isSilo(station, homeStation)
and placeable.spec_productionPoint == nil and (homeStation == nil or placeable ~= homeStation.owningPlaceable)
end
local function usesAsInput(placeable, fillType)
local productionPoint = placeable.spec_productionPoint ~= nil and placeable.spec_productionPoint.productionPoint or nil
for _, production in ipairs(productionPoint ~= nil and productionPoint.productions or {}) do
for _, input in ipairs(production.inputs or {}) do
if input.type == fillType then return true end
end
end
return false
end
-- Lagermål: rene siloer; med allowFactories også gårdens EGNE fabrikker der bruger varen som input
-- (fx et biogasanlæg med gyllesilo). Stalde, fremmede anlæg og hjemmet (målet selv) aldrig.
function ADLoadSwap.isStoreTarget(station, fillType, homeStation, allowFactories)
if isSilo(station, homeStation) then
return true
end
local placeable = station.owningPlaceable
if not allowFactories or placeable == nil or placeable.spec_productionPoint == nil or placeable.getHusbandryFillLevel ~= nil then
return false
end
if homeStation ~= nil and placeable == homeStation.owningPlaceable then
return false
end
local owned = ADPrices ~= nil and ADPrices.isOwnedByPlayer ~= nil and ADPrices.isOwnedByPlayer(placeable)
return owned and usesAsInput(placeable, fillType)
end
local function acceptsRest(station, fillType, rest, farmId)
if station.getIsFillTypeSupported ~= nil and not station:getIsFillTypeSupported(fillType) then
return false
@@ -70,7 +97,7 @@ function ADLoadSwap.rankDumpCandidates(candidates, avoidMarkers)
return ranked
end
function ADLoadSwap.findDumpMarker(adEnv, vehicle, fillType, rest, homeWayPointId, isReachable, excludedPlaceables, avoidMarkers)
function ADLoadSwap.findDumpMarker(adEnv, vehicle, fillType, rest, homeWayPointId, isReachable, excludedPlaceables, avoidMarkers, allowFactories)
if vehicle.rootNode == nil then
return nil, "køretøjet har ingen position"
end
@@ -82,7 +109,7 @@ function ADLoadSwap.findDumpMarker(adEnv, vehicle, fillType, rest, homeWayPointI
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId)
local isExcluded = excludedPlaceables ~= nil and excludedPlaceables[station ~= nil and station.owningPlaceable or false] == true
if station ~= nil and isSilo(station, homeStation) and not isExcluded then
if station ~= nil and ADLoadSwap.isStoreTarget(station, fillType, homeStation, allowFactories) and not isExcluded then
silos = silos + 1
if acceptsRest(station, fillType, rest, farmId) then
withSpace = withSpace + 1
@@ -105,7 +132,7 @@ function ADLoadSwap.findDumpMarker(adEnv, vehicle, fillType, rest, homeWayPointI
end
end
if silos == 0 then
return nil, "ingen silo med aflæsningsmarkør fundet (siloen skal have en AD-markør ved aflæsningstriggeren)"
return nil, allowFactories and "ingen silo eller egen fabrik der bruger varen, med aflæsningsmarkør (sæt en AD-markør ved aflæsningstriggeren)" or "ingen silo med aflæsningsmarkør fundet (siloen skal have en AD-markør ved aflæsningstriggeren)"
elseif withSpace == 0 then
return nil, string.format("%d silo(er) fundet, men ingen tager varen med plads til %.0f l", silos, rest)
end