feat: split end state callback into finished and failed
This commit is contained in:
parent
58a717aec4
commit
51bd3733c4
15
src/unit.cpp
15
src/unit.cpp
|
@ -49,10 +49,15 @@ void Unit::destroy_state() {
|
||||||
if(this->state == nullptr || this->state->is_queued_for_deletion() || !this->state->is_inside_tree())
|
if(this->state == nullptr || this->state->is_queued_for_deletion() || !this->state->is_inside_tree())
|
||||||
return;
|
return;
|
||||||
this->state->queue_free();
|
this->state->queue_free();
|
||||||
this->remove_child(this->state);
|
|
||||||
this->state = nullptr;
|
this->state = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::state_finished() {
|
||||||
|
if(this->current_plan.is_empty())
|
||||||
|
this->emit_signal("goal_finished");
|
||||||
|
this->next_action();
|
||||||
|
}
|
||||||
|
|
||||||
void Unit::next_action() {
|
void Unit::next_action() {
|
||||||
if(this->state != nullptr && !this->state->is_queued_for_deletion())
|
if(this->state != nullptr && !this->state->is_queued_for_deletion())
|
||||||
this->destroy_state();
|
this->destroy_state();
|
||||||
|
@ -66,5 +71,11 @@ void Unit::next_action() {
|
||||||
}
|
}
|
||||||
this->current_plan.remove_at(0);
|
this->current_plan.remove_at(0);
|
||||||
this->add_child(this->state);
|
this->add_child(this->state);
|
||||||
this->state->connect("end_state", this->on_end_state);
|
|
||||||
|
this->state->connect("state_finished", this->on_state_finished);
|
||||||
|
this->state->connect("state_failed", this->on_plan_failed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unit::replan_goal() {
|
||||||
|
this->plan_for_goal(this->current_goal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,17 @@ public:
|
||||||
UnitWorldState *get_world_state() const;
|
UnitWorldState *get_world_state() const;
|
||||||
private:
|
private:
|
||||||
void destroy_state();
|
void destroy_state();
|
||||||
|
void state_finished();
|
||||||
void next_action();
|
void next_action();
|
||||||
|
void replan_goal();
|
||||||
private:
|
private:
|
||||||
goap::Plan current_plan{};
|
goap::Plan current_plan{};
|
||||||
goap::State *state{nullptr};
|
goap::State *state{nullptr};
|
||||||
|
|
||||||
gd::Node3D *eyes{nullptr};
|
gd::Node3D *eyes{nullptr};
|
||||||
|
|
||||||
gd::Callable on_end_state{callable_mp(this, &Unit::next_action)};
|
gd::Callable on_state_finished{callable_mp(this, &Unit::state_finished)};
|
||||||
|
gd::Callable on_plan_failed{callable_mp(this, &Unit::replan_goal)};
|
||||||
|
|
||||||
gd::NavigationAgent3D *agent{nullptr};
|
gd::NavigationAgent3D *agent{nullptr};
|
||||||
UnitWorldState *world_state{nullptr};
|
UnitWorldState *world_state{nullptr};
|
||||||
|
|
Loading…
Reference in a new issue