+
+ void update(T& entry, int bonus, const int D) {
+
+ assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D]
+ assert(abs(32 * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
+
+ entry += bonus * 32 - entry * abs(bonus) / D;
+
+ assert(abs(entry) <= 32 * D);
+ }
+};
+
+/// StatCubes is a generic 3-dimensional array used to store various statistics
+template<int Size1, int Size2, int Size3, typename T = int16_t>
+struct StatCubes : public std::array<std::array<std::array<T, Size3>, Size2>, Size1> {
+
+ void fill(const T& v) {
+ T* p = &(*this)[0][0][0];
+ std::fill(p, p + sizeof(*this) / sizeof(*p), v);
+ }
+
+ void update(T& entry, int bonus, const int D, const int W) {
+
+ assert(abs(bonus) <= D); // Ensure range is [-W * D, W * D]
+ assert(abs(W * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
+
+ entry += bonus * W - entry * abs(bonus) / D;
+
+ assert(abs(entry) <= W * D);
+ }