diff options
Diffstat (limited to 'src/openvic-simulation/map/TerrainType.cpp')
-rw-r--r-- | src/openvic-simulation/map/TerrainType.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp index b4cc430..011a3c3 100644 --- a/src/openvic-simulation/map/TerrainType.cpp +++ b/src/openvic-simulation/map/TerrainType.cpp @@ -1,5 +1,8 @@ #include "TerrainType.hpp" +#include <string_view> + +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/types/Colour.hpp" using namespace OpenVic; @@ -16,6 +19,38 @@ TerrainTypeMapping::TerrainTypeMapping( ) : HasIdentifier { new_identifier }, type { new_type }, terrain_indices { std::move(new_terrain_indicies) }, priority { new_priority }, has_texture { new_has_texture } {} +bool TerrainTypeManager::generate_modifiers(ModifierManager& modifier_manager) const { + using enum ModifierEffect::format_t; + IndexedMap<TerrainType, ModifierEffectCache::unit_terrain_effects_t>& unit_terrain_effects = + modifier_manager.modifier_effect_cache.unit_terrain_effects; + + unit_terrain_effects.set_keys(&get_terrain_types()); + + constexpr bool has_no_effect = true; + bool ret = true; + for (TerrainType const& terrain_type : get_terrain_types()) { + const std::string_view identifier = terrain_type.get_identifier(); + ModifierEffectCache::unit_terrain_effects_t& this_unit_terrain_effects = unit_terrain_effects[terrain_type]; + ret &= modifier_manager.register_unit_terrain_modifier_effect( + this_unit_terrain_effects.attack, ModifierManager::get_flat_identifier("attack", identifier), true, + PROPORTION_DECIMAL, "UA_ATTACK", has_no_effect + ); + ret &= modifier_manager.register_unit_terrain_modifier_effect( + this_unit_terrain_effects.defence, ModifierManager::get_flat_identifier("defence", identifier), true, + PROPORTION_DECIMAL, "UA_DEFENCE", has_no_effect + ); + ret &= modifier_manager.register_unit_terrain_modifier_effect( + this_unit_terrain_effects.attrition, ModifierManager::get_flat_identifier("attrition", identifier), false, + RAW_DECIMAL, "UA_ATTRITION", has_no_effect + ); + ret &= modifier_manager.register_unit_terrain_modifier_effect( + this_unit_terrain_effects.movement, ModifierManager::get_flat_identifier("movement", identifier), true, + PROPORTION_DECIMAL, "UA_MOVEMENT" + ); + } + return ret; +} + bool TerrainTypeManager::add_terrain_type( std::string_view identifier, colour_t colour, ModifierValue&& values, bool is_water ) { @@ -74,11 +109,15 @@ node_callback_t TerrainTypeManager::_load_terrain_type_categories(ModifierManage ModifierValue values; colour_t colour = colour_t::null(); bool is_water = false; - bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values), + + bool ret = NodeTools::expect_dictionary_keys_and_default( + modifier_manager.expect_terrain_modifier(values), "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), "is_water", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_water)) )(type_node); + ret &= add_terrain_type(type_key, colour, std::move(values), is_water); + return ret; } )(root); |