summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-05-28 08:05:03 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-05-28 08:05:03 +0000
commit6977f25bb9ee1dca2c7d3947da850bd1226d6dc9 (patch)
tree8e3434831f3eb078169a2c740fa0b540aaa0fac2 /crawl-ref
parent7aff33edc63728798297f82e51437cdbf556d5b9 (diff)
downloadcrawl-ref-6977f25bb9ee1dca2c7d3947da850bd1226d6dc9.tar.gz
crawl-ref-6977f25bb9ee1dca2c7d3947da850bd1226d6dc9.zip
Modify mon_enemies_around() logic to allow friends to also cast spells
if they have a foe but you don't, i.e. if their foe is out of your LOS. Don't allow patrolling to a target grid that is occupied by a monster in case it's a stationary monster (plant or sleeping). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5311 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/monstuff.cc18
-rw-r--r--crawl-ref/source/view.cc13
2 files changed, 30 insertions, 1 deletions
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index ca7c5115e2..3f46f0d00e 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -2168,18 +2168,33 @@ static bool _choose_random_patrol_target_grid(monsters *mon)
if (!in_bounds(pos_x, pos_y))
continue;
+ // Don't bother for the current position. If everything fails,
+ // we'll stay here anyways.
if (pos_x == mon->x && pos_y == mon->y)
continue;
if (!mon->can_pass_through_feat(grd[pos_x][pos_y]))
continue;
+ // Don't bother moving to squares (currently) occupied by a
+ // monster. We'll usually be able to find other target squares
+ // (and if we're not, we couldn't move anyway), and this avoids
+ // monsters trying to move onto a grid occupied by a plant or
+ // sleeping monster.
+ if (mgrd[pos_x][pos_y] != NON_MONSTER)
+ continue;
+
if (grid_see_grid(mon->x, mon->y, patrol_x, patrol_y, habitat))
{
// If the patrol point can be easily (within LOS) reached
// from the current position, it suffices if the target is
// within reach of the patrol point OR the current position:
// we can easily get there.
+ // Note: This can take us into a position where the target
+ // cannot be easily reached (e.g. blocked by a wall) and the
+ // patrol point is out of sight, too. Such a case will be
+ // handled below, though it might take a while until a monster
+ // gets out of a deadlock.
if (!grid_see_grid(patrol_x, patrol_y, pos_x, pos_y, habitat)
&& !grid_see_grid(mon->x, mon->y, pos_x, pos_y, habitat))
{
@@ -2197,6 +2212,9 @@ static bool _choose_random_patrol_target_grid(monsters *mon)
{
continue;
}
+ // If this fails for all surrounding squares (probably because
+ // we're too far away), we fall back to heading directly for
+ // the patrol point.
}
if (one_chance_in(++count_grids))
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 86e18f81bf..b44b8588e5 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -3611,10 +3611,21 @@ bool mons_near(const monsters *monster, unsigned int foe)
bool mon_enemies_around(const monsters *monster)
{
+ // If the monster has a foe, return true.
+ if (monster->foe != MHITNOT && monster->foe != MHITYOU)
+ return (true);
+
if (mons_friendly(monster))
- return (!mons_near(monster) || !i_feel_safe());
+ {
+ // Additionally, if an ally is nearby and *you* have a foe, consider
+ // it as the ally's enemy too.
+ return (mons_near(monster) && !i_feel_safe());
+ }
else
+ {
+ // For hostile monsters *you* are the main enemy.
return (mons_near(monster));
+ }
}
bool see_grid( const env_show_grid &show,