Skip to content

Commit

Permalink
PR Adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Oct 10, 2023
1 parent cee2974 commit fa28060
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
13 changes: 9 additions & 4 deletions scripts/ai/AIDriveStrategyCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,15 @@ function AIDriveStrategyCourse:isCloseToCourseStart(distance)
return self.course:getDistanceFromFirstWaypoint(self.ppc:getCurrentWaypointIx()) < distance
end

--- Event raised when the driver has finished.
--- This gets called in the :stopCurrentAIJob(), as the giants code might stop the driver and not the active strategy.
function AIDriveStrategyCourse:onFinished()
self:raiseControllerEvent(self.onFinishedEvent)
--- Event raised when the driver was stopped.
---@param hasFinished boolean|nil flag passed by the info text
function AIDriveStrategyCourse:onFinished(hasFinished)
self:raiseControllerEvent(self.onFinishedEvent, hasFinished)
if hasFinished and self.settings.foldImplementAtEnd:getValue() then
--- Folds implements at the end if the setting is active.
self:debug("Finished with folding implements of the implements.")
self.vehicle:prepareForAIDriving()
end
end

--- This is to set the offsets on the course at start, or update those values
Expand Down
4 changes: 2 additions & 2 deletions scripts/ai/AIDriveStrategyFieldWorkCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ function AIDriveStrategyFieldWorkCourse:start(course, startIx, jobParameters)
end

--- Event raised when the driver has finished.
function AIDriveStrategyFieldWorkCourse:onFinished()
AIDriveStrategyFieldWorkCourse:superClass().onFinished(self)
function AIDriveStrategyFieldWorkCourse:onFinished(hasFinished)
AIDriveStrategyFieldWorkCourse:superClass().onFinished(self, hasFinished)
self.remainingTime:reset()
end

Expand Down
37 changes: 19 additions & 18 deletions scripts/ai/jobs/CpAIJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,34 @@ function CpAIJob:stop(aiMessage)
local vehicle = self.vehicleParameter:getVehicle()
vehicle:deleteAgent()
vehicle:aiJobFinished()

vehicle:resetCpAllActiveInfoTexts()
local driveStrategy = vehicle:getCpDriveStrategy()
if driveStrategy then
driveStrategy:onFinished()
if not aiMessage then
self:debug("No valid ai message given!")
if driveStrategy then
driveStrategy:onFinished()
end
return
end
end
CpAIJob:superClass().stop(self, aiMessage)
if not aiMessage then
return
end
if self.isServer then
local vehicle = self.vehicleParameter:getVehicle()
vehicle:resetCpAllActiveInfoTexts()
local releaseMessage, hasFinished, event, isOnlyShownOnPlayerStart = g_infoTextManager:getInfoTextDataByAIMessage(aiMessage)
local releaseMessage, hasFinished, event, isOnlyShownOnPlayerStart =
g_infoTextManager:getInfoTextDataByAIMessage(aiMessage)
if releaseMessage then
self:debug("Release message %s", tostring(releaseMessage))
self:debug("Stopped with release message %s", tostring(releaseMessage))
end
if releaseMessage and not vehicle:getIsControlled() and not isOnlyShownOnPlayerStart then
vehicle:setCpInfoTextActive(releaseMessage)
if driveStrategy then
driveStrategy:onFinished(hasFinished)
end
if event then
SpecializationUtil.raiseEvent(vehicle, event)
end
if hasFinished and vehicle:getCpSettings().foldImplementAtEnd:getValue() then
--- Folds implements at the end if the setting is active.
vehicle:prepareForAIDriving()
if releaseMessage and not vehicle:getIsControlled() and not isOnlyShownOnPlayerStart then
--- Only shows the info text, if the vehicle is not entered.
--- TODO: Add check if passing to ad is active maybe?
vehicle:setCpInfoTextActive(releaseMessage)
end
end
end
CpAIJob:superClass().stop(self, aiMessage)
end

--- Updates the parameter values.
Expand Down

0 comments on commit fa28060

Please sign in to comment.