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.cpp30
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp2
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp22
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp2
4 files changed, 51 insertions, 5 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..bc92f48 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -1,7 +1,9 @@
#include "ProvinceHistory.hpp"
#include "openvic-simulation/DefinitionManager.hpp"
+#include "openvic-simulation/economy/GoodDefinition.hpp"
#include "openvic-simulation/map/ProvinceDefinition.hpp"
+#include "openvic-simulation/utility/Logger.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -50,13 +52,16 @@ 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;
}
};
};
+ constexpr bool allow_empty_true = true;
+ constexpr bool do_warn = true;
+
return expect_dictionary_keys_and_default(
[this, &definition_manager, &building_type_manager, &entry](
std::string_view key, ast::NodeCPtr value) -> bool {
@@ -98,7 +103,20 @@ bool ProvinceHistoryMap::_load_history_entry(
expect_identifier(expect_mapped_string(colony_status_map, assign_variable_callback(entry.colonial))),
"is_slave", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.slave)),
"trade_goods", ZERO_OR_ONE,
- good_definition_manager.expect_good_definition_identifier(assign_variable_callback_pointer_opt(entry.rgo)),
+ good_definition_manager.expect_good_definition_identifier_or_string(
+ [&definition_manager, &entry](GoodDefinition const& rgo_good) ->bool {
+ entry.rgo_production_type_nullable = definition_manager.get_economy_manager().get_production_type_manager().get_good_to_rgo_production_type()[rgo_good];
+ if (entry.rgo_production_type_nullable == nullptr) {
+ Logger::error(entry.province.get_identifier(), " has trade_goods ", rgo_good.get_identifier(), " which has no rgo production type defined.");
+ //we expect the good to have an rgo production type
+ //Victoria 2 treats this as null, but clearly the modder wanted there to be a good
+ return false;
+ }
+ return true;
+ },
+ allow_empty_true, //could be explicitly setting trade_goods to null
+ do_warn //could be typo in good identifier
+ ),
"life_rating", ZERO_OR_ONE, expect_uint<ProvinceInstance::life_rating_t>(assign_variable_callback(entry.life_rating)),
"terrain", ZERO_OR_ONE, terrain_type_manager.expect_terrain_type_identifier(
assign_variable_callback_pointer_opt(entry.terrain_type)
diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp
index 99ea2af..f44fc81 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -32,7 +32,7 @@ namespace OpenVic {
std::optional<ProvinceInstance::colony_status_t> PROPERTY(colonial);
std::optional<bool> PROPERTY(slave);
ordered_map<CountryDefinition const*, bool> PROPERTY(cores);
- std::optional<GoodDefinition const*> PROPERTY(rgo);
+ std::optional<ProductionType const*> PROPERTY(rgo_production_type_nullable);
std::optional<ProvinceInstance::life_rating_t> PROPERTY(life_rating);
std::optional<TerrainType const*> PROPERTY(terrain_type);
ordered_map<BuildingType const*, BuildingType::level_t> PROPERTY(province_buildings);