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.cpp | 36 +++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src/openvic-simulation/history/CountryHistory.cpp') diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp index d312261..b42149b 100644 --- a/src/openvic-simulation/history/CountryHistory.cpp +++ b/src/openvic-simulation/history/CountryHistory.cpp @@ -21,10 +21,13 @@ bool CountryHistoryMap::_load_history_entry( PoliticsManager const& politics_manager = game_manager.get_politics_manager(); IssueManager const& issue_manager = politics_manager.get_issue_manager(); CultureManager const& culture_manager = game_manager.get_pop_manager().get_culture_manager(); + CountryManager const& country_manager = game_manager.get_country_manager(); + TechnologyManager const& technology_manager = game_manager.get_research_manager().get_technology_manager(); + InventionManager const& invention_manager = game_manager.get_research_manager().get_invention_manager(); return expect_dictionary_keys_and_default( - [this, &game_manager, &dataloader, &deployment_manager, &issue_manager, &entry]( - std::string_view key, ast::NodeCPtr value) -> bool { + [this, &game_manager, &dataloader, &deployment_manager, &issue_manager, + &technology_manager, &invention_manager, &country_manager, &entry](std::string_view key, ast::NodeCPtr value) -> bool { ReformGroup const* reform_group = issue_manager.get_reform_group_by_identifier(key); if (reform_group != nullptr) { return issue_manager.expect_reform_identifier([&entry, reform_group](Reform const& reform) -> bool { @@ -46,7 +49,28 @@ bool CountryHistoryMap::_load_history_entry( return true; })(value); } - // TODO: technologies & inventions + + 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; + } + } else return false; + } + + Invention const* invention = invention_manager.get_invention_by_identifier(key); + if (invention != nullptr) { + bool flag; + if (expect_bool(assign_variable_callback(flag))(value)) { + return entry.inventions.emplace(invention, flag).second; + } else return false; + } + return _load_history_sub_entry_callback( game_manager, dataloader, deployment_manager, entry.get_date(), value, key, value, key_value_success_callback ); @@ -93,8 +117,10 @@ bool CountryHistoryMap::_load_history_entry( return ret; } ), - "schools", ZERO_OR_ONE, success_callback, // TODO: technology school - "foreign_investment", ZERO_OR_ONE, success_callback // TODO: foreign investment + "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)) )(root); } -- cgit v1.2.3-56-ga3b1