Advertisement
alestane

Range scanning

Jun 15th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  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 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.     return found
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement