aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic/pop')
-rw-r--r--src/openvic/pop/Culture.cpp60
-rw-r--r--src/openvic/pop/Culture.hpp10
-rw-r--r--src/openvic/pop/Pop.cpp38
-rw-r--r--src/openvic/pop/Pop.hpp6
-rw-r--r--src/openvic/pop/Religion.cpp38
-rw-r--r--src/openvic/pop/Religion.hpp6
6 files changed, 79 insertions, 79 deletions
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
index 2670f00..d86d608 100644
--- a/src/openvic/pop/Culture.cpp
+++ b/src/openvic/pop/Culture.cpp
@@ -50,10 +50,10 @@ CultureManager::CultureManager()
culture_groups { "culture groups" },
cultures { "cultures" } {}
-return_t CultureManager::add_graphical_culture_type(const std::string_view identifier) {
+bool CultureManager::add_graphical_culture_type(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid culture group identifier - empty!");
- return FAILURE;
+ return false;
}
return graphical_culture_types.add_item({ identifier });
}
@@ -74,22 +74,22 @@ std::vector<GraphicalCultureType> const& CultureManager::get_graphical_culture_t
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) {
+bool 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;
+ return false;
}
if (identifier.empty()) {
Logger::error("Invalid culture group identifier - empty!");
- return FAILURE;
+ return false;
}
if (leader.empty()) {
Logger::error("Invalid culture group leader - empty!");
- return FAILURE;
+ return false;
}
if (graphical_culture_type == nullptr) {
Logger::error("Null graphical culture type for ", identifier);
- return FAILURE;
+ return false;
}
return culture_groups.add_item({ identifier, leader, *graphical_culture_type, is_overseas });
}
@@ -110,22 +110,22 @@ 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) {
+bool 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;
+ return false;
}
if (identifier.empty()) {
Logger::error("Invalid culture identifier - empty!");
- return FAILURE;
+ return false;
}
if (group == nullptr) {
Logger::error("Null culture group for ", identifier);
- return FAILURE;
+ return false;
}
if (colour > MAX_COLOUR_RGB) {
Logger::error("Invalid culture colour for ", identifier, ": ", colour_to_hex_string(colour));
- return FAILURE;
+ return false;
}
return cultures.add_item({ identifier, colour, *group, first_names, last_names });
}
@@ -146,8 +146,8 @@ 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 = expect_list_reserve_length(
+bool CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) {
+ const bool ret = expect_list_reserve_length(
graphical_culture_types,
expect_identifier(
std::bind(&CultureManager::add_graphical_culture_type, this, std::placeholders::_1)
@@ -157,10 +157,10 @@ return_t CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) {
return ret;
}
-return_t CultureManager::load_culture_file(ast::NodeCPtr root) {
+bool CultureManager::load_culture_file(ast::NodeCPtr root) {
if (!graphical_culture_types.is_locked()) {
Logger::error("Cannot load culture groups until graphical culture types are locked!");
- return FAILURE;
+ return false;
}
static const std::string default_unit_graphical_culture_type_identifier = "Generic";
@@ -170,14 +170,14 @@ return_t CultureManager::load_culture_file(ast::NodeCPtr root) {
}
size_t total_expected_cultures = 0;
- return_t ret = expect_dictionary_reserve_length(
+ bool 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 {
+ [this, default_unit_graphical_culture_type, &total_expected_cultures](std::string_view key, ast::NodeCPtr value) -> bool {
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(
+ bool ret = expect_dictionary_keys_and_length(
[&total_expected_cultures](size_t size) -> size_t {
total_expected_cultures += size;
return size;
@@ -186,48 +186,48 @@ return_t CultureManager::load_culture_file(ast::NodeCPtr root) {
"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 {
+ [this, &unit_graphical_culture_type](std::string_view identifier) -> bool {
unit_graphical_culture_type = get_graphical_culture_type_by_identifier(identifier);
- if (unit_graphical_culture_type != nullptr) return SUCCESS;
+ if (unit_graphical_culture_type != nullptr) return true;
Logger::error("Invalid unit graphical culture type: ", identifier);
- return FAILURE;
+ return false;
}
),
"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;
+ ret &= add_culture_group(key, leader, unit_graphical_culture_type, is_overseas);
return ret;
}
)(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 {
+ ret &= expect_dictionary(
+ [this](std::string_view culture_group_key, ast::NodeCPtr culture_group_value) -> bool {
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;
+ [this, culture_group](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key == "leader" || key == "unit" || key == "union" || key == "is_overseas") return true;
colour_t colour = NULL_COLOUR;
std::vector<std::string> first_names, last_names;
- return_t ret = expect_dictionary_keys(
+ bool 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;
+ ret &= add_culture(key, colour, culture_group, first_names, last_names);
return ret;
}
)(culture_group_value);
}
- )(root) != SUCCESS) ret = FAILURE;
+ )(root);
lock_cultures();
return ret;
}
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
index 6028fea..cc6c2a6 100644
--- a/src/openvic/pop/Culture.hpp
+++ b/src/openvic/pop/Culture.hpp
@@ -65,25 +65,25 @@ namespace OpenVic {
public:
CultureManager();
- return_t add_graphical_culture_type(const std::string_view identifier);
+ bool 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;
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);
+ bool 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;
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);
+ bool 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);
+ bool load_graphical_culture_type_file(ast::NodeCPtr root);
+ bool load_culture_file(ast::NodeCPtr root);
};
}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
index 4c188f1..fbe8708 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -101,27 +101,27 @@ bool PopType::get_is_slave() const {
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,
+bool 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) {
if (identifier.empty()) {
Logger::error("Invalid pop type identifier - empty!");
- return FAILURE;
+ return false;
}
if (colour > MAX_COLOUR_RGB) {
Logger::error("Invalid pop type colour for ", identifier, ": ", colour_to_hex_string(colour));
- return FAILURE;
+ return false;
}
if (sprite <= 0) {
Logger::error("Invalid pop type sprite index for ", identifier, ": ", sprite);
- return FAILURE;
+ return false;
}
if (max_size <= 0) {
Logger::error("Invalid pop type max size for ", identifier, ": ", max_size);
- return FAILURE;
+ return false;
}
if (merge_max_size <= 0) {
Logger::error("Invalid pop type merge max size for ", identifier, ": ", merge_max_size);
- return FAILURE;
+ return false;
}
return pop_types.add_item({ identifier, colour, strata, sprite, max_size, merge_max_size, state_capital_only, demote_migrant, is_artisan, is_slave });
}
@@ -142,40 +142,40 @@ 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) {
+bool 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 true;
}
-return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr root) const {
+bool PopManager::load_pop_into_province(Province& province, ast::NodeCPtr root) const {
static PopType const* type = get_pop_type_by_identifier("test_pop_type");
Culture const* culture = nullptr;
Religion const* religion = nullptr;
Pop::pop_size_t size = 0;
- return_t ret = expect_assign(
- [this, &culture, &religion, &size](std::string_view, ast::NodeCPtr pop_node) -> return_t {
+ bool ret = expect_assign(
+ [this, &culture, &religion, &size](std::string_view, ast::NodeCPtr pop_node) -> bool {
return expect_dictionary_keys(
"culture", ONE_EXACTLY,
expect_identifier(
- [&culture, this](std::string_view identifier) -> return_t {
+ [&culture, this](std::string_view identifier) -> bool {
culture = culture_manager.get_culture_by_identifier(identifier);
- if (culture != nullptr) return SUCCESS;
+ if (culture != nullptr) return true;
Logger::error("Invalid pop culture: ", identifier);
- return FAILURE;
+ return false;
}
),
"religion", ONE_EXACTLY,
expect_identifier(
- [&religion, this](std::string_view identifier) -> return_t {
+ [&religion, this](std::string_view identifier) -> bool {
religion = religion_manager.get_religion_by_identifier(identifier);
- if (religion != nullptr) return SUCCESS;
+ if (religion != nullptr) return true;
Logger::error("Invalid pop religion: ", identifier);
- return FAILURE;
+ return false;
}
),
"size", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("pop size", size)),
@@ -186,10 +186,10 @@ return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr ro
)(root);
if (type != nullptr && culture != nullptr && religion != nullptr && size > 0) {
- if (province.add_pop({ *type, *culture, *religion, size }) != SUCCESS) ret = FAILURE;
+ ret &= province.add_pop({ *type, *culture, *religion, size });
} else {
Logger::error("Some pop arguments are invalid: type = ", type, ", culture = ", culture, ", religion = ", religion, ", size = ", size);
- ret = FAILURE;
+ ret = false;
}
return ret;
}
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index eab7c20..f4694f0 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -90,7 +90,7 @@ namespace OpenVic {
PopManager();
- return_t add_pop_type(const std::string_view identifier, colour_t new_colour, PopType::strata_t strata, PopType::sprite_t sprite,
+ bool add_pop_type(const std::string_view identifier, colour_t new_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);
void lock_pop_types();
@@ -98,7 +98,7 @@ namespace OpenVic {
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;
+ bool load_pop_type_file(std::filesystem::path const& path, ast::NodeCPtr root);
+ bool 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 58b73e5..f7c657a 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -32,10 +32,10 @@ ReligionManager::ReligionManager()
: religion_groups { "religion groups" },
religions { "religions" } {}
-return_t ReligionManager::add_religion_group(const std::string_view identifier) {
+bool ReligionManager::add_religion_group(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid religion group identifier - empty!");
- return FAILURE;
+ return false;
}
return religion_groups.add_item({ identifier });
}
@@ -56,26 +56,26 @@ 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) {
+bool 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!");
- return FAILURE;
+ return false;
}
if (identifier.empty()) {
Logger::error("Invalid religion identifier - empty!");
- return FAILURE;
+ return false;
}
if (group == nullptr) {
Logger::error("Null religion group for ", identifier);
- return FAILURE;
+ return false;
}
if (colour > MAX_COLOUR_RGB) {
Logger::error("Invalid religion colour for ", identifier, ": ", colour_to_hex_string(colour));
- return FAILURE;
+ return false;
}
if (icon <= 0) {
Logger::error("Invalid religion icon for ", identifier, ": ", icon);
- return FAILURE;
+ return false;
}
return religions.add_item({ identifier, colour, *group, icon, pagan });
}
@@ -96,47 +96,47 @@ std::vector<Religion> const& ReligionManager::get_religions() const {
return religions.get_items();
}
-return_t ReligionManager::load_religion_file(ast::NodeCPtr root) {
+bool ReligionManager::load_religion_file(ast::NodeCPtr root) {
size_t total_expected_religions = 0;
- return_t ret = expect_dictionary_reserve_length(
+ bool 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(
+ [this, &total_expected_religions](std::string_view key, ast::NodeCPtr value) -> bool {
+ bool 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;
+ ret &= add_religion_group(key);
return ret;
}
)(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 {
+ ret &= expect_dictionary(
+ [this](std::string_view religion_group_key, ast::NodeCPtr religion_group_value) -> bool {
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 {
+ [this, religion_group](std::string_view key, ast::NodeCPtr value) -> bool {
colour_t colour = NULL_COLOUR;
Religion::icon_t icon = 0;
bool pagan = false;
- return_t ret = expect_dictionary_keys(
+ bool 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;
+ ret &= add_religion(key, colour, religion_group, icon, pagan);
return ret;
}
)(religion_group_value);
}
- )(root) != SUCCESS) ret = FAILURE;
+ )(root);
lock_religions();
return ret;
}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index 12db36c..f04b035 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -45,18 +45,18 @@ namespace OpenVic {
public:
ReligionManager();
- return_t add_religion_group(const std::string_view identifier);
+ bool 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);
+ bool 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);
+ bool load_religion_file(ast::NodeCPtr root);
};
}