X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fai%2FAIController.hpp;h=cfd49d94a218a12539c98050f45eea0c29416ab9;hb=69d1bc83f472e8fe5b9b16b72ca5c840d8f75123;hp=c1241969bdef702ada0225d0952184cd4a5fa986;hpb=f0a20986c573c4df1eb1212333489252c4b30efa;p=blank.git diff --git a/src/ai/AIController.hpp b/src/ai/AIController.hpp index c124196..cfd49d9 100644 --- a/src/ai/AIController.hpp +++ b/src/ai/AIController.hpp @@ -2,6 +2,7 @@ #define BLANK_AI_AICONTROLLER_HPP_ #include "../app/IntervalTimer.hpp" +#include "../geometry/primitive.hpp" #include "../world/EntityController.hpp" #include @@ -10,22 +11,34 @@ namespace blank { class AIState; -class GaloisLFSR; - +class Entity; +class Player; +class World; + +// TODO: AI and entities are tightly coupled, maybe AIcontroller should +// be part of Entity. In that case, players could either be separated +// from other entities use function as a degenerate AI which blindly +// executes whatever its human tell it to. class AIController : public EntityController { public: - explicit AIController(GaloisLFSR &); + AIController(World &, Entity &); ~AIController(); - void SetState(const AIState &); + void SetState(const AIState &, Entity &); void Update(Entity &, float dt) override; - glm::vec3 ControlForce(const Entity &, const EntityState &) const override; + /// get the closest player that given entity can see + /// returns nullptr if none are in sight + Player *ClosestVisiblePlayer(const Entity &) noexcept; + /// true if to entity is in visible range of from entity + bool LineOfSight(const Entity &from, const Entity &to) const noexcept; - static glm::vec3 Heading(const EntityState &) noexcept; + /// true if the controller may do expensive calculations + bool MayThink() const noexcept; + void SetThinkInterval(float) noexcept; /// schedule a decision in the next minimum ± variance seconds void CueDecision( @@ -37,54 +50,17 @@ public: /// random choice of 0 to num_choices - 1 unsigned int Decide(unsigned int num_choices) noexcept; - void EnterHalt(float speed) noexcept; - void ExitHalt() noexcept; - bool IsHalted() const noexcept; - - void StartFleeing(const Entity &, float speed) noexcept; - void StopFleeing() noexcept; - bool IsFleeing() const noexcept; - const Entity &GetFleeTarget() const noexcept; - - void StartSeeking(const Entity &, float speed) noexcept; - void StopSeeking() noexcept; - bool IsSeeking() const noexcept; - const Entity &GetSeekTarget() const noexcept; - - /// start wandering randomly at given speed - /// the trajectory is modified by targetting a blip on a sphere - /// in front of the entity which moves randomly - /// the displacement is given (roughly) in units per second - void StartWandering( - float speed, - float distance = 2.0f, - float radius = 1.0f, - float displacement = 1.0f - ) noexcept; - void StopWandering() noexcept; - bool IsWandering() const noexcept; - private: - GaloisLFSR &random; + World &world; const AIState *state; - FineTimer decision_timer; - - bool halted; - float halt_speed; - - const Entity *flee_target; - float flee_speed; + /// how far controlled entities can see + float sight_dist; + /// cosine of the half angle of FOV of controlled entities + float sight_angle; - const Entity *seek_target; - float seek_speed; - - bool wandering; - glm::vec3 wander_pos; - float wander_speed; - float wander_dist; - float wander_radius; - float wander_disp; + FineTimer think_timer; + FineTimer decision_timer; };