]> git.localhorst.tv Git - blank.git/blob - src/ai/AIController.hpp
cache some basic entity axes
[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 "../world/EntityController.hpp"
6
7 #include <glm/glm.hpp>
8
9
10 namespace blank {
11
12 class AIState;
13 class Entity;
14 class GaloisLFSR;
15 class Player;
16 class World;
17
18 class AIController
19 : public EntityController {
20
21 public:
22         AIController(World &, GaloisLFSR &);
23         ~AIController();
24
25         void SetState(const AIState &);
26
27         void Update(Entity &, float dt) override;
28
29         glm::vec3 ControlForce(const Entity &, const EntityState &) const override;
30
31         /// get the closest player that given entity can see
32         /// returns nullptr if none are in sight
33         Player *ClosestVisiblePlayer(const Entity &) noexcept;
34         /// true if to entity is in visible range of from entity
35         bool LineOfSight(const Entity &from, const Entity &to) const noexcept;
36
37         /// true if the controller may do expensive calculations
38         bool MayThink() const noexcept;
39         void SetThinkInterval(float) noexcept;
40
41         /// schedule a decision in the next minimum ± variance seconds
42         void CueDecision(
43                 float minimum,
44                 float variance
45         ) noexcept;
46         /// check if the scheduled decision is due already
47         bool DecisionDue() const noexcept;
48         /// random choice of 0 to num_choices - 1
49         unsigned int Decide(unsigned int num_choices) noexcept;
50
51         void EnterHalt() noexcept;
52         void ExitHalt() noexcept;
53         bool IsHalted() const noexcept;
54         void SetHaltSpeed(float) noexcept;
55         glm::vec3 GetHaltForce(const Entity &, const EntityState &) const noexcept;
56
57         void StartFleeing() noexcept;
58         void StopFleeing() noexcept;
59         bool IsFleeing() const noexcept;
60         void SetFleeTarget(Entity &) noexcept;
61         void SetFleeSpeed(float) noexcept;
62         Entity &GetFleeTarget() noexcept;
63         const Entity &GetFleeTarget() const noexcept;
64         glm::vec3 GetFleeForce(const Entity &, const EntityState &) const noexcept;
65
66         void StartSeeking() noexcept;
67         void StopSeeking() noexcept;
68         bool IsSeeking() const noexcept;
69         void SetSeekTarget(Entity &) noexcept;
70         void SetSeekSpeed(float) noexcept;
71         Entity &GetSeekTarget() noexcept;
72         const Entity &GetSeekTarget() const noexcept;
73         glm::vec3 GetSeekForce(const Entity &, const EntityState &) const noexcept;
74
75         void StartEvading() noexcept;
76         void StopEvading() noexcept;
77         bool IsEvading() const noexcept;
78         void SetEvadeTarget(Entity &) noexcept;
79         void SetEvadeSpeed(float) noexcept;
80         Entity &GetEvadeTarget() noexcept;
81         const Entity &GetEvadeTarget() const noexcept;
82         glm::vec3 GetEvadeForce(const Entity &, const EntityState &) const noexcept;
83
84         void StartPursuing() noexcept;
85         void StopPursuing() noexcept;
86         bool IsPursuing() const noexcept;
87         void SetPursuitTarget(Entity &) noexcept;
88         void SetPursuitSpeed(float) noexcept;
89         Entity &GetPursuitTarget() noexcept;
90         const Entity &GetPursuitTarget() const noexcept;
91         glm::vec3 GetPursuitForce(const Entity &, const EntityState &) const noexcept;
92
93         /// start wandering randomly
94         void StartWandering() noexcept;
95         void StopWandering() noexcept;
96         bool IsWandering() const noexcept;
97         /// change how wandering is performed
98         /// the trajectory is modified by targetting a blip on a sphere
99         /// in front of the entity which moves randomly
100         /// the displacement is given (roughly) in units per second
101         void SetWanderParams(
102                 float speed,
103                 float distance = 2.0f,
104                 float radius = 1.0f,
105                 float displacement = 1.0f
106         ) noexcept;
107         glm::vec3 GetWanderForce(const Entity &, const EntityState &) const noexcept;
108
109 private:
110         World &world;
111         GaloisLFSR &random;
112         const AIState *state;
113
114         /// how far controlled entities can see
115         float sight_dist;
116         /// cosine of the half angle of FOV of controlled entities
117         float sight_angle;
118
119         FineTimer think_timer;
120         FineTimer decision_timer;
121
122         bool halted;
123         float halt_speed;
124
125         bool fleeing;
126         Entity *flee_target;
127         float flee_speed;
128
129         bool seeking;
130         Entity *seek_target;
131         float seek_speed;
132
133         bool evading;
134         Entity *evade_target;
135         float evade_speed;
136
137         bool pursuing;
138         Entity *pursuit_target;
139         float pursuit_speed;
140
141         bool wandering;
142         glm::vec3 wander_pos;
143         float wander_speed;
144         float wander_dist;
145         float wander_radius;
146         float wander_disp;
147
148 };
149
150 }
151
152 #endif