VE Lua Documentation

Press F to search!

updateDrivabilities

Definition


-- @/lua/vehicle/mapmgr.lua:20

local function updateDrivabilities()
  -- Dynamically Change edge Drivability for the Navgraph
  if not (mapData and mapData.graph) then return end

  local changeSet = obj:getLastMailbox('updateDrivabilities')
  if changeSet == "" then return end -- mailbox is empty
  changeSet = lpack.decode(changeSet) -- changeSet format: {nodeA1, nodeB1, driv1, nodeA2, nodeB2, driv2, ...}

  local graph = mapData.graph
  for i = 1, #changeSet, 3 do
    if graph[changeSet[i]] then
      local edge = graph[changeSet[i]][changeSet[i+1]]
      local newDrivability = max(1e-30, changeSet[i+2])
      if edge and edge.drivability ~= newDrivability then
        edge.len = max(0, (edge.len - edge.gated) * edge.drivability / newDrivability + edge.gated)
        changeSet[i+2] = newDrivability - edge.drivability -- keep track of whether an edge had its drivability reduced or increased
        edge.drivability = newDrivability
      end
    end
  end

  M.changeSet = changeSet
end

Callers

@/lua/ge/map.lua

local function updateDrivabilities(changeSet)
  -- Dynamically Change edge Drivability for the Navgraph
    for objId, _ in pairs(M.objects) do
      be:queueObjectLua(objId, "mapmgr.updateDrivabilities()")
    end
@/lua/vehicle/mapmgr.lua
  mapData:import(_map.graphData)
  updateDrivabilities()
  M.mapData = mapData