aboutsummaryrefslogtreecommitdiff
path: root/src/openvic
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-07-22 01:18:00 +0200
committer Hop311 <hop3114@gmail.com>2023-07-22 01:18:00 +0200
commit83e61b518788d21283cda481decafee4ee2e252c (patch)
tree4adc383884ad57f404913d5eb4d83da56d354b05 /src/openvic
parent420c2dce47e74c01ff46be991058d543e0c70a6b (diff)
WIP structs for Pop, PopType, and Religion
Diffstat (limited to 'src/openvic')
-rw-r--r--src/openvic/economy/Good.cpp6
-rw-r--r--src/openvic/map/Building.cpp4
-rw-r--r--src/openvic/map/Map.cpp12
-rw-r--r--src/openvic/pop/Pop.cpp99
-rw-r--r--src/openvic/pop/Pop.hpp81
-rw-r--r--src/openvic/pop/Religion.cpp81
-rw-r--r--src/openvic/pop/Religion.hpp54
7 files changed, 328 insertions, 9 deletions
diff --git a/src/openvic/economy/Good.cpp b/src/openvic/economy/Good.cpp
index 6d515d5..4524e5f 100644
--- a/src/openvic/economy/Good.cpp
+++ b/src/openvic/economy/Good.cpp
@@ -50,8 +50,12 @@ return_t GoodManager::add_good(std::string const& identifier, std::string const&
Logger::error("Invalid good identifier - empty!");
return FAILURE;
}
+ if (colour > MAX_COLOUR_RGB) {
+ Logger::error("Invalid good colour for ", identifier, ": ", Good::colour_to_hex_string(colour));
+ return FAILURE;
+ }
if (category.empty()) {
- Logger::error("Invalid good category - empty!");
+ Logger::error("Invalid good category for ", identifier, ": empty!");
return FAILURE;
}
if (base_price <= NULL_PRICE) {
diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp
index 317ccdf..07cbac9 100644
--- a/src/openvic/map/Building.cpp
+++ b/src/openvic/map/Building.cpp
@@ -100,11 +100,11 @@ return_t BuildingManager::add_building_type(std::string const& identifier, Build
return FAILURE;
}
if (max_level < 0) {
- Logger::error("Invalid building type max level: ", max_level);
+ Logger::error("Invalid building type max level for ", identifier, ": ", max_level);
return FAILURE;
}
if (build_time < 0) {
- Logger::error("Invalid building type build time: ", build_time);
+ Logger::error("Invalid building type build time for ", identifier, ": ", build_time);
return FAILURE;
}
return building_types.add_item({ identifier, max_level, build_time });
diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp
index 2efee32..936add0 100644
--- a/src/openvic/map/Map.cpp
+++ b/src/openvic/map/Map.cpp
@@ -39,7 +39,7 @@ return_t Map::add_province(std::string const& identifier, colour_t colour) {
return FAILURE;
}
if (colour == NULL_COLOUR || colour > MAX_COLOUR_RGB) {
- Logger::error("Invalid province colour: ", Province::colour_to_hex_string(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 };
@@ -91,26 +91,26 @@ return_t Map::add_region(std::string const& identifier, std::vector<std::string>
Province* province = get_province_by_identifier(province_identifier);
if (province != nullptr) {
if (new_region.contains_province(province)) {
- Logger::error("Duplicate province identifier ", province_identifier);
+ Logger::error("Duplicate province identifier ", province_identifier, " in region ", identifier);
ret = FAILURE;
} else {
size_t other_region_index = reinterpret_cast<size_t>(province->get_region());
if (other_region_index != 0) {
other_region_index--;
if (other_region_index < regions.get_item_count())
- Logger::error("Province ", province_identifier, " is already part of ", regions.get_item_by_index(other_region_index)->get_identifier());
+ 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("Province ", province_identifier, " is already part of an unknown region with index ", other_region_index);
+ 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 {
- Logger::error("Invalid province identifier ", province_identifier);
+ Logger::error("Invalid province identifier ", province_identifier, " for region ", identifier);
ret = FAILURE;
}
}
if (!new_region.get_province_count()) {
- Logger::error("No valid provinces in region's list");
+ Logger::error("No valid provinces in list for ", identifier);
return FAILURE;
}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
new file mode 100644
index 0000000..0a8c646
--- /dev/null
+++ b/src/openvic/pop/Pop.cpp
@@ -0,0 +1,99 @@
+#include "Pop.hpp"
+
+#include <cassert>
+
+#include "../utility/Logger.hpp"
+
+using namespace OpenVic;
+
+Pop::Pop(PopType const& new_type, Religion const& new_religion)
+ : type { new_type }, religion { new_religion }, size { 1 } {
+ assert(size > 0);
+}
+
+PopType const& Pop::get_type() const {
+ return type;
+}
+
+Religion const& Pop::get_religion() const {
+ return religion;
+}
+
+Pop::pop_size_t Pop::get_size() const {
+ return size;
+}
+
+PopType::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,
+ bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan)
+ : HasIdentifier { new_identifier },
+ HasColour { new_colour, true },
+ strata { new_strata },
+ sprite { new_sprite },
+ max_size { new_max_size },
+ merge_max_size { new_merge_max_size },
+ state_capital_only { new_state_capital_only },
+ demote_migrant { new_demote_migrant },
+ is_artisan { new_is_artisan } {
+ assert(sprite > 0);
+ assert(max_size > 0);
+ assert(merge_max_size > 0);
+}
+
+PopType::sprite_t PopType::get_sprite() const {
+ return sprite;
+}
+
+Pop::pop_size_t PopType::get_max_size() const {
+ return max_size;
+}
+
+Pop::pop_size_t PopType::get_merge_max_size() const {
+ return merge_max_size;
+}
+
+bool PopType::get_state_capital_only() const {
+ return state_capital_only;
+}
+
+bool PopType::get_demote_migrant() const {
+ return demote_migrant;
+}
+
+bool PopType::get_is_artisan() const {
+ return is_artisan;
+}
+
+PopTypeManager::PopTypeManager() : pop_types { "pop types" } {}
+
+return_t PopTypeManager::add_pop_type(std::string const& 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) {
+ if (identifier.empty()) {
+ Logger::error("Invalid pop type identifier - empty!");
+ return FAILURE;
+ }
+ if (colour > MAX_COLOUR_RGB) {
+ Logger::error("Invalid pop type colour for ", identifier, ": ", PopType::colour_to_hex_string(colour));
+ return FAILURE;
+ }
+ if (sprite <= 0) {
+ Logger::error("Invalid pop type sprite index for ", identifier, ": ", sprite);
+ return FAILURE;
+ }
+ if (max_size <= 0) {
+ Logger::error("Invalid pop type max size for ", identifier, ": ", max_size);
+ return FAILURE;
+ }
+ if (merge_max_size <= 0) {
+ Logger::error("Invalid pop type merge max size for ", identifier, ": ", merge_max_size);
+ return FAILURE;
+ }
+ return pop_types.add_item({ identifier, colour, strata, sprite, max_size, merge_max_size, state_capital_only, demote_migrant, is_artisan });
+}
+
+void PopTypeManager::lock_pop_types() {
+ pop_types.lock();
+}
+
+PopType const* PopTypeManager::get_pop_type_by_identifier(std::string const& identifier) const {
+ return pop_types.get_item_by_identifier(identifier);
+}
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
new file mode 100644
index 0000000..51952b9
--- /dev/null
+++ b/src/openvic/pop/Pop.hpp
@@ -0,0 +1,81 @@
+#pragma once
+
+#include "../Types.hpp"
+
+namespace OpenVic {
+
+ struct PopType;
+ struct Religion;
+
+ /* REQUIREMENTS:
+ * POP-18, POP-19, POP-21
+ */
+ struct Pop {
+
+ using pop_size_t = uint32_t;
+
+ private:
+ PopType const& type;
+ Religion const& religion;
+ pop_size_t size;
+
+ Pop(PopType const& new_type, Religion const& new_religion);
+
+ public:
+ Pop(Pop const&) = delete;
+ Pop(Pop&&) = default;
+ Pop& operator=(Pop const&) = delete;
+ Pop& operator=(Pop&&) = delete;
+
+ PopType const& get_type() const;
+ Religion const& get_religion() const;
+ pop_size_t get_size() const;
+ };
+
+ struct PopTypeManager;
+
+ /* REQUIREMENTS:
+ * POP-26
+ */
+ struct PopType : HasIdentifier, HasColour {
+ friend struct PopTypeManager;
+
+ using sprite_t = uint8_t;
+
+ private:
+ const enum class strata_t {
+ POOR,
+ MIDDLE,
+ RICH
+ } strata;
+ const sprite_t sprite;
+ const Pop::pop_size_t max_size, merge_max_size;
+ const bool state_capital_only, demote_migrant, is_artisan;
+
+ // 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, bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan);
+
+ public:
+ PopType(PopType&&) = default;
+
+ sprite_t get_sprite() const;
+ Pop::pop_size_t get_max_size() const;
+ Pop::pop_size_t get_merge_max_size() const;
+ bool get_state_capital_only() const;
+ bool get_demote_migrant() const;
+ bool get_is_artisan() const;
+ };
+
+ struct PopTypeManager {
+ private:
+ IdentifierRegistry<PopType> pop_types;
+
+ public:
+ PopTypeManager();
+
+ return_t add_pop_type(std::string const& identifier, colour_t new_colour, PopType::strata_t new_strata, PopType::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);
+ void lock_pop_types();
+ PopType const* get_pop_type_by_identifier(std::string const& identifier) const;
+ };
+}
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
new file mode 100644
index 0000000..e94476d
--- /dev/null
+++ b/src/openvic/pop/Religion.cpp
@@ -0,0 +1,81 @@
+#include "Religion.hpp"
+
+#include <cassert>
+
+using namespace OpenVic;
+
+ReligionGroup::ReligionGroup(std::string const& 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 },
+ HasIdentifier { new_identifier },
+ HasColour { new_colour, true },
+ icon { new_icon },
+ pagan { new_pagan } {
+ assert(icon > 0);
+}
+
+ReligionGroup const& Religion::get_group() const {
+ return group;
+}
+
+Religion::icon_t Religion::get_icon() const {
+ return icon;
+}
+
+bool Religion::get_pagan() const {
+ return pagan;
+}
+
+ReligionManager::ReligionManager()
+ : religion_groups { "religion groups" },
+ religions { "religions" } {}
+
+return_t ReligionManager::add_religion_group(std::string const& identifier) {
+ if (identifier.empty()) {
+ Logger::error("Invalid relgion group identifier - empty!");
+ return FAILURE;
+ }
+ return religion_groups.add_item({ identifier });
+}
+
+void ReligionManager::lock_religion_groups() {
+ religion_groups.lock();
+}
+
+ReligionGroup const* ReligionManager::get_religion_group_by_identifier(std::string const& identifier) const {
+ return religion_groups.get_item_by_identifier(identifier);
+}
+
+return_t ReligionManager::add_religion(ReligionGroup const* group, std::string const& identifier, colour_t colour, Religion::icon_t icon, bool pagan) {
+ if (!religion_groups.is_locked()) {
+ Logger::error("Cannot register religions until religion groups are locked!");
+ return FAILURE;
+ }
+ if (identifier.empty()) {
+ Logger::error("Invalid religion identifier - empty!");
+ return FAILURE;
+ }
+ if (group == nullptr) {
+ Logger::error("Null religion group for ", identifier);
+ return FAILURE;
+ }
+ if (colour > MAX_COLOUR_RGB) {
+ Logger::error("Invalid religion colour for ", identifier, ": ", Religion::colour_to_hex_string(colour));
+ return FAILURE;
+ }
+ if (icon <= 0) {
+ Logger::error("Invalid religion icon for ", identifier, ": ", icon);
+ return FAILURE;
+ }
+ return religions.add_item({ *group, identifier, colour, icon, pagan });
+}
+
+void ReligionManager::lock_religion() {
+ religions.lock();
+}
+
+Religion const* ReligionManager::get_religion_by_identifier(std::string const& identifier) const {
+ return religions.get_item_by_identifier(identifier);
+}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
new file mode 100644
index 0000000..043bb59
--- /dev/null
+++ b/src/openvic/pop/Religion.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include "../Types.hpp"
+
+namespace OpenVic {
+
+ struct ReligionManager;
+
+ struct ReligionGroup : HasIdentifier {
+ friend struct ReligionManager;
+
+ private:
+ ReligionGroup(std::string const& new_identifier);
+
+ public:
+ ReligionGroup(ReligionGroup&&) = default;
+ };
+
+ struct Religion : HasIdentifier, HasColour {
+ friend struct ReligionManager;
+
+ using icon_t = uint8_t;
+
+ private:
+ ReligionGroup const& group;
+ 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);
+
+ public:
+ Religion(Religion&&) = default;
+
+ ReligionGroup const& get_group() const;
+ icon_t get_icon() const;
+ bool get_pagan() const;
+ };
+
+ struct ReligionManager {
+ private:
+ IdentifierRegistry<ReligionGroup> religion_groups;
+ IdentifierRegistry<Religion> religions;
+
+ public:
+ ReligionManager();
+
+ return_t add_religion_group(std::string const& identifier);
+ void lock_religion_groups();
+ ReligionGroup const* get_religion_group_by_identifier(std::string const& identifier) const;
+ return_t add_religion(ReligionGroup const* group, std::string const& identifier, colour_t colour, Religion::icon_t icon, bool pagan);
+ void lock_religion();
+ Religion const* get_religion_by_identifier(std::string const& identifier) const;
+ };
+}