aboutsummaryrefslogtreecommitdiff
path: root/src/openvic
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-07-23 01:29:13 +0200
committer Hop311 <hop3114@gmail.com>2023-07-23 01:29:13 +0200
commit0422f9fbb06e911a7cf6da11045b47cdda0d2d06 (patch)
treec3aa6375f636ba2ffb3f35885b19ae3db51bf12d /src/openvic
parent83e61b518788d21283cda481decafee4ee2e252c (diff)
Culture data structs
Diffstat (limited to 'src/openvic')
-rw-r--r--src/openvic/Types.hpp2
-rw-r--r--src/openvic/map/Province.cpp2
-rw-r--r--src/openvic/pop/Culture.cpp99
-rw-r--r--src/openvic/pop/Culture.hpp73
-rw-r--r--src/openvic/pop/Pop.cpp14
-rw-r--r--src/openvic/pop/Pop.hpp5
-rw-r--r--src/openvic/pop/Religion.cpp4
-rw-r--r--src/openvic/pop/Religion.hpp2
8 files changed, 192 insertions, 9 deletions
diff --git a/src/openvic/Types.hpp b/src/openvic/Types.hpp
index fe22dc9..7740e17 100644
--- a/src/openvic/Types.hpp
+++ b/src/openvic/Types.hpp
@@ -64,7 +64,7 @@ namespace OpenVic {
const colour_t colour;
protected:
- HasColour(colour_t const new_colour, bool can_be_null = false);
+ HasColour(colour_t const new_colour, bool can_be_null);
public:
HasColour(HasColour const&) = delete;
diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp
index d2a5ecf..06f1c98 100644
--- a/src/openvic/map/Province.cpp
+++ b/src/openvic/map/Province.cpp
@@ -8,7 +8,7 @@ using namespace OpenVic;
Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour)
: HasIdentifier { new_identifier },
- HasColour { new_colour },
+ HasColour { new_colour, false },
index { new_index },
buildings { "buildings" } {
assert(index != NULL_INDEX);
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
new file mode 100644
index 0000000..05fc5fe
--- /dev/null
+++ b/src/openvic/pop/Culture.cpp
@@ -0,0 +1,99 @@
+#include "Culture.hpp"
+
+#include <cassert>
+
+using namespace OpenVic;
+
+GraphicalCultureType::GraphicalCultureType(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+
+CultureGroup::CultureGroup(std::string const& new_identifier,
+ GraphicalCultureType const& new_unit_graphical_culture_type)
+ : HasIdentifier { new_identifier },
+ unit_graphical_culture_type { new_unit_graphical_culture_type } {}
+
+GraphicalCultureType const& CultureGroup::get_unit_graphical_culture_type() const {
+ 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 },
+ HasIdentifier { new_identifier },
+ HasColour { new_colour, true },
+ first_names { new_first_names },
+ last_names { new_last_names } {
+}
+
+CultureGroup const& Culture::get_group() const {
+ return group;
+}
+
+CultureManager::CultureManager()
+ : graphical_culture_types { "graphical culture types" },
+ culture_groups { "culture groups" },
+ cultures { "cultures" } {}
+
+return_t CultureManager::add_graphical_culture_type(std::string const& identifier) {
+ if (identifier.empty()) {
+ Logger::error("Invalid culture group identifier - empty!");
+ return FAILURE;
+ }
+ return graphical_culture_types.add_item({ identifier });
+}
+
+void CultureManager::lock_graphical_culture_types() {
+ graphical_culture_types.lock();
+}
+
+GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identifier(std::string const& 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) {
+ if (!graphical_culture_types.is_locked()) {
+ Logger::error("Cannot register culture groups until graphical culture types are locked!");
+ return FAILURE;
+ }
+ if (identifier.empty()) {
+ Logger::error("Invalid culture group identifier - empty!");
+ return FAILURE;
+ }
+ return culture_groups.add_item({ identifier, graphical_culture_type });
+}
+
+void CultureManager::lock_culture_groups() {
+ culture_groups.lock();
+}
+
+CultureGroup const* CultureManager::get_culture_group_by_identifier(std::string const& identifier) const {
+ return culture_groups.get_item_by_identifier(identifier);
+}
+
+return_t CultureManager::add_culture(CultureGroup const* group, std::string const& identifier, colour_t colour, 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;
+ }
+ if (identifier.empty()) {
+ Logger::error("Invalid culture identifier - empty!");
+ return FAILURE;
+ }
+ if (group == nullptr) {
+ Logger::error("Null culture group for ", identifier);
+ return FAILURE;
+ }
+ if (colour > MAX_COLOUR_RGB) {
+ Logger::error("Invalid culture colour for ", identifier, ": ", Culture::colour_to_hex_string(colour));
+ return FAILURE;
+ }
+ // TODO - name list sanatisation?
+ return cultures.add_item({ *group, identifier, colour, first_names, last_names });
+}
+
+void CultureManager::lock_cultures() {
+ cultures.lock();
+}
+
+Culture const* CultureManager::get_culture_by_identifier(std::string const& identifier) const {
+ return cultures.get_item_by_identifier(identifier);
+}
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
new file mode 100644
index 0000000..ce49cd0
--- /dev/null
+++ b/src/openvic/pop/Culture.hpp
@@ -0,0 +1,73 @@
+#pragma once
+
+#include "../Types.hpp"
+
+namespace OpenVic {
+
+ struct CultureManager;
+
+ struct GraphicalCultureType : HasIdentifier {
+ friend struct CultureManager;
+
+ private:
+ GraphicalCultureType(std::string const& new_identifier);
+
+ public:
+ GraphicalCultureType(GraphicalCultureType&&) = default;
+ };
+
+ struct CultureGroup : HasIdentifier {
+ friend struct CultureManager;
+
+ private:
+ GraphicalCultureType const& unit_graphical_culture_type;
+
+ // TODO - leader type, union tag
+
+ CultureGroup(std::string const& new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type);
+
+ public:
+ CultureGroup(CultureGroup&&) = default;
+
+ GraphicalCultureType const& get_unit_graphical_culture_type() const;
+ };
+
+ struct Culture : HasIdentifier, HasColour {
+ friend struct CultureManager;
+
+ using name_list_t = std::vector<std::string>;
+
+ private:
+ CultureGroup const& group;
+ const name_list_t first_names, last_names;
+
+ // 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);
+
+ public:
+ Culture(Culture&&) = default;
+
+ CultureGroup const& get_group() const;
+ };
+
+ struct CultureManager {
+ private:
+ IdentifierRegistry<GraphicalCultureType> graphical_culture_types;
+ IdentifierRegistry<CultureGroup> culture_groups;
+ IdentifierRegistry<Culture> cultures;
+
+ public:
+ CultureManager();
+
+ return_t add_graphical_culture_type(std::string const& 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);
+ void lock_culture_groups();
+ CultureGroup const* get_culture_group_by_identifier(std::string const& identifier) const;
+ return_t add_culture(CultureGroup const* group, std::string const& identifier, colour_t colour, 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;
+ };
+}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
index 0a8c646..b095358 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -6,8 +6,11 @@
using namespace OpenVic;
-Pop::Pop(PopType const& new_type, Religion const& new_religion)
- : type { new_type }, religion { new_religion }, size { 1 } {
+Pop::Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion)
+ : type { new_type },
+ culture { new_culture },
+ religion { new_religion },
+ size { 1 } {
assert(size > 0);
}
@@ -15,6 +18,10 @@ PopType const& Pop::get_type() const {
return type;
}
+Culture const& Pop::get_culture() const {
+ return culture;
+}
+
Religion const& Pop::get_religion() const {
return religion;
}
@@ -23,7 +30,8 @@ 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,
+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 },
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index 51952b9..4d3f3e0 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -5,6 +5,7 @@
namespace OpenVic {
struct PopType;
+ struct Culture;
struct Religion;
/* REQUIREMENTS:
@@ -16,10 +17,11 @@ namespace OpenVic {
private:
PopType const& type;
+ Culture const& culture;
Religion const& religion;
pop_size_t size;
- Pop(PopType const& new_type, Religion const& new_religion);
+ Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion);
public:
Pop(Pop const&) = delete;
@@ -28,6 +30,7 @@ namespace OpenVic {
Pop& operator=(Pop&&) = delete;
PopType const& get_type() const;
+ Culture const& get_culture() const;
Religion const& get_religion() const;
pop_size_t get_size() const;
};
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
index e94476d..dddabf4 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -34,7 +34,7 @@ ReligionManager::ReligionManager()
return_t ReligionManager::add_religion_group(std::string const& identifier) {
if (identifier.empty()) {
- Logger::error("Invalid relgion group identifier - empty!");
+ Logger::error("Invalid religion group identifier - empty!");
return FAILURE;
}
return religion_groups.add_item({ identifier });
@@ -72,7 +72,7 @@ return_t ReligionManager::add_religion(ReligionGroup const* group, std::string c
return religions.add_item({ *group, identifier, colour, icon, pagan });
}
-void ReligionManager::lock_religion() {
+void ReligionManager::lock_religions() {
religions.lock();
}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index 043bb59..f141f45 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -48,7 +48,7 @@ namespace OpenVic {
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();
+ void lock_religions();
Religion const* get_religion_by_identifier(std::string const& identifier) const;
};
}