aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
author zaaarf <me@zaaarf.foo>2023-12-10 13:35:25 +0100
committer zaaarf <me@zaaarf.foo>2023-12-10 23:19:43 +0100
commit85155e033e9b03d71752626137a75f6418a5786c (patch)
tree986b02c46996447780975f389b9b99d01a5fc600 /src/openvic-simulation/history
parent34fbe27857d77d6f193d6d1848b953a4596cedd2 (diff)
feat: implemented pop history loading
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/HistoryMap.hpp4
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp44
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp6
3 files changed, 52 insertions, 2 deletions
diff --git a/src/openvic-simulation/history/HistoryMap.hpp b/src/openvic-simulation/history/HistoryMap.hpp
index 07f54f0..4a79474 100644
--- a/src/openvic-simulation/history/HistoryMap.hpp
+++ b/src/openvic-simulation/history/HistoryMap.hpp
@@ -27,8 +27,6 @@ namespace OpenVic {
using entry_type = _Entry;
private:
- std::map<Date, std::unique_ptr<entry_type>> PROPERTY(entries);
-
bool _try_load_history_entry(GameManager const& game_manager, Args... args, Date date, ast::NodeCPtr root) {
const Date end_date = _get_end_date(game_manager);
if (date > end_date) {
@@ -49,6 +47,8 @@ namespace OpenVic {
}
protected:
+ std::map<Date, std::unique_ptr<entry_type>> PROPERTY_ACCESS(entries, protected);
+
HistoryMap() = default;
virtual std::unique_ptr<entry_type> _make_entry(Date date) const = 0;
diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp
index d9d3ef6..61638bc 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -2,6 +2,7 @@
#include "openvic-simulation/GameManager.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include <memory>
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -15,6 +16,37 @@ std::unique_ptr<ProvinceHistoryEntry> ProvinceHistoryMap::_make_entry(Date date)
return std::unique_ptr<ProvinceHistoryEntry> { new ProvinceHistoryEntry { province, date } };
}
+ProvinceHistoryEntry* ProvinceHistoryMap::_get_entry(Date date) {
+ return entries.at(date).get();
+}
+
+bool ProvinceHistoryEntry::_load_province_pop_history(PopManager const& pop_manager, ast::NodeCPtr root) {
+ return pop_manager.expect_pop_type_dictionary([this, &pop_manager](PopType const& type, ast::NodeCPtr pop_node) -> bool {
+ CultureManager const& culture_manager = pop_manager.get_culture_manager();
+ ReligionManager const& religion_manager = pop_manager.get_religion_manager();
+ Culture const* culture = nullptr;
+ Religion const* religion = nullptr;
+ Pop::pop_size_t size = 0;
+ bool ret = expect_dictionary_keys(
+ "culture", ONE_EXACTLY, culture_manager.expect_culture_identifier(assign_variable_callback_pointer(culture)),
+ "religion", ONE_EXACTLY, religion_manager.expect_religion_identifier(assign_variable_callback_pointer(religion)),
+ "size", ONE_EXACTLY, expect_uint(assign_variable_callback(size)),
+ "militancy", ZERO_OR_ONE, success_callback,
+ "rebel_type", ZERO_OR_ONE, success_callback
+ )(pop_node);
+ if (culture != nullptr && religion != nullptr && size > 0) {
+ pops.emplace_back(Pop { type, *culture, *religion, size });
+ } else {
+ Logger::warning(
+ "Some pop arguments are invalid: province = ", province, ", type = ", type, ", culture = ", culture,
+ ", religion = ", religion, ", size = ", size
+ );
+ }
+ return ret;
+ }
+ )(root);
+}
+
bool ProvinceHistoryMap::_load_history_entry(
GameManager const& game_manager, ProvinceHistoryEntry& entry, ast::NodeCPtr root
) {
@@ -161,3 +193,15 @@ bool ProvinceHistoryManager::load_province_history_file(
return province_history._load_history_file(game_manager, root);
}
+
+bool ProvinceHistoryManager::load_pop_history_file(GameManager const& game_manager, Date date, ast::NodeCPtr root) {
+ PopManager const& pop_manager = game_manager.get_pop_manager();
+ return game_manager.get_map().expect_province_dictionary([this, &pop_manager, date](Province const& province, ast::NodeCPtr node) -> bool {
+ if (province_histories.contains(&province)) {
+ ProvinceHistoryEntry* entry = province_histories.at(&province)._get_entry(date);
+ return entry != nullptr
+ ? entry->_load_province_pop_history(pop_manager, node)
+ : false;
+ } else return false;
+ })(root);
+} \ No newline at end of file
diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp
index e4adc08..b69408e 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -17,6 +17,7 @@ namespace OpenVic {
struct ProvinceHistoryEntry : HistoryEntry {
friend struct ProvinceHistoryMap;
+ friend struct ProvinceHistoryManager;
private:
Province const& PROPERTY(province);
@@ -33,8 +34,10 @@ namespace OpenVic {
std::map<BuildingType const*, BuildingType::level_t> PROPERTY(province_buildings);
std::map<BuildingType const*, BuildingType::level_t> PROPERTY(state_buildings);
fixed_point_map_t<Ideology const*> PROPERTY(party_loyalties);
+ std::vector<Pop> PROPERTY(pops);
ProvinceHistoryEntry(Province const& new_province, Date new_date);
+ bool _load_province_pop_history(PopManager const& pop_manager, ast::NodeCPtr root);
};
struct ProvinceHistoryManager;
@@ -45,6 +48,8 @@ namespace OpenVic {
private:
Province const& PROPERTY(province);
+ ProvinceHistoryEntry* _get_entry(Date date);
+
protected:
ProvinceHistoryMap(Province const& new_province);
@@ -66,5 +71,6 @@ namespace OpenVic {
ProvinceHistoryMap const* get_province_history(Province const* province) const;
bool load_province_history_file(GameManager const& game_manager, Province const& province, ast::NodeCPtr root);
+ bool load_pop_history_file(GameManager const& game_manager, Date date, ast::NodeCPtr root);
};
} // namespace OpenVic