feat: removed goap::Planner::test_goal
This commit is contained in:
parent
bcf1672f01
commit
d506a9c2d0
|
@ -81,29 +81,21 @@ bool operator>=(goap::WorldStateNode const &lhs, goap::WorldStateNode const &rhs
|
||||||
void Planner::_bind_methods() {
|
void Planner::_bind_methods() {
|
||||||
#define CLASSNAME Planner
|
#define CLASSNAME Planner
|
||||||
GDPROPERTY_HINTED(actions, gd::Variant::ARRAY, gd::PROPERTY_HINT_ARRAY_TYPE, gd::vformat("%s/%s:%s", gd::Variant::INT, gd::PROPERTY_HINT_ENUM, ActionDB::get_enum_hint()));
|
GDPROPERTY_HINTED(actions, gd::Variant::ARRAY, gd::PROPERTY_HINT_ARRAY_TYPE, gd::vformat("%s/%s:%s", gd::Variant::INT, gd::PROPERTY_HINT_ENUM, ActionDB::get_enum_hint()));
|
||||||
GDPROPERTY_HINTED(test_goal, gd::Variant::OBJECT, gd::PROPERTY_HINT_RESOURCE_TYPE, "Goal");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Planner::_enter_tree() { GDGAMEONLY();
|
void Planner::_enter_tree() { GDGAMEONLY();
|
||||||
this->world_state = this->get_node<ActorWorldState>("../ActorWorldState");
|
this->world_state = this->get_node<ActorWorldState>("../ActorWorldState");
|
||||||
if(test_goal.is_valid()) {
|
|
||||||
Plan plan{this->plan_for_goal(test_goal)};
|
|
||||||
gd::UtilityFunctions::print("plan for ", this->test_goal->get_path(), ":");
|
|
||||||
for(Action const *action : plan)
|
|
||||||
gd::UtilityFunctions::print(" ", action->get_class());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Plan Planner::plan_for_goal(gd::Ref<Goal> goal) {
|
Plan Planner::plan_for_goal(gd::Ref<Goal> goal) {
|
||||||
// exit if goal reference is invalid or goal is already completed
|
// exit if goal reference is invalid or goal is already completed
|
||||||
if(!goal.is_valid()) {
|
if(!goal.is_valid()) {
|
||||||
gd::UtilityFunctions::print("goal not valid");
|
gd::UtilityFunctions::push_warning(this->get_path(), " attempt to plan for invalid goal");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
// The node representing the start of the search and the goal of the plan.
|
// The node representing the start of the search and the goal of the plan.
|
||||||
WorldStateNode goal_node{goal->desired_state, this->world_state};
|
WorldStateNode goal_node{goal->desired_state, this->world_state};
|
||||||
if(goal_node.requirements_unmet() == 0) {
|
if(goal_node.requirements_unmet() == 0) {
|
||||||
gd::UtilityFunctions::print("goal ", goal->get_path(), " already met");
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
gd::Vector<WorldStateNode> open{goal_node};
|
gd::Vector<WorldStateNode> open{goal_node};
|
||||||
|
@ -170,25 +162,11 @@ gd::Array Planner::get_actions() const {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Planner::set_test_goal(gd::Ref<Goal> goal) {
|
|
||||||
this->test_goal = goal;
|
|
||||||
}
|
|
||||||
|
|
||||||
gd::Ref<Goal> Planner::get_test_goal() const {
|
|
||||||
return this->test_goal;
|
|
||||||
}
|
|
||||||
|
|
||||||
gd::Vector<Action const *> Planner::get_neighbours(WorldStateNode const &from) const {
|
gd::Vector<Action const *> Planner::get_neighbours(WorldStateNode const &from) const {
|
||||||
gd::Vector<Action const *> retval{};
|
gd::Vector<Action const *> retval{};
|
||||||
for(Action const *action : this->actions) {
|
for(Action const *action : this->actions) {
|
||||||
if(!action->is_possible(from.context)) {
|
if(!action->is_possible(from.context) || !this->does_action_contribute(action, from))
|
||||||
gd::UtilityFunctions::print("action ", action->get_class(), " is not possible");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if(!this->does_action_contribute(action, from)) {
|
|
||||||
gd::UtilityFunctions::print("action ", action->get_class(), " does not contribute");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
retval.push_back(action);
|
retval.push_back(action);
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
@ -60,8 +60,6 @@ public:
|
||||||
|
|
||||||
void set_actions(gd::Array array);
|
void set_actions(gd::Array array);
|
||||||
gd::Array get_actions() const;
|
gd::Array get_actions() const;
|
||||||
void set_test_goal(gd::Ref<Goal> goal);
|
|
||||||
gd::Ref<Goal> get_test_goal() const;
|
|
||||||
private:
|
private:
|
||||||
//! \returns A vector of all actions that satisfy any of the requirements in `unsatisfied`
|
//! \returns A vector of all actions that satisfy any of the requirements in `unsatisfied`
|
||||||
gd::Vector<Action const *> get_neighbours(WorldStateNode const &from) const;
|
gd::Vector<Action const *> get_neighbours(WorldStateNode const &from) const;
|
||||||
|
@ -70,7 +68,6 @@ private:
|
||||||
//! \returns A plan starting with `start_node` traced backwards through the `from` map.
|
//! \returns A plan starting with `start_node` traced backwards through the `from` map.
|
||||||
Plan unroll_plan(WorldStateNode const &start_node, NodeMap const &from);
|
Plan unroll_plan(WorldStateNode const &start_node, NodeMap const &from);
|
||||||
private:
|
private:
|
||||||
gd::Ref<Goal> test_goal{};
|
|
||||||
ActorWorldState *world_state{nullptr};
|
ActorWorldState *world_state{nullptr};
|
||||||
gd::Vector<Action const *> actions;
|
gd::Vector<Action const *> actions;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue