From 58a717aec45cc883ad2f86b308a2115a93727676 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 19 Jun 2024 12:48:34 +0200 Subject: [PATCH] feat: added on-target-destroyed callback to unit world state --- src/unit_world_state.cpp | 7 +++++++ src/unit_world_state.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/unit_world_state.cpp b/src/unit_world_state.cpp index b6d1649..3731417 100644 --- a/src/unit_world_state.cpp +++ b/src/unit_world_state.cpp @@ -44,9 +44,16 @@ bool UnitWorldState::get_is_target_dead() const { void UnitWorldState::set_target_node(gd::Node3D *node) { this->target_node = node; + if(node != nullptr) + node->connect("tree_exited", callable_mp(this, &UnitWorldState::target_destroyed).bind(node)); this->emit_signal("attention_changed"); } gd::Node3D *UnitWorldState::get_target_node() const { return this->target_node; } + +void UnitWorldState::target_destroyed(gd::Node3D *target) { + if(target == this->target_node) + this->set_target_node(nullptr); +} diff --git a/src/unit_world_state.hpp b/src/unit_world_state.hpp index 9f2ba29..6656a60 100644 --- a/src/unit_world_state.hpp +++ b/src/unit_world_state.hpp @@ -18,6 +18,8 @@ public: void set_target_node(gd::Node3D *node); gd::Node3D *get_target_node() const; +private: + void target_destroyed(gd::Node3D *target); private: Unit *parent_unit{nullptr}; gd::NavigationAgent3D *agent{nullptr};