aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-09-08 01:34:47 +0200
committer Hop311 <hop3114@gmail.com>2023-09-08 01:34:47 +0200
commit7f9a9a8241ba81be9213e6606b8be4a48f1cbaab (patch)
tree26b67f150ec1b43593343344eabdc7deca47d0d8 /src
parent3cd1d62ec00690a1b29070dd4903754e8f089a21 (diff)
Remove return_t, use & instead of if(x != SUCCESS)
Diffstat (limited to 'src')
-rw-r--r--src/headless/main.cpp22
-rw-r--r--src/openvic/GameManager.cpp21
-rw-r--r--src/openvic/GameManager.hpp6
-rw-r--r--src/openvic/dataloader/Dataloader.cpp89
-rw-r--r--src/openvic/dataloader/Dataloader.hpp16
-rw-r--r--src/openvic/dataloader/NodeTools.cpp115
-rw-r--r--src/openvic/dataloader/NodeTools.hpp47
-rw-r--r--src/openvic/economy/Good.cpp38
-rw-r--r--src/openvic/economy/Good.hpp6
-rw-r--r--src/openvic/map/Building.cpp24
-rw-r--r--src/openvic/map/Building.hpp6
-rw-r--r--src/openvic/map/Map.cpp134
-rw-r--r--src/openvic/map/Map.hpp20
-rw-r--r--src/openvic/map/Province.cpp16
-rw-r--r--src/openvic/map/Province.hpp8
-rw-r--r--src/openvic/map/Region.cpp14
-rw-r--r--src/openvic/map/Region.hpp3
-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
-rw-r--r--src/openvic/types/IdentifierRegistry.hpp9
-rw-r--r--src/openvic/types/Return.hpp8
-rw-r--r--src/openvic/utility/BMP.cpp56
-rw-r--r--src/openvic/utility/BMP.hpp7
27 files changed, 403 insertions, 420 deletions
diff --git a/src/headless/main.cpp b/src/headless/main.cpp
index 9366f12..a5bfc03 100644
--- a/src/headless/main.cpp
+++ b/src/headless/main.cpp
@@ -20,8 +20,8 @@ static char const* get_program_name(char const* name) {
return last_separator;
}
-static return_t headless_load(std::vector<std::filesystem::path> const& roots) {
- return_t ret = SUCCESS;
+static bool headless_load(std::vector<std::filesystem::path> const& roots) {
+ bool ret = true;
Logger::set_info_func([](std::string&& str) { std::cout << str; });
Logger::set_error_func([](std::string&& str) { std::cerr << str; });
@@ -31,17 +31,17 @@ static return_t headless_load(std::vector<std::filesystem::path> const& roots) {
} };
Dataloader dataloader;
- if (dataloader.set_roots(roots) != SUCCESS) {
+ if (!dataloader.set_roots(roots)) {
Logger::error("Failed to set dataloader roots!");
- ret = FAILURE;
+ ret = false;
}
- if (dataloader.load_defines(game_manager) != SUCCESS) {
+ if (!dataloader.load_defines(game_manager)) {
Logger::error("Failed to load defines!");
- ret = FAILURE;
+ ret = false;
}
- if (game_manager.load_hardcoded_defines() != SUCCESS) {
+ if (!game_manager.load_hardcoded_defines()) {
Logger::error("Failed to load hardcoded defines!");
- ret = FAILURE;
+ ret = false;
}
return ret;
@@ -66,12 +66,12 @@ int main(int argc, char const* argv[]) {
std::cout << "!!! HEADLESS SIMULATION START !!!" << std::endl;
- const return_t ret = headless_load(roots);
+ const bool ret = headless_load(roots);
std::cout << "!!! HEADLESS SIMULATION END !!!" << std::endl;
- std::cout << "\nLoad returned: " << (ret == SUCCESS ? "SUCCESS" : "FAILURE") << std::endl;
+ std::cout << "\nLoad returned: " << (ret ? "true" : "false") << std::endl;
- return ret == SUCCESS ? 0 : -1;
+ return ret ? 0 : -1;
}
#endif
diff --git a/src/openvic/GameManager.cpp b/src/openvic/GameManager.cpp
index f9c9664..052b814 100644
--- a/src/openvic/GameManager.cpp
+++ b/src/openvic/GameManager.cpp
@@ -31,12 +31,12 @@ void GameManager::tick() {
set_needs_update();
}
-return_t GameManager::setup() {
+bool GameManager::setup() {
session_start = time(nullptr);
clock.reset();
today = { 1836 };
good_manager.reset_to_defaults();
- return_t ret = map.setup(good_manager, building_manager, pop_manager);
+ bool ret = map.setup(good_manager, building_manager, pop_manager);
set_needs_update();
return ret;
}
@@ -45,15 +45,18 @@ Date const& GameManager::get_today() const {
return today;
}
-return_t GameManager::expand_building(Province::index_t province_index, const std::string_view building_type_identifier) {
+bool GameManager::expand_building(Province::index_t province_index, const std::string_view building_type_identifier) {
set_needs_update();
Province* province = map.get_province_by_index(province_index);
- if (province == nullptr) return FAILURE;
+ if (province == nullptr) {
+ Logger::error("Invalid province index ", province_index, " while trying to expand building ", building_type_identifier);
+ return false;
+ }
return province->expand_building(building_type_identifier);
}
-return_t GameManager::load_hardcoded_defines() {
- return_t ret = SUCCESS;
+bool GameManager::load_hardcoded_defines() {
+ bool ret = true;
static constexpr colour_t LOW_ALPHA_VALUE = float_to_alpha_value(0.4f);
static constexpr colour_t HIGH_ALPHA_VALUE = float_to_alpha_value(0.7f);
@@ -114,8 +117,7 @@ return_t GameManager::load_hardcoded_defines() {
} }
};
for (mapmode_t const& mapmode : mapmodes)
- if (map.add_mapmode(mapmode.first, mapmode.second) != SUCCESS)
- ret = FAILURE;
+ ret &= map.add_mapmode(mapmode.first, mapmode.second);
map.lock_mapmodes();
using building_type_t = std::tuple<std::string, Building::level_t, Timespan>;
@@ -123,8 +125,7 @@ return_t GameManager::load_hardcoded_defines() {
{ "building_fort", 4, 8 }, { "building_naval_base", 6, 15 }, { "building_railroad", 5, 10 }
};
for (building_type_t const& type : building_types)
- if (building_manager.add_building_type(std::get<0>(type), std::get<1>(type), std::get<2>(type)) != SUCCESS)
- ret = FAILURE;
+ ret &= building_manager.add_building_type(std::get<0>(type), std::get<1>(type), std::get<2>(type));
building_manager.lock_building_types();
return ret;
diff --git a/src/openvic/GameManager.hpp b/src/openvic/GameManager.hpp
index cffa75b..af2ec4f 100644
--- a/src/openvic/GameManager.hpp
+++ b/src/openvic/GameManager.hpp
@@ -27,14 +27,14 @@ namespace OpenVic {
public:
GameManager(state_updated_func_t state_updated_callback);
- return_t setup();
+ bool setup();
Date const& get_today() const;
- return_t expand_building(Province::index_t province_index, const std::string_view building_type_identifier);
+ bool expand_building(Province::index_t province_index, const std::string_view building_type_identifier);
/* Hardcoded data for defining things for which parsing from files has
* not been implemented, currently mapmodes and building types.
*/
- return_t load_hardcoded_defines();
+ bool load_hardcoded_defines();
};
}
diff --git a/src/openvic/dataloader/Dataloader.cpp b/src/openvic/dataloader/Dataloader.cpp
index 685d987..55994d3 100644
--- a/src/openvic/dataloader/Dataloader.cpp
+++ b/src/openvic/dataloader/Dataloader.cpp
@@ -11,12 +11,12 @@ using namespace OpenVic;
using namespace OpenVic::NodeTools;
using namespace ovdl;
-return_t Dataloader::set_roots(std::vector<std::filesystem::path> new_roots) {
+bool Dataloader::set_roots(std::vector<std::filesystem::path> new_roots) {
if (!roots.empty()) {
Logger::error("Overriding existing dataloader roots!");
roots.clear();
}
- return_t ret = SUCCESS;
+ bool ret = true;
for (std::reverse_iterator<std::vector<std::filesystem::path>::const_iterator> it = new_roots.crbegin(); it != new_roots.crend(); ++it) {
if (std::find(roots.begin(), roots.end(), *it) == roots.end()) {
if (std::filesystem::is_directory(*it)) {
@@ -24,16 +24,16 @@ return_t Dataloader::set_roots(std::vector<std::filesystem::path> new_roots) {
roots.push_back(*it);
} else {
Logger::error("Invalid dataloader root (must be an existing directory): ", *it);
- ret = FAILURE;
+ ret = false;
}
} else {
Logger::error("Duplicate dataloader root: ", *it);
- ret = FAILURE;
+ ret = false;
}
}
if (roots.empty()) {
Logger::error("Dataloader has no roots after attempting to add ", new_roots.size());
- ret = FAILURE;
+ ret = false;
}
return ret;
}
@@ -81,15 +81,13 @@ std::vector<std::filesystem::path> Dataloader::lookup_files_in_dir(std::filesyst
return ret;
}
-return_t Dataloader::apply_to_files_in_dir(std::filesystem::path const& path,
- std::function<return_t(std::filesystem::path const&)> callback,
+bool Dataloader::apply_to_files_in_dir(std::filesystem::path const& path,
+ std::function<bool(std::filesystem::path const&)> callback,
std::filesystem::path const* extension) const {
- return_t ret = SUCCESS;
+ bool ret = true;
for (std::filesystem::path const& file : lookup_files_in_dir(path, extension)) {
- if (callback(file) != SUCCESS) {
- ret = FAILURE;
- }
+ ret &= callback(file);
}
return ret;
}
@@ -140,21 +138,20 @@ static csv::Windows1252Parser _parse_csv(std::filesystem::path const& path) {
return _run_ovdl_parser<csv::Windows1252Parser, &csv::Windows1252Parser::parse_csv>(path);
}
-return_t Dataloader::_load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const {
- return_t ret = SUCCESS;
- if (apply_to_files_in_dir(pop_type_directory,
- [&pop_manager](std::filesystem::path const& file) -> return_t {
+bool Dataloader::_load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const {
+ const bool ret = apply_to_files_in_dir(pop_type_directory,
+ [&pop_manager](std::filesystem::path const& file) -> bool {
return pop_manager.load_pop_type_file(file, _parse_defines(file).get_file_node());
}
- ) != SUCCESS) {
+ );
+ if (!ret) {
Logger::error("Failed to load pop types!");
- ret = FAILURE;
}
pop_manager.lock_pop_types();
return ret;
}
-return_t Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_directory) const {
+bool Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_directory) const {
static const std::filesystem::path defaults_filename = "default.map";
static const std::string default_definitions = "definition.csv";
static const std::string default_provinces = "provinces.bmp";
@@ -182,24 +179,24 @@ return_t Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_di
APPLY_TO_MAP_PATHS(MAP_PATH_VAR)
#undef MAP_PATH_VAR
- return_t ret = expect_dictionary_keys(
+ bool ret = expect_dictionary_keys(
"max_provinces", ONE_EXACTLY,
expect_uint(
- [&map](uint64_t val) -> return_t {
+ [&map](uint64_t val) -> bool {
if (Province::NULL_INDEX < val && val <= Province::MAX_INDEX) {
return map.set_max_provinces(val);
}
Logger::error("Invalid max province count ", val, " (out of valid range ", Province::NULL_INDEX, " < max_provinces <= ", Province::MAX_INDEX, ")");
- return FAILURE;
+ return false;
}
),
"sea_starts", ONE_EXACTLY,
expect_list_reserve_length(
water_province_identifiers,
expect_identifier(
- [&water_province_identifiers](std::string_view identifier) -> return_t {
+ [&water_province_identifiers](std::string_view identifier) -> bool {
water_province_identifiers.push_back(identifier);
- return SUCCESS;
+ return true;
}
)
),
@@ -217,25 +214,25 @@ return_t Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_di
"border_cutoff", ZERO_OR_ONE, success_callback
)(parser.get_file_node());
- if (ret != SUCCESS) {
+ if (!ret) {
Logger::error("Failed to load map default file!");
}
- if (map.load_province_definitions(_parse_csv(lookup_file(map_directory / definitions)).get_lines()) != SUCCESS) {
+ if (!map.load_province_definitions(_parse_csv(lookup_file(map_directory / definitions)).get_lines())) {
Logger::error("Failed to load province definitions file!");
- ret = FAILURE;
+ ret = false;
}
- if (map.set_water_province_list(water_province_identifiers) != SUCCESS) {
+ if (!map.set_water_province_list(water_province_identifiers)) {
Logger::error("Failed to set water provinces!");
- ret = FAILURE;
+ ret = false;
}
map.lock_water_provinces();
return ret;
}
-return_t Dataloader::load_defines(GameManager& game_manager) const {
+bool Dataloader::load_defines(GameManager& game_manager) const {
static const std::filesystem::path good_file = "common/goods.txt";
static const std::filesystem::path pop_type_directory = "poptypes";
static const std::filesystem::path graphical_culture_type_file = "common/graphicalculturetype.txt";
@@ -243,45 +240,45 @@ return_t Dataloader::load_defines(GameManager& game_manager) const {
static const std::filesystem::path religion_file = "common/religion.txt";
static const std::filesystem::path map_directory = "map";
- return_t ret = SUCCESS;
+ bool ret = true;
- if (game_manager.good_manager.load_good_file(_parse_defines(lookup_file(good_file)).get_file_node()) != SUCCESS) {
+ if (!game_manager.good_manager.load_good_file(_parse_defines(lookup_file(good_file)).get_file_node())) {
Logger::error("Failed to load goods!");
- ret = FAILURE;
+ ret = false;
}
- if (_load_pop_types(game_manager.pop_manager, pop_type_directory) != SUCCESS) {
+ if (!_load_pop_types(game_manager.pop_manager, pop_type_directory)) {
Logger::error("Failed to load pop types!");
- ret = FAILURE;
+ ret = false;
}
- if (game_manager.pop_manager.culture_manager.load_graphical_culture_type_file(_parse_defines(lookup_file(graphical_culture_type_file)).get_file_node()) != SUCCESS) {
+ if (!game_manager.pop_manager.culture_manager.load_graphical_culture_type_file(_parse_defines(lookup_file(graphical_culture_type_file)).get_file_node())) {
Logger::error("Failed to load graphical culture types!");
- ret = FAILURE;
+ ret = false;
}
- if (game_manager.pop_manager.culture_manager.load_culture_file(_parse_defines(lookup_file(culture_file)).get_file_node()) != SUCCESS) {
+ if (!game_manager.pop_manager.culture_manager.load_culture_file(_parse_defines(lookup_file(culture_file)).get_file_node())) {
Logger::error("Failed to load cultures!");
- ret = FAILURE;
+ ret = false;
}
- if (game_manager.pop_manager.religion_manager.load_religion_file(_parse_defines(lookup_file(religion_file)).get_file_node()) != SUCCESS) {
+ if (!game_manager.pop_manager.religion_manager.load_religion_file(_parse_defines(lookup_file(religion_file)).get_file_node())) {
Logger::error("Failed to load religions!");
- ret = FAILURE;
+ ret = false;
}
- if (_load_map_dir(game_manager.map, map_directory) != SUCCESS) {
+ if (!_load_map_dir(game_manager.map, map_directory)) {
Logger::error("Failed to load map!");
- ret = FAILURE;
+ ret = false;
}
return ret;
}
-return_t Dataloader::load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const {
+bool Dataloader::load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const {
return apply_to_files_in_dir(path,
- [&game_manager](std::filesystem::path const& file) -> return_t {
+ [&game_manager](std::filesystem::path const& file) -> bool {
return expect_dictionary(
- [&game_manager](std::string_view province_key, ast::NodeCPtr province_node) -> return_t {
+ [&game_manager](std::string_view province_key, ast::NodeCPtr province_node) -> bool {
Province* province = game_manager.map.get_province_by_identifier(province_key);
if (province == nullptr) {
Logger::error("Invalid province id: ", province_key);
- return FAILURE;
+ return false;
}
return province->load_pop_list(game_manager.pop_manager, province_node);
}
diff --git a/src/openvic/dataloader/Dataloader.hpp b/src/openvic/dataloader/Dataloader.hpp
index 9e5c24b..f723803 100644
--- a/src/openvic/dataloader/Dataloader.hpp
+++ b/src/openvic/dataloader/Dataloader.hpp
@@ -4,8 +4,6 @@
#include <functional>
#include <vector>
-#include "openvic/types/Return.hpp"
-
namespace OpenVic {
struct GameManager;
struct PopManager;
@@ -14,24 +12,24 @@ namespace OpenVic {
class Dataloader {
std::vector<std::filesystem::path> roots;
- return_t _load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const;
- return_t _load_map_dir(Map& map, std::filesystem::path const& map_directory) const;
+ bool _load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const;
+ bool _load_map_dir(Map& map, std::filesystem::path const& map_directory) const;
public:
Dataloader() = default;
/* In reverse-load order, so base defines first and final loaded mod last */
- return_t set_roots(std::vector<std::filesystem::path> new_roots);
+ bool set_roots(std::vector<std::filesystem::path> new_roots);
std::filesystem::path lookup_file(std::filesystem::path const& path) const;
static const std::filesystem::path TXT;
std::vector<std::filesystem::path> lookup_files_in_dir(std::filesystem::path const& path,
std::filesystem::path const* extension = &TXT) const;
- return_t apply_to_files_in_dir(std::filesystem::path const& path,
- std::function<return_t(std::filesystem::path const&)> callback,
+ bool apply_to_files_in_dir(std::filesystem::path const& path,
+ std::function<bool(std::filesystem::path const&)> callback,
std::filesystem::path const* extension = &TXT) const;
- return_t load_defines(GameManager& game_manager) const;
- return_t load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const;
+ bool load_defines(GameManager& game_manager) const;
+ bool load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const;
};
}
diff --git a/src/openvic/dataloader/NodeTools.cpp b/src/openvic/dataloader/NodeTools.cpp
index 6e5f7d0..499527f 100644
--- a/src/openvic/dataloader/NodeTools.cpp
+++ b/src/openvic/dataloader/NodeTools.cpp
@@ -6,8 +6,8 @@ using namespace OpenVic;
using namespace OpenVic::NodeTools;
template<typename T>
-static node_callback_t _expect_type(std::function<return_t(T const&)> callback) {
- return [callback](ast::NodeCPtr node) -> return_t {
+static node_callback_t _expect_type(std::function<bool(T const&)> callback) {
+ return [callback](ast::NodeCPtr node) -> bool {
if (node != nullptr) {
T const* cast_node = node->cast_to<T>();
if (cast_node != nullptr) {
@@ -17,28 +17,28 @@ static node_callback_t _expect_type(std::function<return_t(T const&)> callback)
} else {
Logger::error("Null node when expecting ", T::get_type_static());
}
- return FAILURE;
+ return false;
};
}
template<typename T = ast::AbstractStringNode>
requires(std::derived_from<T, ast::AbstractStringNode>)
-static std::function<return_t(T const&)> abstract_string_node_callback(std::function<return_t(std::string_view)> callback) {
- return [callback](T const& node) -> return_t {
+static std::function<bool(T const&)> abstract_string_node_callback(std::function<bool(std::string_view)> callback) {
+ return [callback](T const& node) -> bool {
return callback(node._name);
};
}
-node_callback_t NodeTools::expect_identifier(std::function<return_t(std::string_view)> callback) {
+node_callback_t NodeTools::expect_identifier(std::function<bool(std::string_view)> callback) {
return _expect_type<ast::IdentifierNode>(abstract_string_node_callback<ast::IdentifierNode>(callback));
}
-node_callback_t NodeTools::expect_string(std::function<return_t(std::string_view)> callback) {
+node_callback_t NodeTools::expect_string(std::function<bool(std::string_view)> callback) {
return _expect_type<ast::StringNode>(abstract_string_node_callback<ast::StringNode>(callback));
}
-node_callback_t NodeTools::expect_identifier_or_string(std::function<return_t(std::string_view)> callback) {
- return [callback](ast::NodeCPtr node) -> return_t {
+node_callback_t NodeTools::expect_identifier_or_string(std::function<bool(std::string_view)> callback) {
+ return [callback](ast::NodeCPtr node) -> bool {
if (node != nullptr) {
ast::AbstractStringNode const* cast_node = node->cast_to<ast::IdentifierNode>();
if (cast_node == nullptr) {
@@ -51,109 +51,108 @@ node_callback_t NodeTools::expect_identifier_or_string(std::function<return_t(st
} else {
Logger::error("Null node when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static());
}
- return FAILURE;
+ return false;
};
}
-node_callback_t NodeTools::expect_bool(std::function<return_t(bool)> callback) {
+node_callback_t NodeTools::expect_bool(std::function<bool(bool)> callback) {
return expect_identifier(
- [callback](std::string_view identifier) -> return_t {
+ [callback](std::string_view identifier) -> bool {
if (identifier == "yes") {
return callback(true);
} else if (identifier == "no") {
return callback(false);
}
Logger::error("Invalid bool identifier text: ", identifier);
- return FAILURE;
+ return false;
}
);
}
-node_callback_t NodeTools::expect_int(std::function<return_t(int64_t)> callback) {
+node_callback_t NodeTools::expect_int(std::function<bool(int64_t)> callback) {
return expect_identifier(
- [callback](std::string_view identifier) -> return_t {
+ [callback](std::string_view identifier) -> bool {
bool successful = false;
const int64_t val = StringUtils::string_to_int64(identifier, &successful, 10);
if (successful) {
return callback(val);
}
Logger::error("Invalid int identifier text: ", identifier);
- return FAILURE;
+ return false;
}
);
}
-node_callback_t NodeTools::expect_uint(std::function<return_t(uint64_t)> callback) {
+node_callback_t NodeTools::expect_uint(std::function<bool(uint64_t)> callback) {
return expect_identifier(
- [callback](std::string_view identifier) -> return_t {
+ [callback](std::string_view identifier) -> bool {
bool successful = false;
const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, 10);
if (successful) {
return callback(val);
}
Logger::error("Invalid uint identifier text: ", identifier);
- return FAILURE;
+ return false;
}
);
}
-node_callback_t NodeTools::expect_fixed_point(std::function<return_t(FP)> callback) {
+node_callback_t NodeTools::expect_fixed_point(std::function<bool(FP)> callback) {
return expect_identifier(
- [callback](std::string_view identifier) -> return_t {
+ [callback](std::string_view identifier) -> bool {
bool successful = false;
const FP val = FP::parse(identifier.data(), identifier.length(), &successful);
if (successful) {
return callback(val);
}
Logger::error("Invalid fixed point identifier text: ", identifier);
- return FAILURE;
+ return false;
}
);
}
-node_callback_t NodeTools::expect_colour(std::function<return_t(colour_t)> callback) {
- return [callback](ast::NodeCPtr node) -> return_t {
+node_callback_t NodeTools::expect_colour(std::function<bool(colour_t)> callback) {
+ return [callback](ast::NodeCPtr node) -> bool {
colour_t col = NULL_COLOUR;
uint32_t components = 0;
- return_t ret = expect_list_of_length(3,
+ bool ret = expect_list_of_length(3,
expect_fixed_point(
- [&col, &components](FP val) -> return_t {
- return_t ret = SUCCESS;
+ [&col, &components](FP val) -> bool {
+ components++;
+ col <<= 8;
if (val < 0 || val > 255) {
Logger::error("Invalid colour component: ", val);
- val = FP::_0();
- ret = FAILURE;
+ return false;
+ } else {
+ if (val <= 1) val *= 255;
+ col |= val.to_int32_t();
+ return true;
}
- if (val <= 1) val *= 255;
- col = (col << 8) | val.to_int32_t();
- components++;
- return ret;
}
)
)(node);
- if (components < 3) col <<= 8 * (3 - components);
- if (callback(col) != SUCCESS) ret = FAILURE;
+ ret &= callback(col << 8 * (3 - components));
return ret;
};
}
-node_callback_t NodeTools::expect_date(std::function<return_t(Date)> callback) {
+node_callback_t NodeTools::expect_date(std::function<bool(Date)> callback) {
return expect_identifier(
- [callback](std::string_view identifier) -> return_t {
+ [callback](std::string_view identifier) -> bool {
bool successful = false;
const Date date = Date::from_string(identifier, &successful);
if (successful) {
return callback(date);
}
Logger::error("Invalid date identifier text: ", identifier);
- return FAILURE;
+ return false;
}
);
}
node_callback_t NodeTools::expect_assign(key_value_callback_t callback) {
return _expect_type<ast::AssignNode>(
- [callback](ast::AssignNode const& assign_node) -> return_t {
+ [callback](ast::AssignNode const& assign_node) -> bool {
return callback(assign_node._name, assign_node._initializer.get());
}
);
@@ -161,18 +160,18 @@ node_callback_t NodeTools::expect_assign(key_value_callback_t callback) {
node_callback_t NodeTools::expect_list_and_length(length_callback_t length_callback, node_callback_t callback) {
return _expect_type<ast::AbstractListNode>(
- [length_callback, callback](ast::AbstractListNode const& list_node) -> return_t {
+ [length_callback, callback](ast::AbstractListNode const& list_node) -> bool {
std::vector<ast::NodeUPtr> const& list = list_node._statements;
- return_t ret = SUCCESS;
+ bool ret = true;
size_t size = length_callback(list.size());
if (size > list.size()) {
Logger::error("Trying to read more values than the list contains: ", size, " > ", list.size());
size = list.size();
- ret = FAILURE;
+ ret = false;
}
std::for_each(list.begin(), list.begin() + size,
[callback, &ret](ast::NodeUPtr const& sub_node) -> void {
- if (callback(sub_node.get()) != SUCCESS) ret = FAILURE;
+ ret &= callback(sub_node.get());
}
);
return ret;
@@ -181,19 +180,19 @@ node_callback_t NodeTools::expect_list_and_length(length_callback_t length_callb
}
node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t callback) {
- return [length, callback](ast::NodeCPtr node) -> return_t {
- return_t ret = SUCCESS;
- if (expect_list_and_length(
+ return [length, callback](ast::NodeCPtr node) -> bool {
+ bool ret = true;
+ ret &= expect_list_and_length(
[length, &ret](size_t size) -> size_t {
if (size != length) {
Logger::error("List length ", size, " does not match expected length ", length);
- ret = FAILURE;
+ ret = false;
if (length < size) return length;
}
return size;
},
callback
- )(node) != SUCCESS) ret = FAILURE;
+ )(node);
return ret;
};
}
@@ -211,20 +210,20 @@ node_callback_t NodeTools::expect_dictionary(key_value_callback_t callback) {
}
node_callback_t NodeTools::_expect_dictionary_keys_and_length(length_callback_t length_callback, bool allow_other_keys, key_map_t&& key_map) {
- return [length_callback, allow_other_keys, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> return_t {
- return_t ret = expect_dictionary_and_length(
+ return [length_callback, allow_other_keys, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool {
+ bool ret = expect_dictionary_and_length(
length_callback,
- [&key_map, allow_other_keys](std::string_view key, ast::NodeCPtr value) -> return_t {
+ [&key_map, allow_other_keys](std::string_view key, ast::NodeCPtr value) -> bool {
const key_map_t::iterator it = key_map.find(key);
if (it == key_map.end()) {
- if (allow_other_keys) return SUCCESS;
+ if (allow_other_keys) return true;
Logger::error("Invalid dictionary key: ", key);
- return FAILURE;
+ return false;
}
dictionary_entry_t& entry = it->second;
if (++entry.count > 1 && !entry.can_repeat()) {
Logger::error("Invalid repeat of dictionary key: ", key);
- return FAILURE;
+ return false;
}
return entry.callback(value);
}
@@ -233,7 +232,7 @@ node_callback_t NodeTools::_expect_dictionary_keys_and_length(length_callback_t
dictionary_entry_t const& entry = key_entry.second;
if (entry.must_appear() && entry.count < 1) {
Logger::error("Mandatory dictionary key not present: ", key_entry.first);
- ret = FAILURE;
+ ret = false;
}
}
return ret;
@@ -244,13 +243,13 @@ node_callback_t NodeTools::name_list_callback(std::vector<std::string>& list) {
return expect_list_reserve_length(
list,
expect_identifier_or_string(
- [&list](std::string_view str) -> return_t {
+ [&list](std::string_view str) -> bool {
if (!str.empty()) {
list.push_back(std::string { str });
- return SUCCESS;
+ return true;
}
Logger::error("Empty identifier or string");
- return FAILURE;
+ return false;
}
)
);
diff --git a/src/openvic/dataloader/NodeTools.hpp b/src/openvic/dataloader/NodeTools.hpp
index 6dbaa1c..daea8ce 100644
--- a/src/openvic/dataloader/NodeTools.hpp
+++ b/src/openvic/dataloader/NodeTools.hpp
@@ -4,7 +4,6 @@
#include "openvic/types/Colour.hpp"
#include "openvic/types/Date.hpp"
-#include "openvic/types/Return.hpp"
#include "openvic/types/fixed_point/FP.hpp"
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
@@ -14,20 +13,20 @@ namespace OpenVic {
namespace NodeTools {
- using node_callback_t = std::function<return_t(ast::NodeCPtr)>;
- constexpr return_t success_callback(ast::NodeCPtr) { return SUCCESS; }
+ using node_callback_t = std::function<bool(ast::NodeCPtr)>;
+ constexpr bool success_callback(ast::NodeCPtr) { return true; }
- using key_value_callback_t = std::function<return_t(std::string_view, ast::NodeCPtr)>;
+ using key_value_callback_t = std::function<bool(std::string_view, ast::NodeCPtr)>;
- node_callback_t expect_identifier(std::function<return_t(std::string_view)> callback);
- node_callback_t expect_string(std::function<return_t(std::string_view)> callback);
- node_callback_t expect_identifier_or_string(std::function<return_t(std::string_view)> callback);
- node_callback_t expect_bool(std::function<return_t(bool)> callback);
- node_callback_t expect_int(std::function<return_t(int64_t)> callback);
- node_callback_t expect_uint(std::function<return_t(uint64_t)> callback);
- node_callback_t expect_fixed_point(std::function<return_t(FP)> callback);
- node_callback_t expect_colour(std::function<return_t(colour_t)> callback);
- node_callback_t expect_date(std::function<return_t(Date)> callback);
+ node_callback_t expect_identifier(std::function<bool(std::string_view)> callback);
+ node_callback_t expect_string(std::function<bool(std::string_view)> callback);
+ node_callback_t expect_identifier_or_string(std::function<bool(std::string_view)> callback);
+ node_callback_t expect_bool(std::function<bool(bool)> callback);
+ node_callback_t expect_int(std::function<bool(int64_t)> callback);
+ node_callback_t expect_uint(std::function<bool(uint64_t)> callback);
+ node_callback_t expect_fixed_point(std::function<bool(FP)> callback);
+ node_callback_t expect_colour(std::function<bool(colour_t)> callback);
+ node_callback_t expect_date(std::function<bool(Date)> callback);
node_callback_t expect_assign(key_value_callback_t callback);
using length_callback_t = std::function<size_t(size_t)>;
@@ -124,38 +123,38 @@ namespace OpenVic {
node_callback_t name_list_callback(std::vector<std::string>& list);
template<typename T>
- std::function<return_t(T)> assign_variable_callback(T& var) {
- return [&var](T val) -> return_t {
+ std::function<bool(T)> assign_variable_callback(T& var) {
+ return [&var](T val) -> bool {
var = val;
- return SUCCESS;
+ return true;
};
}
template<typename T>
requires(std::integral<T>)
- std::function<return_t(uint64_t)> assign_variable_callback_uint(const std::string_view name, T& var) {
- return [&var, name](uint64_t val) -> return_t {
+ std::function<bool(uint64_t)> assign_variable_callback_uint(const std::string_view name, T& var) {
+ return [&var, name](uint64_t val) -> bool {
if (val <= std::numeric_limits<T>::max()) {
var = val;
- return SUCCESS;
+ return true;
}
Logger::error("Invalid ", name, ": ", val, " (valid range: [0, ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])");
- return FAILURE;
+ return false;
};
}
template<typename T>
requires(std::integral<T>)
- std::function<return_t(int64_t)> assign_variable_callback_int(const std::string_view name, T& var) {
- return [&var, name](int64_t val) -> return_t {
+ std::function<bool(int64_t)> assign_variable_callback_int(const std::string_view name, T& var) {
+ return [&var, name](int64_t val) -> bool {
if (std::numeric_limits<T>::lowest() <= val && val <= std::numeric_limits<T>::max()) {
var = val;
- return SUCCESS;
+ return true;
}
Logger::error("Invalid ", name, ": ", val, " (valid range: [",
static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ",
static_cast<uint64_t>(std::numeric_limits<T>::max()), "])");
- return FAILURE;
+ return false;
};
}
}
diff --git a/src/openvic/economy/Good.cpp b/src/openvic/economy/Good.cpp
index 074bd5a..8ecaae0 100644
--- a/src/openvic/economy/Good.cpp
+++ b/src/openvic/economy/Good.cpp
@@ -58,10 +58,10 @@ void Good::reset_to_defaults() {
GoodManager::GoodManager() : good_categories { "good categories" }, goods { "goods" } {}
-return_t GoodManager::add_good_category(const std::string_view identifier) {
+bool GoodManager::add_good_category(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid good category identifier - empty!");
- return FAILURE;
+ return false;
}
return good_categories.add_item({ identifier });
}
@@ -82,23 +82,23 @@ std::vector<GoodCategory> const& GoodManager::get_good_categories() const {
return good_categories.get_items();
}
-return_t GoodManager::add_good(const std::string_view identifier, colour_t colour, GoodCategory const* category,
+bool GoodManager::add_good(const std::string_view identifier, colour_t colour, GoodCategory const* category,
Good::price_t base_price, bool available_from_start, bool tradeable, bool money, bool overseas_penalty) {
if (identifier.empty()) {
Logger::error("Invalid good identifier - empty!");
- return FAILURE;
+ return false;
}
if (colour > MAX_COLOUR_RGB) {
Logger::error("Invalid good colour for ", identifier, ": ", colour_to_hex_string(colour));
- return FAILURE;
+ return false;
}
if (category == nullptr) {
Logger::error("Invalid good category for ", identifier, ": null");
- return FAILURE;
+ return false;
}
if (base_price <= Good::NULL_PRICE) {
Logger::error("Invalid base price for ", identifier, ": ", base_price);
- return FAILURE;
+ return false;
}
return goods.add_item({ identifier, colour, *category, base_price, available_from_start, tradeable, money, overseas_penalty });
}
@@ -128,36 +128,36 @@ void GoodManager::reset_to_defaults() {
good.reset_to_defaults();
}
-return_t GoodManager::load_good_file(ast::NodeCPtr root) {
+bool GoodManager::load_good_file(ast::NodeCPtr root) {
size_t total_expected_goods = 0;
- return_t ret = expect_dictionary_reserve_length(
+ bool ret = expect_dictionary_reserve_length(
good_categories,
- [this, &total_expected_goods](std::string_view key, ast::NodeCPtr value) -> return_t {
- return_t ret = expect_list_and_length(
+ [this, &total_expected_goods](std::string_view key, ast::NodeCPtr value) -> bool {
+ bool ret = expect_list_and_length(
[&total_expected_goods](size_t size) -> size_t {
total_expected_goods += size;
return 0;
},
success_callback
)(value);
- if (add_good_category(key) != SUCCESS) ret = FAILURE;
+ ret &= add_good_category(key);
return ret;
}
)(root);
lock_good_categories();
goods.reserve(goods.size() + total_expected_goods);
- if (expect_dictionary(
- [this](std::string_view good_category_key, ast::NodeCPtr good_category_value) -> return_t {
+ ret &= expect_dictionary(
+ [this](std::string_view good_category_key, ast::NodeCPtr good_category_value) -> bool {
GoodCategory const* good_category = get_good_category_by_identifier(good_category_key);
return expect_dictionary(
- [this, good_category](std::string_view key, ast::NodeCPtr value) -> return_t {
+ [this, good_category](std::string_view key, ast::NodeCPtr value) -> bool {
colour_t colour = NULL_COLOUR;
Good::price_t base_price;
bool available_from_start, tradeable = true;
bool money, overseas_penalty = false;
- return_t ret = expect_dictionary_keys(
+ bool ret = expect_dictionary_keys(
"color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
"cost", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(base_price)),
"available_from_start", ZERO_OR_ONE, expect_bool(assign_variable_callback(available_from_start)),
@@ -165,14 +165,12 @@ return_t GoodManager::load_good_file(ast::NodeCPtr root) {
"money", ZERO_OR_ONE, expect_bool(assign_variable_callback(money)),
"overseas_penalty", ZERO_OR_ONE, expect_bool(assign_variable_callback(overseas_penalty))
)(value);
- if (add_good(key, colour, good_category, base_price, available_from_start, tradeable, money, overseas_penalty) != SUCCESS)
- ret = FAILURE;
+ ret &= add_good(key, colour, good_category, base_price, available_from_start, tradeable, money, overseas_penalty);
return ret;
}
)(good_category_value);
}
- )(root) != SUCCESS)
- ret = FAILURE;
+ )(root);
lock_goods();
return ret;
}
diff --git a/src/openvic/economy/Good.hpp b/src/openvic/economy/Good.hpp
index 7a41419..f04c9b2 100644
--- a/src/openvic/economy/Good.hpp
+++ b/src/openvic/economy/Good.hpp
@@ -66,13 +66,13 @@ namespace OpenVic {
public:
GoodManager();
- return_t add_good_category(const std::string_view identifier);
+ bool add_good_category(const std::string_view identifier);
void lock_good_categories();
GoodCategory const* get_good_category_by_identifier(const std::string_view identifier) const;
size_t get_good_category_count() const;
std::vector<GoodCategory> const& get_good_categories() const;
- return_t add_good(const std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price,
+ bool add_good(const std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price,
bool available_from_start, bool tradeable, bool money, bool overseas_penalty);
void lock_goods();
Good const* get_good_by_index(size_t index) const;
@@ -81,6 +81,6 @@ namespace OpenVic {
std::vector<Good> const& get_goods() const;
void reset_to_defaults();
- return_t load_good_file(ast::NodeCPtr root);
+ bool load_good_file(ast::NodeCPtr root);
};
}
diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp
index 00e0135..72bccc1 100644
--- a/src/openvic/map/Building.cpp
+++ b/src/openvic/map/Building.cpp
@@ -39,13 +39,13 @@ float Building::get_expansion_progress() const {
return expansion_progress;
}
-return_t Building::expand() {
+bool Building::expand() {
if (expansion_state == ExpansionState::CanExpand) {
expansion_state = ExpansionState::Preparing;
expansion_progress = 0.0f;
- return SUCCESS;
+ return true;
}
- return FAILURE;
+ return false;
}
/* REQUIREMENTS:
@@ -94,18 +94,18 @@ Timespan BuildingType::get_build_time() const {
BuildingManager::BuildingManager() : building_types { "building types" } {}
-return_t BuildingManager::add_building_type(const std::string_view identifier, Building::level_t max_level, Timespan build_time) {
+bool BuildingManager::add_building_type(const std::string_view identifier, Building::level_t max_level, Timespan build_time) {
if (identifier.empty()) {
Logger::error("Invalid building type identifier - empty!");
- return FAILURE;
+ return false;
}
if (max_level < 0) {
Logger::error("Invalid building type max level for ", identifier, ": ", max_level);
- return FAILURE;
+ return false;
}
if (build_time < 0) {
Logger::error("Invalid building type build time for ", identifier, ": ", build_time);
- return FAILURE;
+ return false;
}
return building_types.add_item({ identifier, max_level, build_time });
}
@@ -118,18 +118,16 @@ BuildingType const* BuildingManager::get_building_type_by_identifier(const std::
return building_types.get_item_by_identifier(identifier);
}
-return_t BuildingManager::generate_province_buildings(Province& province) const {
+bool BuildingManager::generate_province_buildings(Province& province) const {
province.reset_buildings();
if (!building_types.is_locked()) {
Logger::error("Cannot generate buildings until building types are locked!");
- return FAILURE;
+ return false;
}
- return_t ret = SUCCESS;
+ bool ret = true;
if (!province.is_water()) {
for (BuildingType const& type : building_types.get_items()) {
- if (province.add_building({ type }) != SUCCESS) {
- ret = FAILURE;
- }
+ ret &= province.add_building({ type });
}
}
province.lock_buildings();
diff --git a/src/openvic/map/Building.hpp b/src/openvic/map/Building.hpp
index 2ff9409..d1c0348 100644
--- a/src/openvic/map/Building.hpp
+++ b/src/openvic/map/Building.hpp
@@ -48,7 +48,7 @@ namespace OpenVic {
Date const& get_end_date() const;
float get_expansion_progress() const;
- return_t expand();
+ bool expand();
void update_state(Date const& today);
void tick(Date const& today);
};
@@ -78,9 +78,9 @@ namespace OpenVic {
public:
BuildingManager();
- return_t add_building_type(const std::string_view identifier, Building::level_t max_level, Timespan build_time);
+ bool add_building_type(const std::string_view identifier, Building::level_t max_level, Timespan build_time);
void lock_building_types();
BuildingType const* get_building_type_by_identifier(const std::string_view identifier) const;
- return_t generate_province_buildings(Province& province) const;
+ bool generate_province_buildings(Province& province) const;
};
}
diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp
index 439338b..6375691 100644
--- a/src/openvic/map/Map.cpp
+++ b/src/openvic/map/Map.cpp
@@ -30,24 +30,24 @@ Map::Map() : provinces { "provinces" },
regions { "regions" },
mapmodes { "mapmodes" } {}
-return_t Map::add_province(const std::string_view identifier, colour_t colour) {
+bool Map::add_province(const std::string_view identifier, colour_t colour) {
if (provinces.size() >= max_provinces) {
Logger::error("The map's province list is full - maximum number of provinces is ", max_provinces, " (this can be at most ", Province::MAX_INDEX, ")");
- return FAILURE;
+ return false;
}
if (identifier.empty()) {
Logger::error("Invalid province identifier - empty!");
- return FAILURE;
+ return false;
}
if (colour == NULL_COLOUR || colour > MAX_COLOUR_RGB) {
Logger::error("Invalid province colour for ", identifier, ": ", colour_to_hex_string(colour));
- return FAILURE;
+ return false;
}
Province new_province { identifier, colour, static_cast<Province::index_t>(provinces.size() + 1) };
const Province::index_t index = get_index_from_colour(colour);
if (index != Province::NULL_INDEX) {
Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string());
- return FAILURE;
+ return false;
}
colour_index_map[new_province.get_colour()] = new_province.get_index();
return provinces.add_item(std::move(new_province));
@@ -57,35 +57,33 @@ void Map::lock_provinces() {
provinces.lock();
}
-return_t Map::set_water_province(const std::string_view identifier) {
+bool Map::set_water_province(const std::string_view identifier) {
if (water_provinces.is_locked()) {
Logger::error("The map's water provinces have already been locked!");
- return FAILURE;
+ return false;
}
Province* province = get_province_by_identifier(identifier);
if (province == nullptr) {
Logger::error("Unrecognised water province identifier: ", identifier);
- return FAILURE;
+ return false;
}
if (province->is_water()) {
Logger::error("Province ", identifier, " is already a water province!");
- return FAILURE;
+ return false;
}
- if (water_provinces.add_province(province) != SUCCESS) {
+ if (!water_provinces.add_province(province)) {
Logger::error("Failed to add province ", identifier, " to water province set!");
- return FAILURE;
+ return false;
}
province->water = true;
- return SUCCESS;
+ return true;
}
-return_t Map::set_water_province_list(std::vector<std::string_view> const& list) {
- return_t ret = SUCCESS;
+bool Map::set_water_province_list(std::vector<std::string_view> const& list) {
+ bool ret = true;
water_provinces.reserve(water_provinces.size() + list.size());
for (std::string_view const& identifier : list) {
- if (set_water_province(identifier) != SUCCESS) {
- ret = FAILURE;
- }
+ ret &= set_water_province(identifier);
}
return ret;
}
@@ -95,19 +93,19 @@ void Map::lock_water_provinces() {
Logger::info("Locked water provinces after registering ", water_provinces.size());
}
-return_t Map::add_region(const std::string_view identifier, std::vector<std::string_view> const& province_identifiers) {
+bool Map::add_region(const std::string_view identifier, std::vector<std::string_view> const& province_identifiers) {
if (identifier.empty()) {
Logger::error("Invalid region identifier - empty!");
- return FAILURE;
+ return false;
}
Region new_region { identifier };
- return_t ret = SUCCESS;
+ bool ret = true;
for (const std::string_view province_identifier : province_identifiers) {
Province* province = get_province_by_identifier(province_identifier);
if (province != nullptr) {
if (new_region.contains_province(province)) {
Logger::error("Duplicate province identifier ", province_identifier, " in region ", identifier);
- ret = FAILURE;
+ ret = false;
} else {
size_t other_region_index = reinterpret_cast<size_t>(province->get_region());
if (other_region_index != 0) {
@@ -116,21 +114,21 @@ return_t Map::add_region(const std::string_view identifier, std::vector<std::str
Logger::error("Cannot add province ", province_identifier, " to region ", identifier, " - it is already part of ", regions.get_item_by_index(other_region_index)->get_identifier());
else
Logger::error("Cannot add province ", province_identifier, " to region ", identifier, " - it is already part of an unknown region with index ", other_region_index);
- ret = FAILURE;
- } else if (new_region.add_province(province) != SUCCESS) {
+ ret = false;
+ } else if (!new_region.add_province(province)) {
Logger::error("Failed to add province ", province_identifier, " to region ", identifier);
- ret = FAILURE;
+ ret = false;
}
}
} else {
Logger::error("Invalid province identifier ", province_identifier, " for region ", identifier);
- ret = FAILURE;
+ ret = false;
}
}
new_region.lock();
- if (!new_region.size()) {
+ if (new_region.empty()) {
Logger::error("No valid provinces in list for ", identifier);
- return FAILURE;
+ return false;
}
// Used to detect provinces listed in multiple regions, will
@@ -138,7 +136,7 @@ return_t Map::add_region(const std::string_view identifier, std::vector<std::str
Region* tmp_region_index = reinterpret_cast<Region*>(regions.size());
for (Province* province : new_region.get_provinces())
province->region = tmp_region_index;
- if (regions.add_item(std::move(new_region)) != SUCCESS) ret = FAILURE;
+ ret &= regions.add_item(std::move(new_region));
return ret;
}
@@ -184,17 +182,17 @@ Province::index_t Map::get_province_index_at(size_t x, size_t y) const {
return Province::NULL_INDEX;
}
-return_t Map::set_max_provinces(Province::index_t new_max_provinces) {
+bool Map::set_max_provinces(Province::index_t new_max_provinces) {
if (new_max_provinces <= Province::NULL_INDEX) {
Logger::error("Trying to set max province count to an invalid value ", new_max_provinces, " (must be greater than ", Province::NULL_INDEX, ")");
- return FAILURE;
+ return false;
}
if (!provinces.empty() || provinces.is_locked()) {
Logger::error("Trying to set max province count to ", new_max_provinces, " after provinces have already been added and/or locked");
- return FAILURE;
+ return false;
}
max_provinces = new_max_provinces;
- return SUCCESS;
+ return true;
}
Province::index_t Map::get_max_provinces() const {
@@ -239,34 +237,34 @@ static colour_t colour_at(uint8_t const* colour_data, int32_t idx) {
return (colour_data[idx] << 16) | (colour_data[idx + 1] << 8) | colour_data[idx + 2];
}
-return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data,
+bool Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data,
uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map, bool detailed_errors) {
if (!province_shape_image.empty()) {
Logger::error("Province index image has already been generated!");
- return FAILURE;
+ return false;
}
if (!provinces.is_locked()) {
Logger::error("Province index image cannot be generated until after provinces are locked!");
- return FAILURE;
+ return false;
}
if (new_width < 1 || new_height < 1) {
Logger::error("Invalid province image dimensions: ", new_width, "x", new_height);
- return FAILURE;
+ return false;
}
if (colour_data == nullptr) {
Logger::error("Province colour data pointer is null!");
- return FAILURE;
+ return false;
}
if (terrain_data == nullptr) {
Logger::error("Province terrain data pointer is null!");
- return FAILURE;
+ return false;
}
width = new_width;
height = new_height;
province_shape_image.resize(width * height);
std::vector<bool> province_checklist(provinces.size());
- return_t ret = SUCCESS;
+ bool ret = true;
std::unordered_set<colour_t> unrecognised_province_colours, unrecognised_terrain_colours;
for (int32_t y = 0; y < height; ++y) {
@@ -320,11 +318,11 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height,
}
if (!unrecognised_province_colours.empty()) {
Logger::error("Province image contains ", unrecognised_province_colours.size(), " unrecognised province colours");
- ret = FAILURE;
+ ret = false;
}
if (!unrecognised_terrain_colours.empty()) {
Logger::error("Terrain image contains ", unrecognised_terrain_colours.size(), " unrecognised terrain colours");
- ret = FAILURE;
+ ret = false;
}
size_t missing = 0;
@@ -338,7 +336,7 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height,
}
if (missing > 0) {
Logger::error("Province image is missing ", missing, " province colours");
- ret = FAILURE;
+ ret = false;
}
return ret;
}
@@ -355,14 +353,14 @@ std::vector<Map::shape_pixel_t> const& Map::get_province_shape_image() const {
return province_shape_image;
}
-return_t Map::add_mapmode(const std::string_view identifier, Mapmode::colour_func_t colour_func) {
+bool Map::add_mapmode(const std::string_view identifier, Mapmode::colour_func_t colour_func) {
if (identifier.empty()) {
Logger::error("Invalid mapmode identifier - empty!");
- return FAILURE;
+ return false;
}
if (colour_func == nullptr) {
Logger::error("Mapmode colour function is null for identifier: ", identifier);
- return FAILURE;
+ return false;
}
return mapmodes.add_item({ identifier, mapmodes.size(), colour_func });
}
@@ -387,20 +385,20 @@ Mapmode const* Map::get_mapmode_by_identifier(const std::string_view identifier)
return mapmodes.get_item_by_identifier(identifier);
}
-return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const {
+bool Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const {
if (target == nullptr) {
Logger::error("Mapmode colour target pointer is null!");
- return FAILURE;
+ return false;
}
- return_t ret = SUCCESS;
+ bool ret = true;
Mapmode const* mapmode = mapmodes.get_item_by_index(index);
if (mapmode == nullptr) {
// Not an error if mapmodes haven't yet been loaded,
// e.g. if we want to allocate the province colour
// texture before mapmodes are loaded.
- if (!(mapmodes.size() == 0 && index == 0)) {
+ if (!(mapmodes.empty() && index == 0)) {
Logger::error("Invalid mapmode index: ", index);
- ret = FAILURE;
+ ret = false;
}
mapmode = &Mapmode::ERROR_MAPMODE;
}
@@ -439,14 +437,14 @@ Pop::pop_size_t Map::get_total_map_population() const {
return total_map_population;
}
-return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager) {
- return_t ret = SUCCESS;
+bool Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager) {
+ bool ret = true;
for (Province& province : provinces.get_items()) {
province.clear_pops();
// Set all land provinces to have an RGO based on their index to test them
if (!province.is_water() && good_manager.get_good_count() > 0)
province.rgo = good_manager.get_good_by_index(province.get_index() % good_manager.get_good_count());
- if (building_manager.generate_province_buildings(province) != SUCCESS) ret = FAILURE;
+ ret &= building_manager.generate_province_buildings(province);
}
return ret;
}
@@ -465,18 +463,18 @@ void Map::tick(Date const& today) {
using namespace ovdl::csv;
-static return_t validate_province_definitions_header(LineObject const& header) {
+static bool validate_province_definitions_header(LineObject const& header) {
static const std::vector<std::string> standard_header { "province", "red", "green", "blue" };
for (size_t i = 0; i < standard_header.size(); ++i) {
const std::string_view val = header.get_value_for(i);
if (i == 0 && val.empty()) break;
- if (val != standard_header[i]) return FAILURE;
+ if (val != standard_header[i]) return false;
}
- return SUCCESS;
+ return true;
}
-static return_t parse_province_colour(colour_t& colour, std::array<std::string_view, 3> components) {
- return_t ret = SUCCESS;
+static bool parse_province_colour(colour_t& colour, std::array<std::string_view, 3> components) {
+ bool ret = true;
colour = NULL_COLOUR;
for (std::string_view& c : components) {
colour <<= 8;
@@ -486,43 +484,43 @@ static return_t parse_province_colour(colour_t& colour, std::array<std::string_v
if (successful && val <= 255) {
colour |= val;
} else {
- ret = FAILURE;
+ ret = false;
}
}
return ret;
}
-return_t Map::load_province_definitions(std::vector<LineObject> const& lines) {
+bool Map::load_province_definitions(std::vector<LineObject> const& lines) {
if (lines.empty()) {
Logger::error("No header or entries in province definition file!");
- return FAILURE;
+ return false;
}
{
LineObject const& header = lines.front();
- if (validate_province_definitions_header(header) != SUCCESS) {
+ if (!validate_province_definitions_header(header)) {
Logger::error("Non-standard province definition file header - make sure this is not a province definition: ", header);
}
}
if (lines.size() <= 1) {
Logger::error("No entries in province definition file!");
- return FAILURE;
+ return false;
}
provinces.reserve(lines.size() - 1);
- return_t ret = SUCCESS;
+ bool ret = true;
std::for_each(lines.begin() + 1, lines.end(),
[this, &ret](LineObject const& line) -> void {
const std::string_view identifier = line.get_value_for(0);
if (!identifier.empty()) {
colour_t colour;
- if (parse_province_colour(colour, {
+ if (!parse_province_colour(colour, {
line.get_value_for(1),
line.get_value_for(2),
line.get_value_for(3)
- }) != SUCCESS) {
+ })) {
Logger::error("Error reading colour in province definition: ", line);
- ret = FAILURE;
+ ret = false;
}
- if (add_province(identifier, colour) != SUCCESS) ret = FAILURE;
+ ret &= add_province(identifier, colour);
}
}
);
diff --git a/src/openvic/map/Map.hpp b/src/openvic/map/Map.hpp
index 0a2c7c6..4684226 100644
--- a/src/openvic/map/Map.hpp
+++ b/src/openvic/map/Map.hpp
@@ -65,12 +65,12 @@ namespace OpenVic {
public:
Map();
- return_t add_province(const std::string_view identifier, colour_t colour);
+ bool add_province(const std::string_view identifier, colour_t colour);
void lock_provinces();
- return_t set_water_province(const std::string_view identifier);
- return_t set_water_province_list(std::vector<std::string_view> const& list);
+ bool set_water_province(const std::string_view identifier);
+ bool set_water_province_list(std::vector<std::string_view> const& list);
void lock_water_provinces();
- return_t add_region(const std::string_view identifier, std::vector<std::string_view> const& province_identifiers);
+ bool add_region(const std::string_view identifier, std::vector<std::string_view> const& province_identifiers);
void lock_regions();
size_t get_province_count() const;
@@ -80,7 +80,7 @@ namespace OpenVic {
Province* get_province_by_identifier(const std::string_view identifier);
Province const* get_province_by_identifier(const std::string_view identifier) const;
Province::index_t get_province_index_at(size_t x, size_t y) const;
- return_t set_max_provinces(Province::index_t new_max_provinces);
+ bool set_max_provinces(Province::index_t new_max_provinces);
Province::index_t get_max_provinces() const;
void set_selected_province(Province::index_t index);
Province::index_t get_selected_province_index() const;
@@ -91,22 +91,22 @@ namespace OpenVic {
size_t get_region_count() const;
std::vector<Region> const& get_regions() const;
- return_t generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data,
+ bool generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data,
uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map, bool detailed_errors);
size_t get_width() const;
size_t get_height() const;
std::vector<shape_pixel_t> const& get_province_shape_image() const;
- return_t add_mapmode(const std::string_view identifier, Mapmode::colour_func_t colour_func);
+ bool add_mapmode(const std::string_view identifier, Mapmode::colour_func_t colour_func);
void lock_mapmodes();
size_t get_mapmode_count() const;
std::vector<Mapmode> const& get_mapmodes() const;
Mapmode const* get_mapmode_by_index(Mapmode::index_t index) const;
Mapmode const* get_mapmode_by_identifier(const std::string_view identifier) const;
static constexpr size_t MAPMODE_COLOUR_SIZE = 4;
- return_t generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
+ bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
- return_t setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager);
+ bool setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager);
void update_highest_province_population();
Pop::pop_size_t get_highest_province_population() const;
@@ -116,6 +116,6 @@ namespace OpenVic {
void update_state(Date const& today);
void tick(Date const& today);
- return_t load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines);
+ bool load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines);
};
}
diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp
index 7d03604..cfdc263 100644
--- a/src/openvic/map/Province.cpp
+++ b/src/openvic/map/Province.cpp
@@ -30,7 +30,7 @@ Province::life_rating_t Province::get_life_rating() const {
return life_rating;
}
-return_t Province::add_building(Building&& building) {
+bool Province::add_building(Building&& building) {
return buildings.add_item(std::move(building));
}
@@ -54,9 +54,9 @@ std::vector<Building> const& Province::get_buildings() const {
return buildings.get_items();
}
-return_t Province::expand_building(const std::string_view building_type_identifier) {
+bool Province::expand_building(const std::string_view building_type_identifier) {
Building* building = buildings.get_item_by_identifier(building_type_identifier);
- if (building == nullptr) return FAILURE;
+ if (building == nullptr) return false;
return building->expand();
}
@@ -70,22 +70,22 @@ std::string Province::to_string() const {
return stream.str();
}
-return_t Province::load_pop_list(PopManager const& pop_manager, ast::NodeCPtr root) {
+bool Province::load_pop_list(PopManager const& pop_manager, ast::NodeCPtr root) {
return expect_list_reserve_length(
pops,
- [this, &pop_manager](ast::NodeCPtr pop_node) -> return_t {
+ [this, &pop_manager](ast::NodeCPtr pop_node) -> bool {
return pop_manager.load_pop_into_province(*this, pop_node);
}
)(root);
}
-return_t Province::add_pop(Pop&& pop) {
+bool Province::add_pop(Pop&& pop) {
if (!is_water()) {
pops.push_back(std::move(pop));
- return SUCCESS;
+ return true;
} else {
Logger::error("Trying to add pop to water province ", get_identifier());
- return FAILURE;
+ return false;
}
}
diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp
index 364bbf8..f64bca2 100644
--- a/src/openvic/map/Province.hpp
+++ b/src/openvic/map/Province.hpp
@@ -41,18 +41,18 @@ namespace OpenVic {
Region* get_region() const;
bool is_water() const;
life_rating_t get_life_rating() const;
- return_t add_building(Building&& building);
+ bool add_building(Building&& building);
void lock_buildings();
void reset_buildings();
Building const* get_building_by_identifier(const std::string_view identifier) const;
size_t get_building_count() const;
std::vector<Building> const& get_buildings() const;
- return_t expand_building(const std::string_view building_type_identifier);
+ bool expand_building(const std::string_view building_type_identifier);
Good const* get_rgo() const;
std::string to_string() const;
- return_t load_pop_list(PopManager const& pop_manager, ast::NodeCPtr root);
- return_t add_pop(Pop&& pop);
+ bool load_pop_list(PopManager const& pop_manager, ast::NodeCPtr root);
+ bool add_pop(Pop&& pop);
void clear_pops();
size_t get_pop_count() const;
std::vector<Pop> const& get_pops() const;
diff --git a/src/openvic/map/Region.cpp b/src/openvic/map/Region.cpp
index 6372e15..33092c5 100644
--- a/src/openvic/map/Region.cpp
+++ b/src/openvic/map/Region.cpp
@@ -2,21 +2,21 @@
using namespace OpenVic;
-return_t ProvinceSet::add_province(Province* province) {
+bool ProvinceSet::add_province(Province* province) {
if (locked) {
Logger::error("Cannot add province to province set - locked!");
- return FAILURE;
+ return false;
}
if (province == nullptr) {
Logger::error("Cannot add province to province set - null province!");
- return FAILURE;
+ return false;
}
if (contains_province(province)) {
Logger::error("Cannot add province ", province->get_identifier(), " to province set - already in the set!");
- return FAILURE;
+ return false;
}
provinces.push_back(province);
- return SUCCESS;
+ return true;
}
void ProvinceSet::lock(bool log) {
@@ -37,6 +37,10 @@ void ProvinceSet::reset() {
locked = false;
}
+bool ProvinceSet::empty() const {
+ return provinces.empty();
+}
+
size_t ProvinceSet::size() const {
return provinces.size();
}
diff --git a/src/openvic/map/Region.hpp b/src/openvic/map/Region.hpp
index e67edaa..a3640ca 100644
--- a/src/openvic/map/Region.hpp
+++ b/src/openvic/map/Region.hpp
@@ -10,10 +10,11 @@ namespace OpenVic {
bool locked = false;
public:
- return_t add_province(Province* province);
+ bool add_province(Province* province);
void lock(bool log = false);
bool is_locked() const;
void reset();
+ bool empty() const;
size_t size() const;
void reserve(size_t size);
bool contains_province(Province const* province) const;
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);
};
}
diff --git a/src/openvic/types/IdentifierRegistry.hpp b/src/openvic/types/IdentifierRegistry.hpp
index 54b466e..502b74b 100644
--- a/src/openvic/types/IdentifierRegistry.hpp
+++ b/src/openvic/types/IdentifierRegistry.hpp
@@ -4,7 +4,6 @@
#include <vector>
#include "openvic/types/Colour.hpp"
-#include "openvic/types/Return.hpp"
#include "openvic/utility/Logger.hpp"
namespace OpenVic {
@@ -84,19 +83,19 @@ namespace OpenVic {
public:
IdentifierRegistry(const std::string_view new_name) : name { new_name } {}
- return_t add_item(T&& item) {
+ bool add_item(T&& item) {
if (locked) {
Logger::error("Cannot add item to the ", name, " registry - locked!");
- return FAILURE;
+ return false;
}
T const* old_item = get_item_by_identifier(item.get_identifier());
if (old_item != nullptr) {
Logger::error("Cannot add item to the ", name, " registry - an item with the identifier \"", item.get_identifier(), "\" already exists!");
- return FAILURE;
+ return false;
}
identifier_index_map[item.get_identifier()] = items.size();
items.push_back(std::move(item));
- return SUCCESS;
+ return true;
}
void lock(bool log = true) {
if (locked) {
diff --git a/src/openvic/types/Return.hpp b/src/openvic/types/Return.hpp
deleted file mode 100644
index 04c3734..0000000
--- a/src/openvic/types/Return.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-
-namespace OpenVic {
- using return_t = bool;
-
- // This mirrors godot::Error, where `OK = 0` and `FAILED = 1`.
- constexpr return_t SUCCESS = false, FAILURE = true;
-}
diff --git a/src/openvic/utility/BMP.cpp b/src/openvic/utility/BMP.cpp
index 6859411..0ea0f30 100644
--- a/src/openvic/utility/BMP.cpp
+++ b/src/openvic/utility/BMP.cpp
@@ -11,57 +11,58 @@ BMP::~BMP() {
close();
}
-return_t BMP::open(char const* filepath) {
+bool BMP::open(char const* filepath) {
reset();
errno = 0;
file = fopen(filepath, "rb");
if (file == nullptr || errno != 0) {
Logger::error("Failed to open BMP file \"", filepath, "\" (errno = ", errno, ")");
file = nullptr;
- return FAILURE;
+ return false;
}
- return SUCCESS;
+ return true;
}
-return_t BMP::read_header() {
+bool BMP::read_header() {
if (header_validated) {
Logger::error("BMP header already validated!");
- return FAILURE;
+ return false;
}
if (file == nullptr) {
Logger::error("Cannot read BMP header before opening a file");
- return FAILURE;
+ return false;
}
if (fseek(file, 0, SEEK_SET) != 0) {
Logger::error("Failed to move to the beginning of the BMP file!");
- return FAILURE;
+ return false;
}
if (fread(&header, sizeof(header), 1, file) != 1) {
Logger::error("Failed to read BMP header!");
- return FAILURE;
+ return false;
}
- return_t ret = SUCCESS;
+
+ header_validated = true;
// Validate constants
static constexpr uint16_t BMP_SIGNATURE = 0x4d42;
if (header.signature != BMP_SIGNATURE) {
Logger::error("Invalid BMP signature: ", header.signature, " (must be ", BMP_SIGNATURE, ")");
- ret = FAILURE;
+ header_validated = false;
}
static constexpr uint32_t DIB_HEADER_SIZE = 40;
if (header.dib_header_size != DIB_HEADER_SIZE) {
Logger::error("Invalid BMP DIB header size: ", header.dib_header_size, " (must be ", DIB_HEADER_SIZE, ")");
- ret = FAILURE;
+ header_validated = false;
}
static constexpr uint16_t NUM_PLANES = 1;
if (header.num_planes != NUM_PLANES) {
Logger::error("Invalid BMP plane count: ", header.num_planes, " (must be ", NUM_PLANES, ")");
- ret = FAILURE;
+ header_validated = false;
}
static constexpr uint16_t COMPRESSION = 0; // Only support uncompressed BMPs
if (header.compression != COMPRESSION) {
Logger::error("Invalid BMP compression method: ", header.compression, " (must be ", COMPRESSION, ")");
- ret = FAILURE;
+ header_validated = false;
}
// Validate sizes and dimensions
@@ -69,17 +70,17 @@ return_t BMP::read_header() {
if (header.file_size != header.offset + header.image_size_bytes) {
Logger::error("Invalid BMP memory sizes: file size = ", header.file_size, " != ", header.offset + header.image_size_bytes,
" = ", header.offset, " + ", header.image_size_bytes, " = image data offset + image data size");
- ret = FAILURE;
+ header_validated = false;
}
// TODO - support negative widths (i.e. horizontal flip)
if (header.width_px <= 0) {
Logger::error("Invalid BMP width: ", header.width_px, " (must be positive)");
- ret = FAILURE;
+ header_validated = false;
}
// TODO - support negative heights (i.e. vertical flip)
if (header.height_px <= 0) {
Logger::error("Invalid BMP height: ", header.height_px, " (must be positive)");
- ret = FAILURE;
+ header_validated = false;
}
// TODO - validate x_resolution_ppm
// TODO - validate y_resolution_ppm
@@ -90,14 +91,14 @@ return_t BMP::read_header() {
static const std::set<uint16_t> BITS_PER_PIXEL { VALID_BITS_PER_PIXEL };
if (!BITS_PER_PIXEL.contains(header.bits_per_pixel)) {
Logger::error("Invalid BMP bits per pixel: ", header.bits_per_pixel, " (must be one of " STR(VALID_BITS_PER_PIXEL) ")");
- ret = FAILURE;
+ header_validated = false;
}
#undef VALID_BITS_PER_PIXEL
#undef STR
static constexpr uint16_t PALETTE_BITS_PER_PIXEL_LIMIT = 8;
if (header.num_colours != 0 && header.bits_per_pixel > PALETTE_BITS_PER_PIXEL_LIMIT) {
Logger::error("Invalid BMP palette size: ", header.num_colours, " (should be 0 as bits per pixel is ", header.bits_per_pixel, " > 8)");
- ret = FAILURE;
+ header_validated = false;
}
// TODO - validate important_colours
@@ -109,37 +110,36 @@ return_t BMP::read_header() {
const uint32_t expected_offset = palette_size * PALETTE_COLOUR_SIZE + sizeof(header);
if (header.offset != expected_offset) {
Logger::error("Invalid BMP image data offset: ", header.offset, " (should be ", expected_offset, ")");
- ret = FAILURE;
+ header_validated = false;
}
- header_validated = ret == SUCCESS;
- return ret;
+ return header_validated;
}
-return_t BMP::read_palette() {
+bool BMP::read_palette() {
if (file == nullptr) {
Logger::error("Cannot read BMP palette before opening a file");
- return FAILURE;
+ return false;
}
if (!header_validated) {
Logger::error("Cannot read palette before BMP header is validated!");
- return FAILURE;
+ return false;
}
if (palette_size == 0) {
Logger::error("Cannot read BMP palette - header indicates this file doesn't have one");
- return FAILURE;
+ return false;
}
if (fseek(file, sizeof(header), SEEK_SET) != 0) {
Logger::error("Failed to move to the palette in the BMP file!");
- return FAILURE;
+ return false;
}
palette.resize(palette_size);
if (fread(palette.data(), palette_size * PALETTE_COLOUR_SIZE, 1, file) != 1) {
Logger::error("Failed to read BMP header!");
palette.clear();
- return FAILURE;
+ return false;
}
- return SUCCESS;
+ return true;
}
void BMP::close() {
diff --git a/src/openvic/utility/BMP.hpp b/src/openvic/utility/BMP.hpp
index 50b333b..7ed36a5 100644
--- a/src/openvic/utility/BMP.hpp
+++ b/src/openvic/utility/BMP.hpp
@@ -4,7 +4,6 @@
#include <vector>
#include "openvic/types/Colour.hpp"
-#include "openvic/types/Return.hpp"
namespace OpenVic {
class BMP {
@@ -41,9 +40,9 @@ namespace OpenVic {
BMP() = default;
~BMP();
- return_t open(char const* filepath);
- return_t read_header();
- return_t read_palette();
+ bool open(char const* filepath);
+ bool read_header();
+ bool read_palette();
void close();
void reset();