]> git.localhorst.tv Git - blank.git/blob - src/ai/AIController.hpp
experiments with ai states and steering
[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 GaloisLFSR;
14
15 class AIController
16 : public EntityController {
17
18 public:
19         explicit AIController(GaloisLFSR &);
20         ~AIController();
21
22         void SetState(const AIState &);
23
24         void Update(Entity &, float dt) override;
25
26         glm::vec3 ControlForce(const Entity &, const EntityState &) const override;
27
28         static glm::vec3 Heading(const EntityState &) noexcept;
29
30         /// schedule a decision in the next minimum ± variance seconds
31         void CueDecision(
32                 float minimum,
33                 float variance
34         ) noexcept;
35         /// check if the scheduled decision is due already
36         bool DecisionDue() const noexcept;
37         /// random choice of 0 to num_choices - 1
38         unsigned int Decide(unsigned int num_choices) noexcept;
39
40         void EnterHalt(float speed) noexcept;
41         void ExitHalt() noexcept;
42         bool IsHalted() const noexcept;
43
44         void StartFleeing(const Entity &, float speed) noexcept;
45         void StopFleeing() noexcept;
46         bool IsFleeing() const noexcept;
47         const Entity &GetFleeTarget() const noexcept;
48
49         void StartSeeking(const Entity &, float speed) noexcept;
50         void StopSeeking() noexcept;
51         bool IsSeeking() const noexcept;
52         const Entity &GetSeekTarget() const noexcept;
53
54         /// start wandering randomly at given speed
55         /// the trajectory is modified by targetting a blip on a sphere
56         /// in front of the entity which moves randomly
57         /// the displacement is given (roughly) in units per second
58         void StartWandering(
59                 float speed,
60                 float distance = 2.0f,
61                 float radius = 1.0f,
62                 float displacement = 1.0f
63         ) noexcept;
64         void StopWandering() noexcept;
65         bool IsWandering() const noexcept;
66
67 private:
68         GaloisLFSR &random;
69         const AIState *state;
70
71         FineTimer decision_timer;
72
73         bool halted;
74         float halt_speed;
75
76         const Entity *flee_target;
77         float flee_speed;
78
79         const Entity *seek_target;
80         float seek_speed;
81
82         bool wandering;
83         glm::vec3 wander_pos;
84         float wander_speed;
85         float wander_dist;
86         float wander_radius;
87         float wander_disp;
88
89 };
90
91 }
92
93 #endif