summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spl-other.cc
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2014-07-13 04:55:04 -0400
committerNeil Moore <neil@s-z.org>2014-07-13 05:04:20 -0400
commit366234d7866321869deb3bc75800a91091f3adeb (patch)
tree64206f0d7e3aa6970090c1a96c6161181ef79cd8 /crawl-ref/source/spl-other.cc
parent8caa665a5bfd477586b1619f879ee4dcd979859a (diff)
downloadcrawl-ref-366234d7866321869deb3bc75800a91091f3adeb.tar.gz
crawl-ref-366234d7866321869deb3bc75800a91091f3adeb.zip
Remove some duplicate code.
We had a template to compare pairs by their second member, and two separate classes to do the same thing for specific pair types. Remove the non-generic versions, and move the template to libutil.h.
Diffstat (limited to 'crawl-ref/source/spl-other.cc')
-rw-r--r--crawl-ref/source/spl-other.cc16
1 files changed, 5 insertions, 11 deletions
diff --git a/crawl-ref/source/spl-other.cc b/crawl-ref/source/spl-other.cc
index 3b2ca4fa7a..f259ae41ca 100644
--- a/crawl-ref/source/spl-other.cc
+++ b/crawl-ref/source/spl-other.cc
@@ -19,6 +19,7 @@
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
+#include "libutil.h"
#include "makeitem.h"
#include "message.h"
#include "misc.h"
@@ -181,14 +182,6 @@ spret_type cast_recall(bool fail)
return SPRET_SUCCESS;
}
-struct recall_sorter
-{
- bool operator()(const pair<mid_t,int> &a, const pair<mid_t,int> &b)
- {
- return a.second > b.second;
- }
-};
-
// Type recalled:
// 0 = anything
// 1 = undead only (Yred religion ability)
@@ -196,7 +189,8 @@ struct recall_sorter
void start_recall(int type)
{
// Assemble the recall list.
- vector<pair<mid_t, int> > rlist;
+ typedef pair<mid_t, int> mid_hd;
+ vector<mid_hd> rlist;
you.recall_list.clear();
for (monster_iterator mi; mi; ++mi)
@@ -215,7 +209,7 @@ void start_recall(int type)
continue;
}
- pair<mid_t, int> m = make_pair(mi->mid, mi->hit_dice);
+ mid_hd m(mi->mid, mi->hit_dice);
rlist.push_back(m);
}
@@ -227,7 +221,7 @@ void start_recall(int type)
// Sort the recall list roughly by HD, randomizing a little
for (unsigned int i = 0; i < rlist.size(); ++i)
rlist[i].second += random2(10);
- sort(rlist.begin(), rlist.end(), recall_sorter());
+ sort(rlist.begin(), rlist.end(), greater_second<mid_hd>());
you.recall_list.clear();
for (unsigned int i = 0; i < rlist.size(); ++i)