From 5688655934d8851a09ebfbc1149fadf3a5bafdd0 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sat, 9 Dec 2023 15:18:43 +0100 Subject: feat: loading techs, inventions and foreign investments in country history --- src/openvic-simulation/history/CountryHistory.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/openvic-simulation/history/CountryHistory.hpp') diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp index ed200bf..0ffab23 100644 --- a/src/openvic-simulation/history/CountryHistory.hpp +++ b/src/openvic-simulation/history/CountryHistory.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "openvic-simulation/country/Country.hpp" @@ -16,6 +17,8 @@ #include "openvic-simulation/pop/Religion.hpp" #include "openvic-simulation/types/Colour.hpp" #include "openvic-simulation/types/Date.hpp" +#include "openvic-simulation/research/Invention.hpp" +#include "openvic-simulation/research/Technology.hpp" namespace OpenVic { struct CountryHistoryMap; @@ -40,8 +43,10 @@ namespace OpenVic { std::optional PROPERTY(prestige); std::vector PROPERTY(reforms); std::optional PROPERTY(inital_oob); - // TODO: technologies, tech schools, and inventions when PR#51 merged - // TODO: starting foreign investment + std::optional PROPERTY(tech_school); + std::map PROPERTY(technologies); + std::map PROPERTY(inventions); + fixed_point_map_t PROPERTY(foreign_investment); CountryHistoryEntry(Country const& new_country, Date new_date); }; -- cgit v1.2.3-56-ga3b1 From 2c562ac2d29942844f0aa4c44339ddd88489db8a Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sun, 10 Dec 2023 01:38:35 +0100 Subject: feat: added missing country history keys (except decisions) --- src/openvic-simulation/country/CountryInstance.cpp | 2 +- src/openvic-simulation/dataloader/NodeTools.hpp | 3 +- src/openvic-simulation/history/CountryHistory.cpp | 41 ++++++++++++++++------ src/openvic-simulation/history/CountryHistory.hpp | 16 +++++++-- src/openvic-simulation/research/Invention.hpp | 6 ++-- src/openvic-simulation/research/Technology.hpp | 4 +-- 6 files changed, 51 insertions(+), 21 deletions(-) (limited to 'src/openvic-simulation/history/CountryHistory.hpp') diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index d4f9be7..5da787e 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -69,7 +69,7 @@ bool CountryInstance::apply_history_to_country(CountryHistoryMap const& history, if (entry->get_government_type()) government_type = *entry->get_government_type(); if (entry->get_plurality()) plurality = *entry->get_plurality(); if (entry->get_national_value()) national_value = *entry->get_national_value(); - if (entry->get_civilised()) civilised = *entry->get_civilised(); + if (entry->is_civilised()) civilised = *entry->is_civilised(); if (entry->get_prestige()) prestige = *entry->get_prestige(); for (Reform const* reform : entry->get_reforms()) { ret &= add_reform(reform); diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 45e6d4f..02ff239 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include @@ -344,7 +343,7 @@ namespace OpenVic { } template - Callback auto set_callback_pointer(std::unordered_set& set) { + Callback auto set_callback_pointer(std::set& set) { return [&set](T const& val) -> bool { set.insert(&val); return true; diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp index b42149b..9ee7d65 100644 --- a/src/openvic-simulation/history/CountryHistory.cpp +++ b/src/openvic-simulation/history/CountryHistory.cpp @@ -1,6 +1,7 @@ #include "CountryHistory.hpp" #include "openvic-simulation/GameManager.hpp" +#include using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -52,14 +53,9 @@ bool CountryHistoryMap::_load_history_entry( Technology const* technology = technology_manager.get_technology_by_identifier(key); if (technology != nullptr) { - uint8_t flag = -1; - if (expect_uint(assign_variable_callback(flag))(value)) { - if (flag == 1) return entry.technologies.emplace(technology, true).second; - else if (flag == 0) return entry.technologies.emplace(technology, false).second; - else { - Logger::warning("Refusing to load country history technology with non-boolean value: ", key, ", ", flag); - return true; - } + bool flag; + if (expect_int_bool(assign_variable_callback(flag))(value)) { + return entry.technologies.emplace(technology, flag).second; } else return false; } @@ -72,7 +68,7 @@ bool CountryHistoryMap::_load_history_entry( } return _load_history_sub_entry_callback( - game_manager, dataloader, deployment_manager, entry.get_date(), value, key, value, key_value_success_callback + game_manager, dataloader, deployment_manager, entry.get_date(), value, key, value ); }, /* we have to use a lambda, assign_variable_callback_pointer @@ -120,7 +116,32 @@ bool CountryHistoryMap::_load_history_entry( "schools", ZERO_OR_ONE, technology_manager.expect_technology_school_identifier( assign_variable_callback_pointer(entry.tech_school) ), - "foreign_investment", ZERO_OR_ONE, country_manager.expect_country_decimal_map(move_variable_callback(entry.foreign_investment)) + "foreign_investment", ZERO_OR_ONE, country_manager.expect_country_decimal_map(move_variable_callback(entry.foreign_investment)), + "literacy", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.literacy)), + "non_state_culture_literacy", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.nonstate_culture_literacy)), + "consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.consciousness)), + "nonstate_consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.nonstate_consciousness)), + "is_releasable_vassal", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.releasable_vassal)), + "decision", ZERO_OR_ONE, success_callback, //TODO: decisions + "govt_flag", ZERO_OR_ONE, [&entry, &politics_manager](ast::NodeCPtr value) -> bool { + GovernmentType const* government_type = nullptr; + std::string_view flag; + bool ret = expect_dictionary_keys( + "government", ONE_EXACTLY, politics_manager.get_government_type_manager() + .expect_government_type_identifier(assign_variable_callback_pointer(government_type)), + "flag", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(flag)) + )(value); + if (government_type != nullptr) { + return ret & entry.government_flags.emplace(government_type, flag).second; + } else return false; + }, + "colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.colonial_points)), + "set_country_flag", ZERO_OR_ONE, expect_identifier_or_string([&entry](std::string_view flag) -> bool { + return entry.country_flags.emplace(flag).second; + }), + "set_global_flag", ZERO_OR_ONE, expect_identifier_or_string([&entry](std::string_view flag) -> bool { + return entry.global_flags.emplace(flag).second; + }) )(root); } diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp index 0ffab23..af7d502 100644 --- a/src/openvic-simulation/history/CountryHistory.hpp +++ b/src/openvic-simulation/history/CountryHistory.hpp @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include #include "openvic-simulation/country/Country.hpp" #include "openvic-simulation/history/Bookmark.hpp" @@ -39,7 +38,7 @@ namespace OpenVic { std::optional PROPERTY(government_type); std::optional PROPERTY(plurality); std::optional PROPERTY(national_value); - std::optional PROPERTY(civilised); + std::optional PROPERTY_CUSTOM_PREFIX(civilised, is); std::optional PROPERTY(prestige); std::vector PROPERTY(reforms); std::optional PROPERTY(inital_oob); @@ -47,6 +46,17 @@ namespace OpenVic { std::map PROPERTY(technologies); std::map PROPERTY(inventions); fixed_point_map_t PROPERTY(foreign_investment); + std::optional PROPERTY(consciousness); + std::optional PROPERTY(nonstate_consciousness); + std::optional PROPERTY(literacy); + std::optional PROPERTY(nonstate_culture_literacy); + std::optional PROPERTY_CUSTOM_PREFIX(releasable_vassal, is); + std::optional PROPERTY(colonial_points); + string_set_t PROPERTY(country_flags); + string_set_t PROPERTY(global_flags); + std::map PROPERTY(government_flags); + + //TODO: decisions CountryHistoryEntry(Country const& new_country, Date new_date); }; diff --git a/src/openvic-simulation/research/Invention.hpp b/src/openvic-simulation/research/Invention.hpp index 9cc158c..dc4256e 100644 --- a/src/openvic-simulation/research/Invention.hpp +++ b/src/openvic-simulation/research/Invention.hpp @@ -15,9 +15,9 @@ namespace OpenVic { struct Invention : Modifier { friend struct InventionManager; //TODO implement limit and chance - using unit_set_t = std::unordered_set; - using building_set_t = std::unordered_set; - using crime_set_t = std::unordered_set; + using unit_set_t = std::set; + using building_set_t = std::set; + using crime_set_t = std::set; private: const bool PROPERTY_CUSTOM_PREFIX(news, is); diff --git a/src/openvic-simulation/research/Technology.hpp b/src/openvic-simulation/research/Technology.hpp index 540d10f..52db87e 100644 --- a/src/openvic-simulation/research/Technology.hpp +++ b/src/openvic-simulation/research/Technology.hpp @@ -32,8 +32,8 @@ namespace OpenVic { struct Technology : Modifier { friend struct TechnologyManager; - using unit_set_t = std::unordered_set; - using building_set_t = std::unordered_set; + using unit_set_t = std::set; + using building_set_t = std::set; private: TechnologyArea const& PROPERTY(area); -- cgit v1.2.3-56-ga3b1