]> git.localhorst.tv Git - blobs.git/blob - src/creature/Creature.hpp
randomize creature properties a bit
[blobs.git] / src / creature / Creature.hpp
1 #ifndef BLOBS_CREATURE_CREATURE_HPP_
2 #define BLOBS_CREATURE_CREATURE_HPP_
3
4 #include "Genome.hpp"
5 #include "Goal.hpp"
6 #include "Need.hpp"
7 #include "Situation.hpp"
8 #include "Steering.hpp"
9 #include "../graphics/SimpleVAO.hpp"
10 #include "../math/glm.hpp"
11
12 #include <memory>
13 #include <string>
14 #include <vector>
15
16
17 namespace blobs {
18 namespace app {
19         struct Assets;
20 }
21 namespace graphics {
22         class Viewport;
23 }
24 namespace world {
25         class Body;
26         class Planet;
27         class Simulation;
28 }
29 namespace creature {
30
31 class Creature {
32
33 public:
34         explicit Creature(world::Simulation &);
35         ~Creature();
36
37         Creature(const Creature &) = delete;
38         Creature &operator =(const Creature &) = delete;
39
40         Creature(Creature &&) = delete;
41         Creature &operator =(Creature &&) = delete;
42
43 public:
44         world::Simulation &GetSimulation() noexcept { return sim; }
45         const world::Simulation &GetSimulation() const noexcept { return sim; }
46
47         void Name(const std::string &n) noexcept { name = n; }
48         const std::string &Name() const noexcept { return name; }
49
50         Genome &GetGenome() noexcept { return genome; }
51         const Genome &GetGenome() const noexcept { return genome; }
52
53         void Mass(double m) noexcept { mass = m; }
54         double Mass() const noexcept { return mass; }
55
56         void Size(double s) noexcept { size = s; }
57         double Size() const noexcept { return size; }
58
59         void Health(double h) noexcept { health = h; }
60         double Health() const noexcept { return health; }
61         void Hurt(double d) noexcept;
62
63         void AddNeed(std::unique_ptr<Need> &&n) { needs.emplace_back(std::move(n)); }
64         const std::vector<std::unique_ptr<Need>> &Needs() const noexcept { return needs; }
65
66         void AddGoal(std::unique_ptr<Goal> &&);
67         const std::vector<std::unique_ptr<Goal>> &Goals() const noexcept { return goals; }
68
69         void Tick(double dt);
70
71         Situation &GetSituation() noexcept { return situation; }
72         const Situation &GetSituation() const noexcept { return situation; }
73
74         Steering &GetSteering() noexcept { return steering; }
75         const Steering &GetSteering() const noexcept { return steering; }
76
77         void Velocity(const glm::dvec3 &v) noexcept { vel = v; }
78         const glm::dvec3 &Velocity() const noexcept { return vel; }
79         bool Moving() const noexcept { return glm::length2(vel) < 0.000001; }
80
81         glm::dmat4 LocalTransform() noexcept;
82
83         void BuildVAO();
84         void Draw(app::Assets &, graphics::Viewport &);
85
86 private:
87         world::Simulation &sim;
88         std::string name;
89
90         Genome genome;
91
92         double mass;
93         double size;
94         double health;
95
96         std::vector<std::unique_ptr<Need>> needs;
97         std::vector<std::unique_ptr<Goal>> goals;
98
99         Situation situation;
100         Steering steering;
101
102         glm::dvec3 vel;
103
104         struct Attributes {
105                 glm::vec3 position;
106                 glm::vec3 normal;
107                 glm::vec3 texture;
108         };
109         graphics::SimpleVAO<Attributes, unsigned short> vao;
110
111 };
112
113 /// put creature on planet and configure it to (hopefully) survive
114 void Spawn(Creature &, world::Planet &, app::Assets &);
115
116 }
117 }
118
119 #endif