diff options
-rw-r--r-- | crawl-ref/source/mon-act.cc | 16 | ||||
-rw-r--r-- | crawl-ref/source/mon-stuff.cc | 38 | ||||
-rw-r--r-- | crawl-ref/source/spl-cast.cc | 14 |
3 files changed, 23 insertions, 45 deletions
diff --git a/crawl-ref/source/mon-act.cc b/crawl-ref/source/mon-act.cc index 1ca78665b2..08993ab449 100644 --- a/crawl-ref/source/mon-act.cc +++ b/crawl-ref/source/mon-act.cc @@ -2128,18 +2128,10 @@ static bool _jelly_divide(monsters *parent) if ( num_spots == 0 ) return (false); - int k = 0; - // Now that we have a spot, find a monster slot {dlb}: - for (k = 0; k < MAX_MONSTERS; k++) - { - child = &menv[k]; - - if (child->type == -1) - break; - else if (k == MAX_MONSTERS - 1) - return (false); - } + child = get_free_monster(); + if (!child) + return (false); // Handle impact of split on parent {dlb}: parent->max_hit_points /= 2; @@ -2158,7 +2150,7 @@ static bool _jelly_divide(monsters *parent) child->speed_increment = 70 + random2(5); child->moveto(child_spot); - mgrd(child->pos()) = k; + mgrd(child->pos()) = child->mindex(); if (!simple_monster_message(parent, " splits in two!")) if (player_can_hear(parent->pos()) || player_can_hear(child->pos())) diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc index bf40170354..fd300ea86c 100644 --- a/crawl-ref/source/mon-stuff.cc +++ b/crawl-ref/source/mon-stuff.cc @@ -3832,15 +3832,9 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious, coord_def pos) { // Is there an open slot in menv? - int midx = NON_MONSTER; - for (int i = 0; i < MAX_MONSTERS; i++) - if (menv[i].type == MONS_NO_MONSTER) - { - midx = i; - break; - } + monsters* mons = get_free_monster(); - if (midx == NON_MONSTER) + if (!mons) return (NON_MONSTER); if (!in_bounds(pos)) @@ -3866,11 +3860,9 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious, ASSERT( !actor_at(pos) ); - monsters &mon(menv[midx]); - - mon = *orig; - mon.set_position(pos); - mgrd(pos) = midx; + *mons = *orig; + mons->set_position(pos); + mgrd(pos) = mons->mindex(); // Duplicate objects, or unequip them if they can't be duplicated. for (int i = 0; i < NUM_MONSTER_SLOTS; i++) @@ -3883,14 +3875,14 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious, const int new_index = get_item_slot(0); if (new_index == NON_ITEM) { - mon.unequip(mitm[old_index], i, 0, true); - mon.inv[i] = NON_ITEM; + mons->unequip(mitm[old_index], i, 0, true); + mons->inv[i] = NON_ITEM; continue; } - mon.inv[i] = new_index; + mons->inv[i] = new_index; mitm[new_index] = mitm[old_index]; - mitm[new_index].set_holding_monster(midx); + mitm[new_index].set_holding_monster(mons->mindex()); } bool _obvious; @@ -3898,24 +3890,24 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious, obvious = &_obvious; *obvious = false; - if (you.can_see(orig) && you.can_see(&mon)) + if (you.can_see(orig) && you.can_see(mons)) { if (!quiet) simple_monster_message(orig, " is duplicated!"); *obvious = true; } - mark_interesting_monst(&mon, mon.behaviour); - if (you.can_see(&mon)) + mark_interesting_monst(mons, mons->behaviour); + if (you.can_see(mons)) { - handle_seen_interrupt(&mon); + handle_seen_interrupt(mons); viewwindow(false); } if (crawl_state.arena) - arena_placed_monster(&mon); + arena_placed_monster(mons); - return (midx); + return (mons->mindex()); } std::string summoned_poof_msg(const monsters* monster, bool plural) diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 94d6aa27cc..bc0e65d97e 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -34,6 +34,7 @@ #include "misc.h" #include "message.h" #include "mon-cast.h" +#include "mon-place.h" #include "mon-stuff.h" #include "mutation.h" #include "ouch.h" @@ -1039,13 +1040,8 @@ static void _try_monster_cast(spell_type spell, int powc, return; } - int midx; - - for (midx = 0; midx < MAX_MONSTERS; midx++) - if (menv[midx].type == MONS_NO_MONSTER) - break; - - if (midx == MAX_MONSTERS) + monsters* mon = get_free_monster(); + if (!mon) { mpr("Couldn't try casting monster spell because there is " "no empty monster slot."); @@ -1054,8 +1050,6 @@ static void _try_monster_cast(spell_type spell, int powc, mpr("Invalid player spell, attempting to cast it as monster spell."); - monsters* mon = &menv[midx]; - mon->mname = "Dummy Monster"; mon->type = MONS_HUMAN; mon->behaviour = BEH_SEEK; @@ -1079,7 +1073,7 @@ static void _try_monster_cast(spell_type spell, int powc, else mon->foe = mgrd(spd.target); - mgrd(you.pos()) = midx; + mgrd(you.pos()) = mon->mindex(); mons_cast(mon, beam, spell); |