From 8ec3692e20caac0782e4324ef5fc10ec558f3c6f Mon Sep 17 00:00:00 2001 From: Peter Vaiko Date: Sun, 31 Jan 2021 06:58:22 -0600 Subject: [PATCH] 6.03.00034 Convoy for lands pattern fixed 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. --- FieldworkAIDriver.lua | 15 +++++++++------ Waypoint.lua | 18 ++++++++---------- modDesc.xml | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/FieldworkAIDriver.lua b/FieldworkAIDriver.lua index dcfc8b815..3a4f95637 100644 --- a/FieldworkAIDriver.lua +++ b/FieldworkAIDriver.lua @@ -863,11 +863,12 @@ 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 @@ -875,6 +876,8 @@ function FieldworkAIDriver:manageConvoy() 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 @@ -882,7 +885,8 @@ function FieldworkAIDriver:manageConvoy() -- 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 @@ -890,7 +894,6 @@ function FieldworkAIDriver:manageConvoy() closestDistance = 0 end - -- TODO: check for change should be handled by setCpVar() self.convoyCurrentDistance=closestDistance self.convoyCurrentPosition=position self.convoyTotalMembers=total diff --git a/Waypoint.lua b/Waypoint.lua index d51a10f57..241450d2a 100644 --- a/Waypoint.lua +++ b/Waypoint.lua @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/modDesc.xml b/modDesc.xml index 6258949d8..c44cee8e2 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,6 +1,6 @@ - 6.03.00033 + 6.03.00034 <!-- 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>