+int Record::Update(creature::Creature &c, double value, double time) noexcept {
+ int found = -1;
+ for (int i = 0; i < MAX; ++i) {
+ if (value > rank[i].value) {
+ found = i;
+ break;
+ }
+ }
+ if (found < 0) {
+ return -1;
+ }
+ int previous = -1;
+ for (int i = 0; i < MAX; ++i) {
+ if (rank[i].holder == &c) {
+ previous = i;
+ break;
+ }
+ }
+ if (previous < 0) {
+ // move all below down by one
+ std::copy_backward(rank + found, rank + MAX - 1, rank + MAX);
+ } else if (found > previous) {
+ // better than last, but not an improvement
+ // this ensures only one slot occupied per creature
+ return found;
+ } else if (found < previous) {
+ // move all in between down by one
+ std::copy_backward(rank + found, rank + previous, rank + previous + 1);
+ }
+ // insert new
+ rank[found].holder = &c;
+ rank[found].value = value;
+ rank[found].time = time;
+ return found;
+}
+
+std::string Record::ValueString(int i) const {
+ if (i < 0 || i >= MAX || !rank[i].holder) {
+ return "—";
+ }