feat: Planner::cached_world_state now clears when make_plan is called

This commit is contained in:
Sara 2024-03-30 23:32:52 +01:00
parent 8017194b0c
commit 4dbeb77ad4

View file

@ -91,6 +91,8 @@ Array Planner::gdscript_make_plan(Ref<Goal> goal) {
}
Vector<Ref<Action>> Planner::make_plan(Ref<Goal> goal) {
// clear cache every planning phase
this->cached_world_state.clear();
// ordered list of all nodes still being considered
Vector<PlannerNode> open{PlannerNode::goal_node(goal->goal_state)};
PlannerNode first = open.get(0);
@ -128,16 +130,15 @@ Vector<Ref<Action>> Planner::make_plan(Ref<Goal> 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> action) {