Peoplemon  0.1.0
Peoplemon 3 game source documentation
AI.hpp
Go to the documentation of this file.
1 #ifndef CORE_SYSTEMS_AI_HPP
2 #define CORE_SYSTEMS_AI_HPP
3 
4 #include <BLIB/ECS.hpp>
5 #include <BLIB/Engine/System.hpp>
11 #include <Core/Files/Behavior.hpp>
12 
13 namespace core
14 {
15 namespace system
16 {
17 class Systems;
18 
25 class AI : public bl::engine::System {
26 public:
32  AI(Systems& owner);
33 
37  virtual ~AI() = default;
38 
46  bool addBehavior(bl::ecs::Entity entity, const file::Behavior& behavior);
47 
55  bool makeStanding(bl::ecs::Entity entity, bl::tmap::Direction dir);
56 
64  bool makeSpinning(bl::ecs::Entity entity, file::Behavior::Spinning::Direction dir);
65 
73  bool makeFollowPath(bl::ecs::Entity entity, const file::Behavior::Path& path);
74 
83  bool makeWander(bl::ecs::Entity entity, unsigned int radius);
84 
94  bool moveToPosition(bl::ecs::Entity entity, const bl::tmap::Position& dest);
95 
101  void removeAi(bl::ecs::Entity ent);
102 
103 private:
104  // type helpers
105  using StandingTypes =
106  bl::ecs::Require<component::StandingBehavior, bl::tmap::Position, component::Controllable>;
107  using SpinTypes =
108  bl::ecs::Require<component::SpinBehavior, bl::tmap::Position, component::Controllable>;
109  using FixedPathTypes =
110  bl::ecs::Require<component::FixedPathBehavior, bl::tmap::Position, component::Controllable>;
111  using WanderTypes =
112  bl::ecs::Require<component::WanderBehavior, bl::tmap::Position, component::Controllable>;
113 
114  using StandingView = bl::ecs::View<StandingTypes>*;
115  using StandingRow = bl::ecs::ComponentSet<StandingTypes>;
116  using SpinView = bl::ecs::View<SpinTypes>*;
117  using SpinRow = bl::ecs::ComponentSet<SpinTypes>;
118  using FixedPathView = bl::ecs::View<FixedPathTypes>*;
119  using FixedPathRow = bl::ecs::ComponentSet<FixedPathTypes>;
120  using WanderView = bl::ecs::View<WanderTypes>*;
121  using WanderRow = bl::ecs::ComponentSet<WanderTypes>;
122 
123  Systems& owner;
124  StandingView standing;
125  SpinView spinning;
126  FixedPathView paths;
127  WanderView wandering;
128 
129  bool findPath(bl::ecs::Entity ent, component::PathFinder& path);
130 
131  virtual void init(bl::engine::Engine&) override;
132  virtual void update(std::mutex&, float dt, float, float, float) override;
133 };
134 
135 } // namespace system
136 } // namespace core
137 
138 #endif
Core classes and functionality for both the editor and game.
Component that dynamically navigates an entity to a specific tile. The entities Controllable componen...
Definition: PathFinder.hpp:18
Set of behaviors for NPCs and trainers.
Definition: Behavior.hpp:19
Direction
The direction to spin.
Definition: Behavior.hpp:51
Contains data for when the behavior type is following a path.
Definition: Behavior.hpp:70
Manages NPC's and trainers and their behaviors.
Definition: AI.hpp:25
virtual ~AI()=default
Destroys the system.
AI(Systems &owner)
Construct a new AI system.
Definition: AI.cpp:26
void removeAi(bl::ecs::Entity ent)
Removes any ai behavior from the given entity. Does not affect path finding.
Definition: AI.cpp:178
bool makeSpinning(bl::ecs::Entity entity, file::Behavior::Spinning::Direction dir)
Makes the given entity spin in place. Replaces any existing behavior.
Definition: AI.cpp:126
bool addBehavior(bl::ecs::Entity entity, const file::Behavior &behavior)
Helper function for adding the given behavior to the given entity.
Definition: AI.cpp:100
bool makeStanding(bl::ecs::Entity entity, bl::tmap::Direction dir)
Makes the given entity stand in place. Replaces any existing behavior on the entity.
Definition: AI.cpp:115
bool moveToPosition(bl::ecs::Entity entity, const bl::tmap::Position &dest)
Uses a pathfinder to navigate the entity to the given position and end up facing the given direction....
Definition: AI.cpp:164
bool makeFollowPath(bl::ecs::Entity entity, const file::Behavior::Path &path)
Make the entity follow a fixed path. Replaces existing behavior.
Definition: AI.cpp:136
bool makeWander(bl::ecs::Entity entity, unsigned int radius)
Makes the given entity wander around within the given radius. Replaces any existing behavior the enti...
Definition: AI.cpp:146
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47