CUGL 1.3
Cornell University Game Library
|
#include <CUBehaviorNode.h>
Public Types | |
enum | Type : int { Type::PRIORITY_NODE, Type::SELECTOR_NODE, Type::RANDOM_NODE, Type::INVERTER_NODE, Type::TIMER_NODE, Type::LEAF_NODE } |
Public Member Functions | |
BehaviorNodeDef () | |
std::shared_ptr< BehaviorNodeDef > | getNodeByName (const std::string &name) |
std::shared_ptr< BehaviorNodeDef > | getNodeByName (const char *name) |
Static Public Member Functions | |
static std::shared_ptr< BehaviorNodeDef > | alloc () |
Public Attributes | |
std::string | name |
Type | type |
std::function< float()> | prioritizer |
bool | background |
bool | preemptive |
bool | uniform |
float | delay |
std::vector< std::shared_ptr< BehaviorNodeDef > > | children |
std::shared_ptr< BehaviorActionDef > | action |
A reusable definition for BehaviorNode.
This definition format allows us to have a single node definition that is used across mutliple instances. The motivation is the same as the difference between a Body and BodyDef in Box2d. This node definition can be used for BehaviorNode or any of its subclasses.
|
strong |
An enum used to describe the type of the BehaviorNode.
When creating an instance of a behavior tree node from a BehaviorNodeDef, this enum is used to determine the type of BehaviorNode created.
Behavior tree nodes are either composite, decorator, or leaf nodes. A leaf node has no children, a decorator has only one, and a composite has one or more. Only leaf nodes have actions attached.
cugl::ai::BehaviorNodeDef::BehaviorNodeDef | ( | ) |
Creates an uninitialized behavior node definition.
To create a definition for an node, access the attributes directly.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use the static constructor instead.
|
inlinestatic |
Returns a newly allocated (uninitialized) behavior node definition.
To create a definition for an node, access the attributes directly.
|
inline |
Returns the (first) node definition with the given name.
This method performs a recursive search down the tree specified by this BehaviorNodeDef. If there is more than one node definition of the given name, it returns the first one that is found in an unspecified search order. As a result, names should be unique for best results.
This method returns nullptr if no node is found.
name | An identifier to find the node. |
std::shared_ptr<BehaviorNodeDef> cugl::ai::BehaviorNodeDef::getNodeByName | ( | const std::string & | name | ) |
Returns the (first) node with the given name.
This method performs a recursive search down the tree specified by this BehaviorNodeDef. If there is more than one node definition of the given name, it returns the first one that is found in an unspecified search order. As a result, names should be unique for best results.
This method returns nullptr if no node is found.
name | An identifier to find the node. |
std::shared_ptr<BehaviorActionDef> cugl::ai::BehaviorNodeDef::action |
The action performed when this node is run.
This value is only used when this node is a LeafNode.
bool cugl::ai::BehaviorNodeDef::background |
Whether this node should be run in the "background".
A background node performs some limited update even when the method BehaviorNode#query is called (which happens every step). Otherwise, the node only updates when BehaviorNode#update is called.
Currently this option is only used by TimerNode, which uses it to implement a background delay.
std::vector<std::shared_ptr<BehaviorNodeDef> > cugl::ai::BehaviorNodeDef::children |
The array of definitions for the children for this node.
If this node is a leaf node, then this vector should be empty. If this node is a decorator node, then this vector should have exactly one element.
float cugl::ai::BehaviorNodeDef::delay |
The amount of time to delay execution of a child.
There are two ways to delay a node. One is to chose the child, but not update the child until after a delay period. This is an "active" delay. The node is chosen, preventing other nodes from being chosen (if the parent is not preemptable), but it is delaying its completion.
The other type of delay is to delay when this node can be selected again once it has completed successfully. This is a "sleepy" delay. It will set the priority to 0, and reassign this once the delay has passed.
This option is currently only used if this node is a TimerNode.
std::string cugl::ai::BehaviorNodeDef::name |
The descriptive, identifying name of the node.
bool cugl::ai::BehaviorNodeDef::preemptive |
Whether a node should choose a child to run on each update.
A preemptive composite node can interrupt an old child node's execution if a different child is chosen. If false, a new child is never rechosen until the current active child finishes. This value does not effect whether this node can be preempted by its parent.
This option is only used if this node is a composite node (PriorityNode, SelectorNode, RandomNode).
std::function<float()> cugl::ai::BehaviorNodeDef::prioritizer |
The priority function for this behavior tree node.
This function is used to assign a priority to a particular node. This function must return a value between 0 and 1.
This option is currently ignored by any decorator node, but is used by all other nodes.
Type cugl::ai::BehaviorNodeDef::type |
The type of behavior tree node this definition describes.
bool cugl::ai::BehaviorNodeDef::uniform |
Whether a random node should use a uniform probability.
When true, the composite node chooses among its children uniformly at random. Otherwise, it uses a weighted probability computed from the priority of each child.
This option is currently only used if this node is a RandomNode.