#ifndef RTS_STATES_HPP
#define RTS_STATES_HPP

#include "unit.hpp"
#include "goap/state.hpp"
#include <godot_cpp/classes/animation_player.hpp>
#include <godot_cpp/classes/navigation_agent3d.hpp>

/*! Uses navigation to chase the desired target node.
 */
class MoveTo : public goap::State {
    GDCLASS(MoveTo, goap::State);
    static void _bind_methods();
public:
    virtual void _ready() override;
    virtual void _end_state() override;
    virtual void _process(double) override;
    void calculate_path();
    void on_velocity_computed(gd::Vector3 vel);
    float target_delta_position() const;
    float distance_to_target() const;
    double get_repath_interval() const;
public:
    gd::Node3D *target_node{nullptr};
private:
    gd::Callable nav_velocity_computed{callable_mp(this, &MoveTo::on_velocity_computed)};
    Unit *parent_unit{nullptr};
    gd::NavigationAgent3D *agent{nullptr};
    gd::Vector3 target_position_at_last{};
    double last_repath{0.0};
};

class Activate : public goap::State {
    GDCLASS(Activate, goap::State);
    static void _bind_methods();
public:
    gd::Node3D *target_node{nullptr};
    gd::String animation{};
};

class Animate : public goap::State {
    GDCLASS(Animate, goap::State);
    static void _bind_methods();
public:
    virtual void _ready() override;
    virtual void _process(double delta_time) override;
    virtual void _end_state() override;
    gd::StringName animation{};
private:
    gd::AnimationPlayer *anim{nullptr};
};

#endif // !RTS_STATES_HPP
