summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dgn-shoals.cc
diff options
context:
space:
mode:
authorDarshan Shaligram <dshaligram@users.sourceforge.net>2009-12-28 06:10:16 +0530
committerDarshan Shaligram <dshaligram@users.sourceforge.net>2009-12-28 06:10:50 +0530
commit892714e8a99eb74424a3a06ad69f45f84ac9e4ca (patch)
treec05b864845e0f693d28a6eb7ee1e0e08a7124681 /crawl-ref/source/dgn-shoals.cc
parent4e6820b10db6edf0d821e785df046bcbcfa165e1 (diff)
downloadcrawl-ref-892714e8a99eb74424a3a06ad69f45f84ac9e4ca.tar.gz
crawl-ref-892714e8a99eb74424a3a06ad69f45f84ac9e4ca.zip
Fix shoals builder dying if an island is placed too close to map edge.
Diffstat (limited to 'crawl-ref/source/dgn-shoals.cc')
-rw-r--r--crawl-ref/source/dgn-shoals.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/crawl-ref/source/dgn-shoals.cc b/crawl-ref/source/dgn-shoals.cc
index c4f51753da..da0070239e 100644
--- a/crawl-ref/source/dgn-shoals.cc
+++ b/crawl-ref/source/dgn-shoals.cc
@@ -94,7 +94,9 @@ static coord_def _random_point_from(const coord_def &c, int radius,
{
const double directed_radians(
directed_angle == -1? 0.0 : _to_radians(directed_angle));
- while (true) {
+ int attempts = 70;
+ while (attempts-- > 0)
+ {
const double angle =
directed_angle == -1? _to_radians(random2(360))
: ((coinflip()? directed_radians : -directed_radians)
@@ -107,9 +109,11 @@ static coord_def _random_point_from(const coord_def &c, int radius,
return res;
}
}
+ return coord_def();
}
-static coord_def _random_point(int offset = 0) {
+static coord_def _random_point(int offset = 0)
+{
return coord_def(random_range(offset, GXM - offset - 1),
random_range(offset, GYM - offset - 1));
}
@@ -119,7 +123,8 @@ static void _shoals_island_center(const coord_def &c, int n_perturb, int radius,
{
for (int i = 0; i < n_perturb; ++i) {
coord_def p = _random_point_from(c, random2(1 + radius));
- shoals_heights(p) += random_range(bounce_low, bounce_high);
+ if (!p.origin())
+ shoals_heights(p) += random_range(bounce_low, bounce_high);
}
}
@@ -160,12 +165,12 @@ static void _shoals_build_island()
const int addition_offset = random_range(2, 10);
coord_def offsetC = _random_point_from(c, addition_offset);
-
- _shoals_island_center(offsetC, random_range(N_PERTURB_OFFSET_LOW,
- N_PERTURB_OFFSET_HIGH),
- random_range(PERTURB_OFFSET_RADIUS_LOW,
- PERTURB_OFFSET_RADIUS_HIGH),
- 25, 35);
+ if (!offsetC.origin())
+ _shoals_island_center(offsetC, random_range(N_PERTURB_OFFSET_LOW,
+ N_PERTURB_OFFSET_HIGH),
+ random_range(PERTURB_OFFSET_RADIUS_LOW,
+ PERTURB_OFFSET_RADIUS_HIGH),
+ 25, 35);
}
}