Advertisement
billysback

Vision-finding loops that I don't like to think about

Jun 24th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. local done = {}
  2.     local temp = {{map.pos[1], map.pos[2], 0, false}}
  3.     while #temp > 0 do
  4.         local ntemp = {}
  5.         for i=1,#temp do
  6.             local x = temp[i][1]
  7.             local y = temp[i][2]
  8.             local n = temp[i][3]
  9.             local sl = temp[i][4]
  10.            
  11.             local dtyp = map[x][y][1]
  12.             if sl == false then
  13.                 for o=-1,1,2 do
  14.                     local nposs = {{x+o, y}, {x, y+o}}
  15.                     for j=1,#nposs do
  16.                         local npos = nposs[j]
  17.                         if map[npos[1]] ~= nil then
  18.                             if map[npos[1]][npos[2]] ~= nil then
  19.                                 local typ = map[npos[1]][npos[2]][1]
  20.                                 if typ == 1 or typ == 2 or typ == 3 or typ == 4 or typ == 5 or typ == 6 then
  21.                                     local ok = false
  22.                                     local stopLoop = false
  23.                                     if typ == 6 then stopLoop = true end
  24.                                     if done[npos[1]] == nil then
  25.                                         ok = true
  26.                                     else
  27.                                         if done[npos[1]][npos[2]] == nil then
  28.                                             ok = true
  29.                                         end
  30.                                     end
  31.                                     if ok then
  32.                                         if n+1 <= radius then
  33.                                             ntemp[#ntemp + 1] = {npos[1], npos[2], n+1, stopLoop}
  34.                                         end
  35.                                     end
  36.                                 end
  37.                             end
  38.                         end
  39.                     end
  40.                 end
  41.             end
  42.             if done[x] == nil then done[x] = {} end
  43.             done[x][y] = {dtyp, false, n}
  44.         end
  45.         temp = ntemp
  46.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement