diff options
author | hop311 <hop3114@gmail.com> | 2024-07-21 15:09:25 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-07-22 20:21:27 +0200 |
commit | 67cbd14630c4344902d3fa1ddca178809da4293b (patch) | |
tree | 9df96829dd0f9a0bd7c2e6b0e047547aa4bff3a7 /src/openvic-simulation/history | |
parent | d1f3a96b72dd06b5f97dd4643e5f016a02b42ea6 (diff) |
Fleshing out Country, State and Province instances + historycountry-instance
Diffstat (limited to 'src/openvic-simulation/history')
4 files changed, 34 insertions, 17 deletions
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp index 935a769..145d26b 100644 --- a/src/openvic-simulation/history/CountryHistory.cpp +++ b/src/openvic-simulation/history/CountryHistory.cpp @@ -47,14 +47,7 @@ bool CountryHistoryMap::_load_history_entry( " when it actually belongs to ", reform.get_reform_group(), " in history of ", entry.get_country() ); } - if (std::find(entry.reforms.begin(), entry.reforms.end(), &reform) != entry.reforms.end()) { - Logger::error( - "Redefinition of reform ", reform.get_identifier(), " in history of ", entry.get_country() - ); - return false; - } - entry.reforms.push_back(&reform); - return true; + return set_callback_pointer(entry.reforms)(reform); })(value); } @@ -81,9 +74,7 @@ bool CountryHistoryMap::_load_history_entry( ), "primary_culture", ZERO_OR_ONE, culture_manager.expect_culture_identifier(assign_variable_callback_pointer_opt(entry.primary_culture)), - "culture", ZERO_OR_MORE, culture_manager.expect_culture_identifier( - vector_callback_pointer(entry.accepted_cultures) - ), + "culture", ZERO_OR_MORE, culture_manager.expect_culture_identifier(set_callback_pointer(entry.accepted_cultures)), "religion", ZERO_OR_ONE, definition_manager.get_pop_manager().get_religion_manager().expect_religion_identifier( assign_variable_callback_pointer_opt(entry.religion) ), diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp index c74841d..d6a6997 100644 --- a/src/openvic-simulation/history/CountryHistory.hpp +++ b/src/openvic-simulation/history/CountryHistory.hpp @@ -32,7 +32,7 @@ namespace OpenVic { CountryDefinition const& PROPERTY(country); std::optional<Culture const*> PROPERTY(primary_culture); - std::vector<Culture const*> PROPERTY(accepted_cultures); + ordered_set<Culture const*> PROPERTY(accepted_cultures); std::optional<Religion const*> PROPERTY(religion); std::optional<CountryParty const*> PROPERTY(ruling_party); std::optional<Date> PROPERTY(last_election); @@ -43,7 +43,7 @@ namespace OpenVic { std::optional<NationalValue const*> PROPERTY(national_value); std::optional<bool> PROPERTY_CUSTOM_PREFIX(civilised, is); std::optional<fixed_point_t> PROPERTY(prestige); - std::vector<Reform const*> PROPERTY(reforms); + ordered_set<Reform const*> PROPERTY(reforms); std::optional<Deployment const*> PROPERTY(inital_oob); std::optional<TechnologySchool const*> PROPERTY(tech_school); ordered_map<Technology const*, bool> PROPERTY(technologies); diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp index 1fa6e90..ca0bf4e 100644 --- a/src/openvic-simulation/history/ProvinceHistory.cpp +++ b/src/openvic-simulation/history/ProvinceHistory.cpp @@ -30,6 +30,33 @@ bool ProvinceHistoryMap::_load_history_entry( { "0", STATE }, { "1", PROTECTORATE }, { "2", COLONY } }; + const auto set_core_instruction = [&entry](bool add) { + return [&entry, add](CountryDefinition const& country) -> bool { + const auto it = entry.cores.find(&country); + if (it == entry.cores.end()) { + // No current core instruction + entry.cores.emplace(&country, add); + return true; + } else if (it->second == add) { + // Desired core instruction already exists + Logger::warning( + "Duplicate attempt to ", add ? "add" : "remove", " core of country ", country.get_identifier(), + " ", add ? "to" : "from", " province history of ", entry.get_province() + ); + return true; + } else { + // Opposite core instruction exists + entry.cores.erase(it); + Logger::warning( + "Attempted to ", add ? "add" : "remove", " core of country ", country.get_identifier(), + " ", add ? "to" : "from", " province history of ", entry.get_province(), + " after previously ", add ? "adding" : "removing", " it" + ); + return true; + } + }; + }; + return expect_dictionary_keys_and_default( [this, &definition_manager, &building_type_manager, &entry]( std::string_view key, ast::NodeCPtr value) -> bool { @@ -60,10 +87,10 @@ bool ProvinceHistoryMap::_load_history_entry( assign_variable_callback_pointer_opt(entry.controller, true) ), "add_core", ZERO_OR_MORE, country_definition_manager.expect_country_definition_identifier( - vector_callback_pointer(entry.add_cores) + set_core_instruction(true) ), "remove_core", ZERO_OR_MORE, country_definition_manager.expect_country_definition_identifier( - vector_callback_pointer(entry.remove_cores) + set_core_instruction(false) ), "colonial", ZERO_OR_ONE, expect_identifier(expect_mapped_string(colony_status_map, assign_variable_callback(entry.colonial))), diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp index 85853d7..99ea2af 100644 --- a/src/openvic-simulation/history/ProvinceHistory.hpp +++ b/src/openvic-simulation/history/ProvinceHistory.hpp @@ -31,8 +31,7 @@ namespace OpenVic { std::optional<CountryDefinition const*> PROPERTY(controller); std::optional<ProvinceInstance::colony_status_t> PROPERTY(colonial); std::optional<bool> PROPERTY(slave); - std::vector<CountryDefinition const*> PROPERTY(add_cores); - std::vector<CountryDefinition const*> PROPERTY(remove_cores); + ordered_map<CountryDefinition const*, bool> PROPERTY(cores); std::optional<GoodDefinition const*> PROPERTY(rgo); std::optional<ProvinceInstance::life_rating_t> PROPERTY(life_rating); std::optional<TerrainType const*> PROPERTY(terrain_type); |