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