Behavior Tree addon

This commit is contained in:
Tony Bark 2023-01-21 04:04:13 -05:00
parent 5de5a0c315
commit 5fa863114a
50 changed files with 1762 additions and 3 deletions

View file

@ -0,0 +1,8 @@
extends BeehaveNode
class_name Composite, "../../icons/category_composite.svg"
func _ready():
if self.get_child_count() < 1:
push_error("BehaviorTree Error: Composite %s should have at least one child (NodePath: %s)" % [self.name, self.get_path()])

View file

@ -0,0 +1,18 @@
extends Composite
class_name SelectorComposite, "../../icons/selector.svg"
func tick(actor, blackboard):
for c in get_children():
var response = c.tick(actor, blackboard)
if c is ConditionLeaf:
blackboard.set("last_condition", c)
blackboard.set("last_condition_status", response)
if response != FAILURE:
if c is ActionLeaf and response == RUNNING:
blackboard.set("running_action", c)
return response
return FAILURE

View file

@ -0,0 +1,33 @@
# Special implementation of a selector that will
# "wait" for running nodes and will not re-attempt
# to execute previous nodes until that node is either
# FAILED or SUCCEEDED
extends Composite
class_name SelectorStarComposite, "../../icons/selector_star.svg"
var last_execution_index = 0
func tick(actor, blackboard):
for c in get_children():
if c.get_index() < last_execution_index:
continue
var response = c.tick(actor, blackboard)
if c is ConditionLeaf:
blackboard.set("last_condition", c)
blackboard.set("last_condition_status", response)
if response != FAILURE:
if c is ActionLeaf and response == RUNNING:
blackboard.set("running_action", c)
if response == SUCCESS:
last_execution_index = 0
return response
else:
last_execution_index += 1
last_execution_index = 0
return FAILURE

View file

@ -0,0 +1,18 @@
extends Composite
class_name SequenceComposite, "../../icons/sequencer.svg"
func tick(actor, blackboard):
for c in get_children():
var response = c.tick(actor, blackboard)
if c is ConditionLeaf:
blackboard.set("last_condition", c)
blackboard.set("last_condition_status", response)
if response != SUCCESS:
if c is ActionLeaf and response == RUNNING:
blackboard.set("running_action", c)
return response
return SUCCESS

View file

@ -0,0 +1,35 @@
# Special implementation of sequencer who will execute
# successful nodes only once until all nodes were successful
extends Composite
class_name SequenceStarComposite, "../../icons/sequencer_star.svg"
var successful_index = 0
func tick(actor, blackboard):
for c in get_children():
if c.get_index() < successful_index:
continue
var response = c.tick(actor, blackboard)
if c is ConditionLeaf:
blackboard.set("last_condition", c)
blackboard.set("last_condition_status", response)
if response != SUCCESS:
if response == FAILURE:
successful_index = 0
if c is ActionLeaf and response == RUNNING:
blackboard.set("running_action", c)
return response
else:
successful_index += 1
if successful_index == get_child_count():
successful_index = 0
return SUCCESS
else:
successful_index = 0
return FAILURE