Skip to content

Commit 1cc5257

Browse files
authored
Merge pull request #968 from Courseplay/953-connecting-path-callstack
fix: connecting path error
2 parents f611ac7 + 34e2b2e commit 1cc5257

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,23 +610,28 @@ function AIDriveStrategyFieldWorkCourse:startConnectingPath(ix)
610610
local targetNode, zOffset = self.turnContext:getTurnEndNodeAndOffsets(steeringLength)
611611
local context = PathfinderContext(self.vehicle):allowReverse(self:getAllowReversePathfinding())
612612
context:preferredPath(connectingPath):mustBeAccurate(true)
613-
self.rawConnectingPath = Course(self.vehicle, connectingPath, true)
613+
if #connectingPath < 2 then
614+
self:debug('Connecting path has only %d waypoint, use an alignment course instead', #connectingPath)
615+
self.workStarterCourse = self:createAlignmentCourse(self.fieldWorkCourse, targetWaypointIx)
616+
else
617+
self.workStarterCourse = Course(self.vehicle, connectingPath, true)
618+
end
614619
self.pathfinderController:registerListeners(self, self.onPathfindingDoneToConnectingPathEnd,
615620
self.onPathfindingFailedToConnectingPathEnd)
616621
self:debug('Connecting path has %d waypoints, start pathfinding to target waypoint %d, zOffset %.1f',
617622
#connectingPath, targetWaypointIx, zOffset)
618623
self.state = self.states.WAITING_FOR_PATHFINDER
619624
-- to have a course set while waiting for the pathfinder and make sure that the course known to the PPC
620625
-- is the same as the one we are using
621-
self:startCourse(self.rawConnectingPath, 1)
626+
self:startCourse(self.workStarterCourse, 1)
622627
self.pathfinderController:findPathToNode(context, targetNode, 0, zOffset, 1)
623628
end
624629
end
625630

626631
function AIDriveStrategyFieldWorkCourse:onPathfindingFailedToConnectingPathEnd(controller, lastContext, wasLastRetry, currentRetryAttempt)
627632
if wasLastRetry then
628-
self:debug('Pathfinding to end of connecting path failed again, use the connecting path as is')
629-
self:startCourseToWorkStart(self.rawConnectingPath)
633+
self:debug('Pathfinding to end of connecting path failed again, use the connecting path/alignment course instead')
634+
self:startCourseToWorkStart(self.workStarterCourse)
630635
else
631636
self:debug('Pathfinding to end of connecting path failed once, retry with disabled collisions')
632637
lastContext:collisionMask(0)
@@ -639,8 +644,8 @@ function AIDriveStrategyFieldWorkCourse:onPathfindingDoneToConnectingPathEnd(con
639644
self:debug('Pathfinding to end of connecting path finished')
640645
self:startCourseToWorkStart(course)
641646
else
642-
self:debug('Pathfinding to end of connecting path failed, use the connecting path as is')
643-
self:startCourseToWorkStart(self.rawConnectingPath)
647+
self:debug('Pathfinding to end of connecting path failed, use the connecting path/alignment course instead')
648+
self:startCourseToWorkStart(self.workStarterCourse)
644649
end
645650
end
646651

0 commit comments

Comments
 (0)