From a57747c0c0f207a2cb5bee3e4d576f1feb355f96 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Thu, 12 Nov 2009 23:09:31 +0100 Subject: Rewrite zap_los_monsters using monster_iter. Not sure it was broken before, but it's cleaner now. Also move tutorial item zapping into a separate function. --- crawl-ref/source/acr.cc | 4 ++++ crawl-ref/source/stuff.cc | 54 ++++++++++++++++++----------------------------- crawl-ref/source/stuff.h | 1 + 3 files changed, 26 insertions(+), 33 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index e3d2edfaba..904ffeb6f4 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -3739,6 +3739,10 @@ static bool _initialise(void) // For a new game, wipe out monsters in LOS. zap_los_monsters(); + // At tutorial beginning disallow items in line of sight. + if (Options.tutorial_events[TUT_SEEN_FIRST_OBJECT]) + zap_los_items(); + // For a newly started tutorial, turn secret doors into normal ones. if (Options.tutorial_left) tutorial_zap_secret_doors(); diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index 377b9ba84a..61820de23a 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -14,6 +14,7 @@ #include "los.h" #include "message.h" #include "misc.h" +#include "mon-iter.h" #include "mon-place.h" #include "state.h" #include "stuff.h" @@ -883,52 +884,39 @@ bool is_trap_square(dungeon_feature_type grid) return (grid >= DNGN_TRAP_MECHANICAL && grid <= DNGN_UNDISCOVERED_TRAP); } +// At tutorial beginning disallow items in line of sight. +void zap_los_items() +{ + for (radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri) + { + int item = igrd(*ri); + + if (item != NON_ITEM && mitm[item].is_valid() ) + destroy_item(item); + } +} + // Does the equivalent of KILL_RESET on all monsters in LOS. Should only be // applied to new games. void zap_los_monsters() { - calc_show_los(); - - for (rectangle_iterator ri(crawl_view.vlos1, crawl_view.vlos2); ri; ++ri ) + you.update_los(); + // If we ever allow starting with a friendly monster, + // we'll have to check here. + for (monster_iterator mi(&you.get_los()); mi; ++mi) { - const coord_def g = view2grid(*ri); - - if (!map_bounds(g)) - continue; - - if (!you.see_cell(g)) - continue; - - if (g == you.pos()) - continue; - - // At tutorial beginning disallow items in line of sight. - if (Options.tutorial_events[TUT_SEEN_FIRST_OBJECT]) - { - int item = igrd(g); - - if (item != NON_ITEM && mitm[item].is_valid() ) - destroy_item(item); - } - - // If we ever allow starting with a friendly monster, - // we'll have to check here. - monsters *mon = monster_at(g); - if (mon == NULL) - continue; - - if (mons_class_flag( mon->type, M_NO_EXP_GAIN )) + if (mons_class_flag(mi->type, M_NO_EXP_GAIN)) continue; #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Dismissing %s", - mon->name(DESC_PLAIN, true).c_str() ); + mi->name(DESC_PLAIN, true).c_str() ); #endif // Do a hard reset so the monster's items will be discarded. - mon->flags |= MF_HARD_RESET; + mi->flags |= MF_HARD_RESET; // Do a silent, wizard-mode monster_die() just to be extra sure the // player sees nothing. - monster_die(mon, KILL_DISMISSED, NON_MONSTER, true, true); + monster_die(*mi, KILL_DISMISSED, NON_MONSTER, true, true); } } diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h index 4a7fab6c11..fe5ff15245 100644 --- a/crawl-ref/source/stuff.h +++ b/crawl-ref/source/stuff.h @@ -93,6 +93,7 @@ template inline Z sgn(Z x) } bool is_trap_square(dungeon_feature_type grid); +void zap_los_items(); void zap_los_monsters(); int integer_sqrt(int value); -- cgit v1.2.3-54-g00ecf