Drag[en]gine Script Module DragonScript  1.23
Dragengine.BehaviorTreeSystem.BTContext Class Reference

Behavior tree context. More...

Inheritance diagram for Dragengine.BehaviorTreeSystem.BTContext:
Dragengine.Scenery.BAAIBehaviorTree.BTContextAI

Public Member Functions

void forEachAction (Block ablock)
 Visit actions using block with parameters String (name and BTAction (action). More...
 
void forEachCondition (Block ablock)
 Visit conditions using block with parameters String (name and BTCondition (condition). More...
 
BTAction getAction (String name)
 Action for name or null if absent. More...
 
int getActionCount ()
 Number of actions. More...
 
bool getActionFirstRun ()
 Action runs for the first time after the current rule changed. More...
 
BehaviorTree getBehaviorTree ()
 Behavior tree. More...
 
BTCondition getCondition (String name)
 Condition for name or null if absent. More...
 
int getConditionCount ()
 Number of conditions. More...
 
Console getConsole ()
 Console or null if not wishing to log anything. More...
 
BTRule getCurrentRule ()
 Current rule. More...
 
BTResult getLastResult ()
 Last result. More...
 
String getLoggingName ()
 Logging name to tell apart logs. More...
 
bool getLogRuleChanges ()
 Log behavior tree rule changes. More...
 
bool getLogSteps ()
 Log behavior tree steps. More...
 
int getRunAwayLimit ()
 Run away limit. More...
 
bool hasAction (String name)
 Action is present. More...
 
bool hasCondition (String name)
 Condition is present. More...
 
BTContext new (BehaviorTree behaviorTree)
 Create behavior tree context. More...
 
BTContext new (BTContext context)
 Create copy of behavior tree context. More...
 
BTContext new (BTContext context, BehaviorTree behaviorTree)
 Create copy of behavior tree context but using a different behavior tree. More...
 
void readFromFile (PersistencyEnvironment env, FileReader reader)
 Read state from file. More...
 
void removeAction (String name)
 Remove action. More...
 
void removeAllActions ()
 Remove all actions. More...
 
void removeAllConditions ()
 Remove all conditions. More...
 
void removeCondition (String name)
 Remove condition. More...
 
void reset ()
 Reset to initial state. More...
 
void setAction (String name, Block action)
 Set action for name using block. More...
 
void setAction (String name, BTAction action)
 Set action for name. More...
 
void setActionFirstRun (bool firstRun)
 Set action runs for the first time after the current rule changed. More...
 
void setBehaviorTree (BehaviorTree behaviorTree)
 Set behavior tree and reset state. More...
 
void setCondition (String name, Block condition)
 Set condition for name using block. More...
 
void setCondition (String name, BTCondition condition)
 Set condition for name. More...
 
void setConsole (Console console)
 Set console or null if not wishing to log anything. More...
 
void setCurrentRule (BTRule rule)
 Set current rule. More...
 
void setCurrentRuleByID (String id)
 Set current rule by identifier. More...
 
void setLoggingName (String name)
 Set logging name to tell apart logs. More...
 
void setLogRuleChanges (bool logRuleChanges)
 Set log behavior tree rule changes. More...
 
void setLogSteps (bool logSteps)
 Set log behavior tree steps. More...
 
void setRunAwayLimit (int limit)
 Set run away limit. More...
 
bool stepBehaviorTree ()
 Step behavior tree. More...
 
void writeToFile (PersistencyEnvironment env, FileWriter writer)
 Write state to file. More...
 

Public Attributes

bool pActionFirstRun
 
Dictionary pActions
 
BehaviorTree pBehaviorTree
 
Dictionary pConditions
 
Console pConsole
 
BTRule pCurrentRule
 
BTResult pLastResult
 
String pLoggingName
 
bool pLogRuleChanges
 
bool pLogSteps
 
Array pRunAwayList
 

Protected Member Functions

void onCurrentRuleChanged ()
 Hook method called if setCurrentRule() is called. More...
 

Detailed Description

Behavior tree context.

Used to run a behavior tree instance. The behavior tree itself is shared across contexts while the individual state is stored in the context. Context has to provide the BTAction instances for the behavior tree rules to call. Subclass the context to provide the required data for your BTAction subclasses to work properly.

The context can be written to and restored from file readers. This class saves only the current rule identifier. Subclass has to save its own states by overwriting readFromFile() and writeToFile().

Since version 1.19 the behavior tree can be changed after creating the context. If you change the behavior tree during runtime you have to make sure it is also set before readFromFile() is called otherwise an exception can be thrown.

Member Function Documentation

◆ forEachAction()

void Dragengine.BehaviorTreeSystem.BTContext.forEachAction ( Block  ablock)

Visit actions using block with parameters String (name and BTAction (action).

◆ forEachCondition()

void Dragengine.BehaviorTreeSystem.BTContext.forEachCondition ( Block  ablock)

Visit conditions using block with parameters String (name and BTCondition (condition).

◆ getAction()

BTAction Dragengine.BehaviorTreeSystem.BTContext.getAction ( String  name)

Action for name or null if absent.

◆ getActionCount()

int Dragengine.BehaviorTreeSystem.BTContext.getActionCount ( )

Number of actions.

◆ getActionFirstRun()

bool Dragengine.BehaviorTreeSystem.BTContext.getActionFirstRun ( )

Action runs for the first time after the current rule changed.

After calling setCurrentRule() this flag is set to true. Whenever an action is run this flag is set to false. This allows actions to know if they are run for the first time after the current rule changed. This allows actions to do some setting up tasks the first time they run and check back on this state as long as they run.

◆ getBehaviorTree()

BehaviorTree Dragengine.BehaviorTreeSystem.BTContext.getBehaviorTree ( )

Behavior tree.

◆ getCondition()

BTCondition Dragengine.BehaviorTreeSystem.BTContext.getCondition ( String  name)

Condition for name or null if absent.

◆ getConditionCount()

int Dragengine.BehaviorTreeSystem.BTContext.getConditionCount ( )

Number of conditions.

◆ getConsole()

Console Dragengine.BehaviorTreeSystem.BTContext.getConsole ( )

Console or null if not wishing to log anything.

◆ getCurrentRule()

BTRule Dragengine.BehaviorTreeSystem.BTContext.getCurrentRule ( )

Current rule.

◆ getLastResult()

BTResult Dragengine.BehaviorTreeSystem.BTContext.getLastResult ( )

Last result.

◆ getLoggingName()

String Dragengine.BehaviorTreeSystem.BTContext.getLoggingName ( )

Logging name to tell apart logs.

◆ getLogRuleChanges()

bool Dragengine.BehaviorTreeSystem.BTContext.getLogRuleChanges ( )

Log behavior tree rule changes.

◆ getLogSteps()

bool Dragengine.BehaviorTreeSystem.BTContext.getLogSteps ( )

Log behavior tree steps.

◆ getRunAwayLimit()

int Dragengine.BehaviorTreeSystem.BTContext.getRunAwayLimit ( )

Run away limit.

◆ hasAction()

bool Dragengine.BehaviorTreeSystem.BTContext.hasAction ( String  name)

Action is present.

◆ hasCondition()

bool Dragengine.BehaviorTreeSystem.BTContext.hasCondition ( String  name)

Condition is present.

◆ new() [1/3]

BTContext Dragengine.BehaviorTreeSystem.BTContext.new ( BehaviorTree  behaviorTree)

Create behavior tree context.

◆ new() [2/3]

BTContext Dragengine.BehaviorTreeSystem.BTContext.new ( BTContext  context)

Create copy of behavior tree context.

Actions are copied as shallow copy. If you need a deep set all actions anew. The state of the context is the same as without creating a copy.

◆ new() [3/3]

BTContext Dragengine.BehaviorTreeSystem.BTContext.new ( BTContext  context,
BehaviorTree  behaviorTree 
)

Create copy of behavior tree context but using a different behavior tree.

Actions are copied as shallow copy. If you need a deep set all actions anew. The state of the context is the same as without creating a copy.

This method is useful to use an initialized base context with a fallback behavior tree. Whenever a new context is required the base context is copied. This avoids the need to assign actions and conditions since they are copied from the base context.

◆ onCurrentRuleChanged()

void Dragengine.BehaviorTreeSystem.BTContext.onCurrentRuleChanged ( )
protected

Hook method called if setCurrentRule() is called.

Allows subclasses to react to current rule changes. This might be required for certain BTAction to reset states if rules change.

◆ readFromFile()

void Dragengine.BehaviorTreeSystem.BTContext.readFromFile ( PersistencyEnvironment  env,
FileReader  reader 
)

Read state from file.

◆ removeAction()

void Dragengine.BehaviorTreeSystem.BTContext.removeAction ( String  name)

Remove action.

◆ removeAllActions()

void Dragengine.BehaviorTreeSystem.BTContext.removeAllActions ( )

Remove all actions.

◆ removeAllConditions()

void Dragengine.BehaviorTreeSystem.BTContext.removeAllConditions ( )

Remove all conditions.

◆ removeCondition()

void Dragengine.BehaviorTreeSystem.BTContext.removeCondition ( String  name)

Remove condition.

◆ reset()

void Dragengine.BehaviorTreeSystem.BTContext.reset ( )

Reset to initial state.

Sets the behavior tree root rule as current rule.

◆ setAction() [1/2]

void Dragengine.BehaviorTreeSystem.BTContext.setAction ( String  name,
Block  action 
)

Set action for name using block.

◆ setAction() [2/2]

void Dragengine.BehaviorTreeSystem.BTContext.setAction ( String  name,
BTAction  action 
)

Set action for name.

◆ setActionFirstRun()

void Dragengine.BehaviorTreeSystem.BTContext.setActionFirstRun ( bool  firstRun)

Set action runs for the first time after the current rule changed.

To be called only by BTRuleAction.run().

◆ setBehaviorTree()

void Dragengine.BehaviorTreeSystem.BTContext.setBehaviorTree ( BehaviorTree  behaviorTree)

Set behavior tree and reset state.

Version
1.19

Sets the behavior tree then calls reset(). If you change the behavior tree during runtime you have to make sure it is also set before readFromFile() is called otherwise an exception can be thrown.

◆ setCondition() [1/2]

void Dragengine.BehaviorTreeSystem.BTContext.setCondition ( String  name,
Block  condition 
)

Set condition for name using block.

◆ setCondition() [2/2]

void Dragengine.BehaviorTreeSystem.BTContext.setCondition ( String  name,
BTCondition  condition 
)

Set condition for name.

◆ setConsole()

void Dragengine.BehaviorTreeSystem.BTContext.setConsole ( Console  console)

Set console or null if not wishing to log anything.

◆ setCurrentRule()

void Dragengine.BehaviorTreeSystem.BTContext.setCurrentRule ( BTRule  rule)

Set current rule.

Sets action first run to true and calls onCurrentRuleChanged().

◆ setCurrentRuleByID()

void Dragengine.BehaviorTreeSystem.BTContext.setCurrentRuleByID ( String  id)

Set current rule by identifier.

Sets action first run to true and calls onCurrentRuleChanged().

Exceptions
EInvalidParamRule with identifier not found.

◆ setLoggingName()

void Dragengine.BehaviorTreeSystem.BTContext.setLoggingName ( String  name)

Set logging name to tell apart logs.

◆ setLogRuleChanges()

void Dragengine.BehaviorTreeSystem.BTContext.setLogRuleChanges ( bool  logRuleChanges)

Set log behavior tree rule changes.

◆ setLogSteps()

void Dragengine.BehaviorTreeSystem.BTContext.setLogSteps ( bool  logSteps)

Set log behavior tree steps.

◆ setRunAwayLimit()

void Dragengine.BehaviorTreeSystem.BTContext.setRunAwayLimit ( int  limit)

Set run away limit.

◆ stepBehaviorTree()

bool Dragengine.BehaviorTreeSystem.BTContext.stepBehaviorTree ( )

Step behavior tree.

Multiple actions can run before this method returns.

Exceptions
BTRunAwayExceptionRun-away condition detected.
Returns
true if tree continues running or false if root rule returned BTResult.failure .

◆ writeToFile()

void Dragengine.BehaviorTreeSystem.BTContext.writeToFile ( PersistencyEnvironment  env,
FileWriter  writer 
)

Write state to file.

Member Data Documentation

◆ pActionFirstRun

bool Dragengine.BehaviorTreeSystem.BTContext.pActionFirstRun

◆ pActions

Dictionary Dragengine.BehaviorTreeSystem.BTContext.pActions

◆ pBehaviorTree

BehaviorTree Dragengine.BehaviorTreeSystem.BTContext.pBehaviorTree

◆ pConditions

Dictionary Dragengine.BehaviorTreeSystem.BTContext.pConditions

◆ pConsole

Console Dragengine.BehaviorTreeSystem.BTContext.pConsole

◆ pCurrentRule

BTRule Dragengine.BehaviorTreeSystem.BTContext.pCurrentRule

◆ pLastResult

BTResult Dragengine.BehaviorTreeSystem.BTContext.pLastResult

◆ pLoggingName

String Dragengine.BehaviorTreeSystem.BTContext.pLoggingName

◆ pLogRuleChanges

bool Dragengine.BehaviorTreeSystem.BTContext.pLogRuleChanges

◆ pLogSteps

bool Dragengine.BehaviorTreeSystem.BTContext.pLogSteps

◆ pRunAwayList

Array Dragengine.BehaviorTreeSystem.BTContext.pRunAwayList

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