getRaceDistance
Definition
-- @/lua/ge/extensions/scenario/scenarios.lua:272
local function getRaceDistance(scenario)
if not scenario or not scenario.lapConfig then
return 0
end
local distance = 0
-- get the last entry in the list, this is usually the last waypoint in the path
local numWaypoints = #scenario.lapConfig -- tableSize(scenario.lapConfig)
-- log('I', 'scenario.race', 'number of waypoint '..numWaypoints)
local mapDataNodes = map.getMap().nodes
for i = 1, numWaypoints - 1 do
local node1 = mapDataNodes[scenario.lapConfig[i]]
local node2 = mapDataNodes[scenario.lapConfig[i + 1]]
local pos1
if not node1 then
node1 = scenetree.findObject(scenario.lapConfig[i])
pos1 = node1:getPosition()
else
pos1 = node1.pos
end
local pos2
if not node2 then
node2 = scenetree.findObject(scenario.lapConfig[i + 1])
pos2 = node2:getPosition()
else
pos2 = node2.pos
end
-- log('I', 'scenario.race', 'node1: '..scenario.lapConfig[i])
-- log('I', 'scenario.race', 'node2: '..scenario.lapConfig[i + 1])
if node2 and node1 then
distance = distance + (pos2 - pos1):len()
else
if not node2 then
log('D', 'scenario.race', 'node2 is null: '..scenario.lapConfig[i + 1])
end
if not node1 then
log('D', 'scenario.race', 'node1 is null: '..scenario.lapConfig[i])
end
end
end
return distance
end
Callers