Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions scripts/ai/strategies/AIDriveStrategyShovelSiloLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ function AIDriveStrategyShovelSiloLoader:getDriveData(dt, vX, vY, vZ)
self.isStuckTimer:stop()
end
local _, _, closestObject = self.siloEndProximitySensor:getClosestObjectDistanceAndRootVehicle()
local isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 2)
local isEndReached, maxSpeed = false, math.huge
if self.siloController:isSameDirection(self.shovelController:getShovelNode()) then
--- Makes sure the silo end calculation is only used, if the driver is turned in that direction...
isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 2)
end
self:setMaxSpeed(maxSpeed)
if isEndReached then
self:debug("End of the silo or heap was detected.")
Expand Down Expand Up @@ -647,18 +651,9 @@ function AIDriveStrategyShovelSiloLoader:startDrivingToSilo(target)
local dx, _, dz = siloCourse:worldToWaypointLocal(1, vx, 0, vz)
if dz < 0 and dz > -self.maxDistanceWithoutPathfinding and
math.abs(dx) <= math.abs(dz) and
math.abs(dx) < self.maxDistanceWithoutPathfinding * math.sqrt(2)/2 then
--[[
|...|
|...| <- Silo
-----
x <- Target waypoint
ooooo
ooooooo <- Circle, where the pathfinding is skipped.
ooooo
o
]]--
-- TODO: Beautify the math above :)
math.abs(dx) < self.maxDistanceWithoutPathfinding * math.sqrt(2)/2 and
self.siloController:isSameDirection(AIUtil.getDirectionNode(self.vehicle)) then

self:debug("Start driving into the silo directly.")
self:startCourse(siloCourse, 1)
self:setNewState(self.states.DRIVING_INTO_SILO)
Expand Down
12 changes: 12 additions & 0 deletions scripts/silo/BunkerSiloVehicleController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ function CpBunkerSiloVehicleController:isEndReached(node, margin)
return false, math.huge
end

--- Check if the drive target direction is within 45° relative to the given node.
--- @param node number
--- @return boolean
function CpBunkerSiloVehicleController:isSameDirection(node)
if not self.drivingTarget then
return false
end
local dx, dz = unpack(self.drivingTarget[2])
local x, _, z = localToWorld(node, 0, 0, 0)
return math.abs(MathUtil.getYRotationFromDirection(x - dx, z - dz)) < math.pi/2
end

--- Generates a silo map with lines and a map with rectangle tiles.
---@param width number
---@param unitWidth number
Expand Down
Loading