SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
ai::AI Class Reference

This is the type the library works with. It interacts with it's real world entity by the ICharacter interface. More...

#include <AI.h>

Inheritance diagram for ai::AI:
[legend]
Collaboration diagram for ai::AI:
[legend]

Public Member Functions

 AI (const TreeNodePtr &behaviour)
 
virtual void update (int64_t dt, bool debuggingActive)
 Update the behaviour and the aggro values if the entity is not on hold. More...
 
void setZone (Zone *zone)
 Set the new Zone this entity is in.
 
Zone * getZone () const
 
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.
 
void setPause (bool pause)
 don't update the entity as long as it is paused More...
 
bool isPause () const
 don't update the entity as long as it is paused More...
 
bool isDebuggingActive () const
 
TreeNodePtr getBehaviour () const
 Get the current behaviour for this ai.
 
TreeNodePtr setBehaviour (const TreeNodePtr &newBehaviour)
 Set a new behaviour. More...
 
ICharacterPtr getCharacter () const
 
void setCharacter (const ICharacterPtr &character)
 
template<typename CharacterType >
CharacterType & getCharacterCast () const
 
int64_t getTime () const
 
CharacterId getId () const
 
AggroMgrgetAggroMgr ()
 
const AggroMgrgetAggroMgr () const
 
const FilteredEntities & getFilteredEntities () const
 FilteredEntities is holding a list of CharacterIds that were selected by the Select condition. More...
 
std::shared_ptr< AIptr ()
 

Protected Types

typedef std::unordered_map
< int, TreeNodeStatus > 
NodeStates
 
typedef std::unordered_map
< int, uint64_t > 
LastExecMap
 
typedef std::unordered_map
< int, int > 
SelectorStates
 
typedef std::unordered_map
< int, int > 
LimitStates
 

Protected Member Functions

void setFilteredEntities (const FilteredEntities &filteredEntities)
 
void addFilteredEntity (CharacterId id)
 

Protected Attributes

NodeStates _lastStatus
 
LastExecMap _lastExecMillis
 
FilteredEntities _filteredEntities
 
SelectorStates _selectorStates
 
LimitStates _limitStates
 
TreeNodePtr _behaviour
 
AggroMgr _aggroMgr
 
ICharacterPtr _character
 
bool _pause
 
bool _debuggingActive
 
int64_t _time
 
Zone * _zone
 
std::atomic_bool _reset
 

Friends

class TreeNode
 
class LUAAIRegistry
 
class IFilter
 
class Filter
 
class Server
 

Detailed Description

This is the type the library works with. It interacts with it's real world entity by the ICharacter interface.

Each ai entity has a [AggroMgr} assigned that is updated with each tick (update()).

A behaviour can be replaced at runtime with setBehaviour()

You can set single AI instances to no longer update their state by calling setPause()

Member Typedef Documentation

typedef std::unordered_map<int, uint64_t> ai::AI::LastExecMap
protected

This map is only filled if we are in debugging mode for this entity

typedef std::unordered_map<int, int> ai::AI::LimitStates
protected

This map stores the amount of execution for the Limit node. The key is the node id

typedef std::unordered_map<int, TreeNodeStatus> ai::AI::NodeStates
protected

This map is only filled if we are in debugging mode for this entity

typedef std::unordered_map<int, int> ai::AI::SelectorStates
protected

Often Selector states must be stored to continue in the next step at a particular position in the behaviour tree. This map is doing exactly this.

Constructor & Destructor Documentation

ai::AI::AI ( const TreeNodePtr &  behaviour)
inlineexplicit
Parameters
behaviourThe behaviour tree node that is applied to this ai entity

Member Function Documentation

AggroMgr & ai::AI::getAggroMgr ( )
inline
Returns
the AggroMgr for this AI instance. Each AI instance has its own AggroMgr instance.
const AggroMgr & ai::AI::getAggroMgr ( ) const
inline
Returns
the AggroMgr for this AI instance. Each AI instance has its own AggroMgr instance.
ICharacterPtr ai::AI::getCharacter ( ) const
inline
Returns
The real world entity reference
const FilteredEntities & ai::AI::getFilteredEntities ( ) const
inline

FilteredEntities is holding a list of CharacterIds that were selected by the Select condition.

See Also
IFilter interface.
Filter condition that executes assigned IFilter implementations.
Returns
A reference to the internal data structure. This should only be used from within TreeNode implementations to access those entities that were filtered by the Filter condition.
Note
If you call this from outside of the behaviour tree tick, you will run into race conditions.
Zone * ai::AI::getZone ( ) const
inline

Returns the Zone this entity is in.

bool ai::AI::isDebuggingActive ( ) const
inline
Returns
true if the owning entity is currently under debugging, false otherwise
bool ai::AI::isPause ( ) const
inline

don't update the entity as long as it is paused

See Also
setPause()
std::shared_ptr<AI> ai::AI::ptr ( )
inline

If the object is currently maintained by a shared_ptr, you can get a shared_ptr from a raw pointer instance that shares the state with the already existing shared_ptrs around.

TreeNodePtr ai::AI::setBehaviour ( const TreeNodePtr &  newBehaviour)
inline

Set a new behaviour.

Returns
the old one if there was any
void ai::AI::setCharacter ( const ICharacterPtr &  character)
inline

You might not set a character twice to an AI instance.

void ai::AI::setPause ( bool  pause)
inline

don't update the entity as long as it is paused

See Also
isPause()
void ai::AI::update ( int64_t  dt,
bool  debuggingActive 
)
inlinevirtual

Update the behaviour and the aggro values if the entity is not on hold.

Parameters
[in]dtThe current milliseconds to update the aggro entries and time based tasks or conditions.

Member Data Documentation

FilteredEntities ai::AI::_filteredEntities
mutableprotected
Note
The filtered entities are kept even over several ticks. The caller should decide whether he still needs an old/previous filtered selection
See Also
IFilter

The documentation for this class was generated from the following file: