]>
Commit | Line | Data |
---|---|---|
e248e6be | 1 | #include "toplist.h" |
2 | #include "player.h" | |
3 | #include <list> | |
4 | ||
5 | using namespace std; | |
6 | ||
7 | toplist::toplist() | |
8 | { | |
9 | myList.clear(); | |
10 | count = 10; | |
11 | } | |
12 | ||
13 | toplist::toplist(int c) | |
14 | { | |
15 | myList.clear(); | |
16 | count = c; | |
17 | } | |
18 | ||
19 | toplist::~toplist() | |
20 | { | |
21 | myList.clear(); | |
22 | count = 10; | |
23 | } | |
24 | ||
25 | void toplist::insertPlayer(Player *p) | |
26 | { | |
27 | myList.push_front(*p); | |
28 | sort(); | |
8cd4c581 | 29 | |
30 | // Reverse the list since list::sort() uses the < operator | |
31 | myList.reverse(); | |
e248e6be | 32 | prune(); |
33 | } | |
34 | ||
35 | void toplist::setCount(int c) | |
36 | { | |
37 | count = c; | |
38 | } | |
39 | ||
40 | void toplist::sort() | |
41 | { | |
42 | myList.sort(); | |
43 | } | |
44 | ||
45 | void toplist::prune() | |
46 | { | |
47 | list<Player>::iterator it; | |
48 | it = myList.begin(); | |
49 | ||
50 | for (int x = 0; it != myList.end(); x++, it++) | |
51 | { | |
52 | if (x > count) | |
53 | { | |
54 | // Delete this player from the top list, because they're over the count | |
55 | myList.erase(it); | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | list<Player>::iterator toplist::top() | |
61 | { | |
62 | return myList.begin(); | |
63 | } |