]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/Record.hpp
track top ten for each record
[blobs.git] / src / world / Record.hpp
index 0f4ea7dc8abd86b9934ad781941fd3aa750ab54b..f90e9f079e4be024cfda58e55aa39fc3d7aa347f 100644 (file)
@@ -12,10 +12,9 @@ namespace world {
 
 struct Record {
 
+       static constexpr int MAX = 10;
+
        std::string name = "";
-       creature::Creature *holder = nullptr;
-       double value = 0.0;
-       double time = 0.0;
        enum Type {
                VALUE,
                LENGTH,
@@ -23,10 +22,27 @@ struct Record {
                PERCENTAGE,
                TIME,
        } type = VALUE;
+       struct Rank {
+               creature::Creature *holder = nullptr;
+               double value = 0.0;
+               double time = 0.0;
+               operator bool() const noexcept { return holder; }
+       } rank[MAX];
+
+       operator bool() const noexcept { return rank[0]; }
+
+       Rank *begin() noexcept { return rank; }
+       const Rank *begin() const noexcept { return rank; }
+       const Rank *cbegin() const noexcept { return rank; }
+
+       Rank *end() noexcept { return rank + 10; }
+       const Rank *end() const noexcept { return rank + 10; }
+       const Rank *cend() const noexcept { return rank + 10; }
 
-       operator bool() const noexcept { return holder; }
+       /// update hiscore table, returns rank of given creature or -1 if not ranked
+       int Update(creature::Creature &, double value, double time) noexcept;
 
-       std::string ValueString() const;
+       std::string ValueString(int i) const;
 
 };