From 3c845a534e67829227b01b246ac66de7c7b55de3 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Wed, 28 Nov 2007 18:49:02 +0000 Subject: Fixed bad messages when uniques are poisoned by toxic radiance. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2927 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/spells2.cc | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'crawl-ref/source/spells2.cc') diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index b0893d8f5c..1488c8e036 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -24,6 +24,7 @@ #include #include +#include #include "externs.h" @@ -816,6 +817,59 @@ void holy_word(int pow, bool silent) } // end "for tu" } // end holy_word() +typedef std::pair counted_monster; +typedef std::vector counted_monster_list; +static void record_monster_by_name(counted_monster_list &list, + const monsters *mons) +{ + const std::string name = mons->name(DESC_PLAIN); + for (counted_monster_list::iterator i = list.begin(); i != list.end(); ++i) + { + if (i->first->name(DESC_PLAIN) == name) + { + i->second++; + return; + } + } + list.push_back( counted_monster(mons, 1) ); +} + +static int monster_count(const counted_monster_list &list) +{ + int nmons = 0; + for (counted_monster_list::const_iterator i = list.begin(); + i != list.end(); ++i) + { + nmons += i->second; + } + return (nmons); +} + +static std::string describe_monsters(const counted_monster_list &list) +{ + std::ostringstream out; + + description_level_type desc = DESC_CAP_THE; + for (counted_monster_list::const_iterator i = list.begin(); + i != list.end(); desc = DESC_NOCAP_THE) + { + const counted_monster &cm(*i); + if (i != list.begin()) + { + ++i; + out << (i == list.end()? " and " : ", "); + } + else + ++i; + + const std::string name = + cm.second > 1? pluralise(cm.first->name(desc)) + : cm.first->name(desc); + out << name; + } + return (out.str()); +} + // poisonous light passes right through invisible players // and monsters, and so, they are unaffected by this spell -- // assumes only you can cast this spell (or would want to) @@ -841,7 +895,7 @@ void cast_toxic_radiance(void) poison_player(2); } - named_thing_collection affected_monsters; + counted_monster_list affected_monsters; // determine which monsters are hit by the radiance: {dlb} for (int toxy = 0; toxy < MAX_MONSTERS; toxy++) { @@ -862,7 +916,7 @@ void cast_toxic_radiance(void) affected = true; if (affected) - affected_monsters.add_thing(monster->name(DESC_PLAIN)); + record_monster_by_name(affected_monsters, monster); } else if (player_see_invis()) { @@ -877,8 +931,8 @@ void cast_toxic_radiance(void) { const std::string message = make_stringf("%s %s poisoned.", - affected_monsters.describe(DESC_CAP_THE).c_str(), - affected_monsters.size() == 1? "is" : "are"); + describe_monsters(affected_monsters).c_str(), + monster_count(affected_monsters) == 1? "is" : "are"); if (static_cast(message.length()) < get_number_of_cols() - 2) mpr(message.c_str()); else -- cgit v1.2.3-54-g00ecf