apply_protest_effects = { apply_passive_protest_drift = yes update_protest_radicalisation = yes set_temp_variable = { protest_drift = 0 } calculate_protest_drift = yes add_to_variable = { protest_strength = protest_drift } clamp_variable = { var = protest_strength min = 0 max = 100 } } apply_passive_protest_drift = { # Display vars persisted only while the player has the panel open. AI never # writes drift_passive_last; player only writes it when MD_protests_GUI is open. if = { limit = { is_ai = no has_country_flag = open_protests_screen } set_variable = { drift_passive_last = 0 } } random = { chance = 50 subtract_from_variable = { protest_strength = 2 } if = { limit = { is_ai = no has_country_flag = open_protests_screen } set_variable = { drift_passive_last = -2 } } } if = { limit = { NOT = { has_variable = protest_strength } } set_variable = { protest_strength = 0 } } clamp_variable = { var = protest_strength min = 0 max = 100 } } update_protest_radicalisation = { if = { limit = { OR = { check_variable = { protest_strength > 49 } has_active_mission = MD_incoming_protest_movement has_active_mission = MD_incoming_revolt } } random = { chance = 20 add_to_variable = { protest_radicalisation = 1 } } } else = { random = { chance = 10 subtract_from_variable = { protest_radicalisation = 1 } } } if = { limit = { NOT = { has_variable = protest_radicalisation } } set_variable = { protest_radicalisation = 0 } } clamp_variable = { var = protest_radicalisation min = 0 max = 10 } } calculate_protest_drift = { if = { limit = { has_fuel < 1 } add_to_temp_variable = { protest_drift = 1 } } add_to_temp_variable = { var = protest_drift value = { value = expected_welfare_spending subtract = social_law } } add_to_temp_variable = { var = protest_drift value = { value = expected_health_spending subtract = health_law } } add_to_temp_variable = { var = protest_drift value = { value = expected_edu_spending subtract = education_law } } add_to_temp_variable = { var = protest_drift value = { value = expected_police_spending subtract = police_law } } add_to_temp_variable = { var = protest_drift value = { value = expected_adm_spending subtract = bureau_law } } add_to_temp_variable = { var = protest_drift value = { value = expected_military_sp subtract = military_law } } multiply_temp_variable = { protest_drift = 0.5 } } calculate_unrest_growth = { MD_protests_calc_deterministic_drift = yes add_to_variable = { var = protest_strength value = { value = det_stability_drift add = det_interest_drift add = det_war_drift add = det_corruption_drift } } #Random sources: the live tick rolls a real poisson value; the panel #projection (MD_protests_recompute_display) uses the expected value instead. if = { limit = { has_idea = recession } randomize_temp_variable = { var = protest_drift distribution = poisson min = 0.5 lambda = 3 } if = { limit = { is_ai = no has_country_flag = open_protests_screen } set_variable = { drift_recession_last = protest_drift } } add_to_variable = { protest_strength = protest_drift } } if = { limit = { has_idea = depression } randomize_temp_variable = { var = protest_drift distribution = poisson min = 0.5 lambda = 4 } if = { limit = { is_ai = no has_country_flag = open_protests_screen } set_variable = { drift_depression_last = protest_drift } } add_to_variable = { protest_strength = protest_drift } } if = { limit = { OR = { has_idea = CT_internet_monitoring has_idea = CT_protesting_arrests } } randomize_temp_variable = { var = protest_drift distribution = poisson min = 0.5 lambda = 5 } if = { limit = { is_ai = no has_country_flag = open_protests_screen } set_variable = { drift_ct_last = protest_drift } } add_to_variable = { protest_strength = protest_drift } } round_variable = protest_strength clamp_variable = { var = protest_strength min = 0 max = 100 } # Display-only computations: only run when the player has the panel open. if = { limit = { is_ai = no has_country_flag = open_protests_screen } MD_protests_compute_drift_total = yes MD_protests_count_resisting_cores = yes add_to_variable = { global.protest_ui_dirty = 1 } } check_protest_trigger = yes } MD_protests_calc_deterministic_drift = { set_temp_variable = { det_spending_drift = 0 } set_temp_variable = { det_stability_drift = 0 } set_temp_variable = { det_interest_drift = 0 } set_temp_variable = { det_war_drift = 0 } set_temp_variable = { det_corruption_drift = 0 } set_temp_variable = { protest_drift = 0 } calculate_protest_drift = yes set_temp_variable = { det_spending_drift = protest_drift } if = { limit = { has_stability < 0.2 has_elections = yes } set_temp_variable = { det_stability_drift = { value = 0.2 subtract = stability } } } if = { limit = { check_variable = { cb_policy_rate > 8.9 } } set_temp_variable = { det_interest_drift = { value = cb_policy_rate subtract = 8.9 } } } if = { limit = { check_variable = { months_at_war > 36 } } set_temp_variable = { det_war_drift = { value = months_at_war divide = 24 } } } if = { limit = { check_variable = { government_coalition_strength < 0.3 } OR = { has_elections = no has_idea = corruption_level_10 has_idea = corruption_level_09 has_idea = corruption_level_08 has_idea = corruption_level_07 has_idea = corruption_level_06 has_idea = corruption_level_05 } } set_temp_variable = { det_corruption_drift = { value = 0.3 subtract = government_coalition_strength } } } if = { limit = { is_ai = no has_country_flag = open_protests_screen } set_variable = { drift_spending_last = det_spending_drift } set_variable = { drift_stability_last = det_stability_drift } set_variable = { drift_interest_last = det_interest_drift } set_variable = { drift_war_last = det_war_drift } set_variable = { drift_corruption_last = det_corruption_drift } set_variable = { drift_recession_last = 0 } set_variable = { drift_depression_last = 0 } set_variable = { drift_ct_last = 0 } } } MD_protests_recompute_display = { MD_protests_calc_deterministic_drift = yes if = { limit = { has_idea = recession } set_variable = { drift_recession_last = 3 } } if = { limit = { has_idea = depression } set_variable = { drift_depression_last = 4 } } if = { limit = { OR = { has_idea = CT_internet_monitoring has_idea = CT_protesting_arrests } } set_variable = { drift_ct_last = 5 } } MD_protests_compute_drift_total = yes } MD_protests_count_resisting_cores = { set_variable = { cores_resisting_count = 0 } set_variable = { MD_top_resistant_state_value = 0 } if = { limit = { has_event_target = MD_top_resistant_state_scope } clear_global_event_target = MD_top_resistant_state_scope } if = { limit = { has_active_mission = MD_incoming_revolt } every_owned_state = { limit = { is_capital = no is_core_of = PREV is_controlled_by = PREV has_state_flag = MD_protests_active@PREV has_resistance = yes OR = { compliance < 50 resistance > 39 } } PREV = { add_to_variable = { cores_resisting_count = 1 } } set_temp_variable = { state_resistance_val = resistance } if = { limit = { check_variable = { state_resistance_val > PREV.MD_top_resistant_state_value } } PREV = { set_variable = { MD_top_resistant_state_value = state_resistance_val } } save_global_event_target_as = MD_top_resistant_state_scope } } } } MD_protests_clear_display_vars = { clear_variable = drift_spending_last clear_variable = drift_stability_last clear_variable = drift_interest_last clear_variable = drift_recession_last clear_variable = drift_depression_last clear_variable = drift_war_last clear_variable = drift_corruption_last clear_variable = drift_ct_last clear_variable = drift_passive_last clear_variable = drift_total_last clear_variable = cores_resisting_count clear_variable = MD_top_resistant_state_value if = { limit = { has_event_target = MD_top_resistant_state_scope } clear_global_event_target = MD_top_resistant_state_scope } } MD_protests_compute_drift_total = { set_variable = { drift_total_last = { value = drift_passive_last add = drift_spending_last add = drift_stability_last add = drift_interest_last add = drift_recession_last add = drift_depression_last add = drift_war_last add = drift_corruption_last add = drift_ct_last } } } MD_resolve_pacified_protest_states = { if = { limit = { has_active_mission = MD_incoming_revolt } every_owned_state = { limit = { is_core_of = PREV is_controlled_by = PREV has_state_flag = MD_protests_active@PREV has_resistance = yes OR = { is_capital = yes AND = { compliance > 49 resistance < 40 } } } cancel_resistance = yes clr_state_flag = MD_protests_active@PREV set_state_flag = MD_protests_resolved@PREV } } } MD_cleanup_protest_revolt = { every_owned_state = { limit = { is_core_of = PREV has_state_flag = MD_protests_active@PREV has_resistance = yes } cancel_resistance = yes } every_core_state = { clr_state_flag = MD_protests_active@PREV clr_state_flag = MD_protests_resolved@PREV } clr_country_flag = MD_protest_revolt_pending clear_variable = protest_spread_exhaustion set_country_flag = { flag = MD_protest_cooldown days = 1000 value = 1 } } MD_calculate_protest_civil_war_size = { set_temp_variable = { protest_active_state_count = 0 } set_temp_variable = { protest_eligible_state_count = 0 } every_owned_state = { limit = { is_capital = no is_core_of = PREV is_controlled_by = PREV } PREV = { add_to_temp_variable = { protest_eligible_state_count = 1 } } if = { limit = { has_state_flag = MD_protests_active@PREV has_resistance = yes } PREV = { add_to_temp_variable = { protest_active_state_count = 1 } } } } set_temp_variable = { protest_civil_war_size = 0.1 } if = { limit = { check_variable = { protest_eligible_state_count > 0 } } set_temp_variable = { protest_civil_war_size = protest_active_state_count } divide_temp_variable = { protest_civil_war_size = protest_eligible_state_count } } set_temp_variable = { protest_radicalisation_size = protest_radicalisation } divide_temp_variable = { protest_radicalisation_size = 50 } add_to_temp_variable = { protest_civil_war_size = protest_radicalisation_size } clamp_temp_variable = { var = protest_civil_war_size min = 0.1 max = 0.5 } } MD_start_scaled_protest_civil_war = { set_country_flag = no_leader_change if = { limit = { has_government = nationalist } start_civil_war = { ideology = nationalist size = protest_civil_war_size } } else_if = { limit = { has_government = communism } start_civil_war = { ideology = communism size = protest_civil_war_size } } else_if = { limit = { has_government = democratic } start_civil_war = { ideology = democratic size = protest_civil_war_size } } else_if = { limit = { has_government = neutrality } start_civil_war = { ideology = neutrality size = protest_civil_war_size } } else_if = { limit = { has_government = fascism } start_civil_war = { ideology = fascism size = protest_civil_war_size } } clr_country_flag = no_leader_change } check_protest_trigger = { if = { limit = { NOT = { has_country_flag = disabled_protests_system } NOT = { has_country_flag = MD_protest_cooldown } NOT = { has_country_flag = MD_protest_revolt_pending } NOT = { has_active_mission = MD_incoming_protest_movement } NOT = { has_active_mission = MD_incoming_revolt } check_variable = { protest_strength > 49 } } set_temp_variable = { protest_roll = protest_strength } round_temp_variable = protest_roll subtract_from_temp_variable = { protest_roll = 49 } clamp_variable = { var = protest_roll max = 100 } random = { chance = var:protest_roll country_event = { id = protests.200 days = 1 } activate_mission = MD_incoming_protest_movement } } } random_protest_events = { MD_resolve_pacified_protest_states = yes if = { limit = { has_active_mission = MD_incoming_revolt any_owned_state = { is_capital = no is_core_of = ROOT is_controlled_by = ROOT has_state_flag = MD_protests_active@ROOT has_resistance = yes } } add_to_variable = { protest_spread_exhaustion = 5 } clamp_variable = { var = protest_spread_exhaustion min = 0 max = 100 } set_temp_variable = { protest_spread_chance = protest_strength } subtract_from_temp_variable = { protest_spread_chance = protest_spread_exhaustion } clamp_variable = { var = protest_spread_chance min = 0 max = 75 } if = { limit = { check_variable = { protest_spread_chance > 0 } any_owned_state = { is_capital = no is_core_of = ROOT is_controlled_by = ROOT has_resistance = no NOT = { has_state_flag = MD_protests_active@ROOT } NOT = { has_state_flag = MD_protests_resolved@ROOT } } } random = { chance = var:protest_spread_chance country_event = protests.101 } } random_list = { 70 = { # Nothing happens } 10 = { country_event = { id = protests.104 days = 30 } } 10 = { country_event = { id = protests.105 days = 30 } } 10 = { country_event = { id = protests.106 days = 30 } } } } } update_protest_dirty_var = { if = { limit = { is_ai = no } if = { limit = { check_variable = { global.protest_ui_dirty < 100000 } } add_to_variable = { global.protest_ui_dirty = 1 } } else = { set_variable = { global.protest_ui_dirty = 1 } } } }