1 #ifndef BLOBS_CREATURE_CREATURE_HPP_
2 #define BLOBS_CREATURE_CREATURE_HPP_
8 #include "Situation.hpp"
9 #include "Steering.hpp"
10 #include "../graphics/SimpleVAO.hpp"
11 #include "../math/glm.hpp"
35 using Callback = std::function<void(Creature &)>;
38 explicit Creature(world::Simulation &);
41 Creature(const Creature &) = delete;
42 Creature &operator =(const Creature &) = delete;
44 Creature(Creature &&) = delete;
45 Creature &operator =(Creature &&) = delete;
48 world::Simulation &GetSimulation() noexcept { return sim; }
49 const world::Simulation &GetSimulation() const noexcept { return sim; }
51 void Name(const std::string &n) noexcept { name = n; }
52 const std::string &Name() const noexcept { return name; }
54 Genome &GetGenome() noexcept { return genome; }
55 const Genome &GetGenome() const noexcept { return genome; }
57 Genome::Properties<double> &GetProperties() noexcept { return properties; }
58 const Genome::Properties<double> &GetProperties() const noexcept { return properties; }
60 const Genome::PropertySet<double> &CurProps() const noexcept { return properties.props[cur_prop]; }
61 const Genome::PropertySet<double> &NextProps() const noexcept { return properties.props[std::min(5, cur_prop + 1)]; }
63 void BaseColor(const glm::dvec3 &c) noexcept { base_color = c; }
64 const glm::dvec3 &BaseColor() const noexcept { return base_color; }
66 void HighlightColor(const glm::dvec3 &c) noexcept { highlight_color = c; }
67 glm::dvec4 HighlightColor() const noexcept;
69 void Mass(double m) noexcept { mass = m; size = std::cbrt(mass / density); }
70 double Mass() const noexcept { return mass; }
71 void Ingest(int res, double amount) noexcept;
73 void Density(double d) noexcept { density = d; size = std::cbrt(mass / density); }
74 double Density() const noexcept { return density; }
76 double Size() const noexcept;
77 double Age() const noexcept;
78 std::string AgeName() const;
79 double AgeLerp(double from, double to) const noexcept;
80 // change of giving birth per tick
81 double Fertility() const noexcept;
83 void Health(double h) noexcept { health = h; }
84 double Health() const noexcept { return health; }
85 void Hurt(double d) noexcept;
87 void OnDeath(Callback cb) noexcept { on_death = cb; }
88 void Remove() noexcept { removable = true; }
89 bool Removable() const noexcept { return removable; }
91 Memory &GetMemory() noexcept { return memory; }
92 const Memory &GetMemory() const noexcept { return memory; }
94 void AddNeed(std::unique_ptr<Need> &&n) { needs.emplace_back(std::move(n)); }
95 const std::vector<std::unique_ptr<Need>> &Needs() const noexcept { return needs; }
97 void AddGoal(std::unique_ptr<Goal> &&);
98 const std::vector<std::unique_ptr<Goal>> &Goals() const noexcept { return goals; }
100 void Tick(double dt);
102 Situation &GetSituation() noexcept { return situation; }
103 const Situation &GetSituation() const noexcept { return situation; }
105 Steering &GetSteering() noexcept { return steering; }
106 const Steering &GetSteering() const noexcept { return steering; }
108 glm::dmat4 LocalTransform() noexcept;
111 void Draw(graphics::Viewport &);
114 Situation::Derivative Step(const Situation::Derivative &ds, double dt) const noexcept;
117 world::Simulation ∼
121 Genome::Properties<double> properties;
124 glm::dvec3 base_color;
125 glm::dvec3 highlight_color;
138 std::vector<std::unique_ptr<Need>> needs;
139 std::vector<std::unique_ptr<Goal>> goals;
149 graphics::SimpleVAO<Attributes, unsigned short> vao;
153 /// put creature on planet and configure it to (hopefully) survive
154 void Spawn(Creature &, world::Planet &);
156 /// split the creature into two
157 void Split(Creature &);