aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/military')
-rw-r--r--src/openvic-simulation/military/LeaderTrait.cpp35
-rw-r--r--src/openvic-simulation/military/LeaderTrait.hpp3
-rw-r--r--src/openvic-simulation/military/Wargoal.cpp3
3 files changed, 26 insertions, 15 deletions
diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp
index 978a3ed..08bb923 100644
--- a/src/openvic-simulation/military/LeaderTrait.cpp
+++ b/src/openvic-simulation/military/LeaderTrait.cpp
@@ -26,20 +26,33 @@ bool LeaderTraitManager::add_leader_trait(
}
bool LeaderTraitManager::load_leader_traits_file(ModifierManager const& modifier_manager, ast::NodeCPtr root) {
- using enum LeaderTrait::trait_type_t;
- const auto trait_callback = [this, &modifier_manager](LeaderTrait::trait_type_t type) -> key_value_callback_t {
- return [this, &modifier_manager, type](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, type, std::move(modifiers));
- return ret;
- };
+ const auto trait_callback = [this, &modifier_manager](LeaderTrait::trait_type_t type) -> NodeCallback auto {
+ return expect_dictionary_reserve_length(
+ leader_traits,
+ [this, &modifier_manager, type](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
+ static const string_set_t allowed_modifiers = {
+ "attack", "defence", "morale", "organisation", "reconnaissance",
+ "speed", "attrition", "experience", "reliability"
+ };
+
+ ModifierValue modifiers;
+ bool ret = modifier_manager.expect_whitelisted_modifier_value(
+ move_variable_callback(modifiers), allowed_modifiers
+ )(value);
+
+ ret &= add_leader_trait(trait_identifier, type, std::move(modifiers));
+ return ret;
+ }
+ );
};
+
+ using enum LeaderTrait::trait_type_t;
+
const bool ret = expect_dictionary_keys(
- "personality", ONE_EXACTLY, expect_dictionary(trait_callback(PERSONALITY)),
- "background", ONE_EXACTLY, expect_dictionary(trait_callback(BACKGROUND))
+ "personality", ONE_EXACTLY, trait_callback(PERSONALITY),
+ "background", ONE_EXACTLY, trait_callback(BACKGROUND)
)(root);
+
lock_leader_traits();
return ret;
diff --git a/src/openvic-simulation/military/LeaderTrait.hpp b/src/openvic-simulation/military/LeaderTrait.hpp
index 0d84814..7dd5217 100644
--- a/src/openvic-simulation/military/LeaderTrait.hpp
+++ b/src/openvic-simulation/military/LeaderTrait.hpp
@@ -44,9 +44,6 @@ namespace OpenVic {
struct LeaderTraitManager {
private:
IdentifierRegistry<LeaderTrait> IDENTIFIER_REGISTRY(leader_trait);
- static inline const string_set_t allowed_modifiers = {
- "attack", "defence", "morale", "organisation", "reconnaissance", "speed", "attrition", "experience", "reliability"
- };
public:
bool add_leader_trait(std::string_view identifier, LeaderTrait::trait_type_t type, ModifierValue&& modifiers);
diff --git a/src/openvic-simulation/military/Wargoal.cpp b/src/openvic-simulation/military/Wargoal.cpp
index 4045fa5..e81eaa0 100644
--- a/src/openvic-simulation/military/Wargoal.cpp
+++ b/src/openvic-simulation/military/Wargoal.cpp
@@ -69,7 +69,8 @@ bool WargoalTypeManager::add_wargoal_type(
}
bool WargoalTypeManager::load_wargoal_file(ast::NodeCPtr root) {
- bool ret = expect_dictionary(
+ bool ret = expect_dictionary_reserve_length(
+ wargoal_types,
[this](std::string_view identifier, ast::NodeCPtr value) -> bool {
if (identifier == "peace_order") {
return true;