diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-11-11 22:35:36 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-11-12 09:38:20 +0100 |
commit | 62a3121fcb79a591a6d7310dfa3b394a85bb54e5 (patch) | |
tree | ad004be6e880c9dc7d3a082b2c1e396b5541ab43 | |
parent | bf9183f6523bf96750b50723fc0f783af6fc8e9c (diff) | |
download | crawl-ref-62a3121fcb79a591a6d7310dfa3b394a85bb54e5.tar.gz crawl-ref-62a3121fcb79a591a6d7310dfa3b394a85bb54e5.zip |
Extract funtion to find an unused monster.
-rw-r--r-- | crawl-ref/source/mon-place.cc | 162 | ||||
-rw-r--r-- | crawl-ref/source/mon-place.h | 2 |
2 files changed, 85 insertions, 79 deletions
diff --git a/crawl-ref/source/mon-place.cc b/crawl-ref/source/mon-place.cc index 15c805455c..12c9aac3e6 100644 --- a/crawl-ref/source/mon-place.cc +++ b/crawl-ref/source/mon-place.cc @@ -23,6 +23,7 @@ #include "message.h" #include "mon-behv.h" #include "mon-gear.h" +#include "mon-iter.h" #include "mon-pick.h" #include "mon-util.h" #include "mon-stuff.h" @@ -1000,23 +1001,26 @@ int place_monster(mgen_data mg, bool force_pos) return (id); } +monsters* get_free_monster() +{ + for (int i = 0; i < MAX_MONSTERS; ++i) + if (env.mons[i].type == MONS_NO_MONSTER) + { + env.mons[i].reset(); + return (&env.mons[i]); + } + return (NULL); +} + static int _place_monster_aux(const mgen_data &mg, bool first_band_member, bool force_pos) { - int id = -1; coord_def fpos; - // Gotta be able to pick an ID. - for (id = 0; id < MAX_MONSTERS; id++) - if (menv[id].type == MONS_NO_MONSTER) - break; - - // Too many monsters on level? - if (id == MAX_MONSTERS) + monsters* mon = get_free_monster(); + if (!mon) return (-1); - menv[id].reset(); - const monster_type montype = (mons_class_is_zombified(mg.cls) ? mg.base_type : mg.cls); @@ -1035,8 +1039,8 @@ static int _place_monster_aux(const mgen_data &mg, // We'll try 1000 times for a good spot. for (i = 0; i < 1000; ++i) { - fpos = mg.pos + coord_def( random_range(-3, 3), - random_range(-3, 3) ); + fpos = mg.pos + coord_def(random_range(-3, 3), + random_range(-3, 3)); if (_valid_monster_generation_location(mg, fpos)) break; @@ -1055,16 +1059,16 @@ static int _place_monster_aux(const mgen_data &mg, return (-1); } - monsters &mons(menv[id]); // Now, actually create the monster. (Wheeee!) - mons.type = mg.cls; - mons.base_monster = mg.base_type; - mons.number = mg.number; + mon->type = mg.cls; + mon->base_monster = mg.base_type; + mon->number = mg.number; - mons.moveto(fpos); + mon->moveto(fpos); // Link monster into monster grid. - mgrd(fpos) = id; + int id = mon->mindex(); + env.mgrid(fpos) = id; // Generate a brand shiny new monster, or zombie. if (mons_class_is_zombified(mg.cls)) @@ -1075,8 +1079,8 @@ static int _place_monster_aux(const mgen_data &mg, // Is it a god gift? if (mg.god != GOD_NO_GOD) { - mons.god = mg.god; - mons.flags |= MF_GOD_GIFT; + mon->god = mg.god; + mon->flags |= MF_GOD_GIFT; } // Not a god gift, give priestly monsters a god. else if (mons_class_flag(mg.cls, M_PRIEST)) @@ -1084,17 +1088,17 @@ static int _place_monster_aux(const mgen_data &mg, switch (mons_genus(mg.cls)) { case MONS_ORC: - mons.god = GOD_BEOGH; + mon->god = GOD_BEOGH; break; case MONS_JELLY: - mons.god = GOD_JIYVA; + mon->god = GOD_JIYVA; break; case MONS_MUMMY: case MONS_DRACONIAN: case MONS_ELF: // [ds] Vault defs can request priest monsters of unusual types. default: - mons.god = GOD_NAMELESS; + mon->god = GOD_NAMELESS; break; } } @@ -1102,34 +1106,34 @@ static int _place_monster_aux(const mgen_data &mg, else if (mons_genus(mg.cls) == MONS_ORC) { if (!one_chance_in(7)) - mons.god = GOD_BEOGH; + mon->god = GOD_BEOGH; } // The royal jelly belongs to Jiyva. else if (mg.cls == MONS_ROYAL_JELLY) - mons.god = GOD_JIYVA; + mon->god = GOD_JIYVA; // Angels and Daevas belong to TSO, but 1 out of 7 in the Abyss are // adopted by Xom. else if (mons_class_holiness(mg.cls) == MH_HOLY) { if (mg.level_type != LEVEL_ABYSS || !one_chance_in(7)) - mons.god = GOD_SHINING_ONE; + mon->god = GOD_SHINING_ONE; else - mons.god = GOD_XOM; + mon->god = GOD_XOM; } // 6 out of 7 demons in the Abyss belong to Lugonu. else if (mons_class_holiness(mg.cls) == MH_DEMONIC) { if (mg.level_type == LEVEL_ABYSS && !one_chance_in(7)) - mons.god = GOD_LUGONU; + mon->god = GOD_LUGONU; } // If the caller requested a specific colour for this monster, apply // it now. if (mg.colour != BLACK) - mons.colour = mg.colour; + mon->colour = mg.colour; if (mg.mname != "") - mons.mname = mg.mname; + mon->mname = mg.mname; // The return of Boris is now handled in monster_die(). Not setting // this for Boris here allows for multiple Borises in the dungeon at @@ -1138,16 +1142,16 @@ static int _place_monster_aux(const mgen_data &mg, you.unique_creatures[mg.cls] = true; if (mons_class_flag(mg.cls, M_INVIS)) - mons.add_ench(ENCH_INVIS); + mon->add_ench(ENCH_INVIS); if (mons_class_flag(mg.cls, M_CONFUSED)) - mons.add_ench(ENCH_CONFUSION); + mon->add_ench(ENCH_CONFUSION); if (mg.cls == MONS_SHAPESHIFTER) - mons.add_ench(ENCH_SHAPESHIFTER); + mon->add_ench(ENCH_SHAPESHIFTER); if (mg.cls == MONS_GLOWING_SHAPESHIFTER) - mons.add_ench(ENCH_GLOWING_SHAPESHIFTER); + mon->add_ench(ENCH_GLOWING_SHAPESHIFTER); if (mg.cls == MONS_TOADSTOOL) { @@ -1156,29 +1160,29 @@ static int _place_monster_aux(const mgen_data &mg, // spawning mushrooms in the same place over and over. Aside // from that, the value is slightly randomised to avoid // simultaneous die-offs of mushroom rings. - mons.add_ench(ENCH_SLOWLY_DYING); + mon->add_ench(ENCH_SLOWLY_DYING); } if (mg.cls == MONS_BALLISTOMYCETE) { // This enchantment causes giant spore production. - mons.add_ench(ENCH_SPORE_PRODUCTION); + mon->add_ench(ENCH_SPORE_PRODUCTION); } - if (monster_can_submerge(&mons, grd(fpos)) && !one_chance_in(5)) - mons.add_ench(ENCH_SUBMERGED); + if (monster_can_submerge(mon, grd(fpos)) && !one_chance_in(5)) + mon->add_ench(ENCH_SUBMERGED); - mons.flags |= MF_JUST_SUMMONED; + mon->flags |= MF_JUST_SUMMONED; // Don't leave shifters in their starting shape. if (mg.cls == MONS_SHAPESHIFTER || mg.cls == MONS_GLOWING_SHAPESHIFTER) { no_messages nm; - monster_polymorph(&mons, RANDOM_MONSTER); + monster_polymorph(mon, RANDOM_MONSTER); // It's not actually a known shapeshifter if it happened to be // placed in LOS of the player. - mons.flags &= ~MF_KNOWN_MIMIC; + mon->flags &= ~MF_KNOWN_MIMIC; } // dur should always be 1-6 for monsters that can be abjured. @@ -1191,16 +1195,16 @@ static int _place_monster_aux(const mgen_data &mg, // Dancing weapons *always* have a weapon. Fail to create them // otherwise. - const item_def* wpn = mons.mslot_item(MSLOT_WEAPON); + const item_def* wpn = mon->mslot_item(MSLOT_WEAPON); if (!wpn) { - mons.destroy_inventory(); - mons.reset(); + mon->destroy_inventory(); + mon->reset(); mgrd(fpos) = NON_MONSTER; return (-1); } else - mons.colour = wpn->colour; + mon->colour = wpn->colour; } else if (mons_class_itemuse(mg.cls) >= MONUSE_STARTING_EQUIPMENT) { @@ -1209,13 +1213,13 @@ static int _place_monster_aux(const mgen_data &mg, if (mons_class_wields_two_weapons(mg.cls)) give_item(id, mg.power, summoned); - unwind_var<int> save_speedinc(mons.speed_increment); - mons.wield_melee_weapon(false); + unwind_var<int> save_speedinc(mon->speed_increment); + mon->wield_melee_weapon(false); } // Give manticores 8 to 16 spike volleys. if (mg.cls == MONS_MANTICORE) - mons.number = 8 + random2(9); + mon->number = 8 + random2(9); if (mg.cls == MONS_SLIME_CREATURE) { @@ -1223,21 +1227,21 @@ static int _place_monster_aux(const mgen_data &mg, { // Boost HP to what it would have been if it had grown this // big by merging. - mons.hit_points *= mg.number; - mons.max_hit_points *= mg.number; + mon->hit_points *= mg.number; + mon->max_hit_points *= mg.number; } } // Set attitude, behaviour and target. - mons.attitude = ATT_HOSTILE; - mons.behaviour = mg.behaviour; + mon->attitude = ATT_HOSTILE; + mon->behaviour = mg.behaviour; // Statues cannot sleep (nor wander but it means they are a bit // more aware of the player than they'd be otherwise). if (mons_is_statue(mg.cls)) - mons.behaviour = BEH_WANDER; + mon->behaviour = BEH_WANDER; - mons.foe_memory = 0; + mon->foe_memory = 0; // Setting attitude will always make the monster wander... // If you want sleeping hostiles, use BEH_SLEEP since the default @@ -1245,66 +1249,66 @@ static int _place_monster_aux(const mgen_data &mg, if (mg.behaviour > NUM_BEHAVIOURS) { if (mg.behaviour == BEH_FRIENDLY) - mons.attitude = ATT_FRIENDLY; + mon->attitude = ATT_FRIENDLY; if (mg.behaviour == BEH_GOOD_NEUTRAL) - mons.attitude = ATT_GOOD_NEUTRAL; + mon->attitude = ATT_GOOD_NEUTRAL; if (mg.behaviour == BEH_NEUTRAL) - mons.attitude = ATT_NEUTRAL; + mon->attitude = ATT_NEUTRAL; if (mg.behaviour == BEH_STRICT_NEUTRAL) - mons.attitude = ATT_STRICT_NEUTRAL; + mon->attitude = ATT_STRICT_NEUTRAL; - mons.behaviour = BEH_WANDER; + mon->behaviour = BEH_WANDER; } if (summoned) { - mons.mark_summoned(mg.abjuration_duration, true, - mg.summon_type); + mon->mark_summoned(mg.abjuration_duration, true, + mg.summon_type); } - mons.foe = mg.foe; + mon->foe = mg.foe; // Initialise (very) ugly things and pandemonium demons. - if (mons.type == MONS_UGLY_THING - || mons.type == MONS_VERY_UGLY_THING) + if (mon->type == MONS_UGLY_THING + || mon->type == MONS_VERY_UGLY_THING) { ghost_demon ghost; - ghost.init_ugly_thing(mons.type == MONS_VERY_UGLY_THING, false, + ghost.init_ugly_thing(mon->type == MONS_VERY_UGLY_THING, false, mg.colour); - mons.set_ghost(ghost, false); - mons.uglything_init(); + mon->set_ghost(ghost, false); + mon->uglything_init(); } - else if (mons.type == MONS_PANDEMONIUM_DEMON) + else if (mon->type == MONS_PANDEMONIUM_DEMON) { ghost_demon ghost; ghost.init_random_demon(); - mons.set_ghost(ghost); - mons.pandemon_init(); + mon->set_ghost(ghost); + mon->pandemon_init(); } - else if (mons.type == MONS_DANCING_WEAPON) + else if (mon->type == MONS_DANCING_WEAPON) { ghost_demon ghost; // We can't use monsters::weapon here because it wants to look // at attack types, which are in the ghost structure we're // building. - ASSERT( mons.mslot_item(MSLOT_WEAPON) ); + ASSERT(mon->mslot_item(MSLOT_WEAPON)); // Dancing weapons are placed at pretty high power. Remember, the // player is fighting them one-on-one, while he will often summon // several. - ghost.init_dancing_weapon(*(mons.mslot_item(MSLOT_WEAPON)), 180); - mons.set_ghost(ghost); - mons.dancing_weapon_init(); + ghost.init_dancing_weapon(*(mon->mslot_item(MSLOT_WEAPON)), 180); + mon->set_ghost(ghost); + mon->dancing_weapon_init(); } - mark_interesting_monst(&mons, mg.behaviour); + mark_interesting_monst(mon, mg.behaviour); - if (you.can_see(&mons)) - handle_seen_interrupt(&mons); + if (you.can_see(mon)) + handle_seen_interrupt(mon); if (crawl_state.arena) - arena_placed_monster(&mons); + arena_placed_monster(mon); return (id); } diff --git a/crawl-ref/source/mon-place.h b/crawl-ref/source/mon-place.h index df810c11bb..9f1f0606d3 100644 --- a/crawl-ref/source/mon-place.h +++ b/crawl-ref/source/mon-place.h @@ -335,6 +335,8 @@ void setup_vault_mon_list(); int mons_tracking_range(const monsters *mon); +monsters* get_free_monster(); + class monster_pathfind { public: |