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 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'crawl-ref/source/actor.cc') 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); +} + + -- cgit v1.2.3-54-g00ecf