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"
18 // TODO: AI and entities are tightly coupled, maybe AIcontroller should
19 // be part of Entity. In that case, players could either be separated
20 // from other entities use function as a degenerate AI which blindly
21 // executes whatever its human tell it to.
23 : public EntityController {
26 AIController(World &, Entity &);
29 void SetState(const AIState &, Entity &);
31 void Update(Entity &, float dt) override;
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;
57 /// how far controlled entities can see
59 /// cosine of the half angle of FOV of controlled entities
62 FineTimer think_timer;
63 FineTimer decision_timer;