aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military/LeaderTrait.cpp
diff options
context:
space:
mode:
author Joel Machens <ajmach6@gmail.com>2023-10-15 19:39:11 +0200
committer Joel Machens <ajmach6@gmail.com>2023-10-15 19:44:33 +0200
commitaf4758d399a75485b9adfeb3058a526eec3c8a4d (patch)
tree401556d0b45378c670b9101606a4fd98a207de27 /src/openvic-simulation/military/LeaderTrait.cpp
parent3249e21104bab6002676abe00450e7bd3f682303 (diff)
Implement Leader Trait Loading
Diffstat (limited to 'src/openvic-simulation/military/LeaderTrait.cpp')
-rw-r--r--src/openvic-simulation/military/LeaderTrait.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp
new file mode 100644
index 0000000..27f81c5
--- /dev/null
+++ b/src/openvic-simulation/military/LeaderTrait.cpp
@@ -0,0 +1,60 @@
+#include "LeaderTrait.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+LeaderTrait::LeaderTrait(std::string_view new_identifier, trait_type_t new_type, ModifierValue new_modifiers)
+ : HasIdentifier { new_identifier }, type { new_type }, modifiers { new_modifiers } {}
+
+trait_type_t LeaderTrait::get_trait_type() const {
+ return type;
+}
+
+bool LeaderTrait::is_personality_trait() const {
+ return type == trait_type_t::PERSONALITY;
+}
+
+bool LeaderTrait::is_background_trait() const {
+ return type == trait_type_t::BACKGROUND;
+}
+
+ModifierValue LeaderTrait::get_modifiers() const {
+ return modifiers;
+}
+
+LeaderTraitManager::LeaderTraitManager() : leader_traits { "leader_traits" } {}
+
+bool LeaderTraitManager::add_leader_trait(std::string_view identifier, trait_type_t type, ModifierValue modifiers) {
+ if (identifier.empty()) {
+ Logger::error("Invalid leader trait identifier - empty!");
+ return false;
+ }
+
+ return leader_traits.add_item({ identifier, type, modifiers });
+}
+
+bool LeaderTraitManager::load_leader_traits_file(ModifierManager& modifier_manager, ast::NodeCPtr root) {
+ bool ret = expect_dictionary_keys(
+ "personality", ONE_EXACTLY, expect_dictionary(
+ [this, &modifier_manager](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue modifiers;
+
+ bool ret = modifier_manager.expect_whitelisted_modifier_value(move_variable_callback(modifiers), allowed_modifiers)(value);
+ ret &= add_leader_trait(trait_identifier, trait_type_t::PERSONALITY, modifiers);
+ return ret;
+ }
+ ),
+ "background", ONE_EXACTLY, expect_dictionary(
+ [this, &modifier_manager](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue modifiers;
+
+ bool ret = modifier_manager.expect_whitelisted_modifier_value(move_variable_callback(modifiers), allowed_modifiers)(value);
+ ret &= add_leader_trait(trait_identifier, trait_type_t::BACKGROUND, modifiers);
+ return ret;
+ }
+ )
+ )(root);
+ lock_leader_traits();
+
+ return ret;
+} \ No newline at end of file