diff options
author | zaaarf <me@zaaarf.foo> | 2023-12-10 13:35:25 +0100 |
---|---|---|
committer | zaaarf <me@zaaarf.foo> | 2023-12-10 23:19:43 +0100 |
commit | 85155e033e9b03d71752626137a75f6418a5786c (patch) | |
tree | 986b02c46996447780975f389b9b99d01a5fc600 /src/openvic-simulation/history/ProvinceHistory.cpp | |
parent | 34fbe27857d77d6f193d6d1848b953a4596cedd2 (diff) |
feat: implemented pop history loading
Diffstat (limited to 'src/openvic-simulation/history/ProvinceHistory.cpp')
-rw-r--r-- | src/openvic-simulation/history/ProvinceHistory.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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 |