summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Feinberg <pleasingfung@gmail.com>2014-07-11 20:40:13 -0700
committerNicholas Feinberg <pleasingfung@gmail.com>2014-07-11 20:56:37 -0700
commitdaae54a4133a85a6393b9351f17d825cfdcdd126 (patch)
treea2043f59b2c2e9e0a1dda1f0a68ba43c24764efe
parent30d9616ef6d9e0f6e5bccaacf4446854ceb757be (diff)
downloadcrawl-ref-daae54a4133a85a6393b9351f17d825cfdcdd126.tar.gz
crawl-ref-daae54a4133a85a6393b9351f17d825cfdcdd126.zip
Improve sleep code
Refactor put_to_sleep() and hibernate() together. Also improve messenging for resisting repeated sleep (by replacing a generic canned message).
-rw-r--r--crawl-ref/source/actor.h4
-rw-r--r--crawl-ref/source/beam.cc7
-rw-r--r--crawl-ref/source/monster.cc18
-rw-r--r--crawl-ref/source/monster.h3
-rw-r--r--crawl-ref/source/player.cc36
-rw-r--r--crawl-ref/source/player.h3
6 files changed, 27 insertions, 44 deletions
diff --git a/crawl-ref/source/actor.h b/crawl-ref/source/actor.h
index f2c1b42aae..46b5e32636 100644
--- a/crawl-ref/source/actor.h
+++ b/crawl-ref/source/actor.h
@@ -223,7 +223,8 @@ public:
virtual bool fully_petrify(actor *foe, bool quiet = false) = 0;
virtual void slow_down(actor *attacker, int strength) = 0;
virtual void confuse(actor *attacker, int strength) = 0;
- virtual void put_to_sleep(actor *attacker, int strength) = 0;
+ virtual void put_to_sleep(actor *attacker, int strength,
+ bool hibernate = false) = 0;
virtual void weaken(actor *attacker, int pow) = 0;
virtual void expose_to_element(beam_type element, int strength = 0,
bool slow_cold_blood = true) = 0;
@@ -231,7 +232,6 @@ public:
virtual bool can_hibernate(bool holi_only = false,
bool intrinsic_only = false) const;
virtual bool can_sleep(bool holi_only = false) const;
- virtual void hibernate(int power = 0) = 0;
virtual void check_awaken(int disturbance) = 0;
virtual int beam_resists(bolt &beam, int hurted, bool doEffects,
string source = "") = 0;
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index 97b0751809..288a0659f7 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -3516,11 +3516,8 @@ void bolt::affect_player_enchantment(bool resistible)
switch (flavour)
{
case BEAM_HIBERNATION:
- you.hibernate(ench_power);
- break;
-
case BEAM_SLEEP:
- you.put_to_sleep(NULL, ench_power);
+ you.put_to_sleep(NULL, ench_power, flavour == BEAM_HIBERNATION);
break;
case BEAM_CORONA:
@@ -5408,7 +5405,7 @@ mon_resist_type bolt::apply_enchantment_to_monster(monster* mon)
{
if (simple_monster_message(mon, " looks drowsy..."))
obvious_effect = true;
- mon->hibernate();
+ mon->put_to_sleep(agent(), ench_power, true);
return MON_AFFECTED;
}
return MON_UNAFFECTED;
diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc
index 93eb968e97..5f4a5a81a6 100644
--- a/crawl-ref/source/monster.cc
+++ b/crawl-ref/source/monster.cc
@@ -5512,25 +5512,17 @@ bool monster::do_shaft()
return reveal;
}
-void monster::hibernate(int)
+void monster::put_to_sleep(actor *attacker, int strength, bool hibernate)
{
- if (!can_hibernate())
- return;
-
- stop_constricting_all();
- behaviour = BEH_SLEEP;
- flags |= MF_JUST_SLEPT;
- add_ench(ENCH_SLEEP_WARY);
-}
-
-void monster::put_to_sleep(actor *attacker, int strength)
-{
- if (!can_sleep())
+ const bool valid_target = hibernate ? can_hibernate() : can_sleep();
+ if (!valid_target)
return;
stop_constricting_all();
behaviour = BEH_SLEEP;
flags |= MF_JUST_SLEPT;
+ if (hibernate)
+ add_ench(ENCH_SLEEP_WARY);
}
void monster::weaken(actor *attacker, int pow)
diff --git a/crawl-ref/source/monster.h b/crawl-ref/source/monster.h
index d0d2087267..4b17e9c125 100644
--- a/crawl-ref/source/monster.h
+++ b/crawl-ref/source/monster.h
@@ -450,8 +450,7 @@ public:
bool shift(coord_def p = coord_def(0, 0));
void suicide(int hp = -1);
- void hibernate(int power = 0);
- void put_to_sleep(actor *attacker, int power = 0);
+ void put_to_sleep(actor *attacker, int power = 0, bool hibernate = false);
void weaken(actor *attacker, int pow);
void check_awaken(int disturbance);
int beam_resists(bolt &beam, int hurted, bool doEffects, string source = "");
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 2a3497e1db..9527e2d14a 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -7777,34 +7777,28 @@ bool player::can_smell() const
return species != SP_MUMMY;
}
-void player::hibernate(int)
+/**
+ * Attempts to put the player to sleep.
+ *
+ * @param power The power of the effect putting the player to sleep.
+ * @param hibernate Whether the player is being put to sleep by 'ensorcelled
+ * hibernation' (doesn't affect characters with rC, ignores
+ * power), or by a normal sleep effect.
+ */
+void player::put_to_sleep(actor*, int power, bool hibernate)
{
ASSERT(!crawl_state.game_is_arena());
- if (!can_hibernate() || duration[DUR_SLEEP_IMMUNITY])
+ const bool valid_target = hibernate ? can_hibernate() : can_sleep();
+ if (!valid_target)
{
canned_msg(MSG_YOU_UNAFFECTED);
return;
}
- stop_constricting_all();
- end_searing_ray();
- mpr("You fall asleep.");
-
- stop_delay();
- flash_view(DARKGREY);
-
- // Do this *after* redrawing the view, or viewwindow() will no-op.
- set_duration(DUR_SLEEP, 3 + random2avg(5, 2));
-}
-
-void player::put_to_sleep(actor*, int power)
-{
- ASSERT(!crawl_state.game_is_arena());
-
- if (!can_sleep() || duration[DUR_SLEEP_IMMUNITY])
+ if (duration[DUR_SLEEP_IMMUNITY])
{
- canned_msg(MSG_YOU_UNAFFECTED);
+ mpr("You can't fall asleep again this soon!");
return;
}
@@ -7816,7 +7810,9 @@ void player::put_to_sleep(actor*, int power)
flash_view(DARKGREY);
// As above, do this after redraw.
- set_duration(DUR_SLEEP, 5 + random2avg(power/10, 5));
+ const int dur = hibernate ? 3 + random2avg(5, 2) :
+ 5 + random2avg(power/10, 5);
+ set_duration(DUR_SLEEP, dur);
}
void player::awake()
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index dfba7e43a3..38a704c0c7 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -671,8 +671,7 @@ public:
}
bool asleep() const;
- void hibernate(int power = 0);
- void put_to_sleep(actor *, int power = 0);
+ void put_to_sleep(actor *, int power = 0, bool hibernate = false);
void awake();
void check_awaken(int disturbance);
int beam_resists(bolt &beam, int hurted, bool doEffects, string source);