aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-12-06 23:10:53 +0100
committer hop311 <hop3114@gmail.com>2023-12-07 21:38:17 +0100
commit398377011cb3d3c970451dcd215f3610159f1ae2 (patch)
tree2a73255f595eabb1441419a08bd0d5e5407213e7 /src/openvic-simulation/dataloader
parent48a3f1729d709847d7cad33f594c77cac414e802 (diff)
Vec/set callbacks + crime file + prov building pos
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp37
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp12
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp30
3 files changed, 45 insertions, 34 deletions
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<Province::index_t>(
- std::bind(&Map::set_max_provinces, &map, std::placeholders::_1)
- ),
+ expect_uint<Province::index_t>(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<std::vector<std::string
return [callback](ast::NodeCPtr node) -> bool {
std::vector<std::string> 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<std::string_view>(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 <optional>
#include <set>
#include <type_traits>
+#include <unordered_set>
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
@@ -320,5 +321,34 @@ namespace OpenVic {
return true;
};
}
+
+ template<typename T, typename U>
+ Callback<T> auto vector_callback(std::vector<U>& vec) {
+ return [&vec](T val) -> bool {
+ vec.emplace_back(std::move(val));
+ return true;
+ };
+ }
+
+ template<typename T>
+ Callback<T> auto vector_callback(std::vector<T>& vec) {
+ return vector_callback<T, T>(vec);
+ }
+
+ template<typename T>
+ Callback<T const&> auto vector_callback_pointer(std::vector<T const*>& vec) {
+ return [&vec](T const& val) -> bool {
+ vec.emplace_back(&val);
+ return true;
+ };
+ }
+
+ template<typename T>
+ Callback<T const&> auto set_callback_pointer(std::unordered_set<T const*>& set) {
+ return [&set](T const& val) -> bool {
+ set.insert(&val);
+ return true;
+ };
+ }
}
}