From 229eb5e575daec5bbf7a099a5461fc009d6abfdc Mon Sep 17 00:00:00 2001 From: dolorous Date: Mon, 26 Jan 2009 21:24:35 +0000 Subject: 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 --- crawl-ref/source/effects.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'crawl-ref/source/effects.cc') 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()) -- cgit v1.2.3-54-g00ecf