aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic/pop')
-rw-r--r--src/openvic/pop/Culture.cpp10
-rw-r--r--src/openvic/pop/Culture.hpp4
-rw-r--r--src/openvic/pop/Pop.cpp61
-rw-r--r--src/openvic/pop/Pop.hpp34
-rw-r--r--src/openvic/pop/Religion.cpp2
-rw-r--r--src/openvic/pop/Religion.hpp2
6 files changed, 85 insertions, 28 deletions
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
index 05fc5fe..8f72f20 100644
--- a/src/openvic/pop/Culture.cpp
+++ b/src/openvic/pop/Culture.cpp
@@ -49,7 +49,7 @@ GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identi
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(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;
@@ -58,7 +58,11 @@ return_t CultureManager::add_culture_group(std::string const& identifier, Graphi
Logger::error("Invalid culture group identifier - empty!");
return FAILURE;
}
- return culture_groups.add_item({ identifier, graphical_culture_type });
+ if (graphical_culture_type == nullptr) {
+ Logger::error("Null graphical culture type for ", identifier);
+ return FAILURE;
+ }
+ return culture_groups.add_item({ identifier, *graphical_culture_type });
}
void CultureManager::lock_culture_groups() {
@@ -69,7 +73,7 @@ CultureGroup const* CultureManager::get_culture_group_by_identifier(std::string
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) {
+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) {
if (!culture_groups.is_locked()) {
Logger::error("Cannot register cultures until culture groups are locked!");
return FAILURE;
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
index ce49cd0..971ef71 100644
--- a/src/openvic/pop/Culture.hpp
+++ b/src/openvic/pop/Culture.hpp
@@ -63,10 +63,10 @@ namespace OpenVic {
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);
+ 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);
+ 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);
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 b095358..babcd25 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -2,15 +2,16 @@
#include <cassert>
+#include "../map/Province.hpp"
#include "../utility/Logger.hpp"
using namespace OpenVic;
-Pop::Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion)
+Pop::Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size)
: type { new_type },
culture { new_culture },
religion { new_religion },
- size { 1 } {
+ size { new_size } {
assert(size > 0);
}
@@ -33,7 +34,7 @@ Pop::pop_size_t Pop::get_size() const {
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)
+ bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave)
: HasIdentifier { new_identifier },
HasColour { new_colour, true },
strata { new_strata },
@@ -42,7 +43,8 @@ PopType::PopType(std::string const& new_identifier, colour_t new_colour,
merge_max_size { new_merge_max_size },
state_capital_only { new_state_capital_only },
demote_migrant { new_demote_migrant },
- is_artisan { new_is_artisan } {
+ is_artisan { new_is_artisan },
+ is_slave { new_is_slave } {
assert(sprite > 0);
assert(max_size > 0);
assert(merge_max_size > 0);
@@ -72,9 +74,35 @@ bool PopType::get_is_artisan() const {
return is_artisan;
}
-PopTypeManager::PopTypeManager() : pop_types { "pop types" } {}
+bool PopType::get_is_slave() const {
+ return is_slave;
+}
+
+PopManager::PopManager() : pop_types { "pop types" } {
+ 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.lock_culture_groups();
+
+ 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.lock_religion_groups();
+
+ religion_manager.add_religion("test_religion", 0xFF0000, religion_manager.get_religion_group_by_identifier("test_religion_group"), 1, false);
+ religion_manager.lock_religions();
-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) {
+ 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,
+ 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;
@@ -95,13 +123,28 @@ return_t PopTypeManager::add_pop_type(std::string const& identifier, colour_t co
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 });
+ return pop_types.add_item({ identifier, colour, strata, sprite, max_size, merge_max_size, state_capital_only, demote_migrant, is_artisan, is_slave });
}
-void PopTypeManager::lock_pop_types() {
+void PopManager::lock_pop_types() {
pop_types.lock();
}
-PopType const* PopTypeManager::get_pop_type_by_identifier(std::string const& identifier) const {
+PopType const* PopManager::get_pop_type_by_identifier(std::string const& 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");
+ province.add_pop({ type_poor, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index() * province.get_index()) * 1000 });
+ province.add_pop({ type_middle, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index()) * 1000 });
+ province.add_pop({ type_rich, culture, religion, static_cast<Pop::pop_size_t>(province.get_index()) * 1000 });
+ } else {
+ Logger::error("Cannot generate pops before pop types registry is locked!");
+ }
+}
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index 4d3f3e0..626cd8c 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -1,17 +1,19 @@
#pragma once
#include "../Types.hpp"
+#include "Culture.hpp"
+#include "Religion.hpp"
namespace OpenVic {
+ struct PopManager;
struct PopType;
- struct Culture;
- struct Religion;
/* REQUIREMENTS:
- * POP-18, POP-19, POP-21
+ * POP-18, POP-19, POP-20, POP-21
*/
struct Pop {
+ friend struct PopManager;
using pop_size_t = uint32_t;
@@ -21,7 +23,7 @@ namespace OpenVic {
Religion const& religion;
pop_size_t size;
- Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion);
+ Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size);
public:
Pop(Pop const&) = delete;
@@ -35,13 +37,11 @@ namespace OpenVic {
pop_size_t get_size() const;
};
- struct PopTypeManager;
-
/* REQUIREMENTS:
* POP-26
*/
struct PopType : HasIdentifier, HasColour {
- friend struct PopTypeManager;
+ friend struct PopManager;
using sprite_t = uint8_t;
@@ -53,11 +53,12 @@ namespace OpenVic {
} strata;
const sprite_t sprite;
const Pop::pop_size_t max_size, merge_max_size;
- const bool state_capital_only, demote_migrant, is_artisan;
+ const bool state_capital_only, demote_migrant, is_artisan, is_slave;
// 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);
+ 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, bool new_is_slave);
public:
PopType(PopType&&) = default;
@@ -68,17 +69,26 @@ namespace OpenVic {
bool get_state_capital_only() const;
bool get_demote_migrant() const;
bool get_is_artisan() const;
+ bool get_is_slave() const;
};
- struct PopTypeManager {
+ struct Province;
+
+ struct PopManager {
private:
IdentifierRegistry<PopType> pop_types;
+ CultureManager culture_manager;
+ ReligionManager religion_manager;
public:
- PopTypeManager();
+ PopManager();
- 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);
+ return_t add_pop_type(std::string const& 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;
+
+ void generate_test_pops(Province& province) const;
};
}
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
index dddabf4..a5b2abb 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -48,7 +48,7 @@ ReligionGroup const* ReligionManager::get_religion_group_by_identifier(std::stri
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) {
+return_t ReligionManager::add_religion(std::string const& 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;
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index f141f45..2a67ce3 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -47,7 +47,7 @@ namespace OpenVic {
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);
+ return_t add_religion(std::string const& 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;
};