From b1349e8dfa0c840ca82472fb7f342de08ed8804b Mon Sep 17 00:00:00 2001 From: zaaarf Date: Tue, 19 Sep 2023 19:26:22 +0200 Subject: feat: added Ideology and IdeologyGroup data structures --- src/openvic-simulation/politics/Ideology.cpp | 48 +++++++++++++++++++++++++ src/openvic-simulation/politics/Ideology.hpp | 53 ++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/openvic-simulation/politics/Ideology.cpp create mode 100644 src/openvic-simulation/politics/Ideology.hpp diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp new file mode 100644 index 0000000..5430140 --- /dev/null +++ b/src/openvic-simulation/politics/Ideology.cpp @@ -0,0 +1,48 @@ +#include "Ideology.hpp" +#include "types/IdentifierRegistry.hpp" + +using namespace OpenVic; + +IdeologyGroup::IdeologyGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {} + +Ideology::Ideology(const std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool uncivilised, Date spawn_date) + : HasIdentifierAndColour { new_identifier, new_colour, true, false }, group { new_group }, uncivilised { uncivilised }, + spawn_date { spawn_date } {} + +bool Ideology::is_uncivilised() const { + return uncivilised; +} + +Date const& Ideology::get_spawn_date() const { + return spawn_date; +} + +IdeologyManager::IdeologyManager() : ideology_groups { "ideology groups" }, ideologies { "ideologies" } {} + +bool IdeologyManager::add_ideology_group(const std::string_view identifier) { + if (identifier.empty()) { + Logger::error("Invalid ideology group identifier - empty!"); + return false; + } + + return ideology_groups.add_item({ identifier }); +} + +bool IdeologyManager::add_ideology(const std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, Date spawn_date) { + if (identifier.empty()) { + Logger::error("Invalid ideology identifier - empty!"); + return false; + } + + if (colour > MAX_COLOUR_RGB) { + Logger::error("Invalid ideology colour for ", identifier, ": ", colour_to_hex_string(colour)); + return false; + } + + if (group == nullptr) { + Logger::error("Null ideology group for ", identifier); + return false; + } + + return ideologies.add_item({ identifier, colour, identifier, uncivilised, spawn_date }); +} \ No newline at end of file diff --git a/src/openvic-simulation/politics/Ideology.hpp b/src/openvic-simulation/politics/Ideology.hpp new file mode 100644 index 0000000..b3227f7 --- /dev/null +++ b/src/openvic-simulation/politics/Ideology.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include "types/Date.hpp" +#include "types/IdentifierRegistry.hpp" + +namespace OpenVic { + struct IdeologyManager; + + struct IdeologyGroup : HasIdentifier { + friend struct IdeologyManager; + + private: + IdeologyGroup(const std::string_view new_identifier); + + public: + IdeologyGroup(IdeologyGroup&&) = default; + }; + + struct Ideology : HasIdentifierAndColour { + friend struct IdeologyManager; + + private: + IdeologyGroup const& group; + const bool uncivilised; + const Date spawn_date; + + //TODO - willingness to repeal/pass reforms (and its modifiers) + + Ideology(const std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool uncivilised, Date spawn_date); + + public: + Ideology(Ideology&&) = default; + bool is_uncivilised() const; + Date const& get_spawn_date() const; + }; + + struct IdeologyManager { + private: + IdentifierRegistry ideology_groups; + IdentifierRegistry ideologies; + + public: + IdeologyManager(); + + bool add_ideology_group(const std::string_view identifier); + IDENTIFIER_REGISTRY_ACCESSORS(IdeologyGroup, ideology_group) + + bool add_ideology(const std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, Date spawn_date); + IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(Ideology, ideology, ideologies) + + //TODO - loaders + }; +} \ No newline at end of file -- cgit v1.2.3-56-ga3b1