diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-04-08 12:12:19 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-04-08 12:12:19 +0000 |
commit | 4f3558feb5639ff93e46a0795d94d638ef0c89fc (patch) | |
tree | 1b42eb5e474a7054dac54a5d50798914b3d99962 /crawl-ref/source/stuff.cc | |
parent | 06b226a27e7c8f2a9ce8928311fcdfcb7c6a2f79 (diff) | |
download | crawl-ref-4f3558feb5639ff93e46a0795d94d638ef0c89fc.tar.gz crawl-ref-4f3558feb5639ff93e46a0795d94d638ef0c89fc.zip |
Added Water card. Might need some rebalancing.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@4127 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stuff.cc')
-rw-r--r-- | crawl-ref/source/stuff.cc | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index b43efaa035..49f5b4f214 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -75,6 +75,106 @@ #include "tutorial.h" #include "view.h" +radius_iterator::radius_iterator( const coord_def& _center, int _radius, + bool _roguelike_metric, bool _require_los, + bool _exclude_center ) + : center(_center), radius(_radius), roguelike_metric(_roguelike_metric), + require_los(_require_los), exclude_center(_exclude_center), + iter_done(false) +{ + location.x = center.x - radius; + location.y = center.y - radius; + + if ( !this->on_valid_square() ) + ++(*this); +} + +bool radius_iterator::done() const +{ + return iter_done; +} + +coord_def radius_iterator::operator *() const +{ + return location; +} + +void radius_iterator::step() +{ + const int minx = std::max(X_BOUND_1+1, center.x - radius); + const int maxx = std::min(X_BOUND_2-1, center.x + radius); + const int maxy = std::min(Y_BOUND_2-1, center.y + radius); + + // Sweep L-R, U-D + location.x++; + if ( location.x > maxx ) + { + location.x = minx; + location.y++; + if ( location.y > maxy ) + iter_done = true; + } +} + +void radius_iterator::step_back() +{ + const int minx = std::max(X_BOUND_1+1, center.x - radius); + const int maxx = std::min(X_BOUND_2-1, center.x + radius); + const int miny = std::max(Y_BOUND_1+1, center.y - radius); + + location.x--; + if ( location.x < minx ) + { + location.x = maxx; + location.y--; + if ( location.y < miny ) + iter_done = true; // hmm + } +} + +bool radius_iterator::on_valid_square() const +{ + if ( !in_bounds(location) ) + return false; + if ( !roguelike_metric && (location - center).abs() > radius*radius ) + return false; + if ( require_los && !see_grid(location) ) + return false; + if ( exclude_center && location == center ) + return false; + return true; +} + +const radius_iterator& radius_iterator::operator++() +{ + do { + this->step(); + } while ( !this->done() && !this->on_valid_square() ); + return *this; +} + +const radius_iterator& radius_iterator::operator--() +{ + do { + this->step_back(); + } while ( !this->done() && !this->on_valid_square() ); + return *this; +} + +radius_iterator radius_iterator::operator++(int dummy) +{ + const radius_iterator copy = *this; + ++(*this); + return copy; +} + +radius_iterator radius_iterator::operator--(int dummy) +{ + const radius_iterator copy = *this; + --(*this); + return copy; +} + // Crude, but functional. std::string make_time_string( time_t abs_time, bool terse ) { |