metro-rts/src/rts_actions.cpp

74 lines
2.3 KiB
C++

#include "rts_actions.hpp"
#include "rts_states.hpp"
#include "goap/actor_world_state.hpp"
#include "goap/state.hpp"
#include <godot_cpp/core/memory.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
MoveToTarget::MoveToTarget()
: Action() {
this->effects.insert("is_at_target", true);
}
goap::State *MoveToTarget::get_apply_state(goap::ActorWorldState *context) const {
gd::Node3D *target{gd::Object::cast_to<gd::Node3D>(context->get_world_property("target_node"))};
if(target == nullptr) {
gd::UtilityFunctions::push_warning("Failed to get target node of action ", get_static_class());
return nullptr;
} else {
MoveTo *state{this->create_state<MoveTo>()};
state->target_node = target;
return state;
}
}
FireAtTarget::FireAtTarget()
: Action() {
this->effects.insert("is_target_dead", true);
this->required.insert("can_see_target", true);
}
goap::State *FireAtTarget::get_apply_state(goap::ActorWorldState *context) const {
Animate *state{this->create_state<Animate>()};
state->animation = "fire_weapon";
return state;
}
FindTarget::FindTarget()
: Action() {
this->effects.insert("can_see_target", true);
}
goap::State *FindTarget::get_apply_state(goap::ActorWorldState *context) const {
gd::Node3D *target{gd::Object::cast_to<gd::Node3D>(context->get_world_property("target_node"))};
MoveTo *state{this->create_state<MoveTo>()};
state->target_node = target;
return state;
}
GetInMeleeRange::GetInMeleeRange()
: Action() {
this->effects.insert("is_in_melee_range", true);
this->required.insert("can_see_target", true);
}
goap::State *GetInMeleeRange::get_apply_state(goap::ActorWorldState *context) const {
gd::Node3D *target{gd::Object::cast_to<gd::Node3D>(context->get_world_property("target_node"))};
MoveTo *state{this->create_state<MoveTo>()};
state->target_node = target;
return state;
}
MeleeAttack::MeleeAttack()
: Action() {
this->effects.insert("is_target_dead", true);
this->required.insert("can_see_target", true);
this->required.insert("is_in_melee_range", true);
}
goap::State *MeleeAttack::get_apply_state(goap::ActorWorldState *context) const {
Animate *state{this->create_state<Animate>()};
state->animation = "melee_attack";
return state;
}