From 83a61b6641c9e85c432953c39f9284d3101ce112 Mon Sep 17 00:00:00 2001 From: BrickPi <49528459+BrickPi@users.noreply.github.com> Date: Sat, 11 Nov 2023 11:56:09 -0600 Subject: Apply Province Histories --- src/openvic-simulation/map/Province.cpp | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/openvic-simulation/map/Province.cpp') diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 77bf33f..099ba9b 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -1,5 +1,7 @@ #include "Province.hpp" +#include "openvic-simulation/history/ProvinceHistory.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -42,6 +44,22 @@ Province::colony_status_t Province::get_colony_status() const { return colony_status; } +Country const* Province::get_owner() const { + return owner; +} + +Country const* Province::get_controller() const { + return controller; +} + +std::vector const& Province::get_cores() const { + return cores; +} + +bool Province::is_slave() const { + return slave; +} + bool Province::load_positions(BuildingManager const& building_manager, ast::NodeCPtr root) { return expect_dictionary_keys( "text_position", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.text)), @@ -204,3 +222,39 @@ std::vector const& Province::get_adjacencies() const { void Province::_set_terrain_type(TerrainType const* type) { terrain_type = type; } + +void Province::apply_history_to_province(ProvinceHistoryMap const& history, Date date) { + auto entries = history.get_entries(date); + + reset_buildings(); + + for (const auto& entry : entries) { + if (entry->get_life_rating()) life_rating = *entry->get_life_rating(); + if (entry->get_colonial()) colony_status = *entry->get_colonial(); + if (entry->get_rgo()) rgo = *entry->get_rgo(); + if (entry->get_terrain_type()) terrain_type = *entry->get_terrain_type(); + if (entry->get_owner()) owner = *entry->get_owner(); + if (entry->get_controller()) controller = *entry->get_controller(); + if (entry->get_slave()) slave = *entry->get_slave(); + for (const auto& core : entry->get_remove_cores()) { + const auto existing_core = std::find(cores.begin(), cores.end(), core); + if (existing_core != cores.end()) cores.erase(existing_core); + } + for (const auto& core : entry->get_add_cores()) { + const auto existing_core = std::find(cores.begin(), cores.end(), core); + if (existing_core == cores.end()) cores.push_back(core); + } + // TODO: rework province buildings + for (const auto& building : entry->get_buildings()) { + BuildingInstance* existing_entry = buildings.get_item_by_identifier(building.first->get_identifier()); + if (existing_entry != nullptr) { + existing_entry->set_level(building.second); + } else { + BuildingInstance instance = { *building.first }; + instance.set_level(building.second); + add_building(std::move(instance)); + } + } + // TODO: party loyalties for each POP when implemented on POP side + } +} -- cgit v1.2.3-56-ga3b1