From 1919eec67ca85d45f9a2afe626ec718952074d96 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sun, 2 Dec 2007 12:45:55 +0000 Subject: Trunk->0.3 merge (2927-2928): Fixed messages for Olgreb's toxic radiance, fixed another initfile carp to stderr. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.3@2970 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/initfile.cc | 5 ++-- crawl-ref/source/libutil.cc | 71 -------------------------------------------- crawl-ref/source/libutil.h | 19 ------------ crawl-ref/source/spells2.cc | 62 +++++++++++++++++++++++++++++++++++--- 4 files changed, 61 insertions(+), 96 deletions(-) diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index c53ee1e455..0a5bc4c210 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -1602,8 +1602,9 @@ void game_options::read_option_line(const std::string &str, bool runscript) autopickups |= (1L << j); else { - fprintf( stderr, "Bad object type '%c' for autopickup.\n", - type ); + crawl_state.add_startup_error( + make_stringf("Bad object type '%c' for autopickup.\n", + type)); } } } diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index ed0b640680..f87496fd6c 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -561,77 +561,6 @@ int snprintf( char *str, size_t size, const char *format, ... ) #endif -////////////////////////////////////////////////////////////////////////// -// named_thing_collection - -named_thing_collection::named_thing_collection() - : names(), nnames(0u) -{ -} - -void named_thing_collection::add_thing(const std::string &name) -{ - names[name]++; - nnames++; -} - -size_t named_thing_collection::size() const -{ - return (nnames); -} - -bool named_thing_collection::empty() const -{ - return (!nnames); -} - -std::string named_thing_collection::describe( - description_level_type desc, - const char **plural_qualifiers, - const char **no_qualifier_suffixes) const -{ - if (empty()) - return (""); - - std::ostringstream out; - for (name_count_map::const_iterator i = names.begin(); - i != names.end(); ) - { - const std::pair &curr(*i); - if (i != names.begin()) - { - ++i; - out << (i == names.end()? " and " : ", "); - } - else - ++i; - - const std::string name = - curr.second > 1? pluralise(curr.first, plural_qualifiers, - no_qualifier_suffixes) - : curr.first; - out << apply_description(desc, name, curr.second); - - switch (desc) - { - case DESC_CAP_A: - desc = DESC_NOCAP_A; - break; - case DESC_CAP_THE: - desc = DESC_NOCAP_THE; - break; - case DESC_CAP_YOUR: case DESC_NOCAP_YOUR: - desc = DESC_PLAIN; - break; - default: - break; - } - } - return (out.str()); -} - -///////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////// // Pattern matching diff --git a/crawl-ref/source/libutil.h b/crawl-ref/source/libutil.h index 6ae7bedec4..b459f1f99b 100644 --- a/crawl-ref/source/libutil.h +++ b/crawl-ref/source/libutil.h @@ -21,25 +21,6 @@ #include #include -// A collection of named things that can be stacked. The collection merges -// things that should be merged (by name) and outputs a comma-separated list -// with the preferred description type. -class named_thing_collection -{ -public: - named_thing_collection(); - void add_thing(const std::string &name); - std::string describe(description_level_type desc, - const char **plural_qualifiers = NULL, - const char **no_qualifier_suffix = NULL) const; - size_t size() const; - bool empty() const; -private: - typedef std::map name_count_map; - name_count_map names; - size_t nnames; -}; - extern const char *standard_plural_qualifiers[]; // Applies a description type to a name, but does not pluralise! You diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index d9cd928d61..3c13e1d31e 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -23,6 +23,7 @@ #include #include +#include #include "externs.h" @@ -797,6 +798,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) @@ -822,7 +876,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++) { @@ -843,7 +897,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()) { @@ -858,8 +912,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