fix(rute): reserve-søgning gennem vejnettet fra traktorens nærmeste waypoint når AD's getPathTo siger nej trods vej (Æg storage -> Chicken Storage Unload) (v1.19.9.0)
This commit is contained in:
@@ -92,12 +92,54 @@ end
|
||||
|
||||
-- Sendes AutoDrive mod et punkt uden rute, viser den "cannot reach" og slukker sig selv.
|
||||
-- getPathTo/pathFromTo er rene opslag uden bivirkninger.
|
||||
-- Reserve: bredde-først gennem vejnettets udgange fra traktorens nærmeste waypoint. AD's getPathTo kan
|
||||
-- sige nej trods en vej (set ved et Wait-punkt: ruten fandtes fra alle omkringliggende waypoints).
|
||||
ADWaitPool.GRAPH_SEARCH_LIMIT = 50000
|
||||
local loggedFallback = {}
|
||||
|
||||
local function graphReaches(adEnv, vehicle, targetId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if vehicle.getClosestWayPoint == nil or graph.getWayPointById == nil then
|
||||
return false
|
||||
end
|
||||
local ok, startId = pcall(vehicle.getClosestWayPoint, vehicle)
|
||||
if not ok or startId == nil then
|
||||
return false
|
||||
end
|
||||
local seen, queue, head = {[startId] = true}, {startId}, 1
|
||||
while queue[head] ~= nil and head <= ADWaitPool.GRAPH_SEARCH_LIMIT do
|
||||
local id = queue[head]
|
||||
head = head + 1
|
||||
if id == targetId then
|
||||
return true
|
||||
end
|
||||
local wayPoint = graph:getWayPointById(id)
|
||||
for _, nextId in ipairs(wayPoint ~= nil and wayPoint.out or {}) do
|
||||
if not seen[nextId] then
|
||||
seen[nextId] = true
|
||||
table.insert(queue, nextId)
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function ADWaitPool.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if graph.getPathTo == nil then
|
||||
return true
|
||||
end
|
||||
return pathReaches(graph:getPathTo(vehicle, wayPointId), wayPointId)
|
||||
if pathReaches(graph:getPathTo(vehicle, wayPointId), wayPointId) then
|
||||
return true
|
||||
end
|
||||
if graphReaches(adEnv, vehicle, wayPointId) then
|
||||
if not loggedFallback[wayPointId] and Logging ~= nil and Logging.info ~= nil then
|
||||
loggedFallback[wayPointId] = true
|
||||
Logging.info("ADSmartPickup: AutoDrives rutesøgning fandt ingen vej til markør %s, men vejnettet har en — godtages", tostring(wayPointId))
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function ADWaitPool.hasRouteBothWays(adEnv, vehicle, toWayPointId, homeWayPointId)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.19.8.0</version>
|
||||
<version>1.19.9.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user