]> git.localhorst.tv Git - blobs.git/blob - src/creature/Creature.hpp
eating and drinking
[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 }
27 namespace creature {
28
29 class Creature {
30
31 public:
32         Creature();
33         ~Creature();
34
35         Creature(const Creature &) = delete;
36         Creature &operator =(const Creature &) = delete;
37
38         Creature(Creature &&) = delete;
39         Creature &operator =(Creature &&) = delete;
40
41 public:
42         void Name(const std::string &n) noexcept { name = n; }
43         const std::string &Name() const noexcept { return name; }
44
45         void Health(double h) noexcept { health = h; }
46         double Health() const noexcept { return health; }
47         void Hurt(double d) noexcept;
48
49         void AddNeed(std::unique_ptr<Need> &&n) { needs.emplace_back(std::move(n)); }
50         const std::vector<std::unique_ptr<Need>> &Needs() const noexcept { return needs; }
51
52         void AddGoal(std::unique_ptr<Goal> &&);
53         const std::vector<std::unique_ptr<Goal>> &Goals() const noexcept { return goals; }
54
55         void Tick(double dt);
56
57         Situation &GetSituation() noexcept { return situation; }
58         const Situation &GetSituation() const noexcept { return situation; }
59
60         Steering &GetSteering() noexcept { return steering; }
61         const Steering &GetSteering() const noexcept { return steering; }
62
63         void Velocity(const glm::dvec3 &v) noexcept { vel = v; }
64         const glm::dvec3 &Velocity() const noexcept { return vel; }
65
66         glm::dmat4 LocalTransform() noexcept;
67
68         void BuildVAO();
69         void Draw(app::Assets &, graphics::Viewport &);
70
71 private:
72         std::string name;
73         double health;
74
75         std::vector<std::unique_ptr<Need>> needs;
76         std::vector<std::unique_ptr<Goal>> goals;
77
78         Situation situation;
79         Steering steering;
80
81         glm::dvec3 vel;
82
83         struct Attributes {
84                 glm::vec3 position;
85                 glm::vec3 normal;
86                 glm::vec3 texture;
87         };
88         graphics::SimpleVAO<Attributes, unsigned short> vao;
89
90 };
91
92 /// put creature on planet and configure it to (hopefully) survive
93 void Spawn(Creature &, world::Planet &, app::Assets &);
94
95 }
96 }
97
98 #endif