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 /// 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;
37 /// true if the controller may do expensive calculations
38 bool MayThink() const noexcept;
39 void SetThinkInterval(float) noexcept;
41 /// schedule a decision in the next minimum ± variance seconds
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;
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;
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;
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;
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;
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;
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(
103 float distance = 2.0f,
105 float displacement = 1.0f
107 glm::vec3 GetWanderForce(const Entity &, const EntityState &) const noexcept;
112 const AIState *state;
114 /// how far controlled entities can see
116 /// cosine of the half angle of FOV of controlled entities
119 FineTimer think_timer;
120 FineTimer decision_timer;
134 Entity *evade_target;
138 Entity *pursuit_target;
142 glm::vec3 wander_pos;