### Claim the Mandate of Heaven ###
situation_dynastic_cycle_claim_mandate_decision = {
	decision_group_type = dynastic_cycle
	title = situation_dynastic_cycle_claim_mandate_decision
	desc = situation_dynastic_cycle_claim_mandate_decision_desc
	selection_tooltip = situation_dynastic_cycle_claim_mandate_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_stability.dds"
	}
	extra_picture = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_stability.dds"
	sort_order = 80

	cooldown = { years = 5 }

	is_shown = {
		has_tgp_dlc_trigger = yes
		exists = top_participant_group:dynastic_cycle #I am part of the dynastic cycle
		situation:dynastic_cycle = { situation_current_phase = situation_dynastic_cycle_phase_chaos } #The era is division
	}

	is_valid = {
		situation:dynastic_cycle = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		is_independent_ruler = yes
		custom_tooltip = {
			text = claim_mandate_decision_county_percentage_tt
			title:h_china = {
				any_de_jure_county = {
					percent >= claim_mandate_china_county_percentage_value
					holder.top_liege = {
						OR = {
							this = root
							is_tributary_of_suzerain_or_above = root
						}
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_at_peace_adult = yes
	}

	effect = {
		add_character_flag = {
			flag = claimed_the_mandate_of_heaven
			days = 3
		}
		#GoK stops really being GoK
		gok_government_change_story_end_effect = yes
		situation:dynastic_cycle = { save_scope_as = situation }
		tgp_claim_mandate_of_heaven_effect = yes
	}
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 36
		empire = 3
		hegemony = 12
	}
	ai_potential = { 
		situation:dynastic_cycle ?= { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		NOT = {
			any_owned_story = {
				OR = {
					story_type = story_mongol_invasion
					story_type = story_greatest_of_khans
				}
			}
		}
	}
	ai_will_do = { base = 10000 }
}

situation_dynastic_cycle_favor_own_culture_for_appointments = {
	title = situation_dynastic_cycle_favor_own_culture_for_appointments
	desc = situation_dynastic_cycle_favor_own_culture_for_appointments_desc
	selection_tooltip = situation_dynastic_cycle_favor_own_culture_for_appointments_tooltip
	confirm_text = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:situation_dynastic_cycle_remove_favor = yes }
				desc = situation_dynastic_cycle_favor_own_culture_for_appointments_confirm_2
			}
			desc = situation_dynastic_cycle_favor_own_culture_for_appointments_confirm_1
		}
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/tgp_debate.dds"
	}
	sort_order = 70
	decision_group_type = dynastic_cycle

	is_shown = {
		has_title = title:h_china
		top_participant_group:dynastic_cycle ?= {
			has_participant_group_parameter = dynastic_cycle_hegemon_may_favour_own_culture_for_appointments
		}
	}

	is_valid = {
		custom_tooltip = {
			text = government_is_celestial_tt
			government_has_flag = government_is_celestial
		}
		situation:dynastic_cycle = { situation_current_phase =  situation_dynastic_cycle_phase_instability_conquest }
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
	}
	
	cost = {
		prestige = 250
	}
	
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"

		### Favor your own culture
		item = {
			value = situation_dynastic_cycle_favor_own_culture
			is_valid = {
				custom_tooltip = {
					text = situation_dynastic_cycle_own_culture_already_favored_desc
					situation:dynastic_cycle ?= {
						OR = {
							NOT = { has_variable = dynastic_cycle_favored_culture }
							var:dynastic_cycle_favored_culture != root.culture
						}
					}
				}
				#culture ?= {
				#	NOT = { has_cultural_pillar = heritage_chinese }
				#}
			}
			current_description = situation_dynastic_cycle_favor_own_culture_desc
			localization = situation_dynastic_cycle_favor_own_culture_name
			icon = "gfx/interface/icons/message_feed/culture.dds"
			ai_chance = {
				value = 100
			}
		}
		### Remove currently favored culture
		item = {
			value = situation_dynastic_cycle_remove_favor
			is_valid = {
				situation:dynastic_cycle ?= {
					save_temporary_scope_as = situation_scope
					custom_tooltip = {
						text = situation_dynastic_cycle_no_favored_culture_desc
						has_variable = dynastic_cycle_favored_culture
					}
				}
			}
			current_description = situation_dynastic_cycle_remove_favor_desc
			localization = situation_dynastic_cycle_remove_favor_name
			icon = "gfx/interface/icons/message_feed/culture.dds"
			ai_chance = {
				value = 0 # The AI doesn't need to do this
			}
		}
	}

	effect = {
		situation:dynastic_cycle ?= { save_scope_as = situation }
		culture = {
			save_scope_as = hegemon_favored_culture
		}
		if = { # Promote your own culture
			limit = { scope:situation_dynastic_cycle_favor_own_culture = yes }
			custom_tooltip = {
				text = situation_dynastic_cycle_conquest_favor_own_culture_desc
				situation:dynastic_cycle ?= {
					set_variable = {
						name = dynastic_cycle_favored_culture
						value = scope:hegemon_favored_culture
					}
				}
				
				# Notify any vassal players
				every_player = {
					limit = { target_is_liege_or_above = root }
					
				}
			}
		}
		else_if = { # Stop promoting currently promoted culture
			limit = { scope:situation_dynastic_cycle_remove_favor = yes }
			custom_tooltip = {
				text = situation_dynastic_cycle_conquest_stop_favored_culture_desc
				situation:dynastic_cycle ?= {
					remove_variable = dynastic_cycle_favored_culture
				}
				
				# Notify any vassal players
				every_player = {
					limit = { target_is_liege_or_above = root }
					
				}
			}
		}
	}
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 0
		hegemony = 36
	}
	
	ai_potential = { always = yes }
	
	ai_will_do = {
		base = 30
		
		modifier = {
			ai_boldness >= high_positive_ai_value
			add = 45
		}
		modifier = {
			ai_honor >= very_high_positive_ai_value
			ai_rationality >= very_high_positive_ai_value
			add = -30
		}
	}
}

#only for Players - ability to choose a participation group in the Dynastic Cycle
### Join Movement ###
situation_dynastic_cycle_choose_movement_decision = {
	decision_group_type = dynastic_cycle
	title = situation_dynastic_cycle_choose_movement_decision
	desc = situation_dynastic_cycle_choose_movement_decision_desc
	selection_tooltip = situation_dynastic_cycle_choose_movement_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/decisions/tgp_scholars.dds"
	}
	sort_order = 80

	is_shown = {
		has_tgp_dlc_trigger = yes
		is_ai = no
		any_character_situation = {
			situation_type = dynastic_cycle
			NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		}
		top_participant_group:dynastic_cycle ?= {
			NOR = {
				participant_group_type = other_rulers
				participant_group_type = hegemon_ruler
			}
		}
	}

	is_valid_showing_failures_only = {
		is_adult = yes
		custom_tooltip = {
			text = situation_dynastic_cycle_choose_movement_decision_cannot_leave_var
			NOT = { has_variable = dynastic_cycle_cannot_leave_movement_var }
		}
	}
	cooldown = { years = 5 }
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = yes

		item = {
			value = pro_hegemon_movement
			is_valid = {
				custom_tooltip = {
					text = already_in_this_movement_desc
					situation:dynastic_cycle ?= {
						situation_participant_group:pro_hegemon_movement = {
							NOT = { participant_group_has_character = root }
						}
					}
				}
			}
			current_description = choose_pro_hegemon_movement_desc
			localization = choose_pro_hegemon_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_pro.dds"
			flat = yes
			ai_chance = {
				value = 100
			}
		}
		item = {
			value = expansion_movement
			is_valid = {
				custom_tooltip = {
					text = already_in_this_movement_desc
					situation:dynastic_cycle ?= {
						situation_participant_group:expansion_movement = {
							NOT = { participant_group_has_character = root }
						}
					}
				}
			}
			current_description = choose_expansion_movement_desc
			localization = choose_expansion_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_expand.dds"
			flat = yes
			ai_chance = {
				value = 100
			}
		}
		item = {
			value = advancement_movement
			is_valid = {
				custom_tooltip = {
					text = already_in_this_movement_desc
					situation:dynastic_cycle ?= {
						situation_participant_group:advancement_movement = {
							NOT = { participant_group_has_character = root }
						}
					}
				}
			}
			current_description = choose_advancement_movement_desc
			localization = choose_advancement_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_advance.dds"
			flat = yes
			ai_chance = {
				value = 100
			}
		}
		item = {
			value = conservative_movement
			is_valid = {
				custom_tooltip = {
					text = already_in_this_movement_desc
					situation:dynastic_cycle ?= {
						situation_participant_group:conservative_movement = {
							NOT = { participant_group_has_character = root }
						}
					}
				}
			}
			current_description = choose_conservative_movement_desc
			localization = choose_conservative_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_anti.dds"
			flat = yes
			ai_chance = {
				value = 100
			}
		}
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = {
					government_allows = administrative
				}
				# Base cost
				value = monumental_influence_value
				# More expensive for each disciple
				add = {
					value = 10
					multiply = root.number_of_disciples
				}
				# Less expensive to go out of the undecided movement to any other movement
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							situation_participant_group:undecided_movement = {
								participant_group_has_character = root
							}
						}
					}
					multiply = 0.5
				}
				# Reduce the cost if your elder is in the selected movement
				if = {
					limit = {
						any_relation = {
							type = elder
							save_temporary_scope_as = elder
						}
						situation:dynastic_cycle ?= {
							OR = {
								AND = {
									situation_participant_group:pro_hegemon_movement = {
										participant_group_has_character = scope:elder
									}
									scope:pro_hegemon_movement ?= yes
								}
								AND = {
									situation_participant_group:expansion_movement = {
										participant_group_has_character = scope:elder
									}
									scope:expansion_movement ?= yes
								}
								AND = {
									situation_participant_group:advancement_movement = {
										participant_group_has_character = scope:elder
									}
									scope:advancement_movement ?= yes
								}
								AND = {
									situation_participant_group:conservative_movement = {
										participant_group_has_character = scope:elder
									}
									scope:conservative_movement ?= yes
								}
							}
						}
					}
					multiply = 0.5
				}
			}
		}
		# Non-admins pay prestige instead
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { government_allows = administrative }
				}
				# Base cost
				value = {
					value = monumental_influence_value
					multiply = 2
				}
				# Less expensive to go out of the undecided movement to any other movement
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							situation_participant_group:undecided_movement = {
								participant_group_has_character = root
							}
						}
					}
					multiply = 0.5
				}
			}
		}
	}

	effect = {
		save_scope_as = recipient #for loc
		switch = {
			trigger = yes
			scope:pro_hegemon_movement = {
				custom_tooltip = choose_pro_hegemon_movement_tt
				situation:dynastic_cycle ?= {
					situation_participant_group:pro_hegemon_movement = {
						save_scope_as = situation_participant_group
					}
				}
				if = {
					limit = {
						scope:recipient.var:movement_power >= high_movement_power_value
					}
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:recipient.top_liege
						CATALYST = catalyst_movement_gained_power_pro_hegemon
					}
				}
				set_variable = {
					name = movement_member
					value = flag:pro_hegemon
				}
			}
			scope:expansion_movement = {
				custom_tooltip = choose_expansion_movement_tt
				situation:dynastic_cycle ?= {
					situation_participant_group:expansion_movement = {
						save_scope_as = situation_participant_group
					}
				}
				if = {
					limit = {
						scope:recipient.var:movement_power >= high_movement_power_value
					}
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:recipient.top_liege
						CATALYST = catalyst_movement_gained_power_expansion
					}
				}
				set_variable = {
					name = movement_member
					value = flag:expansion
				}
			}
			scope:advancement_movement = {
				custom_tooltip = choose_advancement_movement_tt
				situation:dynastic_cycle ?= {
					situation_participant_group:advancement_movement = {
						save_scope_as = situation_participant_group
					}
				}
				if = {
					limit = {
						scope:recipient.var:movement_power >= high_movement_power_value
					}
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:recipient.top_liege
						CATALYST = catalyst_movement_gained_power_advancement
					}
				}
				set_variable = {
					name = movement_member
					value = flag:advancement
				}
			}
			scope:conservative_movement = {
				custom_tooltip = choose_conservative_movement_tt
				situation:dynastic_cycle ?= {
					situation_participant_group:conservative_movement = {
						save_scope_as = situation_participant_group
					}
				}
				if = {
					limit = {
						scope:recipient.var:movement_power >= high_movement_power_value
					}
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:recipient.top_liege
						CATALYST = catalyst_movement_gained_power_conservative
					}
				}
				set_variable = {
					name = movement_member
					value = flag:conservative
				}
			}
		}
		custom_tooltip = adds_movement_power_tt
		if = {
			limit = {
				any_relation = {
					type = disciple
				}
			}
			custom_tooltip = {
				text = every_disciple_adds_movement_power_tt
				every_relation = {
					type = disciple
					recalculate_participant_group = situation:dynastic_cycle
				}
			}
		}
		if = { # break up with the elder if the movement is not the same after applying previous effects and changing your own
			limit = {
				any_relation = {
					type = elder
					save_temporary_scope_as = elder
				}
				scope:elder = {
					top_participant_group:dynastic_cycle = root.top_participant_group:dynastic_cycle
				}
			}
			custom_tooltip = {
				text = situation_dynastic_cycle_choose_movement_decision_elder_tt
				run_interaction = {
					interaction = break_with_elder
					actor = root
					recipient = scope:elder
					execute_threshold = accept
				}
			}
		}
		hidden_effect = { recalculate_participant_group = situation:dynastic_cycle }
	}

	#AI is slotted into the groups automatically by the situation participant groups script in the tgp_dynastic_cycle file
	ai_check_interval = 0
}
# a petition in the name of your movement to be delivered to hegemon/relevant minister
### Make Movement Petition ###
movement_petition_decision = {
	decision_group_type = dynastic_cycle
	title = movement_petition_decision
	desc = movement_petition_decision_desc
	selection_tooltip = movement_petition_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_stability.dds"
	}
	sort_order = 80

	is_shown = {
		has_tgp_dlc_trigger = yes
		top_participant_group:dynastic_cycle ?= {
			NOR = {
				participant_group_type = other_rulers
				participant_group_type = hegemon_ruler
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_any_movement_leader = yes
		influence >= major_influence_value
		trigger_if = {
			limit = {
				situation:dynastic_cycle ?= {
					any_participant_group = {
						var:recent_movement_petition ?= {
							is_ai = no
						}
						save_temporary_scope_as = petitioning_movement_recent
					}
				}
			}
			custom_tooltip = {
				text = movement_petition_decision.recent_movement_petition_reason
				always = no
			}
		}
		trigger_if = {
			limit = {
				situation:dynastic_cycle ?= {
					any_participant_group = {
						var:movement_petition_in_progress ?= {
							is_ai = no
						}
						save_temporary_scope_as = petitioning_movement_progress
					}
				}
			}
			custom_tooltip = {
				text = movement_petition_decision.movement_petition_in_progress_reason
				always = no
			}
		}
	}
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "movement_petition_decision_select_petition"
		show_from_start = yes

		item = {
			value = change_celestial_bureaucracy
			is_valid = {
				title:h_china.holder ?= {
					government_has_flag = government_is_celestial
				}
			}
			current_description = change_celestial_bureaucracy_desc
			localization = change_celestial_bureaucracy_name
			icon = "gfx/interface/icons/message_feed/law.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = change_celestial_army_liege_law
			is_valid = {
				title:h_china.holder ?= {
					government_has_flag = government_is_celestial
				}
			}
			current_description = change_celestial_army_liege_law_desc
			localization = change_celestial_army_liege_law_name
			icon = "gfx/interface/icons/message_feed/soldier.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = change_province_type
			is_valid = {
				title:h_china.holder ?= {
					government_has_flag = government_is_celestial
				}
				custom_tooltip = {
					text = change_province_type_vassal_contract_blocked_reason
					top_participant_group:dynastic_cycle ?= {
						any_situation_group_participant = {
							vassal_contract_has_modifiable_obligations = yes
						}
					}
				}
			}
			current_description = change_province_type_desc
			localization = change_province_type_name
			icon = "gfx/interface/icons/celestial_administration_types/icon_standard_administration.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = change_retirement_law
			is_valid = {
				title:h_china.holder ?= {
					government_has_flag = government_is_celestial
				}
			}
			current_description = change_retirement_law_desc
			localization = change_retirement_law_name
			icon = "gfx/interface/icons/message_feed/icon_scheme_promote.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = increase_budget
			is_valid = {
				title:h_china.holder ?= {
					government_has_flag = government_is_celestial
				}
			}
			current_description = increase_budget_desc
			localization = increase_budget_name
			icon = "gfx/interface/icons/icon_imperial_treasury.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = hold_examinations
			is_valid = {
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = advancement_movement
				}
			}
			current_description = hold_examinations_desc
			localization = hold_examinations_name
			icon = "gfx/interface/icons/activities/activity_imperial_examination.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = change_candidate_score_law
			is_valid = {
				trigger_if = {
					limit = {
						top_liege = {
							has_realm_law = candidate_score_merit_law
						}
					}
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = conservative_movement
					}
					top_liege = {
						can_pass_candidate_score_prestige_law_trigger = yes
					}
				}
				trigger_else = {
					top_participant_group:dynastic_cycle ?= {
						NOT = { participant_group_type = conservative_movement }
					}
					top_liege = {
						can_pass_candidate_score_merit_law_trigger = yes
					}
				}
			}
			current_description = change_candidate_score_law_desc
			localization = change_candidate_score_law_name
			icon = "gfx/interface/icons/appointment_score.dds"
			ai_chance = {
				value = 0
			}
		}
	}

	effect = {
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					var:movement_leader ?= root
				}
				save_scope_as = actors_movement
			}
		}
		save_scope_as = petitioner
		title:h_china.holder ?= {
            save_scope_as = hegemon
			save_scope_as = petition_recipient
		}
		display_movement_petition_recipient_acceptance_chance_effect = yes
		switch = {
			trigger = yes
			scope:change_celestial_bureaucracy = {
				custom_tooltip = celestial_movement_demands_interaction.tt.change_celestial_bureaucracy
				set_variable = {
					name = movement_petition
					value = flag:change_bureaucracy_laws
				}
				open_view_data = {
					view = decision_detail
					data = decision:movement_petition_change_laws_decision
					player = root
				}
			}
			scope:change_celestial_army_liege_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_army_laws
				}
				custom_tooltip = celestial_movement_demands_interaction.tt.change_celestial_army_law
				open_view_data = {
					view = decision_detail
					data = decision:movement_petition_change_laws_decision
					player = root
				}
			}
			scope:change_province_type = {
				set_variable = {
					name = movement_petition
					value = flag:change_province
				}
				custom_tooltip = celestial_movement_demands_interaction.tt.change_province_type
				open_view_data = {
					view = decision_detail
					data = decision:movement_petition_change_laws_decision
					player = root
				}
			}
			scope:change_retirement_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_retirement_law
				}
				custom_tooltip = celestial_movement_demands_interaction.tt.change_retirement_law
				open_view_data = {
					view = decision_detail
					data = decision:movement_petition_change_laws_decision
					player = root
				}
			}
			scope:change_candidate_score_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_candidate_score_law
				}
				custom_tooltip = celestial_movement_demands_interaction.tt.change_candidate_score_law
				if = {
					limit = {
						scope:petitioner.location != scope:petition_recipient.capital_province
					}
					start_travel_plan = {
						destination = scope:petition_recipient.capital_province
						on_arrival_event = tgp_decision_events.0100
						on_travel_planner_cancel_event = tgp_decision_events.0199
					}
				}
				else = {
					trigger_event = tgp_decision_events.0100
				}
			}
			scope:increase_budget = {
				set_variable = {
					name = movement_petition
					value = flag:increase_budget
				}
				custom_tooltip = celestial_movement_demands_interaction.tt.increase_budget
				open_view_data = {
					view = decision_detail
					data = decision:movement_petition_change_laws_decision
					player = root
				}
			}
			scope:hold_examinations = {
				set_variable = {
					name = movement_petition
					value = flag:hold_examinations
				}
				scope:hegemon = {
					save_scope_as = recipient #for loc to work
				}
				custom_tooltip = celestial_movement_demands_interaction.tt.hold_examinations_effect
				if = {
					limit = {
						scope:petitioner.location != scope:petition_recipient.capital_province
					}
					start_travel_plan = {
						destination = scope:petition_recipient.capital_province
						on_arrival_event = tgp_decision_events.0100
						on_travel_planner_cancel_event = tgp_decision_events.0199
					}
				}
				else = {
					trigger_event = tgp_decision_events.0100
				}
			}
		}
		show_as_tooltip = {
			change_influence = major_influence_loss
			if = {
				limit = {
					scope:petitioner.location != scope:petition_recipient.capital_province
				}
				custom_tooltip = movement_petition_decision.travel
			}
		}
	}

	ai_potential = { 
		always = no
	}
	ai_check_interval = 0
}
# a second step of the decision above to select the details of the petition
### Movement Petition Change Laws Decision ###
movement_petition_change_laws_decision = {
	decision_group_type = dynastic_cycle
	title = movement_petition_decision
	desc = movement_petition_decision_desc
	selection_tooltip = movement_petition_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_stability.dds"
	}
	is_invisible = yes
	
	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_any_movement_leader = yes
		influence >= major_influence_value
		trigger_if = {
			limit = {
				situation:dynastic_cycle ?= {
					any_participant_group = {
						var:recent_movement_petition ?= {
							is_ai = no
						}
						save_temporary_scope_as = petitioning_movement_recent
					}
				}
			}
			custom_tooltip = {
				text = movement_petition_decision.recent_movement_petition_reason
				always = no
			}
		}
		trigger_if = {
			limit = {
				situation:dynastic_cycle ?= {
					any_participant_group = {
						var:movement_petition_in_progress ?= {
							is_ai = no
						}
						save_temporary_scope_as = petitioning_movement_progress
					}
				}
			}
			custom_tooltip = {
				text = movement_petition_decision.movement_petition_in_progress_reason
				always = no
			}
		}
	}

	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "movement_petition_decision_select_petition"
		show_from_start = yes

		item = {
			value = increase_law
			is_shown = {
				var:movement_petition ?= flag:change_bureaucracy_laws
			}
			is_valid = {
				title:h_china.holder = {
					NOT = {
						realm_law_group_at_maximum_level = celestial_bureaucracy
					}
					trigger_if = {
						limit = {
							has_realm_law = celestial_bureaucracy_2
						}
						situation:dynastic_cycle ?= {
							NOR = {
								situation_current_phase = situation_dynastic_cycle_phase_instability
								situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
							}
						}
					}
					culture = { has_innovation = innovation_all_things }
				}
			}
			current_description = change_celestial_bureaucracy_increase_desc
			localization = change_celestial_bureaucracy_increase_name
			icon = "gfx/interface/icons/symbols/icon_arrow_up.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = decrease_law
			is_shown = {
				var:movement_petition ?= flag:change_bureaucracy_laws
			}
			is_valid = {
				title:h_china.holder = {
					NOT = {
						realm_law_group_at_minimum_level = celestial_bureaucracy
					}
				}
			}
			current_description = change_celestial_bureaucracy_decrease_desc
			localization = change_celestial_bureaucracy_decrease_name
			icon = "gfx/interface/icons/symbols/icon_arrow_green_down.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = increase_army_law
			is_shown = {
				var:movement_petition ?= flag:change_army_laws
			}
			is_valid = {
				title:h_china.holder = {
					NOT = {
						has_realm_law = celestial_army_liege_law_3
					}
					trigger_if = {
						limit = {
							has_realm_law = celestial_army_liege_law_2
						}
						has_realm_law = celestial_bureaucracy_3
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						}
					}
					trigger_if = {
						limit = {
							OR = {
								has_realm_law = celestial_army_liege_law_0
								has_realm_law = celestial_army_liege_law_1
							}
						}
						custom_tooltip = {
							text = have_bureaucracy_2_or_higher
							OR = {
								has_realm_law = celestial_bureaucracy_2
								has_realm_law = celestial_bureaucracy_3
							}
						}
					}
				}
			}
			current_description = change_army_laws_increase_desc
			localization = change_army_laws_increase_name
			icon = "gfx/interface/icons/symbols/icon_arrow_up.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = decrease_army_law
			is_shown = {
				var:movement_petition ?= flag:change_army_laws
			}
			is_valid = {
				title:h_china.holder = {
					NOT = {
						has_realm_law = celestial_army_liege_law_0
					}
				}
			}
			current_description = change_army_laws_decrease_desc
			localization = change_army_laws_decrease_name
			icon = "gfx/interface/icons/symbols/icon_arrow_green_down.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = increase_budget_salary
			is_shown = {
				var:movement_petition ?= flag:increase_budget
			}
			is_valid = {
				top_liege = {
					NOT = { realm_law_group_at_maximum_level = budget_allocation_salary_law }
				}
			}
			current_description = increase_budget_salary_desc
			localization = increase_budget_salary_name
			icon = "gfx/interface/icons/icon_imperial_treasury.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = increase_budget_ministry
			is_shown = {
				var:movement_petition ?= flag:increase_budget
			}
			is_valid = {
				top_liege = {
					NOT = { realm_law_group_at_maximum_level = budget_allocation_ministry_law }
				}
			}
			current_description = increase_budget_ministry_desc
			localization = increase_budget_ministry_name
			icon = "gfx/interface/icons/court_position_types/favored_minister_court_position.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = increase_budget_military
			is_shown = {
				var:movement_petition ?= flag:increase_budget
			}
			is_valid = {
				top_liege = {
					NOT = { realm_law_group_at_maximum_level = budget_allocation_military_law }
				}
			}
			current_description = increase_budget_military_desc
			localization = increase_budget_military_name
			icon = "gfx/interface/icons/message_feed/soldier.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = province_metropolitan
			is_shown = {
				var:movement_petition ?= flag:change_province
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_participant_group:expansion_movement = {
						any_situation_group_participant = {
							vassal_contract_obligation_level:celestial_provinces != 2
						}
					}
				}
			}
			current_description = change_province_metropolitan_desc
			localization = change_province_metropolitan_name
			icon = "gfx/interface/icons/celestial_administration_types/icon_game_concept_celestial_metropolitan_administration.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = province_industrial
			is_shown = {
				var:movement_petition ?= flag:change_province
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_participant_group:expansion_movement = {
						any_situation_group_participant = {
							vassal_contract_obligation_level:celestial_provinces != 1
						}
					}
				}
			}
			current_description = change_province_industrial_desc
			localization = change_province_industrial_name
			icon = "gfx/interface/icons/celestial_administration_types/icon_game_concept_celestial_industrial_administration.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = province_military
			is_shown = {
				var:movement_petition ?= flag:change_province
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_participant_group:expansion_movement = {
						any_situation_group_participant = {
							vassal_contract_obligation_level:celestial_provinces != 3
						}
					}
				}
			}
			current_description = change_province_military_desc
			localization = change_province_military_name
			icon = "gfx/interface/icons/celestial_administration_types/icon_game_concept_celestial_military_administration.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = province_protectorate
			is_shown = {
				var:movement_petition ?= flag:change_province
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_participant_group:expansion_movement = {
						any_situation_group_participant = {
							vassal_contract_obligation_level:celestial_provinces != 4
						}
					}
				}
			}
			current_description = change_province_protectorate_desc
			localization = change_province_protectorate_name
			icon = "gfx/interface/icons/celestial_administration_types/icon_game_concept_celestial_protectorate_administration.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = increase_retirement_law
			is_shown = {
				var:movement_petition ?= flag:change_retirement_law
			}
			is_valid = {
				title:h_china.holder = {
					NOT = {
						has_realm_law = celestial_retirement_law_5
					}
					custom_tooltip = {
						text = have_celestial_bureaucracy_1_or_higher
						NOT = { realm_law_group_at_minimum_level = celestial_bureaucracy }
					}
				}
			}
			current_description = change_retirement_law_increase_desc
			localization = change_retirement_law_increase_name
			icon = "gfx/interface/icons/symbols/icon_arrow_up.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = decrease_retirement_law
			is_shown = {
				var:movement_petition ?= flag:change_retirement_law
			}
			is_valid = {
				title:h_china.holder = {
					NOT = {
						has_realm_law = celestial_retirement_law_0
					}
					custom_tooltip = {
						text = have_celestial_bureaucracy_1_or_higher
						NOT = { realm_law_group_at_minimum_level = celestial_bureaucracy }
					}
				}
			}
			current_description = change_retirement_law_decrease_desc
			localization = change_retirement_law_decrease_name
			icon = "gfx/interface/icons/symbols/icon_arrow_green_down.dds"
			ai_chance = {
				value = 0
			}
		}
	}
	effect = {
		save_scope_as = petitioner
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					var:movement_leader ?= root
				}
				save_scope_as = actors_movement
			}
		}
		title:h_china.holder ?= {
            save_scope_as = hegemon
			save_scope_as = petition_recipient
		}
		switch = {
			trigger = yes
			scope:increase_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_bureaucracy_laws_increase
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_bureaucracy_laws_increase
				}
			}
			scope:decrease_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_bureaucracy_laws_decrease
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_bureaucracy_laws_decrease
				}
			}
			scope:increase_army_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_army_laws_increase
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_army_laws_increase
				}
			}
			scope:decrease_army_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_army_laws_decrease
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_army_laws_decrease
				}
			}
			scope:province_metropolitan = {
				set_variable = {
					name = movement_petition
					value = flag:change_province_metropolitan
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_province_metropolitan
				}
			}
			scope:province_industrial = {
				set_variable = {
					name = movement_petition
					value = flag:change_province_industrial
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_province_industrial
				}
			}
			scope:province_military = {
				set_variable = {
					name = movement_petition
					value = flag:change_province_military
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_province_military
				}
			}
			scope:province_protectorate = {
				set_variable = {
					name = movement_petition
					value = flag:change_province_protectorate
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_province_protectorate
				}
			}
			scope:increase_retirement_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_retirement_law_increase
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_retirement_law_increase
				}
			}
			scope:decrease_retirement_law = {
				set_variable = {
					name = movement_petition
					value = flag:change_retirement_law_decrease
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:change_retirement_law_decrease
				}
			}
			scope:increase_budget_salary = {
				set_variable = {
					name = movement_petition
					value = flag:increase_budget_salary
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:increase_budget_salary
				}
			}
			scope:increase_budget_ministry = {
				set_variable = {
					name = movement_petition
					value = flag:increase_budget_ministry
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:increase_budget_ministry
				}
			}
			scope:increase_budget_military = {
				set_variable = {
					name = movement_petition
					value = flag:increase_budget_military
				}
				save_scope_value_as = {
					name = movement_petition_effect
					value = flag:increase_budget_military
				}
			}
		}
		display_movement_petition_recipient_acceptance_effect = yes
		if = {
			limit = {
				scope:petitioner.location != scope:petition_recipient.capital_province
			}
			start_travel_plan = {
				destination = scope:petition_recipient.capital_province
				on_arrival_event = tgp_decision_events.0100
				on_travel_planner_cancel_event = tgp_decision_events.0199
			}
		}
		else = {
			trigger_event = tgp_decision_events.0100
		}
		show_as_tooltip = {
			change_influence = major_influence_loss
			custom_tooltip = movement_petition_decision.travel
		}
		scope:actors_movement = {
			set_variable = {
				name = movement_petition_in_progress
				value = scope:petitioner
				years = 3
			}
		}
	}
	ai_potential = {
		always = no
	}
	ai_check_interval = 0
}
# AI only - petition to change laws in China, replaces the 2 petitions above for the AI
### Make Movement Petition ###
ai_movement_petition_change_laws_decision = {
	decision_group_type = dynastic_cycle
	title = movement_petition_decision
	desc = movement_petition_decision_desc
	selection_tooltip = movement_petition_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_stability.dds"
	}
	is_invisible = yes
	cooldown = { years = 10 }
	
	is_valid = {
		is_available_ai_adult = yes
		is_any_movement_leader = yes
		influence >= major_influence_value
		trigger_if = {
			limit = {
				situation:dynastic_cycle ?= {
					any_participant_group = {
						exists = var:recent_movement_petition
						save_temporary_scope_as = petitioning_movement_recent
					}
				}
			}
			custom_tooltip = {
				text = movement_petition_decision.recent_movement_petition_reason
				always = no
			}
		}
		trigger_if = {
			limit = {
				situation:dynastic_cycle ?= {
					any_participant_group = {
						exists = var:movement_petition_in_progress
						save_temporary_scope_as = petitioning_movement_progress
					}
				}
			}
			custom_tooltip = {
				text = movement_petition_decision.movement_petition_in_progress_reason
				always = no
			}
		}
	}
	effect = {
		save_scope_as = petitioner
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					var:movement_leader ?= root
				}
				save_scope_as = actors_movement
			}
		}
		title:h_china.holder ?= {
            save_scope_as = hegemon
			save_scope_as = petition_recipient
		}
		# Decide for the AI which petition they should go for
		random_list = {
			0 = { # Increase Bureaucracy
				trigger = {
					NOT = { # Bureaucracy not at max
						top_liege = { realm_law_group_at_maximum_level = celestial_bureaucracy }
					}
					trigger_if = {
						limit = {
							has_realm_law = celestial_bureaucracy_2
						}
						situation:dynastic_cycle ?= {
							NOR = {
								situation_current_phase = situation_dynastic_cycle_phase_instability
								situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
							}
						}
					}
					top_liege.culture = { has_innovation = innovation_all_things }
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = advancement_movement
					}
					add = 50
				}
				modifier = {
					situation:dynastic_cycle ?= {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
					add = 10
				}
				save_scope_value_as = {
					name = increase_law
					value = yes
				}
			}
			0 = { # Decrease Bureaucracy
				trigger = {
					NOT = { # Bureaucracy not a min
						top_liege = { realm_law_group_at_minimum_level = celestial_bureaucracy }
					}
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = expansion_movement
					}
					add = 50	
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						}
					}
					add = 10
				}
				save_scope_value_as = {
					name = decrease_law
					value = yes
				}
			}
			0 = { # Increase Army
				trigger = {
					top_liege = {
						trigger_if = { # Higher levels require high bureaucracy
							limit = { has_realm_law = celestial_army_liege_law_0 }
							NOT = { has_realm_law = celestial_bureaucracy_0 }
						}
						trigger_else_if = { # Higher levels require high bureaucracy
							limit = { has_realm_law = celestial_army_liege_law_1 }
							OR = {
								has_realm_law = celestial_bureaucracy_2
								has_realm_law = celestial_bureaucracy_3
							}
						}
						trigger_else_if = { # Higher levels require high bureaucracy
							limit = { has_realm_law = celestial_army_liege_law_2 }
							has_realm_law = celestial_bureaucracy_3
							# Highest only in Expansion Phase
							situation:dynastic_cycle ?= { situation_current_phase = situation_dynastic_cycle_phase_stability_expansion }
						}
						trigger_else = { always = no }
					}
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = expansion_movement
					}
					add = 50
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						}
					}
					add = 10
				}
				save_scope_value_as = {
					name = increase_army_law
					value = yes
				}
			}
			0 = { # Decrease Army
				trigger = {
					NOT = { # Army not a min
						top_liege = { realm_law_group_at_minimum_level = celestial_army_liege_law }
					}
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = advancement_movement
					}
					add = 50
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					add = 10
				}
				save_scope_value_as = {
					name = decrease_army_law
					value = yes
				}
			}
			0 = { # Metropolitan Province
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = advancement_movement
					}
					add = 20
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					add = 20
				}
				save_scope_value_as = {
					name = province_metropolitan
					value = yes
				}
			}
			0 = { # Industrial Province
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = advancement_movement
					}
					add = 10
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					add = 10
				}
				save_scope_value_as = {
					name = province_industrial
					value = yes
				}
			}
			0 = { # Military Province
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = expansion_movement
					}
					add = 10
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						}
					}
					add = 10
				}
				save_scope_value_as = {
					name = province_military
					value = yes
				}
			}
			0 = { # Protectorate Province
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = expansion_movement
					}
					add = 20
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						}
					}
					add = 20
				}
				save_scope_value_as = {
					name = province_protectorate
					value = yes
				}
			}
			0 = { # Hold Exams
				trigger = {
					NOT = { # Conservatives don't like exams
						top_participant_group:dynastic_cycle ?= { participant_group_type = conservative_movement }
					}
				}
				modifier = {
					title:h_china ?= {
						exists = var:years_since_imperial_examination
						var:years_since_imperial_examination >= catalyst_imperial_examinations_gap_short_yearly_value
					}
					add = 10
				}
				save_scope_value_as = {
					name = hold_examinations
					value = yes
				}
			}
			0 = { # Increase Retirement
				trigger = {
					top_liege = {
						NOR = {
							# Some bureaucracy needed for retirement
							realm_law_group_at_minimum_level = celestial_bureaucracy
							# Retirement not at max
							realm_law_group_at_maximum_level = celestial_retirement_law
						}
					}
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						}
					}
					add = 10
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = conservative_movement
					}
					add = 50
				}
				save_scope_value_as = {
					name = increase_retirement_law
					value = yes
				}
			}
			0 = { # Decrease Retirement
				trigger = {
					top_liege = {
						NOR = {
							# Some bureaucracy needed for retirement
							realm_law_group_at_minimum_level = celestial_bureaucracy
							# Retirement not at max
							realm_law_group_at_maximum_level = celestial_retirement_law
						}
					}
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					add = 10
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = conservative_movement
					}
					factor = 0
				}
				save_scope_value_as = {
					name = decrease_retirement_law
					value = yes
				}
			}
			0 = { # Increase Salary Budget
				trigger = {
					NOR = {
						# Treasury not empty
						top_liege = { monthly_character_treasury_balance <= 0 }
						# Salaries don't go up in Conservative/Expansion
						top_participant_group:dynastic_cycle ?= {
							OR = {
								participant_group_type = conservative_movement
								participant_group_type = expansion_movement
							}
						}
					}
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					add = 1
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = advancement_movement
					}
					add = 1
				}
				save_scope_value_as = {
					name = increase_budget_salary
					value = yes
				}
			}
			0 = { # Increase Ministry Budget
				trigger = {
					NOR = {
						# Treasury not empty
						top_liege = { monthly_character_treasury_balance <= 0 }
						# Salaries don't go down in Advancement/Expansion
						top_participant_group:dynastic_cycle ?= {
							OR = {
								participant_group_type = advancement_movement
								participant_group_type = expansion_movement
							}
						}
					}
				}
				modifier = {
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					add = 1
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = conservative_movement
					}
					add = 1
				}
				save_scope_value_as = {
					name = increase_budget_ministry
					value = yes
				}
			}
			0 = { # Candidate Score
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = conservative_movement
					}
					top_liege = {
						has_realm_law = candidate_score_merit_law
						any_councillor = {
							count = all
							top_participant_group:dynastic_cycle ?= {
								participant_group_type = conservative_movement
							}
						}
						any_powerful_vassal = {
							count = all
							top_participant_group:dynastic_cycle ?= {
								participant_group_type = conservative_movement
							}
						}
					}
					add = 1
				}
				modifier = {
					top_participant_group:dynastic_cycle ?= {
						NOT = { participant_group_type = conservative_movement }
					}
					top_liege = {
						has_realm_law = candidate_score_prestige_law
						any_councillor = {
							count = all
							top_participant_group:dynastic_cycle ?= {
								NOT = { participant_group_type = conservative_movement }
							}
						}
						any_powerful_vassal = {
							count = all
							top_participant_group:dynastic_cycle ?= {
								NOT = { participant_group_type = conservative_movement }
							}
						}
					}
					add = 1
				}
				save_scope_value_as = {
					name = change_candidate_score_law
					value = yes
				}
			}
		}
		# Set the variable to reference the chosen petition in the follow up events
		if = {
            limit = {
                exists = scope:increase_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_bureaucracy_laws_increase
            }
	    }
	    else_if = {
            limit = {
                exists = scope:decrease_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_bureaucracy_laws_decrease
            }
	    }
	    else_if = {
            limit = {
                exists = scope:increase_army_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_army_laws_increase
            }
	    }
	    else_if = {
            limit = {
                exists = scope:decrease_army_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_army_laws_decrease
            }
	    }
	    else_if = {
            limit = {
                exists = scope:province_metropolitan
            }
            set_variable = {
                name = movement_petition
                value = flag:change_province_metropolitan
            }
	    }
	    else_if = {
            limit = {
                exists = scope:province_industrial
            }
            set_variable = {
                name = movement_petition
                value = flag:change_province_industrial
            }
	    }
	    else_if = {
            limit = {
                exists = scope:province_military
            }
            set_variable = {
                name = movement_petition
                value = flag:change_province_military
       		}
	    }
	    else_if = {
            limit = {
                exists = scope:province_protectorate
            }
            set_variable = {
                name = movement_petition
                value = flag:change_province_protectorate
            }
	    }
	    else_if = {
            limit = {
                exists = scope:hold_examinations
            }
            set_variable = {
                name = movement_petition
                value = flag:hold_examinations
            }
	    }
	    else_if = {
            limit = {
                exists = scope:increase_retirement_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_retirement_law_increase
            }
	    }
	    else_if = {
            limit = {
                exists = scope:decrease_retirement_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_retirement_law_decrease
            }
	    }
	    else_if = {
            limit = {
                exists = scope:increase_budget_salary
            }
            set_variable = {
                name = movement_petition
                value = flag:increase_budget_salary
            }
	    }
	    else_if = {
            limit = {
                exists = scope:increase_budget_ministry
            }
            set_variable = {
                    name = movement_petition
                    value = flag:increase_budget_ministry
            }
	    }
	    else_if = {
            limit = {
                exists = scope:increase_budget_military
            }
            set_variable = {
                name = movement_petition
                value = flag:increase_budget_military
            }
	    }
	    else_if = {
            limit = {
            	exists = scope:change_candidate_score_law
            }
            set_variable = {
                name = movement_petition
                value = flag:change_candidate_score_law
            }
	    }
	    else = {
	    	# Left for debugging in case something goes wrong with saving proper flag above
            set_variable = {
                name = movement_petition
                value = flag:error
            }	    	
	    }
		if = {
			limit = {
				has_variable = movement_petition
				var:movement_petition != flag:error
			}
			if = {
				limit = {
					scope:petitioner.location != scope:petition_recipient.capital_province
				}
				start_travel_plan = {
					destination = scope:petition_recipient.capital_province
					on_arrival_event = tgp_decision_events.0100
					on_travel_planner_cancel_event = tgp_decision_events.0199
				}
			}
			else = {
				trigger_event = tgp_decision_events.0100
			}
			scope:actors_movement = {
				set_variable = {
					name = movement_petition_in_progress
					value = scope:petitioner
					years = 3
				}
			}
		}
		else = {
			debug_log = "AI tried to use Movement Petition, but failed to pick the topic"
		}
	}
	ai_potential = {
		is_any_movement_leader = yes
	}
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 72
		kingdom = 36
		empire = 24
		hegemony = 0
	}
	ai_will_do = {
		base = 100
	}
}
# Renounce Family Title
### Retire from Heading the [ROOT.Char.GetHouse.GetNameNoTooltip] House ###
renounce_noble_family_title_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_scenes/tgp_asia_estate.dds"
	}
	sort_order = 85

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					any_held_title = {
						is_noble_family_title = yes
						exists = current_heir
					}
				}
				desc = renounce_noble_family_title_decision_desc
			}
			desc = renounce_noble_family_title_decision_no_heir_desc
		}
	}
	selection_tooltip = renounce_noble_family_title_decision_tooltip
	decision_group_type = admin

	is_shown = {
		NOT = { top_liege = root } #This is not a general abdication decision
		has_tgp_dlc_trigger = yes
		is_playable_character = yes
		is_house_head = yes
		any_held_title = { is_noble_family_title = yes }
		NOT = { religion = religion:buddhism_religion } # Uses tgp_japan_become_a_monk_decision
	}

	is_valid = {
		custom_tooltip = {
			text = renounce_noble_family_title_decision_tt.title
			any_held_title = { is_noble_family_title = yes }
		}
		custom_tooltip = {
			text = renounce_noble_family_title_decision_tt.heir
			any_held_title = {
				is_noble_family_title = yes
				current_heir ?= { is_available_ai_adult = yes }
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war_with_liege = no
		trigger_if = {
			limit = {
				has_realm_law_flag = celestial_retirement_law
			}
			tgp_is_above_retirement_age_trigger = { REALM_OWNER = root }
		}
	}

	effect = {
		if = {
			limit = { is_ai = no }
			random_held_title = {
				limit = { is_noble_family_title = yes }
				current_heir = {  save_scope_as = new_player }
			}
		}
		show_as_tooltip = {
			add_character_modifier = { modifier = ep3_renounced_estate }
			custom_tooltip = renounce_noble_family_title_decision_tt
			if = {
				limit = { exists = scope:new_player }
				house = { set_house_head = scope:new_player }
				set_player_character = scope:new_player
			}
			tgp_step_down_title_recipient_tooltip_effect = yes
		}
		trigger_event = tgp_dynastic_cycle_decision_event.0101
		close_view = {
			view = decisions
			player = root
		}
	}
	
	cost = {
		influence = {
			value = 0
			if = {
				limit = { government_has_flag = government_has_influence }
				add = minor_influence_value
			}
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { government_has_flag = government_has_influence }
				}
				add = minor_prestige_value
			}
		}
	}

	ai_check_interval = 0

	ai_potential = {
		is_at_war = no
		# Don't step down freely if you don't have any other house members holding a noble_family_title or inherit any held noble_family_title
		OR = {
			house ?= {
				any_house_member = {
					is_governor = yes
					top_liege = root.top_liege
				}
			}
			any_held_title = {
				tier = root.highest_held_title_tier
				is_noble_family_title = no
				current_heir.house = root.house
			}
		}
		tgp_is_above_retirement_age_trigger = { REALM_OWNER = root }
	}

	ai_will_do = {
		base = -10
		modifier = {
			add = 10
			has_trait = lazy
		}
		modifier = {
			add = 10
			has_trait = humble
		}
		modifier = {
			add = 10
			has_trait = content
		}
		modifier = {
			add = -100
			OR = {
				has_trait = ambitious
				has_trait = greedy
				has_trait = arrogant
			}
		}
	}
}

#only for Players - ability to choose a favored Stability Era in the Dynastic Cycle, the AI uses hegemon_favored_stability_phase_value instead
### Favor Dynastic Cycle Era Decision ###
favor_dynastic_cycle_era_decision = {
	decision_group_type = dynastic_cycle
	title = favor_dynastic_cycle_era
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_title = title:h_china
				}
				desc = favor_dynastic_cycle_era_hegemon_desc
			}
			desc = favor_dynastic_cycle_era_chaos_desc
		}
	}
	selection_tooltip = {

		first_valid = {
			triggered_desc = {
				trigger = {
					has_title = title:h_china
				}
				desc = favor_dynastic_cycle_era_decision_hegemon_tooltip
			}
			desc = favor_dynastic_cycle_era_decision_chaos_tooltip
		}
	}
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_corruption.dds"
	}
	sort_order = 80

	is_shown = {
		has_tgp_dlc_trigger = yes
		is_ai = no
		OR = {
			AND = {
				situation:dynastic_cycle ?= {
					NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
				}
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = hegemon_ruler
				}
			}
			AND = {
				situation:dynastic_cycle ?= {
					situation_current_phase = situation_dynastic_cycle_phase_chaos
				}
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = other_rulers
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_adult = yes
	}
	cooldown = { years = 20 }
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_FAVOR_ERA"
		show_from_start = no

		item = {
			value = favor_advancement
			current_description = favor_advancement_desc
			localization = favor_advancement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_advancement.dds"
			ai_chance = {
				value = 0
			}
		}
		item = {
			value = favor_expansion
			current_description = favor_expansion_desc
			localization = favor_expansion_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_expansion.dds"
			ai_chance = {
				value = 0
			}
		}
	}

	cost = {
		influence = {
			value = monumental_influence_value
		}
	}

	effect = {
		switch = {
			trigger = yes
			scope:favor_advancement = {
				set_variable = {
					name = favor_era
					value = flag:advancement
				}
				custom_tooltip = favor_advancement_tt
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_chaos
						}
					}
					custom_tooltip = favor_advancement_movement_power_chaos_tt
				}
				else = {
					custom_tooltip = favor_advancement_movement_power_tt
				}
			}
			scope:favor_expansion = {
				set_variable = {
					name = favor_era
					value = flag:expansion
				}
				custom_tooltip = favor_expansion_tt
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_chaos
						}
					}
					custom_tooltip = favor_expansion_movement_power_chaos_tt
				}
				else = {
					custom_tooltip = favor_expansion_movement_power_tt
				}
			}
		}
	}

	ai_check_interval = 0
}

#only for Players - ability to choose a favored Movement, the AI will always follow the Debates activity outcomes instead
### Favor a Movement ###
favor_movement_decision = {
	decision_group_type = dynastic_cycle
	title = favor_movement_decision
	desc = favor_movement_decision_desc
	selection_tooltip = favor_movement_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_story/tgp_dynastic_cycle_corruption.dds"
	}
	sort_order = 80

	is_shown = {
		has_tgp_dlc_trigger = yes
		is_ai = no
		any_character_situation = {
			situation_type = dynastic_cycle
			NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		}
		has_title = title:h_china
	}

	is_valid_showing_failures_only = {
		is_adult = yes
	}
	cooldown = { years = 20 }
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_FAVOR_MOVEMENT"
		show_from_start = no

		item = {
			value = advancement_movement
			current_description = favor_advancement_movement_desc
			localization = favor_advancement_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_advance.dds"
			flat = yes
			is_valid = {
				NOT = {
					is_movement_in_power = {
						MOVEMENT = advancement_movement
					}
				}
			}
		}
		item = {
			value = expansion_movement
			current_description = favor_expansion_movement_desc
			localization = favor_expansion_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_expand.dds"
			flat = yes
			is_valid = {
				NOT = {
					is_movement_in_power = {
						MOVEMENT = expansion_movement
					}
				}
			}
		}
		item = {
			value = conservative_movement
			current_description = favor_conservative_movement_desc
			localization = favor_conservative_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_anti.dds"
			flat = yes
			is_valid = {
				NOT = {
					is_movement_in_power = {
						MOVEMENT = conservative_movement
					}
				}
			}
		}
		item = {
			value = pro_hegemon_movement
			current_description = favor_pro_hegemon_movement_desc
			localization = favor_pro_hegemon_movement_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_group_pro.dds"
			flat = yes
			is_valid = {
				NOT = {
					is_movement_in_power = {
						MOVEMENT = pro_hegemon_movement
					}
				}
			}
		}
	}

	cost = {
		influence = {
			value = monumental_influence_value
		}
	}

	effect = {
		save_scope_as = hegemon
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					has_variable = movement_favored
				}
				save_scope_as = former_favored_movement
			}
			switch = {
				trigger = yes
				scope:advancement_movement = {
					situation_participant_group:advancement_movement = {
						make_movement_favored_effect = yes
						save_scope_as = new_favored_movement
					}
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_gained_power_advancement
						}
						trigger_situation_catalyst = catalyst_movement_gained_power_advancement
					}
				}
				scope:expansion_movement = {
					situation_participant_group:expansion_movement = {
						make_movement_favored_effect = yes
						save_scope_as = new_favored_movement
					}
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_gained_power_expansion
						}
						trigger_situation_catalyst = catalyst_movement_gained_power_expansion
					}
				}
				scope:conservative_movement = {
					situation_participant_group:conservative_movement = {
						make_movement_favored_effect = yes
						save_scope_as = new_favored_movement
					}
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_gained_power_conservative
						}
						trigger_situation_catalyst = catalyst_movement_gained_power_conservative
					}
				}
				scope:pro_hegemon_movement = {
					situation_participant_group:pro_hegemon_movement = {
						make_movement_favored_effect = yes
						save_scope_as = new_favored_movement
					}
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_gained_power_pro_hegemon
						}
						trigger_situation_catalyst = catalyst_movement_gained_power_pro_hegemon
					}
				}
			}
			every_participant_group = {
				var:movement_leader ?= {
					trigger_event = tgp_dynastic_cycle_decision_event.0111
				}
			}
		}
		hidden_effect = {
			every_player = {
				limit = {
					tgp_does_this_player_care_about_the_dynastic_cycle = yes
					is_any_movement_leader = no
				}
				send_interface_message = {
					type = event_struggle_neutral
					title = favor_movement_decision.tt
					left_icon = scope:hegemon
					right_icon = scope:new_favored_movement.var:movement_leader
					show_as_tooltip = {
						scope:new_favored_movement = {
							make_movement_favored_effect = yes
						}
					}
				}
			}
		}
	}

	ai_check_interval = 0
}

#Ability to trigger a catalyst towards or away from chosen phase
### Shape the Dynastic Cycle ###
favored_movement_consults_heaven_decision = {
	decision_group_type = dynastic_cycle
	title = favored_movement_consults_heaven_decision
	desc = favored_movement_consults_heaven_decision_desc
	selection_tooltip = favored_movement_consults_heaven_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_scenes/tgp_asia_throne_room.dds"
	}
	sort_order = 80

	is_shown = {
		has_tgp_dlc_trigger = yes
		any_character_situation = {
			situation_type = dynastic_cycle
			NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		}
		top_participant_group:dynastic_cycle ?= {
			NOT = { participant_group_type = other_rulers }
		}
	}

	is_valid_showing_failures_only = {
		is_adult = yes
		custom_tooltip = {
			text = can_consult_heaven_tt
			OR = {
				AND = {
					is_any_movement_leader = yes
					top_participant_group:dynastic_cycle ?= {
						exists = var:movement_favored
						var:movement_leader ?= root
					}
				}
				has_title = title:h_china
				has_title = title:e_minister_chancellor
			}
		}
	}
	cooldown = { years = 10 }
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_CONSULT_HEAVEN"
		show_from_start = yes

		item = {
			value = positive_advancement_catalyst
			current_description = positive_advancement_catalyst_desc
			localization = positive_advancement_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_advancement.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_advancement }
				}
			}
			is_valid = {
				custom_tooltip = {
					text = positive_advancement_catalyst_tt
					root = {
						top_participant_group:dynastic_cycle ?= {
							OR = {
								participant_group_type = advancement_movement
								participant_group_type = hegemon_ruler
							}
						}
					}
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							trigger_if = {
								limit = {
									OR = {
										situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
										situation_current_phase = situation_dynastic_cycle_phase_instability
									}
								}
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_chaos >= 150
								}
							}
							trigger_else = {
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_instability >= 150
								}
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = negative_advancement_catalyst
			current_description = negative_advancement_catalyst_desc
			localization = negative_advancement_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_advancement.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_movement_consulted_heaven_advancement_negative
					trigger_if = {
						limit = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
						}
						custom_tooltip = {
							text = negative_advancement_catalyst_tt
							root = {
								top_participant_group:dynastic_cycle ?= {
									OR = {
										participant_group_type = advancement_movement
										participant_group_type = hegemon_ruler
									}
								}
							}
						}
					}
					trigger_else = {
						root = {
							top_participant_group:dynastic_cycle ?= {
								NOT = { participant_group_type = advancement_movement }
							}
						}
					}
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							NOR = {
								situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
								situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							}
							situation_top_sub_region = {
								phase_takeover_points:situation_dynastic_cycle_phase_stability_advancement >= 150
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = positive_expansion_catalyst
			current_description = positive_expansion_catalyst_desc
			localization = positive_expansion_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_expansion.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					NOT = { situation_current_phase = situation_dynastic_cycle_phase_stability_expansion }
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					trigger_if = {
						limit = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						}
						root = {
							top_participant_group:dynastic_cycle ?= {
								NOT = {	participant_group_type = expansion_movement }
							}
						}
					}
					trigger_else = {
						custom_tooltip = {
							text = positive_expansion_catalyst_tt
							root = {
								top_participant_group:dynastic_cycle ?= {
									OR = {
										participant_group_type = expansion_movement
										participant_group_type = hegemon_ruler
									}
								}
							}
						}
					}
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							trigger_if = {
								limit = {
									OR = {
										situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
										situation_current_phase = situation_dynastic_cycle_phase_instability
									}
								}
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_chaos >= 150
								}
							}
							trigger_else = {
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_instability >= 150
								}
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = negative_expansion_catalyst
			current_description = negative_expansion_catalyst_desc
			localization = negative_expansion_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_expansion.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_movement_consulted_heaven_expansion_negative
					trigger_if = {
						limit = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						}
						custom_tooltip = {
							text = negative_expansion_catalyst_tt
							root = {
								top_participant_group:dynastic_cycle ?= {
									OR = {
										participant_group_type = expansion_movement
										participant_group_type = hegemon_ruler
									}
								}
							}
						}
					}
					trigger_else = {
						root = {
							top_participant_group:dynastic_cycle ?= {
								NOT = {	participant_group_type = expansion_movement }
							}
						}
					}
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							NOR = {
								situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
								situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							}
							situation_top_sub_region = {
								phase_takeover_points:situation_dynastic_cycle_phase_stability_expansion >= 150
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = positive_chaos_catalyst
			current_description = positive_chaos_catalyst_desc
			localization = positive_chaos_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_chaos.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					NOR = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_movement_consulted_heaven_chaos_positive
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							trigger_if = {
								limit = {
									OR = {
										situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
										situation_current_phase = situation_dynastic_cycle_phase_instability
									}
								}
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_chaos <= 250
								}
							}
							trigger_else = {
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_instability <= 250
								}
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = negative_chaos_catalyst
			current_description = negative_chaos_catalyst_desc
			localization = negative_chaos_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_chaos.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					NOR = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_movement_consulted_heaven_chaos_negative
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							trigger_if = {
								limit = {
									OR = {
										situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
										situation_current_phase = situation_dynastic_cycle_phase_instability
									}
								}
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_chaos <= 250
								}
							}
							trigger_else = {
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_instability <= 250
								}
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = positive_instability_catalyst
			current_description = positive_instability_catalyst_desc
			localization = positive_instability_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_instability.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_movement_consulted_heaven_instability_positive
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							trigger_if = {
								limit = {
									OR = {
										situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
										situation_current_phase = situation_dynastic_cycle_phase_instability
									}
								}
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_chaos <= 250
								}
							}
							trigger_else = {
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_instability <= 250
								}
							}
						}
					}
					add = 100
				}
			}
		}
		item = {
			value = negative_instability_catalyst
			current_description = negative_instability_catalyst_desc
			localization = negative_instability_catalyst_name
			icon = "gfx/interface/icons/dynastic_cycle/dynastic_cycle_phase_instability.dds"
			is_shown = {
				situation:dynastic_cycle ?= {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
			}
			is_valid = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_movement_consulted_heaven_instability_negative
				}
			}
			ai_chance = {
				value = 0
				if = {
					limit = {
						situation:dynastic_cycle ?= {
							trigger_if = {
								limit = {
									OR = {
										situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
										situation_current_phase = situation_dynastic_cycle_phase_instability
									}
								}
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_chaos <= 250
								}
							}
							trigger_else = {
								situation_top_sub_region = {
									phase_takeover_points:situation_dynastic_cycle_phase_instability <= 250
								}
							}
						}
					}
					add = 100
				}
			}
		}
	}

	cost = {
		influence = {
			value = monumental_influence_value
		}
	}

	effect = {
		top_participant_group:dynastic_cycle ?= {
	        if = {
	        	limit = {
	        		participant_group_type = hegemon_ruler
	        	}
	        	situation:dynastic_cycle.situation_participant_group:pro_hegemon_movement = {
					save_scope_as = actors_movement
				}
	        }
	        else = {
				save_scope_as = actors_movement
		    }
		}
		scope:actors_movement = {
			petition_change_movement_power_effect = {
				VALUE = -200
			}
		}
		situation:dynastic_cycle ?= {
			switch = {
				trigger = yes
				scope:positive_advancement_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_advancement_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_advancement_positive
					}
					else_if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_instability_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_instability_positive
					}
					else_if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_chaos_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_chaos_positive
					}
				}
				scope:negative_advancement_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_advancement_negative
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_advancement_negative
					}
				}
				scope:positive_expansion_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_expansion_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_expansion_positive
					}
					else_if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_instability_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_instability_positive
					}
					else_if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_chaos_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_chaos_positive
					}
				}
				scope:negative_expansion_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_expansion_negative
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_expansion_negative
					}
				}
				scope:positive_chaos_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_chaos_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_chaos_positive
					}
				}
				scope:negative_chaos_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_chaos_negative
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_chaos_negative
					}
				}
				scope:positive_instability_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_instability_positive
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_instability_positive
					}
				}
				scope:negative_instability_catalyst = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_movement_consulted_heaven_instability_negative
						}
						trigger_situation_catalyst = catalyst_movement_consulted_heaven_instability_negative
					}
				}
			}
		}
	}

	ai_potential = {
		is_any_movement_leader = yes
	}
	ai_check_interval_by_tier = {
		barony = 0
		county = 120
		duchy = 120
		kingdom = 36
		empire = 12
		hegemony = 12
	}
	ai_will_do = {
		base = 100
	}
}

#House Heads' ability to trigger a catalyst towards or away from a phase according to their movement
### Consult Heaven ###
house_head_consults_heaven_decision = {
	decision_group_type = dynastic_cycle
	title = house_head_consults_heaven_decision
	desc = house_head_consults_heaven_decision_desc
	selection_tooltip = house_head_consults_heaven_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/event_scenes/tgp_asia_estate.dds"
	}
	sort_order = 80

	is_shown = {
		has_tgp_dlc_trigger = yes
		any_character_situation = {
			situation_type = dynastic_cycle
			NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		}
		top_participant_group:dynastic_cycle ?= {
			NOT = { participant_group_type = other_rulers }
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		custom_tooltip = {
			text = is_in_a_movement_with_leader_tt
			OR = {
				is_house_head = yes
				top_participant_group:dynastic_cycle ?= {
					var:movement_leader ?= root
				}
				has_title = title:e_minister_chancellor
			}
		}
	}
	cooldown = { years = 10 }

	cost = {
		influence = {
			value = 2000
			add = {
				value = 0
				every_close_or_extended_family_member = {
					limit = {
						is_governor = yes
					}
					add = 10
				}
				multiply = -1
			}
			add = {
				value = 0
				every_close_or_extended_family_member = {
					limit = {
						merit_level >= 4
					}
					add = 10
				}
				multiply = -1
			}
			if = {
				limit = {
					scope:discount_none ?= yes
				}
				multiply = 0.5
			}
			min = 100
		}
		piety = {
			value = 0
			if = {
				limit = {
					scope:discount_none ?= yes
				}
				add = 1000
			}
		}
	}
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_CONSULT_HEAVEN"
		show_from_start = yes

		item = {
			value = discount_none
			current_description = positive_advancement_catalyst_desc
			localization = discount_none_name
			icon = "gfx/interface/icons/modifiers/icon_piety_confucianism_04.dds"
			is_valid = {
				piety_level >= 4
			}
			ai_chance = {
				value = 10
			}
		}
		item = {
			value = discount_powerful_family
			current_description = negative_advancement_catalyst_desc
			localization = discount_powerful_family_name
			icon = "gfx/interface/icons/icon_game_concept_powerful_house.dds"
			is_valid = {
				custom_tooltip = {
					text = HOUSE_VIEW_POWERLESS_FAMILY
					house = {
						OR = {
							is_powerful_family = yes
							title:h_china.holder.house ?= this
						}
					}
				}
			}
			ai_chance = {
				value = 50
			}
		}
		item = {
			value = discount_family_governors
			current_description = positive_expansion_catalyst_desc
			localization = discount_family_governors_name
			icon = "gfx/interface/icons/message_feed/governor.dds"
			is_valid = {
				custom_tooltip = {
					text = discount_family_governors_tt
					any_close_or_extended_family_member = {
						is_governor = yes
						count >= 20
					}
				}
			}
			ai_chance = {
				value = 200
			}
		}
		item = {
			value = discount_family_merit
			current_description = negative_expansion_catalyst_desc
			localization = discount_family_merit_name
			icon = "gfx/interface/icons/icon_merit.dds"
			is_valid = {
				custom_tooltip = {
					text = discount_family_merit_tt
					any_close_or_extended_family_member = {
						merit_level >= 6
						count >= 10
					}
				}
			}
			ai_chance = {
				value = 500
			}
		}
	}

	effect = {
		top_participant_group:dynastic_cycle ?= {
	        if = {
	        	limit = {
	        		participant_group_type = hegemon_ruler
	        	}
	        	situation:dynastic_cycle.situation_participant_group:pro_hegemon_movement = {
					save_scope_as = actors_movement
				}
	        }
	        else = {
				save_scope_as = actors_movement
		    }
		}
		show_as_tooltip = {
			if = {
				limit = {
					NOR = {
						scope:discount_none = yes
						scope:discount_powerful_family = yes
						scope:discount_family_governors = yes
						scope:discount_family_merit = yes
					}
				}
				scope:actors_movement = { tgp_catalyst_from_decision_effect = yes }
			}
		}
		scope:actors_movement = {
			switch = {
				trigger = yes
				scope:discount_none = {
					tgp_catalyst_from_decision_effect = yes
				}
				scope:discount_powerful_family = {
					tgp_catalyst_from_decision_effect = yes

				}
				scope:discount_family_governors = {
					tgp_catalyst_from_decision_effect = yes

				}
				scope:discount_family_merit = {
					tgp_catalyst_from_decision_effect = yes
				}
			}
		}
	}

	ai_potential = {
		government_allows = merit
		OR = { # To make sure the cycle isn't nuked by landless families
			highest_held_title_tier >= tier_duchy
			house = {
				is_powerful_family = yes
			}
		}
		situation:dynastic_cycle ?= {
			trigger_if = {
				limit = {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					}
				}
				situation_top_sub_region = {
					phase_takeover_points:situation_dynastic_cycle_phase_instability >= 100
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						situation_current_phase = situation_dynastic_cycle_phase_instability
					}
				}
				situation_top_sub_region = {
					phase_takeover_points:situation_dynastic_cycle_phase_chaos >= 100
				}
			}
			trigger_else = {
				always = yes
			}
		}
	}
	ai_check_interval_by_tier = {
		barony = 0
		county = 120
		duchy = 120
		kingdom = 36
		empire = 12
		hegemony = 12
	}
	ai_will_do = {
		base = 100
		modifier = {
			situation:dynastic_cycle ?= {
				trigger_if = {
					limit = {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
							situation_current_phase = situation_dynastic_cycle_phase_instability
						}
					}
					situation_top_sub_region = {
						phase_takeover_points:situation_dynastic_cycle_phase_chaos >= 100
					}
				}
				trigger_else = {
					situation_top_sub_region = {
						phase_takeover_points:situation_dynastic_cycle_phase_instability >= 100
					}
				}
			}
			factor = 10
		}
	}
}
