Skip to content

Commit

Permalink
fix: generate default course
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vaiko committed Jan 5, 2025
1 parent eb49f12 commit a0cd24b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 9 additions & 0 deletions scripts/courseGenerator/CourseGeneratorInterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,12 @@ function CourseGeneratorInterface:setCourse(vehicle, course)
vehicle:setFieldWorkCourse(course)
end

--- Generate a course for the vehicle, with start position at the vehicle's position
function CourseGeneratorInterface:generateDefaultCourse(vehicle)
local settings = vehicle:getCourseGeneratorSettings()
local x, _, z = getWorldTranslation(vehicle.rootNode)
self.logger:info(vehicle, 'Generating course at x = %.1f, z = %.1f', x, z)
self:startGeneration({x = x, z = z}, vehicle, settings, nil, function()
self.logger:info(vehicle, 'Course generation finished')
end)
end
5 changes: 1 addition & 4 deletions scripts/dev/DevHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ function DevHelper:keyEvent(unicode, sym, modifier, isDown)
-- use the Giants field boundary detector
self.vehicle:cpDetectFieldBoundary(self.data.x, self.data.z, nil, function() end)
elseif bitAND(modifier, Input.MOD_LALT) ~= 0 and isDown and sym == Input.KEY_g then
self:debug('Generate course')
local vehicle = CpUtil.getCurrentVehicle()
local settings = CpUtil.getCurrentVehicle():getCourseGeneratorSettings()
self.courseGeneratorInterface:startGeneration({x = self.data.x, z = self.data.z}, vehicle, settings, nil, function() end)
self.courseGeneratorInterface:generateDefaultCourse(CpUtil.getCurrentVehicle())
elseif bitAND(modifier, Input.MOD_LALT) ~= 0 and isDown and sym == Input.KEY_n then
self:togglePpcControlledNode()
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/specializations/CpAIWorker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function CpAIWorker:onRegisterActionEvents(isActiveForInput, isActiveForInputIgn

addActionEvent(self, InputAction.CP_GENERATE_COURSE, function (self)
if self:getCanStartCpFieldWork() then
CourseGeneratorInterface.generateDefaultCourse()
CourseGeneratorInterface():generateDefaultCourse()
end
end)
addActionEvent(self, InputAction.CP_CHANGE_SELECTED_JOB, function (self)
Expand Down Expand Up @@ -291,7 +291,7 @@ end

--- Is cp drive to field work active
function CpAIWorker:getIsCpDriveToFieldWorkActive()
if not self:getIsCpActive() then
if not self:getIsCpActive() then
return false
end
local job = self:getJob()
Expand Down

0 comments on commit a0cd24b

Please sign in to comment.