From adb21570e7da7ff280113e938ee7a26089614e63 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Wed, 11 Nov 2009 16:38:12 +0100 Subject: 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. --- crawl-ref/source/view.cc | 76 ++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 44 deletions(-) (limited to 'crawl-ref/source/view.cc') 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 -- cgit v1.2.3-54-g00ecf