aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-10-26 18:25:15 +0200
committer GitHub <noreply@github.com>2024-10-26 18:25:15 +0200
commit8d9ff3266439c6a94c35fdf0d8a0642a2cb34de3 (patch)
tree46039d0eb5d630cf000e94aed584aebaaa8f3f9b /src/openvic-simulation/military
parentc88cf59997529cbca008f9a2b629822de9deaa2a (diff)
parent3daebe5db14949f55be2c50220323138260dbaea (diff)
Merge pull request #210 from OpenVicProject/contextual_modifier_parsing
Contextual modifier parsing
Diffstat (limited to 'src/openvic-simulation/military')
-rw-r--r--src/openvic-simulation/military/Deployment.cpp2
-rw-r--r--src/openvic-simulation/military/LeaderTrait.cpp12
-rw-r--r--src/openvic-simulation/military/UnitType.cpp14
3 files changed, 10 insertions, 18 deletions
diff --git a/src/openvic-simulation/military/Deployment.cpp b/src/openvic-simulation/military/Deployment.cpp
index bd176be..27cd124 100644
--- a/src/openvic-simulation/military/Deployment.cpp
+++ b/src/openvic-simulation/military/Deployment.cpp
@@ -144,7 +144,7 @@ bool DeploymentManager::load_oob_file(
return false;
}
- army_regiments.push_back({regiment_name, *regiment_type, regiment_home});
+ army_regiments.push_back({ regiment_name, *regiment_type, regiment_home });
return ret;
},
diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp
index 7835636..e00deec 100644
--- a/src/openvic-simulation/military/LeaderTrait.cpp
+++ b/src/openvic-simulation/military/LeaderTrait.cpp
@@ -1,5 +1,6 @@
#include "LeaderTrait.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/modifier/ModifierManager.hpp"
using namespace OpenVic;
@@ -32,17 +33,10 @@ bool LeaderTraitManager::load_leader_traits_file(ModifierManager const& modifier
return expect_dictionary_reserve_length(
leader_traits,
[this, &modifier_manager, type](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
- using enum Modifier::modifier_type_t;
-
- static const string_set_t allowed_modifiers = {
- "attack", "defence leader", "morale", "organisation", "reconnaissance",
- "speed", "attrition", "experience", "reliability"
- };
-
ModifierValue modifiers;
- bool ret = modifier_manager.expect_whitelisted_modifier_value(
- move_variable_callback(modifiers), LEADER, allowed_modifiers
+ bool ret = NodeTools::expect_dictionary(
+ modifier_manager.expect_leader_modifier(modifiers)
)(value);
ret &= add_leader_trait(trait_identifier, type, std::move(modifiers));
diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp
index 22e108d..920f28b 100644
--- a/src/openvic-simulation/military/UnitType.cpp
+++ b/src/openvic-simulation/military/UnitType.cpp
@@ -1,6 +1,7 @@
#include "UnitType.hpp"
#include "openvic-simulation/country/CountryInstance.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/map/TerrainType.hpp"
#include "openvic-simulation/modifier/ModifierManager.hpp"
@@ -247,11 +248,9 @@ bool UnitTypeManager::load_unit_type_file(
TerrainType const* terrain_type = terrain_type_manager.get_terrain_type_by_identifier(default_key);
if (terrain_type != nullptr) {
- using enum Modifier::modifier_type_t;
-
- // TODO - restrict what modifier effects can be used here
- return modifier_manager.expect_modifier_value(
- map_callback(unit_args.terrain_modifier_values, terrain_type), UNIT_TERRAIN
+ ModifierValue& modifier_value = unit_args.terrain_modifier_values[terrain_type];
+ return expect_dictionary(
+ modifier_manager.expect_unit_terrain_modifier(modifier_value, terrain_type->get_identifier())
)(default_value);
}
@@ -336,14 +335,13 @@ bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) cons
std::derived_from<ModifierEffectCache::unit_type_effects_t> auto unit_type_effects, std::string_view identifier
) -> void {
using enum ModifierEffect::format_t;
- using enum ModifierEffect::target_t;
const auto stat_modifier = [&modifier_manager, &ret, &identifier](
ModifierEffect const*& effect_cache, std::string_view suffix, bool is_positive_good,
ModifierEffect::format_t format, std::string_view localisation_key
) -> void {
- ret &= modifier_manager.add_modifier_effect(
- effect_cache, ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format, COUNTRY,
+ ret &= modifier_manager.register_technology_modifier_effect(
+ effect_cache, ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format,
StringUtils::append_string_views("$", identifier, "$: $", localisation_key, "$")
);
};