aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-09 23:49:54 +0200
committer GitHub <noreply@github.com>2023-09-09 23:49:54 +0200
commit6278a35f4704574933464700026d8deb997da5c1 (patch)
treeeb36a9b030b263d825eb93638e64deb0dbd38a78 /src/openvic/pop
parentbec619fc8f554cb075fcef2428f3b6bdb5e88e82 (diff)
parent3d7fbd9b376811ca0ed226fa78bcc8b6279ba8dc (diff)
Merge pull request #14 from OpenVicProject/dataloading
Dataloading scaffolding + basic culture and pop history loading
Diffstat (limited to 'src/openvic/pop')
-rw-r--r--src/openvic/pop/Culture.cpp102
-rw-r--r--src/openvic/pop/Culture.hpp73
-rw-r--r--src/openvic/pop/Pop.cpp180
-rw-r--r--src/openvic/pop/Pop.hpp99
-rw-r--r--src/openvic/pop/Religion.cpp80
-rw-r--r--src/openvic/pop/Religion.hpp54
6 files changed, 0 insertions, 588 deletions
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
deleted file mode 100644
index f50bb23..0000000
--- a/src/openvic/pop/Culture.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "Culture.hpp"
-
-#include <cassert>
-
-using namespace OpenVic;
-
-GraphicalCultureType::GraphicalCultureType(const std::string_view new_identifier) : HasIdentifier { 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 } {}
-
-GraphicalCultureType const& CultureGroup::get_unit_graphical_culture_type() const {
- return unit_graphical_culture_type;
-}
-
-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 } {
-}
-
-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(const std::string_view 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(const std::string_view identifier) const {
- return graphical_culture_types.get_item_by_identifier(identifier);
-}
-
-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;
- }
- if (identifier.empty()) {
- Logger::error("Invalid culture group identifier - empty!");
- return FAILURE;
- }
- 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() {
- culture_groups.lock();
-}
-
-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(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;
- }
- 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({ identifier, colour, *group, first_names, last_names });
-}
-
-void CultureManager::lock_cultures() {
- cultures.lock();
-}
-
-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
deleted file mode 100644
index 645e226..0000000
--- a/src/openvic/pop/Culture.hpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#pragma once
-
-#include "../Types.hpp"
-
-namespace OpenVic {
-
- struct CultureManager;
-
- struct GraphicalCultureType : HasIdentifier {
- friend struct CultureManager;
-
- private:
- GraphicalCultureType(const std::string_view 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(const std::string_view new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type);
-
- public:
- CultureGroup(CultureGroup&&) = default;
-
- GraphicalCultureType const& get_unit_graphical_culture_type() const;
- };
-
- struct Culture : HasIdentifierAndColour {
- 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(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;
-
- 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(const std::string_view identifier);
- void lock_graphical_culture_types();
- 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(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(const std::string_view identifier) const;
- };
-}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
deleted file mode 100644
index 81915f6..0000000
--- a/src/openvic/pop/Pop.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-#include "Pop.hpp"
-
-#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_size_t new_size)
- : type { new_type },
- culture { new_culture },
- religion { new_religion },
- size { new_size } {
- assert(size > 0);
-}
-
-PopType const& Pop::get_type() const {
- return type;
-}
-
-Culture const& Pop::get_culture() const {
- return culture;
-}
-
-Religion const& Pop::get_religion() const {
- return religion;
-}
-
-Pop::pop_size_t Pop::get_size() const {
- return size;
-}
-
-Pop::pop_size_t Pop::get_num_promoted() const {
- return num_promoted;
-}
-
-Pop::pop_size_t Pop::get_num_demoted() const {
- return num_demoted;
-}
-
-Pop::pop_size_t Pop::get_num_migrated() const {
- return num_migrated;
-}
-
-Pop::pop_size_t Pop::get_pop_daily_change() const {
- return Pop::get_num_promoted() - (Pop::get_num_demoted() + Pop::get_num_migrated());
-}
-
-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)
- : HasIdentifierAndColour { new_identifier, 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 },
- is_slave { new_is_slave } {
- assert(sprite > 0);
- assert(max_size > 0);
- assert(merge_max_size > 0);
-}
-
-PopType::sprite_t PopType::get_sprite() const {
- return sprite;
-}
-
-PopType::strata_t PopType::get_strata() const {
- return strata;
-}
-
-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;
-}
-
-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.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();
-
- 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(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;
- }
- 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, is_slave });
-}
-
-void PopManager::lock_pop_types() {
- pop_types.lock();
-}
-
-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);
-
- 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 });
- } 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
deleted file mode 100644
index db9633f..0000000
--- a/src/openvic/pop/Pop.hpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#pragma once
-
-#include "../Types.hpp"
-#include "Culture.hpp"
-#include "Religion.hpp"
-
-namespace OpenVic {
-
- struct PopManager;
- struct PopType;
-
- /* REQUIREMENTS:
- * POP-18, POP-19, POP-20, POP-21
- */
- struct Pop {
- friend struct PopManager;
-
- using pop_size_t = int64_t;
-
- private:
- PopType const& type;
- Culture const& culture;
- Religion const& religion;
- pop_size_t size, num_migrated, num_promoted, num_demoted, num_migrated;
-
- Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size);
-
- public:
- Pop(Pop const&) = delete;
- Pop(Pop&&) = default;
- Pop& operator=(Pop const&) = delete;
- 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;
- pop_size_t get_num_promoted() const;
- pop_size_t get_num_demoted() const;
- pop_size_t get_num_migrated() const;
- pop_size_t get_pop_daily_change() const;
- };
-
- /* REQUIREMENTS:
- * POP-26
- */
- struct PopType : HasIdentifierAndColour {
- friend struct PopManager;
-
- 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, is_slave;
-
- // TODO - rebel composition, life/everyday/luxury needs, country and province migration targets, promote_to targets, ideologies and issues
-
- 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:
- PopType(PopType&&) = default;
-
- strata_t get_strata() const;
- 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;
- bool get_is_slave() const;
- };
-
- struct Province;
-
- struct PopManager {
- private:
- IdentifierRegistry<PopType> pop_types;
- CultureManager culture_manager;
- ReligionManager religion_manager;
-
- public:
- PopManager();
-
- 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(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
deleted file mode 100644
index 0cfc7a6..0000000
--- a/src/openvic/pop/Religion.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-#include "Religion.hpp"
-
-#include <cassert>
-
-using namespace OpenVic;
-
-ReligionGroup::ReligionGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-
-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);
-}
-
-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(const std::string_view identifier) {
- if (identifier.empty()) {
- Logger::error("Invalid religion 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(const std::string_view identifier) const {
- return religion_groups.get_item_by_identifier(identifier);
-}
-
-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;
- }
- 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({ identifier, colour, *group, icon, pagan });
-}
-
-void ReligionManager::lock_religions() {
- religions.lock();
-}
-
-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
deleted file mode 100644
index 4eb3e4c..0000000
--- a/src/openvic/pop/Religion.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#pragma once
-
-#include "../Types.hpp"
-
-namespace OpenVic {
-
- struct ReligionManager;
-
- struct ReligionGroup : HasIdentifier {
- friend struct ReligionManager;
-
- private:
- ReligionGroup(const std::string_view new_identifier);
-
- public:
- ReligionGroup(ReligionGroup&&) = default;
- };
-
- struct Religion : HasIdentifierAndColour {
- friend struct ReligionManager;
-
- using icon_t = uint8_t;
-
- private:
- ReligionGroup const& group;
- const icon_t icon;
- const bool 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;
-
- 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(const std::string_view identifier);
- void lock_religion_groups();
- 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(const std::string_view identifier) const;
- };
-}