diff options
author | Hop311 <Hop3114@gmail.com> | 2024-09-20 14:11:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 14:11:27 +0200 |
commit | 89b1333b1edff6c08750bd836ae92eccbe06e3bd (patch) | |
tree | ed4e867e2c099b027da2e2205b99575edae7b561 /src/openvic-simulation | |
parent | f0814926f675d6ecf889d8add410b1c37f625b29 (diff) | |
parent | 5550b237fa9b6f8c6a86eea0de9d32e28a626dc7 (diff) |
Merge pull request #201 from OpenVicProject/rule-modifier-locale-keys
ModifierEffect and Rule localisation keys
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r-- | src/openvic-simulation/economy/BuildingType.cpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/economy/BuildingType.hpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/economy/EconomyManager.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/economy/GoodDefinition.cpp | 41 | ||||
-rw-r--r-- | src/openvic-simulation/military/UnitType.cpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 249 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.hpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rebel.cpp | 11 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 34 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.hpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/research/Technology.cpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/utility/StringUtils.hpp | 16 |
13 files changed, 276 insertions, 126 deletions
diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index f0fc8a8..a20aa36 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -113,13 +113,17 @@ bool BuildingTypeManager::load_buildings_file( lock_building_types(); for (BuildingType const& building_type : building_types.get_items()) { + using enum ModifierEffect::format_t; + static constexpr std::string_view max_prefix = "max_"; static constexpr std::string_view min_prefix = "min_build_"; ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(max_prefix, building_type.get_identifier()), true, ModifierEffect::format_t::INT + StringUtils::append_string_views(max_prefix, building_type.get_identifier()), true, INT, + StringUtils::append_string_views("$", building_type.get_identifier(), "$ $TECH_MAX_LEVEL$") ); + // TODO - add custom localisation for "min_build_$building_type$" modifiers ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(min_prefix, building_type.get_identifier()), false, ModifierEffect::format_t::INT + StringUtils::append_string_views(min_prefix, building_type.get_identifier()), false, INT ); if (building_type.is_in_province()) { diff --git a/src/openvic-simulation/economy/BuildingType.hpp b/src/openvic-simulation/economy/BuildingType.hpp index e28dd86..d9a9bd0 100644 --- a/src/openvic-simulation/economy/BuildingType.hpp +++ b/src/openvic-simulation/economy/BuildingType.hpp @@ -7,7 +7,6 @@ #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" - namespace OpenVic { struct BuildingTypeManager; diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp index 7f0520d..5257e6a 100644 --- a/src/openvic-simulation/economy/EconomyManager.hpp +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -1,12 +1,11 @@ #pragma once +#include <openvic-dataloader/v2script/Parser.hpp> + #include "openvic-simulation/economy/BuildingType.hpp" #include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/economy/production/ProductionType.hpp" -#include "openvic-dataloader/v2script/Parser.hpp" - - namespace OpenVic { struct EconomyManager { private: diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index f21ea18..82d3719 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -88,29 +88,46 @@ bool GoodDefinitionManager::load_goods_file(ast::NodeCPtr root) { } bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager) const { + using enum ModifierEffect::format_t; + bool ret = true; - const auto good_modifier = [this, &modifier_manager, &ret](std::string_view name, bool is_positive_good) -> void { + const auto good_modifier = [this, &modifier_manager, &ret]( + std::string_view name, bool is_positive_good, auto make_localisation_suffix + ) -> void { ret &= modifier_manager.register_complex_modifier(name); + for (GoodDefinition const& good : get_good_definitions()) { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(name, good.get_identifier()), is_positive_good + ModifierManager::get_flat_identifier(name, good.get_identifier()), is_positive_good, PROPORTION_DECIMAL, + make_localisation_suffix(good.get_identifier()) ); } }; - good_modifier("artisan_goods_input", false); - good_modifier("artisan_goods_output", true); - good_modifier("artisan_goods_throughput", true); - good_modifier("factory_goods_input", false); - good_modifier("factory_goods_output", true); - good_modifier("factory_goods_throughput", true); - good_modifier("rgo_goods_output", true); - good_modifier("rgo_goods_throughput", true); - good_modifier("rgo_size", true); + const auto make_production_localisation_suffix = [](std::string_view localisation_suffix) -> auto { + return [localisation_suffix](std::string_view good_identifier) -> std::string { + return StringUtils::append_string_views("$", good_identifier, "$ $", localisation_suffix, "$"); + }; + }; + + good_modifier("artisan_goods_input", false, make_production_localisation_suffix("TECH_INPUT")); + good_modifier("artisan_goods_output", true, make_production_localisation_suffix("TECH_OUTPUT")); + good_modifier("artisan_goods_throughput", true, make_production_localisation_suffix("TECH_THROUGHPUT")); + good_modifier("factory_goods_input", false, make_production_localisation_suffix("TECH_INPUT")); + good_modifier("factory_goods_output", true, make_production_localisation_suffix("TECH_OUTPUT")); + good_modifier("factory_goods_throughput", true, make_production_localisation_suffix("TECH_THROUGHPUT")); + good_modifier("rgo_goods_output", true, make_production_localisation_suffix("TECH_OUTPUT")); + good_modifier("rgo_goods_throughput", true, make_production_localisation_suffix("TECH_THROUGHPUT")); + good_modifier("rgo_size", true, [](std::string_view good_identifier) -> std::string { + return StringUtils::append_string_views(good_identifier, "_RGO_SIZE"); + }); for (GoodDefinition const& good : get_good_definitions()) { - ret &= modifier_manager.add_modifier_effect(good.get_identifier(), true, ModifierEffect::format_t::PERCENTAGE_DECIMAL); + ret &= modifier_manager.add_modifier_effect( + good.get_identifier(), true, PERCENTAGE_DECIMAL, + StringUtils::append_string_views("$ENCOURAGEMENT_FOR$$", good.get_identifier(), "$") + ); } return ret; diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index d4ffbee..1c111cc 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -318,12 +318,15 @@ bool UnitTypeManager::load_unit_type_file( bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) const { bool ret = true; - const auto generate_stat_modifiers = [&modifier_manager, &ret](std::string_view identifier, UnitType::branch_t branch) -> void { + const auto generate_stat_modifiers = [&modifier_manager, &ret]( + std::string_view identifier, UnitType::branch_t branch + ) -> void { const auto stat_modifier = [&modifier_manager, &ret, &identifier]( std::string_view suffix, bool is_positive_good, ModifierEffect::format_t format ) -> void { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format + ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format, + StringUtils::append_string_views("$", identifier, "$: $", suffix, "$") ); }; diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 9163af5..e201fdd 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -12,8 +12,16 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -ModifierEffect::ModifierEffect(std::string_view new_identifier, bool new_positive_good, format_t new_format) - : HasIdentifier { new_identifier }, positive_good { new_positive_good }, format { new_format } {} +static std::string make_default_modifier_effect_localisation_key(std::string_view identifier) { + return "MODIFIER_" + StringUtils::string_toupper(identifier); +} + +ModifierEffect::ModifierEffect( + std::string_view new_identifier, bool new_positive_good, format_t new_format, std::string_view new_localisation_key +) : HasIdentifier { new_identifier }, positive_good { new_positive_good }, format { new_format }, + localisation_key { + new_localisation_key.empty() ? make_default_modifier_effect_localisation_key(new_identifier) : new_localisation_key + } {} ModifierValue::ModifierValue() = default; ModifierValue::ModifierValue(effect_map_t&& new_values) : values { std::move(new_values) } {} @@ -105,12 +113,14 @@ bool TriggeredModifier::parse_scripts(DefinitionManager const& definition_manage ModifierInstance::ModifierInstance(Modifier const& modifier, Date expiry_date) : modifier { modifier }, expiry_date { expiry_date } {} -bool ModifierManager::add_modifier_effect(std::string_view identifier, bool positive_good, ModifierEffect::format_t format) { +bool ModifierManager::add_modifier_effect( + std::string_view identifier, bool positive_good, ModifierEffect::format_t format, std::string_view localisation_key +) { if (identifier.empty()) { Logger::error("Invalid modifier effect identifier - empty!"); return false; } - return modifier_effects.add_item({ std::move(identifier), positive_good, format }); + return modifier_effects.add_item({ std::move(identifier), positive_good, format, localisation_key }); } bool ModifierManager::setup_modifier_effects() { @@ -118,88 +128,127 @@ bool ModifierManager::setup_modifier_effects() { using enum ModifierEffect::format_t; /* Tech/inventions only */ - ret &= add_modifier_effect("cb_creation_speed", true); + ret &= add_modifier_effect("cb_creation_speed", true, PROPORTION_DECIMAL, "CB_MANUFACTURE_TECH"); ret &= add_modifier_effect("combat_width", false); - ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL); - ret &= add_modifier_effect("pop_growth", true); - ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL); - ret &= add_modifier_effect("reinforce_rate", true); - ret &= add_modifier_effect("seperatism", false); // paradox typo - ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL); - ret &= add_modifier_effect("tax_eff", true); + ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL, "TECH_PLURALITY"); + ret &= add_modifier_effect("pop_growth", true, PROPORTION_DECIMAL, "TECH_POP_GROWTH"); + ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL, "REGULAR_EXP_TECH"); + ret &= add_modifier_effect("reinforce_rate", true, PROPORTION_DECIMAL, "REINFORCE_TECH"); + ret &= add_modifier_effect("seperatism", false, PROPORTION_DECIMAL, "SEPARATISM_TECH"); // paradox typo + ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL, "SHARED_PRESTIGE_TECH"); + ret &= add_modifier_effect("tax_eff", true, PROPORTION_DECIMAL, "TECH_TAX_EFF"); /* Country Modifier Effects */ ret &= add_modifier_effect("administrative_efficiency", true); - ret &= add_modifier_effect("administrative_efficiency_modifier", true); + ret &= add_modifier_effect( + "administrative_efficiency_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("administrative_efficiency") + ); ret &= add_modifier_effect("artisan_input", false); ret &= add_modifier_effect("artisan_output", true); ret &= add_modifier_effect("artisan_throughput", true); ret &= add_modifier_effect("badboy", false, RAW_DECIMAL); ret &= add_modifier_effect("cb_generation_speed_modifier", true); - ret &= add_modifier_effect("civilization_progress_modifier", true); - ret &= add_modifier_effect("colonial_life_rating", false, INT); - ret &= add_modifier_effect("colonial_migration", true); - ret &= add_modifier_effect("colonial_points", true, INT); - ret &= add_modifier_effect("colonial_prestige", true); + ret &= add_modifier_effect( + "civilization_progress_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("civilization_progress") + ); + ret &= add_modifier_effect("colonial_life_rating", false, INT, "COLONIAL_LIFE_TECH"); + ret &= add_modifier_effect("colonial_migration", true, PROPORTION_DECIMAL, "COLONIAL_MIGRATION_TECH"); + ret &= add_modifier_effect("colonial_points", true, INT, "COLONIAL_POINTS_TECH"); + ret &= add_modifier_effect("colonial_prestige", true, PROPORTION_DECIMAL, "COLONIAL_PRESTIGE_MODIFIER_TECH"); ret &= add_modifier_effect("core_pop_consciousness_modifier", false, RAW_DECIMAL); ret &= add_modifier_effect("core_pop_militancy_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("dig_in_cap", true, INT); - ret &= add_modifier_effect("diplomatic_points", true); - ret &= add_modifier_effect("diplomatic_points_modifier", true); + ret &= add_modifier_effect("dig_in_cap", true, INT, "DIGIN_FROM_TECH"); + ret &= add_modifier_effect("diplomatic_points", true, PROPORTION_DECIMAL, "DIPLOMATIC_POINTS_TECH"); + ret &= add_modifier_effect( + "diplomatic_points_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("diplopoints_gain") + ); ret &= add_modifier_effect("education_efficiency", true); - ret &= add_modifier_effect("education_efficiency_modifier", true); + ret &= add_modifier_effect( + "education_efficiency_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("education_efficiency") + ); ret &= add_modifier_effect("factory_cost", false); ret &= add_modifier_effect("factory_input", false); ret &= add_modifier_effect("factory_maintenance", false); ret &= add_modifier_effect("factory_output", true); ret &= add_modifier_effect("factory_owner_cost", false); ret &= add_modifier_effect("factory_throughput", true); - ret &= add_modifier_effect("global_assimilation_rate", true); - ret &= add_modifier_effect("global_immigrant_attract", true); + ret &= add_modifier_effect( + "global_assimilation_rate", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("assimilation_rate") + ); + ret &= add_modifier_effect( + "global_immigrant_attract", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("immigant_attract") + ); ret &= add_modifier_effect("global_pop_consciousness_modifier", false, RAW_DECIMAL); ret &= add_modifier_effect("global_pop_militancy_modifier", false, RAW_DECIMAL); - ret &= add_modifier_effect("global_population_growth", true); + ret &= add_modifier_effect( + "global_population_growth", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("population_growth") + ); ret &= add_modifier_effect("goods_demand", false); ret &= add_modifier_effect("import_cost", false); - ret &= add_modifier_effect("increase_research", true); - ret &= add_modifier_effect("influence", true); - ret &= add_modifier_effect("influence_modifier", true); + ret &= add_modifier_effect("increase_research", true, PROPORTION_DECIMAL, "INC_RES_TECH"); + ret &= add_modifier_effect("influence", true, PROPORTION_DECIMAL, "TECH_GP_INFLUENCE"); + ret &= add_modifier_effect( + "influence_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("greatpower_influence_gain") + ); ret &= add_modifier_effect("issue_change_speed", true); - ret &= add_modifier_effect("land_attack_modifier", true); - ret &= add_modifier_effect("land_attrition", false); - ret &= add_modifier_effect("land_defense_modifier", true); + ret &= add_modifier_effect( + "land_attack_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("land_attack") + ); + ret &= add_modifier_effect("land_attrition", false, PROPORTION_DECIMAL, "LAND_ATTRITION_TECH"); + ret &= add_modifier_effect( + "land_defense_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("land_defense") + ); ret &= add_modifier_effect("land_organisation", true); ret &= add_modifier_effect("land_unit_start_experience", true, RAW_DECIMAL); - ret &= add_modifier_effect("leadership", true, RAW_DECIMAL); - ret &= add_modifier_effect("leadership_modifier", true); + ret &= add_modifier_effect("leadership", true, RAW_DECIMAL, "LEADERSHIP"); + ret &= add_modifier_effect( + "leadership_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("global_leadership_modifier") + ); ret &= add_modifier_effect("literacy_con_impact", false); ret &= add_modifier_effect("loan_interest", false); - ret &= add_modifier_effect("max_loan_modifier", true); + ret &= add_modifier_effect( + "max_loan_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("max_loan_amount") + ); ret &= add_modifier_effect("max_military_spending", true); - ret &= add_modifier_effect("max_national_focus", true, INT); + ret &= add_modifier_effect("max_national_focus", true, INT, "TECH_MAX_FOCUS"); ret &= add_modifier_effect("max_social_spending", true); ret &= add_modifier_effect("max_tariff", true); ret &= add_modifier_effect("max_tax", true); - ret &= add_modifier_effect("max_war_exhaustion", true, PERCENTAGE_DECIMAL); - ret &= add_modifier_effect("military_tactics", true); + ret &= add_modifier_effect("max_war_exhaustion", true, PERCENTAGE_DECIMAL, "MAX_WAR_EXHAUSTION"); + ret &= add_modifier_effect("military_tactics", true, PROPORTION_DECIMAL, "MIL_TACTICS_TECH"); ret &= add_modifier_effect("min_military_spending", true); ret &= add_modifier_effect("min_social_spending", true); ret &= add_modifier_effect("min_tariff", true); ret &= add_modifier_effect("min_tax", true); - ret &= add_modifier_effect("minimum_wage", true); + ret &= add_modifier_effect( + "minimum_wage", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("minimun_wage") + ); ret &= add_modifier_effect("mobilisation_economy_impact", false); ret &= add_modifier_effect("mobilisation_size", true); ret &= add_modifier_effect("mobilization_impact", false); - ret &= add_modifier_effect("naval_attack_modifier", true); - ret &= add_modifier_effect("naval_attrition", false); - ret &= add_modifier_effect("naval_defense_modifier", true); + ret &= add_modifier_effect( + "naval_attack_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("naval_attack") + ); + ret &= add_modifier_effect("naval_attrition", false, PROPORTION_DECIMAL, "NAVAL_ATTRITION_TECH"); + ret &= add_modifier_effect( + "naval_defense_modifier", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("naval_defense") + ); ret &= add_modifier_effect("naval_organisation", true); ret &= add_modifier_effect("naval_unit_start_experience", true, RAW_DECIMAL); ret &= add_modifier_effect("non_accepted_pop_consciousness_modifier", false, RAW_DECIMAL); ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL); ret &= add_modifier_effect("org_regain", true); ret &= add_modifier_effect("pension_level", true); - ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL); + ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL, "PERMANENT_PRESTIGE_TECH"); ret &= add_modifier_effect("political_reform_desire", false); ret &= add_modifier_effect("poor_savings_modifier", true); ret &= add_modifier_effect("prestige", true, RAW_DECIMAL); @@ -210,47 +259,92 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("rgo_output", true); ret &= add_modifier_effect("rgo_throughput", true); ret &= add_modifier_effect("ruling_party_support", true); - ret &= add_modifier_effect("self_unciv_economic_modifier", false); - ret &= add_modifier_effect("self_unciv_military_modifier", false); + ret &= add_modifier_effect( + "self_unciv_economic_modifier", false, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("self_unciv_economic") + ); + ret &= add_modifier_effect( + "self_unciv_military_modifier", false, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("self_unciv_military") + ); ret &= add_modifier_effect("social_reform_desire", false); - ret &= add_modifier_effect("soldier_to_pop_loss", true); + ret &= add_modifier_effect("soldier_to_pop_loss", true, PROPORTION_DECIMAL, "SOLDIER_TO_POP_LOSS_TECH"); ret &= add_modifier_effect("supply_consumption", false); - ret &= add_modifier_effect("supply_range", true); - ret &= add_modifier_effect("suppression_points_modifier", true); - ret &= add_modifier_effect("tariff_efficiency_modifier", true); + ret &= add_modifier_effect("supply_range", true, PROPORTION_DECIMAL, "SUPPLY_RANGE_TECH"); + ret &= add_modifier_effect("suppression_points_modifier", true, PROPORTION_DECIMAL, "SUPPRESSION_TECH"); + ret &= add_modifier_effect( + "tariff_efficiency_modifier", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("tariff_efficiency") + ); ret &= add_modifier_effect("tax_efficiency", true); ret &= add_modifier_effect("unemployment_benefit", true); - ret &= add_modifier_effect("unciv_economic_modifier", false); - ret &= add_modifier_effect("unciv_military_modifier", false); + ret &= add_modifier_effect( + "unciv_economic_modifier", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("unciv_economic") + ); + ret &= add_modifier_effect( + "unciv_military_modifier", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("unciv_military") + ); ret &= add_modifier_effect("unit_recruitment_time", false); - ret &= add_modifier_effect("war_exhaustion", false); + ret &= add_modifier_effect("war_exhaustion", false, PROPORTION_DECIMAL, "WAR_EXHAUST_BATTLES"); /* State only */ - ret &= add_modifier_effect("flashpoint_tension", true); - ret &= add_modifier_effect("railroads", true); // capitalist likelihood for railroads vs factories + // replace $VAL$ with effect value * 30 (as proportion decimal, only used in national foci) + ret &= add_modifier_effect("flashpoint_tension", true, PROPORTION_DECIMAL, "increase_tension_focus_desc"); + // capitalist likelihood for railroads vs factories + // replace $VAL$ with effect value (as proportion decimal, only used in national foci) + ret &= add_modifier_effect("railroads", true, PROPORTION_DECIMAL, "railroad_build_desc"); /* Province Modifier Effects */ ret &= add_modifier_effect("assimilation_rate", true); ret &= add_modifier_effect("boost_strongest_party", false); - ret &= add_modifier_effect("farm_rgo_eff", true); - ret &= add_modifier_effect("farm_rgo_size", true); - ret &= add_modifier_effect("immigrant_attract", true); - ret &= add_modifier_effect("immigrant_push", false); + ret &= add_modifier_effect("farm_rgo_eff", true, PROPORTION_DECIMAL, "TECH_FARM_OUTPUT"); + ret &= add_modifier_effect( + "farm_rgo_size", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("farm_size") + ); + ret &= add_modifier_effect( + "immigrant_attract", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("immigant_attract") + ); + ret &= add_modifier_effect( + "immigrant_push", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("immigant_push") + ); ret &= add_modifier_effect("life_rating", true); - ret &= add_modifier_effect("local_artisan_input", false); - ret &= add_modifier_effect("local_artisan_output", true); - ret &= add_modifier_effect("local_artisan_throughput", true); - ret &= add_modifier_effect("local_factory_input", false); - ret &= add_modifier_effect("local_factory_output", true); - ret &= add_modifier_effect("local_factory_throughput", true); + ret &= add_modifier_effect( + "local_artisan_input", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("artisan_input") + ); + ret &= add_modifier_effect( + "local_artisan_output", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("artisan_output") + ); + ret &= add_modifier_effect( + "local_artisan_throughput", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("artisan_throughput") + ); + ret &= add_modifier_effect( + "local_factory_input", false, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("factory_input") + ); + ret &= add_modifier_effect( + "local_factory_output", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("factory_output") + ); + ret &= add_modifier_effect( + "local_factory_throughput", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("factory_throughput") + ); ret &= add_modifier_effect("local_repair", true); - ret &= add_modifier_effect("local_rgo_output", true); - ret &= add_modifier_effect("local_rgo_throughput", true); - ret &= add_modifier_effect("local_ruling_party_support", true); + ret &= add_modifier_effect( + "local_rgo_output", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("rgo_output") + ); + ret &= add_modifier_effect( + "local_rgo_throughput", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("rgo_throughput") + ); + ret &= add_modifier_effect( + "local_ruling_party_support", true, PROPORTION_DECIMAL, + make_default_modifier_effect_localisation_key("ruling_party_support") + ); ret &= add_modifier_effect("local_ship_build", false); ret &= add_modifier_effect("max_attrition", false, RAW_DECIMAL); - ret &= add_modifier_effect("mine_rgo_eff", true); - ret &= add_modifier_effect("mine_rgo_size", true); + ret &= add_modifier_effect("mine_rgo_eff", true, PROPORTION_DECIMAL, "TECH_MINE_OUTPUT"); + ret &= add_modifier_effect( + "mine_rgo_size", true, PROPORTION_DECIMAL, make_default_modifier_effect_localisation_key("mine_size") + ); ret &= add_modifier_effect("movement_cost", false); ret &= add_modifier_effect("number_of_voters", false); ret &= add_modifier_effect("pop_consciousness_modifier", false, RAW_DECIMAL); @@ -259,16 +353,15 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL); /* Military Modifier Effects */ - ret &= add_modifier_effect("attack", true, INT); - ret &= add_modifier_effect("attrition", false, RAW_DECIMAL); - ret &= add_modifier_effect("defence", true, INT); - ret &= add_modifier_effect("experience", true); - ret &= add_modifier_effect("morale", true); - ret &= add_modifier_effect("movement", true); - ret &= add_modifier_effect("organisation", true); - ret &= add_modifier_effect("reconnaissance", true); - ret &= add_modifier_effect("reliability", true, RAW_DECIMAL); - ret &= add_modifier_effect("speed", true); + ret &= add_modifier_effect("attack", true, INT, "TRAIT_ATTACK"); + ret &= add_modifier_effect("attrition", false, RAW_DECIMAL, "ATTRITION"); + ret &= add_modifier_effect("defence", true, INT, "TRAIT_DEFEND"); + ret &= add_modifier_effect("experience", true, PROPORTION_DECIMAL, "TRAIT_EXPERIENCE"); + ret &= add_modifier_effect("morale", true, PROPORTION_DECIMAL, "TRAIT_MORALE"); + ret &= add_modifier_effect("organisation", true, PROPORTION_DECIMAL, "TRAIT_ORGANISATION"); + ret &= add_modifier_effect("reconnaissance", true, PROPORTION_DECIMAL, "TRAIT_RECONAISSANCE"); + ret &= add_modifier_effect("reliability", true, RAW_DECIMAL, "TRAIT_RELIABILITY"); + ret &= add_modifier_effect("speed", true, PROPORTION_DECIMAL, "TRAIT_SPEED"); return ret; } diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index bd72a1e..f3cc0f6 100644 --- a/src/openvic-simulation/misc/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -22,10 +22,13 @@ namespace OpenVic { */ const bool PROPERTY_CUSTOM_PREFIX(positive_good, is); const format_t PROPERTY(format); + std::string PROPERTY(localisation_key); // TODO - format/precision, e.g. 80% vs 0.8 vs 0.800, 2 vs 2.0 vs 200% - ModifierEffect(std::string_view new_identifier, bool new_positive_good, format_t new_format); + ModifierEffect( + std::string_view new_identifier, bool new_positive_good, format_t new_format, std::string_view new_localisation_key + ); public: ModifierEffect(ModifierEffect&&) = default; @@ -133,7 +136,8 @@ namespace OpenVic { public: bool add_modifier_effect( std::string_view identifier, bool positive_good, - ModifierEffect::format_t format = ModifierEffect::format_t::PROPORTION_DECIMAL + ModifierEffect::format_t format = ModifierEffect::format_t::PROPORTION_DECIMAL, + std::string_view localisation_key = {} ); bool register_complex_modifier(std::string_view identifier); diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp index fcb08c9..1c54f06 100644 --- a/src/openvic-simulation/politics/Rebel.cpp +++ b/src/openvic-simulation/politics/Rebel.cpp @@ -176,16 +176,23 @@ bool RebelManager::load_rebels_file( } bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const { + using enum ModifierEffect::format_t; + bool ret = true; + static constexpr std::string_view identifier = "rebel_org_gain"; static constexpr bool is_positive_good = false; + ret &= modifier_manager.register_complex_modifier(identifier); - ret &= modifier_manager.add_modifier_effect(ModifierManager::get_flat_identifier(identifier, "all"), is_positive_good); + ret &= modifier_manager.add_modifier_effect( + ModifierManager::get_flat_identifier(identifier, "all"), is_positive_good, PROPORTION_DECIMAL, "TECH_REBEL_ORG_GAIN" + ); for (RebelType const& rebel_type : get_rebel_types()) { ret &= modifier_manager.add_modifier_effect( - ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), is_positive_good + ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), is_positive_good, PROPORTION_DECIMAL, + StringUtils::append_string_views("$", rebel_type.get_identifier(), "_title$ $TECH_REBEL_ORG_GAIN$") ); } return ret; diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index 1d61652..f2c0f8d 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -6,8 +6,15 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -Rule::Rule(std::string_view new_identifier, rule_group_t new_group, index_t new_index) - : HasIdentifier { new_identifier }, HasIndex { new_index }, group { new_group } {} +static std::string make_default_rule_localisation_key(std::string_view identifier) { + return "RULE_" + StringUtils::string_toupper(identifier); +} + +Rule::Rule(std::string_view new_identifier, rule_group_t new_group, index_t new_index, std::string_view new_localisation_key) + : HasIdentifier { new_identifier }, HasIndex { new_index }, group { new_group }, + localisation_key { + new_localisation_key.empty() ? make_default_rule_localisation_key(new_identifier) : new_localisation_key + } {} RuleSet::RuleSet(rule_group_map_t&& new_rule_groups) : rule_groups { std::move(new_rule_groups) } {} @@ -141,12 +148,12 @@ RuleSet RuleSet::operator|(RuleSet const& right) const { return ret |= right; } -bool RuleManager::add_rule(std::string_view identifier, Rule::rule_group_t group) { +bool RuleManager::add_rule(std::string_view identifier, Rule::rule_group_t group, std::string_view localisation_key) { if (identifier.empty()) { Logger::error("Invalid rule identifier - empty!"); return false; } - return rules.add_item({ identifier, group, rule_group_sizes[group]++ }); + return rules.add_item({ identifier, group, rule_group_sizes[group]++, localisation_key }); } bool RuleManager::setup_rules(BuildingTypeManager const& building_type_manager) { @@ -156,10 +163,11 @@ bool RuleManager::setup_rules(BuildingTypeManager const& building_type_manager) static const ordered_map<Rule::rule_group_t, std::vector<std::string_view>> hardcoded_rules { { ECONOMY, { - "expand_factory", "open_factory", "destroy_factory", "pop_build_factory", "pop_expand_factory", "pop_open_factory", - "can_subsidise", "factory_priority", "delete_factory_if_no_input", "build_factory_invest", "expand_factory_invest", - "open_factory_invest", "build_railway_invest", "pop_build_factory_invest", "pop_expand_factory_invest", - "can_invest_in_pop_projects", "allow_foreign_investment" + "build_railway", "build_factory", "expand_factory", "open_factory", "destroy_factory", "pop_build_factory", + "pop_expand_factory", "pop_open_factory", "can_subsidise", "factory_priority", "delete_factory_if_no_input", + "build_factory_invest", "expand_factory_invest", "open_factory_invest", "build_railway_invest", + "pop_build_factory_invest", "pop_expand_factory_invest", "pop_open_factory_invest", "can_invest_in_pop_projects", + "allow_foreign_investment" } }, { CITIZENSHIP, { "primary_culture_voting", "culture_voting", "all_voting" } }, { SLAVERY, { "slavery_allowed" } }, @@ -183,16 +191,6 @@ bool RuleManager::setup_rules(BuildingTypeManager const& building_type_manager) } } - for (std::string const& type : building_type_manager.get_building_type_types()) { - std::string build_rule_string = "build_"; - if (type != "infrastructure") { - build_rule_string += type; - } else { - build_rule_string += "railway"; - } - ret &= add_rule(build_rule_string, ECONOMY); - } - lock_rules(); return ret; diff --git a/src/openvic-simulation/politics/Rule.hpp b/src/openvic-simulation/politics/Rule.hpp index db0c926..579299b 100644 --- a/src/openvic-simulation/politics/Rule.hpp +++ b/src/openvic-simulation/politics/Rule.hpp @@ -28,8 +28,11 @@ namespace OpenVic { private: const rule_group_t PROPERTY(group); + std::string PROPERTY(localisation_key); - Rule(std::string_view new_identifier, rule_group_t new_group, index_t new_index); + Rule( + std::string_view new_identifier, rule_group_t new_group, index_t new_index, std::string_view new_localisation_key + ); public: Rule(Rule&&) = default; @@ -81,7 +84,7 @@ namespace OpenVic { ordered_map<Rule::rule_group_t, size_t> rule_group_sizes; public: - bool add_rule(std::string_view identifier, Rule::rule_group_t group); + bool add_rule(std::string_view identifier, Rule::rule_group_t group, std::string_view localisation_key = {}); bool setup_rules(BuildingTypeManager const& building_type_manager); diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index cde7013..d534fed 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -653,6 +653,8 @@ bool PopManager::load_pop_bases_into_vector( } bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { + using enum ModifierEffect::format_t; + bool ret = true; for (Strata const& strata : get_stratas()) { @@ -673,7 +675,10 @@ bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { } for (PopType const& pop_type : get_pop_types()) { - ret &= modifier_manager.add_modifier_effect(pop_type.get_identifier(), true); + ret &= modifier_manager.add_modifier_effect( + pop_type.get_identifier(), true, PROPORTION_DECIMAL, + StringUtils::append_string_views("$ENCOURAGEMENT_FOR$$", pop_type.get_identifier(), "$") + ); } return ret; diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 89c4a71..847c4b0 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -196,12 +196,14 @@ bool TechnologyManager::load_technologies_file( } bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) const { + using enum ModifierEffect::format_t; + bool ret = true; for (TechnologyFolder const& folder : get_technology_folders()) { - ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"), true - ); + const std::string modifier_identifier = StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"); + + ret &= modifier_manager.add_modifier_effect(modifier_identifier, true, PROPORTION_DECIMAL, modifier_identifier); } return ret; diff --git a/src/openvic-simulation/utility/StringUtils.hpp b/src/openvic-simulation/utility/StringUtils.hpp index bec11ec..53feb9d 100644 --- a/src/openvic-simulation/utility/StringUtils.hpp +++ b/src/openvic-simulation/utility/StringUtils.hpp @@ -160,6 +160,22 @@ namespace OpenVic::StringUtils { return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), ichar_equals); } + inline constexpr std::string string_tolower(std::string_view str) { + std::string result { str }; + std::transform(result.begin(), result.end(), result.begin(), + [](unsigned char c) -> unsigned char { return std::tolower(c); } + ); + return result; + } + + inline constexpr std::string string_toupper(std::string_view str) { + std::string result { str }; + std::transform(result.begin(), result.end(), result.begin(), + [](unsigned char c) -> unsigned char { return std::toupper(c); } + ); + return result; + } + inline constexpr std::string_view get_filename(std::string_view path) { size_t pos = path.size(); while (pos > 0 && path[pos - 1] != '/' && path[pos - 1] != '\\') { |