summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monstuff.cc
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-29 15:47:28 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-29 15:47:28 +0000
commiteeaba130f2a67321b64889c935fe443af70e3e97 (patch)
tree092d27407d961e6347ce1b78be947db82012ef8c /crawl-ref/source/monstuff.cc
parent942a2a13a9bbe4672247b37e58a53abfc4ca4db5 (diff)
downloadcrawl-ref-eeaba130f2a67321b64889c935fe443af70e3e97.tar.gz
crawl-ref-eeaba130f2a67321b64889c935fe443af70e3e97.zip
Fix [2541331]: monster blinking only looked to the southeast.
Also fix a subtle bug causing monsters to be able to teleport through walls if there was clear rock there too. (This is because num_feats_between() is not symmetrical in its first two arguments.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8847 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/monstuff.cc')
-rw-r--r--crawl-ref/source/monstuff.cc73
1 files changed, 34 insertions, 39 deletions
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index c5e56b1038..a3d8e3a601 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -2111,54 +2111,49 @@ static coord_def _random_monster_nearby_habitable_space(const monsters& mon,
coord_def target;
int tries;
- {
- // Save LOS, because we're going to clobber it with monster LOS.
- unwind_var<env_show_grid> visible_grid(env.show);
- // Do the clobbering.
- losight(env.show, grd, mon.pos(), true);
+ for (tries = 0; tries < 150; ++tries)
+ {
+ const coord_def delta(random2(13) - 6, random2(13) - 6);
- for (tries = 0; tries < 150; ++tries)
- {
- const coord_def delta(random2(14), random2(14));
+ // Check that we don't get something too close to the
+ // starting point.
+ if (delta.origin())
+ continue;
- // Check that we don't get something too close to the
- // starting point.
- if (delta.origin())
- continue;
+ if (delta.rdist() == 1 && !allow_adjacent)
+ continue;
- if (delta.rdist() == 1 && !allow_adjacent)
- continue;
+ // Update target.
+ target = delta + mon.pos();
- // Update target.
- target = delta + mon.pos();
+ // Check that the target is valid and survivable.
+ if (!in_bounds(target))
+ continue;
- // Check that the target is valid and survivable.
- if (!in_bounds(target))
- continue;
+ if (!monster_habitable_grid(&mon, grd(target)))
+ continue;
- if (!monster_habitable_grid(&mon, grd(target)))
- continue;
+ if (respect_sanctuary && is_sanctuary(target))
+ continue;
- if (respect_sanctuary && is_sanctuary(target))
- continue;
+ if (target == you.pos())
+ continue;
- // Check that we didn't go through clear walls.
- if (num_feats_between(target, mon.pos(),
- DNGN_CLEAR_ROCK_WALL,
- DNGN_CLEAR_PERMAROCK_WALL,
- true, true) > 0)
- {
- continue;
- }
+ // Check that we didn't go through clear walls.
+ if (num_feats_between(mon.pos(), target,
+ DNGN_CLEAR_ROCK_WALL,
+ DNGN_CLEAR_PERMAROCK_WALL,
+ true, true) > 0)
+ {
+ continue;
+ }
- // Note that this uses the clobbered LOS!
- if (respect_los && !see_grid(target))
- continue;
+ if (respect_los && !mon.mon_see_grid(target))
+ continue;
- // Survived everything, break out (with a good value of target.)
- break;
- }
+ // Survived everything, break out (with a good value of target.)
+ break;
}
if (tries == 150)
@@ -2197,7 +2192,7 @@ bool random_near_space(const coord_def& origin, coord_def& target,
{
// This might involve ray tracing (via num_feats_between()), so
// cache results to avoid duplicating ray traces.
- FixedArray<bool, 14, 14> tried;
+ FixedArray<bool, 13, 13> tried;
tried.init(false);
// Is the monster on the other side of a transparent wall?
@@ -2216,7 +2211,7 @@ bool random_near_space(const coord_def& origin, coord_def& target,
int tries = 0;
while (tries++ < 150)
{
- coord_def delta(random2(14), random2(14));
+ coord_def delta(random2(13), random2(13));
target = origin - coord_def(6, 6) + delta;