From 86b2a07772af036bd6f6d3252ba18af0d6a3cd71 Mon Sep 17 00:00:00 2001 From: Jude Brown Date: Fri, 13 Nov 2009 23:26:32 +1000 Subject: Move duplicated can_hibernate code into actor. --- crawl-ref/source/actor.cc | 30 ++++++++++++++++++++++++++++++ crawl-ref/source/actor.h | 2 +- crawl-ref/source/monster.cc | 25 ------------------------- crawl-ref/source/monster.h | 1 - crawl-ref/source/player.cc | 21 --------------------- crawl-ref/source/player.h | 1 - 6 files changed, 31 insertions(+), 49 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/actor.cc b/crawl-ref/source/actor.cc index 742e347f40..1cacd258d4 100644 --- a/crawl-ref/source/actor.cc +++ b/crawl-ref/source/actor.cc @@ -116,3 +116,33 @@ void actor::set_position(const coord_def &c) los.set_center(c); los_no_trans.set_center(c); } + +bool actor::can_hibernate(bool holi_only) const +{ + // Undead, nonliving, and plants don't sleep. + const mon_holy_type holi = holiness(); + if (holi == MH_UNDEAD || holi == MH_NONLIVING || holi == MH_PLANT) + return (false); + + if (!holi_only) + { + // The monster is berserk or already asleep. + if (berserk() || asleep()) + return (false); + + // The monster is cold-resistant and can't be hibernated. + if (res_cold() > 0) + return (false); + + // The monster has slept recently. + if (atype() == ACT_MONSTER && + static_cast(this)->has_ench(ENCH_SLEEP_WARY)) + { + return (false); + } + } + + return (true); +} + + diff --git a/crawl-ref/source/actor.h b/crawl-ref/source/actor.h index 10dd3f7bda..72c5057e71 100644 --- a/crawl-ref/source/actor.h +++ b/crawl-ref/source/actor.h @@ -157,7 +157,7 @@ public: virtual void confuse(actor *attacker, int strength) = 0; virtual void expose_to_element(beam_type element, int strength = 0) = 0; virtual void drain_stat(int stat, int amount, actor* attacker) { } - virtual bool can_hibernate(bool holi_only = false) const = 0; + virtual bool can_hibernate(bool holi_only = false) const; virtual void hibernate(int power = 0) = 0; virtual void check_awaken(int disturbance) = 0; diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc index 04ffff0e5c..d82093bee9 100644 --- a/crawl-ref/source/monster.cc +++ b/crawl-ref/source/monster.cc @@ -5587,31 +5587,6 @@ bool monsters::do_shaft() return (reveal); } -bool monsters::can_hibernate(bool holi_only) const -{ - // Undead, nonliving, and plants don't sleep. - const mon_holy_type holi = holiness(); - if (holi == MH_UNDEAD || holi == MH_NONLIVING || holi == MH_PLANT) - return (false); - - if (!holi_only) - { - // The monster is berserk or already asleep. - if (berserk() || asleep()) - return (false); - - // The monster is cold-resistant and can't be hibernated. - if (res_cold() > 0) - return (false); - - // The monster has slept recently. - if (has_ench(ENCH_SLEEP_WARY)) - return (false); - } - - return (true); -} - void monsters::hibernate(int) { if (!can_hibernate()) diff --git a/crawl-ref/source/monster.h b/crawl-ref/source/monster.h index 8725688d01..7fb7ea2109 100644 --- a/crawl-ref/source/monster.h +++ b/crawl-ref/source/monster.h @@ -380,7 +380,6 @@ public: void blink(bool allow_partial_control = true); void teleport(bool right_now = false, bool abyss_shift = false); - bool can_hibernate(bool holi_only = false) const; void hibernate(int power = 0); void check_awaken(int disturbance); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 19b8758dd2..7af59e3b10 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -7038,27 +7038,6 @@ bool player::can_throw_large_rocks() const return (player_genus(GENPC_OGRE) || species == SP_TROLL); } -bool player::can_hibernate(bool holi_only) const -{ - // Undead, nonliving, and plants don't sleep. - const mon_holy_type holi = holiness(); - if (holi == MH_UNDEAD || holi == MH_NONLIVING || holi == MH_PLANT) - return (false); - - if (!holi_only) - { - // The player is berserk or already asleep. - if (berserk() || asleep()) - return (false); - - // The player is cold-resistant and can't be hibernated. - if (res_cold() > 0) - return (false); - } - - return (true); -} - void player::hibernate(int) { ASSERT(!crawl_state.arena); diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h index 430307a982..f6fc6bcdd8 100644 --- a/crawl-ref/source/player.h +++ b/crawl-ref/source/player.h @@ -473,7 +473,6 @@ public: bool petrified() const; bool asleep() const; - bool can_hibernate(bool holi_only = false) const; void hibernate(int power = 0); void put_to_sleep(int power = 0); void awake(); -- cgit v1.2.3-54-g00ecf