]> git.localhorst.tv Git - blobs.git/blob - src/creature/Situation.hpp
4205cff449c8e0f1d57cdaedd39c56662c62ddd2
[blobs.git] / src / creature / Situation.hpp
1 #ifndef BLOBS_CREATURE_SITUATION_HPP_
2 #define BLOBS_CREATURE_SITUATION_HPP_
3
4 #include "../math/glm.hpp"
5
6
7 namespace blobs {
8 namespace world {
9         class Planet;
10         class Tile;
11         class TileType;
12 }
13 namespace creature {
14
15 class Situation {
16
17 public:
18         struct State {
19                 // position
20                 glm::dvec3 pos;
21                 // velocity
22                 glm::dvec3 vel;
23                 // face direction, normalized
24                 glm::dvec3 dir;
25                 State(
26                         const glm::dvec3 &pos = glm::dvec3(0.0),
27                         const glm::dvec3 &vel = glm::dvec3(0.0),
28                         const glm::dvec3 &dir = glm::dvec3(0.0, 0.0, -1.0))
29                 : pos(pos), vel(vel), dir(dir) { }
30         };
31         struct Derivative {
32                 // velocity
33                 glm::dvec3 vel;
34                 // acceleration
35                 glm::dvec3 acc;
36                 Derivative(
37                         const glm::dvec3 &vel = glm::dvec3(0.0),
38                         const glm::dvec3 &acc = glm::dvec3(0.0))
39                 : vel(vel), acc(acc) { }
40         };
41
42 public:
43         Situation();
44         ~Situation();
45
46         Situation(const Situation &) = delete;
47         Situation &operator =(const Situation &) = delete;
48
49         Situation(Situation &&) = delete;
50         Situation &operator =(Situation &&) = delete;
51
52 public:
53         bool OnPlanet() const noexcept;
54         world::Planet &GetPlanet() const noexcept { return *planet; }
55         bool OnSurface() const noexcept;
56         int Surface() const noexcept { return surface; }
57         const glm::dvec3 &Position() const noexcept { return state.pos; }
58         bool OnTile() const noexcept;
59         glm::ivec2 SurfacePosition() const noexcept;
60         world::Tile &GetTile() const noexcept;
61         const world::TileType &GetTileType() const noexcept;
62
63         void SetState(const State &s) noexcept { state = s; }
64         const State &GetState() const noexcept { return state; }
65
66         const glm::dvec3 &Velocity() const noexcept { return state.vel; }
67         bool Moving() const noexcept { return glm::length2(state.vel) > 0.0000001; }
68         void Move(const glm::dvec3 &dp) noexcept;
69
70         void Heading(const glm::dvec3 &h) noexcept { state.dir = h; }
71         const glm::dvec3 &Heading() const noexcept { return state.dir; }
72
73         void SetPlanetSurface(world::Planet &, int srf, const glm::dvec3 &pos) noexcept;
74
75 public:
76         world::Planet *planet;
77         State state;
78         int surface;
79         enum {
80                 LOST,
81                 PLANET_SURFACE,
82         } type;
83
84 };
85
86 }
87 }
88
89 #endif