summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-10-21 13:21:20 -0700
committerMatthew Cline <zelgadis@sourceforge.net>2009-10-21 13:21:20 -0700
commitc7a7fb4439a5f5006109abcd20cd0300f7d36827 (patch)
tree9a92c9a28570abc6488d58a032048e5f8b12c137 /crawl-ref/source
parent1995a2a6436f8a2d3216634f24d5ed76d97327e2 (diff)
downloadcrawl-ref-c7a7fb4439a5f5006109abcd20cd0300f7d36827.tar.gz
crawl-ref-c7a7fb4439a5f5006109abcd20cd0300f7d36827.zip
Don't disturb monsters witth their own sound
A monster making noise was causing an ME_DISTURB behaviour_event() for itself, possibly causing it to get a new foe, which could cause strange results if it switched foes during the middle of spell-casting when it made noise from chanting. Now noisy() can accept a "who" parameter, in which case the monster which caused the noise will ignore the noise. This is done in all cases except for when a monster of animal or lower intelligence sets off an alarm trap or does a spell miscast.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/beam.cc2
-rw-r--r--crawl-ref/source/fight.cc2
-rw-r--r--crawl-ref/source/monstuff.cc6
-rw-r--r--crawl-ref/source/mstuff2.cc6
-rw-r--r--crawl-ref/source/spl-mis.cc9
-rw-r--r--crawl-ref/source/traps.cc10
-rw-r--r--crawl-ref/source/view.cc17
-rw-r--r--crawl-ref/source/view.h4
8 files changed, 42 insertions, 14 deletions
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index afce32467e..ae0dadbe7c 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -5497,7 +5497,7 @@ bool bolt::explode(bool show_more, bool hole_in_the_middle)
#endif
// make a noise
- noisy(10 + 5 * r, pos());
+ noisy(10 + 5 * r, pos(), beam_source);
// Run DFS to determine which cells are influenced
explosion_map exp_map;
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index e1e8d6b339..7366b7c29b 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -2647,7 +2647,7 @@ void melee_attack::chaos_affects_attacker()
if (!msg.empty())
{
mpr(msg.c_str(), MSGCH_SOUND);
- noisy(15, attacker->pos());
+ noisy(15, attacker->pos(), attacker->mindex());
#ifdef NOTE_DEBUG_CHAOS_EFFECTS
take_note(Note(NOTE_MESSAGE, 0, 0,
"CHAOS affects attacker: noise"), true);
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index bfb56528c0..8ec912817a 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -6306,7 +6306,7 @@ static bool _handle_special_ability(monsters *monster, bolt & beem)
if (one_chance_in(5)
|| monster->foe == MHITYOU && !already_mesmerised && coinflip())
{
- noisy(12, monster->pos(), NULL, true);
+ noisy(12, monster->pos(), monster->mindex(), true);
bool did_resist = false;
if (you.can_see(monster))
@@ -9086,14 +9086,14 @@ static bool _monster_move(monsters *monster)
mprf(MSGCH_TALK_VISUAL, "%s rages.",
monster->name(DESC_CAP_THE).c_str());
}
- noisy(noise_level, monster->pos());
+ noisy(noise_level, monster->pos(), monster->mindex());
}
else if (one_chance_in(5))
handle_monster_shouts(monster, true);
else
{
// Just be noisy without messaging the player.
- noisy(noise_level, monster->pos());
+ noisy(noise_level, monster->pos(), monster->mindex());
}
}
}
diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc
index 36cb559ec1..689a372175 100644
--- a/crawl-ref/source/mstuff2.cc
+++ b/crawl-ref/source/mstuff2.cc
@@ -884,7 +884,7 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
if (silent)
return;
- noisy(noise, monster->pos());
+ noisy(noise, monster->pos(), monster->mindex());
return;
}
@@ -1086,7 +1086,7 @@ void mons_cast_noise(monsters *monster, bolt &pbolt, spell_type spell_cast)
if (silent)
mons_speaks_msg(monster, msg, chan, true);
- else if (noisy(noise, monster->pos()) || !unseen)
+ else if (noisy(noise, monster->pos(), monster->mindex()) || !unseen)
{
// noisy() returns true if the player heard the noise.
mons_speaks_msg(monster, msg, chan);
@@ -2636,7 +2636,7 @@ bool orc_battle_cry(monsters *chief)
}
// The yell happens whether you happen to see it or not.
- noisy(15, chief->pos());
+ noisy(15, chief->pos(), chief->mindex());
// Disabling detailed frenzy announcement because it's so spammy.
const msg_channel_type channel =
diff --git a/crawl-ref/source/spl-mis.cc b/crawl-ref/source/spl-mis.cc
index 20465845be..dca0b74bb2 100644
--- a/crawl-ref/source/spl-mis.cc
+++ b/crawl-ref/source/spl-mis.cc
@@ -467,7 +467,14 @@ void MiscastEffect::do_msg(bool suppress_nothing_happens)
mpr(msg.c_str(), msg_ch);
if (msg_ch == MSGCH_SOUND)
- noisy(sound_loudness, target->pos());
+ {
+ // Those monsters of normal or greater intelligence will realize that they
+ // were the source of the sound.
+ int source = target->atype() == ACT_PLAYER ? you.mindex()
+ : mons_intel(target_as_monster()) >= I_NORMAL ? target->mindex()
+ : -1;
+ noisy(sound_loudness, target->pos(), source);
+ }
}
bool MiscastEffect::_ouch(int dam, beam_type flavour)
diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc
index c0b3f22f5b..990e277e51 100644
--- a/crawl-ref/source/traps.cc
+++ b/crawl-ref/source/traps.cc
@@ -415,8 +415,14 @@ void trap_def::trigger(actor& triggerer, bool flat_footed)
const char* message_here = "An alarm trap emits a blaring wail!";
const char* message_near = "You hear a blaring wail!";
const char* message_far = "You hear a distant blaring wail!";
- noisy(12, this->pos, (you_trigger ? message_here :
- (in_sight ? message_near : message_far)));
+ const char* msg = (you_trigger ? message_here :
+ (in_sight ? message_near : message_far));
+ // Monsters of normal or greater intelligence will realize that
+ // they were the one to set off the trap.
+ int source = !m ? you.mindex() :
+ mons_intel(m) >= I_NORMAL ? m->mindex() : -1;
+
+ noisy(12, this->pos, msg, source);
}
break;
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 954dee16bd..80b7eeb180 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -1287,7 +1287,7 @@ void handle_monster_shouts(monsters* monster, bool force)
}
const int noise_level = get_shout_noise_level(s_type);
- const bool heard = noisy(noise_level, monster->pos());
+ const bool heard = noisy(noise_level, monster->pos(), monster->mindex());
if (Options.tutorial_left && (heard || you.can_see(monster)))
learned_something_new(TUT_MONSTER_SHOUT, monster->pos());
@@ -1726,7 +1726,8 @@ void cloud_grid(void)
// player is appropriate.
//
// Returns true if the PC heard the noise.
-bool noisy(int loudness, const coord_def& where, const char *msg, bool mermaid)
+bool noisy(int loudness, const coord_def& where, const char *msg, int who,
+ bool mermaid)
{
bool ret = false;
@@ -1767,6 +1768,12 @@ bool noisy(int loudness, const coord_def& where, const char *msg, bool mermaid)
if (!monster->alive())
continue;
+ // Monsters arent' affected by their own noise. We don't check
+ // where == monster->pos() since it might be caused by the
+ // Projected Noise spell.
+ if (p == who)
+ continue;
+
if (distance(monster->pos(), where) <= dist
&& !silenced(monster->pos()))
{
@@ -1788,6 +1795,12 @@ bool noisy(int loudness, const coord_def& where, const char *msg, bool mermaid)
return (ret);
}
+bool noisy(int loudness, const coord_def& where, int who,
+ bool mermaid)
+{
+ return noisy(loudness, where, NULL, who, mermaid);
+}
+
static const char* _player_vampire_smells_blood(int dist)
{
// non-thirsty vampires get no clear indication of how close the
diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h
index bafb2f7117..44cd06863b 100644
--- a/crawl-ref/source/view.h
+++ b/crawl-ref/source/view.h
@@ -72,8 +72,10 @@ void find_features(const std::vector<coord_def>& features,
bool magic_mapping(int map_radius, int proportion, bool suppress_msg,
bool force = false);
-bool noisy(int loudness, const coord_def& where, const char *msg = NULL,
+bool noisy(int loudness, const coord_def& where, int who,
bool mermaid = false);
+bool noisy(int loudness, const coord_def& where, const char *msg = NULL,
+ int who = -1, bool mermaid = false);
void blood_smell( int strength, const coord_def& where);
void handle_monster_shouts(monsters* monster, bool force = false);