metro-rts/src/unit.hpp

70 lines
1.8 KiB
C++

#ifndef RTS_UNIT_HPP
#define RTS_UNIT_HPP
#include "goal_marker.hpp"
#include "unit_world_state.hpp"
#include "goap/goal.hpp"
#include "goap/planner.hpp"
#include "utils/godot_macros.hpp"
#include <godot_cpp/classes/animation_player.hpp>
#include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/navigation_agent3d.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/variant/callable.hpp>
namespace gd = godot;
GDENUM(UnitTeam,
Neutral,
Player,
Ally,
Enemy
);
class Unit : public gd::CharacterBody3D {
GDCLASS(Unit, gd::CharacterBody3D);
static void _bind_methods();
public:
virtual void _enter_tree() override;
void stop_plan();
void begin_marker_temporary(GoalMarker *marker);
void begin_goal(gd::Ref<goap::Goal> goal);
void set_target_goal(gd::Node3D *target, gd::Ref<goap::Goal> goal);
void fire_at_target();
void aim_at(gd::Node3D *node);
void on_death(Unit *damage_source);
UnitWorldState *get_world_state() const;
gd::Transform3D get_eye_transform() const;
UnitTeam get_team() const;
void set_configure_team(int value);
int get_configure_team() const;
private:
void set_goal_and_plan(gd::Ref<goap::Goal> goal);
void destroy_state();
void state_finished();
void next_action();
void replan_goal();
private:
goap::Plan current_plan{};
gd::Ref<goap::Goal> current_goal{};
goap::State *state{nullptr};
gd::Node3D *eyes{nullptr};
gd::Callable on_state_finished{callable_mp(this, &Unit::state_finished)};
gd::Callable on_plan_failed{callable_mp(this, &Unit::replan_goal)};
UnitTeam team{UnitTeam::Neutral};
gd::NavigationAgent3D *agent{nullptr};
gd::AnimationPlayer *anim_player{nullptr};
goap::Planner *planner{nullptr};
UnitWorldState *world_state{nullptr};
};
#endif // !RTS_UNIT_HPP