From d8baf57d46539da9edba5952f73089bf9a54bdaf Mon Sep 17 00:00:00 2001 From: hop311 Date: Thu, 18 Jul 2024 23:25:38 +0100 Subject: Unit position/country/leader handling + more use of unit branch templates --- src/openvic-simulation/military/Deployment.hpp | 54 +++++++++++++------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'src/openvic-simulation/military/Deployment.hpp') diff --git a/src/openvic-simulation/military/Deployment.hpp b/src/openvic-simulation/military/Deployment.hpp index 9a1d2ee..a53f101 100644 --- a/src/openvic-simulation/military/Deployment.hpp +++ b/src/openvic-simulation/military/Deployment.hpp @@ -5,13 +5,18 @@ #include #include "openvic-simulation/military/Leader.hpp" +#include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/types/HasIdentifier.hpp" #include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { struct ProvinceDefinition; - struct RegimentDeployment { + template + struct UnitDeployment; + + template<> + struct UnitDeployment { friend struct DeploymentManager; private: @@ -19,57 +24,52 @@ namespace OpenVic { RegimentType const& PROPERTY(type); ProvinceDefinition const* PROPERTY(home); - RegimentDeployment(std::string_view new_name, RegimentType const& new_type, ProvinceDefinition const* new_home); + UnitDeployment(std::string_view new_name, RegimentType const& new_type, ProvinceDefinition const* new_home); public: - RegimentDeployment(RegimentDeployment&&) = default; + UnitDeployment(UnitDeployment&&) = default; }; - struct ShipDeployment { + using RegimentDeployment = UnitDeployment; + + template<> + struct UnitDeployment { friend struct DeploymentManager; private: std::string PROPERTY(name); ShipType const& PROPERTY(type); - ShipDeployment(std::string_view new_name, ShipType const& new_type); + UnitDeployment(std::string_view new_name, ShipType const& new_type); public: - ShipDeployment(ShipDeployment&&) = default; + UnitDeployment(UnitDeployment&&) = default; }; - struct ArmyDeployment { - friend struct DeploymentManager; - - private: - std::string PROPERTY(name); - ProvinceDefinition const* PROPERTY(location); - std::vector PROPERTY(regiments); + using ShipDeployment = UnitDeployment; - ArmyDeployment( - std::string_view new_name, ProvinceDefinition const* new_location, std::vector&& new_regiments - ); - - public: - ArmyDeployment(ArmyDeployment&&) = default; - }; - - struct NavyDeployment { + template + struct UnitDeploymentGroup { friend struct DeploymentManager; + using _Unit = UnitDeployment; + private: std::string PROPERTY(name); ProvinceDefinition const* PROPERTY(location); - std::vector PROPERTY(ships); + std::vector<_Unit> PROPERTY(units); - NavyDeployment( - std::string_view new_name, ProvinceDefinition const* new_location, std::vector&& new_ships + UnitDeploymentGroup( + std::string_view new_name, ProvinceDefinition const* new_location, std::vector<_Unit>&& new_units ); public: - NavyDeployment(NavyDeployment&&) = default; + UnitDeploymentGroup(UnitDeploymentGroup&&) = default; }; + using ArmyDeployment = UnitDeploymentGroup; + using NavyDeployment = UnitDeploymentGroup; + struct Deployment : HasIdentifier { friend struct DeploymentManager; @@ -85,6 +85,8 @@ namespace OpenVic { public: Deployment(Deployment&&) = default; + + UNIT_BRANCHED_GETTER_CONST(get_unit_deployment_groups, armies, navies); }; struct DefinitionManager; -- cgit v1.2.3-56-ga3b1