From 2d3f243d6828ab20789b6b95dc501806f903b927 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sun, 30 Sep 2007 17:18:31 +0000 Subject: Fixed regex escapes for "." stash search. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2266 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/files.cc | 2 -- crawl-ref/source/place.cc | 5 ++++ crawl-ref/source/place.h | 1 + crawl-ref/source/stash.cc | 63 +++++++++++++++++++++++++++-------------------- crawl-ref/source/stash.h | 1 + 5 files changed, 43 insertions(+), 29 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 190d75cb9c..9f07e5d0ce 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -831,8 +831,6 @@ static void _xom_check_lost_items(level_area_type old_level_type) if (old_level_type == LEVEL_DUNGEON) return; - int amusement = 0; - for (int i = 0; i < MAX_ITEMS; i++) { item_def& item(mitm[i]); diff --git a/crawl-ref/source/place.cc b/crawl-ref/source/place.cc index 0bc2fc8a60..67de365065 100644 --- a/crawl-ref/source/place.cc +++ b/crawl-ref/source/place.cc @@ -177,3 +177,8 @@ bool level_type_allows_followers(level_area_type type) { return (type == LEVEL_DUNGEON || type == LEVEL_PANDEMONIUM); } + +bool level_type_is_stash_trackable(level_area_type type) +{ + return (type != LEVEL_ABYSS && type != LEVEL_LABYRINTH); +} diff --git a/crawl-ref/source/place.h b/crawl-ref/source/place.h index b2bbc0f2b9..078db1f571 100644 --- a/crawl-ref/source/place.h +++ b/crawl-ref/source/place.h @@ -50,5 +50,6 @@ bool single_level_branch(branch_type branch); bool level_type_exits_up(level_area_type type); bool level_type_exits_down(level_area_type type); bool level_type_allows_followers(level_area_type type); +bool level_type_is_stash_trackable(level_area_type type); #endif diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 86dc1c27d4..962883da9d 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -1365,20 +1365,32 @@ void StashTracker::update_visible_stashes( static std::string lastsearch; static input_history search_history(15); +void StashTracker::show_stash_search_prompt() +{ + std::vector opts; + if (!lastsearch.empty()) + opts.push_back( + make_stringf("Enter for \"%s\"", lastsearch.c_str()) ); + if (level_type_is_stash_trackable(you.level_type) + && lastsearch != ".") + { + opts.push_back( + make_stringf("press . for all items on level")); + } + + std::string prompt_qual = + comma_separated_line(opts.begin(), opts.end(), ", or ", ", or "); + + if (!prompt_qual.empty()) + prompt_qual = " [" + prompt_qual + "]"; + + mprf(MSGCH_PROMPT, "Search for what%s?\n", prompt_qual.c_str()); +} + void StashTracker::search_stashes() { - char prompt[200]; - if (lastsearch.length()) - snprintf(prompt, sizeof prompt, - "Search for what [Enter for \"%s\"%s]?\n", - lastsearch.c_str(), lastsearch != "." ? - ", or press . for all items on level" : ""); - else - snprintf(prompt, sizeof prompt, - "Search for what [Press . for all items on level]?\n"); + show_stash_search_prompt(); - mpr(prompt, MSGCH_PROMPT); - char buf[400]; bool validline = !cancelable_get_line(buf, sizeof buf, 80, &search_history); @@ -1392,25 +1404,22 @@ void StashTracker::search_stashes() if (csearch == ".") { - if (you.level_type == LEVEL_DUNGEON) - { - snprintf(info, INFO_SIZE, "%s:%d", - branches[you.where_are_you].abbrevname, player_branch_depth()); - csearch = info; - } - else if (you.level_type == LEVEL_PORTAL_VAULT) - csearch = "{Port}"; - else if (you.level_type == LEVEL_PANDEMONIUM) - csearch = "{Pan}"; - // items in Abyss and Labyrinths are not tracked - else if (you.level_type == LEVEL_ABYSS - || you.level_type == LEVEL_LABYRINTH) + if (!level_type_is_stash_trackable(you.level_type)) { - mprf("Items in %s cannot be tracked.", - you.level_type == LEVEL_ABYSS ? "the Abyss" : "labyrinths"); - return; + mpr("Cannot track items on this level."); + return; } +#if defined(REGEX_PCRE) || defined(REGEX_POSIX) +#define RE_ESCAPE "\\" +#else +#define RE_ESCAPE "" +#endif + + csearch = (RE_ESCAPE "{") + + level_id::current().describe() + + (RE_ESCAPE "}"); } + std::vector results; base_pattern *search = NULL; diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h index 8841911b74..3510d09b07 100644 --- a/crawl-ref/source/stash.h +++ b/crawl-ref/source/stash.h @@ -315,6 +315,7 @@ private: void get_matching_stashes(const base_pattern &search, std::vector &results) const; void display_search_results(std::vector &results); + void show_stash_search_prompt(); private: typedef std::map stash_levels_t; -- cgit v1.2.3-54-g00ecf