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/decorators/decorator.gd
Normal file
8
addons/beehave/nodes/decorators/decorator.gd
Normal file
|
@ -0,0 +1,8 @@
|
|||
extends BeehaveNode
|
||||
|
||||
class_name Decorator, "../../icons/category_decorator.svg"
|
||||
|
||||
|
||||
func _ready():
|
||||
if self.get_child_count() != 1:
|
||||
push_error("Beehave Error: Decorator %s should have only one child (NodePath: %s)" % [self.name, self.get_path()])
|
11
addons/beehave/nodes/decorators/failer.gd
Normal file
11
addons/beehave/nodes/decorators/failer.gd
Normal file
|
@ -0,0 +1,11 @@
|
|||
extends Decorator
|
||||
|
||||
class_name AlwaysFailDecorator, "../../icons/fail.svg"
|
||||
|
||||
|
||||
func tick(action, blackboard):
|
||||
for c in get_children():
|
||||
var response = c.tick(action, blackboard)
|
||||
if response == RUNNING:
|
||||
return RUNNING
|
||||
return FAILURE
|
17
addons/beehave/nodes/decorators/inverter.gd
Normal file
17
addons/beehave/nodes/decorators/inverter.gd
Normal file
|
@ -0,0 +1,17 @@
|
|||
extends Decorator
|
||||
|
||||
class_name InverterDecorator, "../../icons/inverter.svg"
|
||||
|
||||
|
||||
func tick(action, blackboard):
|
||||
for c in get_children():
|
||||
var response = c.tick(action, blackboard)
|
||||
|
||||
if response == SUCCESS:
|
||||
return FAILURE
|
||||
if response == FAILURE:
|
||||
return SUCCESS
|
||||
|
||||
if c is Leaf and response == RUNNING:
|
||||
blackboard.set("running_action", c)
|
||||
return RUNNING
|
19
addons/beehave/nodes/decorators/limiter.gd
Normal file
19
addons/beehave/nodes/decorators/limiter.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
extends Decorator
|
||||
|
||||
class_name LimiterDecorator, "../../icons/limiter.svg"
|
||||
|
||||
onready var cache_key = 'limiter_%s' % self.get_instance_id()
|
||||
|
||||
export (float) var max_count = 0
|
||||
|
||||
func tick(actor, blackboard):
|
||||
var current_count = blackboard.get(cache_key)
|
||||
|
||||
if current_count == null:
|
||||
current_count = 0
|
||||
|
||||
if current_count <= max_count:
|
||||
blackboard.set(cache_key, current_count + 1)
|
||||
return self.get_child(0).tick(actor, blackboard)
|
||||
else:
|
||||
return FAILED
|
11
addons/beehave/nodes/decorators/succeeder.gd
Normal file
11
addons/beehave/nodes/decorators/succeeder.gd
Normal file
|
@ -0,0 +1,11 @@
|
|||
extends Decorator
|
||||
|
||||
class_name AlwaysSucceedDecorator, "../../icons/succeed.svg"
|
||||
|
||||
|
||||
func tick(action, blackboard):
|
||||
for c in get_children():
|
||||
var response = c.tick(action, blackboard)
|
||||
if response == RUNNING:
|
||||
return RUNNING
|
||||
return SUCCESS
|
Loading…
Add table
Add a link
Reference in a new issue