From 4ba6869a30c7f53cf8aba8326532cbee281c1612 Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 28 Jul 2024 11:43:04 +0200 Subject: [PATCH] feat: added debug prints to planner and actor world state --- src/goap/actor_world_state.cpp | 8 ++++++++ src/goap/planner.cpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/goap/actor_world_state.cpp b/src/goap/actor_world_state.cpp index 8c604f8..fcc3582 100644 --- a/src/goap/actor_world_state.cpp +++ b/src/goap/actor_world_state.cpp @@ -1,4 +1,7 @@ #include "actor_world_state.hpp" +#ifdef DEBUG_ENABLED +#include "godot_cpp/variant/utility_functions.hpp" +#endif namespace goap { void ActorWorldState::_bind_methods() { @@ -10,6 +13,11 @@ bool ActorWorldState::check_property_match(WorldProperty const &property) { } gd::Variant ActorWorldState::get_world_property(gd::String world_prop_name) { +#ifdef DEBUG_ENABLED + if(!this->has_method("get_" + world_prop_name)) { + gd::UtilityFunctions::push_error("tried to get nonexistent property ", world_prop_name); + } +#endif return this->call("get_" + world_prop_name); } } diff --git a/src/goap/planner.cpp b/src/goap/planner.cpp index a876a81..4fbd37e 100644 --- a/src/goap/planner.cpp +++ b/src/goap/planner.cpp @@ -190,8 +190,14 @@ bool Planner::does_action_contribute(Action const *action, WorldStateNode const Plan Planner::unroll_plan(WorldStateNode const &start_node, NodeMap const &from) { Plan plan{}; WorldStateNode node{start_node}; +#if DEBUG_ENABLED + gd::UtilityFunctions::print("plan (", this->get_path(), "):"); +#endif while(node.last_action != nullptr) { plan.push_back(node.last_action); +#if DEBUG_ENABLED + gd::UtilityFunctions::print(" (", plan.size(), ") ", node.last_action->get_class()); +#endif node = from.get(node); } return plan;