diff --git a/src/goap/state.cpp b/src/goap/state.cpp index 6660604..1c2b90d 100644 --- a/src/goap/state.cpp +++ b/src/goap/state.cpp @@ -6,6 +6,8 @@ namespace goap { void State::_bind_methods() { #define CLASSNAME State + GDSIGNAL("state_finished"); + GDSIGNAL("state_failed"); GDSIGNAL("end_state"); } @@ -14,9 +16,8 @@ void State::_enter_tree() { } void State::_process(double delta_time) { - if(this->action->is_completed(this->world_state)) { - this->end_state(); - } + if(this->is_action_done()) + this->state_finished(); } Action const *State::get_action() const { @@ -25,6 +26,20 @@ Action const *State::get_action() const { void State::_end_state() {} +void State::state_finished() { + this->end_state(); + this->emit_signal("state_finished"); +} + +void State::state_failed() { + this->end_state(); + this->emit_signal("state_failed"); +} + +bool State::is_action_done() const { + return this->action->is_completed(this->world_state); +} + void State::end_state() { this->_end_state(); this->queue_free(); diff --git a/src/goap/state.hpp b/src/goap/state.hpp index 96d275a..2f08f57 100644 --- a/src/goap/state.hpp +++ b/src/goap/state.hpp @@ -19,7 +19,11 @@ public: virtual void _process(double delta_time) override; protected: Action const *get_action() const; + bool is_action_done() const; virtual void _end_state(); + void state_finished(); + void state_failed(); +private: void end_state(); private: ActorWorldState *world_state{nullptr};