|
Drag[en]gine Script Module DragonScript 1.32.1
|
Actor AI using BehaviorTree. More...
Classes | |
| class | BTActionAI |
| Behavior tree action with link to BAAIBehaviorTree. More... | |
| class | BTContextAI |
| Behavior tree context with link to BAAIBehaviorTree. More... | |
| class | Factory |
| Factory for loading actor ai. More... | |
Public Member Functions | |
| void | activate (BehaviorElement actor) |
| AI has been set as active AI in an actor. | |
| void | activateWhileLoading (BehaviorElement actor) |
| AI has been set as active AI in an actor while loading. | |
| void | dispose () |
| Dispose of actor ai. | |
| ECBehaviorBehaviorTree.Instance | getBehaviorBehaviorTree () |
| Behavior behavior tree to use context of and to send notifications to. | |
| BehaviorTree | getBehaviorTree () |
| Behavior tree to use or null. | |
| BTContextAI | getContext () |
| Custom behavior tree context or null if not set. | |
| bool | getPauseInConversation () |
| Pause behavior tree while actor is in a conversation. | |
| bool | getRunning () |
| Behavior tree is running. | |
| BTContext | getUseContext () |
| Behavior tree context to use or null if not set. | |
| BAAIBehaviorTree | new () |
| Create actor ai. | |
| BAAIBehaviorTree | new (BehaviorTree tree) |
| Create actor ai using behavior tree. | |
| BAAIBehaviorTree | new (PersistencyEnvironment env, FileReader reader) |
| Create actor ai restoring from file reader. | |
| void | onBehaviorTreeFailed (Exception e) |
| Running the behavior tree failed. | |
| String | persistencyFactoryName () |
| Name of PersistencyFactory required to load object from file. | |
| void | resetContext () |
| Reset context to run it again. | |
| void | setBehaviorBehaviorTree (ECBehaviorBehaviorTree.Instance behavior) |
| Set behavior behavior tree to use context of and to send notifications to. | |
| void | setBehaviorTree (BehaviorTree tree) |
| Set behavior tree to use or null. | |
| void | setContext (BTContextAI context) |
| Set custom behavior tree context or null if not set. | |
| void | setPauseInConversation (bool pauseInConversation) |
| Set to pause behavior tree while actor is in a conversation. | |
| void | setRunning (bool running) |
| Set if behavior tree is running. | |
| void | think (float elapsed) |
| Thinking. | |
| void | writeObjectToFile (PersistencyEnvironment env, FileWriter writer) |
| Write object to file writer. | |
Public Member Functions inherited from Dragengine.Scenery.BaseActorAI | |
| void | actionFailed () |
| Action failed. | |
| void | actionFinished () |
| Action finished successfully. | |
| void | collision (Collider owner, CollisionInfo info) |
| Collision detected. | |
| void | deactivate () |
| Action has been unset as active action in an actor. | |
| void | enterConversation () |
| Actor has been added to a conversation playback. | |
| void | enteredGameWorld () |
| Actor entered game world. | |
| void | enterFrame () |
| Actor has been added to game world and enterFrame() is called once. | |
| BehaviorElement | getActor () |
| Actor owning the action or null. | |
| ECBehaviorActorAIAction.Instance | getAIAction () |
| Behavior actor ai-action or null. | |
| ECBehaviorPlayerControllable.Instance | getPlayerControllable () |
| Behavior player controllable or null. | |
| bool | isActive () |
| AI is active actor AI. | |
| bool | isControlledByPlayer () |
| Actor is controlled by player. | |
| bool | isNotActive () |
| AI is not active actor AI. | |
| void | leaveConversation () |
| Actor has been removed from a conversation playback. | |
| void | leftGameWorld () |
| Actor left game world. | |
| void | log (Console console, Element element, String text) |
| Log text about element to console prefixed with actor information. | |
| void | log (Console console, Exception exception) |
| Log exception to console prefixed with actor information. | |
| void | log (Console console, String text) |
| Log text to console prefixed with actor information. | |
| void | log (Element element, String text) |
| Log text about element to BaseGameApp console prefixed with actor information. | |
| void | log (Exception exception) |
| Log exception to BaseGameApp console prefixed with actor information. | |
| void | log (String text) |
| Log text to BaseGameApp console prefixed with actor information. | |
| String | loggingPrefix () |
| Logging prefix. | |
| void | playerReleasesControl () |
| Player released control of actor. | |
| void | playerTakesControl () |
| Player takes control of actor. | |
Public Attributes | |
| ECBehaviorBehaviorTree.Instance | pBehaviorBehaviorTree |
| BehaviorTree | pBehaviorTree |
| BTContextAI | pContext |
| bool | pLoadActionFirstRun |
| String | pLoadRuleId |
| bool | pRunning |
Protected Member Functions | |
| void | initBehaviors () |
| Init behaviors. | |
Protected Attributes | |
| ECBehaviorConversationActor.Instance | conversationActor |
Protected Attributes inherited from Dragengine.Scenery.BaseActorAI | |
| BehaviorElement | actor |
| Actor the action is assigned to or null. | |
| ECBehaviorActorAIAction.Instance | aiAction |
| Behavior actor ai-action or null. | |
| ECBehaviorPlayerControllable.Instance | playerControllable |
| Behavior player controllable or null. | |
Actor AI using BehaviorTree.
Uses BehaviorTree using BTContext to do AI. For each call to #think() the behavior tree is stepped. In case of an exception in the behavior tree the exception is logged and the running of the behavior tree cancelled.
There are two ways to use this AI. The first way is to add a ECBehaviorBehaviorTree::Instance behavior to the actor element class and assign it to the AI. This will use the context of the behavior tree behavior. Behavior tree actions and conditions are then easily added by adding other behaviors providing such actions and conditions.
The second way to use this AI requires setting a custom BTContextAI subclass. In this case you have to add all the required actions and conditions to this context. This is typically done during construction time or activation time. The advantage here is that you can create a custom context without sharing (and modifying) the one of ECBehaviorBehaviorTree::Instance. If both ECBehaviorBehaviorTree::Instance and a custom contex is set the custom context is used.
Which way to use depends on the needs. In general though the first version using ECBehaviorBehaviorTree::Instance is recommended.
To support behaviors receiving notifications about the state of the context set also the ECBehaviorBehaviorTree::Instance used to initialize the context.
| void Dragengine.Scenery.BAAIBehaviorTree.activate | ( | BehaviorElement | actor | ) |
AI has been set as active AI in an actor.
Calls these hook methods:
Reimplemented from Dragengine.Scenery.BaseActorAI.
| void Dragengine.Scenery.BAAIBehaviorTree.activateWhileLoading | ( | BehaviorElement | actor | ) |
AI has been set as active AI in an actor while loading.
Similar to activate(BehaviorElement) but only stores the actor and calls initBehaviors(). This is required since while loading behaviors load their state and AIs load their states. If activate(BehaviorElement) is called these states would be reset to initial values.
Reimplemented from Dragengine.Scenery.BaseActorAI.
| void Dragengine.Scenery.BAAIBehaviorTree.dispose | ( | ) |
Dispose of actor ai.
Reimplemented from Dragengine.Scenery.BaseActorAI.
| ECBehaviorBehaviorTree.Instance Dragengine.Scenery.BAAIBehaviorTree.getBehaviorBehaviorTree | ( | ) |
Behavior behavior tree to use context of and to send notifications to.
| BehaviorTree Dragengine.Scenery.BAAIBehaviorTree.getBehaviorTree | ( | ) |
Behavior tree to use or null.
| BTContextAI Dragengine.Scenery.BAAIBehaviorTree.getContext | ( | ) |
Custom behavior tree context or null if not set.
| bool Dragengine.Scenery.BAAIBehaviorTree.getPauseInConversation | ( | ) |
Pause behavior tree while actor is in a conversation.
| bool Dragengine.Scenery.BAAIBehaviorTree.getRunning | ( | ) |
Behavior tree is running.
| BTContext Dragengine.Scenery.BAAIBehaviorTree.getUseContext | ( | ) |
Behavior tree context to use or null if not set.
If custom context is set returns the value of #getContext(). If ECBehaviorBehaviorTree::Instance is set returns ECBehaviorBehaviorTree.Instance::getContext(). Otherwise returns null.
|
protected |
Init behaviors.
Retrieve and store required and optional behavior instances from the actor element.
Reimplemented from Dragengine.Scenery.BaseActorAI.
| BAAIBehaviorTree Dragengine.Scenery.BAAIBehaviorTree.new | ( | ) |
Create actor ai.
Reimplemented from Dragengine.Scenery.BaseActorAI.
| BAAIBehaviorTree Dragengine.Scenery.BAAIBehaviorTree.new | ( | BehaviorTree | tree | ) |
Create actor ai using behavior tree.
| BAAIBehaviorTree Dragengine.Scenery.BAAIBehaviorTree.new | ( | PersistencyEnvironment | env, |
| FileReader | reader | ||
| ) |
Create actor ai restoring from file reader.
| void Dragengine.Scenery.BAAIBehaviorTree.onBehaviorTreeFailed | ( | Exception | e | ) |
Running the behavior tree failed.
Default implementation logs exception using log(Exception).
| exception | Exception if thrown or null otherwise. |
| String Dragengine.Scenery.BAAIBehaviorTree.persistencyFactoryName | ( | ) |
Name of PersistencyFactory required to load object from file.
Name of PersistencyFactory is first written to the file as string with 8-bit length. Then writeToFile() is called to write the object itself. Empty name is not allowed as is names longer than 255 characters. Name has to match a PersistencyFactory present in the Persistency instance used for loading objects. Object is read using PersistencyFactory.readObjectFromFile() of the matching PersistencyFactory.
Reimplemented from Dragengine.Scenery.BaseActorAI.
| void Dragengine.Scenery.BAAIBehaviorTree.resetContext | ( | ) |
Reset context to run it again.
| void Dragengine.Scenery.BAAIBehaviorTree.setBehaviorBehaviorTree | ( | ECBehaviorBehaviorTree.Instance | behavior | ) |
Set behavior behavior tree to use context of and to send notifications to.
| void Dragengine.Scenery.BAAIBehaviorTree.setBehaviorTree | ( | BehaviorTree | tree | ) |
Set behavior tree to use or null.
Change affects context only before #activate() has been called.
| void Dragengine.Scenery.BAAIBehaviorTree.setContext | ( | BTContextAI | context | ) |
Set custom behavior tree context or null if not set.
If context is not null resetContext() is also called.
| void Dragengine.Scenery.BAAIBehaviorTree.setPauseInConversation | ( | bool | pauseInConversation | ) |
Set to pause behavior tree while actor is in a conversation.
| void Dragengine.Scenery.BAAIBehaviorTree.setRunning | ( | bool | running | ) |
Set if behavior tree is running.
| void Dragengine.Scenery.BAAIBehaviorTree.think | ( | float | elapsed | ) |
Thinking.
Behavior tree is process if:
If running the behavior tree throws an exception or returns false running is set to false and onBehaviorTreeFailed() is called. To run the context again call resetContext().
Reimplemented from Dragengine.Scenery.BaseActorAI.
| void Dragengine.Scenery.BAAIBehaviorTree.writeObjectToFile | ( | PersistencyEnvironment | env, |
| FileWriter | writer | ||
| ) |
Write object to file writer.
Reimplemented from Dragengine.Scenery.BaseActorAI.
|
protected |
| ECBehaviorBehaviorTree.Instance Dragengine.Scenery.BAAIBehaviorTree.pBehaviorBehaviorTree |
| BehaviorTree Dragengine.Scenery.BAAIBehaviorTree.pBehaviorTree |
| BTContextAI Dragengine.Scenery.BAAIBehaviorTree.pContext |
| bool Dragengine.Scenery.BAAIBehaviorTree.pLoadActionFirstRun |
| String Dragengine.Scenery.BAAIBehaviorTree.pLoadRuleId |
| bool Dragengine.Scenery.BAAIBehaviorTree.pRunning |