From be0551c2205ac189be5558447625642553c80dd3 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Thu, 12 Nov 2009 20:15:52 -0800 Subject: porkulator: completely restore reverted monsters --- crawl-ref/source/mon-stuff.cc | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'crawl-ref/source/mon-stuff.cc') diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc index d035182376..5cf5677528 100644 --- a/crawl-ref/source/mon-stuff.cc +++ b/crawl-ref/source/mon-stuff.cc @@ -1320,23 +1320,42 @@ static void _hogs_to_humans() const bool could_see = you.can_see(*mi); - // XXX: This resets the size of slime creatures, the number - // of heads a hydra has, and the number of spikes a manticore - // has. Plus it also changes the colour of a draconian which - // has a sub-type. And it re-rolls the spellbook the monster - // has. - if (mi->number == 0) - mi->type = MONS_HUMAN; + monsters _orig; + monsters* orig; + + if (mi->props.exists(ORIG_MONSTER_KEY)) + { + orig = &(mi->props[ORIG_MONSTER_KEY].get_monster()); + } else - mi->type = (monster_type) (mi->number - 1); + { + orig = &_orig; + orig->type = MONS_HUMAN; + define_monster(*orig); + } + + // Preserve relative HP. + const float hp + = (float) mi->hit_points / (float) mi->max_hit_points; + // Preserve some flags. + const unsigned long preserve_flags = + mi->flags & ~(MF_JUST_SUMMONED | MF_WAS_IN_VIEW); - // Keep enchantments. + // Preserve enchantments. mon_enchant_list enchantments = mi->enchantments; - mi->number = 0; - define_monster(**mi); + // Restore original monster. + **mi = *orig; mi->enchantments = enchantments; + mi->hit_points = std::max(1, (int) (mi->max_hit_points * hp)); + mi->flags = mi->flags | preserve_flags; + + // Allow ORIG_MONSTER_KEY to be chained. + if (orig->props.exists(ORIG_MONSTER_KEY)) + mi->props[ORIG_MONSTER_KEY] = orig->props[ORIG_MONSTER_KEY]; + else + mi->props.erase(ORIG_MONSTER_KEY); const bool can_see = you.can_see(*mi); @@ -1354,7 +1373,7 @@ static void _hogs_to_humans() && mons_intel(*mi) >= I_NORMAL) { mi->attitude = ATT_GOOD_NEUTRAL; - mi->flags |= MF_WAS_NEUTRAL; + mi->flags |= MF_WAS_NEUTRAL; } } -- cgit v1.2.3-54-g00ecf