diff --git a/limboai/bt_always_fail.cpp b/limboai/bt_always_fail.cpp new file mode 100644 index 0000000..6dc112c --- /dev/null +++ b/limboai/bt_always_fail.cpp @@ -0,0 +1,10 @@ +/* bt_always_fail.cpp */ + +#include "bt_always_fail.h" + +int BTAlwaysFail::_tick(float p_delta) { + if (get_child(0)->execute(p_delta) == RUNNING) { + return RUNNING; + } + return FAILURE; +} diff --git a/limboai/bt_always_fail.h b/limboai/bt_always_fail.h new file mode 100644 index 0000000..e67a101 --- /dev/null +++ b/limboai/bt_always_fail.h @@ -0,0 +1,16 @@ +/* bt_always_fail.h */ + +#ifndef BT_ALWAYS_FAIL_H +#define BT_ALWAYS_FAIL_H + +#include "bt_decorator.h" +#include "core/object.h" + +class BTAlwaysFail : public BTDecorator { + GDCLASS(BTAlwaysFail, BTDecorator); + +protected: + virtual int _tick(float p_delta); +}; + +#endif // BT_ALWAYS_FAIL_H \ No newline at end of file diff --git a/limboai/bt_always_succeed.cpp b/limboai/bt_always_succeed.cpp new file mode 100644 index 0000000..a7beb03 --- /dev/null +++ b/limboai/bt_always_succeed.cpp @@ -0,0 +1,10 @@ +/* bt_always_succeed.cpp */ + +#include "bt_always_succeed.h" + +int BTAlwaysSucceed::_tick(float p_delta) { + if (get_child(0)->execute(p_delta) == RUNNING) { + return RUNNING; + } + return SUCCESS; +} diff --git a/limboai/bt_always_succeed.h b/limboai/bt_always_succeed.h new file mode 100644 index 0000000..58a4179 --- /dev/null +++ b/limboai/bt_always_succeed.h @@ -0,0 +1,16 @@ +/* bt_always_succeed.h */ + +#ifndef BT_ALWAYS_SUCCEED_H +#define BT_ALWAYS_SUCCEED_H + +#include "bt_decorator.h" +#include "core/object.h" + +class BTAlwaysSucceed : public BTDecorator { + GDCLASS(BTAlwaysSucceed, BTDecorator); + +protected: + virtual int _tick(float p_delta); +}; + +#endif // BT_ALWAYS_SUCCEED_H \ No newline at end of file diff --git a/limboai/bt_delay.cpp b/limboai/bt_delay.cpp new file mode 100644 index 0000000..53153f1 --- /dev/null +++ b/limboai/bt_delay.cpp @@ -0,0 +1,29 @@ +/* bt_delay.cpp */ + +#include "bt_delay.h" +#include "core/array.h" +#include "core/class_db.h" +#include "core/object.h" +#include "core/variant.h" + +String BTDelay::_generate_name() const { + return vformat("Delay %ss", seconds); +} + +void BTDelay::_enter() { + time_passed = 0.0; +} + +int BTDelay::_tick(float p_delta) { + time_passed += p_delta; + if (time_passed <= seconds) { + return RUNNING; + } + return get_child(0)->execute(p_delta); +} + +void BTDelay::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_seconds", "p_value"), &BTDelay::set_seconds); + ClassDB::bind_method(D_METHOD("get_seconds"), &BTDelay::get_seconds); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "seconds"), "set_seconds", "get_seconds"); +} diff --git a/limboai/bt_delay.h b/limboai/bt_delay.h new file mode 100644 index 0000000..1919445 --- /dev/null +++ b/limboai/bt_delay.h @@ -0,0 +1,31 @@ +/* bt_delay.h */ + +#ifndef BT_DELAY +#define BT_DELAY + +#include "bt_decorator.h" +#include "core/object.h" + +class BTDelay : public BTDecorator { + GDCLASS(BTDelay, BTDecorator); + +private: + float seconds = 1.0; + float time_passed = 0.0; + +protected: + static void _bind_methods(); + + virtual String _generate_name() const; + virtual void _enter(); + virtual int _tick(float p_delta); + +public: + void set_seconds(float p_value) { + seconds = p_value; + emit_changed(); + }; + float get_seconds() const { return seconds; }; +}; + +#endif // BT_DELAY \ No newline at end of file diff --git a/limboai/bt_invert.cpp b/limboai/bt_invert.cpp new file mode 100644 index 0000000..7bf90ef --- /dev/null +++ b/limboai/bt_invert.cpp @@ -0,0 +1,13 @@ +/* bt_invert.cpp */ + +#include "bt_invert.h" + +int BTInvert::_tick(float p_delta) { + int status = get_child(0)->execute(p_delta); + if (status == SUCCESS) { + status = FAILURE; + } else if (status == FAILURE) { + status = SUCCESS; + } + return status; +} \ No newline at end of file diff --git a/limboai/bt_invert.h b/limboai/bt_invert.h new file mode 100644 index 0000000..6f8875a --- /dev/null +++ b/limboai/bt_invert.h @@ -0,0 +1,16 @@ +/* bt_invert.h */ + +#ifndef BT_INVERT_H +#define BT_INVERT_H + +#include "bt_decorator.h" +#include "core/object.h" + +class BTInvert : public BTDecorator { + GDCLASS(BTInvert, BTDecorator); + +protected: + virtual int _tick(float p_delta); +}; + +#endif // BT_INVERT_H \ No newline at end of file diff --git a/limboai/register_types.cpp b/limboai/register_types.cpp index 813b14f..050b873 100644 --- a/limboai/register_types.cpp +++ b/limboai/register_types.cpp @@ -5,9 +5,13 @@ #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_decorator.h" +#include "bt_delay.h" +#include "bt_invert.h" #include "bt_parallel.h" #include "bt_selector.h" #include "bt_sequence.h" @@ -24,6 +28,10 @@ void register_limboai_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); LimboStringNames::create(); }