summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-26 20:33:38 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-26 20:33:38 +0000
commit46444e5e558c8cc779c90c7abe0f2f8577d51342 (patch)
treedd9cea552217107d8e264cbf9a0401b3f609b414 /crawl-ref
parent7b6bfa7d8c9922a6a690fe31db02d678bb60298b (diff)
downloadcrawl-ref-46444e5e558c8cc779c90c7abe0f2f8577d51342.tar.gz
crawl-ref-46444e5e558c8cc779c90c7abe0f2f8577d51342.zip
Use random_in_bounds() in another place, and, for paranoia's sake, check
that monsters don't run off the grid instead of the map. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8794 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/effects.cc10
-rw-r--r--crawl-ref/source/monstuff.cc12
2 files changed, 12 insertions, 10 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index b228cbe87a..3546008fa0 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -3461,7 +3461,7 @@ static void _catchup_monster_moves(monsters *mon, int turns)
const int moves = (range > 50) ? 50 : range;
// const bool short_time = (range >= 5 + random2(10));
- const bool long_time = (range >= (500 + roll_dice( 2, 500 )));
+ const bool long_time = (range >= (500 + roll_dice( 2, 500 )));
const bool ranged_attack = (mons_has_ranged_spell( mon, true )
|| mons_has_ranged_attack( mon ));
@@ -3489,7 +3489,7 @@ static void _catchup_monster_moves(monsters *mon, int turns)
{
mon->behaviour = BEH_WANDER;
mon->foe = MHITNOT;
- mon->target.set(10 + random2(GXM - 10), 10 + random2(GYM - 10));
+ mon->target = random_in_bounds();
}
else
{
@@ -3563,13 +3563,15 @@ static void _catchup_monster_moves(monsters *mon, int turns)
if (grid_is_solid(feat)
|| mgrd(next) != NON_MONSTER
|| !monster_habitable_grid(mon, feat))
+ {
break;
+ }
pos = next;
}
- if (!shift_monster( mon, pos ))
- shift_monster( mon, mon->pos() );
+ if (!shift_monster(mon, pos))
+ shift_monster(mon, mon->pos());
#if DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS, "moved to (%d,%d)", mon->pos().x, mon->pos().y );
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index b64cf0de77..c7121b398b 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -4600,11 +4600,11 @@ static void _handle_movement(monsters *monster)
mmov.reset();
}
- // Bounds check: don't let fleeing monsters try to run off the map.
+ // Bounds check: don't let fleeing monsters try to run off the grid.
const coord_def s = monster->target + mmov;
- if (!map_bounds_x(s.x))
+ if (!in_bounds_x(s.x))
mmov.x = 0;
- if (!map_bounds_y(s.y))
+ if (!in_bounds_y(s.y))
mmov.y = 0;
// Now quit if we can't move.
@@ -7145,11 +7145,11 @@ static void _handle_monster_move(int i, monsters *monster)
mmov.reset();
// Bounds check: don't let confused monsters try to run
- // off the map.
+ // off the grid.
const coord_def s = monster->pos() + mmov;
- if (!map_bounds_x(s.x))
+ if (!in_bounds_x(s.x))
mmov.x = 0;
- if (!map_bounds_y(s.y))
+ if (!in_bounds_y(s.y))
mmov.y = 0;
if (!monster->can_pass_through(monster->pos() + mmov))