File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99struct Stats
1010{
1111public:
12- double & getStat (StatRequest request);
12+ // Returns copy of the stat corresponding to the request
13+ [[nodiscard]] double getStat (StatRequest request) const ;
14+
15+ // Adds the amount of the double to the stat corresponding with the request
16+ void changeStat (StatRequest request, double change);
17+
18+ // Merge another stat object into the called object
19+ // Sums together all stats effectively
20+ void mergeStats (const Stats& other);
1321private:
14- std::array<double , static_cast <size_t >(StatRequest::COUNT)> _data ;
22+ std::array<double , static_cast <size_t >(StatRequest::COUNT)> data{} ;
1523};
1624
1725#endif
Original file line number Diff line number Diff line change 1+ #include " combatants/stats/Stats.hpp"
2+
3+ // type cast the request to an integral value then return double
4+ double Stats::getStat (const StatRequest request) const
5+ {
6+ return data[(static_cast <size_t >(request))];
7+ }
8+
9+ // type cast the request to integral than add change
10+ void Stats::changeStat (const StatRequest request, const double change)
11+ {
12+ data[static_cast <size_t >(request)] += change;
13+ }
14+
15+ void Stats::mergeStats (const Stats& other)
16+ {
17+ for (size_t i{}; i < data.size (); ++i)
18+ {
19+ data[i] += other.data [i];
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments