aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/ProvinceInstance.cpp
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-09-22 10:48:18 +0200
committer wvpm <24685035+wvpm@users.noreply.github.com>2024-09-22 10:48:18 +0200
commitea9b695022d197d918f1bb4292a0f424018dad37 (patch)
tree15d46970d136b08da9adf53a86e54fa97675cab2 /src/openvic-simulation/map/ProvinceInstance.cpp
parent61ccb748627a3faeec282f53f746045d1a695517 (diff)
Map province history rgo to production type for province instance
Diffstat (limited to 'src/openvic-simulation/map/ProvinceInstance.cpp')
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index 06b3f1e..1d69fec 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -1,6 +1,8 @@
#include "ProvinceInstance.hpp"
#include "openvic-simulation/country/CountryInstance.hpp"
+#include "openvic-simulation/economy/GoodDefinition.hpp"
+#include "openvic-simulation/economy/production/ProductionType.hpp"
#include "openvic-simulation/history/ProvinceHistory.hpp"
#include "openvic-simulation/map/ProvinceDefinition.hpp"
#include "openvic-simulation/military/UnitInstanceGroup.hpp"
@@ -23,7 +25,7 @@ ProvinceInstance::ProvinceInstance(
cores {},
slave { false },
crime { nullptr },
- rgo { nullptr },
+ rgo_production_type { nullptr },
buildings { "buildings", false },
armies {},
navies {},
@@ -255,7 +257,7 @@ bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) {
return ret;
}
-bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager) {
+bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager) {
bool ret = true;
constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const& source) {
@@ -279,7 +281,25 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
ret &= remove_core(country_manager.get_country_instance_from_definition(*country));
}
}
- set_optional(rgo, entry.get_rgo());
+
+ auto const& rgo_good_optional = entry.get_rgo();
+ if(rgo_good_optional.has_value()) {
+ GoodDefinition const* const rgo_good = rgo_good_optional.value();
+ if(rgo_good != nullptr) {
+ IndexedMap<GoodDefinition, ProductionType const*> const& good_to_rgo_production_type = production_type_manager.get_good_to_rgo_production_type();
+ ProductionType const* rgo_production_type = good_to_rgo_production_type[*rgo_good];
+ if(rgo_production_type!= nullptr) {
+ set_rgo_production_type(rgo_production_type);
+ }
+ else {
+ //error we expect the good to have an rgo production type but there is none
+ //Victoria 2 treats this as null, but clearly the modder wanted there to be a good
+ }
+ }
+ //else explicitly set null, no-op
+ }
+ //else default null, no-op
+
set_optional(life_rating, entry.get_life_rating());
set_optional(terrain_type, entry.get_terrain_type());
for (auto const& [building, level] : entry.get_province_buildings()) {