diff options
author | Jude Brown <bookofjude@users.sourceforge.net> | 2009-11-21 18:46:52 +1000 |
---|---|---|
committer | Jude Brown <bookofjude@users.sourceforge.net> | 2009-11-21 18:47:16 +1000 |
commit | e077609ef9f797916eaf79c4818231b2dff3c6f5 (patch) | |
tree | d519d90808f0287da74df522130fd37fe6144e2d | |
parent | 4ac8908825d1c21a7bc7e0fb652bdf553db52aa4 (diff) | |
download | crawl-ref-e077609ef9f797916eaf79c4818231b2dff3c6f5.tar.gz crawl-ref-e077609ef9f797916eaf79c4818231b2dff3c6f5.zip |
Some clean up of Lua iterator code.
-rw-r--r-- | crawl-ref/source/dat/clua/iter.lua | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/crawl-ref/source/dat/clua/iter.lua b/crawl-ref/source/dat/clua/iter.lua index 568fed991b..95bdc863e3 100644 --- a/crawl-ref/source/dat/clua/iter.lua +++ b/crawl-ref/source/dat/clua/iter.lua @@ -110,20 +110,17 @@ end -- los_iterator ------------------------------------------------------------------------------- -function iter.los_iterator (include_center, filter, center) - local y_x, y_y - if center == nil then - y_x, y_y = you.pos() - else +function iter.los_iterator (ic, filter, center) + local y_x, y_y = you.pos() + + if center ~= nil then y_x, y_y = center:xy() end + + local include_center = ic or false local top_corner = dgn.point(y_x - 8, y_y - 8) local bottom_corner = dgn.point(y_x + 8, y_y + 8) - if include_center ~= true then - include_center = false - end - local function check_los (point) local _x, _y = point:xy() @@ -137,13 +134,13 @@ function iter.los_iterator (include_center, filter, center) return include_center end - if you.see_cell(_x, _y) then - return true - else + if not you.see_cell(_x, _y) then return false end + return true end + return iter.rect_iterator(top_corner, bottom_corner, check_los) end @@ -151,19 +148,16 @@ end -- adjacent_iterator ------------------------------------------------------------------------------- -function iter.adjacent_iterator (include_center, filter, center) - local y_x, y_y - if center == nil then - y_x, y_y = you.pos() - else +function iter.adjacent_iterator (ic, filter, center) + local y_x, y_y = you.pos() + + if center ~= nil then y_x, y_y = center:xy() end + local top_corner = dgn.point(y_x - 1, y_y - 1) local bottom_corner = dgn.point(y_x + 1, y_y + 1) - - if include_center ~= true then - include_center = false - end + local include_center = ic or false local function check_adj (point) local _x, _y = point:xy() @@ -180,6 +174,7 @@ function iter.adjacent_iterator (include_center, filter, center) return true end + return iter.rect_iterator(top_corner, bottom_corner, check_adj) end @@ -187,25 +182,21 @@ end -- circle_iterator ------------------------------------------------------------------------------- -function iter.circle_iterator (radius, include_center, filter, center) +function iter.circle_iterator (radius, ic, filter, center) if radius == nil then error("circle_iterator needs a radius") end - local y_x, y_y - - if include_center ~= true then - include_center = false - end + local y_x, y_y = you.pos() - if center == nil then - y_x, y_y = you.pos() - else + if center ~= nil then y_x, y_y = center:xy() end + local include_center = ic or false local top_corner = dgn.point(y_x - radius, y_y - radius) local bottom_corner = dgn.point(y_x + radius, y_y + radius) + local function check_dist (point) local _x, _y = point:xy() local dist = dgn.distance(y_x, y_y, _x, _y) @@ -226,6 +217,6 @@ function iter.circle_iterator (radius, include_center, filter, center) return true end + return iter.rect_iterator(top_corner, bottom_corner, check_dist) end - |