From 46444e5e558c8cc779c90c7abe0f2f8577d51342 Mon Sep 17 00:00:00 2001 From: dolorous Date: Mon, 26 Jan 2009 20:33:38 +0000 Subject: 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 --- crawl-ref/source/effects.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'crawl-ref/source/effects.cc') 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 ); -- cgit v1.2.3-54-g00ecf