Drag[en]gine Script Module DragonScript 1.32.1
Loading...
Searching...
No Matches
Dragengine.Scenery.BAAIBehaviorTree Class Reference

Actor AI using BehaviorTree. More...

Inheritance diagram for Dragengine.Scenery.BAAIBehaviorTree:
Dragengine.Scenery.BaseActorAI

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.
 

Detailed Description

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.

Member Function Documentation

◆ activate()

void Dragengine.Scenery.BAAIBehaviorTree.activate ( BehaviorElement  actor)

AI has been set as active AI in an actor.

Calls these hook methods:

  • initBehaviors()

Reimplemented from Dragengine.Scenery.BaseActorAI.

◆ activateWhileLoading()

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.

◆ dispose()

void Dragengine.Scenery.BAAIBehaviorTree.dispose ( )

Dispose of actor ai.

Reimplemented from Dragengine.Scenery.BaseActorAI.

◆ getBehaviorBehaviorTree()

ECBehaviorBehaviorTree.Instance Dragengine.Scenery.BAAIBehaviorTree.getBehaviorBehaviorTree ( )

Behavior behavior tree to use context of and to send notifications to.

Version
1.19

◆ getBehaviorTree()

BehaviorTree Dragengine.Scenery.BAAIBehaviorTree.getBehaviorTree ( )

Behavior tree to use or null.

Version
1.26

◆ getContext()

BTContextAI Dragengine.Scenery.BAAIBehaviorTree.getContext ( )

Custom behavior tree context or null if not set.

◆ getPauseInConversation()

bool Dragengine.Scenery.BAAIBehaviorTree.getPauseInConversation ( )

Pause behavior tree while actor is in a conversation.

Version
1.19

◆ getRunning()

bool Dragengine.Scenery.BAAIBehaviorTree.getRunning ( )

Behavior tree is running.

◆ getUseContext()

BTContext Dragengine.Scenery.BAAIBehaviorTree.getUseContext ( )

Behavior tree context to use or null if not set.

Version
1.26

If custom context is set returns the value of #getContext(). If ECBehaviorBehaviorTree::Instance is set returns ECBehaviorBehaviorTree.Instance::getContext(). Otherwise returns null.

◆ initBehaviors()

void Dragengine.Scenery.BAAIBehaviorTree.initBehaviors ( )
protected

Init behaviors.

Retrieve and store required and optional behavior instances from the actor element.

Reimplemented from Dragengine.Scenery.BaseActorAI.

◆ new() [1/3]

BAAIBehaviorTree Dragengine.Scenery.BAAIBehaviorTree.new ( )

Create actor ai.

Reimplemented from Dragengine.Scenery.BaseActorAI.

◆ new() [2/3]

BAAIBehaviorTree Dragengine.Scenery.BAAIBehaviorTree.new ( BehaviorTree  tree)

Create actor ai using behavior tree.

◆ new() [3/3]

BAAIBehaviorTree Dragengine.Scenery.BAAIBehaviorTree.new ( PersistencyEnvironment  env,
FileReader  reader 
)

Create actor ai restoring from file reader.

◆ onBehaviorTreeFailed()

void Dragengine.Scenery.BAAIBehaviorTree.onBehaviorTreeFailed ( Exception  e)

Running the behavior tree failed.

Default implementation logs exception using log(Exception).

Parameters
exceptionException if thrown or null otherwise.

◆ persistencyFactoryName()

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.

◆ resetContext()

void Dragengine.Scenery.BAAIBehaviorTree.resetContext ( )

Reset context to run it again.

Version
1.19

◆ setBehaviorBehaviorTree()

void Dragengine.Scenery.BAAIBehaviorTree.setBehaviorBehaviorTree ( ECBehaviorBehaviorTree.Instance  behavior)

Set behavior behavior tree to use context of and to send notifications to.

Version
1.19

◆ setBehaviorTree()

void Dragengine.Scenery.BAAIBehaviorTree.setBehaviorTree ( BehaviorTree  tree)

Set behavior tree to use or null.

Version
1.26

Change affects context only before #activate() has been called.

◆ setContext()

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.

◆ setPauseInConversation()

void Dragengine.Scenery.BAAIBehaviorTree.setPauseInConversation ( bool  pauseInConversation)

Set to pause behavior tree while actor is in a conversation.

Version
1.19

◆ setRunning()

void Dragengine.Scenery.BAAIBehaviorTree.setRunning ( bool  running)

Set if behavior tree is running.

◆ think()

void Dragengine.Scenery.BAAIBehaviorTree.think ( float  elapsed)

Thinking.

Behavior tree is process if:

  • Context is not null
  • Running is true
  • Actor is not controlled by player

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.

◆ writeObjectToFile()

void Dragengine.Scenery.BAAIBehaviorTree.writeObjectToFile ( PersistencyEnvironment  env,
FileWriter  writer 
)

Write object to file writer.

Reimplemented from Dragengine.Scenery.BaseActorAI.

Member Data Documentation

◆ conversationActor

ECBehaviorConversationActor.Instance Dragengine.Scenery.BAAIBehaviorTree.conversationActor
protected

◆ pBehaviorBehaviorTree

ECBehaviorBehaviorTree.Instance Dragengine.Scenery.BAAIBehaviorTree.pBehaviorBehaviorTree

◆ pBehaviorTree

BehaviorTree Dragengine.Scenery.BAAIBehaviorTree.pBehaviorTree

◆ pContext

BTContextAI Dragengine.Scenery.BAAIBehaviorTree.pContext

◆ pLoadActionFirstRun

bool Dragengine.Scenery.BAAIBehaviorTree.pLoadActionFirstRun

◆ pLoadRuleId

String Dragengine.Scenery.BAAIBehaviorTree.pLoadRuleId

◆ pRunning

bool Dragengine.Scenery.BAAIBehaviorTree.pRunning

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