diff options
author | hop311 <hop3114@gmail.com> | 2024-09-20 14:02:17 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-09-20 14:06:40 +0200 |
commit | 3703851ced696a2d4559c3e3340c537982d5ebc7 (patch) | |
tree | 0f103095b45de46688206d0e33e24f0331afbabd /src/openvic-simulation/politics/Rule.cpp | |
parent | 7c312e21c6ac3a28fe5f7963ffe12b409cce643c (diff) |
Add ModifierSum and improve ModifierValue and RuleSet
Diffstat (limited to 'src/openvic-simulation/politics/Rule.cpp')
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index f2c0f8d..64d06f1 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -83,54 +83,42 @@ bool RuleSet::empty() const { return true; } -RuleSet::rule_map_t const& RuleSet::get_rule_group(Rule::rule_group_t group, bool* successful) const { +RuleSet::rule_map_t const& RuleSet::get_rule_group(Rule::rule_group_t group, bool* rule_group_found) const { const rule_group_map_t::const_iterator it = rule_groups.find(group); if (it != rule_groups.end()) { - if (successful != nullptr) { - *successful = true; + if (rule_group_found != nullptr) { + *rule_group_found = true; } return it->second; } - if (successful != nullptr) { - *successful = false; + if (rule_group_found != nullptr) { + *rule_group_found = false; } static const rule_map_t empty_map {}; return empty_map; } -bool RuleSet::get_rule(Rule const* rule, bool* successful) const { - if (rule == nullptr) { - Logger::error("Invalid rule - null!"); - return false; - } - rule_map_t const& rule_map = get_rule_group(rule->get_group()); - const rule_map_t::const_iterator it = rule_map.find(rule); +bool RuleSet::get_rule(Rule const& rule, bool* rule_found) const { + rule_map_t const& rule_map = get_rule_group(rule.get_group()); + const rule_map_t::const_iterator it = rule_map.find(&rule); if (it != rule_map.end()) { - if (successful != nullptr) { - *successful = true; + if (rule_found != nullptr) { + *rule_found = true; } return it->second; } - if (successful != nullptr) { - *successful = false; + if (rule_found != nullptr) { + *rule_found = false; } - return Rule::is_default_enabled(rule->get_group()); + return Rule::is_default_enabled(rule.get_group()); } -bool RuleSet::has_rule(Rule const* rule) const { - if (rule == nullptr) { - Logger::error("Invalid rule - null!"); - return false; - } - return get_rule_group(rule->get_group()).contains(rule); +bool RuleSet::has_rule(Rule const& rule) const { + return get_rule_group(rule.get_group()).contains(&rule); } -bool RuleSet::set_rule(Rule const* rule, bool value) { - if (rule == nullptr) { - Logger::error("Invalid rule - null!"); - return false; - } - rule_groups[rule->get_group()][rule] = value; +bool RuleSet::set_rule(Rule const& rule, bool value) { + rule_groups[rule.get_group()][&rule] = value; return true; } @@ -144,8 +132,8 @@ RuleSet& RuleSet::operator|=(RuleSet const& right) { } RuleSet RuleSet::operator|(RuleSet const& right) const { - RuleSet ret = *this; - return ret |= right; + RuleSet copy = *this; + return copy |= right; } bool RuleManager::add_rule(std::string_view identifier, Rule::rule_group_t group, std::string_view localisation_key) { |