CUGL 1.3
Cornell University Game Library
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cugl::ai::BehaviorNodeDef Class Reference

#include <CUBehaviorNode.h>

Inheritance diagram for cugl::ai::BehaviorNodeDef:

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< BehaviorNodeDefgetNodeByName (const std::string &name)
 
std::shared_ptr< BehaviorNodeDefgetNodeByName (const char *name)
 

Static Public Member Functions

static std::shared_ptr< BehaviorNodeDefalloc ()
 

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< BehaviorActionDefaction
 

Detailed Description

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.

Member Enumeration Documentation

◆ Type

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.

Enumerator
PRIORITY_NODE 

A composite node to select the child with the highest priority.

SELECTOR_NODE 

A composite node to select the child first in a list.

RANDOM_NODE 

A composite node to select the child randomly.

The selection is either uniform or from a weighted probability based on priority values.

INVERTER_NODE 

A decorator to invert a child's priority value.

As priorities are measure 0 to 1, the inverted priority it 1-priority. This node does not use the priority function provided by the user.

TIMER_NODE 

A decorator to delay the execution of a child node.

Based on the value of _timeDelay, this will delay the initial execution of its child, and also ensure that the child is not run again after a subsequent delay.

LEAF_NODE 

A leaf node in charge of running an action.

This is the base node used for conditional execution (through the priority function). A leaf node must have an action associated with it, and cannot have any children.

Constructor & Destructor Documentation

◆ BehaviorNodeDef()

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.

Member Function Documentation

◆ alloc()

static std::shared_ptr<BehaviorNodeDef> cugl::ai::BehaviorNodeDef::alloc ( )
inlinestatic

Returns a newly allocated (uninitialized) behavior node definition.

To create a definition for an node, access the attributes directly.

Returns
a newly allocated (uninitialized) behavior node definition.

◆ getNodeByName() [1/2]

std::shared_ptr<BehaviorNodeDef> cugl::ai::BehaviorNodeDef::getNodeByName ( const char *  name)
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.

Parameters
nameAn identifier to find the node.
Returns
the (first) node with the given name.

◆ getNodeByName() [2/2]

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.

Parameters
nameAn identifier to find the node.
Returns
the (first) node with the given name.

Member Data Documentation

◆ action

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.

◆ background

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.

◆ children

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.

◆ delay

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.

◆ name

std::string cugl::ai::BehaviorNodeDef::name

The descriptive, identifying name of the node.

◆ preemptive

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).

◆ prioritizer

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

Type cugl::ai::BehaviorNodeDef::type

The type of behavior tree node this definition describes.

◆ uniform

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.


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