1 #ifndef BLANK_AI_AICONTROLLER_HPP_
2 #define BLANK_AI_AICONTROLLER_HPP_
4 #include "../app/IntervalTimer.hpp"
5 #include "../geometry/primitive.hpp"
6 #include "../world/EntityController.hpp"
20 : public EntityController {
23 AIController(World &, GaloisLFSR &);
26 void SetState(const AIState &);
28 void Update(Entity &, float dt) override;
30 glm::vec3 ControlForce(const Entity &, const EntityState &) const override;
32 /// get the closest player that given entity can see
33 /// returns nullptr if none are in sight
34 Player *ClosestVisiblePlayer(const Entity &) noexcept;
35 /// true if to entity is in visible range of from entity
36 bool LineOfSight(const Entity &from, const Entity &to) const noexcept;
38 /// true if the controller may do expensive calculations
39 bool MayThink() const noexcept;
40 void SetThinkInterval(float) noexcept;
42 /// schedule a decision in the next minimum ± variance seconds
47 /// check if the scheduled decision is due already
48 bool DecisionDue() const noexcept;
49 /// random choice of 0 to num_choices - 1
50 unsigned int Decide(unsigned int num_choices) noexcept;
52 void EnterHalt() noexcept;
53 void ExitHalt() noexcept;
54 bool IsHalted() const noexcept;
55 void SetHaltSpeed(float) noexcept;
56 glm::vec3 GetHaltForce(const Entity &, const EntityState &) const noexcept;
58 void StartAvoidingObstacles() noexcept;
59 void StopAvoidingObstacles() noexcept;
60 bool IsAvoidingObstacles() const noexcept;
61 glm::vec3 GetObstacleAvoidanceForce(const Entity &, const EntityState &) const noexcept;
63 void StartFleeing() noexcept;
64 void StopFleeing() noexcept;
65 bool IsFleeing() const noexcept;
66 void SetFleeTarget(Entity &) noexcept;
67 void SetFleeSpeed(float) noexcept;
68 Entity &GetFleeTarget() noexcept;
69 const Entity &GetFleeTarget() const noexcept;
70 glm::vec3 GetFleeForce(const Entity &, const EntityState &) const noexcept;
72 void StartSeeking() noexcept;
73 void StopSeeking() noexcept;
74 bool IsSeeking() const noexcept;
75 void SetSeekTarget(Entity &) noexcept;
76 void SetSeekSpeed(float) noexcept;
77 Entity &GetSeekTarget() noexcept;
78 const Entity &GetSeekTarget() const noexcept;
79 glm::vec3 GetSeekForce(const Entity &, const EntityState &) const noexcept;
81 void StartEvading() noexcept;
82 void StopEvading() noexcept;
83 bool IsEvading() const noexcept;
84 void SetEvadeTarget(Entity &) noexcept;
85 void SetEvadeSpeed(float) noexcept;
86 Entity &GetEvadeTarget() noexcept;
87 const Entity &GetEvadeTarget() const noexcept;
88 glm::vec3 GetEvadeForce(const Entity &, const EntityState &) const noexcept;
90 void StartPursuing() noexcept;
91 void StopPursuing() noexcept;
92 bool IsPursuing() const noexcept;
93 void SetPursuitTarget(Entity &) noexcept;
94 void SetPursuitSpeed(float) noexcept;
95 Entity &GetPursuitTarget() noexcept;
96 const Entity &GetPursuitTarget() const noexcept;
97 glm::vec3 GetPursuitForce(const Entity &, const EntityState &) const noexcept;
99 /// start wandering randomly
100 void StartWandering() noexcept;
101 void StopWandering() noexcept;
102 bool IsWandering() const noexcept;
103 /// change how wandering is performed
104 /// the trajectory is modified by targetting a blip on a sphere
105 /// in front of the entity which moves randomly
106 /// the displacement is given (roughly) in units per second
107 void SetWanderParams(
109 float distance = 2.0f,
111 float displacement = 1.0f
113 glm::vec3 GetWanderForce(const Entity &, const EntityState &) const noexcept;
118 const AIState *state;
120 /// how far controlled entities can see
122 /// cosine of the half angle of FOV of controlled entities
125 FineTimer think_timer;
126 FineTimer decision_timer;
131 bool avoid_obstacles;
133 glm::mat4 obstacle_transform;
144 Entity *evade_target;
148 Entity *pursuit_target;
152 glm::vec3 wander_pos;