diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-11-12 08:33:03 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-11-12 09:38:15 +0100 |
commit | bf9183f6523bf96750b50723fc0f783af6fc8e9c (patch) | |
tree | 0833c35f8b11d3f57ea22c57bcce48a15cf5319e /crawl-ref/source | |
parent | a32d122dd8d29cf5982ac1052d9c88c91ce0bcd3 (diff) | |
download | crawl-ref-bf9183f6523bf96750b50723fc0f783af6fc8e9c.tar.gz crawl-ref-bf9183f6523bf96750b50723fc0f783af6fc8e9c.zip |
More monster_iterator conversions.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/arena.cc | 65 | ||||
-rw-r--r-- | crawl-ref/source/mon-behv.cc | 11 | ||||
-rw-r--r-- | crawl-ref/source/mon-cast.cc | 38 | ||||
-rw-r--r-- | crawl-ref/source/mon-stuff.cc | 9 | ||||
-rw-r--r-- | crawl-ref/source/spells1.cc | 40 | ||||
-rw-r--r-- | crawl-ref/source/wiz-item.cc | 24 |
6 files changed, 77 insertions, 110 deletions
diff --git a/crawl-ref/source/arena.cc b/crawl-ref/source/arena.cc index 178a592129..31512cd621 100644 --- a/crawl-ref/source/arena.cc +++ b/crawl-ref/source/arena.cc @@ -22,6 +22,7 @@ #include "maps.h" #include "message.h" #include "mon-behv.h" +#include "mon-iter.h" #include "mon-pick.h" #include "mon-util.h" #include "mon-place.h" @@ -139,12 +140,8 @@ namespace arena void adjust_monsters() { - for (int i = 0; i < MAX_MONSTERS; i++) + for (monster_iterator mon; mon; ++mon) { - monsters *mon = &menv[i]; - if (!mon->alive()) - continue; - const bool friendly = mon->friendly(); // Set target to the opposite faction's home base. mon->target = friendly ? place_b : place_a; @@ -543,16 +540,12 @@ namespace arena faction_a.active_members = 0; faction_b.active_members = 0; - for (int i = 0; i < MAX_MONSTERS; ++i) + for (monster_iterator mons; mons; ++mons) { - const monsters *mons(&menv[i]); - if (mons->alive()) - { - if (mons->attitude == ATT_FRIENDLY) - faction_a.active_members++; - else if (mons->attitude == ATT_HOSTILE) - faction_b.active_members++; - } + if (mons->attitude == ATT_FRIENDLY) + faction_a.active_members++; + else if (mons->attitude == ATT_HOSTILE) + faction_b.active_members++; } if (orig_a != faction_a.active_members @@ -601,35 +594,27 @@ namespace arena void report_foes() { - for (int i = 0; i < MAX_MONSTERS; ++i) + for (monster_iterator mons; mons; ++mons) { - monsters *mons(&menv[i]); - if (mons->alive()) + if (mons->type == MONS_SIGMUND) { - if (mons->type == MONS_SIGMUND) - { - coord_def where; - if (mons->get_foe()) - where = mons->get_foe()->pos(); - mprf("%s (%d,%d) foe: %s (%d,%d)", - mons->name(DESC_PLAIN).c_str(), - mons->pos().x, mons->pos().y, - mons->get_foe()? mons->get_foe()->name(DESC_PLAIN).c_str() - : "(none)", - where.x, where.y); - } + coord_def where; + if (mons->get_foe()) + where = mons->get_foe()->pos(); + mprf("%s (%d,%d) foe: %s (%d,%d)", + mons->name(DESC_PLAIN).c_str(), + mons->pos().x, mons->pos().y, + mons->get_foe()? mons->get_foe()->name(DESC_PLAIN).c_str() + : "(none)", + where.x, where.y); } } } void fixup_foes() { - for (int i = 0; i < MAX_MONSTERS; ++i) - { - monsters *mons(&menv[i]); - if (mons->alive()) - behaviour_event(mons, ME_DISTURB, MHITNOT, mons->pos()); - } + for (monster_iterator mons; mons; ++mons) + behaviour_event(*mons, ME_DISTURB, MHITNOT, mons->pos()); } void dump_messages() @@ -718,15 +703,13 @@ namespace arena if (!miscasts) return; - for (int i = 0; i < MAX_MONSTERS; i++) + for (monster_iterator mon; mon; ++mon) { - monsters* mon = &menv[i]; - - if (!mon->alive() || mon->type == MONS_TEST_SPAWNER) + if (mon->type == MONS_TEST_SPAWNER) continue; - MiscastEffect(mon, i, SPTYP_RANDOM, random_range(1, 3), - "arena miscast", NH_NEVER); + MiscastEffect(*mon, mon->mindex(), SPTYP_RANDOM, + random_range(1, 3), "arena miscast", NH_NEVER); } } diff --git a/crawl-ref/source/mon-behv.cc b/crawl-ref/source/mon-behv.cc index 7883a367b1..03ae622bb9 100644 --- a/crawl-ref/source/mon-behv.cc +++ b/crawl-ref/source/mon-behv.cc @@ -15,6 +15,7 @@ #include "fprop.h" #include "exclude.h" #include "los.h" +#include "mon-iter.h" #include "mon-place.h" #include "mon-stuff.h" #include "mon-util.h" @@ -914,13 +915,13 @@ static void _arena_set_foe(monsters *mons) int nearest_unseen = -1; int best_unseen_distance = -1; - for (int i = 0; i < MAX_MONSTERS; ++i) + for (monster_iterator other; other; ++other) { + int i = other->mindex(); if (mind == i) continue; - const monsters *other(&menv[i]); - if (!other->alive() || mons_aligned(mind, i)) + if (mons_aligned(mind, i)) continue; // Don't fight test spawners, since they're only pseudo-monsters @@ -934,7 +935,7 @@ static void _arena_set_foe(monsters *mons) } const int distance = grid_distance(mons->pos(), other->pos()); - const bool seen = mons->can_see(other); + const bool seen = mons->can_see(*other); if (seen) { @@ -954,7 +955,7 @@ static void _arena_set_foe(monsters *mons) } if ((best_distance == -1 || distance < best_distance) - && mons->can_see(other)) + && mons->can_see(*other)) { best_distance = distance; diff --git a/crawl-ref/source/mon-cast.cc b/crawl-ref/source/mon-cast.cc index 08cba24f19..748815eb73 100644 --- a/crawl-ref/source/mon-cast.cc +++ b/crawl-ref/source/mon-cast.cc @@ -21,6 +21,7 @@ #include "los.h" #include "misc.h" #include "mon-behv.h" +#include "mon-iter.h" #include "mon-place.h" #include "mon-speak.h" #include "mon-stuff.h" @@ -148,22 +149,19 @@ static bool _set_allied_target(monsters * caster, bolt & pbolt) monster_type caster_genus = mons_genus(caster->type); - for (int i = 0; i < MAX_MONSTERS; i++) + for (monster_iterator targ(caster); targ; ++targ) { - monsters * targ = &menv[i]; - if (i != caster->mindex() - && targ->alive() - && caster->can_see(targ) + if (*targ != caster && mons_genus(targ->type) == caster_genus && mons_atts_aligned(targ->attitude, caster->attitude) && !targ->has_ench(ENCH_CHARM) - && _flavour_benefits_monster(pbolt.flavour, *targ)) + && _flavour_benefits_monster(pbolt.flavour, **targ)) { int targ_distance = grid_distance(targ->pos(), caster->pos()); if (targ_distance < min_distance && targ_distance < pbolt.range) { min_distance = targ_distance; - selected_target = targ; + selected_target = *targ; } } } @@ -846,35 +844,29 @@ bool setup_mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast, } else if (spell_cast == SPELL_PORKALATOR && one_chance_in(3)) { - int target = -1; + monsters* targ; int count = 0; monster_type hog_type = MONS_HOG; - for (int i = 0; i < MAX_MONSTERS; i++) + for (monster_iterator mi(monster); mi; ++mi) { - monsters *targ = &menv[i]; - - if (!monster->can_see(targ)) - continue; - hog_type = MONS_HOG; - if (targ->holiness() == MH_DEMONIC) + if (mi->holiness() == MH_DEMONIC) hog_type = MONS_HELL_HOG; - else if (targ->holiness() != MH_NATURAL) + else if (mi->holiness() != MH_NATURAL) continue; - if (targ->type != hog_type - && mons_atts_aligned(monster->attitude, targ->attitude) - && mons_power(hog_type) + random2(4) >= mons_power(targ->type) - && (!targ->can_use_spells() || coinflip()) + if (mi->type != hog_type + && mons_atts_aligned(monster->attitude, mi->attitude) + && mons_power(hog_type) + random2(4) >= mons_power(mi->type) + && (!mi->can_use_spells() || coinflip()) && one_chance_in(++count)) { - target = i; + targ = *mi; } } - if (target != -1) + if (targ) { - monsters *targ = &menv[target]; pbolt.target = targ->pos(); #if DEBUG_DIAGNOSTICS mprf("Porkalator: targetting %s instead", diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc index fd9c9eec10..bf40170354 100644 --- a/crawl-ref/source/mon-stuff.cc +++ b/crawl-ref/source/mon-stuff.cc @@ -1216,16 +1216,17 @@ static void _elven_twin_died(monsters* twin) bool found_dowan = false; monsters *monster; - for (int i = 0; i < MAX_MONSTERS; ++i) + for (monster_iterator mi; mi; ++mi) { - monster = &menv[i]; - if (monster->alive() && monster->type == MONS_DUVESSA) + if (mi->type == MONS_DUVESSA) { + monster = *mi; found_duvessa = true; break; } - else if (monster->alive() && monster->type == MONS_DOWAN) + else if (monster->type == MONS_DOWAN) { + monster = *mi; found_dowan = true; break; } diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc index 59e8163ae6..9ba939477d 100644 --- a/crawl-ref/source/spells1.cc +++ b/crawl-ref/source/spells1.cc @@ -33,6 +33,7 @@ #include "los.h" #include "message.h" #include "misc.h" +#include "mon-iter.h" #include "mon-stuff.h" #include "mon-util.h" #include "options.h" @@ -372,14 +373,12 @@ void cast_chain_lightning(int pow, const actor *caster) target.x = -1; target.y = -1; - for (int i = 0; i < MAX_MONSTERS; i++) + for (monster_iterator mi; mi; ++mi) { - monsters *monster = &menv[i]; - - if (invalid_monster(monster)) + if (invalid_monster(*mi)) continue; - dist = grid_distance(source, monster->pos()); + dist = grid_distance(source, mi->pos()); // check for the source of this arc if (!dist) @@ -392,7 +391,7 @@ void cast_chain_lightning(int pow, const actor *caster) if (dist > min_dist) continue; - if (!_lightning_los(source, monster->pos())) + if (!_lightning_los(source, mi->pos())) continue; count++; @@ -403,14 +402,14 @@ void cast_chain_lightning(int pow, const actor *caster) if (!one_chance_in(10)) { min_dist = dist; - target = monster->pos(); + target = mi->pos(); count = 0; } } else if (target.x == -1 || one_chance_in(count)) { // either first target, or new selected target at min_dist - target = monster->pos(); + target = mi->pos(); // need to set min_dist for first target case dist = std::max(dist, min_dist); @@ -1132,30 +1131,25 @@ void abjuration(int pow) // Scale power into something comparable to summon lifetime. const int abjdur = pow * 12; - for (int i = 0; i < MAX_MONSTERS; ++i) + for (monster_iterator mon(&you.get_los()); mon; ++mon) { - monsters* const monster = &menv[i]; - - if (monster->type == MONS_NO_MONSTER || !mons_near(monster)) - continue; - - if (monster->wont_attack()) + if (mon->wont_attack()) continue; int duration; - if (monster->is_summoned(&duration)) + if (mon->is_summoned(&duration)) { int sockage = std::max(fuzz_value(abjdur, 60, 30), 40); #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "%s abj: dur: %d, abj: %d", - monster->name(DESC_PLAIN).c_str(), duration, sockage); + mon->name(DESC_PLAIN).c_str(), duration, sockage); #endif bool shielded = false; // TSO and Trog's abjuration protection. - if (mons_is_god_gift(monster, GOD_SHINING_ONE)) + if (mons_is_god_gift(*mon, GOD_SHINING_ONE)) { - sockage = sockage * (30 - monster->hit_dice) / 45; + sockage = sockage * (30 - mon->hit_dice) / 45; if (sockage < duration) { simple_god_message(" protects a fellow warrior from your evil magic!", @@ -1163,7 +1157,7 @@ void abjuration(int pow) shielded = true; } } - else if (mons_is_god_gift(monster, GOD_TROG)) + else if (mons_is_god_gift(*mon, GOD_TROG)) { sockage = sockage * 8 / 15; if (sockage < duration) @@ -1174,9 +1168,9 @@ void abjuration(int pow) } } - mon_enchant abj = monster->get_ench(ENCH_ABJ); - if (!monster->lose_ench_duration(abj, sockage) && !shielded) - simple_monster_message(monster, " shudders."); + mon_enchant abj = mon->get_ench(ENCH_ABJ); + if (!mon->lose_ench_duration(abj, sockage) && !shielded) + simple_monster_message(*mon, " shudders."); } } } diff --git a/crawl-ref/source/wiz-item.cc b/crawl-ref/source/wiz-item.cc index eb800da140..bae01bc91a 100644 --- a/crawl-ref/source/wiz-item.cc +++ b/crawl-ref/source/wiz-item.cc @@ -22,6 +22,7 @@ #include "it_use2.h" #include "invent.h" #include "makeitem.h" +#include "mon-iter.h" #include "mon-stuff.h" #include "mon-util.h" #include "options.h" @@ -729,25 +730,20 @@ void wizard_unidentify_pack() // Forget things that nearby monsters are carrying, as well. // (For use with the "give monster an item" wizard targetting // command.) - for (int i = 0; i < MAX_MONSTERS; ++i) + for (monster_iterator mon(&you.get_los()); mon; ++mon) { - monsters* mon = &menv[i]; - - if (mon->alive() && mons_near(mon)) + for (int j = 0; j < NUM_MONSTER_SLOTS; ++j) { - for (int j = 0; j < NUM_MONSTER_SLOTS; ++j) - { - if (mon->inv[j] == NON_ITEM) - continue; + if (mon->inv[j] == NON_ITEM) + continue; - item_def &item = mitm[mon->inv[j]]; + item_def &item = mitm[mon->inv[j]]; - if (!item.is_valid()) - continue; + if (!item.is_valid()) + continue; - set_ident_type(item, ID_UNKNOWN_TYPE); - unset_ident_flags(item, ISFLAG_IDENT_MASK); - } + set_ident_type(item, ID_UNKNOWN_TYPE); + unset_ident_flags(item, ISFLAG_IDENT_MASK); } } } |