aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp74
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp10
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp11
3 files changed, 38 insertions, 57 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 223b795..fd4f2b0 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -948,69 +948,41 @@ bool Dataloader::load_defines(GameManager& game_manager) {
Logger::error("Failed to load diplomatic actions!");
ret = false;
}
+ if(!game_manager.get_script_manager().get_condition_manager().setup_conditions(game_manager)) {
+ Logger::error("Failed to set up conditions!");
+ ret = false;
+ }
- parse_scripts(game_manager);
+ ret &= parse_scripts(game_manager);
free_cache();
return ret;
}
+#define PARSE_SCRIPTS(name, mgr) \
+ if (!mgr.parse_scripts(game_manager)) { Logger::error("Failed to parse ", name, " scripts!"); ret = false; } \
+ else Logger::info("Successfully parsed ", name, " scripts!");
+
bool Dataloader::parse_scripts(GameManager& game_manager) const {
bool ret = true;
-
- if (!game_manager.get_pop_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse pop scripts!");
- ret = false;
- }
- if (!game_manager.get_politics_manager().get_ideology_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse ideology scripts!");
- ret = false;
- }
- if (!game_manager.get_politics_manager().get_issue_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse reform scripts!");
- ret = false;
- }
- if (!game_manager.get_economy_manager().get_production_type_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse production type scripts!");
- ret = false;
- }
- if (!game_manager.get_politics_manager().get_rebel_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse rebel type scripts!");
- ret = false;
- }
- if (!game_manager.get_research_manager().get_technology_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse technology scripts!");
- ret = false;
- }
- if (!game_manager.get_crime_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse crime scripts!");
- ret = false;
- }
- if (!game_manager.get_modifier_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse triggered modifier scripts!");
- ret = false;
- }
- if (!game_manager.get_research_manager().get_invention_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse invention scripts!");
- ret = false;
- }
- if (!game_manager.get_military_manager().get_wargoal_type_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse wargoal type scripts!");
- ret = false;
- }
- if (!game_manager.get_decision_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse decision scripts!");
- ret = false;
- }
- if (!game_manager.get_event_manager().parse_scripts(game_manager)) {
- Logger::error("Failed to parse event scripts!");
- ret = false;
- }
-
+ PARSE_SCRIPTS("pop", game_manager.get_pop_manager());
+ PARSE_SCRIPTS("ideology", game_manager.get_politics_manager().get_ideology_manager());
+ PARSE_SCRIPTS("reform", game_manager.get_politics_manager().get_issue_manager());
+ PARSE_SCRIPTS("production type", game_manager.get_economy_manager().get_production_type_manager());
+ PARSE_SCRIPTS("rebel type", game_manager.get_politics_manager().get_rebel_manager());
+ PARSE_SCRIPTS("technology", game_manager.get_research_manager().get_technology_manager());
+ PARSE_SCRIPTS("crime", game_manager.get_crime_manager());
+ PARSE_SCRIPTS("triggered modifier", game_manager.get_modifier_manager());
+ PARSE_SCRIPTS("invention", game_manager.get_research_manager().get_invention_manager());
+ PARSE_SCRIPTS("wargoal type", game_manager.get_military_manager().get_wargoal_type_manager());
+ PARSE_SCRIPTS("decision", game_manager.get_decision_manager());
+ PARSE_SCRIPTS("event", game_manager.get_event_manager());
return ret;
}
+#undef PARSE_SCRIPTS
+
static bool _load_localisation_file(Dataloader::localisation_callback_t callback, std::vector<csv::LineObject> const& lines) {
bool ret = true;
for (csv::LineObject const& line : lines) {
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index e429ed9..4612f77 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -70,13 +70,17 @@ node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_vi
}
node_callback_t NodeTools::expect_bool(callback_t<bool> callback) {
- static const string_map_t<bool> bool_map = { { "yes", true }, { "no", false } };
+ static const case_insensitive_string_map_t<bool> bool_map = { { "yes", true }, { "no", false } };
return expect_identifier(expect_mapped_string(bool_map, callback));
}
node_callback_t NodeTools::expect_int_bool(callback_t<bool> callback) {
- static const string_map_t<bool> bool_map = { { "1", true }, { "0", false } };
- return expect_identifier(expect_mapped_string(bool_map, callback));
+ return expect_uint64([callback](uint64_t num) -> bool {
+ if (num > 1) {
+ Logger::warning("Found int bool with value >1: ", num);
+ }
+ return callback(num != 0);
+ });
}
node_callback_t NodeTools::expect_int64(callback_t<int64_t> callback, int base) {
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 8ad731b..00ba02d 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -21,9 +21,12 @@ namespace OpenVic {
* searched for without needing to be copied into a string */
template<typename T, class Hash = container_hash<std::string>, class KeyEqual = std::equal_to<>>
using string_map_t = ordered_map<std::string, T, Hash, KeyEqual>;
+ template<typename T>
+ using case_insensitive_string_map_t = string_map_t<T, case_insensitive_string_hash, case_insensitive_string_equal>;
/* String set type supporting heterogeneous key lookup */
using string_set_t = ordered_set<std::string>;
+ using case_insensitive_string_set_t = case_insensitive_ordered_set<std::string>;
namespace NodeTools {
@@ -247,10 +250,12 @@ namespace OpenVic {
node_callback_t name_list_callback(callback_t<std::vector<std::string>&&> callback);
- template<typename T>
- Callback<std::string_view> auto expect_mapped_string(string_map_t<T> const& map, Callback<T> auto callback) {
+ template<typename T, class Hash, class KeyEqual>
+ Callback<std::string_view> auto expect_mapped_string(
+ string_map_t<T, Hash, KeyEqual> const& map, Callback<T> auto callback
+ ) {
return [&map, callback](std::string_view string) -> bool {
- const typename string_map_t<T>::const_iterator it = map.find(string);
+ const typename string_map_t<T, Hash, KeyEqual>::const_iterator it = map.find(string);
if (it != map.end()) {
return callback(it->second);
}