diff options
author | Hop311 <Hop3114@gmail.com> | 2024-07-14 17:37:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-14 17:37:10 +0200 |
commit | e8a3b33f13ebdf3a388b4996308b4db9763dc375 (patch) | |
tree | db365e5d71df41b7b35abdcc3d4c0d76f1653619 /src/openvic-simulation/map | |
parent | b9b35ad9536cfdcd61f5208eeaad7ead4bd0418d (diff) | |
parent | e4701ebc08f57575a02bdc1777d9851a987c1cba (diff) |
Merge pull request #173 from OpenVicProject/unit-colonies
Unit and leader rework (branch based templates and colony containers)
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 34 |
2 files changed, 33 insertions, 3 deletions
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 61b1527..8bb5345 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -3,7 +3,7 @@ #include "openvic-simulation/country/CountryDefinition.hpp" #include "openvic-simulation/history/ProvinceHistory.hpp" #include "openvic-simulation/map/ProvinceDefinition.hpp" -#include "openvic-simulation/military/UnitInstance.hpp" +#include "openvic-simulation/military/UnitInstanceGroup.hpp" using namespace OpenVic; diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index ca7f149..a4f9e98 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -1,6 +1,8 @@ #pragma once #include "openvic-simulation/economy/BuildingInstance.hpp" +#include "openvic-simulation/military/UnitInstance.hpp" +#include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" #include "openvic-simulation/types/HasIdentifier.hpp" @@ -14,8 +16,6 @@ namespace OpenVic { struct CountryDefinition; struct Crime; struct GoodDefinition; - struct ArmyInstance; - struct NavyInstance; struct Ideology; struct Culture; struct Religion; @@ -24,6 +24,15 @@ namespace OpenVic { struct IdeologyManager; struct IssueManager; + template<UnitType::branch_t> + struct UnitInstanceGroup; + + template<UnitType::branch_t> + struct UnitInstanceGroupBranched; + + using ArmyInstance = UnitInstanceGroupBranched<UnitType::branch_t::LAND>; + using NavyInstance = UnitInstanceGroupBranched<UnitType::branch_t::NAVAL>; + struct ProvinceInstance : HasIdentifierAndColour { friend struct MapInstance; @@ -83,6 +92,27 @@ namespace OpenVic { bool add_navy(NavyInstance& navy); bool remove_navy(NavyInstance& navy); + template<UnitType::branch_t Branch> + bool add_unit_instance_group(UnitInstanceGroup<Branch>& group) { + if constexpr (Branch == UnitType::branch_t::LAND) { + return add_army(static_cast<ArmyInstance&>(group)); + } else if constexpr (Branch == UnitType::branch_t::NAVAL) { + return add_navy(static_cast<NavyInstance&>(group)); + } else { + OpenVic::utility::unreachable(); + } + } + template<UnitType::branch_t Branch> + bool remove_unit_instance_group(UnitInstanceGroup<Branch>& group) { + if constexpr (Branch == UnitType::branch_t::LAND) { + return remove_army(static_cast<ArmyInstance&>(group)); + } else if constexpr (Branch == UnitType::branch_t::NAVAL) { + return remove_navy(static_cast<NavyInstance&>(group)); + } else { + OpenVic::utility::unreachable(); + } + } + bool setup(BuildingTypeManager const& building_type_manager); bool apply_history_to_province(ProvinceHistoryEntry const* entry); |