From 85b70c927bf2e95c88530500d01a6ba5f1a9acb7 Mon Sep 17 00:00:00 2001 From: Jude Brown Date: Wed, 11 Nov 2009 22:22:08 +1000 Subject: Move monster speech calculations to monspeak.cc. Make Yiuf chattier. Crazy Yiuf now speaks with more regularity than normal; this is a special case, and could probably be converted to a flag (M_CHATTY) or something similar for other uniques. The monster-speaking chance code seems to make more sense being in monspeak.cc, so moved it there under maybe_mons_speaks. --- crawl-ref/source/monspeak.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'crawl-ref/source/monspeak.cc') diff --git a/crawl-ref/source/monspeak.cc b/crawl-ref/source/monspeak.cc index 8f66ebb025..1d9650bbca 100644 --- a/crawl-ref/source/monspeak.cc +++ b/crawl-ref/source/monspeak.cc @@ -355,6 +355,59 @@ static bool _polyd_can_speak(const monsters* monster) return (shape >= MON_SHAPE_HUMANOID && shape <= MON_SHAPE_NAGA); } +// Returns true if the monster did speak, false otherwise. +// Maybe monsters will speak! +void maybe_mons_speaks (monsters *monster) +{ +#define MON_SPEAK_CHANCE 21 + + if (monster->is_patrolling() || mons_is_wandering(monster) + || monster->attitude == ATT_NEUTRAL) + { + // Very fast wandering/patrolling monsters might, in one monster turn, + // move into the player's LOS and then back out (or the player + // might move into their LOS and the monster move back out before + // the player's view has a chance to update) so prevent them + // from speaking. + ; + } + else if ((mons_class_flag(monster->type, M_SPEAKS) + || !monster->mname.empty()) + && one_chance_in(MON_SPEAK_CHANCE)) + { + mons_speaks(monster); + } + else if (monster->type == MONS_CRAZY_YIUF + && one_chance_in(MON_SPEAK_CHANCE / 3)) + { + // Yiuf gets an extra chance to speak! + mons_speaks(monster); + } + else if (get_mon_shape(monster) >= MON_SHAPE_QUADRUPED) + { + // Non-humanoid-ish monsters have a low chance of speaking + // without the M_SPEAKS flag, to give the dungeon some + // atmosphere/flavour. + int chance = MON_SPEAK_CHANCE * 4; + + // Band members are a lot less likely to speak, since there's + // a lot of them. + if (testbits(monster->flags, MF_BAND_MEMBER)) + chance *= 10; + + // However, confused and fleeing monsters are more interesting. + if (mons_is_fleeing(monster)) + chance /= 2; + if (monster->has_ench(ENCH_CONFUSION)) + chance /= 2; + + if (one_chance_in(chance)) + mons_speaks(monster); + } + // Okay then, don't speak. +} + + // Returns true if something is said. bool mons_speaks(monsters *monster) { -- cgit v1.2.3-54-g00ecf