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

The base class for all behaviour tree actions. More...

#include <TreeNode.h>

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

Public Member Functions

 TreeNode (const std::string &name, const std::string &parameters, const ConditionPtr &condition)
 
int getId () const
 Return the unique id for this node. More...
 
const std::string & getName () const
 Each node can have a user defines name that can be retrieved with this method.
 
const std::string & getParameters () const
 Return the raw parameters for this node.
 
void setName (const std::string &name)
 Updates the custom name of this TreeNode. More...
 
const std::string & getType () const
 The node type - this usually matches the class name of the TreeNode.
 
const ConditionPtr & getCondition () const
 
void setCondition (const ConditionPtr &condition)
 
const TreeNodes & getChildren () const
 
TreeNodes & getChildren ()
 
virtual void getRunningChildren (const AIPtr &entity, std::vector< bool > &active) const
 Get the state of all child nodes for the given entity. More...
 
int64_t getLastExecMillis (const AIPtr &ai) const
 Returns the time in milliseconds when this node was last run. This is only updated if execute() was called.
 
TreeNodeStatus getLastStatus (const AIPtr &ai) const
 
virtual TreeNodeStatus execute (const AIPtr &entity, int64_t deltaMillis)
 
virtual void resetState (const AIPtr &entity)
 Reset the states in the node and also in the entity.
 
virtual bool addChild (const TreeNodePtr &child)
 
TreeNodePtr getChild (int id) const
 
bool replaceChild (int id, const TreeNodePtr &newNode)
 Replace the given child node with a new one (or removes it) More...
 
TreeNodePtr getParent (const TreeNodePtr &self, int id) const
 Get the parent node for a given TreeNode id - This should only be called on the root node of the behaviour. More...
 
- Public Member Functions inherited from ai::_MemObject< AllocatorClass >
void * operator new (size_t size)
 
void * operator new (size_t, void *ptr)
 
void * operator new[] (size_t size)
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *)
 
void operator delete[] (void *ptr)
 

Protected Member Functions

TreeNodeStatus state (const AIPtr &entity, TreeNodeStatus treeNodeState)
 
int getSelectorState (const AIPtr &entity) const
 
void setSelectorState (const AIPtr &entity, int selected)
 
int getLimitState (const AIPtr &entity) const
 
void setLimitState (const AIPtr &entity, int amount)
 
void setLastExecMillis (const AIPtr &entity)
 
TreeNodePtr getParent_r (const TreeNodePtr &parent, int id) const
 

Static Protected Member Functions

static int getNextId ()
 

Protected Attributes

int _id
 Every node has an id to identify it. It's unique per type.
 
TreeNodes _children
 
std::string _name
 
std::string _type
 
std::string _parameters
 
ConditionPtr _condition
 

Detailed Description

The base class for all behaviour tree actions.

TreeNode::execute is triggered with each AI::update. Also the attached ICondition is evaluated here. States are stored on the connected AI instance. Don't store states on tree nodes, because they can be reused for multiple AI instances. Always use the AI or ICharacter to store your state!

Constructor & Destructor Documentation

ai::TreeNode::TreeNode ( const std::string &  name,
const std::string &  parameters,
const ConditionPtr &  condition 
)
inline
Parameters
nameThe internal name of the node
parametersEach node can be configured with several parameters that are hand in as a string. It's the responsibility of the node to parse the values in its constructor
conditionThe connected ICondition for this node

Member Function Documentation

TreeNodeStatus ai::TreeNode::execute ( const AIPtr &  entity,
int64_t  deltaMillis 
)
inlinevirtual
Parameters
entityThe entity to execute the TreeNode for
deltaMillisThe delta since the last execution
Returns
TreeNodeStatus

Reimplemented in ai::LUATreeNode, ai::ProbabilitySelector, ai::ITimedNode, ai::ITask, ai::Limit, ai::Parallel, ai::Sequence, ai::RandomSelector, ai::Invert, ai::PrioritySelector, ai::Succeed, and ai::Fail.

int ai::TreeNode::getId ( ) const
inline

Return the unique id for this node.

Returns
unique id
TreeNodePtr ai::TreeNode::getParent ( const TreeNodePtr &  self,
int  id 
) const
inline

Get the parent node for a given TreeNode id - This should only be called on the root node of the behaviour.

Parameters
[in]selfThe pointer to the root node that is returned if one of the direct children need their parent
[in]idThe child node id
Returns
An empty TreeNodePtr if not found, or the parent is the root node of the behaviour tree
void ai::TreeNode::getRunningChildren ( const AIPtr &  entity,
std::vector< bool > &  active 
) const
inlinevirtual

Get the state of all child nodes for the given entity.

Parameters
[in]entityThe entity to get the child node states for

Reimplemented in ai::Selector, and ai::Parallel.

bool ai::TreeNode::replaceChild ( int  id,
const TreeNodePtr &  newNode 
)
inline

Replace the given child node with a new one (or removes it)

Parameters
[in]idThe child node id
[in]newNodeIf this is an empty TreeNodePtr the child will be removed
Returns
true if the removal/replace was successful, false otherwise
void ai::TreeNode::setName ( const std::string &  name)
inline

Updates the custom name of this TreeNode.

Parameters
[in]nameThe name to set - empty strings are ignored here

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