mirror of
https://github.com/tonytins/citylimits
synced 2025-06-26 09:44:44 -04:00
Behavior Tree addon
This commit is contained in:
parent
5de5a0c315
commit
5fa863114a
50 changed files with 1762 additions and 3 deletions
8
addons/beehave/nodes/composites/composite.gd
Normal file
8
addons/beehave/nodes/composites/composite.gd
Normal 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()])
|
18
addons/beehave/nodes/composites/selector.gd
Normal file
18
addons/beehave/nodes/composites/selector.gd
Normal 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
|
33
addons/beehave/nodes/composites/selector_star.gd
Normal file
33
addons/beehave/nodes/composites/selector_star.gd
Normal 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
|
18
addons/beehave/nodes/composites/sequence.gd
Normal file
18
addons/beehave/nodes/composites/sequence.gd
Normal 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
|
35
addons/beehave/nodes/composites/sequence_star.gd
Normal file
35
addons/beehave/nodes/composites/sequence_star.gd
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue