2022-08-28 10:54:34 +00:00
|
|
|
/* bt_task.h */
|
|
|
|
|
|
|
|
#ifndef BTTASK_H
|
|
|
|
#define BTTASK_H
|
|
|
|
|
|
|
|
#include "core/array.h"
|
|
|
|
#include "core/dictionary.h"
|
2022-08-31 15:05:25 +00:00
|
|
|
#include "core/object.h"
|
2022-08-28 10:54:34 +00:00
|
|
|
#include "core/reference.h"
|
|
|
|
#include "core/resource.h"
|
|
|
|
#include "core/ustring.h"
|
|
|
|
#include "core/vector.h"
|
2022-09-08 13:56:51 +00:00
|
|
|
#include "modules/limboai/blackboard.h"
|
2022-08-28 10:54:34 +00:00
|
|
|
#include "scene/resources/texture.h"
|
|
|
|
|
|
|
|
class BTTask : public Resource {
|
|
|
|
GDCLASS(BTTask, Resource);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
FRESH,
|
|
|
|
RUNNING,
|
|
|
|
FAILURE,
|
|
|
|
SUCCESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-08-30 16:48:49 +00:00
|
|
|
friend class BehaviorTree;
|
|
|
|
|
2022-08-31 15:05:25 +00:00
|
|
|
String custom_name;
|
|
|
|
Object *agent;
|
2022-09-08 13:56:51 +00:00
|
|
|
Ref<Blackboard> blackboard;
|
2022-08-31 15:05:25 +00:00
|
|
|
BTTask *parent;
|
|
|
|
Vector<Ref<BTTask>> children;
|
|
|
|
int status;
|
2022-08-28 10:54:34 +00:00
|
|
|
|
|
|
|
Array _get_children() const;
|
|
|
|
void _set_children(Array children);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
virtual String _generate_name() const;
|
2022-08-31 15:05:25 +00:00
|
|
|
virtual void _setup() {}
|
|
|
|
virtual void _enter() {}
|
|
|
|
virtual void _exit() {}
|
|
|
|
virtual int _tick(float p_delta) { return FAILURE; }
|
2022-08-28 10:54:34 +00:00
|
|
|
|
|
|
|
public:
|
2022-08-31 15:05:25 +00:00
|
|
|
Object *get_agent() const { return agent; }
|
2022-09-08 13:56:51 +00:00
|
|
|
Ref<Blackboard> get_blackboard() const { return blackboard; }
|
2022-08-31 15:05:25 +00:00
|
|
|
Ref<BTTask> get_parent() const { return Ref<BTTask>(parent); }
|
|
|
|
bool is_root() const { return parent == nullptr; }
|
2022-08-28 10:54:34 +00:00
|
|
|
Ref<BTTask> get_root() const;
|
2022-08-31 15:05:25 +00:00
|
|
|
int get_status() const { return status; }
|
|
|
|
String get_custom_name() const { return custom_name; }
|
2022-08-28 10:54:34 +00:00
|
|
|
void set_custom_name(const String &p_name);
|
|
|
|
String get_task_name() const;
|
|
|
|
|
2022-09-08 13:56:51 +00:00
|
|
|
void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
|
2022-08-28 10:54:34 +00:00
|
|
|
virtual Ref<BTTask> clone() const;
|
|
|
|
int execute(float p_delta);
|
|
|
|
void cancel();
|
|
|
|
Ref<BTTask> get_child(int p_idx) const;
|
|
|
|
int get_child_count() const;
|
|
|
|
void add_child(Ref<BTTask> p_child);
|
|
|
|
void add_child_at_index(Ref<BTTask> p_child, int p_idx);
|
|
|
|
void remove_child(Ref<BTTask> p_child);
|
|
|
|
bool has_child(const Ref<BTTask> &p_child) const;
|
2022-09-03 15:00:20 +00:00
|
|
|
bool is_descendant_of(const Ref<BTTask> &p_task) const;
|
2022-08-28 10:54:34 +00:00
|
|
|
int get_child_index(const Ref<BTTask> &p_child) const;
|
|
|
|
Ref<BTTask> next_sibling() const;
|
|
|
|
virtual String get_configuration_warning() const;
|
2022-09-05 14:39:40 +00:00
|
|
|
// virtual Ref<Texture> get_icon() const;
|
2022-08-28 10:54:34 +00:00
|
|
|
void print_tree(int p_initial_tabs = 0) const;
|
|
|
|
|
|
|
|
BTTask();
|
2022-08-30 16:48:49 +00:00
|
|
|
~BTTask();
|
2022-08-28 10:54:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BTTASK_H
|