Drag[en]gine Script Module DragonScript
1.23
|
Behavior element behavior adding BehaviorTree support. More...
Classes | |
interface | ActionConditionFactory |
Factory assigining actions and conditions to behavior tree. More... | |
class | BlockActionConditionFactory |
Factory assigining actions and conditions to behavior tree using a block. More... | |
class | BlockListenerFactory |
Factory creating listeners using block. More... | |
class | DefaultListener |
Default implementation of behavior instance listener. More... | |
class | Instance |
Behavior instance. More... | |
interface | Listener |
Listener for behavior instance events. More... | |
interface | ListenerFactory |
Factory creating listeners. More... | |
Public Member Functions | |
void | addActionConditionFactory (ActionConditionFactory factory) |
Add action and condition factory. More... | |
void | addActionConditionFactory (Block factory) |
Add action and condition factory using block receiving Instance as parameter. More... | |
void | addListenerFactory (Block blockFactory) |
Add listener factory using block. More... | |
void | createListeners (Instance instance) |
Create listeners from factories adding them to behavior instance. More... | |
void | dispose () |
Dispose of behavior. More... | |
void | forEachActionConditionFactory (Block ablock) |
Visit listener factories with block with argument ActionConditionFactory. More... | |
void | forEachListenerFactory (Block ablock) |
Visit listener factories with block with argument ListenerFactory. More... | |
ECPBehaviorTree | getBehaviorTree () |
Behavior tree. More... | |
ECPBoolean | getRun () |
Run behavior tree during element thinking. More... | |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass) |
Create behavior element class. More... | |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass, Loaders loaders) |
Create behavior element class. More... | |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass, Loaders loaders, String id) |
Create behavior element class. More... | |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass, Loaders loaders, String id, String subID) |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass, Loaders loaders, String id, String subID, String prefix) |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass, String id) |
Create behavior element class. More... | |
ECBehaviorBehaviorTree | new (BehaviorElementClass eclass, String id, String prefix) |
Create behavior element class. More... | |
void | setActionsConditions (Instance instance) |
Assign actions and conditions to behavior instance. More... | |
Public Member Functions inherited from Dragengine.Scenery.DefaultECBehavior | |
void | assignInstanceIndex (int instanceIndex) |
Assign instance index. More... | |
String | getBehaviorID () |
Unique identifier of behavior. More... | |
String | getID () |
Identifier. More... | |
int | getInstanceIndex () |
Instance index. More... | |
void | loadSupportedData (String identifier, PersistencyEnvironment env, FileReader reader, ECBehaviorInstance instance) |
Load instance data of another behavior. More... | |
bool | supportsBehaviorID (String identifier) |
Behavior supports loading instance data of another behavior. More... | |
Public Member Functions inherited from Dragengine.Scenery.ECBehavior | |
ECBehaviorInstance | createInstance (BehaviorElement element) |
Create Behavior instance. More... | |
Static Public Member Functions | |
static ECBehaviorBehaviorTree | getBehaviorIn (BehaviorElementClass eclass) |
Get behavior in element class or null if absent. More... | |
Public Attributes | |
Array | pActionConditionFactories |
ECPBehaviorTree | pBehaviorTree |
Array | pListenerFactories |
ECPBoolean | pRun |
Additional Inherited Members | |
Protected Member Functions inherited from Dragengine.Scenery.DefaultECBehavior | |
void | setBehaviorID (String identifier) |
Set behavior identifier. More... | |
void | useClassNameAsBehaviorID () |
Set behavior identifier to "<class-name>:<identifier>". More... | |
void | useFullyQualifiedClassNameAsBehaviorID () |
Set behavior identifier to "<fully-qualified-class-name>:<identifier>". More... | |
Behavior element behavior adding BehaviorTree support.
Loads a single behavior tree from file and creates a BTContext. Other behaviors can add actions and conditions to this behavior tree allowing to compose behavior tree actions and conditions easily.
This behavior can be used in different ways depending on the needs.
This is the most simple solution where only one behavior tree is used. For many AI situations this is enough and is the most simple solution to use. Add one ECBehaviorBehaviorTree with no ID to the element and as many other behaviors adding actions and conditions as required. Set the "behaviorTree.path" property to define the behavior tree to load. If you want to use this behavior for simple elements you can set the "behaviorTree.run" to "true". In this case the behavior will run the behavior tree on "think()" calls. For BaseActor use it is better to keep this feature disabled and using a BaseActorAI supporting this behavior. This is an example code for such a setup:
You can add multiple instances of ECBehaviorBehaviorTree to the element to load and use multiple behavior trees. This can be either because you want to switch between behavior trees or using multiple trees together to model complex AI logic. In this situation behaviors adding actions and conditions do add them to all instances of ECBehaviorBehaviorTree. This is usually not a problem since the behavior trees are written to use only the actions and conditions making sense to be used. You can set any ECBehaviorBehaviorTree to run during "think()". If enabling more than one behavior like this make sure the individual behavior trees properly work together. This is an example code for such a setup:
The above example loads and runs two behavior trees. The first one is running specific behavior tree with AI behavior like searching for the player or communicating with other actors. The second behavior tree provides idle actions used if the specific behavior tree is doing nothing. By choosing conditions properly the two trees do not interfere with each other and allow to split up behavior trees into multiple trees which can help create complex AI more simple and stable.
This use case allows to use this behavior for BaseActor usage. BaseActor supports using BaseActorAI which can be exchanged to allow multiple different AI routines to be used without needing one large behavior tree. In this situation the behavior tree is not run by this behavior but by a BaseActorAI subclass. Both of the above scenarios are possible either using one behavior tree or multiple. Typically BaseActorAI does not use the BTContext from this behavior directly but instead create a copy. This has the advantage that each time a BaseActorAI is switched on it starts with a fresh context initialized with all actions and conditions added by other behaviors. Furthermore you can change the BehaviorTree to use during copy time opening up all kinds of possibilities to create actor AI easily. This is an example code for such a setup:
You can assign actions and conditions without using other behaviors by using one or more factories. The factories are added to the behavior. Upon creating the behavior instances the factories are asked to create and assign BTAction and BTCondition. The example below shows how to use a factory to add a condition checking for a trigger and an action manipulating a trigger.
This behavior does require the element class to be persistable (setPersistable) only if the context is run by the behavior itself.
void Dragengine.Scenery.ECBehaviorBehaviorTree.addActionConditionFactory | ( | ActionConditionFactory | factory | ) |
Add action and condition factory.
void Dragengine.Scenery.ECBehaviorBehaviorTree.addActionConditionFactory | ( | Block | factory | ) |
Add action and condition factory using block receiving Instance as parameter.
This is a convenience method for using BlockActionConditionFactory.
void Dragengine.Scenery.ECBehaviorBehaviorTree.addListenerFactory | ( | Block | blockFactory | ) |
void Dragengine.Scenery.ECBehaviorBehaviorTree.createListeners | ( | Instance | instance | ) |
Create listeners from factories adding them to behavior instance.
void Dragengine.Scenery.ECBehaviorBehaviorTree.dispose | ( | ) |
Dispose of behavior.
Reimplemented from Dragengine.Scenery.DefaultECBehavior.
void Dragengine.Scenery.ECBehaviorBehaviorTree.forEachActionConditionFactory | ( | Block | ablock | ) |
Visit listener factories with block with argument ActionConditionFactory.
void Dragengine.Scenery.ECBehaviorBehaviorTree.forEachListenerFactory | ( | Block | ablock | ) |
Visit listener factories with block with argument ListenerFactory.
|
static |
Get behavior in element class or null if absent.
Use this method to check if a particular BehaviorElementClass contains a behavior of type ECBehaviorCollider.
ECPBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.getBehaviorTree | ( | ) |
Behavior tree.
ECPBoolean Dragengine.Scenery.ECBehaviorBehaviorTree.getRun | ( | ) |
Run behavior tree during element thinking.
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass | ) |
Create behavior element class.
Reimplemented from Dragengine.Scenery.DefaultECBehavior.
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass, |
Loaders | loaders | ||
) |
Create behavior element class.
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass, |
Loaders | loaders, | ||
String | id | ||
) |
Create behavior element class.
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass, |
Loaders | loaders, | ||
String | id, | ||
String | subID | ||
) |
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass, |
Loaders | loaders, | ||
String | id, | ||
String | subID, | ||
String | prefix | ||
) |
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass, |
String | id | ||
) |
Create behavior element class.
Reimplemented from Dragengine.Scenery.DefaultECBehavior.
ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.new | ( | BehaviorElementClass | eclass, |
String | id, | ||
String | prefix | ||
) |
Create behavior element class.
void Dragengine.Scenery.ECBehaviorBehaviorTree.setActionsConditions | ( | Instance | instance | ) |
Assign actions and conditions to behavior instance.
Array Dragengine.Scenery.ECBehaviorBehaviorTree.pActionConditionFactories |
ECPBehaviorTree Dragengine.Scenery.ECBehaviorBehaviorTree.pBehaviorTree |
Array Dragengine.Scenery.ECBehaviorBehaviorTree.pListenerFactories |
ECPBoolean Dragengine.Scenery.ECBehaviorBehaviorTree.pRun |