summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/effects.cc
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-26 21:24:35 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-26 21:24:35 +0000
commit229eb5e575daec5bbf7a099a5461fc009d6abfdc (patch)
tree2f4ce48f1ad00526c295285f252746fa11d7bfcb /crawl-ref/source/effects.cc
parente98f2b79cc1189f7c6e426bca8fc79e6e8f8a107 (diff)
downloadcrawl-ref-229eb5e575daec5bbf7a099a5461fc009d6abfdc.tar.gz
crawl-ref-229eb5e575daec5bbf7a099a5461fc009d6abfdc.zip
Properly do bounds checks in _catchup_monster_moves(). After a short
time between levels, monsters with ranged attacks were shifting their target without checking it afterwards with in_bounds(), and all monsters were later making their "dirt simple movement" and checking it with the equivalent of map_bounds() instead of in_bounds(). I believe this should finally fix [2488905]. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8799 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/effects.cc')
-rw-r--r--crawl-ref/source/effects.cc23
1 files changed, 18 insertions, 5 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index d71978a899..92da990d38 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -3518,10 +3518,20 @@ static void _catchup_monster_moves(monsters *mon, int turns)
}
else
{
+ coord_def mshift(random2(3) - 1, random2(3) - 1);
+
+ // Bounds check: don't let fleeing monsters try to
+ // run off the grid.
+ const coord_def s = mon->target + mshift;
+ if (!in_bounds_x(s.x))
+ mshift.x = 0;
+ if (!in_bounds_y(s.y))
+ mshift.y = 0;
+
// Randomise the target so we have a direction to
// flee.
- mon->target.x += (random2(3) - 1);
- mon->target.y += (random2(3) - 1);
+ mon->target.x += mshift.x;
+ mon->target.y += mshift.y;
}
}
@@ -3543,7 +3553,7 @@ static void _catchup_monster_moves(monsters *mon, int turns)
coord_def pos(mon->pos());
- // dirt simple movement:
+ // Dirt simple movement.
for (int i = 0; i < moves; ++i)
{
coord_def inc(mon->target - pos);
@@ -3552,9 +3562,12 @@ static void _catchup_monster_moves(monsters *mon, int turns)
if (mons_is_fleeing(mon))
inc *= -1;
- if (pos.x + inc.x < 0 || pos.x + inc.x >= GXM)
+ // Bounds check: don't let shifting monsters try to run off the
+ // grid.
+ const coord_def s = pos + inc;
+ if (!in_bounds_x(s.x))
inc.x = 0;
- if (pos.y + inc.y < 0 || pos.y + inc.y >= GYM)
+ if (!in_bounds_y(s.y))
inc.y = 0;
if (inc.origin())