summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/travel.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-06 10:42:29 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-06 10:42:29 +0000
commitbeafe98a63d782fccf7324bc48a5f5394b46b591 (patch)
tree16fc10f0be2ac1f18665257799def758170e8da5 /crawl-ref/source/travel.cc
parent862f907158311aa239b0a82fa4abb4a4e398861d (diff)
downloadcrawl-ref-beafe98a63d782fccf7324bc48a5f5394b46b591.tar.gz
crawl-ref-beafe98a63d782fccf7324bc48a5f5394b46b591.zip
[1748837] Merge identical features when reporting explore discoveries,
distinguish between stairs and portals. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1770 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/travel.cc')
-rw-r--r--crawl-ref/source/travel.cc83
1 files changed, 67 insertions, 16 deletions
diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc
index d579e0752d..529d3c6a47 100644
--- a/crawl-ref/source/travel.cc
+++ b/crawl-ref/source/travel.cc
@@ -628,7 +628,7 @@ bool is_branch_stair(int gridx, int gridy)
return (next.branch != curr.branch);
}
-bool is_stair(unsigned gridc)
+bool is_stair(dungeon_feature_type gridc)
{
return (is_travelable_stair(gridc)
|| gridc == DNGN_ENTER_ABYSS
@@ -641,7 +641,7 @@ bool is_stair(unsigned gridc)
/*
* Returns true if the given dungeon feature can be considered a stair.
*/
-bool is_travelable_stair(unsigned gridc)
+bool is_travelable_stair(dungeon_feature_type gridc)
{
switch (gridc)
{
@@ -2254,7 +2254,7 @@ void start_translevel_travel(bool prompt_for_destination)
}
}
-command_type stair_direction(int stair)
+command_type stair_direction(dungeon_feature_type stair)
{
return ((stair < DNGN_STONE_STAIRS_UP_I
|| stair > DNGN_ROCK_STAIRS_UP)
@@ -2975,7 +2975,7 @@ void LevelInfo::get_stairs(std::vector<coord_def> &st)
{
for (int x = 0; x < GXM; ++x)
{
- int grid = grd[x][y];
+ dungeon_feature_type grid = grd[x][y];
int envc = env.map[x][y].object;
if ((x == you.x_pos && y == you.y_pos)
@@ -3547,7 +3547,8 @@ void runrest::check_mp()
// explore_discoveries
explore_discoveries::explore_discoveries()
- : es_flags(0), current_level(NULL), items(), stairs(), shops(), altars()
+ : es_flags(0), current_level(NULL), items(), stairs(),
+ portals(), shops(), altars()
{
}
@@ -3556,12 +3557,27 @@ std::string explore_discoveries::cleaned_feature_description(
{
std::string s = lowercase_first(feature_description(grid));
if (s.length() && s[s.length() - 1] == '.')
- {
s.erase(s.length() - 1);
- }
+ if (s.find("a ") != std::string::npos)
+ s = s.substr(2);
+ else if (s.find("an ") != std::string::npos)
+ s = s.substr(3);
return (s);
}
+bool explore_discoveries::merge_feature(
+ std::vector< explore_discoveries::named_thing<int> > &v,
+ const explore_discoveries::named_thing<int> &feat) const
+{
+ for (int i = 0, size = v.size(); i < size; ++i)
+ if (feat == v[i])
+ {
+ ++v[i].thing;
+ return (true);
+ }
+ return (false);
+}
+
void explore_discoveries::found_feature(const coord_def &pos,
dungeon_feature_type grid)
{
@@ -3572,22 +3588,34 @@ void explore_discoveries::found_feature(const coord_def &pos,
}
else if (is_stair(grid) && ES_stair)
{
- stairs.push_back(
- named_thing<int>(
- cleaned_feature_description(grid), grid ) );
+ const named_thing<int> stair(cleaned_feature_description(grid), 1);
+ add_stair(stair);
es_flags |= ES_STAIR;
}
else if (is_altar(grid)
&& ES_altar
&& !player_in_branch(BRANCH_ECUMENICAL_TEMPLE))
{
- altars.push_back(
- named_thing<int>(
- cleaned_feature_description(grid), grid ) );
- es_flags |= ES_ALTAR;
+ const named_thing<int> altar(cleaned_feature_description(grid), 1);
+ if (!merge_feature(altars, altar))
+ altars.push_back(altar);
+ es_flags |= ES_ALTAR;
}
}
+void explore_discoveries::add_stair(
+ const explore_discoveries::named_thing<int> &stair)
+{
+ if (merge_feature(stairs, stair) || merge_feature(portals, stair))
+ return;
+
+ // Hackadelic
+ if (stair.name.find("stair") != std::string::npos)
+ stairs.push_back(stair);
+ else
+ portals.push_back(stair);
+}
+
void explore_discoveries::add_item(const item_def &i)
{
if (is_stackable_item(i))
@@ -3659,6 +3687,28 @@ template <class C> void explore_discoveries::say_any(
mprf("%s", message.c_str());
}
+std::vector<std::string> explore_discoveries::apply_quantities(
+ const std::vector< named_thing<int> > &v) const
+{
+ static const char *feature_plural_qualifiers[] =
+ {
+ " leading ", " back to ", " to ", " of "
+ };
+
+ std::vector<std::string> things;
+ for (int i = 0, size = v.size(); i < size; ++i)
+ {
+ const named_thing<int> &nt = v[i];
+ if (nt.thing == 1)
+ things.push_back(article_a(nt.name));
+ else
+ things.push_back(number_in_words(nt.thing)
+ + " "
+ + pluralise(nt.name, feature_plural_qualifiers));
+ }
+ return (things);
+}
+
bool explore_discoveries::prompt_stop() const
{
if (!es_flags)
@@ -3666,8 +3716,9 @@ bool explore_discoveries::prompt_stop() const
say_any(items, "Found %s items.");
say_any(shops, "Found %s shops.");
- say_any(altars, "Found %s altars.");
- say_any(stairs, "Found %s stairs.");
+ say_any(apply_quantities(altars), "Found %s altars.");
+ say_any(apply_quantities(portals), "Found %s gates.");
+ say_any(apply_quantities(stairs), "Found %s stairs.");
return ((Options.explore_stop_prompt & es_flags) != es_flags
|| prompt_stop_explore(es_flags));