summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
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
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')
-rw-r--r--crawl-ref/source/actor.h2
-rw-r--r--crawl-ref/source/beam.cc2
-rw-r--r--crawl-ref/source/effects.cc5
-rw-r--r--crawl-ref/source/fight.cc2
-rw-r--r--crawl-ref/source/mon-abil.cc2
-rw-r--r--crawl-ref/source/mon-act.cc2
-rw-r--r--crawl-ref/source/mon-cast.cc3
-rw-r--r--crawl-ref/source/monster.cc34
-rw-r--r--crawl-ref/source/monster.h2
-rw-r--r--crawl-ref/source/monstuff.cc39
-rw-r--r--crawl-ref/source/monstuff.h2
-rw-r--r--crawl-ref/source/player.cc3
-rw-r--r--crawl-ref/source/player.h2
-rw-r--r--crawl-ref/source/religion.cc2
-rw-r--r--crawl-ref/source/spells1.cc2
15 files changed, 45 insertions, 59 deletions
diff --git a/crawl-ref/source/actor.h b/crawl-ref/source/actor.h
index 009bfb237a..1bd4c2cfe8 100644
--- a/crawl-ref/source/actor.h
+++ b/crawl-ref/source/actor.h
@@ -144,7 +144,7 @@ public:
virtual int hurt(const actor *attacker, int amount,
beam_type flavour = BEAM_MISSILE,
bool cleanup_dead = true) = 0;
- virtual void heal(int amount, bool max_too = false) = 0;
+ virtual bool heal(int amount, bool max_too = false) = 0;
virtual void banish(const std::string &who = "") = 0;
virtual void blink(bool allow_partial_control = true) = 0;
virtual void teleport(bool right_now = false, bool abyss_shift = false) = 0;
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index 976d62b1a5..4f5e94ba9e 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -5266,7 +5266,7 @@ mon_resist_type bolt::apply_enchantment_to_monster(monsters* mon)
obvious_effect = true;
msg_generated = true; // to avoid duplicate "nothing happens"
}
- else if (heal_monster(mon, 5 + damage.roll(), false))
+ else if (mon->heal(5 + damage.roll()))
{
if (mon->hit_points == mon->max_hit_points)
{
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index c3be41fa8b..5ed0c37bf8 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -4197,7 +4197,7 @@ void update_level(double elapsedTime)
if (monster_descriptor(mon->type, MDSC_REGENERATES)
|| mon->type == MONS_PLAYER_GHOST)
{
- heal_monster(mon, turns, false);
+ mon->heal(turns);
}
else
{
@@ -4205,8 +4205,7 @@ void update_level(double elapsedTime)
const int regen_rate =
std::max(mons_natural_regen_rate(mon) * 2, 5);
- heal_monster(mon, div_rand_round(turns * regen_rate, 50),
- false);
+ mon->heal(div_rand_round(turns * regen_rate, 50));
}
}
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index 77e0813412..f40ef534e9 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -3555,7 +3555,7 @@ bool melee_attack::chop_hydra_head( int dam,
simple_monster_message(defender_as_monster(),
" grows two more!" );
defender_as_monster()->number += 2;
- heal_monster(defender_as_monster(), 8 + random2(8), true);
+ defender->heal(8 + random2(8), true);
}
}
}
diff --git a/crawl-ref/source/mon-abil.cc b/crawl-ref/source/mon-abil.cc
index 0d3b2e9b2a..73d0547f6c 100644
--- a/crawl-ref/source/mon-abil.cc
+++ b/crawl-ref/source/mon-abil.cc
@@ -1416,7 +1416,7 @@ void mon_nearby_ability(monsters *monster)
dec_mp(5 + random2avg(13, 3));
- heal_monster(monster, 10, true); // heh heh {dlb}
+ monster->heal(10, true); // heh heh {dlb}
}
break;
diff --git a/crawl-ref/source/mon-act.cc b/crawl-ref/source/mon-act.cc
index db634705b4..4e347b9fe8 100644
--- a/crawl-ref/source/mon-act.cc
+++ b/crawl-ref/source/mon-act.cc
@@ -105,7 +105,7 @@ static void _monster_regenerate(monsters *monster)
|| _mons_natural_regen_roll(monster))
{
- heal_monster(monster, 1, false);
+ monster->heal(1);
}
}
diff --git a/crawl-ref/source/mon-cast.cc b/crawl-ref/source/mon-cast.cc
index 04311be6d4..2c2c0f1517 100644
--- a/crawl-ref/source/mon-cast.cc
+++ b/crawl-ref/source/mon-cast.cc
@@ -1597,8 +1597,7 @@ void mons_cast(monsters *monster, bolt &pbolt, spell_type spell_cast,
break;
case SPELL_MAJOR_HEALING:
- if (heal_monster(monster, 50 + random2avg(monster->hit_dice * 10, 2),
- false))
+ if (monster->heal(50 + random2avg(monster->hit_dice * 10, 2)))
{
simple_monster_message(monster, " is healed.");
}
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);
diff --git a/crawl-ref/source/monster.h b/crawl-ref/source/monster.h
index 8ff03b76dd..8fdf14078a 100644
--- a/crawl-ref/source/monster.h
+++ b/crawl-ref/source/monster.h
@@ -371,7 +371,7 @@ public:
int hurt(const actor *attacker, int amount,
beam_type flavour = BEAM_MISSILE,
bool cleanup_dead = true);
- void heal(int amount, bool max_too = false);
+ bool heal(int amount, bool max_too = false);
void blink(bool allow_partial_control = true);
void teleport(bool right_now = false, bool abyss_shift = false);
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index d8e71794f8..9cee1e134a 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -1982,8 +1982,7 @@ int monster_die(monsters *monster, killer_type killer,
{
simple_monster_message(killer_mon,
" looks invigorated.");
- heal_monster(killer_mon,
- 1 + random2(monster->hit_dice / 4), false);
+ killer_mon->heal(1 + random2(monster->hit_dice / 4));
}
}
@@ -3508,42 +3507,6 @@ unsigned int monster_index(const monsters *monster)
return (monster - menv.buffer());
}
-bool heal_monster(monsters * patient, int health_boost,
- bool permit_growth)
-{
- if (mons_is_statue(patient->type))
- return (false);
-
- if (health_boost < 1)
- return (false);
- else if (!permit_growth && patient->hit_points == patient->max_hit_points)
- return (false);
-
- patient->hit_points += health_boost;
-
- bool success = true;
-
- if (patient->hit_points > patient->max_hit_points)
- {
- if (permit_growth)
- {
- const monsterentry* m = get_monster_data(patient->type);
- const int maxhp =
- m->hpdice[0] * (m->hpdice[1] + m->hpdice[2]) + m->hpdice[3];
-
- // Limit HP growth.
- if (random2(3 * maxhp) > 2 * patient->max_hit_points)
- patient->max_hit_points++;
- else
- success = false;
- }
-
- patient->hit_points = patient->max_hit_points;
- }
-
- return (success);
-}
-
void seen_monster(monsters *monster)
{
// If the monster is in the auto_exclude list, automatically
diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h
index a364b93a4f..75656c73a1 100644
--- a/crawl-ref/source/monstuff.h
+++ b/crawl-ref/source/monstuff.h
@@ -140,8 +140,6 @@ unsigned int monster_index(const monsters *monster);
void mons_get_damage_level(const monsters*, std::string& desc,
mon_dam_level_type&);
-bool heal_monster(monsters *patient, int health_boost, bool permit_growth);
-
void seen_monster(monsters *monster);
bool shift_monster(monsters *mon, coord_def p = coord_def(0, 0));
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index e02c28e6e7..6dc93fb6f4 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -6346,9 +6346,10 @@ int player::melee_evasion(const actor *act, ev_ignore_type evit) const
&& !is_run_delay(current_delay_action())? 5 : 0));
}
-void player::heal(int amount, bool max_too)
+bool player::heal(int amount, bool max_too)
{
::inc_hp(amount, max_too);
+ return true; /* TODO Check whether the player was healed. */
}
mon_holy_type player::holiness() const
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index 881e8f4f18..3f19574b95 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -427,7 +427,7 @@ public:
void petrify(actor *, int str);
void slow_down(actor *, int str);
void confuse(actor *, int strength);
- void heal(int amount, bool max_too = false);
+ bool heal(int amount, bool max_too = false);
bool drain_exp(actor *, bool quiet = false, int pow = 3);
bool rot(actor *, int amount, int immediate = 0, bool quiet = false);
int hurt(const actor *attacker, int amount,
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 7d90600713..7625f252c0 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -1546,7 +1546,7 @@ static bool _blessing_healing(monsters* mon)
const int healing = mon->max_hit_points / 4 + 1;
// Heal a monster.
- if (heal_monster(mon, healing + random2(healing + 1), false))
+ if (mon->heal(healing + random2(healing + 1)))
{
// A high-HP monster might get a unique name.
if (x_chance_in_y(mon->max_hit_points + 1, 100))
diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc
index 71f9f071c1..1b2e1b14df 100644
--- a/crawl-ref/source/spells1.cc
+++ b/crawl-ref/source/spells1.cc
@@ -847,7 +847,7 @@ static int _healing_spell(int healed, bool divine_ability,
}
}
- if (heal_monster(monster, healed, false))
+ if (monster->heal(healed))
{
did_something = true;
mprf("You heal %s.", monster->name(DESC_NOCAP_THE).c_str());