aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp13
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp4
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp31
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp3
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);