Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
6.03.00034 Convoy for lands pattern fixed
Browse files Browse the repository at this point in the history
Fixes a minor issue when using convoy (multitool) with lands
or other patterns with wide turns where the vehicle in the front
let the one behind it pass after a turn.
  • Loading branch information
pvaiko committed Feb 4, 2021
1 parent f05fbcc commit 8ec3692
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
15 changes: 9 additions & 6 deletions FieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -863,34 +863,37 @@ function FieldworkAIDriver:manageConvoy()
local closestDistance = math.huge
for _, otherVehicle in pairs(CpManager.activeCoursePlayers) do
if otherVehicle ~= self.vehicle and otherVehicle.cp.settings.convoyActive:is(true) and self:hasSameCourse(otherVehicle) then
local myProgress = self:getProgress()
local myProgress, myWpIx = self:getProgress()
local length = self.fieldworkCourse:getLength()
local otherProgress = otherVehicle.cp.driver:getProgress()
self:debugSparse('convoy: my progress %.1f%%, other progress %.1f%%, 100%% %d',
myProgress * 100, otherProgress * 100, length)
local otherProgress, otherWpIx = otherVehicle.cp.driver:getProgress()
self:debugSparse(
'convoy: my progress at waypoint %d is %.3f%%, %s progress at waypoint %d is %.3f%%, 100%% %d m',
myWpIx, myProgress * 100, nameNum(otherVehicle), otherWpIx, otherProgress * 100, length)
total = total + 1
if myProgress < otherProgress then
position = position + 1
local distance = (otherProgress - myProgress) * length
if distance < closestDistance then
closestDistance = distance
end
self:debugSparse('convoy: my position %d, calculated distance from %s is %.3f m',
position, nameNum(otherVehicle), distance)
end
end
end

-- stop when I'm too close to the combine in front of me
if position > 1 then
if closestDistance < self.vehicle.cp.settings.convoyMinDistance:get() then
self:debugSparse('too close (%.1f) to other vehicles in convoy, holding.', closestDistance)
self:debugSparse('too close (%.1f m < %.1f) to other vehicles in convoy, holding.',
closestDistance, self.vehicle.cp.settings.convoyMinDistance:get())
self:setSpeed(0)
self:overrideAutoEngineStop()
end
else
closestDistance = 0
end

-- TODO: check for change should be handled by setCpVar()
self.convoyCurrentDistance=closestDistance
self.convoyCurrentPosition=position
self.convoyTotalMembers=total
Expand Down
18 changes: 8 additions & 10 deletions Waypoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,20 @@ function Course:enrichWaypointData()
self.headlandLength = 0
self.firstHeadlandWpIx = nil
self.firstCenterWpIx = nil
local dOnHeadland = 0
for i = 1, #self.waypoints - 1 do
self.waypoints[i].dToHere = self.length
self.waypoints[i].dToHereOnHeadland = self.headlandLength
local cx, _, cz = self:getWaypointPosition(i)
local nx, _, nz = self:getWaypointPosition(i + 1)
local dToNext = courseplay:distance(cx, cz, nx, nz)
self.waypoints[i].dToNext = dToNext
self.length = self.length + dToNext
if self:isOnHeadland(i) then
self.headlandLength = self.headlandLength + dToNext
self.firstHeadlandWpIx = self.firstHeadlandWpIx or i
dOnHeadland = dOnHeadland + dToNext
else
-- TODO: this and firstHeadlandWpIx works only if there is one block on the field and
-- no islands, as then we have more than one group of headlands. But these are only
-- TODO: this and firstHeadlandWpIx works only if there is one block on the field and
-- no islands, as then we have more than one group of headlands. But these are only
-- for the convoy mode anyway so it is ok if it does not work in all possible situations
self.firstCenterWpIx = self.firstCenterWpIx or i
end
Expand All @@ -375,9 +376,6 @@ function Course:enrichWaypointData()
elseif self.dFromLastTurn then
self.dFromLastTurn = self.dFromLastTurn + dToNext
end
self.waypoints[i].dToNext = dToNext
self.waypoints[i].dToHere = self.length
self.waypoints[i].dToHereOnHeadland = dOnHeadland
self.waypoints[i].turnsToHere = self.totalTurns
self.waypoints[i].dx, _, self.waypoints[i].dz, _ = courseplay:getWorldDirection(cx, 0, cz, nx, 0, nz)
local dx, dz = MathUtil.vector2Normalize(nx - cx, nz - cz)
Expand Down Expand Up @@ -405,7 +403,7 @@ function Course:enrichWaypointData()
self.waypoints[#self.waypoints].dx = self.waypoints[#self.waypoints - 1].dx
self.waypoints[#self.waypoints].dz = self.waypoints[#self.waypoints - 1].dz
self.waypoints[#self.waypoints].dToNext = 0
self.waypoints[#self.waypoints].dToHere = self.length + self.waypoints[#self.waypoints - 1].dToNext
self.waypoints[#self.waypoints].dToHere = self.length
self.waypoints[#self.waypoints].dToHereOnHeadland = self:isOnHeadland(#self.waypoints - 1) and
self.waypoints[#self.waypoints - 1].dToHereOnHeadland + self.waypoints[#self.waypoints - 1].dToNext or
self.waypoints[#self.waypoints - 1].dToHereOnHeadland
Expand Down Expand Up @@ -1548,9 +1546,9 @@ function Course:getProgress(ix)
-- original headland.
local dToHere = self.nonHeadlandLengthRatio * dToHereOnNonHeadland +
self.headlandLengthRatio * self.waypoints[ix].dToHereOnHeadland
return dToHere / self.originalCourseLength
return dToHere / self.originalCourseLength, ix
else
return self.waypoints[ix].dToHere / self.length
return self.waypoints[ix].dToHere / self.length, ix
end
end

2 changes: 1 addition & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="47">
<version>6.03.00033</version>
<version>6.03.00034</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title><!-- en=English de=German fr=French es=Spanish ru=Russian pl=Polish it=Italian br=Brazilian-Portuguese cs=Chinese(Simplified) ct=Chinese(Traditional) cz=Czech nl=Netherlands hu=Hungary jp=Japanese kr=Korean pt=Portuguese ro=Romanian tr=Turkish -->
<en>CoursePlay SIX</en>
Expand Down

0 comments on commit 8ec3692

Please sign in to comment.