From 6963b000a2dc694900f9eb3252ef5363ce8ddf92 Mon Sep 17 00:00:00 2001 From: Vsevolod Kozlov Date: Fri, 13 Nov 2009 16:27:50 +0300 Subject: Replace monster_index with monsters::mindex. --- crawl-ref/source/dbg-util.cc | 4 ++-- crawl-ref/source/effects.cc | 4 ++-- crawl-ref/source/godabil.cc | 2 +- crawl-ref/source/mon-abil.cc | 10 +++++----- crawl-ref/source/mon-act.cc | 14 +++++++------- crawl-ref/source/mon-behv.cc | 4 ++-- crawl-ref/source/mon-cast.cc | 10 +++++----- crawl-ref/source/mon-stuff.cc | 30 ++++++++++++------------------ crawl-ref/source/mon-stuff.h | 2 -- crawl-ref/source/monster.cc | 6 +++--- crawl-ref/source/religion.cc | 2 +- crawl-ref/source/spells3.cc | 2 +- 12 files changed, 41 insertions(+), 49 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/dbg-util.cc b/crawl-ref/source/dbg-util.cc index 12b2bf7931..e8a0c1a153 100644 --- a/crawl-ref/source/dbg-util.cc +++ b/crawl-ref/source/dbg-util.cc @@ -151,7 +151,7 @@ std::string debug_coord_str(const coord_def &pos) std::string debug_mon_str(const monsters* mon) { - const int midx = monster_index(mon); + const int midx = mon->mindex(); if (invalid_monster_index(midx)) return make_stringf("Invalid monster index %d", midx); @@ -164,7 +164,7 @@ std::string debug_mon_str(const monsters* mon) void debug_dump_mon(const monsters* mon, bool recurse) { - const int midx = monster_index(mon); + const int midx = mon->mindex(); if (invalid_monster_index(midx) || invalid_monster_type(mon->type)) return; diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index f74729b323..f0160ef846 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -837,7 +837,7 @@ void direct_effect(monsters *source, spell_type spell, if (def) { // annoy the target - behaviour_event(def, ME_ANNOY, monster_index(source)); + behaviour_event(def, ME_ANNOY, source->mindex()); } int damage_taken = 0; @@ -4006,7 +4006,7 @@ static void _catchup_monster_moves(monsters *mon, int turns) mprf(MSGCH_DIAGNOSTICS, "mon #%d: range %d; long %d; " "pos (%d,%d); targ %d(%d,%d); flags %ld", - monster_index(mon), range, long_time, mon->pos().x, mon->pos().y, + mon->mindex(), range, long_time, mon->pos().x, mon->pos().y, mon->foe, mon->target.x, mon->target.y, mon->flags ); #endif diff --git a/crawl-ref/source/godabil.cc b/crawl-ref/source/godabil.cc index 69986ec4be..48876a0a2c 100644 --- a/crawl-ref/source/godabil.cc +++ b/crawl-ref/source/godabil.cc @@ -290,7 +290,7 @@ void yred_make_enslaved_soul(monsters *mon, bool force_hostile, mon->base_monster = soul_type; // Re-equip the spectral thing. - equip_undead(mon->pos(), corps, monster_index(mon), + equip_undead(mon->pos(), corps, mon->mindex(), mon->base_monster); // Destroy the monster's corpse, as it's no longer needed. diff --git a/crawl-ref/source/mon-abil.cc b/crawl-ref/source/mon-abil.cc index 02afabec9a..ba42c46658 100644 --- a/crawl-ref/source/mon-abil.cc +++ b/crawl-ref/source/mon-abil.cc @@ -572,7 +572,7 @@ static bool _orange_statue_effects(monsters *mons) foe->name(DESC_NOCAP_THE).c_str()); } - MiscastEffect(foe, monster_index(mons), SPTYP_DIVINATION, + MiscastEffect(foe, mons->mindex(), SPTYP_DIVINATION, random2(15), random2(150), "an orange crystal statue"); return (true); @@ -592,7 +592,7 @@ static bool _orc_battle_cry(monsters *chief) && chief->can_see(foe) && coinflip()) { - const int boss_index = monster_index(chief); + const int boss_index = chief->mindex(); const int level = chief->hit_dice > 12? 2 : 1; std::vector seen_affected; for (monster_iterator mi(chief); mi; ++mi) @@ -873,7 +873,7 @@ bool mon_special_ability(monsters *monster, bolt & beem) beem.colour = RED; beem.type = dchar_glyph(DCHAR_FIRED_ZAP); beem.flavour = BEAM_LAVA; - beem.beam_source = monster_index(monster); + beem.beam_source = monster->mindex(); beem.thrower = KILL_MON; // Fire tracer. @@ -908,7 +908,7 @@ bool mon_special_ability(monsters *monster, bolt & beem) beem.colour = LIGHTCYAN; beem.type = dchar_glyph(DCHAR_FIRED_ZAP); beem.flavour = BEAM_ELECTRICITY; - beem.beam_source = monster_index(monster); + beem.beam_source = monster->mindex(); beem.thrower = KILL_MON; beem.is_beam = true; @@ -1067,7 +1067,7 @@ bool mon_special_ability(monsters *monster, bolt & beem) beem.range = 6; beem.hit = 14; beem.damage = dice_def( 2, 10 ); - beem.beam_source = monster_index(monster); + beem.beam_source = monster->mindex(); beem.type = dchar_glyph(DCHAR_FIRED_MISSILE); beem.colour = LIGHTGREY; beem.flavour = BEAM_MISSILE; diff --git a/crawl-ref/source/mon-act.cc b/crawl-ref/source/mon-act.cc index f699d7578e..d58b1fc1d2 100644 --- a/crawl-ref/source/mon-act.cc +++ b/crawl-ref/source/mon-act.cc @@ -745,7 +745,7 @@ static bool _handle_reaching(monsters *monster) if (monster->submerged()) return (false); - if (mons_aligned(monster_index(monster), monster->foe)) + if (mons_aligned(monster->mindex(), monster->foe)) return (false); if (wpn != NON_ITEM && get_weapon_brand(mitm[wpn]) == SPWPN_REACHING) @@ -927,7 +927,7 @@ static bool _handle_wand(monsters *monster, bolt &beem) bolt theBeam = mons_spells(monster, mzap, power); beem.name = theBeam.name; - beem.beam_source = monster_index(monster); + beem.beam_source = monster->mindex(); beem.source = monster->pos(); beem.colour = theBeam.colour; beem.range = theBeam.range; @@ -1067,7 +1067,7 @@ static void _setup_generic_throw(struct monsters *monster, struct bolt &pbolt) { // FIXME we should use a sensible range here pbolt.range = LOS_RADIUS; - pbolt.beam_source = monster_index(monster); + pbolt.beam_source = monster->mindex(); pbolt.type = dchar_glyph(DCHAR_FIRED_MISSILE); pbolt.flavour = BEAM_MISSILE; @@ -2713,7 +2713,7 @@ static bool _mons_can_displace(const monsters *mpusher, if (invalid_monster(mpusher) || invalid_monster(mpushee)) return (false); - const int ipushee = monster_index(mpushee); + const int ipushee = mpushee->mindex(); if (invalid_monster_index(ipushee)) return (false); @@ -3041,9 +3041,9 @@ static bool _monster_swaps_places( monsters *mon, const coord_def& delta ) _swim_or_move_energy(mon); mon->set_position(n); - mgrd(n) = monster_index(mon); + mgrd(n) = mon->mindex(); m2->set_position(c); - const int m2i = monster_index(m2); + const int m2i = m2->mindex(); ASSERT(m2i >= 0 && m2i < MAX_MONSTERS); mgrd(c) = m2i; immobile_monster[m2i] = true; @@ -3108,7 +3108,7 @@ static bool _do_move_monster(monsters *monster, const coord_def& delta) monster->set_position(f); - mgrd(monster->pos()) = monster_index(monster); + mgrd(monster->pos()) = monster->mindex(); ballisto_on_move(monster, old_pos); diff --git a/crawl-ref/source/mon-behv.cc b/crawl-ref/source/mon-behv.cc index 03ae622bb9..25045c6546 100644 --- a/crawl-ref/source/mon-behv.cc +++ b/crawl-ref/source/mon-behv.cc @@ -908,7 +908,7 @@ static void _check_wander_target(monsters *mon, bool isPacified = false, static void _arena_set_foe(monsters *mons) { - const int mind = monster_index(mons); + const int mind = mons->mindex(); int nearest = -1; int best_distance = -1; @@ -1216,7 +1216,7 @@ void handle_behaviour(monsters *mon) _set_nearest_monster_foe(mon); // Monsters do not attack themselves. {dlb} - if (mon->foe == monster_index(mon)) + if (mon->foe == mon->mindex()) mon->foe = MHITNOT; // Friendly and good neutral monsters do not attack other friendly diff --git a/crawl-ref/source/mon-cast.cc b/crawl-ref/source/mon-cast.cc index daf8520ac1..80d395cbf8 100644 --- a/crawl-ref/source/mon-cast.cc +++ b/crawl-ref/source/mon-cast.cc @@ -738,7 +738,7 @@ bool setup_mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast, else if (spell_cast == SPELL_SLEEP) pbolt.ench_power = 6 * monster->hit_dice; - pbolt.beam_source = monster_index(monster); + pbolt.beam_source = monster->mindex(); // Convenience for the hapless innocent who assumes that this // damn function does all possible setup. [ds] @@ -1192,7 +1192,7 @@ bool handle_mon_spell(monsters *monster, bolt &beem) spellOK = true; if (ms_direct_nasty(spell_cast) - && mons_aligned(monster_index(monster), + && mons_aligned(monster->mindex(), monster->foe)) { spellOK = false; @@ -1543,7 +1543,7 @@ void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast, #if DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Mon #%d casts %s (#%d)", - monster_index(monster), spell_title(spell_cast), spell_cast); + monster->mindex(), spell_title(spell_cast), spell_cast); #endif if (spell_cast == SPELL_CANTRIP) @@ -1681,7 +1681,7 @@ void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast, case SPELL_KRAKEN_TENTACLES: { - int kraken_index = monster_index(monster); + int kraken_index = monster->mindex(); if (invalid_monster_index(duration)) { mpr("Error! Kraken is not a part of the current environment!", @@ -1875,7 +1875,7 @@ void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast, if (!monsterNearby || monster->friendly()) return; - torment(monster_index(monster), monster->pos()); + torment(monster->mindex(), monster->pos()); return; case SPELL_SUMMON_GREATER_DEMON: diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc index f3beee2fc5..d507a7d7f8 100644 --- a/crawl-ref/source/mon-stuff.cc +++ b/crawl-ref/source/mon-stuff.cc @@ -549,7 +549,7 @@ static void _give_monster_experience(monsters *victim, return; if ((!victim_was_born_friendly || !mon->friendly()) - && !mons_aligned(killer_index, monster_index(victim))) + && !mons_aligned(killer_index, victim->mindex())) { if (mon->gain_exp(experience)) { @@ -869,7 +869,7 @@ static void _fire_monster_death_event(monsters *monster, dungeon_events.fire_event( dgn_event(DET_MONSTER_DIED, monster->pos(), 0, - monster_index(monster), killer)); + monster->mindex(), killer)); if (type == MONS_ROYAL_JELLY && !polymorph) { @@ -949,7 +949,7 @@ static void _mummy_curse(monsters* monster, killer_type killer, int index) mprf(MSGCH_MONSTER_SPELL, "A malignant aura surrounds %s.", target->name(DESC_NOCAP_THE).c_str()); } - MiscastEffect(target, monster_index(monster), SPTYP_NECROMANCY, + MiscastEffect(target, monster->mindex(), SPTYP_NECROMANCY, pow, random2avg(88, 3), "a mummy death curse"); } } @@ -968,7 +968,7 @@ static bool _spore_goes_pop(monsters *monster, killer_type killer, beam.is_tracer = false; beam.is_explosion = true; - beam.beam_source = monster_index(monster); + beam.beam_source = monster->mindex(); beam.type = dchar_glyph(DCHAR_FIRED_BURST); beam.source = monster->pos(); beam.target = monster->pos(); @@ -1312,7 +1312,7 @@ void mons_relocated(monsters *monster) { if (monster->type == MONS_KRAKEN) { - int headnum = monster_index(monster); + int headnum = monster->mindex(); if (invalid_monster_index(headnum)) return; @@ -1341,7 +1341,7 @@ void mons_relocated(monsters *monster) static int _destroy_tentacles(monsters *head) { int tent = 0; - int headnum = monster_index(head); + int headnum = head->mindex(); if (invalid_monster_index(headnum)) return 0; @@ -1443,7 +1443,7 @@ int monster_die(monsters *monster, killer_type killer, int summon_type = 0; int duration = 0; const bool summoned = monster->is_summoned(&duration, &summon_type); - const int monster_killed = monster_index(monster); + const int monster_killed = monster->mindex(); const bool hard_reset = testbits(monster->flags, MF_HARD_RESET); const bool gives_xp = (!summoned && !mons_class_flag(monster->type, M_NO_EXP_GAIN)); @@ -2172,7 +2172,7 @@ void monster_cleanup(monsters *monster) { crawl_state.mon_gone(monster); - unsigned int monster_killed = monster_index(monster); + unsigned int monster_killed = monster->mindex(); monster->reset(); for (monster_iterator mi; mi; ++mi) @@ -2455,7 +2455,7 @@ bool monster_polymorph(monsters *monster, monster_type targetc, monster->number = 0; // Note: define_monster() will clear out all enchantments! - bwr - define_monster(monster_index(monster)); + define_monster(monster->mindex()); monster->mname = name; monster->flags = flags; @@ -2750,7 +2750,7 @@ bool swap_places(monsters *monster, const coord_def &loc) monster->moveto(loc); - mgrd(monster->pos()) = monster_index(monster); + mgrd(monster->pos()) = monster->mindex(); return true; } @@ -3375,7 +3375,7 @@ void mons_check_pool(monsters *monster, const coord_def &oldpos, { // Self-kill. killer = KILL_MON; - killnum = monster_index(monster); + killnum = monster->mindex(); } // Yredelemnul special, redux: It's the only one that can @@ -3484,12 +3484,6 @@ bool message_current_target() return (false); } -// aaah, the simple joys of pointer arithmetic! {dlb}: -unsigned int monster_index(const monsters *monster) -{ - return (monster - menv.buffer()); -} - void seen_monster(monsters *monster) { // If the monster is in the auto_exclude list, automatically @@ -3699,7 +3693,7 @@ void monster_teleport(monsters *monster, bool instan, bool silent) if (monster_random_space(monster, newpos, !monster->wont_attack())) monster->moveto(newpos); - mgrd(monster->pos()) = monster_index(monster); + mgrd(monster->pos()) = monster->mindex(); // Mimics change form/colour when teleported. if (mons_is_mimic(monster->type)) diff --git a/crawl-ref/source/mon-stuff.h b/crawl-ref/source/mon-stuff.h index 525cb666e0..4c69d6b58a 100644 --- a/crawl-ref/source/mon-stuff.h +++ b/crawl-ref/source/mon-stuff.h @@ -135,8 +135,6 @@ std::string get_wounds_description(const monsters *monster); void print_wounds(const monsters *monster); bool monster_descriptor(int which_class, mon_desc_type which_descriptor); -unsigned int monster_index(const monsters *monster); - void mons_get_damage_level(const monsters*, std::string& desc, mon_dam_level_type&); diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc index 2944ff1188..04ffff0e5c 100644 --- a/crawl-ref/source/monster.cc +++ b/crawl-ref/source/monster.cc @@ -1070,7 +1070,7 @@ bool monsters::pickup(item_def &item, int slot, int near, bool force_merge) { dungeon_events.fire_position_event( dgn_event(DET_ITEM_PICKUP, pos(), 0, item.index(), - monster_index(this)), + mindex()), pos()); pickup_message(item, near); @@ -1086,7 +1086,7 @@ bool monsters::pickup(item_def &item, int slot, int near, bool force_merge) dungeon_events.fire_position_event( dgn_event(DET_ITEM_PICKUP, pos(), 0, item.index(), - monster_index(this)), + mindex()), pos()); const int item_index = item.index(); @@ -2644,7 +2644,7 @@ monster_type monsters::id() const int monsters::mindex() const { - return (monster_index(this)); + return (this - menv.buffer()); } int monsters::get_experience_level() const diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 74158c88b8..e51a7a9a5a 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -3518,7 +3518,7 @@ void religion_turn_end() void set_attack_conducts(god_conduct_trigger conduct[3], const monsters *mon, bool known) { - const unsigned int midx = monster_index(mon); + const unsigned int midx = mon->mindex(); if (mon->friendly()) { diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc index 17b33ead54..a14535c98f 100644 --- a/crawl-ref/source/spells3.cc +++ b/crawl-ref/source/spells3.cc @@ -1282,7 +1282,7 @@ bool cast_haunt(int pow, const coord_def& where, god_type god) return (true); } - int mi = monster_index(m); + int mi = m->mindex(); ASSERT(!invalid_monster_index(mi)); if (stop_attack_prompt(m, false, you.pos())) -- cgit v1.2.3-54-g00ecf