diff options
author | Jude Brown <bookofjude@users.sourceforge.net> | 2009-11-13 23:26:32 +1000 |
---|---|---|
committer | Jude Brown <bookofjude@users.sourceforge.net> | 2009-11-13 23:30:22 +1000 |
commit | 86b2a07772af036bd6f6d3252ba18af0d6a3cd71 (patch) | |
tree | 58904850410aaffc52927e1fc52ac232fe9bf5bf /crawl-ref/source/actor.cc | |
parent | 14bd8545684708902309fe17d5b5840ad4f6b848 (diff) | |
download | crawl-ref-86b2a07772af036bd6f6d3252ba18af0d6a3cd71.tar.gz crawl-ref-86b2a07772af036bd6f6d3252ba18af0d6a3cd71.zip |
Move duplicated can_hibernate code into actor.
Diffstat (limited to 'crawl-ref/source/actor.cc')
-rw-r--r-- | crawl-ref/source/actor.cc | 30 |
1 files changed, 30 insertions, 0 deletions
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<const monsters*>(this)->has_ench(ENCH_SLEEP_WARY)) + { + return (false); + } + } + + return (true); +} + + |