From d35c05cb15fdcc7c512932fe6b9b6a528ce70a52 Mon Sep 17 00:00:00 2001 From: Peter Vaiko Date: Mon, 29 Jul 2019 06:40:49 -0500 Subject: [PATCH 1/3] 6.01.00255 Back to loading all courses at startup due to #4016 Foreign start/stop/crossing points are visible again. Still would like to not load all courses at startup but if we need this use case it seems too expensive to change. --- course_management.lua | 2 +- modDesc.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/course_management.lua b/course_management.lua index 55bffc0a9..08020389b 100644 --- a/course_management.lua +++ b/course_management.lua @@ -1392,7 +1392,7 @@ function courseplay.courses:loadCoursesAndFoldersFromXml() else table.insert(courses_without_id, course); end; - waypoints = nil; + courseplay.courses:loadCourseFromFile(course) end; end; -- END for loop diff --git a/modDesc.xml b/modDesc.xml index 552ab9f1b..768a833e3 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,6 +1,6 @@ - 6.01.00254 + 6.01.00255 <br>CoursePlay SIX</br> From 6db505b2d4670d593340b4613620411b9bb152da Mon Sep 17 00:00:00 2001 From: Peter Vaiko <github@vaiko.us> Date: Mon, 29 Jul 2019 20:27:07 -0500 Subject: [PATCH 2/3] 6.01.00256 Fixing those bale loaders/wrappers again #4022 Sorry folks, I'll get this right eventually ... --- FieldworkAIDriver.lua | 20 +++++++++++++++++++- modDesc.xml | 2 +- turn.lua | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/FieldworkAIDriver.lua b/FieldworkAIDriver.lua index 80d333030..d360c3041 100644 --- a/FieldworkAIDriver.lua +++ b/FieldworkAIDriver.lua @@ -1006,6 +1006,7 @@ function FieldworkAIDriver:getAIMarkers(object) end if not aiLeftMarker or not aiRightMarker or not aiLeftMarker then -- use the root node if there are no AI markers + -- TODO: these debug messages are shown even when CP is not driving, fix that. self:debug('%s has no AI markers, try work areas', nameNum(object)) aiLeftMarker, aiRightMarker, aiBackMarker = self:getAIMarkersFromWorkAreas(object) if not aiLeftMarker or not aiRightMarker or not aiLeftMarker then @@ -1150,10 +1151,27 @@ function FieldworkAIDriver:getAllAIImplements(object, implements) if not implements then implements = {} end for _, implement in ipairs(object:getAttachedImplements()) do -- ignore everything which has no work area - if courseplay:hasWorkAreas(implement.object) then + if self:isValidAIImplement(implement.object) then table.insert(implements, implement) end self:getAllAIImplements(implement.object, implements) end return implements +end + +-- Is this and implement we should consider when deciding when to lift/raise implements at the end/start of a row? +function FieldworkAIDriver:isValidAIImplement(object) + if courseplay:hasWorkAreas(object) then + -- has work areas, good. + return true + else + local aiLeftMarker, _, _ = self:getAIMarkers(object) + if aiLeftMarker then + -- has AI markers, good + return true + else + -- no work areas, no AI markers, can't use. + return false + end + end end \ No newline at end of file diff --git a/modDesc.xml b/modDesc.xml index 768a833e3..dc8cdeae5 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8" standalone="no" ?> <modDesc descVersion="40"> - <version>6.01.00255</version> + <version>6.01.00256</version> <author><![CDATA[Courseplay.devTeam]]></author> <title> <br>CoursePlay SIX</br> diff --git a/turn.lua b/turn.lua index ce0d21e6e..f81b5a011 100644 --- a/turn.lua +++ b/turn.lua @@ -333,7 +333,7 @@ function courseplay:turn(vehicle, dt, turnContext) --- Get the Triangle sides turnInfo.centerOffset = (turnInfo.targetDeltaX * turnInfo.direction) - turnInfo.turnRadius; local sideC = turnInfo.turnDiameter; - local sideB = turnInfo.turnRadius + turnInfo.centerOffset; + local sideB = turnInfo.turnRadius + turnInfo.centerOffset; -- which is exactly targetDeltaX, see above turnInfo.centerHeight = square(sideC^2 - sideB^2); local neededSpace = abs(turnInfo.targetDeltaZ) + turnInfo.zOffset + 1 + turnInfo.centerHeight + (turnInfo.reverseWPChangeDistance * 1.5); From 4b2f3a3e9b70ab67d7437ee530108d714d65eab0 Mon Sep 17 00:00:00 2001 From: Axel32019 <52026009+Axel32019@users.noreply.github.com> Date: Tue, 30 Jul 2019 04:03:52 +0200 Subject: [PATCH 3/3] bugfix for #4004 V1 (#4019) --- TrafficCollision.lua | 3 ++- combines.lua | 1 + mode2.lua | 11 +++++++---- register.lua | 1 + settings.lua | 1 + start_stop.lua | 4 +++- traffic.lua | 10 +++++++--- vehicles.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 66 insertions(+), 9 deletions(-) diff --git a/TrafficCollision.lua b/TrafficCollision.lua index ea2bfc000..a0604a66e 100644 --- a/TrafficCollision.lua +++ b/TrafficCollision.lua @@ -63,7 +63,8 @@ end -- so they form a snake in front of the vehicle along the path. When this snakes collides with something, the -- the onCollision() callback is triggered by the game engine function CollisionDetector:createTriggers() - if not courseplay:findAiCollisionTrigger(self.vehicle) then return end + + if not courseplay:findAiCollisionTrigger(self.vehicle) then return end -- create triggers only for enterable vehicles -- self.aiTrafficCollisionTrigger = courseplay:findAiCollisionTrigger(self.vehicle) -- if not self.aiTrafficCollisionTrigger then return end if not self.trafficCollisionTriggers then diff --git a/combines.lua b/combines.lua index 3b3959890..c832eec4e 100644 --- a/combines.lua +++ b/combines.lua @@ -259,6 +259,7 @@ function courseplay:unregisterFromCombine(vehicle, combine) vehicle.allow_follwing = false vehicle.cp.positionWithCombine = nil + courseplay:removeFromVehicleLocalIgnoreList(vehicle, combine) vehicle.cp.lastActiveCombine = vehicle.cp.activeCombine vehicle.cp.activeCombine = nil courseplay:setModeState(vehicle, 1); diff --git a/mode2.lua b/mode2.lua index c6004f5c9..307bd8f69 100644 --- a/mode2.lua +++ b/mode2.lua @@ -202,6 +202,7 @@ function courseplay:handle_mode2(vehicle, dt) if vehicle.cp.lastActiveCombine ~= nil then local distance = courseplay:distanceToObject(vehicle, vehicle.cp.lastActiveCombine) if distance > 20 or vehicle.cp.totalFillLevelPercent == 100 then + courseplay:removeFromVehicleLocalIgnoreList(vehicle, vehicle.cp.lastActiveCombine) vehicle.cp.lastActiveCombine = nil courseplay:debug(string.format("%s (%s): last combine = nil", nameNum(vehicle), tostring(vehicle.id)), 4); else @@ -323,7 +324,8 @@ function courseplay:handle_mode2(vehicle, dt) if vehicle.cp.hasDriveControl and vehicle.cp.driveControl.hasFourWD then --courseplay:setFourWheelDrive(vehicle); disabled, already moved to AIDriver end; -end + return true +end -- end handle_mode2() function courseplay:unload_combine(vehicle, dt) local curFile = "mode2.lua" @@ -1318,7 +1320,7 @@ function courseplay:unload_combine(vehicle, dt) local combine = vehicle.cp.activeCombine or vehicle.cp.lastActiveCombine local distanceToCombine = math.huge --reasons for not calling bypassing in 50m range - if combine ~= nil and (combine.cp.isChopper or vehicle.cp.driveUnloadNow or vehicle.cp.totalFillLevel >= vehicle.cp.totalCapacity) then + if combine ~= nil then distanceToCombine = courseplay:distanceToObject( vehicle, combine ) end if distanceToCombine > 50 and ((vehicle.cp.modeState == STATE_FOLLOW_TARGET_WPS and not vehicle.cp.curTarget.turn and not vehicle.cp.curTarget.rev and not vehicle.cp.isParking ) or vehicle.cp.modeState == STATE_DRIVE_TO_COMBINE) then @@ -1336,8 +1338,9 @@ function courseplay:unload_combine(vehicle, dt) lx, lz = courseplay:isTheWayToTargetFree(vehicle, lx, lz, tx, tz,dod ) end - -- courseplay:setTrafficCollision(vehicle, lx, lz,true) - courseplay:setTrafficCollisionOnField(vehicle, lx, lz,false) + courseplay:addToVehicleLocalIgnoreList(vehicle, combine) + + courseplay:setTrafficCollisionOnField(vehicle, lx, lz,false,distanceToCombine) if math.abs(vehicle.lastSpeedReal) < 0.0001 and not g_currentMission.missionInfo.stopAndGoBraking then if not moveForwards then diff --git a/register.lua b/register.lua index e2e6dcce3..09a7b15e4 100644 --- a/register.lua +++ b/register.lua @@ -172,6 +172,7 @@ function courseplay:vehicleDelete() courseplay:unregisterFromCombine(courseplayer, self) end if courseplayer.cp.lastActiveCombine and courseplayer.cp.lastActiveCombine == self then + courseplay:removeFromVehicleLocalIgnoreList(self, courseplayer.cp.lastActiveCombine) courseplayer.cp.lastActiveCombine = nil end end diff --git a/settings.lua b/settings.lua index 8de3adad3..940be8bcb 100644 --- a/settings.lua +++ b/settings.lua @@ -675,6 +675,7 @@ function courseplay:removeActiveCombineFromTractor(vehicle) if vehicle.cp.activeCombine ~= nil then courseplay:unregisterFromCombine(vehicle, vehicle.cp.activeCombine); end; + courseplay:removeFromVehicleLocalIgnoreList(vehicle, vehicle.cp.lastActiveCombine) vehicle.cp.lastActiveCombine = nil; courseplay.hud:setReloadPageOrder(vehicle, 4, true); end; diff --git a/start_stop.lua b/start_stop.lua index 7f2e304f7..e8b7aecdd 100644 --- a/start_stop.lua +++ b/start_stop.lua @@ -715,7 +715,9 @@ function courseplay:stop(self) if self.cp.takeOverSteering then self.cp.takeOverSteering = false end - + + courseplay:removeFromVehicleLocalIgnoreList(vehicle, self.cp.activeCombine) + courseplay:removeFromVehicleLocalIgnoreList(vehicle, self.cp.lastActiveCombine) courseplay:releaseCombineStop(self) self.cp.BunkerSiloMap = nil self.cp.mode9TargetSilo = nil diff --git a/traffic.lua b/traffic.lua index 7b7bfdc2a..7a0d1f179 100644 --- a/traffic.lua +++ b/traffic.lua @@ -172,7 +172,11 @@ function courseplay:updateCollisionVehicle(vehicle) courseplay:debug(string.format(" setting vehicle.cp.collidingVehicleId to %d (%s)",currentCollisionVehicleId,tostring(getName(currentCollisionVehicleId))), 3); end vehicle.cp.collidingVehicleId = currentCollisionVehicleId - + if vehicle.cp.collidingVehicleId ~= nil then + courseplay.debugVehicle(3, vehicle, 'updateCollisionVehicle: vehicle.cp.collidingVehicleId = %d (%s)',vehicle.cp.collidingVehicleId, getName(vehicle.cp.collidingVehicleId)) + else + courseplay.debugVehicle(3, vehicle, 'updateCollisionVehicle: vehicle.cp.collidingVehicleId is nil') + end; end function courseplay:checkTraffic(vehicle, displayWarnings, allowedToDrive) @@ -337,7 +341,7 @@ function courseplay:removeLegacyCollisionTriggers(vehicle) return ret; end -function courseplay:setTrafficCollisionOnField(vehicle, lx, lz, disableLongCheck) +function courseplay:setTrafficCollisionOnField(vehicle, lx, lz, disableLongCheck, distanceToCombine) local steeringfactor = 0.25; local colDirX = lx; local colDirZ = lz; @@ -346,7 +350,7 @@ function courseplay:setTrafficCollisionOnField(vehicle, lx, lz, disableLongCheck courseplay:setCollisionDirection(vehicle.cp.DirectionNode, vehicle.cp.trafficCollisionTriggers[1], colDirX * steeringfactor, colDirZ * steeringfactor); local recordNumber = vehicle.cp.waypointIndex for i=2,vehicle.cp.numTrafficCollisionTriggers do -- continue with i=2 for the rest of the colli boxes - if disableLongCheck or recordNumber + i >= vehicle.cp.numWaypoints then + if disableLongCheck or (distanceToCombine) < ((i+2) * 5) then courseplay:setCollisionDirection(vehicle.cp.trafficCollisionTriggers[i-1], vehicle.cp.trafficCollisionTriggers[i], 0, -1); else courseplay:setCollisionDirection(vehicle.cp.trafficCollisionTriggers[i-1], vehicle.cp.trafficCollisionTriggers[i], 0, 1); diff --git a/vehicles.lua b/vehicles.lua index f4345c35a..9cf1b84f9 100644 --- a/vehicles.lua +++ b/vehicles.lua @@ -1559,3 +1559,47 @@ function courseplay:findAiCollisionTrigger(vehicle) return ret; end + +--[[ +remove the targetVehicle and all its components and attached implements to the local collision ignore list of the vehicle +]] +function courseplay:removeFromVehicleLocalIgnoreList(vehicle, targetVehicle) + if vehicle and targetVehicle and vehicle.cpTrafficCollisionIgnoreList then + + vehicle.cpTrafficCollisionIgnoreList[targetVehicle.rootNode] = nil; + + -- TRAFFIC COLLISION IGNORE LIST (components) + if targetVehicle.components ~= nil then + courseplay:debug(('%s: removing %q (%q) components to cpTrafficCollisionIgnoreList'):format(nameNum(vehicle), nameNum(targetVehicle), tostring(targetVehicle.cp.xmlFileName)), 3); + for i,component in pairs(targetVehicle.components) do + vehicle.cpTrafficCollisionIgnoreList[component.node] = nil; + end; + end; + -- CHECK ATTACHED IMPLEMENTS + for k,impl in pairs(targetVehicle:getAttachedImplements()) do + courseplay:removeFromVehicleLocalIgnoreList(vehicle, impl.object); + end; + end; +end + +--[[ +add the targetVehicle and all its components and attached implements to the local collision ignore list of the vehicle +]] +function courseplay:addToVehicleLocalIgnoreList(vehicle, targetVehicle) + if vehicle and targetVehicle and vehicle.cpTrafficCollisionIgnoreList then + + vehicle.cpTrafficCollisionIgnoreList[targetVehicle.rootNode] = true; + + -- TRAFFIC COLLISION IGNORE LIST (components) + if targetVehicle.components ~= nil then + courseplay:debug(('%s: adding %q (%q) components to cpTrafficCollisionIgnoreList'):format(nameNum(vehicle), nameNum(targetVehicle), tostring(targetVehicle.cp.xmlFileName)), 3); + for i,component in pairs(targetVehicle.components) do + vehicle.cpTrafficCollisionIgnoreList[component.node] = true; + end; + end; + -- CHECK ATTACHED IMPLEMENTS + for k,impl in pairs(targetVehicle:getAttachedImplements()) do + courseplay:addToVehicleLocalIgnoreList(vehicle, impl.object); + end; + end; +end \ No newline at end of file