|
Drag[en]gine Script Module DragonScript 1.35
|
Behavior tree context. More...
Classes | |
| class | StateBackup |
| Behavior tree state backup. More... | |
Public Member Functions | |
| StateBackup | createBackupState () |
| Back up state. | |
| String | debugGetCurrentRule () |
| Get string path describing current rule for debug purpose. | |
| String | debugGetRulePath (BTRule rule) |
| Get string path describing rule for debug purpose. | |
| void | forEachAction (Block ablock) |
| Visit actions using block with parameters String (name and BTAction (action). | |
| void | forEachCondition (Block ablock) |
| Visit conditions using block with parameters String (name and BTCondition (condition). | |
| BTAction | getAction (String name) |
| Action for name or null if absent. | |
| int | getActionCount () |
| Number of actions. | |
| bool | getActionFirstRun () |
| Action runs for the first time after the current rule changed. | |
| BehaviorTree | getBehaviorTree () |
| Behavior tree. | |
| BTCondition | getCondition (String name) |
| Condition for name or null if absent. | |
| int | getConditionCount () |
| Number of conditions. | |
| Console | getConsole () |
| Console or null if not wishing to log anything. | |
| BTRule | getCurrentRule () |
| Current rule. | |
| BTResult | getLastResult () |
| Last result. | |
| String | getLoggingName () |
| Logging name to tell apart logs. | |
| bool | getLogRuleChanges () |
| Log behavior tree rule changes. | |
| bool | getLogSteps () |
| Log behavior tree steps. | |
| int | getRunAwayLimit () |
| Run away limit. | |
| bool | hasAction (String name) |
| Action is present. | |
| bool | hasCondition (String name) |
| Condition is present. | |
| BTContext | new (BehaviorTree behaviorTree) |
| Create behavior tree context. | |
| BTContext | new (BTContext context) |
| Create copy of behavior tree context. | |
| BTContext | new (BTContext context, BehaviorTree behaviorTree) |
| Create copy of behavior tree context but using a different behavior tree. | |
| void | readFromFile (PersistencyEnvironment env, FileReader reader) |
| Read state from file. | |
| void | removeAction (String name) |
| Remove action. | |
| void | removeAllActions () |
| Remove all actions. | |
| void | removeAllConditions () |
| Remove all conditions. | |
| void | removeCondition (String name) |
| Remove condition. | |
| void | reset () |
| Reset to initial state. | |
| void | restoreBackupState (StateBackup state) |
| Restore state from backup. | |
| void | setAction (String name, Block action) |
| Set action for name using block. | |
| void | setAction (String name, BTAction action) |
| Set action for name. | |
| void | setActionFirstRun (bool firstRun) |
| Set action runs for the first time after the current rule changed. | |
| void | setBehaviorTree (BehaviorTree behaviorTree) |
| Set behavior tree and reset state. | |
| void | setCondition (String name, Block condition) |
| Set condition for name using block. | |
| void | setCondition (String name, BTCondition condition) |
| Set condition for name. | |
| void | setConsole (Console console) |
| Set console or null if not wishing to log anything. | |
| void | setCurrentRule (BTRule rule) |
| Set current rule. | |
| void | setCurrentRuleByID (String id) |
| Set current rule by identifier. | |
| void | setLoggingName (String name) |
| Set logging name to tell apart logs. | |
| void | setLogRuleChanges (bool logRuleChanges) |
| Set log behavior tree rule changes. | |
| void | setLogSteps (bool logSteps) |
| Set log behavior tree steps. | |
| void | setRunAwayLimit (int limit) |
| Set run away limit. | |
| bool | stepBehaviorTree () |
| Step behavior tree. | |
| void | writeToFile (PersistencyEnvironment env, FileWriter writer) |
| Write state to file. | |
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. | |
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.
| StateBackup Dragengine.BehaviorTreeSystem.BTContext.createBackupState | ( | ) |
Back up state.
Allows to properly restore the behavior tree to this state. Restores current rule and action first run flag.
You can also call
directly.
References pActions, and setAction().
Referenced by writeToFile().
| String Dragengine.BehaviorTreeSystem.BTContext.debugGetCurrentRule | ( | ) |
Get string path describing current rule for debug purpose.
References onCurrentRuleChanged(), pConsole, pLoggingName, and pLogRuleChanges.
Referenced by writeToFile().
| String Dragengine.BehaviorTreeSystem.BTContext.debugGetRulePath | ( | BTRule | rule | ) |
| void Dragengine.BehaviorTreeSystem.BTContext.forEachAction | ( | Block | ablock | ) |
Visit actions using block with parameters String (name and BTAction (action).
References pConsole, pLoggingName, and pLogSteps.
Referenced by setLogRuleChanges().
| void Dragengine.BehaviorTreeSystem.BTContext.forEachCondition | ( | Block | ablock | ) |
Visit conditions using block with parameters String (name and BTCondition (condition).
Referenced by getActionFirstRun().
| BTAction Dragengine.BehaviorTreeSystem.BTContext.getAction | ( | String | name | ) |
Action for name or null if absent.
References pActions, pConditions, and pCurrentRule.
Referenced by getLogRuleChanges().
| int Dragengine.BehaviorTreeSystem.BTContext.getActionCount | ( | ) |
| 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. BTAction can use this flag to know if they run for the first time after a rule change. This can be used to set up tasks the first time an action runs and check back later on the state.
References forEachCondition(), and pConditions.
Referenced by writeToFile().
| BehaviorTree Dragengine.BehaviorTreeSystem.BTContext.getBehaviorTree | ( | ) |
| BTCondition Dragengine.BehaviorTreeSystem.BTContext.getCondition | ( | String | name | ) |
Condition for name or null if absent.
Referenced by setCurrentRuleByID().
| int Dragengine.BehaviorTreeSystem.BTContext.getConditionCount | ( | ) |
Number of conditions.
References pLogRuleChanges, and pLogSteps.
Referenced by setCurrentRuleByID().
| Console Dragengine.BehaviorTreeSystem.BTContext.getConsole | ( | ) |
Console or null if not wishing to log anything.
Referenced by writeToFile().
| BTRule Dragengine.BehaviorTreeSystem.BTContext.getCurrentRule | ( | ) |
| BTResult Dragengine.BehaviorTreeSystem.BTContext.getLastResult | ( | ) |
| String Dragengine.BehaviorTreeSystem.BTContext.getLoggingName | ( | ) |
| bool Dragengine.BehaviorTreeSystem.BTContext.getLogRuleChanges | ( | ) |
| bool Dragengine.BehaviorTreeSystem.BTContext.getLogSteps | ( | ) |
Log behavior tree steps.
Referenced by writeToFile().
| int Dragengine.BehaviorTreeSystem.BTContext.getRunAwayLimit | ( | ) |
Run away limit.
Referenced by writeToFile().
| bool Dragengine.BehaviorTreeSystem.BTContext.hasAction | ( | String | name | ) |
| bool Dragengine.BehaviorTreeSystem.BTContext.hasCondition | ( | String | name | ) |
Condition is present.
Referenced by setCurrentRuleByID().
| BTContext Dragengine.BehaviorTreeSystem.BTContext.new | ( | BehaviorTree | behaviorTree | ) |
Create behavior tree context.
References pActionFirstRun.
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.
References pActionFirstRun, pActions, pBehaviorTree, pConditions, pCurrentRule, pLastResult, and pRunAwayList.
| 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.
References pConsole, pLoggingName, pLogRuleChanges, and pLogSteps.
|
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.
References pActionFirstRun, pCurrentRule, and setCurrentRule().
Referenced by debugGetCurrentRule(), and writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.readFromFile | ( | PersistencyEnvironment | env, |
| FileReader | reader ) |
Read state from file.
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.removeAction | ( | String | name | ) |
| void Dragengine.BehaviorTreeSystem.BTContext.removeAllActions | ( | ) |
Remove all actions.
Referenced by stepBehaviorTree().
| void Dragengine.BehaviorTreeSystem.BTContext.removeAllConditions | ( | ) |
Remove all conditions.
Referenced by getLoggingName().
| void Dragengine.BehaviorTreeSystem.BTContext.removeCondition | ( | String | name | ) |
Remove condition.
Referenced by setConsole().
| void Dragengine.BehaviorTreeSystem.BTContext.reset | ( | ) |
Reset to initial state.
Sets the behavior tree root rule as current rule.
References getCurrentRule(), and pCurrentRule.
Referenced by setCurrentRule(), and writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.restoreBackupState | ( | StateBackup | state | ) |
Restore state from backup.
Works only if the state has been created from this context with the same behavior tree.
References pActions, removeAction(), and setAction().
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setAction | ( | String | name, |
| Block | action ) |
Set action for name using block.
| void Dragengine.BehaviorTreeSystem.BTContext.setAction | ( | String | name, |
| BTAction | action ) |
Set action for name.
References pLogRuleChanges.
Referenced by createBackupState(), and restoreBackupState().
| void Dragengine.BehaviorTreeSystem.BTContext.setActionFirstRun | ( | bool | firstRun | ) |
Set action runs for the first time after the current rule changed.
Called by BTRuleAction.run() and BTResultYield. Call this if your rule needs to know if it is run for the first time after setCurrentRule() is called.
References setCondition().
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setBehaviorTree | ( | BehaviorTree | behaviorTree | ) |
Set behavior tree and reset state.
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.
References pActionFirstRun, pActions, pCurrentRule, pLoggingName, and pRunAwayList.
Referenced by getCurrentRule().
| void Dragengine.BehaviorTreeSystem.BTContext.setCondition | ( | String | name, |
| Block | condition ) |
Set condition for name using block.
| void Dragengine.BehaviorTreeSystem.BTContext.setCondition | ( | String | name, |
| BTCondition | condition ) |
Set condition for name.
Referenced by setActionFirstRun(), and setRunAwayLimit().
| void Dragengine.BehaviorTreeSystem.BTContext.setConsole | ( | Console | console | ) |
Set console or null if not wishing to log anything.
References pConditions, and removeCondition().
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setCurrentRule | ( | BTRule | rule | ) |
Set current rule.
Sets action first run to true and calls onCurrentRuleChanged().
References pBehaviorTree, and reset().
Referenced by onCurrentRuleChanged(), and writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setCurrentRuleByID | ( | String | id | ) |
Set current rule by identifier.
Sets action first run to true and calls onCurrentRuleChanged().
| EInvalidParam | Rule with identifier not found. |
References getCondition(), getConditionCount(), hasCondition(), and pConditions.
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setLoggingName | ( | String | name | ) |
| void Dragengine.BehaviorTreeSystem.BTContext.setLogRuleChanges | ( | bool | logRuleChanges | ) |
Set log behavior tree rule changes.
References forEachAction(), hasAction(), and pActions.
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setLogSteps | ( | bool | logSteps | ) |
Set log behavior tree steps.
References getActionCount(), and pActions.
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.setRunAwayLimit | ( | int | limit | ) |
| bool Dragengine.BehaviorTreeSystem.BTContext.stepBehaviorTree | ( | ) |
Step behavior tree.
Multiple actions can run before this method returns.
| BTRunAwayException | Run-away condition detected. |
References pActions, and removeAllActions().
Referenced by writeToFile().
| void Dragengine.BehaviorTreeSystem.BTContext.writeToFile | ( | PersistencyEnvironment | env, |
| FileWriter | writer ) |
Write state to file.
References createBackupState(), debugGetCurrentRule(), debugGetRulePath(), getActionFirstRun(), getConsole(), getLastResult(), getLoggingName(), getLogRuleChanges(), getLogSteps(), getRunAwayLimit(), onCurrentRuleChanged(), pActionFirstRun, pBehaviorTree, pConsole, pCurrentRule, pLastResult, pLoggingName, pLogRuleChanges, pLogSteps, pRunAwayList, readFromFile(), reset(), restoreBackupState(), setActionFirstRun(), setConsole(), setCurrentRule(), setCurrentRuleByID(), setLoggingName(), setLogRuleChanges(), setLogSteps(), setRunAwayLimit(), stepBehaviorTree(), and writeToFile().
Referenced by writeToFile().
| bool Dragengine.BehaviorTreeSystem.BTContext.pActionFirstRun |
Referenced by hasAction(), new(), new(), onCurrentRuleChanged(), setBehaviorTree(), and writeToFile().
| Dictionary Dragengine.BehaviorTreeSystem.BTContext.pActions |
Referenced by createBackupState(), getAction(), new(), restoreBackupState(), setBehaviorTree(), setLogRuleChanges(), setLogSteps(), and stepBehaviorTree().
| BehaviorTree Dragengine.BehaviorTreeSystem.BTContext.pBehaviorTree |
Referenced by getActionCount(), getBehaviorTree(), new(), removeAction(), setCurrentRule(), and writeToFile().
| Dictionary Dragengine.BehaviorTreeSystem.BTContext.pConditions |
Referenced by getAction(), getActionFirstRun(), getBehaviorTree(), getLastResult(), new(), setConsole(), setCurrentRuleByID(), setLoggingName(), and setRunAwayLimit().
| Console Dragengine.BehaviorTreeSystem.BTContext.pConsole |
Referenced by debugGetCurrentRule(), forEachAction(), new(), and writeToFile().
| BTRule Dragengine.BehaviorTreeSystem.BTContext.pCurrentRule |
Referenced by getAction(), new(), onCurrentRuleChanged(), reset(), setBehaviorTree(), and writeToFile().
| BTResult Dragengine.BehaviorTreeSystem.BTContext.pLastResult |
Referenced by new(), and writeToFile().
| String Dragengine.BehaviorTreeSystem.BTContext.pLoggingName |
Referenced by debugGetCurrentRule(), forEachAction(), new(), setBehaviorTree(), and writeToFile().
| bool Dragengine.BehaviorTreeSystem.BTContext.pLogRuleChanges |
Referenced by debugGetCurrentRule(), getConditionCount(), new(), setAction(), and writeToFile().
| bool Dragengine.BehaviorTreeSystem.BTContext.pLogSteps |
Referenced by forEachAction(), getConditionCount(), new(), and writeToFile().
| Array Dragengine.BehaviorTreeSystem.BTContext.pRunAwayList |
Referenced by hasAction(), new(), setBehaviorTree(), and writeToFile().