From ee8bfe95919cb737826f04629698df9258200020 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Mon, 24 Sep 2007 05:04:58 +0000 Subject: ?/ 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 --- crawl-ref/source/database.cc | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'crawl-ref/source/database.cc') 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 database_find_keys(DBM *database, const std::string ®ex, - bool ignore_case) + bool ignore_case, + db_find_filter filter) { text_pattern tpat(regex, ignore_case); std::vector matches; @@ -165,14 +166,12 @@ std::vector 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 database_find_keys(DBM *database, std::vector database_find_bodies(DBM *database, const std::string ®ex, - bool ignore_case) + bool ignore_case, + db_find_filter filter) { text_pattern tpat(regex, ignore_case); std::vector matches; @@ -193,17 +193,15 @@ std::vector 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 getLongDescKeysByRegex(const std::string ®ex) +std::vector getLongDescKeysByRegex(const std::string ®ex, + db_find_filter filter) { if (!descriptionDB) { @@ -470,10 +469,11 @@ std::vector getLongDescKeysByRegex(const std::string ®ex) return (empty); } - return database_find_keys(descriptionDB, regex, true); + return database_find_keys(descriptionDB, regex, true, filter); } -std::vector getLongDescBodiesByRegex(const std::string ®ex) +std::vector getLongDescBodiesByRegex(const std::string ®ex, + db_find_filter filter) { if (!descriptionDB) { @@ -481,7 +481,7 @@ std::vector getLongDescBodiesByRegex(const std::string ®ex) return (empty); } - return database_find_bodies(descriptionDB, regex, true); + return database_find_bodies(descriptionDB, regex, true, filter); } static std::vector description_txt_paths() -- cgit v1.2.3-54-g00ecf