1 #ifndef BLANK_AI_AICONTROLLER_HPP_
2 #define BLANK_AI_AICONTROLLER_HPP_
4 #include "../app/IntervalTimer.hpp"
5 #include "../world/EntityController.hpp"
19 : public EntityController {
22 AIController(World &, GaloisLFSR &);
25 void SetState(const AIState &);
27 void Update(Entity &, float dt) override;
29 glm::vec3 ControlForce(const Entity &, const EntityState &) const override;
31 static glm::vec3 Heading(const EntityState &) noexcept;
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;
39 /// true if the controller may do expensive calculations
40 bool MayThink() const noexcept;
41 void SetThinkInterval(float) noexcept;
43 /// schedule a decision in the next minimum ± variance seconds
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;
53 void EnterHalt() noexcept;
54 void ExitHalt() noexcept;
55 bool IsHalted() const noexcept;
56 void SetHaltSpeed(float) noexcept;
57 glm::vec3 GetHaltForce(const EntityState &) const noexcept;
59 void StartFleeing() noexcept;
60 void StopFleeing() noexcept;
61 bool IsFleeing() const noexcept;
62 void SetFleeTarget(Entity &) noexcept;
63 void SetFleeSpeed(float) noexcept;
64 Entity &GetFleeTarget() noexcept;
65 const Entity &GetFleeTarget() const noexcept;
66 glm::vec3 GetFleeForce(const EntityState &) const noexcept;
68 void StartSeeking() noexcept;
69 void StopSeeking() noexcept;
70 bool IsSeeking() const noexcept;
71 void SetSeekTarget(Entity &) noexcept;
72 void SetSeekSpeed(float) noexcept;
73 Entity &GetSeekTarget() noexcept;
74 const Entity &GetSeekTarget() const noexcept;
75 glm::vec3 GetSeekForce(const EntityState &) const noexcept;
77 void StartEvading() noexcept;
78 void StopEvading() noexcept;
79 bool IsEvading() const noexcept;
80 void SetEvadeTarget(Entity &) noexcept;
81 void SetEvadeSpeed(float) noexcept;
82 Entity &GetEvadeTarget() noexcept;
83 const Entity &GetEvadeTarget() const noexcept;
84 glm::vec3 GetEvadeForce(const EntityState &) const noexcept;
86 void StartPursuing() noexcept;
87 void StopPursuing() noexcept;
88 bool IsPursuing() const noexcept;
89 void SetPursuitTarget(Entity &) noexcept;
90 void SetPursuitSpeed(float) noexcept;
91 Entity &GetPursuitTarget() noexcept;
92 const Entity &GetPursuitTarget() const noexcept;
93 glm::vec3 GetPursuitForce(const EntityState &) const noexcept;
95 /// start wandering randomly
96 void StartWandering() noexcept;
97 void StopWandering() noexcept;
98 bool IsWandering() const noexcept;
99 /// change how wandering is performed
100 /// the trajectory is modified by targetting a blip on a sphere
101 /// in front of the entity which moves randomly
102 /// the displacement is given (roughly) in units per second
103 void SetWanderParams(
105 float distance = 2.0f,
107 float displacement = 1.0f
109 glm::vec3 GetWanderForce(const EntityState &) const noexcept;
114 const AIState *state;
116 /// how far controlled entities can see
118 /// cosine of the half angle of FOV of controlled entities
121 FineTimer think_timer;
122 FineTimer decision_timer;
136 Entity *evade_target;
140 Entity *pursuit_target;
144 glm::vec3 wander_pos;