feat: removed goap::Planner::test_goal

This commit is contained in:
Sara 2024-06-21 21:02:13 +02:00
parent bcf1672f01
commit d506a9c2d0
2 changed files with 2 additions and 27 deletions

View file

@ -81,29 +81,21 @@ bool operator>=(goap::WorldStateNode const &lhs, goap::WorldStateNode const &rhs
void Planner::_bind_methods() {
#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(test_goal, gd::Variant::OBJECT, gd::PROPERTY_HINT_RESOURCE_TYPE, "Goal");
}
void Planner::_enter_tree() { GDGAMEONLY();
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) {
// exit if goal reference is invalid or goal is already completed
if(!goal.is_valid()) {
gd::UtilityFunctions::print("goal not valid");
gd::UtilityFunctions::push_warning(this->get_path(), " attempt to plan for invalid goal");
return {};
}
// The node representing the start of the search and the goal of the plan.
WorldStateNode goal_node{goal->desired_state, this->world_state};
if(goal_node.requirements_unmet() == 0) {
gd::UtilityFunctions::print("goal ", goal->get_path(), " already met");
return {};
}
gd::Vector<WorldStateNode> open{goal_node};
@ -170,25 +162,11 @@ gd::Array Planner::get_actions() const {
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 *> retval{};
for(Action const *action : this->actions) {
if(!action->is_possible(from.context)) {
gd::UtilityFunctions::print("action ", action->get_class(), " is not possible");
if(!action->is_possible(from.context) || !this->does_action_contribute(action, from))
continue;
}
if(!this->does_action_contribute(action, from)) {
gd::UtilityFunctions::print("action ", action->get_class(), " does not contribute");
continue;
}
retval.push_back(action);
}
return retval;

View file

@ -60,8 +60,6 @@ public:
void set_actions(gd::Array array);
gd::Array get_actions() const;
void set_test_goal(gd::Ref<Goal> goal);
gd::Ref<Goal> get_test_goal() const;
private:
//! \returns A vector of all actions that satisfy any of the requirements in `unsatisfied`
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.
Plan unroll_plan(WorldStateNode const &start_node, NodeMap const &from);
private:
gd::Ref<Goal> test_goal{};
ActorWorldState *world_state{nullptr};
gd::Vector<Action const *> actions;
};