Skip to content

Commit

Permalink
Beatification
Browse files Browse the repository at this point in the history
  • Loading branch information
pops64 committed Aug 29, 2023
1 parent cf26f2b commit 1826d4c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions scripts/ai/Markers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ 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 @@ -70,16 +77,15 @@ local function setFrontMarkerNode(vehicle)
local firstImplement, frontMarkerOffset = AIUtil.getFirstAttachedImplement(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
createMarkerIfDoesNotExist(vehicle, 'frontMarkerNode', vehicle.rootNode)
unlink(g_vehicleMarkers[vehicle].frontMarkerNode)
link( vehicle.rootNode, g_vehicleMarkers[vehicle].frontMarkerNode)
else
createMarkerIfDoesNotExist(vehicle, 'frontMarkerNode', AIUtil.getDirectionNode(vehicle))
unlink(g_vehicleMarkers[vehicle].frontMarkerNode)
link( AIUtil.getDirectionNode(vehicle), g_vehicleMarkers[vehicle].frontMarkerNode)
createLinkBetweenNodes(vehicle, vehicle.rootNode, 'frontMarkerNode')
else
createLinkBetweenNodes(vehicle, AIUtil.getDirectionNode(vehicle), 'frontMarkerNode')
end
-- relink to current reference node (in case of implement change for example

setTranslation(g_vehicleMarkers[vehicle].frontMarkerNode, 0, 0, frontMarkerOffset)
g_vehicleMarkers[vehicle].frontMarkerOffset = frontMarkerOffset
Expand Down

0 comments on commit 1826d4c

Please sign in to comment.