Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorActorAIAction
Behavior adding AI and Action support to actors.
Allows instance of BaseActorAction and BaseActorAI to be assigned to actor. During thinking first the AI then the Action is called.
Actions allow actors to perform a specific, well defined and enclosed action like interacting with an object. Actions are suitable to be used by player and computer controlled actors alike. This concept allows using the same actions for both player and computer controlled actors reducing coding effort, misbehavior and overall ensures that what a player can do a computer controlled actor can do and vice versa.
AIs allow computer controlled actors to act on their own. With player controlled actors the AI is skipped and the player is the AI. AI provides long running actor actions like guarding a zone with the possiblity to switch between different actions depending on how the actor wants to react to events. This separation makes it simple to design AI in coarse grain placing actual small grained actions into reusable action instances. This separation also allows actors to easily switch between player and computer controlled because both can reuse the same action instances.
This behavior can be used only once on an element.
Element class properties have the prefix aiAction.
.
Since this behavior provides no support to apply the chosen color listening is used. Behaviors knowing how to apply the color add a listener and are notified if the color changes. These events can be received:
This behavior adds these behavior tree actions if behavior tree is present.
Set one or more actor ai/action parameters.
Parameter | Value | Description |
---|---|---|
ai.behaviorTree | string | Set AI using BAAIBehaviorTree with behavior tree loaded from value path. Path can be relative to behavior tree file containing this action |
action.stateMachine | string | Set Action using BAAStateMachine with state machine loaded from value path. Path can be relative to behavior tree or state machine file containing this action |
action.conversationWait | true , false | Set if conversation waits due to active action |
This is an example of using this action:
<action name='aiAction.set'> <parameter name='ai.behaviorTree'>/content/ai/patrol.debt</parameter> <parameter name='action.stateMachine'>/content/action/human.desm</parameter> </action>
Update AI/Action.
Parameter | Value | Description |
---|---|---|
ai.actionFinished | success , failure | If actor is not player controlled calls actionFinished() or actionFailed() on the active AI if present |
This is an example of using this action:
<action name='aiAction.update'> <parameter name='ai.actionFinished'>success</parameter> </action>
Check one or more behavior parameters. Action succeeds if all parameter value matches their respective player input crouch parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a player input crouch parameter matches (or not).
Parameter | Value | Description |
---|---|---|
action.conversationWait | true , false | Conversation waits due to active action |
This is an example of using this action:
<sequence> <action name='aiAction.check'> <parameter name='action.conversationWait'>true</parameter> </action> <!-- actions here run only if conversation wait is enabled --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present.
Check one or more behavior parameters. Conditions returns true if all parameter value match their respective player input crouch parameter. This condition is typically used to run an action or sequence of actions as long as player input crouch conditions are true.
Parameter | Value | Description |
---|---|---|
aiAction.action.conversationWait | true , false | Conversation waits due to active action |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='aiAction.action.conversationWait'>true</parameter> <condition>aiAction.check</condition> </action>
This behavior requires no other behaviors.
This behavior does support element class to be persistable (setPersistable). Saves active action and AI object.
Since DragonScript Module Version 1.0
This example defines an element which action and AI support.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorColliderAI colliderAI public var ECBehaviorConversationActor conversationActor public var ECBehaviorPlayerControllable playerControllable public var ECBehaviorActorAIAction aiAction func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) colliderAI = ECBehaviorColliderAI.new(this, collider) conversationActor = ECBehaviorConversationActor.new(this) playerControllable = ECBehaviorPlayerControllable.new(this) playerControllable.setConversationActor(conversationActor) aiAction = ECBehaviorActorAIAction.new(this, colliderAI, conversationActor, pPlayerControllable) end end
Using element class supporting adding behaviors the behavior can be added like this:
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <behavior type='ECBehaviorComponent'/> <behavior type='ECBehaviorCollider'/> <behavior type='ECBehaviorColliderAI'/> <behavior type='ECBehaviorConversationActor'/> <behavior type='ECBehaviorPlayerControllable'/> <behavior type='ECBehaviorActorAIAction'> <!-- behavior factory automatically assigns all optional behaviors if present --> <!-- optional: use behavior tree with id instead of empty string --> <string name='behaviorTree'>second</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.name'>value</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorActorAIAction' id='second'/> </elementClass>