diff --git a/bt/composites/bt_random_selector.cpp b/bt/composites/bt_random_selector.cpp index b9ee1ae..db61e87 100644 --- a/bt/composites/bt_random_selector.cpp +++ b/bt/composites/bt_random_selector.cpp @@ -4,19 +4,19 @@ void BTRandomSelector::_enter() { last_running_idx = 0; - if (_indicies.size() != get_child_count()) { - _indicies.resize(get_child_count()); + if (indicies.size() != get_child_count()) { + indicies.resize(get_child_count()); for (int i = 0; i < get_child_count(); i++) { - _indicies.set(i, i); + indicies.set(i, i); } } - _indicies.shuffle(); + indicies.shuffle(); } int BTRandomSelector::_tick(float p_delta) { int status = FAILURE; for (int i = last_running_idx; i < get_child_count(); i++) { - status = get_child(_indicies[i])->execute(p_delta); + status = get_child(indicies[i])->execute(p_delta); if (status != FAILURE) { last_running_idx = i; break; diff --git a/bt/composites/bt_random_selector.h b/bt/composites/bt_random_selector.h index 94603cd..75140c5 100644 --- a/bt/composites/bt_random_selector.h +++ b/bt/composites/bt_random_selector.h @@ -11,7 +11,7 @@ class BTRandomSelector : public BTComposite { private: int last_running_idx = 0; - Array _indicies; + Array indicies; protected: virtual void _enter() override; diff --git a/bt/composites/bt_random_sequence.cpp b/bt/composites/bt_random_sequence.cpp index d7a4072..f041ce6 100644 --- a/bt/composites/bt_random_sequence.cpp +++ b/bt/composites/bt_random_sequence.cpp @@ -4,19 +4,19 @@ void BTRandomSequence::_enter() { last_running_idx = 0; - if (_indicies.size() != get_child_count()) { - _indicies.resize(get_child_count()); + if (indicies.size() != get_child_count()) { + indicies.resize(get_child_count()); for (int i = 0; i < get_child_count(); i++) { - _indicies.set(i, i); + indicies.set(i, i); } } - _indicies.shuffle(); + indicies.shuffle(); } int BTRandomSequence::_tick(float p_delta) { int status = SUCCESS; for (int i = last_running_idx; i < get_child_count(); i++) { - status = get_child(_indicies[i])->execute(p_delta); + status = get_child(indicies[i])->execute(p_delta); if (status != SUCCESS) { last_running_idx = i; break; diff --git a/bt/composites/bt_random_sequence.h b/bt/composites/bt_random_sequence.h index 06cf178..9c65ae8 100644 --- a/bt/composites/bt_random_sequence.h +++ b/bt/composites/bt_random_sequence.h @@ -11,7 +11,7 @@ class BTRandomSequence : public BTComposite { private: int last_running_idx = 0; - Array _indicies; + Array indicies; protected: virtual void _enter() override; diff --git a/bt/conditions/bt_condition.cpp b/bt/conditions/bt_condition.cpp index 9746d71..fb50a6c 100644 --- a/bt/conditions/bt_condition.cpp +++ b/bt/conditions/bt_condition.cpp @@ -8,7 +8,7 @@ String BTCondition::get_configuration_warning() const { warning += "\n"; } if (get_child_count() != 0) { - warning += "Condition can't have child tasks.\n"; + warning += "Condition task can't have child tasks.\n"; } return warning; } \ No newline at end of file diff --git a/bt/decorators/bt_cooldown.cpp b/bt/decorators/bt_cooldown.cpp index 089e1f0..730a7a2 100644 --- a/bt/decorators/bt_cooldown.cpp +++ b/bt/decorators/bt_cooldown.cpp @@ -33,17 +33,17 @@ int BTCooldown::_tick(float p_delta) { void BTCooldown::_chill() { get_blackboard()->set_var(cooldown_state_var, true); - if (_timer.is_valid()) { - _timer->set_time_left(duration); + if (timer.is_valid()) { + timer->set_time_left(duration); } else { - _timer = SceneTree::get_singleton()->create_timer(duration, process_pause); - _timer->connect("timeout", callable_mp(this, &BTCooldown::_on_timeout), CONNECT_ONE_SHOT); + timer = SceneTree::get_singleton()->create_timer(duration, process_pause); + timer->connect("timeout", callable_mp(this, &BTCooldown::_on_timeout), CONNECT_ONE_SHOT); } } void BTCooldown::_on_timeout() { get_blackboard()->set_var(cooldown_state_var, false); - _timer.unref(); + timer.unref(); } void BTCooldown::_bind_methods() { diff --git a/bt/decorators/bt_cooldown.h b/bt/decorators/bt_cooldown.h index 1474df4..05330e1 100644 --- a/bt/decorators/bt_cooldown.h +++ b/bt/decorators/bt_cooldown.h @@ -17,7 +17,7 @@ private: bool trigger_on_failure = false; String cooldown_state_var = ""; - Ref _timer = nullptr; + Ref timer = nullptr; void _chill(); void _on_timeout(); diff --git a/bt/decorators/bt_new_scope.cpp b/bt/decorators/bt_new_scope.cpp index 703efcc..aa649d0 100644 --- a/bt/decorators/bt_new_scope.cpp +++ b/bt/decorators/bt_new_scope.cpp @@ -12,15 +12,6 @@ void BTNewScope::initialize(Node *p_agent, const Ref &p_blackboard) Ref bb = memnew(Blackboard); - // if (blackboard_data.empty()) { - // bb->set_parent_scope(p_blackboard); - // } else { - // Ref ro = memnew(Blackboard); - // ro->set_data(blackboard_data); - // ro->set_parent_scope(p_blackboard); - // bb->set_parent_scope(ro); - // } - bb->set_data(blackboard_data.duplicate()); bb->set_parent_scope(p_blackboard); diff --git a/bt/decorators/bt_repeat.cpp b/bt/decorators/bt_repeat.cpp index 406fb2b..49d9466 100644 --- a/bt/decorators/bt_repeat.cpp +++ b/bt/decorators/bt_repeat.cpp @@ -9,7 +9,7 @@ String BTRepeat::_generate_name() const { } void BTRepeat::_enter() { - _cur_iteration = 1; + cur_iteration = 1; } int BTRepeat::_tick(float p_delta) { @@ -19,10 +19,10 @@ int BTRepeat::_tick(float p_delta) { return RUNNING; } else if (status == FAILURE && abort_on_failure) { return FAILURE; - } else if (_cur_iteration >= times) { + } else if (cur_iteration >= times) { return SUCCESS; } else { - _cur_iteration += 1; + cur_iteration += 1; return RUNNING; } } diff --git a/bt/decorators/bt_repeat.h b/bt/decorators/bt_repeat.h index 2e629fa..d213a8a 100644 --- a/bt/decorators/bt_repeat.h +++ b/bt/decorators/bt_repeat.h @@ -12,7 +12,7 @@ class BTRepeat : public BTDecorator { private: int times = 1; bool abort_on_failure = false; - int _cur_iteration = 0; + int cur_iteration = 0; protected: static void _bind_methods(); diff --git a/bt/decorators/bt_run_limit.cpp b/bt/decorators/bt_run_limit.cpp index 643321c..d6ffa92 100644 --- a/bt/decorators/bt_run_limit.cpp +++ b/bt/decorators/bt_run_limit.cpp @@ -9,10 +9,10 @@ String BTRunLimit::_generate_name() const { int BTRunLimit::_tick(float p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_child(0)->get_status() != RUNNING) { - if (_num_runs >= run_limit) { + if (num_runs >= run_limit) { return FAILURE; } - _num_runs += 1; + num_runs += 1; } return get_child(0)->execute(p_delta); } diff --git a/bt/decorators/bt_run_limit.h b/bt/decorators/bt_run_limit.h index 75ab8b5..7b69ea1 100644 --- a/bt/decorators/bt_run_limit.h +++ b/bt/decorators/bt_run_limit.h @@ -11,7 +11,7 @@ class BTRunLimit : public BTDecorator { private: int run_limit = 1; - int _num_runs = 0; + int num_runs = 0; protected: static void _bind_methods(); diff --git a/bt/decorators/bt_time_limit.cpp b/bt/decorators/bt_time_limit.cpp index 791f4ab..db8ca0c 100644 --- a/bt/decorators/bt_time_limit.cpp +++ b/bt/decorators/bt_time_limit.cpp @@ -7,14 +7,14 @@ String BTTimeLimit::_generate_name() const { } void BTTimeLimit::_enter() { - _time_passed = 0.0; + time_passed = 0.0; } int BTTimeLimit::_tick(float p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); - _time_passed += p_delta; + time_passed += p_delta; int status = get_child(0)->execute(p_delta); - if (status == RUNNING and _time_passed >= time_limit) { + if (status == RUNNING and time_passed >= time_limit) { get_child(0)->cancel(); return FAILURE; } diff --git a/bt/decorators/bt_time_limit.h b/bt/decorators/bt_time_limit.h index cc99f95..cd7d713 100644 --- a/bt/decorators/bt_time_limit.h +++ b/bt/decorators/bt_time_limit.h @@ -11,7 +11,7 @@ class BTTimeLimit : public BTDecorator { private: float time_limit = 5.0; - float _time_passed = 0.0; + float time_passed = 0.0; protected: static void _bind_methods(); diff --git a/test/ai/trees/waypoints.tres b/test/ai/trees/waypoints.tres index 4997301..32a319a 100644 --- a/test/ai/trees/waypoints.tres +++ b/test/ai/trees/waypoints.tres @@ -1,4 +1,4 @@ -[gd_resource type="BehaviorTree" load_steps=8 format=3 uid="uid://cjkqi41oagagd"] +[gd_resource type="BehaviorTree" load_steps=9 format=3 uid="uid://cjkqi41oagagd"] [ext_resource type="Script" path="res://ai/tasks/arrive_pos.gd" id="1_rhs33"] [ext_resource type="Script" path="res://ai/tasks/play_animation.gd" id="2_dg0ss"] @@ -22,8 +22,12 @@ children = [SubResource("BTSequence_a2ng0")] array_var = "waypoints" save_var = "wp" -[sub_resource type="BTSelector" id="BTSelector_5dclr"] +[sub_resource type="BTCooldown" id="BTCooldown_gen0l"] children = [SubResource("BTForEach_0cp04")] +duration = 3.0 + +[sub_resource type="BTSelector" id="BTSelector_5dclr"] +children = [SubResource("BTCooldown_gen0l")] [resource] root_task = SubResource("BTSelector_5dclr")