feat: læs på vej tælles med — flere traktorer til samme stald fordeler sig på varer og stalde (v1.14.1.0)
This commit is contained in:
@@ -49,6 +49,9 @@ local supplyState = setmetatable({}, {__mode = "k"})
|
||||
-- køretøj -> {station, fillTypes}: siloen moden sendte køretøjet til på denne tur.
|
||||
local activePickups = setmetatable({}, {__mode = "k"})
|
||||
-- køretøj -> senest loggede valg (AutoDrive spørger flere gange pr. start).
|
||||
-- køretøj -> {wayPointId, fillType, liters}: læs traktoren er på vej med (fordeler flere traktorer til
|
||||
-- samme mål; ryddes ved aflæsning, stop eller ny tur)
|
||||
local enRoute = setmetatable({}, {__mode = "k"})
|
||||
local lastLogged = setmetatable({}, {__mode = "k"})
|
||||
|
||||
-- Cross-mod adgang: FS25-mods er sandboxede; AutoDrives globals ligger
|
||||
@@ -436,7 +439,7 @@ local function getFoodPriority(station, fillType)
|
||||
end
|
||||
local capacity = foodSpec.capacity or 0
|
||||
local troughScore = capacity > 0 and math.max(0, capacity - total) / capacity or 0
|
||||
return troughScore, foodFillTypes[fillType]
|
||||
return troughScore, foodFillTypes[fillType], capacity
|
||||
end
|
||||
|
||||
-- En stald kan MODTAGE foder, halm og vand — ikke sine egne outputs (mælk, gødning, gylle),
|
||||
@@ -508,16 +511,49 @@ local function getTargetNeeds(station, ingredients, farmId, demand)
|
||||
for _, fillType in ipairs(ingredients) do
|
||||
local level, capacity = getTargetLevelAndCapacity(station, fillType, farmId)
|
||||
if level ~= nil then
|
||||
local troughScore, priority = getFoodPriority(station, fillType)
|
||||
table.insert(needs, {fillType = fillType, level = level, capacity = capacity, litersPerMinute = demand[fillType], scoreOverride = troughScore, priority = priority})
|
||||
local troughScore, priority, troughCapacity = getFoodPriority(station, fillType)
|
||||
table.insert(needs, {fillType = fillType, level = level, capacity = capacity, litersPerMinute = demand[fillType], scoreOverride = troughScore, priority = priority, troughCapacity = troughCapacity})
|
||||
end
|
||||
end
|
||||
return needs
|
||||
end
|
||||
|
||||
-- Til fanen: samme rangering som valget bruger (uden vogn-størrelse). Fulde varer sidst.
|
||||
function ADSmartPickup.getTargetNeedsRanked(station, fillTypes, farmId)
|
||||
-- ---- læs på vej ----
|
||||
|
||||
function ADSmartPickup.setEnRoute(vehicle, wayPointId, fillType, liters)
|
||||
if wayPointId == nil or fillType == nil or liters == nil or liters <= 0 then
|
||||
enRoute[vehicle] = nil
|
||||
return
|
||||
end
|
||||
enRoute[vehicle] = {wayPointId = wayPointId, fillType = fillType, liters = liters}
|
||||
end
|
||||
|
||||
function ADSmartPickup.clearEnRoute(vehicle)
|
||||
enRoute[vehicle] = nil
|
||||
end
|
||||
|
||||
function ADSmartPickup.resetEnRoute()
|
||||
enRoute = setmetatable({}, {__mode = "k"})
|
||||
end
|
||||
|
||||
-- {[fillType] = liter} som ANDRE (aktive) traktorer er på vej med til målet.
|
||||
function ADSmartPickup.getPending(wayPointId, excludeVehicle)
|
||||
local pending = {}
|
||||
for vehicle, entry in pairs(enRoute) do
|
||||
if vehicle ~= excludeVehicle and entry.wayPointId == wayPointId then
|
||||
pending[entry.fillType] = (pending[entry.fillType] or 0) + entry.liters
|
||||
end
|
||||
end
|
||||
return pending
|
||||
end
|
||||
|
||||
-- pending (valgfri): læs på vej til målet, lægges oven i (fanen og mål-valget mellem stalde).
|
||||
function ADSmartPickup.getTargetNeedsRanked(station, fillTypes, farmId, pending)
|
||||
local needs = getTargetNeeds(station, fillTypes, farmId, {})
|
||||
if pending ~= nil and next(pending) ~= nil then
|
||||
needs = ADSupplyPlanner.applyPending(needs, pending)
|
||||
end
|
||||
local ranked = ADSupplyPlanner.rankNeeds(needs)
|
||||
local seen = {}
|
||||
for _, need in ipairs(ranked) do seen[need.fillType] = true end
|
||||
@@ -593,7 +629,8 @@ function ADSmartPickup.findSupplyPickup(adEnv, driver, ingredients, targetWayPoi
|
||||
local allMarkers = adEnv.ADGraphManager:getMapMarkers()
|
||||
local markerStations = collectMarkerStations(adEnv, allMarkers, farmId, target.owningPlaceable)
|
||||
local loadCapacity = getLoadCapacity(adEnv, driver)
|
||||
local ranked = ADSupplyPlanner.rankNeeds(getTargetNeeds(target, ingredients, farmId, demand), loadCapacity)
|
||||
local needs = ADSupplyPlanner.applyPending(getTargetNeeds(target, ingredients, farmId, demand), ADSmartPickup.getPending(wayPointId, driver))
|
||||
local ranked = ADSupplyPlanner.rankNeeds(needs, loadCapacity)
|
||||
-- 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
|
||||
@@ -602,6 +639,9 @@ function ADSmartPickup.findSupplyPickup(adEnv, driver, ingredients, targetWayPoi
|
||||
return {
|
||||
markerIndex = choice.markerIndex,
|
||||
markerId = choice.markerId,
|
||||
targetWayPointId = wayPointId,
|
||||
-- det der reelt kommer af: vognen, kildens beholdning og målets fri plads sætter grænsen
|
||||
pendingLiters = math.min(loadCapacity or math.huge, choice.level or math.huge, need.freeSpace or math.huge),
|
||||
markerName = choice.markerName,
|
||||
group = choice.group,
|
||||
level = choice.level,
|
||||
@@ -619,6 +659,7 @@ end
|
||||
|
||||
local function applySupplyChoice(driver, ingredients, choice)
|
||||
local stateModule = driver.ad.stateModule
|
||||
ADSmartPickup.setEnRoute(driver, choice.targetWayPointId, choice.fillType, choice.pendingLiters)
|
||||
stateModule:setFillType(choice.fillType)
|
||||
stateModule.selectedFillTypes = {choice.fillType}
|
||||
stateModule:raiseDirtyFlag()
|
||||
@@ -687,6 +728,7 @@ end
|
||||
|
||||
-- Samlet valg: behovsstyret med ingrediensliste, ellers mappe-logik. nil = AutoDrives original.
|
||||
function ADSmartPickup.choosePickup(adEnv, driver)
|
||||
enRoute[driver] = nil -- ny tur: forrige læs er leveret (eller opgivet)
|
||||
chooseRunTarget(adEnv, driver)
|
||||
local ingredients = ADSmartPickup.getIngredientsFor(adEnv, driver)
|
||||
if ingredients == nil then
|
||||
@@ -913,6 +955,12 @@ local function restoreStoppedVehicles()
|
||||
activePickups[vehicle] = nil
|
||||
end
|
||||
end
|
||||
for vehicle in pairs(enRoute) do
|
||||
local stateModule = vehicle.ad ~= nil and vehicle.ad.stateModule or nil
|
||||
if stateModule == nil or stateModule.isActive == nil or not stateModule:isActive() then
|
||||
enRoute[vehicle] = nil
|
||||
end
|
||||
end
|
||||
for vehicle, state in pairs(supplyState) do
|
||||
local stateModule = vehicle.ad ~= nil and vehicle.ad.stateModule or nil
|
||||
if stateModule == nil or not stateModule:isActive() then
|
||||
|
||||
Reference in New Issue
Block a user