diff options
author | hop311 <hop3114@gmail.com> | 2024-09-19 00:07:28 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-09-19 00:07:28 +0200 |
commit | 5550b237fa9b6f8c6a86eea0de9d32e28a626dc7 (patch) | |
tree | ed4e867e2c099b027da2e2205b99575edae7b561 /src/openvic-simulation/politics | |
parent | f0814926f675d6ecf889d8add410b1c37f625b29 (diff) |
ModifierEffect and Rule localisation keysrule-modifier-locale-keys
Diffstat (limited to 'src/openvic-simulation/politics')
-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 |
3 files changed, 30 insertions, 22 deletions
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); |