diff options
author | Adam Borowski <kilobyte@angband.pl> | 2012-01-05 14:55:45 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2012-01-05 15:08:09 +0100 |
commit | b8daaf465ebac57c905efccb3ce5c0caa44aa94e (patch) | |
tree | 16e193ed4b0a4582fe2f87f2c18e30c10857013f /crawl-ref/source/mon-transit.cc | |
parent | 2db87d6d5c94edc73c41230093cc3d1cfe251bf1 (diff) | |
download | crawl-ref-b8daaf465ebac57c905efccb3ce5c0caa44aa94e.tar.gz crawl-ref-b8daaf465ebac57c905efccb3ce5c0caa44aa94e.zip |
Some more mindexicide.
Also, rename a variable "fmenv" in a few places, it referred to menv[f],
and now only confuses grep.
Diffstat (limited to 'crawl-ref/source/mon-transit.cc')
-rw-r--r-- | crawl-ref/source/mon-transit.cc | 110 |
1 files changed, 53 insertions, 57 deletions
diff --git a/crawl-ref/source/mon-transit.cc b/crawl-ref/source/mon-transit.cc index 1146b66a54..07147fc38c 100644 --- a/crawl-ref/source/mon-transit.cc +++ b/crawl-ref/source/mon-transit.cc @@ -240,51 +240,47 @@ void follower::load_mons_items() bool follower::place(bool near_player) { - for (int i = 0; i < MAX_MONSTERS - 5; ++i) - { - // Find first empty slot in menv and copy monster into it. - monster& m = menv[i]; - if (m.alive()) - continue; - m = mons; + monster *m = get_free_monster(); + if (!m) + return false; - bool placed = false; + // Copy the saved data. + *m = mons; - // In certain instances (currently, falling through a shaft) - // try to place monster as close as possible to its previous - // <x,y> coordinates. - if (!near_player && you.level_type == LEVEL_DUNGEON - && in_bounds(m.pos())) - { - const coord_def where_to_go = - dgn_find_nearby_stair(DNGN_ESCAPE_HATCH_DOWN, - m.pos(), true); - - if (where_to_go == you.pos()) - near_player = true; - else if (m.find_home_near_place(where_to_go)) - placed = true; - } + bool placed = false; - if (!placed) - placed = m.find_place_to_live(near_player); + // In certain instances (currently, falling through a shaft) + // try to place monster as close as possible to its previous + // <x,y> coordinates. + if (!near_player && you.level_type == LEVEL_DUNGEON + && in_bounds(m->pos())) + { + const coord_def where_to_go = + dgn_find_nearby_stair(DNGN_ESCAPE_HATCH_DOWN, + m->pos(), true); - if (placed) - { - dprf("Placed follower: %s", m.name(DESC_PLAIN).c_str()); - m.target.reset(); + if (where_to_go == you.pos()) + near_player = true; + else if (m->find_home_near_place(where_to_go)) + placed = true; + } - m.flags &= ~MF_TAKING_STAIRS; - m.flags |= MF_JUST_SUMMONED; + if (!placed) + placed = m->find_place_to_live(near_player); - restore_mons_items(m); - return (true); - } + if (placed) + { + dprf("Placed follower: %s", m->name(DESC_PLAIN).c_str()); + m->target.reset(); + + m->flags &= ~MF_TAKING_STAIRS; + m->flags |= MF_JUST_SUMMONED; - m.reset(); - break; + restore_mons_items(*m); + return (true); } + m->reset(); return (false); } @@ -320,26 +316,26 @@ static bool _tag_follower_at(const coord_def &pos, bool &real_follower) if (!in_bounds(pos) || pos == you.pos()) return (false); - monster* fmenv = monster_at(pos); - if (fmenv == NULL) + monster* fol = monster_at(pos); + if (fol == NULL) return (false); - if (!fmenv->alive() - || fmenv->speed_increment < 50 - || fmenv->incapacitated() - || mons_is_stationary(fmenv)) + if (!fol->alive() + || fol->speed_increment < 50 + || fol->incapacitated() + || mons_is_stationary(fol)) { return (false); } - if (!monster_habitable_grid(fmenv, DNGN_FLOOR)) + if (!monster_habitable_grid(fol, DNGN_FLOOR)) return (false); // Only non-wandering friendly monsters or those actively // seeking the player will follow up/down stairs. - if (!fmenv->friendly() - && (!mons_is_seeking(fmenv) || fmenv->foe != MHITYOU) - || fmenv->foe == MHITNOT) + if (!fol->friendly() + && (!mons_is_seeking(fol) || fol->foe != MHITYOU) + || fol->foe == MHITNOT) { return (false); } @@ -348,23 +344,23 @@ static bool _tag_follower_at(const coord_def &pos, bool &real_follower) // stringent checks. if ((pos - you.pos()).abs() > 2) { - if (!fmenv->friendly()) + if (!fol->friendly()) return (false); // Undead will follow Yredelemnul worshippers, and orcs will // follow Beogh worshippers. - if (!_is_religious_follower(fmenv)) + if (!_is_religious_follower(fol)) return (false); } // Monsters that can't use stairs can still be marked as followers // (though they'll be ignored for transit), so any adjacent real // follower can follow through. (jpeg) - if (!mons_can_use_stairs(fmenv)) + if (!mons_can_use_stairs(fol)) { - if (_is_religious_follower(fmenv)) + if (_is_religious_follower(fol)) { - fmenv->flags |= MF_TAKING_STAIRS; + fol->flags |= MF_TAKING_STAIRS; return (true); } return (false); @@ -373,17 +369,17 @@ static bool _tag_follower_at(const coord_def &pos, bool &real_follower) real_follower = true; // Monster is chasing player through stairs. - fmenv->flags |= MF_TAKING_STAIRS; + fol->flags |= MF_TAKING_STAIRS; // Clear patrolling/travel markers. - fmenv->patrol_point.reset(); - fmenv->travel_path.clear(); - fmenv->travel_target = MTRAV_NONE; + fol->patrol_point.reset(); + fol->travel_path.clear(); + fol->travel_target = MTRAV_NONE; - fmenv->clear_clinging(); + fol->clear_clinging(); dprf("%s is marked for following.", - fmenv->name(DESC_THE, true).c_str()); + fol->name(DESC_THE, true).c_str()); return (true); } |