Skip to content

Commit 179f1e1

Browse files
committed
feat: restart course at the first waypoint
1 parent a699c7b commit 179f1e1

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ end
445445
--- State changes
446446
-----------------------------------------------------------------------------------------------------------------------
447447
function AIDriveStrategyFieldWorkCourse:finishFieldWork()
448-
if self.settings.returnToStart:getValue() and self.fieldWorkCourse:startsWithHeadland() then
448+
if (self.settings.returnToStart:getValue() and self.fieldWorkCourse:startsWithHeadland()) or
449+
self.settings.restartCourseAtEnd:getValue() then
449450
self:debug('Fieldwork ended, returning to first waypoint.')
450451
self.vehicle:prepareForAIDriving()
451452
self:returnToStartAfterDone()
@@ -530,9 +531,15 @@ function AIDriveStrategyFieldWorkCourse:onPathfindingDoneToReturnToStart(path)
530531
self:debug('Pathfinding to return to start finished with %d waypoints (%d ms)',
531532
#path, g_currentMission.time - (self.pathfindingStartedAt or 0))
532533
local returnCourse = Course(self.vehicle, CpMathUtil.pointsToGameInPlace(path), true)
533-
self.state = self.states.RETURNING_TO_START
534-
self.waitingForPrepare:set(true, 10000)
535-
self:startCourse(returnCourse, 1)
534+
if self.settings.restartCourseAtEnd:getValue() then
535+
self:debug('Returning to the first waypoint and then restarting the fieldwork course')
536+
self:startAlignmentTurn(self.fieldWorkCourse, 1, returnCourse)
537+
else
538+
self:debug('Returning to the first waypoint and stopping there')
539+
self.state = self.states.RETURNING_TO_START
540+
self.waitingForPrepare:set(true, 10000)
541+
self:startCourse(returnCourse, 1)
542+
end
536543
else
537544
self:debug('No path found to return to fieldwork start after work is done (%d ms), stopping job',
538545
g_currentMission.time - (self.pathfindingStartedAt or 0))

0 commit comments

Comments
 (0)