Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions addons/behaviour_toolkit/behaviour_tree/bt_composite.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
@icon("res://addons/behaviour_toolkit/icons/BTComposite.svg")
class_name BTComposite extends BTBehaviour
## Basic Composite node for Behaviour Tree.
##
## By itself is not doing much but is aware of it's children. You can use it
## to implement custom composite behaviours. If you Implement custom composite
## node remember to call [code]super()[/code] first in your custom node
## [code]_ready()[/code] callback!


## The leaves under the composite node.
@onready var leaves: Array = get_children()


func _ready() -> void:
connect("child_order_changed", _on_child_order_changed)


## BTComposite updates [member BTComposite.leaves] when it's children nodes are
## added, moved or deleted. If you implement custom composite node remember to
## call [code]super()[/code] first in your custom node [code]_ready()[/code]
## callback!
func _on_child_order_changed() -> void:
leaves = get_children()
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ class_name BTIntegratedFSM extends BTComposite
@onready var state_machine: FiniteStateMachine = _get_machine()


func _ready() -> void:
# Important to add when extending BTComposite!
super()


func tick(_actor: Node, _blackboard: Blackboard) -> Status:
if state_machine.active == false:
state_machine.start()
Expand Down
27 changes: 15 additions & 12 deletions addons/behaviour_toolkit/behaviour_tree/composites/bt_random.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ var active_leave: BTBehaviour


func _ready():
if use_seed:
rng.seed = hash(seed)
# Important to add when extending BTComposite!
super()

if use_seed:
rng.seed = hash(seed)


func tick(actor: Node, blackboard: Blackboard):
if active_leave == null:
active_leave = leaves[rng.randi() % leaves.size()]
var response = active_leave.tick(actor, blackboard)
if response == Status.RUNNING:
return response
active_leave = null
return response
if active_leave == null:
active_leave = leaves[rng.randi() % leaves.size()]
var response = active_leave.tick(actor, blackboard)
if response == Status.RUNNING:
return response
active_leave = null
return response
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ var is_shuffled: bool = false
var current_leaf: int = 0


func _ready() -> void:
# Important to add when extending BTComposite!
super()


func tick(actor: Node, blackboard: Blackboard):
if not is_shuffled:
leaves.shuffle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ var is_shuffled: bool = false
var current_leaf: int = 0


func _ready() -> void:
# Important to add when extending BTComposite!
super()


func tick(actor: Node, blackboard: Blackboard):
if not is_shuffled:
leaves.shuffle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class_name BTSelector extends BTComposite
var current_leaf: int = 0


func _ready() -> void:
# Important to add when extending BTComposite!
super()


func tick(actor: Node, blackboard: Blackboard):
if current_leaf > leaves.size() -1:
current_leaf = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class_name BTSequence extends BTComposite
var current_leaf: int = 0


func _ready() -> void:
# Important to add when extending BTComposite!
super()


func tick(actor: Node, blackboard: Blackboard):
if current_leaf > leaves.size() -1:
current_leaf = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ enum ParallelPolicy {
@onready var responses: Dictionary = {}


func _ready() -> void:
# Important to add when extending BTComposite!
super()


func tick(actor: Node, blackboard: Blackboard):
var leave_counter = 0
for leave in leaves:
Expand Down