aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-09-07 00:54:09 +0200
committer Hop311 <hop3114@gmail.com>2023-09-07 20:37:24 +0200
commit3cd1d62ec00690a1b29070dd4903754e8f089a21 (patch)
tree61d630aa130f8411cc0d539dbfb3705154740631 /src/openvic/pop
parent8e12540771f1fcc670481aa6299fd73cb10aad00 (diff)
NodeTools cleanup+province definition csv loading
Diffstat (limited to 'src/openvic/pop')
-rw-r--r--src/openvic/pop/Culture.cpp202
-rw-r--r--src/openvic/pop/Culture.hpp29
-rw-r--r--src/openvic/pop/Pop.cpp71
-rw-r--r--src/openvic/pop/Pop.hpp2
-rw-r--r--src/openvic/pop/Religion.cpp98
-rw-r--r--src/openvic/pop/Religion.hpp5
6 files changed, 237 insertions, 170 deletions
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
index b0c04c2..2670f00 100644
--- a/src/openvic/pop/Culture.cpp
+++ b/src/openvic/pop/Culture.cpp
@@ -3,21 +3,31 @@
#include "openvic/dataloader/NodeTools.hpp"
using namespace OpenVic;
+using namespace OpenVic::NodeTools;
GraphicalCultureType::GraphicalCultureType(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-CultureGroup::CultureGroup(const std::string_view new_identifier,
+CultureGroup::CultureGroup(const std::string_view new_identifier, const std::string_view new_leader,
GraphicalCultureType const& new_unit_graphical_culture_type, bool new_is_overseas)
- : HasIdentifier { new_identifier },
+ : HasIdentifier { new_identifier }, leader { new_leader },
unit_graphical_culture_type { new_unit_graphical_culture_type },
is_overseas { new_is_overseas } {}
+
+std::string const& CultureGroup::get_leader() const {
+ return leader;
+}
+
GraphicalCultureType const& CultureGroup::get_unit_graphical_culture_type() const {
return unit_graphical_culture_type;
}
+bool CultureGroup::get_is_overseas() const {
+ return is_overseas;
+}
+
Culture::Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group,
- name_list_t const& new_first_names, name_list_t const& new_last_names)
+ std::vector<std::string> const& new_first_names, std::vector<std::string> const& new_last_names)
: HasIdentifierAndColour { new_identifier, new_colour, true },
group { new_group },
first_names { new_first_names },
@@ -27,6 +37,14 @@ CultureGroup const& Culture::get_group() const {
return group;
}
+std::vector<std::string> const& Culture::get_first_names() const {
+ return first_names;
+}
+
+std::vector<std::string> const& Culture::get_last_names() const {
+ return last_names;
+}
+
CultureManager::CultureManager()
: graphical_culture_types { "graphical culture types" },
culture_groups { "culture groups" },
@@ -48,7 +66,15 @@ GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identi
return graphical_culture_types.get_item_by_identifier(identifier);
}
-return_t CultureManager::add_culture_group(const std::string_view identifier, GraphicalCultureType const* graphical_culture_type, bool is_overseas) {
+size_t CultureManager::get_graphical_culture_type_count() const {
+ return graphical_culture_types.size();
+}
+
+std::vector<GraphicalCultureType> const& CultureManager::get_graphical_culture_types() const {
+ return graphical_culture_types.get_items();
+}
+
+return_t CultureManager::add_culture_group(const std::string_view identifier, const std::string_view leader, GraphicalCultureType const* graphical_culture_type, bool is_overseas) {
if (!graphical_culture_types.is_locked()) {
Logger::error("Cannot register culture groups until graphical culture types are locked!");
return FAILURE;
@@ -57,11 +83,15 @@ return_t CultureManager::add_culture_group(const std::string_view identifier, Gr
Logger::error("Invalid culture group identifier - empty!");
return FAILURE;
}
+ if (leader.empty()) {
+ Logger::error("Invalid culture group leader - empty!");
+ return FAILURE;
+ }
if (graphical_culture_type == nullptr) {
Logger::error("Null graphical culture type for ", identifier);
return FAILURE;
}
- return culture_groups.add_item({ identifier, *graphical_culture_type, is_overseas });
+ return culture_groups.add_item({ identifier, leader, *graphical_culture_type, is_overseas });
}
void CultureManager::lock_culture_groups() {
@@ -72,7 +102,15 @@ CultureGroup const* CultureManager::get_culture_group_by_identifier(const std::s
return culture_groups.get_item_by_identifier(identifier);
}
-return_t CultureManager::add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names) {
+size_t CultureManager::get_culture_group_count() const {
+ return culture_groups.size();
+}
+
+std::vector<CultureGroup> const& CultureManager::get_culture_groups() const {
+ return culture_groups.get_items();
+}
+
+return_t CultureManager::add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, std::vector<std::string> const& first_names, std::vector<std::string> const& last_names) {
if (!culture_groups.is_locked()) {
Logger::error("Cannot register cultures until culture groups are locked!");
return FAILURE;
@@ -86,7 +124,7 @@ return_t CultureManager::add_culture(const std::string_view identifier, colour_t
return FAILURE;
}
if (colour > MAX_COLOUR_RGB) {
- Logger::error("Invalid culture colour for ", identifier, ": ", Culture::colour_to_hex_string(colour));
+ Logger::error("Invalid culture colour for ", identifier, ": ", colour_to_hex_string(colour));
return FAILURE;
}
return cultures.add_item({ identifier, colour, *group, first_names, last_names });
@@ -100,14 +138,21 @@ Culture const* CultureManager::get_culture_by_identifier(const std::string_view
return cultures.get_item_by_identifier(identifier);
}
+size_t CultureManager::get_culture_count() const {
+ return cultures.size();
+}
+
+std::vector<Culture> const& CultureManager::get_cultures() const {
+ return cultures.get_items();
+}
+
return_t CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) {
- 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);
+ const return_t ret = expect_list_reserve_length(
+ graphical_culture_types,
+ expect_identifier(
+ std::bind(&CultureManager::add_graphical_culture_type, this, std::placeholders::_1)
+ )
+ )(root);
lock_graphical_culture_types();
return ret;
}
@@ -124,80 +169,65 @@ return_t CultureManager::load_culture_file(ast::NodeCPtr root) {
Logger::error("Failed to find default unit graphical culture type: ", default_unit_graphical_culture_type_identifier);
}
- return_t ret = NodeTools::expect_dictionary(root, [this, default_unit_graphical_culture_type](std::string_view key, ast::NodeCPtr value) -> return_t {
-
- GraphicalCultureType const* unit_graphical_culture_type = default_unit_graphical_culture_type;
- bool is_overseas = true;
-
- return_t ret = NodeTools::expect_dictionary_keys(value, {
- { "leader", { true, false, NodeTools::success_callback } },
- { "unit", { false, false, [this, &unit_graphical_culture_type](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_identifier(node, [this, &unit_graphical_culture_type](std::string_view identifier) -> return_t {
- unit_graphical_culture_type = get_graphical_culture_type_by_identifier(identifier);
- if (unit_graphical_culture_type != nullptr) return SUCCESS;
- Logger::error("Invalid unit graphical culture type: ", identifier);
- return FAILURE;
- });
- } } },
- { "union", { false, false, NodeTools::success_callback } },
- { "is_overseas", { false, false, [&is_overseas](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_bool(node, [&is_overseas](bool val) -> return_t {
- is_overseas = val;
- return SUCCESS;
- });
- } } }
- }, true);
- if (add_culture_group(key, unit_graphical_culture_type, is_overseas) != SUCCESS) ret = FAILURE;
- return ret;
- }, true);
- lock_culture_groups();
- if (NodeTools::expect_dictionary(root, [this](std::string_view culture_group_key, ast::NodeCPtr culture_group_value) -> return_t {
-
- CultureGroup const* culture_group = get_culture_group_by_identifier(culture_group_key);
-
- 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;
- 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_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;
- });
+ size_t total_expected_cultures = 0;
+ return_t ret = expect_dictionary_reserve_length(
+ culture_groups,
+ [this, default_unit_graphical_culture_type, &total_expected_cultures](std::string_view key, ast::NodeCPtr value) -> return_t {
+ std::string_view leader;
+ GraphicalCultureType const* unit_graphical_culture_type = default_unit_graphical_culture_type;
+ bool is_overseas = true;
+
+ return_t ret = expect_dictionary_keys_and_length(
+ [&total_expected_cultures](size_t size) -> size_t {
+ total_expected_cultures += size;
+ return size;
+ },
+ ALLOW_OTHER_KEYS,
+ "leader", ONE_EXACTLY, expect_identifier(assign_variable_callback(leader)),
+ "unit", ZERO_OR_ONE,
+ expect_identifier(
+ [this, &unit_graphical_culture_type](std::string_view identifier) -> return_t {
+ unit_graphical_culture_type = get_graphical_culture_type_by_identifier(identifier);
+ if (unit_graphical_culture_type != nullptr) return SUCCESS;
+ Logger::error("Invalid unit graphical culture type: ", identifier);
+ return FAILURE;
}
- );
- };
-
- return_t ret = NodeTools::expect_dictionary_keys(value, {
- { "color", { true, false, [&colour](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_colour(node, [&colour](colour_t val) -> return_t {
- colour = val;
- return SUCCESS;
- });
- } } },
- { "first_names", { true, false, [&first_names](ast::NodeCPtr node) -> return_t {
- return read_name_list(first_names, node);
- } } },
- { "last_names", { true, false, [&last_names](ast::NodeCPtr node) -> return_t {
- return read_name_list(last_names, node);
- } } },
- { "radicalism", { false, false, NodeTools::success_callback } },
- { "primary", { false, false, NodeTools::success_callback } }
- });
- if (add_culture(key, colour, culture_group, first_names, last_names) != SUCCESS) ret = FAILURE;
+ ),
+ "union", ZERO_OR_ONE, success_callback,
+ "is_overseas", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_overseas))
+ )(value);
+ if (add_culture_group(key, leader, unit_graphical_culture_type, is_overseas) != SUCCESS) ret = FAILURE;
return ret;
- });
- }, true) != SUCCESS) ret = FAILURE;
+ }
+ )(root);
+ lock_culture_groups();
+ cultures.reserve(cultures.size() + total_expected_cultures);
+
+ if (expect_dictionary(
+ [this](std::string_view culture_group_key, ast::NodeCPtr culture_group_value) -> return_t {
+
+ CultureGroup const* culture_group = get_culture_group_by_identifier(culture_group_key);
+
+ return expect_dictionary(
+ [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;
+ std::vector<std::string> first_names, last_names;
+
+ return_t ret = expect_dictionary_keys(
+ "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
+ "first_names", ONE_EXACTLY, name_list_callback(first_names),
+ "last_names", ONE_EXACTLY, name_list_callback(last_names),
+ "radicalism", ZERO_OR_ONE, success_callback,
+ "primary", ZERO_OR_ONE, success_callback
+ )(value);
+ if (add_culture(key, colour, culture_group, first_names, last_names) != SUCCESS) ret = FAILURE;
+ return ret;
+ }
+ )(culture_group_value);
+ }
+ )(root) != SUCCESS) ret = FAILURE;
lock_cultures();
return ret;
}
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
index 495ba1d..6028fea 100644
--- a/src/openvic/pop/Culture.hpp
+++ b/src/openvic/pop/Culture.hpp
@@ -21,36 +21,39 @@ namespace OpenVic {
friend struct CultureManager;
private:
+ const std::string leader;
GraphicalCultureType const& unit_graphical_culture_type;
- bool is_overseas;
+ const bool is_overseas;
- // TODO - leader type, union tag
+ // TODO - union tag
- CultureGroup(const std::string_view new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type, bool new_is_overseas);
+ CultureGroup(const std::string_view new_identifier, const std::string_view new_leader, GraphicalCultureType const& new_unit_graphical_culture_type, bool new_is_overseas);
public:
CultureGroup(CultureGroup&&) = default;
+ std::string const& get_leader() const;
GraphicalCultureType const& get_unit_graphical_culture_type() const;
+ bool get_is_overseas() const;
};
struct Culture : HasIdentifierAndColour {
friend struct CultureManager;
- using name_list_t = std::vector<std::string>;
-
private:
CultureGroup const& group;
- const name_list_t first_names, last_names;
+ const std::vector<std::string> first_names, last_names;
// TODO - radicalism, primary tag
- Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, name_list_t const& new_first_names, name_list_t const& new_last_names);
+ Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, std::vector<std::string> const& new_first_names, std::vector<std::string> const& new_last_names);
public:
Culture(Culture&&) = default;
CultureGroup const& get_group() const;
+ std::vector<std::string> const& get_first_names() const;
+ std::vector<std::string> const& get_last_names() const;
};
struct CultureManager {
@@ -65,12 +68,20 @@ namespace OpenVic {
return_t add_graphical_culture_type(const std::string_view identifier);
void lock_graphical_culture_types();
GraphicalCultureType const* get_graphical_culture_type_by_identifier(const std::string_view identifier) const;
- return_t add_culture_group(const std::string_view identifier, GraphicalCultureType const* new_graphical_culture_type, bool is_overseas);
+ size_t get_graphical_culture_type_count() const;
+ std::vector<GraphicalCultureType> const& get_graphical_culture_types() const;
+
+ return_t add_culture_group(const std::string_view identifier, const std::string_view leader, GraphicalCultureType const* new_graphical_culture_type, bool is_overseas);
void lock_culture_groups();
CultureGroup const* get_culture_group_by_identifier(const std::string_view identifier) const;
- return_t add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names);
+ size_t get_culture_group_count() const;
+ std::vector<CultureGroup> const& get_culture_groups() const;
+
+ return_t add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, std::vector<std::string> const& first_names, std::vector<std::string> const& last_names);
void lock_cultures();
Culture const* get_culture_by_identifier(const std::string_view identifier) const;
+ size_t get_culture_count() const;
+ std::vector<Culture> const& get_cultures() const;
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 4e6533a..4c188f1 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -7,6 +7,7 @@
#include "openvic/utility/Logger.hpp"
using namespace OpenVic;
+using namespace OpenVic::NodeTools;
Pop::Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size)
: type { new_type },
@@ -107,7 +108,7 @@ return_t PopManager::add_pop_type(const std::string_view identifier, colour_t co
return FAILURE;
}
if (colour > MAX_COLOUR_RGB) {
- Logger::error("Invalid pop type colour for ", identifier, ": ", PopType::colour_to_hex_string(colour));
+ Logger::error("Invalid pop type colour for ", identifier, ": ", colour_to_hex_string(colour));
return FAILURE;
}
if (sprite <= 0) {
@@ -133,6 +134,14 @@ PopType const* PopManager::get_pop_type_by_identifier(const std::string_view ide
return pop_types.get_item_by_identifier(identifier);
}
+size_t PopManager::get_pop_type_count() const {
+ return pop_types.size();
+}
+
+std::vector<PopType> const& PopManager::get_pop_types() const {
+ return pop_types.get_items();
+}
+
return_t PopManager::load_pop_type_file(std::filesystem::path const& path, ast::NodeCPtr root) {
// TODO - pop type loading
@@ -148,39 +157,33 @@ return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr ro
Religion const* religion = nullptr;
Pop::pop_size_t size = 0;
- return_t ret = NodeTools::expect_assign(root, [this, &culture, &religion, &size](std::string_view, ast::NodeCPtr pop_node) -> return_t {
- return NodeTools::expect_dictionary_keys(pop_node, {
- { "culture", { true, false, [this, &culture](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_identifier(node, [&culture, this](std::string_view identifier) -> return_t {
- culture = culture_manager.get_culture_by_identifier(identifier);
- if (culture != nullptr) return SUCCESS;
- Logger::error("Invalid pop culture: ", identifier);
- return FAILURE;
- });
- } } },
- { "religion", { true, false, [this, &religion](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_identifier(node, [&religion, this](std::string_view identifier) -> return_t {
- religion = religion_manager.get_religion_by_identifier(identifier);
- if (religion != nullptr) return SUCCESS;
- Logger::error("Invalid pop religion: ", identifier);
- return FAILURE;
- });
- } } },
- { "size", { true, false, [&size](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_uint(node, [&size](uint64_t val) -> return_t {
- if (val > 0) {
- size = val;
- return SUCCESS;
- } else {
- Logger::error("Invalid pop size: ", val);
- return FAILURE;
- }
- });
- } } },
- { "militancy", { false, false, NodeTools::success_callback } },
- { "rebel_type", { false, false, NodeTools::success_callback } }
- });
- });
+ return_t ret = expect_assign(
+ [this, &culture, &religion, &size](std::string_view, ast::NodeCPtr pop_node) -> return_t {
+ return expect_dictionary_keys(
+ "culture", ONE_EXACTLY,
+ expect_identifier(
+ [&culture, this](std::string_view identifier) -> return_t {
+ culture = culture_manager.get_culture_by_identifier(identifier);
+ if (culture != nullptr) return SUCCESS;
+ Logger::error("Invalid pop culture: ", identifier);
+ return FAILURE;
+ }
+ ),
+ "religion", ONE_EXACTLY,
+ expect_identifier(
+ [&religion, this](std::string_view identifier) -> return_t {
+ religion = religion_manager.get_religion_by_identifier(identifier);
+ if (religion != nullptr) return SUCCESS;
+ Logger::error("Invalid pop religion: ", identifier);
+ return FAILURE;
+ }
+ ),
+ "size", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("pop size", size)),
+ "militancy", ZERO_OR_ONE, success_callback,
+ "rebel_type", ZERO_OR_ONE, success_callback
+ )(pop_node);
+ }
+ )(root);
if (type != nullptr && culture != nullptr && religion != nullptr && size > 0) {
if (province.add_pop({ *type, *culture, *religion, size }) != SUCCESS) ret = FAILURE;
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index 144d53c..eab7c20 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -95,6 +95,8 @@ namespace OpenVic {
bool is_artisan, bool is_slave);
void lock_pop_types();
PopType const* get_pop_type_by_identifier(const std::string_view identifier) const;
+ size_t get_pop_type_count() const;
+ std::vector<PopType> const& get_pop_types() 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 3102bfb..58b73e5 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -3,6 +3,7 @@
#include <cassert>
using namespace OpenVic;
+using namespace OpenVic::NodeTools;
ReligionGroup::ReligionGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
@@ -47,6 +48,14 @@ ReligionGroup const* ReligionManager::get_religion_group_by_identifier(const std
return religion_groups.get_item_by_identifier(identifier);
}
+size_t ReligionManager::get_religion_group_count() const {
+ return religion_groups.size();
+}
+
+std::vector<ReligionGroup> const& ReligionManager::get_religion_groups() const {
+ return religion_groups.get_items();
+}
+
return_t ReligionManager::add_religion(const std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan) {
if (!religion_groups.is_locked()) {
Logger::error("Cannot register religions until religion groups are locked!");
@@ -61,7 +70,7 @@ return_t ReligionManager::add_religion(const std::string_view identifier, colour
return FAILURE;
}
if (colour > MAX_COLOUR_RGB) {
- Logger::error("Invalid religion colour for ", identifier, ": ", Religion::colour_to_hex_string(colour));
+ Logger::error("Invalid religion colour for ", identifier, ": ", colour_to_hex_string(colour));
return FAILURE;
}
if (icon <= 0) {
@@ -79,48 +88,55 @@ Religion const* ReligionManager::get_religion_by_identifier(const std::string_vi
return religions.get_item_by_identifier(identifier);
}
-return_t ReligionManager::load_religion_file(ast::NodeCPtr root) {
+size_t ReligionManager::get_religion_count() const {
+ return religions.size();
+}
- return_t ret = NodeTools::expect_dictionary(root, [this](std::string_view key, ast::NodeCPtr value) -> return_t {
- return_t ret = NodeTools::expect_dictionary_keys(value, {}, true);
- if (add_religion_group(key) != SUCCESS) ret = FAILURE;
- return ret;
- }, true);
- lock_religion_groups();
+std::vector<Religion> const& ReligionManager::get_religions() const {
+ return religions.get_items();
+}
+
+return_t ReligionManager::load_religion_file(ast::NodeCPtr root) {
- if (NodeTools::expect_dictionary(root, [this](std::string_view religion_group_key, ast::NodeCPtr religion_group_value) -> return_t {
-
- ReligionGroup const* religion_group = get_religion_group_by_identifier(religion_group_key);
-
- return NodeTools::expect_dictionary(religion_group_value, [this, religion_group](std::string_view key, ast::NodeCPtr value) -> return_t {
- colour_t colour = NULL_COLOUR;
- Religion::icon_t icon = 0;
- bool pagan = true;
-
- return_t ret = NodeTools::expect_dictionary_keys(value, {
- { "icon", { true, false, [&icon](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_int(node, [&icon](Religion::icon_t val) -> return_t {
- icon = val;
- return SUCCESS;
- });
- } } },
- { "color", { true, false, [&colour](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_colour(node, [&colour](colour_t val) -> return_t {
- colour = val;
- return SUCCESS;
- });
- } } },
- { "pagan", { false, false, [&pagan](ast::NodeCPtr node) -> return_t {
- return NodeTools::expect_bool(node, [&pagan](bool val) -> return_t {
- pagan = val;
- return SUCCESS;
- });
- } } }
- });
- if (add_religion(key, colour, religion_group, icon, pagan) != SUCCESS) ret = FAILURE;
+ size_t total_expected_religions = 0;
+ return_t ret = expect_dictionary_reserve_length(
+ religion_groups,
+ [this, &total_expected_religions](std::string_view key, ast::NodeCPtr value) -> return_t {
+ return_t ret = expect_list_and_length(
+ [&total_expected_religions](size_t size) -> size_t {
+ total_expected_religions += size;
+ return 0;
+ },
+ success_callback
+ )(value);
+ if (add_religion_group(key) != SUCCESS) ret = FAILURE;
return ret;
- });
- }, true) != SUCCESS) ret = FAILURE;
+ }
+ )(root);
+ lock_religion_groups();
+ religions.reserve(religions.size() + total_expected_religions);
+ if (expect_dictionary(
+ [this](std::string_view religion_group_key, ast::NodeCPtr religion_group_value) -> return_t {
+
+ ReligionGroup const* religion_group = get_religion_group_by_identifier(religion_group_key);
+
+ return expect_dictionary(
+ [this, religion_group](std::string_view key, ast::NodeCPtr value) -> return_t {
+ colour_t colour = NULL_COLOUR;
+ Religion::icon_t icon = 0;
+ bool pagan = false;
+
+ return_t ret = expect_dictionary_keys(
+ "icon", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("religion icon", icon)),
+ "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
+ "pagan", ZERO_OR_ONE, expect_bool(assign_variable_callback(pagan))
+ )(value);
+ if (add_religion(key, colour, religion_group, icon, pagan) != SUCCESS) ret = FAILURE;
+ return ret;
+ }
+ )(religion_group_value);
+ }
+ )(root) != SUCCESS) ret = FAILURE;
lock_religions();
return ret;
-} \ No newline at end of file
+}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index 730454e..12db36c 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -48,9 +48,14 @@ namespace OpenVic {
return_t add_religion_group(const std::string_view identifier);
void lock_religion_groups();
ReligionGroup const* get_religion_group_by_identifier(const std::string_view identifier) const;
+ size_t get_religion_group_count() const;
+ std::vector<ReligionGroup> const& get_religion_groups() const;
+
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;
+ size_t get_religion_count() const;
+ std::vector<Religion> const& get_religions() const;
return_t load_religion_file(ast::NodeCPtr root);
};