diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/openvic-simulation/InstanceManager.cpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/country/CountryDefinition.cpp | 19 | ||||
-rw-r--r-- | src/openvic-simulation/country/CountryDefinition.hpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/country/CountryInstance.cpp | 77 | ||||
-rw-r--r-- | src/openvic-simulation/country/CountryInstance.hpp | 14 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 9 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.cpp | 32 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.hpp | 10 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 14 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.hpp | 4 |
11 files changed, 140 insertions, 47 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp index b731d12..c9ce24a 100644 --- a/src/openvic-simulation/InstanceManager.cpp +++ b/src/openvic-simulation/InstanceManager.cpp @@ -83,6 +83,7 @@ bool InstanceManager::setup() { definition_manager.get_research_manager().get_technology_manager().get_technologies(), definition_manager.get_research_manager().get_invention_manager().get_inventions(), definition_manager.get_politics_manager().get_ideology_manager().get_ideologies(), + definition_manager.get_politics_manager().get_issue_manager().get_reform_groups(), definition_manager.get_politics_manager().get_government_type_manager().get_government_types(), definition_manager.get_crime_manager().get_crime_modifiers(), definition_manager.get_pop_manager().get_pop_types(), diff --git a/src/openvic-simulation/country/CountryDefinition.cpp b/src/openvic-simulation/country/CountryDefinition.cpp index a9e7487..12a7a22 100644 --- a/src/openvic-simulation/country/CountryDefinition.cpp +++ b/src/openvic-simulation/country/CountryDefinition.cpp @@ -138,24 +138,31 @@ node_callback_t CountryDefinitionManager::load_country_party( std::string_view party_name; Date start_date, end_date; Ideology const* ideology; - CountryParty::policy_map_t policies; + CountryParty::policy_map_t policies { &politics_manager.get_issue_manager().get_issue_groups() }; bool ret = expect_dictionary_keys_and_default( [&politics_manager, &policies, &party_name](std::string_view key, ast::NodeCPtr value) -> bool { return politics_manager.get_issue_manager().expect_issue_group_str( [&politics_manager, &policies, value, &party_name](IssueGroup const& group) -> bool { - if (policies.contains(&group)) { + CountryParty::policy_map_t::value_ref_t policy = policies[group]; + + if (policy != nullptr) { Logger::error("Country party ", party_name, " has duplicate entry for ", group.get_identifier()); return false; } + return politics_manager.get_issue_manager().expect_issue_identifier( - [&policies, &group](Issue const& issue) -> bool { + [&group, &policy](Issue const& issue) -> bool { if (&issue.get_group() == &group) { - return map_callback(policies, &group)(&issue); + policy = &issue; + return true; } + // TODO - change this back to error/false once TGC no longer has this issue - Logger::warning("Invalid policy ", issue.get_identifier(), ", group is ", - issue.get_group().get_identifier(), " when ", group.get_identifier(), " was expected"); + Logger::warning( + "Invalid policy ", issue.get_identifier(), ", group is ", + issue.get_group().get_identifier(), " when ", group.get_identifier(), " was expected." + ); return true; } )(value); diff --git a/src/openvic-simulation/country/CountryDefinition.hpp b/src/openvic-simulation/country/CountryDefinition.hpp index f04796a..6462be1 100644 --- a/src/openvic-simulation/country/CountryDefinition.hpp +++ b/src/openvic-simulation/country/CountryDefinition.hpp @@ -14,6 +14,7 @@ #include "openvic-simulation/types/Colour.hpp" #include "openvic-simulation/types/Date.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/types/IndexedMap.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" namespace OpenVic { @@ -23,7 +24,7 @@ namespace OpenVic { struct CountryParty : HasIdentifierAndColour { friend struct CountryDefinitionManager; - using policy_map_t = ordered_map<IssueGroup const*, Issue const*>; + using policy_map_t = IndexedMap<IssueGroup, Issue const*>; private: const Date PROPERTY(start_date); diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index e0932eb..183b0c8 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -21,6 +21,7 @@ CountryInstance::CountryInstance( decltype(unlocked_technologies)::keys_t const& technology_keys, decltype(unlocked_inventions)::keys_t const& invention_keys, decltype(upper_house)::keys_t const& ideology_keys, + decltype(reforms)::keys_t const& reform_keys, decltype(government_flag_overrides)::keys_t const& government_type_keys, decltype(unlocked_crimes)::keys_t const& crime_keys, decltype(pop_type_distribution)::keys_t const& pop_type_keys, @@ -69,7 +70,9 @@ CountryInstance::CountryInstance( last_election {}, ruling_party { nullptr }, upper_house { &ideology_keys }, - reforms {}, + reforms { &reform_keys }, + total_administrative_multiplier { 0 }, + rule_set {}, government_flag_overrides { &government_type_keys }, flag_government_type { nullptr }, suppression_points { 0 }, @@ -240,27 +243,37 @@ bool CountryInstance::set_upper_house(Ideology const* ideology, fixed_point_t po } } -bool CountryInstance::add_reform(Reform const* new_reform) { - if (std::find(reforms.begin(), reforms.end(), new_reform) != reforms.end()) { - Logger::warning( - "Attempted to add reform \"", new_reform, "\" to country ", get_identifier(), ": already present!" - ); - return false; +bool CountryInstance::set_ruling_party(CountryParty const& new_ruling_party) { + if (ruling_party != &new_ruling_party) { + ruling_party = &new_ruling_party; + + return update_rule_set(); + } else { + return true; } - reforms.push_back(new_reform); - return true; } -bool CountryInstance::remove_reform(Reform const* reform_to_remove) { - auto existing_entry = std::find(reforms.begin(), reforms.end(), reform_to_remove); - if (existing_entry == reforms.end()) { - Logger::warning( - "Attempted to remove reform \"", reform_to_remove, "\" from country ", get_identifier(), ": not present!" - ); - return false; +bool CountryInstance::add_reform(Reform const& new_reform) { + ReformGroup const& reform_group = new_reform.get_reform_group(); + decltype(reforms)::value_ref_t reform = reforms[reform_group]; + + if (reform != &new_reform) { + if (reform_group.is_administrative()) { + if (reform != nullptr) { + total_administrative_multiplier -= reform->get_administrative_multiplier(); + } + total_administrative_multiplier += new_reform.get_administrative_multiplier(); + } + + reform = &new_reform; + + // TODO - if new_reform.get_reform_group().get_type().is_uncivilised() ? + // TODO - new_reform.get_on_execute_trigger() / new_reform.get_on_execute_effect() ? + + return update_rule_set(); + } else { + return true; } - reforms.erase(existing_entry); - return true; } template<UnitType::branch_t Branch> @@ -663,7 +676,9 @@ bool CountryInstance::apply_history_to_country( ret &= add_accepted_culture(*culture); } set_optional(religion, entry.get_religion()); - set_optional(ruling_party, entry.get_ruling_party()); + if (entry.get_ruling_party()) { + ret &= set_ruling_party(**entry.get_ruling_party()); + } set_optional(last_election, entry.get_last_election()); ret &= upper_house.copy(entry.get_upper_house()); if (entry.get_capital()) { @@ -677,7 +692,7 @@ bool CountryInstance::apply_history_to_country( } set_optional(prestige, entry.get_prestige()); for (Reform const* reform : entry.get_reforms()) { - ret &= add_reform(reform); + ret &= add_reform(*reform); } set_optional(tech_school, entry.get_tech_school()); constexpr auto set_bool_map_to_indexed_map = @@ -888,6 +903,26 @@ void CountryInstance::_update_military(DefineManager const& define_manager, Unit // TODO - update max_ship_supply, leadership_points, war_exhaustion } +bool CountryInstance::update_rule_set() { + rule_set.clear(); + + if (ruling_party != nullptr) { + for (Issue const* issue : ruling_party->get_policies()) { + if (issue != nullptr) { + rule_set |= issue->get_rules(); + } + } + } + + for (Reform const* reform : reforms) { + if (reform != nullptr) { + rule_set |= reform->get_rules(); + } + } + + return rule_set.trim_and_resolve_conflicts(true); +} + void CountryInstance::update_gamestate(DefineManager const& define_manager, UnitTypeManager const& unit_type_manager) { // Order of updates might need to be changed/functions split up to account for dependencies _update_production(define_manager); @@ -1060,6 +1095,7 @@ bool CountryInstanceManager::generate_country_instances( decltype(CountryInstance::unlocked_technologies)::keys_t const& technology_keys, decltype(CountryInstance::unlocked_inventions)::keys_t const& invention_keys, decltype(CountryInstance::upper_house)::keys_t const& ideology_keys, + decltype(CountryInstance::reforms)::keys_t const& reform_keys, decltype(CountryInstance::government_flag_overrides)::keys_t const& government_type_keys, decltype(CountryInstance::unlocked_crimes)::keys_t const& crime_keys, decltype(CountryInstance::pop_type_distribution)::keys_t const& pop_type_keys, @@ -1077,6 +1113,7 @@ bool CountryInstanceManager::generate_country_instances( technology_keys, invention_keys, ideology_keys, + reform_keys, government_type_keys, crime_keys, pop_type_keys, diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp index c768a86..a7128aa 100644 --- a/src/openvic-simulation/country/CountryInstance.hpp +++ b/src/openvic-simulation/country/CountryInstance.hpp @@ -6,6 +6,7 @@ #include "openvic-simulation/military/Leader.hpp" #include "openvic-simulation/military/UnitInstanceGroup.hpp" +#include "openvic-simulation/politics/Rule.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/types/Date.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" @@ -24,6 +25,7 @@ namespace OpenVic { struct GovernmentType; struct CountryParty; struct Ideology; + struct ReformGroup; struct Reform; struct Crime; struct Culture; @@ -109,7 +111,9 @@ namespace OpenVic { Date PROPERTY(last_election); CountryParty const* PROPERTY(ruling_party); IndexedMap<Ideology, fixed_point_t> PROPERTY(upper_house); - std::vector<Reform const*> PROPERTY(reforms); // TODO: should be map of reform groups to active reforms: must set defaults & validate applied history + IndexedMap<ReformGroup, Reform const*> PROPERTY(reforms); + fixed_point_t PROPERTY(total_administrative_multiplier); + RuleSet PROPERTY(rule_set); // TODO - national issue support distribution (for just voters and for everyone) IndexedMap<GovernmentType, GovernmentType const*> PROPERTY(government_flag_overrides); GovernmentType const* PROPERTY(flag_government_type); @@ -181,6 +185,7 @@ namespace OpenVic { decltype(unlocked_technologies)::keys_t const& technology_keys, decltype(unlocked_inventions)::keys_t const& invention_keys, decltype(upper_house)::keys_t const& ideology_keys, + decltype(reforms)::keys_t const& reform_keys, decltype(government_flag_overrides)::keys_t const& government_type_keys, decltype(unlocked_crimes)::keys_t const& crime_keys, decltype(pop_type_distribution)::keys_t const& pop_type_keys, @@ -212,8 +217,8 @@ namespace OpenVic { bool remove_accepted_culture(Culture const& culture_to_remove); /* Set a party's popularity in the upper house. */ bool set_upper_house(Ideology const* ideology, fixed_point_t popularity); - bool add_reform(Reform const* new_reform); - bool remove_reform(Reform const* reform_to_remove); + bool set_ruling_party(CountryParty const& new_ruling_party); + bool add_reform(Reform const& new_reform); template<UnitType::branch_t Branch> bool add_unit_instance_group(UnitInstanceGroup<Branch>& group); @@ -287,6 +292,8 @@ namespace OpenVic { void _update_diplomacy(); void _update_military(DefineManager const& define_manager, UnitTypeManager const& unit_type_manager); + bool update_rule_set(); + public: void update_gamestate(DefineManager const& define_manager, UnitTypeManager const& unit_type_manager); @@ -321,6 +328,7 @@ namespace OpenVic { decltype(CountryInstance::unlocked_technologies)::keys_t const& technology_keys, decltype(CountryInstance::unlocked_inventions)::keys_t const& invention_keys, decltype(CountryInstance::upper_house)::keys_t const& ideology_keys, + decltype(CountryInstance::reforms)::keys_t const& reform_keys, decltype(CountryInstance::government_flag_overrides)::keys_t const& government_type_keys, decltype(CountryInstance::unlocked_crimes)::keys_t const& crime_keys, decltype(CountryInstance::pop_type_distribution)::keys_t const& pop_type_keys, diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index 4d6abb7..9163af5 100644 --- a/src/openvic-simulation/misc/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -33,6 +33,14 @@ size_t ModifierValue::get_effect_count() const { return values.size(); } +void ModifierValue::clear() { + values.clear(); +} + +bool ModifierValue::empty() const { + return values.empty(); +} + fixed_point_t ModifierValue::get_effect(ModifierEffect const* effect, bool* successful) { const effect_map_t::const_iterator it = values.find(effect); if (it != values.end()) { @@ -123,7 +131,6 @@ bool ModifierManager::setup_modifier_effects() { /* Country Modifier Effects */ ret &= add_modifier_effect("administrative_efficiency", true); ret &= add_modifier_effect("administrative_efficiency_modifier", true); - ret &= add_modifier_effect("administrative_multiplier", true); ret &= add_modifier_effect("artisan_input", false); ret &= add_modifier_effect("artisan_output", true); ret &= add_modifier_effect("artisan_throughput", true); diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index 58b335d..bd72a1e 100644 --- a/src/openvic-simulation/misc/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -37,7 +37,7 @@ namespace OpenVic { using effect_map_t = fixed_point_map_t<ModifierEffect const*>; private: - effect_map_t values; + effect_map_t PROPERTY(values); public: ModifierValue(); @@ -51,6 +51,8 @@ namespace OpenVic { /* Removes effect entries with a value of zero. */ void trim(); size_t get_effect_count() const; + void clear(); + bool empty() const; fixed_point_t get_effect(ModifierEffect const* effect, bool* successful = nullptr); bool has_effect(ModifierEffect const* effect) const; diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp index a03ffa3..1dca176 100644 --- a/src/openvic-simulation/politics/Issue.cpp +++ b/src/openvic-simulation/politics/Issue.cpp @@ -19,10 +19,11 @@ ReformGroup::ReformGroup(std::string_view new_identifier, ReformType const& new_ Reform::Reform( std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_values, ReformGroup const& new_group, - size_t new_ordinal, RuleSet&& new_rules, tech_cost_t new_technology_cost, ConditionScript&& new_allow, - ConditionScript&& new_on_execute_trigger, EffectScript&& new_on_execute_effect -) : Issue { new_identifier, new_colour, std::move(new_values), new_group, std::move(new_rules), false }, ordinal { new_ordinal }, - reform_group { new_group }, technology_cost { new_technology_cost }, allow { std::move(new_allow) }, + size_t new_ordinal, fixed_point_t new_administrative_multiplier, RuleSet&& new_rules, tech_cost_t new_technology_cost, + ConditionScript&& new_allow, ConditionScript&& new_on_execute_trigger, EffectScript&& new_on_execute_effect +) : Issue { new_identifier, new_colour, std::move(new_values), new_group, std::move(new_rules), false }, + reform_group { new_group }, ordinal { new_ordinal }, administrative_multiplier { new_administrative_multiplier }, + technology_cost { new_technology_cost }, allow { std::move(new_allow) }, on_execute_trigger { std::move(new_on_execute_trigger) }, on_execute_effect { std::move(new_on_execute_effect) } {} bool Reform::parse_scripts(DefinitionManager const& definition_manager) { @@ -84,8 +85,8 @@ bool IssueManager::add_reform_group(std::string_view identifier, ReformType cons bool IssueManager::add_reform( std::string_view identifier, colour_t new_colour, ModifierValue&& values, ReformGroup const* group, size_t ordinal, - RuleSet&& rules, Reform::tech_cost_t technology_cost, ConditionScript&& allow, ConditionScript&& on_execute_trigger, - EffectScript&& on_execute_effect + fixed_point_t administrative_multiplier, RuleSet&& rules, Reform::tech_cost_t technology_cost, ConditionScript&& allow, + ConditionScript&& on_execute_trigger, EffectScript&& on_execute_effect ) { if (identifier.empty()) { Logger::error("Invalid issue identifier - empty!"); @@ -116,9 +117,16 @@ bool IssueManager::add_reform( Logger::warning("Non-zero technology cost ", technology_cost, " found in civilised reform ", identifier, "!"); } + if (administrative_multiplier != 0 && !group->is_administrative()) { + Logger::warning( + "Non-zero administrative multiplier ", administrative_multiplier, " found in reform ", identifier, + " belonging to non-administrative group ", group->get_identifier(), "!" + ); + } + return reforms.add_item({ - identifier, new_colour, std::move(values), *group, ordinal, std::move(rules), technology_cost, std::move(allow), - std::move(on_execute_trigger), std::move(on_execute_effect) + identifier, new_colour, std::move(values), *group, ordinal, administrative_multiplier, std::move(rules), + technology_cost, std::move(allow), std::move(on_execute_trigger), std::move(on_execute_effect) }); } @@ -198,12 +206,15 @@ bool IssueManager::_load_reform( ) { ModifierValue values; RuleSet rules; + fixed_point_t administrative_multiplier = 0; Reform::tech_cost_t technology_cost = 0; ConditionScript allow { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE }; ConditionScript on_execute_trigger { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE }; EffectScript on_execute_effect; - bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values), + bool ret = modifier_manager.expect_modifier_value_and_keys( + move_variable_callback(values), + "administrative_multiplier", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(administrative_multiplier)), "technology_cost", ZERO_OR_ONE, expect_uint(assign_variable_callback(technology_cost)), "allow", ZERO_OR_ONE, allow.expect_script(), "rules", ZERO_OR_ONE, rule_manager.expect_rule_set(move_variable_callback(rules)), @@ -214,7 +225,8 @@ bool IssueManager::_load_reform( )(node); ret &= add_reform( identifier, create_issue_reform_colour(get_issue_count() + get_reform_count()), std::move(values), group, ordinal, - std::move(rules), technology_cost, std::move(allow), std::move(on_execute_trigger), std::move(on_execute_effect) + administrative_multiplier, std::move(rules), technology_cost, std::move(allow), std::move(on_execute_trigger), + std::move(on_execute_effect) ); return ret; } diff --git a/src/openvic-simulation/politics/Issue.hpp b/src/openvic-simulation/politics/Issue.hpp index 70f082d..d49f897 100644 --- a/src/openvic-simulation/politics/Issue.hpp +++ b/src/openvic-simulation/politics/Issue.hpp @@ -76,6 +76,7 @@ namespace OpenVic { private: ReformGroup const& PROPERTY(reform_group); // stores an already casted reference const size_t PROPERTY(ordinal); // assigned by the parser to allow policy sorting + const fixed_point_t PROPERTY(administrative_multiplier); const tech_cost_t PROPERTY(technology_cost); ConditionScript PROPERTY(allow); ConditionScript PROPERTY(on_execute_trigger); @@ -83,8 +84,9 @@ namespace OpenVic { Reform( std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_values, ReformGroup const& new_group, - size_t new_ordinal, RuleSet&& new_rules, tech_cost_t new_technology_cost, ConditionScript&& new_allow, - ConditionScript&& new_on_execute_trigger, EffectScript&& new_on_execute_effect + size_t new_ordinal, fixed_point_t new_administrative_multiplier, RuleSet&& new_rules, + tech_cost_t new_technology_cost, ConditionScript&& new_allow, ConditionScript&& new_on_execute_trigger, + EffectScript&& new_on_execute_effect ); bool parse_scripts(DefinitionManager const& definition_manager); @@ -125,8 +127,8 @@ namespace OpenVic { bool add_reform_group(std::string_view identifier, ReformType const* type, bool ordered, bool administrative); bool add_reform( std::string_view identifier, colour_t new_colour, ModifierValue&& values, ReformGroup const* group, size_t ordinal, - RuleSet&& rules, Reform::tech_cost_t technology_cost, ConditionScript&& allow, ConditionScript&& on_execute_trigger, - EffectScript&& on_execute_effect + fixed_point_t administrative_multiplier, RuleSet&& rules, Reform::tech_cost_t technology_cost, + ConditionScript&& allow, ConditionScript&& on_execute_trigger, EffectScript&& on_execute_effect ); bool load_issues_file(ModifierManager const& modifier_manager, RuleManager const& rule_manager, ast::NodeCPtr root); diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index 37aa22a..1d61652 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -62,6 +62,20 @@ size_t RuleSet::get_rule_count() const { return ret; } +void RuleSet::clear() { + rule_groups.clear(); +} + +bool RuleSet::empty() const { + for (auto const& [group, rule_map] : rule_groups) { + if (!rule_map.empty()) { + return false; + } + } + + return true; +} + RuleSet::rule_map_t const& RuleSet::get_rule_group(Rule::rule_group_t group, bool* successful) const { const rule_group_map_t::const_iterator it = rule_groups.find(group); if (it != rule_groups.end()) { diff --git a/src/openvic-simulation/politics/Rule.hpp b/src/openvic-simulation/politics/Rule.hpp index 518c555..db0c926 100644 --- a/src/openvic-simulation/politics/Rule.hpp +++ b/src/openvic-simulation/politics/Rule.hpp @@ -42,7 +42,7 @@ namespace OpenVic { using rule_group_map_t = ordered_map<Rule::rule_group_t, rule_map_t>; private: - rule_group_map_t rule_groups; + rule_group_map_t PROPERTY(rule_groups); public: RuleSet() = default; @@ -59,6 +59,8 @@ namespace OpenVic { bool trim_and_resolve_conflicts(bool log); size_t get_rule_group_count() const; size_t get_rule_count() const; + void clear(); + bool empty() const; rule_map_t const& get_rule_group(Rule::rule_group_t group, bool* successful = nullptr) const; bool get_rule(Rule const* rule, bool* successful = nullptr) const; |