feat: StateArgs now require a Planner as construction context
This commit is contained in:
parent
8d3484163c
commit
73ff6ead46
|
@ -64,8 +64,9 @@ void Planner::_bind_methods() {
|
||||||
GDPROPERTY_HINTED(goals, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, GDRESOURCETYPE(Goal));
|
GDPROPERTY_HINTED(goals, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, GDRESOURCETYPE(Goal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Planner::_ready() {
|
void Planner::_enter_tree() {
|
||||||
this->global_world_state = GlobalWorldState::get_singleton();
|
this->global_world_state = GlobalWorldState::get_singleton();
|
||||||
|
UtilityFunctions::print("global world state cached: ", this->global_world_state);
|
||||||
this->actor = Object::cast_to<CharacterActor>(this->get_parent());
|
this->actor = Object::cast_to<CharacterActor>(this->get_parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +197,7 @@ State Planner::get_next_state() {
|
||||||
this->plan = this->make_plan();
|
this->plan = this->make_plan();
|
||||||
if(this->plan.is_empty())
|
if(this->plan.is_empty())
|
||||||
return State::new_invalid();
|
return State::new_invalid();
|
||||||
return this->plan.get(0)->apply_state->construct(this->actor);
|
return this->plan.get(0)->apply_state->construct(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Planner::set_actions(Array value) {
|
void Planner::set_actions(Array value) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Planner : public Node {
|
||||||
GDCLASS(Planner, Node);
|
GDCLASS(Planner, Node);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
virtual void _ready() override;
|
virtual void _enter_tree() override;
|
||||||
|
|
||||||
Vector<Ref<Action>> make_plan();
|
Vector<Ref<Action>> make_plan();
|
||||||
Ref<Goal> select_goal();
|
Ref<Goal> select_goal();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "character_actor.hpp"
|
#include "character_actor.hpp"
|
||||||
|
#include "planner.hpp"
|
||||||
#include "utils/godot_macros.h"
|
#include "utils/godot_macros.h"
|
||||||
|
|
||||||
namespace godot::goap {
|
namespace godot::goap {
|
||||||
|
@ -51,7 +52,7 @@ void StateArgs::_bind_methods() {
|
||||||
GDPROPERTY(argument_property, Variant::STRING_NAME);
|
GDPROPERTY(argument_property, Variant::STRING_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
State StateArgs::construct(Node *context) const {
|
State StateArgs::construct(Planner *context) const {
|
||||||
return { .type = State::STATE_TYPE_MAX };
|
return { .type = State::STATE_TYPE_MAX };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,21 +61,21 @@ StringName StateArgs::get_argument_property() const { return this->argument_prop
|
||||||
|
|
||||||
void MoveStateArgs::_bind_methods() {}
|
void MoveStateArgs::_bind_methods() {}
|
||||||
|
|
||||||
State MoveStateArgs::construct(Node *context) const {
|
State MoveStateArgs::construct(Planner *context) const {
|
||||||
Node3D *node = Object::cast_to<Node3D>(context->call("get_" + this->argument_property));
|
Node3D *node = Object::cast_to<Node3D>(context->get_world_property(this->argument_property));
|
||||||
return State::new_move_to(node);
|
return State::new_move_to(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimateStateArgs::_bind_methods() {}
|
void AnimateStateArgs::_bind_methods() {}
|
||||||
|
|
||||||
State AnimateStateArgs::construct(Node *context) const {
|
State AnimateStateArgs::construct(Planner *context) const {
|
||||||
return State::new_animate(context->call("get_" + this->argument_property));
|
return State::new_animate(context->get_world_property(this->argument_property));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivateStateArgs::_bind_methods() {}
|
void ActivateStateArgs::_bind_methods() {}
|
||||||
|
|
||||||
State ActivateStateArgs::construct(Node *context) const {
|
State ActivateStateArgs::construct(Planner *context) const {
|
||||||
Node *node = Object::cast_to<Node>(context->call("get_" + this->argument_property));
|
Node *node = Object::cast_to<Node>(context->get_world_property(this->argument_property));
|
||||||
return State::new_activate(node);
|
return State::new_activate(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
namespace godot { class CharacterActor; }
|
namespace godot { class CharacterActor; }
|
||||||
namespace godot::goap {
|
namespace godot::goap {
|
||||||
|
class Planner;
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
~State();
|
~State();
|
||||||
static State new_move_to(Node3D *location);
|
static State new_move_to(Node3D *location);
|
||||||
|
@ -36,7 +38,7 @@ class StateArgs : public Resource {
|
||||||
GDCLASS(StateArgs, Resource);
|
GDCLASS(StateArgs, Resource);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
virtual State construct(Node *context) const;
|
virtual State construct(Planner *context) const;
|
||||||
void set_argument_property(StringName name);
|
void set_argument_property(StringName name);
|
||||||
StringName get_argument_property() const;
|
StringName get_argument_property() const;
|
||||||
StringName argument_property;
|
StringName argument_property;
|
||||||
|
@ -45,21 +47,21 @@ public:
|
||||||
class MoveStateArgs : public StateArgs {
|
class MoveStateArgs : public StateArgs {
|
||||||
GDCLASS(MoveStateArgs, StateArgs);
|
GDCLASS(MoveStateArgs, StateArgs);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
virtual State construct(Node *context) const override;
|
virtual State construct(Planner *context) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AnimateStateArgs : public StateArgs {
|
class AnimateStateArgs : public StateArgs {
|
||||||
GDCLASS(AnimateStateArgs, StateArgs);
|
GDCLASS(AnimateStateArgs, StateArgs);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
virtual State construct(Node *context) const override;
|
virtual State construct(Planner *context) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ActivateStateArgs : public StateArgs {
|
class ActivateStateArgs : public StateArgs {
|
||||||
GDCLASS(ActivateStateArgs, StateArgs);
|
GDCLASS(ActivateStateArgs, StateArgs);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
virtual State construct(Node *context) const override;
|
virtual State construct(Planner *context) const override;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue