aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-26 00:25:12 +0200
committer Hop311 <hop3114@gmail.com>2023-09-03 12:53:52 +0200
commit366f1b3941315641bdcb0ee98465b4d2134eee86 (patch)
treeebb1e95b5e874c6eab09f19a323d721fd1fdac1b /src/openvic/pop
parentefa88c722fcb6c8fea7a86e1b3b8a83f1f59eb31 (diff)
Followup big dataloader commit
Diffstat (limited to 'src/openvic/pop')
-rw-r--r--src/openvic/pop/Culture.cpp40
-rw-r--r--src/openvic/pop/Culture.hpp6
-rw-r--r--src/openvic/pop/Pop.cpp38
-rw-r--r--src/openvic/pop/Pop.hpp3
-rw-r--r--src/openvic/pop/Religion.cpp12
-rw-r--r--src/openvic/pop/Religion.hpp3
6 files changed, 57 insertions, 45 deletions
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
index 3bfb9b9..b0c04c2 100644
--- a/src/openvic/pop/Culture.cpp
+++ b/src/openvic/pop/Culture.cpp
@@ -101,11 +101,13 @@ Culture const* CultureManager::get_culture_by_identifier(const std::string_view
}
return_t CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) {
- const return_t ret = NodeTools::expect_list(root, [this](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_identifier(node, [this](std::string_view identifier) -> return_t {
- return add_graphical_culture_type(identifier);
- });
- }, 0, true);
+ const return_t ret = NodeTools::expect_list_and_length(root,
+ NodeTools::reserve_length_callback(graphical_culture_types),
+ [this](ast::NodeCPtr node) -> return_t {
+ return NodeTools::expect_identifier(node, [this](std::string_view identifier) -> return_t {
+ return add_graphical_culture_type(identifier);
+ });
+ }, true);
lock_graphical_culture_types();
return ret;
}
@@ -156,21 +158,25 @@ return_t CultureManager::load_culture_file(ast::NodeCPtr root) {
return NodeTools::expect_dictionary(culture_group_value, [this, culture_group](std::string_view key, ast::NodeCPtr value) -> return_t {
if (key == "leader" || key == "unit" || key == "union" || key == "is_overseas") return SUCCESS;
- colour_t colour = NULL_COLOUR;
+ colour_t colour = NULL_COLOUR;
Culture::name_list_t first_names, last_names;
- static const std::function<return_t(Culture::name_list_t&, ast::NodeCPtr)> read_name_list = [](Culture::name_list_t& names, ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_list(node, [&names](ast::NodeCPtr val) -> return_t {
- return NodeTools::expect_identifier_or_string(val, [&names](std::string_view str) -> return_t {
- if (!str.empty()) {
- names.push_back(std::string { str });
- return SUCCESS;
+ static const std::function<return_t(Culture::name_list_t&, ast::NodeCPtr)> read_name_list =
+ [](Culture::name_list_t& names, ast::NodeCPtr node) -> return_t {
+ return NodeTools::expect_list_and_length(node,
+ NodeTools::reserve_length_callback(names),
+ [&names](ast::NodeCPtr val) -> return_t {
+ return NodeTools::expect_identifier_or_string(val, [&names](std::string_view str) -> return_t {
+ if (!str.empty()) {
+ names.push_back(std::string { str });
+ return SUCCESS;
+ }
+ Logger::error("Empty identifier or string");
+ return FAILURE;
+ });
}
- Logger::error("Empty identifier or string");
- return FAILURE;
- });
- });
- };
+ );
+ };
return_t ret = NodeTools::expect_dictionary_keys(value, {
{ "color", { true, false, [&colour](ast::NodeCPtr node) -> return_t {
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
index 7012512..495ba1d 100644
--- a/src/openvic/pop/Culture.hpp
+++ b/src/openvic/pop/Culture.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "openvic/types/IdentifierRegistry.hpp"
#include "openvic/dataloader/NodeTools.hpp"
+#include "openvic/types/IdentifierRegistry.hpp"
namespace OpenVic {
@@ -72,7 +72,7 @@ namespace OpenVic {
void lock_cultures();
Culture const* get_culture_by_identifier(const std::string_view identifier) const;
- return_t load_graphical_culture_type_file(ast::NodeCPtr node);
- return_t load_culture_file(ast::NodeCPtr node);
+ return_t load_graphical_culture_type_file(ast::NodeCPtr root);
+ return_t load_culture_file(ast::NodeCPtr root);
};
}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
index 710d3e0..445aec3 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -98,27 +98,7 @@ bool PopType::get_is_slave() const {
return is_slave;
}
-static const std::string test_graphical_culture_type = "test_graphical_culture_type";
-static const std::string test_culture_group = "test_culture_group";
-static const std::string test_culture = "test_culture";
-static const std::string test_religion_group = "test_religion_group";
-static const std::string test_religion = "test_religion";
-static const std::string test_pop_type_poor = "test_pop_type_poor";
-static const std::string test_pop_type_middle = "test_pop_type_middle";
-static const std::string test_pop_type_rich = "test_pop_type_rich";
-
-PopManager::PopManager() : pop_types { "pop types" } {
- religion_manager.add_religion_group(test_religion_group);
- religion_manager.lock_religion_groups();
-
- religion_manager.add_religion(test_religion, 0xFF0000, religion_manager.get_religion_group_by_identifier(test_religion_group), 1, false);
- religion_manager.lock_religions();
-
- add_pop_type(test_pop_type_poor, 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
- add_pop_type(test_pop_type_middle, 0x00FF00, PopType::strata_t::MIDDLE, 1, 1, 1, false, false, false, false);
- add_pop_type(test_pop_type_rich, 0x0000FF, PopType::strata_t::RICH, 1, 1, 1, false, false, false, false);
- lock_pop_types();
-}
+PopManager::PopManager() : pop_types { "pop types" } {}
return_t PopManager::add_pop_type(const std::string_view identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave) {
@@ -153,8 +133,17 @@ PopType const* PopManager::get_pop_type_by_identifier(const std::string_view ide
return pop_types.get_item_by_identifier(identifier);
}
+return_t PopManager::load_pop_type_file(std::filesystem::path const& path, ast::NodeCPtr root) {
+
+ // TODO - pop type loading
+
+ if (pop_types.empty())
+ return add_pop_type("test_pop_type", 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
+ return SUCCESS;
+}
+
return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr root) const {
- static PopType const* type = get_pop_type_by_identifier("test_pop_type_poor");
+ static PopType const* type = get_pop_type_by_identifier("test_pop_type");
Culture const* culture = nullptr;
static Religion const* religion = religion_manager.get_religion_by_identifier("test_religion");
Pop::pop_size_t size = 0;
@@ -176,8 +165,7 @@ return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr ro
size = val;
return SUCCESS;
} else {
- Logger::error("Invalid pop size: ", val, " (setting to 1 instead)");
- size = 1;
+ Logger::error("Invalid pop size: ", val);
return FAILURE;
}
});
@@ -190,7 +178,7 @@ return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr ro
if (type != nullptr && culture != nullptr && religion != nullptr && size > 0) {
if (province.add_pop({ *type, *culture, *religion, size }) != SUCCESS) ret = FAILURE;
} else {
- Logger::error("Some pop arguments are missing: type = ", type, ", culture = ", culture, ", religion = ", religion, ", size = ", size);
+ Logger::error("Some pop arguments are invalid: type = ", type, ", culture = ", culture, ", religion = ", religion, ", size = ", size);
ret = FAILURE;
}
return ret;
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index f5a7c4e..144d53c 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <filesystem>
+
#include "openvic/pop/Culture.hpp"
#include "openvic/pop/Religion.hpp"
@@ -94,6 +96,7 @@ namespace OpenVic {
void lock_pop_types();
PopType const* get_pop_type_by_identifier(const std::string_view identifier) const;
+ return_t load_pop_type_file(std::filesystem::path const& path, ast::NodeCPtr root);
return_t load_pop_into_province(Province& province, ast::NodeCPtr root) const;
};
}
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
index 0cfc7a6..8ff143f 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -78,3 +78,15 @@ void ReligionManager::lock_religions() {
Religion const* ReligionManager::get_religion_by_identifier(const std::string_view identifier) const {
return religions.get_item_by_identifier(identifier);
}
+
+return_t ReligionManager::load_religion_file(ast::NodeCPtr root) {
+
+ // TODO - religion loading
+
+ return_t ret = add_religion_group("test_religion_group");
+ lock_religion_groups();
+ if (add_religion("test_religion", 0xFF0000, get_religion_group_by_identifier("test_religion_group"), 1, false) != SUCCESS)
+ ret = FAILURE;
+ lock_religions();
+ return ret;
+}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index e629977..730454e 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "openvic/types/IdentifierRegistry.hpp"
+#include "openvic/dataloader/NodeTools.hpp"
namespace OpenVic {
@@ -50,5 +51,7 @@ namespace OpenVic {
return_t add_religion(const std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan);
void lock_religions();
Religion const* get_religion_by_identifier(const std::string_view identifier) const;
+
+ return_t load_religion_file(ast::NodeCPtr root);
};
}