Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/Modules/DrivePathModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ function ADDrivePathModule:reset(retainLastUsedWaypoint)
self.vehicle:setTurnLightState(Lights.TURNLIGHT_OFF)
self.distanceToTarget = math.huge
self.speedLimit = 0
-- skip resetting last used waypoint to resume looping courses from prior destination
if not retainLastUsedWaypoint then
-- skip resetting last used waypoint to resume looping courses or refuel/repair tasks from prior destination
if retainLastUsedWaypoint then
self.isResumingFromLastWayPoint = true
else
self.lastUsedWayPoint = nil
self.isResumingFromLastWayPoint = false
end
-- increase steering speed
if self.vehicle.spec_aiJobVehicle ~= nil then
Expand All @@ -56,7 +59,7 @@ function ADDrivePathModule:reset(retainLastUsedWaypoint)
end

function ADDrivePathModule:setPathTo(wayPointId)
self:reset(self.atTarget)
self:reset(self.atTarget or self.isResumingFromLastWayPoint)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't reset self.isResumingFromLastWaypoint after setting the path, which I was a bit on the fence about. This way the flag remains in case it's useful for other decisions on the same course, but if there's any places I missed where setPathTo is called without resetting if necessary then we could wind up using the last waypoint in cases where we don't intend to.

self.wayPoints = ADGraphManager:getPathTo(self.vehicle, wayPointId, self.lastUsedWayPoint)
local destination = ADGraphManager:getMapMarkerByWayPointId(self:getLastWayPointId())
self.vehicle.ad.stateModule:setCurrentDestination(destination)
Expand Down
4 changes: 2 additions & 2 deletions scripts/Specialization.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1183,13 +1183,13 @@ function AutoDrive:startAutoDrive()
end
end

function AutoDrive:stopAutoDrive()
function AutoDrive:stopAutoDrive(retainLastUsedWaypoint)

if self.isServer then
ADScheduler:removePathfinderVehicle(self)

if self.ad.stateModule:isActive() then
self.ad.drivePathModule:reset()
self.ad.drivePathModule:reset(retainLastUsedWaypoint)
self.ad.specialDrivingModule:reset()
self.ad.trailerModule:reset()

Expand Down
2 changes: 1 addition & 1 deletion scripts/Tasks/RefuelTask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function RefuelTask:finished()
self.vehicle.ad.onRouteToRefuel = #AutoDrive.getRequiredRefuels(self.vehicle, self.vehicle.ad.onRouteToRefuel) > 0
self.refuelTrigger = nil
self.wasRefuelling = false
self.vehicle:stopAutoDrive()
self.vehicle:stopAutoDrive(true) -- stop AD, but retain last used waypoint so we can resume from it
self.vehicle.ad.stateModule:getCurrentMode():start()
self.vehicle.ad.taskModule:setCurrentTaskFinished(ADTaskModule.DONT_PROPAGATE)
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/Tasks/RepairTask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ end
function RepairTask:finished()
self.vehicle.ad.onRouteToRepair = false

self.vehicle:stopAutoDrive()
self.vehicle:stopAutoDrive(true) -- stop AD, but retain last used waypoint so we can resume from it
self.vehicle.ad.stateModule:getCurrentMode():start()
self.vehicle.ad.taskModule:setCurrentTaskFinished(ADTaskModule.DONT_PROPAGATE)
end
Expand Down