diff options
author | Raphael Langella <raphael.langella@gmail.com> | 2013-01-14 00:14:05 +0100 |
---|---|---|
committer | Raphael Langella <raphael.langella@gmail.com> | 2013-01-14 00:16:11 +0100 |
commit | f8bea7efb50797de8f87549cdf7bb732f97001a7 (patch) | |
tree | 102c39874518f298c053dd395a323276e1213e4c /crawl-ref/source/stash.cc | |
parent | e113f069087158f8470a4db4b660525d3731d454 (diff) | |
download | crawl-ref-f8bea7efb50797de8f87549cdf7bb732f97001a7.tar.gz crawl-ref-f8bea7efb50797de8f87549cdf7bb732f97001a7.zip |
Allow toggling stack to expand shop inventory in search results.
Search for "shop" and press - to quickly see all available goods on the market.
Diffstat (limited to 'crawl-ref/source/stash.cc')
-rw-r--r-- | crawl-ref/source/stash.cc | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index d229da5354..d1a3d8ca9e 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -1027,6 +1027,14 @@ bool ShopInfo::matches_search(const string &prefix, return (match || res.matches); } +vector<item_def> ShopInfo::inventory() const +{ + vector<item_def> ret; + for (unsigned i = 0; i < items.size(); ++i) + ret.push_back(items[i].item); + return ret; +} + void ShopInfo::write(FILE *f, bool identify) const { bool note_status = notes_are_active(); @@ -1908,29 +1916,37 @@ static void _stash_flatten_results(const vector<stash_search_result> &in, out.reserve(in.size() * 2); for (unsigned i = 0; i < in.size(); ++i) { - if (in[i].count < 2) + vector<item_def> items; + + // expand shop inventory + if (in[i].matching_items.empty() && in[i].shop) + items = in[i].shop->inventory(); + else if (in[i].count < 2) + { out.push_back(in[i]); + continue; + } else + items = in[i].matching_items; + + stash_search_result tmp = in[i]; + tmp.count = 1; + for (unsigned j = 0; j < items.size(); ++j) { - stash_search_result tmp = in[i]; - tmp.count = 1; - for (unsigned j = 0; j < in[i].matching_items.size(); ++j) + const item_def &item = items[j]; + tmp.match = Stash::stash_item_name(item); + if (tmp.shop) { - const item_def &item = in[i].matching_items[j]; - tmp.match = Stash::stash_item_name(item); - if (tmp.shop) - { - // Need to check if the item is in the shop so we can add gold price... - // tmp.shop->shop_item_name() - string sn = tmp.shop->get_shop_item_name(item); - if (!sn.empty()) - tmp.match=sn; - } - tmp.matches = item.quantity; - tmp.matching_items.clear(); - tmp.matching_items.push_back(item); - out.push_back(tmp); + // Need to check if the item is in the shop so we can add gold price... + // tmp.shop->shop_item_name() + string sn = tmp.shop->get_shop_item_name(item); + if (!sn.empty()) + tmp.match=sn; } + tmp.matches = item.quantity; + tmp.matching_items.clear(); + tmp.matching_items.push_back(item); + out.push_back(tmp); } } } |