diff --git a/src/planner.cpp b/src/planner.cpp index 43b3955..dbf4340 100644 --- a/src/planner.cpp +++ b/src/planner.cpp @@ -91,6 +91,8 @@ Array Planner::gdscript_make_plan(Ref goal) { } Vector> Planner::make_plan(Ref goal) { + // clear cache every planning phase + this->cached_world_state.clear(); // ordered list of all nodes still being considered Vector open{PlannerNode::goal_node(goal->goal_state)}; PlannerNode first = open.get(0); @@ -128,16 +130,15 @@ Vector> Planner::make_plan(Ref goal) { } Variant Planner::get_world_property(StringName prop_key) { - if(prop_key.begins_with("g_")) + if(prop_key.begins_with("g_")) { return this->global_world_state->get_world_property(prop_key); - if(this->cached_world_state.has(prop_key)) + } else if(this->cached_world_state.has(prop_key)) { return this->cached_world_state.get(prop_key); - if(this->has_method("get_" + prop_key)) { - Variant val = this->call(prop_key); + } else if(this->actor->has_method("get_" + prop_key)) { + Variant val = this->actor->call("get_" + prop_key); this->cached_world_state.insert(prop_key, val); return val; - } - return nullptr; + } else return nullptr; } bool Planner::can_do(Ref action) {