6 #include <unordered_map>
22 typedef std::shared_ptr<ICharacter> ICharacterPtr;
25 typedef std::vector<CharacterId> FilteredEntities;
27 #ifndef AI_NOTHING_SELECTED
28 #define AI_NOTHING_SELECTED (-1)
41 class AI :
public NonCopyable,
public std::enable_shared_from_this<AI> {
51 typedef std::unordered_map<int, TreeNodeStatus>
NodeStates;
66 void setFilteredEntities(
const FilteredEntities& filteredEntities);
68 void addFilteredEntity(CharacterId
id);
83 TreeNodePtr _behaviour;
86 ICharacterPtr _character;
89 bool _debuggingActive;
95 std::atomic_bool _reset;
100 explicit AI(
const TreeNodePtr& behaviour) :
101 _behaviour(behaviour), _pause(false), _debuggingActive(false), _time(0L), _zone(nullptr), _reset(false) {
111 virtual void update(int64_t dt,
bool debuggingActive);
152 TreeNodePtr
setBehaviour(
const TreeNodePtr& newBehaviour);
162 template <
typename CharacterType>
163 inline CharacterType& getCharacterCast()
const {
164 return *
static_cast<CharacterType*
>(_character.get());
167 int64_t getTime()
const;
169 CharacterId getId()
const;
195 inline std::shared_ptr<AI>
ptr() {
196 return shared_from_this();
205 TreeNodePtr current = _behaviour;
206 _behaviour = newBehaviour;
224 ai_assert(!_character,
"There is already a character set");
225 _character = character;
240 inline void AI::setFilteredEntities(
const FilteredEntities& filteredEntities) {
244 inline void AI::addFilteredEntity(CharacterId
id) {
249 return _debuggingActive;
261 return _zone !=
nullptr;
264 inline int64_t AI::getTime()
const {
268 inline CharacterId AI::getId()
const {
270 return AI_NOTHING_SELECTED;
272 return _character->getId();
281 _character->update(dt, debuggingActive);
288 _lastExecMillis.clear();
290 _selectorStates.clear();
293 _debuggingActive = debuggingActive;
298 typedef std::shared_ptr<AI> AIPtr;
virtual void update(int64_t dt, bool debuggingActive)
Update the behaviour and the aggro values if the entity is not on hold.
Definition: AI.h:275
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
Manages the aggro values for one AI instance. There are several ways to degrade the aggro values...
Definition: AggroMgr.h:21
Zone * getZone() const
Definition: AI.h:256
std::shared_ptr< AI > ptr()
Definition: AI.h:195
const FilteredEntities & getFilteredEntities() const
FilteredEntities is holding a list of CharacterIds that were selected by the Select condition...
Definition: AI.h:236
bool hasZone() const
Returns true if the entity is already in a Zone. This must not be managed manually, the Zone is doing that already.
Definition: AI.h:260
TreeNodePtr setBehaviour(const TreeNodePtr &newBehaviour)
Set a new behaviour.
Definition: AI.h:204
std::unordered_map< int, TreeNodeStatus > NodeStates
Definition: AI.h:51
AI(const TreeNodePtr &behaviour)
Definition: AI.h:100
std::unordered_map< int, int > LimitStates
Definition: AI.h:80
std::unordered_map< int, int > SelectorStates
Definition: AI.h:74
This is the type the library works with. It interacts with it's real world entity by the ICharacter i...
Definition: AI.h:41
The base class for all behaviour tree actions.
Definition: TreeNode.h:88
void setZone(Zone *zone)
Set the new Zone this entity is in.
Definition: AI.h:252
TreeNodePtr getBehaviour() const
Get the current behaviour for this ai.
Definition: AI.h:200
Allows you to register lua TreeNodes, Conditions, Filters and ISteerings.
Definition: LUAAIRegistry.h:69
bool isPause() const
don't update the entity as long as it is paused
Definition: AI.h:215
Definition: NonCopyable.h:8
ICharacterPtr getCharacter() const
Definition: AI.h:219
void setCharacter(const ICharacterPtr &character)
Definition: AI.h:223
AggroMgr & getAggroMgr()
Definition: AI.h:228
void update(int64_t deltaMillis)
this will update the aggro list according to the reduction type of an entry.
Definition: AggroMgr.h:131
std::unordered_map< int, uint64_t > LastExecMap
Definition: AI.h:56
The filter condition executes some selection filters (IFilter) and evaluates to true if the resulting...
Definition: Filter.h:20
FilteredEntities _filteredEntities
Definition: AI.h:64
The server can serialize the state of the AI and broadcast it to all connected clients.
Definition: Server.h:50
bool isDebuggingActive() const
Definition: AI.h:248
void setPause(bool pause)
don't update the entity as long as it is paused
Definition: AI.h:211