summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-26 15:38:40 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-26 15:38:40 +0000
commit17fb80af7acbed035921b894f2b2712f93afd670 (patch)
tree272ce229e35e326f0ad2ed492bfd5e154235ed5b
parent416bb292eb8bab5f0bb094a369921703663e5bb6 (diff)
downloadcrawl-ref-17fb80af7acbed035921b894f2b2712f93afd670.tar.gz
crawl-ref-17fb80af7acbed035921b894f2b2712f93afd670.zip
Simplify monster_random_space().
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8790 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/mstuff2.cc10
-rw-r--r--crawl-ref/source/stuff.cc20
-rw-r--r--crawl-ref/source/stuff.h5
-rw-r--r--crawl-ref/source/view.cc2
4 files changed, 16 insertions, 21 deletions
diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc
index a722dfd598..ee10088f8e 100644
--- a/crawl-ref/source/mstuff2.cc
+++ b/crawl-ref/source/mstuff2.cc
@@ -1066,20 +1066,16 @@ bool monster_random_space(const monsters *monster, coord_def& target,
int tries = 0;
while (tries++ < 1000)
{
-
if (crawl_state.arena)
{
const coord_def &ul = crawl_view.glos1; // Upper left
const coord_def &lr = crawl_view.glos2; // Lower right
- target.x = ul.x + random2(lr.x - ul.x);
- target.y = ul.y + random2(lr.y - ul.y);
+ target = coord_def(random_range(ul.x, lr.x - 1),
+ random_range(ul.y, lr.y - 1));
}
else
- {
- target.x = 10 + random2(GXM - 20);
- target.y = 10 + random2(GYM - 20);
- }
+ target = random_in_bounds();
// Don't land on top of another monster.
if (mgrd(target) != NON_MONSTER || target == you.pos())
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 1f1ab72a38..0d6368fb83 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -1244,7 +1244,7 @@ bool player_can_hear(const coord_def& p)
}
// Returns true if inside the area the player can move and dig (ie exclusive).
-bool in_bounds( int x, int y )
+bool in_bounds(int x, int y)
{
return (x > X_BOUND_1 && x < X_BOUND_2
&& y > Y_BOUND_1 && y < Y_BOUND_2);
@@ -1253,7 +1253,7 @@ bool in_bounds( int x, int y )
// Returns true if inside the area the player can map (ie inclusive).
// Note that terrain features should be in_bounds() leaving an outer
// ring of rock to frame the level.
-bool map_bounds( int x, int y )
+bool map_bounds(int x, int y)
{
return (x >= X_BOUND_1 && x <= X_BOUND_2
&& y >= Y_BOUND_1 && y <= Y_BOUND_2);
@@ -1261,22 +1261,22 @@ bool map_bounds( int x, int y )
coord_def random_in_bounds()
{
- return coord_def( random_range(MAPGEN_BORDER, GXM - MAPGEN_BORDER - 1),
- random_range(MAPGEN_BORDER, GYM - MAPGEN_BORDER - 1) );
+ return coord_def(random_range(MAPGEN_BORDER, GXM - MAPGEN_BORDER - 1),
+ random_range(MAPGEN_BORDER, GYM - MAPGEN_BORDER - 1));
}
// Returns a random location in (x_pos, y_pos)... the grid will be
// DNGN_FLOOR if clear, and NON_MONSTER if empty. Exclusive tells
// if we're using in_bounds() or map_bounds() restriction.
-void random_in_bounds( int &x_pos, int &y_pos, int terr,
- bool empty, bool excl )
+void random_in_bounds(int &x_pos, int &y_pos, int terr,
+ bool empty, bool excl)
{
bool done = false;
do
{
- x_pos = X_BOUND_1 + random2( X_WIDTH - 2 * excl ) + 1 * excl;
- y_pos = Y_BOUND_1 + random2( Y_WIDTH - 2 * excl ) + 1 * excl;
+ x_pos = X_BOUND_1 + random2(X_WIDTH - 2 * excl) + 1 * excl;
+ y_pos = Y_BOUND_1 + random2(Y_WIDTH - 2 * excl) + 1 * excl;
if (terr == DNGN_RANDOM)
done = true;
@@ -1287,7 +1287,7 @@ void random_in_bounds( int &x_pos, int &y_pos, int terr,
done = true;
else if (empty
&& mgrd[x_pos][y_pos] != NON_MONSTER
- && (coord_def(x_pos,y_pos) != you.pos()))
+ && (coord_def(x_pos, y_pos) != you.pos()))
{
done = true;
}
@@ -1298,7 +1298,7 @@ void random_in_bounds( int &x_pos, int &y_pos, int terr,
unsigned char random_colour(void)
{
return (1 + random2(15));
-} // end random_colour()
+}
unsigned char random_uncommon_colour()
{
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index a29c0c07e7..415feeaa2b 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -152,9 +152,8 @@ int yesnoquit( const char* str, bool safe = true, int safeanswer = 0,
bool allow_all = false, bool clear_after = true,
char alt_yes = 'Y', char alt_yes2 = 'Y' );
-
-bool in_bounds( int x, int y );
-bool map_bounds( int x, int y );
+bool in_bounds(int x, int y);
+bool map_bounds(int x, int y);
coord_def random_in_bounds();
inline bool in_bounds(const coord_def &p)
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index b0866f06a1..1755de2a30 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -3120,7 +3120,7 @@ static int _find_feature(int feature, int curs_x, int curs_y,
int matchcount = 0;
// Find the first occurrence of feature 'feature', spiralling around (x,y)
- int maxradius = GXM > GYM? GXM : GYM;
+ int maxradius = GXM > GYM ? GXM : GYM;
for (int radius = 1; radius < maxradius; ++radius)
for (int axis = -2; axis < 2; ++axis)
{