]> git.localhorst.tv Git - blank.git/blob - src/ai/AIController.hpp
glm backwards compatibility
[blank.git] / src / ai / AIController.hpp
1 #ifndef BLANK_AI_AICONTROLLER_HPP_
2 #define BLANK_AI_AICONTROLLER_HPP_
3
4 #include "../app/IntervalTimer.hpp"
5 #include "../geometry/primitive.hpp"
6 #include "../graphics/glm.hpp"
7 #include "../world/EntityController.hpp"
8
9
10 namespace blank {
11
12 class AIState;
13 class Entity;
14 class Player;
15 class World;
16
17 // TODO: AI and entities are tightly coupled, maybe AIcontroller should
18 //       be part of Entity. In that case, players could either be separated
19 //       from other entities use function as a degenerate AI which blindly
20 //       executes whatever its human tell it to.
21 class AIController
22 : public EntityController {
23
24 public:
25         AIController(World &, Entity &);
26         ~AIController();
27
28         void SetState(const AIState &, Entity &);
29
30         void Update(Entity &, float dt) override;
31
32         /// get the closest player that given entity can see
33         /// returns nullptr if none are in sight
34         Player *ClosestVisiblePlayer(const Entity &) noexcept;
35         /// true if to entity is in visible range of from entity
36         bool LineOfSight(const Entity &from, const Entity &to) const noexcept;
37
38         /// true if the controller may do expensive calculations
39         bool MayThink() const noexcept;
40         void SetThinkInterval(float) noexcept;
41
42         /// schedule a decision in the next minimum ± variance seconds
43         void CueDecision(
44                 float minimum,
45                 float variance
46         ) noexcept;
47         /// check if the scheduled decision is due already
48         bool DecisionDue() const noexcept;
49         /// random choice of 0 to num_choices - 1
50         unsigned int Decide(unsigned int num_choices) noexcept;
51
52 private:
53         World &world;
54         const AIState *state;
55
56         /// how far controlled entities can see
57         float sight_dist;
58         /// cosine of the half angle of FOV of controlled entities
59         float sight_angle;
60
61         FineTimer think_timer;
62         FineTimer decision_timer;
63
64 };
65
66 }
67
68 #endif