diff --git a/blackboard/bb_param/bb_param.cpp b/blackboard/bb_param/bb_param.cpp index 3e65ee3..d4663fe 100644 --- a/blackboard/bb_param/bb_param.cpp +++ b/blackboard/bb_param/bb_param.cpp @@ -29,10 +29,6 @@ void BBParam::set_value_source(ValueSource p_value) { } Variant BBParam::get_saved_value() { - if (saved_value.get_type() != get_type()) { - Callable::CallError err; - Variant::construct(get_type(), saved_value, nullptr, 0, err); - } return saved_value; } @@ -50,7 +46,21 @@ void BBParam::set_variable(const String &p_value) { String BBParam::to_string() { if (value_source == SAVED_VALUE) { - return String(saved_value); + String s = saved_value.stringify(); + switch (get_type()) { + case Variant::STRING: { + s = s.c_escape().quote(); + } break; + case Variant::STRING_NAME: { + s = "&" + s.c_escape().quote(); + } break; + case Variant::NODE_PATH: { + s = "^" + s.c_escape().quote(); + } break; + default: { + } break; + } + return s; } else { return LimboUtility::get_singleton()->decorate_var(variable); } @@ -62,6 +72,7 @@ Variant BBParam::get_value(Object *p_agent, const Ref &p_blackboard, if (value_source == SAVED_VALUE) { return saved_value; } else { + ERR_FAIL_COND_V_MSG(!p_blackboard->has_var(variable), Variant(), vformat("BBParam: Blackboard variable doesn't exist: \"%s\".", p_default)); return p_blackboard->get_var(variable, p_default); } } @@ -84,7 +95,7 @@ void BBParam::_bind_methods() { ClassDB::bind_method(D_METHOD("get_type"), &BBParam::get_type); ClassDB::bind_method(D_METHOD("get_value", "p_agent", "p_blackboard", "p_default"), &BBParam::get_value, Variant()); - ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value, Blackboard Var"), "set_value_source", "get_value_source"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value,Blackboard Var"), "set_value_source", "get_value_source"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable"); ADD_PROPERTY(PropertyInfo(Variant::NIL, "saved_value", PROPERTY_HINT_NONE, "", 0), "set_saved_value", "get_saved_value"); @@ -95,5 +106,6 @@ void BBParam::_bind_methods() { BBParam::BBParam() { value_source = SAVED_VALUE; variable = ""; - saved_value = Variant(); + + _assign_default_value(); } diff --git a/blackboard/bb_param/bb_param.h b/blackboard/bb_param/bb_param.h index 343eb20..4a74e2d 100644 --- a/blackboard/bb_param/bb_param.h +++ b/blackboard/bb_param/bb_param.h @@ -43,6 +43,11 @@ protected: virtual Variant::Type get_type() const { return Variant::NIL; } + _FORCE_INLINE_ void _assign_default_value() { + Callable::CallError err; + Variant::construct(get_type(), saved_value, nullptr, 0, err); + } + void _get_property_list(List *p_list) const; public: diff --git a/blackboard/bb_param/bb_variant.cpp b/blackboard/bb_param/bb_variant.cpp index d27e727..2e92dc6 100644 --- a/blackboard/bb_param/bb_variant.cpp +++ b/blackboard/bb_param/bb_variant.cpp @@ -14,9 +14,18 @@ #include "core/variant/variant.h" void BBVariant::set_type(Variant::Type p_type) { - type = p_type; - notify_property_list_changed(); - emit_changed(); + if (type != p_type) { + type = p_type; + if (get_saved_value().get_type() != p_type) { + _assign_default_value(); + } + emit_changed(); + notify_property_list_changed(); + } +} + +Variant::Type BBVariant::get_type() const { + return type; } void BBVariant::_bind_methods() { @@ -33,5 +42,4 @@ void BBVariant::_bind_methods() { } BBVariant::BBVariant() { - type = Variant::NIL; } diff --git a/blackboard/bb_param/bb_variant.h b/blackboard/bb_param/bb_variant.h index f806233..d8664bd 100644 --- a/blackboard/bb_param/bb_variant.h +++ b/blackboard/bb_param/bb_variant.h @@ -20,12 +20,12 @@ class BBVariant : public BBParam { GDCLASS(BBVariant, BBParam); private: - Variant::Type type; + Variant::Type type = Variant::NIL; protected: static void _bind_methods(); - virtual Variant::Type get_type() const override { return type; } + virtual Variant::Type get_type() const override; void set_type(Variant::Type p_type); public: diff --git a/bt/actions/bt_console_print.cpp b/bt/actions/bt_console_print.cpp index 18b234f..3bc90ae 100644 --- a/bt/actions/bt_console_print.cpp +++ b/bt/actions/bt_console_print.cpp @@ -22,10 +22,13 @@ String BTConsolePrint::_generate_name() const { tx = text.substr(0, 30) + "..."; } tx = tx.replace("\"", "\\\""); + tx = tx.replace("\r", "\\r"); + tx = tx.replace("\t", "\\t"); + tx = tx.replace("\n", "\\n"); if (bb_format_parameters.size() > 0) { - return vformat("ConsolePrint text: \"%s\" format_parameters: %s", tx, bb_format_parameters); + return vformat("ConsolePrint text: \"%s\" params: %s", tx, bb_format_parameters); } - return vformat("ConsolePrint \"%s\"", tx); + return vformat("ConsolePrint text: \"%s\"", tx); } int BTConsolePrint::_tick(double p_delta) { diff --git a/bt/actions/bt_set_agent_property.cpp b/bt/actions/bt_set_agent_property.cpp new file mode 100644 index 0000000..a204f98 --- /dev/null +++ b/bt/actions/bt_set_agent_property.cpp @@ -0,0 +1,68 @@ +/** + * bt_set_agent_property.cpp + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#include "bt_set_agent_property.h" + +void BTSetAgentProperty::set_property_name(StringName p_prop) { + property_name = p_prop; + emit_changed(); +} + +void BTSetAgentProperty::set_value(Ref 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"))); + } +} + +String BTSetAgentProperty::get_configuration_warning() const { + String warning = BTAction::get_configuration_warning(); + if (!warning.is_empty()) { + warning += "\n"; + } + if (property_name == StringName()) { + warning += "`property_name` should be assigned.\n"; + } + if (!value.is_valid()) { + warning += "`value` should be assigned.\n"; + } + return warning; +} + +String BTSetAgentProperty::_generate_name() const { + if (property_name == StringName()) { + return "SetAgentProperty ???"; + } + + return vformat("Set agent.%s = %s", property_name, + value.is_valid() ? Variant(value) : Variant("???")); +} + +int BTSetAgentProperty::_tick(double p_delta) { + ERR_FAIL_COND_V_MSG(property_name == StringName(), FAILURE, "BTSetAgentProperty: `property_name` is not set."); + ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetAgentProperty: `value` is not set."); + + bool r_valid; + get_agent()->set(property_name, value->get_value(get_agent(), get_blackboard()), &r_valid); + ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Agent doesn't have property named \"%s\"", property_name)); + return SUCCESS; +} + +void BTSetAgentProperty::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_property_name", "p_property_name"), &BTSetAgentProperty::set_property_name); + ClassDB::bind_method(D_METHOD("get_property_name"), &BTSetAgentProperty::get_property_name); + ClassDB::bind_method(D_METHOD("set_value", "p_value"), &BTSetAgentProperty::set_value); + ClassDB::bind_method(D_METHOD("get_value"), &BTSetAgentProperty::get_value); + + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "property_name"), "set_property_name", "get_property_name"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "BBVariant"), "set_value", "get_value"); +} diff --git a/bt/actions/bt_set_agent_property.h b/bt/actions/bt_set_agent_property.h new file mode 100644 index 0000000..5b7d8a8 --- /dev/null +++ b/bt/actions/bt_set_agent_property.h @@ -0,0 +1,45 @@ +/** + * bt_set_agent_property.h + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#ifndef BT_SET_AGENT_PROPERTY_H +#define BT_SET_AGENT_PROPERTY_H + +#include "modules/limboai/bt/actions/bt_action.h" + +#include "modules/limboai/blackboard/bb_param/bb_variant.h" + +#include "core/object/class_db.h" +#include "core/object/object.h" + +class BTSetAgentProperty : public BTAction { + GDCLASS(BTSetAgentProperty, BTAction); + +private: + StringName property_name; + Ref value; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const override; + virtual int _tick(double p_delta) override; + +public: + virtual String get_configuration_warning() const override; + + void set_property_name(StringName p_prop); + StringName get_property_name() const { return property_name; } + + void set_value(Ref p_value); + Ref get_value() const { return value; } +}; + +#endif // BT_SET_AGENT_PROPERTY \ No newline at end of file diff --git a/bt/actions/bt_set_var.cpp b/bt/actions/bt_set_var.cpp new file mode 100644 index 0000000..561dc7e --- /dev/null +++ b/bt/actions/bt_set_var.cpp @@ -0,0 +1,68 @@ +/** + * bt_set_var.cpp + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#include "bt_set_var.h" + +#include "modules/limboai/util/limbo_utility.h" + +#include "core/variant/callable.h" + +String BTSetVar::_generate_name() const { + if (variable.is_empty()) { + return "SetVar ???"; + } + return vformat("Set %s = %s", LimboUtility::get_singleton()->decorate_var(variable), + value.is_valid() ? Variant(value) : Variant("???")); +} + +int BTSetVar::_tick(double p_delta) { + ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BBSetVar: `variable` is not set."); + ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BBSetVar: `value` is not set."); + get_blackboard()->set_var(variable, value->get_value(get_agent(), get_blackboard())); + return SUCCESS; +}; + +void BTSetVar::set_variable(const String &p_variable) { + variable = p_variable; + emit_changed(); +} + +void BTSetVar::set_value(Ref 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"))); + } +} + +String BTSetVar::get_configuration_warning() const { + String warning = BTAction::get_configuration_warning(); + if (!warning.is_empty()) { + warning += "\n"; + } + if (variable.is_empty()) { + warning += "`variable` should be assigned.\n"; + } + if (!value.is_valid()) { + warning += "`value` should be assigned.\n"; + } + return warning; +} + +void BTSetVar::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_variable", "p_variable"), &BTSetVar::set_variable); + ClassDB::bind_method(D_METHOD("get_variable"), &BTSetVar::get_variable); + ClassDB::bind_method(D_METHOD("set_value", "p_value"), &BTSetVar::set_value); + ClassDB::bind_method(D_METHOD("get_value"), &BTSetVar::get_value); + + ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable"), "set_variable", "get_variable"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "BBVariant"), "set_value", "get_value"); +} diff --git a/bt/actions/bt_set_var.h b/bt/actions/bt_set_var.h new file mode 100644 index 0000000..f2f679f --- /dev/null +++ b/bt/actions/bt_set_var.h @@ -0,0 +1,46 @@ +/** + * bt_set_var.h + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ +/* bt_set_var.h */ + +#ifndef BT_SET_VAR_H +#define BT_SET_VAR_H + +#include "../actions/bt_action.h" + +#include "../../blackboard/bb_param/bb_variant.h" + +#include "core/object/object.h" +#include "core/string/ustring.h" + +class BTSetVar : public BTAction { + GDCLASS(BTSetVar, BTAction); + +private: + String variable; + Ref value; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const override; + virtual int _tick(double p_delta) override; + +public: + virtual String get_configuration_warning() const override; + + void set_variable(const String &p_variable); + String get_variable() const { return variable; } + + void set_value(Ref p_value); + Ref get_value() const { return value; } +}; + +#endif // BT_SET_VAR \ No newline at end of file diff --git a/bt/conditions/bt_check_agent_property.cpp b/bt/conditions/bt_check_agent_property.cpp new file mode 100644 index 0000000..fc4a07a --- /dev/null +++ b/bt/conditions/bt_check_agent_property.cpp @@ -0,0 +1,84 @@ +/** + * bt_check_agent_property.cpp + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#include "bt_check_agent_property.h" + +#include "modules/limboai/util/limbo_utility.h" + +#include "core/variant/callable.h" + +void BTCheckAgentProperty::set_property_name(StringName p_prop) { + property_name = p_prop; + emit_changed(); +} + +void BTCheckAgentProperty::set_check_type(LimboUtility::CheckType p_check_type) { + check_type = p_check_type; + emit_changed(); +} + +void BTCheckAgentProperty::set_value(Ref 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"))); + } +} + +String BTCheckAgentProperty::get_configuration_warning() const { + String warning = BTCondition::get_configuration_warning(); + if (!warning.is_empty()) { + warning += "\n"; + } + if (property_name == StringName()) { + warning += "`property_name` should be assigned.\n"; + } + if (!value.is_valid()) { + warning += "`value` should be assigned.\n"; + } + return warning; +} + +String BTCheckAgentProperty::_generate_name() const { + if (property_name == StringName()) { + return "CheckAgentProperty ???"; + } + + return vformat("Check if: agent.%s %s %s", property_name, + LimboUtility::get_singleton()->get_check_operator_string(check_type), + value.is_valid() ? Variant(value) : Variant("???")); +} + +int BTCheckAgentProperty::_tick(double p_delta) { + ERR_FAIL_COND_V_MSG(property_name == StringName(), FAILURE, "BTCheckAgentProperty: `property_name` is not set."); + ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckAgentProperty: `value` is not set."); + + bool r_valid; + Variant left_value = get_agent()->get(property_name, &r_valid); + ERR_FAIL_COND_V_MSG(r_valid == false, FAILURE, vformat("BTCheckAgentProperty: Agent has no property named \"%s\"", property_name)); + + Variant right_value = value->get_value(get_agent(), get_blackboard()); + + return LimboUtility::get_singleton()->perform_check(check_type, left_value, right_value) ? SUCCESS : FAILURE; +} + +void BTCheckAgentProperty::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_property_name", "p_property_name"), &BTCheckAgentProperty::set_property_name); + ClassDB::bind_method(D_METHOD("get_property_name"), &BTCheckAgentProperty::get_property_name); + ClassDB::bind_method(D_METHOD("set_check_type", "p_check_type"), &BTCheckAgentProperty::set_check_type); + ClassDB::bind_method(D_METHOD("get_check_type"), &BTCheckAgentProperty::get_check_type); + ClassDB::bind_method(D_METHOD("set_value", "p_value"), &BTCheckAgentProperty::set_value); + ClassDB::bind_method(D_METHOD("get_value"), &BTCheckAgentProperty::get_value); + + ADD_PROPERTY(PropertyInfo(Variant::STRING, "property_name"), "set_property_name", "get_property_name"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "check_type", PROPERTY_HINT_ENUM, "Equal,Less Than,Less Than Or Equal,Greater Than,Greater Than Or Equal,Not Equal"), "set_check_type", "get_check_type"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "BBVariant"), "set_value", "get_value"); +} diff --git a/bt/conditions/bt_check_agent_property.h b/bt/conditions/bt_check_agent_property.h new file mode 100644 index 0000000..10a9fc2 --- /dev/null +++ b/bt/conditions/bt_check_agent_property.h @@ -0,0 +1,50 @@ +/** + * bt_check_agent_property.h + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#ifndef BT_CHECK_AGENT_PROPERTY +#define BT_CHECK_AGENT_PROPERTY + +#include "bt_condition.h" + +#include "modules/limboai/blackboard/bb_param/bb_variant.h" +#include "modules/limboai/util/limbo_utility.h" + +#include "core/object/object.h" +#include "core/string/string_name.h" + +class BTCheckAgentProperty : public BTCondition { + GDCLASS(BTCheckAgentProperty, BTCondition); + +private: + StringName property_name; + LimboUtility::CheckType check_type = LimboUtility::CheckType::CHECK_EQUAL; + Ref value; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const override; + virtual int _tick(double p_delta) override; + +public: + virtual String get_configuration_warning() const override; + + void set_property_name(StringName p_prop); + StringName get_property_name() const { return property_name; } + + void set_check_type(LimboUtility::CheckType p_check_type); + LimboUtility::CheckType get_check_type() const { return check_type; } + + void set_value(Ref p_value); + Ref get_value() const { return value; } +}; + +#endif // BT_CHECK_AGENT_PROPERTY \ No newline at end of file diff --git a/bt/conditions/bt_check_trigger.cpp b/bt/conditions/bt_check_trigger.cpp new file mode 100644 index 0000000..517bd19 --- /dev/null +++ b/bt/conditions/bt_check_trigger.cpp @@ -0,0 +1,45 @@ +/** + * bt_check_trigger.cpp + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#include "bt_check_trigger.h" + +#include "modules/limboai/util/limbo_utility.h" + +#include "core/variant/variant.h" + +void BTCheckTrigger::set_variable(String p_variable) { + variable = p_variable; + emit_changed(); +} + +String BTCheckTrigger::_generate_name() const { + if (variable.is_empty()) { + return "CheckTrigger ???"; + } + return "CheckTrigger " + LimboUtility::get_singleton()->decorate_var(variable); +} + +int BTCheckTrigger::_tick(double p_delta) { + ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BBCheckVar: `variable` is not set."); + Variant trigger_value = get_blackboard()->get_var(variable, false); + if (trigger_value == Variant(true)) { + get_blackboard()->set_var(variable, false); + return SUCCESS; + } + return FAILURE; +} + +void BTCheckTrigger::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_variable", "p_variable"), &BTCheckTrigger::set_variable); + ClassDB::bind_method(D_METHOD("get_variable"), &BTCheckTrigger::get_variable); + + ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable"), "set_variable", "get_variable"); +} diff --git a/bt/conditions/bt_check_trigger.h b/bt/conditions/bt_check_trigger.h new file mode 100644 index 0000000..aed4cc7 --- /dev/null +++ b/bt/conditions/bt_check_trigger.h @@ -0,0 +1,41 @@ +/** + * bt_check_trigger.h + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +/* bt_check_trigger.h */ + +#ifndef BT_CHECK_TRIGGER_H +#define BT_CHECK_TRIGGER_H + +#include "bt_condition.h" + +#include "core/object/object.h" +#include "core/string/ustring.h" + +#include "core/object/class_db.h" + +class BTCheckTrigger : public BTCondition { + GDCLASS(BTCheckTrigger, BTCondition); + +private: + String variable; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const override; + virtual int _tick(double p_delta) override; + +public: + void set_variable(String p_variable); + String get_variable() const { return variable; } +}; + +#endif // BT_CHECK_TRIGGER \ No newline at end of file diff --git a/bt/conditions/bt_check_var.cpp b/bt/conditions/bt_check_var.cpp new file mode 100644 index 0000000..86c141b --- /dev/null +++ b/bt/conditions/bt_check_var.cpp @@ -0,0 +1,83 @@ +/** + * bt_check_var.cpp + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#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(); +} + +void BTCheckVar::set_check_type(LimboUtility::CheckType p_check_type) { + check_type = p_check_type; + emit_changed(); +} + +void BTCheckVar::set_value(Ref 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"))); + } +} + +String BTCheckVar::get_configuration_warning() const { + String warning = BTCondition::get_configuration_warning(); + if (!warning.is_empty()) { + warning += "\n"; + } + if (variable.is_empty()) { + warning += "`variable` should be assigned.\n"; + } + if (!value.is_valid()) { + warning += "`value` should be assigned.\n"; + } + return warning; +} + +String BTCheckVar::_generate_name() const { + if (variable.is_empty()) { + return "CheckVar ???"; + } + + return vformat("Check if: %s %s %s", LimboUtility::get_singleton()->decorate_var(variable), + LimboUtility::get_singleton()->get_check_operator_string(check_type), + value.is_valid() ? Variant(value) : Variant("???")); +} + +int BTCheckVar::_tick(double p_delta) { + ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BTCheckVar: `variable` is not set."); + ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckVar: `value` is not set."); + + ERR_FAIL_COND_V_MSG(!get_blackboard()->has_var(variable), FAILURE, vformat("BTCheckVar: Blackboard variable doesn't exist: \"%s\". Returning FAILURE.", variable)); + + Variant left_value = get_blackboard()->get_var(variable, Variant()); + Variant right_value = value->get_value(get_agent(), get_blackboard()); + + return LimboUtility::get_singleton()->perform_check(check_type, left_value, right_value) ? SUCCESS : FAILURE; +} + +void BTCheckVar::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_variable", "p_variable"), &BTCheckVar::set_variable); + ClassDB::bind_method(D_METHOD("get_variable"), &BTCheckVar::get_variable); + ClassDB::bind_method(D_METHOD("set_check_type", "p_check_type"), &BTCheckVar::set_check_type); + ClassDB::bind_method(D_METHOD("get_check_type"), &BTCheckVar::get_check_type); + ClassDB::bind_method(D_METHOD("set_value", "p_value"), &BTCheckVar::set_value); + ClassDB::bind_method(D_METHOD("get_value"), &BTCheckVar::get_value); + + ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable"), "set_variable", "get_variable"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "check_type", PROPERTY_HINT_ENUM, "Equal,Less Than,Less Than Or Equal,Greater Than,Greater Than Or Equal,Not Equal"), "set_check_type", "get_check_type"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "BBVariant"), "set_value", "get_value"); +} diff --git a/bt/conditions/bt_check_var.h b/bt/conditions/bt_check_var.h new file mode 100644 index 0000000..1268ea4 --- /dev/null +++ b/bt/conditions/bt_check_var.h @@ -0,0 +1,50 @@ +/** + * bt_check_var.h + * ============================================================================= + * Copyright 2021-2023 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. + * ============================================================================= + */ + +#ifndef BT_CHECK_VAR_H +#define BT_CHECK_VAR_H + +#include "bt_condition.h" + +#include "modules/limboai/blackboard/bb_param/bb_variant.h" +#include "modules/limboai/util/limbo_utility.h" + +#include "core/object/class_db.h" +#include "core/object/object.h" + +class BTCheckVar : public BTCondition { + GDCLASS(BTCheckVar, BTCondition); + +private: + String variable; + LimboUtility::CheckType check_type = LimboUtility::CheckType::CHECK_EQUAL; + Ref value; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const override; + virtual int _tick(double p_delta) override; + +public: + virtual String get_configuration_warning() const override; + + void set_variable(String p_variable); + String get_variable() const { return variable; } + + void set_check_type(LimboUtility::CheckType p_check_type); + LimboUtility::CheckType get_check_type() const { return check_type; } + + void set_value(Ref p_value); + Ref get_value() const { return value; } +}; + +#endif // BT_CHECK_VAR_H \ No newline at end of file diff --git a/config.py b/config.py index 8ceb56a..8ddd132 100644 --- a/config.py +++ b/config.py @@ -60,6 +60,9 @@ def get_doc_classes(): "BTAction", "BTAlwaysFail", "BTAlwaysSucceed", + "BTCheckAgentProperty", + "BTCheckTrigger", + "BTCheckVar", "BTComposite", "BTCondition", "BTConsolePrint", @@ -84,6 +87,8 @@ def get_doc_classes(): "BTRunLimit", "BTSelector", "BTSequence", + "BTSetAgentProperty", + "BTSetVar", "BTState", "BTSubtree", "BTTask", diff --git a/demo/ai/trees/variables.tres b/demo/ai/trees/variables.tres new file mode 100644 index 0000000..2fbc380 --- /dev/null +++ b/demo/ai/trees/variables.tres @@ -0,0 +1,53 @@ +[gd_resource type="BehaviorTree" load_steps=13 format=3 uid="uid://cvm3gqes75f53"] + +[sub_resource type="BBVariant" id="BBVariant_t70f2"] +resource_name = "false" +saved_value = false +type = 1 + +[sub_resource type="BTSetVar" id="BTSetVar_nxwdg"] +variable = "triggered" +value = SubResource("BBVariant_t70f2") + +[sub_resource type="BTRunLimit" id="BTRunLimit_mlytb"] +children = [SubResource("BTSetVar_nxwdg")] + +[sub_resource type="BBVariant" id="BBVariant_8bpg1"] +resource_name = "false" +saved_value = false +type = 1 + +[sub_resource type="BTCheckVar" id="BTCheckVar_g5b0s"] +variable = "triggered" +value = SubResource("BBVariant_8bpg1") + +[sub_resource type="BBVariant" id="BBVariant_loenl"] +resource_name = "true" +saved_value = true +type = 1 + +[sub_resource type="BTSetVar" id="BTSetVar_u051c"] +variable = "triggered" +value = SubResource("BBVariant_loenl") + +[sub_resource type="BBVariant" id="BBVariant_cu1uc"] +resource_name = "Hello, World!" +saved_value = "Hello, World!" +type = 4 + +[sub_resource type="BTSetVar" id="BTSetVar_2e0uw"] +variable = "message" +value = SubResource("BBVariant_cu1uc") + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_533ui"] +text = "Message is: %s" +bb_format_parameters = PackedStringArray("message") + +[sub_resource type="BTSequence" id="BTSequence_bhar3"] +children = [SubResource("BTCheckVar_g5b0s"), SubResource("BTSetVar_u051c"), SubResource("BTSetVar_2e0uw"), SubResource("BTConsolePrint_533ui")] + +[sub_resource type="BTSelector" id="BTSelector_ndrjh"] +children = [SubResource("BTRunLimit_mlytb"), SubResource("BTSequence_bhar3")] + +[resource] +root_task = SubResource("BTSelector_ndrjh") diff --git a/demo/examples/variables/variables.tscn b/demo/examples/variables/variables.tscn new file mode 100644 index 0000000..0f955f7 --- /dev/null +++ b/demo/examples/variables/variables.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=3 uid="uid://d4bjeyescflm8"] + +[ext_resource type="BehaviorTree" uid="uid://cvm3gqes75f53" path="res://ai/trees/variables.tres" id="1_tq7fc"] + +[node name="Variables Example" type="Node2D"] + +[node name="BTPlayer" type="BTPlayer" parent="."] +behavior_tree = ExtResource("1_tq7fc") diff --git a/demo/tests/agent_properties/agent_properties.gd b/demo/tests/agent_properties/agent_properties.gd new file mode 100644 index 0000000..9369a23 --- /dev/null +++ b/demo/tests/agent_properties/agent_properties.gd @@ -0,0 +1,3 @@ +extends Node2D + +@export var speed: float = 200.0 diff --git a/demo/tests/agent_properties/agent_properties.tscn b/demo/tests/agent_properties/agent_properties.tscn new file mode 100644 index 0000000..9309aeb --- /dev/null +++ b/demo/tests/agent_properties/agent_properties.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://c3d3ed6545cly"] + +[ext_resource type="Script" path="res://tests/agent_properties/agent_properties.gd" id="1_jh88u"] +[ext_resource type="BehaviorTree" uid="uid://ddhxf0haxgw" path="res://tests/agent_properties/bt_agent_properties.tres" id="2_txe8k"] + +[node name="AgentProperties" type="Node2D"] +script = ExtResource("1_jh88u") + +[node name="BTPlayer" type="BTPlayer" parent="."] +behavior_tree = ExtResource("2_txe8k") diff --git a/demo/tests/agent_properties/bt_agent_properties.tres b/demo/tests/agent_properties/bt_agent_properties.tres new file mode 100644 index 0000000..0477333 --- /dev/null +++ b/demo/tests/agent_properties/bt_agent_properties.tres @@ -0,0 +1,109 @@ +[gd_resource type="BehaviorTree" load_steps=29 format=3 uid="uid://ddhxf0haxgw"] + +[sub_resource type="BBVariant" id="BBVariant_5o8fh"] +resource_name = "200" +saved_value = 200.0 +type = 3 + +[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_0nprx"] +property_name = &"speed" +value = SubResource("BBVariant_5o8fh") + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_dlmwi"] +text = "Test 1: Passed" + +[sub_resource type="BTSequence" id="BTSequence_fou4d"] +children = [SubResource("BTCheckAgentProperty_0nprx"), SubResource("BTConsolePrint_dlmwi")] + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_ggvml"] +text = "Test 1: Failed" + +[sub_resource type="BTSelector" id="BTSelector_hw3on"] +custom_name = "Test 1" +children = [SubResource("BTSequence_fou4d"), SubResource("BTConsolePrint_ggvml")] + +[sub_resource type="BBVariant" id="BBVariant_r2elk"] +resource_name = "300" +saved_value = 300.0 +type = 3 + +[sub_resource type="BTSetAgentProperty" id="BTSetAgentProperty_lh1xy"] +property_name = &"speed" +value = SubResource("BBVariant_r2elk") + +[sub_resource type="BBVariant" id="BBVariant_jhcxn"] +resource_name = "200" +saved_value = 200.0 +type = 3 + +[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_p20lt"] +property_name = &"speed" +check_type = 3 +value = SubResource("BBVariant_jhcxn") + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_nb21y"] +text = "Test 2: Passed" + +[sub_resource type="BTSequence" id="BTSequence_rp57i"] +children = [SubResource("BTCheckAgentProperty_p20lt"), SubResource("BTConsolePrint_nb21y")] + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_o5xxa"] +text = "Test 2: Failed" + +[sub_resource type="BTSelector" id="BTSelector_cr664"] +custom_name = "Test 2" +children = [SubResource("BTSequence_rp57i"), SubResource("BTConsolePrint_o5xxa")] + +[sub_resource type="BBVariant" id="BBVariant_2aotu"] +resource_name = "400" +saved_value = 400.0 +type = 3 + +[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_avnfr"] +property_name = &"speed" +check_type = 1 +value = SubResource("BBVariant_2aotu") + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_wgw5j"] +text = "Test 3: Passed" + +[sub_resource type="BTSequence" id="BTSequence_ykp38"] +children = [SubResource("BTCheckAgentProperty_avnfr"), SubResource("BTConsolePrint_wgw5j")] + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_0eshq"] +text = "Test 3: Failed" + +[sub_resource type="BTSelector" id="BTSelector_nxupw"] +custom_name = "Test 3" +children = [SubResource("BTSequence_ykp38"), SubResource("BTConsolePrint_0eshq")] + +[sub_resource type="BBVariant" id="BBVariant_28e2y"] +resource_name = "300" +saved_value = 300.0 +type = 3 + +[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_sayma"] +property_name = &"speed" +value = SubResource("BBVariant_28e2y") + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_xugph"] +text = "Test 4: Passed" + +[sub_resource type="BTSequence" id="BTSequence_3wj0i"] +children = [SubResource("BTCheckAgentProperty_sayma"), SubResource("BTConsolePrint_xugph")] + +[sub_resource type="BTConsolePrint" id="BTConsolePrint_16vkj"] +text = "Test 4: Failed" + +[sub_resource type="BTSelector" id="BTSelector_qhmh3"] +custom_name = "Test 4" +children = [SubResource("BTSequence_3wj0i"), SubResource("BTConsolePrint_16vkj")] + +[sub_resource type="BTSequence" id="BTSequence_7bmj1"] +children = [SubResource("BTSelector_hw3on"), SubResource("BTSetAgentProperty_lh1xy"), SubResource("BTSelector_cr664"), SubResource("BTSelector_nxupw"), SubResource("BTSelector_qhmh3")] + +[sub_resource type="BTRunLimit" id="BTRunLimit_034mk"] +children = [SubResource("BTSequence_7bmj1")] + +[resource] +root_task = SubResource("BTRunLimit_034mk") diff --git a/doc_classes/BBAabb.xml b/doc_classes/BBAabb.xml index 55c3f88..9c840c5 100644 --- a/doc_classes/BBAabb.xml +++ b/doc_classes/BBAabb.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBArray.xml b/doc_classes/BBArray.xml index 66afe7a..888d87a 100644 --- a/doc_classes/BBArray.xml +++ b/doc_classes/BBArray.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBBasis.xml b/doc_classes/BBBasis.xml index 7539fa1..001b8ce 100644 --- a/doc_classes/BBBasis.xml +++ b/doc_classes/BBBasis.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBBool.xml b/doc_classes/BBBool.xml index 14c630f..b1ffc27 100644 --- a/doc_classes/BBBool.xml +++ b/doc_classes/BBBool.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBByteArray.xml b/doc_classes/BBByteArray.xml index d43447d..7de0d39 100644 --- a/doc_classes/BBByteArray.xml +++ b/doc_classes/BBByteArray.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBColor.xml b/doc_classes/BBColor.xml index e914c40..b876695 100644 --- a/doc_classes/BBColor.xml +++ b/doc_classes/BBColor.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBColorArray.xml b/doc_classes/BBColorArray.xml index 2be9f14..0a11dfe 100644 --- a/doc_classes/BBColorArray.xml +++ b/doc_classes/BBColorArray.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBDictionary.xml b/doc_classes/BBDictionary.xml index 69786b8..0c5827e 100644 --- a/doc_classes/BBDictionary.xml +++ b/doc_classes/BBDictionary.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBFloat.xml b/doc_classes/BBFloat.xml index df9f5a7..06aeda7 100644 --- a/doc_classes/BBFloat.xml +++ b/doc_classes/BBFloat.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBFloatArray.xml b/doc_classes/BBFloatArray.xml index b32bcd7..fd39ed0 100644 --- a/doc_classes/BBFloatArray.xml +++ b/doc_classes/BBFloatArray.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBIntArray.xml b/doc_classes/BBIntArray.xml index 765420a..e67d4ac 100644 --- a/doc_classes/BBIntArray.xml +++ b/doc_classes/BBIntArray.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBNode.xml b/doc_classes/BBNode.xml index c53e9f6..9a932b7 100644 --- a/doc_classes/BBNode.xml +++ b/doc_classes/BBNode.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBParam.xml b/doc_classes/BBParam.xml index a1d546d..e00b665 100644 --- a/doc_classes/BBParam.xml +++ b/doc_classes/BBParam.xml @@ -28,7 +28,7 @@ - + A value that is saved with BBParam resource. The type of value is defined by [method get_type]. Provides the parameter's value, if [member value_source] is [constant SAVED_VALUE]. diff --git a/doc_classes/BBPlane.xml b/doc_classes/BBPlane.xml index 4cdc40d..266b76d 100644 --- a/doc_classes/BBPlane.xml +++ b/doc_classes/BBPlane.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBQuaternion.xml b/doc_classes/BBQuaternion.xml index 553a876..7dd0513 100644 --- a/doc_classes/BBQuaternion.xml +++ b/doc_classes/BBQuaternion.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBRect2.xml b/doc_classes/BBRect2.xml index 4105dc4..a7a03fd 100644 --- a/doc_classes/BBRect2.xml +++ b/doc_classes/BBRect2.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBRect2i.xml b/doc_classes/BBRect2i.xml index 188b919..0fb39fe 100644 --- a/doc_classes/BBRect2i.xml +++ b/doc_classes/BBRect2i.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBString.xml b/doc_classes/BBString.xml index 96829aa..e26656c 100644 --- a/doc_classes/BBString.xml +++ b/doc_classes/BBString.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBStringArray.xml b/doc_classes/BBStringArray.xml index 11e1186..4897383 100644 --- a/doc_classes/BBStringArray.xml +++ b/doc_classes/BBStringArray.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBStringName.xml b/doc_classes/BBStringName.xml index 9596ded..20662ac 100644 --- a/doc_classes/BBStringName.xml +++ b/doc_classes/BBStringName.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBTransform2D.xml b/doc_classes/BBTransform2D.xml index 4496eb4..7b0145e 100644 --- a/doc_classes/BBTransform2D.xml +++ b/doc_classes/BBTransform2D.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBTransform3D.xml b/doc_classes/BBTransform3D.xml index 300c50c..b9c906a 100644 --- a/doc_classes/BBTransform3D.xml +++ b/doc_classes/BBTransform3D.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBVariant.xml b/doc_classes/BBVariant.xml index 8d3b970..8b3dfdc 100644 --- a/doc_classes/BBVariant.xml +++ b/doc_classes/BBVariant.xml @@ -8,7 +8,6 @@ - diff --git a/doc_classes/BBVector2.xml b/doc_classes/BBVector2.xml index 17e0f51..26c13b0 100644 --- a/doc_classes/BBVector2.xml +++ b/doc_classes/BBVector2.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBVector2Array.xml b/doc_classes/BBVector2Array.xml index f762e8b..057559e 100644 --- a/doc_classes/BBVector2Array.xml +++ b/doc_classes/BBVector2Array.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBVector2i.xml b/doc_classes/BBVector2i.xml index bac866f..eb42234 100644 --- a/doc_classes/BBVector2i.xml +++ b/doc_classes/BBVector2i.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBVector3.xml b/doc_classes/BBVector3.xml index f670b96..b81681a 100644 --- a/doc_classes/BBVector3.xml +++ b/doc_classes/BBVector3.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBVector3Array.xml b/doc_classes/BBVector3Array.xml index 27f0509..0ccc593 100644 --- a/doc_classes/BBVector3Array.xml +++ b/doc_classes/BBVector3Array.xml @@ -7,7 +7,4 @@ - - - diff --git a/doc_classes/BBVector3i.xml b/doc_classes/BBVector3i.xml index 3bd7fb3..ba06bd5 100644 --- a/doc_classes/BBVector3i.xml +++ b/doc_classes/BBVector3i.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBVector4.xml b/doc_classes/BBVector4.xml index 2e92fd3..35f23b3 100644 --- a/doc_classes/BBVector4.xml +++ b/doc_classes/BBVector4.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BBVector4i.xml b/doc_classes/BBVector4i.xml index 5477ae8..504f90b 100644 --- a/doc_classes/BBVector4i.xml +++ b/doc_classes/BBVector4i.xml @@ -6,7 +6,4 @@ - - - diff --git a/doc_classes/BTCheckAgentProperty.xml b/doc_classes/BTCheckAgentProperty.xml new file mode 100644 index 0000000..f2abc2c --- /dev/null +++ b/doc_classes/BTCheckAgentProperty.xml @@ -0,0 +1,22 @@ + + + + BT condition that checks agent's property value. + + + BTCheckAgentProperty checks agent's property value against [member value] and returns [code]SUCCESS[/code] or [code]FAILURE[/code] based on the [member check_type]. + + + + + + Type of check to perform. + + + Parameter that specifies the agent's property name which will be compared. + + + Parameter that specifies the value to which an agent's property will be compared. + + + diff --git a/doc_classes/BTCheckTrigger.xml b/doc_classes/BTCheckTrigger.xml new file mode 100644 index 0000000..24ce704 --- /dev/null +++ b/doc_classes/BTCheckTrigger.xml @@ -0,0 +1,17 @@ + + + + BT condition that checks a trigger (a boolean variable). + + + BTCheckTrigger verifies whether the [member variable] is set to [code]true[/code]. If it is, the task changes it to [code]false[/code] and returns [code]SUCCESS[/code]. Otherwise, it returns [code]FAILURE[/code]. + + + + + + A boolean variable on the blackboard that is used as a trigger. + When it is set to [code]true[/code], BTCheckTrigger will flip it to [code]false[/code] and return [code]SUCCESS[/code]. Otherwise, it will return [code]FAILURE[/code]. + + + diff --git a/doc_classes/BTCheckVar.xml b/doc_classes/BTCheckVar.xml new file mode 100644 index 0000000..11494c6 --- /dev/null +++ b/doc_classes/BTCheckVar.xml @@ -0,0 +1,22 @@ + + + + BT condition that checks a variable on the blackboard. + + + BTCheckVar checks [member variable] against [member value] and returns [code]SUCCESS[/code] or [code]FAILURE[/code] based on the [member check_type]. + + + + + + Type of check to perform. + + + Parameter that specifies the value to which the [member variable] will be compared. + + + Variable name to check its value. + + + diff --git a/doc_classes/BTRepeat.xml b/doc_classes/BTRepeat.xml index a0edb45..a5c9c68 100644 --- a/doc_classes/BTRepeat.xml +++ b/doc_classes/BTRepeat.xml @@ -16,7 +16,7 @@ If [code]false[/code], [code]FAILURE[/code] status returned by the child is also considered a successfully finished execution. - If [code]true[/code], the child's execution will be repeated indefinitely, always returning [code]RUNNING[/code]. + If [code]true[/code], the child's execution will be repeated indefinitely, always returning [code]RUNNING[/code]. A number of times to repeat an execution of the child task. diff --git a/doc_classes/BTSetAgentProperty.xml b/doc_classes/BTSetAgentProperty.xml new file mode 100644 index 0000000..aa5e7e0 --- /dev/null +++ b/doc_classes/BTSetAgentProperty.xml @@ -0,0 +1,20 @@ + + + + BT action that assigns a value to agent's property. + + + BTSetAgentProperty assigns the specified [member value] to the agent's property identified by the [member property_name] and returns [code]SUCCESS[/code]. + Returns [code]FAILURE[/code] if it fails to set the property. + + + + + + Parameter that specifies the agent's property name. + + + Parameter that specifies the value that will be assigned to agent's property. + + + diff --git a/doc_classes/BTSetVar.xml b/doc_classes/BTSetVar.xml new file mode 100644 index 0000000..4850546 --- /dev/null +++ b/doc_classes/BTSetVar.xml @@ -0,0 +1,18 @@ + + + + BT action that assigns [member value] to the [member variable] and then returns [code]SUCCESS[/code]. + + + + + + + + Parameter that specifies the value to be assigned to the variable. + + + Variable name whose value is to be assigned. + + + diff --git a/doc_classes/LimboUtility.xml b/doc_classes/LimboUtility.xml index a5ff636..3edb3b8 100644 --- a/doc_classes/LimboUtility.xml +++ b/doc_classes/LimboUtility.xml @@ -30,4 +30,18 @@ + + + + + + + + + + + + + + diff --git a/icons/BTCheckAgentProperty.svg b/icons/BTCheckAgentProperty.svg new file mode 100644 index 0000000..6c869c3 --- /dev/null +++ b/icons/BTCheckAgentProperty.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/BTCheckTrigger.svg b/icons/BTCheckTrigger.svg new file mode 100644 index 0000000..2a59673 --- /dev/null +++ b/icons/BTCheckTrigger.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/BTCheckVar.svg b/icons/BTCheckVar.svg new file mode 100644 index 0000000..150a4f2 --- /dev/null +++ b/icons/BTCheckVar.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/BTSetAgentProperty.svg b/icons/BTSetAgentProperty.svg new file mode 100644 index 0000000..c92a710 --- /dev/null +++ b/icons/BTSetAgentProperty.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/BTSetVar.svg b/icons/BTSetVar.svg new file mode 100644 index 0000000..09f6822 --- /dev/null +++ b/icons/BTSetVar.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/register_types.cpp b/register_types.cpp index 5c4c24a..80a3074 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -48,6 +48,8 @@ #include "bt/actions/bt_console_print.h" #include "bt/actions/bt_fail.h" #include "bt/actions/bt_random_wait.h" +#include "bt/actions/bt_set_agent_property.h" +#include "bt/actions/bt_set_var.h" #include "bt/actions/bt_wait.h" #include "bt/actions/bt_wait_ticks.h" #include "bt/behavior_tree.h" @@ -62,6 +64,9 @@ #include "bt/composites/bt_random_sequence.h" #include "bt/composites/bt_selector.h" #include "bt/composites/bt_sequence.h" +#include "bt/conditions/bt_check_agent_property.h" +#include "bt/conditions/bt_check_trigger.h" +#include "bt/conditions/bt_check_var.h" #include "bt/conditions/bt_condition.h" #include "bt/decorators/bt_always_fail.h" #include "bt/decorators/bt_always_succeed.h" @@ -99,6 +104,7 @@ void initialize_limboai_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) { LimboDebugger::initialize(); + GDREGISTER_CLASS(LimboUtility); GDREGISTER_CLASS(Blackboard); GDREGISTER_CLASS(LimboState); @@ -133,15 +139,20 @@ void initialize_limboai_module(ModuleInitializationLevel p_level) { GDREGISTER_CLASS(BTForEach); GDREGISTER_CLASS(BTAction); - GDREGISTER_CLASS(BTFail); - GDREGISTER_CLASS(BTWait); - GDREGISTER_CLASS(BTRandomWait); - GDREGISTER_CLASS(BTWaitTicks); - GDREGISTER_CLASS(BTNewScope); - GDREGISTER_CLASS(BTSubtree); GDREGISTER_CLASS(BTConsolePrint); + GDREGISTER_CLASS(BTFail); + GDREGISTER_CLASS(BTNewScope); + GDREGISTER_CLASS(BTRandomWait); + GDREGISTER_CLASS(BTSetAgentProperty); + GDREGISTER_CLASS(BTSetVar); + GDREGISTER_CLASS(BTSubtree); + GDREGISTER_CLASS(BTWait); + GDREGISTER_CLASS(BTWaitTicks); GDREGISTER_CLASS(BTCondition); + GDREGISTER_CLASS(BTCheckAgentProperty); + GDREGISTER_CLASS(BTCheckTrigger); + GDREGISTER_CLASS(BTCheckVar); GDREGISTER_ABSTRACT_CLASS(BBParam); GDREGISTER_CLASS(BBInt); @@ -178,7 +189,6 @@ void initialize_limboai_module(ModuleInitializationLevel p_level) { GDREGISTER_CLASS(BBVariant); _limbo_utility = memnew(LimboUtility); - GDREGISTER_CLASS(LimboUtility); Engine::get_singleton()->add_singleton(Engine::Singleton("LimboUtility", LimboUtility::get_singleton())); LimboStringNames::create(); diff --git a/util/limbo_utility.cpp b/util/limbo_utility.cpp index 27d8c76..2594b77 100644 --- a/util/limbo_utility.cpp +++ b/util/limbo_utility.cpp @@ -58,17 +58,91 @@ Ref LimboUtility::get_task_icon(String p_class_or_script_path) const Ref