1 #ifndef BLOBS_CREATURE_CREATURE_HPP_
2 #define BLOBS_CREATURE_CREATURE_HPP_
7 #include "Situation.hpp"
8 #include "Steering.hpp"
9 #include "../graphics/SimpleVAO.hpp"
10 #include "../math/glm.hpp"
34 using Callback = std::function<void(Creature &)>;
37 explicit Creature(world::Simulation &);
40 Creature(const Creature &) = delete;
41 Creature &operator =(const Creature &) = delete;
43 Creature(Creature &&) = delete;
44 Creature &operator =(Creature &&) = delete;
47 world::Simulation &GetSimulation() noexcept { return sim; }
48 const world::Simulation &GetSimulation() const noexcept { return sim; }
50 void Name(const std::string &n) noexcept { name = n; }
51 const std::string &Name() const noexcept { return name; }
53 Genome &GetGenome() noexcept { return genome; }
54 const Genome &GetGenome() const noexcept { return genome; }
56 Genome::Properties<double> &GetProperties() noexcept { return properties; }
57 const Genome::Properties<double> &GetProperties() const noexcept { return properties; }
59 void Mass(double m) noexcept { mass = m; size = std::cbrt(mass / density); }
60 double Mass() const noexcept { return mass; }
61 void Grow(double amount) noexcept;
63 void Density(double d) noexcept { density = d; size = std::cbrt(mass / density); }
64 double Density() const noexcept { return density; }
66 double Size() const noexcept;
67 double Age() const noexcept;
68 // change of giving birth per tick
69 double Fertility() const noexcept;
71 void Health(double h) noexcept { health = h; }
72 double Health() const noexcept { return health; }
73 void Hurt(double d) noexcept;
75 void OnDeath(Callback cb) noexcept { on_death = cb; }
76 void Remove() noexcept { removable = true; }
77 bool Removable() const noexcept { return removable; }
79 void AddNeed(std::unique_ptr<Need> &&n) { needs.emplace_back(std::move(n)); }
80 const std::vector<std::unique_ptr<Need>> &Needs() const noexcept { return needs; }
82 void AddGoal(std::unique_ptr<Goal> &&);
83 const std::vector<std::unique_ptr<Goal>> &Goals() const noexcept { return goals; }
87 Situation &GetSituation() noexcept { return situation; }
88 const Situation &GetSituation() const noexcept { return situation; }
90 Steering &GetSteering() noexcept { return steering; }
91 const Steering &GetSteering() const noexcept { return steering; }
93 void Velocity(const glm::dvec3 &v) noexcept { vel = v; }
94 const glm::dvec3 &Velocity() const noexcept { return vel; }
95 bool Moving() const noexcept { return glm::length2(vel) < 0.00000001; }
97 glm::dmat4 LocalTransform() noexcept;
100 void Draw(graphics::Viewport &);
103 world::Simulation ∼
107 Genome::Properties<double> properties;
118 std::vector<std::unique_ptr<Need>> needs;
119 std::vector<std::unique_ptr<Goal>> goals;
131 graphics::SimpleVAO<Attributes, unsigned short> vao;
135 /// put creature on planet and configure it to (hopefully) survive
136 void Spawn(Creature &, world::Planet &);
138 /// split the creature into two
139 void Split(Creature &);