Skip to content

Commit

Permalink
Better Bug Fix as requested
Browse files Browse the repository at this point in the history
  • Loading branch information
pops64 committed Aug 29, 2023
1 parent 1826d4c commit 2e48994
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
6 changes: 4 additions & 2 deletions scripts/ai/AIUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,10 @@ end
---@return table, number frontmost object and the distance between the front of that object and the root node of the vehicle
--- when > 0 in front of the vehicle
function AIUtil.getFirstAttachedImplement(vehicle,suppressLog)
-- by default, it is the vehicle's front
local maxDistance = vehicle.size.length / 2 + vehicle.size.lengthOffset
-- by default, it is the vehicle's front. We must do local to local due to using AI DIrection Node in the setMarkers function and the differnce in location between root and AIDirection
local _, _, maxDistance = localToLocal(vehicle.rootNode, AIUtil.getDirectionNode(vehicle), 0, 0,
vehicle.size.length / 2 + vehicle.size.lengthOffset)
--local maxDistance = vehicle.size.length / 2 + vehicle.size.lengthOffset
local firstImplement = vehicle
for _, implement in pairs(AIUtil.getAllAttachedImplements(vehicle)) do
if implement.object ~= nil then
Expand Down
20 changes: 4 additions & 16 deletions scripts/ai/Markers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ local function createMarkerIfDoesNotExist(vehicle, name, referenceNode)
end
end

local function createLinkBetweenNodes(vehicle, referenceNode, name)
createMarkerIfDoesNotExist(vehicle, name, referenceNode)
-- relink to current reference node (in case of implement change for example
unlink(g_vehicleMarkers[vehicle].name)
link(referenceNode, g_vehicleMarkers[vehicle].name)
end

-- Put a node on the back of the vehicle for easy distance checks use this instead of the root/direction node
local function setBackMarkerNode(vehicle, measuredBackDistance)
local backMarkerOffset = 0
Expand Down Expand Up @@ -78,15 +71,10 @@ local function setFrontMarkerNode(vehicle)
CpUtil.debugVehicle(CpDebug.DBG_IMPLEMENTS, vehicle, 'Using the %s\'s root node for the front marker node, %d m from root node',
CpUtil.getName(firstImplement), frontMarkerOffset)

-- If we don't have an implement on the front we must use the vehicles root node as our reference
-- We fall back to relying on vehicle lenght to deterime the front node and AI Direction Node is rarely in the center of the vehilce
-- The root node is always in the center if not there is a giants supplied offset? Maybe, would have to trace the vehicle.size.lengthOffset variable deeper
if vehicle == firstImplement then
createLinkBetweenNodes(vehicle, vehicle.rootNode, 'frontMarkerNode')
else
createLinkBetweenNodes(vehicle, AIUtil.getDirectionNode(vehicle), 'frontMarkerNode')
end

createMarkerIfDoesNotExist(vehicle, 'frontMarkerNode', AIUtil.getDirectionNode(vehicle))
-- relink to current reference node (in case of implement change for example
unlink(g_vehicleMarkers[vehicle].frontMarkerNode)
link( AIUtil.getDirectionNode(vehicle), g_vehicleMarkers[vehicle].frontMarkerNode)
setTranslation(g_vehicleMarkers[vehicle].frontMarkerNode, 0, 0, frontMarkerOffset)
g_vehicleMarkers[vehicle].frontMarkerOffset = frontMarkerOffset
end
Expand Down

0 comments on commit 2e48994

Please sign in to comment.