summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stash.cc
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2014-07-13 04:37:03 -0400
committerNeil Moore <neil@s-z.org>2014-07-13 05:01:35 -0400
commit8caa665a5bfd477586b1619f879ee4dcd979859a (patch)
treef8af15797022cf35edfce8aefe2059434acce7f5 /crawl-ref/source/stash.cc
parent7a1f68f5395443fff466645b0e2f1e6749a13c34 (diff)
downloadcrawl-ref-8caa665a5bfd477586b1619f879ee4dcd979859a.tar.gz
crawl-ref-8caa665a5bfd477586b1619f879ee4dcd979859a.zip
More functionobjecticide.
If there is no state, function objects are usually just extra verbosity compared to a function pointer.
Diffstat (limited to 'crawl-ref/source/stash.cc')
-rw-r--r--crawl-ref/source/stash.cc100
1 files changed, 46 insertions, 54 deletions
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index 3935a58945..b45389e691 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -1678,67 +1678,59 @@ protected:
};
// helper for search_stashes
-class compare_by_distance
+static bool _compare_by_distance(const stash_search_result& lhs,
+ const stash_search_result& rhs)
{
-public:
- bool operator()(const stash_search_result& lhs,
- const stash_search_result& rhs)
+ if (lhs.player_distance != rhs.player_distance)
{
- if (lhs.player_distance != rhs.player_distance)
- {
- // Sort by increasing distance
- return lhs.player_distance < rhs.player_distance;
- }
- else if (lhs.player_distance == 0)
- {
- // If on the same level, sort by distance to player.
- const int lhs_dist = grid_distance(you.pos(), lhs.pos.pos);
- const int rhs_dist = grid_distance(you.pos(), rhs.pos.pos);
- if (lhs_dist != rhs_dist)
- return lhs_dist < rhs_dist;
- }
+ // Sort by increasing distance
+ return lhs.player_distance < rhs.player_distance;
+ }
+ else if (lhs.player_distance == 0)
+ {
+ // If on the same level, sort by distance to player.
+ const int lhs_dist = grid_distance(you.pos(), lhs.pos.pos);
+ const int rhs_dist = grid_distance(you.pos(), rhs.pos.pos);
+ if (lhs_dist != rhs_dist)
+ return lhs_dist < rhs_dist;
+ }
- if (lhs.matches != rhs.matches)
- {
- // Then by decreasing number of matches
- return lhs.matches > rhs.matches;
- }
- else if (lhs.match != rhs.match)
- {
- // Then by name.
- return lhs.match < rhs.match;
- }
- else
- return false;
+ if (lhs.matches != rhs.matches)
+ {
+ // Then by decreasing number of matches
+ return lhs.matches > rhs.matches;
}
-};
+ else if (lhs.match != rhs.match)
+ {
+ // Then by name.
+ return lhs.match < rhs.match;
+ }
+ else
+ return false;
+}
// helper for search_stashes
-class compare_by_name
+static bool _compare_by_name(const stash_search_result& lhs,
+ const stash_search_result& rhs)
{
-public:
- bool operator()(const stash_search_result& lhs,
- const stash_search_result& rhs)
+ if (lhs.match != rhs.match)
{
- if (lhs.match != rhs.match)
- {
- // Sort by name
- return lhs.match < rhs.match;
- }
- else if (lhs.player_distance != rhs.player_distance)
- {
- // Then sort by increasing distance
- return lhs.player_distance < rhs.player_distance;
- }
- else if (lhs.matches != rhs.matches)
- {
- // Then by decreasing number of matches
- return lhs.matches > rhs.matches;
- }
- else
- return false;
+ // Sort by name
+ return lhs.match < rhs.match;
}
-};
+ else if (lhs.player_distance != rhs.player_distance)
+ {
+ // Then sort by increasing distance
+ return lhs.player_distance < rhs.player_distance;
+ }
+ else if (lhs.matches != rhs.matches)
+ {
+ // Then by decreasing number of matches
+ return lhs.matches > rhs.matches;
+ }
+ else
+ return false;
+}
void StashTracker::search_stashes()
{
@@ -2102,9 +2094,9 @@ bool StashTracker::display_search_results(
}
if (sort_by_dist)
- sort(results->begin(), results->end(), compare_by_distance());
+ sort(results->begin(), results->end(), _compare_by_distance);
else
- sort(results->begin(), results->end(), compare_by_name());
+ sort(results->begin(), results->end(), _compare_by_name);
StashSearchMenu stashmenu(show_as_stacks ? "hide" : "show",
sort_by_dist ? "dist" : "name",