diff options
author | infiniplex <infiniplex@hotmail.com> | 2013-04-24 15:53:13 -0600 |
---|---|---|
committer | Pete Hurst <pete@streamuniverse.tv> | 2013-04-26 04:35:51 +0100 |
commit | 2bf6e517d8fc587274b02438e8e99f89b1c02c26 (patch) | |
tree | 1ef96e29c8e74e42023d7cdf63e7f4b11cbb56eb /crawl-ref/source/coordit.cc | |
parent | 6b2219cf93f0c96be5923cf33475389937050397 (diff) | |
download | crawl-ref-2bf6e517d8fc587274b02438e8e99f89b1c02c26.tar.gz crawl-ref-2bf6e517d8fc587274b02438e8e99f89b1c02c26.zip |
Added dgn_connect_adjacent_rooms LUA function
Diffstat (limited to 'crawl-ref/source/coordit.cc')
-rw-r--r-- | crawl-ref/source/coordit.cc | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/crawl-ref/source/coordit.cc b/crawl-ref/source/coordit.cc index 5851283ff3..78fb358a65 100644 --- a/crawl-ref/source/coordit.cc +++ b/crawl-ref/source/coordit.cc @@ -58,12 +58,93 @@ void rectangle_iterator::operator ++() current.x++; } - void rectangle_iterator::operator++(int dummy) { ++(*this); } + +random_rectangle_iterator::random_rectangle_iterator(const coord_def& corner1, + const coord_def& corner2) +{ + int left = min(corner1.x, corner2.x); + int right = max(corner1.x, corner2.x); + int top = min(corner1.y, corner2.y); + int bottom = max(corner1.y, corner2.y); + + top_left.x = left; + top_left.y = top; + + for(int y = top; y <= bottom; y++) + for(int x = left; x <= right; x++) + remaining.push_back(coord_def(x, y)); + + if(remaining.empty()) + current = 0; + else + current = random2(remaining.size()); +} + +random_rectangle_iterator::random_rectangle_iterator(int x_border_dist, + int y_border_dist) +{ + if (y_border_dist < 0) + y_border_dist = x_border_dist; + + int right = GXM - x_border_dist - 1; + int bottom = GYM - y_border_dist - 1; + + top_left.x = x_border_dist; + top_left.y = y_border_dist; + + for(int y = y_border_dist; y <= bottom; y++) + for(int x = x_border_dist; x <= right; x++) + remaining.push_back(coord_def(x, y)); + + if(remaining.empty()) + current = 0; + else + current = random2(remaining.size()); +} + +random_rectangle_iterator::operator bool() const +{ + return !remaining.empty(); +} + +coord_def random_rectangle_iterator::operator *() const +{ + if(remaining.empty()) + return top_left; + else + return remaining[current]; +} + +const coord_def* random_rectangle_iterator::operator->() const +{ + if(remaining.empty()) + return &top_left; + else + return &(remaining[current]); +} + +void random_rectangle_iterator::operator ++() +{ + if(!remaining.empty()) + { + remaining[current] = remaining.back(); + remaining.pop_back(); + if(!remaining.empty()) + current = random2(remaining.size()); + } +} + +void random_rectangle_iterator::operator++(int dummy) +{ + ++(*this); +} + + /* * circle iterator */ |