]> git.localhorst.tv Git - blobs.git/blob - src/creature/Composition.hpp
da669923972a340d8c68a4219014cad105648256
[blobs.git] / src / creature / Composition.hpp
1 #ifndef BLOBLS_CREATURE_COMPOSITION_HPP_
2 #define BLOBLS_CREATURE_COMPOSITION_HPP_
3
4 #include "../world/Set.hpp"
5
6 #include <vector>
7
8
9 namespace blobs {
10 namespace world {
11         class Resource;
12 }
13 namespace creature {
14
15 class Composition {
16
17 public:
18         struct Component {
19                 int resource;
20                 double value;
21                 Component(int r, double v)
22                 : resource(r), value(v) { }
23         };
24
25 public:
26         Composition();
27         ~Composition();
28
29         Composition(const Composition &) = default;
30         Composition &operator =(const Composition &) = default;
31
32         Composition(Composition &&) = default;
33         Composition &operator =(Composition &&) = default;
34
35 public:
36         void Add(int res, double amount);
37         bool Has(int res) const noexcept;
38         double Get(int res) const noexcept;
39         double Proportion(int res) const noexcept;
40         double Compatibility(const world::Set<world::Resource> &, int res) const noexcept;
41         double TotalMass() const noexcept { return total_mass; }
42
43 public:
44         std::vector<Component>::size_type size() const noexcept { return components.size(); }
45         std::vector<Component>::iterator begin() noexcept { return components.begin(); }
46         std::vector<Component>::iterator end() noexcept { return components.end(); }
47         std::vector<Component>::const_iterator begin() const noexcept { return components.begin(); }
48         std::vector<Component>::const_iterator end() const noexcept { return components.end(); }
49         std::vector<Component>::const_iterator cbegin() noexcept { return components.cbegin(); }
50         std::vector<Component>::const_iterator cend() noexcept { return components.cend(); }
51
52 private:
53         std::vector<Component> components;
54         double total_mass;
55
56 };
57
58 }
59 }
60
61 #endif