Skip to content

Commit dccc21d

Browse files
authored
Merge pull request #822 from Courseplay/issue-612
Fixes bug, where the silo end is detected with a 180 degree angree fo…
2 parents 9939793 + bc502bb commit dccc21d

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

scripts/ai/strategies/AIDriveStrategyShovelSiloLoader.lua

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ function AIDriveStrategyShovelSiloLoader:getDriveData(dt, vX, vY, vZ)
297297
self.isStuckTimer:stop()
298298
end
299299
local _, _, closestObject = self.siloEndProximitySensor:getClosestObjectDistanceAndRootVehicle()
300-
local isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 2)
300+
local isEndReached, maxSpeed = false, math.huge
301+
if self.siloController:isSameDirection(self.shovelController:getShovelNode()) then
302+
--- Makes sure the silo end calculation is only used, if the driver is turned in that direction...
303+
isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 2)
304+
end
301305
self:setMaxSpeed(maxSpeed)
302306
if isEndReached then
303307
self:debug("End of the silo or heap was detected.")
@@ -647,18 +651,9 @@ function AIDriveStrategyShovelSiloLoader:startDrivingToSilo(target)
647651
local dx, _, dz = siloCourse:worldToWaypointLocal(1, vx, 0, vz)
648652
if dz < 0 and dz > -self.maxDistanceWithoutPathfinding and
649653
math.abs(dx) <= math.abs(dz) and
650-
math.abs(dx) < self.maxDistanceWithoutPathfinding * math.sqrt(2)/2 then
651-
--[[
652-
|...|
653-
|...| <- Silo
654-
-----
655-
x <- Target waypoint
656-
ooooo
657-
ooooooo <- Circle, where the pathfinding is skipped.
658-
ooooo
659-
o
660-
]]--
661-
-- TODO: Beautify the math above :)
654+
math.abs(dx) < self.maxDistanceWithoutPathfinding * math.sqrt(2)/2 and
655+
self.siloController:isSameDirection(AIUtil.getDirectionNode(self.vehicle)) then
656+
662657
self:debug("Start driving into the silo directly.")
663658
self:startCourse(siloCourse, 1)
664659
self:setNewState(self.states.DRIVING_INTO_SILO)

scripts/silo/BunkerSiloVehicleController.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ function CpBunkerSiloVehicleController:isEndReached(node, margin)
229229
return false, math.huge
230230
end
231231

232+
--- Check if the drive target direction is within 45° relative to the given node.
233+
--- @param node number
234+
--- @return boolean
235+
function CpBunkerSiloVehicleController:isSameDirection(node)
236+
if not self.drivingTarget then
237+
return false
238+
end
239+
local dx, dz = unpack(self.drivingTarget[2])
240+
local x, _, z = localToWorld(node, 0, 0, 0)
241+
return math.abs(MathUtil.getYRotationFromDirection(x - dx, z - dz)) < math.pi/2
242+
end
243+
232244
--- Generates a silo map with lines and a map with rectangle tiles.
233245
---@param width number
234246
---@param unitWidth number

0 commit comments

Comments
 (0)