aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics/Rule.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-09-20 14:11:27 +0200
committer GitHub <noreply@github.com>2024-09-20 14:11:27 +0200
commit89b1333b1edff6c08750bd836ae92eccbe06e3bd (patch)
treeed4e867e2c099b027da2e2205b99575edae7b561 /src/openvic-simulation/politics/Rule.cpp
parentf0814926f675d6ecf889d8add410b1c37f625b29 (diff)
parent5550b237fa9b6f8c6a86eea0de9d32e28a626dc7 (diff)
Merge pull request #201 from OpenVicProject/rule-modifier-locale-keys
ModifierEffect and Rule localisation keys
Diffstat (limited to 'src/openvic-simulation/politics/Rule.cpp')
-rw-r--r--src/openvic-simulation/politics/Rule.cpp34
1 files changed, 16 insertions, 18 deletions
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;