diff options
author | Neil Moore <neil@s-z.org> | 2014-02-23 20:00:19 -0500 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2014-02-23 20:02:50 -0500 |
commit | c2328442afdce263a890bf45d22657b10cd4bbe3 (patch) | |
tree | 88b01dc299ba4571bb7019085cab7e8ecfe839ec /crawl-ref/source/coordit.cc | |
parent | 7f5c0d692c6173e5e05734313882f1d5fbe9afcf (diff) | |
download | crawl-ref-c2328442afdce263a890bf45d22657b10cd4bbe3.tar.gz crawl-ref-c2328442afdce263a890bf45d22657b10cd4bbe3.zip |
Don't crash when sanctuary shrinks near the map edge
See for example:
http://crawl.lantea.net/crawl/morgue/letownia/crash-letownia-20140224-004021.txt
Introduced by 0.14-a0-622-g0c137b5, which replaced radius_iterator with
C_SQUARE by rectangle_iterator. Unfortunately, the latter did not clip
the iterator to the map. Add a flag to do so: false by default because
iterated rectangles are not always in map coordinates.
Diffstat (limited to 'crawl-ref/source/coordit.cc')
-rw-r--r-- | crawl-ref/source/coordit.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/crawl-ref/source/coordit.cc b/crawl-ref/source/coordit.cc index 17804d72ef..96efd57b7b 100644 --- a/crawl-ref/source/coordit.cc +++ b/crawl-ref/source/coordit.cc @@ -24,12 +24,23 @@ rectangle_iterator::rectangle_iterator(const coord_def& corner1, current = topleft; } -rectangle_iterator::rectangle_iterator(const coord_def& center, int halfside) +rectangle_iterator::rectangle_iterator(const coord_def& center, int halfside, + bool clip_to_map) { topleft.x = center.x - halfside; topleft.y = center.y - halfside; + if (clip_to_map) + { + topleft.x = max(topleft.x, X_BOUND_1); + topleft.y = max(topleft.y, Y_BOUND_1); + } bottomright.x = center.x + halfside; bottomright.y = center.y + halfside; + if (clip_to_map) + { + bottomright.x = min(bottomright.x, X_BOUND_2); + bottomright.y = min(bottomright.y, Y_BOUND_2); + } current = topleft; } |