diff options
author | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-09 02:56:30 +0000 |
---|---|---|
committer | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-09 02:56:30 +0000 |
commit | 6eb9841f76396644005a047518c775e7d867db62 (patch) | |
tree | 52809fd820b8966ac41abab4df2d663b5e5810d0 /crawl-ref/source | |
parent | 613b175f1baededdfddf46221e882dbdae8e5709 (diff) | |
download | crawl-ref-6eb9841f76396644005a047518c775e7d867db62.tar.gz crawl-ref-6eb9841f76396644005a047518c775e7d867db62.zip |
Move there_are_monsters_nearby() to misc.cc, and make it a wrapper
around get_playervisible_monsters(), in order to reduce code
duplication.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5630 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/misc.cc | 9 | ||||
-rw-r--r-- | crawl-ref/source/xom.cc | 29 |
2 files changed, 9 insertions, 29 deletions
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 342e7f96ae..c1115df870 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -2759,6 +2759,15 @@ bool i_feel_safe(bool announce, bool want_move, bool just_monsters, int range) return (false); } +bool there_are_monsters_nearby() +{ + // Monster check. + std::vector<monsters*> visible; + get_playervisible_monsters(visible, false, true); + + return (!visible.empty()); +} + static const char *shop_types[] = { "weapon", "armour", diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc index d5507f12e6..cb40a50823 100644 --- a/crawl-ref/source/xom.cc +++ b/crawl-ref/source/xom.cc @@ -382,35 +382,6 @@ bool xom_gives_item(int power) return (true); } -bool there_are_monsters_nearby() -{ - const int ystart = MAX(0, you.y_pos - 9); - const int yend = MIN(GYM - 1, you.y_pos + 9); - const int xstart = MAX(0, you.x_pos - 9); - const int xend = MIN(GXM - 1, you.x_pos + 9); - - // Monster check. - for (int y = ystart; y <= yend; ++y) - { - for (int x = xstart; x <= xend; ++x) - { - // If you can see a monster, then it's nearby. - if (see_grid(x, y)) - { - const int targ_monst = mgrd[x][y]; - if (targ_monst != NON_MONSTER) - { - const monsters *mon = &menv[targ_monst]; - if (!mons_is_submerged(mon)) - return (true); - } - } - } - } - - return (false); -} - static bool choose_mutatable_monster(const monsters* mon) { return (mon->alive() && mon->can_safely_mutate() |