diff options
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/monstuff.cc | 18 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 13 |
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, |