summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mgrow.cc
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-21 02:22:03 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-21 02:22:03 +0000
commit0c496e0be392bbf839533c9d69da1499b883b3ac (patch)
tree113f5b56928b11cbd7049535cdbb815d49f6d6d4 /crawl-ref/source/mgrow.cc
parentd07a34ba115b47a74496b1810c5ede4b0e86c748 (diff)
downloadcrawl-ref-0c496e0be392bbf839533c9d69da1499b883b3ac.tar.gz
crawl-ref-0c496e0be392bbf839533c9d69da1499b883b3ac.zip
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
Diffstat (limited to 'crawl-ref/source/mgrow.cc')
-rw-r--r--crawl-ref/source/mgrow.cc57
1 files changed, 31 insertions, 26 deletions
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<monster_type>(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<monster_type>(type), hit_dice))
+ {
+ change_type(lup->after, lup->adjust_hp);
return (true);
}
return (false);