2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_new_scope.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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-09-20 17:15:48 +00:00
|
|
|
|
|
|
|
#include "bt_new_scope.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
|
|
|
|
#include "modules/limboai/blackboard/blackboard.h"
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/error/error_macros.h"
|
2022-11-01 13:03:20 +00:00
|
|
|
#include "core/os/memory.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/string/ustring.h"
|
2022-09-20 17:15:48 +00:00
|
|
|
|
2022-12-17 07:33:18 +00:00
|
|
|
void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) {
|
2022-09-20 17:15:48 +00:00
|
|
|
ERR_FAIL_COND(p_agent == nullptr);
|
|
|
|
ERR_FAIL_COND(p_blackboard == nullptr);
|
2022-11-01 13:03:20 +00:00
|
|
|
|
2022-09-20 17:15:48 +00:00
|
|
|
Ref<Blackboard> bb = memnew(Blackboard);
|
2022-11-01 13:03:20 +00:00
|
|
|
|
|
|
|
bb->set_data(blackboard_data.duplicate());
|
2022-09-20 17:15:48 +00:00
|
|
|
bb->set_parent_scope(p_blackboard);
|
2022-11-01 13:03:20 +00:00
|
|
|
|
2022-09-20 17:15:48 +00:00
|
|
|
BTDecorator::initialize(p_agent, bb);
|
|
|
|
}
|
|
|
|
|
2023-04-10 08:08:11 +00:00
|
|
|
int BTNewScope::_tick(double p_delta) {
|
2022-09-21 10:37:19 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
2022-09-20 17:15:48 +00:00
|
|
|
return get_child(0)->execute(p_delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BTNewScope::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("_set_blackboard_data", "p_data"), &BTNewScope::_set_blackboard_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("_get_blackboard_data"), &BTNewScope::_get_blackboard_data);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_blackboard_data"), "_set_blackboard_data", "_get_blackboard_data");
|
|
|
|
}
|