diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-11-11 16:38:12 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-11-11 19:14:39 +0100 |
commit | adb21570e7da7ff280113e938ee7a26089614e63 (patch) | |
tree | 3fe1dc829ae1826eac4a4081ed3e3c115a562d04 /crawl-ref/source/view.cc | |
parent | 24636262aded779e9759895c536e0f42f79c4b52 (diff) | |
download | crawl-ref-adb21570e7da7ff280113e938ee7a26089614e63.tar.gz crawl-ref-adb21570e7da7ff280113e938ee7a26089614e63.zip |
Convert another 45 monster loops to monster_iterator.
A total of 53 have been converted; 39 left, of which some should
stay. Now at a net loss of lines of code for monster_iterator.
Occurrences of MAX_MONSTERS down to 65 from 116 in *.cc.
Diffstat (limited to 'crawl-ref/source/view.cc')
-rw-r--r-- | crawl-ref/source/view.cc | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index c0a55da171..3ee1f5e6bb 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -48,6 +48,7 @@ #include "message.h" #include "misc.h" #include "mon-behv.h" +#include "mon-iter.h" #include "monplace.h" #include "monstuff.h" #include "mon-util.h" @@ -122,34 +123,31 @@ void flush_comes_into_view() void monster_grid_updates() { - for (int s = 0; s < MAX_MONSTERS; ++s) + for (monster_iterator mi(&you.get_los()); mi; ++mi) { - monsters *monster = &menv[s]; - - if (monster->alive() && mons_near(monster)) + if ((mi->asleep() || mons_is_wandering(*mi)) + && check_awaken(*mi)) { - if ((monster->asleep() || mons_is_wandering(monster)) - && check_awaken(monster)) - { - behaviour_event(monster, ME_ALERT, MHITYOU, you.pos(), false); - handle_monster_shouts(monster); - } + behaviour_event(*mi, ME_ALERT, MHITYOU, you.pos(), false); + handle_monster_shouts(*mi); + } - if (!monster->visible_to(&you)) - continue; + if (!mi->visible_to(&you)) + continue; - good_god_follower_attitude_change(monster); - beogh_follower_convert(monster); - slime_convert(monster); - fedhas_neutralise(monster); - } + good_god_follower_attitude_change(*mi); + beogh_follower_convert(*mi); + slime_convert(*mi); + fedhas_neutralise(*mi); } } -static void _check_monster_pos(const monsters* monster, int s) +static void _check_monster_pos(const monsters* monster) { + int s = monster->mindex(); ASSERT(mgrd(monster->pos()) == s); + // [rob] The following in case asserts aren't enabled. // [enne] - It's possible that mgrd and monster->x/y are out of // sync because they are updated separately. If we can see this // monster, then make sure that the mgrd is set correctly. @@ -169,20 +167,15 @@ static void _check_monster_pos(const monsters* monster, int s) void monster_grid() { - for (int s = 0; s < MAX_MONSTERS; ++s) + for (monster_iterator mi(&you.get_los()); mi; ++mi) { - monsters *monster = &menv[s]; - - if (monster->alive() && mons_near(monster)) - { - _check_monster_pos(monster, s); - env.show.update_monster(monster); + _check_monster_pos(*mi); + env.show.update_monster(*mi); #ifdef USE_TILE - if (monster->visible_to(&you)) - tile_place_monster(monster->pos().x, monster->pos().y, s, true); + if (mi->visible_to(&you)) + tile_place_monster(mi->pos().x, mi->pos().y, s, true); #endif - } } } @@ -190,39 +183,34 @@ void update_monsters_in_view() { unsigned int num_hostile = 0; - for (int s = 0; s < MAX_MONSTERS; s++) + for (monster_iterator mi; mi; ++mi) { - monsters *monster = &menv[s]; - - if (!monster->alive()) - continue; - - if (mons_near(monster)) + if (mons_near(*mi)) { - if (monster->attitude == ATT_HOSTILE) + if (mi->attitude == ATT_HOSTILE) num_hostile++; - if (mons_is_unknown_mimic(monster)) + if (mons_is_unknown_mimic(*mi)) { // For unknown mimics, don't mark as seen, // but do mark it as in view for later messaging. // FIXME: is this correct? - monster->flags |= MF_WAS_IN_VIEW; + mi->flags |= MF_WAS_IN_VIEW; } - else if (monster->visible_to(&you)) + else if (mi->visible_to(&you)) { - handle_seen_interrupt(monster); - seen_monster(monster); + handle_seen_interrupt(*mi); + seen_monster(*mi); } else - monster->flags &= ~MF_WAS_IN_VIEW; + mi->flags &= ~MF_WAS_IN_VIEW; } else - monster->flags &= ~MF_WAS_IN_VIEW; + mi->flags &= ~MF_WAS_IN_VIEW; // If the monster hasn't been seen by the time that the player // gets control back then seen_context is out of date. - monster->seen_context.clear(); + mi->seen_context.clear(); } // Xom thinks it's hilarious the way the player picks up an ever |