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