diff options
Diffstat (limited to 'src/openvic-simulation/military')
-rw-r--r-- | src/openvic-simulation/military/UnitInstance.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/military/UnitInstance.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/military/UnitInstanceGroup.cpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/military/UnitType.cpp | 24 | ||||
-rw-r--r-- | src/openvic-simulation/military/UnitType.hpp | 15 |
5 files changed, 49 insertions, 6 deletions
diff --git a/src/openvic-simulation/military/UnitInstance.cpp b/src/openvic-simulation/military/UnitInstance.cpp index d9f12b9..7c6488d 100644 --- a/src/openvic-simulation/military/UnitInstance.cpp +++ b/src/openvic-simulation/military/UnitInstance.cpp @@ -19,8 +19,8 @@ template struct OpenVic::UnitInstance<UnitType::branch_t::LAND>; template struct OpenVic::UnitInstance<UnitType::branch_t::NAVAL>; UnitInstanceBranched<UnitType::branch_t::LAND>::UnitInstanceBranched( - std::string_view new_name, RegimentType const& new_regiment_type, Pop* new_pop -) : UnitInstance { new_name, new_regiment_type }, pop { new_pop } {} + std::string_view new_name, RegimentType const& new_regiment_type, Pop* new_pop, bool new_mobilised +) : UnitInstance { new_name, new_regiment_type }, pop { new_pop }, mobilised { new_mobilised } {} UnitInstanceBranched<UnitType::branch_t::NAVAL>::UnitInstanceBranched( std::string_view new_name, ShipType const& new_ship_type diff --git a/src/openvic-simulation/military/UnitInstance.hpp b/src/openvic-simulation/military/UnitInstance.hpp index 5ff4503..ffbd37f 100644 --- a/src/openvic-simulation/military/UnitInstance.hpp +++ b/src/openvic-simulation/military/UnitInstance.hpp @@ -41,8 +41,11 @@ namespace OpenVic { private: Pop* PROPERTY(pop); + bool PROPERTY_CUSTOM_PREFIX(mobilised, is); - UnitInstanceBranched(std::string_view new_name, RegimentType const& new_regiment_type, Pop* new_pop); + UnitInstanceBranched( + std::string_view new_name, RegimentType const& new_regiment_type, Pop* new_pop, bool new_mobilised) + ; public: UnitInstanceBranched(UnitInstanceBranched&&) = default; diff --git a/src/openvic-simulation/military/UnitInstanceGroup.cpp b/src/openvic-simulation/military/UnitInstanceGroup.cpp index 65ecf5b..09206e3 100644 --- a/src/openvic-simulation/military/UnitInstanceGroup.cpp +++ b/src/openvic-simulation/military/UnitInstanceGroup.cpp @@ -172,8 +172,11 @@ bool UnitInstanceManager::generate_unit_instance( unit_instance = &*get_unit_instances<Branch>().insert( [&unit_deployment]() -> UnitInstanceBranched<Branch> { if constexpr (Branch == UnitType::branch_t::LAND) { - // TODO - get pop from Province unit_deployment.get_home() - return { unit_deployment.get_name(), unit_deployment.get_type(), nullptr }; + return { + unit_deployment.get_name(), unit_deployment.get_type(), + nullptr, // TODO - get pop from Province unit_deployment.get_home() + false // Not mobilised + }; } else if constexpr (Branch == UnitType::branch_t::NAVAL) { return { unit_deployment.get_name(), unit_deployment.get_type() }; } diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index 11f7221..d4ffbee 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -1,5 +1,6 @@ #include "UnitType.hpp" +#include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/map/TerrainType.hpp" using namespace OpenVic; @@ -30,6 +31,29 @@ UnitType::UnitType( supply_cost { std::move(unit_args.supply_cost) }, terrain_modifiers { std::move(unit_args.terrain_modifiers) } {} +bool UnitTypeBranched<LAND>::allowed_cultures_check_culture_in_country( + allowed_cultures_t allowed_cultures, Culture const& culture, CountryInstance const& country +) { + using enum allowed_cultures_t; + + switch (allowed_cultures) { + case ALL_CULTURES: + return true; + case ACCEPTED_CULTURES: + return country.is_primary_or_accepted_culture(culture); + case PRIMARY_CULTURE: + return country.is_primary_culture(culture); + case NO_CULTURES: + return false; + default: + Logger::error( + "Unknown allowed cultures value ", static_cast<uint32_t>(allowed_cultures), " for culture ", + culture.get_identifier(), " and country ", country.get_identifier() + ); + return false; + } +} + UnitTypeBranched<LAND>::UnitTypeBranched( std::string_view new_identifier, unit_type_args_t& unit_args, regiment_type_args_t const& regiment_type_args ) : UnitType { new_identifier, LAND, unit_args }, diff --git a/src/openvic-simulation/military/UnitType.hpp b/src/openvic-simulation/military/UnitType.hpp index 6bd7392..6bbaca7 100644 --- a/src/openvic-simulation/military/UnitType.hpp +++ b/src/openvic-simulation/military/UnitType.hpp @@ -15,6 +15,8 @@ namespace OpenVic { struct TerrainType; struct TerrainTypeManager; + struct Culture; + struct CountryInstance; struct UnitType : HasIdentifier { using icon_t = uint32_t; @@ -94,7 +96,18 @@ namespace OpenVic { struct UnitTypeBranched<UnitType::branch_t::LAND> : UnitType { friend struct UnitTypeManager; - enum struct allowed_cultures_t { ALL_CULTURES, ACCEPTED_CULTURES, PRIMARY_CULTURE }; + // Each value is a subset of its predecessor, so smaller values contain larger values + enum struct allowed_cultures_t { ALL_CULTURES, ACCEPTED_CULTURES, PRIMARY_CULTURE, NO_CULTURES }; + + constexpr static allowed_cultures_t allowed_cultures_get_most_permissive( + allowed_cultures_t lhs, allowed_cultures_t rhs + ) { + return std::min(lhs, rhs); + } + + static bool allowed_cultures_check_culture_in_country( + allowed_cultures_t allowed_cultures, Culture const& culture, CountryInstance const& country + ); struct regiment_type_args_t { allowed_cultures_t allowed_cultures = allowed_cultures_t::ALL_CULTURES; |