From 4284b73b82c02fb5d2d86fbfd966c03caab8dce4 Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 19 Apr 2024 19:28:30 +0100 Subject: Menu reqs: country index, flag type set, province set total population --- src/openvic-simulation/country/Country.cpp | 9 +++++---- src/openvic-simulation/country/Country.hpp | 7 ++++--- src/openvic-simulation/map/Region.cpp | 16 +++++++++++----- src/openvic-simulation/map/Region.hpp | 5 ++--- src/openvic-simulation/politics/Government.cpp | 4 ++-- src/openvic-simulation/politics/Government.hpp | 2 +- src/openvic-simulation/types/IdentifierRegistry.hpp | 2 +- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/openvic-simulation/country/Country.cpp b/src/openvic-simulation/country/Country.cpp index 0fdeb60..447f2dc 100644 --- a/src/openvic-simulation/country/Country.cpp +++ b/src/openvic-simulation/country/Country.cpp @@ -26,6 +26,7 @@ CountryParty::CountryParty( Country::Country( std::string_view new_identifier, colour_t new_colour, + size_t new_index, GraphicalCultureType const& new_graphical_culture, IdentifierRegistry&& new_parties, unit_names_map_t&& new_unit_names, @@ -34,8 +35,8 @@ Country::Country( colour_t new_primary_unit_colour, colour_t new_secondary_unit_colour, colour_t new_tertiary_unit_colour -) : HasIdentifierAndColour { - new_identifier, new_colour, false }, +) : HasIdentifierAndColour { new_identifier, new_colour, false }, + index { new_index }, graphical_culture { new_graphical_culture }, parties { std::move(new_parties) }, unit_names { std::move(new_unit_names) }, @@ -68,8 +69,8 @@ bool CountryManager::add_country( static constexpr colour_t default_colour = colour_t::fill_as(colour_t::max_value); return countries.add_item({ - identifier, colour, *graphical_culture, std::move(parties), std::move(unit_names), dynamic_tag, - std::move(alternative_colours), + identifier, colour, countries.size(), *graphical_culture, std::move(parties), std::move(unit_names), + dynamic_tag, std::move(alternative_colours), /* Default to country colour for the chest and grey for the others. Update later if necessary. */ colour, default_colour, default_colour }); diff --git a/src/openvic-simulation/country/Country.hpp b/src/openvic-simulation/country/Country.hpp index 1d960c2..558b726 100644 --- a/src/openvic-simulation/country/Country.hpp +++ b/src/openvic-simulation/country/Country.hpp @@ -48,6 +48,7 @@ namespace OpenVic { using government_colour_map_t = ordered_map; private: + const size_t PROPERTY(index); GraphicalCultureType const& PROPERTY(graphical_culture); /* Not const to allow elements to be moved, otherwise a copy is forced * which causes a compile error as the copy constructor has been deleted. */ @@ -61,9 +62,9 @@ namespace OpenVic { // Unit colours not const due to being added after construction Country( - std::string_view new_identifier, colour_t new_colour, GraphicalCultureType const& new_graphical_culture, - IdentifierRegistry&& new_parties, unit_names_map_t&& new_unit_names, bool new_dynamic_tag, - government_colour_map_t&& new_alternative_colours, + std::string_view new_identifier, colour_t new_colour, size_t new_index, + GraphicalCultureType const& new_graphical_culture, IdentifierRegistry&& new_parties, + unit_names_map_t&& new_unit_names, bool new_dynamic_tag, government_colour_map_t&& new_alternative_colours, colour_t new_primary_unit_colour, colour_t new_secondary_unit_colour, colour_t new_tertiary_unit_colour ); diff --git a/src/openvic-simulation/map/Region.cpp b/src/openvic-simulation/map/Region.cpp index c735279..9b31d0f 100644 --- a/src/openvic-simulation/map/Region.cpp +++ b/src/openvic-simulation/map/Region.cpp @@ -95,12 +95,18 @@ ProvinceSet::provinces_t const& ProvinceSet::get_provinces() const { return provinces; } -Region::Region(std::string_view new_identifier, colour_t new_colour, bool new_meta) - : HasIdentifierAndColour { new_identifier, new_colour, false }, meta { new_meta } {} +Pop::pop_size_t ProvinceSet::calculate_total_population() const { + Pop::pop_size_t total_population = 0; + + for (Province const* province : provinces) { + total_population += province->get_total_population(); + } + + return total_population; +} ProvinceSetModifier::ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values) : Modifier { new_identifier, std::move(new_values), 0 } {} -bool Region::get_meta() const { - return meta; -} +Region::Region(std::string_view new_identifier, colour_t new_colour, bool new_meta) + : HasIdentifierAndColour { new_identifier, new_colour, false }, meta { new_meta } {} diff --git a/src/openvic-simulation/map/Region.hpp b/src/openvic-simulation/map/Region.hpp index 420d221..f12e14a 100644 --- a/src/openvic-simulation/map/Region.hpp +++ b/src/openvic-simulation/map/Region.hpp @@ -26,6 +26,7 @@ namespace OpenVic { void reserve_more(size_t size); bool contains_province(Province const* province) const; provinces_t const& get_provinces() const; + Pop::pop_size_t calculate_total_population() const; }; struct ProvinceSetModifier : Modifier, ProvinceSet { @@ -47,13 +48,11 @@ namespace OpenVic { * Any region containing a province already listed in a * previously defined region is considered a meta region. */ - const bool meta; + const bool PROPERTY(meta); Region(std::string_view new_identifier, colour_t new_colour, bool new_meta); public: Region(Region&&) = default; - - bool get_meta() const; }; } diff --git a/src/openvic-simulation/politics/Government.cpp b/src/openvic-simulation/politics/Government.cpp index 28f5d09..634db8e 100644 --- a/src/openvic-simulation/politics/Government.cpp +++ b/src/openvic-simulation/politics/Government.cpp @@ -38,8 +38,8 @@ bool GovernmentTypeManager::add_government_type( }); /* flag_type can be empty here for default/non-ideological flag */ - if (ret && std::find(flag_types.begin(), flag_types.end(), flag_type) == flag_types.end()) { - flag_types.emplace_back(flag_type); + if (ret) { + flag_types.emplace(flag_type); } return ret; diff --git a/src/openvic-simulation/politics/Government.hpp b/src/openvic-simulation/politics/Government.hpp index 34a9194..f2a2318 100644 --- a/src/openvic-simulation/politics/Government.hpp +++ b/src/openvic-simulation/politics/Government.hpp @@ -29,7 +29,7 @@ namespace OpenVic { struct GovernmentTypeManager { private: IdentifierRegistry IDENTIFIER_REGISTRY(government_type); - std::vector PROPERTY(flag_types); + string_set_t PROPERTY(flag_types); public: bool add_government_type( diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index 533273a..8c8ba11 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -610,7 +610,7 @@ private: return registry.expect_item_string(callback, allow_empty, warn); \ } \ constexpr NodeTools::NodeCallback auto expect_##singular##_identifier_or_string( \ - NodeTools::Callback auto callback,bool allow_empty = false, \ + NodeTools::Callback auto callback, bool allow_empty = false, \ bool warn = false \ ) const_kw { \ return registry.expect_item_identifier_or_string(callback, allow_empty, warn); \ -- cgit v1.2.3-56-ga3b1