summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dungeon.cc
diff options
context:
space:
mode:
authorDavid Lawrence Ramsey <dolorous@users.sourceforge.net>2009-11-05 11:07:40 -0600
committerDavid Lawrence Ramsey <dolorous@users.sourceforge.net>2009-11-05 11:12:50 -0600
commitcf225c256f67b33f96a04c243f7c88ba23168664 (patch)
treef815dfbb1562b957f700785909c882ebf870a0a6 /crawl-ref/source/dungeon.cc
parent48f785a271089f4f85bdfb5624b56b433e0ebd13 (diff)
downloadcrawl-ref-cf225c256f67b33f96a04c243f7c88ba23168664.tar.gz
crawl-ref-cf225c256f67b33f96a04c243f7c88ba23168664.zip
Clean up random coordinate usage a bit.
Specifically, use random_in_bounds() in a few places instead of random ranges involving X_BOUND and Y_BOUND values. The former won't return any coordinates in the dungeon's map border (which acts as a wall), but the latter will, and all the changed places are looking for empty dungeon squares, so this should make these operations more efficient.
Diffstat (limited to 'crawl-ref/source/dungeon.cc')
-rw-r--r--crawl-ref/source/dungeon.cc32
1 files changed, 12 insertions, 20 deletions
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index 6518683197..17d488a8e9 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -2962,16 +2962,13 @@ static void _place_fog_machines(int level_number)
static void _place_specific_feature(dungeon_feature_type feat)
{
- int sx, sy;
+ coord_def c;
do
- {
- sx = random_range(X_BOUND_1 + 1, X_BOUND_2 - 1);
- sy = random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1);
- }
- while (grd[sx][sy] != DNGN_FLOOR || mgrd[sx][sy] != NON_MONSTER);
+ c = random_in_bounds();
+ while (grd(c) != DNGN_FLOOR || mgrd(c) != NON_MONSTER);
- grd[sx][sy] = feat;
+ grd(c) = feat;
}
static void _place_specific_stair(dungeon_feature_type stair,
@@ -4422,7 +4419,7 @@ static bool _build_vaults(int level_number, const map_def *vault,
_dig_vault_loose(place, target_connections);
}
- unsigned char pos_x, pos_y;
+ coord_def pos;
for (stx = 0; stx < 10; stx++)
stair_exist[stx] = 0;
@@ -4457,13 +4454,10 @@ static bool _build_vaults(int level_number, const map_def *vault,
int tries = 10000;
do
- {
- pos_x = random_range(X_BOUND_1 + 1, X_BOUND_2 - 1);
- pos_y = random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1);
- }
- while ((grd[pos_x][pos_y] != DNGN_FLOOR
- || (!is_layout && pos_x >= v1x && pos_x <= v2x
- && pos_y >= v1y && pos_y <= v2y))
+ pos = random_in_bounds();
+ while ((grd(pos) != DNGN_FLOOR
+ || (!is_layout && pos.x >= v1x && pos.x <= v2x
+ && pos.y >= v1y && pos.y <= v2y))
&& tries-- > 0);
@@ -4476,11 +4470,10 @@ static bool _build_vaults(int level_number, const map_def *vault,
"(layout: %s) failed",
place.map.name.c_str(), is_layout? "yes" : "no");
#endif
- pos_x = you.pos().x;
- pos_y = you.pos().y;
+ pos = you.pos();
}
- grd[pos_x][pos_y] = stair;
+ grd(pos) = stair;
}
return (true);
@@ -5627,8 +5620,7 @@ static void _place_shops(int level_number, int nshops)
do
{
- shop_place.set(random_range(X_BOUND_1 + 1, X_BOUND_2 - 1),
- random_range(Y_BOUND_1 + 1, Y_BOUND_2 - 1));
+ shop_place = random_in_bounds();
timeout++;