aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author zaaarf <me@zaaarf.foo>2024-09-27 12:10:59 +0200
committer zaaarf <me@zaaarf.foo>2024-09-27 12:10:59 +0200
commit45ea5382921f71bd247f57210937c3d384d46cdf (patch)
treefbb752ea8c4bba4448dddcb87e5541df89f684fc /src
parent7e895eaea194e266b112cb507b0d643083f2ad4b (diff)
Added support for remove_culture custom instructionremove-culture
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp10
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp30
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp2
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp2
4 files changed, 38 insertions, 6 deletions
diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp
index 183b0c8..55ceb23 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -671,9 +671,13 @@ bool CountryInstance::apply_history_to_country(
bool ret = true;
- set_optional(primary_culture, entry.get_primary_culture());
- for (Culture const* culture : entry.get_accepted_cultures()) {
- ret &= add_accepted_culture(*culture);
+ set_optional(primary_culture, entry.get_primary_culture());
+ for (auto const& [culture, add] : entry.get_accepted_cultures()) {
+ if (add) {
+ ret &= add_accepted_culture(*culture);
+ } else {
+ ret &= remove_accepted_culture(*culture);
+ }
}
set_optional(religion, entry.get_religion());
if (entry.get_ruling_party()) {
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;
}