Post the rest of the BT tasks (massive changes)

This commit is contained in:
Serhii Snitsaruk 2024-01-07 00:47:46 +01:00
parent 8eed672213
commit 4f97c1bd24
59 changed files with 284 additions and 227 deletions

View File

@ -11,10 +11,14 @@
#include "behavior_tree.h"
#ifdef LIMBOAI_MODULE
#include "core/error/error_macros.h"
#include "core/object/class_db.h"
#include "core/templates/list.h"
#include "core/variant/variant.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#endif // LIMBOAI_GDEXTENSION
Ref<BehaviorTree> BehaviorTree::clone() const {
Ref<BehaviorTree> copy = duplicate(false);

View File

@ -12,11 +12,18 @@
#ifndef BEHAVIOR_TREE_H
#define BEHAVIOR_TREE_H
#include "core/io/resource.h"
#include "modules/limboai/blackboard/blackboard.h"
#include "tasks/bt_task.h"
#ifdef LIMBOAI_MODULE
#include "core/io/resource.h"
#include "modules/limboai/blackboard/blackboard.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/resource.hpp>
using namespace godot;
#endif // LIMBOAI_GDEXTENSION
class BehaviorTree : public Resource {
GDCLASS(BehaviorTree, Resource);
@ -28,7 +35,9 @@ protected:
static void _bind_methods();
public:
#ifdef LIMBOAI_MODULE
virtual bool editor_can_reload_from_file() override { return false; }
#endif
void set_description(String p_value) {
description = p_value;

View File

@ -11,16 +11,14 @@
#include "bt_check_trigger.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/variant/variant.h"
#include "../../../util/limbo_utility.h"
void BTCheckTrigger::set_variable(String p_variable) {
variable = p_variable;
emit_changed();
}
PackedStringArray BTCheckTrigger::get_configuration_warnings() const {
PackedStringArray BTCheckTrigger::get_configuration_warnings() {
PackedStringArray warnings = BTCondition::get_configuration_warnings();
if (variable.is_empty()) {
warnings.append("Variable is not set.");
@ -28,7 +26,7 @@ PackedStringArray BTCheckTrigger::get_configuration_warnings() const {
return warnings;
}
String BTCheckTrigger::_generate_name() const {
String BTCheckTrigger::_generate_name() {
if (variable.is_empty()) {
return "CheckTrigger ???";
}

View File

@ -14,8 +14,6 @@
#include "../bt_condition.h"
#include "core/string/ustring.h"
class BTCheckTrigger : public BTCondition {
GDCLASS(BTCheckTrigger, BTCondition);
TASK_CATEGORY(Blackboard);
@ -26,14 +24,14 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
void set_variable(String p_variable);
String get_variable() const { return variable; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_CHECK_TRIGGER

View File

@ -11,10 +11,6 @@
#include "bt_check_var.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/variant/callable.h"
void BTCheckVar::set_variable(String p_variable) {
variable = p_variable;
emit_changed();
@ -29,11 +25,11 @@ void BTCheckVar::set_value(Ref<BBVariant> p_value) {
value = p_value;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) {
value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
PackedStringArray BTCheckVar::get_configuration_warnings() const {
PackedStringArray BTCheckVar::get_configuration_warnings() {
PackedStringArray warnings = BTCondition::get_configuration_warnings();
if (variable.is_empty()) {
warnings.append("`variable` should be assigned.");
@ -44,7 +40,7 @@ PackedStringArray BTCheckVar::get_configuration_warnings() const {
return warnings;
}
String BTCheckVar::_generate_name() const {
String BTCheckVar::_generate_name() {
if (variable.is_empty()) {
return "CheckVar ???";
}

View File

@ -14,8 +14,8 @@
#include "../bt_condition.h"
#include "modules/limboai/blackboard/bb_param/bb_variant.h"
#include "modules/limboai/util/limbo_utility.h"
#include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../limboai/util/limbo_utility.h"
class BTCheckVar : public BTCondition {
GDCLASS(BTCheckVar, BTCondition);
@ -29,11 +29,11 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
void set_variable(String p_variable);
String get_variable() const { return variable; }

View File

@ -11,13 +11,7 @@
#include "bt_set_var.h"
#include "modules/limboai/blackboard/bb_param/bb_param.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/variant/callable.h"
#include "core/variant/variant.h"
String BTSetVar::_generate_name() const {
String BTSetVar::_generate_name() {
if (variable.is_empty()) {
return "SetVar ???";
}
@ -31,7 +25,7 @@ BT::Status BTSetVar::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BTSetVar: `variable` is not set.");
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetVar: `value` is not set.");
Variant result;
Variant error_result = SNAME("Error: BTSetVar failed to get value!");
Variant error_result = LSNAME(error_value);
Variant right_value = value->get_value(get_agent(), get_blackboard(), error_result);
ERR_FAIL_COND_V_MSG(right_value == error_result, FAILURE, "BTSetVar: Failed to get parameter value. Returning FAILURE.");
if (operation == LimboUtility::OPERATION_NONE) {
@ -55,7 +49,7 @@ void BTSetVar::set_value(Ref<BBVariant> p_value) {
value = p_value;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) {
value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
@ -64,7 +58,7 @@ void BTSetVar::set_operation(LimboUtility::Operation p_operation) {
emit_changed();
}
PackedStringArray BTSetVar::get_configuration_warnings() const {
PackedStringArray BTSetVar::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (variable.is_empty()) {
warnings.append("`variable` should be assigned.");

View File

@ -14,10 +14,8 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_variant.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/string/ustring.h"
#include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../limboai/util/limbo_utility.h"
class BTSetVar : public BTAction {
GDCLASS(BTSetVar, BTAction);
@ -31,11 +29,11 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
void set_variable(const String &p_variable);
String get_variable() const { return variable; }

View File

@ -287,16 +287,9 @@ void BTTask::abort() {
int BTTask::get_child_count_excluding_comments() const {
int count = 0;
for (int i = 0; i < data.children.size(); i++) {
#ifdef LIMBOAI_MODULE
if (!data.children[i]->is_class_ptr(BTComment::get_class_ptr_static())) {
if (!IS_CLASS(data.children[i], BTComment)) {
count += 1;
}
#endif
#ifdef LIMBOAI_GDEXTENSION
if (data.children[i]->get_class_static() != BTComment::get_class_static()) {
count += 1;
}
#endif
}
return count;
}

View File

@ -14,11 +14,16 @@
#ifdef LIMBOAI_MODULE
#include "modules/limboai/blackboard/blackboard.h"
#include "modules/limboai/util/limbo_string_names.h"
#include "modules/limboai/util/limbo_task_db.h"
#include "core/config/engine.h"
#include "core/error/error_macros.h"
#include "core/io/resource.h"
#include "core/math/math_funcs.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/os/memory.h"
#include "core/string/ustring.h"
#include "core/templates/vector.h"
#include "core/typedefs.h"
@ -30,8 +35,11 @@
#ifdef LIMBOAI_GDEXTENSION
#include "blackboard/blackboard.h"
#include "util/limbo_def.h"
#include "util/limbo_string_names.h"
#include "util/limbo_task_db.h"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/resource.hpp>
#include <godot_cpp/core/object.hpp>
#include <godot_cpp/templates/vector.hpp>

View File

@ -11,8 +11,6 @@
#include "bt_parallel.h"
#include "core/object/class_db.h"
void BTParallel::_enter() {
for (int i = 0; i < get_child_count(); i++) {
get_child(i)->abort();

View File

@ -10,26 +10,23 @@
*/
#include "bt_probability_selector.h"
#include "modules/limboai/bt/tasks/bt_task.h"
#include "core/error/error_macros.h"
#include "godot_cpp/variant/utility_functions.hpp"
double BTProbabilitySelector::get_weight(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_child_count(), 0.0);
ERR_FAIL_COND_V(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()), 0.0);
ERR_FAIL_COND_V(IS_CLASS(get_child(p_index), BTComment), 0.0);
return _get_weight(p_index);
}
void BTProbabilitySelector::set_weight(int p_index, double p_weight) {
ERR_FAIL_INDEX(p_index, get_child_count());
ERR_FAIL_COND(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()));
ERR_FAIL_COND(IS_CLASS(get_child(p_index), BTComment));
_set_weight(p_index, p_weight);
}
double BTProbabilitySelector::get_probability(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_child_count(), 0.0);
ERR_FAIL_COND_V(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()), 0.0);
ERR_FAIL_COND_V(IS_CLASS(get_child(p_index), BTComment), 0.0);
double total = _get_total_weight();
return total == 0.0 ? 0.0 : _get_weight(p_index) / total;
}
@ -38,7 +35,7 @@ void BTProbabilitySelector::set_probability(int p_index, double p_probability) {
ERR_FAIL_INDEX(p_index, get_child_count());
ERR_FAIL_COND(p_probability < 0.0);
ERR_FAIL_COND(p_probability >= 1.0);
ERR_FAIL_COND(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()));
ERR_FAIL_COND(IS_CLASS(get_child(p_index), BTComment));
double others_total = _get_total_weight() - _get_weight(p_index);
double others_probability = 1.0 - p_probability;
@ -52,7 +49,7 @@ void BTProbabilitySelector::set_probability(int p_index, double p_probability) {
bool BTProbabilitySelector::has_probability(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_child_count(), false);
return !get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static());
return !IS_CLASS(get_child(p_index), BTComment);
}
void BTProbabilitySelector::set_abort_on_failure(bool p_abort_on_failure) {
@ -98,7 +95,7 @@ void BTProbabilitySelector::_select_task() {
remaining_tasks_weight -= _get_weight(task);
}
double roll = Math::random(0.0, remaining_tasks_weight);
double roll = RAND_RANGE(0.0, remaining_tasks_weight);
for (int i = 0; i < get_child_count(); i++) {
Ref<BTTask> task = get_child(i);
if (failed_tasks.has(task)) {

View File

@ -12,11 +12,16 @@
#ifndef BT_PROBABILITY_SELECTOR_H
#define BT_PROBABILITY_SELECTOR_H
#include "modules/limboai/bt/tasks/bt_comment.h"
#include "modules/limboai/bt/tasks/bt_composite.h"
#include "../bt_comment.h"
#include "../bt_composite.h"
#ifdef LIMBOAI_MODULE
#include "core/core_string_names.h"
#include "core/typedefs.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/templates/hash_set.hpp>
#endif // LIMBOAI_GDEXTENSION
class BTProbabilitySelector : public BTComposite {
GDCLASS(BTProbabilitySelector, BTComposite);
@ -28,17 +33,17 @@ private:
bool abort_on_failure = false;
void _select_task();
_FORCE_INLINE_ double _get_weight(int p_index) const { return get_child(p_index)->get_meta(SNAME("_weight_"), 1.0); }
_FORCE_INLINE_ double _get_weight(Ref<BTTask> p_task) const { return p_task->get_meta(SNAME("_weight_"), 1.0); }
#define SNAME(m_arg) ([]() -> const StringName & { static StringName sname = _scs_create(m_arg, true); return sname; })()
_FORCE_INLINE_ double _get_weight(int p_index) const { return get_child(p_index)->get_meta(LSNAME(_weight_), 1.0); }
_FORCE_INLINE_ double _get_weight(Ref<BTTask> p_task) const { return p_task->get_meta(LSNAME(_weight_), 1.0); }
_FORCE_INLINE_ void _set_weight(int p_index, double p_weight) {
get_child(p_index)->set_meta(SNAME("_weight_"), Variant(p_weight));
get_child(p_index)->emit_signal(CoreStringNames::get_singleton()->changed);
get_child(p_index)->set_meta(LSNAME(_weight_), Variant(p_weight));
get_child(p_index)->emit_signal(LSNAME(changed));
}
_FORCE_INLINE_ double _get_total_weight() const {
double total = 0.0;
for (int i = 0; i < get_child_count(); i++) {
if (!get_child(i)->is_class_ptr(BTComment::get_class_ptr_static())) {
if (!IS_CLASS(get_child(i), BTComment)) {
total += _get_weight(i);
}
}

View File

@ -16,7 +16,7 @@ void BTRandomSelector::_enter() {
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[i] = i;
}
}
indicies.shuffle();

View File

@ -14,8 +14,6 @@
#include "../bt_composite.h"
#include "core/templates/vector.h"
class BTRandomSelector : public BTComposite {
GDCLASS(BTRandomSelector, BTComposite);
TASK_CATEGORY(Composites);

View File

@ -1,7 +1,7 @@
/**
* bt_random_sequence.cpp
* =============================================================================
* Copyright 2021-2023 Serhii Snitsaruk
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
@ -16,7 +16,7 @@ void BTRandomSequence::_enter() {
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[i] = i;
}
}
indicies.shuffle();

View File

@ -14,8 +14,6 @@
#include "../bt_composite.h"
#include "core/templates/vector.h"
class BTRandomSequence : public BTComposite {
GDCLASS(BTRandomSequence, BTComposite);
TASK_CATEGORY(Composites);

View File

@ -11,10 +11,12 @@
#include "bt_cooldown.h"
#include "core/math/math_funcs.h"
#include "core/object/class_db.h"
#include "core/variant/array.h"
#ifdef LIMBOAI_MODULE
#include "scene/main/scene_tree.h"
#endif
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/scene_tree.hpp>
#endif
//**** Setters / Getters
@ -45,7 +47,7 @@ void BTCooldown::set_cooldown_state_var(String p_value) {
//**** Task Implementation
String BTCooldown::_generate_name() const {
String BTCooldown::_generate_name() {
return vformat("Cooldown %s sec", Math::snapped(duration, 0.001));
}
@ -76,7 +78,13 @@ void BTCooldown::_chill() {
if (timer.is_valid()) {
timer->set_time_left(duration);
} else {
#ifdef LIMBOAI_MODULE
timer = SceneTree::get_singleton()->create_timer(duration, process_pause);
#endif
#ifdef LIMBOAI_GDEXTENSION
SceneTree *st = (SceneTree *)Engine::get_singleton()->get_main_loop();
timer = st->create_timer(duration, process_pause);
#endif
timer->connect("timeout", callable_mp(this, &BTCooldown::_on_timeout), CONNECT_ONE_SHOT);
}
}

View File

@ -14,7 +14,12 @@
#include "../bt_decorator.h"
#ifdef LIMBOAI_MODULE
#include "scene/main/scene_tree.h"
#endif
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/scene_tree_timer.hpp>
#endif
class BTCooldown : public BTDecorator {
GDCLASS(BTCooldown, BTDecorator);
@ -35,7 +40,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _setup() override;
virtual Status _tick(double p_delta) override;

View File

@ -11,19 +11,12 @@
#include "bt_delay.h"
#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/array.h"
#include "core/variant/variant.h"
void BTDelay::set_seconds(double p_value) {
seconds = p_value;
emit_changed();
}
String BTDelay::_generate_name() const {
String BTDelay::_generate_name() {
return vformat("Delay %s sec", Math::snapped(seconds, 0.001));
}

View File

@ -24,7 +24,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:

View File

@ -11,12 +11,12 @@
#include "bt_for_each.h"
#include "modules/limboai/blackboard/blackboard.h"
#include "modules/limboai/util/limbo_utility.h"
#include "../../../blackboard/blackboard.h"
#include "../../../util/limbo_utility.h"
#ifdef LIMBOAI_MODULE
#include "core/error/error_list.h"
#include "core/error/error_macros.h"
#include "core/variant/variant.h"
#endif
//**** Setters / Getters
@ -32,7 +32,7 @@ void BTForEach::set_save_var(String p_value) {
//**** Task Implementation
String BTForEach::_generate_name() const {
String BTForEach::_generate_name() {
return vformat("ForEach %s in %s",
LimboUtility::get_singleton()->decorate_var(save_var),
LimboUtility::get_singleton()->decorate_var(array_var));
@ -51,7 +51,7 @@ BT::Status BTForEach::_tick(double p_delta) {
if (arr.size() == 0) {
return SUCCESS;
}
Variant elem = arr.get(current_idx);
Variant elem = arr[current_idx];
get_blackboard()->set_var(save_var, elem);
Status status = get_child(0)->execute(p_delta);

View File

@ -27,7 +27,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _enter() override;
virtual Status _tick(double p_delta) override;

View File

@ -11,12 +11,6 @@
#include "bt_new_scope.h"
#include "modules/limboai/blackboard/blackboard.h"
#include "core/error/error_macros.h"
#include "core/os/memory.h"
#include "core/string/ustring.h"
void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) {
ERR_FAIL_COND(p_agent == nullptr);
ERR_FAIL_COND(p_blackboard == nullptr);

View File

@ -16,13 +16,13 @@ void BTProbability::set_run_chance(float p_value) {
emit_changed();
}
String BTProbability::_generate_name() const {
String BTProbability::_generate_name() {
return vformat("Probability %.1f%%", run_chance);
}
BT::Status BTProbability::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
if (get_child(0)->get_status() == RUNNING || Math::randf() <= run_chance) {
if (get_child(0)->get_status() == RUNNING || RANDF() <= run_chance) {
return get_child(0)->execute(p_delta);
}
return FAILURE;

View File

@ -24,7 +24,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:

View File

@ -10,19 +10,11 @@
*/
#include "bt_repeat.h"
#include "util/limbo_string_names.h"
#include "core/object/object.h"
#include "core/string/ustring.h"
#include "core/variant/variant.h"
static String repeat_forever_str;
String BTRepeat::_generate_name() const {
String BTRepeat::_generate_name() {
if (forever) {
if (repeat_forever_str.is_empty()) {
repeat_forever_str.parse_utf8("Repeat ∞");
}
return repeat_forever_str;
return LSNAME(repeat_forever);
}
return vformat("Repeat x%s", times);
}
@ -81,3 +73,6 @@ void BTRepeat::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "times", PROPERTY_HINT_RANGE, "1,65535", PROPERTY_USAGE_NONE), "set_times", "get_times");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "abort_on_failure", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_abort_on_failure", "get_abort_on_failure");
}
BTRepeat::BTRepeat() {
}

View File

@ -29,7 +29,7 @@ protected:
void _get_property_list(List<PropertyInfo> *p_list) const;
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _enter() override;
virtual Status _tick(double p_delta) override;
@ -42,6 +42,8 @@ public:
void set_abort_on_failure(bool p_value);
bool get_abort_on_failure() const { return abort_on_failure; }
BTRepeat();
};
#endif // BT_REPEAT_H

View File

@ -16,7 +16,7 @@ void BTRunLimit::set_run_limit(int p_value) {
emit_changed();
}
String BTRunLimit::_generate_name() const {
String BTRunLimit::_generate_name() {
return vformat("RunLimit x%d", run_limit);
}

View File

@ -25,7 +25,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:

View File

@ -11,20 +11,12 @@
#include "bt_subtree.h"
#include "bt_new_scope.h"
#include "modules/limboai/blackboard/blackboard.h"
#include "core/config/engine.h"
#include "core/error/error_macros.h"
#include "core/typedefs.h"
#include "core/variant/variant.h"
void BTSubtree::set_subtree(const Ref<BehaviorTree> &p_value) {
subtree = p_value;
emit_changed();
}
String BTSubtree::_generate_name() const {
String BTSubtree::_generate_name() {
String s;
if (subtree.is_null()) {
s = "(unassigned)";
@ -51,7 +43,7 @@ BT::Status BTSubtree::_tick(double p_delta) {
return get_child(0)->execute(p_delta);
}
PackedStringArray BTSubtree::get_configuration_warnings() const {
PackedStringArray BTSubtree::get_configuration_warnings() {
PackedStringArray warnings = BTTask::get_configuration_warnings(); // ! BTDecorator skipped intentionally
if (subtree.is_null()) {
warnings.append("Subtree needs to be assigned.");

View File

@ -14,7 +14,7 @@
#include "bt_new_scope.h"
#include "modules/limboai/bt/behavior_tree.h"
#include "../../../bt/behavior_tree.h"
class BTSubtree : public BTNewScope {
GDCLASS(BTSubtree, BTNewScope);
@ -26,7 +26,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
@ -34,7 +34,7 @@ public:
Ref<BehaviorTree> get_subtree() const { return subtree; }
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_SUBTREE_H

View File

@ -11,14 +11,12 @@
#include "bt_time_limit.h"
#include "core/math/math_funcs.h"
void BTTimeLimit::set_time_limit(double p_value) {
time_limit = p_value;
emit_changed();
}
String BTTimeLimit::_generate_name() const {
String BTTimeLimit::_generate_name() {
return vformat("TimeLimit %s sec", Math::snapped(time_limit, 0.001));
}

View File

@ -24,7 +24,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:

View File

@ -17,7 +17,7 @@ void BTAwaitAnimation::set_animation_player(Ref<BBNode> p_animation_player) {
animation_player_param = p_animation_player;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) {
animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
@ -33,12 +33,12 @@ void BTAwaitAnimation::set_max_time(double p_max_time) {
//**** Task Implementation
PackedStringArray BTAwaitAnimation::get_configuration_warnings() const {
PackedStringArray BTAwaitAnimation::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (animation_player_param.is_null()) {
warnings.append("Animation Player parameter is not set.");
} else {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) {
warnings.append("Path to AnimationPlayer node is not set.");
} else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) {
warnings.append("AnimationPlayer blackboard variable is not set.");
@ -53,7 +53,7 @@ PackedStringArray BTAwaitAnimation::get_configuration_warnings() const {
return warnings;
}
String BTAwaitAnimation::_generate_name() const {
String BTAwaitAnimation::_generate_name() {
return "AwaitAnimation" +
(animation_name != StringName() ? vformat(" \"%s\"", animation_name) : " ???") +
vformat(" max_time: %ss", Math::snapped(max_time, 0.001));

View File

@ -14,9 +14,15 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_node.h"
#include "../../../blackboard/bb_param/bb_node.h"
#ifdef LIMBOAI_MODULE
#include "scene/animation/animation_player.h"
#endif
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/animation_player.hpp>
#endif
class BTAwaitAnimation : public BTAction {
GDCLASS(BTAwaitAnimation, BTAction);
@ -33,7 +39,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _setup() override;
virtual Status _tick(double p_delta) override;
@ -47,7 +53,7 @@ public:
void set_max_time(double p_max_time);
double get_max_time() const { return max_time; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_AWAIT_ANIMATION

View File

@ -11,10 +11,6 @@
#include "bt_check_agent_property.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/variant/callable.h"
void BTCheckAgentProperty::set_property(StringName p_prop) {
property = p_prop;
emit_changed();
@ -29,11 +25,11 @@ void BTCheckAgentProperty::set_value(Ref<BBVariant> p_value) {
value = p_value;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) {
value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
PackedStringArray BTCheckAgentProperty::get_configuration_warnings() const {
PackedStringArray BTCheckAgentProperty::get_configuration_warnings() {
PackedStringArray warnings = BTCondition::get_configuration_warnings();
if (property == StringName()) {
warnings.append("`property` should be assigned.");
@ -44,7 +40,7 @@ PackedStringArray BTCheckAgentProperty::get_configuration_warnings() const {
return warnings;
}
String BTCheckAgentProperty::_generate_name() const {
String BTCheckAgentProperty::_generate_name() {
if (property == StringName()) {
return "CheckAgentProperty ???";
}
@ -58,9 +54,14 @@ BT::Status BTCheckAgentProperty::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(property == StringName(), FAILURE, "BTCheckAgentProperty: `property` is not set.");
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckAgentProperty: `value` is not set.");
#ifdef LIMBOAI_MODULE
bool r_valid;
Variant left_value = get_agent()->get(property, &r_valid);
ERR_FAIL_COND_V_MSG(r_valid == false, FAILURE, vformat("BTCheckAgentProperty: Agent has no property named \"%s\"", property));
#endif
#ifdef LIMBOAI_GDEXTENSION
Variant left_value = get_agent()->get(property);
#endif
Variant right_value = value->get_value(get_agent(), get_blackboard());

View File

@ -14,10 +14,8 @@
#include "../bt_condition.h"
#include "modules/limboai/blackboard/bb_param/bb_variant.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/string/string_name.h"
#include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../util/limbo_utility.h"
class BTCheckAgentProperty : public BTCondition {
GDCLASS(BTCheckAgentProperty, BTCondition);
@ -31,7 +29,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
@ -44,7 +42,7 @@ public:
void set_value(Ref<BBVariant> p_value);
Ref<BBVariant> get_value() const { return value; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_CHECK_AGENT_PROPERTY

View File

@ -17,18 +17,18 @@ void BTPauseAnimation::set_animation_player(Ref<BBNode> p_animation_player) {
animation_player_param = p_animation_player;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) {
animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
//**** Task Implementation
PackedStringArray BTPauseAnimation::get_configuration_warnings() const {
PackedStringArray BTPauseAnimation::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (animation_player_param.is_null()) {
warnings.append("Animation Player parameter is not set.");
} else {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) {
warnings.append("Path to AnimationPlayer node is not set.");
} else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) {
warnings.append("AnimationPlayer blackboard variable is not set.");
@ -37,7 +37,7 @@ PackedStringArray BTPauseAnimation::get_configuration_warnings() const {
return warnings;
}
String BTPauseAnimation::_generate_name() const {
String BTPauseAnimation::_generate_name() {
return "PauseAnimation";
}

View File

@ -14,9 +14,15 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_node.h"
#include "../../../blackboard/bb_param/bb_node.h"
#ifdef LIMBOAI_MODULE
#include "scene/animation/animation_player.h"
#endif
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/animation_player.hpp>
#endif
class BTPauseAnimation : public BTAction {
GDCLASS(BTPauseAnimation, BTAction);
@ -31,7 +37,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _setup() override;
virtual Status _tick(double p_delta) override;
@ -39,7 +45,7 @@ public:
void set_animation_player(Ref<BBNode> p_animation_player);
Ref<BBNode> get_animation_player() const { return animation_player_param; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_PAUSE_ANIMATION

View File

@ -11,15 +11,13 @@
#include "bt_play_animation.h"
#include "core/math/math_funcs.h"
//**** Setters / Getters
void BTPlayAnimation::set_animation_player(Ref<BBNode> p_animation_player) {
animation_player_param = p_animation_player;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) {
animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
@ -50,12 +48,12 @@ void BTPlayAnimation::set_from_end(bool p_from_end) {
//**** Task Implementation
PackedStringArray BTPlayAnimation::get_configuration_warnings() const {
PackedStringArray BTPlayAnimation::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (animation_player_param.is_null()) {
warnings.append("Animation Player parameter is not set.");
} else {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) {
warnings.append("Path to AnimationPlayer node is not set.");
} else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) {
warnings.append("AnimationPlayer blackboard variable is not set.");
@ -67,7 +65,7 @@ PackedStringArray BTPlayAnimation::get_configuration_warnings() const {
return warnings;
}
String BTPlayAnimation::_generate_name() const {
String BTPlayAnimation::_generate_name() {
return "PlayAnimation" +
(animation_name != StringName() ? vformat(" \"%s\"", animation_name) : "") +
(blend >= 0.0 ? vformat(" blend: %ss", Math::snapped(blend, 0.001)) : "") +

View File

@ -14,9 +14,15 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_node.h"
#include "../../../blackboard/bb_param/bb_node.h"
#ifdef LIMBOAI_MODULE
#include "scene/animation/animation_player.h"
#endif
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/animation_player.hpp>
#endif
class BTPlayAnimation : public BTAction {
GDCLASS(BTPlayAnimation, BTAction);
@ -36,7 +42,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _setup() override;
virtual void _enter() override;
virtual Status _tick(double p_delta) override;
@ -60,7 +66,7 @@ public:
void set_from_end(bool p_from_end);
bool get_from_end() const { return from_end; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_PLAY_ANIMATION

View File

@ -20,7 +20,7 @@ void BTSetAgentProperty::set_value(Ref<BBVariant> p_value) {
value = p_value;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) {
value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
@ -29,7 +29,7 @@ void BTSetAgentProperty::set_operation(LimboUtility::Operation p_operation) {
emit_changed();
}
PackedStringArray BTSetAgentProperty::get_configuration_warnings() const {
PackedStringArray BTSetAgentProperty::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (property == StringName()) {
warnings.append("`property` should be assigned.");
@ -40,7 +40,7 @@ PackedStringArray BTSetAgentProperty::get_configuration_warnings() const {
return warnings;
}
String BTSetAgentProperty::_generate_name() const {
String BTSetAgentProperty::_generate_name() {
if (property == StringName()) {
return "SetAgentProperty ???";
}
@ -54,21 +54,31 @@ BT::Status BTSetAgentProperty::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetAgentProperty: `value` is not set.");
Variant result;
StringName error_value = SNAME("ErrorGettingValue");
StringName error_value = LSNAME(error_value);
Variant right_value = value->get_value(get_agent(), get_blackboard(), error_value);
ERR_FAIL_COND_V_MSG(right_value == Variant(error_value), FAILURE, "BTSetAgentProperty: Couldn't get value of value-parameter.");
bool r_valid;
if (operation == LimboUtility::OPERATION_NONE) {
result = right_value;
} else {
#ifdef LIMBOAI_MODULE
Variant left_value = get_agent()->get(property, &r_valid);
ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Failed to get agent's \"%s\" property. Returning FAILURE.", property));
#endif
#ifdef LIMBOAI_GDEXTENSION
Variant left_value = get_agent()->get(property);
#endif
result = LimboUtility::get_singleton()->perform_operation(operation, left_value, right_value);
ERR_FAIL_COND_V_MSG(result == Variant(), FAILURE, "BTSetAgentProperty: Operation not valid. Returning FAILURE.");
}
#ifdef LIMBOAI_MODULE
get_agent()->set(property, result, &r_valid);
ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Couldn't set property \"%s\" with value \"%s\"", property, result));
#endif
#ifdef LIMBOAI_GDEXTENSION
get_agent()->set(property, result);
#endif
return SUCCESS;
}

View File

@ -14,8 +14,8 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_variant.h"
#include "modules/limboai/util/limbo_utility.h"
#include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../util/limbo_utility.h"
class BTSetAgentProperty : public BTAction {
GDCLASS(BTSetAgentProperty, BTAction);
@ -29,11 +29,11 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
void set_property(StringName p_prop);
StringName get_property() const { return property; }

View File

@ -17,7 +17,7 @@ void BTStopAnimation::set_animation_player(Ref<BBNode> p_animation_player) {
animation_player_param = p_animation_player;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) {
animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
@ -33,12 +33,12 @@ void BTStopAnimation::set_keep_state(bool p_keep_state) {
//**** Task Implementation
PackedStringArray BTStopAnimation::get_configuration_warnings() const {
PackedStringArray BTStopAnimation::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (animation_player_param.is_null()) {
warnings.append("Animation Player parameter is not set.");
} else {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) {
if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) {
warnings.append("Path to AnimationPlayer node is not set.");
} else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) {
warnings.append("AnimationPlayer blackboard variable is not set.");
@ -47,7 +47,7 @@ PackedStringArray BTStopAnimation::get_configuration_warnings() const {
return warnings;
}
String BTStopAnimation::_generate_name() const {
String BTStopAnimation::_generate_name() {
return "StopAnimation" +
(animation_name != StringName() ? vformat(" \"%s\"", animation_name) : "") +
(keep_state ? " keep_state: true" : "");

View File

@ -14,9 +14,15 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_node.h"
#include "../../../blackboard/bb_param/bb_node.h"
#ifdef LIMBOAI_MODULE
#include "scene/animation/animation_player.h"
#endif
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/animation_player.hpp>
#endif
class BTStopAnimation : public BTAction {
GDCLASS(BTStopAnimation, BTAction);
@ -33,7 +39,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _setup() override;
virtual Status _tick(double p_delta) override;
@ -47,7 +53,7 @@ public:
void set_keep_state(bool p_keep_state);
bool get_keep_state() const { return keep_state; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_STOP_ANIMATION

View File

@ -22,7 +22,7 @@ void BTCallMethod::set_node_param(Ref<BBNode> p_object) {
node_param = p_object;
emit_changed();
if (Engine::get_singleton()->is_editor_hint() && node_param.is_valid()) {
node_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed")));
node_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed)));
}
}
@ -38,14 +38,14 @@ void BTCallMethod::set_args(Array p_args) {
//**** Task Implementation
PackedStringArray BTCallMethod::get_configuration_warnings() const {
PackedStringArray BTCallMethod::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (method == StringName()) {
warnings.append("Method Name is not set.");
}
if (node_param.is_null()) {
warnings.append("Node parameter is not set.");
} else if (node_param->get_value_source() == BBParam::SAVED_VALUE && node_param->get_saved_value().is_zero()) {
} else if (node_param->get_value_source() == BBParam::SAVED_VALUE && node_param->get_saved_value() == Variant()) {
warnings.append("Path to node is not set.");
} else if (node_param->get_value_source() == BBParam::BLACKBOARD_VAR && node_param->get_variable() == StringName()) {
warnings.append("Node blackboard variable is not set.");
@ -53,13 +53,13 @@ PackedStringArray BTCallMethod::get_configuration_warnings() const {
return warnings;
}
String BTCallMethod::_generate_name() const {
String BTCallMethod::_generate_name() {
String args_str = include_delta ? "delta" : "";
if (args.size() > 0) {
if (!args_str.is_empty()) {
args_str += ", ";
}
args_str += Variant(args).get_construct_string().trim_prefix("[").trim_suffix("]");
args_str += vformat("%s", args).trim_prefix("[").trim_suffix("]");
}
return vformat("CallMethod %s(%s) node: %s",
(method != StringName() ? method : "???"),
@ -73,6 +73,7 @@ BT::Status BTCallMethod::_tick(double p_delta) {
Object *obj = node_param->get_value(get_agent(), get_blackboard());
ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string());
#ifdef LIMBOAI_MODULE
const Variant delta = include_delta ? Variant(p_delta) : Variant();
const Variant **argptrs = nullptr;
@ -92,6 +93,19 @@ BT::Status BTCallMethod::_tick(double p_delta) {
if (ce.error != Callable::CallError::CALL_OK) {
ERR_FAIL_V_MSG(FAILURE, "BTCallMethod: Error calling method: " + Variant::get_call_error_text(obj, method, argptrs, argument_count, ce) + ".");
}
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
Array call_args;
if (include_delta) {
call_args.push_back(Variant(p_delta));
call_args.append_array(args);
} else {
call_args = args;
}
// TODO: Unsure how to detect call error, so we return SUCCESS for now...
obj->callv(method, call_args);
#endif // LIMBOAI_GDEXTENSION
return SUCCESS;
}
@ -114,7 +128,7 @@ void BTCallMethod::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args");
ADD_PROPERTY_DEFAULT("args_include_delta", false);
// ADD_PROPERTY_DEFAULT("args_include_delta", false);
}
BTCallMethod::BTCallMethod() {

View File

@ -14,7 +14,7 @@
#include "../bt_action.h"
#include "modules/limboai/blackboard/bb_param/bb_node.h"
#include "../../limboai/blackboard/bb_param/bb_node.h"
class BTCallMethod : public BTAction {
GDCLASS(BTCallMethod, BTAction);
@ -29,7 +29,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
@ -45,7 +45,7 @@ public:
void set_include_delta(bool p_include_delta);
bool is_delta_included() const { return include_delta; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
BTCallMethod();
};

View File

@ -11,10 +11,7 @@
#include "bt_console_print.h"
#include "core/object/object.h"
#include "core/string/print_string.h"
String BTConsolePrint::_generate_name() const {
String BTConsolePrint::_generate_name() {
String tx = text;
if (text.length() > 30) {
tx = text.substr(0, 30) + "...";
@ -32,29 +29,29 @@ String BTConsolePrint::_generate_name() const {
BT::Status BTConsolePrint::_tick(double p_delta) {
switch (bb_format_parameters.size()) {
case 0: {
print_line(text);
PRINT_LINE(text);
} break;
case 1: {
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], "")));
PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], "")));
} break;
case 2: {
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
get_blackboard()->get_var(bb_format_parameters[1], "")));
} break;
case 3: {
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
get_blackboard()->get_var(bb_format_parameters[1], ""),
get_blackboard()->get_var(bb_format_parameters[2], "")));
} break;
case 4: {
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
get_blackboard()->get_var(bb_format_parameters[1], ""),
get_blackboard()->get_var(bb_format_parameters[2], ""),
get_blackboard()->get_var(bb_format_parameters[3], "")));
} break;
case 5:
default: {
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
get_blackboard()->get_var(bb_format_parameters[1], ""),
get_blackboard()->get_var(bb_format_parameters[2], ""),
get_blackboard()->get_var(bb_format_parameters[3], ""),
@ -64,7 +61,7 @@ BT::Status BTConsolePrint::_tick(double p_delta) {
return SUCCESS;
}
PackedStringArray BTConsolePrint::get_configuration_warnings() const {
PackedStringArray BTConsolePrint::get_configuration_warnings() {
PackedStringArray warnings = BTAction::get_configuration_warnings();
if (bb_format_parameters.size() > 5) {
warnings.append("ConsolePrint supports up to 5 format arguments.");

View File

@ -14,8 +14,6 @@
#include "../bt_action.h"
#include "core/variant/variant.h"
class BTConsolePrint : public BTAction {
GDCLASS(BTConsolePrint, BTAction);
TASK_CATEGORY(Utility);
@ -27,7 +25,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:
@ -43,7 +41,7 @@ public:
}
PackedStringArray get_bb_format_parameters() const { return bb_format_parameters; }
virtual PackedStringArray get_configuration_warnings() const override;
virtual PackedStringArray get_configuration_warnings() override;
};
#endif // BT_CONSOLE_PRINT_H

View File

@ -11,16 +11,14 @@
#include "bt_random_wait.h"
#include "core/math/math_funcs.h"
String BTRandomWait::_generate_name() const {
String BTRandomWait::_generate_name() {
return vformat("Wait %s to %s sec",
Math::snapped(min_duration, 0.001),
Math::snapped(max_duration, 0.001));
}
void BTRandomWait::_enter() {
duration = Math::random(min_duration, max_duration);
duration = RAND_RANGE(min_duration, max_duration);
}
BT::Status BTRandomWait::_tick(double p_delta) {

View File

@ -27,7 +27,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _enter() override;
virtual Status _tick(double p_delta) override;

View File

@ -11,12 +11,7 @@
#include "bt_wait.h"
#include "core/math/math_funcs.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
String BTWait::_generate_name() const {
String BTWait::_generate_name() {
return vformat("Wait %s sec", Math::snapped(duration, 0.001));
}

View File

@ -24,7 +24,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual Status _tick(double p_delta) override;
public:

View File

@ -11,10 +11,7 @@
#include "bt_wait_ticks.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
String BTWaitTicks::_generate_name() const {
String BTWaitTicks::_generate_name() {
return vformat("WaitTicks x%d", num_ticks);
}

View File

@ -26,7 +26,7 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const override;
virtual String _generate_name() override;
virtual void _enter() override;
virtual Status _tick(double p_delta) override;

32
util/limbo_def.h Normal file
View File

@ -0,0 +1,32 @@
#/**
* limbo_def.h
* =============================================================================
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
#ifdef LIMBOAI_MODULE
#include "core/string/print_string.h"
#define IS_CLASS(m_obj, m_class) (m_obj->is_class_ptr(m_class::get_class_ptr_static()))
#define RAND_RANGE(m_from, m_to) (Math::random(m_from, m_to))
#define RANDF() (Math::randf())
#define PRINT_LINE(...) (print_line(__VA_ARGS__))
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/variant/utility_functions.hpp>
#define IS_CLASS(m_obj, m_class) (m_obj->get_class_static() == m_class::get_class_static())
#define RAND_RANGE(m_from, m_to) (UtilityFunctions::randf_range(m_from, m_to))
#define RANDF() (UtilityFunctions::randf())
#define PRINT_LINE(...) (UtilityFunctions::print(__VA_ARGS__))
#endif // LIMBOAI_GDEXTENSION

View File

@ -28,4 +28,10 @@ LimboStringNames::LimboStringNames() {
_update = StringName("_update");
state_changed = StringName("state_changed");
_get_configuration_warning = StringName("_get_configuration_warning");
changed = StringName("changed");
changed = StringName("emit_changed");
_weight_ = StringName("_weight_");
error_value = StringName("error_value");
repeat_forever.parse_utf8("Repeat ∞");
}

View File

@ -53,6 +53,14 @@ public:
StringName _update;
StringName state_changed;
StringName _get_configuration_warning;
StringName changed;
StringName emit_changed;
StringName _weight_;
StringName error_value;
String repeat_forever;
};
#define LSNAME(m_arg) LimboStringNames::get_singleton()->m_arg
#endif // LIMBO_STRING_NAMES_H