diff options
author | David Lawrence Ramsey <dolorous@users.sourceforge.net> | 2009-11-06 15:10:29 -0600 |
---|---|---|
committer | David Lawrence Ramsey <dolorous@users.sourceforge.net> | 2009-11-06 15:12:26 -0600 |
commit | f9b61b5115bb93a1381cfc3032820489875624c5 (patch) | |
tree | 637b6b52c190b1feb0e17193784056324213cf08 /crawl-ref/source/monster.cc | |
parent | b192fdbbbeb85e80aae71e169417511b52e5ab19 (diff) | |
download | crawl-ref-f9b61b5115bb93a1381cfc3032820489875624c5.tar.gz crawl-ref-f9b61b5115bb93a1381cfc3032820489875624c5.zip |
Consolidate player/monster sleep checks.
Diffstat (limited to 'crawl-ref/source/monster.cc')
-rw-r--r-- | crawl-ref/source/monster.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc index 27cd5113e2..e3d6ac58bd 100644 --- a/crawl-ref/source/monster.cc +++ b/crawl-ref/source/monster.cc @@ -2696,7 +2696,7 @@ void monsters::expose_to_element(beam_type flavour, int strength) switch (flavour) { case BEAM_COLD: - if (mons_class_flag(this->type, M_COLD_BLOOD) && this->res_cold() <= 0 + if (mons_class_flag(type, M_COLD_BLOOD) && res_cold() <= 0 && coinflip()) { slow_down(this, strength); @@ -5392,9 +5392,34 @@ bool monsters::do_shaft() return (reveal); } +bool monsters::can_sleep(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::put_to_sleep(int) { - if (has_ench(ENCH_BERSERK)) + if (!can_sleep()) return; behaviour = BEH_SLEEP; |