From 41d50b15ac978530a53ed99eea36f180e1d27b16 Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 14 Jun 2024 23:06:19 +0100 Subject: Renamed Country to CountryDefinition --- src/openvic-simulation/pop/Culture.cpp | 38 ++++++++++++++++++---------------- src/openvic-simulation/pop/Culture.hpp | 25 +++++++++++----------- src/openvic-simulation/pop/Pop.cpp | 4 ++-- src/openvic-simulation/pop/Pop.hpp | 2 +- 4 files changed, 36 insertions(+), 33 deletions(-) (limited to 'src/openvic-simulation/pop') diff --git a/src/openvic-simulation/pop/Culture.cpp b/src/openvic-simulation/pop/Culture.cpp index 18ed3d8..93d4d19 100644 --- a/src/openvic-simulation/pop/Culture.cpp +++ b/src/openvic-simulation/pop/Culture.cpp @@ -1,6 +1,6 @@ #include "Culture.hpp" -#include "openvic-simulation/country/Country.hpp" +#include "openvic-simulation/country/CountryDefinition.hpp" #include "openvic-simulation/dataloader/NodeTools.hpp" #include "openvic-simulation/types/Colour.hpp" @@ -11,13 +11,13 @@ GraphicalCultureType::GraphicalCultureType(std::string_view new_identifier) : Ha CultureGroup::CultureGroup( std::string_view new_identifier, std::string_view new_leader, GraphicalCultureType const& new_unit_graphical_culture_type, - bool new_is_overseas, Country const* new_union_country + bool new_is_overseas, CountryDefinition const* new_union_country ) : HasIdentifier { new_identifier }, leader { new_leader }, unit_graphical_culture_type { new_unit_graphical_culture_type }, is_overseas { new_is_overseas }, union_country { new_union_country } {} Culture::Culture( std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, name_list_t&& new_first_names, - name_list_t&& new_last_names, fixed_point_t new_radicalism, Country const* new_primary_country + name_list_t&& new_last_names, fixed_point_t new_radicalism, CountryDefinition const* new_primary_country ) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, first_names { std::move(new_first_names) }, last_names { std::move(new_last_names) }, radicalism { new_radicalism }, primary_country { new_primary_country } {} @@ -34,7 +34,7 @@ bool CultureManager::add_graphical_culture_type(std::string_view identifier) { bool CultureManager::add_culture_group( std::string_view identifier, std::string_view leader, GraphicalCultureType const* graphical_culture_type, bool is_overseas, - Country const* union_country + CountryDefinition const* union_country ) { if (!graphical_culture_types.is_locked()) { Logger::error("Cannot register culture groups until graphical culture types are locked!"); @@ -57,7 +57,7 @@ bool CultureManager::add_culture_group( bool CultureManager::add_culture( std::string_view identifier, colour_t colour, CultureGroup const& group, name_list_t&& first_names, - name_list_t&& last_names, fixed_point_t radicalism, Country const* primary_country + name_list_t&& last_names, fixed_point_t radicalism, CountryDefinition const* primary_country ) { if (!culture_groups.is_locked()) { Logger::error("Cannot register cultures until culture groups are locked!"); @@ -95,20 +95,21 @@ bool CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) { } bool CultureManager::_load_culture_group( - CountryManager const& country_manager, size_t& total_expected_cultures, std::string_view culture_group_key, - ast::NodeCPtr culture_group_node + CountryDefinitionManager const& country_definition_manager, size_t& total_expected_cultures, + std::string_view culture_group_key, ast::NodeCPtr culture_group_node ) { std::string_view leader {}; GraphicalCultureType const* unit_graphical_culture_type = default_graphical_culture_type; bool is_overseas = true; - Country const* union_country = nullptr; + CountryDefinition const* union_country = nullptr; bool ret = expect_dictionary_keys_and_default( increment_callback(total_expected_cultures), "leader", ONE_EXACTLY, expect_identifier(assign_variable_callback(leader)), "unit", ZERO_OR_ONE, expect_graphical_culture_type_identifier(assign_variable_callback_pointer(unit_graphical_culture_type)), - "union", ZERO_OR_ONE, country_manager.expect_country_identifier(assign_variable_callback_pointer(union_country)), + "union", ZERO_OR_ONE, + country_definition_manager.expect_country_definition_identifier(assign_variable_callback_pointer(union_country)), "is_overseas", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_overseas)) )(culture_group_node); ret &= add_culture_group(culture_group_key, leader, unit_graphical_culture_type, is_overseas, union_country); @@ -116,20 +117,21 @@ bool CultureManager::_load_culture_group( } bool CultureManager::_load_culture( - CountryManager const& country_manager, CultureGroup const& culture_group, std::string_view culture_key, + CountryDefinitionManager const& country_definition_manager, CultureGroup const& culture_group, std::string_view culture_key, ast::NodeCPtr culture_node ) { colour_t colour = colour_t::null(); name_list_t first_names {}, last_names {}; fixed_point_t radicalism = 0; - Country const* primary_country = nullptr; + CountryDefinition const* primary_country = nullptr; bool ret = expect_dictionary_keys( "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), "first_names", ONE_EXACTLY, name_list_callback(move_variable_callback(first_names)), "last_names", ONE_EXACTLY, name_list_callback(move_variable_callback(last_names)), "radicalism", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(radicalism)), - "primary", ZERO_OR_ONE, country_manager.expect_country_identifier(assign_variable_callback_pointer(primary_country)) + "primary", ZERO_OR_ONE, + country_definition_manager.expect_country_definition_identifier(assign_variable_callback_pointer(primary_country)) )(culture_node); ret &= add_culture( culture_key, colour, culture_group, std::move(first_names), std::move(last_names), radicalism, primary_country @@ -157,7 +159,7 @@ bool CultureManager::_load_culture( * POP-267, POP-268, POP-269, POP-270, POP-271, POP-272, POP-273, POP-274, POP-275, POP-276, POP-277, POP-278, POP-279, * POP-280, POP-281, POP-282, POP-283, POP-284 */ -bool CultureManager::load_culture_file(CountryManager const& country_manager, ast::NodeCPtr root) { +bool CultureManager::load_culture_file(CountryDefinitionManager const& country_definition_manager, ast::NodeCPtr root) { if (!graphical_culture_types.is_locked()) { Logger::error("Cannot load culture groups until graphical culture types are locked!"); return false; @@ -165,24 +167,24 @@ bool CultureManager::load_culture_file(CountryManager const& country_manager, as size_t total_expected_cultures = 0; bool ret = expect_dictionary_reserve_length(culture_groups, - [this, &country_manager, &total_expected_cultures]( + [this, &country_definition_manager, &total_expected_cultures]( std::string_view key, ast::NodeCPtr value ) -> bool { - return _load_culture_group(country_manager, total_expected_cultures, key, value); + return _load_culture_group(country_definition_manager, total_expected_cultures, key, value); } )(root); lock_culture_groups(); reserve_more_cultures(total_expected_cultures); ret &= expect_culture_group_dictionary( - [this, &country_manager](CultureGroup const& culture_group, ast::NodeCPtr culture_group_value) -> bool { + [this, &country_definition_manager](CultureGroup const& culture_group, ast::NodeCPtr culture_group_value) -> bool { return expect_dictionary( - [this, &country_manager, &culture_group](std::string_view key, ast::NodeCPtr value) -> bool { + [this, &country_definition_manager, &culture_group](std::string_view key, ast::NodeCPtr value) -> bool { static const string_set_t reserved_keys = { "leader", "unit", "union", "is_overseas" }; if (reserved_keys.contains(key)) { return true; } - return _load_culture(country_manager, culture_group, key, value); + return _load_culture(country_definition_manager, culture_group, key, value); } )(culture_group_value); } diff --git a/src/openvic-simulation/pop/Culture.hpp b/src/openvic-simulation/pop/Culture.hpp index 72ea3ee..9fe06de 100644 --- a/src/openvic-simulation/pop/Culture.hpp +++ b/src/openvic-simulation/pop/Culture.hpp @@ -5,8 +5,8 @@ namespace OpenVic { struct CultureManager; - struct Country; - struct CountryManager; + struct CountryDefinition; + struct CountryDefinitionManager; struct GraphicalCultureType : HasIdentifier { friend struct CultureManager; @@ -25,11 +25,12 @@ namespace OpenVic { std::string PROPERTY(leader); GraphicalCultureType const& PROPERTY(unit_graphical_culture_type); bool PROPERTY(is_overseas); - Country const* PROPERTY(union_country); + CountryDefinition const* PROPERTY(union_country); CultureGroup( std::string_view new_identifier, std::string_view new_leader, - GraphicalCultureType const& new_unit_graphical_culture_type, bool new_is_overseas, Country const* new_union_country + GraphicalCultureType const& new_unit_graphical_culture_type, bool new_is_overseas, + CountryDefinition const* new_union_country ); public: @@ -44,11 +45,11 @@ namespace OpenVic { name_list_t PROPERTY(first_names); name_list_t PROPERTY(last_names); fixed_point_t PROPERTY(radicalism); - Country const* PROPERTY(primary_country); + CountryDefinition const* PROPERTY(primary_country); Culture( std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, name_list_t&& new_first_names, - name_list_t&& new_last_names, fixed_point_t new_radicalism, Country const* new_primary_country + name_list_t&& new_last_names, fixed_point_t new_radicalism, CountryDefinition const* new_primary_country ); public: @@ -64,12 +65,12 @@ namespace OpenVic { GraphicalCultureType const* PROPERTY(default_graphical_culture_type); bool _load_culture_group( - CountryManager const& country_manager, size_t& total_expected_cultures, + CountryDefinitionManager const& country_definition_manager, size_t& total_expected_cultures, std::string_view culture_group_key, ast::NodeCPtr culture_group_node ); bool _load_culture( - CountryManager const& country_manager, CultureGroup const& culture_group, std::string_view culture_key, - ast::NodeCPtr node + CountryDefinitionManager const& country_definition_manager, CultureGroup const& culture_group, + std::string_view culture_key, ast::NodeCPtr node ); public: @@ -79,15 +80,15 @@ namespace OpenVic { bool add_culture_group( std::string_view identifier, std::string_view leader, GraphicalCultureType const* graphical_culture_type, - bool is_overseas, Country const* union_country + bool is_overseas, CountryDefinition const* union_country ); bool add_culture( std::string_view identifier, colour_t colour, CultureGroup const& group, name_list_t&& first_names, - name_list_t&& last_names, fixed_point_t radicalism, Country const* primary_country + name_list_t&& last_names, fixed_point_t radicalism, CountryDefinition const* primary_country ); bool load_graphical_culture_type_file(ast::NodeCPtr root); - bool load_culture_file(CountryManager const& country_manager, ast::NodeCPtr root); + bool load_culture_file(CountryDefinitionManager const& country_definition_manager, ast::NodeCPtr root); }; } diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index b1bf56f..4f8bdcb 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -1,6 +1,6 @@ #include "Pop.hpp" -#include "openvic-simulation/country/Country.hpp" +#include "openvic-simulation/country/CountryDefinition.hpp" #include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/politics/Issue.hpp" @@ -50,7 +50,7 @@ Pop::Pop( } void Pop::setup_pop_test_values( - IdeologyManager const& ideology_manager, IssueManager const& issue_manager, Country const& country + IdeologyManager const& ideology_manager, IssueManager const& issue_manager, CountryDefinition const& country ) { /* Returns +/- range% of size. */ const auto test_size = [this](int32_t range) -> pop_size_t { diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index a5033ef..b069f02 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -87,7 +87,7 @@ namespace OpenVic { Pop& operator=(Pop&&) = delete; void setup_pop_test_values( - IdeologyManager const& ideology_manager, IssueManager const& issue_manager, Country const& country + IdeologyManager const& ideology_manager, IssueManager const& issue_manager, CountryDefinition const& country ); }; -- cgit v1.2.3-56-ga3b1 From 45d66d887983177612d7cb8e715d5b28c1f87f31 Mon Sep 17 00:00:00 2001 From: hop311 Date: Thu, 27 Jun 2024 20:28:34 +0100 Subject: Use minimal PopBase for pop history --- src/openvic-simulation/history/ProvinceHistory.cpp | 2 +- src/openvic-simulation/history/ProvinceHistory.hpp | 4 +- src/openvic-simulation/map/ProvinceInstance.cpp | 10 ++-- src/openvic-simulation/map/ProvinceInstance.hpp | 4 +- src/openvic-simulation/pop/Pop.cpp | 38 ++++++++-------- src/openvic-simulation/pop/Pop.hpp | 53 ++++++++++++---------- 6 files changed, 58 insertions(+), 53 deletions(-) (limited to 'src/openvic-simulation/pop') diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp index f2291e8..1fa6e90 100644 --- a/src/openvic-simulation/history/ProvinceHistory.cpp +++ b/src/openvic-simulation/history/ProvinceHistory.cpp @@ -214,7 +214,7 @@ bool ProvinceHistoryEntry::_load_province_pop_history( return pop_manager.expect_pop_type_dictionary_reserve_length( pops, [this, &pop_manager, &rebel_manager, non_integer_size](PopType const& pop_type, ast::NodeCPtr pop_node) -> bool { - return pop_manager.load_pop_into_vector(rebel_manager, pops, pop_type, pop_node, non_integer_size); + return pop_manager.load_pop_bases_into_vector(rebel_manager, pops, pop_type, pop_node, non_integer_size); } )(root); } diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp index d6bf150..85853d7 100644 --- a/src/openvic-simulation/history/ProvinceHistory.hpp +++ b/src/openvic-simulation/history/ProvinceHistory.hpp @@ -39,9 +39,7 @@ namespace OpenVic { ordered_map PROPERTY(province_buildings); ordered_map PROPERTY(state_buildings); fixed_point_map_t PROPERTY(party_loyalties); - - // TODO - use minimal pop representation (size, type, culture, religion, consciousness, militancy, rebel type) - std::vector PROPERTY(pops); + std::vector PROPERTY(pops); ProvinceHistoryEntry(ProvinceDefinition const& new_province, Date new_date); diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 967d72b..61b1527 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -39,8 +39,8 @@ bool ProvinceInstance::expand_building(size_t building_index) { return building->expand(); } -void ProvinceInstance::_add_pop(Pop pop) { - pop.set_location(this); +void ProvinceInstance::_add_pop(Pop&& pop) { + pop.set_location(*this); pops.push_back(std::move(pop)); } @@ -54,11 +54,11 @@ bool ProvinceInstance::add_pop(Pop&& pop) { } } -bool ProvinceInstance::add_pop_vec(std::vector const& pop_vec) { +bool ProvinceInstance::add_pop_vec(std::vector const& pop_vec) { if (!province_definition.is_water()) { reserve_more(pops, pop_vec.size()); - for (Pop const& pop : pop_vec) { - _add_pop(pop); + for (PopBase const& pop : pop_vec) { + _add_pop(Pop { pop }); } return true; } else { diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index 8e8ec93..ca7f149 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -59,7 +59,7 @@ namespace OpenVic { ProvinceInstance(ProvinceDefinition const& new_province_definition); - void _add_pop(Pop pop); + void _add_pop(Pop&& pop); void _update_pops(); public: @@ -72,7 +72,7 @@ namespace OpenVic { bool expand_building(size_t building_index); bool add_pop(Pop&& pop); - bool add_pop_vec(std::vector const& pop_vec); + bool add_pop_vec(std::vector const& pop_vec); size_t get_pop_count() const; void update_gamestate(Date today); diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index 4f8bdcb..8f4c445 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -1,6 +1,7 @@ #include "Pop.hpp" #include "openvic-simulation/country/CountryDefinition.hpp" +#include "openvic-simulation/map/ProvinceInstance.hpp" #include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/politics/Issue.hpp" @@ -12,18 +13,14 @@ using namespace OpenVic::NodeTools; using enum PopType::income_type_t; -Pop::Pop( - PopType const& new_type, - Culture const& new_culture, - Religion const& new_religion, - pop_size_t new_size, - fixed_point_t new_militancy, - fixed_point_t new_consciousness, - RebelType const* new_rebel_type -) : type { new_type }, - culture { new_culture }, - religion { new_religion }, - size { new_size }, +PopBase::PopBase( + PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size, + fixed_point_t new_militancy, fixed_point_t new_consciousness, RebelType const* new_rebel_type +) : type { new_type }, culture { new_culture }, religion { new_religion }, size { new_size }, militancy { new_militancy }, + consciousness { new_consciousness }, rebel_type { new_rebel_type } {} + +Pop::Pop(PopBase const& pop_base) + : PopBase { pop_base }, location { nullptr }, total_change { 0 }, num_grown { 0 }, @@ -32,9 +29,6 @@ Pop::Pop( num_migrated_internal { 0 }, num_migrated_external { 0 }, num_migrated_colonial { 0 }, - militancy { new_militancy }, - consciousness { new_consciousness }, - rebel_type { new_rebel_type }, ideologies {}, issues {}, votes {}, @@ -117,6 +111,14 @@ void Pop::setup_pop_test_values( luxury_needs_fulfilled = test_range(); } +void Pop::set_location(ProvinceInstance const& new_location) { + if (location != &new_location) { + location = &new_location; + + // TODO - update location dependent attributes + } +} + Strata::Strata(std::string_view new_identifier) : HasIdentifier { new_identifier } {} PopType::PopType( @@ -596,8 +598,8 @@ bool PopManager::load_pop_type_chances_file(ast::NodeCPtr root) { )(root); } -bool PopManager::load_pop_into_vector( - RebelManager const& rebel_manager, std::vector& vec, PopType const& type, ast::NodeCPtr pop_node, +bool PopManager::load_pop_bases_into_vector( + RebelManager const& rebel_manager, std::vector& vec, PopType const& type, ast::NodeCPtr pop_node, bool *non_integer_size ) const { Culture const* culture = nullptr; @@ -620,7 +622,7 @@ bool PopManager::load_pop_into_vector( } if (culture != nullptr && religion != nullptr && size >= 1) { - vec.emplace_back(Pop { type, *culture, *religion, size.to_int64_t(), militancy, consciousness, rebel_type }); + vec.emplace_back(PopBase { type, *culture, *religion, size.to_int64_t(), militancy, consciousness, rebel_type }); } else { Logger::warning( "Some pop arguments are invalid: culture = ", culture, ", religion = ", religion, ", size = ", size diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index b069f02..8ac6d4c 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -26,22 +26,36 @@ namespace OpenVic { struct ProvinceInstance; struct CountryParty; - /* REQUIREMENTS: - * POP-18, POP-19, POP-20, POP-21, POP-34, POP-35, POP-36, POP-37 - */ - struct Pop { + struct PopBase { friend struct PopManager; using pop_size_t = int64_t; + protected: + PopType const& PROPERTY_ACCESS(type, protected); + Culture const& PROPERTY_ACCESS(culture, protected); + Religion const& PROPERTY_ACCESS(religion, protected); + pop_size_t PROPERTY_ACCESS(size, protected); + fixed_point_t PROPERTY_ACCESS(militancy, protected); + fixed_point_t PROPERTY_ACCESS(consciousness, protected); + RebelType const* PROPERTY_ACCESS(rebel_type, protected); + + PopBase( + PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size, + fixed_point_t new_militancy, fixed_point_t new_consciousness, RebelType const* new_rebel_type + ); + }; + + /* REQUIREMENTS: + * POP-18, POP-19, POP-20, POP-21, POP-34, POP-35, POP-36, POP-37 + */ + struct Pop : PopBase { + friend struct ProvinceInstance; + static constexpr pop_size_t MAX_SIZE = std::numeric_limits::max(); private: - PopType const& PROPERTY(type); - Culture const& PROPERTY(culture); - Religion const& PROPERTY(religion); - pop_size_t PROPERTY(size); - ProvinceInstance const* PROPERTY_RW(location); + ProvinceInstance const* PROPERTY(location); /* Last day's size change by source. */ pop_size_t PROPERTY(total_change); @@ -52,10 +66,7 @@ namespace OpenVic { pop_size_t PROPERTY(num_migrated_external); pop_size_t PROPERTY(num_migrated_colonial); - fixed_point_t PROPERTY(militancy); - fixed_point_t PROPERTY(consciousness); fixed_point_t PROPERTY(literacy); - RebelType const* PROPERTY(rebel_type); fixed_point_map_t PROPERTY(ideologies); fixed_point_map_t PROPERTY(issues); @@ -70,18 +81,10 @@ namespace OpenVic { fixed_point_t PROPERTY(everyday_needs_fulfilled); fixed_point_t PROPERTY(luxury_needs_fulfilled); - Pop( - PopType const& new_type, - Culture const& new_culture, - Religion const& new_religion, - pop_size_t new_size, - fixed_point_t new_militancy, - fixed_point_t new_consciousness, - RebelType const* new_rebel_type - ); + Pop(PopBase const& pop_base); public: - Pop(Pop const&) = default; + Pop(Pop const&) = delete; Pop(Pop&&) = default; Pop& operator=(Pop const&) = delete; Pop& operator=(Pop&&) = delete; @@ -89,6 +92,8 @@ namespace OpenVic { void setup_pop_test_values( IdeologyManager const& ideology_manager, IssueManager const& issue_manager, CountryDefinition const& country ); + + void set_location(ProvinceInstance const& new_location); }; struct Strata : HasIdentifier { @@ -319,8 +324,8 @@ namespace OpenVic { bool load_pop_type_chances_file(ast::NodeCPtr root); - bool load_pop_into_vector( - RebelManager const& rebel_manager, std::vector& vec, PopType const& type, ast::NodeCPtr pop_node, + bool load_pop_bases_into_vector( + RebelManager const& rebel_manager, std::vector& vec, PopType const& type, ast::NodeCPtr pop_node, bool *non_integer_size ) const; -- cgit v1.2.3-56-ga3b1