From 398377011cb3d3c970451dcd215f3610159f1ae2 Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 6 Dec 2023 22:10:53 +0000 Subject: Vec/set callbacks + crime file + prov building pos --- src/openvic-simulation/dataloader/Dataloader.cpp | 37 +++++++++--------------- src/openvic-simulation/dataloader/NodeTools.cpp | 12 +------- src/openvic-simulation/dataloader/NodeTools.hpp | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+), 34 deletions(-) (limited to 'src/openvic-simulation/dataloader') diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 11b4332..c986a78 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -349,17 +349,13 @@ bool Dataloader::_load_rebel_types(GameManager& game_manager) const { PoliticsManager& politics_manager = game_manager.get_politics_manager(); RebelManager& rebel_manager = politics_manager.get_rebel_manager(); - bool ret = rebel_manager.load_rebels_file( - politics_manager.get_ideology_manager(), - politics_manager.get_government_type_manager(), - parse_defines(lookup_file(rebel_types_file)).get_file_node() - ); + bool ret = politics_manager.load_rebels_file(parse_defines(lookup_file(rebel_types_file)).get_file_node()); if(!rebel_manager.generate_modifiers(game_manager.get_modifier_manager())) { Logger::error("Failed to generate rebel type-based modifiers!"); ret &= false; } - + return ret; } @@ -396,7 +392,7 @@ bool Dataloader::_load_technologies(GameManager& game_manager) const { return technology_manager.load_technologies_file( modifier_manager, game_manager.get_military_manager().get_unit_manager(), - game_manager.get_economy_manager().get_building_manager(), + game_manager.get_economy_manager().get_building_type_manager(), parse_defines(file).get_file_node() ); } @@ -420,12 +416,13 @@ bool Dataloader::_load_inventions(GameManager& game_manager) const { return invention_manager.load_inventions_file( game_manager.get_modifier_manager(), game_manager.get_military_manager().get_unit_manager(), - game_manager.get_economy_manager().get_building_manager(), + game_manager.get_economy_manager().get_building_type_manager(), + game_manager.get_crime_manager(), parse_defines(file).get_file_node() ); } ); - + invention_manager.lock_inventions(); return ret; @@ -491,7 +488,9 @@ bool Dataloader::_load_history(GameManager& game_manager, bool unused_history_fi ret &= apply_to_files( lookup_files_in_dir(diplomacy_history_directory, ".txt"), [this, &game_manager](fs::path const& file) -> bool { - return game_manager.get_history_manager().get_diplomacy_manager().load_diplomacy_history_file(game_manager, parse_defines(file).get_file_node()); + return game_manager.get_history_manager().get_diplomacy_manager().load_diplomacy_history_file( + game_manager.get_country_manager(), parse_defines(file).get_file_node() + ); } ); static constexpr std::string_view war_history_directory = "history/wars"; @@ -548,18 +547,10 @@ bool Dataloader::_load_map_dir(GameManager& game_manager) const { bool ret = expect_dictionary_keys( "max_provinces", ONE_EXACTLY, - expect_uint( - std::bind(&Map::set_max_provinces, &map, std::placeholders::_1) - ), + expect_uint(std::bind_front(&Map::set_max_provinces, &map)), "sea_starts", ONE_EXACTLY, expect_list_reserve_length( - water_province_identifiers, - expect_identifier( - [&water_province_identifiers](std::string_view identifier) -> bool { - water_province_identifiers.push_back(identifier); - return true; - } - ) + water_province_identifiers, expect_identifier(vector_callback(water_province_identifiers)) ), #define MAP_PATH_DICT_ENTRY(X) #X, ONE_EXACTLY, expect_string(assign_variable_callback(X)), @@ -584,7 +575,7 @@ bool Dataloader::_load_map_dir(GameManager& game_manager) const { } if (!map.load_province_positions( - game_manager.get_economy_manager().get_building_manager(), + game_manager.get_economy_manager().get_building_type_manager(), parse_defines(lookup_file(append_string_views(map_directory, positions))).get_file_node() )) { Logger::error("Failed to load province positions file!"); @@ -744,8 +735,8 @@ bool Dataloader::load_defines(GameManager& game_manager) const { if (!_load_technologies(game_manager)) { ret = false; } - if (!game_manager.get_modifier_manager().load_crime_modifiers( - parse_defines(lookup_file(crime_modifiers_file)).get_file_node() + if (!game_manager.get_crime_manager().load_crime_modifiers( + game_manager.get_modifier_manager(), parse_defines(lookup_file(crime_modifiers_file)).get_file_node() )) { Logger::error("Failed to load crime modifiers!"); ret = false; diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index 12e51a4..c4addb7 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -380,17 +380,7 @@ node_callback_t NodeTools::name_list_callback(callback_t bool { std::vector list; bool ret = expect_list_reserve_length( - list, - expect_identifier_or_string( - [&list](std::string_view str) -> bool { - if (!str.empty()) { - list.push_back(std::string { str }); - return true; - } - Logger::error("Empty identifier or string"); - return false; - } - ) + list, expect_identifier_or_string(vector_callback(list)) )(node); ret &= callback(std::move(list)); return ret; diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 1ca6cf0..45e6d4f 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -320,5 +321,34 @@ namespace OpenVic { return true; }; } + + template + Callback auto vector_callback(std::vector& vec) { + return [&vec](T val) -> bool { + vec.emplace_back(std::move(val)); + return true; + }; + } + + template + Callback auto vector_callback(std::vector& vec) { + return vector_callback(vec); + } + + template + Callback auto vector_callback_pointer(std::vector& vec) { + return [&vec](T const& val) -> bool { + vec.emplace_back(&val); + return true; + }; + } + + template + Callback auto set_callback_pointer(std::unordered_set& set) { + return [&set](T const& val) -> bool { + set.insert(&val); + return true; + }; + } } } -- cgit v1.2.3-56-ga3b1