aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military/LeaderTrait.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-01-24 01:47:16 +0100
committer GitHub <noreply@github.com>2024-01-24 01:47:16 +0100
commit6bcb1e70a15755ceb0aaa13a080f85f8edb50911 (patch)
treeb30e9b5774130552fe97e27deaf0370d83920c43 /src/openvic-simulation/military/LeaderTrait.cpp
parentd4e597da089a81f719a9c33b46111d1c2c590124 (diff)
parent268a6948c0400905dfc335427395519689f067f5 (diff)
Merge pull request #137 from OpenVicProject/reserve_more
Added reserve_more, expect_dictionary_key[s|_map]_reserve_length[_and_default]
Diffstat (limited to 'src/openvic-simulation/military/LeaderTrait.cpp')
-rw-r--r--src/openvic-simulation/military/LeaderTrait.cpp35
1 files changed, 24 insertions, 11 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;