summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/mon-util.cc6
-rw-r--r--crawl-ref/source/monster.h2
-rw-r--r--crawl-ref/source/monstuff.cc7
-rw-r--r--crawl-ref/source/view.cc25
-rw-r--r--crawl-ref/source/view.h2
5 files changed, 17 insertions, 25 deletions
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index dd2e773592..b7002de4a4 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -8000,6 +8000,12 @@ bool monsters::can_see(const actor *targ) const
return (targ->visible_to(this) && see_cell(targ->pos()));
}
+bool monsters::near_foe() const
+{
+ const actor *afoe = get_foe();
+ return (afoe && see_cell(afoe->pos()));
+}
+
bool monsters::can_mutate() const
{
return (holiness() == MH_NATURAL || holiness() == MH_PLANT);
diff --git a/crawl-ref/source/monster.h b/crawl-ref/source/monster.h
index 41c17ecbfd..27ac976b07 100644
--- a/crawl-ref/source/monster.h
+++ b/crawl-ref/source/monster.h
@@ -302,6 +302,8 @@ public:
bool mon_see_cell(const coord_def& pos, bool reach = false) const;
bool see_cell(const coord_def& c) const;
bool can_see(const actor *target) const;
+ bool near_foe() const;
+
bool is_icy() const;
bool is_fiery() const;
bool paralysed() const;
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index b74e0f0a71..fe48bf9751 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -4496,9 +4496,9 @@ static void _handle_behaviour(monsters *mon)
}
else
{
- proxFoe = mons_near(mon, mon->foe);
+ proxFoe = mon->near_foe();
- if (!mon->can_see( &menv[mon->foe]))
+ if (!mon->can_see(&menv[mon->foe]))
proxFoe = false;
foepos = menv[mon->foe].pos();
@@ -5660,7 +5660,6 @@ static void _handle_nearby_ability(monsters *monster)
{
actor *foe = monster->get_foe();
if (!foe
- || !mons_near(monster, monster->foe)
|| !monster->can_see(foe)
|| mons_is_sleeping(monster)
|| mons_is_submerged(monster))
@@ -7863,7 +7862,7 @@ static void _handle_monster_move(monsters *monster)
beem.beam_source = monster->mindex();
const bool friendly_or_near =
- mons_friendly(monster) || mons_near(monster, monster->foe);
+ mons_friendly(monster) || monster->near_foe();
// Prevents unfriendlies from nuking you from offscreen.
// How nice!
if (friendly_or_near || monster->type == MONS_TEST_SPAWNER)
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index d7a03f82f3..e2a35e53c5 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -3051,27 +3051,12 @@ bool magic_mapping(int map_radius, int proportion, bool suppress_msg,
return (did_map);
}
-// Is the given monster near (in LOS of) the given foe's
-// position (the player by default)?
-bool mons_near(const monsters *monster, unsigned short foe)
+// Is the given monster near (in LOS of) the player?
+bool mons_near(const monsters *monster)
{
- // Early out -- no foe!
- if (foe == MHITNOT)
- return (false);
-
- if (foe == MHITYOU)
- {
- if (crawl_state.arena || crawl_state.arena_suspended)
- return (true);
- return (see_cell(monster->pos()));
- }
-
- // Must be a monster.
- const monsters *foemons = &menv[foe];
- if (foemons->alive())
- return (monster->mon_see_cell(foemons->pos()));
-
- return (false);
+ if (crawl_state.arena || crawl_state.arena_suspended)
+ return (true);
+ return (see_cell(monster->pos()));
}
bool mon_enemies_around(const monsters *monster)
diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h
index fd9c4dbf5f..e561040106 100644
--- a/crawl-ref/source/view.h
+++ b/crawl-ref/source/view.h
@@ -62,7 +62,7 @@ void init_monsters_seens();
void beogh_follower_convert(monsters *monster, bool orc_hit = false);
void slime_convert(monsters *monster);
-bool mons_near(const monsters *monster, unsigned short foe = MHITYOU);
+bool mons_near(const monsters *monster);
bool mon_enemies_around(const monsters *monster);
void find_features(const std::vector<coord_def>& features,