From 412bcd6e779cd3883bc5c6ce29a8e79ad32c63f4 Mon Sep 17 00:00:00 2001 From: haranp Date: Fri, 13 Feb 2009 00:47:33 +0000 Subject: Remove a great many cases where mgrd is accessed directly in favour of monster_at(). The hope is to eventually remove mgrd completely (in favour of scanning through the monster list, or a different datastructure which gets updated automatically when monsters move), and thus fix all the mgrd-out-of-sync bugs in one fell swoop. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9056 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/misc.cc | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'crawl-ref/source/misc.cc') diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index e419a646fc..a3c77d2036 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -2669,10 +2669,8 @@ std::vector get_nearby_monsters(bool want_move, // Sweep every visible square within range. for (radius_iterator ri(you.pos(), range); ri; ++ri) { - const unsigned short targ_monst = env.mgrid(*ri); - if (targ_monst != NON_MONSTER) + if (monsters* mon = monster_at(*ri)) { - monsters *mon = &menv[targ_monst]; if (mon->alive() && (!require_visible || player_monster_visible(mon)) && !mons_is_submerged(mon) @@ -2682,7 +2680,7 @@ std::vector get_nearby_monsters(bool want_move, { mons.push_back(mon); if (just_check) // stop once you find one - return mons; + break; } } } @@ -2908,23 +2906,12 @@ coord_def pick_adjacent_free_square(const coord_def& p) { int num_ok = 0; coord_def result(-1, -1); - for ( int ux = p.x-1; ux <= p.x+1; ++ux ) - { - for ( int uy = p.y-1; uy <= p.y+1; ++uy ) - { - if ( ux == p.x && uy == p.y ) - continue; - if ( in_bounds(ux, uy) - && grd[ux][uy] == DNGN_FLOOR - && mgrd[ux][uy] == NON_MONSTER ) - { - ++num_ok; - if ( one_chance_in(num_ok) ) - result.set(ux, uy); - } - } - } + for (adjacent_iterator ai(p); ai; ++ai) + if (grd(*ai) == DNGN_FLOOR && monster_at(*ai) == NULL) + if (one_chance_in(++num_ok)) + result = *ai; + return result; } -- cgit v1.2.3-54-g00ecf