From 3c75b592d33a076503b9ba5929c34a667988ae0d Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 19 Jun 2024 12:53:07 +0200 Subject: [PATCH] feat: now tracking current goal in unit --- src/unit.cpp | 8 ++++---- src/unit.hpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/unit.cpp b/src/unit.cpp index dfba9a0..1b841e6 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -1,9 +1,9 @@ #include "unit.hpp" #include "goap/goal.hpp" -#include "godot_cpp/variant/callable_method_pointer.hpp" -#include "godot_cpp/variant/utility_functions.hpp" #include "utils/godot_macros.hpp" #include +#include +#include void Unit::_bind_methods() { #define CLASSNAME Unit @@ -20,8 +20,7 @@ void Unit::_process(double delta_time) { } void Unit::stop_plan() { - if(this->is_queued_for_deletion()) - return; + this->current_goal.unref(); this->current_plan.clear(); if(this->state && !this->state->is_queued_for_deletion()) this->destroy_state(); @@ -36,6 +35,7 @@ void Unit::plan_for_marker(GoalMarker *marker) { void Unit::plan_for_goal(gd::Ref goal) { this->current_plan = this->planner->plan_for_goal(goal); + this->current_goal = goal; this->next_action(); } diff --git a/src/unit.hpp b/src/unit.hpp index 8227c95..9d17a3d 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -31,6 +31,7 @@ private: void replan_goal(); private: goap::Plan current_plan{}; + gd::Ref current_goal{}; goap::State *state{nullptr}; gd::Node3D *eyes{nullptr};