unit.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include "../systems/nation_id.h"
  3. #include "spawn_type.h"
  4. #include "troop_type.h"
  5. #include <QVector3D>
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. namespace Engine::Core {
  10. class World;
  11. class Entity;
  12. using EntityID = unsigned int;
  13. struct TransformComponent;
  14. struct RenderableComponent;
  15. struct UnitComponent;
  16. struct MovementComponent;
  17. struct AttackComponent;
  18. } // namespace Engine::Core
  19. namespace Game::Units {
  20. struct SpawnParams {
  21. QVector3D position{0, 0, 0};
  22. int player_id = 0;
  23. SpawnType spawn_type = SpawnType::Archer;
  24. bool ai_controlled = false;
  25. int max_population = 100;
  26. Game::Systems::NationID nation_id = Game::Systems::NationID::RomanRepublic;
  27. bool is_initial_spawn = true;
  28. };
  29. class Unit {
  30. public:
  31. virtual ~Unit() = default;
  32. [[nodiscard]] auto id() const -> Engine::Core::EntityID { return m_id; }
  33. [[nodiscard]] auto type_string() const -> std::string {
  34. return m_type_string;
  35. }
  36. void move_to(float x, float z);
  37. [[nodiscard]] auto is_alive() const -> bool;
  38. [[nodiscard]] auto position() const -> QVector3D;
  39. void set_hold_mode(bool enabled);
  40. [[nodiscard]] auto is_in_hold_mode() const -> bool;
  41. void set_guard_mode(bool enabled);
  42. void set_guard_target(Engine::Core::EntityID target_id);
  43. void set_guard_position(float x, float z);
  44. [[nodiscard]] auto is_in_guard_mode() const -> bool;
  45. void clear_guard_mode();
  46. void set_run_mode(bool enabled);
  47. [[nodiscard]] auto is_running() const -> bool;
  48. [[nodiscard]] auto can_run() const -> bool;
  49. protected:
  50. Unit(Engine::Core::World &world, TroopType type);
  51. Unit(Engine::Core::World &world, std::string type);
  52. [[nodiscard]] auto entity() const -> Engine::Core::Entity *;
  53. void ensureCoreComponents();
  54. static auto
  55. resolve_nation_id(const SpawnParams &params) -> Game::Systems::NationID;
  56. Engine::Core::World *m_world = nullptr;
  57. Engine::Core::EntityID m_id = 0;
  58. std::string m_type_string;
  59. Engine::Core::TransformComponent *m_t = nullptr;
  60. Engine::Core::RenderableComponent *m_r = nullptr;
  61. Engine::Core::UnitComponent *m_u = nullptr;
  62. Engine::Core::MovementComponent *m_mv = nullptr;
  63. Engine::Core::AttackComponent *m_atk = nullptr;
  64. };
  65. } // namespace Game::Units