diff options
author | zaaarf <zaaarf@proton.me> | 2023-11-30 21:20:37 +0100 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-12-02 01:12:12 +0100 |
commit | c935e471782764dcc10a3175741a02ab3ffffa8e (patch) | |
tree | 49016457c09ef3583b200a8bd016dc702b6e298e /src/openvic-simulation/dataloader/Dataloader.cpp | |
parent | 51583b66feb1d13b285bb2e9c05364659c854130 (diff) |
feat: implemented modifier identifier flattening, added/fixed remaining tech modifiers effects
Diffstat (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 100 |
1 files changed, 67 insertions, 33 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 68e5b92..7715104 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -1,14 +1,5 @@ #include "Dataloader.hpp" -#include <array> -#include <cstdlib> -#include <filesystem> -#include <optional> -#include <string_view> -#include <system_error> -#include <type_traits> -#include <variant> - #include <openvic-dataloader/csv/Parser.hpp> #include <openvic-dataloader/detail/CallbackOStream.hpp> #include <openvic-dataloader/v2script/Parser.hpp> @@ -624,26 +615,79 @@ bool Dataloader::_load_pop_types( return ret; } -bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_manager) const { +bool Dataloader::_load_units(GameManager& game_manager) const { static constexpr std::string_view units_directory = "units"; - const bool ret = apply_to_files( + + UnitManager& unit_manager = game_manager.get_military_manager().get_unit_manager(); + bool ret = apply_to_files( lookup_files_in_dir(units_directory, ".txt"), - [&unit_manager, &good_manager](fs::path const& file) -> bool { - return unit_manager.load_unit_file(good_manager, parse_defines(file).get_file_node()); + [&game_manager, &unit_manager](fs::path const& file) -> bool { + return unit_manager.load_unit_file(game_manager.get_economy_manager().get_good_manager(), parse_defines(file).get_file_node()); } ); + unit_manager.lock_units(); + + if(!unit_manager.generate_modifiers(game_manager.get_modifier_manager())) { + Logger::error("Failed to generate unit-based modifiers!"); + ret &= false; + } + + return ret; +} + +bool Dataloader::_load_goods(GameManager& game_manager, std::string_view goods_file) const { + GoodManager& good_manager = game_manager.get_economy_manager().get_good_manager(); + bool ret = good_manager.load_goods_file(parse_defines(lookup_file(goods_file)).get_file_node()); + + if(!good_manager.generate_modifiers(game_manager.get_modifier_manager())) { + Logger::error("Failed to generate good-based modifiers!"); + ret &= false; + } + return ret; } -bool Dataloader::_load_technologies(TechnologyManager& technology_manager, ModifierManager& modifier_manager) const { +bool Dataloader::_load_technologies(GameManager& game_manager, std::string_view technology_file) const { + TechnologyManager& technology_manager = game_manager.get_technology_manager(); + + bool ret = true; + + const v2script::Parser technology_file_parser = parse_defines(lookup_file(technology_file)); + + if(!technology_manager.load_technology_file_areas(technology_file_parser.get_file_node())) { + Logger::error("Failed to load technology areas and folders!"); + ret = false; + } + + ModifierManager& modifier_manager = game_manager.get_modifier_manager(); + + if(!technology_manager.generate_modifiers(modifier_manager)) { + Logger::error("Failed to generate technollogy-based modifiers!"); + ret = false; + } + + if(!technology_manager.load_technology_file_schools(modifier_manager, technology_file_parser.get_file_node())) { + Logger::error("Failed to load technology schools!"); + ret = false; + } + static constexpr std::string_view technologies_directory = "technologies"; - bool ret = apply_to_files( + if(!apply_to_files( lookup_files_in_dir(technologies_directory, ".txt"), - [&technology_manager, &modifier_manager](fs::path const& file) -> bool { - return technology_manager.load_technologies_file(modifier_manager, parse_defines(file).get_file_node()); + [&game_manager, &technology_manager, &modifier_manager](fs::path const& file) -> bool { + return technology_manager.load_technologies_file( + modifier_manager, + game_manager.get_military_manager().get_unit_manager(), + game_manager.get_economy_manager().get_building_manager(), + parse_defines(file).get_file_node() + ); } - ); + )) { + Logger::error("Failed to load technologies!"); + ret = false; + } + technology_manager.lock_technologies(); return ret; } @@ -906,27 +950,14 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load defines!"); ret = false; } - if (!game_manager.get_economy_manager().get_good_manager().load_goods_file( - parse_defines(lookup_file(goods_file)).get_file_node() - )) { + if (!_load_goods(game_manager, goods_file)) { Logger::error("Failed to load goods!"); ret = false; } - if (!_load_units( - game_manager.get_military_manager().get_unit_manager(), game_manager.get_economy_manager().get_good_manager() - )) { + if (!_load_units(game_manager)) { Logger::error("Failed to load units!"); ret = false; } - if (!game_manager.get_technology_manager().load_technology_file(game_manager.get_modifier_manager(), - parse_defines(lookup_file(technology_file)).get_file_node())) { - Logger::error("Failed to load technology areas!"); - ret = false; - } - if (!_load_technologies(game_manager.get_technology_manager(), game_manager.get_modifier_manager())) { - Logger::error("Failed to load technologies!"); - ret = false; - } if (!_load_pop_types( game_manager.get_pop_manager(), game_manager.get_military_manager().get_unit_manager(), game_manager.get_economy_manager().get_good_manager() @@ -994,6 +1025,9 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load buildings!"); ret = false; } + if (!_load_technologies(game_manager, technology_file)) { + ret = false; + } if (!_load_map_dir(game_manager)) { Logger::error("Failed to load map!"); ret = false; |