aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/Dataloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp84
1 files changed, 63 insertions, 21 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index f2e94d7..475cdd1 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -45,17 +45,22 @@ static constexpr bool path_equals(std::string_view lhs, std::string_view rhs) {
#endif
}
-template<typename LT, typename RT>
-static bool filename_equals(const LT& lhs, const RT& rhs) {
- std::string left, right;
- if constexpr (std::same_as<LT, std::filesystem::path>)
- left = lhs.filename().string();
- else left = lhs;
-
- if constexpr (std::same_as<RT, std::filesystem::path>)
- right = rhs.filename().string();
- else right = rhs;
-
+template<typename T>
+concept is_filename = std::same_as<T, std::filesystem::path> || std::convertible_to<T, std::string_view>;
+
+bool filename_equals(const is_filename auto& lhs, const is_filename auto& rhs) {
+ auto left = [&lhs] {
+ if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>)
+ return lhs.filename().string();
+ else
+ return lhs;
+ }();
+ auto right = [&rhs] {
+ if constexpr (std::same_as<std::decay_t<decltype(rhs)>, std::filesystem::path>)
+ return rhs.filename().string();
+ else
+ return rhs;
+ }();
return path_equals(left, right);
}
@@ -452,10 +457,10 @@ csv::Windows1252Parser Dataloader::parse_csv(fs::path const& path) {
return _run_ovdl_parser<csv::Windows1252Parser, &_csv_parse>(path);
}
-bool Dataloader::_load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const {
+bool Dataloader::_load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const {
const bool ret = apply_to_files_in_dir(pop_type_directory, ".txt",
- [&pop_manager](fs::path const& file) -> bool {
- return pop_manager.load_pop_type_file(file.stem().string(), parse_defines(file).get_file_node());
+ [&pop_manager, &unit_manager, &good_manager](fs::path const& file) -> bool {
+ return pop_manager.load_pop_type_file(file.stem().string(), unit_manager, good_manager, parse_defines(file).get_file_node());
}
);
pop_manager.lock_pop_types();
@@ -472,6 +477,28 @@ bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_
return ret;
}
+bool Dataloader::_load_countries(GameManager& game_manager, fs::path const& countries_file, ast::NodeCPtr root) const {
+ bool is_dynamic = false;
+
+ bool ret = expect_dictionary(
+ [this, &game_manager, &is_dynamic, &countries_file](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key == "dynamic_tags") {
+ return expect_bool(assign_variable_callback(is_dynamic))(value);
+ }
+
+ std::string_view data_path;
+
+ if (!expect_string(assign_variable_callback(data_path))(value)) {
+ return false;
+ }
+
+ return game_manager.get_country_manager().load_country_data_file(game_manager, key, is_dynamic, Dataloader::parse_defines(lookup_file(countries_file.parent_path() / data_path)).get_file_node());
+ }
+ )(root);
+ game_manager.get_country_manager().lock_countries();
+ return ret;
+}
+
bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const {
Map& map = game_manager.get_map();
@@ -594,9 +621,11 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
static const fs::path graphical_culture_type_file = "common/graphicalculturetype.txt";
static const fs::path ideology_file = "common/ideologies.txt";
static const fs::path issues_file = "common/issues.txt";
+ static const fs::path national_values_file = "common/nationalvalues.txt";
static const fs::path production_types_file = "common/production_types.txt";
static const fs::path religion_file = "common/religion.txt";
static const fs::path leader_traits_file = "common/traits.txt";
+ static const fs::path countries_file = "common/countries.txt";
bool ret = true;
@@ -609,7 +638,15 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load goods!");
ret = false;
}
- if (!_load_pop_types(game_manager.get_pop_manager(), pop_type_directory)) {
+ if (!_load_units(game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_economy_manager().get_good_manager(), units_directory)) {
+ Logger::error("Failed to load units!");
+ 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(),
+ pop_type_directory)) {
Logger::error("Failed to load pop types!");
ret = false;
}
@@ -643,6 +680,15 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load issues!");
ret = false;
}
+ if (!game_manager.get_politics_manager().get_national_value_manager().load_national_values_file(
+ game_manager.get_modifier_manager(), parse_defines(lookup_file(national_values_file)).get_file_node())) {
+ Logger::error("Failed to load national values!");
+ ret = false;
+ }
+ if (!_load_countries(game_manager, countries_file, parse_defines(lookup_file(countries_file)).get_file_node())) {
+ Logger::error("Failed to load countries!");
+ ret = false;
+ }
if (!game_manager.get_economy_manager().load_production_types_file(
game_manager.get_pop_manager(),
parse_defines(lookup_file(production_types_file)).get_file_node())) {
@@ -659,12 +705,8 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load map!");
ret = false;
}
- if (!_load_units(game_manager.get_military_manager().get_unit_manager(),
- game_manager.get_economy_manager().get_good_manager(), units_directory)) {
- Logger::error("Failed to load units!");
- ret = false;
- }
- if (!game_manager.get_military_manager().get_leader_trait_manager().load_leader_traits_file(game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node())) {
+ if (!game_manager.get_military_manager().get_leader_trait_manager().load_leader_traits_file(
+ game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node())) {
Logger::error("Failed to load leader traits!");
ret = false;
}