limboai/bt/bt_task.h

98 lines
2.5 KiB
C
Raw Normal View History

2022-08-28 10:54:34 +00:00
/* bt_task.h */
#ifndef BTTASK_H
#define BTTASK_H
#include "core/io/resource.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/string/ustring.h"
#include "core/templates/vector.h"
#include "core/variant/array.h"
#include "core/variant/dictionary.h"
#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:
friend class BehaviorTree;
2022-08-31 15:05:25 +00:00
String custom_name;
2022-12-17 07:33:18 +00:00
Node *agent;
Ref<Blackboard> blackboard;
2022-08-31 15:05:25 +00:00
BTTask *parent;
Vector<Ref<BTTask>> children;
int status;
double elapsed;
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(double p_delta) { return FAILURE; }
2022-08-28 10:54:34 +00:00
GDVIRTUAL0RC(String, _generate_name);
GDVIRTUAL0(_setup);
GDVIRTUAL0(_enter);
GDVIRTUAL0(_exit);
GDVIRTUAL1R(int, _tick, double);
GDVIRTUAL0RC(String, _get_configuration_warning);
2022-08-28 10:54:34 +00:00
public:
virtual bool editor_can_reload_from_file() override { return false; }
2022-12-17 07:33:18 +00:00
Node *get_agent() const { return agent; }
void set_agent(Node *p_agent) { agent = p_agent; }
2022-08-31 15:05:25 +00:00
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-12-17 07:33:18 +00:00
Ref<Blackboard> get_blackboard() const { return blackboard; }
Ref<BTTask> get_parent() const { return Ref<BTTask>(parent); }
Ref<BTTask> get_root() const;
bool is_root() const { return parent == nullptr; }
2022-08-28 10:54:34 +00:00
virtual Ref<BTTask> clone() const;
2022-12-17 07:33:18 +00:00
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard);
virtual String get_configuration_warning() const;
int execute(double p_delta);
2022-08-28 10:54:34 +00:00
void cancel();
2022-12-17 07:33:18 +00:00
int get_status() const { return status; }
double get_elapsed_time() const { return elapsed; };
2022-12-17 07:33:18 +00:00
2022-08-28 10:54:34 +00:00
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);
2022-09-21 14:13:17 +00:00
void remove_child_at_index(int p_idx);
2022-08-28 10:54:34 +00:00
bool has_child(const Ref<BTTask> &p_child) const;
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;
2022-12-17 07:33:18 +00:00
2022-08-28 10:54:34 +00:00
void print_tree(int p_initial_tabs = 0) const;
BTTask();
~BTTask();
2022-08-28 10:54:34 +00:00
};
#endif // BTTASK_H