summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mgrow.cc
diff options
context:
space:
mode:
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);