diff --git a/limboai/bt/bt_dynamic_selector.cpp b/limboai/bt/bt_dynamic_selector.cpp new file mode 100644 index 0000000..2e486e5 --- /dev/null +++ b/limboai/bt/bt_dynamic_selector.cpp @@ -0,0 +1,25 @@ +/* bt_dynamic_selector.cpp */ + +#include "bt_dynamic_selector.h" + +void BTDynamicSelector::_enter() { + last_running_idx = 0; +} + +int BTDynamicSelector::_tick(float p_delta) { + int status = SUCCESS; + int i; + for (i = 0; i < get_child_count(); i++) { + status = get_child(i)->execute(p_delta); + if (status != FAILURE) { + break; + } + } + // If the last node ticked is earlier in the tree than the previous runner, + // cancel previous runner. + if (last_running_idx > i && get_child(last_running_idx)->get_status() == RUNNING) { + get_child(last_running_idx)->cancel(); + } + last_running_idx = i; + return status; +} \ No newline at end of file diff --git a/limboai/bt/bt_dynamic_selector.h b/limboai/bt/bt_dynamic_selector.h new file mode 100644 index 0000000..65b251a --- /dev/null +++ b/limboai/bt/bt_dynamic_selector.h @@ -0,0 +1,20 @@ +/* bt_dynamic_selector.h */ + +#ifndef BT_DYNAMIC_SELECTOR_H +#define BT_DYNAMIC_SELECTOR_H + +#import "bt_composite.h" +#include "core/object.h" + +class BTDynamicSelector : public BTComposite { + GDCLASS(BTDynamicSelector, BTComposite); + +private: + int last_running_idx = 0; + +protected: + virtual void _enter(); + virtual int _tick(float p_delta); +}; + +#endif // BT_DYNAMIC_SELECTOR_H \ No newline at end of file diff --git a/limboai/bt/bt_dynamic_sequence.cpp b/limboai/bt/bt_dynamic_sequence.cpp new file mode 100644 index 0000000..e8c6833 --- /dev/null +++ b/limboai/bt/bt_dynamic_sequence.cpp @@ -0,0 +1,25 @@ +/* bt_dynamic_sequence.cpp */ + +#include "bt_dynamic_sequence.h" + +void BTDynamicSequence::_enter() { + last_running_idx = 0; +} + +int BTDynamicSequence::_tick(float p_delta) { + int status = SUCCESS; + int i; + for (i = 0; i < get_child_count(); i++) { + status = get_child(i)->execute(p_delta); + if (status != SUCCESS) { + break; + } + } + // If the last node ticked is earlier in the tree than the previous runner, + // cancel previous runner. + if (last_running_idx > i && get_child(last_running_idx)->get_status() == RUNNING) { + get_child(last_running_idx)->cancel(); + } + last_running_idx = i; + return status; +} \ No newline at end of file diff --git a/limboai/bt/bt_dynamic_sequence.h b/limboai/bt/bt_dynamic_sequence.h new file mode 100644 index 0000000..7ff2c64 --- /dev/null +++ b/limboai/bt/bt_dynamic_sequence.h @@ -0,0 +1,20 @@ +/* bt_dynamic_sequence.h */ + +#ifndef BT_DYNAMIC_SEQUENCE_H +#define BT_DYNAMIC_SEQUENCE_H + +#import "bt_composite.h" +#include "core/object.h" + +class BTDynamicSequence : public BTComposite { + GDCLASS(BTDynamicSequence, BTComposite); + +private: + int last_running_idx = 0; + +protected: + virtual void _enter(); + virtual int _tick(float p_delta); +}; + +#endif // BT_DYNAMIC_SEQUENCE_H \ No newline at end of file diff --git a/limboai/bt/bt_selector.cpp b/limboai/bt/bt_selector.cpp index 367f978..99ae5ef 100644 --- a/limboai/bt/bt_selector.cpp +++ b/limboai/bt/bt_selector.cpp @@ -7,7 +7,7 @@ void BTSelector::_enter() { } int BTSelector::_tick(float p_delta) { - int status = FRESH; + int status = FAILURE; for (int i = 0; i < get_child_count(); i++) { status = get_child(i)->execute(p_delta); if (status != FAILURE) { diff --git a/limboai/bt/bt_sequence.cpp b/limboai/bt/bt_sequence.cpp index 05b437c..f174711 100644 --- a/limboai/bt/bt_sequence.cpp +++ b/limboai/bt/bt_sequence.cpp @@ -7,7 +7,7 @@ void BTSequence::_enter() { } int BTSequence::_tick(float p_delta) { - int status = FRESH; + int status = SUCCESS; for (int i = 0; i < get_child_count(); i++) { status = get_child(i)->execute(p_delta); if (status != SUCCESS) { diff --git a/limboai/icons/icon_b_t_action.svg b/limboai/icons/icon_b_t_action.svg new file mode 100644 index 0000000..ed7cd17 --- /dev/null +++ b/limboai/icons/icon_b_t_action.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_condition.svg b/limboai/icons/icon_b_t_condition.svg new file mode 100644 index 0000000..b12b8d7 --- /dev/null +++ b/limboai/icons/icon_b_t_condition.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_decorator.svg b/limboai/icons/icon_b_t_decorator.svg new file mode 100644 index 0000000..b031a8b --- /dev/null +++ b/limboai/icons/icon_b_t_decorator.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_dynamic_selector.svg b/limboai/icons/icon_b_t_dynamic_selector.svg new file mode 100644 index 0000000..2fd14fa --- /dev/null +++ b/limboai/icons/icon_b_t_dynamic_selector.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_dynamic_sequence.svg b/limboai/icons/icon_b_t_dynamic_sequence.svg new file mode 100644 index 0000000..afdab24 --- /dev/null +++ b/limboai/icons/icon_b_t_dynamic_sequence.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_parallel.svg b/limboai/icons/icon_b_t_parallel.svg new file mode 100644 index 0000000..3f71bb2 --- /dev/null +++ b/limboai/icons/icon_b_t_parallel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_probability_selector.svg b/limboai/icons/icon_b_t_probability_selector.svg new file mode 100644 index 0000000..cedacf3 --- /dev/null +++ b/limboai/icons/icon_b_t_probability_selector.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_random_selector.svg b/limboai/icons/icon_b_t_random_selector.svg new file mode 100644 index 0000000..b110003 --- /dev/null +++ b/limboai/icons/icon_b_t_random_selector.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_random_sequence.svg b/limboai/icons/icon_b_t_random_sequence.svg new file mode 100644 index 0000000..260d2a3 --- /dev/null +++ b/limboai/icons/icon_b_t_random_sequence.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_selector.svg b/limboai/icons/icon_b_t_selector.svg new file mode 100644 index 0000000..b371bb0 --- /dev/null +++ b/limboai/icons/icon_b_t_selector.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/icons/icon_b_t_sequence.svg b/limboai/icons/icon_b_t_sequence.svg new file mode 100644 index 0000000..4729d46 --- /dev/null +++ b/limboai/icons/icon_b_t_sequence.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/limboai/register_types.cpp b/limboai/register_types.cpp index fc270f0..ba4277b 100644 --- a/limboai/register_types.cpp +++ b/limboai/register_types.cpp @@ -12,6 +12,8 @@ #include "bt/bt_cooldown.h" #include "bt/bt_decorator.h" #include "bt/bt_delay.h" +#include "bt/bt_dynamic_selector.h" +#include "bt/bt_dynamic_sequence.h" #include "bt/bt_invert.h" #include "bt/bt_parallel.h" #include "bt/bt_probability.h" @@ -35,8 +37,11 @@ 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(); ClassDB::register_class(); ClassDB::register_class(); @@ -48,6 +53,7 @@ void register_limboai_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + LimboStringNames::create(); }