From e4701ebc08f57575a02bdc1777d9851a987c1cba Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 14 Jul 2024 15:01:25 +0100 Subject: Unit and leader rework (branch based templates and colony containers) --- src/openvic-simulation/map/ProvinceInstance.hpp | 34 +++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/openvic-simulation/map/ProvinceInstance.hpp') 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 + struct UnitInstanceGroup; + + template + struct UnitInstanceGroupBranched; + + using ArmyInstance = UnitInstanceGroupBranched; + using NavyInstance = UnitInstanceGroupBranched; + struct ProvinceInstance : HasIdentifierAndColour { friend struct MapInstance; @@ -83,6 +92,27 @@ namespace OpenVic { bool add_navy(NavyInstance& navy); bool remove_navy(NavyInstance& navy); + template + bool add_unit_instance_group(UnitInstanceGroup& group) { + if constexpr (Branch == UnitType::branch_t::LAND) { + return add_army(static_cast(group)); + } else if constexpr (Branch == UnitType::branch_t::NAVAL) { + return add_navy(static_cast(group)); + } else { + OpenVic::utility::unreachable(); + } + } + template + bool remove_unit_instance_group(UnitInstanceGroup& group) { + if constexpr (Branch == UnitType::branch_t::LAND) { + return remove_army(static_cast(group)); + } else if constexpr (Branch == UnitType::branch_t::NAVAL) { + return remove_navy(static_cast(group)); + } else { + OpenVic::utility::unreachable(); + } + } + bool setup(BuildingTypeManager const& building_type_manager); bool apply_history_to_province(ProvinceHistoryEntry const* entry); -- cgit v1.2.3-56-ga3b1