From b3d8365da8efb695a18b85146a4e50ee0e9d7698 Mon Sep 17 00:00:00 2001 From: dolorous Date: Mon, 16 Jun 2008 19:27:45 +0000 Subject: Clean up and consolidate most of the monster pacification routines. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5885 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/delay.cc | 12 ++---------- crawl-ref/source/mon-util.cc | 19 +++++++++++++++++-- crawl-ref/source/mon-util.h | 8 +++++++- crawl-ref/source/spells1.cc | 12 +++--------- 4 files changed, 29 insertions(+), 22 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index 81f8aba5ca..eb8268df08 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -198,23 +198,15 @@ static int _recite_to_monsters(int x, int y, int pow, int unused) } else { - // permanently neutral - mons->attitude = ATT_NEUTRAL; - mons->flags |= MF_WAS_NEUTRAL; - - // give half of the monster's xp - unsigned int exp_gain = 0, avail_gain = 0; - gain_exp( exper_value(mons) / 2 + 1, &exp_gain, &avail_gain ); - mons->flags |= MF_GOT_HALF_XP; - simple_monster_message(mons, " seems fully impressed!"); + mons_pacify(mons); } } break; } return (1); -} // end recite_to_monsters() +} static const char* _get_recite_speech(const std::string key, int weight) { diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index e6930fad96..b87f450e3f 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2127,10 +2127,10 @@ mon_attitude_type mons_attitude(const monsters *m) return ATT_HOSTILE; } -bool mons_is_submerged(const monsters *mon) +bool mons_is_submerged(const monsters *m) { // FIXME, switch to 4.1's MF_SUBMERGED system which is much cleaner. - return (mon->has_ench(ENCH_SUBMERGED)); + return (m->has_ench(ENCH_SUBMERGED)); } bool mons_is_paralysed(const monsters *m) @@ -2214,6 +2214,21 @@ bool mons_looks_distracted(const monsters *m) || mons_is_petrifying(m))); } +void mons_pacify(monsters *mon) +{ + // Make the monster permanently neutral. + mon->attitude = ATT_NEUTRAL; + mon->flags |= MF_WAS_NEUTRAL; + + if (!testbits(mon->flags, MF_GOT_HALF_XP)) + { + // Give the player half of the monster's XP. + unsigned int exp_gain = 0, avail_gain = 0; + gain_exp(exper_value(mon) / 2 + 1, &exp_gain, &avail_gain); + mon->flags |= MF_GOT_HALF_XP; + } +} + bool mons_should_fire(struct bolt &beam) { #ifdef DEBUG_DIAGNOSTICS diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 8a56ef67c9..82b5a10f2a 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -584,6 +584,12 @@ void mons_load_spells( monsters *mon, mon_spellbook_type book ); void define_monster(int mid); void define_monster(monsters &mons); +// last updated 4jan2001 (gdl) +/* *********************************************************************** + * called from: delay - monstuff - spells1 + * *********************************************************************** */ +void mons_pacify(monsters *mon); + // last updated 4jan2001 (gdl) /* *********************************************************************** * called from: monstuff @@ -673,7 +679,7 @@ bool mons_is_stationary(const monsters *mon); bool mons_is_wall_shielded(int mc); bool mons_is_insubstantial(int mc); bool mons_has_blood(int mc); -bool mons_is_submerged(const monsters *mon); +bool mons_is_submerged(const monsters *m); bool invalid_monster(const monsters *mon); bool invalid_monster_class(int mclass); diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc index 4639baad68..0ed1ac0e53 100644 --- a/crawl-ref/source/spells1.cc +++ b/crawl-ref/source/spells1.cc @@ -602,7 +602,7 @@ void big_cloud(cloud_type cl_type, kill_category whose, static bool _mons_hostile(const monsters *mon) { // Needs to be done this way because of friendly/neutral enchantments. - return (!mons_friendly(mon) && !mons_neutral(mon)); + return (!mons_wont_attack(mon) && !mons_neutral(mon)); } static bool _can_pacify_monster(const monsters *mon, const int healed) @@ -732,15 +732,9 @@ static int _healing_spell( int healed, int target_x = -1, int target_y = -1) else { simple_monster_message( monster, " turns neutral." ); - monster->attitude = ATT_NEUTRAL; - monster->flags |= MF_WAS_NEUTRAL; + mons_pacify(monster); - // give half of the monster's xp - unsigned int exp_gain = 0, avail_gain = 0; - gain_exp( exper_value(monster) / 2 + 1, &exp_gain, &avail_gain ); - monster->flags |= MF_GOT_HALF_XP; - - // finally give a small piety return + // give a small piety return gain_piety(1 + random2(healed/15)); } } -- cgit v1.2.3-54-g00ecf