1 #ifndef BLOBLS_CREATURE_COMPOSITION_HPP_
2 #define BLOBLS_CREATURE_COMPOSITION_HPP_
4 #include "../world/Set.hpp"
5 #include "../world/Resource.hpp"
22 Component(int r, double v)
23 : resource(r), value(v) { }
27 explicit Composition(const world::Set<world::Resource> &);
30 Composition(const Composition &) = default;
31 Composition &operator =(const Composition &) = default;
33 Composition(Composition &&) = default;
34 Composition &operator =(Composition &&) = default;
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 TotalVolume() const noexcept { return total_volume; }
45 double TotalDensity() const noexcept { return total_mass / total_volume; }
46 double StateMass(world::Resource::State s) const noexcept { return state_mass[s]; }
49 std::vector<Component>::size_type size() const noexcept { return components.size(); }
50 std::vector<Component>::iterator begin() noexcept { return components.begin(); }
51 std::vector<Component>::iterator end() noexcept { return components.end(); }
52 std::vector<Component>::const_iterator begin() const noexcept { return components.begin(); }
53 std::vector<Component>::const_iterator end() const noexcept { return components.end(); }
54 std::vector<Component>::const_iterator cbegin() noexcept { return components.cbegin(); }
55 std::vector<Component>::const_iterator cend() noexcept { return components.cend(); }
58 const world::Set<world::Resource> &resources;
59 std::vector<Component> components;