aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author BrickPi <49528459+BrickPi@users.noreply.github.com>2023-11-12 17:49:15 +0100
committer GitHub <noreply@github.com>2023-11-12 17:49:15 +0100
commitc8983f5cda0b396b76c9d1491cf4c8ff5997d420 (patch)
tree96b80c19116ea6685bad2bde34f0365df58fb408
parentfd85491cdbb13760f039787e0d19d534a24027fb (diff)
parent83a61b6641c9e85c432953c39f9284d3101ce112 (diff)
Merge pull request #73 from OpenVicProject/history-integration
Apply Province Histories
-rw-r--r--src/openvic-simulation/country/Country.hpp1
-rw-r--r--src/openvic-simulation/economy/Building.cpp4
-rw-r--r--src/openvic-simulation/economy/Building.hpp5
-rw-r--r--src/openvic-simulation/history/DiplomaticHistory.hpp1
-rw-r--r--src/openvic-simulation/map/Province.cpp54
-rw-r--r--src/openvic-simulation/map/Province.hpp14
6 files changed, 76 insertions, 3 deletions
diff --git a/src/openvic-simulation/country/Country.hpp b/src/openvic-simulation/country/Country.hpp
index 50cca04..fa38293 100644
--- a/src/openvic-simulation/country/Country.hpp
+++ b/src/openvic-simulation/country/Country.hpp
@@ -10,7 +10,6 @@
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
#include "openvic-simulation/dataloader/Dataloader.hpp"
-#include "openvic-simulation/map/Province.hpp"
#include "openvic-simulation/military/Unit.hpp"
#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
diff --git a/src/openvic-simulation/economy/Building.cpp b/src/openvic-simulation/economy/Building.cpp
index 38a8863..bade4a5 100644
--- a/src/openvic-simulation/economy/Building.cpp
+++ b/src/openvic-simulation/economy/Building.cpp
@@ -125,6 +125,10 @@ BuildingInstance::level_t BuildingInstance::get_current_level() const {
return level;
}
+void BuildingInstance::set_level(BuildingInstance::level_t new_level) {
+ level = new_level;
+}
+
ExpansionState BuildingInstance::get_expansion_state() const {
return expansion_state;
}
diff --git a/src/openvic-simulation/economy/Building.hpp b/src/openvic-simulation/economy/Building.hpp
index e907e49..c2eb1ef 100644
--- a/src/openvic-simulation/economy/Building.hpp
+++ b/src/openvic-simulation/economy/Building.hpp
@@ -124,14 +124,15 @@ namespace OpenVic {
bool _can_expand() const;
- BuildingInstance(Building const& building);
-
public:
+ BuildingInstance(Building const& building);
BuildingInstance(BuildingInstance&&) = default;
Building const& get_building() const;
level_t get_current_level() const;
+ void set_level(level_t new_level);
+
ExpansionState get_expansion_state() const;
Date get_start_date() const;
Date get_end_date() const;
diff --git a/src/openvic-simulation/history/DiplomaticHistory.hpp b/src/openvic-simulation/history/DiplomaticHistory.hpp
index 84c2bd7..85e2654 100644
--- a/src/openvic-simulation/history/DiplomaticHistory.hpp
+++ b/src/openvic-simulation/history/DiplomaticHistory.hpp
@@ -7,6 +7,7 @@
#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/military/Wargoal.hpp"
+#include "openvic-simulation/map/Province.hpp"
namespace OpenVic {
struct DiplomaticHistoryManager;
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<Country const*> 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<Province::adjacency_t> 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
+ }
+}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index 2fd15c9..eda05fb 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -5,6 +5,7 @@
#include "openvic-simulation/economy/Building.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/pop/Pop.hpp"
+#include "openvic-simulation/country/Country.hpp"
namespace OpenVic {
struct Map;
@@ -12,6 +13,7 @@ namespace OpenVic {
struct Good;
struct TerrainType;
struct TerrainTypeMapping;
+ struct ProvinceHistoryMap;
/* REQUIREMENTS:
* MAP-5, MAP-7, MAP-8, MAP-43, MAP-47
@@ -85,6 +87,11 @@ namespace OpenVic {
void _set_terrain_type(TerrainType const* type);
+ Country const* owner = nullptr;
+ Country const* controller = nullptr;
+ std::vector<Country const*> cores;
+ bool slave = false;
+
Province(std::string_view new_identifier, colour_t new_colour, index_t new_index);
public:
@@ -121,5 +128,12 @@ namespace OpenVic {
bool is_adjacent_to(Province const* province);
bool add_adjacency(Province const* province, distance_t distance, flags_t flags);
std::vector<adjacency_t> const& get_adjacencies() const;
+
+ Country const* get_owner() const;
+ Country const* get_controller() const;
+ std::vector<Country const*> const& get_cores() const;
+ bool is_slave() const;
+
+ void apply_history_to_province(ProvinceHistoryMap const& history, Date date);
};
}