diff options
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r-- | src/openvic-simulation/history/CountryHistory.cpp | 30 | ||||
-rw-r--r-- | src/openvic-simulation/history/CountryHistory.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/history/ProvinceHistory.cpp | 2 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp index cd51e19..c5d8977 100644 --- a/src/openvic-simulation/history/CountryHistory.cpp +++ b/src/openvic-simulation/history/CountryHistory.cpp @@ -35,6 +35,33 @@ bool CountryHistoryMap::_load_history_entry( InventionManager const& invention_manager = definition_manager.get_research_manager().get_invention_manager(); DecisionManager const& decision_manager = definition_manager.get_decision_manager(); + const auto accepted_culture_instruction = [&entry](bool add) { + return [&entry, add](Culture const& culture) -> bool { + const auto it = entry.accepted_cultures.find(&culture); + if (it == entry.accepted_cultures.end()) { + // No current culture instruction + entry.accepted_cultures.emplace(&culture, add); + return true; + } else if (it->second == add) { + // Desired culture instruction already exists + Logger::warning( + "Duplicate attempt to ", add ? "add" : "remove", " accepted culture ", culture.get_identifier(), + " ", add ? "to" : "from", " country history of ", entry.get_country() + ); + return true; + } else { + // Opposite culture instruction exists + entry.accepted_cultures.erase(it); + Logger::warning( + "Attempted to ", add ? "add" : "remove", " accepted culture ", culture.get_identifier(), + " ", add ? "to" : "from", " country history of ", entry.get_country(), + " after previously ", add ? "removing" : "adding", " it" + ); + return true; + } + }; + }; + return expect_dictionary_keys_and_default( [this, &definition_manager, &dataloader, &deployment_manager, &issue_manager, &technology_manager, &invention_manager, &country_definition_manager, &entry](std::string_view key, ast::NodeCPtr value) -> bool { @@ -84,7 +111,8 @@ 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(set_callback_pointer(entry.accepted_cultures)), + "culture", ZERO_OR_MORE, culture_manager.expect_culture_identifier(accepted_culture_instruction(true)), + "remove_culture", ZERO_OR_MORE, culture_manager.expect_culture_identifier(accepted_culture_instruction(false)), "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 04de653..7ee9d6b 100644 --- a/src/openvic-simulation/history/CountryHistory.hpp +++ b/src/openvic-simulation/history/CountryHistory.hpp @@ -33,7 +33,7 @@ namespace OpenVic { CountryDefinition const& PROPERTY(country); std::optional<Culture const*> PROPERTY(primary_culture); - ordered_set<Culture const*> PROPERTY(accepted_cultures); + ordered_map<Culture const*, bool> PROPERTY(accepted_cultures); std::optional<Religion const*> PROPERTY(religion); std::optional<CountryParty const*> PROPERTY(ruling_party); std::optional<Date> PROPERTY(last_election); diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp index ef8793b..60fcbe4 100644 --- a/src/openvic-simulation/history/ProvinceHistory.cpp +++ b/src/openvic-simulation/history/ProvinceHistory.cpp @@ -50,7 +50,7 @@ bool ProvinceHistoryMap::_load_history_entry( 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" + " after previously ", add ? "removing" : "adding", " it" ); return true; } |