diff --git a/FS25_ADSmartPickup/adWaitPool.lua b/FS25_ADSmartPickup/adWaitPool.lua index d4986db..31af1dd 100644 --- a/FS25_ADSmartPickup/adWaitPool.lua +++ b/FS25_ADSmartPickup/adWaitPool.lua @@ -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) diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 8dadbc2..bbb71f7 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.19.8.0 + 1.19.9.0 <en>AD Smart Pickup</en> diff --git a/docs/BRUGERMANUAL.md b/docs/BRUGERMANUAL.md index c6c3f57..ffd169d 100644 --- a/docs/BRUGERMANUAL.md +++ b/docs/BRUGERMANUAL.md @@ -1,6 +1,6 @@ # AD Smart Pickup — brugermanual -Version 1.19.8 · Farming Simulator 25 · tillæg til AutoDrive +Version 1.19.9 · Farming Simulator 25 · tillæg til AutoDrive *English version: [USER_MANUAL.md](USER_MANUAL.md)* diff --git a/docs/USER_MANUAL.md b/docs/USER_MANUAL.md index 5c68f5a..8c9c46d 100644 --- a/docs/USER_MANUAL.md +++ b/docs/USER_MANUAL.md @@ -1,6 +1,6 @@ # AD Smart Pickup — user manual -Version 1.19.8 · Farming Simulator 25 · add-on for AutoDrive +Version 1.19.9 · Farming Simulator 25 · add-on for AutoDrive *Dansk version: [BRUGERMANUAL.md](BRUGERMANUAL.md)* diff --git a/tests/test_adWaitPool.lua b/tests/test_adWaitPool.lua index dd5c0b2..541d731 100644 --- a/tests/test_adWaitPool.lua +++ b/tests/test_adWaitPool.lua @@ -92,5 +92,20 @@ check("W6 state driving", task.state, 2) check("W6 setPathTo", stopped.pathTo, 10) check("W6 stopUnloading", stopped.unload, true) +-- WR: AD's rutesøgning siger nej, men vejnettet har en vej fra traktorens nærmeste waypoint -> godtages +-- (in-game 24/9: 'Æg storage' ved Chicken Wait 1, "ingen vej til 'Chicken Storage Unload'" trods vej) +do + wayPoints[901] = {id = 901, x = 0, z = 0, out = {902}} + wayPoints[902] = {id = 902, x = 5, z = 0, out = {903}} + wayPoints[903] = {id = 903, x = 10, z = 0, out = {}} + wayPoints[904] = {id = 904, x = 20, z = 0, out = {}} -- ingen indgang + unreachable[903], unreachable[904] = true, true + local vehicle = {getClosestWayPoint = function() return 901, 1 end} + check("WR AD nej, vejnettet ja -> nåelig", ADWaitPool.hasRouteTo(adEnv, vehicle, 903), true) + check("WR hverken AD eller vejnet -> ikke nåelig", ADWaitPool.hasRouteTo(adEnv, vehicle, 904), false) + check("WR uden nærmeste waypoint -> AD's svar", ADWaitPool.hasRouteTo(adEnv, {}, 903), false) + unreachable[903], unreachable[904] = nil, nil +end + print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)