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

Commit

Permalink
Merge pull request #3 from Courseplay/master
Browse files Browse the repository at this point in the history
Rebase
  • Loading branch information
Axel32019 authored Aug 3, 2019
2 parents 07f984b + 4b2f3a3 commit e055550
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 13 deletions.
20 changes: 19 additions & 1 deletion FieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion TrafficCollision.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions combines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion course_management.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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="40">
<version>6.01.00254</version>
<version>6.01.00256</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title>
<br>CoursePlay SIX</br>
Expand Down
11 changes: 7 additions & 4 deletions mode2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion start_stop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions traffic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion turn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions vehicles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e055550

Please sign in to comment.