diff --git a/limboai/SCsub b/limboai/SCsub index e208d38..f332202 100644 --- a/limboai/SCsub +++ b/limboai/SCsub @@ -2,4 +2,5 @@ Import('env') -env.add_source_files(env.modules_sources, "*.cpp") # Add all cpp files to the build +env.add_source_files(env.modules_sources, "*.cpp") +env.add_source_files(env.modules_sources, "bt/*.cpp") diff --git a/limboai/bt_action.cpp b/limboai/bt/bt_action.cpp similarity index 100% rename from limboai/bt_action.cpp rename to limboai/bt/bt_action.cpp diff --git a/limboai/bt_action.h b/limboai/bt/bt_action.h similarity index 100% rename from limboai/bt_action.h rename to limboai/bt/bt_action.h diff --git a/limboai/bt_always_fail.cpp b/limboai/bt/bt_always_fail.cpp similarity index 100% rename from limboai/bt_always_fail.cpp rename to limboai/bt/bt_always_fail.cpp diff --git a/limboai/bt_always_fail.h b/limboai/bt/bt_always_fail.h similarity index 100% rename from limboai/bt_always_fail.h rename to limboai/bt/bt_always_fail.h diff --git a/limboai/bt_always_succeed.cpp b/limboai/bt/bt_always_succeed.cpp similarity index 100% rename from limboai/bt_always_succeed.cpp rename to limboai/bt/bt_always_succeed.cpp diff --git a/limboai/bt_always_succeed.h b/limboai/bt/bt_always_succeed.h similarity index 100% rename from limboai/bt_always_succeed.h rename to limboai/bt/bt_always_succeed.h diff --git a/limboai/bt_composite.cpp b/limboai/bt/bt_composite.cpp similarity index 100% rename from limboai/bt_composite.cpp rename to limboai/bt/bt_composite.cpp diff --git a/limboai/bt_composite.h b/limboai/bt/bt_composite.h similarity index 100% rename from limboai/bt_composite.h rename to limboai/bt/bt_composite.h diff --git a/limboai/bt_condition.cpp b/limboai/bt/bt_condition.cpp similarity index 100% rename from limboai/bt_condition.cpp rename to limboai/bt/bt_condition.cpp diff --git a/limboai/bt_condition.h b/limboai/bt/bt_condition.h similarity index 100% rename from limboai/bt_condition.h rename to limboai/bt/bt_condition.h diff --git a/limboai/bt_cooldown.cpp b/limboai/bt/bt_cooldown.cpp similarity index 100% rename from limboai/bt_cooldown.cpp rename to limboai/bt/bt_cooldown.cpp diff --git a/limboai/bt_cooldown.h b/limboai/bt/bt_cooldown.h similarity index 100% rename from limboai/bt_cooldown.h rename to limboai/bt/bt_cooldown.h diff --git a/limboai/bt_decorator.cpp b/limboai/bt/bt_decorator.cpp similarity index 100% rename from limboai/bt_decorator.cpp rename to limboai/bt/bt_decorator.cpp diff --git a/limboai/bt_decorator.h b/limboai/bt/bt_decorator.h similarity index 100% rename from limboai/bt_decorator.h rename to limboai/bt/bt_decorator.h diff --git a/limboai/bt_delay.cpp b/limboai/bt/bt_delay.cpp similarity index 100% rename from limboai/bt_delay.cpp rename to limboai/bt/bt_delay.cpp diff --git a/limboai/bt_delay.h b/limboai/bt/bt_delay.h similarity index 100% rename from limboai/bt_delay.h rename to limboai/bt/bt_delay.h diff --git a/limboai/bt_invert.cpp b/limboai/bt/bt_invert.cpp similarity index 100% rename from limboai/bt_invert.cpp rename to limboai/bt/bt_invert.cpp diff --git a/limboai/bt_invert.h b/limboai/bt/bt_invert.h similarity index 100% rename from limboai/bt_invert.h rename to limboai/bt/bt_invert.h diff --git a/limboai/bt_parallel.cpp b/limboai/bt/bt_parallel.cpp similarity index 100% rename from limboai/bt_parallel.cpp rename to limboai/bt/bt_parallel.cpp diff --git a/limboai/bt_parallel.h b/limboai/bt/bt_parallel.h similarity index 100% rename from limboai/bt_parallel.h rename to limboai/bt/bt_parallel.h diff --git a/limboai/bt/bt_probability.cpp b/limboai/bt/bt_probability.cpp new file mode 100644 index 0000000..e70c2fc --- /dev/null +++ b/limboai/bt/bt_probability.cpp @@ -0,0 +1,21 @@ +/* bt_probability.cpp */ + +#include "bt_probability.h" +#include "core/object.h" + +String BTProbability::_generate_name() const { + return vformat("Probability %.1f%%", run_chance); +} + +int BTProbability::_tick(float p_delta) { + if (get_child(0)->get_status() == RUNNING or Math::randf() <= run_chance) { + return get_child(0)->execute(p_delta); + } + return FAILURE; +} + +void BTProbability::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_run_chance", "p_value"), &BTProbability::set_run_chance); + ClassDB::bind_method(D_METHOD("get_run_chance"), &BTProbability::get_run_chance); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "run_chance", PROPERTY_HINT_RANGE, "0.0,1.0"), "set_run_chance", "get_run_chance"); +} diff --git a/limboai/bt/bt_probability.h b/limboai/bt/bt_probability.h new file mode 100644 index 0000000..3e73202 --- /dev/null +++ b/limboai/bt/bt_probability.h @@ -0,0 +1,29 @@ +/* bt_probability.h */ + +#ifndef BT_PROBABILITY_H +#define BT_PROBABILITY_H + +#include "bt_decorator.h" +#include "core/object.h" + +class BTProbability : public BTDecorator { + GDCLASS(BTProbability, BTDecorator); + +private: + float run_chance = 0.5; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const; + virtual int _tick(float p_delta); + +public: + void set_run_chance(float p_value) { + run_chance = p_value; + emit_changed(); + } + float get_run_chance() const { return run_chance; } +}; + +#endif // BT_PROBABILITY_H \ No newline at end of file diff --git a/limboai/bt_repeat.cpp b/limboai/bt/bt_repeat.cpp similarity index 100% rename from limboai/bt_repeat.cpp rename to limboai/bt/bt_repeat.cpp diff --git a/limboai/bt_repeat.h b/limboai/bt/bt_repeat.h similarity index 100% rename from limboai/bt_repeat.h rename to limboai/bt/bt_repeat.h diff --git a/limboai/bt_repeat_until_failure.cpp b/limboai/bt/bt_repeat_until_failure.cpp similarity index 100% rename from limboai/bt_repeat_until_failure.cpp rename to limboai/bt/bt_repeat_until_failure.cpp diff --git a/limboai/bt_repeat_until_failure.h b/limboai/bt/bt_repeat_until_failure.h similarity index 100% rename from limboai/bt_repeat_until_failure.h rename to limboai/bt/bt_repeat_until_failure.h diff --git a/limboai/bt_repeat_until_success.cpp b/limboai/bt/bt_repeat_until_success.cpp similarity index 100% rename from limboai/bt_repeat_until_success.cpp rename to limboai/bt/bt_repeat_until_success.cpp diff --git a/limboai/bt_repeat_until_success.h b/limboai/bt/bt_repeat_until_success.h similarity index 100% rename from limboai/bt_repeat_until_success.h rename to limboai/bt/bt_repeat_until_success.h diff --git a/limboai/bt_run_limit.cpp b/limboai/bt/bt_run_limit.cpp similarity index 100% rename from limboai/bt_run_limit.cpp rename to limboai/bt/bt_run_limit.cpp diff --git a/limboai/bt_run_limit.h b/limboai/bt/bt_run_limit.h similarity index 100% rename from limboai/bt_run_limit.h rename to limboai/bt/bt_run_limit.h diff --git a/limboai/bt_selector.cpp b/limboai/bt/bt_selector.cpp similarity index 100% rename from limboai/bt_selector.cpp rename to limboai/bt/bt_selector.cpp diff --git a/limboai/bt_selector.h b/limboai/bt/bt_selector.h similarity index 100% rename from limboai/bt_selector.h rename to limboai/bt/bt_selector.h diff --git a/limboai/bt_sequence.cpp b/limboai/bt/bt_sequence.cpp similarity index 100% rename from limboai/bt_sequence.cpp rename to limboai/bt/bt_sequence.cpp diff --git a/limboai/bt_sequence.h b/limboai/bt/bt_sequence.h similarity index 100% rename from limboai/bt_sequence.h rename to limboai/bt/bt_sequence.h diff --git a/limboai/bt_task.cpp b/limboai/bt/bt_task.cpp similarity index 98% rename from limboai/bt_task.cpp rename to limboai/bt/bt_task.cpp index dd2d166..94ca285 100644 --- a/limboai/bt_task.cpp +++ b/limboai/bt/bt_task.cpp @@ -8,8 +8,8 @@ #include "core/variant.h" #include "editor/editor_node.h" -#include "limbo_string_names.h" -#include "limbo_utility.h" +#include "../limbo_string_names.h" +#include "../limbo_utility.h" String BTTask::_generate_name() const { if (get_script_instance()) { @@ -23,7 +23,7 @@ String BTTask::_generate_name() const { return name; } } - return get_class(); + return get_class().trim_prefix("BT"); } Array BTTask::_get_children() const { diff --git a/limboai/bt_task.h b/limboai/bt/bt_task.h similarity index 100% rename from limboai/bt_task.h rename to limboai/bt/bt_task.h diff --git a/limboai/bt_time_limit.cpp b/limboai/bt/bt_time_limit.cpp similarity index 100% rename from limboai/bt_time_limit.cpp rename to limboai/bt/bt_time_limit.cpp diff --git a/limboai/bt_time_limit.h b/limboai/bt/bt_time_limit.h similarity index 100% rename from limboai/bt_time_limit.h rename to limboai/bt/bt_time_limit.h diff --git a/limboai/register_types.cpp b/limboai/register_types.cpp index b4d76cf..fc270f0 100644 --- a/limboai/register_types.cpp +++ b/limboai/register_types.cpp @@ -4,24 +4,25 @@ #include "core/class_db.h" -#include "bt_action.h" -#include "bt_always_fail.h" -#include "bt_always_succeed.h" -#include "bt_composite.h" -#include "bt_condition.h" -#include "bt_cooldown.h" -#include "bt_decorator.h" -#include "bt_delay.h" -#include "bt_invert.h" -#include "bt_parallel.h" -#include "bt_repeat.h" -#include "bt_repeat_until_failure.h" -#include "bt_repeat_until_success.h" -#include "bt_run_limit.h" -#include "bt_selector.h" -#include "bt_sequence.h" -#include "bt_task.h" -#include "bt_time_limit.h" +#include "bt/bt_action.h" +#include "bt/bt_always_fail.h" +#include "bt/bt_always_succeed.h" +#include "bt/bt_composite.h" +#include "bt/bt_condition.h" +#include "bt/bt_cooldown.h" +#include "bt/bt_decorator.h" +#include "bt/bt_delay.h" +#include "bt/bt_invert.h" +#include "bt/bt_parallel.h" +#include "bt/bt_probability.h" +#include "bt/bt_repeat.h" +#include "bt/bt_repeat_until_failure.h" +#include "bt/bt_repeat_until_success.h" +#include "bt/bt_run_limit.h" +#include "bt/bt_selector.h" +#include "bt/bt_sequence.h" +#include "bt/bt_task.h" +#include "bt/bt_time_limit.h" #include "limbo_string_names.h" #include "limbo_utility.h" @@ -46,6 +47,7 @@ void register_limboai_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); LimboStringNames::create(); } diff --git a/limboai/register_types.h b/limboai/register_types.h index 8417c05..b91530c 100644 --- a/limboai/register_types.h +++ b/limboai/register_types.h @@ -1,4 +1,9 @@ /* register_types.h */ +#ifndef LIMBOAI_REGISTER_TYPES_H +#define LIMBOAI_REGISTER_TYPES_H + void register_limboai_types(); void unregister_limboai_types(); + +#endif // LIMBOAI_REGISTER_TYPES_H