From 0c496e0be392bbf839533c9d69da1499b883b3ac Mon Sep 17 00:00:00 2001 From: dolorous Date: Fri, 21 Mar 2008 02:22:03 +0000 Subject: Revert the splitting out of monster_change_type() from monster_polymorph(), as it still doesn't do everything needed. Replace it with monsters::change_type(), split out from monsters::level_up_change(), which does do everything needed, and in a cleaner way. Unfortunately, it's still a hack, but it should be easier to deal with for now. Sorry for the mess. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3783 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/mgrow.cc | 57 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'crawl-ref/source/mgrow.cc') diff --git a/crawl-ref/source/mgrow.cc b/crawl-ref/source/mgrow.cc index 520aa1117b..679f2643aa 100644 --- a/crawl-ref/source/mgrow.cc +++ b/crawl-ref/source/mgrow.cc @@ -95,39 +95,44 @@ static const monster_level_up *monster_level_up_target( return (NULL); } -bool monsters::level_up_change() +void monsters::change_type(monster_type after, bool adjust_hp) { - if (const monster_level_up *lup = - monster_level_up_target(static_cast(type), hit_dice)) - { - const monsterentry *orig = get_monster_data(type); - // Ta-da! - type = lup->after; + const monsterentry *orig = get_monster_data(type); + // Ta-da! + type = after; - // Initialise a dummy monster to save work. - monsters dummy; - dummy.type = type; - define_monster(dummy); + // Initialise a dummy monster to save work. + monsters dummy; + dummy.type = after; + define_monster(dummy); - colour = dummy.colour; - speed = dummy.speed; - spells = dummy.spells; - fix_speed(); + colour = dummy.colour; + speed = dummy.speed; + spells = dummy.spells; + fix_speed(); - const monsterentry *m = get_monster_data(type); - ac += m->AC - orig->AC; - ev += m->ev - orig->ev; + const monsterentry *m = get_monster_data(after); + ac += m->AC - orig->AC; + ev += m->ev - orig->ev; - if (lup->adjust_hp) + if (adjust_hp) + { + const int minhp = dummy.max_hit_points; + if (max_hit_points < minhp) { - const int minhp = dummy.max_hit_points; - if (max_hit_points < minhp) - { - hit_points += minhp - max_hit_points; - max_hit_points = minhp; - hit_points = std::min(hit_points, max_hit_points); - } + hit_points += minhp - max_hit_points; + max_hit_points = minhp; + hit_points = std::min(hit_points, max_hit_points); } + } +} + +bool monsters::level_up_change() +{ + if (const monster_level_up *lup = + monster_level_up_target(static_cast(type), hit_dice)) + { + change_type(lup->after, lup->adjust_hp); return (true); } return (false); -- cgit v1.2.3-54-g00ecf