summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-08 14:01:16 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-08 14:01:16 +0000
commitc7ab36b8b51c2fa925fd5245d31e5f98cfa466e0 (patch)
treef121170da25495ab7f6deaedfeac493c4fb201e2 /crawl-ref
parentc0976eb78b1c1319e427b449073d532d033dee50 (diff)
downloadcrawl-ref-c7ab36b8b51c2fa925fd5245d31e5f98cfa466e0.tar.gz
crawl-ref-c7ab36b8b51c2fa925fd5245d31e5f98cfa466e0.zip
Ghosts can use ensorcelled hibernation. Breaks saves, needs some work on PC sleep and wake-up correctness.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2377 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/acr.cc17
-rw-r--r--crawl-ref/source/beam.cc7
-rw-r--r--crawl-ref/source/enum.h1
-rw-r--r--crawl-ref/source/externs.h9
-rw-r--r--crawl-ref/source/fight.cc11
-rw-r--r--crawl-ref/source/ghost.cc1
-rw-r--r--crawl-ref/source/message.cc10
-rw-r--r--crawl-ref/source/mon-util.cc19
-rw-r--r--crawl-ref/source/mstuff2.cc10
-rw-r--r--crawl-ref/source/ouch.cc3
-rw-r--r--crawl-ref/source/player.cc44
-rw-r--r--crawl-ref/source/view.cc10
12 files changed, 121 insertions, 21 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 8d7af5c50d..7385ce5c68 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -1276,9 +1276,9 @@ static void input()
learned_something_new(TUT_RETREAT_CASTER);
}
- if ( you.duration[DUR_PARALYSIS] )
+ if ( you.cannot_move() )
{
- crawl_state.cancel_cmd_repeat("Paralyzed, cancelling command "
+ crawl_state.cancel_cmd_repeat("Cannot move, cancelling command "
"repetition.");
world_reacts();
@@ -2228,6 +2228,9 @@ static void decrement_durations()
if (decrement_a_duration(DUR_BUILDING_RAGE))
go_berserk(false);
+ if (decrement_a_duration(DUR_SLEEP))
+ you.awake();
+
// paradox: it both lasts longer & does more damage overall if you're
// moving slower.
// rationalisation: I guess it gets rubbed off/falls off/etc if you
@@ -2691,10 +2694,12 @@ static void world_reacts()
run_environment_effects();
- if ( !you.duration[DUR_PARALYSIS] && !you.mutation[MUT_BLURRY_VISION] &&
+ if ( !you.cannot_move() && !you.mutation[MUT_BLURRY_VISION] &&
(you.mutation[MUT_ACUTE_VISION] >= 2 ||
random2(50) < you.skills[SK_TRAPS_DOORS]) )
+ {
search_around(false); // check nonadjacent squares too
+ }
stealth = check_stealth();
@@ -2793,7 +2798,7 @@ static void world_reacts()
// food death check:
if (you.is_undead != US_UNDEAD && you.hunger <= 500)
{
- if (!you.duration[DUR_PARALYSIS] && one_chance_in(40))
+ if (!you.cannot_move() && one_chance_in(40))
{
mpr("You lose consciousness!", MSGCH_FOOD);
you.duration[DUR_PARALYSIS] += 5 + random2(8);
@@ -2834,7 +2839,7 @@ static void world_reacts()
*/
viewwindow(true, false);
- if (you.duration[DUR_PARALYSIS] > 0 && any_messages())
+ if (you.cannot_move() && any_messages())
more();
spawn_random_monsters();
@@ -2856,8 +2861,6 @@ static void show_message_line(std::string line)
std::string sender = line.substr(0, sender_pos);
line = line.substr(sender_pos + 1);
trim_string(line);
- // XXX: Eventually fix mpr so it can do a different colour for
- // the sender.
formatted_string fs;
fs.textcolor(WHITE);
fs.cprintf("%s: ", sender.c_str());
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index eae783afcf..7f3f315569 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -3184,6 +3184,10 @@ static int affect_player( bolt &beam )
// these colors are misapplied - see mons_ench_f2() {dlb}
switch (beam.flavour)
{
+ case BEAM_SLEEP:
+ you.put_to_sleep(beam.ench_power);
+ break;
+
case BEAM_BACKLIGHT:
if (!you.duration[DUR_INVIS])
{
@@ -3214,7 +3218,8 @@ static int affect_player( bolt &beam )
you.mutate();
beam.obvious_effect = true;
}
- else if (get_ident_type(OBJ_WANDS, WAND_POLYMORPH_OTHER) == ID_KNOWN_TYPE)
+ else if (get_ident_type(OBJ_WANDS, WAND_POLYMORPH_OTHER)
+ == ID_KNOWN_TYPE)
{
mpr("This is polymorph other only!");
}
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index 21983398ac..ddbc58490c 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -1029,6 +1029,7 @@ enum duration_type
DUR_SLAYING,
DUR_STEALTH,
DUR_MAGIC_SHIELD,
+ DUR_SLEEP,
NUM_DURATIONS
};
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 7a8a551bba..e3027c9587 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -132,6 +132,7 @@ public:
virtual void expose_to_element(beam_type element, int strength = 0) = 0;
virtual void drain_stat(int stat, int amount, actor* attacker) { }
virtual void put_to_sleep(int power = 0) { };
+ virtual void check_awaken(int disturbance) = 0;
virtual bool wearing_light_armour(bool = false) const { return (true); }
virtual int skill(skill_type sk, bool skill_bump = false) const
@@ -803,6 +804,13 @@ public:
bool caught() const;
bool backlit() const;
+ bool asleep() const;
+ void put_to_sleep(int power = 0);
+ void awake();
+ void check_awaken(int disturbance);
+
+ bool cannot_move() const;
+
int armour_class() const;
int melee_evasion(const actor *attacker) const;
@@ -1090,6 +1098,7 @@ public:
void teleport(bool right_now = false, bool abyss_shift = false);
void put_to_sleep(int power = 0);
+ void check_awaken(int disturbance);
int stat_hp() const { return hit_points; }
int stat_maxhp() const { return max_hit_points; }
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index 857daf5109..e09e30410b 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -2886,6 +2886,17 @@ int melee_attack::mons_calc_damage(const mon_attack_def &attk)
if (water_attack)
damage *= 2;
+ // If the defender is asleep, the attacker gets a stab.
+ if (defender && defender->asleep())
+ {
+ damage = damage * 5 / 2;
+#ifdef DEBUG_DIAGNOSTICS
+ mprf(MSGCH_DIAGNOSTICS, "Stab damage vs %s: %d",
+ defender->name(DESC_PLAIN).c_str(),
+ damage);
+#endif
+ }
+
return (mons_apply_defender_ac(damage, damage_max));
}
diff --git a/crawl-ref/source/ghost.cc b/crawl-ref/source/ghost.cc
index f856c07047..21812c5a8d 100644
--- a/crawl-ref/source/ghost.cc
+++ b/crawl-ref/source/ghost.cc
@@ -48,6 +48,7 @@ static int search_order_conj[] = {
SPELL_STING,
SPELL_SHOCK,
SPELL_MAGIC_DART,
+ SPELL_SLEEP,
SPELL_BACKLIGHT,
SPELL_NO_SPELL, // end search
};
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index 3c825a38c7..798b15b206 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -222,6 +222,9 @@ static char god_message_altar_colour( god_type god )
// returns a colour or MSGCOL_MUTED
int channel_to_colour( msg_channel_type channel, int param )
{
+ if (you.asleep())
+ return (DARKGREY);
+
char ret;
switch (Options.channels[ channel ])
@@ -486,7 +489,6 @@ static void mpr_check_patterns(const std::string& message,
}
}
- // reusing travel_stop_message here
if (channel != MSGCH_DIAGNOSTICS && channel != MSGCH_EQUIPMENT
&& channel != MSGCH_TALK && channel != MSGCH_TALK_VISUAL
&& channel != MSGCH_SOUND)
@@ -495,6 +497,10 @@ static void mpr_check_patterns(const std::string& message,
channel_to_str(channel) + ":" + message );
}
+ // Any sound has a chance of waking the PC if the PC is asleep.
+ if (channel == MSGCH_SOUND)
+ you.check_awaken(5);
+
// Check messages for all forms of running now.
if (you.running)
{
@@ -565,7 +571,7 @@ static int prepare_message(const std::string& imsg, msg_channel_type channel,
int param)
{
if (suppress_messages)
- return MSGCOL_MUTED;
+ return MSGCOL_MUTED;
int colour = channel_to_colour( channel, param );
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index 38291386ec..396d2811e1 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -1962,6 +1962,7 @@ bool ms_waste_of_time( const monsters *mon, spell_type monspell )
bool ret = false;
int intel, est_magic_resist, power, diff;
+ const actor *foe = mon->get_foe();
// Eventually, we'll probably want to be able to have monsters
// learn which of their elemental bolts were resisted and have those
// handled here as well. -- bwr
@@ -1969,11 +1970,10 @@ bool ms_waste_of_time( const monsters *mon, spell_type monspell )
{
case SPELL_BACKLIGHT:
{
- const actor *foe = mon->get_foe();
- ret = !foe || foe->backlit() || foe->invisible();
+ ret = !foe || foe->backlit();
break;
}
-
+
case SPELL_BERSERKER_RAGE:
if (!mon->needs_berserk(false))
ret = true;
@@ -2021,6 +2021,10 @@ bool ms_waste_of_time( const monsters *mon, spell_type monspell )
case SPELL_BANISHMENT:
case SPELL_DISINTEGRATE:
case SPELL_PARALYSE:
+ case SPELL_SLEEP:
+ if (monspell == SPELL_SLEEP && (!foe || foe->asleep()))
+ return (true);
+
// occasionally we don't estimate... just fire and see:
if (one_chance_in(5))
return (false);
@@ -2039,9 +2043,7 @@ bool ms_waste_of_time( const monsters *mon, spell_type monspell )
if (mon->foe == MHITYOU)
est_magic_resist = player_res_magic();
else
- {
est_magic_resist = mons_resist_magic(&menv[mon->foe]);
- }
// now randomize (normal intels less accurate than high):
if (intel == I_NORMAL)
@@ -4884,7 +4886,12 @@ void monsters::put_to_sleep(int)
add_ench(ENCH_SLEEPY);
add_ench(ENCH_SLEEP_WARY);
}
-
+
+void monsters::check_awaken(int)
+{
+ // XXX
+}
+
/////////////////////////////////////////////////////////////////////////
// mon_enchant
diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc
index c3f4e07fca..c402c44f8c 100644
--- a/crawl-ref/source/mstuff2.cc
+++ b/crawl-ref/source/mstuff2.cc
@@ -1542,6 +1542,16 @@ bolt mons_spells( int spell_cast, int power )
beam.is_beam = true;
break;
+ case SPELL_SLEEP:
+ beam.name = "0";
+ beam.range = 5;
+ beam.rangeMax = 9;
+ beam.type = 0;
+ beam.flavour = BEAM_SLEEP;
+ beam.thrower = KILL_MON_MISSILE;
+ beam.is_beam = true;
+ break;
+
case SPELL_POLYMORPH_OTHER:
beam.name = "0";
beam.range = 6;
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index 258309c533..0e819d8630 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -765,6 +765,9 @@ void ouch( int dam, int death_source, kill_method_type death_type,
ait_hp_loss hpl(dam, death_type);
interrupt_activity( AI_HP_LOSS, &hpl );
+ if (dam > 0)
+ you.check_awaken(500);
+
if (you.duration[DUR_DEATHS_DOOR] && death_type != KILLED_BY_LAVA
&& death_type != KILLED_BY_WATER)
{
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 519e7dca5d..9e74b1628d 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -6073,6 +6073,48 @@ void player::moveto(const coord_def &c)
dungeon_events.fire_position_event(DET_PLAYER_MOVED, c);
}
+bool player::asleep() const
+{
+ return duration[DUR_SLEEP] > 0;
+}
+
+bool player::cannot_move() const
+{
+ return (asleep() || paralysed());
+}
+
+void player::put_to_sleep(int)
+{
+ if (asleep()) // No cumulative sleeps.
+ return;
+
+ // Not all species can be put to sleep. Check holiness.
+ const mon_holy_type holy = holiness();
+ if (holy == MH_UNDEAD || holy == MH_NONLIVING)
+ return;
+
+ mpr("You fall asleep.");
+ you.flash_colour = DARKGREY;
+ viewwindow(true, false);
+
+ // Do this *after* redrawing the view, or viewwindow() will no-op.
+ duration[DUR_SLEEP] = 3 + random2avg(5, 2);
+}
+
+void player::awake()
+{
+ duration[DUR_SLEEP] = 0;
+ mpr("You wake up.");
+ you.flash_colour = BLACK;
+ viewwindow(true, false);
+}
+
+void player::check_awaken(int disturbance)
+{
+ if (asleep() && random2(50) <= disturbance)
+ awake();
+}
+
////////////////////////////////////////////////////////////////////////////
PlaceInfo::PlaceInfo()
@@ -6223,7 +6265,6 @@ PlaceInfo PlaceInfo::operator - (const PlaceInfo &other) const
return copy;
}
-
PlaceInfo& player::get_place_info() const
{
return get_place_info(where_are_you, level_type);
@@ -6327,4 +6368,3 @@ bool player::do_shaft()
return (true);
}
-
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 0b82260ec2..6cd379344d 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -1343,13 +1343,16 @@ bool noisy( int loudness, int nois_x, int nois_y, const char *msg )
const int dist = loudness * loudness;
+ const int player_distance =
+ distance( you.x_pos, you.y_pos, nois_x, nois_y );
// message the player
- if (distance( you.x_pos, you.y_pos, nois_x, nois_y ) <= dist
- && player_can_hear( nois_x, nois_y ))
+ if (player_distance <= dist && player_can_hear( nois_x, nois_y ))
{
if (msg)
mpr( msg, MSGCH_SOUND );
+ you.check_awaken(dist - player_distance);
+
ret = true;
}
@@ -4298,7 +4301,8 @@ void viewwindow(bool draw_it, bool do_updates)
cursor_control cs(false);
const bool map = player_in_mappable_area();
- const bool draw = !you.running || Options.travel_delay > -1;
+ const bool draw =
+ (!you.running || Options.travel_delay > -1) && !you.asleep();
int bufcount = 0;
int flash_colour = you.flash_colour;