Advertisement
alestane

Range Scanning with obstacles

Jun 18th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function character.ValidTiles(start, mapModel, range)
  2.     local found, following, current = {}, {[start] = 0}
  3.     for step = 1, range do
  4.         current, following = following, {}
  5.         for space in pairs(current) do
  6.             if space.isTraversable and (not space.Character or space == start) then
  7.                 for neighbor in neighborsInMap(space) do
  8.                     found[neighbor.yTile] = found[neighbor.yTile] or {}
  9.                     if not found[neighbor.yTile][neighbor.xTile] then
  10.                         found[neighbor.yTile][neighbor.xTile] = neighbor
  11.                         following[neighbor] = step
  12.                     end
  13.                 end
  14.             end
  15.         end
  16.     end
  17.     found[start] = nil
  18.     return found
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement