Skip to content

Commit

Permalink
v6.01.00092 Bale loader unload sees bale stacks at unload point (Cour…
Browse files Browse the repository at this point in the history
…seplay#3157)

Hard coded 2 meters. Used to be a special tool setting but that is in
dire need of refactoring so leave it hard coded for now.
  • Loading branch information
pvaiko committed Feb 24, 2019
1 parent b76492d commit 5cd183c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion BaleLoaderAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ function BaleLoaderAIDriver:driveUnloadOrRefill(dt)

if self:hasTipTrigger() or nearUnloadPoint then
self:setSpeed(self.vehicle.cp.speeds.approach)
self:raycast()
if self:haveBales() and self.unloadRefillState == nil then
self.unloadRefillState = self.states.APPROACHING_UNLOAD_POINT
self:debug('Approaching unload point.')
elseif self:haveBales() and self.unloadRefillState == self.states.APPROACHING_UNLOAD_POINT then
local unloadNode = self:getUnloadNode(nearUnloadPoint, unloadPointIx)
local _, _, dz = localToLocal(self.baleLoader.cp.realUnloadOrFillNode, unloadNode, 0, 0, 0)
self:debugSparse('distance to unload point: %.1f', dz)
if math.abs(dz) < 1 then
if math.abs(dz) < 1 or self.tooCloseToOtherBales then
self:debug('Unload point reached.')
self.unloadRefillState = self.states.UNLOADING
end
Expand Down Expand Up @@ -180,6 +181,7 @@ function BaleLoaderAIDriver:getFillType()
end
end

--- Unload node is either an unload waypoint or an unload trigger
function BaleLoaderAIDriver:getUnloadNode(isUnloadpoint, unloadPointIx)
if isUnloadpoint then
self:debugSparse('manual unload point at ix = %d', unloadPointIx)
Expand All @@ -188,4 +190,26 @@ function BaleLoaderAIDriver:getUnloadNode(isUnloadpoint, unloadPointIx)
else
return self.vehicle.cp.currentTipTrigger.triggerId
end
end

--- Raycast back to stop when there's already a stack of bales at the unload point.
function BaleLoaderAIDriver:raycast()
if not self.baleLoader.cp.realUnloadOrFillNode then return end
local nx, ny, nz = localDirectionToWorld(self.baleLoader.cp.realUnloadOrFillNode, 0, 0, -1)
local x, y, z = localToWorld(self.baleLoader.cp.realUnloadOrFillNode, 0, 0, 0)
raycastClosest(x, y, z, nx, ny, nz, 'raycastCallback', 5, self)
end

function BaleLoaderAIDriver:raycastCallback(hitObjectId, x, y, z, distance, nx, ny, nz, subShapeIndex)
if hitObjectId ~= 0 then
local object = g_currentMission:getNodeObject(hitObjectId)
if object and object:isa(Bale) then
if distance < 2 then
self.tooCloseToOtherBales = true
self:debugSparse('Bale found at d=%.1f', distance)
else
self.tooCloseToOtherBales = false
end
end
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="40">
<version>6.01.00091</version>
<version>6.01.00092</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title>
<br>CoursePlay SIX</br>
Expand Down

0 comments on commit 5cd183c

Please sign in to comment.