The base class for all behaviour tree actions.
More...
#include <TreeNode.h>
|
| TreeNode (const std::string &name, const std::string ¶meters, 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...
|
|
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) |
|
|
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 |
|
|
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 |
|
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!
ai::TreeNode::TreeNode |
( |
const std::string & |
name, |
|
|
const std::string & |
parameters, |
|
|
const ConditionPtr & |
condition |
|
) |
| |
|
inline |
- Parameters
-
name | The internal name of the node |
parameters | Each 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 |
condition | The connected ICondition for this node |
TreeNodeStatus ai::TreeNode::execute |
( |
const AIPtr & |
entity, |
|
|
int64_t |
deltaMillis |
|
) |
| |
|
inlinevirtual |
- Parameters
-
entity | The entity to execute the TreeNode for |
deltaMillis | The 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] | self | The pointer to the root node that is returned if one of the direct children need their parent |
[in] | id | The 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] | entity | The 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] | id | The child node id |
[in] | newNode | If 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] | name | The name to set - empty strings are ignored here |
The documentation for this class was generated from the following files:
- /home/travis/build/mgerhardy/simpleai/src/ai/tree/TreeNode.h
- /home/travis/build/mgerhardy/simpleai/src/ai/tree/TreeNodeImpl.h