feat: added state done functions to goap::State

This commit is contained in:
Sara 2024-06-21 21:03:15 +02:00
parent d506a9c2d0
commit ffafcac23a
2 changed files with 22 additions and 3 deletions

View file

@ -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();

View file

@ -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};