summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/database.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-24 05:04:58 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-24 05:04:58 +0000
commitee8bfe95919cb737826f04629698df9258200020 (patch)
treeb8b4f48ee90c6c6c3efade2c8793fdd0f249f230 /crawl-ref/source/database.cc
parentbcbd0cca53601270c2b128eb9c89a9185cb40336 (diff)
downloadcrawl-ref-ee8bfe95919cb737826f04629698df9258200020.tar.gz
crawl-ref-ee8bfe95919cb737826f04629698df9258200020.zip
?/ now asks if you want to describe a monster, spell, or feature, and
filters out matches if they aren't of the desired type. If there's more than one match, after selecting a match to look at, exiting from the description will return you to the menu, rather than to the dungeon. If you've asked for monsters, you can toggle sorting of the menu between alphabetical and by aproximated monster toughness (this probably still needs some work, since it seems to say that ordinary worms are tougher than brain worms). Only the monster symbol is coloured when showing a menu of monsters to describe. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2185 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r--crawl-ref/source/database.cc38
1 files changed, 19 insertions, 19 deletions
diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc
index 86ae4b098c..0e9b598f9c 100644
--- a/crawl-ref/source/database.cc
+++ b/crawl-ref/source/database.cc
@@ -154,7 +154,8 @@ datum database_fetch(DBM *database, const std::string &key)
std::vector<std::string> database_find_keys(DBM *database,
const std::string &regex,
- bool ignore_case)
+ bool ignore_case,
+ db_find_filter filter)
{
text_pattern tpat(regex, ignore_case);
std::vector<std::string> matches;
@@ -165,14 +166,12 @@ std::vector<std::string> database_find_keys(DBM *database,
{
std::string key((const char *)dbKey.dptr, dbKey.dsize);
- if (key.find("__") != std::string::npos)
+ if (tpat.matches(key) &&
+ key.find("__") == std::string::npos
+ && (filter == NULL || !(*filter)(key, "")))
{
- dbKey = dbm_nextkey(database);
- continue;
- }
-
- if (tpat.matches(key))
matches.push_back(key);
+ }
dbKey = dbm_nextkey(database);
}
@@ -182,7 +181,8 @@ std::vector<std::string> database_find_keys(DBM *database,
std::vector<std::string> database_find_bodies(DBM *database,
const std::string &regex,
- bool ignore_case)
+ bool ignore_case,
+ db_find_filter filter)
{
text_pattern tpat(regex, ignore_case);
std::vector<std::string> matches;
@@ -193,17 +193,15 @@ std::vector<std::string> database_find_bodies(DBM *database,
{
std::string key((const char *)dbKey.dptr, dbKey.dsize);
- if (key.find("__") != std::string::npos)
- {
- dbKey = dbm_nextkey(database);
- continue;
- }
-
datum dbBody = dbm_fetch(database, dbKey);
std::string body((const char *)dbBody.dptr, dbBody.dsize);
- if (tpat.matches(body))
+ if (tpat.matches(body) &&
+ key.find("__") == std::string::npos
+ && (filter == NULL || !(*filter)(key, body)))
+ {
matches.push_back(key);
+ }
dbKey = dbm_nextkey(database);
}
@@ -462,7 +460,8 @@ std::string getLongDescription(const std::string &key)
return std::string((const char *)result.dptr, result.dsize);
}
-std::vector<std::string> getLongDescKeysByRegex(const std::string &regex)
+std::vector<std::string> getLongDescKeysByRegex(const std::string &regex,
+ db_find_filter filter)
{
if (!descriptionDB)
{
@@ -470,10 +469,11 @@ std::vector<std::string> getLongDescKeysByRegex(const std::string &regex)
return (empty);
}
- return database_find_keys(descriptionDB, regex, true);
+ return database_find_keys(descriptionDB, regex, true, filter);
}
-std::vector<std::string> getLongDescBodiesByRegex(const std::string &regex)
+std::vector<std::string> getLongDescBodiesByRegex(const std::string &regex,
+ db_find_filter filter)
{
if (!descriptionDB)
{
@@ -481,7 +481,7 @@ std::vector<std::string> getLongDescBodiesByRegex(const std::string &regex)
return (empty);
}
- return database_find_bodies(descriptionDB, regex, true);
+ return database_find_bodies(descriptionDB, regex, true, filter);
}
static std::vector<std::string> description_txt_paths()