summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spells2.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-11-28 18:49:02 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-11-28 18:49:02 +0000
commit3c845a534e67829227b01b246ac66de7c7b55de3 (patch)
tree593d2592432de513ace434c7544f98afd8237179 /crawl-ref/source/spells2.cc
parent95259b9b62799b2e5fe00f8833c28b8a96879e49 (diff)
downloadcrawl-ref-3c845a534e67829227b01b246ac66de7c7b55de3.tar.gz
crawl-ref-3c845a534e67829227b01b246ac66de7c7b55de3.zip
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
Diffstat (limited to 'crawl-ref/source/spells2.cc')
-rw-r--r--crawl-ref/source/spells2.cc62
1 files changed, 58 insertions, 4 deletions
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 <stdio.h>
#include <string.h>
+#include <sstream>
#include "externs.h"
@@ -816,6 +817,59 @@ void holy_word(int pow, bool silent)
} // end "for tu"
} // end holy_word()
+typedef std::pair<const monsters*,int> counted_monster;
+typedef std::vector<counted_monster> 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<int>(message.length()) < get_number_of_cols() - 2)
mpr(message.c_str());
else