2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_random_sequence.cpp
|
|
|
|
* =============================================================================
|
2024-01-06 23:47:46 +00:00
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
2023-07-21 09:50:06 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-08-29 09:41:42 +00:00
|
|
|
|
|
|
|
#include "bt_random_sequence.h"
|
|
|
|
|
|
|
|
void BTRandomSequence::_enter() {
|
|
|
|
last_running_idx = 0;
|
2022-12-17 10:47:10 +00:00
|
|
|
if (indicies.size() != get_child_count()) {
|
|
|
|
indicies.resize(get_child_count());
|
2022-08-29 09:41:42 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2024-01-06 23:47:46 +00:00
|
|
|
indicies[i] = i;
|
2022-08-29 09:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-17 10:47:10 +00:00
|
|
|
indicies.shuffle();
|
2022-08-29 09:41:42 +00:00
|
|
|
}
|
|
|
|
|
2023-09-19 11:43:26 +00:00
|
|
|
BT::Status BTRandomSequence::_tick(double p_delta) {
|
|
|
|
Status status = SUCCESS;
|
2022-09-05 13:08:35 +00:00
|
|
|
for (int i = last_running_idx; i < get_child_count(); i++) {
|
2022-12-17 10:47:10 +00:00
|
|
|
status = get_child(indicies[i])->execute(p_delta);
|
2022-08-29 09:41:42 +00:00
|
|
|
if (status != SUCCESS) {
|
|
|
|
last_running_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|