feat: gylle som gødning — flåden foretrækker gyllevogn når lageret dækker mindst X % af markens behov (indstilling, 80 %), salg holder markernes resterende behov tilbage (loft 80 % af tankkapacitet), påfyldning nærmeste tank med helt læs først — 1.62.305
This commit is contained in:
@@ -309,30 +309,71 @@ end
|
||||
-- tjekkes igen i refillPlan efter påkobling).
|
||||
-- exclude (valgfri): {[wayPointId] = true} der springes over (fx et lager der er løbet tørt, mens vognen ventede)
|
||||
ADFieldWork.MIN_REFILL_STOCK_L = 500 -- eget lager skal have mindst så meget af varen for at være påfyldningssted
|
||||
|
||||
-- Bedste eget lager: nærmeste med et HELT læs (level >= capacity); ellers nærmeste med noget (brugerønske 17/10:
|
||||
-- gyllevognen skal ikke køre til en tank med 600 l og videre derfra). entries = {{id, distance, level}} -> id
|
||||
function ADFieldWork.bestRefill(entries, capacity)
|
||||
local bestFull, bestFullDistance, bestAny, bestAnyDistance = nil, math.huge, nil, math.huge
|
||||
for _, entry in ipairs(entries or {}) do
|
||||
if entry.distance < bestAnyDistance then bestAny, bestAnyDistance = entry.id, entry.distance end
|
||||
if (capacity or 0) > 0 and (entry.level or 0) >= capacity and entry.distance < bestFullDistance then
|
||||
bestFull, bestFullDistance = entry.id, entry.distance
|
||||
end
|
||||
end
|
||||
return bestFull or bestAny
|
||||
end
|
||||
|
||||
-- Sættets plads til varen (alle fyldenheder på traktor + redskaber, der tager varen)
|
||||
local function loadCapacity(vehicle, fillType)
|
||||
local capacity = 0
|
||||
pcall(function()
|
||||
local units = vehicle.getChildVehicles ~= nil and vehicle:getChildVehicles() or {vehicle}
|
||||
for _, unit in ipairs(units) do
|
||||
for index in ipairs(unit.getFillUnits ~= nil and unit:getFillUnits() or {}) do
|
||||
if unit.getFillUnitSupportsFillType ~= nil and unit:getFillUnitSupportsFillType(index, fillType) then
|
||||
capacity = capacity + (unit:getFillUnitCapacity(index) or 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
return capacity
|
||||
end
|
||||
|
||||
function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute, exclude)
|
||||
local farmId = vehicle:getOwnerFarmId()
|
||||
local best, bestDistance = nil, math.huge
|
||||
local function consider(wayPointId)
|
||||
if exclude ~= nil and wayPointId ~= nil and exclude[wayPointId] then return end
|
||||
-- -> afstand² når markøren kan bruges (findes, ikke udelukket, vej til den), ellers nil
|
||||
local function usable(wayPointId)
|
||||
if exclude ~= nil and wayPointId ~= nil and exclude[wayPointId] then return nil end
|
||||
local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil
|
||||
if wayPoint == nil then return end
|
||||
local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
|
||||
if distance < bestDistance and (skipRoute or ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId)) then
|
||||
if wayPoint == nil then return nil end
|
||||
if not (skipRoute or ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId)) then return nil end
|
||||
return (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
|
||||
end
|
||||
local function consider(wayPointId)
|
||||
local distance = usable(wayPointId)
|
||||
if distance ~= nil and distance < bestDistance then
|
||||
best, bestDistance = wayPointId, distance
|
||||
end
|
||||
end
|
||||
-- gårdens egne lagre først (stalde/tanke med gylle, lager med gødning): købes kun når intet eget findes
|
||||
-- (in-game 26/9: 7 mio. l gylle ved BGA'en, men påfyldningen ville købe ved købestationen)
|
||||
-- (in-game 26/9: 7 mio. l gylle ved BGA'en, men påfyldningen ville købe ved købestationen).
|
||||
-- Nærmeste med et helt læs først, ellers nærmeste med noget.
|
||||
local own = {}
|
||||
pcall(function()
|
||||
for _, station in pairs(g_currentMission.storageSystem:getLoadingStations()) do
|
||||
local supported = station.getAISupportedFillTypes ~= nil and station:getAISupportedFillTypes() or {}
|
||||
local isShop = station.owningPlaceable ~= nil and station.owningPlaceable.spec_buyingStation ~= nil
|
||||
if not isShop and g_currentMission.accessHandler:canFarmAccess(farmId, station) and supported[fillType]
|
||||
and (station:getFillLevel(fillType, farmId) or 0) >= ADFieldWork.MIN_REFILL_STOCK_L then
|
||||
consider(markerAtStation(adEnv, vehicle, station, station.owningPlaceable))
|
||||
local level = (not isShop and supported[fillType] and g_currentMission.accessHandler:canFarmAccess(farmId, station))
|
||||
and (station:getFillLevel(fillType, farmId) or 0) or 0
|
||||
if level >= ADFieldWork.MIN_REFILL_STOCK_L then
|
||||
local id = markerAtStation(adEnv, vehicle, station, station.owningPlaceable)
|
||||
local distance = usable(id)
|
||||
if distance ~= nil then table.insert(own, {id = id, distance = distance, level = level}) end
|
||||
end
|
||||
end
|
||||
end)
|
||||
best = ADFieldWork.bestRefill(own, loadCapacity(vehicle, fillType))
|
||||
if best ~= nil then return best end
|
||||
pcall(function()
|
||||
for _, placeable in pairs(g_currentMission.placeableSystem.placeables) do
|
||||
|
||||
Reference in New Issue
Block a user