summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monster.cc
diff options
context:
space:
mode:
authorVsevolod Kozlov <zaba@thorium.homeunix.org>2009-11-10 16:48:44 +0300
committerVsevolod Kozlov <zaba@thorium.homeunix.org>2009-11-10 16:48:44 +0300
commit54ccf63c382d3e27c7165ee57a721929dc45f77c (patch)
tree50084e3a093d19b7826ea54834d4d3a5db2e3153 /crawl-ref/source/monster.cc
parent672df2f6a49ff8683255e5bad316674d16285f0c (diff)
downloadcrawl-ref-54ccf63c382d3e27c7165ee57a721929dc45f77c.tar.gz
crawl-ref-54ccf63c382d3e27c7165ee57a721929dc45f77c.zip
Make actor::heal return bool; move heal_monster to monsters::heal.
monsters::heal and heal_monster used to have slightly different logic for increasing maximum HP. Now the heal_monster logic is used everywhere. player::heal always returns true at the moment, but since its return value is never checked, that does not affect anything.
Diffstat (limited to 'crawl-ref/source/monster.cc')
-rw-r--r--crawl-ref/source/monster.cc34
1 files changed, 30 insertions, 4 deletions
diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc
index 847935c37a..78bb92a710 100644
--- a/crawl-ref/source/monster.cc
+++ b/crawl-ref/source/monster.cc
@@ -2938,13 +2938,39 @@ int monsters::melee_evasion(const actor *act, ev_ignore_type evit) const
return (evasion);
}
-void monsters::heal(int amount, bool max_too)
+bool monsters::heal(int amount, bool max_too)
{
+ if (mons_is_statue(type))
+ return (false);
+
+ if (amount < 1)
+ return (false);
+ else if (!max_too && hit_points == max_hit_points)
+ return (false);
+
hit_points += amount;
- if (max_too)
- max_hit_points += amount;
+
+ bool success = true;
+
if (hit_points > max_hit_points)
+ {
+ if (max_too)
+ {
+ const monsterentry* m = get_monster_data(type);
+ const int maxhp =
+ m->hpdice[0] * (m->hpdice[1] + m->hpdice[2]) + m->hpdice[3];
+
+ // Limit HP growth.
+ if (random2(3 * maxhp) > 2 * max_hit_points)
+ max_hit_points++;
+ else
+ success = false;
+ }
+
hit_points = max_hit_points;
+ }
+
+ return (success);
}
mon_holy_type monsters::holiness() const
@@ -4786,7 +4812,7 @@ void monsters::apply_enchantment(const mon_enchant &me)
// isn't up to choice. - bwr
if (type == MONS_AIR_ELEMENTAL)
{
- heal_monster(this, 1, one_chance_in(5));
+ heal(1, one_chance_in(5));
if (one_chance_in(5))
del_ench(ENCH_SUBMERGED);