summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mon-stuff.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-12 20:15:52 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-12 20:16:21 -0800
commitbe0551c2205ac189be5558447625642553c80dd3 (patch)
tree65bb0a2b8e30c9f8bc88a67968f6a91420d28163 /crawl-ref/source/mon-stuff.cc
parent81909732f69d66ccd53c0701bbb7c6507ecec5b1 (diff)
downloadcrawl-ref-be0551c2205ac189be5558447625642553c80dd3.tar.gz
crawl-ref-be0551c2205ac189be5558447625642553c80dd3.zip
porkulator: completely restore reverted monsters
Diffstat (limited to 'crawl-ref/source/mon-stuff.cc')
-rw-r--r--crawl-ref/source/mon-stuff.cc43
1 files changed, 31 insertions, 12 deletions
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;
}
}