diff --git a/src/unit.cpp b/src/unit.cpp index 505924f..1b70c38 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -52,6 +52,10 @@ void Unit::stop_plan() { } void Unit::begin_marker_temporary(GoalMarker *marker) { + if(!this->get_entity_health()->is_conscious()) { + marker->queue_free(); + return; + } this->world_state->set_target_node(marker); this->set_goal_and_plan(marker->get_goal()); // destroy temporary marker if goal is already achieved or failed @@ -61,6 +65,7 @@ void Unit::begin_marker_temporary(GoalMarker *marker) { } else { this->world_state->connect("attention_changed", callable_mp(marker, &GoalMarker::destroy_on_forgotten)); this->connect("goal_finished", callable_mp(marker, &GoalMarker::destroy_on_forgotten)); + this->connect("plan_failed", callable_mp(marker, &GoalMarker::destroy_on_forgotten)); } this->next_action(); } @@ -92,12 +97,14 @@ void Unit::aim_at(gd::Node3D *target) { void Unit::on_unconscious(Unit *damage_source) { this->destroy_state(); + this->emit_signal("plan_failed"); this->anim_player->stop(); this->anim_player->play("death"); } void Unit::on_death(Unit *damage_source) { this->destroy_state(); + this->emit_signal("plan_failed"); if(this->anim_player->get_current_animation() != gd::StringName("death")) { this->anim_player->stop(); this->anim_player->play("death");