diff options
Diffstat (limited to 'src/openvic-simulation/politics/Issue.cpp')
-rw-r--r-- | src/openvic-simulation/politics/Issue.cpp | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp index 30dc1cd..d8fe52e 100644 --- a/src/openvic-simulation/politics/Issue.cpp +++ b/src/openvic-simulation/politics/Issue.cpp @@ -191,7 +191,8 @@ bool IssueManager::_load_reform( bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, RuleManager const& rule_manager, ast::NodeCPtr root) { size_t expected_issue_groups = 0; size_t expected_reform_groups = 0; - bool ret = expect_dictionary_reserve_length(reform_types, + bool ret = expect_dictionary_reserve_length( + reform_types, [this, &expected_issue_groups, &expected_reform_groups](std::string_view key, ast::NodeCPtr value) -> bool { if (key == "party_issues") { return expect_length(add_variable_callback(expected_issue_groups))(value); @@ -206,12 +207,12 @@ bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, Rul )(root); lock_reform_types(); - issue_groups.reserve(issue_groups.size() + expected_issue_groups); - reform_groups.reserve(reform_groups.size() + expected_reform_groups); + reserve_more_issue_groups(expected_issue_groups); + reserve_more_reform_groups(expected_reform_groups); size_t expected_issues = 0; size_t expected_reforms = 0; - ret &= expect_dictionary_reserve_length(issue_groups, + ret &= expect_dictionary( [this, &expected_issues, &expected_reforms](std::string_view type_key, ast::NodeCPtr type_value) -> bool { if (type_key == "party_issues") { return expect_dictionary([this, &expected_issues](std::string_view key, ast::NodeCPtr value) -> bool { @@ -230,28 +231,36 @@ bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, Rul lock_issue_groups(); lock_reform_groups(); - issues.reserve(issues.size() + expected_issues); - reforms.reserve(reforms.size() + expected_reforms); - - ret &= expect_dictionary([this, &modifier_manager, &rule_manager](std::string_view type_key, ast::NodeCPtr type_value) -> bool { - return expect_dictionary([this, &modifier_manager, &rule_manager, type_key](std::string_view group_key, ast::NodeCPtr group_value) -> bool { - if (type_key == "party_issues") { - IssueGroup const* issue_group = get_issue_group_by_identifier(group_key); - return expect_dictionary([this, &modifier_manager, &rule_manager, issue_group](std::string_view key, ast::NodeCPtr value) -> bool { - return _load_issue(modifier_manager, rule_manager, key, issue_group, value); - })(group_value); - } else { - ReformGroup const* reform_group = get_reform_group_by_identifier(group_key); - size_t ordinal = 0; - return expect_dictionary([this, &modifier_manager, &rule_manager, reform_group, &ordinal](std::string_view key, ast::NodeCPtr value) -> bool { - if (key == "next_step_only" || key == "administrative") { - return true; - } - return _load_reform(modifier_manager, rule_manager, ordinal++, key, reform_group, value); - })(group_value); - } - })(type_value); - })(root); + reserve_more_issues(expected_issues); + reserve_more_reforms(expected_reforms); + + ret &= expect_dictionary( + [this, &modifier_manager, &rule_manager](std::string_view type_key, ast::NodeCPtr type_value) -> bool { + return expect_dictionary([this, &modifier_manager, &rule_manager, type_key]( + std::string_view group_key, ast::NodeCPtr group_value + ) -> bool { + if (type_key == "party_issues") { + IssueGroup const* issue_group = get_issue_group_by_identifier(group_key); + return expect_dictionary([this, &modifier_manager, &rule_manager, issue_group]( + std::string_view key, ast::NodeCPtr value + ) -> bool { + return _load_issue(modifier_manager, rule_manager, key, issue_group, value); + })(group_value); + } else { + ReformGroup const* reform_group = get_reform_group_by_identifier(group_key); + size_t ordinal = 0; + return expect_dictionary([this, &modifier_manager, &rule_manager, reform_group, &ordinal]( + std::string_view key, ast::NodeCPtr value + ) -> bool { + if (key == "next_step_only" || key == "administrative") { + return true; + } + return _load_reform(modifier_manager, rule_manager, ordinal++, key, reform_group, value); + })(group_value); + } + })(type_value); + } + )(root); lock_issues(); lock_reforms(); |