feat: forsynings-miss viser hvorfor foder ikke købes (v1.62.123)
This commit is contained in:
@@ -955,25 +955,32 @@ function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z, skipRoute)
|
||||
end
|
||||
|
||||
-- Kun købestationer der sælger varen (dyrefoder som sidste udvej, 8/10). -> waypoint-id | nil
|
||||
-- -> waypoint-id | nil, diagnose {stations, withMarker, withRoute} (hvorfor intet købes — til loggen)
|
||||
function ADFieldWork.findBuyMarker(adEnv, vehicle, fillType, x, z, skipRoute)
|
||||
local best, bestDistance = nil, math.huge
|
||||
pcall(function()
|
||||
local info = {stations = 0, withMarker = 0, withRoute = 0}
|
||||
local ok, err = pcall(function()
|
||||
for _, placeable in pairs(g_currentMission.placeableSystem.placeables) do
|
||||
local spec = placeable.spec_buyingStation
|
||||
local station = spec ~= nil and spec.buyingStation or nil
|
||||
if station ~= nil and ADFieldWork.buyingSupports(station, fillType) then
|
||||
info.stations = info.stations + 1
|
||||
local wayPointId = markerAtStation(adEnv, vehicle, station, placeable)
|
||||
local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil
|
||||
if wayPoint ~= nil then
|
||||
info.withMarker = info.withMarker + 1
|
||||
local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
|
||||
if distance < bestDistance and (skipRoute or ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId)) then
|
||||
local routed = skipRoute or ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
if routed then info.withRoute = info.withRoute + 1 end
|
||||
if distance < bestDistance and routed then
|
||||
best, bestDistance = wayPointId, distance
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
return best
|
||||
if not ok then info.error = tostring(err) end
|
||||
return best, info
|
||||
end
|
||||
|
||||
-- Påfyldning undervejs (såmaskine/sprøjte/spreder): AutoDrive LOAD med hjælper = Courseplay. Når CP melder
|
||||
|
||||
Reference in New Issue
Block a user