Skip to content

Commit

Permalink
Makes sure the vine driver always raises late and lowers early.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Mar 24, 2022
1 parent f314fb1 commit 1087621
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions scripts/ai/AIDriveStrategyFieldWorkCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ end
function AIDriveStrategyFieldWorkCourse:setAITarget()
--local dx, _, dz = localDirectionToWorld(self.vehicle:getAIDirectionNode(), 0, 0, 1)
local wp = self.ppc:getCurrentWaypoint()
local dx, dz = wp.dx, wp.dz
--- TODO: For some reason wp.dx and wp.dz are nil sometimes.
local dx, dz = wp.dx or 0, wp.dz or 0
local length = MathUtil.vector2Length(dx, dz)
dx = dx / length
dz = dz / length
Expand Down Expand Up @@ -281,7 +282,7 @@ function AIDriveStrategyFieldWorkCourse:shouldRaiseThisImplement(object, turnSta
-- if something (like a combine) does not have an AI marker it should not prevent from raising other implements
-- like the header, which does have markers), therefore, return true here
if not aiBackMarker or not aiFrontMarker then return true end
local marker = self.settings.raiseImplementLate:getValue() and aiBackMarker or aiFrontMarker
local marker = self:getImplementRaiseLate() and aiBackMarker or aiFrontMarker
-- turn start node in the back marker node's coordinate system
local _, _, dz = localToLocal(marker, turnStartNode, 0, 0, 0)
self:debugSparse('%s: shouldRaiseImplements: dz = %.1f', CpUtil.getName(object), dz)
Expand Down Expand Up @@ -342,7 +343,7 @@ function AIDriveStrategyFieldWorkCourse:shouldLowerThisImplement(object, turnEnd
local dxFront = (dxLeft + dxRight) / 2
self:debug('%s: dzLeft = %.1f, dzRight = %.1f, dzFront = %.1f, dxFront = %.1f, dzBack = %.1f, loweringDistance = %.1f, reversing %s',
CpUtil.getName(object), dzLeft, dzRight, dzFront, dxFront, dzBack, loweringDistance, tostring(reversing))
local dz = self.settings.lowerImplementEarly:getValue() and dzFront or dzBack
local dz = self:getImplementLowerEarly() and dzFront or dzBack
if reversing then
return dz < 0 , true, nil
else
Expand Down Expand Up @@ -554,6 +555,14 @@ function AIDriveStrategyFieldWorkCourse:getTurnEndForwardOffset()
return 0
end

function AIDriveStrategyFieldWorkCourse:getImplementRaiseLate()
return self.settings.raiseImplementLate:getValue()
end

function AIDriveStrategyFieldWorkCourse:getImplementLowerEarly()
return self.settings.lowerImplementEarly:getValue()
end

function AIDriveStrategyFieldWorkCourse:rememberWaypointToContinueFieldWork()
local ix = self:getBestWaypointToContinueFieldWork()
self.vehicle:rememberCpLastWaypointIx(ix)
Expand Down
8 changes: 8 additions & 0 deletions scripts/ai/AIDriveStrategyVineFieldWorkCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ end
--- Always disables turn on field.
function AIDriveStrategyVineFieldWorkCourse:isTurnOnFieldActive()
return false
end

function AIDriveStrategyVineFieldWorkCourse:getImplementRaiseLate()
return true
end

function AIDriveStrategyVineFieldWorkCourse:getImplementLowerEarly()
return true
end
8 changes: 8 additions & 0 deletions scripts/specializations/CpAIFieldWorker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,11 @@ function CpAIFieldWorker:replaceAIFieldWorkerDriveStrategies(jobParameters, star
--- Only the last driving strategy can stop the helper, while it is running.
table.insert(spec.driveStrategies, cpDriveStrategy)
end

--- Makes sure a callstack is printed, when an error appeared.
--- TODO: Might be a good idea to stop the cp helper.
local function onUpdate(vehicle, superFunc, ...)
CpUtil.try(superFunc, vehicle, ...)
end

AIFieldWorker.onUpdate = Utils.overwrittenFunction(AIFieldWorker.onUpdate, onUpdate)

0 comments on commit 1087621

Please sign in to comment.