aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic/Date.cpp78
-rw-r--r--src/openvic/Date.hpp2
-rw-r--r--src/openvic/GameManager.cpp2
-rw-r--r--src/openvic/GameManager.hpp2
-rw-r--r--src/openvic/Types.cpp5
-rw-r--r--src/openvic/Types.hpp12
-rw-r--r--src/openvic/economy/Good.cpp10
-rw-r--r--src/openvic/economy/Good.hpp5
-rw-r--r--src/openvic/map/Building.cpp16
-rw-r--r--src/openvic/map/Building.hpp6
-rw-r--r--src/openvic/map/Map.cpp87
-rw-r--r--src/openvic/map/Map.hpp25
-rw-r--r--src/openvic/map/Province.cpp6
-rw-r--r--src/openvic/map/Province.hpp6
-rw-r--r--src/openvic/map/Region.cpp37
-rw-r--r--src/openvic/map/Region.hpp7
-rw-r--r--src/openvic/pop/Culture.cpp26
-rw-r--r--src/openvic/pop/Culture.hpp18
-rw-r--r--src/openvic/pop/Pop.cpp41
-rw-r--r--src/openvic/pop/Pop.hpp6
-rw-r--r--src/openvic/pop/Religion.cpp20
-rw-r--r--src/openvic/pop/Religion.hpp12
22 files changed, 281 insertions, 148 deletions
diff --git a/src/openvic/Date.cpp b/src/openvic/Date.cpp
index 109b82d..7c37386 100644
--- a/src/openvic/Date.cpp
+++ b/src/openvic/Date.cpp
@@ -3,6 +3,7 @@
#include <algorithm>
#include <cassert>
#include <cctype>
+#include <charconv>
#include "utility/Logger.hpp"
@@ -156,29 +157,70 @@ std::ostream& OpenVic::operator<<(std::ostream& out, Date const& date) {
}
// Parsed from string of the form YYYY.MM.DD
-Date Date::from_string(std::string const& date) {
- year_t year = 0;
+Date Date::from_string(const std::string_view date) {
+ size_t first_pos = 0;
+ while (first_pos < date.length() && std::isdigit(date[first_pos])) {
+ first_pos++;
+ }
+
+ if (first_pos == 0) {
+ Logger::error("Failed to find year digits in date: ", date);
+ return {};
+ }
+
+ int val = 0;
+ char const* start = date.data();
+ char const* end = start + first_pos;
+ std::from_chars_result result = std::from_chars(start, end, val);
+ if (result.ec != std::errc{} || result.ptr != end || val < 0 || val >= 1 << (8 * sizeof(year_t))) {
+ Logger::error("Failed to read year: ", date);
+ return {};
+ }
+ year_t year = val;
month_t month = 1;
day_t day = 1;
-
- size_t first_pos = 0;
- while (first_pos < date.length() && std::isdigit(date[first_pos++]));
- year = stoi(date.substr(0, first_pos));
if (first_pos < date.length()) {
if (date[first_pos] == '.') {
- size_t second_pos = first_pos + 1;
- while (second_pos < date.length() && std::isdigit(date[second_pos++]));
- month = stoi(date.substr(first_pos, second_pos - first_pos));
- if (second_pos < date.length()) {
- if (date[second_pos] == '.') {
- size_t third_pos = second_pos + 1;
- while (third_pos < date.length() && std::isdigit(date[third_pos++]));
- day = stoi(date.substr(second_pos, third_pos - second_pos));
- if (third_pos < date.length())
- Logger::error("Unexpected string \"", date.substr(third_pos), "\" at the end of date ", date);
- } else Logger::error("Unexpected character \"", date[second_pos], "\" in date ", date);
+ size_t second_pos = ++first_pos;
+ while (second_pos < date.length() && std::isdigit(date[second_pos])) {
+ second_pos++;
+ }
+ if (first_pos == second_pos) {
+ Logger::error("Failed to find month digits in date: ", date);
+ } else {
+ start = date.data() + first_pos;
+ end = date.data() + second_pos;
+ result = std::from_chars(start, end, val);
+ if (result.ec != std::errc{} || result.ptr != end || val < 1 || val > MONTHS_IN_YEAR) {
+ Logger::error("Failed to read month: ", date);
+ } else {
+ month = val;
+ if (second_pos < date.length()) {
+ if (date[second_pos] == '.') {
+ size_t third_pos = ++second_pos;
+ while (third_pos < date.length() && std::isdigit(date[third_pos])) {
+ third_pos++;
+ }
+ if (second_pos == third_pos) {
+ Logger::error("Failed to find day digits in date: ", date);
+ } else {
+ start = date.data() + second_pos;
+ end = date.data() + third_pos;
+ result = std::from_chars(start, end, val);
+ if (result.ec != std::errc{} || result.ptr != end || val < 1 || val > DAYS_IN_MONTH[month - 1]) {
+ Logger::error("Failed to read day: ", date);
+ } else {
+ day = val;
+ if (third_pos < date.length()) {
+ Logger::error("Unexpected string \"", date.substr(third_pos), "\" at the end of date ", date);
+ }
+ }
+ }
+ } else Logger::error("Unexpected character \"", date[second_pos], "\" in month of date ", date);
+ }
+ }
}
- } else Logger::error("Unexpected character \"", date[first_pos], "\" in date ", date);
+ } else Logger::error("Unexpected character \"", date[first_pos], "\" in year of date ", date);
}
return _dateToTimespan(year, month, day);
};
diff --git a/src/openvic/Date.hpp b/src/openvic/Date.hpp
index f616e3b..2994523 100644
--- a/src/openvic/Date.hpp
+++ b/src/openvic/Date.hpp
@@ -84,7 +84,7 @@ namespace OpenVic {
explicit operator std::string() const;
// Parsed from string of the form YYYY.MM.DD
- static Date from_string(std::string const& date);
+ static Date from_string(const std::string_view date);
};
std::ostream& operator<<(std::ostream& out, Date const& date);
}
diff --git a/src/openvic/GameManager.cpp b/src/openvic/GameManager.cpp
index 9ab59a3..580dc4b 100644
--- a/src/openvic/GameManager.cpp
+++ b/src/openvic/GameManager.cpp
@@ -45,7 +45,7 @@ Date const& GameManager::get_today() const {
return today;
}
-return_t GameManager::expand_building(index_t province_index, std::string const& building_type_identifier) {
+return_t GameManager::expand_building(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;
diff --git a/src/openvic/GameManager.hpp b/src/openvic/GameManager.hpp
index 6a061e6..52de06e 100644
--- a/src/openvic/GameManager.hpp
+++ b/src/openvic/GameManager.hpp
@@ -30,6 +30,6 @@ namespace OpenVic {
return_t setup();
Date const& get_today() const;
- return_t expand_building(index_t province_index, std::string const& building_type_identifier);
+ return_t expand_building(index_t province_index, const std::string_view building_type_identifier);
};
}
diff --git a/src/openvic/Types.cpp b/src/openvic/Types.cpp
index c7ad3ae..4902ce3 100644
--- a/src/openvic/Types.cpp
+++ b/src/openvic/Types.cpp
@@ -6,7 +6,8 @@
using namespace OpenVic;
-HasIdentifier::HasIdentifier(std::string const& new_identifier) : identifier { new_identifier } {
+HasIdentifier::HasIdentifier(const std::string_view new_identifier)
+ : identifier { new_identifier } {
assert(!identifier.empty());
}
@@ -30,7 +31,7 @@ std::string HasColour::colour_to_hex_string() const {
return colour_to_hex_string(colour);
}
-HasIdentifierAndColour::HasIdentifierAndColour(std::string const& new_identifier,
+HasIdentifierAndColour::HasIdentifierAndColour(const std::string_view new_identifier,
const colour_t new_colour, bool can_be_null)
: HasIdentifier { new_identifier },
HasColour { new_colour, can_be_null } {}
diff --git a/src/openvic/Types.hpp b/src/openvic/Types.hpp
index d22f686..dab455f 100644
--- a/src/openvic/Types.hpp
+++ b/src/openvic/Types.hpp
@@ -50,7 +50,7 @@ namespace OpenVic {
const std::string identifier;
protected:
- HasIdentifier(std::string const& new_identifier);
+ HasIdentifier(const std::string_view new_identifier);
public:
HasIdentifier(HasIdentifier const&) = delete;
@@ -87,7 +87,7 @@ namespace OpenVic {
*/
class HasIdentifierAndColour : public HasIdentifier, public HasColour {
protected:
- HasIdentifierAndColour(std::string const& new_identifier, const colour_t new_colour, bool can_be_null);
+ HasIdentifierAndColour(const std::string_view new_identifier, const colour_t new_colour, bool can_be_null);
public:
HasIdentifierAndColour(HasIdentifierAndColour const&) = delete;
@@ -106,7 +106,7 @@ namespace OpenVic {
*/
template<class T, typename std::enable_if<std::is_base_of<HasIdentifier, T>::value>::type* = nullptr>
class IdentifierRegistry {
- using identifier_index_map_t = std::map<std::string, size_t>;
+ using identifier_index_map_t = std::map<std::string, size_t, std::less<void>>;
const std::string name;
std::vector<T> items;
@@ -114,7 +114,7 @@ namespace OpenVic {
identifier_index_map_t identifier_index_map;
public:
- IdentifierRegistry(std::string const& new_name) : name(new_name) {}
+ IdentifierRegistry(const std::string_view new_name) : name { new_name } {}
return_t add_item(T&& item) {
if (locked) {
Logger::error("Cannot add item to the ", name, " registry - locked!");
@@ -148,12 +148,12 @@ namespace OpenVic {
size_t get_item_count() const {
return items.size();
}
- T* get_item_by_identifier(std::string const& identifier) {
+ T* get_item_by_identifier(const std::string_view identifier) {
const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier);
if (it != identifier_index_map.end()) return &items[it->second];
return nullptr;
}
- T const* get_item_by_identifier(std::string const& identifier) const {
+ T const* get_item_by_identifier(const std::string_view identifier) const {
const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier);
if (it != identifier_index_map.end()) return &items[it->second];
return nullptr;
diff --git a/src/openvic/economy/Good.cpp b/src/openvic/economy/Good.cpp
index 27d6133..9e8a7dd 100644
--- a/src/openvic/economy/Good.cpp
+++ b/src/openvic/economy/Good.cpp
@@ -4,7 +4,7 @@
using namespace OpenVic;
-Good::Good(std::string const& new_identifier, std::string const& new_category, colour_t new_colour, price_t new_base_price,
+Good::Good(const std::string_view new_identifier, colour_t new_colour, const std::string_view new_category, price_t new_base_price,
bool new_default_available, bool new_tradeable, bool new_currency, bool new_overseas_maintenance)
: HasIdentifierAndColour { new_identifier, new_colour, true },
category { new_category },
@@ -43,7 +43,7 @@ void Good::reset_to_defaults() {
GoodManager::GoodManager() : goods { "goods" } {}
-return_t GoodManager::add_good(std::string const& identifier, std::string const& category, colour_t colour,
+return_t GoodManager::add_good(const std::string_view identifier, colour_t colour, const std::string_view category,
price_t base_price, bool default_available, bool tradeable, bool currency, bool overseas_maintenance) {
if (identifier.empty()) {
Logger::error("Invalid good identifier - empty!");
@@ -61,7 +61,7 @@ return_t GoodManager::add_good(std::string const& identifier, std::string const&
Logger::error("Invalid base price for ", identifier, ": ", base_price);
return FAILURE;
}
- return goods.add_item({ identifier, category, colour, base_price, default_available, tradeable, currency, overseas_maintenance });
+ return goods.add_item({ identifier, colour, category, base_price, default_available, tradeable, currency, overseas_maintenance });
}
void GoodManager::lock_goods() {
@@ -77,6 +77,10 @@ Good const* GoodManager::get_good_by_index(size_t index) const {
return goods.get_item_by_index(index);
}
+Good const* GoodManager::get_good_by_identifier(const std::string_view identifier) const {
+ return goods.get_item_by_identifier(identifier);
+}
+
size_t GoodManager::get_good_count() const {
return goods.get_item_count();
}
diff --git a/src/openvic/economy/Good.hpp b/src/openvic/economy/Good.hpp
index 833b17a..cfe185d 100644
--- a/src/openvic/economy/Good.hpp
+++ b/src/openvic/economy/Good.hpp
@@ -27,7 +27,7 @@ namespace OpenVic {
const bool default_available, tradeable, currency, overseas_maintenance;
bool available;
- Good(std::string const& new_identifier, std::string const& new_category, colour_t new_colour, price_t new_base_price,
+ Good(const std::string_view new_identifier, colour_t new_colour, const std::string_view new_category, price_t new_base_price,
bool new_default_available, bool new_tradeable, bool new_currency, bool new_overseas_maintenance);
public:
@@ -48,12 +48,13 @@ namespace OpenVic {
public:
GoodManager();
- return_t add_good(std::string const& identifier, std::string const& category, colour_t colour, price_t base_price,
+ return_t add_good(const std::string_view identifier, colour_t colour, const std::string_view category, price_t base_price,
bool default_available, bool tradeable, bool currency, bool overseas_maintenance);
void lock_goods();
void reset_to_defaults();
Good const* get_good_by_index(size_t index) const;
+ Good const* get_good_by_identifier(const std::string_view identifier) const;
size_t get_good_count() const;
std::vector<Good> const& get_goods() const;
};
diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp
index 81532c4..73a1886 100644
--- a/src/openvic/map/Building.cpp
+++ b/src/openvic/map/Building.cpp
@@ -76,7 +76,7 @@ void Building::tick(Date const& today) {
}
}
-BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time)
+BuildingType::BuildingType(const std::string_view new_identifier, Building::level_t new_max_level, Timespan new_build_time)
: HasIdentifier { new_identifier },
max_level { new_max_level },
build_time { new_build_time } {
@@ -94,7 +94,7 @@ Timespan BuildingType::get_build_time() const {
BuildingManager::BuildingManager() : building_types { "building types" } {}
-return_t BuildingManager::add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time) {
+return_t 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;
@@ -114,7 +114,7 @@ void BuildingManager::lock_building_types() {
building_types.lock();
}
-BuildingType const* BuildingManager::get_building_type_by_identifier(std::string const& identifier) const {
+BuildingType const* BuildingManager::get_building_type_by_identifier(const std::string_view identifier) const {
return building_types.get_item_by_identifier(identifier);
}
@@ -124,10 +124,14 @@ return_t BuildingManager::generate_province_buildings(Province& province) const
Logger::error("Cannot generate buildings until building types are locked!");
return FAILURE;
}
- if (province.is_water()) return SUCCESS;
return_t ret = SUCCESS;
- for (BuildingType const& type : building_types.get_items())
- if (province.add_building({ type }) != SUCCESS) ret = FAILURE;
+ if (!province.is_water()) {
+ for (BuildingType const& type : building_types.get_items()) {
+ if (province.add_building({ type }) != SUCCESS) {
+ ret = FAILURE;
+ }
+ }
+ }
province.lock_buildings();
return ret;
}
diff --git a/src/openvic/map/Building.hpp b/src/openvic/map/Building.hpp
index c4f8950..c00932b 100644
--- a/src/openvic/map/Building.hpp
+++ b/src/openvic/map/Building.hpp
@@ -60,7 +60,7 @@ namespace OpenVic {
const Building::level_t max_level;
const Timespan build_time;
- BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time);
+ BuildingType(const std::string_view new_identifier, Building::level_t new_max_level, Timespan new_build_time);
public:
BuildingType(BuildingType&&) = default;
@@ -78,9 +78,9 @@ namespace OpenVic {
public:
BuildingManager();
- return_t add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time);
+ return_t 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(std::string const& identifier) const;
+ BuildingType const* get_building_type_by_identifier(const std::string_view identifier) const;
return_t generate_province_buildings(Province& province) const;
};
}
diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp
index 21bb6a5..e8599b1 100644
--- a/src/openvic/map/Map.cpp
+++ b/src/openvic/map/Map.cpp
@@ -8,14 +8,15 @@
using namespace OpenVic;
-Mapmode::Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func)
+Mapmode::Mapmode(const std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func)
: HasIdentifier { new_identifier },
index { new_index },
colour_func { new_colour_func } {
assert(colour_func != nullptr);
}
-const Mapmode Mapmode::ERROR_MAPMODE { 0, "mapmode_error", [](Map const& map, Province const& province) -> colour_t { return 0xFFFF0000; } };
+const Mapmode Mapmode::ERROR_MAPMODE { "mapmode_error", 0,
+ [](Map const& map, Province const& province) -> colour_t { return 0xFFFF0000; } };
Mapmode::index_t Mapmode::get_index() const {
return index;
@@ -29,7 +30,7 @@ Map::Map() : provinces { "provinces" },
regions { "regions" },
mapmodes { "mapmodes" } {}
-return_t Map::add_province(std::string const& identifier, colour_t colour) {
+return_t Map::add_province(const std::string_view identifier, colour_t colour) {
if (provinces.get_item_count() >= MAX_INDEX) {
Logger::error("The map's province list is full - there can be at most ", MAX_INDEX, " provinces");
return FAILURE;
@@ -42,7 +43,7 @@ return_t Map::add_province(std::string const& identifier, colour_t colour) {
Logger::error("Invalid province colour for ", identifier, ": ", Province::colour_to_hex_string(colour));
return FAILURE;
}
- Province new_province { static_cast<index_t>(provinces.get_item_count() + 1), identifier, colour };
+ Province new_province { identifier, colour, static_cast<index_t>(provinces.get_item_count() + 1) };
const index_t index = get_index_from_colour(colour);
if (index != NULL_INDEX) {
Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string());
@@ -56,8 +57,8 @@ void Map::lock_provinces() {
provinces.lock();
}
-return_t Map::set_water_province(std::string const& identifier) {
- if (water_provinces_locked) {
+return_t 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;
}
@@ -70,24 +71,27 @@ return_t Map::set_water_province(std::string const& identifier) {
Logger::error("Province ", identifier, " is already a water province!");
return FAILURE;
}
+ if (water_provinces.add_province(province) != SUCCESS) {
+ Logger::error("Failed to add province ", identifier, " to water province set!");
+ return FAILURE;
+ }
province->water = true;
- water_province_count++;
return SUCCESS;
}
void Map::lock_water_provinces() {
- water_provinces_locked = true;
- Logger::info("Locked water provinces after registering ", water_province_count);
+ water_provinces.lock();
+ Logger::info("Locked water provinces after registering ", water_provinces.get_province_count());
}
-return_t Map::add_region(std::string const& identifier, std::vector<std::string> const& province_identifiers) {
+return_t 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;
}
Region new_region { identifier };
return_t ret = SUCCESS;
- for (std::string const& province_identifier : province_identifiers) {
+ 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)) {
@@ -102,13 +106,17 @@ return_t Map::add_region(std::string const& identifier, std::vector<std::string>
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 new_region.provinces.push_back(province);
+ } else if (new_region.add_province(province) != SUCCESS) {
+ Logger::error("Failed to add province ", province_identifier, " to region ", identifier);
+ ret = FAILURE;
+ }
}
} else {
Logger::error("Invalid province identifier ", province_identifier, " for region ", identifier);
ret = FAILURE;
}
}
+ new_region.lock();
if (!new_region.get_province_count()) {
Logger::error("No valid provinces in list for ", identifier);
return FAILURE;
@@ -142,11 +150,11 @@ Province const* Map::get_province_by_index(index_t index) const {
return index != NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr;
}
-Province* Map::get_province_by_identifier(std::string const& identifier) {
+Province* Map::get_province_by_identifier(const std::string_view identifier) {
return provinces.get_item_by_identifier(identifier);
}
-Province const* Map::get_province_by_identifier(std::string const& identifier) const {
+Province const* Map::get_province_by_identifier(const std::string_view identifier) const {
return provinces.get_item_by_identifier(identifier);
}
@@ -162,7 +170,12 @@ index_t Map::get_province_index_at(size_t x, size_t y) const {
}
void Map::set_selected_province(index_t index) {
- selected_province = index <= get_province_count() ? index : NULL_INDEX;
+ if (index < get_province_count()) {
+ Logger::error("Trying to set selected province to an invalid index ", index, " (max index is ", get_province_count(), ")");
+ selected_province = NULL_INDEX;
+ } else {
+ selected_province = index;
+ }
}
index_t Map::get_selected_province_index() const {
@@ -173,11 +186,12 @@ Province const* Map::get_selected_province() const {
return get_province_by_index(get_selected_province_index());
}
-Region* Map::get_region_by_identifier(std::string const& identifier) {
+
+Region* Map::get_region_by_identifier(const std::string_view identifier) {
return regions.get_item_by_identifier(identifier);
}
-Region const* Map::get_region_by_identifier(std::string const& identifier) const {
+Region const* Map::get_region_by_identifier(const std::string_view identifier) const {
return regions.get_item_by_identifier(identifier);
}
@@ -187,7 +201,7 @@ static colour_t colour_at(uint8_t const* colour_data, int32_t idx) {
}
return_t 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) {
+ 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;
@@ -226,8 +240,10 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height,
else {
if (unrecognised_terrain_colours.find(terrain_colour) == unrecognised_terrain_colours.end()) {
unrecognised_terrain_colours.insert(terrain_colour);
- Logger::error("Unrecognised terrain colour ", Province::colour_to_hex_string(terrain_colour), " at (", x, ", ", y, ")");
- ret = FAILURE;
+ if (detailed_errors) {
+ Logger::error("Unrecognised terrain colour ", Province::colour_to_hex_string(terrain_colour),
+ " at (", x, ", ", y, ")");
+ }
}
province_shape_image[idx].terrain = 0;
}
@@ -255,19 +271,36 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height,
}
if (unrecognised_province_colours.find(province_colour) == unrecognised_province_colours.end()) {
unrecognised_province_colours.insert(province_colour);
- Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(province_colour), " at (", x, ", ", y, ")");
- ret = FAILURE;
+ if (detailed_errors) {
+ Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(province_colour),
+ " at (", x, ", ", y, ")");
+ }
}
province_shape_image[idx].index = NULL_INDEX;
}
}
+ if (!unrecognised_province_colours.empty()) {
+ Logger::error("Province image contains ", unrecognised_province_colours.size(), " unrecognised province colours");
+ ret = FAILURE;
+ }
+ if (!unrecognised_terrain_colours.empty()) {
+ Logger::error("Terrain image contains ", unrecognised_terrain_colours.size(), " unrecognised terrain colours");
+ ret = FAILURE;
+ }
+ size_t missing = 0;
for (size_t idx = 0; idx < province_checklist.size(); ++idx) {
if (!province_checklist[idx]) {
- Logger::error("Province missing from shape image: ", provinces.get_item_by_index(idx)->to_string());
- ret = FAILURE;
+ if (detailed_errors) {
+ Logger::error("Province missing from shape image: ", provinces.get_item_by_index(idx)->to_string());
+ }
+ missing++;
}
}
+ if (missing > 0) {
+ Logger::error("Province image is missing ", missing, " province colours");
+ ret = FAILURE;
+ }
return ret;
}
@@ -283,7 +316,7 @@ std::vector<Map::shape_pixel_t> const& Map::get_province_shape_image() const {
return province_shape_image;
}
-return_t Map::add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func) {
+return_t 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;
@@ -292,7 +325,7 @@ return_t Map::add_mapmode(std::string const& identifier, Mapmode::colour_func_t
Logger::error("Mapmode colour function is null for identifier: ", identifier);
return FAILURE;
}
- return mapmodes.add_item({ mapmodes.get_item_count(), identifier, colour_func });
+ return mapmodes.add_item({ identifier, mapmodes.get_item_count(), colour_func });
}
void Map::lock_mapmodes() {
@@ -307,7 +340,7 @@ Mapmode const* Map::get_mapmode_by_index(size_t index) const {
return mapmodes.get_item_by_index(index);
}
-Mapmode const* Map::get_mapmode_by_identifier(std::string const& identifier) const {
+Mapmode const* Map::get_mapmode_by_identifier(const std::string_view identifier) const {
return mapmodes.get_item_by_identifier(identifier);
}
diff --git a/src/openvic/map/Map.hpp b/src/openvic/map/Map.hpp
index 3e1370b..64678c8 100644
--- a/src/openvic/map/Map.hpp
+++ b/src/openvic/map/Map.hpp
@@ -16,7 +16,7 @@ namespace OpenVic {
const index_t index;
const colour_func_t colour_func;
- Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func);
+ Mapmode(const std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func);
public:
static const Mapmode ERROR_MAPMODE;
@@ -46,8 +46,7 @@ namespace OpenVic {
IdentifierRegistry<Province> provinces;
IdentifierRegistry<Region> regions;
IdentifierRegistry<Mapmode> mapmodes;
- bool water_provinces_locked = false;
- size_t water_province_count = 0;
+ ProvinceSet water_provinces;
size_t width = 0, height = 0;
std::vector<shape_pixel_t> province_shape_image;
@@ -61,37 +60,37 @@ namespace OpenVic {
public:
Map();
- return_t add_province(std::string const& identifier, colour_t colour);
+ return_t add_province(const std::string_view identifier, colour_t colour);
void lock_provinces();
- return_t set_water_province(std::string const& identifier);
+ return_t set_water_province(const std::string_view identifier);
void lock_water_provinces();
- return_t add_region(std::string const& identifier, std::vector<std::string> const& province_identifiers);
+ return_t add_region(const std::string_view identifier, std::vector<std::string_view> const& province_identifiers);
void lock_regions();
size_t get_province_count() const;
Province* get_province_by_index(index_t index);
Province const* get_province_by_index(index_t index) const;
- Province* get_province_by_identifier(std::string const& identifier);
- Province const* get_province_by_identifier(std::string const& identifier) const;
+ Province* get_province_by_identifier(const std::string_view identifier);
+ Province const* get_province_by_identifier(const std::string_view identifier) const;
index_t get_province_index_at(size_t x, size_t y) const;
void set_selected_province(index_t index);
index_t get_selected_province_index() const;
Province const* get_selected_province() const;
- Region* get_region_by_identifier(std::string const& identifier);
- Region const* get_region_by_identifier(std::string const& identifier) const;
+ Region* get_region_by_identifier(const std::string_view identifier);
+ Region const* get_region_by_identifier(const std::string_view identifier) const;
return_t 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);
+ 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(std::string const& identifier, Mapmode::colour_func_t colour_func);
+ return_t add_mapmode(const std::string_view identifier, Mapmode::colour_func_t colour_func);
void lock_mapmodes();
size_t get_mapmode_count() const;
Mapmode const* get_mapmode_by_index(Mapmode::index_t index) const;
- Mapmode const* get_mapmode_by_identifier(std::string const& identifier) 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;
diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp
index 0b6d1f4..ea284b6 100644
--- a/src/openvic/map/Province.cpp
+++ b/src/openvic/map/Province.cpp
@@ -6,7 +6,7 @@
using namespace OpenVic;
-Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour)
+Province::Province(const std::string_view new_identifier, colour_t new_colour, index_t new_index)
: HasIdentifierAndColour { new_identifier, new_colour, false },
index { new_index },
buildings { "buildings" } {
@@ -41,7 +41,7 @@ void Province::reset_buildings() {
buildings.reset();
}
-Building const* Province::get_building_by_identifier(std::string const& identifier) const {
+Building const* Province::get_building_by_identifier(const std::string_view identifier) const {
return buildings.get_item_by_identifier(identifier);
}
@@ -49,7 +49,7 @@ std::vector<Building> const& Province::get_buildings() const {
return buildings.get_items();
}
-return_t Province::expand_building(std::string const& building_type_identifier) {
+return_t 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;
return building->expand();
diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp
index 3ca5d93..20c5870 100644
--- a/src/openvic/map/Province.hpp
+++ b/src/openvic/map/Province.hpp
@@ -29,7 +29,7 @@ namespace OpenVic {
Pop::pop_size_t total_population;
distribution_t pop_types, cultures;
- Province(index_t new_index, std::string const& new_identifier, colour_t new_colour);
+ Province(const std::string_view new_identifier, colour_t new_colour, index_t new_index);
public:
Province(Province&&) = default;
@@ -41,9 +41,9 @@ namespace OpenVic {
return_t add_building(Building&& building);
void lock_buildings();
void reset_buildings();
- Building const* get_building_by_identifier(std::string const& identifier) const;
+ Building const* get_building_by_identifier(const std::string_view identifier) const;
std::vector<Building> const& get_buildings() const;
- return_t expand_building(std::string const& building_type_identifier);
+ return_t expand_building(const std::string_view building_type_identifier);
Good const* get_rgo() const;
std::string to_string() const;
diff --git a/src/openvic/map/Region.cpp b/src/openvic/map/Region.cpp
index b83f556..fc207e3 100644
--- a/src/openvic/map/Region.cpp
+++ b/src/openvic/map/Region.cpp
@@ -4,6 +4,41 @@
using namespace OpenVic;
+return_t ProvinceSet::add_province(Province* province) {
+ if (locked) {
+ Logger::error("Cannot add province to province set - locked!");
+ return FAILURE;
+ }
+ if (province == nullptr) {
+ Logger::error("Cannot add province to province set - null province!");
+ return FAILURE;
+ }
+ if (contains_province(province)) {
+ Logger::error("Cannot add province ", province->get_identifier(), " to province set - already in the set!");
+ return FAILURE;
+ }
+ provinces.push_back(province);
+ return SUCCESS;
+}
+
+void ProvinceSet::lock(bool log) {
+ if (locked) {
+ Logger::error("Failed to lock province set - already locked!");
+ } else {
+ locked = true;
+ if (log) Logger::info("Locked province set with ", get_province_count(), " provinces");
+ }
+}
+
+bool ProvinceSet::is_locked() const {
+ return locked;
+}
+
+void ProvinceSet::reset() {
+ provinces.clear();
+ locked = false;
+}
+
size_t ProvinceSet::get_province_count() const {
return provinces.size();
}
@@ -16,7 +51,7 @@ std::vector<Province*> const& ProvinceSet::get_provinces() const {
return provinces;
}
-Region::Region(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+Region::Region(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
colour_t Region::get_colour() const {
if (provinces.empty()) return FULL_COLOUR << 16;
diff --git a/src/openvic/map/Region.hpp b/src/openvic/map/Region.hpp
index 331d883..beeb76e 100644
--- a/src/openvic/map/Region.hpp
+++ b/src/openvic/map/Region.hpp
@@ -7,8 +7,13 @@ namespace OpenVic {
struct ProvinceSet {
protected:
std::vector<Province*> provinces;
+ bool locked = false;
public:
+ return_t add_province(Province* province);
+ void lock(bool log = false);
+ bool is_locked() const;
+ void reset();
size_t get_province_count() const;
bool contains_province(Province const* province) const;
std::vector<Province*> const& get_provinces() const;
@@ -21,7 +26,7 @@ namespace OpenVic {
friend struct Map;
private:
- Region(std::string const& new_identifier);
+ Region(const std::string_view new_identifier);
public:
Region(Region&&) = default;
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
index b683804..f50bb23 100644
--- a/src/openvic/pop/Culture.cpp
+++ b/src/openvic/pop/Culture.cpp
@@ -4,9 +4,9 @@
using namespace OpenVic;
-GraphicalCultureType::GraphicalCultureType(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+GraphicalCultureType::GraphicalCultureType(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-CultureGroup::CultureGroup(std::string const& new_identifier,
+CultureGroup::CultureGroup(const std::string_view new_identifier,
GraphicalCultureType const& new_unit_graphical_culture_type)
: HasIdentifier { new_identifier },
unit_graphical_culture_type { new_unit_graphical_culture_type } {}
@@ -15,10 +15,10 @@ GraphicalCultureType const& CultureGroup::get_unit_graphical_culture_type() cons
return unit_graphical_culture_type;
}
-Culture::Culture(CultureGroup const& new_group, std::string const& new_identifier,
- colour_t new_colour, name_list_t const& new_first_names, name_list_t const& new_last_names)
- : group { new_group },
- HasIdentifierAndColour { new_identifier, new_colour, true },
+Culture::Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group,
+ name_list_t const& new_first_names, name_list_t const& new_last_names)
+ : HasIdentifierAndColour { new_identifier, new_colour, true },
+ group { new_group },
first_names { new_first_names },
last_names { new_last_names } {
}
@@ -32,7 +32,7 @@ CultureManager::CultureManager()
culture_groups { "culture groups" },
cultures { "cultures" } {}
-return_t CultureManager::add_graphical_culture_type(std::string const& identifier) {
+return_t CultureManager::add_graphical_culture_type(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid culture group identifier - empty!");
return FAILURE;
@@ -44,11 +44,11 @@ void CultureManager::lock_graphical_culture_types() {
graphical_culture_types.lock();
}
-GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identifier(std::string const& identifier) const {
+GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identifier(const std::string_view identifier) const {
return graphical_culture_types.get_item_by_identifier(identifier);
}
-return_t CultureManager::add_culture_group(std::string const& identifier, GraphicalCultureType const* graphical_culture_type) {
+return_t CultureManager::add_culture_group(const std::string_view identifier, GraphicalCultureType const* graphical_culture_type) {
if (!graphical_culture_types.is_locked()) {
Logger::error("Cannot register culture groups until graphical culture types are locked!");
return FAILURE;
@@ -68,11 +68,11 @@ void CultureManager::lock_culture_groups() {
culture_groups.lock();
}
-CultureGroup const* CultureManager::get_culture_group_by_identifier(std::string const& identifier) const {
+CultureGroup const* CultureManager::get_culture_group_by_identifier(const std::string_view identifier) const {
return culture_groups.get_item_by_identifier(identifier);
}
-return_t CultureManager::add_culture(std::string const& identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names) {
+return_t CultureManager::add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names) {
if (!culture_groups.is_locked()) {
Logger::error("Cannot register cultures until culture groups are locked!");
return FAILURE;
@@ -90,13 +90,13 @@ return_t CultureManager::add_culture(std::string const& identifier, colour_t col
return FAILURE;
}
// TODO - name list sanatisation?
- return cultures.add_item({ *group, identifier, colour, first_names, last_names });
+ return cultures.add_item({ identifier, colour, *group, first_names, last_names });
}
void CultureManager::lock_cultures() {
cultures.lock();
}
-Culture const* CultureManager::get_culture_by_identifier(std::string const& identifier) const {
+Culture const* CultureManager::get_culture_by_identifier(const std::string_view identifier) const {
return cultures.get_item_by_identifier(identifier);
}
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
index 657a531..645e226 100644
--- a/src/openvic/pop/Culture.hpp
+++ b/src/openvic/pop/Culture.hpp
@@ -10,7 +10,7 @@ namespace OpenVic {
friend struct CultureManager;
private:
- GraphicalCultureType(std::string const& new_identifier);
+ GraphicalCultureType(const std::string_view new_identifier);
public:
GraphicalCultureType(GraphicalCultureType&&) = default;
@@ -24,7 +24,7 @@ namespace OpenVic {
// TODO - leader type, union tag
- CultureGroup(std::string const& new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type);
+ CultureGroup(const std::string_view new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type);
public:
CultureGroup(CultureGroup&&) = default;
@@ -43,7 +43,7 @@ namespace OpenVic {
// TODO - radicalism, primary tag
- Culture(CultureGroup const& new_group, std::string const& new_identifier, colour_t new_colour, name_list_t const& new_first_names, name_list_t const& new_last_names);
+ Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, name_list_t const& new_first_names, name_list_t const& new_last_names);
public:
Culture(Culture&&) = default;
@@ -60,14 +60,14 @@ namespace OpenVic {
public:
CultureManager();
- return_t add_graphical_culture_type(std::string const& identifier);
+ return_t add_graphical_culture_type(const std::string_view identifier);
void lock_graphical_culture_types();
- GraphicalCultureType const* get_graphical_culture_type_by_identifier(std::string const& identifier) const;
- return_t add_culture_group(std::string const& identifier, GraphicalCultureType const* new_graphical_culture_type);
+ GraphicalCultureType const* get_graphical_culture_type_by_identifier(const std::string_view identifier) const;
+ return_t add_culture_group(const std::string_view identifier, GraphicalCultureType const* new_graphical_culture_type);
void lock_culture_groups();
- CultureGroup const* get_culture_group_by_identifier(std::string const& identifier) const;
- return_t add_culture(std::string const& identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names);
+ CultureGroup const* get_culture_group_by_identifier(const std::string_view identifier) const;
+ return_t add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names);
void lock_cultures();
- Culture const* get_culture_by_identifier(std::string const& identifier) const;
+ Culture const* get_culture_by_identifier(const std::string_view identifier) const;
};
}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
index 913d31f..c4b11b8 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -31,7 +31,7 @@ Pop::pop_size_t Pop::get_size() const {
return size;
}
-PopType::PopType(std::string const& new_identifier, colour_t new_colour,
+PopType::PopType(const std::string_view new_identifier, colour_t new_colour,
strata_t new_strata, sprite_t new_sprite,
Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave)
@@ -77,30 +77,39 @@ bool PopType::get_is_slave() const {
return is_slave;
}
+static const std::string test_graphical_culture_type = "test_graphical_culture_type";
+static const std::string test_culture_group = "test_culture_group";
+static const std::string test_culture = "test_culture";
+static const std::string test_religion_group = "test_religion_group";
+static const std::string test_religion = "test_religion";
+static const std::string test_pop_type_poor = "test_pop_type_poor";
+static const std::string test_pop_type_middle = "test_pop_type_middle";
+static const std::string test_pop_type_rich = "test_pop_type_rich";
+
PopManager::PopManager() : pop_types { "pop types" } {
- culture_manager.add_graphical_culture_type("test_graphical_culture_type");
+ culture_manager.add_graphical_culture_type(test_graphical_culture_type);
culture_manager.lock_graphical_culture_types();
- culture_manager.add_culture_group("test_culture_group", culture_manager.get_graphical_culture_type_by_identifier("test_graphical_culture_type"));
+ culture_manager.add_culture_group(test_culture_group, culture_manager.get_graphical_culture_type_by_identifier(test_graphical_culture_type));
culture_manager.lock_culture_groups();
- culture_manager.add_culture("test_culture", 0x0000FF, culture_manager.get_culture_group_by_identifier("test_culture_group"),
+ culture_manager.add_culture(test_culture, 0x0000FF, culture_manager.get_culture_group_by_identifier(test_culture_group),
{ "john" }, { "smith" });
culture_manager.lock_cultures();
- religion_manager.add_religion_group("test_religion_group");
+ religion_manager.add_religion_group(test_religion_group);
religion_manager.lock_religion_groups();
- religion_manager.add_religion("test_religion", 0xFF0000, religion_manager.get_religion_group_by_identifier("test_religion_group"), 1, false);
+ religion_manager.add_religion(test_religion, 0xFF0000, religion_manager.get_religion_group_by_identifier(test_religion_group), 1, false);
religion_manager.lock_religions();
- add_pop_type("test_pop_type_poor", 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
- add_pop_type("test_pop_type_middle", 0x00FF00, PopType::strata_t::MIDDLE, 1, 1, 1, false, false, false, false);
- add_pop_type("test_pop_type_rich", 0x0000FF, PopType::strata_t::RICH, 1, 1, 1, false, false, false, false);
+ add_pop_type(test_pop_type_poor, 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
+ add_pop_type(test_pop_type_middle, 0x00FF00, PopType::strata_t::MIDDLE, 1, 1, 1, false, false, false, false);
+ add_pop_type(test_pop_type_rich, 0x0000FF, PopType::strata_t::RICH, 1, 1, 1, false, false, false, false);
lock_pop_types();
}
-return_t PopManager::add_pop_type(std::string const& identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
+return_t PopManager::add_pop_type(const std::string_view identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave) {
if (identifier.empty()) {
Logger::error("Invalid pop type identifier - empty!");
@@ -129,17 +138,17 @@ void PopManager::lock_pop_types() {
pop_types.lock();
}
-PopType const* PopManager::get_pop_type_by_identifier(std::string const& identifier) const {
+PopType const* PopManager::get_pop_type_by_identifier(const std::string_view identifier) const {
return pop_types.get_item_by_identifier(identifier);
}
void PopManager::generate_test_pops(Province& province) const {
if (pop_types.is_locked()) {
- static PopType const& type_poor = *get_pop_type_by_identifier("test_pop_type_poor");
- static PopType const& type_middle = *get_pop_type_by_identifier("test_pop_type_middle");
- static PopType const& type_rich = *get_pop_type_by_identifier("test_pop_type_rich");
- static Culture const& culture = *culture_manager.get_culture_by_identifier("test_culture");
- static Religion const& religion = *religion_manager.get_religion_by_identifier("test_religion");
+ static PopType const& type_poor = *get_pop_type_by_identifier(test_pop_type_poor);
+ static PopType const& type_middle = *get_pop_type_by_identifier(test_pop_type_middle);
+ static PopType const& type_rich = *get_pop_type_by_identifier(test_pop_type_rich);
+ static Culture const& culture = *culture_manager.get_culture_by_identifier(test_culture);
+ static Religion const& religion = *religion_manager.get_religion_by_identifier(test_religion);
province.add_pop({ type_poor, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index()) * 100 });
province.add_pop({ type_middle, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index()) * 50 });
province.add_pop({ type_rich, culture, religion, static_cast<Pop::pop_size_t>(province.get_index()) * 1000 });
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index 628194d..5bd1b90 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -57,7 +57,7 @@ namespace OpenVic {
// TODO - rebel composition, life/everyday/luxury needs, country and province migration targets, promote_to targets, ideologies and issues
- PopType(std::string const& new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite, Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
+ PopType(const std::string_view new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite, Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave);
public:
@@ -83,11 +83,11 @@ namespace OpenVic {
public:
PopManager();
- return_t add_pop_type(std::string const& identifier, colour_t new_colour, PopType::strata_t strata, PopType::sprite_t sprite,
+ return_t 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();
- PopType const* get_pop_type_by_identifier(std::string const& identifier) const;
+ PopType const* get_pop_type_by_identifier(const std::string_view identifier) const;
void generate_test_pops(Province& province) const;
};
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
index f3d3341..0cfc7a6 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -4,12 +4,12 @@
using namespace OpenVic;
-ReligionGroup::ReligionGroup(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+ReligionGroup::ReligionGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-Religion::Religion(ReligionGroup const& new_group, std::string const& new_identifier,
- colour_t new_colour, icon_t new_icon, bool new_pagan)
- : group { new_group },
- HasIdentifierAndColour { new_identifier, new_colour, true },
+Religion::Religion(const std::string_view new_identifier, colour_t new_colour,
+ ReligionGroup const& new_group, icon_t new_icon, bool new_pagan)
+ : HasIdentifierAndColour { new_identifier, new_colour, true },
+ group { new_group },
icon { new_icon },
pagan { new_pagan } {
assert(icon > 0);
@@ -31,7 +31,7 @@ ReligionManager::ReligionManager()
: religion_groups { "religion groups" },
religions { "religions" } {}
-return_t ReligionManager::add_religion_group(std::string const& identifier) {
+return_t ReligionManager::add_religion_group(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid religion group identifier - empty!");
return FAILURE;
@@ -43,11 +43,11 @@ void ReligionManager::lock_religion_groups() {
religion_groups.lock();
}
-ReligionGroup const* ReligionManager::get_religion_group_by_identifier(std::string const& identifier) const {
+ReligionGroup const* ReligionManager::get_religion_group_by_identifier(const std::string_view identifier) const {
return religion_groups.get_item_by_identifier(identifier);
}
-return_t ReligionManager::add_religion(std::string const& identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan) {
+return_t ReligionManager::add_religion(const std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan) {
if (!religion_groups.is_locked()) {
Logger::error("Cannot register religions until religion groups are locked!");
return FAILURE;
@@ -68,13 +68,13 @@ return_t ReligionManager::add_religion(std::string const& identifier, colour_t c
Logger::error("Invalid religion icon for ", identifier, ": ", icon);
return FAILURE;
}
- return religions.add_item({ *group, identifier, colour, icon, pagan });
+ return religions.add_item({ identifier, colour, *group, icon, pagan });
}
void ReligionManager::lock_religions() {
religions.lock();
}
-Religion const* ReligionManager::get_religion_by_identifier(std::string const& identifier) const {
+Religion const* ReligionManager::get_religion_by_identifier(const std::string_view identifier) const {
return religions.get_item_by_identifier(identifier);
}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index e781cf9..4eb3e4c 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -10,7 +10,7 @@ namespace OpenVic {
friend struct ReligionManager;
private:
- ReligionGroup(std::string const& new_identifier);
+ ReligionGroup(const std::string_view new_identifier);
public:
ReligionGroup(ReligionGroup&&) = default;
@@ -26,7 +26,7 @@ namespace OpenVic {
const icon_t icon;
const bool pagan;
- Religion(ReligionGroup const& new_group, std::string const& new_identifier, colour_t new_colour, icon_t new_icon, bool new_pagan);
+ Religion(const std::string_view new_identifier, colour_t new_colour, ReligionGroup const& new_group, icon_t new_icon, bool new_pagan);
public:
Religion(Religion&&) = default;
@@ -44,11 +44,11 @@ namespace OpenVic {
public:
ReligionManager();
- return_t add_religion_group(std::string const& identifier);
+ return_t add_religion_group(const std::string_view identifier);
void lock_religion_groups();
- ReligionGroup const* get_religion_group_by_identifier(std::string const& identifier) const;
- return_t add_religion(std::string const& identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan);
+ ReligionGroup const* get_religion_group_by_identifier(const std::string_view identifier) const;
+ return_t add_religion(const std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan);
void lock_religions();
- Religion const* get_religion_by_identifier(std::string const& identifier) const;
+ Religion const* get_religion_by_identifier(const std::string_view identifier) const;
};
}