]> git.localhorst.tv Git - blobs.git/blob - src/world/Record.hpp
track top ten for each record
[blobs.git] / src / world / Record.hpp
1 #ifndef BLOBS_WORLD_RECORD_HPP_
2 #define BLOBS_WORLD_RECORD_HPP_
3
4 #include <string>
5
6
7 namespace blobs {
8 namespace creature {
9         class Creature;
10 }
11 namespace world {
12
13 struct Record {
14
15         static constexpr int MAX = 10;
16
17         std::string name = "";
18         enum Type {
19                 VALUE,
20                 LENGTH,
21                 MASS,
22                 PERCENTAGE,
23                 TIME,
24         } type = VALUE;
25         struct Rank {
26                 creature::Creature *holder = nullptr;
27                 double value = 0.0;
28                 double time = 0.0;
29                 operator bool() const noexcept { return holder; }
30         } rank[MAX];
31
32         operator bool() const noexcept { return rank[0]; }
33
34         Rank *begin() noexcept { return rank; }
35         const Rank *begin() const noexcept { return rank; }
36         const Rank *cbegin() const noexcept { return rank; }
37
38         Rank *end() noexcept { return rank + 10; }
39         const Rank *end() const noexcept { return rank + 10; }
40         const Rank *cend() const noexcept { return rank + 10; }
41
42         /// update hiscore table, returns rank of given creature or -1 if not ranked
43         int Update(creature::Creature &, double value, double time) noexcept;
44
45         std::string ValueString(int i) const;
46
47 };
48
49 }
50 }
51
52 #endif