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